소스 검색

fix(alibaba): 修正阿里巴巴物流信息字段映射

- 修正 AlibabaNotify.php 中物流单号字段从 logisticsCode 改为 logisticsBillNo
- 修正 OrderService.php 中物流信息数据结构解析逻辑
- 更新物流信息字段映射:logisticsCode 替换为 logisticsBillNo,logisticsName 替换为 logisticsCompanyName
- 添加详细的物流信息返回数据结构注释文档
- 修复因字段名不匹配导致的物流信息获取失败问题
shichen 3 달 전
부모
커밋
3fac90a42a
2개의 변경된 파일22개의 추가작업 그리고 8개의 파일을 삭제
  1. 2 2
      app/controller/api/AlibabaNotify.php
  2. 20 6
      app/services/ThirdParty/AlibabaAgent/OrderService.php

+ 2 - 2
app/controller/api/AlibabaNotify.php

@@ -141,8 +141,8 @@ class AlibabaNotify
141 141
 
142 142
         // 4. 取第一条物流信息
143 143
         $firstLogistics = $logisticsResult['logisticsItems'][0];
144
-        $deliveryName = $firstLogistics['logisticsName'] ?? '';
145
-        $deliveryId   = $firstLogistics['logisticsCode'] ?? '';
144
+        $deliveryName = $firstLogistics['logisticsName'] ?? '';      // 物流公司名称
145
+        $deliveryId   = $firstLogistics['logisticsBillNo'] ?? '';    // 物流单号
146 146
 
147 147
         if (empty($deliveryName) || empty($deliveryId)) {
148 148
             Log::channel('alibaba')->warning('[发货通知] 物流信息不完整, logistics:' . json_encode($firstLogistics, JSON_UNESCAPED_UNICODE));

+ 20 - 6
app/services/ThirdParty/AlibabaAgent/OrderService.php

@@ -466,6 +466,19 @@ class OrderService extends AlibabaAgentBaseService
466 466
     /**
467 467
      * 格式化物流信息返回结果
468 468
      *
469
+     * 实际返回数据结构(result为数组):
470
+     * {
471
+     *   "result": [{
472
+     *     "logisticsId": "LP00815917141701",
473
+     *     "logisticsBillNo": "YT7619307479079",   // 物流单号
474
+     *     "logisticsCompanyName": "圆通速递(YTO)", // 物流公司名称
475
+     *     "logisticsCompanyNo": "YTO",             // 物流公司编码
476
+     *     "status": "SIGN",
477
+     *     ...
478
+     *   }],
479
+     *   "success": true
480
+     * }
481
+     *
469 482
      * @param array $result API原始返回数据
470 483
      * @return array
471 484
      */
@@ -474,15 +487,16 @@ class OrderService extends AlibabaAgentBaseService
474 487
         $success = $result['success'] ?? false;
475 488
         $logisticsItems = [];
476 489
 
477
-        if (isset($result['result']['logisticsItems']) && is_array($result['result']['logisticsItems'])) {
478
-            foreach ($result['result']['logisticsItems'] as $item) {
490
+        // result 是数组,每个元素是一条物流信息
491
+        if (isset($result['result']) && is_array($result['result'])) {
492
+            foreach ($result['result'] as $item) {
479 493
                 $logisticsItems[] = [
480 494
                     'logisticsId'      => $item['logisticsId'] ?? '',
481
-                    'logisticsCode'    => $item['logisticsCode'] ?? '',    // 物流单号
482
-                    'logisticsName'    => $item['logisticsName'] ?? '',    // 物流公司名称
483
-                    'logisticsCompany' => $item['logisticsCompany'] ?? '', // 物流公司编码
495
+                    'logisticsBillNo'  => $item['logisticsBillNo'] ?? '',          // 物流单号
496
+                    'logisticsName'    => $item['logisticsCompanyName'] ?? '',     // 物流公司名称
497
+                    'logisticsCompany' => $item['logisticsCompanyNo'] ?? '',       // 物流公司编码
484 498
                     'status'           => $item['status'] ?? '',
485
-                    'gmtCreate'        => $item['gmtCreate'] ?? '',
499
+                    'orderEntryIds'    => $item['orderEntryIds'] ?? '',
486 500
                 ];
487 501
             }
488 502
         }