SoccerNoteListController.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Jonlin
  5. * Date: 2019/4/9
  6. * Time: 9:11
  7. */
  8. namespace App\Http\Controllers\Admin;
  9. use App\Http\Controllers\Controller;
  10. use Illuminate\Http\Request as Req;
  11. use Illuminate\Support\Facades\DB;
  12. Use App\Lib\Settlement\SettlementOrder;
  13. Use App\Lib\Settlement\SettlementWinFail;
  14. use App\Models;
  15. use Request;
  16. /**
  17. *
  18. */
  19. class SoccerNoteListController extends Controller
  20. {
  21. public function notelist(Req $req)
  22. {
  23. $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
  24. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  25. $request['account'] = isset($req->account) ? trim($req->account) :null ;
  26. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) :null ;
  27. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) :null ;
  28. $request['order_id'] = isset($req->order_id) ? trim($req->order_id) :null ;
  29. $request['match_id'] = isset($req->match_id) ? trim($req->match_id) :null ;
  30. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  31. $request['order_status'] = isset($req->order_status) ? trim($req->order_status) : '-1';
  32. $request['type'] = isset($req->type) ? trim($req->type) : 'zq';
  33. $dt = \App\Lib\DataTable\DataTable::init();
  34. $dt->setDataSource('/admin/SoccerNoteList/getinfo');
  35. $dt->setLang('sportsnotelist');
  36. //$dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  37. $dt->addColsFields('match_id_order', array('sort' => true, 'width' => 200));
  38. $dt->addColsFields('league', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  39. $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  40. $dt->addColsFields('content', array('templet' => '#userdetail', 'sort' => false, 'width' => 250));
  41. $dt->addColsFields('money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  42. $dt->addColsFields('water_return', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  43. $dt->addColsFields('prize_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  44. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  45. $dt->addColsFields('money_match_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  46. $dt->addColsFields('order_status', array('sort' => false, 'width' => 80));
  47. $dt->addColsFields('account_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 110));
  48. $dt->addColsFields('game_status', array('templet' => '#game_status','sort' => false, 'width' =>90));
  49. //$arr[] = 'view';
  50. // if (checkRriv('/admin/SoccerNoteList/edit')) {
  51. // $arr[] = 'edit';
  52. // }
  53. // $dt->setToolBar($arr, array('width' => 70));
  54. $dt->enableCheckBox();//var_dump($request['type']);
  55. return view('sports/sports_notelist', $dt->render($request));
  56. }
  57. function info()
  58. {
  59. $page = Request::has('page') ? Request::get('page') : '';
  60. $list = Request::has('limit') ? Request::get('limit') : 10;
  61. $account = Request::get('account') ? Request::get('account') : '';
  62. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  63. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  64. $order_id = Request::get('order_id') ? Request::get('order_id') : '';
  65. $match_id = Request::get('match_id') ? Request::get('match_id') : '';
  66. $status = Request::has('status') ? Request::get('status') : '';
  67. $order_status = Request::has('order_status') ? Request::get('order_status') : '';
  68. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  69. $type = Request::has('type') ? Request::get('type') : 'zq';
  70. $where = array();
  71. if (!empty($account)) {
  72. if (empty($sureblur) || $sureblur == 'off') {
  73. $where[] = array('money_buy_simplex.account_name', 'like', '%' . $account . '%');
  74. } else {
  75. $where[] = array('money_buy_simplex.account_name', '=', $account);
  76. }
  77. }
  78. if (!empty($star_time)) {
  79. if (!empty($end_time)){
  80. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  81. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  82. }else{
  83. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  84. }
  85. }else if(empty($star_time)){
  86. if (!empty($end_time)){
  87. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  88. }
  89. }
  90. if (!empty($order_id)){
  91. $where[] = array('money_buy_simplex.order_id', $order_id);
  92. }
  93. if (!empty($match_id)){
  94. $where[] = array('money_buy_simplex.match_id', $match_id);
  95. }
  96. if ($status != -1) {
  97. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  98. }
  99. if ($order_status != -1) {
  100. $where[] = array('money_buy_simplex.status', '=', $order_status);
  101. }
  102. $where[] = array('money_buy_simplex.game_code', $type);
  103. $newapp = new \App\Models\SportsNoteList();
  104. $data = $newapp->getinfo($list, $page, $where,$type);
  105. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total'], 0, $where);
  106. }
  107. public function search(Req $req)
  108. {
  109. $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
  110. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  111. $request['account'] = isset($req->account) ? trim($req->account) :null ;
  112. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) :null ;
  113. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) :null ;
  114. $request['order_id'] = isset($req->order_id) ? trim($req->order_id) :null ;
  115. $request['match_id'] = isset($req->match_id) ? trim($req->match_id) :null ;
  116. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  117. $request['order_status'] = isset($req->order_status) ? trim($req->order_status) : '-1';
  118. $request['type'] = isset($req->type) ? trim($req->type) : 'zq';
  119. $dt = \App\Lib\DataTable\DataTable::init();
  120. $dt->setDataSource('/admin/SoccerNoteList/info');
  121. $dt->setLang('sportsnotelist');
  122. //$dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  123. $dt->addColsFields('match_id_order', array('sort' => true, 'width' => 200));
  124. $dt->addColsFields('league', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  125. $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  126. $dt->addColsFields('content', array('templet' => '#userdetail', 'sort' => false, 'width' => 250));
  127. $dt->addColsFields('money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  128. $dt->addColsFields('water_return', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  129. $dt->addColsFields('prize_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  130. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  131. $dt->addColsFields('money_match_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  132. $dt->addColsFields('order_status', array('sort' => false, 'width' => 80));
  133. $dt->addColsFields('account_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 110));
  134. $dt->addColsFields('game_status', array('sort' => false, 'width' =>90));
  135. //$arr[] = 'view';
  136. // if (checkRriv('/admin/SoccerNoteList/edit')) {
  137. // $arr[] = 'edit';
  138. // }
  139. // $dt->setToolBar($arr, array('width' => 70));
  140. $dt->enableCheckBox();
  141. return view('sports/sports_search', $dt->render($request));
  142. }
  143. //查询赛事结果
  144. function Sairesult(Req $req){
  145. $did = $req->did;
  146. $qlgame = $req->qlgame?$req->qlgame:'zq';
  147. $newapp = \App\Models\SportsNoteList::where('id', $did)->first();
  148. if($qlgame=='zq'){
  149. if($newapp['match_id']){
  150. $newre = new \App\Models\Stzqresult();
  151. $teamname = $newre->matchjg($newapp['match_id']);
  152. }else{
  153. $teamname ='';
  154. }
  155. }elseif($qlgame=='lq'){
  156. if($newapp['match_id']){
  157. $newre = new \App\Models\Stlqresult();
  158. $teamname = $newre->matchjg($newapp['match_id']);
  159. }else{
  160. $teamname ='';
  161. }
  162. }elseif($qlgame=='bq'){
  163. if($newapp['match_id']){
  164. $newre = new \App\Models\Stbqresult();
  165. $teamname = $newre->matchjg($newapp['match_id']);
  166. }else{
  167. $teamname ='';
  168. }
  169. }elseif($qlgame=='wq'){
  170. if($newapp['match_id']){
  171. $newre = new \App\Models\Stwqresult();
  172. $teamname = $newre->matchjg($newapp['match_id']);
  173. }else{
  174. $teamname ='';
  175. }
  176. }else{
  177. $data = "参数错误";
  178. }
  179. $data =array(
  180. 'singleresult' => json_decode($newapp['single_result'],true),
  181. 'teamname' => $teamname,
  182. );
  183. return $data;
  184. }
  185. //结果添加
  186. function addend(Req $req){
  187. $did = $req->did;
  188. $model = \App\Models\SportsNoteList::where('id', $did)->first();
  189. $single_result = array(
  190. 'home_team' => $req->home_team?$req->home_team:0,//主队
  191. 'guest_team' => $req->guest_team?$req->guest_team:0,//客队
  192. 'home_score' => $req->home_score?$req->home_score:0,//主队进球
  193. 'guest_score' => $req->guest_score?$req->guest_score:0,//客队进球
  194. 'all_goal' => $req->all_goal?$req->all_goal:0,//总进球
  195. 'first_score' => $req->firstscore?$req->firstscore:0,//最先进球球队
  196. 'last_score' => $req->lastscore?$req->lastscore:0,//最后进球球队
  197. 'match_winer' => $req->matchwiner?$req->matchwiner:0,//赢球球队
  198. 'update_time' => time(),//更新时间
  199. 'match_id' => $req->match_id?$req->match_id:0,
  200. 'u_guest_score' => $req->u_guest_score?$req->u_guest_score:0,//上半场-主队进球数
  201. 'u_home_score' => $req->u_home_score?$req->u_home_score:0,//上半场-客队进球数
  202. 'penaltycard' => array(
  203. 'home'=>intval($req->homeallcard)?intval($req->homeallcard):0,
  204. 'guest'=>intval($req->guestallcard)?intval($req->guestallcard):0,
  205. 'home_half'=>intval($req->homehalfcard)?intval($req->homehalfcard):0,
  206. 'guest_half'=>intval($req->guesthalfcard)?intval($req->guesthalfcard):0,
  207. ),
  208. 'cornerball' => array(
  209. 'home'=>intval($req->homeallcorner)?intval($req->homeallcorner):0,
  210. 'guest'=>intval($req->guestallcorner)?intval($req->guestallcorner):0,
  211. 'home_half'=>intval($req->homehalfcorner)?intval($req->homehalfcorner):0,
  212. 'guest_half'=>intval($req->guesthalfcorner)?intval($req->guesthalfcorner):0,
  213. ),
  214. );
  215. $model->single_result = json_encode([$single_result]);
  216. $model->result_flag = 1;
  217. $model->save();
  218. return responseToJson(1);
  219. }
  220. function getinfo()
  221. {
  222. $page = Request::has('page') ? Request::get('page') : '';
  223. $list = Request::has('limit') ? Request::get('limit') : 10;
  224. $account = Request::get('account') ? Request::get('account') : '';
  225. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  226. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  227. $order_id = Request::get('order_id') ? Request::get('order_id') : '';
  228. $match_id = Request::get('match_id') ? Request::get('match_id') : '';
  229. $status = Request::has('status') ? Request::get('status') : '-1';
  230. $order_status = Request::has('order_status') ? Request::get('order_status') : '';
  231. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  232. $type = Request::has('type') ? Request::get('type') : 'zq';
  233. $where = array();
  234. if (!empty($account)) {
  235. if (empty($sureblur) || $sureblur == 'off') {
  236. $where[] = array('money_buy_simplex.account_name', 'like', '%' . $account . '%');
  237. } else {
  238. $where[] = array('money_buy_simplex.account_name', '=', $account);
  239. }
  240. }
  241. if (!empty($star_time)) {
  242. if (!empty($end_time)){
  243. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  244. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  245. }else{
  246. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  247. }
  248. }else if(empty($star_time)){
  249. if (!empty($end_time)){
  250. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  251. }
  252. }
  253. if (!empty($order_id)){
  254. $where[] = array('money_buy_simplex.order_id', $order_id);
  255. }
  256. if (!empty($match_id)){
  257. $where[] = array('money_buy_simplex.match_id', $match_id);
  258. }
  259. if ($status != -1) {
  260. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  261. }
  262. if ($order_status != -1) {
  263. $where[] = array('money_buy_simplex.status', '=', $order_status);
  264. }
  265. $where[] = array('money_buy_simplex.game_code', $type);
  266. $newapp = new \App\Models\SportsNoteList();
  267. $data = $newapp->info($list, $page, $where,$type);
  268. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total'], 0, $where);
  269. }
  270. /**
  271. *单式注单作废
  272. */
  273. public function invalid(Req $req)
  274. {
  275. $id = $req->id;
  276. if (intval($id) < 1) {
  277. return -1;
  278. }
  279. $order = \App\Models\SportsNoteList::where('id',$id)->first();
  280. //用戶账户金额
  281. $account_money = \App\Models\Account_detailed::where('account_identity',$order->account_identity)->first();
  282. //反水
  283. $water_return_money = \App\Models\Money_details::where('trade_id',$order->order_id)->where('trade_type','7')->first();
  284. if(!empty($water_return_money)){
  285. $water_return = $water_return_money->money;
  286. }else{
  287. $water_return = 0;
  288. }
  289. //撤单后用户账户金额
  290. $available_cash = $account_money->available_cash;
  291. $new_available_cash = $available_cash+$order->money-$order->gain_money-$water_return;
  292. $model =new \App\Models\Money_details();
  293. $model->info_identity = UUID();
  294. $model->trade_id = $order->order_id;
  295. $model->account_name = $order->account_name;
  296. $model->account_identity = $order->account_identity;
  297. $model->money = abs($order->money-$order->gain_money-$water_return);
  298. $model->money_time = date("Y-m-d H:i:s",time());
  299. if($new_available_cash>$available_cash){
  300. $model->money_type = '1';
  301. }else{
  302. $model->money_type = '2';
  303. }
  304. $model->money_cash = $new_available_cash;
  305. $model->trade_type = '3';
  306. $model->trade_desc = '管理员作废单式注单';
  307. $model->status = '1';
  308. try {
  309. DB::beginTransaction();//开启事务
  310. \App\Models\SportsNoteList::where('id',$id)->update(['status'=>'2'],['gain_money'=>'0']);
  311. \App\Models\Account_detailed::where('account_identity',$order->account_identity)->update(['available_cash'=>$new_available_cash,'cash'=>$new_available_cash]);
  312. $model->save();
  313. DB::commit();//提交
  314. return 1;
  315. } catch (Exception $e) {
  316. DB::rollback();//回滚
  317. return -1;
  318. }
  319. }
  320. /**
  321. *单式注单首次结算
  322. */
  323. public function settlement(Req $req)
  324. {
  325. $id = $req->id;
  326. if (intval($id) < 1) {
  327. return -1;
  328. }
  329. $order = \App\Models\SportsNoteList::where('id', $id)->first();
  330. $order_id = $order->order_id;
  331. $order_ids = array($order->order_id);
  332. $match_id = $order->match_id;
  333. $game_code = $order->game_code;
  334. $bet_type = 1;//单式注单
  335. //return $match_id;
  336. //判断输赢
  337. $settlementWinFail = new SettlementWinFail();
  338. $res = $settlementWinFail->ProcWinInfoByOneOrder($match_id, $order_id, $bet_type);
  339. //结算
  340. $SettlementOrder = new SettlementOrder();
  341. $settype = 1; //首次结算
  342. $data = $SettlementOrder->reSettlement($order_ids,$bet_type,$settype,$game_code,$match_id,$match_status=0);
  343. return $data;
  344. }
  345. /**
  346. *单式注单重新结算
  347. */
  348. public function resettlement(Req $req) {
  349. $id = $req->id;
  350. if (intval($id) < 1) {
  351. return -1;
  352. }
  353. $order = \App\Models\SportsNoteList::where('id',$id)->first();
  354. $match_id = $order->match_id;
  355. $game_code = $order->game_code;
  356. $order_id = $order->order_id;
  357. $order_ids = array($order->order_id);
  358. //return $match_id;
  359. $bet_type = 1;//单式注单
  360. //重新判断输赢
  361. $settlementWinFail = new SettlementWinFail();
  362. $res = $settlementWinFail->ProcWinInfoByOneOrder($match_id, $order_id, $bet_type);
  363. //结算
  364. $SettlementOrder = new SettlementOrder();
  365. $settype = 2; //重新结算
  366. $data = $SettlementOrder->reSettlement($order_ids,$bet_type,$settype,$game_code,$match_id,$match_status=0);
  367. return $data;
  368. }
  369. /**
  370. *单式注单批量结算
  371. */
  372. public function batchsettlement(){
  373. $orders = \App\Models\SportsNoteList::where('settle_status','1')->get();
  374. $order_ids = array();
  375. for($i=0;$i<count($orders);$i++){
  376. $result = \App\Models\MoneyBuyMatch::where('batch_id',$orders[$i]->batch_id)->where('match_id',$orders[$i]->match_id)->get();
  377. $res = array();
  378. for($j=0;$j<count($result);$j++){
  379. $res[] = $result[$j]->result;
  380. }
  381. if(!in_array(0,$res)){
  382. $order_ids[] = $orders[$i]->order_id;
  383. }
  384. }
  385. $SettlementOrder = new SettlementOrder();
  386. $bet_type = 1;//单式注单
  387. $data = $SettlementOrder->reSettlement($order_ids,$bet_type);
  388. return $data;
  389. }
  390. /**
  391. *删除订单
  392. */
  393. public function delete(Req $req) {
  394. $id = $req->input('id');
  395. if (empty($id)) {
  396. return responseToJson(-2001); //id������
  397. }
  398. $ids = explode(',', $id);
  399. if (!is_array($ids) && intval($ids) < 0) {
  400. return responseToJson(-2002); //id����
  401. }
  402. if (is_array($ids) && count($ids) > 0) {
  403. foreach ($ids as $k => $v) {
  404. if (intval($v) < 1) {
  405. unset($ids[$k]);
  406. }
  407. }
  408. }
  409. $rows = \App\Models\SportsNoteList::whereIn('id', $ids)->delete();
  410. if (!$rows) {
  411. return responseToJson(-2003); //id����
  412. }
  413. return responseToJson(1, trans('menu.delete_success')); //id����
  414. }
  415. /**
  416. * 投注金额统计
  417. */
  418. function moneycount()
  419. {
  420. $where = Request::has('where') ? Request::get('where') : '';
  421. $type = Request::has('type') ? Request::get('type') : 'zq';
  422. $db = new \App\Models\SportsNoteList;
  423. $data = $db->MoneyCount($where,$type);
  424. return responseToJson($data);
  425. }
  426. }