SysbaseController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Files;
  5. use app\model\Users;
  6. use app\model\AdminMenu;
  7. use app\model\UsersRoles;
  8. class SysbaseController extends Base
  9. {
  10. /*
  11. * @Description 图片管理列表
  12. */
  13. function fileList()
  14. {
  15. $limit = $this->request->post('limit', 20, 'intval');
  16. $page = $this->request->post('page', 1, 'intval');
  17. $where = [];
  18. $field = 'id,filepath,hash,create_time';
  19. $res = Files::where($where)->field($field)->order('id desc')->paginate(['list_rows' => $limit, 'page' => $page])->toArray();
  20. $data['data'] = $res;
  21. return $this->json($data);
  22. }
  23. /*
  24. * @Description 删除图片
  25. */
  26. function deleteFile()
  27. {
  28. $filepath = $this->request->post('filepath', '', 'serach_in');
  29. if (!$filepath) $this->error('请选择图片');
  30. Files::where('filepath', 'in', $filepath)->delete();
  31. return $this->json(['msg' => '操作成功']);
  32. }
  33. public function sysversion()
  34. {
  35. if (config('database.app_name') == config('my.app_v2')) {
  36. return $this->json(['data' => 'v2']);
  37. } elseif (config('database.app_name') == config('my.app_v3')) {
  38. return $this->json(['data' => 'v3']);
  39. } elseif (config('database.app_name') == config('my.app_v6')) {
  40. return $this->json(['data' => 'v6']);
  41. }
  42. }
  43. /*
  44. * @Description 重置密码
  45. */
  46. public function resetPwd()
  47. {
  48. $password = $this->request->post('password');
  49. if (empty($password)) $this->error('密码不能为空');
  50. $data['id'] = $this->userInfo['id'];
  51. $data["salt"] = substr(md5(uniqid()), 8, 8);
  52. $data['password'] = pass_hash($password, $data["salt"]);
  53. $res = Users::update($data);
  54. return $this->json(['msg' => '操作成功']);
  55. }
  56. /*
  57. * @Description 清除缓存
  58. */
  59. public function clearCache()
  60. {
  61. $appname = app('http')->getName();
  62. try {
  63. deldir(app()->getRootPath() . 'runtime/cache');
  64. } catch (\Exception $e) {
  65. abort(config('my.error_log_code'), $e->getMessage());
  66. }
  67. return $this->json(['msg' => '操作成功']);
  68. }
  69. public function getRolesMenus()
  70. {
  71. $menu = $this->getAdminMenus(0);
  72. $order_array = array_column($menu, 'sort'); //数组排序 根据
  73. array_multisort($order_array, SORT_ASC, $menu);
  74. return $this->json(['menus' => $menu]);
  75. }
  76. //权限系统获取菜单
  77. private function getAdminMenus($pid)
  78. {
  79. $field = 'id,title,path,status,icon,sort';
  80. $rolesInfo = UsersRoles::getinfo($this->userInfo);
  81. $query = AdminMenu::field($field)->where(['pid' => $pid, 'status' => 1]);
  82. if ($rolesInfo['is_allrole'] != 1 && $rolesInfo['pid'] != 0) {
  83. $query->where('path', 'in', $rolesInfo['access']);
  84. }
  85. if (!empty($this->sid)) {
  86. $query->where('is_store', 1);
  87. } elseif (!empty($this->cashregister)) {
  88. $query->where('is_cashregister', 1);
  89. } elseif (!empty($this->ocid)) {
  90. $query->where('is_city', 1);
  91. } elseif (!empty($this->tzid)) {
  92. $query->where('is_tuanzhang', 1);
  93. } elseif ($this->console == 1) {
  94. $query->where('is_console', 1);
  95. } else {
  96. $query->where('is_admin', 1);
  97. }
  98. if (config('database.app_name') == config('my.app_v2')) {
  99. $query->where('is_v2', 1);
  100. }
  101. if (config('database.app_name') == config('my.app_v3')) {
  102. $query->where('is_v3', 1);
  103. }
  104. if (config('database.app_name') == config('my.app_v6')) {
  105. $query->where('is_v6', 1);
  106. }
  107. $list = $query->order('sort asc')->select()->toArray();
  108. if ($list) {
  109. foreach ($list as $key => $val) {
  110. $menus[$key]['sort'] = $val['sort'];
  111. $menus[$key]['access'] = $val['path'];
  112. $menus[$key]['title'] = $val['title'] . '' . '(' . $val['path'] . ')';
  113. $sublist = AdminMenu::field($field)
  114. ->where(['pid' => $val['id'], 'status' => 1])
  115. ->order('sort asc')
  116. ->select()
  117. ->toArray();
  118. if ($sublist) {
  119. $menus[$key]['children'] = $this->getAdminMenus($val['id']);
  120. }
  121. }
  122. if (is_array($menus)) {
  123. $menus = array_values($menus);
  124. }
  125. return $menus;
  126. }
  127. }
  128. }