zory há 2 semanas atrás
pai
commit
06270aa034

+ 2 - 3
app/controller/mini/Auth.php

@@ -43,7 +43,6 @@ class Auth extends Base
     {
         try {
             $param = $request->post();
-            print_r($param);
             $sessionKey = (new Crypt)->config($this->getDyConfig())->getSessionKey($param['auth']);
             if (!isset($sessionKey['openid'])) return error("获取数据失败");
             $openId = $sessionKey['openid'];
@@ -59,8 +58,8 @@ class Auth extends Base
                 $userIn['id'] = $user->insertGetId($userIn);
             }
             // 同步已经下单的订单
-            if (!empty($param['account'])) {
-                $this->asyncDyOrder($param['account'],$openId);
+            if (!empty($param['account_id'])) {
+                $this->asyncDyOrder($param['account_id'],$openId);
             }
             return successTrans("success.data",[
                 "user"      => get_object_vars((new AuthMode)->guard("member")->login($userIn)),

+ 45 - 7
app/controller/mini/Notify.php

@@ -5,6 +5,8 @@ namespace app\controller\mini;
 use app\extra\basic\Base;
 use app\model\saas\SaasGoods;
 use app\model\saas\SaasOrderLife;
+use app\model\saas\SaasOrderLog;
+use app\model\saas\SaasStore;
 use LinFly\Annotation\Route\Controller;
 use LinFly\Annotation\Route\Route;
 use support\Request;
@@ -26,15 +28,51 @@ class Notify extends Base
     {
         try {
             $param = $request->post();
-            echo getDateFull()."==webhook==\n";
-            print_r($param);
             if (empty($param['event'])) return error("参数错误");
             if (empty($param['content'])) return error("参数错误");
-            $return = match ($param['event']) {
-                "verify_webhook" => ['challenge' => $param['content']['challenge']],
-                default => [],
-            };
-            print_r($return);
+            switch ($param['event']) {
+                case "verify_webhook":
+                    $return = ['challenge' => $param['content']['challenge']];
+                    break;
+                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"        => getDateFull("",$resp['order']['pay_time'])
+                            ]);
+                            (new SaasOrderLog)->insertGetId([
+                                "order_id"  => $resp['order']['order_id'],
+                                "title"     => "发起订单",
+                                "remark"    => "下单并完成支付"
+                            ]);
+                        }
+                    }
+                    $return = [];
+                    break;
+                case "life_trade_certificate_notify": // 退款
+                    $resp = json_decode($param['content'], true);
+                    if ($resp['action'] == "refund_success") {
+                        $order = (new SaasOrderLife)->where("order_id",$resp['order']['order_id'])->findOrEmpty();
+                        if (!$order->isEmpty()) {
+                            $order->status = 4;
+                            $order->refund_at = getDateFull();
+                            $order->save();
+                        }
+                    }
+                    $return = [];
+                    break;
+                default:
+                    $return = [];
+                    break;
+            }
             return json($return);
         } catch (\Throwable $e) {
             return error($e->getMessage());

+ 4 - 4
app/controller/mini/Order.php

@@ -39,7 +39,6 @@ class Order extends Base
     {
         try {
             $param = $request->post();
-            print_r($param);
             $sessionKey = (new Crypt)->config($this->getDyConfig())->getSessionKey($param['auth']);
             if (empty($sessionKey)) return error("授权登录失败");
             if (!isset($sessionKey['openid'])) return error("获取数据失败");
@@ -56,10 +55,10 @@ class Order extends Base
                 $userIn['id'] = $user->insertGetId($userIn);
             }
             // 同步已经下单的订单
-            if (!empty($param['account'])) {
-                $this->asyncDyOrder($param['account'],$openId);
+            if (!empty($param['account_id'])) {
+                $this->asyncDyOrder($param['account_id'],$openId);
             }
-            $order = (new SaasOrderLife)->where("open_id",$openId)->with(['goods' => function($query){
+            $order = (new SaasOrderLife)->where("open_id",$openId)->where('order_id',$param['order_id'])->with(['goods' => function($query){
                 $query->field("out_id,product_img");
             },'store' => function($query){
                 $query->field("store_id,service_mobile");
@@ -67,6 +66,7 @@ class Order extends Base
                 return date("Y-m-d",strtotime($resp['expire_at']));
             }])->findOrEmpty();
             if ($order->isEmpty()) return error("订单尚未同步");
+            $order['order'] = (new SaasOrder)->where("order_id",$param['order_id'])->where("status","in",[1,2,4])->field("order_sn,order_id")->findOrEmpty();
             return successTrans("success.data",[
                 "user"      => get_object_vars((new AuthMode)->guard("member")->login($userIn)),
                 "order"     => $order

+ 2 - 2
app/controller/mini/Test.php

@@ -20,8 +20,8 @@ class Test extends Base
     {
         try {
             $uuid = ["228287898988984"];
-//            $resp = (new \app\extra\douyin\Account())->config($this->getDyConfig())->token()->setWhiteSetting("7513378475235919883",1,true);
-            $resp = (new Client)->config($this->getDyConfig())->token()->setMiniPath("7513378475235919883");
+            $resp = (new \app\extra\douyin\Account())->config($this->getDyConfig())->token()->setWhiteSetting("7513378475235919883",1,false,$uuid);
+//            $resp = (new Client)->config($this->getDyConfig())->token()->setMiniPath("7513378475235919883");
 //            $resp = (new Client)->config($this->getDyConfig())->token()->queryOrder("7513378475235919883","_000SDaHqDYY9GGnyrpYfp4vIPHD8qs32XCx");
             print_r($resp);
             return success("ok");

+ 12 - 2
app/extra/basic/Base.php

@@ -49,7 +49,6 @@ class Base
         // 同步已经下单的订单
         if (!empty($account)) {
             $resp = (new Client)->config($this->getDyConfig())->token()->queryOrder($account,$openId);
-            print_r($resp);
             $store = (new SaasStore)->where("store_id",$account)->findOrEmpty();
             if (!empty($resp['data']['orders'])) {
                 $orderData = $orderLog = [];
@@ -57,7 +56,7 @@ class Base
                     if ($val['can_use']) {
                         $orderEx = (new SaasOrderLife)->where("order_id",$val['order_id'])->findOrEmpty();
                         $certificates = $val['certificates'][0];
-                        if ($orderEx->isEmpty() && !isset($certificates['lock_info_extra'])) {
+                        if ($orderEx->isEmpty()) {
                             $orderData[$key] = [
                                 "open_id"   => $openId,
                                 "agent_id"  => $store['agent_id']??'',
@@ -78,6 +77,17 @@ class Base
                                 "title"     => "发起订单",
                                 "remark"    => "下单并完成支付"
                             ];
+                        } else {
+                            $orderEx->save([
+                                "open_id"       => $openId,
+                                "expire_at"     => date("Y-m-d H:i:s",$certificates['expire_time']),
+                                "out_id"        => $certificates['sku_info']['sku_id'],
+                                "product_name"  => $certificates['sku_info']['title'],
+                                "groupon_type"  => $certificates['sku_info']['groupon_type'],
+                                "certificate_id"  => $certificates['certificate_id']??'',
+                                "start_time"    => date("Y-m-d H:i:s",$certificates['start_time']),
+                                "status"        => 1
+                            ]);
                         }
                     }
                 }

+ 1 - 1
app/functions.php

@@ -252,7 +252,7 @@ if (!function_exists("getDateFull"))
     function getDateFull(string $format = "Y-m-d H:i:s",string $time = ""): string
     {
         if (empty($time)) $time = time();
-        return date($format,$time);
+        return date($format??'Y-m-d H:i:s',$time);
     }
 }