UserController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\api\controller\v1\user;
  12. use app\Request;
  13. use app\services\user\UserServices;
  14. use crmeb\services\CacheService;
  15. /**
  16. * 用户类
  17. * Class UserController
  18. * @package app\api\controller\store
  19. */
  20. class UserController
  21. {
  22. protected $services = NUll;
  23. /**
  24. * UserController constructor.
  25. * @param UserServices $services
  26. */
  27. public function __construct(UserServices $services)
  28. {
  29. $this->services = $services;
  30. }
  31. /**
  32. * 获取用户信息
  33. * @param Request $request
  34. * @return mixed
  35. */
  36. public function userInfo(Request $request)
  37. {
  38. $info = $request->user()->toArray();
  39. return app('json')->success($this->services->userInfo($info));
  40. }
  41. /**
  42. * 用户资金统计
  43. * @param Request $request
  44. * @return mixed
  45. * @throws \think\Exception
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. * @throws \think\exception\DbException
  49. */
  50. public function balance(Request $request)
  51. {
  52. $uid = (int)$request->uid();
  53. return app('json')->successful($this->services->balance($uid));
  54. }
  55. /**
  56. * 个人中心
  57. * @param Request $request
  58. * @return mixed
  59. */
  60. public function user(Request $request)
  61. {
  62. $user = $request->user()->toArray();
  63. return app('json')->success($this->services->personalHome($user, $request->tokenData()));
  64. }
  65. /**
  66. * 获取活动状态
  67. * @return mixed
  68. */
  69. public function activity()
  70. {
  71. return app('json')->successful($this->services->activity());
  72. }
  73. /**
  74. * 用户修改信息
  75. * @param Request $request
  76. * @return mixed
  77. */
  78. public function edit(Request $request)
  79. {
  80. list($avatar, $nickname) = $request->postMore([
  81. ['avatar', ''],
  82. ['nickname', ''],
  83. ], true);
  84. if (!$avatar && $nickname == '') {
  85. return app('json')->fail('请输入昵称或者选择头像');
  86. }
  87. $uid = (int)$request->uid();
  88. if ($this->services->eidtNickname($uid, ['avatar' => $avatar, 'nickname' => $nickname])) {
  89. return app('json')->successful('修改成功');
  90. }
  91. return app('json')->fail('修改失败');
  92. }
  93. /**
  94. * 推广人排行
  95. * @param Request $request
  96. * @return mixed
  97. * @throws \think\db\exception\DataNotFoundException
  98. * @throws \think\db\exception\ModelNotFoundException
  99. * @throws \think\exception\DbException
  100. */
  101. public function rank(Request $request)
  102. {
  103. $data = $request->getMore([
  104. ['page', ''],
  105. ['limit', ''],
  106. ['type', '']
  107. ]);
  108. return app('json')->success($this->services->getRankList($data));
  109. }
  110. /**
  111. * 添加访问记录
  112. * @param Request $request
  113. * @return mixed
  114. */
  115. public function set_visit(Request $request)
  116. {
  117. $data = $request->postMore([
  118. ['url', ''],
  119. ['stay_time', 0]
  120. ]);
  121. if ($data['url'] == '') return app('json')->fail('未获取页面路径');
  122. $data['uid'] = (int)$request->uid();
  123. $data['ip'] = $request->ip();
  124. if ($this->services->setVisit($data)) {
  125. return app('json')->success('添加访问记录成功');
  126. } else {
  127. return app('json')->fail('添加访问记录失败');
  128. }
  129. }
  130. /**
  131. * 静默绑定推广人
  132. * @param Request $request
  133. * @return mixed
  134. */
  135. public function spread(Request $request)
  136. {
  137. [$spreadUid, $code] = $request->postMore([
  138. ['puid', 0],
  139. ['code', 0]
  140. ], true);
  141. $uid = (int)$request->uid();
  142. $this->services->spread($uid, (int)$spreadUid, $code);
  143. return app('json')->success();
  144. }
  145. /**
  146. * 推荐用户
  147. * @param Request $request
  148. * @return mixed
  149. *
  150. * grade == 0 获取一级推荐人
  151. * grade == 1 获取二级推荐人
  152. *
  153. * keyword 会员名称查询
  154. *
  155. * sort childCount ASC/DESC 团队排序 numberCount ASC/DESC 金额排序 orderCount ASC/DESC 订单排序
  156. */
  157. public function spread_people(Request $request)
  158. {
  159. $spreadInfo = $request->postMore([
  160. ['grade', 0],
  161. ['keyword', ''],
  162. ['sort', ''],
  163. ]);
  164. if (!in_array($spreadInfo['grade'], [0, 1])) {
  165. return app('json')->fail('等级错误');
  166. }
  167. $uid = $request->uid();
  168. return app('json')->successful($this->services->getUserSpreadGrade($uid, $spreadInfo['grade'], $spreadInfo['sort'], $spreadInfo['keyword']));
  169. }
  170. }