|
@@ -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) {
|