User.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\api\model\user\User as UserModel;
  4. use app\api\controller\Controller;
  5. use app\common\library\easywechat\AppWx;
  6. /**
  7. * 用户管理模型
  8. */
  9. class User extends Controller
  10. {
  11. /**
  12. * 用户自动登录,默认微信小程序
  13. */
  14. public function login()
  15. {
  16. $model = new UserModel;
  17. $user_id = $model->login($this->request->post());
  18. return $this->renderSuccess('', [
  19. 'user_id' => $user_id,
  20. 'token' => $model->getToken()
  21. ]);
  22. }
  23. /**
  24. * 当前用户详情
  25. */
  26. public function detail()
  27. {
  28. // 当前用户信息
  29. $userInfo = $this->getUser();
  30. return $this->renderSuccess('', compact('userInfo'));
  31. }
  32. public function getSession($code)
  33. {
  34. // 微信登录 获取session_key
  35. $app = AppWx::getApp();
  36. $session_key = AppWx::sessionKey($app, $code)['session_key'];
  37. return $this->renderSuccess('', compact('session_key'));
  38. }
  39. /**
  40. * 绑定手机号
  41. */
  42. public function bindMobile()
  43. {
  44. $model = $this->getUser();
  45. $mobile = $model->bindMobile($this->request->post());
  46. if ($mobile) {
  47. return $this->renderSuccess('', compact('mobile'));
  48. }
  49. return $this->renderError('绑定失败');
  50. }
  51. /**
  52. * 修改用户信息
  53. */
  54. public function updateInfo()
  55. {
  56. // 当前用户信息
  57. $model = $this->getUser();
  58. if ($model->edit($this->request->post())) {
  59. return $this->renderSuccess('修改成功');
  60. }
  61. return $this->renderError($model->getError() ?: '修改失败');
  62. }
  63. }