12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- /**
- * @Created by PhpStorm
- * @author: Kirin
- * @day: 2024/11/20
- * @time: 17:59
- */
- namespace app\controller\admin;
- use app\common\AdminBaseController;
- 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 AdminBaseController
- {
- public function adminInfo(SystemMenusServices $services, SystemRoleServices $roleServices)
- {
- $adminInfo = $this->request->adminInfo();
- [$menus, $uniqueAuth] = $services->getMenusList($adminInfo['roles'], (int)$adminInfo['level']);
- 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'])
- ]
- ]);
- }
- /**
- * 格式化菜单
- * @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', 1)
- ->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 app('json')->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));
- }
- }
|