AuctionController.php 17 KB

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