Browse Source

Merge remote-tracking branch 'origin/developerA' into developerA

chao 3 years ago
parent
commit
92b28dcbd9

+ 3 - 4
src/main/java/com/caimei365/commodity/mapper/CouponMapper.java

@@ -51,15 +51,16 @@ public interface CouponMapper {
      * @param userId
      * @return
      */
-    List<CouponVo> findCouponList(Integer userId);
+    List<CouponVo> findCouponList(@Param("userId") Integer userId, @Param("registerTime") Date registerTime);
 
     /**
      * 查询优惠券信息
      *
      * @param couponId
+     * @param registerTime
      * @return
      */
-    CouponVo getCoupons(Integer couponId);
+    CouponVo getCoupons(@Param("couponId") Integer couponId, @Param("registerTime") Date registerTime);
 
     /**
      * 查询兑换码是否有效
@@ -108,6 +109,4 @@ public interface CouponMapper {
      * @return
      */
     List<Integer> findVipCoupon();
-
-
 }

+ 5 - 0
src/main/java/com/caimei365/commodity/model/vo/CouponVo.java

@@ -81,4 +81,9 @@ public class CouponVo implements Serializable {
      * 领取状态: 0未领取 1已领取 (前端使用)
      */
     private Integer couponBtnType = 0;
+
+    /**
+     * 使用截止时间
+     */
+    private Date usePeriod;
 }

+ 11 - 4
src/main/java/com/caimei365/commodity/service/impl/CouponServiceImpl.java

@@ -111,7 +111,8 @@ public class CouponServiceImpl implements CouponService {
     @Override
     public ResponseJson<PageInfo<CouponVo>> collarCouponsList(Integer userId, int pageNum, int pageSize) {
         PageHelper.startPage(pageNum, pageSize);
-        List<CouponVo> couponList = couponMapper.findCouponList(userId);
+        Date registerTime = couponMapper.findUserRegisterTime(userId);
+        List<CouponVo> couponList = couponMapper.findCouponList(userId, registerTime);
         //剔除超级会员优惠券
         List<Integer> vipCoupon = couponMapper.findVipCoupon();
         if (couponList != null && couponList.size() > 0) {
@@ -155,8 +156,10 @@ public class CouponServiceImpl implements CouponService {
         if (redemptionCode.getStatus() == 2) {
             return ResponseJson.error("兑换码已使用,请更换兑换码进行兑换", null);
         }
-        CouponVo coupon = couponMapper.getCoupons(redemptionCode.getCouponId());
+        Date registerTime = couponMapper.findUserRegisterTime(redeemCouponsDto.getUserId());
+        CouponVo coupon = couponMapper.getCoupons(redemptionCode.getCouponId(), registerTime);
         Date date = new Date();
+        // 判断是否在领取期限内
         if (coupon == null || date.compareTo(coupon.getStartDate()) < 0 || date.compareTo(coupon.getEndDate()) > 0) {
             return ResponseJson.error("兑换的优惠券已失效", null);
         }
@@ -164,7 +167,6 @@ public class CouponServiceImpl implements CouponService {
             return ResponseJson.error("该优惠券属于其他用户,您不能兑换", null);
         }
         if (coupon.getCouponType() == 4) {
-            Date registerTime = couponMapper.findUserRegisterTime(redeemCouponsDto.getUserId());
             if (registerTime == null || registerTime.compareTo(coupon.getStartDate()) < 0) {
                 return ResponseJson.error("该优惠券只供新用户使用,您不能兑换", null);
             }
@@ -179,6 +181,9 @@ public class CouponServiceImpl implements CouponService {
         couponClub.setDelFlag("0");
         couponMapper.insertCouponClub(couponClub);
         couponMapper.updateRedemptionCode(redemptionCode.getId(), couponClub.getId());
+        // 设置使用有效期
+        coupon.setStartDate(new Date());
+        coupon.setEndDate(coupon.getUsePeriod());
         return ResponseJson.success(coupon);
     }
 
@@ -205,8 +210,10 @@ public class CouponServiceImpl implements CouponService {
             return ResponseJson.error("商品数据异常", null);
         }
         List<Integer> vipCoupon = couponMapper.findVipCoupon();
+        // 注册时间
+        Date registerTime = couponMapper.findUserRegisterTime(userId);
         //未领取
-        List<CouponVo> notCouponList = couponMapper.findCouponList(userId);
+        List<CouponVo> notCouponList = couponMapper.findCouponList(userId, registerTime);
         filterCoupon(source, product, notCouponList);
         //超级会员优惠券移除
         if (notCouponList != null && notCouponList.size() > 0) {

+ 1 - 1
src/main/java/com/caimei365/commodity/service/impl/PageServiceImpl.java

@@ -231,7 +231,7 @@ public class PageServiceImpl implements PageService {
         List<BaseLinkVo> friendLinks = pageMapper.getFriendLinks();
         map.put("friendLinks", friendLinks);
         //是否显示领取优惠券入口
-        List<CouponVo> couponList = couponMapper.findCouponList(null);
+        List<CouponVo> couponList = couponMapper.findCouponList(null, null);
         if (couponList != null && couponList.size() > 0) {
             //展示
             map.put("couponEntry", 1);

+ 23 - 11
src/main/resources/mapper/CouponMapper.xml

@@ -8,8 +8,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`,
@@ -24,17 +24,14 @@
         AND a.userId = #{userId}
         <if test="status == 1">
             AND a.status = 1
-            AND NOW() BETWEEN cc.startDate
-            AND cc.endDate
+            AND NOW() <![CDATA[ < ]]> date_add(a.createDate,interval cc.usePeriod DAY)
         </if>
         <if test="status == 2">
             AND a.status = 2
-            AND NOW() BETWEEN cc.startDate
-            AND cc.endDate
         </if>
         <if test="status == 3">
-            AND NOW() NOT BETWEEN cc.startDate
-            AND cc.endDate
+            AND a.status = 1
+            AND NOW() <![CDATA[ > ]]> date_add(a.createDate,interval cc.usePeriod DAY)
         </if>
         AND cc.status != 2
         ORDER BY
@@ -108,6 +105,14 @@
         `id` AS "couponId",
         `couponAmount`,
         `touchPrice`,
+        <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>
         `startDate`,
         `endDate`,
         `couponType`,
@@ -119,12 +124,12 @@
         cm_coupon
         WHERE
         delFlag = 0 AND vipFlag != 1
-        AND NOW() BETWEEN startDate
-        AND endDate
         AND status != 2
         AND couponsMode = 0
         <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})
@@ -132,6 +137,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
@@ -141,7 +150,10 @@
         SELECT `id` AS "couponId",
                `couponAmount`,
                `touchPrice`,
-               `startDate`,
+               if(#{registerTime} <![CDATA[ > ]]> startDate,#{registerTime},startDate),
+               if(receiveFlag=1,endDate,date_add(if(#{registerTime} <![CDATA[ > ]]> startDate,#{registerTime},startDate),
+                   interval receivePeriod day)) as endDate,
+               date_add(NOW(),interval usePeriod day ) as usePeriod,
                `endDate`,
                `couponType`,
                `userId`,