UserController.php 36 KB

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