UserController.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 app\services\wechat\WechatUserServices;
  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. *
  68. * @param Request $request
  69. * @return mixed
  70. */
  71. // public function like_add(Request $request)
  72. // {
  73. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  74. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  75. // $res = StoreProductRelation::productRelation($id,$request->uid(),'like',$category);
  76. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  77. // else return app('json')->successful();
  78. // }
  79. /**
  80. * 取消点赞
  81. *
  82. * @param Request $request
  83. * @return mixed
  84. */
  85. // public function like_del(Request $request)
  86. // {
  87. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  88. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  89. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  90. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  91. // else return app('json')->successful();
  92. // }
  93. /**
  94. * 获取活动状态
  95. * @return mixed
  96. */
  97. public function activity()
  98. {
  99. return app('json')->successful($this->services->activity());
  100. }
  101. /**
  102. * 用户修改信息
  103. * @param Request $request
  104. * @return mixed
  105. */
  106. public function edit(Request $request)
  107. {
  108. list($avatar, $nickname) = $request->postMore([
  109. ['avatar', ''],
  110. ['nickname', ''],
  111. ], true);
  112. if (!$avatar && $nickname == '') {
  113. return app('json')->fail('请输入昵称或者选择头像');
  114. }
  115. $uid = (int)$request->uid();
  116. if ($this->services->eidtNickname($uid, ['avatar' => $avatar, 'nickname' => $nickname])) {
  117. return app('json')->successful('修改成功');
  118. }
  119. return app('json')->fail('修改失败');
  120. }
  121. /**
  122. * 推广人排行
  123. * @param Request $request
  124. * @return mixed
  125. * @throws \think\db\exception\DataNotFoundException
  126. * @throws \think\db\exception\ModelNotFoundException
  127. * @throws \think\exception\DbException
  128. */
  129. public function rank(Request $request)
  130. {
  131. $data = $request->getMore([
  132. ['page', ''],
  133. ['limit', ''],
  134. ['type', '']
  135. ]);
  136. return app('json')->success($this->services->getRankList($data));
  137. }
  138. /**
  139. * 添加访问记录
  140. * @param Request $request
  141. * @return mixed
  142. */
  143. public function set_visit(Request $request)
  144. {
  145. $data = $request->postMore([
  146. ['url', ''],
  147. ['stay_time', 0]
  148. ]);
  149. if ($data['url'] == '') return app('json')->fail('未获取页面路径');
  150. $data['uid'] = (int)$request->uid();
  151. $data['ip'] = $request->ip();
  152. if ($this->services->setVisit($data)) {
  153. return app('json')->success('添加访问记录成功');
  154. } else {
  155. return app('json')->fail('添加访问记录失败');
  156. }
  157. }
  158. /**
  159. * 静默绑定推广人
  160. * @param Request $request
  161. * @return mixed
  162. */
  163. public function spread(Request $request)
  164. {
  165. [$spreadUid, $code] = $request->postMore([
  166. ['puid', 0],
  167. ['code', 0]
  168. ], true);
  169. $uid = (int)$request->uid();
  170. $this->services->spread($uid, (int)$spreadUid, $code);
  171. return app('json')->success();
  172. }
  173. /**
  174. * 推荐用户
  175. * @param Request $request
  176. * @return mixed
  177. *
  178. * grade == 0 获取一级推荐人
  179. * grade == 1 获取二级推荐人
  180. *
  181. * keyword 会员名称查询
  182. *
  183. * sort childCount ASC/DESC 团队排序 numberCount ASC/DESC 金额排序 orderCount ASC/DESC 订单排序
  184. */
  185. public function spread_people(Request $request)
  186. {
  187. $spreadInfo = $request->postMore([
  188. ['grade', 0],
  189. ['keyword', ''],
  190. ['sort', ''],
  191. ]);
  192. if (!in_array($spreadInfo['grade'], [0, 1])) {
  193. return app('json')->fail('等级错误');
  194. }
  195. $uid = $request->uid();
  196. return app('json')->successful($this->services->getUserSpreadGrade($uid, $spreadInfo['grade'], $spreadInfo['sort'], $spreadInfo['keyword']));
  197. }
  198. /**
  199. * 是否关注
  200. * @param Request $request
  201. * @return mixed
  202. */
  203. public function subscribe(Request $request)
  204. {
  205. if ($request->uid()) {
  206. /** @var WechatUserServices $wechatUserService */
  207. $wechatUserService = app()->make(WechatUserServices::class);
  208. $subscribe = (bool)$wechatUserService->value(['uid' => $request->uid()], 'subscribe');
  209. return app('json')->success(['subscribe' => $subscribe]);
  210. } else {
  211. return app('json')->success(['subscribe' => true]);
  212. }
  213. }
  214. }