AuctionController.php 17 KB

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