Kirin 1 tydzień temu
rodzic
commit
8fdc02e9ff

+ 32 - 0
app/Request.php

@@ -2,6 +2,8 @@
 
 namespace app;
 
+use app\services\system\store\SystemStoreServices;
+use think\exception\ValidateException;
 use think\facade\Lang;
 
 /**
@@ -13,6 +15,10 @@ class Request extends \think\Request
 
     private $adminInfo = null;
     private $user = null;
+
+    private $adminStoreId = 0;
+    private $adminStoreInfo = null;
+
     private $tokenData = null;
     private $longitude = 0;
     private $latitude = 0;
@@ -32,6 +38,11 @@ class Request extends \think\Request
     public function setAdmin($adminInfo)
     {
         $this->adminInfo = $adminInfo;
+        if ($adminInfo['admin_type'] == 2) {
+            $this->adminStoreId = $adminInfo['relation_id'];
+        } else {
+            $this->adminStoreId = 0;
+        }
     }
 
     public function setLang($lang)
@@ -52,6 +63,17 @@ class Request extends \think\Request
         return $this->lang;
     }
 
+    public function setStoreInfo($storeId)
+    {
+        /** @var SystemStoreServices $storeService */
+        $storeService = app()->make(SystemStoreServices::class);
+        $storeInfo = $storeService->get($storeId);
+        if (!$storeInfo) {
+            throw new ValidateException('店铺不存在');
+        }
+        $this->adminStoreInfo = $storeInfo;
+    }
+
 
     public function setUser($user)
     {
@@ -292,5 +314,15 @@ class Request extends \think\Request
         return [$this->latitude, $this->longitude];
     }
 
+    public function adminStoreId()
+    {
+        return $this->adminStoreId;
+    }
+
+    public function adminStoreInfo()
+    {
+        return $this->adminStoreInfo;
+    }
+
 
 }

+ 182 - 0
app/common/StoreBaseController.php

@@ -0,0 +1,182 @@
+<?php
+/**
+ * @Created by PhpStorm
+ * @author: Kirin
+ * @day: 2024/11/20
+ * @time: 11:24
+ */
+
+namespace app\common;
+
+
+use app\Request;
+use qiniu\basic\BaseController;
+use qiniu\exceptions\AdminException;
+
+abstract class StoreBaseController extends BaseController
+{
+
+
+    /**
+     * 当前登陆管理员信息
+     * @var
+     */
+    protected $adminInfo;
+
+    /**
+     * 当前登陆管理员ID
+     * @var
+     */
+    protected $adminId;
+
+    protected $storeId;
+
+    protected $storeInfo;
+
+    protected $auth = [];
+
+    // 搜索条件
+    protected $searchable = [];
+    // 搜索处理
+    protected $searchDeal = null;
+
+    // 创建参数
+    protected $createParams = [];
+    // 新增处理
+    protected $saveDeal = null;
+    // 更新处理
+    protected $updateDeal = null;
+
+    protected $validate = null;
+
+    protected $service = null;
+
+    protected $with = [];
+
+    protected $storeSearch = false;
+
+    /**
+     * 初始化
+     */
+
+    public function __construct(Request $request)
+    {
+        parent::__construct($request);
+        $this->initialize();
+    }
+
+    protected function initialize()
+    {
+        $this->adminId = $this->request->adminId();
+        $this->adminInfo = $this->request->adminInfo();
+        $this->storeId = $this->request->adminStoreId();
+        $this->storeInfo = $this->request->adminStoreInfo();
+        $this->auth = $this->adminInfo['rule'] ?? [];
+    }
+
+
+    public function index()
+    {
+        if (!$this->service) {
+            throw new AdminException('接口不存在');
+        }
+        $where = $this->request->getMore($this->searchable, false, $this->searchDeal);
+        if ($this->storeSearch) $where['store_id'] = $this->storeId;
+        list($page, $limit) = $this->service->getPageValue();
+        $list = $this->service->getList($where, '*', $page, $limit, $this->with);
+        $count = $this->service->getCount($where);
+        return $this->success(compact('list', 'count'));
+    }
+
+
+    public function read($id)
+    {
+        if (!$this->service) {
+            throw new AdminException('接口不存在');
+        }
+        if ($this->storeSearch) {
+            $info = $this->service->getOne(['id' => $id, 'store_id' => $this->storeId], '*', $this->with);
+        } else {
+            $info = $this->service->get($id, '*', $this->with);
+        }
+        if (!$info)
+            return $this->error('数据不存在');
+        return $this->success('ok', $info->toArray());
+    }
+
+
+    public function save()
+    {
+        if (!$this->service) {
+            throw new AdminException('接口不存在');
+        }
+        $data = $this->request->postMore($this->createParams, false, $this->saveDeal);
+        if ($this->validate) {
+            $this->validate($data, $this->validate, 'save');
+        }
+        $res = $this->service->create($data);
+        if ($res) return $this->success('添加成功');
+        return $this->error('添加失败');
+    }
+
+    public function validate($data, $validate, $s = '')
+    {
+        $scene = method_exists($validate, 'allScene') ? ($validate->allScene() ?? []) : [];
+        if (in_array($s, $scene))
+            $res = $validate->scene($s)->check($data);
+        else
+            $res = $validate->check($data);
+        if (!$res) throw new AdminException($validate->getError());
+    }
+
+
+    public function update($id)
+    {
+        if (!$this->service) {
+            throw new AdminException('接口不存在');
+        }
+        if ($this->storeSearch) {
+            $info = $this->service->getOne(['id' => $id, 'store_id' => $this->storeId], '*', $this->with);
+        } else {
+            $info = $this->service->get($id);
+        }
+        if (!$info)
+            return $this->error('数据不存在');
+        $data = $this->request->postMore($this->createParams, false, $this->updateDeal, $id);
+        if ($this->validate) {
+            $this->validate($data, $this->validate, 'update');
+        }
+        $res = $this->service->update($id, $data);
+        if ($res) return $this->success('修改成功');
+        return $this->error('修改失败');
+    }
+
+
+    public function delete($id)
+    {
+        if (!$this->service) {
+            throw new AdminException('接口不存在');
+        }
+        if ($this->storeSearch) {
+            $info = $this->service->getOne(['id' => $id, 'store_id' => $this->storeId], '*', $this->with);
+        } else {
+            $info = $this->service->get($id);
+        }
+        if (!$info)
+            return $this->error('数据不存在');
+        $res = $this->service->delete($id);
+        if ($res) return $this->success('已删除');
+        return $this->error('删除失败');
+    }
+
+    public function export()
+    {
+        if (!$this->service) {
+            throw new AdminException('接口不存在');
+        }
+        $where = $this->request->getMore($this->searchable, false, $this->searchDeal);
+        if ($this->storeSearch) $where['store_id'] = $this->storeId;
+        $export_type = sys_config('export_type', 1);
+        return $this->success($this->service->export($where, $export_type));
+    }
+}

+ 8 - 8
app/controller/admin/system/Qrcode.php

@@ -30,14 +30,14 @@ class Qrcode extends AdminBaseController
         };
         $this->createParams = [
             ['third_type', ''],
-            ['third_id', 0],
-            ['ticket', ''],
-            ['expire_seconds', 0],
-            ['status', '1'],
-            ['url', ''],
-            ['qrcode_url', ''],
-            ['scan', 0],
-            ['type', '3']
+	        ['third_id', 0],
+	        ['ticket', ''],
+	        ['expire_seconds', 0],
+	        ['status', '1'],
+	        ['url', ''],
+	        ['qrcode_url', ''],
+	        ['scan', 0],
+	        ['type', '3']
         ];
         $this->saveDeal = $this->updateDeal = function (&$data){
         };

+ 1 - 2
app/controller/admin/system/SystemAdmins.php

@@ -15,7 +15,6 @@ use app\services\system\admin\SystemAdminServices;
 use app\services\system\admin\SystemRoleServices;
 use app\validate\admin\SystemAdminValidate;
 use think\exception\ValidateException;
-use think\Validate;
 
 class SystemAdmins extends AdminBaseController
 {
@@ -71,7 +70,7 @@ class SystemAdmins extends AdminBaseController
             return $this->error('数据不存在');
         /** @var SystemRoleServices $services */
         $services = app()->make(SystemRoleServices::class);
-        $info['roles'] = $services->getRoleArray(['level' => $this->adminInfo['level'] + 1]);
+        $info['roles'] = $services->getRoleArray(['level' => $this->adminInfo['level'] + 1, 'type' => 0]);
         return $this->success('ok', $info->toArray());
     }
 

+ 1 - 0
app/controller/admin/system/SystemLogs.php

@@ -30,6 +30,7 @@ class SystemLogs extends AdminBaseController
             ['path', ''],
             ['ip', ''],
         ]);
+        $where['store_id'] = 0;
         return $this->success($this->service->getLogList($where, $this->adminInfo['level']));
     }
 

+ 2 - 1
app/controller/admin/system/SystemRoles.php

@@ -58,7 +58,7 @@ class SystemRoles extends AdminBaseController
             return $this->error('数据不存在');
         /** @var SystemMenusServices $services */
         $services = app()->make(SystemMenusServices::class);
-        $info['menus'] = $services->getMenus($this->adminInfo['level'] == 0 ? [] : $this->adminInfo['roles'], 1, 0);
+        $info['menus'] = $services->getMenus($this->adminInfo['level'] == 0 ? [] : $this->adminInfo['roles'], $this->adminInfo['admin_type'] - 1, 0);
         return $this->success('ok', $info->toArray());
     }
 
@@ -67,6 +67,7 @@ class SystemRoles extends AdminBaseController
     {
         $data = $this->request->postMore($this->createParams);
         $data['level'] = $this->adminInfo['level'] + 1;
+        $data['type'] = 0;
         $res = $this->service->create($data);
         if ($res) return $this->success('添加成功');
         return $this->error('添加失败');

+ 0 - 1
app/controller/admin/system/config/SystemConfig.php

@@ -20,7 +20,6 @@ use think\db\exception\DbException;
 use think\db\exception\ModelNotFoundException;
 use think\facade\App;
 use think\Response;
-use think\Validate;
 
 /**
  * 系统配置

+ 18 - 1
app/controller/admin/system/store/SystemStore.php

@@ -8,6 +8,7 @@
 
 namespace app\controller\admin\system\store;
 
+use app\model\system\admin\SystemAdmin;
 use app\Request;
 use app\services\system\admin\SystemAdminServices;
 use think\db\exception\DataNotFoundException;
@@ -81,7 +82,7 @@ class SystemStore extends AdminBaseController
                 }
             }
             if (!$uid) {
-               throw new ValidateException('请选择门店管理员');
+                throw new ValidateException('请选择门店管理员');
             }
         };
     }
@@ -251,4 +252,20 @@ class SystemStore extends AdminBaseController
             return $this->success('删除门店成功!');
         }
     }
+
+    public function adminLogin($id)
+    {
+        /** @var SystemAdminServices $adminService */
+        $adminService = app()->make(SystemAdminServices::class);
+        $storeAdmin = $adminService->search(['admin_type' => '2', 'relation_id' => $id, 'level' => 0])->find();
+        if (!$storeAdmin) {
+            return $this->error('管理员不存在');
+        }
+        $token = $tokenInfo = $adminService->createToken($storeAdmin->id, 'store', $storeAdmin['pwd']);
+        if (!$token) {
+            return $this->error('登录失败');
+        } else {
+            return $this->success('登录成功', ['token' => $tokenInfo['token'], 'expires_time' => $tokenInfo['expires_time']]);
+        }
+    }
 }

+ 105 - 0
app/controller/store/Common.php

@@ -0,0 +1,105 @@
+<?php
+/**
+ * @Created by PhpStorm
+ * @author: Kirin
+ * @day: 2024/11/20
+ * @time: 17:59
+ */
+
+namespace app\controller\store;
+
+
+use app\common\StoreBaseController;
+use app\services\system\admin\SystemMenusServices;
+use app\services\system\admin\SystemRoleServices;
+use app\services\system\CityAreaServices;
+use Psr\SimpleCache\InvalidArgumentException;
+use qiniu\services\CacheService;
+use think\db\exception\DataNotFoundException;
+use think\db\exception\DbException;
+use think\db\exception\ModelNotFoundException;
+
+class Common extends StoreBaseController
+{
+
+    public function adminInfo(SystemMenusServices $services, SystemRoleServices $roleServices)
+    {
+        $adminInfo = $this->adminInfo;
+        $storeInfo = $this->storeInfo;
+        [$menus, $uniqueAuth] = $services->getMenusList($adminInfo['roles'], (int)$adminInfo['level'], 2, $this->storeId);
+        return $this->success([
+            'menus' => $menus,
+            'unique_auth' => $uniqueAuth,
+            'role' => $services->getMenus($this->adminInfo['level'] == 0 ? [] : $this->adminInfo['roles'], 1, 0),
+            'user_info' => [
+                'id' => $adminInfo['id'],
+                'account' => $adminInfo['account'],
+                'phone' => $adminInfo['phone'],
+                'real_name' => $adminInfo['real_name'],
+                'head_pic' => $adminInfo['head_pic'],
+                'roles' => $roleServices->getRolesNames($adminInfo['roles'])
+            ],
+            'store_info' => $storeInfo,
+            'map_key' => sys_config('tengxun_map_key')
+        ]);
+    }
+
+    public function getConfig()
+    {
+        return $this->success([$this->request->get('key', 'site_name') => sys_config($this->request->get('key', 'site_name'))]);
+    }
+
+    /**
+     * 格式化菜单
+     * @return mixed
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException|InvalidArgumentException
+     */
+    public function menusList()
+    {
+        $cahcheKey = md5('admin_common_menu_list');
+        $list = CacheService::redisHandler()->get($cahcheKey);
+        if (!$list) {
+            /** @var SystemMenusServices $menusServices */
+            $menusServices = app()->make(SystemMenusServices::class);
+            $menus = $menusServices->search(['is_show' => 1, 'auth_type' => 1, 'is_show_path' => 0])->where('type', 2)
+                ->field('id,pid,menu_name,menu_path,unique_auth,sort')->order('sort DESC')->select();
+            $counts = $menusServices->getColumn([
+                ['is_show', '=', 1],
+                ['auth_type', '=', 1],
+                ['is_show_path', '=', 0],
+            ], 'pid');
+            $data = [];
+            foreach ($menus as $key => $item) {
+                $pid = $item->getData('pid');
+                $data[$key] = json_decode($item, true);
+                $data[$key]['pid'] = $pid;
+                if (in_array($item->id, $counts)) {
+                    $data[$key]['type'] = 1;
+                } else {
+                    $data[$key]['type'] = 0;
+                }
+                $data[$key]['menu_path'] = preg_replace('/^\/admin/', '', $item['menu_path']);
+            }
+            $list = sort_list_tier($data);
+            CacheService::redisHandler()->set($cahcheKey, $list, 86400);
+        }
+        return $this->success($list);
+    }
+
+    /**
+     * @param CityAreaServices $services
+     * @return mixed
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException
+     */
+    public function city(CityAreaServices $services)
+    {
+        $pid = $this->request->get('pid', 0);
+        $type = $this->request->get('type', 0);
+        return $this->success($services->getCityTreeList((int)$pid, $type));
+    }
+
+}

+ 135 - 0
app/controller/store/Login.php

@@ -0,0 +1,135 @@
+<?php
+/**
+ * @Created by PhpStorm
+ * @author: Kirin
+ * @day: 2024/11/20
+ * @time: 11:21
+ */
+
+namespace app\controller\store;
+
+
+use app\common\StoreBaseController;
+use app\services\system\admin\SystemAdminServices;
+use app\validate\admin\SystemAdminValidate;
+use qiniu\services\CacheService;
+use qiniu\services\SystemConfigService;
+use qiniu\utils\Captcha;
+use think\facade\Cache;
+use think\facade\Config;
+
+class Login extends StoreBaseController
+{
+    /**
+     * 验证码
+     * @return $this|\think\Response
+     */
+    public function captcha()
+    {
+        return app()->make(Captcha::class)->create();
+    }
+
+    /**
+     * 获取验证码
+     * @return mixed
+     */
+    public function getAjCaptcha()
+    {
+        [$account,] = $this->request->postMore([
+            'account',
+        ], true);
+
+        $key = 'login_captcha_' . $account;
+
+        return $this->success(['is_captcha' => Cache::get($key) > 2]);
+    }
+
+    /**
+     * 获取后台登录页轮播图以及LOGO
+     * @return mixed
+     */
+    public function info()
+    {
+        $data = SystemConfigService::more(['site_name', 'admin_login_slide', 'site_logo_square', 'site_logo', 'login_logo'], true);
+        return $this->success([
+            'slide' => sys_config('admin_login_slide') ?? [],
+            'logo_square' => $data['site_logo_square'] ?? '',//透明
+            'logo_rectangle' => $data['site_logo'] ?? '',//方形
+            'login_logo' => $data['login_logo'] ?? '',//登陆
+            'site_name' => $data['site_name'],
+            'upload_file_size_max' => config('upload.filesize'),//文件上传大小kb
+        ]);
+    }
+
+    /**
+     * @return mixed
+     */
+    public function ajcaptcha()
+    {
+        $captchaType = $this->request->get('captchaType');
+        return $this->success(aj_captcha_create($captchaType));
+    }
+
+
+    /**
+     * 一次验证
+     * @return mixed
+     */
+    public function ajcheck()
+    {
+        [$token, $pointJson, $captchaType] = $this->request->postMore([
+            ['token', ''],
+            ['pointJson', ''],
+            ['captchaType', ''],
+        ], true);
+        try {
+            aj_captcha_check_one($captchaType, $token, $pointJson);
+            return $this->success();
+        } catch (\Throwable $e) {
+            return $this->error();
+        }
+    }
+
+    /**
+     * 登陆
+     * @return mixed
+     */
+    public function login(SystemAdminServices $service)
+    {
+        [$account, $password, $captchaType, $captchaVerification] = $this->request->postMore([
+            'account',
+            'pwd',
+            ['captchaType', ''],
+            ['captchaVerification', ''],
+        ], true);
+
+        $key = 'login_captcha_' . $account;
+
+
+        if (Cache::has($key) && Cache::get($key) > 2) {
+            if (!$captchaType || !$captchaVerification) {
+                return $this->error('请拖动滑块验证');
+            }
+            //二次验证
+            try {
+                aj_captcha_check_two($captchaType, $captchaVerification);
+            } catch (\Throwable $e) {
+                return $this->error($e->getError());
+            }
+        }
+        validate(SystemAdminValidate::class)->scene('get')->check(['account' => $account, 'pwd' => $password]);
+        $res = $service->login($account, $password, 'store');
+        if ($res) {
+            Cache::delete($key);
+        }
+        return $this->success($res);
+    }
+
+    public function logout()
+    {
+        $key = trim(ltrim($this->request->header(Config::get('cookie.token_name')), 'Bearer'));
+        CacheService::redisHandler()->delete(md5($key));
+        return $this->success();
+    }
+
+}

+ 23 - 0
app/controller/store/finance/Finance.php

@@ -0,0 +1,23 @@
+<?php
+/**
+ * @Created by PhpStorm
+ * @author: Kirin
+ * @day: 2024/12/12
+ * @time: 9:59
+ */
+
+namespace app\controller\store\finance;
+
+
+use app\common\StoreBaseController;
+use app\Request;
+use app\services\user\UserBrokerageServices;
+use app\services\user\UserMoneyServices;
+
+class Finance extends StoreBaseController
+{
+    public function __construct(Request $request)
+    {
+        parent::__construct($request);
+    }
+}

+ 120 - 0
app/controller/store/system/SystemAdmins.php

@@ -0,0 +1,120 @@
+<?php
+/**
+ * @Created by PhpStorm
+ * @author: Kirin
+ * @day: 2024/11/21
+ * @time: 17:39
+ */
+
+namespace app\controller\store\system;
+
+
+use app\common\StoreBaseController;
+use app\Request;
+use app\services\system\admin\SystemAdminServices;
+use app\services\system\admin\SystemRoleServices;
+use app\validate\admin\SystemAdminValidate;
+
+class SystemAdmins extends StoreBaseController
+{
+    public function __construct(Request $request, SystemAdminServices $service)
+    {
+        parent::__construct($request);
+        $this->service = $service;
+        $this->request->filter(['addslashes', 'trim']);
+        $this->validate = new SystemAdminValidate();
+        $this->createParams = [
+            ['account', ''],
+            ['conf_pwd', ''],
+            ['pwd', ''],
+            ['real_name', ''],
+            ['phone', ''],
+            ['roles', []],
+            ['status', 0]
+        ];
+        $this->searchable = [
+            ['name', '', '', 'account_like'],
+            ['roles', ''],
+            ['status', '']
+        ];
+        $this->saveDeal = $this->updateDeal = function (&$data) {
+            $data['level'] = $this->adminInfo['level'] + 1;
+        };
+
+    }
+
+    /**
+     * 显示管理员资源列表
+     *
+     * @return \think\Response
+     */
+    public function index()
+    {
+        $where = $this->request->getMore($this->searchable);
+        $where['level'] = $this->adminInfo['level'] + 1;
+        $where['store_id'] = $this->storeId;
+        return $this->success($this->service->getAdminList($where));
+    }
+
+    /**
+     * @param $id
+     * @return mixed
+     */
+    public function read($id)
+    {
+        $info = $this->service->get($id);
+        if (!$info)
+            return $this->error('数据不存在');
+        if ($info['level'] != $this->adminInfo['level'] + 1 || $info['admin_type'] != 2 || $info['relation_id'] != $this->storeId)
+            return $this->error('数据不存在');
+        /** @var SystemRoleServices $services */
+        $services = app()->make(SystemRoleServices::class);
+        $info['roles'] = $services->getRoleArray(['level' => $this->adminInfo['level'] + 1, 'type' => 1, 'relation_id' => $this->storeId]);
+        return $this->success('ok', $info->toArray());
+    }
+
+
+    /**
+     * 修改状态
+     * @param $id
+     * @param $status
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function setStatus($id, $status)
+    {
+        $info = $this->service->getOne(['id' => $id, 'level' => $this->adminInfo['level'] + 1, 'store_id' => $this->storeId]);
+        if (!$info)
+            return $this->error('数据不存在');
+        $this->service->update((int)$id, ['status' => $status]);
+        return $this->success($status == 0 ? '关闭成功' : '开启成功');
+    }
+
+
+    /**
+     * 修改当前登陆admin信息
+     * @return mixed
+     * @throws \Psr\SimpleCache\InvalidArgumentException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function update_admin()
+    {
+        $data = $this->request->postMore([
+            ['real_name', ''],
+            ['head_pic', ''],
+            ['pwd', ''],
+            ['new_pwd', ''],
+            ['conf_pwd', ''],
+            ['phone', ''],
+            ['code', '']
+        ]);
+        if ($this->service->updateAdmin($this->adminId, $data))
+            return $this->success('修改成功');
+        else
+            return $this->error('修改失败');
+    }
+}

+ 38 - 0
app/controller/store/system/SystemLogs.php

@@ -0,0 +1,38 @@
+<?php
+/**
+ * @Created by PhpStorm
+ * @author: Kirin
+ * @day: 2024/11/20
+ * @time: 19:58
+ */
+
+namespace app\controller\store\system;
+
+
+use app\common\StoreBaseController;
+use app\Request;
+use app\services\system\SystemLogServices;
+
+class SystemLogs extends StoreBaseController
+{
+    protected $storeSearch = true;
+
+    public function __construct(Request $request, SystemLogServices $service)
+    {
+        parent::__construct($request);
+        $this->service = $service;
+    }
+
+    public function index()
+    {
+        $where = $this->request->getMore([
+            ['time', ''],
+            ['admin_id', ''],
+            ['path', ''],
+            ['ip', ''],
+        ]);
+        $where['store_id'] = $this->storeId;
+        return $this->success($this->service->getLogList($where, $this->adminInfo['level']));
+    }
+
+}

+ 50 - 0
app/controller/store/system/SystemMenus.php

@@ -0,0 +1,50 @@
+<?php
+/**
+ * @Created by PhpStorm
+ * @author: Kirin
+ * @day: 2024/11/21
+ * @time: 13:35
+ */
+
+namespace app\controller\store\system;
+
+
+use app\common\StoreBaseController;
+use app\Request;
+use app\services\system\admin\SystemMenusServices;
+use think\db\exception\DataNotFoundException;
+use think\db\exception\DbException;
+use think\db\exception\ModelNotFoundException;
+
+class SystemMenus extends StoreBaseController
+{
+
+    public function __construct(Request $request, SystemMenusServices $service)
+    {
+        parent::__construct($request);
+        $this->service = $service;
+        $this->request->filter(['addslashes', 'trim']);
+        $this->createParams = [
+        ];
+        $this->saveDeal = $this->updateDeal = function (&$data) {
+        };
+        $this->searchable = [
+            ['is_show', ''],
+            ['keyword', ''],
+        ];
+    }
+
+
+    /**
+     * 获取菜单数据
+     * @return mixed
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException
+     */
+    public function menus()
+    {
+        [$menus, $unique] = $this->service->getMenusList($this->adminInfo['roles'], (int)$this->adminInfo['level'], 2, $this->storeId);
+        return $this->success(['menus' => $menus, 'unique' => $unique]);
+    }
+}

+ 111 - 0
app/controller/store/system/SystemRoles.php

@@ -0,0 +1,111 @@
+<?php
+/**
+ * @Created by PhpStorm
+ * @author: Kirin
+ * @day: 2024/11/21
+ * @time: 17:39
+ */
+
+namespace app\controller\store\system;
+
+
+use app\common\StoreBaseController;
+use app\Request;
+use app\services\system\admin\SystemMenusServices;
+use app\services\system\admin\SystemRoleServices;
+use qiniu\services\CacheService;
+use think\db\exception\DataNotFoundException;
+use think\db\exception\DbException;
+use think\db\exception\ModelNotFoundException;
+use think\exception\ValidateException;
+
+class SystemRoles extends StoreBaseController
+{
+    public function __construct(Request $request, SystemRoleServices $service)
+    {
+        parent::__construct($request);
+        $this->service = $service;
+        $this->request->filter(['addslashes', 'trim']);
+        $this->createParams = [
+            ['role_name', ''],
+            ['status', 0],
+            ['checked_menus', []]
+        ];
+        $this->saveDeal = $this->updateDeal = function (&$data) {
+            if (!$data['role_name']) throw new ValidateException('请输入身份名称');
+            if (!is_array($data['checked_menus']) || !count($data['checked_menus']))
+                throw new ValidateException('请选择最少一个权限');
+            $data['rules'] = implode(',', $data['checked_menus']);
+        };
+        $this->searchable = [
+            ['status', ''],
+            ['role_name', ''],
+        ];
+    }
+
+    public function index()
+    {
+        $where = $this->request->getMore($this->searchable);
+        $where['type'] = 1;
+        $where['relation_id'] = $this->storeId;
+        $where['level'] = $this->adminInfo['level'] + 1;
+        return $this->success($this->service->getRoleList($where));
+    }
+
+    public function read($id)
+    {
+        $info = $this->service->get($id);
+        if (!$info)
+            return $this->error('数据不存在');
+        if ($info['type'] != 1 || $info['relation_id'] != $this->storeId) {
+            return $this->error('数据不存在');
+        }
+        /** @var SystemMenusServices $services */
+        $services = app()->make(SystemMenusServices::class);
+        $info['menus'] = $services->getMenus($this->adminInfo['level'] == 0 ? [] : $this->adminInfo['roles'], 1, 0);
+        return $this->success('ok', $info->toArray());
+    }
+
+
+    public function save()
+    {
+        $data = $this->request->postMore($this->createParams);
+        $data['level'] = $this->adminInfo['level'] + 1;
+        $data['type'] = 1;
+        $data['relation_id'] = $this->storeId;
+        $res = $this->service->create($data);
+        if ($res) return $this->success('添加成功');
+        return $this->error('添加失败');
+    }
+
+
+    /**
+     * 修改状态
+     * @param $id
+     * @param $status
+     * @return mixed
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException
+     */
+    public function setStatus($id, $status)
+    {
+        if (!$id) {
+            return $this->error('缺少参数');
+        }
+        $role = $this->service->get($id);
+        if (!$role) {
+            return $this->error('没有查到此身份');
+        }
+        if ($role['type'] != 1 || $role['relation_id'] != $this->storeId) {
+            return $this->error('没有查到此身份');
+        }
+        $role->status = $status;
+        if ($role->save()) {
+            CacheService::clear();
+            return $this->success('修改成功');
+        } else {
+            return $this->error('修改失败');
+        }
+    }
+}

+ 190 - 0
app/controller/store/system/attachment/SystemAttachment.php

@@ -0,0 +1,190 @@
+<?php
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+namespace app\controller\store\system\attachment;
+
+use app\common\StoreBaseController;
+use app\Request;
+use app\services\system\attachment\SystemAttachmentServices;
+use Exception;
+use qiniu\services\UploadService;
+use think\db\exception\DataNotFoundException;
+use think\db\exception\DbException;
+use think\db\exception\ModelNotFoundException;
+use think\Response;
+
+
+/**
+ * 图片管理类
+ * Class SystemAttachment
+ * @package app\controller\admin\v1\file
+ */
+class SystemAttachment extends StoreBaseController
+{
+    protected $service;
+
+    public function __construct(Request $request, SystemAttachmentServices $service)
+    {
+        parent::__construct($request);
+        $this->service = $service;
+        $this->searchable = [
+            ['name', '', '', 'like_name'],
+            ['pid', 0],
+            ['file_type', 1]
+        ];
+    }
+
+    /**
+     * 显示列表
+     * @return mixed
+     * @throws DbException
+     */
+    public function index()
+    {
+        $where = $this->request->getMore($this->searchable);
+        $where['store_id'] = $this->storeId;
+        $where['module_type'] = 1;
+        return $this->success($this->service->getImageList($where));
+    }
+
+    /**
+     * 删除指定资源
+     *
+     * @return Response
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException
+     */
+    public function batchDelete()
+    {
+        $ids = $this->request->post('ids', '');
+        $ids = $this->service->search(['store_id' => $this->storeId, 'id' => is_string($ids) ? explode(',', $ids) : $ids])->column('id');
+        $this->service->del(implode(',', $ids));
+        return $this->success('删除成功');
+    }
+
+    /**图片上传
+     * @param int $upload_type
+     * @param int $type
+     * @return mixed
+     */
+    public function upload(int $upload_type = 0)
+    {
+        [$pid, $file] = $this->request->postMore([
+            ['pid', 0],
+            ['file', 'file'],
+        ], true);
+        $res = $this->service->upload((int)$pid, $file, (int)$upload_type, 2, $this->storeId);
+        return $this->success('上传成功', ['src' => $res]);
+    }
+
+    /**
+     * 移动图片
+     * @return mixed
+     */
+    public function moveImageCate()
+    {
+        $data = $this->request->postMore([
+            ['pid', 0],
+            ['images', '']
+        ]);
+        $this->service->move($data);
+        return $this->success('移动成功');
+    }
+
+    /**
+     * 修改文件名
+     * @param $id
+     * @return mixed
+     */
+    public function update($id)
+    {
+        $realName = $this->request->post('real_name', '');
+        if (!$realName) {
+            return $this->error('文件名称不能为空');
+        }
+        $this->service->update($id, ['real_name' => $realName]);
+        return $this->success('修改成功');
+    }
+
+    /**
+     * 获取上传类型
+     * @return mixed
+     */
+    public function uploadType()
+    {
+        $data['upload_type'] = (string)sys_config('upload_type', 1);
+        return $this->success($data);
+    }
+
+    /**
+     * 视频分片上传
+     * @return mixed
+     */
+    public function videoUpload()
+    {
+        $data = $this->request->postMore([
+            ['chunkNumber', 0],//第几分片
+            ['currentChunkSize', 0],//分片大小
+            ['chunkSize', 0],//总大小
+            ['totalChunks', 0],//分片总数
+            ['file', 'file'],//文件
+            ['md5', ''],//MD5
+            ['filename', ''],//文件名称
+            ['pid', 0],//分类ID
+        ]);
+        $fileHandle = $this->request->file($data['file']);
+        if (!$fileHandle) return $this->error('上传信息为空');
+        $res = $this->service->videoUpload($data, $fileHandle, 2, $this->storeId);
+        return $this->success($res);
+    }
+
+    /**
+     * 保存云端视频记录
+     * @return mixed
+     */
+    public function saveVideoAttachment()
+    {
+        $data = $this->request->postMore([
+            ['path', ''],//视频地址
+            ['cover_image', ''],//封面地址
+            ['pid', 0],//分类ID
+            ['upload_type', 1],//上传类型
+        ]);
+        $res = $this->service->saveOssVideoAttachment($data, 2, $this->storeId, (int)$data['upload_type']);
+        return $this->success($res);
+    }
+
+    /**网络图片上传
+     * @return Response
+     * @throws Exception
+     */
+    public function onlineUpload()
+    {
+        $data = $this->request->postMore([
+            ['pid', 0],
+            ['images', []]
+        ]);
+        $this->service->onlineUpload($data, 2, $this->storeId);
+        return $this->success('上传完成');
+    }
+
+    /**
+     * 获取视频上传token
+     * @return mixed
+     * @throws Exception
+     */
+    public function getTempKeys()
+    {
+        $upload = UploadService::init();
+        $re = $upload->getTempKeys();
+        return $re ? $this->success($re) : $this->error($upload->getError());
+    }
+}

+ 116 - 0
app/controller/store/system/attachment/SystemAttachmentCategory.php

@@ -0,0 +1,116 @@
+<?php
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+namespace app\controller\store\system\attachment;
+
+use app\common\StoreBaseController;
+use app\Request;
+use app\services\system\attachment\SystemAttachmentCategoryServices;
+use think\db\exception\DataNotFoundException;
+use think\db\exception\DbException;
+use think\db\exception\ModelNotFoundException;
+use think\exception\ValidateException;
+use think\Response;
+
+/**
+ * 图片分类管理类
+ * Class SystemAttachmentCategory
+ * @package app\controller\admin\v1\file
+ */
+class SystemAttachmentCategory extends StoreBaseController
+{
+
+    public function __construct(Request $request, SystemAttachmentCategoryServices $service)
+    {
+        parent::__construct($request);
+        $this->service = $service;
+        $this->searchable = [
+            ['name', ''],
+            ['pid', ''],
+            ['file_type', 1],
+        ];
+        $this->searchDeal = function (&$data) {
+            if ($data['name'] != '') $data['pid'] = '';
+        };
+        $this->createParams = [
+            ['pid', 0],
+            ['name', ''],
+            ['file_type', 1]
+        ];
+        $this->saveDeal = $this->updateDeal = function (&$data) {
+            if (!$data['name']) {
+                throw new ValidateException('请输入分类名称');
+            }
+        };
+    }
+
+    /**
+     * 显示资源列表
+     *
+     * @return Response
+     */
+    public function index()
+    {
+        $where = $this->request->getMore($this->searchable);
+        $where['store_id'] = $this->storeId;
+        return $this->success($this->service->getAll($where));
+    }
+
+    /**
+     * 保存新增
+     * @return mixed
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException
+     */
+    public function save()
+    {
+        $data = $this->request->postMore($this->createParams);
+        $data['type'] = 2;
+        $data['relation_id'] = $this->storeId;
+        $this->service->save($data);
+        return $this->success('添加成功');
+    }
+
+    /**
+     * 保存更新的资源
+     *
+     * @param int $id
+     * @return Response
+     * @throws DbException
+     * @throws DataNotFoundException
+     * @throws ModelNotFoundException
+     */
+    public function update($id)
+    {
+        $data = $this->request->postMore($this->createParams);
+        $info = $this->service->getOne(['id' => $id, 'store_id' => $this->storeId]);
+        if (!$info) return $this->error('数据不存在');
+        $count = $this->service->getCount(['pid' => $id]);
+        if ($count && $info['pid'] != $data['pid']) return $this->error('该分类有下级分类,无法修改上级');
+        $this->service->update($id, $data);
+        return $this->success('分类编辑成功!');
+    }
+
+    /**
+     * 删除指定资源
+     *
+     * @param int $id
+     * @return Response
+     * @throws DbException
+     */
+    public function delete($id)
+    {
+        $info = $this->service->getOne(['id' => $id, 'store_id' => $this->storeId]);
+        if (!$info) return $this->error('数据不存在');
+        $this->service->del($id);
+        return $this->success('删除成功!');
+    }
+}

+ 90 - 0
app/controller/store/user/User.php

@@ -0,0 +1,90 @@
+<?php
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+namespace app\controller\store\user;
+
+
+use app\common\StoreBaseController;
+use app\Request;
+use app\services\user\UserServices;
+use think\db\exception\DataNotFoundException;
+use think\db\exception\DbException;
+use think\db\exception\ModelNotFoundException;
+
+class User extends StoreBaseController
+{
+    /**
+     * user constructor.
+     * @param Request $request
+     * @param UserServices $services
+     */
+    public function __construct(Request $request, UserServices $services)
+    {
+        parent::__construct($request);
+        $this->service = $services;
+        $this->searchable = [
+            ['page', 1],
+            ['limit', 20],
+            ['nickname', ''],
+            ['status', ''],
+            ['is_promoter', ''],
+            ['user_type', ''],
+            ['country', ''],
+            ['province', ''],
+            ['city', ''],
+            ['user_time_type', ''],
+            ['user_time', ''],
+            ['sex', ''],
+            [['level', 0], 0],
+            [['group_id', 'd'], 0],
+            ['now_money', 'normal'],
+            ['field_key', ''],
+        ];
+    }
+
+    /**
+     * 显示资源列表头部
+     *
+     * @return \think\Response
+     */
+    public function typeHeader()
+    {
+        $list = $this->service->typeHead();
+        return $this->success(compact('list'));
+    }
+
+    /**
+     * 显示资源列表
+     *
+     * @return \think\Response
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException
+     */
+    public function index()
+    {
+        $where = $this->request->getMore($this->searchable);
+        $where['user_time_type'] = $where['user_time_type'] == 'all' ? '' : $where['user_time_type'];
+        return $this->success($this->service->userIndex($where));
+    }
+
+
+    /**
+     * 获取单个用户信息
+     * @param int $id 用户id
+     * @return mixed
+     */
+    public function oneUserInfo($type, int $id)
+    {
+        $data = $this->request->get();
+        if (!$type) return $this->error('缺少参数');
+        return $this->success($this->service->oneUserInfo($id, $type, $data));
+    }
+}

+ 43 - 0
app/controller/store/user/UserGroup.php

@@ -0,0 +1,43 @@
+<?php
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+namespace app\controller\store\user;
+
+use app\common\StoreBaseController;
+use app\Request;
+use app\services\user\UserGroupServices;
+use think\exception\ValidateException;
+
+/**
+ * 会员设置
+ * Class UserLevel
+ * @package app\controller\admin\v1\user
+ */
+class UserGroup extends StoreBaseController
+{
+    /**
+     * user constructor.
+     * @param Request $request
+     * @param UserGroupServices $services
+     */
+    public function __construct(Request $request, UserGroupServices $services)
+    {
+        parent::__construct($request);
+        $this->service = $services;
+        $this->createParams = [
+            ['group_name', '', '', '', function ($value) {
+                if (!$value) throw new ValidateException('请输入分组名称');
+            }],
+        ];
+        $this->saveDeal = $this->updateDeal = function (&$data) {
+            if (!$data['group_name']) throw new ValidateException('请输入分组名称');
+        };
+    }
+}

+ 5 - 0
app/http/middleware/admin/AdminAuthTokenMiddleware.php

@@ -16,6 +16,7 @@ use app\Request;
 use app\services\system\admin\SystemAdminServices;
 use Closure;
 use Psr\SimpleCache\InvalidArgumentException;
+use qiniu\exceptions\AdminException;
 use qiniu\interfaces\MiddlewareInterface;
 use think\facade\Config;
 
@@ -42,6 +43,10 @@ class AdminAuthTokenMiddleware implements MiddlewareInterface
 
         $request->setAdmin($adminInfo);
 
+        if ($request->adminStoreId() > 0) {
+            throw new AdminException('账号错误');
+        }
+
         return $next($request);
     }
 }

+ 54 - 0
app/http/middleware/store/AdminAuthTokenMiddleware.php

@@ -0,0 +1,54 @@
+<?php
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+
+namespace app\http\middleware\store;
+
+
+use app\Request;
+use app\services\system\admin\SystemAdminServices;
+use Closure;
+use Psr\SimpleCache\InvalidArgumentException;
+use qiniu\exceptions\AdminException;
+use qiniu\interfaces\MiddlewareInterface;
+use think\facade\Config;
+
+/**
+ * 后台登陆验证中间件
+ * Class AdminAuthTokenMiddleware
+ * @package app\http\middleware\admin
+ */
+class AdminAuthTokenMiddleware implements MiddlewareInterface
+{
+    /**
+     * @param Request $request
+     * @param Closure $next
+     * @return mixed
+     * @throws InvalidArgumentException
+     */
+    public function handle(Request $request, Closure $next)
+    {
+        $token = trim(ltrim($request->header(Config::get('cookie.token_name', 'Authori-zation')), 'Bearer'));
+
+        /** @var SystemAdminServices $service */
+        $service = app()->make(SystemAdminServices::class);
+        $adminInfo = $service->parseToken($token);
+
+        $request->setAdmin($adminInfo);
+
+        if ($request->adminStoreId() <= 0) {
+            throw new AdminException('账号错误');
+        }
+
+        $request->setStoreInfo($request->adminStoreId());
+
+        return $next($request);
+    }
+}

+ 41 - 0
app/http/middleware/store/AdminCheckRoleMiddleware.php

@@ -0,0 +1,41 @@
+<?php
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+
+namespace app\http\middleware\admin;
+
+use app\Request;
+use app\services\system\admin\SystemRoleServices;
+use qiniu\exceptions\AuthException;
+use qiniu\interfaces\MiddlewareInterface;
+use qiniu\utils\ApiErrorCode;
+
+/**
+ * 权限规则验证
+ * Class AdminCkeckRoleMiddleware
+ * @package app\http\middleware
+ */
+class AdminCheckRoleMiddleware implements MiddlewareInterface
+{
+
+    public function handle(Request $request, \Closure $next)
+    {
+        if (!$request->adminId() || !$request->adminInfo())
+            throw new AuthException(ApiErrorCode::ERR_ADMINID_VOID);
+
+        if ($request->adminInfo()['level']) {
+            /** @var SystemRoleServices $systemRoleService */
+            $systemRoleService = app()->make(SystemRoleServices::class);
+            $systemRoleService->verifiAuth($request);
+        }
+
+        return $next($request);
+    }
+}

+ 42 - 0
app/http/middleware/store/AdminLogMiddleware.php

@@ -0,0 +1,42 @@
+<?php
+// +----------------------------------------------------------------------
+// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
+// +----------------------------------------------------------------------
+// | Author: CRMEB Team <admin@crmeb.com>
+// +----------------------------------------------------------------------
+
+namespace app\http\middleware\store;
+
+
+use app\Request;
+use app\jobs\system\AdminLogJob;
+use qiniu\interfaces\MiddlewareInterface;
+
+/**
+ * 日志中間件
+ * Class AdminLogMiddleware
+ * @package app\http\middleware\admin
+ */
+class AdminLogMiddleware implements MiddlewareInterface
+{
+    /**
+     * @param Request $request
+     * @param \Closure $next
+     * @return mixed
+     */
+    public function handle(Request $request, \Closure $next)
+    {
+        $module = $request->method();
+        $params = $request->param();
+        $rule = trim(strtolower($request->rule()->getRule()));
+        //记录后台日志
+        AdminLogJob::dispatch([$request->adminId(), $request->adminInfo()['account'], $module, $rule, $request->ip(), 'store', json_encode($params), $request->adminStoreId()]);
+
+        return $next($request);
+    }
+
+}