mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-13 17:51:53 +08:00
fix: 完善拼团、秒杀、砍价活动管理
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package cn.iocoder.yudao.module.trade.service.message;
|
||||
|
||||
import cn.iocoder.yudao.module.trade.service.message.dto.TradeOrderMessageWhenDeliveryOrderReqDTO;
|
||||
import cn.iocoder.yudao.module.trade.service.message.bo.TradeOrderMessageWhenDeliveryOrderReqBO;
|
||||
|
||||
/**
|
||||
* Trade 消息 service 接口
|
||||
@@ -10,10 +10,10 @@ import cn.iocoder.yudao.module.trade.service.message.dto.TradeOrderMessageWhenDe
|
||||
public interface TradeMessageService {
|
||||
|
||||
/**
|
||||
* 订单发货时发送消息
|
||||
* 订单发货时发送通知
|
||||
*
|
||||
* @param reqDTO 发送消息
|
||||
* @param reqBO 发送消息
|
||||
*/
|
||||
void sendMessageWhenDeliveryOrder(TradeOrderMessageWhenDeliveryOrderReqDTO reqDTO);
|
||||
void sendMessageWhenDeliveryOrder(TradeOrderMessageWhenDeliveryOrderReqBO reqBO);
|
||||
|
||||
}
|
||||
|
@@ -2,7 +2,8 @@ package cn.iocoder.yudao.module.trade.service.message;
|
||||
|
||||
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
|
||||
import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
|
||||
import cn.iocoder.yudao.module.trade.service.message.dto.TradeOrderMessageWhenDeliveryOrderReqDTO;
|
||||
import cn.iocoder.yudao.module.trade.enums.MessageTemplateConstants;
|
||||
import cn.iocoder.yudao.module.trade.service.message.bo.TradeOrderMessageWhenDeliveryOrderReqBO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -23,18 +24,16 @@ public class TradeMessageServiceImpl implements TradeMessageService {
|
||||
private NotifyMessageSendApi notifyMessageSendApi;
|
||||
|
||||
@Override
|
||||
public void sendMessageWhenDeliveryOrder(TradeOrderMessageWhenDeliveryOrderReqDTO reqDTO) {
|
||||
public void sendMessageWhenDeliveryOrder(TradeOrderMessageWhenDeliveryOrderReqBO reqBO) {
|
||||
// 1、构造消息
|
||||
Map<String, Object> msgMap = new HashMap<>();
|
||||
msgMap.put("orderId", reqDTO.getOrderId());
|
||||
// TODO puhui999:应该不是 msg 哇,应该是涉及到的模版参数哈;msg 太大了
|
||||
msgMap.put("msg", reqDTO.getMessage());
|
||||
Map<String, Object> msgMap = new HashMap<>(2);
|
||||
msgMap.put("orderId", reqBO.getOrderId());
|
||||
msgMap.put("deliveryMessage", reqBO.getMessage());
|
||||
// 2、发送站内信
|
||||
notifyMessageSendApi.sendSingleMessageToMember(
|
||||
new NotifySendSingleToUserReqDTO()
|
||||
.setUserId(reqDTO.getUserId())
|
||||
// TODO puhui999:短信模版编号,枚举起来;
|
||||
.setTemplateCode("order_delivery")
|
||||
.setUserId(reqBO.getUserId())
|
||||
.setTemplateCode(MessageTemplateConstants.ORDER_DELIVERY)
|
||||
.setTemplateParams(msgMap));
|
||||
}
|
||||
|
||||
|
@@ -1,18 +1,17 @@
|
||||
package cn.iocoder.yudao.module.trade.service.message.dto;
|
||||
package cn.iocoder.yudao.module.trade.service.message.bo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
// TODO @puhui999:改成 ReqBO 哈;包名也换了;service 我们还是同一用 bo 对象
|
||||
/**
|
||||
* 订单发货时 Req DTO
|
||||
* 订单发货时通知创建 Req BO
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class TradeOrderMessageWhenDeliveryOrderReqDTO {
|
||||
public class TradeOrderMessageWhenDeliveryOrderReqBO {
|
||||
|
||||
/**
|
||||
* 订单编号
|
@@ -5,6 +5,7 @@ import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.enums.TerminalEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
@@ -21,6 +22,7 @@ import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDT
|
||||
import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
|
||||
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi;
|
||||
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUpdateReqDTO;
|
||||
import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi;
|
||||
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO;
|
||||
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
|
||||
@@ -45,7 +47,7 @@ import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties
|
||||
import cn.iocoder.yudao.module.trade.service.cart.TradeCartService;
|
||||
import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService;
|
||||
import cn.iocoder.yudao.module.trade.service.message.TradeMessageService;
|
||||
import cn.iocoder.yudao.module.trade.service.message.dto.TradeOrderMessageWhenDeliveryOrderReqDTO;
|
||||
import cn.iocoder.yudao.module.trade.service.message.bo.TradeOrderMessageWhenDeliveryOrderReqBO;
|
||||
import cn.iocoder.yudao.module.trade.service.price.TradePriceService;
|
||||
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
|
||||
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
|
||||
@@ -173,9 +175,7 @@ public class TradeOrderServiceImpl implements TradeOrderService {
|
||||
if (equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) {
|
||||
MemberUserRespDTO user = memberUserApi.getUser(userId);
|
||||
// TODO 拼团一次应该只能选择一种规格的商品
|
||||
// TODO @puhui999:应该是前置校验哈;然后不应该设置状态,而是交给拼团记录那处理;
|
||||
combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, orderItems.get(0), createReqVO, user)
|
||||
.setStatus(CombinationRecordStatusEnum.WAITING.getStatus()));
|
||||
combinationRecordApi.createRecord(TradeOrderConvert.INSTANCE.convert(order, orderItems.get(0), createReqVO, user));
|
||||
}
|
||||
// TODO 秒杀扣减库存是下单就扣除还是等待订单支付成功再扣除
|
||||
if (equal(TradeOrderTypeEnum.SECKILL.getType(), order.getType())) {
|
||||
@@ -311,7 +311,8 @@ public class TradeOrderServiceImpl implements TradeOrderService {
|
||||
// 1、拼团活动
|
||||
if (equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) {
|
||||
// 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录
|
||||
combinationRecordApi.updateCombinationRecordStatusAndStartTime(order.getUserId(), order.getId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus());
|
||||
combinationRecordApi.updateRecordStatus(new CombinationRecordUpdateReqDTO().setUserId(order.getUserId())
|
||||
.setOrderId(order.getId()).setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()).setStartTime(LocalDateTime.now()));
|
||||
}
|
||||
// TODO 芋艿:发送订单变化的消息
|
||||
|
||||
@@ -394,11 +395,7 @@ public class TradeOrderServiceImpl implements TradeOrderService {
|
||||
// 2.1 快递发货
|
||||
if (equal(deliveryReqVO.getType(), DeliveryTypeEnum.EXPRESS.getMode())) {
|
||||
// 校验快递公司
|
||||
// TODO @puhui999:getDeliveryExpress 直接封装一个校验的,会不会好点;因为还有开启关闭啥的;
|
||||
DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId());
|
||||
if (deliveryExpress == null) {
|
||||
throw exception(EXPRESS_NOT_EXISTS);
|
||||
}
|
||||
validateDeliveryExpress(deliveryReqVO);
|
||||
updateOrderObj.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo());
|
||||
}
|
||||
// 2.2 用户自提
|
||||
@@ -425,13 +422,23 @@ public class TradeOrderServiceImpl implements TradeOrderService {
|
||||
// TODO 芋艿:发送订单变化的消息
|
||||
|
||||
// 发送站内信
|
||||
tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqDTO().setOrderId(order.getId())
|
||||
tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO().setOrderId(order.getId())
|
||||
.setUserId(userId).setMessage(TradeOrderDeliveryStatusEnum.DELIVERED.getName()));
|
||||
|
||||
// TODO 芋艿:OrderLog
|
||||
// TODO 设计:lili:是不是发货后,才支持售后?
|
||||
}
|
||||
|
||||
private void validateDeliveryExpress(TradeOrderDeliveryReqVO deliveryReqVO) {
|
||||
DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId());
|
||||
if (deliveryExpress == null) {
|
||||
throw exception(EXPRESS_NOT_EXISTS);
|
||||
}
|
||||
if (deliveryExpress.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) {
|
||||
throw exception(EXPRESS_STATUS_NOT_ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验交易订单满足被发货的条件
|
||||
*
|
||||
@@ -458,8 +465,7 @@ public class TradeOrderServiceImpl implements TradeOrderService {
|
||||
// 订单类型:拼团
|
||||
if (equal(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) {
|
||||
// 校验订单拼团是否成功
|
||||
// TODO 用户 ID 使用当前登录用户的还是订单保存的?
|
||||
if (combinationRecordApi.isCombinationRecordSuccess(order.getUserId(), order.getId())) {
|
||||
if (combinationRecordApi.isRecordSuccess(order.getUserId(), order.getId())) {
|
||||
throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user