Browse Source

Merge remote-tracking branch 'origin/developer' into developerD

hau 2 years ago
parent
commit
74c0a17485
1 changed files with 79 additions and 63 deletions
  1. 79 63
      src/main/resources/mapper/CouponMapper.xml

+ 79 - 63
src/main/resources/mapper/CouponMapper.xml

@@ -9,7 +9,7 @@
         cc.`couponAmount`,
         cc.`touchPrice`,
         if(cc.vipFlag = 1,cc.startDate,a.createDate) as startDate,
-        if(cc.vipFlag = 1,cc.endDate,date_add(a.createDate,interval cc.usePeriod day)) as endDate,
+        if(cc.vipFlag = 1 or cc.useTimeFlag = 1,cc.endDate,date_add(a.createDate,interval cc.usePeriod day)) as endDate,
         cc.`couponType`,
         cc.`userId`,
         cc.`shopId`,
@@ -29,8 +29,8 @@
         <if test="status == 1">
             AND a.status = 1
             AND if(cc.vipFlag = 1,
-                NOW() BETWEEN cc.startDate AND cc.endDate,
-                NOW() <![CDATA[ < ]]> date_add(a.createDate,interval cc.usePeriod DAY))
+            NOW() BETWEEN cc.startDate AND cc.endDate,
+            NOW() <![CDATA[ < ]]> IF(cc.usePeriod IS NULL,cc.endDate,DATE_ADD(a.createDate,INTERVAL cc.usePeriod DAY)))
         </if>
         <if test="status == 2">
             AND a.status = 2
@@ -38,8 +38,8 @@
         <if test="status == 3">
             AND a.status = 1
             AND if(cc.vipFlag = 1,
-                NOW() > cc.endDate,
-                NOW() <![CDATA[ > ]]> date_add(a.createDate,interval cc.usePeriod DAY))
+            NOW() > cc.endDate,
+            NOW() <![CDATA[ < ]]> IF(cc.usePeriod IS NULL,cc.endDate,DATE_ADD(a.createDate,INTERVAL cc.usePeriod DAY)))
         </if>
         AND cc.status != 2
         ORDER BY
@@ -137,8 +137,11 @@
             endDate,
         </if>
         <if test="userId != null and userId > 0">
-            if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]> endDate,#{registerTime},startDate) as startDate,
-            if(receiveFlag=1,endDate,date_add(if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]> endDate,#{registerTime},startDate),interval receivePeriod day)) as endDate,
+            if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]>
+            endDate,#{registerTime},startDate) as startDate,
+            if(useTimeFlag = 1 or receiveFlag = 1,endDate,
+            date_add(if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]> endDate,
+            #{registerTime},startDate),interval receivePeriod day)) as endDate,
         </if>
         moneyCouponPrice,
         moneyCouponFlag,
@@ -158,31 +161,35 @@
         <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))
+            AND NOW() <![CDATA[ < ]]> if(useTimeFlag = 1 or receiveFlag = 1,endDate,date_add(startDate,interval
+            receivePeriod day))
         </if>
         <if test="userId != null and userId > 0">
             AND id NOT IN(SELECT couponId FROM cm_coupon_club WHERE userId = #{userId})
             AND (couponType IN (0,1,3)
             OR (couponType = 2 AND userId = #{userId})
-            OR (#{registerTime} <![CDATA[ >= ]]> startDate and #{registerTime} <![CDATA[ < ]]> endDate AND couponType = 4))
+            OR (#{registerTime} <![CDATA[ >= ]]> startDate and #{registerTime} <![CDATA[ < ]]> endDate AND couponType =
+            4))
             and NOW() <![CDATA[ > ]]> startDate
-            and NOW() <![CDATA[ < ]]> if(receiveFlag = 1,endDate,
-                    date_add(if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]> endDate,#{registerTime},startDate),interval receivePeriod day)
-                )
+            and NOW() <![CDATA[ < ]]> if(useTimeFlag = 1 or receiveFlag = 1,endDate,
+            date_add(if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]>
+            endDate,#{registerTime},startDate),interval receivePeriod day)
+            )
         </if>
         ORDER BY
         createDate DESC
     </select>
 
     <select id="getCoupons" resultType="com.caimei365.commodity.model.vo.CouponVo">
-        SELECT `id` AS "couponId",
+        SELECT `id`                                                                                      AS "couponId",
                `couponAmount`,
                `touchPrice`,
-               if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]> endDate,#{registerTime},startDate) as startDate,
-               if(receiveFlag=1,endDate,date_add(if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]> endDate,#{registerTime},startDate),
-                   interval receivePeriod day)) as endDate,
-               date_add(NOW(),interval usePeriod day ) as usePeriod,
-               `endDate`,
+               if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]> endDate, #{registerTime}, startDate) as startDate,
+               if(useTimeFlag = 1 or receiveFlag = 1, endDate,
+                  date_add(if(#{registerTime} <![CDATA[ > ]]> startDate and #{registerTime} <![CDATA[ < ]]> endDate, #{registerTime}, startDate),
+                           interval receivePeriod day))                                                  as endDate,
+               if(usePeriod is null, endDate, date_add(NOW(), interval usePeriod day))                   as usePeriod,
+--                `endDate`,
                `couponType`,
                `userId`,
                `shopId`,
@@ -260,63 +267,72 @@
         from cm_svip_coupon
     </select>
     <select id="findMoneyCoupons" resultType="com.caimei365.commodity.model.vo.CouponVo">
-        SELECT
-        cc.`id` AS "couponId",
-        cc.`couponAmount`,
-        cc.`touchPrice`,
-        if(#{registerTime} <![CDATA[ > ]]> cc.startDate and #{registerTime} <![CDATA[ < ]]> cc.endDate,#{registerTime},cc.startDate) as startDate,
-        if(receiveFlag=1,cc.endDate,date_add(if(#{registerTime} <![CDATA[ > ]]> cc.startDate and #{registerTime} <![CDATA[ < ]]> cc.endDate,#{registerTime},cc.startDate),interval receivePeriod day)) as endDate,
-        cc.moneyCouponPrice,
-        cc.moneyCouponFlag,
-        cc.moneyCouponType,
-        cc.`couponType`,
-        cc.`userId`,
-        cc.`shopId`,
-        cc.`productType`,
-        cc.`categoryType`,
-        cc.couponPayWay,
-        s.name as shopName
-        FROM
-        cm_coupon cc
-        LEFT JOIN shop s ON cc.shopId = s.shopId
-        WHERE
-            cc.delFlag = 0 AND cc.vipFlag != 1
+        SELECT cc.`id`                              AS "couponId",
+               cc.`couponAmount`,
+               cc.`touchPrice`,
+               if(#{registerTime} <![CDATA[ > ]]> cc.startDate and #{registerTime} <![CDATA[ < ]]> cc.endDate, #{registerTime},
+                  cc.startDate)                     as startDate,
+               if(useTimeFlag = 1 or receiveFlag = 1, cc.endDate, date_add(
+                       if(#{registerTime} <![CDATA[ > ]]> cc.startDate and #{registerTime} <![CDATA[ < ]]> cc.endDate, #{registerTime},
+                          cc.startDate),
+                       interval receivePeriod day)) as endDate,
+               cc.moneyCouponPrice,
+               cc.moneyCouponFlag,
+               cc.moneyCouponType,
+               cc.`couponType`,
+               cc.`userId`,
+               cc.`shopId`,
+               cc.`productType`,
+               cc.`categoryType`,
+               cc.couponPayWay,
+               s.name                               as shopName
+        FROM cm_coupon cc
+                 LEFT JOIN shop s ON cc.shopId = s.shopId
+        WHERE cc.delFlag = 0
+          AND cc.vipFlag != 1
         AND cc.id != 49
         AND cc.status != 2
         AND cc.couponsMode = 0
         AND cc.moneyCouponFlag = 1
         AND (cc.couponType IN (0,1,3)
         OR (cc.couponType = 2 AND cc.userId = #{userId})
-        OR (#{registerTime} <![CDATA[ >= ]]> cc.startDate and #{registerTime} <![CDATA[ < ]]> cc.endDate AND cc.couponType = 4))
-        and NOW() <![CDATA[ > ]]> cc.startDate
-        and NOW() <![CDATA[ < ]]> if(receiveFlag = 1,cc.endDate,
-        date_add(if(#{registerTime} <![CDATA[ > ]]> cc.startDate and #{registerTime} <![CDATA[ < ]]> cc.endDate,#{registerTime},cc.startDate),interval receivePeriod day)
-        )
+           OR (#{registerTime} <![CDATA[ >= ]]> cc.startDate
+          and #{registerTime} <![CDATA[ < ]]> cc.endDate
+          AND cc.couponType = 4))
+          and NOW() <![CDATA[ > ]]> cc.startDate
+          and NOW() <![CDATA[ < ]]> if(receiveFlag = 1
+            , cc.endDate
+            , date_add(if(#{registerTime} <![CDATA[ > ]]> cc.startDate
+          and #{registerTime} <![CDATA[ < ]]> cc.endDate
+            , #{registerTime}
+            , cc.startDate)
+            , interval receivePeriod day)
+            )
         ORDER BY
             cc.createDate DESC
     </select>
     <select id="findCouponDetail" resultType="com.caimei365.commodity.model.vo.CouponVo">
-        SELECT
-            cc.`id` AS "couponId",
-            cc.`couponAmount`,
-            cc.`touchPrice`,
-            cc.startDate,
-            cc.endDate,
-            cc.`couponType`,
-            cc.`userId`,
-            cc.`shopId`,
-            cc.`productType`,
-            cc.`categoryType`,
-            cc.moneyCouponPrice,
-            cc.moneyCouponFlag,
-            s.name as shopName,
-            cc.couponPayWay
-        FROM
-            cm_coupon cc
-        LEFT JOIN shop s ON cc.shopId = s.shopId
+        SELECT cc.`id` AS "couponId",
+               cc.`couponAmount`,
+               cc.`touchPrice`,
+               cc.startDate,
+               cc.endDate,
+               cc.`couponType`,
+               cc.`userId`,
+               cc.`shopId`,
+               cc.`productType`,
+               cc.`categoryType`,
+               cc.moneyCouponPrice,
+               cc.moneyCouponFlag,
+               s.name  as shopName,
+               cc.couponPayWay
+        FROM cm_coupon cc
+                 LEFT JOIN shop s ON cc.shopId = s.shopId
         where id = #{couponId}
     </select>
     <select id="findUserPermission" resultType="java.lang.Integer">
-        select userIdentity from user where userID = #{userId}
+        select userIdentity
+        from user
+        where userID = #{userId}
     </select>
 </mapper>