From eb7a808aaf7dd0a6dd2ff70f9ef3f8ce0b1e31d1 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期五, 22 五月 2026 18:27:32 +0800
Subject: [PATCH] Merge branch 'master' of http://139.186.142.91:10010/r/productDev/gtzxinglijicun

---
 server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java |  223 ++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 146 insertions(+), 77 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java
index 6269a48..06fe53c 100644
--- a/server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java
+++ b/server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java
@@ -236,10 +236,12 @@
                 .selectAll(Orders.class)
                 .selectAs(Category::getDetail, Orders::getOrderLevel)
                 .select("s1.name", Orders::getDepositShopName)
-                .leftJoin(Category.class, Category::getId, Orders::getGoodType)
+                .select("o2.code", Orders::getRelationOrderCode)
+                .leftJoin(Category.class, Category::getId, Orders::getGoodLevel)
                 .leftJoin(DriverInfo.class, DriverInfo::getId, Orders::getAcceptDriver)
                 .leftJoin("shop_info s1 on s1.id = t.DEPOSIT_SHOP_ID")
-                .leftJoin("shop_info s2 on s2.id = t.TAKE_SHOP_ID") ;
+                .leftJoin("shop_info s2 on s2.id = t.TAKE_SHOP_ID")
+                .leftJoin("orders o2 on o2.id = t.RELATION_ORDER_ID")
                 ;
         Utils.MP.blankToNull(pageWrap.getModel());
         queryWrapper.eq(pageWrap.getModel().getDeleted() != null, Orders::getDeleted, pageWrap.getModel().getDeleted());
@@ -348,7 +350,7 @@
     }
 
     /**
-     * 璁$畻灏卞湴瀛樺彇棰勪及璐圭敤
+     * 璁$畻灏卞湴瀵勫瓨棰勪及璐圭敤
      *
      * 璁$畻瑙勫垯锛�
      * 1. 鏍规嵁鍩庡競+鐗╁搧绫诲瀷 鏌ヨ pricing_rule(type=0)锛宖ieldA=categoryId, fieldB=鍗曚环(鍒�/澶�)
@@ -357,7 +359,7 @@
      * 4. 淇濅环璐圭敤 = 鎶ヤ环閲戦 脳 淇濅环璐圭巼锛堝瓧鍏� INSURANCE_RATE锛夛紝鍏冭浆鍒�
      * 5. 鎬讳环鏍� = 鐗╁搧浠锋牸 + 淇濅环璐圭敤
      *
-     * @param dto 灏卞湴瀛樺彇璁′环璇锋眰鍙傛暟
+     * @param dto 灏卞湴瀵勫瓨璁′环璇锋眰鍙傛暟
      * @return 浠锋牸璁$畻缁撴灉
      */
     @Override
@@ -447,7 +449,7 @@
     }
 
     /**
-     * 璁$畻寮傚湴瀛樺彇棰勪及璐圭敤
+     * 璁$畻鍚屽煄瀵勯�侀浼拌垂鐢�
      *
      * 璁$畻瑙勫垯锛�
      * 1. 璋冪敤鑵捐鍦板浘API璁$畻瀵勪欢鐐逛笌鍙栦欢鐐圭殑椹捐溅璺濈(绫斥啋鍏噷)
@@ -462,7 +464,7 @@
      * 7. 鍔犳�ヨ垂鐢� = 鐗╁搧浠锋牸 脳 鍔犳�ョ郴鏁帮紙瀛楀吀 URGENT_COEFFICIENT锛�
      * 8. 鎬讳环鏍� = 鐗╁搧浠锋牸 + 淇濅环璐圭敤 + 鍔犳�ヨ垂鐢�
      *
-     * @param dto 寮傚湴瀛樺彇璁′环璇锋眰鍙傛暟
+     * @param dto 鍚屽煄瀵勯�佽浠疯姹傚弬鏁�
      * @return 浠锋牸璁$畻缁撴灉
      */
     @Override
@@ -499,7 +501,7 @@
             ruleMap.put(r.getFieldA(), r);
         }
 
-        // 鏌ヨ灏卞湴瀛樺彇璁′环瑙勫垯 pricing_rule type=0锛岀敤浜庤幏鍙� locallyPrice
+        // 鏌ヨ灏卞湴瀵勫瓨璁′环瑙勫垯 pricing_rule type=0锛岀敤浜庤幏鍙� locallyPrice
         List<PricingRule> localRules = pricingRuleMapper.selectList(new QueryWrapper<PricingRule>().lambda()
                 .eq(PricingRule::getDeleted, Constants.ZERO)
                 .eq(PricingRule::getType, Constants.ZERO)
@@ -553,7 +555,7 @@
 
             long subtotal = unitPrice * item.getQuantity();
 
-            // 灏卞湴瀛樺彇鍗曚环
+            // 灏卞湴瀵勫瓨鍗曚环
             PricingRule localRule = localRuleMap.get(String.valueOf(item.getCategoryId()));
             Long locallyPrice = localRule != null ? Long.parseLong(localRule.getFieldB()) : null;
 
@@ -812,7 +814,7 @@
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "璇烽�夋嫨鍙栦欢搴楅摵鎴栬緭鍏ヨ嚜閫夊彇浠跺湴鍧�");
             }
         } else {
-            // 灏卞湴瀛樺彇锛氬彇浠堕棬搴楀悓瀵勪欢闂ㄥ簵
+            // 灏卞湴瀵勫瓨锛氬彇浠堕棬搴楀悓瀵勪欢闂ㄥ簵
             takeShop = depositShop;
         }
 
@@ -862,6 +864,7 @@
         orders.setPayStatus(Constants.ZERO); // 鏈敮浠�
         orders.setCommentStatus(Constants.ZERO); // 鏈瘎浠�
         orders.setSettlementStatus(Constants.ZERO); // 鏈粨绠�
+        orders.setExceptionStatus(Constants.ZERO); // 闈炲紓甯�
         orders.setDeleted(Constants.ZERO);
         orders.setCreateTime(now);
         orders.setUpdateTime(now);
@@ -1283,7 +1286,7 @@
         vo.setCode(order.getCode());
         vo.setPayAmountYuan(order.getPayAmount() != null ? Constants.getFormatMoney(order.getPayAmount()) : 0);
         vo.setType(order.getType());
-        vo.setTypeDesc(order.getType() != null && order.getType() == Constants.ONE ? "寮傚湴瀛樺彇" : "灏卞湴瀛樺彇");
+        vo.setTypeDesc(order.getType() != null && order.getType() == Constants.ONE ? "鍚屽煄瀵勯��" : "灏卞湴瀵勫瓨");
         vo.setDetailList(buildDetailList(id));
 
         return vo;
@@ -1302,9 +1305,9 @@
             throw new BusinessException(ResponseStatus.DATA_EMPTY);
         }
 
-        // 鍓嶇疆鏉′欢鏍¢獙锛氬紓鍦板瓨鍙� + 宸插瘎瀛�
+        // 鍓嶇疆鏉′欢鏍¢獙锛氬悓鍩庡瘎閫� + 宸插瘎瀛�
         if (!Constants.ONE.equals(order.getType())) {
-            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "浠呮敮鎸佸紓鍦板瓨鍙栬鍗曟淳鍗�");
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "浠呮敮鎸佸悓鍩庡瘎閫佽鍗曟淳鍗�");
         }
         if (!Integer.valueOf(Constants.OrderStatus.deposited.getStatus()).equals(order.getStatus())) {
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "浠呭凡瀵勫瓨鐘舵�佽鍗曞彲娲惧崟");
@@ -1534,7 +1537,7 @@
      *
      * @param orders        璁㈠崟瀹炰綋锛堥渶瑕� totalAmount銆乧ityId 宸茶缃級
      * @param depositShop   瀵勪欢闂ㄥ簵锛堥渶瑕� companyType锛�
-     * @param takeShop      鍙栦欢闂ㄥ簵锛堥渶瑕� companyType锛屽氨鍦板瓨鍙栨椂涓� depositShop 鐩稿悓锛�
+     * @param takeShop      鍙栦欢闂ㄥ簵锛堥渶瑕� companyType锛屽氨鍦板瘎瀛樻椂涓� depositShop 鐩稿悓锛�
      */
     private void calculateAndSetFeeAllocation(Orders orders, ShopInfo depositShop, ShopInfo takeShop) {
         Long totalAmount = orders.getTotalAmount() != null ? orders.getTotalAmount() : 0L;
@@ -1746,8 +1749,13 @@
 
                 // 璇勪环鐘舵��
                 vo.setCommentStatus(o.getCommentStatus());
+
+                String dateStr = new SimpleDateFormat("dd").format(o.getPayTime() != null ? o.getPayTime() : new Date());
+                String autoNumStr = String.format("%03d", o.getAutoNum() != null ? o.getAutoNum() : 0);
+                String sort = o.getDepositShopId() + "-" + dateStr + "-" + autoNumStr;
                 //搴忓彿
-                vo.setSortnum(Constants.formatIntegerNum(o.getDepositShopId())+"-"+o.getId());
+                vo.setSortnum(sort);
+
                 if(o.getTakeShopId()!=null){
                     vo.setSortnumTake(Constants.formatIntegerNum(o.getTakeShopId())+"-"+o.getId());
                 }
@@ -2164,6 +2172,10 @@
             throw new BusinessException(ResponseStatus.DATA_EMPTY);
         }
 
+        if (Constants.equalsInteger(order.getExceptionStatus(), Constants.ONE)) {
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "寮傚父璁㈠崟鏃犳硶鍙栨秷");
+        }
+
         Integer status = order.getStatus();
         if (status == null) {
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "璁㈠崟鐘舵�佸紓甯�");
@@ -2199,8 +2211,6 @@
                     "orderNo", order.getCode());
             // 鐭俊閫氱煡浼氬憳锛氳鍗曞凡鍙栨秷
             Member cancelMember2 = memberMapper.selectById(memberId);
-            sendSmsNotify(cancelMember2 != null ? cancelMember2.getTelephone() : null,
-                    Constants.SmsNotify.MEMBER_CANCELLED, "orderNo", order.getCode());
 
             // 璋冪敤寰俊閫�娆綱3锛屽叏棰濋��娆�
             String outRefundNo = ID.nextGUID();
@@ -2238,6 +2248,8 @@
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "閫�娆惧け璐ワ紝璇疯仈绯诲鏈嶅鐞�");
             }
             ordersRefundMapper.insert(refund);
+            sendSmsNotify(cancelMember2 != null ? cancelMember2.getTelephone() : null,
+                    Constants.SmsNotify.MEMBER_CANCELLED, "orderNo", order.getCode());
             restoreCoupon(order);
             return;
         }
@@ -2406,9 +2418,10 @@
         if (Constants.equalsInteger(order.getManualRefund(), Constants.ONE)) {
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "璇ヨ鍗曞凡鎵嬪姩閫�娆�");
         }
-        // 寮傚父璁㈠崟涓嶅厑璁告墜鍔ㄩ��娆�
-        if (Constants.equalsInteger(order.getExceptionStatus(), Constants.ONE)) {
-            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "寮傚父璁㈠崟涓嶆敮鎸佹墜鍔ㄩ��娆�");
+        // 灏卞湴瀵勫瓨寮傚父璁㈠崟涓嶅厑璁告墜鍔ㄩ��娆�
+        if (Constants.equalsInteger(order.getExceptionStatus(), Constants.ONE)
+                && Constants.equalsInteger(order.getType(), Constants.ZERO)) {
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "灏卞湴瀵勫瓨寮傚父璁㈠崟涓嶆敮鎸佹墜鍔ㄩ��娆�");
         }
 
         // 2. 鏍¢獙閫�娆鹃噾棰�
@@ -2851,13 +2864,27 @@
         if (otherOrders.getOrderId() != null) {
             Orders order = ordersMapper.selectById(otherOrders.getOrderId());
             if (order != null) {
-                order.setOverdueStatus(Constants.TWO); // 2=宸叉敮浠�
-                // 鎬婚噾棰� = 鍘熼噾棰� + 閫炬湡璐圭敤
                 Long overdueFee = otherOrders.getPayAccount() != null ? otherOrders.getPayAccount() : 0L;
                 long newTotal = (order.getTotalAmount() != null ? order.getTotalAmount() : 0L) + overdueFee;
+
+                // 寮傚父灏卞湴瀵勫瓨璁㈠崟锛氬悓鏃舵洿鏂颁富璁㈠崟瀹為檯閫炬湡璐圭敤
+                boolean isAbnormal = Constants.equalsInteger(order.getExceptionStatus(), Constants.ONE)
+                        && Constants.equalsInteger(order.getType(), Constants.ZERO);
+                if(isAbnormal){
+                    long shopException = isAbnormal ? (order.getShopCompensationAmount() != null ? order.getShopCompensationAmount() : 0L) : 0L;
+                    long driverException = isAbnormal ? (order.getExceptionFee() != null ? order.getExceptionFee() : 0L) : 0L;
+                    long actualOverdueFee = isAbnormal ? (overdueFee - shopException - driverException) : 0L;
+                    if(actualOverdueFee!=order.getOverdueAmount()){
+                        order.setOverdueAmount(actualOverdueFee);
+                    }
+                }
+
+                order.setOverdueStatus(Constants.TWO); // 2=宸叉敮浠�
                 order.setTotalAmount(newTotal);
                 order.setUpdateTime(now);
                 ordersMapper.updateById(order);
+
+
                 // 閲嶇畻涓夋柟鏀剁泭
                 calculateAndSaveOrderFees(order.getId());
             }
@@ -3348,6 +3375,37 @@
             }
             // 瀵勫瓨鎴愬姛璧犻�佷紭鎯犲埜
             giftOrderCoupon(order.getMemberId());
+            // 寮傚父璁㈠崟瀵勫瓨鏍搁攢锛氭爣璁板師璁㈠崟瀹屾垚
+            if (Constants.equalsInteger(order.getExceptionStatus(), Constants.ONE) && order.getRelationOrderId() != null) {
+                Orders originalOrder = ordersMapper.selectById(order.getRelationOrderId());
+                if (originalOrder != null) {
+                    originalOrder.setStatus(Constants.OrderStatus.finished.getStatus());
+                    originalOrder.setInvoiceStatus(Constants.ONE);
+                    originalOrder.setSettlementStatus(Constants.ZERO);
+                    originalOrder.setFinishTime(now);
+                    originalOrder.setUpdateTime(now);
+                    ordersMapper.updateById(originalOrder);
+                    // 瑙﹀彂鍘熻鍗曟敹鐩婅绠�
+                    calculateAndSaveOrderFees(originalOrder.getId());
+                    generateRevenueRecords(originalOrder.getId());
+                    // 璁板綍鍘熻鍗曟棩蹇�
+                    saveShopVerifyLog(originalOrder, Constants.OrderLogType.shopTake, "寮傚父璁㈠崟鏍搁攢锛屽師璁㈠崟瀹屾垚", remark, shopId);
+                    // 閫氱煡浼氬憳锛氳鍗曞凡瀹屾垚
+                    sendOrderNotice(originalOrder.getMemberId(), Constants.MemberOrderNotify.FINISHED, originalOrder.getId(),
+                            "orderNo", originalOrder.getCode());
+                    // 閫氱煡瀛樹欢闂ㄥ簵鍜屽彇浠堕棬搴�
+                    String settleDays = operationConfigBiz.getConfig().getSettlementDate();
+                    notifyBothShops(originalOrder, Constants.ShopOrderNotify.FINISHED,
+                            "orderNo", originalOrder.getCode(),
+                            "settleDays", settleDays != null ? settleDays : "7");
+                    // 閫氱煡鍙告満锛氳鍗曞凡瀹屾垚
+                    if (originalOrder.getAcceptDriver() != null) {
+                        sendDriverNotice(originalOrder.getAcceptDriver(), Constants.DriverOrderNotify.FINISHED, originalOrder.getId(),
+                                "orderNo", originalOrder.getCode(),
+                                "settleDays", settleDays != null ? settleDays : "7");
+                    }
+                }
+            }
         } else if (Constants.equalsInteger(status, Constants.OrderStatus.arrived.getStatus())) {
             // 寮傚湴瀵勫瓨 + 鏃犲彇浠堕棬搴� 鈫� 鏃犳硶鏍搁攢锛堝鎴疯嚜鍙栵紝鏃犻棬搴楁搷浣滐級
             if (Constants.equalsInteger(order.getType(), Constants.ONE) && order.getTakeShopId() == null) {
@@ -3516,30 +3574,7 @@
                 sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.WAIT_PICKUP_REMIND, order.getId(),
                         "orderNo", order.getCode(), "shopName", shopName);
             }
-            // 寮傚父璁㈠崟瀵勫瓨鏍搁攢锛氭爣璁板師璁㈠崟瀹屾垚
-            if (Constants.equalsInteger(order.getExceptionStatus(), Constants.ONE) && order.getRelationOrderId() != null) {
-                Orders originalOrder = ordersMapper.selectById(order.getRelationOrderId());
-                if (originalOrder != null) {
-                    originalOrder.setStatus(Constants.OrderStatus.finished.getStatus());
-                    originalOrder.setInvoiceStatus(Constants.ONE);
-                    originalOrder.setFinishTime(now);
-                    originalOrder.setUpdateTime(now);
-                    ordersMapper.updateById(originalOrder);
-                    // 瑙﹀彂鍘熻鍗曟敹鐩婅绠�
-                    calculateAndSaveOrderFees(originalOrder.getId());
-                    generateRevenueRecords(originalOrder.getId());
-                    // 閫氱煡浼氬憳锛氳鍗曞凡瀹屾垚
-                    sendOrderNotice(originalOrder.getMemberId(), Constants.MemberOrderNotify.FINISHED, originalOrder.getId(),
-                            "orderNo", originalOrder.getCode());
-                    // 閫氱煡鍙告満锛氳鍗曞凡瀹屾垚
-                    if (originalOrder.getAcceptDriver() != null) {
-                        String settleDays = operationConfigBiz.getConfig().getSettlementDate();
-                        sendDriverNotice(originalOrder.getAcceptDriver(), Constants.DriverOrderNotify.FINISHED, originalOrder.getId(),
-                                "orderNo", originalOrder.getCode(),
-                                "settleDays", settleDays != null ? settleDays : "7");
-                    }
-                }
-            }
+
         } else if (Constants.equalsInteger(status, Constants.OrderStatus.arrived.getStatus())) {
             // 寮傚湴瀵勫瓨 + 鏃犲彇浠堕棬搴� 鈫� 鏃犳硶鏍搁攢锛堝鎴疯嚜鍙栵紝鏃犻棬搴楁搷浣滐級
             if (Constants.equalsInteger(order.getType(), Constants.ONE) && order.getTakeShopId() == null) {
@@ -3767,13 +3802,17 @@
         }
 
         Long totalAmount = order.getTotalAmount() != null ? order.getTotalAmount() : 0L;
+        Long shopCompensationAmount = order.getShopCompensationAmount() != null ? order.getShopCompensationAmount() : 0L;
+        Long exceptionFee = order.getExceptionFee() != null ? order.getExceptionFee() : 0L;
+        // 鍒嗘垚鍩烘暟 = 鎬婚噾棰� - 闂ㄥ簵寮傚父閲戦 - 鍙告満寮傚父閲戦
+        Long feeBase = totalAmount - shopCompensationAmount - exceptionFee;
         // 璐圭巼锛堜负绌烘椂榛樿0锛�
         BigDecimal depositRate = order.getDepositShopFeeRata() != null ? order.getDepositShopFeeRata() : BigDecimal.ZERO;
         BigDecimal takeRate = order.getTakeShopFeeRata() != null ? order.getTakeShopFeeRata() : BigDecimal.ZERO;
         BigDecimal driverRate = order.getDriverFeeRata() != null ? order.getDriverFeeRata() : BigDecimal.ZERO;
 
         //瀛樹欢闂ㄥ簵鏀剁泭
-        Long depositShopFee = new BigDecimal(totalAmount)
+        Long depositShopFee = new BigDecimal(feeBase)
                 .multiply(depositRate)
                 .setScale(0, RoundingMode.HALF_UP)
                 .longValue();
@@ -3783,14 +3822,14 @@
 
         if (Constants.equalsInteger(order.getType(), Constants.ONE)) {
             // 寮傚湴瀵勫瓨锛氬瓨浠堕棬搴� + 鍙告満
-            driverFee = new BigDecimal(totalAmount)
+            driverFee = new BigDecimal(feeBase)
                     .multiply(driverRate)
                     .setScale(0, RoundingMode.HALF_UP)
                     .longValue();
 
             // 寮傚湴瀵勫瓨涓旀湁鍙栦欢闂ㄥ簵锛氬姞涓婂彇浠堕棬搴楁敹鐩�
             if (order.getTakeShopId() != null) {
-                takeShopFee = new BigDecimal(totalAmount)
+                takeShopFee = new BigDecimal(feeBase)
                         .multiply(takeRate)
                         .setScale(0, RoundingMode.HALF_UP)
                         .longValue();
@@ -3828,6 +3867,29 @@
             }
         }
 
+        // 寮傚父璁㈠崟锛氬瓨浠堕棬搴楀紓甯歌ˉ鍋挎敹鐩婏紙鍗曠嫭涓�鏉¤褰曪紝type=5锛�
+        if (Constants.equalsInteger(order.getExceptionStatus(), Constants.ONE)
+                && order.getShopCompensationAmount() != null && order.getShopCompensationAmount() > 0
+                && order.getDepositShopId() != null) {
+            ShopInfo depositShop = shopInfoMapper.selectById(order.getDepositShopId());
+            if (depositShop != null && depositShop.getId() != null) {
+                Revenue shopExRevenue = new Revenue();
+                shopExRevenue.setMemberId(depositShop.getId());
+                shopExRevenue.setMemberType(Constants.TWO); // 2=闂ㄥ簵
+                shopExRevenue.setType(5); // 5=寮傚父閲戦
+                shopExRevenue.setOptType(Constants.ONE); // 1=鏀跺叆
+                shopExRevenue.setAmount(order.getShopCompensationAmount());
+                shopExRevenue.setVaildStatus(Constants.ZERO);
+                shopExRevenue.setObjId(orderId);
+                shopExRevenue.setObjType(Constants.ZERO);
+                shopExRevenue.setStatus(Constants.ZERO);
+                shopExRevenue.setOrderNo(order.getCode());
+                shopExRevenue.setDeleted(Constants.ZERO);
+                shopExRevenue.setCreateTime(now);
+                revenueMapper.insert(shopExRevenue);
+            }
+        }
+
         // 鍙栦欢闂ㄥ簵鏀剁泭锛堝紓鍦板瘎瀛樹笖鏈夊彇浠堕棬搴楋級
         if (takeShopFee > 0 && order.getTakeShopId() != null) {
             ShopInfo takeShop = shopInfoMapper.selectById(order.getTakeShopId());
@@ -3846,27 +3908,33 @@
             }
         }
 
-        // 寮傚父璁㈠崟锛氬徃鏈哄紓甯歌ˉ鍋匡紙寮傚湴 + 寮傚父鏍囪 + 鏈夊紓甯歌ˉ鍋块噾棰濓級
+        // 寮傚父璁㈠崟锛氬徃鏈哄紓甯歌ˉ鍋匡紙寮傚湴 + 寮傚父鏍囪锛屼粠鍏宠仈寮傚父瀛愯鍗曡幏鍙杄xceptionFee锛�
         if (Constants.equalsInteger(order.getType(), Constants.ONE)
                 && Constants.equalsInteger(order.getExceptionStatus(), Constants.ONE)
-                && order.getExceptionFee() != null && order.getExceptionFee() > 0
                 && order.getAcceptDriver() != null) {
-            DriverInfo driver = driverInfoMapper.selectById(order.getAcceptDriver());
-            if (driver != null && driver.getMemberId() != null) {
-                Revenue exRevenue = new Revenue();
-                exRevenue.setMemberId(driver.getMemberId());
-                exRevenue.setMemberType(Constants.ONE); // 1=鍙告満
-                exRevenue.setType(5); // 5=寮傚父閲戦
-                exRevenue.setOptType(Constants.ONE); // 1=鏀跺叆
-                exRevenue.setAmount(order.getExceptionFee());
-                exRevenue.setVaildStatus(Constants.ZERO);
-                exRevenue.setObjId(orderId);
-                exRevenue.setObjType(Constants.ZERO);
-                exRevenue.setStatus(Constants.ZERO);
-                exRevenue.setOrderNo(order.getCode());
-                exRevenue.setDeleted(Constants.ZERO);
-                exRevenue.setCreateTime(now);
-                revenueMapper.insert(exRevenue);
+            Orders childOrder = ordersMapper.selectOne(new QueryWrapper<Orders>().lambda()
+                    .eq(Orders::getRelationOrderId, orderId)
+                    .eq(Orders::getExceptionStatus, Constants.ONE)
+                    .eq(Orders::getDeleted, Constants.ZERO)
+                    .last("limit 1"));
+            if (childOrder != null && childOrder.getExceptionFee() != null && childOrder.getExceptionFee() > 0) {
+                DriverInfo driver = driverInfoMapper.selectById(order.getAcceptDriver());
+                if (driver != null && driver.getMemberId() != null) {
+                    Revenue exRevenue = new Revenue();
+                    exRevenue.setMemberId(driver.getMemberId());
+                    exRevenue.setMemberType(Constants.ONE); // 1=鍙告満
+                    exRevenue.setType(5); // 5=寮傚父閲戦
+                    exRevenue.setOptType(Constants.ONE); // 1=鏀跺叆
+                    exRevenue.setAmount(childOrder.getExceptionFee());
+                    exRevenue.setVaildStatus(Constants.ZERO);
+                    exRevenue.setObjId(orderId);
+                    exRevenue.setObjType(Constants.ZERO);
+                    exRevenue.setStatus(Constants.ZERO);
+                    exRevenue.setOrderNo(order.getCode());
+                    exRevenue.setDeleted(Constants.ZERO);
+                    exRevenue.setCreateTime(now);
+                    revenueMapper.insert(exRevenue);
+                }
             }
         }
 
@@ -4100,8 +4168,7 @@
         if (Constants.equalsInteger(order.getExceptionStatus(), Constants.ONE)
                 && order.getRelationOrderId() != null) {
             Orders originalOrder = ordersMapper.selectById(order.getRelationOrderId());
-            long driverExceptionFee = (originalOrder != null && originalOrder.getExceptionFee() != null)
-                    ? originalOrder.getExceptionFee() : 0L;
+            long driverExceptionFee = order.getExceptionFee() != null ? order.getExceptionFee() : 0L;
             long shopExceptionFee = order.getShopCompensationAmount() != null ? order.getShopCompensationAmount() : 0L;
             long totalExceptionFee = driverExceptionFee + shopExceptionFee;
 
@@ -4115,13 +4182,14 @@
                 overdueFee = totalExceptionFee;
                 overdueDays = totalExceptionFee > 0 ? 1 : 0;
             } else {
-                // 闈炲綋澶╁彇浠讹細姝e父閫炬湡璁$畻 + 鍙告満寮傚父璐圭敤锛堜笉鍚棬搴楀紓甯歌垂鐢級
+                // 闈炲綋澶╁彇浠讹細姝e父閫炬湡璁$畻 + 鍙告満寮傚父璐圭敤锛堜笉鍚棬搴楀紓甯歌垂鐢級锛岄棬搴楀紓甯搁噾棰濇竻闆�
                 OverdueFeeVO normalOverdue = calculateOverdueFeeInternal(order, details);
                 long normalFee = (normalOverdue != null && normalOverdue.getOverdueFee() != null)
                         ? normalOverdue.getOverdueFee() : 0L;
                 overdueFee = normalFee + driverExceptionFee;
                 overdueDays = (normalOverdue != null && normalOverdue.getOverdueDays() != null)
                         ? normalOverdue.getOverdueDays() : 0;
+                order.setShopCompensationAmount(0L);
             }
 
             order.setConfirmArriveTime(now);
@@ -5108,14 +5176,14 @@
                 targetLat = order.getDepositLat();
                 targetLgt = order.getDepositLgt();
             } else if (Constants.equalsInteger(order.getStatus(), Constants.OrderStatus.arrived.getStatus())&&Constants.equalsInteger(order.getType(), Constants.ZERO)) {
-                // 灏卞湴瀛樺彇 鈫� 瀵规瘮瀛樹欢闂ㄥ簵
+                // 灏卞湴瀵勫瓨 鈫� 瀵规瘮瀛樹欢闂ㄥ簵
                 if (!Constants.equalsInteger(order.getDepositShopId(), userId)) {
                     throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鏃犳潈鎿嶄綔璇ヨ鍗�");
                 }
                 targetLat = order.getDepositLat();
                 targetLgt = order.getDepositLgt();
             } else if ((Constants.equalsInteger(order.getStatus(), Constants.OrderStatus.delivering.getStatus())||Constants.equalsInteger(order.getStatus(), Constants.OrderStatus.arrived.getStatus()))&&Constants.equalsInteger(order.getType(), Constants.ONE)) {
-                // 寮傚湴瀛樺彇 鈫� 瀵规瘮鍙栦欢闂ㄥ簵
+                // 鍚屽煄瀵勯�� 鈫� 瀵规瘮鍙栦欢闂ㄥ簵
                 if (!Constants.equalsInteger(order.getTakeShopId(), userId)) {
                     throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鏃犳潈鎿嶄綔璇ヨ鍗�");
                 }
@@ -5181,7 +5249,7 @@
 
         Date now = new Date();
 
-        // ========== B. 鍒涘缓鏂拌鍗曪紙灏卞湴瀛樺彇锛� ==========
+        // ========== B. 鍒涘缓鏂拌鍗曪紙灏卞湴瀵勫瓨锛� ==========
         String orderCode = "JC" + new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(now)
                 + String.format("%04d", new java.util.Random().nextInt(10000));
         String orderTradeNo = generateOrderTradeNo();
@@ -5222,7 +5290,7 @@
             }
         }
 
-        // 瀛樹欢闂ㄥ簵鍒嗘垚鍗犳瘮锛堝氨鍦板瓨鍙栵級
+        // 瀛樹欢闂ㄥ簵鍒嗘垚鍗犳瘮锛堝氨鍦板瘎瀛橈級
         Integer cityId = Integer.valueOf(original.getCityId());
         boolean isCompany = Constants.equalsInteger(newShop.getCompanyType(), Constants.ONE);
         int fallbackFieldA = isCompany ? Constants.FIVE : Constants.SIX;
@@ -5232,7 +5300,7 @@
         newOrder.setCode(orderCode);
         newOrder.setOutTradeNo(orderTradeNo);
         newOrder.setMemberId(original.getMemberId());
-        newOrder.setType(Constants.ZERO); // 灏卞湴瀛樺彇
+        newOrder.setType(Constants.ZERO); // 灏卞湴瀵勫瓨
         newOrder.setCityId(original.getCityId());
         newOrder.setStatus(Constants.ONE); // 寰呭瘎瀛�
         newOrder.setPayStatus(Constants.ONE); // 宸叉敮浠�
@@ -5283,8 +5351,8 @@
         newOrder.setDeclaredAmount(0L);
         newOrder.setDeclaredFee(0L);
         newOrder.setPrice(price);
-        newOrder.setBasicAmount(basicAmount);
-        newOrder.setEstimatedAmount(basicAmount);
+        newOrder.setBasicAmount(0L);//);
+        newOrder.setEstimatedAmount(0L);//basicAmount);
         newOrder.setTotalAmount(0L);
         newOrder.setPayAmount(0L);
         newOrder.setManualRefund(Constants.ZERO);
@@ -5299,6 +5367,8 @@
 
         // 闂ㄥ簵琛ュ伩閲戦
         newOrder.setShopCompensationAmount(dto.getShopCompensation());
+        // 鍙告満寮傚父琛ュ伩閲戦
+        newOrder.setExceptionFee(dto.getDriverCompensation());
 
         newOrder.setRemark(dto.getRemark());
         newOrder.setPlatformSmsNotified(Constants.ZERO);
@@ -5355,7 +5425,6 @@
         // ========== E. 鏇存柊鍘熻鍗� ==========
         ordersMapper.update(new UpdateWrapper<Orders>().lambda()
                 .set(Orders::getExceptionStatus, Constants.ONE)
-                .set(Orders::getExceptionFee, dto.getDriverCompensation())
                 .set(Orders::getUpdateTime, now)
                 .eq(Orders::getId, original.getId()));
 

--
Gitblit v1.9.3