Admin.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. var_dump($input);
  33. $rule = [
  34. 'username|用户名' => 'require',
  35. 'password|内容' => 'require',
  36. ];
  37. Until::check($rule, $input);
  38. $info = (new AdminModel())::where(['account' => $input['username'], 'passwd' => $input['password']])->find();
  39. if (empty($info)) {
  40. throw new ApiException('账号或密码错误');
  41. }
  42. $tokenService = new \app\common\until\Token();
  43. $token = $tokenService->getToken($info['id']);
  44. Until::output(['token' => $token,'id' => $info['id']]);
  45. }
  46. public function logout() {
  47. Until::output(['name' => 'tom']);
  48. }
  49. /**
  50. * 显示指定的资源
  51. *
  52. * @return \think\Response
  53. */
  54. public function read()
  55. {
  56. $info = (new AdminModel())::where(['id' => $this->userId])->field('account,avatar')->find();
  57. if (empty($info)) {
  58. throw new ApiException('无此用户');
  59. }
  60. Until::output(['username' => $info['account'],'avatar' => $info['avatar']]);
  61. }
  62. /**
  63. * 保存更新的资源
  64. *
  65. * @param \think\Request $request
  66. * @param int $id
  67. * @return \think\Response
  68. */
  69. public function update(Request $request, $id)
  70. {
  71. //
  72. }
  73. /**
  74. * 删除指定资源
  75. *
  76. * @param int $id
  77. * @return \think\Response
  78. */
  79. public function delete($id)
  80. {
  81. //
  82. }
  83. }