Browse Source

[add] 同城配送逻辑修改

BKGin 6 months ago
parent
commit
436bef86b7

+ 15 - 6
yiqi-admin/src/main/java/com/yiqi/admin/controller/core/SysStoreIntracityExpressController.java

@@ -5,15 +5,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.yiqi.app.domain.AppUser;
 import com.yiqi.app.service.IAppUserService;
+import com.yiqi.common.enums.*;
 import com.yiqi.common.exception.ServiceException;
 import com.yiqi.common.config.SystemEnvConfig;
 import com.yiqi.common.constant.UrlConstants;
 import com.yiqi.common.core.controller.BaseController;
 import com.yiqi.common.core.domain.R;
-import com.yiqi.common.enums.ClothOrderDeliveryType;
-import com.yiqi.common.enums.ClothOrderDeliveryWay;
-import com.yiqi.common.enums.ClothOrderStatusType;
-import com.yiqi.common.enums.SystemEnv;
 import com.yiqi.common.utils.DateUtils;
 import com.yiqi.common.utils.SecurityUtils;
 import com.yiqi.common.utils.StringUtils;
@@ -294,11 +291,22 @@ public class SysStoreIntracityExpressController extends BaseController {
                 }
                 break;
             }
+            case 30000:
+            case 40000:
+            case 50000:
+            {
+                if (orderDelivery.getClothOrderType().equals(ClothOrderDeliveryType.takeCloth.getCode())
+                        && orderCloth.getOrderStatus().equals(ClothOrderStatusType.WAITING_TO_SEND.getCode())) {
+                    orderClothService.update(new UpdateWrapper<OrderCloth>().lambda()
+                            .set(OrderCloth::getOrderStatus, ClothOrderStatusType.SENDING.getCode())
+                            .eq(OrderCloth::getId, orderCloth.getId()));
+                }
+                break;
+            }
             case 70000://配送完成
             {
                 if (orderDelivery.getClothOrderType().equals(ClothOrderDeliveryType.takeCloth.getCode())
-                        && (orderCloth.getOrderStatus().equals(ClothOrderStatusType.WAITING_TO_SEND.getCode())
-                        || orderCloth.getOrderStatus().equals(ClothOrderStatusType.SENDING.getCode()))) {
+                        && orderCloth.getOrderStatus().equals(ClothOrderStatusType.SENDING.getCode())) {
                     orderClothService.update(new UpdateWrapper<OrderCloth>().lambda()
                             .set(OrderCloth::getOrderStatus, ClothOrderStatusType.FINISH.getCode())
                             .eq(OrderCloth::getId, orderCloth.getId()));
@@ -307,6 +315,7 @@ public class SysStoreIntracityExpressController extends BaseController {
             }
         }
         orderDelivery.setDeliveryStatus(String.valueOf(intracityExpressOrderStatusChangeDTO.getOrder_status()));
+        orderDelivery.setDeliveryStatusMsg(OrderDeliveryStatusEnum.getLabelByCode(String.valueOf(intracityExpressOrderStatusChangeDTO.getOrder_status())));
         orderDeliveryService.updateById(orderDelivery);
         return new IntracityExpressOrderStatusChangeVO();
     }

+ 19 - 11
yiqi-admin/src/main/java/com/yiqi/admin/controller/order/OrderClothController.java

@@ -5,17 +5,12 @@ import cn.hutool.core.collection.CollUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.yiqi.app.domain.*;
+import com.yiqi.app.service.*;
+import com.yiqi.common.core.domain.AuthHolder;
 import com.yiqi.common.exception.ServiceException;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.yiqi.app.domain.AppDeliveryMan;
-import com.yiqi.app.domain.AppDeliveryRelation;
-import com.yiqi.app.domain.AppUser;
-import com.yiqi.app.domain.AppUserBillMstr;
 import com.yiqi.app.domain.vo.AppUserInfoVO;
-import com.yiqi.app.service.IAppDeliveryManService;
-import com.yiqi.app.service.IAppDeliveryRelationService;
-import com.yiqi.app.service.IAppUserBillMstrService;
-import com.yiqi.app.service.IAppUserService;
 import com.yiqi.common.annotation.Log;
 import com.yiqi.common.constant.UrlConstants;
 import com.yiqi.common.core.controller.BaseController;
@@ -29,6 +24,7 @@ import com.yiqi.common.utils.poi.ExcelUtil;
 import com.yiqi.core.domain.dto.wx.IntracityExpressAddOrderRequest;
 import com.yiqi.core.domain.vo.ClothHangerOrderRelationVO;
 import com.yiqi.core.domain.vo.wx.IntracityExpressBaseResult;
+import com.yiqi.core.domain.vo.wx.IntracityExpressCreateOrderResult;
 import com.yiqi.core.service.ISysStoreIntracityExpressService;
 import com.yiqi.order.domain.OrderCloth;
 import com.yiqi.order.domain.OrderClothItem;
@@ -100,6 +96,8 @@ public class OrderClothController extends BaseController {
     private IThirdDeliveryService thirdDeliveryService;
     @Autowired
     private IManageFactoryService manageFactoryService;
+    @Autowired
+    private IAppUserAddressService appUserAddressService;
 
     @PreAuthorize("@ss.hasPermi('order:cloth:selectOrg')")
     @Transactional(rollbackFor = Exception.class)
@@ -305,19 +303,29 @@ public class OrderClothController extends BaseController {
                 if (orderDelivery == null) {
                     throw new ServiceException("未查询到配送信息");
                 }
-                orderDelivery.setDeliverySn(orderNoUtils.getDeliveryOrderNo());
+                // 设置未同城配送订单
                 orderDelivery.setDeliveryWay(ClothOrderDeliveryWay.intracityExpress.getCode());
-                orderDeliveryService.updateById(orderDelivery);
+
                 if (!ClothTakeWay.DELIVERY.getCode().equals(orderCloth.getSendClothWay())) {
                     throw new ServiceException("该订单客户未选择送货上门,无法分配配送员");
                 }
                 AppUser appUser = appUserService.getOne(new QueryWrapper<AppUser>().lambda().eq(AppUser::getId, orderCloth.getAppUserId()));
-                IntracityExpressBaseResult result = sysStoreIntracityExpressService
+                IntracityExpressCreateOrderResult result = sysStoreIntracityExpressService
                         .addOrder(IntracityExpressAddOrderRequest
                                 .build(orderCloth, orderDelivery, sysStore, appUser.getWxOpenId()));
+                // 更新订单状态
                 orderClothService.update(new UpdateWrapper<OrderCloth>().lambda()
                         .eq(OrderCloth::getId, orderCloth.getId())
                         .set(OrderCloth::getOrderStatus, ClothOrderStatusType.SENDING.getCode()));
+                // 更新配送单状态
+                orderDelivery.setDistance(String.valueOf(result.getDistance()));
+                // 金额 分 -> 元
+                orderDelivery.setFee(BigDecimal.valueOf(result.getFee()).divide(BigDecimal.valueOf(100), 2));
+                orderDelivery.setFetchCode(result.getFetch_code());
+                orderDelivery.setServiceTransId(result.getService_trans_id());
+                orderDelivery.setTransOrderId(result.getTrans_order_id());
+                orderDeliveryService.updateById(orderDelivery);
+
                 if (result.getErrcode() != 0) {
                     throw new ServiceException("errorCode:" + result.getErrcode() + ";errorMsg:" + result.getErrmsg());
                 }

+ 8 - 0
yiqi-api/src/main/java/com/yiqi/api/controller/order/WeAppOrderClothController.java

@@ -186,6 +186,14 @@ public class WeAppOrderClothController {
                 || ClothOrderType.thirdPart.getCode().equals(orderCloth.getOrderType())){
         }
         orderClothService.save(orderCloth);
+        // 预创建配送单
+        OrderDelivery orderDelivery = new OrderDelivery(appUserAddress);
+        orderDelivery.setDeliverySn(orderNoUtils.getDeliveryOrderNo());
+        orderDelivery.setOrderSn(orderCloth.getOrderNo());
+        orderDelivery.setClothOrderType(ClothOrderDeliveryType.collectCloth.getCode());
+        orderDelivery.setCreateTime(DateUtils.getNowDate());
+        orderDelivery.setDeliveryStatus(OrderDeliveryStatusEnum.ORIGIN_STATUS.getCode());
+        orderDeliveryService.save(orderDelivery);
         return R.ok();
     }
 

+ 10 - 0
yiqi-common/src/main/java/com/yiqi/common/enums/OrderDeliveryStatusEnum.java

@@ -7,6 +7,7 @@ package com.yiqi.common.enums;
  */
 public enum OrderDeliveryStatusEnum {
 
+    ORIGIN_STATUS("0", "订单初始化"),
     CREATE_ORDER_SUCCESS("10000", "订单创建成功"),
     STORE_CANCEL("20000", "商家取消订单"),
     DELIVERY_CANCEL("20001", "配送方取消订单"),
@@ -34,4 +35,13 @@ public enum OrderDeliveryStatusEnum {
         return label;
     }
 
+    public static String getLabelByCode(String code) {
+        for (OrderDeliveryStatusEnum item : OrderDeliveryStatusEnum.values()) {
+            if (item.getCode().equals(code)) {
+                return item.getLabel();
+            }
+        }
+        return "";
+    }
+
 }

+ 63 - 0
yiqi-common/src/main/java/com/yiqi/core/domain/vo/wx/IntracityExpressCreateOrderResult.java

@@ -0,0 +1,63 @@
+package com.yiqi.core.domain.vo.wx;
+
+import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * @Author BKGin
+ * @Email libra14xu@gmail.com
+ * @Date 2024-09-10
+ */
+@Data
+public class IntracityExpressCreateOrderResult extends IntracityExpressBaseResult {
+
+
+    /**
+     * 微信门店编号
+     */
+    private String wx_store_id;
+    /**
+     * 微信订单编号
+     */
+    private String wx_order_id;
+    /**
+     * 门店订单编号
+     */
+    private String store_order_id;
+    /**
+     * 配送运力
+     */
+    private String service_trans_id;
+    /**
+     * 运力订单号
+     */
+    private String trans_order_id;
+    /**
+     * 运力配送单号
+     */
+    private String waybill_id;
+
+    /**
+     * 配送距离 单位:米
+     */
+    private Long distance;
+    /**
+     * 配送费 单位:分
+     */
+    private Long fee;
+    /**
+     * 取货码
+     */
+    private String fetch_code;
+    /**
+     * 取货序号
+     */
+    private String order_seq;
+
+    public static IntracityExpressCreateOrderResult fromJson(String json) {
+        return WxMaGsonBuilder.create().fromJson(json, IntracityExpressCreateOrderResult.class);
+    }
+
+}

+ 1 - 1
yiqi-common/src/main/java/com/yiqi/core/service/ISysStoreIntracityExpressService.java

@@ -68,7 +68,7 @@ public interface ISysStoreIntracityExpressService {
      * @return
      * @throws Exception
      */
-    public IntracityExpressBaseResult addOrder(IntracityExpressAddOrderRequest request) throws Exception;
+    public IntracityExpressCreateOrderResult addOrder(IntracityExpressAddOrderRequest request) throws Exception;
 
     public IntracityExpressBaseResult cancelOrder(IntracityExpressCancelOrderRequest request ) throws Exception;
 

+ 2 - 2
yiqi-core/src/main/java/com/yiqi/core/service/impl/SysStoreIntracityExpressServiceImpl.java

@@ -105,8 +105,8 @@ public class SysStoreIntracityExpressServiceImpl implements ISysStoreIntracityEx
     }
 
     @Override
-    public IntracityExpressBaseResult addOrder(IntracityExpressAddOrderRequest request) throws Exception {
-        IntracityExpressBaseResult result = IntracityExpressBaseResult
+    public IntracityExpressCreateOrderResult addOrder(IntracityExpressAddOrderRequest request) throws Exception {
+        IntracityExpressCreateOrderResult result = IntracityExpressCreateOrderResult
                 .fromJson(httpPost("https://api.weixin.qq.com/cgi-bin/express/intracity/addorder"
                         , request.toJson()));
         return result;