|
@@ -49,8 +49,18 @@ import cn.newfeifan.mall.module.trade.service.price.TradePriceService;
|
|
|
import cn.newfeifan.mall.module.trade.service.price.bo.TradePriceCalculateReqBO;
|
|
|
import cn.newfeifan.mall.module.trade.service.price.bo.TradePriceCalculateRespBO;
|
|
|
import cn.newfeifan.mall.module.trade.service.price.calculator.TradePriceCalculatorHelper;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.gson.JsonObject;
|
|
|
+import com.kuaidi100.sdk.api.Subscribe;
|
|
|
+import com.kuaidi100.sdk.contant.ApiInfoConstant;
|
|
|
+import com.kuaidi100.sdk.core.IBaseClient;
|
|
|
+import com.kuaidi100.sdk.pojo.HttpResult;
|
|
|
+import com.kuaidi100.sdk.request.SubscribeParam;
|
|
|
+import com.kuaidi100.sdk.request.SubscribeParameters;
|
|
|
+import com.kuaidi100.sdk.request.SubscribeReq;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -67,6 +77,7 @@ 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 实现类
|
|
@@ -107,6 +118,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
@Resource
|
|
|
private TradeOrderProperties tradeOrderProperties;
|
|
|
|
|
|
+ @Value("${feifan.trade.express.kd100.key}")
|
|
|
+ private String key;
|
|
|
+
|
|
|
// =================== Order ===================
|
|
|
|
|
|
@Override
|
|
@@ -336,6 +350,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
public void deliveryOrder(TradeOrderDeliveryReqVO deliveryReqVO) {
|
|
|
// 1.1 校验并获得交易订单(可发货)
|
|
|
TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId());
|
|
|
+ order.setLogisticsId(deliveryReqVO.getLogisticsId());
|
|
|
+ order.setLogisticsNo(deliveryReqVO.getLogisticsNo());
|
|
|
// 1.2 校验 deliveryType 是否为快递,是快递才可以发货
|
|
|
if (ObjectUtil.notEqual(order.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getType())) {
|
|
|
throw exception(ORDER_DELIVERY_FAIL_DELIVERY_TYPE_NOT_EXPRESS);
|
|
@@ -352,9 +368,18 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
// 2.2 无需发货
|
|
|
updateOrderObj.setLogisticsId(0L).setLogisticsNo("");
|
|
|
}
|
|
|
+
|
|
|
+ try {
|
|
|
+ //发送订单订阅
|
|
|
+ testSubscribe(order);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
// 执行更新
|
|
|
updateOrderObj.setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()).setDeliveryTime(LocalDateTime.now());
|
|
|
int updateCount = tradeOrderMapper.updateByIdAndStatus(order.getId(), order.getStatus(), updateOrderObj);
|
|
|
+ TradeOrderDO tradeOrderDO = tradeOrderMapper.selectById(order.getId());
|
|
|
if (updateCount == 0) {
|
|
|
throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED);
|
|
|
}
|
|
@@ -369,6 +394,59 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
.setOrderId(order.getId()).setUserId(order.getUserId()).setMessage(null));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 订阅物流信息
|
|
|
+ *
|
|
|
+ * @param order 交易订单对象,包含物流信息和接收人手机号
|
|
|
+ * @throws Exception 抛出异常,可能由于外部服务调用失败等原因
|
|
|
+ */
|
|
|
+ private void testSubscribe(TradeOrderDO order) throws Exception {
|
|
|
+ // 根据物流ID获取配送信息
|
|
|
+ DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(order.getLogisticsId());
|
|
|
+
|
|
|
+ // 设置订阅参数,包括回调URL和手机号
|
|
|
+ SubscribeParameters subscribeParameters = new SubscribeParameters();
|
|
|
+ subscribeParameters.setCallbackurl("https://47.107.28.221:8001/admin-api/trade/order/callBackUrl?orderId=" + order.getId());
|
|
|
+ subscribeParameters.setPhone(order.getReceiverMobile());
|
|
|
+ //添加盐
|
|
|
+ subscribeParameters.setSalt(order.getLogisticsNo());
|
|
|
+
|
|
|
+ // 创建订阅参数实例,并设置相关公司代码、物流单号和密钥
|
|
|
+ SubscribeParam subscribeParam = new SubscribeParam();
|
|
|
+ subscribeParam.setParameters(subscribeParameters);
|
|
|
+ subscribeParam.setCompany(deliveryExpress.getCode());
|
|
|
+ subscribeParam.setNumber(order.getLogisticsNo());
|
|
|
+ subscribeParam.setKey(key);
|
|
|
+
|
|
|
+ // 构建订阅请求对象,设置请求模式和参数
|
|
|
+ SubscribeReq subscribeReq = new SubscribeReq();
|
|
|
+ subscribeReq.setSchema(ApiInfoConstant.SUBSCRIBE_SCHEMA);
|
|
|
+ subscribeReq.setParam(new Gson().toJson(subscribeParam));
|
|
|
+
|
|
|
+ // 调用订阅服务,并打印执行结果
|
|
|
+ IBaseClient subscribe = new Subscribe();
|
|
|
+ HttpResult execute = subscribe.execute(subscribeReq);
|
|
|
+
|
|
|
+ Gson gson = new Gson();
|
|
|
+ JsonObject jsonObject = gson.fromJson(execute.getBody(), JsonObject.class);
|
|
|
+ boolean result = jsonObject.get("result").getAsBoolean();
|
|
|
+ String returnCode = jsonObject.get("returnCode").getAsString();
|
|
|
+
|
|
|
+ if (result && returnCode.equals("200")) {
|
|
|
+ log.info("订单号:{}:订阅成功", order.getLogisticsNo());
|
|
|
+
|
|
|
+ order.setSubscriptionLogisticsInfo(TradeOrderSubscribeStatusEnum.SUBSCRIBE.getStatus());
|
|
|
+ } else if (returnCode.equals("600") || returnCode.equals("601")) {
|
|
|
+ throw exception(NOT_SUFFICIENT_FUNDS);
|
|
|
+ } else {
|
|
|
+ log.info("订单号:{}:订阅失败", order.getLogisticsNo());
|
|
|
+
|
|
|
+ order.setSubscriptionLogisticsInfo(TradeOrderSubscribeStatusEnum.abnormal.getStatus());
|
|
|
+ }
|
|
|
+ tradeOrderMapper.updateById(order);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 校验交易订单满足被发货的条件
|
|
|
* <p>
|
|
@@ -837,6 +915,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
cancelOrder0(order, TradeOrderCancelTypeEnum.MEMBER_CANCEL);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void updateOrderById(TradeOrderDO order) {
|
|
|
+ tradeOrderMapper.updateById(order);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 创建单个订单的评论
|
|
|
*
|