From 387ef6f396d4d182a5755f74ca2a7cbfd8b86814 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 10 Aug 2024 12:15:57 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E3=80=91=E5=95=86=E5=9F=8E=EF=BC=9A1=EF=BC=89=E6=8B=BC?= =?UTF-8?q?=E5=9B=A2=E6=B4=BB=E5=8A=A8=EF=BC=8C=E7=A7=BB=E9=99=A4=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=B8=BB=E5=8A=A8=E5=8F=96=E6=B6=88=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E5=B8=B8=E7=94=A8=EF=BC=9B2=EF=BC=89review=20=E6=8B=BC?= =?UTF-8?q?=E5=9B=A2=E7=9B=B8=E5=85=B3=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppCombinationRecordController.java | 28 ---------- .../combination/CombinationRecordService.java | 18 ------ .../CombinationRecordServiceImpl.java | 56 ------------------- .../order/TradeOrderUpdateServiceImpl.java | 4 +- 4 files changed, 3 insertions(+), 103 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java index d363a9109..8a3ea838e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java @@ -10,9 +10,7 @@ import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.Ap import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.AppCombinationRecordSummaryRespVO; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; -import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; -import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -20,7 +18,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.validation.Valid; import jakarta.validation.constraints.Max; -import org.springframework.context.annotation.Lazy; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -43,9 +40,6 @@ public class AppCombinationRecordController { @Resource private CombinationRecordService combinationRecordService; - @Resource - @Lazy - private TradeOrderApi tradeOrderApi; @GetMapping("/get-summary") @Operation(summary = "获得拼团记录的概要信息", description = "用于小程序首页") @@ -117,26 +111,4 @@ public class AppCombinationRecordController { return success(CombinationActivityConvert.INSTANCE.convert(getLoginUserId(), headRecord, memberRecords)); } - @GetMapping("/cancel") - @Operation(summary = "取消拼团") - @Parameter(name = "id", description = "拼团记录编号", required = true, example = "1024") - public CommonResult cancelCombinationRecord(@RequestParam("id") Long id) { - Long userId = getLoginUserId(); - // 1、查找这条拼团记录 - CombinationRecordDO record = combinationRecordService.getCombinationRecordByIdAndUser(userId, id); - if (record == null) { - return success(Boolean.FALSE); - } - // 1.1、需要先校验拼团记录未完成; - if (!CombinationRecordStatusEnum.isInProgress(record.getStatus())) { - return success(Boolean.FALSE); - } - - // 2. 取消已支付的订单 - tradeOrderApi.cancelPaidOrder(userId, record.getOrderId()); - // 3. 取消拼团记录 - combinationRecordService.cancelCombinationRecord(userId, record.getId(), record.getHeadId()); - return success(Boolean.TRUE); - } - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java index ada81d224..41400d3d8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java @@ -139,24 +139,6 @@ public interface CombinationRecordService { @Nullable Integer status, @Nullable Long headId); - /** - * 获取拼团记录 - * - * @param userId 用户编号 - * @param id 拼团记录编号 - * @return 拼团记录 - */ - CombinationRecordDO getCombinationRecordByIdAndUser(Long userId, Long id); - - /** - * 取消拼团 - * - * @param userId 用户编号 - * @param id 拼团记录编号 - * @param headId 团长编号 - */ - void cancelCombinationRecord(Long userId, Long id, Long headId); - /** * 处理过期拼团 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 1f7c9a073..cb70b8ea9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -69,7 +69,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { private ProductSpuApi productSpuApi; @Resource private ProductSkuApi productSkuApi; - @Resource @Lazy // 延迟加载,避免循环依赖 private TradeOrderApi tradeOrderApi; @@ -289,61 +288,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return combinationRecordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId); } - @Override - public CombinationRecordDO getCombinationRecordByIdAndUser(Long userId, Long id) { - return combinationRecordMapper.selectOne(CombinationRecordDO::getUserId, userId, CombinationRecordDO::getId, id); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void cancelCombinationRecord(Long userId, Long id, Long headId) { - // 删除记录 - combinationRecordMapper.deleteById(id); - - // 需要更新的记录 - List updateRecords = new ArrayList<>(); - // 如果它是团长,则顺序(下单时间)继承 - if (Objects.equals(headId, CombinationRecordDO.HEAD_ID_GROUP)) { // 情况一:团长 - // 团员 - List list = getCombinationRecordListByHeadId(id); - if (CollUtil.isEmpty(list)) { - return; - } - // 按照创建时间升序排序 - list.sort(Comparator.comparing(CombinationRecordDO::getCreateTime)); // 影响原 list - CombinationRecordDO newHead = list.get(0); // 新团长继位 - list.forEach(item -> { - CombinationRecordDO recordDO = new CombinationRecordDO(); - recordDO.setId(item.getId()); - if (ObjUtil.equal(item.getId(), newHead.getId())) { // 新团长 - recordDO.setHeadId(CombinationRecordDO.HEAD_ID_GROUP); - } else { - recordDO.setHeadId(newHead.getId()); - } - recordDO.setUserCount(list.size()); - updateRecords.add(recordDO); - }); - } else { // 情况二:团员 - // 团长 - CombinationRecordDO recordHead = combinationRecordMapper.selectById(headId); - // 团员 - List records = getCombinationRecordListByHeadId(headId); - if (CollUtil.isEmpty(records)) { - return; - } - records.add(recordHead); // 加入团长,团长数据也需要更新 - records.forEach(item -> { - CombinationRecordDO recordDO = new CombinationRecordDO(); - recordDO.setId(item.getId()); - recordDO.setUserCount(records.size()); - updateRecords.add(recordDO); - }); - } - - // 更新拼团记录 - combinationRecordMapper.updateBatch(updateRecords); - } - @Override public KeyValue expireCombinationRecord() { // 1. 获取所有正在进行中的过期的父拼团 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 7acba7dde..945e36fc5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -855,12 +855,14 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Override @Transactional(rollbackFor = Exception.class) public void cancelPaidOrder(Long userId, Long orderId) { - // TODO 芋艿:这里实现要优化下; + // TODO @puhui999:需要校验状态;已支付的情况下,才可以。 TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId); if (order == null) { throw exception(ORDER_NOT_FOUND); } cancelOrder0(order, TradeOrderCancelTypeEnum.MEMBER_CANCEL); + + // TODO @puhui999:需要退款 } /**