fixed 完善购物车列表展示

This commit is contained in:
lwh 2023-08-03 15:40:59 +08:00
parent 064b9fea0a
commit 33942e2a60
4 changed files with 226 additions and 9 deletions

View File

@ -130,12 +130,17 @@ namespace ARW.Model.Vo.Api.Carts
/// <summary>
/// 商品规格详情
/// </summary>
public SpecInfo SpecInfo { get; set; }
public List<SpecInfo> SpecInfo { get; set; }
/// <summary>
/// 购物车加入时间
/// </summary>
public DateTime JoinCartTime { get; set; }
/// <summary>
/// 是否选中
/// </summary>
public bool IsSelected { get; set; }
}

View File

@ -0,0 +1,32 @@
using Newtonsoft.Json;
using OfficeOpenXml.Attributes;
using SqlSugar;
using System;
using System.Collections.Generic;
namespace ARW.Model.Vo.Api.Carts
{
/// <summary>
/// 购物车列表记录展示对象Api
///
/// @author lwh
/// @date 2023-08-03
/// </summary>
public class CartListVoApi
{
/// <summary>
/// 描述 : 是否为空
/// </summary>
public bool IsNotEmpty { get; set; }
/// <summary>
/// 购物车信息
/// </summary>
public List<CartVoApi> StoreGoods { get; set; }
}
}

View File

@ -18,6 +18,17 @@ using ARW.Model.Models.Business.GoodsManager.Goodss;
using ARW.Model.Models.Business.ShopManager.Shops;
using Org.BouncyCastle.Crypto.Prng;
using ARW.Repository.Business.ShopManager.Shops;
using ARW.Repository.Business.Marketing.CouponManage.Coupons;
using ARW.Repository.Business.Marketing.CouponManage.CustomerCoupons;
using ARW.Repository.Business.GoodsManager.Goodss;
using ARW.Repository.Business.GoodsManager.GoodsSpecs.GoodsSkus;
using ARW.Repository.Business.GoodsManager.GoodsSpecs.Specs;
using ARW.Repository.Business.GoodsManager.GoodsSpecs.SpecValues;
using ARW.Repository.Business.GoodsManager.GoodsSpecs.GoodsSpecRels;
using Senparc.Weixin.MP.AdvancedAPIs.MerChant;
using Infrastructure;
using ARW.Model.Models.Business.Marketing.CouponManage.CustomerCoupons;
using ARW.Model.Models.Business.Marketing.CouponManage.Coupons;
namespace ARW.Service.Api.BusinessService.Carts
{
@ -32,11 +43,23 @@ namespace ARW.Service.Api.BusinessService.Carts
{
private readonly CartRepository _CartRepository;
private readonly ShopRepository _ShopRepository;
private readonly CouponRepository _CouponRepository;
private readonly CustomerCouponRepository _CustomerCouponRepository;
private readonly GoodsRepository _GoodsRepository;
private readonly GoodsSkuRepository _GoodsSkuRepository;
private readonly SpecRepository _SpecRepository;
private readonly SpecValueRepository _SpecValueRepository;
public CartServiceImplApi(CartRepository CartRepository, ShopRepository shopRepository)
public CartServiceImplApi(CartRepository CartRepository, ShopRepository shopRepository, CustomerCouponRepository customerCouponRepository, CouponRepository couponRepository, GoodsRepository goodsRepository, GoodsSkuRepository goodsSkuRepository, SpecRepository specRepository, SpecValueRepository specValueRepository)
{
this._CartRepository = CartRepository;
_ShopRepository = shopRepository;
_CustomerCouponRepository = customerCouponRepository;
_CouponRepository = couponRepository;
_GoodsRepository = goodsRepository;
_GoodsSkuRepository = goodsSkuRepository;
_SpecRepository = specRepository;
_SpecValueRepository = specValueRepository;
}
#region Api接口代码
@ -47,7 +70,7 @@ namespace ARW.Service.Api.BusinessService.Carts
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public async Task<List<CartVoApi>> GetCartListApi(CartQueryDtoApi parm)
public async Task<CartListVoApi> GetCartListApi(CartQueryDtoApi parm)
{
// 找到当前客户的所有购物车列表
var customerCartList = await _CartRepository.GetListAsync(s => s.CustomerGuid == parm.CustomerGuid);
@ -64,20 +87,177 @@ namespace ARW.Service.Api.BusinessService.Carts
shopCart.StoreId = shop.ShopGuid;
shopCart.StoreName = shop.ShopName;
// 查找当前用户的优惠券
//var coupon =
var promotionGoodsList = new List<PromotionGoods>();
// 查找当前客户可使用的优惠券
var couponList = await _CustomerCouponRepository.GetListAsync(s => s.CustomerGuid == parm.CustomerGuid && s.CustomerCouponIsUsed == 1 && s.CustomerCouponIsExpired == 1);
foreach (var _item in customerCartList)
// 如果有优惠券
if (couponList.Count() > 0)
{
if (_item.ShopGuid == shop.ShopGuid)
foreach (var customerCoupon in couponList)
{
var promotionGoods = new PromotionGoods();
var coupon = await _CouponRepository.GetFirstAsync(s => s.CouponGuid == customerCoupon.CouponGuid);
promotionGoods.PromotionId = coupon.CouponId;
promotionGoods.Title = coupon.CouponName;
promotionGoods.PromotionCode = "MERCHANT";
if (coupon.CouponType == 1)
promotionGoods.Tag = "满减";
else
promotionGoods.Tag = "折扣";
promotionGoods.Description = coupon.CouponDesc;
// 情况1全部商品的通用券
if (coupon.CouponApplicableScope == 1)
{
var goodsPromotionList = await GetGoodsPromotionList(customerCartList, shop.ShopGuid);
promotionGoods.GoodsPromotionList = goodsPromotionList;
promotionGoodsList.Add(promotionGoods);
}
// // 情况2指定商品的券
if (coupon.CouponApplicableScope == 2)
{
// 根据优惠券指定的商品查找购物车中是否有对应的商品
if (string.IsNullOrEmpty(coupon.CouponGoodsIds)) throw new CustomException("该优惠券还未指定商品");
var goodsIds = coupon.CouponGoodsIds.Split(',');
var hasCouponGoodsList = new List<Cart>();
var notHasCouponGoodsList = new List<Cart>();
foreach (var id in goodsIds)
{
var couponGoods = await _GoodsRepository.GetFirstAsync(s => s.GoodsId == Convert.ToInt32(id));
foreach (var cart in customerCartList)
{
if (cart.GoodsGuid == couponGoods.GoodsGuid)
{
hasCouponGoodsList.Add(cart);
}
else
{
notHasCouponGoodsList.Add(cart);
}
}
}
var goodsPromotionList = await GetGoodsPromotionList(hasCouponGoodsList, shop.ShopGuid);
promotionGoods.GoodsPromotionList = goodsPromotionList;
if(promotionGoods.GoodsPromotionList.Count() > 0)
{
promotionGoodsList.Add(promotionGoods);
}
var NotCouponPromotionGoods = new PromotionGoods();
NotCouponPromotionGoods.GoodsPromotionList = await GetGoodsPromotionList(notHasCouponGoodsList, shop.ShopGuid); ;
promotionGoodsList.Add(NotCouponPromotionGoods);
}
}
}
else // 如果没有优惠券
{
var promotionGoods = new PromotionGoods();
var goodsPromotionList = await GetGoodsPromotionList(customerCartList, shop.ShopGuid);
promotionGoods.GoodsPromotionList = goodsPromotionList;
promotionGoodsList.Add(promotionGoods);
}
shopCart.PromotionGoodsList = promotionGoodsList;
res.Add(shopCart);
}
return res;
var cartList = new CartListVoApi();
if(res.Count() > 0)
{
cartList.IsNotEmpty = true;
cartList.StoreGoods = res;
}
return cartList;
}
private async Task<SpecInfo> GetSpecInfo(int value)
{
var specInfo = new SpecInfo();
var sepcValue = await _SpecValueRepository.GetFirstAsync(s => s.SpecValueId == value);
var sepc = await _SpecRepository.GetFirstAsync(s => s.SpecId == sepcValue.SpecId);
specInfo.SpecTitle = sepc.SpecName;
specInfo.SpecValue = sepcValue.SpecValueName;
return specInfo;
}
/// <summary>
/// 获取购物车商品信息
/// </summary>
/// <param name="customerCartList">当前客户的购物车列表</param>
/// <param name="shopGuid">店铺guid</param>
/// <param name="type">购物车类型</param>
/// <returns></returns>
/// <exception cref="CustomException"></exception>
private async Task<List<GoodsPromotion>> GetGoodsPromotionList(List<Cart> customerCartList, long shopGuid)
{
var goodsPromotionList = new List<GoodsPromotion>();
foreach (var _item in customerCartList)
{
var goodsPromotion = new GoodsPromotion();
if (_item.ShopGuid == shopGuid)
{
var goods = new Goods();
goods = await _GoodsRepository.GetFirstAsync(s => s.GoodsGuid == _item.GoodsGuid);
if (goods.GoodsId != 0)
{
goodsPromotion.StoreId = goods.ShopGuid;
goodsPromotion.SpuId = goods.GoodsGuid;
goodsPromotion.SkuId = _item.GoodsSkuId;
goodsPromotion.Thumb = goods.GoodsPicture.Split(',').First();
goodsPromotion.Title = goods.GoodsName;
goodsPromotion.Quantity = _item.CartGoodsNum;
goodsPromotion.StockStatus = goods.GoodsTotalInventory > _item.CartGoodsNum;
goodsPromotion.StockQuantity = goods.GoodsTotalInventory;
// 查找当前规格的价格
var sku = await _GoodsSkuRepository.GetFirstAsync(s => s.GoodsSkuId == _item.GoodsSkuId);
if (sku == null) throw new CustomException("所选规格不存在,请重新挑选");
goodsPromotion.Price = sku.GoodsSkuPrice;
goodsPromotion.OriginPrice = sku.GoodsSkuLinePrice;
// 查找当前规格的详细信息
var specInfoList = new List<SpecInfo>();
if (sku.SpecValueId != 0)
{
var specInfo = await GetSpecInfo(sku.SpecValueId);
specInfoList.Add(specInfo);
if (sku.SpecSecondValueId != 0)
{
var specInfo2 = await GetSpecInfo(sku.SpecSecondValueId);
specInfoList.Add(specInfo2);
}
if (sku.SpecThirdValueId != 0)
{
var specInfo3 = await GetSpecInfo(sku.SpecThirdValueId);
specInfoList.Add(specInfo3);
}
}
goodsPromotion.SpecInfo = specInfoList;
goodsPromotion.JoinCartTime = _item.Create_time;
goodsPromotionList.Add(goodsPromotion);
}
}
}
return goodsPromotionList;
}

View File

@ -23,7 +23,7 @@ namespace ARW.Service.Api.IBusinessService.Carts
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
Task<List<CartVoApi>> GetCartListApi(CartQueryDtoApi parm);
Task<CartListVoApi> GetCartListApi(CartQueryDtoApi parm);
}