UserController.php 36 KB

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