Commit 07d6ab5842a5ce15c434df58e04e7516c96fc1fb
1 parent
1bda3c8b
拼团活动:完善 TradeCombinationHandler
Showing
5 changed files
with
80 additions
and
40 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainRecordApiImpl.java
| 1 | package cn.iocoder.yudao.module.promotion.api.bargain; | 1 | package cn.iocoder.yudao.module.promotion.api.bargain; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainRecordCreateReqDTO; | ||
| 4 | import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainValidateJoinRespDTO; | 3 | import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainValidateJoinRespDTO; |
| 5 | import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService; | 4 | import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService; |
| 6 | import org.springframework.stereotype.Service; | 5 | import org.springframework.stereotype.Service; |
| @@ -18,9 +17,9 @@ public class BargainRecordApiImpl implements BargainRecordApi { | @@ -18,9 +17,9 @@ public class BargainRecordApiImpl implements BargainRecordApi { | ||
| 18 | @Resource | 17 | @Resource |
| 19 | private BargainRecordService bargainRecordService; | 18 | private BargainRecordService bargainRecordService; |
| 20 | 19 | ||
| 21 | - @Override | ||
| 22 | - public void createBargainRecord(BargainRecordCreateReqDTO reqDTO) { | ||
| 23 | - } | 20 | + //@Override |
| 21 | + //public void createBargainRecord(BargainRecordCreateReqDTO reqDTO) { | ||
| 22 | + //} | ||
| 24 | 23 | ||
| 25 | @Override | 24 | @Override |
| 26 | public BargainValidateJoinRespDTO validateJoinBargain(Long userId, Long bargainRecordId, Long skuId) { | 25 | public BargainValidateJoinRespDTO validateJoinBargain(Long userId, Long bargainRecordId, Long skuId) { |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainRecordServiceImpl.java
| @@ -77,12 +77,12 @@ public class BargainRecordServiceImpl implements BargainRecordService { | @@ -77,12 +77,12 @@ public class BargainRecordServiceImpl implements BargainRecordService { | ||
| 77 | 77 | ||
| 78 | @Override | 78 | @Override |
| 79 | public BargainValidateJoinRespDTO validateJoinBargain(Long userId, Long bargainRecordId, Long skuId) { | 79 | public BargainValidateJoinRespDTO validateJoinBargain(Long userId, Long bargainRecordId, Long skuId) { |
| 80 | - // 1.1 拼团记录不存在 | 80 | + // 1.1 砍价记录不存在 |
| 81 | BargainRecordDO record = bargainRecordMapper.selectByIdAndUserId(bargainRecordId, userId); | 81 | BargainRecordDO record = bargainRecordMapper.selectByIdAndUserId(bargainRecordId, userId); |
| 82 | if (record == null) { | 82 | if (record == null) { |
| 83 | throw exception(BARGAIN_RECORD_NOT_EXISTS); | 83 | throw exception(BARGAIN_RECORD_NOT_EXISTS); |
| 84 | } | 84 | } |
| 85 | - // 1.2 拼团记录未在进行中 | 85 | + // 1.2 砍价记录未在进行中 |
| 86 | if (ObjUtil.notEqual(record.getStatus(), BargainRecordStatusEnum.IN_PROGRESS)) { | 86 | if (ObjUtil.notEqual(record.getStatus(), BargainRecordStatusEnum.IN_PROGRESS)) { |
| 87 | throw exception(BARGAIN_JOIN_RECORD_NOT_SUCCESS); | 87 | throw exception(BARGAIN_JOIN_RECORD_NOT_SUCCESS); |
| 88 | } | 88 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java
| @@ -16,6 +16,7 @@ import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDeta | @@ -16,6 +16,7 @@ import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDeta | ||
| 16 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; | 16 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; |
| 17 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; | 17 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; |
| 18 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | 18 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 19 | +import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; | ||
| 19 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; | 20 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; |
| 20 | import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO; | 21 | import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO; |
| 21 | import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO; | 22 | import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO; |
| @@ -263,4 +264,16 @@ public interface TradeOrderConvert { | @@ -263,4 +264,16 @@ public interface TradeOrderConvert { | ||
| 263 | 264 | ||
| 264 | List<TradeOrderRespDTO> convertList04(List<TradeOrderDO> list); | 265 | List<TradeOrderRespDTO> convertList04(List<TradeOrderDO> list); |
| 265 | 266 | ||
| 267 | + @Mappings({ | ||
| 268 | + @Mapping(target = "activityId", source = "order.combinationActivityId"), | ||
| 269 | + @Mapping(target = "spuId", source = "item.spuId"), | ||
| 270 | + @Mapping(target = "skuId", source = "item.skuId"), | ||
| 271 | + @Mapping(target = "count", source = "item.count"), | ||
| 272 | + @Mapping(target = "orderId", source = "order.id"), | ||
| 273 | + @Mapping(target = "userId", source = "order.userId"), | ||
| 274 | + @Mapping(target = "headId", source = "order.combinationRecordHeadId"), | ||
| 275 | + @Mapping(target = "combinationPrice", source = "item.payPrice"), | ||
| 276 | + }) | ||
| 277 | + CombinationRecordCreateReqDTO convert(TradeOrderDO order, TradeOrderItemDO item); | ||
| 278 | + | ||
| 266 | } | 279 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java
| @@ -7,7 +7,10 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; | @@ -7,7 +7,10 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; | ||
| 7 | import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; | 7 | import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; |
| 8 | import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryPickUpStoreDO; | 8 | import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryPickUpStoreDO; |
| 9 | import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; | 9 | import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; |
| 10 | -import cn.iocoder.yudao.module.trade.enums.order.*; | 10 | +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderCancelTypeEnum; |
| 11 | +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderRefundStatusEnum; | ||
| 12 | +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; | ||
| 13 | +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; | ||
| 11 | import com.baomidou.mybatisplus.annotation.KeySequence; | 14 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 12 | import com.baomidou.mybatisplus.annotation.TableName; | 15 | import com.baomidou.mybatisplus.annotation.TableName; |
| 13 | import lombok.*; | 16 | import lombok.*; |
| @@ -308,4 +311,17 @@ public class TradeOrderDO extends BaseDO { | @@ -308,4 +311,17 @@ public class TradeOrderDO extends BaseDO { | ||
| 308 | */ | 311 | */ |
| 309 | private Long bargainRecordId; | 312 | private Long bargainRecordId; |
| 310 | 313 | ||
| 314 | + /** | ||
| 315 | + * 拼团活动编号 TODO puhui999:价格计算后设置 | ||
| 316 | + * | ||
| 317 | + * 关联 CombinationActivityDO 的 id 字段 | ||
| 318 | + */ | ||
| 319 | + private Long combinationActivityId; | ||
| 320 | + /** | ||
| 321 | + * 团长编号 | ||
| 322 | + * | ||
| 323 | + * 关联 CombinationRecordDO 的 id 字段 | ||
| 324 | + */ | ||
| 325 | + private Long combinationRecordHeadId; | ||
| 326 | + | ||
| 311 | } | 327 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java
| 1 | package cn.iocoder.yudao.module.trade.service.order.handler; | 1 | package cn.iocoder.yudao.module.trade.service.order.handler; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.lang.Assert; | ||
| 4 | +import cn.hutool.core.util.ObjectUtil; | ||
| 3 | import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; | 5 | import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; |
| 6 | +import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; | ||
| 7 | +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; | ||
| 8 | +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; | ||
| 9 | +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; | ||
| 4 | import org.springframework.stereotype.Component; | 10 | import org.springframework.stereotype.Component; |
| 5 | 11 | ||
| 6 | import javax.annotation.Resource; | 12 | import javax.annotation.Resource; |
| 13 | +import java.util.List; | ||
| 7 | 14 | ||
| 8 | /** | 15 | /** |
| 9 | * 拼团订单 handler 接口实现类 | 16 | * 拼团订单 handler 接口实现类 |
| @@ -16,38 +23,43 @@ public class TradeCombinationHandler implements TradeOrderHandler { | @@ -16,38 +23,43 @@ public class TradeCombinationHandler implements TradeOrderHandler { | ||
| 16 | @Resource | 23 | @Resource |
| 17 | private CombinationRecordApi combinationRecordApi; | 24 | private CombinationRecordApi combinationRecordApi; |
| 18 | 25 | ||
| 19 | -// @Override | ||
| 20 | -// public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) { | ||
| 21 | -// // 如果不是拼团订单则结束 | ||
| 22 | -// if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), reqBO.getOrderType())) { | ||
| 23 | -// return; | ||
| 24 | -// } | ||
| 25 | -// | ||
| 26 | -// // 获取商品信息 | ||
| 27 | -// TradeBeforeOrderCreateReqBO.Item item = reqBO.getItems().get(0); | ||
| 28 | -// // 校验是否满足拼团活动相关限制 | ||
| 29 | -// combinationRecordApi.validateCombinationRecord(reqBO.getCombinationActivityId(), reqBO.getUserId(), item.getSkuId(), item.getCount()); | ||
| 30 | -// } | ||
| 31 | - | ||
| 32 | -// @Override | ||
| 33 | -// public void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO) { | ||
| 34 | -// if (reqBO.getCombinationActivityId() == null) { | ||
| 35 | -// return; | ||
| 36 | -// } | ||
| 37 | -// | ||
| 38 | -// // 创建砍价记录 | ||
| 39 | -// combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(reqBO)); | ||
| 40 | -// } | ||
| 41 | - | ||
| 42 | -// @Override | ||
| 43 | -// public void afterPayOrder(TradeAfterPayOrderReqBO reqBO) { | ||
| 44 | -// // 如果不是拼团订单则结束 | ||
| 45 | -// if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), reqBO.getOrderType())) { | ||
| 46 | -// return; | ||
| 47 | -// } | ||
| 48 | -// | ||
| 49 | -// // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 | ||
| 50 | -// combinationRecordApi.updateRecordStatusToInProgress(reqBO.getUserId(), reqBO.getOrderId(), reqBO.getPayTime()); | ||
| 51 | -// } | 26 | + @Override |
| 27 | + public void beforeOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { | ||
| 28 | + // 如果不是拼团订单则结束 | ||
| 29 | + if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | ||
| 30 | + return; | ||
| 31 | + } | ||
| 32 | + Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); | ||
| 33 | + | ||
| 34 | + // 获取商品信息 | ||
| 35 | + TradeOrderItemDO item = orderItems.get(0); | ||
| 36 | + // 校验是否满足拼团活动相关限制 | ||
| 37 | + combinationRecordApi.validateCombinationRecord(order.getCombinationActivityId(), order.getUserId(), item.getSkuId(), item.getCount()); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public void afterOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { | ||
| 42 | + // 如果不是拼团订单则结束 | ||
| 43 | + if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | ||
| 44 | + return; | ||
| 45 | + } | ||
| 46 | + Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); | ||
| 47 | + | ||
| 48 | + // 获取商品信息 | ||
| 49 | + TradeOrderItemDO item = orderItems.get(0); | ||
| 50 | + // 创建砍价记录 | ||
| 51 | + combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, item)); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + @Override | ||
| 55 | + public void afterPayOrder(TradeOrderDO order) { | ||
| 56 | + // 如果不是拼团订单则结束 | ||
| 57 | + if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | ||
| 58 | + return; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 | ||
| 62 | + combinationRecordApi.updateRecordStatusToInProgress(order.getUserId(), order.getId(), order.getPayTime()); | ||
| 63 | + } | ||
| 52 | 64 | ||
| 53 | } | 65 | } |