Zory 3 周之前
父节点
当前提交
c0b7a344f3

+ 18 - 0
app/controller/admin/Store.php

@@ -7,6 +7,7 @@ use app\middleware\AuthMiddleware;
 use LinFly\Annotation\Attributes\Route\Controller;
 use LinFly\Annotation\Attributes\Route\GetMapping;
 use LinFly\Annotation\Attributes\Route\Middleware;
+use support\Container;
 use support\Request;
 use support\Response;
 use Webman\RedisQueue\Redis;
@@ -19,6 +20,23 @@ use Webman\RedisQueue\Redis;
 class Store extends Base
 {
 
+
+    /**
+     * 数据列表
+     * @param Request $request
+     * @return Response|void
+     */
+    #[GetMapping('list')]
+    public function getStoreData(Request $request)
+    {
+        try {
+
+        } catch (\Throwable $th) {
+            return error($th->getMessage());
+        }
+    }
+
+
     /**
      * 同步POI门店
      * @param Request $request

+ 30 - 0
app/controller/api/Home.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace app\controller\api;
+
+use app\extra\basic\Base;
+use app\middleware\AuthMiddleware;
+use LinFly\Annotation\Attributes\Route\Controller;
+use LinFly\Annotation\Attributes\Route\Middleware;
+use support\Request;
+
+
+#[Controller("/dy/home"),Middleware(AuthMiddleware::class)]
+class Home extends Base
+{
+
+    /**
+     * @var array|string[]
+     */
+    protected array $noNeedLogin = ["getHomeData"];
+
+    public function getHomeData(Request $request)
+    {
+        try {
+            return $this->success("ok");
+        } catch (\Throwable $th) {
+            return error($th->getMessage());
+        }
+    }
+
+}

+ 5 - 4
app/extra/basic/Base.php

@@ -2,6 +2,7 @@
 
 namespace app\extra\basic;
 
+use support\Response;
 use think\contract\Arrayable;
 use think\Validate;
 
@@ -104,11 +105,11 @@ class Base
     }
 
     /**
-     * @param string|array|Arrayable $message
-     * @param array|Arrayable|null $data
-     * @return Json
+     * @param string $message
+     * @param array|null $data
+     * @return Response
      */
-    public function success($message = self::DEFAULT_SUCCESS_MESSAGE, $data = null)
+    public function success(string $message = self::DEFAULT_SUCCESS_MESSAGE, array $data = null): Response
     {
         $message = $this->parseData($message);
         if (is_array($message)) {

+ 35 - 3
app/extra/dyLife/BasicLife.php

@@ -3,6 +3,7 @@
 namespace app\extra\dyLife;
 
 use support\think\Cache;
+use yzh52521\EasyHttp\Http;
 
 class BasicLife
 {
@@ -21,9 +22,7 @@ class BasicLife
      * 默认header
      * @var string[]
      */
-    protected array $header = [
-        "content-type"  => "application/json"
-    ];
+    protected array $header = [];
 
     /**
      * AccessToken前缀
@@ -77,4 +76,37 @@ class BasicLife
         return str_replace("[appid]",$this->config['appid'],$this->prefix);
     }
 
+
+    /**
+     * @param string $url
+     * @param array $data
+     * @param string $field
+     * @return array
+     */
+    public function curlPostApi(string $url = "", array $data = [], string $field = "data"): array
+    {
+        $result = Http::asJson()->withHeaders($this->header)->post($this->gateway.$url,$data)->array();
+        if(!empty($result[$field]))
+        {
+            return $result[$field];
+        }
+        return [];
+    }
+
+    /**
+     * @param string $url
+     * @param array $data
+     * @param string $field
+     * @return array
+     */
+    public function curlGetApi(string $url = "", array $data = [], string $field = "data"): array
+    {
+        $result = Http::asJson()->withHeaders($this->header)->get($this->gateway.$url,$data)->array();
+        if(!empty($result[$field]))
+        {
+            return $result[$field];
+        }
+        return [];
+    }
+
 }

+ 4 - 16
app/extra/dyLife/data/BaseData.php

@@ -12,39 +12,27 @@ class BaseData extends BasicLife
      * 获取来客绑定的所有门店
      * 一页最多50条
      */
-    public function getStoreData(string $account,int $page = 1,int $size = 50)
+    public function getStoreData(string $account,int $page = 1,int $size = 50): array
     {
         $data = [
             "account_id"    => $account,
             "page"          => $page,
             "size"          => $size
         ];
-        $url = "{$this->gateway}goodlife/v1/shop/poi/query/";
-        $result = Http::asJson()->withHeaders($this->header)->get($url,$data)->array();
-        if(!empty($result['data']))
-        {
-            return $result['data'];
-        }
-        return [];
+        return $this->curlGetApi("goodlife/v1/shop/poi/query/",$data);
     }
 
 
     /**
      * 获取来客绑定的所有分类
      */
-    public function getStoreCategoryData(string $account)
+    public function getStoreCategoryData(string $account): array
     {
         $data = [
             "account_id"            => $account,
             "query_category_type"   => 1
         ];
-        $url = "{$this->gateway}goodlife/v1/goods/category/get/";
-        $result = Http::asJson()->withHeaders($this->header)->get($url,$data)->array();
-        if(!empty($result['data']))
-        {
-            return $result['data'];
-        }
-        return [];
+        return $this->curlGetApi("goodlife/v1/goods/category/get/",$data);
     }
 
 }

+ 6 - 2
app/middleware/AuthMiddleware.php

@@ -21,8 +21,12 @@ class AuthMiddleware implements MiddlewareInterface
                 if (empty($type)) return json(['code'=> 0,'msg'=> trans("error.param")]);
                 $token =  $request->header("Authorization","");
                 if (empty($token)) return json(['code'=> 0,'msg'=> trans("error.request")]);
-                (new JWT)->guard("admin")->verify();
-                $user = (new Auth)->guard("admin")->user();
+                $guard = "admin";
+                if ($type == 'mini') {
+                    $guard = "user";
+                }
+                (new JWT)->guard($guard)->verify();
+                $user = (new Auth)->guard($guard)->user();
                 if (empty($user)) return json(['code'=>401,'msg'=> trans("error.login")]);
                 $request->user = $user->toArray();
             }

+ 0 - 0
webman