Quellcode durchsuchen

feat(wechatpay): 新增 deliverySend 方法实现订单发货功能
- 更新依赖版本至最新

runphp vor 6 Monaten
Ursprung
Commit
1db686d14a
2 geänderte Dateien mit 26 neuen und 7 gelöschten Zeilen
  1. 3 3
      composer.json
  2. 23 4
      src/PaymentProvider.php

+ 3 - 3
composer.json

@@ -8,9 +8,9 @@
   ],
   "require": {
     "php": ">=8.3",
-    "six-shop/payment": ">=0.2 <1.0",
-    "six-shop/core": ">=0.5.13 <1.0",
-    "six-shop/wechat": "^0.1",
+    "six-shop/payment": ">=0.2.3 <1.0",
+    "six-shop/core": ">=0.6.4 <1.0",
+    "six-shop/wechat": ">=0.1.1 <1.0",
     "wechatpay/wechatpay": "^1.4.12"
   },
   "authors": [

+ 23 - 4
src/PaymentProvider.php

@@ -3,9 +3,9 @@ declare(strict_types=1);
 
 namespace SixShop\WechatPay;
 
+use EasyWeChat\Kernel\HttpClient\Response;
 use GuzzleHttp\Exception\ClientException;
 use SixShop\Core\Exception\NotFoundException;
-use SixShop\Core\Helper;
 use SixShop\Payment\Contracts\PaymentNotifyResult;
 use SixShop\Payment\Contracts\PaymentProviderInterface;
 use SixShop\Payment\Contracts\PaymentQueryResult;
@@ -21,6 +21,7 @@ use SixShop\Payment\Enum\RefundStatusEnum;
 use SixShop\Payment\Event\PaymentSuccessEvent;
 use SixShop\Payment\Event\RefundSuccessEvent;
 use SixShop\Wechat\Facade\WechatUser;
+use SixShop\Wechat\Service\MiniApp;
 use SixShop\WechatPay\Job\QueryRefundJob;
 use SixShop\WechatPay\Trait\ApiTrait;
 use SixShop\WechatPay\Trait\PaymentParamsTrait;
@@ -36,7 +37,8 @@ class PaymentProvider implements PaymentProviderInterface
 
     public function __construct(
         private readonly ExtensionPaymentEntity $extensionPaymentEntity,
-        private readonly ExtensionRefundEntity $extensionRefundEntity,
+        private readonly ExtensionRefundEntity  $extensionRefundEntity,
+        private readonly MiniApp                $miniApp,
     )
     {
     }
@@ -170,12 +172,12 @@ class PaymentProvider implements PaymentProviderInterface
             $refund->refund_result = $result;
             if ($result->status === 'SUCCESS') {
                 $refund->status = RefundStatusEnum::SUCCESS;
-                $refund->status_desc = '成功退款到'.$result->user_received_account;
+                $refund->status_desc = '成功退款到' . $result->user_received_account;
                 $refund->success_time = strtotime($result->success_time);
                 Event::trigger(new RefundSuccessEvent(
                         $refund->model(),
                         $refund->payment,
-                        new PaymentRefundRequest($refund->amount,$refund->reason, $refund->refund_param))
+                        new PaymentRefundRequest($refund->amount, $refund->reason, $refund->refund_param))
                 );
             } else if ($result->status === 'PROCESSING') {
                 QueryRefundJob::dispatch($refund->id)->delay(10);
@@ -185,4 +187,21 @@ class PaymentProvider implements PaymentProviderInterface
 
         return new PaymentRefundResult($refund->model());
     }
+
+    /**
+     * 订单发货
+     *
+     * @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/delivery/send.html
+     */
+    public function deliverySend(int $orderID, array $deliveryList, int $finishAll = 1): Response
+    {
+        $order = $this->orderEntity->find($orderID);
+        return $this->miniApp->getClient()->postJson('/shop/delivery/send', [
+            'out_order_id' => $order->out_trade_no,
+            'openid' => WechatUser::openid($order->user_id),
+            'finish_all_delivery' => $finishAll,
+            'delivery_list' => $deliveryList,
+            'ship_done_time' => date('Y-m-d H:i:s')
+        ]);
+    }
 }