SportsbqController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request as Req;
  5. use Illuminate\Support\Facades\DB;
  6. use App\Models;
  7. use Request;
  8. /**
  9. *棒球结果结算
  10. */
  11. class SportsbqController extends Controller {
  12. //棒球结果列表
  13. function outcome(Req $req) {
  14. $request=array();
  15. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  16. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  17. $request['home_team'] = isset($req->home_team) ? trim($req->home_team) : null;
  18. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) :trans('status.default_time.seven_day') ;
  19. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : trans('status.default_time.etime');
  20. $dt = \App\Lib\DataTable\DataTable::init();
  21. $dt->setDataSource('/admin/Sportsbq/info');
  22. $dt->setLang('Sportsbq');
  23. $dt->addColsFields('newtime', array('templet' => '#newtime', 'sort' => false, 'width' => 200));
  24. $dt->addColsFields('totime', array('templet' => '#totime', 'sort' => false, 'width' => 200));
  25. $dt->addColsFields('home_team', array('templet' => '#home_team', 'sort' => false, 'width' => 80));
  26. $dt->addColsFields('guest_team', array('templet' => '#guest_team', 'sort' => false, 'width' => 80));
  27. $dt->addColsFields('dsnum', array('templet' => '#dsnum', 'sort' => false, 'width' => 80));
  28. $dt->addColsFields('csnum', array('templet' => '#home_rate', 'sort' => false, 'width' => 80));
  29. $dt->addColsFields('match_score', array('templet' => '#match_score', 'sort' => false, 'width' => 200));
  30. $dt->addColsFields('statusmatch', array('templet' => '#statusmatch', 'sort' => false, 'width' => 80));
  31. $dt->addColsFields('operation', array('templet' => '#operation', 'sort' => false, 'width' => 300));
  32. return view('admin.Sportsbq/outcome', $dt->render($request));
  33. }
  34. function info(){
  35. $page = Request::has('page') ? Request::get('page') : '';
  36. $list = Request::has('limit') ? Request::get('limit') : 10;
  37. $home_team = Request::has('home_team') ? Request::get('home_team') : '';
  38. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  39. $status = Request::has('status') ? Request::get('status') : '';
  40. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  41. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  42. $where = array();
  43. $orwhere = array();
  44. if (!empty($home_team)) {
  45. if (empty($sureblur) || $sureblur == 'off') {
  46. $where[] = array('st_bq_result.home_team', 'like', '%' . $home_team . '%');
  47. $orwhere[] = array('st_bq_result.guest_team', 'like', '%' . $home_team . '%');
  48. } else {
  49. $where[] = array('st_bq_result.home_team', '=', $home_team);
  50. $orwhere[] = array('st_bq_result.guest_team', '=', $home_team);
  51. }
  52. }
  53. if ($status != -1) {
  54. $where[] = array('st_bq_result.status', '=', $status);
  55. $orwhere[] = array('st_bq_result.status', '=', $status);
  56. }
  57. if (!empty($star_time)) {
  58. $star_time = date('Y-m-d H:i:s', strtotime($star_time));
  59. $where[] = array('st_bq_result.start_time', '>', $star_time);
  60. $orwhere[] = array('st_bq_result.start_time', '>', $star_time);
  61. }
  62. if (!empty($end_time)) {
  63. $end_time = date('Y-m-d H:i:s', strtotime($end_time));
  64. $where[] = array('st_bq_result.start_time', '<', $end_time);
  65. $orwhere[] = array('st_bq_result.start_time', '<', $end_time);
  66. }
  67. $newapp = new \App\Models\Stbqresult();
  68. $data = $newapp->getinfo($list, $page, $where,$orwhere);
  69. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  70. }
  71. //作废
  72. function revoke(Req $req){
  73. $match_id = $req->match_id;//赛事id
  74. $model = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  75. $model->status = 4;
  76. $model->save();
  77. $smodel = \App\Models\SportsSoccer::where('match_id', $match_id)->first();
  78. if($smodel){
  79. $smodel->status = 4;
  80. $smodel->save();
  81. }
  82. $upapp = new \App\Models\SportsNoteList();
  83. $data = $upapp->updatesimplex($match_id,'bq');//修改单式状态
  84. //单式撤单返现
  85. $newapp = new \App\Models\MoneyBuyMatch();
  86. $all = $newapp->allsimplexorder($match_id,'bq');
  87. for ($i=0; $i < count($all); $i++) {
  88. $appgx = new \App\Lib\Settlement\SettlementOrder();
  89. $appgx->insertData($all[$i]['order_id'], $all[$i]['money'], $all[$i]['account_identity'], '1', 'bq', $all[$i]['info_identity'], $all[$i]['money'],$all[$i]['match_id']);
  90. }
  91. //串式撤单只改状态
  92. $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  93. $csapp = new \App\Models\MoneyBuyStr();
  94. $csapp->updatestatus($str_ids);//var_dump($ss);die;
  95. //修改money_buy_match 投注结果result=2为平
  96. $newapp->updatast($match_id);
  97. return responseToJson(1);
  98. }
  99. //结算
  100. // function Settlement(Req $req){
  101. // //查询赛事下所有订单
  102. // $ssid = $req->match_id;//赛事id
  103. // $type = $req->type;//是否再结算1,首次结算2,再次结算
  104. // $newapp = new \App\Models\MoneyBuyMatch();
  105. // $simplex_ids = array_column($newapp->allsimplexorder($ssid,'bq'),'order_id');
  106. // $str_ids = array_column($newapp->allstrorder($ssid),'order_id');
  107. // $update = $this->addcomendnotice($ssid);
  108. // if($update['status']==1){
  109. // $SettlementOrder = new SettlementOrder();
  110. // $SettlementOrder->reSettlement($str_ids, 2,$type,'bq',$ssid);//串式
  111. // $data = $SettlementOrder->reSettlement($simplex_ids, 1,$type,'bq',$ssid);//单式注单
  112. // return responseToJson($data);
  113. // }else{
  114. // return responseToJson($update);
  115. // }
  116. // }
  117. function Settlement(Req $req){
  118. $jsurl = config('sconstant.url');//结算请求域名地址
  119. $match_id = $req->match_id;
  120. $type = $req->type;
  121. $token = session('adminInfo.token');
  122. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  123. $noticeid = $notice['id'];
  124. //查询赛事单式是否有订单(篮球)
  125. $newapp = new \App\Models\MoneyBuyMatch();
  126. $simplex_ids = array_column($newapp->allsimplexorder($match_id,'bq'),'order_id');
  127. $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  128. if(count($simplex_ids)>0 || count($str_ids)>0){
  129. $requet = file_get_contents($jsurl."/WinFail?noticeid=".$noticeid."&token=".$token);
  130. if(json_decode($requet,true)['status']==1){
  131. $napp = new \App\Models\Stzqresult();
  132. //单式结算
  133. if($simplex_ids){
  134. $simplex = array(
  135. 'token'=>$token,
  136. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  137. 'bettype'=>1, //结算类型 1单式 2串式
  138. 'settype'=>2, //结算次数 1首次 2非首冷饮
  139. 'game_code'=>'bq', //赛事类型 zq lq wq bq
  140. 'match_id'=>$match_id, // 赛事ID
  141. 'change_status'=>1 //是否改状态
  142. );
  143. $url=$jsurl.'/Settelement';
  144. $simplex_res = $napp->post_curls($url,$simplex);//返回json
  145. $huawei_res = json_decode($simplex_res,true);
  146. }
  147. //串式结算
  148. if($str_ids){
  149. $tandem = array(
  150. 'token'=>$token,
  151. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  152. 'bettype'=>2, //结算类型 1单式 2串式
  153. 'settype'=>2, //结算次数 1首次 2非首冷饮
  154. 'game_code'=>'bq', //赛事类型 zq lq wq bq
  155. 'match_id'=>$match_id, // 赛事ID
  156. 'change_status'=>1 //是否改状态
  157. );
  158. $url=$jsurl.'/Settelement';
  159. $tandem_res = $napp->post_curls($url,$tandem);//返回json
  160. $tandem_res = json_decode($tandem_res,true);
  161. }
  162. if($huawei_res['status']==1 || $tandem_res['status']==1){
  163. return json_encode(['status'=>1,'msg'=>'结算成功']);
  164. }else{
  165. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!']);//结算错误
  166. }
  167. }else{
  168. return json_encode(['status'=>2,'msg'=>'结算有错,请联系管理员!!!']);;//输赢错误
  169. }
  170. }else{
  171. $res = \App\Models\Stbqresult::where ('match_id', $match_id)->update(['status' =>3]);
  172. $res = \App\Models\SportsBase::where ('match_id', $match_id)->update(['status' =>3]);
  173. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  174. }
  175. }
  176. //查询赛事结果
  177. function Matchresult(Req $req){
  178. $match_id = $req->match_id;
  179. $newapp = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  180. $array =array(
  181. // 'corner_ball' => json_decode($newapp['corner_ball'],true),
  182. // 'penalty_card' => json_decode($newapp['penalty_card'],true),
  183. 'bqresult' => $newapp,
  184. );
  185. return $array;
  186. }
  187. function onlyresult(Req $req){
  188. $match_id = $req->matchid;
  189. $newapp = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  190. return $newapp;
  191. }
  192. //结果添加
  193. function addend(Req $req){
  194. $match_id = $req->matchid;
  195. $model = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  196. $model->first_score = $req->firstscoreplayer?$req->firstscoreplayer:0;
  197. $model->last_score = $req->lastscoreplayer?$req->lastscoreplayer:0;
  198. $model->match_winer = $req->matchwinerplayer?$req->matchwinerplayer:0;
  199. $model->save();
  200. return responseToJson(1);
  201. }
  202. //更新赛事比分
  203. function updatascore(Req $req){
  204. $only = $req->only;
  205. $num = $req->num;
  206. $match_id = $req->match_id;
  207. $newapp = new \App\Models\Stbqresult();
  208. // $data = array();
  209. // $data['update_time'] = data('Y-m-d H:i:s');//更新时间
  210. if($only==1){
  211. $data['u_home_score'] = $num;
  212. $res = $newapp->updateInfo($data,$match_id);//联赛id
  213. }else if($only==2){
  214. $data['u_guest_score'] = $num;
  215. $res = $newapp->updateInfo($data,$match_id);//联赛id
  216. }else if($only==3){
  217. $data['home_score'] = $num;
  218. $res = $newapp->updateInfo($data,$match_id);//联赛id
  219. }else{
  220. $data['guest_score'] = $num;
  221. $res = $newapp->updateInfo($data,$match_id);//联赛id
  222. }
  223. $addnew = new \App\Models\Comendnotice();
  224. $addnew->addcomendnotice($match_id,'bq');
  225. $twoapp = new \App\Models\SportsBase();
  226. $twoapp->updatestatus('match_id',$match_id,['status'=>2]);//修改赛事状态
  227. $newapp->updatestatus('match_id',$match_id,['status'=>2]);//修改结果状态
  228. return responseToJson(1);
  229. }
  230. }