UserController.php 30 KB

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