From 77f776356011b878d8d191407cb5ef22e350e8a7 Mon Sep 17 00:00:00 2001 From: owen Date: Tue, 26 Sep 2023 23:21:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=EF=BC=9A=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E4=BC=98=E6=83=A0=E5=88=B8=E9=A2=86=E5=8F=96=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/coupon/AppCouponController.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) 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 index d366459fc..f6b92eaae 100755 --- 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 @@ -1,22 +1,25 @@ package cn.iocoder.yudao.module.promotion.controller.app.coupon; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; -import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchReqVO; -import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchRespVO; -import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponPageReqVO; -import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponRespVO; -import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.template.AppCouponTemplatePageReqVO; +import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.*; import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; +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.tags.Tag; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.validation.Valid; import java.util.Collections; import java.util.List; @@ -31,12 +34,25 @@ public class AppCouponController { @Resource private CouponService couponService; + @Resource + private CouponTemplateService couponTemplateService; - // TODO 芋艿:待实现 @PostMapping("/take") @Operation(summary = "领取优惠劵") - public CommonResult takeCoupon(@RequestBody AppCouponTemplatePageReqVO pageReqVO) { - return success(1L); + @Parameter(name = "templateId", description = "优惠券模板编号", required = true, example = "1024") + public CommonResult takeCoupon(@Valid @RequestBody AppCouponTakeReqVO reqVO) { + Long userId = getLoginUserId(); + // 领取 + couponService.takeCoupon(reqVO.getTemplateId(), CollUtil.newHashSet(userId), CouponTakeTypeEnum.USER); + // 检查是否可以继续领取 + CouponTemplateDO couponTemplate = couponTemplateService.getCouponTemplate(reqVO.getTemplateId()); + boolean canTakeAgain = true; + if (couponTemplate.getTakeLimitCount() != null && couponTemplate.getTakeLimitCount() > 0) { + Integer takeCount = MapUtil.getInt(couponService.getTakeCountMapByTemplateIds( + Collections.singleton(reqVO.getTemplateId()), userId), reqVO.getTemplateId(), 0); + canTakeAgain = takeCount < couponTemplate.getTakeLimitCount(); + } + return success(canTakeAgain); } @GetMapping("/match-list")