Ver Fonte

2332001

zory há 1 mês atrás
pai
commit
6ff224f481

+ 1 - 0
app/controller/api/Goods.php

@@ -61,6 +61,7 @@ class Goods extends Base
             $param['sku_name'] = $param['name'];
             $param['poi_id'] = $goods['poi_id'];
             $param['goods_id'] = $goods['id'];
+            $param['left_goods_id'] = $sku['goods_id'];
             $state = (new SaasOrder)->setAutoData($param);
             if (!$state) return error("提交订单失败");
             return success("提交成功",['order' => $param['order_sn']]);

+ 39 - 1
app/controller/api/Notify.php

@@ -3,6 +3,7 @@
 namespace app\controller\api;
 
 use app\extra\basic\Base;
+use app\model\saas\SaasOrder;
 use LinFly\Annotation\Attributes\Route\Controller;
 use LinFly\Annotation\Attributes\Route\PostMapping;
 use support\Request;
@@ -20,9 +21,46 @@ class Notify extends Base
             $param = $request->all();
             echo getDateFull()."===支付返回\n";
             print_r($param);
-            return success("ok");
+            $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"]);
+            if (empty($data)) return json(['err_no' => 0,'err_tips' => "success"]);
+            $order = (new SaasOrder)->where("order_sn",$orderSn)->findOrEmpty();
+            if ($order->isEmpty()) return json(['err_no' => 0,'err_tips' => "success"]);
+            if ($order['status'] <> 0) return json(['err_no' => 0,'err_tips' => "success"]);
+            $order->status = 1;
+            $order->pay_at = getDateFull();
+            $order->pay_type = $data['way'];
+            $order->pay_sn = $data['cp_orderno'];
+            $order->pay_money = $data['total_amount'];
+            $order->save();
+            return json(['err_no' => 0,'err_tips' => "success"]);
         } catch (\Throwable $th) {
             return error($th->getMessage());
         }
     }
+
+    #[PostMapping("refund")]
+    public function getOrderRefund(Request $request): Response
+    {
+        try {
+            $param = $request->all();
+            echo getDateFull()."===退款返回\n";
+            print_r($param);
+            $data = !empty($param['msg']) ? json_decode($param['msg'],true) : [];
+            $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"]);
+            $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());
+        }
+    }
 }

+ 16 - 0
app/controller/api/Order.php

@@ -21,6 +21,8 @@ use support\Response;
 class Order extends Base
 {
 
+
+
     #[Inject]
     protected SaasOrder $model;
 
@@ -57,6 +59,20 @@ class Order extends Base
             if ($order->isEmpty()) return errorTrans("empty.data");
             if ($order['openid'] <> $request->user['openid']) return errorTrans("empty.data");
             if ($order['status'] <> 1) return error("当前订单不支持退款");
+            $reason = explode(",",$param['refund']);
+            $payParam = [
+                "order_sn"      => $order['order_sn'],
+                "total"         => $order['pay_money'],
+                "reason"        => $reason[0]??'不想要了',
+                "out_refund_no" => $order['pay_sn'],
+                "notify_url"    => "https://tran.jsshuita.cn/notify/refund"
+            ];
+            $byteAuthorization = (new Pay)->config([
+                "appid"     => sConf("wechat.mini_appid"),
+                "secret"    => sConf("wechat.mini_secret"),
+                "salt"      => sConf("wechat.mch_salt"),
+            ])->createRefund($payParam);
+            if (!$byteAuthorization) return error("发起退款失败");
             $order->status = 4;
             $order->refund_apply = getDateFull();
             $state = $order->save();

+ 2 - 2
app/controller/api/Service.php

@@ -42,9 +42,9 @@ class Service extends Base
             $list = $this->service->setModel()->getList($param,null,true,['last','avatar'],['last' => function($data,$resp) use($param){
                 $last = (new SaasChatMsg)->where("poi_id",$resp['poi_id'])->where("openid",$param['openid'])->order("create_at desc")->field("content,create_at")->findOrEmpty();
                 if ($last->isEmpty()) {
-                    return ["content"=>"无","create_at"=> formatTime(date("Y-m-d H:i:s",time()))];
+                    return ["content"=>"无",'num' => 0,"create_at"=> formatTime(date("Y-m-d H:i:s",time()))];
                 }
-                return ["content"=> $last['content'],"create_at"=> formatTime($last['create_at'])];
+                return ["content"=> $last['content'],'num' => 0,"create_at"=> formatTime($last['create_at'])];
             },'avatar' => function(){
                 return "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png";
             }]);

+ 50 - 0
app/controller/api/Solution.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace app\controller\api;
+
+use app\extra\basic\Base;
+use app\extra\dyMini\Relation;
+use app\middleware\AuthMiddleware;
+use LinFly\Annotation\Attributes\Route\Controller;
+use LinFly\Annotation\Attributes\Route\GetMapping;
+use LinFly\Annotation\Attributes\Route\Middleware;
+use LinFly\Annotation\Attributes\Route\PostMapping;
+use support\Request;
+use support\Response;
+
+
+/**
+ * 解决方案回传
+ */
+
+#[Controller("/solution")]
+class Solution extends Base
+{
+
+
+    #[PostMapping("notify")]
+    public function getSolutionData(Request $request): Response
+    {
+        try {
+            $data = $request->all();
+            echo getDateFull()."===扩展回调\n";
+            print_r($data);
+            return json(['err_no' => 0,"err_tips" => "success"]);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+
+    #[GetMapping("test")]
+    public function setTest()
+    {
+        try {
+            $data = (new Relation)->config($this->getDyConfig())->token()->createOrderFirst(['1865253598118939']);
+            return success("ok",$data);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+}

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

@@ -86,6 +86,7 @@ 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];

+ 20 - 0
app/extra/dyMini/Pay.php

@@ -29,6 +29,26 @@ class Pay extends BasicLife
         return [];
     }
 
+
+    public function createRefund(array $data = [])
+    {
+        $url = "https://developer.toutiao.com/api/apps/ecpay/v1/create_refund";
+        $param = [
+            "out_order_no"  => $data['out_refund_no'],
+            "out_refund_no" => $data['out_refund_no'],
+//            "out_refund_no" => $data['order_sn'].rand(1000,9999),
+            "refund_amount" => (int) $data['total'],
+            "reason"        => $data['reason'],
+            "notify_url"    => $data['notify_url'],
+            "cp_extra"      => $data['order_sn']
+        ];
+        $param['sign'] = $this->requestSign($param);
+        $param['app_id'] = $this->config['appid'];
+        $resp = Http::asJson()->post($url,$param)->array();
+        if ($resp['err_no'] == 0) return true;
+        return false;
+    }
+
     /**
      * 生成签名
      */

+ 72 - 0
app/extra/dyMini/Relation.php

@@ -0,0 +1,72 @@
+<?php
+
+namespace app\extra\dyMini;
+
+use app\extra\dyLife\BasicLife;
+use yzh52521\EasyHttp\Http;
+
+class Relation extends BasicLife
+{
+
+    /**
+     * 新增测试实体
+     * @param array $goodsId
+     * @return array
+     */
+    public function createTestRelation(array $goodsId = []): array
+    {
+        $param = [
+            "operator"      => "小谢",
+            "ref_id_list"   => $goodsId,
+            "type"          => "goods"
+        ];
+        return $this->curlPostApi("api/industry/v1/solution/add_app_test_relation/",$param);
+    }
+
+
+    public function getTestRelation(array $goodsId = []): array
+    {
+        $param = [
+            "type"          => "goods"
+        ];
+        return $this->curlPostApi("api/industry/v1/solution/query_app_test_relation/",$param,'ref_id_list');
+    }
+
+    /**
+     * 预下单
+     * @param array $data
+     * @return array
+     */
+    public function createOrderFirst(array $data = []): array
+    {
+        $param = [
+            "sku_list"  => [
+                [
+                    "quantity" => 1,
+                      "sku_id" => "424144008809807427",
+                      "sku_id_type" => 1,
+                      "price" =>  1,
+                      "discount_amount" => 0,
+                      "goods_info" => [
+                            "date_rule" => "周一至周日可用",
+                            "goods_id" => "1865253598118939",
+                            "goods_id_type" => 1
+                      ]
+                ]
+            ],
+            "total_amount"  => 1,
+            "discount_amount" => 0,
+            "phone_num" => "13265000719",
+            "contact_name" => "小谢",
+            "extra" => "AL202605156234065268123",
+            "open_id" => "_000KmfiVkio30K9VxoeLUUY3_hngEWcgR7u",
+            "out_order_no" => "AL202605156234065268123",
+            "order_entry_schema" => [
+                "params" => ["order" => "AL202605156234065268123"],
+                "path" => "pages/order/detail"
+            ]
+        ];
+        return $this->curlPostApi("api/apps/trade/v2/order/create_order/",$param);
+    }
+
+}