User.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\common\exception\BaseException;
  14. use app\api\model\UserCoupon as UserCouponModel;
  15. use app\api\service\User as UserService;
  16. /**
  17. * 用户管理
  18. * Class User
  19. * @package app\api
  20. */
  21. class User extends Controller
  22. {
  23. /**
  24. * 当前用户详情
  25. * @return array|\think\response\Json
  26. * @throws BaseException
  27. */
  28. public function info()
  29. {
  30. // 当前用户信息
  31. $userInfo = UserService::getCurrentLoginUser(true);
  32. // 获取用户头像
  33. $userInfo['avatar'];
  34. // 获取会员等级
  35. $userInfo['grade'];
  36. return $this->renderSuccess(compact('userInfo'));
  37. }
  38. /**
  39. * 账户资产
  40. * @return array|\think\response\Json
  41. * @throws BaseException
  42. */
  43. public function assets()
  44. {
  45. // 当前用户信息
  46. $userInfo = UserService::getCurrentLoginUser(true);
  47. // 用户优惠券模型
  48. $model = new UserCouponModel;
  49. // 返回数据
  50. return $this->renderSuccess([
  51. 'assets' => [
  52. 'balance' => $userInfo['balance'], // 账户余额
  53. 'points' => $userInfo['points'], // 会员积分
  54. 'coupon' => $model->getCount($userInfo['user_id']), // 优惠券数量(可用)
  55. ]
  56. ]);
  57. }
  58. }