diff --git a/ARW.Model/Vo/Api/Carts/CartApiVo.cs b/ARW.Model/Vo/Api/Carts/CartApiVo.cs
index b7e2d55..5f8f0ec 100644
--- a/ARW.Model/Vo/Api/Carts/CartApiVo.cs
+++ b/ARW.Model/Vo/Api/Carts/CartApiVo.cs
@@ -130,12 +130,17 @@ namespace ARW.Model.Vo.Api.Carts
///
/// 商品规格详情
///
- public SpecInfo SpecInfo { get; set; }
+ public List SpecInfo { get; set; }
///
/// 购物车加入时间
///
public DateTime JoinCartTime { get; set; }
+
+ ///
+ /// 是否选中
+ ///
+ public bool IsSelected { get; set; }
}
diff --git a/ARW.Model/Vo/Api/Carts/CartListApiVo.cs b/ARW.Model/Vo/Api/Carts/CartListApiVo.cs
new file mode 100644
index 0000000..8b960c2
--- /dev/null
+++ b/ARW.Model/Vo/Api/Carts/CartListApiVo.cs
@@ -0,0 +1,32 @@
+using Newtonsoft.Json;
+using OfficeOpenXml.Attributes;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+
+namespace ARW.Model.Vo.Api.Carts
+{
+ ///
+ /// 购物车列表记录展示对象Api
+ ///
+ /// @author lwh
+ /// @date 2023-08-03
+ ///
+ public class CartListVoApi
+ {
+
+ ///
+ /// 描述 : 是否为空
+ ///
+ public bool IsNotEmpty { get; set; }
+
+
+ ///
+ /// 购物车信息
+ ///
+ public List StoreGoods { get; set; }
+
+ }
+
+
+}
diff --git a/ARW.Service/Api/BusinessService/Carts/CartServiceApi.cs b/ARW.Service/Api/BusinessService/Carts/CartServiceApi.cs
index 980e431..a61a06d 100644
--- a/ARW.Service/Api/BusinessService/Carts/CartServiceApi.cs
+++ b/ARW.Service/Api/BusinessService/Carts/CartServiceApi.cs
@@ -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
///
///
///
- public async Task> GetCartListApi(CartQueryDtoApi parm)
+ public async Task 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();
+ // 查找当前客户可使用的优惠券
+ 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();
+ var notHasCouponGoodsList = new List();
+ 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 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;
+ }
+
+
+ ///
+ /// 获取购物车商品信息
+ ///
+ /// 当前客户的购物车列表
+ /// 店铺guid
+ /// 购物车类型
+ ///
+ ///
+ private async Task> GetGoodsPromotionList(List customerCartList, long shopGuid)
+ {
+ var goodsPromotionList = new List();
+ 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();
+
+ 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;
}
diff --git a/ARW.Service/Api/IBusinessService/Carts/ICartServiceApi.cs b/ARW.Service/Api/IBusinessService/Carts/ICartServiceApi.cs
index 836cf85..492985c 100644
--- a/ARW.Service/Api/IBusinessService/Carts/ICartServiceApi.cs
+++ b/ARW.Service/Api/IBusinessService/Carts/ICartServiceApi.cs
@@ -23,7 +23,7 @@ namespace ARW.Service.Api.IBusinessService.Carts
///
///
///
- Task> GetCartListApi(CartQueryDtoApi parm);
+ Task GetCartListApi(CartQueryDtoApi parm);
}