|
@@ -11,6 +11,7 @@ import cn.newfeifan.mall.framework.common.core.KeyValue;
|
|
|
import cn.newfeifan.mall.framework.common.enums.UserTypeEnum;
|
|
|
import cn.newfeifan.mall.framework.common.util.json.JsonUtils;
|
|
|
import cn.newfeifan.mall.framework.common.util.number.MoneyUtils;
|
|
|
+import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
|
import cn.newfeifan.mall.module.member.api.address.MemberAddressApi;
|
|
|
import cn.newfeifan.mall.module.member.api.address.dto.MemberAddressRespDTO;
|
|
|
import cn.newfeifan.mall.module.pay.api.order.PayOrderApi;
|
|
@@ -80,7 +81,6 @@ import static cn.newfeifan.mall.framework.common.util.date.LocalDateTimeUtils.mi
|
|
|
import static cn.newfeifan.mall.framework.common.util.servlet.ServletUtils.getClientIP;
|
|
|
import static cn.newfeifan.mall.framework.web.core.util.WebFrameworkUtils.getTerminal;
|
|
|
import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.*;
|
|
|
-import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.NOT_SUFFICIENT_FUNDS;
|
|
|
|
|
|
/**
|
|
|
* 交易订单【写】Service 实现类
|
|
@@ -353,12 +353,19 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@TradeOrderLog(operateType = TradeOrderOperateTypeEnum.ADMIN_DELIVERY)
|
|
|
public void deliveryOrder(TradeOrderDeliveryReqVO deliveryReqVO) {
|
|
|
+ //校验发货信息不能都为空
|
|
|
+ if (deliveryReqVO.getLogisticsNo() == null && deliveryReqVO.getAttachment() == null) {
|
|
|
+ throw exception(ORDER_DELIVERY_DETAILS_IS_NULL);
|
|
|
+ }
|
|
|
+
|
|
|
// 1.1 校验并获得交易订单(可发货)
|
|
|
TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId());
|
|
|
order.setLogisticsId(deliveryReqVO.getLogisticsId());
|
|
|
order.setLogisticsNo(deliveryReqVO.getLogisticsNo());
|
|
|
+ order.setAttachment(deliveryReqVO.getAttachment());
|
|
|
+ order.setDeliveryRemark(deliveryReqVO.getDeliveryRemark());
|
|
|
// 1.2 校验 deliveryType 是否为快递,是快递才可以发货
|
|
|
- if (ObjectUtil.notEqual(order.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getType())) {
|
|
|
+ if (ObjectUtil.notEqual(order.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getType()) && ObjectUtil.notEqual(order.getDeliveryType(), DeliveryTypeEnum.VIRTUAL_PRODUCT.getType())) {
|
|
|
throw exception(ORDER_DELIVERY_FAIL_DELIVERY_TYPE_NOT_EXPRESS);
|
|
|
}
|
|
|
|
|
@@ -366,7 +373,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
TradeOrderDO updateOrderObj = new TradeOrderDO();
|
|
|
// 2.1 快递发货
|
|
|
DeliveryExpressDO express = null;
|
|
|
- if (ObjectUtil.notEqual(deliveryReqVO.getLogisticsId(), TradeOrderDO.LOGISTICS_ID_NULL)) {
|
|
|
+ if (ObjectUtil.notEqual(deliveryReqVO.getLogisticsId(), TradeOrderDO.LOGISTICS_ID_NULL) && deliveryReqVO.getLogisticsId() != null) {
|
|
|
express = deliveryExpressService.validateDeliveryExpress(deliveryReqVO.getLogisticsId());
|
|
|
updateOrderObj.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo());
|
|
|
} else {
|
|
@@ -376,13 +383,25 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
|
|
|
try {
|
|
|
//发送订单订阅
|
|
|
- subscribe(order);
|
|
|
+ if (deliveryReqVO.getLogisticsId() != null && deliveryReqVO.getLogisticsNo() != null) {
|
|
|
+ subscribe(order);
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
|
|
|
// 执行更新
|
|
|
- updateOrderObj.setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()).setDeliveryTime(LocalDateTime.now());
|
|
|
+ if (deliveryReqVO.getAttachment() != null) {
|
|
|
+ //如果是虚拟商品直接完成发货和签收
|
|
|
+ updateOrderObj.setStatus(TradeOrderStatusEnum.COMPLETED.getStatus()).setDeliveryTime(LocalDateTime.now()).setReceivingTime(LocalDateTime.now());
|
|
|
+ TradeOrderItemDO tradeOrderItemDO = tradeOrderItemMapper.selectOne(new LambdaQueryWrapperX<TradeOrderItemDO>()
|
|
|
+ .eq(TradeOrderItemDO::getOrderId, order.getId())
|
|
|
+ );
|
|
|
+ tradeOrderItemDO.setDistributeBenefit(true);
|
|
|
+ tradeOrderItemMapper.updateById(tradeOrderItemDO);
|
|
|
+ } else {
|
|
|
+ updateOrderObj.setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()).setDeliveryTime(LocalDateTime.now());
|
|
|
+ }
|
|
|
int updateCount = tradeOrderMapper.updateByIdAndStatus(order.getId(), order.getStatus(), updateOrderObj);
|
|
|
if (updateCount == 0) {
|
|
|
throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED);
|
|
@@ -399,13 +418,18 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
//5.发送微信模板消息
|
|
|
List<String> params = new ArrayList<>();
|
|
|
params.add(order.getNo());
|
|
|
- params.add(deliveryExpressService.getDeliveryNameById(order.getLogisticsId()));
|
|
|
- params.add(order.getLogisticsNo());
|
|
|
+ if (deliveryReqVO.getAttachment() != null) {
|
|
|
+ params.add("无");
|
|
|
+ params.add("-");
|
|
|
+ }else{
|
|
|
+ params.add(deliveryExpressService.getDeliveryNameById(order.getLogisticsId()));
|
|
|
+ params.add(order.getLogisticsNo());
|
|
|
+ }
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
params.add(LocalDateTime.now().format(formatter));
|
|
|
params.add(tradeOrderItemMapper.getSupNameByOrderId(order.getId()));
|
|
|
- wcChatMessageUtils.sendWcChatMessage(order.getUserId(), WcChatMessageTemplateIdEnum.ORDER_DELIVERY.getTemplateId(),
|
|
|
- params, null,order.getUserId(), order.getId());
|
|
|
+ wcChatMessageUtils.sendWcChatMessage(order.getUserId(), WcChatMessageTemplateIdEnum.ORDER_DELIVERY2.getTemplateId(),
|
|
|
+ params, null, order.getUserId(), order.getId());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -420,7 +444,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
|
|
|
// 设置订阅参数,包括回调URL和手机号
|
|
|
SubscribeParameters subscribeParameters = new SubscribeParameters();
|
|
|
- subscribeParameters.setCallbackurl("http://47.107.28.221:8001/admin-api/trade/order/callBackUrl?orderId="+order.getId());
|
|
|
+ subscribeParameters.setCallbackurl("http://47.107.28.221:8001/admin-api/trade/order/callBackUrl?orderId=" + order.getId());
|
|
|
subscribeParameters.setPhone(order.getReceiverMobile());
|
|
|
//添加盐
|
|
|
subscribeParameters.setSalt(order.getLogisticsNo());
|
|
@@ -447,13 +471,13 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
String returnCode = jsonObject.get("returnCode").getAsString();
|
|
|
|
|
|
if (result && returnCode.equals("200")) {
|
|
|
- log.info("订单号:{}:订阅成功",order.getNo());
|
|
|
+ log.info("订单号:{}:订阅成功", order.getNo());
|
|
|
|
|
|
order.setSubscriptionLogisticsInfo(TradeOrderSubscribeStatusEnum.SUBSCRIBE.getStatus());
|
|
|
- } else if(returnCode.equals("600") || returnCode.equals("601")) {
|
|
|
+ } else if (returnCode.equals("600") || returnCode.equals("601")) {
|
|
|
throw exception(NOT_SUFFICIENT_FUNDS);
|
|
|
} else {
|
|
|
- log.info("订单号:{}:订阅失败原因:{}",order.getNo(),jsonObject);
|
|
|
+ log.info("订单号:{}:订阅失败原因:{}", order.getNo(), jsonObject);
|
|
|
|
|
|
order.setSubscriptionLogisticsInfo(TradeOrderSubscribeStatusEnum.abnormal.getStatus());
|
|
|
}
|