Common.php 3.7 KB

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