User.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\api\controller;
  13. use app\api\model\User as UserModel;
  14. use app\common\exception\BaseException;
  15. use app\api\model\UserCoupon as UserCouponModel;
  16. use app\api\service\User as UserService;
  17. use think\response\Json;
  18. /**
  19. * 用户管理
  20. * Class User
  21. * @package app\api
  22. */
  23. class User extends Controller
  24. {
  25. /**
  26. * 当前用户详情
  27. * @return Json
  28. * @throws BaseException
  29. */
  30. public function info(): Json
  31. {
  32. // 当前用户信息
  33. $userInfo = UserService::getCurrentLoginUser(true);
  34. // 获取用户头像
  35. $userInfo['avatar'];
  36. // 获取会员等级
  37. $userInfo['grade'];
  38. return $this->renderSuccess(compact('userInfo'));
  39. }
  40. /**
  41. * @return Json
  42. * @throws \cores\exception\BaseException
  43. */
  44. public function setInfo(): Json
  45. {
  46. $model = new UserModel;
  47. if (!$result = $model->saveInfo($this->request->param())) {
  48. return $this->renderSuccess($model->getError() ?: '保存失败');
  49. }
  50. return $this->renderSuccess($result? $result : '保存成功');
  51. }
  52. /**
  53. * 账户资产
  54. * @return Json
  55. * @throws BaseException
  56. */
  57. public function assets(): Json
  58. {
  59. // 当前用户信息
  60. $userInfo = UserService::getCurrentLoginUser(true);
  61. // 用户优惠券模型
  62. $model = new UserCouponModel;
  63. // 返回数据
  64. return $this->renderSuccess([
  65. 'assets' => [
  66. 'balance' => $userInfo['balance'], // 账户余额
  67. 'points' => $userInfo['points'], // 会员积分
  68. 'coupon' => $model->getCount($userInfo['user_id']), // 优惠券数量(可用)
  69. ]
  70. ]);
  71. }
  72. /**
  73. * 手机号绑定
  74. * @return Json
  75. * @throws \cores\exception\BaseException
  76. */
  77. public function bindMobile(): Json
  78. {
  79. $model = new UserModel;
  80. if (!$model->bindMobile($this->postForm())) {
  81. return $this->renderSuccess($model->getError() ?: '操作失败');
  82. }
  83. return $this->renderSuccess('恭喜您,手机号绑定成功');
  84. }
  85. }