SystemController.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | saiadmin [ saiadmin快速开发框架 ]
  4. // +----------------------------------------------------------------------
  5. // | Author: sai <1430792918@qq.com>
  6. // +----------------------------------------------------------------------
  7. namespace plugin\saiadmin\app\controller;
  8. use plugin\saiadmin\app\cache\DictCache;
  9. use plugin\saiadmin\app\cache\UserAuthCache;
  10. use plugin\saiadmin\app\cache\UserInfoCache;
  11. use plugin\saiadmin\app\cache\UserMenuCache;
  12. use plugin\saiadmin\app\logic\system\SystemCategoryLogic;
  13. use plugin\saiadmin\app\logic\system\SystemLoginLogLogic;
  14. use plugin\saiadmin\app\logic\system\SystemOperLogLogic;
  15. use plugin\saiadmin\basic\BaseController;
  16. use plugin\saiadmin\app\logic\system\SystemUserLogic;
  17. use plugin\saiadmin\app\logic\system\SystemAttachmentLogic;
  18. use plugin\saiadmin\service\Permission;
  19. use support\Request;
  20. use support\Response;
  21. use plugin\saiadmin\utils\Arr;
  22. use Tinywan\Storage\Storage;
  23. /**
  24. * 系统控制器
  25. */
  26. class SystemController extends BaseController
  27. {
  28. /**
  29. * 用户信息
  30. */
  31. public function userInfo(): Response
  32. {
  33. $info['user'] = $this->adminInfo;
  34. $info = [];
  35. $info['id'] = $this->adminInfo['id'];
  36. $info['username'] = $this->adminInfo['username'];
  37. $info['dashboard'] = $this->adminInfo['dashboard'];
  38. $info['avatar'] = $this->adminInfo['avatar'];
  39. $info['email'] = $this->adminInfo['email'];
  40. $info['phone'] = $this->adminInfo['phone'];
  41. $info['gender'] = $this->adminInfo['gender'];
  42. $info['signed'] = $this->adminInfo['signed'];
  43. $info['realname'] = $this->adminInfo['realname'];
  44. $info['department'] = $this->adminInfo['deptList'];
  45. if ($this->adminInfo['id'] === 1) {
  46. $info['buttons'] = ['*'];
  47. $info['roles'] = ['super_admin'];
  48. } else {
  49. $info['buttons'] = UserAuthCache::getUserAuth($this->adminInfo['id']);
  50. $info['roles'] = Arr::getArrayColumn($this->adminInfo['roleList'], 'code');
  51. }
  52. return $this->success($info);
  53. }
  54. /**
  55. * 全部字典数据
  56. */
  57. public function dictAll(): Response
  58. {
  59. $dict = DictCache::getDictAll();
  60. return $this->success($dict);
  61. }
  62. /**
  63. * 菜单数据
  64. * @return Response
  65. */
  66. public function menu(): Response
  67. {
  68. $data = UserMenuCache::getUserMenu($this->adminInfo['id']);
  69. return $this->success($data);
  70. }
  71. /**
  72. * 获取资源列表
  73. * @param Request $request
  74. * @return Response
  75. */
  76. #[Permission('附件列表读取', 'core:system:resource')]
  77. public function getResourceCategory(Request $request): Response
  78. {
  79. $logic = new SystemCategoryLogic();
  80. $data = $logic->tree([]);
  81. return $this->success($data);
  82. }
  83. /**
  84. * 获取资源列表
  85. * @param Request $request
  86. * @return Response
  87. */
  88. #[Permission('附件列表读取', 'core:system:resource')]
  89. public function getResourceList(Request $request): Response
  90. {
  91. $logic = new SystemAttachmentLogic();
  92. $where = $request->more([
  93. ['origin_name', ''],
  94. ['category_id', ''],
  95. ]);
  96. $query = $logic->search($where);
  97. $query->whereIn('mime_type', ['image/jpeg', 'image/png', 'image/gif', 'image/webp']);
  98. $data = $logic->getList($query);
  99. return $this->success($data);
  100. }
  101. /**
  102. * 获取用户列表
  103. * @param Request $request
  104. * @return Response
  105. */
  106. #[Permission('用户列表读取', 'core:system:user')]
  107. public function getUserList(Request $request): Response
  108. {
  109. $logic = new SystemUserLogic();
  110. $where = $request->more([
  111. ['keyword', ''],
  112. ['dept_id', ''],
  113. ]);
  114. $data = $logic->openUserList($where);
  115. return $this->success($data);
  116. }
  117. /**
  118. * 下载网络图片
  119. */
  120. #[Permission('上传网络图片', 'core:system:uploadImage')]
  121. public function saveNetworkImage(Request $request): Response
  122. {
  123. $url = $request->input('url', '');
  124. $config = Storage::getConfig('local');
  125. $logic = new SystemAttachmentLogic();
  126. $data = $logic->saveNetworkImage($url, $config);
  127. return $this->success($data, '操作成功');
  128. }
  129. /**
  130. * 上传图片
  131. */
  132. #[Permission('上传图片', 'core:system:uploadImage')]
  133. public function uploadImage(Request $request): Response
  134. {
  135. $logic = new SystemAttachmentLogic();
  136. $type = $request->input('mode', 'system');
  137. if ($type == 'local') {
  138. return $this->success($logic->uploadBase('image', true));
  139. }
  140. return $this->success($logic->uploadBase('image'));
  141. }
  142. /**
  143. * 上传文件
  144. */
  145. #[Permission('上传文件', 'core:system:uploadFile')]
  146. public function uploadFile(Request $request): Response
  147. {
  148. $logic = new SystemAttachmentLogic();
  149. $type = $request->input('mode', 'system');
  150. if ($type == 'local') {
  151. return $this->success($logic->uploadBase('file', true));
  152. }
  153. return $this->success($logic->uploadBase('file'));
  154. }
  155. /**
  156. * 切片上传
  157. */
  158. #[Permission('上传文件', 'core:system:chunkUpload')]
  159. public function chunkUpload(Request $request): Response
  160. {
  161. $logic = new SystemAttachmentLogic();
  162. $data = $request->post();
  163. $result = $logic->chunkUpload($data);
  164. return $this->success($result);
  165. }
  166. /**
  167. * 获取登录日志
  168. * @return Response
  169. */
  170. public function getLoginLogList(): Response
  171. {
  172. $logic = new SystemLoginLogLogic();
  173. $logic->init($this->adminInfo);
  174. $query = $logic->search(['username' => $this->adminName]);
  175. $data = $logic->getList($query);
  176. return $this->success($data);
  177. }
  178. /**
  179. * 获取操作日志
  180. * @return Response
  181. */
  182. public function getOperationLogList(): Response
  183. {
  184. $logic = new SystemOperLogLogic();
  185. $logic->init($this->adminInfo);
  186. $data = $logic->getOwnOperLogList(['username' => $this->adminName]);
  187. return $this->success($data);
  188. }
  189. /**
  190. * 清除缓存
  191. * @return Response
  192. */
  193. public function clearAllCache(): Response
  194. {
  195. UserInfoCache::clearUserInfo($this->adminId);
  196. UserAuthCache::clearUserAuth($this->adminId);
  197. UserMenuCache::clearUserMenu($this->adminId);
  198. return $this->success([], '清除缓存成功!');
  199. }
  200. /**
  201. * 基本统计
  202. * @return Response
  203. */
  204. #[Permission('工作台数据统计', 'core:console:list')]
  205. public function statistics(): Response
  206. {
  207. $userLogic = new SystemUserLogic();
  208. $userCount = $userLogic->count('id');
  209. $uploadLogic = new SystemAttachmentLogic();
  210. $attachCount = $uploadLogic->count('id');
  211. $loginLogic = new SystemLoginLogLogic();
  212. $loginCount = $loginLogic->count('id');
  213. $operLogic = new SystemOperLogLogic();
  214. $operCount = $operLogic->count('id');
  215. return $this->success([
  216. 'user' => $userCount,
  217. 'attach' => $attachCount,
  218. 'login' => $loginCount,
  219. 'operate' => $operCount,
  220. ]);
  221. }
  222. /**
  223. * 登录统计曲线图
  224. * @return Response
  225. */
  226. #[Permission('工作台数据统计', 'core:console:list')]
  227. public function loginChart(): Response
  228. {
  229. $logic = new SystemLoginLogLogic();
  230. $data = $logic->loginChart();
  231. return $this->success($data);
  232. }
  233. /**
  234. * 登录统计柱状图
  235. * @return Response
  236. */
  237. #[Permission('工作台数据统计', 'core:console:list')]
  238. public function loginBarChart(): Response
  239. {
  240. $logic = new SystemLoginLogLogic();
  241. $data = $logic->loginBarChart();
  242. return $this->success($data);
  243. }
  244. }