AuctionController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <?php
  2. namespace app\api\controller\auction;
  3. use app\models\auction\Auction;
  4. use app\models\auction\AuctionBooking;
  5. use app\models\auction\AuctionGu;
  6. use app\models\auction\AuctionPay;
  7. use app\models\user\User;
  8. use app\models\user\UserBill;
  9. use app\Request;
  10. use Monolog\Handler\Curl\Util;
  11. use think\facade\Cache;
  12. use crmeb\services\{
  13. CacheService,
  14. ExpressService,
  15. SystemConfigService,
  16. };
  17. use crmeb\services\UtilService;
  18. use crmeb\repositories\OrderRepository;
  19. use think\facade\Db;
  20. class AuctionController
  21. {
  22. /**
  23. * 场馆列表
  24. * @param Request $request
  25. * @return mixed
  26. */
  27. public function list(Request $request)
  28. {
  29. $data = UtilService::getMore([
  30. [['page', 'd'], 0],
  31. [['limit', 'd'], 0],
  32. ['advance'],
  33. ['auction_gu_id']
  34. ], $request);
  35. if (!$data['auction_gu_id']) return app('json')->fail('数据传入错误');
  36. $auctionModel = new \app\models\auction\Auction();
  37. return app('json')->successful($auctionModel->list($data, $request->uid()));
  38. }
  39. /**
  40. * 预约场馆
  41. * @param Request $request
  42. * @return void
  43. */
  44. public function subscribe(Request $request)
  45. {
  46. $data = UtilService::postMore([
  47. ['id']
  48. ]);
  49. if (!$data['id']) return app('json')->fail('数据传入错误');
  50. $auctionModel = new Auction();
  51. $auction = $auctionModel->find($data['id']);
  52. if (!$auction)return app('json')->fail('没有此数据');
  53. if (time() < strtotime($auction['add_time'])){
  54. return app('json')->fail('预约未开始');
  55. }
  56. if (time() > strtotime($auction['end_time'])){
  57. return app('json')->fail('预约时间已过');
  58. }
  59. if (AuctionBooking::where([['uid', '=', $request->uid()], ['auction_id' , '=', $auction['id']], ['frequency', '=', $auction['frequency']]])->find()){
  60. return app('json')->fail('当前场馆已预约');
  61. }
  62. $userModel = new User();
  63. $user = $userModel->find($request->uid());
  64. if ($user['anticipate'] < $auction['anticipate']) return app('json')->fail('预约卷不够');
  65. $user['anticipate'] = $user['anticipate'] - $auction['anticipate'];// 扣除预约卷
  66. User::rollbackTrans();
  67. $res = $user->save();
  68. if ($res){
  69. AuctionBooking::booking($user['uid'], $auction);
  70. UserBill::expend('预约场馆', $user['uid'], 'anticipate','reduce_anticipate', $auction['anticipate'], 0, $user['anticipate'], '预约扣除预约卷'); // 写入记录
  71. User::commitTrans();
  72. return app('json')->successful('预约成功');
  73. }else{
  74. User::rollbackTrans();
  75. return app('json')->fail('预约失败');
  76. }
  77. }
  78. /**
  79. * 进入场馆
  80. * @param Request $request
  81. * @return void
  82. */
  83. public function advance(Request $request)
  84. {
  85. $data = UtilService::getMore([
  86. ['id']
  87. ]);
  88. if (!$data['id']) return app('json')->fail('数据传入错误');
  89. $auction = Auction::find($data['id']);
  90. $booking = AuctionBooking::where([['auction_id', '=',$auction['id']], ['frequency', '=', $auction['frequency']]])->find();
  91. $user = $request->user();
  92. $time = strtotime(date('Y-m-d', time()));// 今天
  93. $today = strtotime(date('Y-m-d', strtotime('+1day')));// 明天
  94. if ($user['is_new'] == 1 or ($user['green_time'] >= $time and $user['green_time'] <= $today)){
  95. // 新人或者绿色通道提前三分钟入场
  96. if (strtotime($auction['radd_time']) -3000 > time()){
  97. return app('json')->fail('未到进入时间');
  98. }
  99. if (strtotime($auction['rend_time']) < time()){
  100. return app('json')->fail('进场时间已过');
  101. }
  102. }else{
  103. if (strtotime($auction['radd_time']) > time()){
  104. return app('json')->fail('未到进入时间');
  105. }
  106. if (strtotime($auction['rend_time']) < time()){
  107. return app('json')->fail('进场时间已过');
  108. }
  109. }
  110. if ($booking){
  111. return app('json')->successful('可进入');
  112. }else{
  113. return app('json')->fail('未预约');
  114. }
  115. }
  116. /**
  117. * 用户下级
  118. * @param Request $request
  119. * @return mixed
  120. */
  121. public function lower(Request $request){
  122. $data = UtilService::getMore([
  123. [['page', 'd'], 0],
  124. [['limit', 'd'], 0],
  125. ], $request);
  126. $user = User::where('spread_uid', $request->uid())->page($data['page'], $data['limit'])->order('uid DESC')->select()->toArray();
  127. return app('json')->successful($user);
  128. }
  129. /**
  130. * 转预约卷给下级
  131. * @param Request $request
  132. * @return mixed
  133. * @throws \think\db\exception\DataNotFoundException
  134. * @throws \think\db\exception\DbException
  135. * @throws \think\db\exception\ModelNotFoundException
  136. */
  137. public function transfer_accounts(Request $request){
  138. $data = UtilService::getMore([
  139. ['uid'],
  140. ['anticipate']
  141. ], $request);
  142. if (!$data['uid'] or !$data['anticipate']) return app('json')->fail('数据传入错误');
  143. $user = User::find($request->uid());
  144. if ($user['anticipate'] < $data['anticipate']) return app('json')->fail('预约卷不够');
  145. $me = User::find($data['uid']);
  146. $user['anticipate'] = $user['anticipate'] - $data['anticipate'];// 扣除预约卷
  147. $me['anticipate'] = $me['anticipate'] + $data['anticipate'];// 增加预约卷
  148. try {
  149. Db::startTrans();
  150. UserBill::expend('预约卷减少',$user['uid'], 'anticipate', 'reduce_anticipate', $data['anticipate'], 0, $user['anticipate'], '转账给用户'.$me['nickname'].$data['anticipate'].'预约卷');
  151. UserBill::income('预约卷增加',$me['uid'], 'anticipate', 'add_anticipate', $data['anticipate'], 0, $me['anticipate'], $me['nickname'].'转账'.$data['anticipate'].'预约卷');
  152. $user->save();
  153. $me->save();
  154. Db::commit();
  155. return app('json')->successful('成功');
  156. } catch (\Exception $e) {
  157. Db::rollback();
  158. return app('json')->fail('失败');
  159. }
  160. }
  161. /**
  162. * 会馆
  163. * @param Request $request
  164. * @return mixed
  165. * @throws \think\db\exception\DataNotFoundException
  166. * @throws \think\db\exception\DbException
  167. * @throws \think\db\exception\ModelNotFoundException
  168. */
  169. public function auction_gu(Request $request)
  170. {
  171. $data = UtilService::getMore([
  172. [['page', 'd'], 0],
  173. [['limit', 'd'], 0],
  174. ], $request);
  175. $uid = getParent($request->uid());
  176. $uid[] = $request->uid();
  177. $list = AuctionGu::where('a.uid', 'in', $uid)
  178. ->alias('a')
  179. ->field('a.*,u.nickname,u.avatar')
  180. ->leftJoin('user u', 'a.uid = u.uid')
  181. ->page($data['page'], $data['limit'])
  182. ->select();
  183. $list = count($list) ? $list->toArray() : [];
  184. return app('json')->successful($list);
  185. }
  186. /**
  187. * 用户管理会馆
  188. * @param Request $request
  189. * @return mixed
  190. */
  191. public function user_gu(Request $request)
  192. {
  193. $data = UtilService::getMore([
  194. [['page', 'd'], 0],
  195. [['limit', 'd'], 0],
  196. ], $request);
  197. $list = AuctionGu::where('uid', $request->uid())->page($data['page'], $data['limit'])->select();
  198. $list = count($list) ? $list->toArray() : [];
  199. return app('json')->successful($list);
  200. }
  201. /**
  202. * 添加收款方式
  203. * @param Request $request
  204. * @return void
  205. */
  206. public function pay(Request $request)
  207. {
  208. $data = UtilService::postMore([
  209. ['payment'],
  210. ['image'],
  211. ['bank'],
  212. ['name'],
  213. ['type']
  214. ], $request);
  215. if (!$data['type']) return app('json')->fail('数据传入错误');
  216. $data['uid'] =$request->uid();
  217. $model = new AuctionPay();
  218. $pay = $model->where([['uid', '=', $request->uid()], ['type', '=', $data['type']]])->find();
  219. if (!empty($pay)){
  220. if ($data['type'] == 1 ){
  221. // 微信收款方式
  222. if (!$data['payment']) return app('json')->fail('微信账号不能为空');
  223. if (!$data['image']) return app('json')->fail('二维码不能为空');
  224. if (!$data['name']) return app('json')->fail('姓名不能为空');
  225. $pay['payment'] = $data['payment'];
  226. $pay['image'] = $data['image'];
  227. $pay['name'] = $data['name'];
  228. }elseif ($data['type'] == 2){
  229. // 支付宝收款方式
  230. if (!$data['payment']) return app('json')->fail('支付宝账号不能为空');
  231. if (!$data['name']) return app('json')->fail('姓名不能为空');
  232. $pay['payment'] = $data['payment'];
  233. $pay['name'] = $data['name'];
  234. }elseif ($data['type'] == 3){
  235. // 银行卡收款方式
  236. if (!$data['payment']) return app('json')->fail('银行卡号不能为空');
  237. if (!$data['name']) return app('json')->fail('姓名不能为空');
  238. if (!$data['bank']) return app('json')->fail('开户行');
  239. $pay['payment'] = $data['payment'];
  240. $pay['image'] = $data['image'];
  241. $pay['bank'] = $data['name'];
  242. }
  243. $res = $pay->save();
  244. if ($res) return app('json')->successful('修改成功');
  245. return app('json')->fail('修改失败');
  246. }else{
  247. if ($data['type'] == 1 ){
  248. // 微信收款方式
  249. if (!$data['payment']) return app('json')->fail('微信账号不能为空');
  250. if (!$data['image']) return app('json')->fail('二维码不能为空');
  251. if (!$data['name']) return app('json')->fail('姓名不能为空');
  252. }elseif ($data['type'] == 2){
  253. // 支付宝收款方式
  254. if (!$data['payment']) return app('json')->fail('支付宝账号不能为空');
  255. if (!$data['name']) return app('json')->fail('姓名不能为空');
  256. }elseif ($data['type'] == 3){
  257. // 银行卡收款方式
  258. if (!$data['payment']) return app('json')->fail('银行卡号不能为空');
  259. if (!$data['name']) return app('json')->fail('姓名不能为空');
  260. if (!$data['bank']) return app('json')->fail('开户行不能为空');
  261. }
  262. $res = $model->save($data);
  263. if ($res) return app('json')->successful('添加成功');
  264. return app('json')->fail('添加失败');
  265. }
  266. }
  267. public function pay_list(Request $request)
  268. {
  269. $model = new AuctionPay();
  270. $list = $model->where('uid', $request->uid())->select();
  271. $list = empty($list)? []: $list->toArray();
  272. $data = [];
  273. foreach ($list as $k => $v){
  274. if ($v['type'] == 1){
  275. $data['wx'] = $v;
  276. }elseif ($v['type'] == 2){
  277. $data['zfb'] = $v;
  278. }elseif ($v['type'] == 3){
  279. $data['bank'] = $v;
  280. }
  281. }
  282. return app('json')->successful($data);
  283. }
  284. }