diff --git a/app/common/model/Admin.php b/app/common/model/Admin.php deleted file mode 100644 index d0ad3da..0000000 --- a/app/common/model/Admin.php +++ /dev/null @@ -1,128 +0,0 @@ -find(); - if (empty($info)) return self::setErrorInfo("登录账号不存在"); - if ($info['password'] != md5(md5($pwd))) return self::setErrorInfo("密码不正确!"); - if ($info['status'] != 1) return self::setErrorInfo("账号已被冻结!"); - self::setLoginInfo($info); - return true; - } - - /** - * 设置登录信息 - * @param $info - * @return bool - */ - public static function setLoginInfo($info) - { - unset($info->password);//去除密码字段 - $info->role_auth = AdminRole::getAuth($info['role_id'] ?? 0);//提前缓存auth字段避免频繁查询 - Session::set(Data::SESSION_KEY_ADMIN_ID, $info['id']); - Session::set(Data::SESSION_KEY_ADMIN_INFO, $info->toArray()); - event("AdminLog", [$info->toArray(), "admin", "login", "login"]); - return true; - } - - /** - * 退出登录 - */ - public static function clearLoginInfo() - { - Session::delete(Data::SESSION_KEY_ADMIN_ID); - Session::delete(Data::SESSION_KEY_ADMIN_INFO); - Session::clear(); - return true; - } - - /** - * 列表 - * @param array $where - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function systemPage(array $where): array - { - $model = new self; - if ($where['username'] != '') $model = $model->where("username|id|nickname", "like", "%$where[username]%"); - if ($where['start_time'] != '') $model = $model->where("create_time", ">", strtotime($where['start_time'] . " 00:00:00")); - if ($where['end_time'] != '') $model = $model->where("create_time", "<", strtotime($where['end_time'] . " 23:59:59")); - if ($where['tel'] != '') $model = $model->where("tel|mail", "like", "%$where[tel]%"); - if ($where['status'] != '') $model = $model->where("status", $where['status']); - if ($where['role_id'] != '') $model = $model->where("role_id", $where['role_id']); - $count = self::count(); - if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'], (int)$where['limit']); - $data = $model->select()->each(function ($item) { - unset($item['password']); - // 用户信息 - $info = self::getAdminInfoById((int)$item['create_user']); - $item['create_user'] = $info ? $info['nickname'] : $item['create_user']; - $item['role_id'] = AdminRole::getAuthNameById((int)$item['role_id']); - }); - $data = $data ? $data->toArray() : []; - return compact("data", "count"); - } - - /** - * 获取账号信息 - * @param int $id - * @param string $field - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function getAdminInfoById(int $id, string $field = '*'): array - { - $model = new self; - $model = $model->where("id", $id); - $model = $model->field($field); - $info = $model->find(); - unset($info->password); - return $info ? $info->toArray() : []; - } - - /** - * 人员列表 - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function lst() - { - $model = new self; - $model = $model->where("status", 1); - $model = $model->field("id,realname"); - $data = $model->select(); - return $data ? $data->toArray() : []; - } -} \ No newline at end of file diff --git a/app/common/model/AdminAuth.php b/app/common/model/AdminAuth.php deleted file mode 100644 index 895ff83..0000000 --- a/app/common/model/AdminAuth.php +++ /dev/null @@ -1,251 +0,0 @@ - $value) { - $temp[$value['module'] . '_' . $value['controller'] . '_' . $value['action']] = $key; - } - $authList = $temp; - cache(AdminAuth::getAuthCacheKey(), $authList, 24 * 60 * 60); - unset($temp); - } - return $authList[$module . '_' . $controller . '_' . $action] ?? -1; - } - - /** - * 获取用户权限列表 - * @param $admin_id - * @param $auth - * @return array|mixed|object|\think\App - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function getAuthList($admin_id,$auth){ - $menuList = cache(self::getMenuCacheKey($admin_id)); - if ($menuList === null) { - $menuList = self::getMenu(0, $auth); - cache(AdminAuth::getMenuCacheKey($admin_id), $menuList, 1 * 60 * 60); - } - return $menuList; - } - - /** - * 获取菜单 - * @param int $pid - * @param array $auth - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function getMenu(int $pid = 0, array $auth = []): array - { - $model = new self; - $model = $model->where("is_menu", 1); - $model = $model->where("status", 1); - $model = $model->where("pid", $pid); - if ($auth != []) $model = $model->where("id", 'in', $auth); - $model = $model->field(['name as title', 'path as href', 'icon', 'id', 'font_family as fontFamily', 'is_check as isCheck', 'spreed', 'params']); - $model = $model->order(["rank desc", "id"]); - $data = $model->select()->each(function ($item) use ($auth) { - $item['children'] = self::getMenu($item['id'], $auth); - $item['isCheck'] = $item['isCheck'] ? true : false; - $item['spreed'] = $item['spreed'] ? true : false; - }); - return $data->toArray() ?: []; - } - - /** - * 权限列表 - * @param $where - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function systemPage($where): array - { - $model = new self; - if (isset($where['status']) && $where['status'] != '') $model = $model->where("status", $where['status']); - if (isset($where['name']) && $where['name'] != '') $model = $model->where("name|id", "like", "%$where[name]%"); - $model = $model->field(['id', 'name', 'icon', 'pid', 'module', 'controller', 'action', 'params', 'is_menu', 'path', 'rank', 'status']); - $model = $model->order(["rank desc", "id"]); - $data = $model->select(); - return $data->toArray() ?: []; - } - - /** - * 获取选择数据 - * @param int $pid - * @param array $auth - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function lst(int $pid = 0, array $auth = []): array - { - $model = new self; - $model = $model->where("pid", $pid); - if ($auth != []) $model = $model->where("id", 'in', $auth); - $model = $model->field(['name', 'id']); - $model = $model->order(["rank desc", "id"]); - $data = $model->select()->each(function ($item) use ($auth) { - $item['children'] = self::lst($item['id'], $auth); - }); - return $data->toArray() ?: []; - } - - /** - * 获取菜单列表缓存key - * @param $adminId - * @return string - * @author 木子的忧伤 - * @date 2021-06-09 17:24 - */ - public static function getMenuCacheKey($adminId) - { - return 'menu:List:' . $adminId; - } - - /** - * @return string - * @author 木子的忧伤 - * @date 2021-06-15 11:11 - */ - public static function getAuthCacheKey() - { - return 'auth:key:list'; - } - - public static function clearCache($adminId) - { - cache(AdminAuth::getMenuCacheKey($adminId), null); - cache(AdminAuth::getAuthCacheKey(), null); - } - - /** - * 遍历选择项 - * @param array $data - * @param $list - * @param int $num - * @param bool $clear - */ - public static function myOptions(array $data, &$list, $num = 0, $clear = true) - { - foreach ($data as $k => $v) { - $list[] = ['value' => $v['id'], 'label' => self::cross($num) . $v['name']]; - if (is_array($v['children']) && !empty($v['children'])) { - self::myOptions($v['children'], $list, $num + 1, false); - } - } - } - - /** - * 返回选择项 - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function returnOptions(): array - { - $list = []; - $list[] = ['value' => 0, 'label' => '总后台']; - self::myOptions(self::lst(), $list, 1, true); - return $list; - } - - /** - * 横线 - * @param int $num - * @return string - */ - public static function cross(int $num = 0): string - { - $str = ""; - if ($num == 1) $str .= "|--"; - elseif ($num > 1) for ($i = 0; $i < $num; $i++) - if ($i == 0) $str .= "|--"; - else $str .= "--"; - return $str . " "; - } - - /** - * 生成treeData - * @param int $pid - * @param array $auth - * @param array $list - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function selectAndBuildTree(int $pid = 0, array $auth = [], array $list = []) - { - $model = new self; - $model = $model->where("pid", $pid); - if ($auth != []) $model = $model->where("id", 'in', $auth); - $model = $model->where("status", 1); - $model = $model->field(['name', 'id']); - $model = $model->order(["rank desc", "id"]); - $data = $model->select(); - foreach ($data as $k => $v) { - $list[] = AdminRole::buildTreeData($v['id'], $v['name'], self::selectAndBuildTree($v['id'], $auth)); - } - return $list; - } - - /** - * 获取所有权限id - * @param array $ids - * @return array - */ - public static function getIds(array $ids = []): array - { - if (empty($ids)) return self::where("status", 1)->column("id"); - $pids = self::where("id", "in", $ids)->column("pid"); - return array_merge($ids, $pids) ?: []; - } - - /** - * 获取操作名 - * @param string $module - * @param string $controller - * @param string $action - * @return string - */ - public static function getNameByAction(string $module, string $controller, string $action) - { - return self::where("module", $module)->where("controller", $controller)->where("action", $action)->value("name") ?: '未知操作'; - } -} \ No newline at end of file diff --git a/app/common/model/AdminLog.php b/app/common/model/AdminLog.php deleted file mode 100644 index 7375e56..0000000 --- a/app/common/model/AdminLog.php +++ /dev/null @@ -1,61 +0,0 @@ - $adminInfo['id'], - 'admin_name' => $adminInfo['username'], - 'module' => $module, - 'controller' => $controller, - 'action' => $action, - 'ip' => request()->ip(), - 'create_time' => time(), - 'user_agent' => substr(request()->server('HTTP_USER_AGENT'), 0, 255), - ]) ? true : false; - } - - /** - * 日志列表 - * @param $where - * @return array - * @throws DbException - */ - public static function systemPage($where) - { - $model = new self; - $model = $model->order("id desc"); - if ($where['name'] != '') $model = $model->where('admin_name|id', "like", "%$where[name]%"); - if ($where['ip'] != '') $model = $model->where('ip', "like", "%$where[ip]%"); - if ($where['start_time'] != '') $model = $model->where('create_time', '>', strtotime($where['start_time'] . " 00:00:00")); - if ($where['end_time'] != '') $model = $model->where('create_time', '<', strtotime($where['end_time'] . " 23:59:59")); - $count = self::count(); - if (!empty($where['page']) && !empty($where['limit'])) $model = $model->page((int)$where['page'], (int)$where['limit']); - $data = $model->select()->each(function ($item) { - $item['name'] = AdminAuth::getNameByAction($item['module'], $item['controller'], $item['action']); - }); - $data = $data ? $data->toArray() : []; - return compact("data", "count"); - } -} \ No newline at end of file diff --git a/app/common/model/AdminNotify.php b/app/common/model/AdminNotify.php deleted file mode 100644 index 0d81dba..0000000 --- a/app/common/model/AdminNotify.php +++ /dev/null @@ -1,68 +0,0 @@ -where("create_time", "between", [strtotime($where['start_time'] . " 00:00:00"), strtotime($where['end_time'] . " 23:59:59")]); - } - if ($where['title'] != '') $model = $model->where("title|content", "like", "%$where[title]%"); - if ($where['is_read'] != '') $model = $model->where("is_read", $where['is_read']); - if ($where['aid'] != '') $model = $model->where("aid", $where['aid']); - $model = $model->order("is_read"); - $model = $model->order("create_time desc"); - return $model->paginate(10)->appends($where); - } - - /** - * 添加记录 - * @param array $data - * @return int|string - */ - public static function addLog(array $data) - { - return self::create($data); - } - - /** - * 后台首页获取通知信息 - * @param int $num - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function pageList(int $num) - { - $model = new self; - $model = $model->where("is_read", 0); - $count = self::count(); - $model = $model->order("create_time desc"); - $model = $model->page(1, $num); - $data = $model->select(); - if ($data) $data = $data->toArray(); - return compact("data", "count"); - } -} \ No newline at end of file diff --git a/app/common/model/AdminRole.php b/app/common/model/AdminRole.php deleted file mode 100644 index 11afd3c..0000000 --- a/app/common/model/AdminRole.php +++ /dev/null @@ -1,151 +0,0 @@ -value("auth") ?: ''; - } - - /** - * 获取所有角色ids - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function getAuthLst(): array - { - $data = self::where("status", 1)->field("id,name")->select(); - return $data ? $data->toArray() : []; - } - - /** - * 获取角色名称 - * @param int $id - * @return string - */ - public static function getAuthNameById(int $id): string - { - return self::where("id", $id)->value("name") ?: (string)$id; - } - - /** - * 角色列表 - * @param int $pid - * @param array $auth - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function systemPage(int $pid = -1): array - { - $model = new self; - if ($pid != -1) $model = $model->where("pid", $pid); - $model = $model->field(['id', 'name', 'pid', 'auth', 'rank', 'status']); - $model = $model->order(["rank desc", "id"]); - $data = $model->select(); - return $data->toArray() ?: []; - } - - /** - * 获取选择数据 - * @param int $pid - * @param array $auth - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function lst(int $pid = 0, array $auth = []): array - { - $model = new self; - $model = $model->where("pid", $pid); - $model = $model->field(['name', 'id']); - $model = $model->order(["rank desc", "id"]); - $data = $model->select()->each(function ($item) use ($auth) { - $item['children'] = self::lst($item['id'], $auth); - }); - return $data->toArray() ?: []; - } - - /** - * 遍历选择项 - * @param array $data - * @param $list - * @param int $num - * @param bool $clear - */ - public static function myOptions(array $data, &$list, $num = 0, $clear = true) - { - foreach ($data as $k => $v) { - $list[] = ['value' => $v['id'], 'label' => self::cross($num) . $v['name']]; - if (is_array($v['children']) && !empty($v['children'])) { - self::myOptions($v['children'], $list, $num + 1, false); - } - } - } - - /** - * 返回选择项 - * @return array - * @throws DataNotFoundException - * @throws DbException - * @throws ModelNotFoundException - */ - public static function returnOptions(): array - { - $list = []; - $list[] = ['label' => '总后台', 'value' => 0]; - self::myOptions(self::lst(), $list, 1, true); - return $list; - } - - /** - * 横线 - * @param int $num - * @return string - */ - public static function cross(int $num = 0): string - { - $str = ""; - if ($num == 1) $str .= "|--"; - elseif ($num > 1) for ($i = 0; $i < $num; $i++) - if ($i == 0) $str .= "|--"; - else $str .= "--"; - return $str . " "; - } - - /** - * 生成单个节点 - * @param $id - * @param $title - * @return array - */ - public static function buildTreeData($id, $title, $children = []): array - { - $tree = Elm::TreeData($id, $title); - if (!empty($children)) $tree = $tree->children($children); - return $tree->getOption(); - } -} \ No newline at end of file diff --git a/app/common/validate/FriendLink.php b/app/common/validate/FriendLink.php deleted file mode 100644 index 9bacc30..0000000 --- a/app/common/validate/FriendLink.php +++ /dev/null @@ -1,38 +0,0 @@ - 'require|max:255', - 'url' => 'require|max:255', - 'sort' => 'require|number', - ]; - protected $message = [ - 'title.require' => '请输入链接名称!', - 'url.require' => '请输入链接地址!', - 'sort' => '请输入排序序号', - 'sort.number' => '排序序号只能是数字', - 'title.max' => '链接名称最多输入255个字符', - 'url.max' => '链接地址最多输入255个字符', - ]; - - //更新排序 - protected $scene = [ - 'sort' => ['sort'] - ]; -}