UserController.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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\UserCancelServices;
  14. use app\services\user\UserServices;
  15. use app\services\wechat\WechatUserServices;
  16. /**
  17. * 用户类
  18. * Class UserController
  19. * @package app\api\controller\store
  20. */
  21. class UserController
  22. {
  23. protected $services = NUll;
  24. /**
  25. * UserController constructor.
  26. * @param UserServices $services
  27. */
  28. public function __construct(UserServices $services)
  29. {
  30. $this->services = $services;
  31. }
  32. /**
  33. * 获取用户信息
  34. * @param Request $request
  35. * @return mixed
  36. */
  37. public function userInfo(Request $request)
  38. {
  39. $info = $request->user()->toArray();
  40. return app('json')->success($this->services->userInfo($info));
  41. }
  42. /**
  43. * 用户资金统计
  44. * @param Request $request
  45. * @return mixed
  46. * @throws \think\Exception
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. * @throws \think\exception\DbException
  50. */
  51. public function balance(Request $request)
  52. {
  53. $uid = (int)$request->uid();
  54. return app('json')->successful($this->services->balance($uid));
  55. }
  56. /**
  57. * 个人中心
  58. * @param Request $request
  59. * @return mixed
  60. */
  61. public function user(Request $request)
  62. {
  63. $user = $request->user()->toArray();
  64. return app('json')->success($this->services->personalHome($user, $request->tokenData()));
  65. }
  66. /**
  67. * 添加点赞
  68. *
  69. * @param Request $request
  70. * @return mixed
  71. */
  72. // public function like_add(Request $request)
  73. // {
  74. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  75. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  76. // $res = StoreProductRelation::productRelation($id,$request->uid(),'like',$category);
  77. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  78. // else return app('json')->successful();
  79. // }
  80. /**
  81. * 取消点赞
  82. *
  83. * @param Request $request
  84. * @return mixed
  85. */
  86. // public function like_del(Request $request)
  87. // {
  88. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  89. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  90. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  91. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  92. // else return app('json')->successful();
  93. // }
  94. /**
  95. * 获取活动状态
  96. * @return mixed
  97. */
  98. public function activity()
  99. {
  100. return app('json')->successful($this->services->activity());
  101. }
  102. /**
  103. * 用户修改信息
  104. * @param Request $request
  105. * @return mixed
  106. */
  107. public function edit(Request $request)
  108. {
  109. list($avatar, $nickname) = $request->postMore([
  110. ['avatar', ''],
  111. ['nickname', ''],
  112. ], true);
  113. if (!$avatar && $nickname == '') {
  114. return app('json')->fail('请输入昵称或者选择头像');
  115. }
  116. $uid = (int)$request->uid();
  117. if ($this->services->eidtNickname($uid, ['avatar' => $avatar, 'nickname' => $nickname])) {
  118. return app('json')->successful('修改成功');
  119. }
  120. return app('json')->fail('修改失败');
  121. }
  122. /**
  123. * 推广人排行
  124. * @param Request $request
  125. * @return mixed
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\ModelNotFoundException
  128. * @throws \think\exception\DbException
  129. */
  130. public function rank(Request $request)
  131. {
  132. $data = $request->getMore([
  133. ['page', ''],
  134. ['limit', ''],
  135. ['type', '']
  136. ]);
  137. return app('json')->success($this->services->getRankList($data));
  138. }
  139. /**
  140. * 添加访问记录
  141. * @param Request $request
  142. * @return mixed
  143. */
  144. public function set_visit(Request $request)
  145. {
  146. $data = $request->postMore([
  147. ['url', ''],
  148. ['stay_time', 0]
  149. ]);
  150. if ($data['url'] == '') return app('json')->fail('未获取页面路径');
  151. $data['uid'] = (int)$request->uid();
  152. $data['ip'] = $request->ip();
  153. if ($this->services->setVisit($data)) {
  154. return app('json')->success('添加访问记录成功');
  155. } else {
  156. return app('json')->fail('添加访问记录失败');
  157. }
  158. }
  159. /**
  160. * 静默绑定推广人
  161. * @param Request $request
  162. * @return mixed
  163. */
  164. public function spread(Request $request)
  165. {
  166. [$spreadUid, $code] = $request->postMore([
  167. ['puid', 0],
  168. ['code', 0]
  169. ], true);
  170. $uid = (int)$request->uid();
  171. $this->services->spread($uid, (int)$spreadUid, $code);
  172. return app('json')->success();
  173. }
  174. /**
  175. * 推荐用户
  176. * @param Request $request
  177. * @return mixed
  178. *
  179. * grade == 0 获取一级推荐人
  180. * grade == 1 获取二级推荐人
  181. *
  182. * keyword 会员名称查询
  183. *
  184. * sort childCount ASC/DESC 团队排序 numberCount ASC/DESC 金额排序 orderCount ASC/DESC 订单排序
  185. */
  186. public function spread_people(Request $request)
  187. {
  188. $spreadInfo = $request->postMore([
  189. ['grade', 0],
  190. ['keyword', ''],
  191. ['sort', ''],
  192. ]);
  193. if (!in_array($spreadInfo['grade'], [0, 1])) {
  194. return app('json')->fail('等级错误');
  195. }
  196. $uid = $request->uid();
  197. return app('json')->successful($this->services->getUserSpreadGrade($uid, $spreadInfo['grade'], $spreadInfo['sort'], $spreadInfo['keyword']));
  198. }
  199. /**
  200. * 是否关注
  201. * @param Request $request
  202. * @return mixed
  203. */
  204. public function subscribe(Request $request)
  205. {
  206. if ($request->uid()) {
  207. /** @var WechatUserServices $wechatUserService */
  208. $wechatUserService = app()->make(WechatUserServices::class);
  209. $subscribe = (bool)$wechatUserService->value(['uid' => $request->uid()], 'subscribe');
  210. return app('json')->success(['subscribe' => $subscribe]);
  211. } else {
  212. return app('json')->success(['subscribe' => true]);
  213. }
  214. }
  215. /**
  216. * 用户注销
  217. * @param Request $request
  218. * @return mixed
  219. */
  220. public function SetUserCancel(Request $request)
  221. {
  222. /** @var UserCancelServices $userCancelServices */
  223. $userCancelServices = app()->make(UserCancelServices::class);
  224. $userCancelServices->SetUserCancel($request->uid());
  225. return app('json')->success('注销成功');
  226. }
  227. }