Browse Source

promotion:增加 coupon 的 code review

YunaiV 1 year ago
parent
commit
9ee0aebd3f

+ 0 - 9
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/coupon/CouponController.java

@@ -37,15 +37,6 @@ public class CouponController {
     @Resource
     private MemberUserApi memberUserApi;
 
-//    @GetMapping("/get")
-//    @Operation(summary = "获得优惠劵")
-//    @Parameter(name = "id", description = "编号", required = true, example = "1024")
-//    @PreAuthorize("@ss.hasPermission('promotion:coupon:query')")
-//    public CommonResult<CouponRespVO> getCoupon(@RequestParam("id") Long id) {
-//        CouponDO coupon = couponService.getCoupon(id);
-//        return success(CouponConvert.INSTANCE.convert(coupon));
-//    }
-
     @DeleteMapping("/delete")
     @Operation(summary = "回收优惠劵")
     @Parameter(name = "id", description = "编号", required = true)

+ 7 - 5
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java

@@ -40,12 +40,13 @@ public class AppCouponController {
     @PostMapping("/take")
     @Operation(summary = "领取优惠劵")
     @Parameter(name = "templateId", description = "优惠券模板编号", required = true, example = "1024")
+    @PreAuthenticated
     public CommonResult<Boolean> takeCoupon(@Valid @RequestBody AppCouponTakeReqVO reqVO) {
-        // 领取
+        // 1. 领取优惠劵
         Long userId = getLoginUserId();
         couponService.takeCoupon(reqVO.getTemplateId(), CollUtil.newHashSet(userId), CouponTakeTypeEnum.USER);
 
-        // 检查是否可以继续领取
+        // 2. 检查是否可以继续领取
         CouponTemplateDO couponTemplate = couponTemplateService.getCouponTemplate(reqVO.getTemplateId());
         boolean canTakeAgain = true;
         if (couponTemplate.getTakeLimitCount() != null && couponTemplate.getTakeLimitCount() > 0) {
@@ -58,15 +59,16 @@ public class AppCouponController {
     }
 
     @GetMapping("/match-list")
-    @Operation(summary = "获得匹配指定商品的优惠劵列表")
+    @Operation(summary = "获得匹配指定商品的优惠劵列表", description = "用于下单页,展示优惠劵列表")
     public CommonResult<List<AppCouponMatchRespVO>> getMatchCouponList(AppCouponMatchReqVO matchReqVO) {
         // todo: 优化:优惠金额倒序
         return success(CouponConvert.INSTANCE.convertList(couponService.getMatchCouponList(getLoginUserId(), matchReqVO)));
     }
 
     @GetMapping("/page")
-    @Operation(summary = "优惠劵列表", description = "我的优惠劵")
-    public CommonResult<PageResult<AppCouponRespVO>> takeCoupon(AppCouponPageReqVO pageReqVO) {
+    @Operation(summary = "我的优惠劵列表")
+    @PreAuthenticated
+    public CommonResult<PageResult<AppCouponRespVO>> getCouponPage(AppCouponPageReqVO pageReqVO) {
         PageResult<CouponDO> pageResult = couponService.getCouponPage(
                 CouponConvert.INSTANCE.convert(pageReqVO, Collections.singleton(getLoginUserId())));
         return success(CouponConvert.INSTANCE.convertAppPage(pageResult));

+ 49 - 0
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java

@@ -15,13 +15,17 @@ import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum;
 import cn.iocoder.yudao.module.promotion.service.coupon.CouponService;
 import cn.iocoder.yudao.module.promotion.service.coupon.CouponTemplateService;
 import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Parameters;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.time.LocalDateTime;
 import java.util.*;
 
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@@ -42,6 +46,51 @@ public class AppCouponTemplateController {
     @Resource
     private ProductSpuApi productSpuApi;
 
+    // TODO 疯狂:这里应该还有个 list 接口哈;获得优惠劵模版列表,用于首页、商品页的优惠劵
+    @GetMapping("/list")
+    @Operation(summary = "获得优惠劵模版列表")
+    @Parameters({
+            @Parameter(name = "spuId", description = "商品 SPU 编号"), // 目前主要给商品详情使用
+            @Parameter(name = "useType", description = "使用类型"),
+            @Parameter(name = "count", description = "数量", required = true)
+    })
+    public CommonResult<List<AppCouponTemplateRespVO>> getCouponTemplateList(
+            @RequestParam(value = "spuId", required = false) Long spuId,
+            @RequestParam(value = "useType", required = false) Integer useType,
+            @RequestParam(value = "count", required = false, defaultValue = "10") Integer count) {
+        List<AppCouponTemplateRespVO> list = new ArrayList<>();
+        Random random = new Random();
+        for (int i = 0; i < 10; i++) {
+            AppCouponTemplateRespVO vo = new AppCouponTemplateRespVO();
+            vo.setId(i + 1L);
+            vo.setName("优惠劵" + (i + 1));
+            vo.setTakeLimitCount(random.nextInt(10) + 1);
+            vo.setUsePrice(random.nextInt(100) * 100);
+            vo.setValidityType(random.nextInt(2) + 1);
+            if (vo.getValidityType() == 1) {
+                vo.setValidStartTime(LocalDateTime.now().plusDays(random.nextInt(10)));
+                vo.setValidEndTime(LocalDateTime.now().plusDays(random.nextInt(20) + 10));
+            } else {
+                vo.setFixedStartTerm(random.nextInt(10));
+                vo.setFixedEndTerm(random.nextInt(10) + vo.getFixedStartTerm() + 1);
+            }
+            vo.setDiscountType(random.nextInt(2) + 1);
+            if (vo.getDiscountType() == 1) {
+                vo.setDiscountPercent(null);
+                vo.setDiscountPrice(random.nextInt(50) * 100);
+                vo.setDiscountLimitPrice(null);
+            } else {
+                vo.setDiscountPercent(random.nextInt(90) + 10);
+                vo.setDiscountPrice(null);
+                vo.setDiscountLimitPrice(random.nextInt(200) * 100);
+            }
+            // TODO @疯狂:是否已领取,要不在 TemplateService 搞个 static 方法,让它基于 countMap 这种去计算,这样好点?
+            vo.setTakeStatus(random.nextBoolean());
+            list.add(vo);
+        }
+        return success(list);
+    }
+
     @GetMapping("/page")
     @Operation(summary = "获得优惠劵模版分页")
     public CommonResult<PageResult<AppCouponTemplateRespVO>> getCouponTemplatePage(AppCouponTemplatePageReqVO pageReqVO) {

+ 0 - 8
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplateRespVO.java

@@ -23,14 +23,6 @@ public class AppCouponTemplateRespVO {
     // 单位:分;0 - 不限制
     private Integer usePrice;
 
-    // TODO 芋艿:这两要改的
-//    @Schema(description = "商品范围", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
-//    @InEnum(PromotionProductScopeEnum.class)
-//    private Integer productScope;
-//
-//    @Schema(description = "商品范围编号的数组", example = "1,3")
-//    private List<Long> productScopeValues;
-
     @Schema(description = "生效日期类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
     private Integer validityType;
 

+ 2 - 1
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/job/CouponExpireJob.java → yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/job/coupon/CouponExpireJob.java

@@ -1,4 +1,4 @@
-package cn.iocoder.yudao.module.promotion.job;
+package cn.iocoder.yudao.module.promotion.job.coupon;
 
 import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 
+// TODO 芋艿:配置一个 Job
 /**
  * 优惠券过期 Job
  *

+ 4 - 0
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/job/package-info.java

@@ -0,0 +1,4 @@
+/**
+ * TODO 占位,无具体含义
+ */
+package cn.iocoder.yudao.module.promotion.job;

+ 1 - 0
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java

@@ -165,4 +165,5 @@ public interface CouponService {
      * @return 过期数量
      */
     int expireCoupon();
+
 }

+ 9 - 1
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java

@@ -40,6 +40,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
 import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
 import static java.util.Arrays.asList;
 
+// TODO @疯狂:注册时,赠送用户优惠劵;为了解耦,可以考虑注册时发个 MQ 消息;然后营销这里监听后消费;
 /**
  * 优惠劵 Service 实现类
  *
@@ -192,7 +193,8 @@ public class CouponServiceImpl implements CouponService {
 
     @Override
     public List<CouponDO> getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO) {
-        return couponMapper.selectListByUserIdAndStatusAndUsePriceLeAndProductScope(userId, CouponStatusEnum.UNUSED.getStatus(),
+        return couponMapper.selectListByUserIdAndStatusAndUsePriceLeAndProductScope(userId,
+                CouponStatusEnum.UNUSED.getStatus(),
                 matchReqVO.getPrice(), matchReqVO.getSpuIds(), matchReqVO.getCategoryIds());
     }
 
@@ -220,6 +222,12 @@ public class CouponServiceImpl implements CouponService {
         return count;
     }
 
+    /**
+     * 过期单个优惠劵
+     *
+     * @param coupon 优惠劵
+     * @return 是否过期成功
+     */
     private boolean expireCoupon(CouponDO coupon) {
         // 更新记录状态
         int updateRows = couponMapper.updateByIdAndStatus(coupon.getId(), CouponStatusEnum.UNUSED.getStatus(),

+ 1 - 0
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java

@@ -29,6 +29,7 @@ public class CouponTemplateServiceImpl implements CouponTemplateService {
     @Resource
     private CouponTemplateMapper couponTemplateMapper;
 
+    // TODO @疯狂:新增/修改时,需要校验对应的商品、分类是否存在
     @Override
     public Long createCouponTemplate(CouponTemplateCreateReqVO createReqVO) {
         // 插入

+ 1 - 1
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/cart/CartServiceImpl.java

@@ -26,7 +26,7 @@ import static java.util.Collections.emptyList;
 /**
  * 购物车 Service 实现类
  *
- * // TODO 芋艿:未来优化:购物车的价格计算,支持营销信息;目前不支持的原因,前端界面需要前端 pr 支持下;
+ * // TODO 芋艿:未来优化:购物车的价格计算,支持营销信息;目前不支持的原因,前端界面需要前端 pr 支持下;例如说:会员价格;
  *
  * @author 芋道源码
  */