UserController.php 31 KB

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