AuctionController.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <?php
  2. namespace app\api\controller\auction;
  3. use app\models\auction\Auction;
  4. use app\models\auction\AuctionApply;
  5. use app\models\auction\AuctionBooking;
  6. use app\models\auction\AuctionGu;
  7. use app\models\auction\AuctionOrder;
  8. use app\models\auction\AuctionPay;
  9. use app\models\auction\AuctionProduct;
  10. use app\models\auction\AuctionTime;
  11. use app\models\user\User;
  12. use app\models\user\UserBill;
  13. use app\Request;
  14. use Monolog\Handler\Curl\Util;
  15. use think\facade\Cache;
  16. use crmeb\services\{
  17. CacheService,
  18. ExpressService,
  19. SystemConfigService
  20. };
  21. use crmeb\services\UtilService;
  22. use crmeb\repositories\OrderRepository;
  23. use think\facade\Db;
  24. use think\facade\Validate;
  25. class AuctionController
  26. {
  27. /**
  28. * 场馆列表
  29. * @param Request $request
  30. * @return mixed
  31. */
  32. public function list(Request $request)
  33. {
  34. $data = UtilService::getMore([
  35. [['page', 'd'], 0],
  36. [['limit', 'd'], 0],
  37. ['advance'],
  38. ['auction_gu_id']
  39. ], $request);
  40. if (!$data['auction_gu_id']) return app('json')->fail('数据传入错误');
  41. $auctionModel = new \app\models\auction\Auction();
  42. return app('json')->successful($auctionModel->list($data, $request->uid()));
  43. }
  44. /**
  45. * 预约场馆
  46. * @param Request $request
  47. * @return void
  48. */
  49. public function subscribe(Request $request)
  50. {
  51. $data = UtilService::postMore([
  52. ['id']
  53. ]);
  54. User::rollbackTrans();
  55. if (!$data['id']) return app('json')->fail('数据传入错误');
  56. if (cache($request->uid())) return app('json')->fail('请勿频繁点击');
  57. $auctionModel = new Auction();
  58. $auction = $auctionModel->lock(true)->find($data['id']);
  59. if (!$auction)return app('json')->fail('没有此数据');
  60. if (time() < strtotime($auction['add_time'])){
  61. return app('json')->fail('预约未开始');
  62. }
  63. if (time() > strtotime($auction['end_time'])){
  64. return app('json')->fail('预约时间已过');
  65. }
  66. if (AuctionBooking::where([['uid', '=', $request->uid()], ['auction_id' , '=', $auction['id']], ['frequency', '=', $auction['frequency']]])->find()){
  67. return app('json')->fail('当前场馆已预约');
  68. }
  69. cache($request->uid(), 1, 5);
  70. $userModel = new User();
  71. $user = User::where('uid', $request->uid())->find();
  72. if ($user['is_auth'] != 2) return app('json')->fail('未实名认证');
  73. if ($user['anticipate'] < $auction['anticipate']) return app('json')->fail('易趣卷不足');
  74. $user['anticipate'] = $user['anticipate'] - $auction['anticipate'];// 扣除预约卷
  75. $res = $user->save();
  76. if ($res){
  77. AuctionBooking::booking($user['uid'], $auction);
  78. UserBill::expend('预约场馆', $user['uid'], 'anticipate','reduce_anticipate', $auction['anticipate'], 0, $user['anticipate'], '预约扣除易趣卷'); // 写入记录
  79. User::commitTrans();
  80. return app('json')->successful('预约成功');
  81. }else{
  82. User::rollbackTrans();
  83. return app('json')->fail('预约失败');
  84. }
  85. }
  86. /**
  87. * 进入场馆
  88. * @param Request $request
  89. * @return void
  90. */
  91. public function advance(Request $request)
  92. {
  93. $data = UtilService::getMore([
  94. ['id']
  95. ]);
  96. if (!$data['id']) return app('json')->fail('数据传入错误');
  97. $auction = Auction::find($data['id']);
  98. $booking = AuctionBooking::where([['auction_id', '=',$auction['id']], ['frequency', '=', $auction['frequency']]])->find();
  99. $radd_time = strtotime($auction['radd_time']) - 360; // 提前6分钟进场
  100. if (!$booking){
  101. return app('json')->fail('未预约');
  102. }
  103. if ($radd_time > time()){
  104. return app('json')->fail('未到进入时间');
  105. }
  106. if (strtotime($auction['rend_time']) < time()){
  107. return app('json')->fail('进场时间已过');
  108. }
  109. return app('json')->successful('可进入');
  110. }
  111. /**
  112. * 用户下级
  113. * @param Request $request
  114. * @return mixed
  115. */
  116. public function lower(Request $request){
  117. $data = UtilService::getMore([
  118. [['page', 'd'], 0],
  119. [['limit', 'd'], 0],
  120. ], $request);
  121. $user = User::where('spread_uid', $request->uid())->page($data['page'], $data['limit'])->field('uid,nickname,avatar')->order('uid DESC')->select();
  122. $user = empty($user) ? [] : $user->toArray();
  123. if ($user) {
  124. foreach ($user as $k => $v){
  125. $user[$k]['count'] = User::where('spread_uid',$v['uid'])->count(); // 粉丝人数
  126. $user[$k]['money'] = AuctionOrder::where('uid', $v['uid'])
  127. ->whereBetweenTime('create_time', date('Y-m-d 00:00:00'), date('Y-m-d 00:00:00', strtotime('+1 day')))
  128. ->where('status', 3)
  129. ->sum('price');
  130. }
  131. }
  132. $count = User::where('spread_uid', $request->uid())->count(); // 粉丝人数
  133. $active = User::where('spread_uid', $request->uid())->whereBetweenTime('last_time', date('Y-m-d H:i:s', strtotime('-1 week')), date('Y-m-d H:i:s'))->count(); // 活跃人数
  134. $money = AuctionOrder::where('uid', 'in', User::where('spread_uid', $request->uid())->column('uid'))
  135. ->where('status', 3)
  136. ->sum('price');
  137. $data = [
  138. 'user' => $user, // 下级用户
  139. 'count' => $count, // 下级用户人数
  140. 'active' => $active,// 活跃人数
  141. 'money' => $money // 总金额
  142. ];
  143. return app('json')->successful($data);
  144. }
  145. /**
  146. * 转预约卷给下级
  147. * @param Request $request
  148. * @return mixed
  149. * @throws \think\db\exception\DataNotFoundException
  150. * @throws \think\db\exception\DbException
  151. * @throws \think\db\exception\ModelNotFoundException
  152. */
  153. public function transfer_accounts(Request $request){
  154. $data = UtilService::getMore([
  155. ['uid'],
  156. ['anticipate'],
  157. ['payment']
  158. ], $request);
  159. if (!$data['uid'] or !$data['anticipate']) return app('json')->fail('数据传入错误');
  160. if (!$data['payment']) return app('json')->fail('请填写支付密码');
  161. $user = User::find($request->uid());
  162. $userList = User::select();
  163. $uid = get_downline($userList, $user['uid']);
  164. if ($user['payment'] != md5($data['payment'])) return app('json')->fail('支付密码错误');
  165. if (!in_array($data['uid'],$uid)) return app('json')->fail('该用户不是你下级');
  166. if ($data['anticipate'] < 10) return app('json')->fail('最少转账10');
  167. if ($user['anticipate'] < $data['anticipate']) return app('json')->fail('易趣卷不够');
  168. $me = User::find($data['uid']);
  169. $user['anticipate'] = $user['anticipate'] - $data['anticipate'];// 扣除预约卷
  170. $me['anticipate'] = $me['anticipate'] + $data['anticipate'];// 增加预约卷
  171. try {
  172. Db::startTrans();
  173. UserBill::expend('易趣卷减少',$user['uid'], 'anticipate', 'reduce_anticipate', $data['anticipate'], 0, $user['anticipate'], '转账给('.$me['nickname'].'-'.$me['uid'].')'.$data['anticipate'].'预约卷');
  174. UserBill::income('易趣卷增加',$me['uid'], 'anticipate', 'add_anticipate', $data['anticipate'], 0, $me['anticipate'], '接收('.$user['nickname'].'-'.$user['uid'].')的'.$data['anticipate'].'预约卷');
  175. $user->save();
  176. $me->save();
  177. Db::commit();
  178. return app('json')->successful('成功');
  179. } catch (\Exception $e) {
  180. Db::rollback();
  181. return app('json')->fail('失败');
  182. }
  183. }
  184. /**
  185. * 会馆
  186. * @param Request $request
  187. * @return mixed
  188. * @throws \think\db\exception\DataNotFoundException
  189. * @throws \think\db\exception\DbException
  190. * @throws \think\db\exception\ModelNotFoundException
  191. */
  192. public function auction_gu(Request $request)
  193. {
  194. $data = UtilService::getMore([
  195. [['page', 'd'], 0],
  196. [['limit', 'd'], 0],
  197. ], $request);
  198. $uid = getParent($request->uid());
  199. $uid[] = $request->uid();
  200. $list = [];
  201. if ($uid){
  202. $list = AuctionGu::where('a.uid', 'in', $uid)
  203. ->where('a.status', 1)
  204. ->alias('a')
  205. ->field('a.*,u.nickname,u.avatar')
  206. ->leftJoin('user u', 'a.uid = u.uid')
  207. ->page($data['page'], $data['limit'])
  208. ->select();
  209. }
  210. $list = !empty($list) ? $list->toArray() : [];
  211. return app('json')->successful($list);
  212. }
  213. /**
  214. * 用户管理会馆
  215. * @param Request $request
  216. * @return mixed
  217. */
  218. public function user_gu(Request $request)
  219. {
  220. $data = UtilService::getMore([
  221. [['page', 'd'], 0],
  222. [['limit', 'd'], 0],
  223. ], $request);
  224. $list = AuctionGu::where('uid', $request->uid())->page($data['page'], $data['limit'])->select();
  225. $list = count($list) ? $list->toArray() : [];
  226. return app('json')->successful($list);
  227. }
  228. /**
  229. * 添加收款方式
  230. * @param Request $request
  231. * @return void
  232. */
  233. public function pay(Request $request)
  234. {
  235. $data = UtilService::postMore([
  236. ['payment'],
  237. ['image'],
  238. ['bank'],
  239. ['name'],
  240. ['type'],
  241. ['phone'],
  242. ['bank_name']
  243. ], $request);
  244. if (!$data['type']) return app('json')->fail('数据传入错误');
  245. $data['uid'] =$request->uid();
  246. $model = new AuctionPay();
  247. $pay = $model->where([['uid', '=', $request->uid()], ['type', '=', $data['type']]])->find();
  248. $res = Validate::rule([
  249. 'phone' => 'mobile'
  250. ]);
  251. $res->message([
  252. 'phone.mobile' => '请填写正确手机格式'
  253. ]);
  254. if (!$res->check($data)){
  255. return app('json')->fail($res->getError());
  256. }
  257. if (!empty($pay)){
  258. if ($data['type'] == 1 ){
  259. // 微信收款方式
  260. if (!$data['payment']) return app('json')->fail('微信账号不能为空');
  261. if (!$data['image']) return app('json')->fail('二维码不能为空');
  262. if (!$data['name']) return app('json')->fail('姓名不能为空');
  263. if (!$data['phone']) return app('json')->fail('请填写手机号');
  264. $pay['payment'] = $data['payment'];
  265. $pay['image'] = $data['image'];
  266. $pay['name'] = $data['name'];
  267. $pay['phone'] = $data['phone'];
  268. }elseif ($data['type'] == 2){
  269. // 支付宝收款方式
  270. if (!$data['payment']) return app('json')->fail('支付宝账号不能为空');
  271. if (!$data['name']) return app('json')->fail('姓名不能为空');
  272. if (!$data['phone']) return app('json')->fail('请填写手机号');
  273. $pay['payment'] = $data['payment'];
  274. $pay['name'] = $data['name'];
  275. $pay['phone'] = $data['phone'];
  276. }elseif ($data['type'] == 3){
  277. // 银行卡收款方式
  278. if (!$data['payment']) return app('json')->fail('银行卡号不能为空');
  279. if (!$data['name']) return app('json')->fail('姓名不能为空');
  280. if (!$data['bank']) return app('json')->fail('开户行不能为空');
  281. if (!$data['bank_name']) return app('json')->fail('开户支行不能为空');
  282. if (!$data['phone']) return app('json')->fail('请填写手机号');
  283. $pay['payment'] = $data['payment'];
  284. $pay['bank'] = $data['bank'];
  285. $pay['bank_name'] = $data['bank_name'];
  286. $pay['phone'] = $data['phone'];
  287. $pay['name'] = $data['name'];
  288. }
  289. $res = $pay->save();
  290. if ($res) return app('json')->successful('修改成功');
  291. return app('json')->fail('修改失败');
  292. }else{
  293. if ($data['type'] == 1 ){
  294. // 微信收款方式
  295. if (!$data['payment']) return app('json')->fail('微信账号不能为空');
  296. if (!$data['image']) return app('json')->fail('二维码不能为空');
  297. if (!$data['name']) return app('json')->fail('姓名不能为空');
  298. if (!$data['phone']) return app('json')->fail('请填写手机号');
  299. }elseif ($data['type'] == 2){
  300. // 支付宝收款方式
  301. if (!$data['payment']) return app('json')->fail('支付宝账号不能为空');
  302. if (!$data['name']) return app('json')->fail('姓名不能为空');
  303. if (!$data['phone']) return app('json')->fail('请填写手机号');
  304. }elseif ($data['type'] == 3){
  305. // 银行卡收款方式
  306. if (!$data['payment']) return app('json')->fail('银行卡号不能为空');
  307. if (!$data['name']) return app('json')->fail('姓名不能为空');
  308. if (!$data['bank']) return app('json')->fail('开户行不能为空');
  309. if (!$data['bank_name']) return app('json')->fail('开户支行不能为空');
  310. if (!$data['phone']) return app('json')->fail('请填写手机号');
  311. }
  312. $res = $model->save($data);
  313. if ($res) return app('json')->successful('添加成功');
  314. return app('json')->fail('添加失败');
  315. }
  316. }
  317. /**
  318. * 收款方式详情
  319. * @param Request $request
  320. * @return mixed
  321. * @throws \think\db\exception\DataNotFoundException
  322. * @throws \think\db\exception\DbException
  323. * @throws \think\db\exception\ModelNotFoundException
  324. */
  325. public function pay_list(Request $request)
  326. {
  327. $model = new AuctionPay();
  328. $list = $model->where('uid', $request->uid())->select();
  329. $list = empty($list)? []: $list->toArray();
  330. $data['wx'] = [];
  331. $data['zfb'] = [];
  332. $data['bank'] = [];
  333. foreach ($list as $k => $v){
  334. if ($v['type'] == 1){
  335. $data['wx'] = $v;
  336. }elseif ($v['type'] == 2){
  337. $data['zfb'] = $v;
  338. }elseif ($v['type'] == 3){
  339. $data['bank'] = $v;
  340. }
  341. }
  342. return app('json')->successful($data);
  343. }
  344. /**
  345. * 馆长申请
  346. * @param Request $request
  347. * @return mixed
  348. * @throws \think\db\exception\DataNotFoundException
  349. * @throws \think\db\exception\DbException
  350. * @throws \think\db\exception\ModelNotFoundException
  351. */
  352. public function apply(Request $request)
  353. {
  354. $data = AuctionApply::where('status', '>', 0)->where('uid', $request->uid())->find();
  355. if (!$data){
  356. $res = AuctionApply::create([
  357. 'uid' => $request->uid()
  358. ]);
  359. if ($res)return app('json')->successful('申请成功');
  360. return app('json')->fail('申请失败');
  361. }
  362. return app('json')->fail('已申请,请等待管理员操作');
  363. }
  364. /**
  365. * 馆长申请
  366. * @param Request $request
  367. * @return void
  368. * @throws \think\db\exception\DataNotFoundException
  369. * @throws \think\db\exception\DbException
  370. * @throws \think\db\exception\ModelNotFoundException
  371. */
  372. public function apply_status(Request $request)
  373. {
  374. $data = AuctionApply::where('uid', $request->uid())->find();
  375. if (!$data){
  376. return app('json')->success(['status' => 0, 'str' => '未提交申请']); // 未提交申请
  377. }
  378. $data = AuctionApply::where([['status', '=', 1], ['uid', '=', $request->uid()]])->find();
  379. if ($data){
  380. return app('json')->success(['status' => 1, 'str' => '待审核']);// 待审核
  381. }
  382. $data = AuctionApply::where([['status', '=', 2], ['uid', '=', $request->uid()]])->find();
  383. if ($data){
  384. return app('json')->success(['status' => 2 ,'str' => '已完成']);// 已完成
  385. }
  386. $data = AuctionApply::where([['status', '=', 0], ['uid', '=', $request->uid()]])->find();
  387. if ($data){
  388. return app('json')->success(['status' => 3, 'str' => '失败']);// 失败
  389. }
  390. }
  391. /**
  392. * 倒计时
  393. * @param Request $request
  394. * @return mixed
  395. * @throws \think\db\exception\DataNotFoundException
  396. * @throws \think\db\exception\DbException
  397. * @throws \think\db\exception\ModelNotFoundException
  398. */
  399. public function count_down(Request $request)
  400. {
  401. $data = UtilService::postMore([
  402. ['id'],
  403. ], $request);
  404. $list = Auction::where('id', $data['id'])->find();
  405. if (!$list) return app('json')->fail('场次不存在');// 失败
  406. $user = $request->user();
  407. $time = strtotime(date('Y-m-d', time()));// 今天
  408. $today = strtotime(date('Y-m-d', strtotime('+1day')));// 明天
  409. $datas = [];
  410. $datas['time'] = strtotime($list['radd_time']) - 60;
  411. $datas['times'] = strtotime($list['radd_time']);
  412. return app('json')->success($datas);// 失败
  413. }
  414. }