From 9e894e04306bdd37ef0de348a3818d6b01ea231d Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 10 Jun 2023 09:57:37 +0800 Subject: [PATCH] =?UTF-8?q?mall=20+=20promotion=EF=BC=9A=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=8A=B5=E7=9A=84=20mock=20=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProductCommentServiceImplTest.java | 27 ------ .../app/coupon/AppCouponController.java | 28 +++++++ .../coupon/AppCouponTemplateController.java | 84 +++++++++++++++++++ .../coupon/vo/coupon/AppCouponTakeReqVO.java | 16 ++++ .../template/AppCouponTemplatePageReqVO.java | 19 +++++ .../vo/template/AppCouponTemplateRespVO.java | 68 +++++++++++++++ 6 files changed, 215 insertions(+), 27 deletions(-) create mode 100755 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java create mode 100755 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/coupon/AppCouponTakeReqVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplatePageReqVO.java create mode 100755 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplateRespVO.java diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java index 6754f3ba0..520555141 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java @@ -4,12 +4,10 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.RandomUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; -import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentAdditionalReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; @@ -93,12 +91,10 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { o.setSkuId(generateId()); o.setDescriptionScores(ProductCommentScoresEnum.FOUR.getScores()); o.setBenefitScores(ProductCommentScoresEnum.FOUR.getScores()); - o.setDeliveryScores(ProductCommentScoresEnum.FOUR.getScores()); o.setContent("真好吃"); o.setReplyUserId(generateId()); o.setReplyContent("确实"); o.setReplyTime(LocalDateTime.now()); - o.setAdditionalTime(LocalDateTime.now()); o.setCreateTime(LocalDateTime.now()); o.setUpdateTime(LocalDateTime.now()); }); @@ -196,27 +192,4 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { assertEquals("测试", productCommentDO.getReplyContent()); } - @Test - public void testCreateComment_success() { - // mock 测试 - ProductCommentDO productComment = randomPojo(ProductCommentDO.class, o -> { - o.setAdditionalContent(""); - }); - - productCommentService.createComment(productComment, Boolean.TRUE); - - MemberUserRespDTO user = new MemberUserRespDTO(); - user.setId(productComment.getUserId()); - - AppCommentAdditionalReqVO createReqVO = new AppCommentAdditionalReqVO(); - createReqVO.setId(productComment.getId()); - createReqVO.setAdditionalContent("追加"); - createReqVO.setAdditionalPicUrls(productComment.getAdditionalPicUrls()); - - productCommentService.additionalComment(user, createReqVO); - ProductCommentDO exist = productCommentMapper.selectById(productComment.getId()); - - assertEquals("追加", exist.getAdditionalContent()); - } - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java new file mode 100755 index 000000000..a0804079b --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.promotion.controller.app.coupon; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template.AppCouponTemplatePageReqVO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "用户 App - 优惠劵") +@RestController +@RequestMapping("/promotion/coupon") +@Validated +public class AppCouponController { + + // TODO 芋艿:待实现 + @PostMapping("/take") + @Operation(description = "领取优惠劵") + public CommonResult takeCoupon(@RequestBody AppCouponTemplatePageReqVO pageReqVO) { + return success(1L); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java new file mode 100755 index 000000000..f08bd0d74 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java @@ -0,0 +1,84 @@ +package cn.iocoder.yudao.module.promotion.controller.app.coupon; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template.AppCouponTemplatePageReqVO; +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template.AppCouponTemplateRespVO; +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.ArrayList; +import java.util.List; +import java.util.Random; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "用户 App - 优惠劵模板") +@RestController +@RequestMapping("/promotion/coupon-template") +@Validated +public class AppCouponTemplateController { + + @Resource + private CouponTemplateService couponTemplateService; + + // TODO 芋艿:待实现 + @GetMapping("/list") + @Operation(description = "获得优惠劵模版列表") // 目前主要给商品详情使用 + @Parameters({ + @Parameter(name = "spuId", description = "商品 SPU 编号", required = true), + @Parameter(name = "useType", description = "使用类型"), + @Parameter(name = "count", description = "数量", required = true) + }) + public CommonResult> getCouponTemplateList(@RequestParam("spuId") Long spuId, + @RequestParam(value = "useType", required = false) Integer useType) { + List 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); + } + vo.setTakeStatus(random.nextBoolean()); + list.add(vo); + } + return success(list); + } + + // TODO 芋艿:待实现 + @GetMapping("/page") + @Operation(description = "获得优惠劵模版分页") + public CommonResult> getCouponTemplatePage(AppCouponTemplatePageReqVO pageReqVO) { + return null; + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/coupon/AppCouponTakeReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/coupon/AppCouponTakeReqVO.java new file mode 100644 index 000000000..0f71fe2bf --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/coupon/AppCouponTakeReqVO.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Schema(description = "用户 App - 优惠劵领取 Request VO") +@Data +public class AppCouponTakeReqVO { + + @Schema(description = "优惠劵模板编号", example = "1") + @NotNull(message = "优惠劵模板编号不能为空") + private Long templateId; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplatePageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplatePageReqVO.java new file mode 100644 index 000000000..6eda32167 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplatePageReqVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@Schema(description = "用户 App - 优惠劵模板分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AppCouponTemplatePageReqVO extends PageParam { + + @Schema(description = "使用类型", example = "1") + // TODO 芋艿:这里要限制下枚举的使用 + private Integer useType; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplateRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplateRespVO.java new file mode 100755 index 000000000..5e8aa86ef --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/vo/template/AppCouponTemplateRespVO.java @@ -0,0 +1,68 @@ +package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.Min; +import java.time.LocalDateTime; + +@Schema(description = "用户 App - 优惠劵模板 Response VO") +@Data +public class AppCouponTemplateRespVO { + + @Schema(description = "优惠劵模板编号", required = true, example = "1") + private Long id; + + @Schema(description = "优惠劵名", required = true, example = "春节送送送") + private String name; + + @Schema(description = "每人限领个数", required = true, example = "66") // -1 - 则表示不限制 + private Integer takeLimitCount; + + @Schema(description = "是否设置满多少金额可用", required = true, example = "100") // 单位:分;0 - 不限制 + private Integer usePrice; + + // TODO 芋艿:这两要改的 +// @Schema(description = "商品范围", required = true, example = "1") +// @InEnum(PromotionProductScopeEnum.class) +// private Integer productScope; +// +// @Schema(description = "商品 SPU 编号的数组", example = "1,3") +// private List productSpuIds; + + @Schema(description = "生效日期类型", required = true, example = "1") + private Integer validityType; + + @Schema(description = "固定日期 - 生效开始时间") + private LocalDateTime validStartTime; + + @Schema(description = "固定日期 - 生效结束时间") + private LocalDateTime validEndTime; + + @Schema(description = "领取日期 - 开始天数") + @Min(value = 0L, message = "开始天数必须大于 0") + private Integer fixedStartTerm; + + @Schema(description = "领取日期 - 结束天数") + @Min(value = 1L, message = "开始天数必须大于 1") + private Integer fixedEndTerm; + + @Schema(description = "优惠类型", required = true, example = "1") + private Integer discountType; + + @Schema(description = "折扣百分比", example = "80") // 例如说,80% 为 80 + private Integer discountPercent; + + @Schema(description = "优惠金额", example = "10") + @Min(value = 0, message = "优惠金额需要大于等于 0") + private Integer discountPrice; + + @Schema(description = "折扣上限", example = "100") // 单位:分,仅在 discountType 为 PERCENT 使用 + private Integer discountLimitPrice; + + // ========== 用户相关字段 ========== + + @Schema(description = "是否已领取", required = true, example = "true") + private Boolean takeStatus; + +}