Zory 2 周之前
父节点
当前提交
3b38a5bb32
共有 3 个文件被更改,包括 49 次插入9 次删除
  1. 24 5
      app/controller/api/Notify.php
  2. 25 3
      app/controller/api/Solution.php
  3. 0 1
      app/extra/dyLife/BasicLife.php

+ 24 - 5
app/controller/api/Notify.php

@@ -20,9 +20,7 @@ class Notify extends Base
         try {
             $param = $request->all();
             echo getDateFull()."===支付返回\n";
-            print_r($param);
             $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
-            print_r($param['msg']);
             print_r($data);
             $orderSn = $data['out_order_no'];
             if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
@@ -49,9 +47,7 @@ class Notify extends Base
         try {
             $param = $request->all();
             echo getDateFull()."===支付返回\n";
-            print_r($param);
             $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
-            print_r($param['msg']);
             print_r($data);
             $orderSn = $data['cp_extra'];
             if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
@@ -77,8 +73,31 @@ class Notify extends Base
         try {
             $param = $request->all();
             echo getDateFull()."===退款返回\n";
-            print_r($param);
             $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
+            print_r($data);
+            $orderSn = $data['order_id'];
+            if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
+            if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
+            $order = (new SaasOrder)->where("order_sn",$orderSn)->findOrEmpty();
+            if ($order['status'] <> 4) return json(['err_no' => 0,'err_tips' => "success"]);
+            $order->status = 3;
+            $order->refund_at = getDateFull();
+            $order->save();
+            return json(['err_no' => 0,'err_tips' => "success"]);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+
+    #[PostMapping("refund/mini")]
+    public function getOrderRefundMini(Request $request): Response
+    {
+        try {
+            $param = $request->all();
+            echo getDateFull()."===小程序退款返回\n";
+            $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
+            print_r($data);
             $orderSn = $data['cp_extra'];
             if ($data['status'] <> "SUCCESS") return json(['err_no' => 0,'err_tips' => "success"]);
             if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);

+ 25 - 3
app/controller/api/Solution.php

@@ -45,6 +45,25 @@ class Solution extends Base
                 $msgData = json_decode($data['msg'],true);
                 switch ($data['type'])
                 {
+                    case "pre_create_refund": // 退款回调
+                        $order = (new SaasOrder)->where("order_sn",$msgData['order_id'])->findOrEmpty();
+                        if ($order->isEmpty()) return json(['err_no' => 0,"err_tips" => "success"]);
+                        if ($order['status'] <> 1) return json(['err_no' => 0,"err_tips" => "success"]);
+                        $order->status = 4; // 退款中
+                        $order->refund_msg = json_encode($msgData['refund_reason']);
+                        $order->refund_apply = getDateFull();
+                        $order->save();
+                        return json(['err_no' => 0,"err_tips" => "success","data" => [
+                            "out_refund_no" => "R".$order['out_order_no'],
+                            "order_entry_schema"    => [
+                                "path"      => "pages/order/detail",
+                                "params"    => json_encode([
+                                    "order" => $order['out_order_no']
+                                ])
+                            ],
+                            "notify_url"    => "https://tran.jsshuita.cn/notify/refund"
+                        ]]);
+                        break;
                     case "pre_create_order": // 预下单
                         if (!isset($msgData['item_order_info_list'][0]['goods_id'])) return json(['err_no' => 0,"err_tips" => "success"]);
                         $goods = (new SaasGoods)->where("goods_id",$msgData['item_order_info_list'][0]['goods_id'])->findOrEmpty();
@@ -52,7 +71,7 @@ class Solution extends Base
                         $order = (new SaasOrder)->where("order_sn",$msgData['order_id'])->findOrEmpty();
                         if (!$order->isEmpty()) return json(['err_no' => 0,"err_tips" => "success"]);
                         $orderSn = "AL".CodeExtend::uniqidDate(18).rand(100,999);
-                        $goodsImg = is_string($goods['image_list'])?json_decode($goods['image_list'],true):[];
+                        $goodsImg = is_string($goods['image_list'])?json_decode($goods['image_list'],true):$goods['image_list'];
                         $order->insertGetId([
                             "out_order_no"  => $orderSn,
                             "order_sn"  => $msgData['order_id'],
@@ -72,13 +91,13 @@ class Solution extends Base
                         ]);
                         return json(['err_no' => 0,"err_tips" => "success","data" => [
                             "order_entry_schema"    => [
-                                "path"      => "page/order/detail",
+                                "path"      => "pages/order/detail",
                                 "params"    => json_encode([
                                     "order" => $orderSn
                                 ])
                             ],
                             "out_order_no"  => $orderSn,
-                            "pay_expire_seconds"    => 300,
+                            "pay_expire_seconds"    => 1800,
                             "pay_notify_url"        => "https://tran.jsshuita.cn/notify/douyin"
                         ]]);
                         break;
@@ -88,6 +107,9 @@ class Solution extends Base
             }
             return json(['err_no' => 0,"err_tips" => "success"]);
         } catch (\Throwable $throwable) {
+            echo $throwable->getMessage()."\n";
+            echo $throwable->getLine()."\n";
+            echo $throwable->getFile()."\n";
             return error($throwable->getMessage());
         }
     }

+ 0 - 1
app/extra/dyLife/BasicLife.php

@@ -86,7 +86,6 @@ class BasicLife
     public function curlPostApi(string $url = "", array $data = [], string $field = "data"): array
     {
         $result = Http::asJson()->withHeaders($this->header)->post($this->gateway.$url,$data)->array();
-        print_r($result);
         if(!empty($result[$field]))
         {
             return $result[$field];