Index.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Controller;
  4. use think\Exception;
  5. use think\Session;
  6. use think\Request;
  7. use think\Log;
  8. use think\cache\driver\Redis;
  9. class Index extends Common
  10. {
  11. /**
  12. * 主页显示
  13. *
  14. * @access public
  15. * @return string
  16. */
  17. public function index()
  18. {
  19. // 获取管理员信息.
  20. $adminInfo = session('admin');
  21. // 获取当前模块地址.
  22. $getModular = $this->getModular();
  23. // 传递参数.
  24. $this->assign([
  25. 'adminInfo' => $adminInfo,
  26. 'getPath' => $getModular['path'],
  27. 'getAction' => $getModular['action'],
  28. ]);
  29. return $this->fetch();
  30. }//end index()
  31. /**
  32. * 用户列表
  33. *
  34. * @access public
  35. * @return string
  36. */
  37. public function userList()
  38. {
  39. // 获取管理员信息.
  40. $adminInfo = session('admin');
  41. // 获取当前模块地址.
  42. $getModular = $this->getModular();
  43. // 获取用户列表.
  44. $userList = model('User')->userList();
  45. // 传递参数.
  46. $this->assign([
  47. 'adminInfo' => $adminInfo,
  48. 'getPath' => $getModular['path'],
  49. 'getAction' => $getModular['action'],
  50. 'userList' => $userList['data']['userList'],
  51. 'page' => $userList['data']['page'],
  52. 'currentPage' => $userList['data']['currentPage'],
  53. ]);
  54. return $this->fetch('userlist');
  55. }//end userList()
  56. /**
  57. * 修改用户
  58. *
  59. * @access public
  60. * @return string
  61. */
  62. public function updateUser()
  63. {
  64. try {
  65. model('User')->updateUser();
  66. } catch (\Exception $e) {
  67. Log::write($e->getMessage(), 'error');
  68. return json(['code' => -2, 'data' => '', 'msg' => lang('EC01002')]);
  69. }
  70. return json(['code' => 1, 'data' => '', 'msg' => lang('MC01004')]);
  71. }//end updateUser()
  72. /**
  73. * 平台列表
  74. *
  75. * @access public
  76. * @return string
  77. */
  78. public function platformList()
  79. {
  80. // 获取管理员信息.
  81. $adminInfo = session('admin');
  82. // 获取当前模块地址.
  83. $getModular = $this->getModular();
  84. // 获取平台列表.
  85. $platformList = model('Platform')->platformList();
  86. // 传递参数.
  87. $this->assign([
  88. 'adminInfo' => $adminInfo,
  89. 'getPath' => $getModular['path'],
  90. 'getAction' => $getModular['action'],
  91. 'platformList' => $platformList['data']['platformList'],
  92. 'page' => $platformList['data']['page'],
  93. 'currentPage' => $platformList['data']['currentPage'],
  94. ]);
  95. return $this->fetch('platformlist');
  96. }//end platformList()
  97. /**
  98. * 修改平台
  99. *
  100. * @access public
  101. * @return string
  102. */
  103. public function updatePlatform()
  104. {
  105. if(request()->isAjax()) {
  106. try {
  107. $back = model('Platform')->updatePlatform();
  108. } catch (\Exception $e) {
  109. Log::write($e->getMessage(), 'error');
  110. return json(['code' => -2, 'data' => '', 'msg' => lang('EC01002')]);
  111. }
  112. return json($back);
  113. }
  114. // 获取管理员信息.
  115. $adminInfo = session('admin');
  116. // 获取当前模块地址.
  117. $getModular = $this->getModular();
  118. // 获取平台数据.
  119. $platform = model('Platform')->platform();
  120. // 传递参数.
  121. $this->assign([
  122. 'adminInfo' => $adminInfo,
  123. 'getPath' => $getModular['path'],
  124. 'getAction' => $getModular['action'],
  125. 'platform' => $platform['data']['platform'],
  126. ]);
  127. return $this->fetch('updateplatform');
  128. }//end updatePlatform()
  129. /**
  130. * 删除所选平台
  131. *
  132. * @access public
  133. * @return string
  134. */
  135. public function delPlatform()
  136. {
  137. $ids = $_GET['ids'];
  138. try {
  139. $back = model('Platform')->delPlatform($ids);
  140. } catch (\Exception $e) {
  141. Log::write($e->getMessage(), 'error');
  142. return json(['code' => -2, 'data' => '', 'msg' => lang('EC01002')]);
  143. }
  144. return json(['code' => 1, 'data' => $ids, 'msg' => lang('MC01003')]);
  145. }
  146. /**
  147. * 删除所选用户
  148. *
  149. * @access public
  150. * @return string
  151. */
  152. public function delUser()
  153. {
  154. $ids = $_GET['ids'];
  155. try {
  156. $back = model('User')->delUser($ids);
  157. } catch (\Exception $e) {
  158. Log::write($e->delUser(), 'error');
  159. return json(['code' => -2, 'data' => '', 'msg' => lang('EC01002')]);
  160. }
  161. return json(['code' => 1, 'data' => $ids, 'msg' => lang('MC01003')]);
  162. }
  163. /**
  164. * 删除所选消息
  165. *
  166. * @access public
  167. * @return string
  168. */
  169. public function delMessage()
  170. {
  171. $ids = $_GET['ids'];
  172. try {
  173. $back = model('Message')->delMessage($ids);
  174. } catch (\Exception $e) {
  175. Log::write($e->getMessage(), 'error');
  176. return json(['code' => -2, 'data' => '', 'msg' => lang('EC01002')]);
  177. }
  178. return json(['code' => 1, 'data' => $ids, 'msg' => lang('MC01003')]);
  179. }
  180. /**
  181. * 新增平台
  182. *
  183. * @access public
  184. * @return string
  185. */
  186. public function addPlatform()
  187. {
  188. if(request()->isAjax()) {
  189. try {
  190. $back = model('Platform')->addPlatform();
  191. } catch (\Exception $e) {
  192. Log::write($e->getMessage(), 'error');
  193. return json(['code' => -2, 'data' => '', 'msg' => lang('EC01002')]);
  194. }
  195. return json($back);
  196. }
  197. // 获取管理员信息.
  198. $adminInfo = session('admin');
  199. // 获取当前模块地址.
  200. $getModular = $this->getModular();
  201. // 传递参数.
  202. $this->assign([
  203. 'adminInfo' => $adminInfo,
  204. 'getPath' => $getModular['path'],
  205. 'getAction' => $getModular['action'],
  206. ]);
  207. return $this->fetch('addplatform');
  208. }//end addPlatform()
  209. /**
  210. * 平台用户列表
  211. *
  212. * @access public
  213. * @return string
  214. */
  215. public function platformUser()
  216. {
  217. // 获取管理员信息.
  218. $adminInfo = session('admin');
  219. // 获取当前模块地址.
  220. $getModular = $this->getModular();
  221. // 获取平台用户列表.
  222. $userList = model('UserPlatform')->userList();
  223. // 传递参数.
  224. $this->assign([
  225. 'adminInfo' => $adminInfo,
  226. 'getPath' => $getModular['path'],
  227. 'getAction' => $getModular['action'],
  228. 'userList' => $userList['data']['userList'],
  229. 'page' => $userList['data']['page'],
  230. 'currentPage' => $userList['data']['currentPage'],
  231. ]);
  232. return $this->fetch('platformuser');
  233. }//end platformUser()
  234. /**
  235. * 删除平台用户
  236. *
  237. * @access public
  238. * @return string
  239. */
  240. public function delPlatUser()
  241. {
  242. try {
  243. model('UserPlatform')->deleteUser();
  244. } catch (\Exception $e) {
  245. Log::write($e->getMessage(), 'error');
  246. return json(['code' => -2, 'data' => '', 'msg' => lang('EC01002')]);
  247. }
  248. return json(['code' => 1, 'data' => '', 'msg' => lang('MC01004')]);
  249. }//end delPlatUser()
  250. /**
  251. * 修改用户密码
  252. *
  253. * @access public
  254. * @return string
  255. */
  256. public function updatePassword()
  257. {
  258. $code = -2;
  259. $msg = lang('EC01002');
  260. $data = [];
  261. try {
  262. // 修改密码.
  263. $backData = model('Admin')->updatePassword();
  264. if ($backData['code'] === 1) {
  265. $code = 1;
  266. $msg = $backData['msg'];
  267. $data = $backData['data'];
  268. // 失败则返回错误信息.
  269. } else {
  270. $msg = $backData['msg'];
  271. }
  272. } catch (Exception $e) {
  273. Log::write($e->getMessage(), 'error');
  274. }
  275. return json(['code' => $code, 'data' => $data, 'msg' => $msg]);
  276. }//end updatePassword()
  277. /**
  278. * 消息列表
  279. *
  280. * @access public
  281. * @return string
  282. */
  283. public function messageList()
  284. {
  285. // 获取管理员信息.
  286. $adminInfo = session('admin');
  287. // 获取当前模块地址.
  288. $getModular = $this->getModular();
  289. // 获取消息列表.
  290. $messageList = model('message')->messageList();
  291. // 传递参数.
  292. $this->assign([
  293. 'adminInfo' => $adminInfo,
  294. 'getPath' => $getModular['path'],
  295. 'getAction' => $getModular['action'],
  296. 'messageList' => $messageList['data']['messageList'],
  297. 'page' => $messageList['data']['page'],
  298. 'currentPage' => $messageList['data']['currentPage'],
  299. ]);
  300. return $this->fetch('messagelist');
  301. }//end messageList()
  302. /**
  303. * 消息详情
  304. *
  305. * @access public
  306. * @return string
  307. */
  308. public function messageInfo()
  309. {
  310. // 获取管理员信息.
  311. $adminInfo = session('admin');
  312. // 获取当前模块地址.
  313. $getModular = $this->getModular();
  314. // 获取消息详情.
  315. $messageList = model('message')->messageInfo();
  316. // 传递参数.
  317. $this->assign([
  318. 'adminInfo' => $adminInfo,
  319. 'getPath' => $getModular['path'],
  320. 'getAction' => $getModular['action'],
  321. 'messageInfo' => $messageList['data']['messageInfo'],
  322. ]);
  323. return $this->fetch('messageinfo');
  324. }//end messageInfo()
  325. }