From 95f9ea7eb339c36cade6c67d0385c49ec2d81477 Mon Sep 17 00:00:00 2001
From: 935090232@qq.com <ak473600000>
Date: Wed, 14 Apr 2021 19:39:45 +0800
Subject: [PATCH] Merge branch 'score_shop' into api_score_meger

---
 zq-erp/src/main/java/com/matrix/system/shopXcx/api/service/impl/WxShopCouponServiceImpl.java |   88 ++++++++++++++++++++++----------------------
 1 files changed, 44 insertions(+), 44 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 bf87285..d2840d3 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,20 +1,20 @@
 package com.matrix.system.shopXcx.api.service.impl;
 
+import com.matrix.system.hive.bean.SysVipInfo;
+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.*;
-import com.matrix.system.shopXcx.dao.*;
+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;
@@ -54,15 +54,16 @@
      *
      * @return
      */
-    public List<CouponReceiveInfoVO> getCartVoCouponList(Long companyId,List<ShopShoppingCart> shopShoppingCarts) {
+    public List<CouponReceiveInfoVO> getCartVoCouponList(Long companyId,List<OrderItemDto> OrderItemDtos){
 
-        //可用优惠券列表
+
+    //可用优惠券列表
         List<CouponReceiveInfoVO> shopCoupons = new ArrayList<>();
 
 
-        BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class);
+        SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
         //1.找到用户所有的优惠券
-        List<CouponReceiveInfoVO> userAllCoupon = shopCouponRecordDao.selectMyCouponByStatus(companyId, bizUser.getOpenId(), AppConstance.MY_COUPON_NOT_USE,
+        List<CouponReceiveInfoVO> userAllCoupon = shopCouponRecordDao.selectMyCouponByStatus(companyId, sysVipInfo.getId(), AppConstance.MY_COUPON_NOT_USE,
                 null);
         if (CollectionUtils.isNotEmpty(userAllCoupon)) {
             //根据优惠力度排序,优惠力度大的先参与计算
@@ -77,7 +78,7 @@
 
 
             //定义购物车优惠分组
-            List<ShopCartVo> cartList = new ArrayList<>();
+            List<OrderCouponGroup> cartList = new ArrayList<>();
 
             // 记录所有优惠券,一个优惠券(活动)表示一组
             Map<Integer, ShopCoupon> shopCouponMap = new HashMap<>();
@@ -86,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;
                         }
                     }
@@ -113,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());
                 }
             }
         }
@@ -125,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);
         }
     }
 
@@ -149,14 +150,14 @@
      */
     @Override
     public AjaxResult getUsableCoupon(PaginationVO pageVo) {
-        BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class);
-        boolean newPeople = wxShopCouponUtil.verifyIsNewPeople(bizUser.getOpenId());
-        List<ShopCoupon> list = shopCouponDao.selectUsableCoupon(newPeople, bizUser.getOpenId(), pageVo);
+        SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
+        boolean newPeople = wxShopCouponUtil.verifyIsNewPeople(sysVipInfo.getId());
+        List<ShopCoupon> list = shopCouponDao.selectUsableCoupon(newPeople, sysVipInfo.getOpenId(), pageVo);
         return new AjaxResult(AjaxResult.STATUS_SUCCESS, list);
     }
 
     /**
-     * 领取优惠券
+     *
      *
      * @param couponId
      * @return
@@ -165,7 +166,7 @@
     @Override
     public AjaxResult receiveCoupon(Integer couponId) {
         ShopCoupon shopCoupon = shopCouponDao.selectById(couponId);
-        BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class);
+        SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
 
         // 如果没有找到该优惠券
         if (shopCoupon == null) {
@@ -177,7 +178,7 @@
             return new AjaxResult(AjaxResult.STATUS_FAIL, "优惠券已领完!");
         }
 
-        boolean newPeople = wxShopCouponUtil.verifyIsNewPeople(bizUser.getOpenId());
+        boolean newPeople = wxShopCouponUtil.verifyIsNewPeople(sysVipInfo.getId());
 
         // 如果改券是新人专属且当前用户不是新人
         if (AppConstance.COUPON_GET_LIMT_NEW.equals(shopCoupon.getGetLimit()) && !newPeople) {
@@ -185,7 +186,7 @@
         }
 
         ShopCouponRecord param = new ShopCouponRecord();
-        param.setUserId(bizUser.getOpenId());
+        param.setUserId(sysVipInfo.getId());
         param.setCId(couponId);
         List<ShopCouponRecord> recordList = shopCouponRecordDao.selectByModel(param);
         // 如果已经领取改优惠券
@@ -196,7 +197,7 @@
         insertRecord.setCreateBy(AppConstance.SYSTEM_USER);
         insertRecord.setUpdateBy(AppConstance.SYSTEM_USER);
         insertRecord.setCId(couponId);
-        insertRecord.setUserId(bizUser.getOpenId());
+        insertRecord.setUserId(sysVipInfo.getId());
         insertRecord.setIsUsing(2);
         int i = shopCouponRecordDao.insert(insertRecord);
         // 如果插入领取记录表失败
@@ -218,14 +219,14 @@
      */
     @Override
     public AjaxResult getMyCouponInfoByStatus(Long companyId, Integer status, PaginationVO pageVo) {
-        BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class);
+        SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
         // 如果查询使用或未使用状态的优惠券列表
         if (AppConstance.MY_COUPON_USE.equals(status) || AppConstance.MY_COUPON_NOT_USE.equals(status)) {
-            List<CouponReceiveInfoVO> list = shopCouponRecordDao.selectMyCouponByStatus(companyId,bizUser.getOpenId(), status,
+            List<CouponReceiveInfoVO> list = shopCouponRecordDao.selectMyCouponByStatus(companyId,sysVipInfo.getId(), status,
                     pageVo);
             return new AjaxResult(AjaxResult.STATUS_SUCCESS, list);
         }
-        List<CouponReceiveInfoVO> list = shopCouponRecordDao.selectMyPastCoupon(companyId,bizUser.getOpenId(), pageVo);
+        List<CouponReceiveInfoVO> list = shopCouponRecordDao.selectMyPastCoupon(companyId,sysVipInfo.getId(), pageVo);
         return new AjaxResult(AjaxResult.STATUS_SUCCESS, list);
     }
 
@@ -255,8 +256,8 @@
                 attrIds.addAll(ids);
             }
         }
-        BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class);
-        List<ShopCoupon> list = shopCouponDao.selectUsableCouponByProductInfo(bizUser.getOpenId(), productId,
+        SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
+        List<ShopCoupon> list = shopCouponDao.selectUsableCouponByProductInfo(sysVipInfo.getOpenId(), productId,
                 attrIds);
         return list;
     }
@@ -299,14 +300,13 @@
      * 通过优惠券标签获取优惠券列表
      *
      * @param tag 标签名称
-     * @param shopId
      * @return
      */
     @Override
     public AjaxResult getCouponListByTag(String tag, Long companyId) {
-        BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class);
-        boolean newPeople = wxShopCouponUtil.verifyIsNewPeople(bizUser.getOpenId());
-        List<ShopCoupon> couponList = shopCouponDao.selectCouponListByTag(newPeople, bizUser.getOpenId(), tag,companyId);
+        SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
+        boolean newPeople = wxShopCouponUtil.verifyIsNewPeople(sysVipInfo.getId());
+        List<ShopCoupon> couponList = shopCouponDao.selectCouponListByTag(newPeople, sysVipInfo.getOpenId(), tag,companyId);
         AjaxResult res = new AjaxResult(AjaxResult.STATUS_SUCCESS, couponList);
         res.putInMap("isNewPeople", newPeople);
         return res;

--
Gitblit v1.9.1