Просмотр исходного кода

feat(wechat): 支持微信订单发货状态查询与更新

- 修改微信订单状态查询条件,支持状态为1和2的订单
- 新增微信订单发货状态更新逻辑
- 实现快递公司信息获取失败的日志记录与异常抛出
- 新增订单发货状态查询接口
- 新增发货信息录入方法
- 添加订单发货状态查询的单元测试
runphp 4 месяцев назад
Родитель
Сommit
0077baf571
2 измененных файлов с 38 добавлено и 0 удалено
  1. 31 0
      src/Service/ExpressService.php
  2. 7 0
      test/Service/ExpressServiceTest.php

+ 31 - 0
src/Service/ExpressService.php

@@ -4,6 +4,8 @@ namespace SixShop\Wechat\Service;
 
 use SixShop\Wechat\Entity\WechatDeliveryEntity;
 use think\Collection;
+use think\facade\Log;
+use function SixShop\Core\throw_logic_exception;
 
 class ExpressService
 {
@@ -19,9 +21,38 @@ class ExpressService
         $result = $this->wechatDeliveryEntity->select();
         if ($result->isEmpty()) {
             $response = $this->miniApp->getClient()->get('/cgi-bin/express/business/delivery/getall');
+            if ($response->isFailed()) {
+                Log::error('获取所有快递公司失败'.json_encode($response->toArray()));
+                throw_logic_exception('获取所有快递公司失败');
+            }
             $result = $response->toArray();
             $result = $this->wechatDeliveryEntity->saveAll($result['data']);
         }
         return $result;
     }
+
+    /**
+     * 查询订单发货状态
+     */
+    public function queryOrder(string $transactionID): array
+    {
+        $response = $this->miniApp->getClient()->postJson('/wxa/sec/order/get_order', [
+            'transaction_id' => $transactionID,
+        ]);
+        if ($response->isFailed()) {
+            Log::error('查询订单发货状态失败'.json_encode($response->toArray()));
+            throw_logic_exception('查询订单发货状态失败');
+        }
+        return $response->toArray()['order'];
+    }
+
+    /**
+     * 发货信息录入
+     *
+     * 使用微信支付单号
+     */
+    public function uploadShippingInfo(string $transactionID): array
+    {
+
+    }
 }

+ 7 - 0
test/Service/ExpressServiceTest.php

@@ -19,4 +19,11 @@ class ExpressServiceTest extends TestCase
         $res = $this->expressService->getAllDelivery();
         dump($res);
     }
+
+    #[Test]
+    public function queryOrder()
+    {
+        $res = $this->expressService->queryOrder('4200002925202511205107137676');
+        dump($res);
+    }
 }