zory 3 nedēļas atpakaļ
vecāks
revīzija
4ce2aab0f3

+ 64 - 3
app/controller/admin/Store.php

@@ -4,9 +4,13 @@ namespace app\controller\admin;
 
 use app\extra\basic\Base;
 use app\middleware\AuthMiddleware;
+use app\model\saas\SaasStore;
+use app\service\saas\StoreService;
+use DI\Attribute\Inject;
 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\Container;
 use support\Request;
 use support\Response;
@@ -21,16 +25,24 @@ class Store extends Base
 {
 
 
+    #[Inject]
+    protected StoreService $service;
+
+    #[Inject]
+    protected SaasStore $model;
+
+
     /**
      * 数据列表
      * @param Request $request
-     * @return Response|void
+     * @return Response
      */
     #[GetMapping('list')]
-    public function getStoreData(Request $request)
+    public function getStoreData(Request $request): Response
     {
         try {
-
+            $data = $this->service->setModel()->getList($request->all());
+            return successTrans(100010,pageFormat($data),200);
         } catch (\Throwable $th) {
             return error($th->getMessage());
         }
@@ -57,4 +69,53 @@ class Store extends Base
         }
     }
 
+
+    /**
+     * 编辑代理信息
+     * @param Request $request
+     * @return Response
+     */
+    #[PostMapping("edit")]
+    public function setListData(Request $request): Response
+    {
+        try {
+            $param = $request->post();
+            $factory = $this->model->where("id",$param['id'])->findOrEmpty();
+            if ($factory->isEmpty()) return errorTrans("error.data");
+            $state = $this->model->setAutoData($param);
+            if (!$state) return errorTrans("error.data");
+            return successTrans("success.data");
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+    /**
+     * 批量操作
+     * @param Request $request
+     * @return Response
+     */
+    #[PostMapping("batch")]
+    public function setGoodsBatch(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "id.require"        => "参数错误",
+                "value.require"     => "参数错误",
+                "field.require"     => "参数错误",
+                "type.require"      => "参数错误"
+            ],"post");
+            if (!is_array($param)) return error($param);
+            if ($param['type'] == "batch") {
+                $state = $this->model->where("id","in",$param['id'])->save([$param['field'] => $param['value']]);
+            } else {
+                $state = $this->model->where("id",$param['id'])->save([$param['field'] => $param['value']]);
+            }
+            if (!$state) return errorTrans("error.data");
+            return successTrans("success.data");
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
 }

+ 103 - 0
app/controller/admin/StoreUser.php

@@ -0,0 +1,103 @@
+<?php
+
+namespace app\controller\admin;
+
+
+use app\extra\basic\Base;
+use app\extra\tools\CodeExtend;
+use app\middleware\AuthMiddleware;
+use app\model\system\SystemUser;
+use app\service\system\UserService;
+use DI\Attribute\Inject;
+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("/api/store/user"),Middleware(AuthMiddleware::class)]
+class StoreUser extends Base
+{
+
+    #[Inject]
+    protected UserService $service;
+
+    #[Inject]
+    protected SystemUser $model;
+
+
+    #[GetMapping('list')]
+    public function getDataList(Request $request): Response
+    {
+        try {
+            $data = $this->service->setModel()->getList($request->all());
+            return successTrans(100010,pageFormat($data),200);
+        } catch (\Throwable $th) {
+            return error($th->getMessage());
+        }
+    }
+
+
+
+    /**
+     * 账户列表
+     * @param Request $request
+     * @return Response
+     */
+    #[PostMapping("save")]
+    public function setUserData(Request $request): Response
+    {
+        try {
+            $param = $request->post();
+            if(!isset($param['id'])) // 新增
+            {
+                $param['salt'] = CodeExtend::random(6,3);
+                $param['password'] = md5($param['password'].$param['salt']);
+                $param['create_ip'] = $request->getRealIp();
+                $user = $this->model->where("username",$param['username'])->findOrEmpty();
+                if (!$user->isEmpty()) return errorTrans(20011);
+            }
+            if (isset($param['app_id'])) {
+                $param['app_id'] = json_encode($param['app_id']);
+            }
+            if(isset($param['role_path']) && is_array($param['role_path'])){
+                $parent = $param['role_path'];
+                $param['role_path'] = implode(",",$parent);
+                $param['role_id'] = $parent[count($parent) - 1];
+            }
+            $state = $this->model->setAutoData($param);
+            if (!$state) return errorTrans(100011);
+            return successTrans(100010);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+
+
+    /**
+     * 修改密码
+     * @param Request $request
+     * @return Response
+     */
+    #[PostMapping("passwd")]
+    public function setUserPasswd(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "id.require"        => trans(20010),
+                "password.require"  => trans(20010)
+            ],"post");
+            if (!is_array($param)) return error($param);
+            $user = $this->model->where("id",$param['id'])->findOrEmpty();
+            if ($user->isEmpty()) return errorTrans("empty.error");
+            $user->password = md5($param['password'].$user['salt']);
+            $state = $user->save();
+            if (!$state) return errorTrans(100102);
+            return successTrans(100010);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+}

+ 3 - 2
app/controller/common/Login.php

@@ -4,6 +4,7 @@ namespace app\controller\common;
 
 use app\extra\basic\Base;
 use app\middleware\AuthMiddleware;
+use app\model\saas\SaasStore;
 use app\model\system\SystemConfig;
 use app\model\system\SystemUser;
 use DI\Attribute\Inject;
@@ -68,7 +69,7 @@ class Login extends Base
             if (empty($typeUser)) return [0,trans("empty.agent"),[]];
             if ($typeUser['status'] <> 0) return [0,trans("error.agent"),[]];
             if (time() > strtotime($typeUser['vip_end'])) return [0,trans("error.agent-out"),[]];
-            $user['shop_name'] = $typeUser['shop_name'];
+            $user['shop_name'] = $typeUser['poi_name'];
         }
         if ($type == 2) {
             if (md5($param['password'].$user['salt']) <> $user['password']) return [0,trans("error.passwd"),[]];
@@ -88,7 +89,7 @@ class Login extends Base
      */
     protected function getTypeUser(int $agentId = 0): array
     {
-        return [];
+        return (new SaasStore)->where("poi_id",$agentId)->findOrEmpty()->toArray();
     }
 
     #[GetMapping('profile')]

+ 12 - 0
app/extra/basic/Service.php

@@ -100,4 +100,16 @@ class Service
         return $this->mode->order($orderBy)->where($filter);
     }
 
+
+    /**
+     *
+     */
+    public function getList(array $param = [])
+    {
+        return $this->searchVal($param,$this->searchFilter($param))->paginate([
+            "list_rows" => $param['pageSize'],
+            "page"      => $param['page']
+        ]);
+    }
+
 }

+ 1 - 7
app/extra/dyLife/Token.php

@@ -21,13 +21,7 @@ class Token extends BasicLife
             "client_secret"     => $this->config['secret'],
             "grant_type"        => $grantType
         ];
-        $url = $this->gateway."oauth/client_token/";
-        $result = Http::asJson()->post($url,$data)->array();
-        if(!empty($result['data']))
-        {
-            return $result['data'];
-        }
-        return [];
+        return $this->curlPostApi("oauth/client_token/",$data);
     }
 
 }

+ 137 - 0
app/extra/tools/CodeExtend.php

@@ -0,0 +1,137 @@
+<?php
+
+namespace app\extra\tools;
+
+class CodeExtend
+{
+
+    /**
+     * 生成随机编码
+     * @param integer $size 编码长度
+     * @param integer $type 编码类型(1纯数字,2纯字母,3数字字母)
+     * @param string $prefix 编码前缀
+     * @return string
+     */
+    public static function random(int $size = 10, int $type = 1, string $prefix = ''): string
+    {
+        $numbs = '0123456789';
+        $chars = 'abcdefghijklmnopqrstuvwxyz';
+        if ($type === 1) $chars = $numbs;
+        if ($type === 3) $chars = "{$numbs}{$chars}";
+        $code = $prefix . $chars[rand(1, strlen($chars) - 1)];
+        while (strlen($code) < $size) $code .= $chars[rand(0, strlen($chars) - 1)];
+        return $code;
+    }
+
+    /**
+     * 生成日期编码
+     * @param integer $size 编码长度
+     * @param string $prefix 编码前缀
+     * @return string
+     */
+    public static function uniqidDate(int $size = 16, string $prefix = ''): string
+    {
+        if ($size < 14) $size = 14;
+        $code = $prefix . date('Ymd') . (date('H') + date('i')) . date('s');
+        while (strlen($code) < $size) $code .= rand(0, 9);
+        return $code;
+    }
+
+    /**
+     * 生成数字编码
+     * @param integer $size 编码长度
+     * @param string $prefix 编码前缀
+     * @return string
+     */
+    public static function uniqidNumber(int $size = 12, string $prefix = ''): string
+    {
+        $time = strval(time());
+        if ($size < 10) $size = 10;
+        $code = $prefix . (intval($time[0]) + intval($time[1])) . substr($time, 2) . rand(0, 9);
+        while (strlen($code) < $size) $code .= rand(0, 9);
+        return $code;
+    }
+
+    /**
+     * 文本转码
+     * @param string $text 文本内容
+     * @param string $target 目标编码
+     * @return string
+     */
+    public static function text2utf8(string $text, string $target = 'UTF-8'): string
+    {
+        [$first2, $first4] = [substr($text, 0, 2), substr($text, 0, 4)];
+        if ($first4 === chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF)) $ft = 'UTF-32BE';
+        elseif ($first4 === chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00)) $ft = 'UTF-32LE';
+        elseif ($first2 === chr(0xFE) . chr(0xFF)) $ft = 'UTF-16BE';
+        elseif ($first2 === chr(0xFF) . chr(0xFE)) $ft = 'UTF-16LE';
+        return mb_convert_encoding($text, $target, $ft ?? mb_detect_encoding($text));
+    }
+
+    /**
+     * 数据解密处理
+     * @param mixed $data 加密数据
+     * @param string $skey 安全密钥
+     * @return string
+     */
+    public static function encrypt($data, string $skey): string
+    {
+        $iv = static::random(16, 3);
+        $value = openssl_encrypt(serialize($data), 'AES-256-CBC', $skey, 0, $iv);
+        return static::enSafe64(json_encode(['iv' => $iv, 'value' => $value]));
+    }
+
+    /**
+     * 数据加密处理
+     * @param string $data 解密数据
+     * @param string $skey 安全密钥
+     * @return mixed
+     */
+    public static function decrypt(string $data, string $skey)
+    {
+        $attr = json_decode(static::deSafe64($data), true);
+        return unserialize(openssl_decrypt($attr['value'], 'AES-256-CBC', $skey, 0, $attr['iv']));
+    }
+
+    /**
+     * Base64Url 安全编码
+     * @param string $text 待加密文本
+     * @return string
+     */
+    public static function enSafe64(string $text): string
+    {
+        return rtrim(strtr(base64_encode($text), '+/', '-_'), '=');
+    }
+
+    /**
+     * Base64Url 安全解码
+     * @param string $text 待解密文本
+     * @return string
+     */
+    public static function deSafe64(string $text): string
+    {
+        return base64_decode(str_pad(strtr($text, '-_', '+/'), strlen($text) % 4, '='));
+    }
+
+    /**
+     * 压缩数据对象
+     * @param mixed $data
+     * @return string
+     */
+    public static function enzip($data): string
+    {
+        return static::enSafe64(gzcompress(serialize($data)));
+    }
+
+    /**
+     * 解压数据对象
+     * @param string $string
+     * @return mixed
+     */
+    public static function dezip(string $string)
+    {
+        return unserialize(gzuncompress(static::deSafe64($string)));
+    }
+
+
+}

+ 35 - 0
app/service/saas/StoreService.php

@@ -0,0 +1,35 @@
+<?php
+
+namespace app\service\saas;
+
+use app\extra\basic\Service;
+use app\model\saas\SaasStore;
+
+class StoreService extends Service
+{
+
+    /**
+     *
+     * @return $this
+     */
+    public function setModel()
+    {
+        $this->mode = (new SaasStore);
+        return $this;
+    }
+
+
+    /**
+     *
+     * @param array $param
+     * @return array
+     */
+    public function searchFilter(array $param = []): array
+    {
+        $filter = [];
+        !empty($param['status']) && $filter[] = ["status", '=', $param['status']];
+        !empty($param['name']) && $filter[] = ["poi_name", 'like', "%{$param['name']}%"];
+        return $filter;
+    }
+
+}

+ 35 - 0
app/service/system/UserService.php

@@ -0,0 +1,35 @@
+<?php
+
+namespace app\service\system;
+
+use app\extra\basic\Service;
+use app\model\system\SystemUser;
+
+class UserService extends Service
+{
+
+    /**
+     *
+     * @return $this
+     */
+    public function setModel()
+    {
+        $this->mode = (new SystemUser);
+        return $this;
+    }
+
+    /**
+     *
+     * @param array $param
+     * @return array
+     */
+    public function searchFilter(array $param = []): array
+    {
+        $filter = [];
+        !empty($param['status']) && $filter[] = ["status", '=', $param['status']];
+        !empty($param['name']) && $filter[] = ["poi_name", 'like', "%{$param['name']}%"];
+        return $filter;
+    }
+
+
+}