Browse Source

修改领取优惠券方法

qmj 2 weeks ago
parent
commit
e591a921b0

+ 5 - 4
ruoyi-admin/src/main/java/com/ruoyi/app/user/UserPromotionCouponController.java

@@ -1,7 +1,6 @@
 package com.ruoyi.app.user;
 
 import java.util.List;
-import java.util.Map;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import com.ruoyi.common.annotation.Anonymous;
@@ -9,6 +8,8 @@ import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.system.domain.PromotionUserCoupon;
 import com.ruoyi.system.domain.dto.ReceiveCouponDto;
+import com.ruoyi.system.domain.vo.StoreCouponVO;
+import com.ruoyi.system.domain.vo.MyCouponVO;
 import com.ruoyi.system.service.IPromotionUserCouponService;
 import com.ruoyi.system.utils.Auth;
 import com.ruoyi.system.utils.JwtUtil;
@@ -47,7 +48,7 @@ public class UserPromotionCouponController extends BaseController {
         if (userId == null) {
             return AjaxResult.error("请先登录");
         }
-        List<Map<String, Object>> list = userCouponService.selectStoreCouponsForUser(Long.valueOf(userId), storeId);
+        List<StoreCouponVO> list = userCouponService.selectStoreCouponsForUser(Long.valueOf(userId), storeId);
         return AjaxResult.success(list);
     }
 
@@ -57,7 +58,7 @@ public class UserPromotionCouponController extends BaseController {
      * 规则:每用户每批次限领1张,乐观锁扣库存,领取后计算过期时间(领取日期+validDays天23:59:59)
      *
      * @param token  用户登录token
-     * @param params batchId(必填), storeId(必填)
+     * @param dto batchId(必填), storeId(必填)
      * @return 领取成功的券实例
      */
     @Anonymous
@@ -96,7 +97,7 @@ public class UserPromotionCouponController extends BaseController {
         if (userId == null) {
             return AjaxResult.error("请先登录");
         }
-        List<Map<String, Object>> list = userCouponService.selectMyCoupons(Long.valueOf(userId), status, storeId);
+        List<MyCouponVO> list = userCouponService.selectMyCoupons(Long.valueOf(userId), status, storeId);
         return AjaxResult.success(list);
     }
 }

+ 48 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/MyCouponVO.java

@@ -0,0 +1,48 @@
+package com.ruoyi.system.domain.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 我的优惠券列表项
+ */
+@Data
+public class MyCouponVO {
+
+    /** 用户券ID */
+    private Long id;
+
+    /** 券批次ID */
+    private Long batchId;
+
+    /** 门店ID */
+    private Long storeId;
+
+    /** 券状态 0=未使用 1=已使用 2=已过期 */
+    private Integer status;
+
+    /** 过期时间 */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date expireTime;
+
+    /** 券名称 */
+    private String name;
+
+    /** 券类型 */
+    private Integer couponType;
+
+    /** 使用门槛金额 */
+    private BigDecimal threshold;
+
+    /** 优惠金额 */
+    private BigDecimal amount;
+
+    /** 折扣率 */
+    private BigDecimal discountRate;
+
+    /** 是否互斥 0=同享 1=互斥 */
+    private Integer isMutex;
+}

+ 42 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/StoreCouponVO.java

@@ -0,0 +1,42 @@
+package com.ruoyi.system.domain.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * 门店可领优惠券列表项
+ */
+@Data
+public class StoreCouponVO {
+
+    /** 券批次ID */
+    private Long id;
+
+    /** 券名称 */
+    private String name;
+
+    /** 券类型 */
+    private Integer couponType;
+
+    /** 总发行量 */
+    private Integer totalCount;
+
+    /** 剩余数量 */
+    private Integer remainCount;
+
+    /** 使用门槛金额 */
+    private BigDecimal threshold;
+
+    /** 优惠金额 */
+    private BigDecimal amount;
+
+    /** 折扣率 */
+    private BigDecimal discountRate;
+
+    /** 是否互斥 0=同享 1=互斥 */
+    private Integer isMutex;
+
+    /** 当前用户是否已领取 */
+    private Boolean hasReceived;
+}

+ 4 - 3
ruoyi-system/src/main/java/com/ruoyi/system/service/IPromotionUserCouponService.java

@@ -1,9 +1,10 @@
 package com.ruoyi.system.service;
 
 import java.util.List;
-import java.util.Map;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.system.domain.PromotionUserCoupon;
+import com.ruoyi.system.domain.vo.StoreCouponVO;
+import com.ruoyi.system.domain.vo.MyCouponVO;
 
 /**
  * 用户优惠券Service接口
@@ -18,12 +19,12 @@ public interface IPromotionUserCouponService extends IService<PromotionUserCoupo
     /**
      * 查询门店可领优惠券列表
      */
-    public List<Map<String, Object>> selectStoreCouponsForUser(Long userId, Long storeId);
+    public List<StoreCouponVO> selectStoreCouponsForUser(Long userId, Long storeId);
 
     /**
      * 查询用户优惠券列表
      */
-    public List<Map<String, Object>> selectMyCoupons(Long userId, Integer status, Long storeId);
+    public List<MyCouponVO> selectMyCoupons(Long userId, Integer status, Long storeId);
 
     /**
      * 标记优惠券为已使用

+ 31 - 29
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PromotionUserCouponServiceImpl.java

@@ -15,6 +15,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.system.domain.PromotionCouponBatch;
 import com.ruoyi.system.domain.PromotionCouponRule;
 import com.ruoyi.system.domain.PromotionUserCoupon;
+import com.ruoyi.system.domain.vo.StoreCouponVO;
+import com.ruoyi.system.domain.vo.MyCouponVO;
 import com.ruoyi.system.mapper.PromotionCouponBatchMapper;
 import com.ruoyi.system.mapper.PromotionCouponRuleMapper;
 import com.ruoyi.system.mapper.PromotionUserCouponMapper;
@@ -87,7 +89,7 @@ public class PromotionUserCouponServiceImpl extends ServiceImpl<PromotionUserCou
     }
 
     @Override
-    public List<Map<String, Object>> selectStoreCouponsForUser(Long userId, Long storeId) {
+    public List<StoreCouponVO> selectStoreCouponsForUser(Long userId, Long storeId) {
         // 查询门店进行中的券批次
         LambdaQueryWrapper<PromotionCouponBatch> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(PromotionCouponBatch::getStoreId, storeId)
@@ -96,24 +98,24 @@ public class PromotionUserCouponServiceImpl extends ServiceImpl<PromotionUserCou
                 .ge(PromotionCouponBatch::getEndTime, new Date());
         List<PromotionCouponBatch> batches = batchMapper.selectList(wrapper);
 
-        List<Map<String, Object>> result = new ArrayList<>();
+        List<StoreCouponVO> result = new ArrayList<>();
         for (PromotionCouponBatch batch : batches) {
-            Map<String, Object> item = new HashMap<>();
-            item.put("id", batch.getId());
-            item.put("name", batch.getName());
-            item.put("couponType", batch.getCouponType());
-            item.put("totalCount", batch.getTotalCount());
-            item.put("remainCount", batch.getRemainCount());
+            StoreCouponVO vo = new StoreCouponVO();
+            vo.setId(batch.getId());
+            vo.setName(batch.getName());
+            vo.setCouponType(batch.getCouponType());
+            vo.setTotalCount(batch.getTotalCount());
+            vo.setRemainCount(batch.getRemainCount());
 
             // 查询券规则
             PromotionCouponRule rule = ruleMapper.selectOne(
                 new LambdaQueryWrapper<PromotionCouponRule>()
                     .eq(PromotionCouponRule::getBatchId, batch.getId()));
             if (rule != null) {
-                item.put("threshold", rule.getThreshold());
-                item.put("amount", rule.getAmount());
-                item.put("discountRate", rule.getDiscountRate());
-                item.put("isMutex", rule.getIsMutex());
+                vo.setThreshold(rule.getThreshold());
+                vo.setAmount(rule.getAmount());
+                vo.setDiscountRate(rule.getDiscountRate());
+                vo.setIsMutex(rule.getIsMutex());
             }
 
             // 检查用户是否已领取
@@ -121,15 +123,15 @@ public class PromotionUserCouponServiceImpl extends ServiceImpl<PromotionUserCou
                 new LambdaQueryWrapper<PromotionUserCoupon>()
                     .eq(PromotionUserCoupon::getUserId, userId)
                     .eq(PromotionUserCoupon::getBatchId, batch.getId()));
-            item.put("hasReceived", received > 0);
+            vo.setHasReceived(received > 0);
 
-            result.add(item);
+            result.add(vo);
         }
         return result;
     }
 
     @Override
-    public List<Map<String, Object>> selectMyCoupons(Long userId, Integer status, Long storeId) {
+    public List<MyCouponVO> selectMyCoupons(Long userId, Integer status, Long storeId) {
         // 先把已过期的券标记为过期(expire_time < NOW() 且 status=0)
         userCouponMapper.update(null,
             new LambdaUpdateWrapper<PromotionUserCoupon>()
@@ -151,20 +153,20 @@ public class PromotionUserCouponServiceImpl extends ServiceImpl<PromotionUserCou
         wrapper.orderByDesc(PromotionUserCoupon::getReceiveTime);
         List<PromotionUserCoupon> coupons = userCouponMapper.selectList(wrapper);
 
-        List<Map<String, Object>> result = new ArrayList<>();
+        List<MyCouponVO> result = new ArrayList<>();
         for (PromotionUserCoupon coupon : coupons) {
-            Map<String, Object> item = new HashMap<>();
-            item.put("id", coupon.getId());
-            item.put("batchId", coupon.getBatchId());
-            item.put("storeId", coupon.getStoreId());
-            item.put("status", coupon.getStatus());
-            item.put("expireTime", coupon.getExpireTime());
+            MyCouponVO vo = new MyCouponVO();
+            vo.setId(coupon.getId());
+            vo.setBatchId(coupon.getBatchId());
+            vo.setStoreId(coupon.getStoreId());
+            vo.setStatus(coupon.getStatus());
+            vo.setExpireTime(coupon.getExpireTime());
 
             // 查询批次信息
             PromotionCouponBatch batch = batchMapper.selectById(coupon.getBatchId());
             if (batch != null) {
-                item.put("name", batch.getName());
-                item.put("couponType", batch.getCouponType());
+                vo.setName(batch.getName());
+                vo.setCouponType(batch.getCouponType());
             }
 
             // 查询规则信息
@@ -172,13 +174,13 @@ public class PromotionUserCouponServiceImpl extends ServiceImpl<PromotionUserCou
                 new LambdaQueryWrapper<PromotionCouponRule>()
                     .eq(PromotionCouponRule::getBatchId, coupon.getBatchId()));
             if (rule != null) {
-                item.put("threshold", rule.getThreshold());
-                item.put("amount", rule.getAmount());
-                item.put("discountRate", rule.getDiscountRate());
-                item.put("isMutex", rule.getIsMutex());
+                vo.setThreshold(rule.getThreshold());
+                vo.setAmount(rule.getAmount());
+                vo.setDiscountRate(rule.getDiscountRate());
+                vo.setIsMutex(rule.getIsMutex());
             }
 
-            result.add(item);
+            result.add(vo);
         }
         return result;
     }