From dd6adb8ee6f431d062dc826971711066675f6f86 Mon Sep 17 00:00:00 2001 From: "zhijiantianya@gmail.com" Date: Fri, 1 Sep 2023 19:08:27 +0800 Subject: [PATCH] code review order --- .../AppDeliverPickUpStoreController.java | 2 + .../app/order/AppTradeOrderController.java | 7 ++- .../dataobject/order/TradeOrderItemDO.java | 2 + .../aftersale/TradeAfterSaleServiceImpl.java | 2 + .../order/TradeOrderUpdateServiceImpl.java | 53 ++++++++++++------- .../service/price/TradePriceServiceImpl.java | 1 + .../TradeDeliveryPriceCalculator.java | 1 + 7 files changed, 46 insertions(+), 22 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverPickUpStoreController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverPickUpStoreController.java index 275eacde8..3b49fb6ae 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverPickUpStoreController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverPickUpStoreController.java @@ -24,6 +24,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Validated public class AppDeliverPickUpStoreController { + // TODO 待实现[门店自提]:如果 latitude、longitude 非空,计算经纬度,并排序。计算的库,可以使用 hutool 的 DistanceUtil 计算。 @GetMapping("/list") @Operation(summary = "获得自提门店列表") public CommonResult> getDeliveryPickUpStoreList( @@ -50,6 +51,7 @@ public class AppDeliverPickUpStoreController { return success(list); } + // TODO 待实现[门店自提]: @GetMapping("/get") @Operation(summary = "获得自提门店") @Parameter(name = "id", description = "门店编号") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index e3205fcaf..92181fca7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -49,9 +49,6 @@ public class AppTradeOrderController { @Resource private DeliveryExpressService deliveryExpressService; - @Resource - private ProductPropertyValueApi productPropertyValueApi; - @Resource private TradeOrderProperties tradeOrderProperties; @@ -78,6 +75,7 @@ public class AppTradeOrderController { return success(true); } + // TODO @芋艿:如果拼团活动、秒杀活动、砍价活动时,是不是要额外在返回活动之类的信息; @GetMapping("/get-detail") @Operation(summary = "获得交易订单") @Parameter(name = "id", description = "交易订单编号") @@ -93,6 +91,7 @@ public class AppTradeOrderController { // 查询物流公司 DeliveryExpressDO express = order.getLogisticsId() != null && order.getLogisticsId() > 0 ? deliveryExpressService.getDeliveryExpress(order.getLogisticsId()) : null; + // TODO @puhui999:如果门店自提,信息的拼接; // 最终组合 return success(TradeOrderConvert.INSTANCE.convert02(order, orderItems, tradeOrderProperties, express)); } @@ -141,7 +140,7 @@ public class AppTradeOrderController { @PutMapping("/receive") @Operation(summary = "确认交易订单收货") @Parameter(name = "id", description = "交易订单编号") - public CommonResult takeOrder(@RequestParam("id") Long id) { + public CommonResult receiveOrder(@RequestParam("id") Long id) { tradeOrderUpdateService.receiveOrder(getLoginUserId(), id); return success(true); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java index f078f149e..27dd13f67 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java @@ -143,6 +143,8 @@ public class TradeOrderItemDO extends BaseDO { * 对应 taobao 的 trade.point_fee 字段 */ private Integer pointPrice; + // TODO @芋艿:如果商品 vip 折扣时,到底是新增一个 vipPrice 记录优惠记录,还是 vipDiscountPrice,记录 vip 的优惠;还是直接使用 vipPrice; + // 目前 crmeb 的选择,单独一个 vipPrice 记录优惠价格;感觉不一定合理,可以在看看有赞的; // ========== 售后基本信息 ========== diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java index 83a180fc5..eae983799 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java @@ -98,6 +98,8 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa return afterSale; } + // TODO 芋艿:拼团失败,要不要发起售后的方式退款?还是走取消逻辑? + @Override @Transactional(rollbackFor = Exception.class) public Long createAfterSale(Long userId, AppTradeAfterSaleCreateReqVO createReqVO) { 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 41da62dab..0776e4beb 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 @@ -96,6 +96,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { private TradePriceService tradePriceService; @Resource private DeliveryExpressService deliveryExpressService; + @Resource + private TradeMessageService tradeMessageService; @Resource private ProductSkuApi productSkuApi; @@ -105,27 +107,22 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { private AddressApi addressApi; @Resource private CouponApi couponApi; - + @Resource + private CombinationRecordApi combinationRecordApi; + @Resource + private BargainRecordApi bargainRecordApi; @Resource private MemberUserApi memberUserApi; @Resource private MemberLevelApi memberLevelApi; @Resource private MemberPointApi memberPointApi; - @Resource private ProductCommentApi productCommentApi; - @Resource - private TradeMessageService tradeMessageService; + @Resource private TradeOrderProperties tradeOrderProperties; - @Resource - private CombinationRecordApi combinationRecordApi; - - @Resource - private BargainRecordApi bargainRecordApi; - // =================== Order =================== @Override @@ -179,15 +176,17 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Override @Transactional(rollbackFor = Exception.class) public TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO) { - // 2. 价格计算 + // 1. 价格计算 TradePriceCalculateRespBO calculateRespBO = calculatePrice(userId, createReqVO); - // 3.1 插入 TradeOrderDO 订单 + + // 2.1 插入 TradeOrderDO 订单 TradeOrderDO order = createTradeOrder(userId, userIp, createReqVO, calculateRespBO); - // 3.2 插入 TradeOrderItemDO 订单项 + // 2.2 插入 TradeOrderItemDO 订单项 List orderItems = createTradeOrderItems(order, calculateRespBO); - // 订单创建完后的逻辑 + + // 3. 订单创建完后的逻辑 afterCreateTradeOrder(userId, createReqVO, order, orderItems, calculateRespBO); - // 3.3 校验订单类型 + // 3.1 拼团的特殊逻辑 // TODO @puhui999:这个逻辑,先抽个小方法;未来要通过设计模式,把这些拼团之类的逻辑,抽象出去 // 拼团 if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { @@ -205,15 +204,21 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, orderItemDO, createReqVO, user)); } + // 3.2 秒杀的特殊逻辑 // TODO 秒杀扣减库存是下单就扣除还是等待订单支付成功再扣除 if (Objects.equals(TradeOrderTypeEnum.SECKILL.getType(), order.getType())) { } + // 3.3 砍价的特殊逻辑 // TODO @LeeYan9: 是可以思考下, 订单的营销优惠记录, 应该记录在哪里, 微信讨论起来! return order; } + // TODO @puhui999:订单超时,自动取消; + + // TODO @疯狂:用户手动取消订单; + /** * 校验收件地址是否存在 * @@ -239,7 +244,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { } TradeOrderDO order = TradeOrderConvert.INSTANCE.convert(userId, clientIp, createReqVO, calculateRespBO, address); order.setType(validateActivity(createReqVO)); - order.setNo(IdUtil.getSnowflakeNextId() + ""); // TODO @LeeYan9: 思考下, 怎么生成好点哈; 这个是会展示给用户的; + order.setNo(IdUtil.getSnowflakeNextId() + ""); // TODO @puhui999: 参考支付订单,的 no 生成哈; order.setStatus(TradeOrderStatusEnum.UNPAID.getStatus()); order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()); order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum)); @@ -251,6 +256,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 退款信息 order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0); tradeOrderMapper.insert(order); + // TODO @puhui999:如果是门店订单,则需要生成核销码; return order; } @@ -291,6 +297,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { TradeOrderDO tradeOrderDO, List orderItems, TradePriceCalculateRespBO calculateRespBO) { // 下单时扣减商品库存 + // TODO @puhui999:扣库存,需要前置; + // 1)如果是秒杀商品:额外扣减秒杀的库存; + // 2)如果是拼团活动:额外扣减拼团的库存; + // 3)如果是砍价活动:额外扣减砍价的库存; productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems)); // 删除购物车商品 @@ -299,9 +309,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { cartService.deleteCart(userId, cartIds); } - // 扣减积分 TODO 芋艿:待实现 + // 扣减积分 TODO 芋艿:待实现,需要前置; - // 有使用优惠券时更新 + // 有使用优惠券时更新 TODO 芋艿:需要前置; if (createReqVO.getCouponId() != null) { couponApi.useCoupon(new CouponUseReqDTO().setId(createReqVO.getCouponId()).setUserId(userId) .setOrderId(tradeOrderDO.getId())); @@ -510,6 +520,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO 芋艿:lili 发送订单变化的消息 // TODO 芋艿:lili 发送商品被购买完成的数据 + + // TODO 芋艿:销售佣金的记录; + + // TODO 芋艿:获得积分; } @Override @@ -529,11 +543,13 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { if (order.getPayStatus()) { throw exception(ORDER_UPDATE_PRICE_FAIL_PAID); } + // TODO @puhui999:如果改价,需要校验下是否真的变化; // 更新 // TODO @puhui999:TradeOrderItemDO 需要做 adjustPrice 的分摊;另外,支付订单那的价格,需要 update 下; TradeOrderDO update = TradeOrderConvert.INSTANCE.convert(reqVO); update.setPayPrice(update.getPayPrice() + update.getAdjustPrice()); + // TODO @芋艿:改价时,赠送的积分,要不要做改动??? tradeOrderMapper.updateById(update); } @@ -651,6 +667,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { List orderItems = tradeOrderItemMapper.selectListByOrderId(order.getId()); if (!anyMatch(orderItems, item -> Objects.equals(item.getCommentStatus(), Boolean.FALSE))) { tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()).setCommentStatus(Boolean.TRUE)); + // TODO 待实现:已完成评价,要不要写一条订单日志?目前 crmeb 会写,有赞可以研究下 } return comment; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java index a6982c177..e211374bf 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java @@ -41,6 +41,7 @@ public class TradePriceServiceImpl implements TradePriceService { @Resource private List priceCalculators; + // TODO @疯狂:需要搞个 TradePriceCalculator,计算赠送积分; @Override public TradePriceCalculateRespBO calculatePrice(TradePriceCalculateReqBO calculateReqBO) { // 1.1 获得商品 SKU 数组 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java index 35a3cb92a..5454c450d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java @@ -42,6 +42,7 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { @Override public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + // TODO @芋艿:如果门店自提,需要校验是否开启; // 1.1 判断配送方式 if (param.getDeliveryType() == null || DeliveryTypeEnum.PICK_UP.getMode().equals(param.getDeliveryType())) { return;