UserController.php 37 KB

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