User.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * User:林志杰
  5. * Email:[email protected]
  6. * Motto:纵有疾风起,人生不言弃!
  7. * Time:2020/2/8 23:12
  8. */
  9. namespace app\api\controller;
  10. use app\api\validate\User as UserValidate;
  11. use app\common\business\User as UserBusiness;
  12. class User extends AuthBase
  13. {
  14. public function index()
  15. {
  16. $user = (new UserBusiness)->getNormalUserById($this->userId);
  17. $resultUser = [
  18. 'id' => $this->userId,
  19. 'username' => $user['username'],
  20. 'sex' => $user['sex'],
  21. ];
  22. return show(config('status.success'), 'OK', $resultUser);
  23. }
  24. public function update()
  25. {
  26. $username = $this->request->param('username', '', 'trim');
  27. $sex = input('param.sex', 0, 'intval');
  28. //
  29. $data = [
  30. 'username' => $username,
  31. 'sex' => $sex,
  32. ];
  33. $validate = (new UserValidate)->scene('update_user');
  34. if (!$validate->check($data)) {
  35. return show(config('status.error'), $validate->getError());
  36. }
  37. $user = (new UserBusiness())->update($this->userId, $data);
  38. if (!$user) {
  39. return show(config('status.error'), '更新失败');
  40. }
  41. // 如果用户名被修改,Redis里面的数据也需要同步一下
  42. // todo
  43. return show(1, 'OK');
  44. }
  45. }