From d49c4335300c06504760c1bf02f3320da98964ae Mon Sep 17 00:00:00 2001
From: 935090232@qq.com <ak473600000>
Date: Thu, 01 Apr 2021 10:00:07 +0800
Subject: [PATCH] 积分
---
zq-erp/src/main/java/com/matrix/system/shopXcx/api/service/impl/WxShopCouponServiceImpl.java | 64 +++++++++++++++----------------
1 files changed, 31 insertions(+), 33 deletions(-)
diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/service/impl/WxShopCouponServiceImpl.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/service/impl/WxShopCouponServiceImpl.java
index 3f4f488..088d320 100644
--- a/zq-erp/src/main/java/com/matrix/system/shopXcx/api/service/impl/WxShopCouponServiceImpl.java
+++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/api/service/impl/WxShopCouponServiceImpl.java
@@ -1,26 +1,20 @@
package com.matrix.system.shopXcx.api.service.impl;
+import com.matrix.biz.bean.BizUser;
+import com.matrix.component.redis.RedisUserLoginUtils;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.LogUtil;
import com.matrix.core.tools.StringUtils;
-import com.matrix.biz.bean.BizUser;
-import com.matrix.component.redis.RedisUserLoginUtils;
import com.matrix.system.common.constance.AppConstance;
-
-import com.matrix.system.shopXcx.bean.ShopCoupon;
-import com.matrix.system.shopXcx.bean.ShopCouponRecord;
-import com.matrix.system.shopXcx.bean.ShopProductAttrRef;
-import com.matrix.system.shopXcx.bean.ShopShoppingCart;
-import com.matrix.system.shopXcx.dao.ShopCouponDao;
-import com.matrix.system.shopXcx.dao.ShopCouponRecordDao;
-import com.matrix.system.shopXcx.dao.ShopProductAttrRefDao;
-import com.matrix.system.shopXcx.dao.ShopReceiveAddressDao;
+import com.matrix.system.shopXcx.api.pojo.OrderCouponGroup;
+import com.matrix.system.shopXcx.api.pojo.OrderItemDto;
import com.matrix.system.shopXcx.api.service.WxShopCouponService;
import com.matrix.system.shopXcx.api.tools.WxShopCouponUtil;
import com.matrix.system.shopXcx.api.tools.WxShopOrderUtil;
import com.matrix.system.shopXcx.api.vo.CouponReceiveInfoVO;
-import com.matrix.system.shopXcx.api.vo.ShopCartVo;
+import com.matrix.system.shopXcx.bean.*;
+import com.matrix.system.shopXcx.dao.*;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -51,15 +45,19 @@
@Autowired
private WxShopCouponUtil wxShopCouponUtil;
+ @Autowired
+ private ShopProductDao productDao;
+
/**
* 根据购物车选中的产品,计算合适的优惠券
*
* @return
*/
- public List<CouponReceiveInfoVO> getCartVoCouponList(Long companyId,List<ShopShoppingCart> shopShoppingCarts) {
+ public List<CouponReceiveInfoVO> getCartVoCouponList(Long companyId,List<OrderItemDto> OrderItemDtos){
- //可用优惠券列表
+
+ //可用优惠券列表
List<CouponReceiveInfoVO> shopCoupons = new ArrayList<>();
@@ -80,7 +78,7 @@
//定义购物车优惠分组
- List<ShopCartVo> cartList = new ArrayList<>();
+ List<OrderCouponGroup> cartList = new ArrayList<>();
// 记录所有优惠券,一个优惠券(活动)表示一组
Map<Integer, ShopCoupon> shopCouponMap = new HashMap<>();
@@ -89,24 +87,24 @@
for (int i = 0; i < userAllCoupon.size(); i++) {
CouponReceiveInfoVO couponReceiveInfoVO = userAllCoupon.get(i);
- ShopCartVo shopCarVo = new ShopCartVo();
+ OrderCouponGroup shopCarVo = new OrderCouponGroup();
shopCarVo.setCouponReceiveInfoVO(couponReceiveInfoVO);
- shopCarVo.setCartList(new ArrayList<>());
+ shopCarVo.setOrderItemDtos(new ArrayList<>());
cartList.add(i, shopCarVo);
- for (ShopShoppingCart shoppingCart : shopShoppingCarts) {
+ for (OrderItemDto orderItemDto : OrderItemDtos) {
// 如果匹配到的产品已经出现在其他优惠组中,则需要判断是否移除之前的组
boolean needRemove = false;
//找到产品所有的优惠券
- List<ShopCoupon> productShopCoupons = getCouponListByProductId(shoppingCart.getCartProductId());
+ List<ShopCoupon> productShopCoupons = getCouponListByProductId(orderItemDto.getProductId());
for (ShopCoupon productShopCoupon : productShopCoupons) {
if (couponReceiveInfoVO.getCouponId().equals(productShopCoupon.getId())) {
- LogUtil.debug("购物车" + shoppingCart.getName() + "和优惠券" + couponReceiveInfoVO.getcName() + "匹配");
- shopCarVo.getCartList().add(shoppingCart);
+ LogUtil.debug("购物车" + orderItemDto.getProductId() + "和优惠券" + couponReceiveInfoVO.getcName() + "匹配");
+ shopCarVo.getOrderItemDtos().add(orderItemDto);
break;
}
}
@@ -116,9 +114,9 @@
}
//3.计算各组的金额是否满足,把满足的优惠券全部返回
- for (ShopCartVo shopCartVo : cartList) {
- if (shopCartVo.isSatisfactionCoupon() && CollectionUtils.isNotEmpty(shopCartVo.getCartList())) {
- shopCoupons.add(shopCartVo.getCouponReceiveInfoVO());
+ for (OrderCouponGroup orderCouponGroup : cartList) {
+ if (orderCouponGroup.isSatisfactionCoupon() && CollectionUtils.isNotEmpty(orderCouponGroup.getOrderItemDtos())) {
+ shopCoupons.add(orderCouponGroup.getCouponReceiveInfoVO());
}
}
}
@@ -128,19 +126,19 @@
- private void countPrice(ShopCartVo shopCartVo) {
- List<ShopShoppingCart> cartList = shopCartVo.getCartList();
+ private void countPrice(OrderCouponGroup orderCouponGroup) {
+ List<OrderItemDto> orderItemDtoList = orderCouponGroup.getOrderItemDtos();
// 计算总价
BigDecimal sum = BigDecimal.ZERO;
- for (ShopShoppingCart shopShoppingCart : cartList) {
- sum = sum.add(shopShoppingCart.getPrice().multiply(BigDecimal.valueOf(shopShoppingCart.getCartNumber())));
+ for (OrderItemDto orderItemDto : orderItemDtoList) {
+ sum = sum.add(orderItemDto.getShopSku().getPrice().multiply(BigDecimal.valueOf(orderItemDto.getCount())));
}
// 存在优惠券
- if (sum.compareTo(shopCartVo.getCouponReceiveInfoVO().getMinAmount()) >= 0) {
+ if (sum.compareTo(orderCouponGroup.getCouponReceiveInfoVO().getMinAmount()) >= 0) {
//标记为合理分组
- shopCartVo.setSatisfactionCoupon(true);
+ orderCouponGroup.setSatisfactionCoupon(true);
} else {
- shopCartVo.setSatisfactionCoupon(false);
+ orderCouponGroup.setSatisfactionCoupon(false);
}
}
@@ -290,7 +288,8 @@
attrIds.addAll(ids);
}
}
- List<ShopCoupon> list = shopCouponDao.selectHdListByProductId(productId, attrIds);
+ ShopProduct shopProduct = productDao.selectById(productId);
+ List<ShopCoupon> list = shopCouponDao.selectHdListByProductId(productId, attrIds,shopProduct.getCompanyId());
return list;
}
@@ -301,7 +300,6 @@
* 通过优惠券标签获取优惠券列表
*
* @param tag 标签名称
- * @param shopId
* @return
*/
@Override
--
Gitblit v1.9.1