UserController.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\admin\model\diagnosis\DiagnosisApply;
  4. use app\admin\model\diagnosis\DiagnosisCate;
  5. use app\admin\model\diagnosis\DiagnosisOrder;
  6. use app\admin\model\user\UserEquity;
  7. use app\http\validates\user\AddressValidate;
  8. use app\models\system\SystemCity;
  9. use app\models\user\UserPay;
  10. use app\models\user\UserVisit;
  11. use crmeb\services\CacheService;
  12. use think\db\exception\DataNotFoundException;
  13. use think\db\exception\DbException;
  14. use think\db\exception\ModelNotFoundException;
  15. use think\exception\ValidateException;
  16. use app\Request;
  17. use app\models\user\UserLevel;
  18. use app\models\user\UserSign;
  19. use app\models\store\StoreBargain;
  20. use app\models\store\StoreCombination;
  21. use app\models\store\StoreCouponUser;
  22. use app\models\store\StoreOrder;
  23. use app\models\store\StoreProductRelation;
  24. use app\models\store\StoreSeckill;
  25. use app\models\user\User;
  26. use app\models\user\UserAddress;
  27. use app\models\user\UserBill;
  28. use app\models\user\UserExtract;
  29. use app\models\user\UserNotice;
  30. use crmeb\services\GroupDataService;
  31. use crmeb\services\UtilService;
  32. use think\facade\Validate;
  33. /**
  34. * 用户类
  35. * Class UserController
  36. * @package app\api\controller\store
  37. */
  38. class UserController
  39. {
  40. /**
  41. * 获取用户信息
  42. * @param Request $request
  43. * @return mixed
  44. */
  45. public function userInfo(Request $request)
  46. {
  47. $info = $request->user()->toArray();
  48. $broken_time = intval(sys_config('extract_time'));
  49. $search_time = time() - 86400 * $broken_time;
  50. //返佣 +
  51. $brokerage_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  52. ->where('add_time', '>', $search_time)
  53. ->where('pm', 1)
  54. ->sum('number');
  55. //退款退的佣金 -
  56. $refund_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  57. ->where('add_time', '>', $search_time)
  58. ->where('pm', 0)
  59. ->sum('number');
  60. $info['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  61. if ($info['broken_commission'] < 0)
  62. $info['broken_commission'] = 0;
  63. $info['commissionCount'] = bcsub($info['brokerage_price'], $info['broken_commission'], 2);
  64. if ($info['commissionCount'] < 0)
  65. $info['commissionCount'] = 0;
  66. return app('json')->success($info);
  67. }
  68. /**
  69. * 用户资金统计
  70. * @param Request $request
  71. * @return mixed
  72. * @throws \think\Exception
  73. * @throws DataNotFoundException
  74. * @throws ModelNotFoundException
  75. * @throws \think\exception\DbException
  76. */
  77. public function balance(Request $request)
  78. {
  79. $uid = $request->uid();
  80. $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money'];//当前总资金
  81. $user['recharge'] = UserBill::getRecharge($uid);//累计充值
  82. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid);//累计消费
  83. return app('json')->successful($user);
  84. }
  85. /**
  86. * 个人中心
  87. * @param Request $request
  88. * @return mixed
  89. */
  90. public function user(Request $request)
  91. {
  92. $user = $request->user();
  93. $user = $user->toArray();
  94. $user['couponCount'] = StoreCouponUser::getUserValidCouponCount($user['uid']);
  95. $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']);
  96. $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']);
  97. $user['notice'] = UserNotice::getNotice($user['uid']);
  98. // $user['brokerage'] = UserBill::getBrokerage($user['uid']);//获取总佣金
  99. $user['recharge'] = UserBill::getRecharge($user['uid']);//累计充值
  100. $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']);//累计消费
  101. $user['extractTotalPrice'] = UserExtract::userExtractTotalPrice($user['uid']);//累计提现
  102. $user['extractPrice'] = $user['brokerage_price'];//可提现
  103. $user['statu'] = (int)sys_config('store_brokerage_statu');
  104. $broken_time = intval(sys_config('extract_time'));
  105. $search_time = time() - 86400 * $broken_time;
  106. if (!$user['is_promoter'] && $user['statu'] == 2) {
  107. $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price');
  108. $status = is_brokerage_statu($price);
  109. if ($status) {
  110. User::where('uid', $user['uid'])->update(['is_promoter' => 1]);
  111. $user['is_promoter'] = 1;
  112. } else {
  113. $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
  114. $user['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2);
  115. }
  116. }
  117. //可提现佣金
  118. //返佣 +
  119. $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  120. ->where('add_time', '>', $search_time)
  121. ->where('pm', 1)
  122. ->sum('number');
  123. //退款退的佣金 -
  124. $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage'])
  125. ->where('add_time', '>', $search_time)
  126. ->where('pm', 0)
  127. ->sum('number');
  128. $user['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2);
  129. if ($user['broken_commission'] < 0)
  130. $user['broken_commission'] = 0;
  131. $user['commissionCount'] = bcsub($user['brokerage_price'], $user['broken_commission'], 2);
  132. if ($user['commissionCount'] < 0)
  133. $user['commissionCount'] = 0;
  134. if (!sys_config('vip_open'))
  135. $user['vip'] = false;
  136. else {
  137. $vipId = UserLevel::getUserLevel($user['uid']);
  138. $user['vip'] = $vipId !== false ? true : false;
  139. if ($user['vip']) {
  140. $user['vip_id'] = $vipId;
  141. $user['vip_icon'] = UserLevel::getUserLevelInfo($vipId, 'icon');
  142. $user['vip_name'] = UserLevel::getUserLevelInfo($vipId, 'name');
  143. }
  144. }
  145. $user['yesterDay'] = UserBill::yesterdayCommissionSum($user['uid']);
  146. $user['recharge_switch'] = (int)sys_config('recharge_switch');//充值开关
  147. $user['adminid'] = (boolean)\app\models\store\StoreService::orderServiceStatus($user['uid']);
  148. if ($user['phone'] && $user['user_type'] != 'h5') {
  149. $user['switchUserInfo'][] = $request->user();
  150. if ($h5UserInfo = User::where('account', $user['phone'])->where('user_type', 'h5')->find()) {
  151. $user['switchUserInfo'][] = $h5UserInfo;
  152. }
  153. } else if ($user['phone'] && $user['user_type'] == 'h5') {
  154. if ($wechatUserInfo = User::where('phone', $user['phone'])->where('user_type', '<>', 'h5')->find()) {
  155. $user['switchUserInfo'][] = $wechatUserInfo;
  156. }
  157. $user['switchUserInfo'][] = $request->user();
  158. } else if (!$user['phone']) {
  159. $user['switchUserInfo'][] = $request->user();
  160. }
  161. return app('json')->successful($user);
  162. }
  163. /**
  164. * 地址 获取单个
  165. * @param Request $request
  166. * @param $id
  167. * @return mixed
  168. * @throws DataNotFoundException
  169. * @throws ModelNotFoundException
  170. * @throws \think\exception\DbException
  171. */
  172. public function address(Request $request, $id)
  173. {
  174. $addressInfo = [];
  175. if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) {
  176. $addressInfo = UserAddress::find($id)->toArray();
  177. }
  178. return app('json')->successful($addressInfo);
  179. }
  180. /**
  181. * 地址列表
  182. * @param Request $request
  183. * @param $page
  184. * @param $limit
  185. * @return mixed
  186. */
  187. public function address_list(Request $request)
  188. {
  189. list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true);
  190. $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default');
  191. return app('json')->successful($list);
  192. }
  193. /**
  194. * 设置默认地址
  195. *
  196. * @param Request $request
  197. * @return mixed
  198. */
  199. public function address_default_set(Request $request)
  200. {
  201. list($id) = UtilService::getMore([['id', 0]], $request, true);
  202. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  203. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  204. return app('json')->fail('地址不存在!');
  205. $res = UserAddress::setDefaultAddress($id, $request->uid());
  206. if (!$res)
  207. return app('json')->fail('地址不存在!');
  208. else
  209. return app('json')->successful();
  210. }
  211. /**
  212. * 获取默认地址
  213. * @param Request $request
  214. * @return mixed
  215. */
  216. public function address_default(Request $request)
  217. {
  218. $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default');
  219. if ($defaultAddress) {
  220. $defaultAddress = $defaultAddress->toArray();
  221. return app('json')->successful('ok', $defaultAddress);
  222. }
  223. return app('json')->successful('empty', []);
  224. }
  225. /**
  226. * 修改 添加地址
  227. * @param Request $request
  228. * @return mixed
  229. */
  230. public function address_edit(Request $request)
  231. {
  232. $addressInfo = UtilService::postMore([
  233. ['address', []],
  234. ['is_default', false],
  235. ['real_name', ''],
  236. ['post_code', ''],
  237. ['phone', ''],
  238. ['detail', ''],
  239. ['id', 0],
  240. ['type', 0]
  241. ], $request);
  242. if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!');
  243. if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!');
  244. if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!');
  245. if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) {
  246. return app('json')->fail('收货地址格式错误!请重新选择!');
  247. } else if ($addressInfo['type'] == 1) {
  248. $city = $addressInfo['address']['city'];
  249. $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id');
  250. if ($cityId) {
  251. $addressInfo['address']['city_id'] = $cityId;
  252. } else {
  253. if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) {
  254. return app('json')->fail('收货地址格式错误!修改后请重新导入!');
  255. }
  256. $addressInfo['address']['city_id'] = $cityId;
  257. }
  258. }
  259. $addressInfo['province'] = $addressInfo['address']['province'];
  260. $addressInfo['city'] = $addressInfo['address']['city'];
  261. $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0;
  262. $addressInfo['district'] = $addressInfo['address']['district'];
  263. $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0;
  264. $addressInfo['uid'] = $request->uid();
  265. unset($addressInfo['address'], $addressInfo['type']);
  266. try {
  267. validate(AddressValidate::class)->check($addressInfo);
  268. } catch (ValidateException $e) {
  269. return app('json')->fail($e->getError());
  270. }
  271. if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) {
  272. $id = $addressInfo['id'];
  273. unset($addressInfo['id']);
  274. if (UserAddress::edit($addressInfo, $id, 'id')) {
  275. if ($addressInfo['is_default'])
  276. UserAddress::setDefaultAddress($id, $request->uid());
  277. return app('json')->successful();
  278. } else
  279. return app('json')->fail('编辑收货地址失败!');
  280. } else {
  281. $addressInfo['add_time'] = time();
  282. if ($address = UserAddress::create($addressInfo)) {
  283. if ($addressInfo['is_default']) {
  284. UserAddress::setDefaultAddress($address->id, $request->uid());
  285. }
  286. return app('json')->successful(['id' => $address->id]);
  287. } else {
  288. return app('json')->fail('添加收货地址失败!');
  289. }
  290. }
  291. }
  292. /**
  293. * 删除地址
  294. *
  295. * @param Request $request
  296. * @return mixed
  297. */
  298. public function address_del(Request $request)
  299. {
  300. list($id) = UtilService::postMore([['id', 0]], $request, true);
  301. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
  302. if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()]))
  303. return app('json')->fail('地址不存在!');
  304. if (UserAddress::edit(['is_del' => '1'], $id, 'id'))
  305. return app('json')->successful();
  306. else
  307. return app('json')->fail('删除地址失败!');
  308. }
  309. /**
  310. * 获取收藏产品
  311. *
  312. * @param Request $request
  313. * @return mixed
  314. */
  315. public function collect_user(Request $request)
  316. {
  317. list($page, $limit) = UtilService::getMore([
  318. ['page', 0],
  319. ['limit', 0]
  320. ], $request, true);
  321. if (!(int)$limit) return app('json')->successful([]);
  322. $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit);
  323. return app('json')->successful($productRelationList);
  324. }
  325. /**
  326. * 添加收藏
  327. * @param Request $request
  328. * @param $id
  329. * @param $category
  330. * @return mixed
  331. */
  332. public function collect_add(Request $request)
  333. {
  334. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  335. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  336. $res = StoreProductRelation::productRelation($id, $request->uid(), 'collect', $category);
  337. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  338. else return app('json')->successful();
  339. }
  340. /**
  341. * 取消收藏
  342. *
  343. * @param Request $request
  344. * @return mixed
  345. */
  346. public function collect_del(Request $request)
  347. {
  348. list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true);
  349. if (!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  350. $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category);
  351. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  352. else return app('json')->successful();
  353. }
  354. /**
  355. * 批量收藏
  356. * @param Request $request
  357. * @return mixed
  358. */
  359. public function collect_all(Request $request)
  360. {
  361. $collectInfo = UtilService::postMore([
  362. ['id', []],
  363. ['category', 'product'],
  364. ], $request);
  365. if (!count($collectInfo['id'])) return app('json')->fail('参数错误');
  366. $productIdS = $collectInfo['id'];
  367. $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['category']);
  368. if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  369. else return app('json')->successful('收藏成功');
  370. }
  371. /**
  372. * 添加点赞
  373. *
  374. * @param Request $request
  375. * @return mixed
  376. */
  377. // public function like_add(Request $request)
  378. // {
  379. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  380. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  381. // $res = StoreProductRelation::productRelation($id,$request->uid(),'like',$category);
  382. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  383. // else return app('json')->successful();
  384. // }
  385. /**
  386. * 取消点赞
  387. *
  388. * @param Request $request
  389. * @return mixed
  390. */
  391. // public function like_del(Request $request)
  392. // {
  393. // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true);
  394. // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误');
  395. // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category);
  396. // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo());
  397. // else return app('json')->successful();
  398. // }
  399. /**
  400. * 签到 配置
  401. * @return mixed
  402. * @throws DataNotFoundException
  403. * @throws ModelNotFoundException
  404. * @throws \think\exception\DbException
  405. */
  406. public function sign_config()
  407. {
  408. $signConfig = sys_data('sign_day_num') ?? [];
  409. return app('json')->successful($signConfig);
  410. }
  411. /**
  412. * 签到 列表
  413. * @param Request $request
  414. * @param $page
  415. * @param $limit
  416. * @return mixed
  417. */
  418. public function sign_list(Request $request)
  419. {
  420. list($page, $limit) = UtilService::getMore([
  421. ['page', 0],
  422. ['limit', 0]
  423. ], $request, true);
  424. if (!$limit) return app('json')->successful([]);
  425. $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit);
  426. if ($signList) $signList = $signList->toArray();
  427. return app('json')->successful($signList);
  428. }
  429. /**
  430. * 签到
  431. * @param Request $request
  432. * @return mixed
  433. */
  434. public function sign_integral(Request $request)
  435. {
  436. $signed = UserSign::getIsSign($request->uid());
  437. if ($signed) return app('json')->fail('已签到');
  438. if (false !== ($integral = UserSign::sign($request->uid())))
  439. return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]);
  440. return app('json')->fail(UserSign::getErrorInfo('签到失败'));
  441. }
  442. /**
  443. * 签到用户信息
  444. * @param Request $request
  445. * @return mixed
  446. */
  447. public function sign_user(Request $request)
  448. {
  449. list($sign, $integral, $all) = UtilService::postMore([
  450. ['sign', 0],
  451. ['integral', 0],
  452. ['all', 0],
  453. ], $request, true);
  454. $user = $request->user();
  455. //是否统计签到
  456. if ($sign || $all) {
  457. $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']);
  458. $user['is_day_sgin'] = UserSign::getIsSign($user['uid']);
  459. $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday');
  460. if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) {
  461. $user['sign_num'] = 0;
  462. }
  463. }
  464. //是否统计积分使用情况
  465. if ($integral || $all) {
  466. $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain');
  467. $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0;
  468. $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today');
  469. }
  470. unset($user['pwd']);
  471. if (!$user['is_promoter']) {
  472. $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == 2 ? true : false;
  473. }
  474. return app('json')->successful($user->hidden(['account', 'real_name', 'birthday', 'card_id', 'mark', 'partner_id', 'group_id', 'add_time', 'add_ip', 'phone', 'last_time', 'last_ip', 'spread_uid', 'spread_time', 'user_type', 'status', 'level', 'clean_time', 'addres'])->toArray());
  475. }
  476. /**
  477. * 签到列表(年月)
  478. *
  479. * @param Request $request
  480. * @return mixed
  481. */
  482. public function sign_month(Request $request)
  483. {
  484. list($page, $limit) = UtilService::getMore([
  485. ['page', 0],
  486. ['limit', 0]
  487. ], $request, true);
  488. if (!$limit) return app('json')->successful([]);
  489. $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit);
  490. return app('json')->successful($userSignList);
  491. }
  492. /**
  493. * 获取活动状态
  494. * @return mixed
  495. */
  496. public function activity()
  497. {
  498. $data['is_bargin'] = StoreBargain::validBargain() ? true : false;
  499. $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false;
  500. $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false;
  501. return app('json')->successful($data);
  502. }
  503. /**
  504. * 用户修改信息
  505. * @param Request $request
  506. * @return mixed
  507. */
  508. public function edit(Request $request)
  509. {
  510. list($avatar, $nickname) = UtilService::postMore([
  511. ['avatar', ''],
  512. ['nickname', ''],
  513. ], $request, true);
  514. if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功');
  515. return app('json')->fail('修改失败');
  516. }
  517. /**
  518. * 推广人排行
  519. * @param Request $request
  520. * @return mixed
  521. * @throws DataNotFoundException
  522. * @throws ModelNotFoundException
  523. * @throws \think\exception\DbException
  524. */
  525. public function rank(Request $request)
  526. {
  527. $data = UtilService::getMore([
  528. ['page', ''],
  529. ['limit', ''],
  530. ['type', '']
  531. ], $request);
  532. $users = User::getRankList($data);
  533. return app('json')->success($users);
  534. }
  535. /**
  536. * 佣金排行
  537. * @param Request $request
  538. * @return mixed
  539. */
  540. public function brokerage_rank(Request $request)
  541. {
  542. $data = UtilService::getMore([
  543. ['page', ''],
  544. ['limit'],
  545. ['type']
  546. ], $request);
  547. return app('json')->success([
  548. 'rank' => User::brokerageRank($data),
  549. 'position' => User::currentUserRank($data['type'], $request->user()['brokerage_price'])
  550. ]);
  551. }
  552. /**
  553. * 添加访问记录
  554. * @param Request $request
  555. * @return mixed
  556. */
  557. public function set_visit(Request $request)
  558. {
  559. $data = UtilService::postMore([
  560. ['url', ''],
  561. ['stay_time', 0]
  562. ], $request);
  563. if ($data['url'] == '') return app('json')->fail('未获取页面路径');
  564. $data['uid'] = $request->uid();
  565. $data['ip'] = $request->ip();
  566. $data['add_time'] = time();
  567. $res = UserVisit::insert($data);
  568. if ($res) {
  569. return app('json')->success('添加访问记录成功');
  570. } else {
  571. return app('json')->fail('添加访问记录失败');
  572. }
  573. }
  574. /**
  575. * 静默绑定推广人
  576. * @param Request $request
  577. * @return mixed
  578. * @throws DataNotFoundException
  579. * @throws DbException
  580. * @throws ModelNotFoundException
  581. */
  582. public function spread(Request $request)
  583. {
  584. $puid = $request->post('puid/d', 0);
  585. return app('json')->success(User::setSpread($puid, $request->uid()));
  586. }
  587. /**
  588. * 提交修改申请
  589. * @param Request $request
  590. * @return mixed
  591. * @throws DataNotFoundException
  592. * @throws DbException
  593. * @throws ModelNotFoundException
  594. */
  595. public function apply(Request $request)
  596. {
  597. $data = UtilService::postMore([
  598. ['name'],
  599. ['sex'],
  600. ['phone'],
  601. ['images', []],
  602. ['captcha']
  603. ]);
  604. $verifyCode = CacheService::get('code_' . $data['phone']);
  605. if (!$verifyCode)
  606. return app('json')->fail('请先获取验证码');
  607. $verifyCode = substr($verifyCode, 0, 6);
  608. if ($verifyCode != $data['captcha'])
  609. return app('json')->fail('验证码错误');
  610. if (empty($data['name'])) return app('json')->fail('请填写姓名');
  611. if (empty($data['sex'])) return app('json')->fail('请填写性别');
  612. if (empty($data['phone'])) return app('json')->fail('请填写手机号');
  613. if(!(preg_match("/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/",$data['phone'])))
  614. {
  615. return app('json')->fail('请填写正确的手机号');
  616. }
  617. if (empty($data['images'])) return app('json')->fail('请上传身份证正反面');
  618. $apply = DiagnosisApply::where('uid', $request->uid())->find();
  619. if (!$apply){
  620. $res = DiagnosisApply::create([
  621. 'name' => $data['name'],
  622. 'uid' => $request->uid(),
  623. 'sex' => $data['sex'],
  624. 'phone' => $data['phone'],
  625. 'images' => json_encode($data['images'])
  626. ]);
  627. if ($res) return app('json')->success('提交成功');
  628. return app('json')->fail('提交失败');
  629. }else{
  630. if ($apply['status'] == 0) return app('json')->success('审核中无法修改');
  631. if ($apply['status'] == 1) return app('json')->success('审核已通过');
  632. if ($apply['status'] == -1){
  633. $apply['status'] = 0;
  634. $apply['remarks'] = '';
  635. }
  636. $apply['name'] = $data['name'];
  637. $apply['sex'] = $data['sex'];
  638. $apply['phone'] = $data['phone'];
  639. $apply['images'] = json_encode($data['images']);
  640. $res = $apply->save();
  641. if ($res) return app('json')->success('修改成功');
  642. return app('json')->fail('修改失败');
  643. }
  644. }
  645. /**
  646. * 申请记录
  647. * @param Request $request
  648. * @return mixed
  649. * @throws DataNotFoundException
  650. * @throws DbException
  651. * @throws ModelNotFoundException
  652. */
  653. public function user_apply(Request $request)
  654. {
  655. $list = DiagnosisApply::where('uid', $request->uid())->select();
  656. $list = count($list) > 0 ? $list->toArray() : [];
  657. if ($list){
  658. foreach ($list as &$item)
  659. {
  660. $item['images'] = json_decode($item['images']);
  661. }
  662. }
  663. return app('json')->successful($list);
  664. }
  665. /**
  666. * 添加收款方式
  667. * @param Request $request
  668. * @return void
  669. */
  670. public function pay(Request $request)
  671. {
  672. $data = UtilService::postMore([
  673. ['payment'],
  674. ['image'],
  675. ['bank'],
  676. ['name'],
  677. ['type'],
  678. ['phone'],
  679. ['bank_name']
  680. ], $request);
  681. if (!$data['type']) return app('json')->fail('数据传入错误');
  682. $data['uid'] =$request->uid();
  683. $model = new UserPay();
  684. $pay = $model->where([['uid', '=', $request->uid()], ['type', '=', $data['type']]])->find();
  685. $res = Validate::rule([
  686. 'phone' => 'mobile'
  687. ]);
  688. $res->message([
  689. 'phone.mobile' => '请填写正确手机格式'
  690. ]);
  691. if (!$res->check($data)){
  692. return app('json')->fail($res->getError());
  693. }
  694. if (!empty($pay)){
  695. if ($data['type'] == 1 ){
  696. // 微信收款方式
  697. if (!$data['payment']) return app('json')->fail('微信账号不能为空');
  698. if (!$data['image']) return app('json')->fail('二维码不能为空');
  699. if (!$data['name']) return app('json')->fail('姓名不能为空');
  700. $pay['payment'] = $data['payment'];
  701. $pay['image'] = $data['image'];
  702. $pay['name'] = $data['name'];
  703. $pay['phone'] = $data['phone'];
  704. }elseif ($data['type'] == 2){
  705. // 支付宝收款方式
  706. if (!$data['payment']) return app('json')->fail('支付宝账号不能为空');
  707. if (!$data['name']) return app('json')->fail('姓名不能为空');
  708. $pay['payment'] = $data['payment'];
  709. $pay['name'] = $data['name'];
  710. $pay['phone'] = $data['phone'];
  711. }elseif ($data['type'] == 3){
  712. // 银行卡收款方式
  713. if (!$data['payment']) return app('json')->fail('银行卡号不能为空');
  714. if (!$data['name']) return app('json')->fail('姓名不能为空');
  715. if (!$data['bank']) return app('json')->fail('开户行不能为空');
  716. if (!$data['bank_name']) return app('json')->fail('开户支行不能为空');
  717. if (!$data['phone']) return app('json')->fail('请填写手机号');
  718. $pay['payment'] = $data['payment'];
  719. $pay['bank'] = $data['bank'];
  720. $pay['bank_name'] = $data['bank_name'];
  721. $pay['phone'] = $data['phone'];
  722. $pay['name'] = $data['name'];
  723. }
  724. $res = $pay->save();
  725. if ($res) return app('json')->successful('修改成功');
  726. return app('json')->fail('修改失败');
  727. }else{
  728. if ($data['type'] == 1 ){
  729. // 微信收款方式
  730. if (!$data['payment']) return app('json')->fail('微信账号不能为空');
  731. if (!$data['image']) return app('json')->fail('二维码不能为空');
  732. if (!$data['name']) return app('json')->fail('姓名不能为空');
  733. if (!$data['phone']) return app('json')->fail('请填写手机号');
  734. }elseif ($data['type'] == 2){
  735. // 支付宝收款方式
  736. if (!$data['payment']) return app('json')->fail('支付宝账号不能为空');
  737. if (!$data['name']) return app('json')->fail('姓名不能为空');
  738. if (!$data['phone']) return app('json')->fail('请填写手机号');
  739. }elseif ($data['type'] == 3){
  740. // 银行卡收款方式
  741. if (!$data['payment']) return app('json')->fail('银行卡号不能为空');
  742. if (!$data['name']) return app('json')->fail('姓名不能为空');
  743. if (!$data['bank']) return app('json')->fail('开户行不能为空');
  744. if (!$data['bank_name']) return app('json')->fail('开户支行不能为空');
  745. if (!$data['phone']) return app('json')->fail('请填写手机号');
  746. }
  747. $res = $model->save($data);
  748. if ($res) return app('json')->successful('添加成功');
  749. return app('json')->fail('添加失败');
  750. }
  751. }
  752. /**
  753. * 收款方式详情
  754. * @param Request $request
  755. * @return mixed
  756. * @throws \think\db\exception\DataNotFoundException
  757. * @throws \think\db\exception\DbException
  758. * @throws \think\db\exception\ModelNotFoundException
  759. */
  760. public function pay_list(Request $request)
  761. {
  762. $model = new UserPay();
  763. $list = $model->where('uid', $request->uid())->select();
  764. $list = empty($list)? []: $list->toArray();
  765. $data['wx'] = [];
  766. $data['zfb'] = [];
  767. $data['bank'] = [];
  768. foreach ($list as $k => $v){
  769. if ($v['type'] == 1){
  770. $data['wx'] = $v;
  771. }elseif ($v['type'] == 2){
  772. $data['zfb'] = $v;
  773. }elseif ($v['type'] == 3){
  774. $data['bank'] = $v;
  775. }
  776. }
  777. return app('json')->successful($data);
  778. }
  779. public function equity(Request $request)
  780. {
  781. $equity = UserEquity::where('uid', $request->uid())->where('use', 1)->select();
  782. $table = [];
  783. foreach ($equity as $item)
  784. {
  785. $table = array_merge($table,explode(',', $item['c_id']));
  786. }
  787. $list = DiagnosisCate::where('id', 'in', $table)->select();
  788. $list = count($list) > 0 ? $list->toArray() : [];
  789. return app('json')->successful($list);
  790. }
  791. }