Zory 5 dní pred
rodič
commit
1e7868b2fd

+ 18 - 13
app/controller/mini/Notify.php

@@ -11,6 +11,7 @@ use LinFly\Annotation\Route\Controller;
 use LinFly\Annotation\Route\Route;
 use support\Request;
 use support\Response;
+use Webman\RedisQueue\Redis;
 
 
 #[Controller(prefix: "/notify")]
@@ -39,24 +40,28 @@ class Notify extends Base
                 case "life_trade_order_notify": // 支付成功
                     $resp = json_decode($param['content'], true);
                     if ($resp['action'] == "pay_success") {
-                        $order = (new SaasOrderLife)->where("order_id",$resp['order']['order_id'])->findOrEmpty();
-                        if ($order->isEmpty()) {
-                            $store = (new SaasStore)->where("store_id",$resp['order']['account_id'])->findOrEmpty();
-                            $order->insertGetId([
-                                "agent_id"  => $store['agent_id']??'',
-                                "store_id"  => $store['store_id']??'',
-                                "order_id"  => $resp['order']['order_id'],
-                                "pay_amount"    => $resp['order']['pay_amount'],
-                                "order_amount"  => $resp['order']['original_amount'],
-                                "pay_at"        => date("Y-m-d H:i:s",$resp['order']['pay_time']),
-                                "status"        => 1
-                            ]);
+                        Redis::send("sync-order",[
+                            "order"     => $resp['order']['order_id'],
+                            "openid"    => $param['from_user_id']
+                        ]);
+//                        $order = (new SaasOrderLife)->where("order_id",$resp['order']['order_id'])->findOrEmpty();
+//                        if ($order->isEmpty()) {
+//                            $store = (new SaasStore)->where("store_id",$resp['order']['account_id'])->findOrEmpty();
+//                            $order->insertGetId([
+//                                "agent_id"  => $store['agent_id']??'',
+//                                "store_id"  => $store['store_id']??'',
+//                                "order_id"  => $resp['order']['order_id'],
+//                                "pay_amount"    => $resp['order']['pay_amount'],
+//                                "order_amount"  => $resp['order']['original_amount'],
+//                                "pay_at"        => date("Y-m-d H:i:s",$resp['order']['pay_time']),
+//                                "status"        => 1
+//                            ]);
 //                            (new SaasOrderLog)->insertGetId([
 //                                "order_id"  => $resp['order']['order_id'],
 //                                "title"     => "发起订单",
 //                                "remark"    => "下单并完成支付"
 //                            ]);
-                        }
+//                        }
                     }
                     $return = [];
                     break;

+ 3 - 0
app/controller/mini/Test.php

@@ -37,6 +37,9 @@ class Test extends Base
             if ($param['type'] == 3) { // 加锁/解锁
                 $resp = (new \app\extra\douyin\Order())->config($this->getDyConfig())->token()->orderLock(1,$param['order'],"7580559591462207503","81O6R1PT9QLW8T5MEA");
             }
+            if ($param['type'] == 4) { // 查询订单可用门店
+                $resp = (new Client)->config($this->getDyConfig())->token()->queryOrderStore($param['order']);
+            }
             return success("ok",$resp);
         } catch (\Throwable $throwable) {
             return error($throwable->getMessage());

+ 0 - 6
app/extra/basic/Base.php

@@ -74,11 +74,6 @@ class Base
                         "status"        => 1,
                         "start_time"    => date("Y-m-d H:i:s",$val['start_time']),
                     ];
-                    $orderLog[$key] = [
-                        "order_id"  => $val['certificate_id'],
-                        "title"     => "发起订单",
-                        "remark"    => "下单并完成支付"
-                    ];
                 } else {
                     $orderEx->save([
                         "open_id"       => $openId,
@@ -93,7 +88,6 @@ class Base
             }
             if (!empty($orderData)) {
                 (new SaasOrderLife)->insertAll(array_values($orderData));
-                (new SaasOrderLog)->insertAll(array_values($orderLog));
             }
             return [];
         }

+ 14 - 0
app/extra/douyin/Client.php

@@ -56,6 +56,20 @@ class Client extends Base
         return Http::asJson()->withHeaders($this->header)->post($this->gateway."api/trade/v2/fulfillment/query_user_certificates/", $param)->array();
     }
 
+
+    /**
+     * 查询订单可用门店
+     * @param string $orderId
+     * @return array
+     */
+    public function queryOrderStore(string $orderId = ""): array
+    {
+        $param = [
+            "order_id"          => $orderId
+        ];
+        return Http::asJson()->withHeaders($this->header)->post($this->gateway."api/trade/v2/fulfillment/order_can_use/", $param)->array();
+    }
+
     /**
      * 查询商家配置文案
      * @return array

+ 36 - 0
app/extra/life/OrderLife.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace app\extra\life;
+
+use app\extra\douyin\Base;
+use yzh52521\EasyHttp\Http;
+
+class OrderLife extends Base
+{
+
+
+    /**
+     * 同步线索,半个小时内
+     * @param string $accountId
+     * @param string $endTime
+     * @param string $startTime
+     * @param int $page
+     * @param int $pageSize
+     * @return array
+     */
+    public function asyncClue(string $accountId = "",int $page = 1,string $endTime = '',string $startTime = "",int $pageSize = 100): array
+    {
+        $param = [
+            "account_id"    => $accountId,
+            "end_time"      => empty($endTime) ? date("Y-m-d H:i:s") : $endTime,
+            "start_time"    => empty($startTime) ? date("Y-m-d H:i:s",strtotime("-60 min")) : $startTime,
+            "page"          => $page,
+            "page_size"     => $pageSize,
+        ];
+        echo getDateFull()."===线索同步\n";
+        print_r($param);
+        return Http::asJson()->withHeaders($this->header)->get($this->gateway."goodlife/v1/open_api/crm/clue/query/",$param)->array();
+    }
+
+
+}

+ 74 - 0
app/queue/redis/SyncOrder.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace app\queue\redis;
+
+use app\extra\douyin\Client;
+use app\extra\life\OrderLife;
+use app\model\saas\SaasOrderLife;
+use app\model\saas\SaasOrderLog;
+use app\model\saas\SaasStore;
+use Webman\RedisQueue\Consumer;
+use Webman\RedisQueue\Redis;
+
+class SyncOrder implements Consumer
+{
+
+
+    public $queue = "sync-order";
+
+    public $connection = "default";
+
+
+    public function consume($data): bool
+    {
+        if (empty($data['order'])) return true;
+        if (empty($data['openid'])) return true;
+        $order = (new SaasOrderLife)->where("order_id",$data['order'])->findOrEmpty();
+        if (!$order->isEmpty()) return true;
+        $resp = (new Client)->config($this->getDyConfig())->token()->queryOrderStore($data['order']);
+        if (empty($resp['data']['data'])) return true;
+        $lifeOrder = $resp['data']['data'];
+        $orderData = [];
+        foreach ($lifeOrder['certificates'] as $key=>$val) {
+            $orderEx = (new SaasOrderLife)->where("order_id",$lifeOrder['order_id'])->where("certificate_id",$val['certificate_id'])->findOrEmpty();
+            if ($orderEx->isEmpty()) {
+                $store = (new SaasStore)->where("store_id",$val['sku_info']['account_id'])->findOrEmpty();
+                $orderData[$key] = [
+                    "open_id"   => $data['openid'],
+                    "agent_id"  => $store['agent_id']??'',
+                    "store_id"  => $store['store_id']??'',
+                    "order_id"  => $lifeOrder['order_id'],
+                    "pay_amount"    => $val['amount']['pay_amount'],
+                    "order_amount"  => $val['amount']['original_amount'],
+                    "expire_at"     => date("Y-m-d H:i:s",$val['expire_time']),
+                    "out_id"        => $val['sku_info']['sku_id'],
+                    "product_name"  => $val['sku_info']['title'],
+                    "groupon_type"  => $val['sku_info']['groupon_type'],
+                    "certificate_id"  => $val['certificate_id']??'',
+                    "status"        => 1,
+                    "start_time"    => date("Y-m-d H:i:s",$val['start_time']),
+                ];
+            } else {
+                $orderEx->save([
+                    "expire_at"     => date("Y-m-d H:i:s",$val['expire_time']),
+                    "out_id"        => $val['sku_info']['sku_id'],
+                    "product_name"  => $val['sku_info']['title'],
+                    "groupon_type"  => $val['sku_info']['groupon_type'],
+                    "certificate_id"  => $val['certificate_id']??'',
+                    "start_time"    => date("Y-m-d H:i:s",$val['start_time']),
+                ]);
+            }
+        }
+        if (!empty($orderData)) {
+            (new SaasOrderLife)->insertAll(array_values($orderData));
+        }
+        return true;
+    }
+
+
+    protected function getDyConfig(): array
+    {
+        return ["appid" => sConf('dy.appid'),'secret' => sConf('dy.secret')];
+    }
+
+}