瀏覽代碼

优惠券优化

Aslee 3 年之前
父節點
當前提交
8ed6fe700b

+ 7 - 1
src/main/java/com/caimei365/order/mapper/OrderCommonMapper.java

@@ -4,6 +4,7 @@ import com.caimei365.order.model.vo.*;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -134,8 +135,9 @@ public interface OrderCommonMapper {
     /**
      * 未领取的优惠券
      * @param userId 用户Id
+     * @param registerTime
      */
-    List<CouponVo> getPrevCouponList(Integer userId);
+    List<CouponVo> getPrevCouponList(@Param("userId") Integer userId, @Param("registerTime") Date registerTime);
     /**
      * 活动券商品Ids
      */
@@ -144,4 +146,8 @@ public interface OrderCommonMapper {
      * 获取订单发票信息
      */
     InvoiceVo getOrderInvoice(Integer orderId);
+    /**
+     * 根据用户id查询注册时间
+     */
+    Date getUserRegisterTime(Integer userId);
 }

+ 12 - 5
src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java

@@ -1,8 +1,5 @@
 package com.caimei365.order.service.impl;
 
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.caimei365.order.components.ProductService;
@@ -90,8 +87,15 @@ public class CartClubServiceImpl implements CartClubService {
         // 促销活动(总)
         List<PromotionsVo> totalPromotions = new ArrayList<>();
         List<Integer> promotionsIds = new ArrayList<>();
+        // 用户注册时间
+        Date registerTime = orderCommonMapper.getUserRegisterTime(userId);
         // 用户可用优惠券(总)
         List<CouponVo> couponList = orderCommonMapper.getClubCouponList(userId);
+        // 用户可领取优惠券(总)
+        List<CouponVo> preCouponList = orderCommonMapper.getPrevCouponList(userId, registerTime);
+        List<CouponVo> totalCouponList = new ArrayList<>();
+        totalCouponList.addAll(couponList);
+        totalCouponList.addAll(preCouponList);
         List<CartItemVo> cartAllProducts = new ArrayList<>();
         // 用户身份
         Integer userIdentity = baseMapper.getIdentityByUserId(userId);
@@ -321,7 +325,7 @@ public class CartClubServiceImpl implements CartClubService {
                         }
                     }
                     // 是否可领取优惠券
-                    Boolean couponsLogo = setCouponsLogo(shop.getShopId(), source, productList, couponList);
+                    Boolean couponsLogo = setCouponsLogo(shop.getShopId(), source, productList, totalCouponList);
                     shop.setCouponsLogo(couponsLogo);
 
                     // 供应商商品
@@ -338,6 +342,8 @@ public class CartClubServiceImpl implements CartClubService {
                     totalPrice.set(MathUtil.add(totalPrice, shop.getTotalPrice()).doubleValue());
                     // 优惠总额
                     reducedPrice.set(MathUtil.add(reducedPrice, shop.getReducedPrice()).doubleValue());
+                    // 超级会员优惠总额
+                    svipReducedPrice.set(MathUtil.add(svipReducedPrice, shop.getSvipReducedPrice()).doubleValue());
                     // 总划线价
                     totalOriginalPrice.set(MathUtil.add(totalOriginalPrice, shop.getOriginalPrice()).doubleValue());
                     // 商品种类
@@ -388,6 +394,7 @@ public class CartClubServiceImpl implements CartClubService {
         resultMap.put("totalCount", totalCount);
         resultMap.put("totalPrice", totalPrice);
         resultMap.put("reducedPrice", reducedPrice);
+        resultMap.put("svipReducedPrice", svipReducedPrice);
         resultMap.put("totalOriginalPrice", totalOriginalPrice);
         resultMap.put("promotions", totalPromotions);
         resultMap.put("couponList", couponList);
@@ -1841,7 +1848,7 @@ public class CartClubServiceImpl implements CartClubService {
         // 供应商下购物车商品列表
         List<CartItemVo> productList = cartClubMapper.getCartProductsByShopId(shopId, userId);
         // 未领取的优惠券
-        List<CouponVo> preCouponList = orderCommonMapper.getPrevCouponList(userId);
+        List<CouponVo> preCouponList = orderCommonMapper.getPrevCouponList(userId, registerTime);
         //剔除超级会员优惠券
         List<Integer> vipCoupon = cartClubMapper.findVipCoupon();
         if (preCouponList != null && preCouponList.size() > 0) {

+ 21 - 7
src/main/resources/mapper/OrderCommonMapper.xml

@@ -404,8 +404,14 @@
             id AS couponId,
             couponAmount,
             touchPrice,
-            startDate,
-            endDate,
+            <if test="userId == null || userId == 0">
+                startDate,
+                endDate,
+            </if>
+            <if test="userId >0">
+                if(#{registerTime} <![CDATA[ > ]]> startDate,#{registerTime},startDate) as startDate,
+                if(receiveFlag=1,endDate,date_add(if(#{registerTime} <![CDATA[ > ]]> startDate,#{registerTime},startDate),interval receivePeriod day)) as endDate,
+            </if>
             couponType,
             userId,
             shopId,
@@ -413,9 +419,10 @@
             categoryType
         FROM cm_coupon
         WHERE delFlag = 0 AND couponsMode = 0 AND status != 2
-        AND (NOW() BETWEEN startDate AND endDate)
         <if test="userId == null or userId == 0">
             AND couponType != 2
+            AND NOW() <![CDATA[ > ]]> startDate
+            AND NOW() <![CDATA[ < ]]> if(receiveFlag = 1,endDate,date_add(startDate,interval receivePeriod day)
         </if>
         <if test="userId > 0">
             AND id NOT IN(SELECT couponId FROM cm_coupon_club WHERE userId = #{userId})
@@ -423,6 +430,10 @@
             OR couponType = 2 AND userId = #{userId}
             OR ((SELECT registerTime FROM USER WHERE userID = #{userId}) <![CDATA[ >= ]]> startDate
             AND couponType = 4))
+            and NOW() <![CDATA[ > ]]> startDate
+            and NOW() <![CDATA[ < ]]> if(receiveFlag = 1,endDate,
+            date_add(if(#{registerTime} <![CDATA[ > ]]> startDate,#{registerTime},startDate),
+            interval receivePeriod day))
         </if>
         ORDER BY createDate DESC
     </select>
@@ -432,8 +443,8 @@
             cc.id AS couponId,
             cc.couponAmount,
             cc.touchPrice,
-            cc.startDate,
-            cc.endDate,
+            a.createDate as startDate,
+            date_add(a.createDate,interval cc.usePeriod day) as endDate,
             cc.couponType,
             cc.userId,
             cc.shopId,
@@ -445,8 +456,8 @@
         AND a.delFlag = 0
         AND a.userId = #{userId}
         AND a.status = 1
-        AND NOW() BETWEEN cc.startDate
-        AND cc.endDate
+        AND NOW() BETWEEN a.createDate
+        AND date_add(a.createDate,interval cc.usePeriod day)
         AND cc.status != 2
         ORDER BY a.createDate DESC
     </select>
@@ -475,4 +486,7 @@
         WHERE orderId = #{orderId}
         LIMIT 1
     </select>
+    <select id="getUserRegisterTime" resultType="java.util.Date">
+        select registerTime from user where userID = #{userId}
+    </select>
 </mapper>