User.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /**
  86. * 学长学姐列表
  87. * @return Json
  88. * @throws \cores\exception\BaseException
  89. * @throws \think\db\exception\DbException
  90. */
  91. public function seniorList()
  92. {
  93. // 当前用户信息
  94. $userInfo = UserService::getCurrentLoginUser(true);
  95. $info = isset($userInfo['info'])? $userInfo['info'] : [];
  96. $admissionYear = isset($info['admission_year'])? $info['admission_year'] : 0;
  97. $model = new UserModel;
  98. $params = $this->request->param();
  99. $params['admission_year'] = isset($params['admission_year'])? $params['admission_year'] : $admissionYear;
  100. $params['user_id'] = $userInfo['user_id'];
  101. $list = $model->getList($params, 15);
  102. return $this->renderSuccess(compact('list'));
  103. }
  104. }