User.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. * 账户资产
  42. * @return Json
  43. * @throws BaseException
  44. */
  45. public function assets(): Json
  46. {
  47. // 当前用户信息
  48. $userInfo = UserService::getCurrentLoginUser(true);
  49. // 用户优惠券模型
  50. $model = new UserCouponModel;
  51. // 返回数据
  52. return $this->renderSuccess([
  53. 'assets' => [
  54. 'balance' => $userInfo['balance'], // 账户余额
  55. 'points' => $userInfo['points'], // 会员积分
  56. 'coupon' => $model->getCount($userInfo['user_id']), // 优惠券数量(可用)
  57. ]
  58. ]);
  59. }
  60. /**
  61. * 手机号绑定
  62. * @return Json
  63. * @throws \cores\exception\BaseException
  64. */
  65. public function bindMobile(): Json
  66. {
  67. $model = new UserModel;
  68. if (!$model->bindMobile($this->postForm())) {
  69. return $this->renderSuccess($model->getError() ?: '操作失败');
  70. }
  71. return $this->renderSuccess('恭喜您,手机号绑定成功');
  72. }
  73. }