超管后台 - 主菜单返工、删除超管后台冗余的模型对象
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 菜单模型类
|
||||
@@ -11,116 +11,4 @@ class Menu extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'menus';
|
||||
|
||||
/**
|
||||
* 获取所有菜单,并组织成树状结构
|
||||
* @param bool $onlyEnabled 是否只获取启用的菜单
|
||||
* @param bool $useCache 是否使用缓存
|
||||
* @return array
|
||||
*/
|
||||
public static function getMenuTree($onlyEnabled = true, $useCache = true)
|
||||
{
|
||||
$cacheKey = 'superadmin_menu_tree' . ($onlyEnabled ? '_enabled' : '_all');
|
||||
|
||||
// 查询条件
|
||||
$where = [];
|
||||
if ($onlyEnabled) {
|
||||
$where[] = ['status', '=', 1];
|
||||
}
|
||||
|
||||
// 获取所有菜单
|
||||
$allMenus = self::where($where)
|
||||
->order('sort', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 组织成树状结构
|
||||
$menuTree = self::buildMenuTree($allMenus);
|
||||
|
||||
// 缓存结果
|
||||
if ($useCache) {
|
||||
Cache::set($cacheKey, $menuTree, 3600); // 缓存1小时
|
||||
}
|
||||
|
||||
return $menuTree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建菜单树
|
||||
* @param array $menus 所有菜单
|
||||
* @param int $parentId 父菜单ID
|
||||
* @return array
|
||||
*/
|
||||
private static function buildMenuTree($menus, $parentId = 0)
|
||||
{
|
||||
$tree = [];
|
||||
|
||||
foreach ($menus as $menu) {
|
||||
if ($menu['parent_id'] == $parentId) {
|
||||
$children = self::buildMenuTree($menus, $menu['id']);
|
||||
if (!empty($children)) {
|
||||
$menu['children'] = $children;
|
||||
}
|
||||
$tree[] = $menu;
|
||||
}
|
||||
}
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据权限ID获取相应的菜单树
|
||||
* @param array $permissionIds 权限ID数组
|
||||
* @param bool $onlyEnabled 是否只获取启用的菜单
|
||||
* @return array
|
||||
*/
|
||||
public static function getMenuTreeByPermissions($permissionIds, $onlyEnabled = true)
|
||||
{
|
||||
// 如果没有权限,返回空数组
|
||||
if (empty($permissionIds)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 查询条件
|
||||
$where = [];
|
||||
if ($onlyEnabled) {
|
||||
$where[] = ['status', '=', 1];
|
||||
}
|
||||
|
||||
// 获取所有一级菜单(用户拥有权限的)
|
||||
$topMenus = self::where($where)
|
||||
->where('parent_id', 0)
|
||||
->whereIn('id', $permissionIds)
|
||||
->order('sort', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 菜单ID集合,用于获取子菜单
|
||||
$menuIds = array_column($topMenus, 'id');
|
||||
|
||||
// 获取所有子菜单
|
||||
$childMenus = self::where($where)
|
||||
->where('parent_id', 'in', $menuIds)
|
||||
->order('sort', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 将子菜单按照父ID进行分组
|
||||
$childMenusGroup = [];
|
||||
foreach ($childMenus as $menu) {
|
||||
$childMenusGroup[$menu['parent_id']][] = $menu;
|
||||
}
|
||||
|
||||
// 构建菜单树
|
||||
$menuTree = [];
|
||||
foreach ($topMenus as $topMenu) {
|
||||
// 添加子菜单
|
||||
if (isset($childMenusGroup[$topMenu['id']])) {
|
||||
$topMenu['children'] = $childMenusGroup[$topMenu['id']];
|
||||
}
|
||||
$menuTree[] = $topMenu;
|
||||
}
|
||||
|
||||
return $menuTree;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,12 +14,7 @@ Route::group('', function () {
|
||||
|
||||
// 菜单管理相关路由
|
||||
Route::group('menu', function () {
|
||||
Route::get('tree', 'app\superadmin\controller\MenuController@getMenuTree');
|
||||
Route::get('list', 'app\superadmin\controller\MenuController@getMenuList');
|
||||
Route::post('save', 'app\superadmin\controller\MenuController@saveMenu');
|
||||
Route::delete('delete/:id', 'app\superadmin\controller\MenuController@deleteMenu');
|
||||
Route::post('status', 'app\superadmin\controller\MenuController@updateStatus');
|
||||
Route::get('toplevel', 'app\superadmin\controller\MenuController@getTopLevelMenus');
|
||||
Route::get('tree', 'app\superadmin\controller\Menu\GetMenuTreeController@index');
|
||||
});
|
||||
|
||||
// 管理员相关路由
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace app\superadmin\controller\Menu;
|
||||
|
||||
use app\common\model\Menu as MenuModel;
|
||||
use app\common\model\AdministratorPermissions as AdministratorPermissionsModel;
|
||||
use app\superadmin\controller\BaseController;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 菜单控制器
|
||||
*/
|
||||
class GetMenuTreeController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 组织成树状结构
|
||||
*
|
||||
* @param array $menus
|
||||
* @param int $parentId
|
||||
* @return array
|
||||
*/
|
||||
private function buildMenuTree(array $menus, int $parentId = 0): array
|
||||
{
|
||||
$tree = [];
|
||||
|
||||
foreach ($menus as $menu) {
|
||||
if ($menu['parentId'] == $parentId) {
|
||||
$children = $this->buildMenuTree($menus, $menu['id']);
|
||||
|
||||
if (!empty($children)) {
|
||||
$menu['children'] = $children;
|
||||
}
|
||||
|
||||
$tree[] = $menu;
|
||||
}
|
||||
}
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取管理员权限
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getPermissions(): array
|
||||
{
|
||||
$record = AdministratorPermissionsModel::where('adminId', $this->getAdminInfo('id'))->find();
|
||||
|
||||
if (!$record || empty($record->permissions)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$permissions = $record->permissions ? json_decode($record->permissions, true) : [];
|
||||
|
||||
if (isset($permissions['ids']) && !empty($permissions['ids'])) {
|
||||
return is_string($permissions['ids']) ? explode(',', $permissions['ids']) : $permissions['ids'];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有菜单,并组织成树状结构
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getMenuTree(): array
|
||||
{
|
||||
// 获取所有菜单
|
||||
$allMenus = MenuModel::where('status', 1)->order('sort', 'asc')->select()->toArray();
|
||||
|
||||
// 组织成树状结构
|
||||
return $allMenus ? $this->buildMenuTree($allMenus) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有一级菜单(用户拥有权限的)
|
||||
*
|
||||
* @param array $permissionIds
|
||||
* @return array
|
||||
*/
|
||||
protected function getTopMenusInPermissionIds(array $permissionIds): array
|
||||
{
|
||||
$where = [
|
||||
'id' => ['in', $permissionIds],
|
||||
'parentId' => 0,
|
||||
'status' => 1,
|
||||
];
|
||||
|
||||
return MenuModel::where($where)->order('sort', 'asc')->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有子菜单.
|
||||
*
|
||||
* @param array $topMenuIds
|
||||
* @return array
|
||||
*/
|
||||
protected function getAllChildrenInPermissionIds(array $topMenuIds): array
|
||||
{
|
||||
$where = [
|
||||
'parentId' => ['in', $topMenuIds],
|
||||
'status' => 1,
|
||||
];
|
||||
|
||||
return MenuModel::where($where)->order('sort', 'asc')->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户菜单
|
||||
*
|
||||
* @param array $permissionIds
|
||||
* @return array
|
||||
*/
|
||||
protected function getUserMenus(array $permissionIds): array
|
||||
{
|
||||
$topMenus = $this->getTopMenusInPermissionIds($permissionIds);
|
||||
|
||||
// 菜单ID集合,用于获取子菜单
|
||||
$menuIds = array_column($topMenus, 'id');
|
||||
|
||||
return $this->getAllChildrenInPermissionIds($menuIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建菜单树.
|
||||
*
|
||||
* @param array $childMenus
|
||||
* @return array
|
||||
*/
|
||||
protected function _makeMenuTree(array $childMenus): array
|
||||
{
|
||||
// 将子菜单按照父ID进行分组
|
||||
$childMenusGroup = [];
|
||||
|
||||
foreach ($childMenus as $menu) {
|
||||
$childMenusGroup[$menu['parentId']][] = $menu;
|
||||
}
|
||||
|
||||
foreach ($topMenus as $topMenu) {
|
||||
if (isset($childMenusGroup[$topMenu['id']])) {
|
||||
$topMenu['children'] = $childMenusGroup[$topMenu['id']];
|
||||
}
|
||||
|
||||
$menuTree[] = $topMenu;
|
||||
}
|
||||
|
||||
return $menuTree ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据权限ID获取相应的菜单树
|
||||
*
|
||||
* @param array $permissionIds 权限ID数组
|
||||
* @return array
|
||||
*/
|
||||
protected function getMenuTreeByPermissions(array $permissionIds): array
|
||||
{
|
||||
if ($permissionIds) {
|
||||
$childMenus = $this->getUserMenus($permissionIds);
|
||||
|
||||
// 构建菜单树
|
||||
return $this->_makeMenuTree($childMenus);
|
||||
}
|
||||
|
||||
// 如果没有权限,返回空数组
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单列表(树状结构)
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->getAdminInfo('id') == 1) {
|
||||
$menuTree = $this->getMenuTree();
|
||||
} else {
|
||||
$menuTree = $this->getMenuTreeByPermissions(
|
||||
$this->getPermissions()
|
||||
);
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => $menuTree
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,183 +0,0 @@
|
||||
<?php
|
||||
namespace app\superadmin\controller;
|
||||
|
||||
use think\Controller;
|
||||
use app\superadmin\model\Menu as MenuModel;
|
||||
|
||||
/**
|
||||
* 菜单控制器
|
||||
*/
|
||||
class MenuController extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取菜单列表(树状结构)
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getMenuTree()
|
||||
{
|
||||
// 参数处理
|
||||
$onlyEnabled = $this->request->param('only_enabled', 1);
|
||||
$useCache = $this->request->param('use_cache', 0); // 由于要根据用户权限过滤,默认不使用缓存
|
||||
|
||||
// 获取当前登录的管理员信息
|
||||
$adminInfo = $this->request->adminInfo;
|
||||
|
||||
// 调用模型获取菜单树
|
||||
if ($adminInfo->id == 1) {
|
||||
// 超级管理员获取所有菜单
|
||||
$menuTree = MenuModel::getMenuTree($onlyEnabled, $useCache);
|
||||
} else {
|
||||
// 非超级管理员根据权限获取菜单
|
||||
$permissionIds = \app\superadmin\model\AdministratorPermissions::getPermissions($adminInfo->id);
|
||||
$menuTree = MenuModel::getMenuTreeByPermissions($permissionIds, $onlyEnabled);
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => $menuTree
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有菜单(平铺结构,便于后台管理)
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getMenuList()
|
||||
{
|
||||
// 查询条件
|
||||
$where = [];
|
||||
$status = $this->request->param('status');
|
||||
if ($status !== null && $status !== '') {
|
||||
$where[] = ['status', '=', intval($status)];
|
||||
}
|
||||
|
||||
// 获取所有菜单
|
||||
$menus = MenuModel::where($where)
|
||||
->order('sort', 'asc')
|
||||
->select();
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => $menus
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加或更新菜单
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function saveMenu()
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return json(['code' => 405, 'msg' => '请求方法不允许']);
|
||||
}
|
||||
|
||||
// 获取参数
|
||||
$data = $this->request->post();
|
||||
|
||||
// 验证参数
|
||||
$validate = $this->validate($data, [
|
||||
'title|菜单名称' => 'require|max:50',
|
||||
'path|路由路径' => 'require|max:100',
|
||||
'parent_id|父菜单ID' => 'require|number',
|
||||
'status|状态' => 'require|in:0,1',
|
||||
'sort|排序' => 'require|number',
|
||||
]);
|
||||
|
||||
if ($validate !== true) {
|
||||
return json(['code' => 400, 'msg' => $validate]);
|
||||
}
|
||||
|
||||
// 保存菜单
|
||||
$result = MenuModel::saveMenu($data);
|
||||
|
||||
if ($result) {
|
||||
return json(['code' => 200, 'msg' => '保存成功']);
|
||||
} else {
|
||||
return json(['code' => 500, 'msg' => '保存失败']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
* @param int $id 菜单ID
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function deleteMenu($id)
|
||||
{
|
||||
if (!$this->request->isDelete()) {
|
||||
return json(['code' => 405, 'msg' => '请求方法不允许']);
|
||||
}
|
||||
|
||||
if (empty($id) || !is_numeric($id)) {
|
||||
return json(['code' => 400, 'msg' => '参数错误']);
|
||||
}
|
||||
|
||||
$result = MenuModel::deleteMenu($id);
|
||||
|
||||
if ($result) {
|
||||
return json(['code' => 200, 'msg' => '删除成功']);
|
||||
} else {
|
||||
return json(['code' => 500, 'msg' => '删除失败,可能存在子菜单']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新菜单状态
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function updateStatus()
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
return json(['code' => 405, 'msg' => '请求方法不允许']);
|
||||
}
|
||||
|
||||
$id = $this->request->post('id');
|
||||
$status = $this->request->post('status');
|
||||
|
||||
if (empty($id) || !is_numeric($id) || !in_array($status, [0, 1])) {
|
||||
return json(['code' => 400, 'msg' => '参数错误']);
|
||||
}
|
||||
|
||||
$menu = MenuModel::find($id);
|
||||
if (!$menu) {
|
||||
return json(['code' => 404, 'msg' => '菜单不存在']);
|
||||
}
|
||||
|
||||
$menu->status = $status;
|
||||
$result = $menu->save();
|
||||
|
||||
// 清除缓存
|
||||
MenuModel::clearMenuCache();
|
||||
|
||||
if ($result) {
|
||||
return json(['code' => 200, 'msg' => '状态更新成功']);
|
||||
} else {
|
||||
return json(['code' => 500, 'msg' => '状态更新失败']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一级菜单(供权限设置使用)
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getTopLevelMenus()
|
||||
{
|
||||
// 获取所有启用的一级菜单
|
||||
$menus = \app\superadmin\model\Menu::where([
|
||||
['parent_id', '=', 0],
|
||||
['status', '=', 1]
|
||||
])
|
||||
->field('id, title')
|
||||
->order('sort', 'asc')
|
||||
->select();
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => $menus
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 超级管理员模型类
|
||||
*/
|
||||
class Administrator extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'administrators';
|
||||
|
||||
// 隐藏字段
|
||||
protected $hidden = [
|
||||
'password'
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证管理员登录
|
||||
* @param string $account 账号
|
||||
* @param string $password 密码(已MD5加密)
|
||||
* @return array|null
|
||||
*/
|
||||
public static function login($account, $password)
|
||||
{
|
||||
return self::where([
|
||||
['account', '=', $account],
|
||||
['password', '=', $password],
|
||||
['status', '=', 1],
|
||||
['deleteTime', '=', 0]
|
||||
])->find();
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 超级管理员权限配置模型类
|
||||
*/
|
||||
class AdministratorPermissions extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'administrator_permissions';
|
||||
|
||||
|
||||
/**
|
||||
* 获取管理员权限
|
||||
* @param int $adminId 管理员ID
|
||||
* @return array 权限ID数组
|
||||
*/
|
||||
public static function getPermissions($adminId)
|
||||
{
|
||||
$record = self::where('adminId', $adminId)->find();
|
||||
|
||||
if (!$record || empty($record->permissions)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$permissions = $record->permissions ? json_decode($record->permissions, true) : [];
|
||||
|
||||
if (isset($permissions['ids']) && !empty($permissions['ids'])) {
|
||||
return is_string($permissions['ids']) ? explode(',', $permissions['ids']) : $permissions['ids'];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 项目模型
|
||||
*/
|
||||
class Company extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'company';
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 菜单模型类
|
||||
*/
|
||||
class Menu extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'menus';
|
||||
|
||||
/**
|
||||
* 获取所有菜单,并组织成树状结构
|
||||
* @param bool $onlyEnabled 是否只获取启用的菜单
|
||||
* @param bool $useCache 是否使用缓存
|
||||
* @return array
|
||||
*/
|
||||
public static function getMenuTree($onlyEnabled = true, $useCache = true)
|
||||
{
|
||||
$cacheKey = 'superadmin_menu_tree' . ($onlyEnabled ? '_enabled' : '_all');
|
||||
|
||||
// 查询条件
|
||||
$where = [];
|
||||
if ($onlyEnabled) {
|
||||
$where[] = ['status', '=', 1];
|
||||
}
|
||||
|
||||
// 获取所有菜单
|
||||
$allMenus = self::where($where)
|
||||
->order('sort', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 组织成树状结构
|
||||
$menuTree = self::buildMenuTree($allMenus);
|
||||
|
||||
// 缓存结果
|
||||
if ($useCache) {
|
||||
Cache::set($cacheKey, $menuTree, 3600); // 缓存1小时
|
||||
}
|
||||
|
||||
return $menuTree;
|
||||
}
|
||||
|
||||
public static function getMenusNameByIds($ids)
|
||||
{
|
||||
return self::whereIn('id', $ids)->column('title');
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建菜单树
|
||||
* @param array $menus 所有菜单
|
||||
* @param int $parentId 父菜单ID
|
||||
* @return array
|
||||
*/
|
||||
private static function buildMenuTree($menus, $parentId = 0)
|
||||
{
|
||||
$tree = [];
|
||||
|
||||
foreach ($menus as $menu) {
|
||||
if ($menu['parent_id'] == $parentId) {
|
||||
$children = self::buildMenuTree($menus, $menu['id']);
|
||||
if (!empty($children)) {
|
||||
$menu['children'] = $children;
|
||||
}
|
||||
$tree[] = $menu;
|
||||
}
|
||||
}
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据权限ID获取相应的菜单树
|
||||
* @param array $permissionIds 权限ID数组
|
||||
* @param bool $onlyEnabled 是否只获取启用的菜单
|
||||
* @return array
|
||||
*/
|
||||
public static function getMenuTreeByPermissions($permissionIds, $onlyEnabled = true)
|
||||
{
|
||||
// 如果没有权限,返回空数组
|
||||
if (empty($permissionIds)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 查询条件
|
||||
$where = [];
|
||||
if ($onlyEnabled) {
|
||||
$where[] = ['status', '=', 1];
|
||||
}
|
||||
|
||||
// 获取所有一级菜单(用户拥有权限的)
|
||||
$topMenus = self::where($where)
|
||||
->where('parent_id', 0)
|
||||
->whereIn('id', $permissionIds)
|
||||
->order('sort', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 菜单ID集合,用于获取子菜单
|
||||
$menuIds = array_column($topMenus, 'id');
|
||||
|
||||
// 获取所有子菜单
|
||||
$childMenus = self::where($where)
|
||||
->where('parent_id', 'in', $menuIds)
|
||||
->order('sort', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 将子菜单按照父ID进行分组
|
||||
$childMenusGroup = [];
|
||||
foreach ($childMenus as $menu) {
|
||||
$childMenusGroup[$menu['parent_id']][] = $menu;
|
||||
}
|
||||
|
||||
// 构建菜单树
|
||||
$menuTree = [];
|
||||
foreach ($topMenus as $topMenu) {
|
||||
// 添加子菜单
|
||||
if (isset($childMenusGroup[$topMenu['id']])) {
|
||||
$topMenu['children'] = $childMenusGroup[$topMenu['id']];
|
||||
}
|
||||
$menuTree[] = $topMenu;
|
||||
}
|
||||
|
||||
return $menuTree;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 场景模型
|
||||
*/
|
||||
class Scene extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'scene';
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 客户池模型
|
||||
*/
|
||||
class TrafficPool extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'traffic_pool';
|
||||
|
||||
// 设置表前缀
|
||||
protected $prefix = 'ck_';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
// 定义字段类型
|
||||
protected $type = [
|
||||
'id' => 'integer',
|
||||
'wechatId' => 'string',
|
||||
'createTime' => 'datetime',
|
||||
'updateTime' => 'integer'
|
||||
];
|
||||
|
||||
// 定义字段验证规则
|
||||
protected $rule = [
|
||||
'wechatId' => 'require|max:64',
|
||||
'identifier' => 'require|max:64'
|
||||
];
|
||||
|
||||
// 定义字段验证提示信息
|
||||
protected $message = [
|
||||
'wechatId.require' => '微信ID不能为空',
|
||||
'wechatId.max' => '微信ID最多不能超过64个字符',
|
||||
'identifier.require' => '标识符不能为空',
|
||||
'identifier.max' => '标识符最多不能超过64个字符'
|
||||
];
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 流量来源模型
|
||||
*/
|
||||
class TrafficSource extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'traffic_source';
|
||||
|
||||
// 设置表前缀
|
||||
protected $prefix = 'ck_';
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
// 定义字段类型
|
||||
protected $type = [
|
||||
'id' => 'integer',
|
||||
'identifier' => 'string',
|
||||
'companyId' => 'integer',
|
||||
'createTime' => 'datetime',
|
||||
'updateTime' => 'integer'
|
||||
];
|
||||
|
||||
// 定义字段验证规则
|
||||
protected $rule = [
|
||||
'identifier' => 'require|max:64',
|
||||
'companyId' => 'number',
|
||||
'fromd' => 'max:255'
|
||||
];
|
||||
|
||||
// 定义字段验证提示信息
|
||||
protected $message = [
|
||||
'identifier.require' => '标识符不能为空',
|
||||
'identifier.max' => '标识符最多不能超过64个字符',
|
||||
'companyId.number' => '公司ID必须为数字',
|
||||
'fromd.max' => '来源最多不能超过255个字符'
|
||||
];
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 用户模型
|
||||
*/
|
||||
class Users extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'users';
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 微信账号模型
|
||||
*/
|
||||
class WechatAccount extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'wechat_account';
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 微信好友模型
|
||||
*/
|
||||
class WechatFriend extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'wechat_friend';
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
namespace app\superadmin\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 微信标签模型
|
||||
*/
|
||||
class WechatTag extends Model
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'wechat_tag';
|
||||
}
|
||||
Reference in New Issue
Block a user