Common.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * @Created by PhpStorm
  4. * @author: Kirin
  5. * @day: 2024/11/20
  6. * @time: 17:59
  7. */
  8. namespace app\controller\admin;
  9. use app\common\AdminBaseController;
  10. use app\services\system\admin\SystemMenusServices;
  11. use app\services\system\admin\SystemRoleServices;
  12. use app\services\system\CityAreaServices;
  13. use Psr\SimpleCache\InvalidArgumentException;
  14. use qiniu\services\CacheService;
  15. use think\db\exception\DataNotFoundException;
  16. use think\db\exception\DbException;
  17. use think\db\exception\ModelNotFoundException;
  18. class Common extends AdminBaseController
  19. {
  20. public function adminInfo(SystemMenusServices $services, SystemRoleServices $roleServices)
  21. {
  22. $adminInfo = $this->request->adminInfo();
  23. [$menus, $uniqueAuth] = $services->getMenusList($adminInfo['roles'], (int)$adminInfo['level']);
  24. return $this->success([
  25. 'menus' => $menus,
  26. 'unique_auth' => $uniqueAuth,
  27. 'role' => $services->getMenus($this->adminInfo['level'] == 0 ? [] : $this->adminInfo['roles'], 1, 0),
  28. 'user_info' => [
  29. 'id' => $adminInfo['id'],
  30. 'account' => $adminInfo['account'],
  31. 'phone' => $adminInfo['phone'],
  32. 'real_name' => $adminInfo['real_name'],
  33. 'head_pic' => $adminInfo['head_pic'],
  34. 'roles' => $roleServices->getRolesNames($adminInfo['roles'])
  35. ]
  36. ]);
  37. }
  38. /**
  39. * 格式化菜单
  40. * @return mixed
  41. * @throws DataNotFoundException
  42. * @throws DbException
  43. * @throws ModelNotFoundException|InvalidArgumentException
  44. */
  45. public function menusList()
  46. {
  47. $cahcheKey = md5('admin_common_menu_list');
  48. $list = CacheService::redisHandler()->get($cahcheKey);
  49. if (!$list) {
  50. /** @var SystemMenusServices $menusServices */
  51. $menusServices = app()->make(SystemMenusServices::class);
  52. $menus = $menusServices->search(['is_show' => 1, 'auth_type' => 1, 'is_show_path' => 0])->where('type', 1)
  53. ->field('id,pid,menu_name,menu_path,unique_auth,sort')->order('sort DESC')->select();
  54. $counts = $menusServices->getColumn([
  55. ['is_show', '=', 1],
  56. ['auth_type', '=', 1],
  57. ['is_show_path', '=', 0],
  58. ], 'pid');
  59. $data = [];
  60. foreach ($menus as $key => $item) {
  61. $pid = $item->getData('pid');
  62. $data[$key] = json_decode($item, true);
  63. $data[$key]['pid'] = $pid;
  64. if (in_array($item->id, $counts)) {
  65. $data[$key]['type'] = 1;
  66. } else {
  67. $data[$key]['type'] = 0;
  68. }
  69. $data[$key]['menu_path'] = preg_replace('/^\/admin/', '', $item['menu_path']);
  70. }
  71. $list = sort_list_tier($data);
  72. CacheService::redisHandler()->set($cahcheKey, $list, 86400);
  73. }
  74. return app('json')->success($list);
  75. }
  76. /**
  77. * @param CityAreaServices $services
  78. * @return mixed
  79. * @throws DataNotFoundException
  80. * @throws DbException
  81. * @throws ModelNotFoundException
  82. */
  83. public function city(CityAreaServices $services)
  84. {
  85. $pid = $this->request->get('pid', 0);
  86. $type = $this->request->get('type', 0);
  87. return $this->success($services->getCityTreeList((int)$pid, $type));
  88. }
  89. }