瀏覽代碼

feat(lakala): 新增微信订单定时任务并调整支付记录服务方法

- 创建 WechatOrderCron 类用于处理拉卡拉微信订单的定时任务
- 将 PaymentRecordService 中的 createWechatOrder 方法由 private 改为 public
- 在 Extension 类中注册 WechatOrderCron 定时任务
- 实现每十分钟执行一次的订单发货状态检查逻辑
- 自动为符合条件的支付记录创建微信订单状态
- 调整 Extension 类中的方法返回类型和注解声明
runphp 4 月之前
父節點
當前提交
0e7ae5da33
共有 3 個文件被更改,包括 46 次插入5 次删除
  1. 33 0
      src/Cron/WechatOrderCron.php
  2. 12 4
      src/Extension.php
  3. 1 1
      src/Service/PaymentRecordService.php

+ 33 - 0
src/Cron/WechatOrderCron.php

@@ -0,0 +1,33 @@
+<?php
+declare(strict_types=1);
+namespace SixShop\Lakala\Cron;
+
+use SixShop\Core\Attribute\Cron;
+use SixShop\Lakala\Service\PaymentRecordService;
+use SixShop\Payment\Model\ExtensionPaymentModel;
+
+class WechatOrderCron
+{
+    public function __construct(private PaymentRecordService $paymentRecordService)
+    {
+    }
+
+    #[Cron('* */10 * * * *', 'lakala.shipping')]
+    public function orderShipping(): void
+    {
+        ExtensionPaymentModel::alias('p')
+            ->leftJoin('order o', 'o.id = p.order_id')
+            ->leftJoin('lakala_wechat_payment w', 'p.id = w.payment_id')
+            ->where([
+                'p.pay_type' => 'lakala',
+                'p.status' => 2,
+                'o.shipping_status' => 1,
+                'w.status' => 1
+            ])
+            ->whereNull('w.order_state')
+            ->field('p.id')
+            ->select()->each(function ($payment){
+                $this->paymentRecordService->createWechatOrder($payment->id);
+            });
+    }
+}

+ 12 - 4
src/Extension.php

@@ -4,6 +4,7 @@ declare(strict_types=1);
 namespace SixShop\Lakala;
 
 use SixShop\Core\ExtensionAbstract;
+use SixShop\Lakala\Cron\WechatOrderCron;
 use SixShop\Lakala\Hook\LakalaHook;
 use SixShop\Payment\Contracts\PaymentExtensionInterface;
 use SixShop\Payment\Contracts\PaymentProviderInterface;
@@ -15,20 +16,27 @@ class Extension extends ExtensionAbstract implements PaymentExtensionInterface
 {
     public const string EXTENSION_ID = 'lakala';
 
-    protected function getBaseDir(): string
+    #[\Override] protected function getBaseDir(): string
     {
         return dirname(__DIR__);
     }
 
-    public function getPaymentProvider(): PaymentProviderInterface
+    #[\Override] public function getPaymentProvider(): PaymentProviderInterface
     {
         return app(PaymentProvider::class);
     }
 
-    public function getHooks(): array
+    #[\Override] public function getHooks(): array
     {
         return [
-            LakalaHook::class
+            LakalaHook::class,
+        ];
+    }
+
+    #[\Override] public function getCronJobs()
+    {
+        return [
+            WechatOrderCron::class,
         ];
     }
 }

+ 1 - 1
src/Service/PaymentRecordService.php

@@ -64,7 +64,7 @@ class PaymentRecordService
         return $paginator;
     }
 
-    private function createWechatOrder(int $paymentID):LakalaWechatPaymentModel
+    public function createWechatOrder(int $paymentID):LakalaWechatPaymentModel
     {
         $payment = ExtensionPaymentModel::find($paymentID);
         $goods = OrderGoods::where(['order_id' => $payment['order_id']])->find();