UserController.php 38 KB

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