User.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. return $this->renderSuccess(compact('userInfo'));
  35. }
  36. /**
  37. * 账户资产
  38. * @return array|\think\response\Json
  39. * @throws BaseException
  40. */
  41. public function assets()
  42. {
  43. // 当前用户信息
  44. $userInfo = UserService::getCurrentLoginUser(true);
  45. // 用户优惠券模型
  46. $model = new UserCouponModel;
  47. // 返回数据
  48. return $this->renderSuccess([
  49. 'assets' => [
  50. 'balance' => $userInfo['balance'], // 账户余额
  51. 'points' => $userInfo['points'], // 会员积分
  52. 'coupon' => $model->getCount($userInfo['user_id']), // 优惠券数量(可用)
  53. ]
  54. ]);
  55. }
  56. }