mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	mall + promotion:增加优惠劵的 mock 接口
This commit is contained in:
		| @@ -4,12 +4,10 @@ import cn.hutool.core.date.DateUtil; | |||||||
| import cn.hutool.core.util.RandomUtil; | import cn.hutool.core.util.RandomUtil; | ||||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||||
| import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | 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.ProductCommentPageReqVO; | ||||||
| import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO; | 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.ProductCommentRespVO; | ||||||
| import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; | 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.AppCommentPageReqVO; | ||||||
| import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; | ||||||
| import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; | import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; | ||||||
| @@ -93,12 +91,10 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { | |||||||
|             o.setSkuId(generateId()); |             o.setSkuId(generateId()); | ||||||
|             o.setDescriptionScores(ProductCommentScoresEnum.FOUR.getScores()); |             o.setDescriptionScores(ProductCommentScoresEnum.FOUR.getScores()); | ||||||
|             o.setBenefitScores(ProductCommentScoresEnum.FOUR.getScores()); |             o.setBenefitScores(ProductCommentScoresEnum.FOUR.getScores()); | ||||||
|             o.setDeliveryScores(ProductCommentScoresEnum.FOUR.getScores()); |  | ||||||
|             o.setContent("真好吃"); |             o.setContent("真好吃"); | ||||||
|             o.setReplyUserId(generateId()); |             o.setReplyUserId(generateId()); | ||||||
|             o.setReplyContent("确实"); |             o.setReplyContent("确实"); | ||||||
|             o.setReplyTime(LocalDateTime.now()); |             o.setReplyTime(LocalDateTime.now()); | ||||||
|             o.setAdditionalTime(LocalDateTime.now()); |  | ||||||
|             o.setCreateTime(LocalDateTime.now()); |             o.setCreateTime(LocalDateTime.now()); | ||||||
|             o.setUpdateTime(LocalDateTime.now()); |             o.setUpdateTime(LocalDateTime.now()); | ||||||
|         }); |         }); | ||||||
| @@ -196,27 +192,4 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { | |||||||
|         assertEquals("测试", productCommentDO.getReplyContent()); |         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()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -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<Long> takeCoupon(@RequestBody AppCouponTemplatePageReqVO pageReqVO) { | ||||||
|  |         return success(1L); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -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<List<AppCouponTemplateRespVO>> getCouponTemplateList(@RequestParam("spuId") Long spuId, | ||||||
|  |                                                                              @RequestParam(value = "useType", required = false) Integer useType) { | ||||||
|  |         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); | ||||||
|  |             } | ||||||
|  |             vo.setTakeStatus(random.nextBoolean()); | ||||||
|  |             list.add(vo); | ||||||
|  |         } | ||||||
|  |         return success(list); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // TODO 芋艿:待实现 | ||||||
|  |     @GetMapping("/page") | ||||||
|  |     @Operation(description = "获得优惠劵模版分页") | ||||||
|  |     public CommonResult<PageResult<AppCouponTemplateRespVO>> getCouponTemplatePage(AppCouponTemplatePageReqVO pageReqVO) { | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -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; | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -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; | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -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<Long> 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; | ||||||
|  |  | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV