Explorar o código

fix(wechat): 优化发货信息上传逻辑并增强错误日志

- 将请求数据提取为独立变量以提高可读性
- 在错误日志中添加完整的请求数据以便调试
- 保持原有业务逻辑不变,仅重构代码结构
runphp hai 4 meses
pai
achega
2fec24ff36
Modificáronse 1 ficheiros con 8 adicións e 3 borrados
  1. 8 3
      src/Service/ExpressService.php

+ 8 - 3
src/Service/ExpressService.php

@@ -72,7 +72,7 @@ class ExpressService
         bool   $isAllDelivered = false,
     ): void
     {
-        $response = $this->miniApp->getClient()->postJson('/wxa/sec/order/upload_shipping_info', [
+        $data = [
             'order_key' => [
                 'order_number_type' => 2, // 使用微信支付单号
                 'transaction_id' => $transactionID,
@@ -84,10 +84,15 @@ class ExpressService
             ],
             'upload_time' => date('c'),
             'shipping_list' => $shippingList,
-        ]);
+        ];
+        $response = $this->miniApp->getClient()->postJson('/wxa/sec/order/upload_shipping_info', $data);
         if ($response->isFailed()) {
             $responseData = $response->toArray();
-            Log::error('发货信息录入失败{transaction_id}{response}', ['transaction_id' => $transactionID, 'response' => json_encode($responseData)]);
+            Log::error('发货信息录入失败 {transaction_id} {response} {request}', [
+                'transaction_id' => $transactionID,
+                'response' => json_encode($responseData),
+                'request' => json_encode($data),
+            ]);
             throw_logic_exception(msg: '发货信息录入失败', code: $responseData['errcode']);
         }
     }