plf 3 سال پیش
والد
کامیت
7ae54d60cb

+ 9 - 0
src/main/java/com/caimei365/commodity/mapper/CouponMapper.java

@@ -8,6 +8,7 @@ import com.caimei365.commodity.model.vo.ProductItemVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -91,4 +92,12 @@ public interface CouponMapper {
      * @param clubCouponId 用户关联优惠券id
      */
     void updateRedemptionCode(@Param("id") Integer id, @Param("clubCouponId") Integer clubCouponId);
+
+    /**
+     * 查询机构用户的注册时间
+     *
+     * @param userId
+     * @return
+     */
+    Date findUserRegisterTime(Integer userId);
 }

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

@@ -33,13 +33,13 @@ public class CouponVo implements Serializable {
     /**
      * 使用开始时间(有效期)
      */
-    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    @JsonFormat(pattern = "yyyy.MM.dd", timezone = "GMT+8")
     private Date startDate;
 
     /**
      * 使用结束时间(有效期)
      */
-    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    @JsonFormat(pattern = "yyyy.MM.dd", timezone = "GMT+8")
     private Date endDate;
 
     /**

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

@@ -147,6 +147,16 @@ public class CouponServiceImpl implements CouponService {
         if (coupon == null || date.compareTo(coupon.getStartDate()) < 0 || date.compareTo(coupon.getEndDate()) > 0) {
             return ResponseJson.error("兑换的优惠券已失效", null);
         }
+        if (coupon.getCouponType() == 2 && !redeemCouponsDto.getUserId().equals(coupon.getUserId())) {
+            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);
+            }
+        }
+        setShopName(coupon);
         CouponClubPo couponClub = new CouponClubPo();
         couponClub.setCouponId(redemptionCode.getCouponId());
         couponClub.setUserId(redeemCouponsDto.getUserId());
@@ -203,12 +213,7 @@ public class CouponServiceImpl implements CouponService {
         if (couponList != null) {
             list.addAll(couponList);
         }
-        list.sort(new Comparator<CouponVo>() {
-            @Override
-            public int compare(CouponVo o1, CouponVo o2) {
-                return o2.getCouponAmount().compareTo(o1.getCouponAmount());
-            }
-        });
+        list.sort((o1, o2) -> o2.getCouponAmount().compareTo(o1.getCouponAmount()));
         map.put("list", list);
         return ResponseJson.success(map);
     }

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

@@ -1,10 +1,7 @@
 package com.caimei365.commodity.service.impl;
 
 import com.caimei365.commodity.components.PriceUtilService;
-import com.caimei365.commodity.mapper.PageMapper;
-import com.caimei365.commodity.mapper.PriceMapper;
-import com.caimei365.commodity.mapper.ProductTypeMapper;
-import com.caimei365.commodity.mapper.ShopMapper;
+import com.caimei365.commodity.mapper.*;
 import com.caimei365.commodity.model.ResponseJson;
 import com.caimei365.commodity.model.po.ProductDetailInfoPo;
 import com.caimei365.commodity.model.po.ProductImagePo;
@@ -50,6 +47,8 @@ public class PageServiceImpl implements PageService {
     private ProductTypeMapper productTypeMapper;
     @Resource
     private PageService pageService;
+    @Resource
+    private CouponMapper couponMapper;
 
     /**
      * 获取分类列表
@@ -206,6 +205,15 @@ public class PageServiceImpl implements PageService {
         // 友情链接
         List<BaseLinkVo> friendLinks = pageMapper.getFriendLinks();
         map.put("friendLinks", friendLinks);
+        //是否显示领取优惠券入口
+        List<CouponVo> couponList = couponMapper.findCouponList(null);
+        if (couponList != null && couponList.size() > 0) {
+            //展示
+            map.put("couponEntry", 1);
+        } else {
+            //隐藏
+            map.put("couponEntry", 2);
+        }
         return ResponseJson.success(map);
     }
 

+ 6 - 1
src/main/resources/mapper/CouponMapper.xml

@@ -134,7 +134,8 @@
               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 (SELECT registerTime FROM USER WHERE userID = #{userId}) <![CDATA[ >= ]]> startDate)
+              OR ((SELECT registerTime FROM USER WHERE userID = #{userId}) <![CDATA[ >= ]]> startDate
+                    AND couponType = 4))
           </if>
         ORDER BY
           createDate DESC
@@ -219,4 +220,8 @@
         WHERE
           id = #{id}
     </update>
+
+    <select id="findUserRegisterTime" resultType="date">
+        SELECT registerTime FROM user WHERE userID = #{userId}
+    </select>
 </mapper>