Commit 9ee0aebd3fe4216e5ee0e236512edc4734a625f7
1 parent
666ba351
promotion:增加 coupon 的 code review
Showing
10 changed files
with
74 additions
and
25 deletions
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 { |
| 37 | 37 | @Resource |
| 38 | 38 | private MemberUserApi memberUserApi; |
| 39 | 39 | |
| 40 | -// @GetMapping("/get") | |
| 41 | -// @Operation(summary = "获得优惠劵") | |
| 42 | -// @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 43 | -// @PreAuthorize("@ss.hasPermission('promotion:coupon:query')") | |
| 44 | -// public CommonResult<CouponRespVO> getCoupon(@RequestParam("id") Long id) { | |
| 45 | -// CouponDO coupon = couponService.getCoupon(id); | |
| 46 | -// return success(CouponConvert.INSTANCE.convert(coupon)); | |
| 47 | -// } | |
| 48 | - | |
| 49 | 40 | @DeleteMapping("/delete") |
| 50 | 41 | @Operation(summary = "回收优惠劵") |
| 51 | 42 | @Parameter(name = "id", description = "编号", required = true) | ... | ... |
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 { |
| 40 | 40 | @PostMapping("/take") |
| 41 | 41 | @Operation(summary = "领取优惠劵") |
| 42 | 42 | @Parameter(name = "templateId", description = "优惠券模板编号", required = true, example = "1024") |
| 43 | + @PreAuthenticated | |
| 43 | 44 | public CommonResult<Boolean> takeCoupon(@Valid @RequestBody AppCouponTakeReqVO reqVO) { |
| 44 | - // 领取 | |
| 45 | + // 1. 领取优惠劵 | |
| 45 | 46 | Long userId = getLoginUserId(); |
| 46 | 47 | couponService.takeCoupon(reqVO.getTemplateId(), CollUtil.newHashSet(userId), CouponTakeTypeEnum.USER); |
| 47 | 48 | |
| 48 | - // 检查是否可以继续领取 | |
| 49 | + // 2. 检查是否可以继续领取 | |
| 49 | 50 | CouponTemplateDO couponTemplate = couponTemplateService.getCouponTemplate(reqVO.getTemplateId()); |
| 50 | 51 | boolean canTakeAgain = true; |
| 51 | 52 | if (couponTemplate.getTakeLimitCount() != null && couponTemplate.getTakeLimitCount() > 0) { |
| ... | ... | @@ -58,15 +59,16 @@ public class AppCouponController { |
| 58 | 59 | } |
| 59 | 60 | |
| 60 | 61 | @GetMapping("/match-list") |
| 61 | - @Operation(summary = "获得匹配指定商品的优惠劵列表") | |
| 62 | + @Operation(summary = "获得匹配指定商品的优惠劵列表", description = "用于下单页,展示优惠劵列表") | |
| 62 | 63 | public CommonResult<List<AppCouponMatchRespVO>> getMatchCouponList(AppCouponMatchReqVO matchReqVO) { |
| 63 | 64 | // todo: 优化:优惠金额倒序 |
| 64 | 65 | return success(CouponConvert.INSTANCE.convertList(couponService.getMatchCouponList(getLoginUserId(), matchReqVO))); |
| 65 | 66 | } |
| 66 | 67 | |
| 67 | 68 | @GetMapping("/page") |
| 68 | - @Operation(summary = "优惠劵列表", description = "我的优惠劵") | |
| 69 | - public CommonResult<PageResult<AppCouponRespVO>> takeCoupon(AppCouponPageReqVO pageReqVO) { | |
| 69 | + @Operation(summary = "我的优惠劵列表") | |
| 70 | + @PreAuthenticated | |
| 71 | + public CommonResult<PageResult<AppCouponRespVO>> getCouponPage(AppCouponPageReqVO pageReqVO) { | |
| 70 | 72 | PageResult<CouponDO> pageResult = couponService.getCouponPage( |
| 71 | 73 | CouponConvert.INSTANCE.convert(pageReqVO, Collections.singleton(getLoginUserId()))); |
| 72 | 74 | return success(CouponConvert.INSTANCE.convertAppPage(pageResult)); | ... | ... |
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; |
| 15 | 15 | import cn.iocoder.yudao.module.promotion.service.coupon.CouponService; |
| 16 | 16 | import cn.iocoder.yudao.module.promotion.service.coupon.CouponTemplateService; |
| 17 | 17 | import io.swagger.v3.oas.annotations.Operation; |
| 18 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 19 | +import io.swagger.v3.oas.annotations.Parameters; | |
| 18 | 20 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 19 | 21 | import org.springframework.validation.annotation.Validated; |
| 20 | 22 | import org.springframework.web.bind.annotation.GetMapping; |
| 21 | 23 | import org.springframework.web.bind.annotation.RequestMapping; |
| 24 | +import org.springframework.web.bind.annotation.RequestParam; | |
| 22 | 25 | import org.springframework.web.bind.annotation.RestController; |
| 23 | 26 | |
| 24 | 27 | import javax.annotation.Resource; |
| 28 | +import java.time.LocalDateTime; | |
| 25 | 29 | import java.util.*; |
| 26 | 30 | |
| 27 | 31 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| ... | ... | @@ -42,6 +46,51 @@ public class AppCouponTemplateController { |
| 42 | 46 | @Resource |
| 43 | 47 | private ProductSpuApi productSpuApi; |
| 44 | 48 | |
| 49 | + // TODO 疯狂:这里应该还有个 list 接口哈;获得优惠劵模版列表,用于首页、商品页的优惠劵 | |
| 50 | + @GetMapping("/list") | |
| 51 | + @Operation(summary = "获得优惠劵模版列表") | |
| 52 | + @Parameters({ | |
| 53 | + @Parameter(name = "spuId", description = "商品 SPU 编号"), // 目前主要给商品详情使用 | |
| 54 | + @Parameter(name = "useType", description = "使用类型"), | |
| 55 | + @Parameter(name = "count", description = "数量", required = true) | |
| 56 | + }) | |
| 57 | + public CommonResult<List<AppCouponTemplateRespVO>> getCouponTemplateList( | |
| 58 | + @RequestParam(value = "spuId", required = false) Long spuId, | |
| 59 | + @RequestParam(value = "useType", required = false) Integer useType, | |
| 60 | + @RequestParam(value = "count", required = false, defaultValue = "10") Integer count) { | |
| 61 | + List<AppCouponTemplateRespVO> list = new ArrayList<>(); | |
| 62 | + Random random = new Random(); | |
| 63 | + for (int i = 0; i < 10; i++) { | |
| 64 | + AppCouponTemplateRespVO vo = new AppCouponTemplateRespVO(); | |
| 65 | + vo.setId(i + 1L); | |
| 66 | + vo.setName("优惠劵" + (i + 1)); | |
| 67 | + vo.setTakeLimitCount(random.nextInt(10) + 1); | |
| 68 | + vo.setUsePrice(random.nextInt(100) * 100); | |
| 69 | + vo.setValidityType(random.nextInt(2) + 1); | |
| 70 | + if (vo.getValidityType() == 1) { | |
| 71 | + vo.setValidStartTime(LocalDateTime.now().plusDays(random.nextInt(10))); | |
| 72 | + vo.setValidEndTime(LocalDateTime.now().plusDays(random.nextInt(20) + 10)); | |
| 73 | + } else { | |
| 74 | + vo.setFixedStartTerm(random.nextInt(10)); | |
| 75 | + vo.setFixedEndTerm(random.nextInt(10) + vo.getFixedStartTerm() + 1); | |
| 76 | + } | |
| 77 | + vo.setDiscountType(random.nextInt(2) + 1); | |
| 78 | + if (vo.getDiscountType() == 1) { | |
| 79 | + vo.setDiscountPercent(null); | |
| 80 | + vo.setDiscountPrice(random.nextInt(50) * 100); | |
| 81 | + vo.setDiscountLimitPrice(null); | |
| 82 | + } else { | |
| 83 | + vo.setDiscountPercent(random.nextInt(90) + 10); | |
| 84 | + vo.setDiscountPrice(null); | |
| 85 | + vo.setDiscountLimitPrice(random.nextInt(200) * 100); | |
| 86 | + } | |
| 87 | + // TODO @疯狂:是否已领取,要不在 TemplateService 搞个 static 方法,让它基于 countMap 这种去计算,这样好点? | |
| 88 | + vo.setTakeStatus(random.nextBoolean()); | |
| 89 | + list.add(vo); | |
| 90 | + } | |
| 91 | + return success(list); | |
| 92 | + } | |
| 93 | + | |
| 45 | 94 | @GetMapping("/page") |
| 46 | 95 | @Operation(summary = "获得优惠劵模版分页") |
| 47 | 96 | public CommonResult<PageResult<AppCouponTemplateRespVO>> getCouponTemplatePage(AppCouponTemplatePageReqVO pageReqVO) { | ... | ... |
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 { |
| 23 | 23 | // 单位:分;0 - 不限制 |
| 24 | 24 | private Integer usePrice; |
| 25 | 25 | |
| 26 | - // TODO 芋艿:这两要改的 | |
| 27 | -// @Schema(description = "商品范围", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 28 | -// @InEnum(PromotionProductScopeEnum.class) | |
| 29 | -// private Integer productScope; | |
| 30 | -// | |
| 31 | -// @Schema(description = "商品范围编号的数组", example = "1,3") | |
| 32 | -// private List<Long> productScopeValues; | |
| 33 | - | |
| 34 | 26 | @Schema(description = "生效日期类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 35 | 27 | private Integer validityType; |
| 36 | 28 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/job/CouponExpireJob.java renamed to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/job/coupon/CouponExpireJob.java
| 1 | -package cn.iocoder.yudao.module.promotion.job; | |
| 1 | +package cn.iocoder.yudao.module.promotion.job.coupon; | |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; |
| ... | ... | @@ -8,6 +8,7 @@ import org.springframework.stereotype.Component; |
| 8 | 8 | |
| 9 | 9 | import javax.annotation.Resource; |
| 10 | 10 | |
| 11 | +// TODO 芋艿:配置一个 Job | |
| 11 | 12 | /** |
| 12 | 13 | * 优惠券过期 Job |
| 13 | 14 | * | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/job/package-info.java
0 → 100644
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java
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. |
| 40 | 40 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; |
| 41 | 41 | import static java.util.Arrays.asList; |
| 42 | 42 | |
| 43 | +// TODO @疯狂:注册时,赠送用户优惠劵;为了解耦,可以考虑注册时发个 MQ 消息;然后营销这里监听后消费; | |
| 43 | 44 | /** |
| 44 | 45 | * 优惠劵 Service 实现类 |
| 45 | 46 | * |
| ... | ... | @@ -192,7 +193,8 @@ public class CouponServiceImpl implements CouponService { |
| 192 | 193 | |
| 193 | 194 | @Override |
| 194 | 195 | public List<CouponDO> getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO) { |
| 195 | - return couponMapper.selectListByUserIdAndStatusAndUsePriceLeAndProductScope(userId, CouponStatusEnum.UNUSED.getStatus(), | |
| 196 | + return couponMapper.selectListByUserIdAndStatusAndUsePriceLeAndProductScope(userId, | |
| 197 | + CouponStatusEnum.UNUSED.getStatus(), | |
| 196 | 198 | matchReqVO.getPrice(), matchReqVO.getSpuIds(), matchReqVO.getCategoryIds()); |
| 197 | 199 | } |
| 198 | 200 | |
| ... | ... | @@ -220,6 +222,12 @@ public class CouponServiceImpl implements CouponService { |
| 220 | 222 | return count; |
| 221 | 223 | } |
| 222 | 224 | |
| 225 | + /** | |
| 226 | + * 过期单个优惠劵 | |
| 227 | + * | |
| 228 | + * @param coupon 优惠劵 | |
| 229 | + * @return 是否过期成功 | |
| 230 | + */ | |
| 223 | 231 | private boolean expireCoupon(CouponDO coupon) { |
| 224 | 232 | // 更新记录状态 |
| 225 | 233 | int updateRows = couponMapper.updateByIdAndStatus(coupon.getId(), CouponStatusEnum.UNUSED.getStatus(), | ... | ... |
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 { |
| 29 | 29 | @Resource |
| 30 | 30 | private CouponTemplateMapper couponTemplateMapper; |
| 31 | 31 | |
| 32 | + // TODO @疯狂:新增/修改时,需要校验对应的商品、分类是否存在 | |
| 32 | 33 | @Override |
| 33 | 34 | public Long createCouponTemplate(CouponTemplateCreateReqVO createReqVO) { |
| 34 | 35 | // 插入 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/cart/CartServiceImpl.java