From e19200eb5bd7ec8eb56b5afae3e09bf4fd01f1c1 Mon Sep 17 00:00:00 2001 From: XinWei <2718030729@qq.com> Date: Sat, 12 Oct 2024 14:43:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E5=92=8C=E7=A7=92=E6=9D=80?= =?UTF-8?q?=E6=AC=A1=E6=95=B0=E6=95=B4=E5=90=88=E5=88=B0get-detail?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppCombinationActivityController.java | 22 +++++++-------- .../AppCombinationActivityDetailRespVO.java | 3 +++ .../seckill/AppSeckillActivityController.java | 27 +++++++++++-------- .../AppSeckillActivityDetailRespVO.java | 3 +++ 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java index 71b13da..7060967 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java @@ -41,6 +41,7 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Tag(name = "用户 APP - 拼团活动") @RestController @@ -134,16 +135,15 @@ public class AppCombinationActivityController { // 2. 获取活动商品 List products = activityService.getCombinationProductsByActivityId(activity.getId()); - return success(CombinationActivityConvert.INSTANCE.convert3(activity, products)); - } - @GetMapping("/getPurchaseTimes") - @Operation(summary = "获得剩余拼团购买次数") - public CommonResult getSeckillActivityPage(AppCombinationActivityPurchasesTimesReqVO reqVO) { - // 1. 获取总限购数量 - CombinationActivityDO combinationActivity = activityService.getCombinationActivity(reqVO.getActivityId()); - // 2. 获取已购买数量 - int seckillProductCount = tradeOrderApi.getCombinationProductCount(reqVO.getUserId(), reqVO.getActivityId()); - // 3. 总次数减去下单过的次数 得到剩余次数 - return success(Math.max(combinationActivity.getTotalLimitCount() - seckillProductCount, 0)); + AppCombinationActivityDetailRespVO appCombinationActivityDetailRespVO = CombinationActivityConvert.INSTANCE.convert3(activity, products); + // 3.获取已购买数量 + if (getLoginUserId() != null) { + int seckillProductCount = tradeOrderApi.getCombinationProductCount(getLoginUserId(), id); + // 总次数减去下单过的次数 得到剩余次数 + appCombinationActivityDetailRespVO.setRemainingPurchases(Math.max(activity.getTotalLimitCount() - seckillProductCount, 0)); + } else { + appCombinationActivityDetailRespVO.setRemainingPurchases(0); + } + return success(appCombinationActivityDetailRespVO); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityDetailRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityDetailRespVO.java index e2996b8..38fcda9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityDetailRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/vo/activity/AppCombinationActivityDetailRespVO.java @@ -43,6 +43,9 @@ public class AppCombinationActivityDetailRespVO { @Schema(description = "商品信息数组", requiredMode = Schema.RequiredMode.REQUIRED) private List products; + @Schema(description = "剩余购买次数", requiredMode = Schema.RequiredMode.REQUIRED) + private Integer remainingPurchases; + @Schema(description = "商品信息") @Data public static class Product { diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java index e8d8119..02d401f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; @@ -49,6 +50,7 @@ import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsync import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.isBetween; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.TIME_FORMAT_ERROR; @Tag(name = "用户 App - 秒杀活动") @@ -85,6 +87,9 @@ public class AppSeckillActivityController { @Resource private TradeOrderApi tradeOrderApi; + @Resource + private MemberUserApi memberUserApi; + @GetMapping("/get-now") @Operation(summary = "获得当前秒杀活动", description = "获取当前正在进行的活动,提供给首页使用") public CommonResult getNowSeckillActivity() { @@ -216,17 +221,17 @@ public class AppSeckillActivityController { // 4. 拼接数据 List productList = activityService.getSeckillProductListByActivityId(activity.getId()); - return success(SeckillActivityConvert.INSTANCE.convert3(activity, productList, startTime, endTime)); - } + AppSeckillActivityDetailRespVO appSeckillActivityDetailRespVO = SeckillActivityConvert.INSTANCE.convert3(activity, productList, startTime, endTime); - @GetMapping("/getPurchaseTimes") - @Operation(summary = "获得剩余秒杀购买次数") - public CommonResult getSeckillActivityPage(AppSeckillPurchasesTimesReqVO reqVO) { - // 1. 获取总限购数量 - SeckillActivityDO seckillActivity = activityService.getSeckillActivity(reqVO.getActivityId()); - // 2. 获取已购买数量 - int seckillProductCount = tradeOrderApi.getSeckillProductCount(reqVO.getUserId(), reqVO.getActivityId()); - // 3. 总次数减去下单过的次数 得到剩余次数 - return success(Math.max(seckillActivity.getTotalLimitCount() - seckillProductCount, 0)); + // 5.获取已购买数量 + if (getLoginUserId() != null) { + int seckillProductCount = tradeOrderApi.getSeckillProductCount(getLoginUserId(), id); + // 总次数减去下单过的次数 得到剩余次数 + appSeckillActivityDetailRespVO.setRemainingPurchases(Math.max(activity.getTotalLimitCount() - seckillProductCount, 0)); + } else { + appSeckillActivityDetailRespVO.setRemainingPurchases(0); + } + + return success(appSeckillActivityDetailRespVO); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/activity/AppSeckillActivityDetailRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/activity/AppSeckillActivityDetailRespVO.java index ebb5ac5..4d4630f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/activity/AppSeckillActivityDetailRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/vo/activity/AppSeckillActivityDetailRespVO.java @@ -43,6 +43,9 @@ public class AppSeckillActivityDetailRespVO { @Schema(description = "商品信息数组", requiredMode = Schema.RequiredMode.REQUIRED) private List products; + @Schema(description = "剩余购买次数", requiredMode = Schema.RequiredMode.REQUIRED) + private Integer remainingPurchases; + @Schema(description = "商品信息") @Data public static class Product {