Admin.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\index\controller;
  4. use app\index\BaseController;
  5. use app\index\exception\ApiException;
  6. use app\index\model\AdminModel;
  7. use app\common\until\Until;
  8. use think\Request;
  9. class Admin extends BaseController
  10. {
  11. /**
  12. * 显示资源列表
  13. *
  14. * @return \think\Response
  15. */
  16. public function index()
  17. {
  18. //
  19. }
  20. /**
  21. * 保存新建的资源
  22. *
  23. * @param \think\Request $request
  24. * @return \think\Response
  25. */
  26. public function save(Request $request)
  27. {
  28. //
  29. }
  30. public function login() {
  31. $input = Until::getInput();
  32. $rule = [
  33. 'username|用户名' => 'require',
  34. 'password|内容' => 'require',
  35. ];
  36. Until::check($rule, $input);
  37. $info = (new AdminModel())::where(['account' => $input['username'], 'passwd' => $input['password']])->find();
  38. if (empty($info)) {
  39. throw new ApiException('账号或密码错误');
  40. }
  41. $tokenService = new \app\common\until\Token();
  42. $token = $tokenService->getToken($info['id']);
  43. Until::output(['token' => $token,'id' => $info['id']]);
  44. }
  45. public function logout() {
  46. Until::output(['name' => 'tom']);
  47. }
  48. /**
  49. * 显示指定的资源
  50. *
  51. * @return \think\Response
  52. */
  53. public function read()
  54. {
  55. $info = (new AdminModel())::where(['id' => $this->userId])->field('account,avatar')->find();
  56. if (empty($info)) {
  57. throw new ApiException('无此用户');
  58. }
  59. Until::output(['username' => $info['account'],'avatar' => $info['avatar']]);
  60. }
  61. /**
  62. * 保存更新的资源
  63. *
  64. * @param \think\Request $request
  65. * @param int $id
  66. * @return \think\Response
  67. */
  68. public function update(Request $request, $id)
  69. {
  70. //
  71. }
  72. /**
  73. * 删除指定资源
  74. *
  75. * @param int $id
  76. * @return \think\Response
  77. */
  78. public function delete($id)
  79. {
  80. //
  81. }
  82. }