SportsbqController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. use App\Lib\Biz\Sport\Common as commonFunction;
  9. /**
  10. *棒球结果结算
  11. */
  12. class SportsbqController extends Controller {
  13. //棒球结果列表
  14. function outcome(Req $req) {
  15. $request=array();
  16. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  17. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  18. $request['home_team'] = isset($req->home_team) ? trim($req->home_team) : null;
  19. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) :trans('status.default_time.seven_day') ;
  20. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : trans('status.default_time.etime');
  21. $dt = \App\Lib\DataTable\DataTable::init();
  22. $dt->setDataSource('/admin/Sportsbq/info');
  23. $dt->setLang('Sportsbq');
  24. $dt->addColsFields('newtime', array('templet' => '#newtime', 'sort' => false, 'width' => 200));
  25. $dt->addColsFields('totime', array('templet' => '#totime', 'sort' => false, 'width' => 200));
  26. $dt->addColsFields('home_team', array('templet' => '#home_team', 'sort' => false, 'width' => 80));
  27. $dt->addColsFields('guest_team', array('templet' => '#guest_team', 'sort' => false, 'width' => 80));
  28. $dt->addColsFields('dsnum', array('templet' => '#dsnum', 'sort' => false, 'width' => 80));
  29. // $dt->addColsFields('csnum', array('templet' => '#home_rate', 'sort' => false, 'width' => 80));
  30. $dt->addColsFields('csnum', array('templet' => '#csnum', 'sort' => false, 'width' => 110));
  31. $dt->addColsFields('match_score', array( 'templet' => '#match_score','sort' => false, 'width' => 220));//
  32. $dt->addColsFields('statusmatch', array('templet' => '#statusmatch', 'sort' => false, 'width' => 80));
  33. $dt->addColsFields('operation', array('templet' => '#operation', 'sort' => false, 'width' => 300));
  34. $dt->enableCheckBox();
  35. return view('admin.Sportsbq/outcome', $dt->render($request));
  36. }
  37. function info(){
  38. $page = Request::has('page') ? Request::get('page') : '';
  39. $list = Request::has('limit') ? Request::get('limit') : 10;
  40. $home_team = Request::has('home_team') ? Request::get('home_team') : '';
  41. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  42. $status = Request::has('status') ? Request::get('status') : '';
  43. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  44. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  45. $where = array();
  46. $orwhere = array();
  47. if (!empty($home_team)) {
  48. if (empty($sureblur) || $sureblur == 'off') {
  49. $where[] = array('st_bq_result.home_team', 'like', '%' . $home_team . '%');
  50. $orwhere[] = array('st_bq_result.guest_team', 'like', '%' . $home_team . '%');
  51. } else {
  52. if(is_numeric($home_team)){
  53. $where[] = array('st_bq_result.match_id', '=', $home_team);
  54. $orwhere[] = array('st_bq_result.match_id', '=', $home_team);
  55. }else{
  56. $where[] = array('st_bq_result.home_team', '=', $home_team);
  57. $orwhere[] = array('st_bq_result.guest_team', '=', $home_team);
  58. }
  59. }
  60. }
  61. //
  62. if ($status != -1) {
  63. $where[] = array('st_bq_competition.status', '=', $status);
  64. $orwhere[] = array('st_bq_competition.status', '=', $status);
  65. }
  66. if (!empty($star_time) and empty($home_team)) {
  67. $star_time = date('Y-m-d H:i:s', strtotime($star_time));
  68. $where[] = array('st_bq_result.start_time', '>', $star_time);
  69. $orwhere[] = array('st_bq_result.start_time', '>', $star_time);
  70. }
  71. if (!empty($end_time) and empty($home_team)) {
  72. $end_time = date('Y-m-d H:i:s', strtotime($end_time));
  73. $where[] = array('st_bq_result.start_time', '<', $end_time);
  74. $orwhere[] = array('st_bq_result.start_time', '<', $end_time);
  75. }
  76. $newapp = new \App\Models\Stbqresult();
  77. $data = $newapp->getinfo($list, $page, $where,$orwhere);
  78. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  79. }
  80. //作废
  81. function revoke(Req $req){
  82. $match_id = $req->match_id;//赛事id
  83. $model = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  84. $model->status = 4;
  85. $model->save();
  86. $smodel = \App\Models\SportsBase::where('id', $match_id)->first();
  87. if($smodel){
  88. $smodel->status = 4;
  89. $smodel->save();
  90. }
  91. //赛事下单式注单作废,串关注单下此赛事按平局处理
  92. $upapp = new \App\Models\SportsNoteList();
  93. $upapp->delorder($match_id,'bq');
  94. // $upapp = new \App\Models\SportsNoteList();
  95. // $data = $upapp->updatesimplex($match_id,'bq');//修改单式状态
  96. //
  97. // //单式撤单返现
  98. // $newapp = new \App\Models\MoneyBuyMatch();
  99. // $all = $newapp->allsimplexorder($match_id,'bq');
  100. // for ($i=0; $i < count($all); $i++) {
  101. // $appgx = new \App\Lib\Settlement\SettlementOrder();
  102. // $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']);
  103. // }
  104. //
  105. // //串式撤单只改状态
  106. // $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  107. // $csapp = new \App\Models\MoneyBuyStr();
  108. // $csapp->updatestatus($str_ids);//var_dump($ss);die;
  109. // //修改money_buy_match 投注结果result=2为平
  110. // $newapp->updatast($match_id);
  111. return responseToJson(1);
  112. }
  113. //结算
  114. function Settlement(Req $req){
  115. $jsurl = config('sconstant.url');//结算请求域名地址
  116. $match_id = $req->match_id;
  117. $type = $req->type;
  118. $token = session('adminInfo.token');
  119. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  120. $noticeid = $notice['id'];
  121. if(!$notice){
  122. return json_encode(['status'=>5,'msg'=>'请先核对结果,并提交结果']);
  123. }
  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(count($simplex_ids)>0 && count($str_ids)==0){
  134. $huawei_res = $napp->simplexs($token,$match_id,$jsurl,'bq');
  135. if($huawei_res['status']==1){
  136. return json_encode(['status'=>1,'msg'=>'单式结算成功,没有串式订单']);
  137. }else{
  138. return json_encode(['status'=>3,'msg'=>'单式结算有误,请联系管理员!!!('.$huawei_res['msg'].')']);//结算错误
  139. }
  140. }elseif(count($str_ids)>0 && count($simplex_ids)==0){
  141. //串式结算
  142. $tandem_res = $napp->tandems($token,$match_id,$jsurl,'bq');
  143. if($tandem_res['status']==1){
  144. return json_encode(['status'=>1,'msg'=>'串式结算成功,没有单式订单']);
  145. }else{
  146. return json_encode(['status'=>3,'msg'=>'串式结算有误,请联系管理员!!!('.$tandem_res['msg'].')']);//结算错误
  147. }
  148. }elseif(count($str_ids)>0 && count($simplex_ids)>0){
  149. //既有单式又有串式
  150. $huawei_res = $napp->simplexs($token,$match_id,$jsurl,'bq');
  151. //串式结算
  152. $tandem_res = $napp->tandems($token,$match_id,$jsurl,'bq');
  153. if($tandem_res['status']==1 && $huawei_res['status']==1){
  154. return json_encode(['status'=>1,'msg'=>'结算成功']);
  155. }elseif($tandem_res['status']!=1 || $huawei_res['status']!=1){
  156. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!('.$tandem_res['msg'].$huawei_res['msg'].')']);
  157. }else{
  158. return json_encode(['status'=>3,'msg'=>'返回参数不对']);
  159. }
  160. }
  161. }else{
  162. return json_encode(['status'=>2,'msg'=>'判断输赢错误,请联系管理员!!!']);;//输赢错误
  163. }
  164. }else{
  165. $res = \App\Models\Stbqresult::where ('match_id', $match_id)->update(['status' =>3]);
  166. $res = \App\Models\SportsBase::where ('match_id', $match_id)->update(['status' =>3]);
  167. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  168. }
  169. }
  170. //查询赛事结果
  171. function Matchresult(Req $req){
  172. $match_id = $req->match_id;
  173. $newapp = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  174. $jieguo =array(
  175. 'bqresult' => json_decode($newapp['match_score_t'],true),
  176. );
  177. return $jieguo;
  178. }
  179. //查询赛事结果
  180. function resultLog(Req $req){
  181. $match_id = $req->match_id;
  182. $list = \App\Models\Stbqresultlog::leftJoin('system_user', 'user_id', '=', 'system_user.id')
  183. ->select('st_bq_result_log.*', 'system_user.loginname')->where('match_id', $match_id)->orderBy('id', 'asc')->get();
  184. foreach ($list as $key=>$value){
  185. $list[$key]['match_score_t'] = json_decode($value['match_score_t'], true);
  186. }
  187. $result =array(
  188. 'status' => 200,
  189. 'list' => $list
  190. );
  191. echo json_encode($result);die;
  192. }
  193. function onlyresult(Req $req){
  194. $match_id = $req->matchid;
  195. $newapp = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  196. return $newapp;
  197. }
  198. //结果添加
  199. function addend(Req $req){
  200. $match_id = $req->match_id;
  201. $model = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  202. $match = \App\Models\SportsBase::where('id', $match_id)->first();
  203. $match_status = $match['status'];
  204. $uscore = array(
  205. "1" => array(
  206. 'home' => intval($req->homea)?intval($req->homea):1,
  207. 'guest' => intval($req->guesta)?intval($req->guesta):0,
  208. ),
  209. "2" => array(
  210. 'home' => intval($req->homeb)?intval($req->homeb):0,
  211. 'guest' => intval($req->guestb)?intval($req->guestb):0,
  212. ),
  213. "3" => array(
  214. 'home' => intval($req->homec)?intval($req->homec):0,
  215. 'guest' => intval($req->guestc)?intval($req->guestc):0,
  216. ),
  217. "4" => array(
  218. 'home' => intval($req->homed)?intval($req->homed):0,
  219. 'guest' => intval($req->guestd)?intval($req->guestd):0,
  220. ),
  221. "5" => array(
  222. 'home' => intval($req->homee)?intval($req->homee):0,
  223. 'guest' => intval($req->gueste)?intval($req->gueste):0,
  224. ),
  225. "6" => array(
  226. 'home' => intval($req->homef)?intval($req->homef):0,
  227. 'guest' => intval($req->guestf)?intval($req->guestf):0,
  228. ),
  229. "7" => array(
  230. 'home' => intval($req->homeg)?intval($req->homeg):0,
  231. 'guest' => intval($req->guestg)?intval($req->guestg):0,
  232. ),
  233. "8" => array(
  234. 'home' => intval($req->homeh)?intval($req->homeh):0,
  235. 'guest' => intval($req->guesth)?intval($req->guesth):0,
  236. ),
  237. "9" => array(
  238. 'home' => intval($req->homei)?intval($req->homei):0,
  239. 'guest' => intval($req->guesti)?intval($req->guesti):0,
  240. ),
  241. "other" => array(
  242. 'home' => intval($req->homej)?intval($req->homej):0,
  243. 'guest' => intval($req->guestj)?intval($req->guestj):0,
  244. ),
  245. "five" => array(
  246. 'home' => intval($req->homek)?intval($req->homek):0,
  247. 'guest' => intval($req->guestk)?intval($req->guestk):0,
  248. ),
  249. "all" => array(
  250. 'home' => intval($req->homel)?intval($req->homel):0,
  251. 'guest' => intval($req->guestl)?intval($req->guestl):0,
  252. ),
  253. );
  254. foreach($uscore as $key){
  255. $data[] = $key['home'];
  256. $data[] = $key['guest'];
  257. }
  258. //赛事下注单作废 处理
  259. if(in_array(-1,$data)){
  260. commonFunction::HandleInvalid($uscore,$match_id,$match_status,'bq');
  261. }
  262. $updatainfo = [
  263. "home_score"=>$data['all']['home'],
  264. "guest_score"=>$data['all']['guest'],
  265. "match_score_t"=>json_encode($uscore),
  266. "match_score"=>$data['all']['home'].':'.$data['all']['guest'],
  267. "u_home_score"=>$data['five']['home'],
  268. "u_guest_score"=>$data['five']['guest'],
  269. 'is_correct'=>1,
  270. ];
  271. \App\Models\Stbqresult::where('match_id', $match_id)->update($updatainfo);
  272. $addnew = new \App\Models\Comendnotice();
  273. $addnew->addcomendnotice($match_id,'bq');
  274. $twoapp = new \App\Models\SportsBase();
  275. $twoapp->updatestatus('id',$match_id,['status'=>2,'utime'=>date('Y-m-d H:i:s')]);//修改赛事状态
  276. $newapp = new \App\Models\Stbqresult();
  277. $newapp->updatestatus('match_id',$match_id,['status'=>2,'update_time'=>date('Y-m-d H:i:s')]);//修改结果状态
  278. //添加赛事结果记录
  279. $lastLog = \App\Models\Stbqresultlog::where([
  280. ['match_id', $match_id],
  281. ['type', 1]
  282. ])->orderBy('id', 'desc')->first();
  283. if(empty($lastLog) || $lastLog['match_score_t'] != json_encode($uscore)){
  284. \App\Models\Stbqresultlog::insert([
  285. 'match_id' => $match_id,
  286. 'match_score_t' => json_encode($uscore),
  287. 'user_id' => session('adminInfo.admin_id'),
  288. 'type' => 1,
  289. 'create_at' => now()
  290. ]);
  291. }
  292. return responseToJson(1);
  293. }
  294. //更新赛事比分
  295. function updatascore(Req $req){
  296. $only = $req->only;
  297. $num = $req->num;
  298. $match_id = $req->match_id;
  299. $newapp = new \App\Models\Stbqresult();
  300. //赛事状态
  301. $match_status = intval($req->match_status)?intval($req->match_status):0;
  302. // $data['update_time'] = data('Y-m-d H:i:s');//更新时间
  303. $data['u_home_score'] = intval($req->u_home_score)?intval($req->u_home_score):0;
  304. $data['u_guest_score'] = intval($req->u_guest_score)?intval($req->u_guest_score):0;
  305. $data['guest_score'] = intval($req->guest_score)?intval($req->guest_score):0;
  306. $data['home_score'] = intval($req->home_score)?intval($req->home_score):0;
  307. $data['is_correct'] = 1;//追加手动更改标识
  308. //更新比分 默认 status
  309. $status = 2;
  310. //追加判断比分 如果都== -1,则作废该赛事
  311. if($data['u_home_score'] < 0 and $data['u_guest_score'] < 0 and $data['home_score'] < 0 and $data['guest_score'] < 0){
  312. //已结算作废赛事处理
  313. if($match_status == 3){
  314. $url = 'http://stadmin.bocai108.com:9094/UnSettelement';
  315. $data_up = [
  316. 'token'=>session('adminInfo.token'),
  317. 'game_code'=>'bq',
  318. 'match_id'=>$match_id,
  319. ];
  320. $ret_json = commonFunction::https_request($url,$data_up);
  321. // $ret_json = '{"status":1,"msg":"撤销成功!2019-10-26 16:28:30 取消赛事处理--结束end:game_code= zq match_id= 40986 \n","data":[]}';
  322. $ret_arr = json_decode($ret_json,true);
  323. if($ret_arr['status'] != 1){
  324. return responseToJson(-20003);
  325. }
  326. }
  327. //赛事下单式注单作废,串关注单下此赛事按平局处理
  328. $upapp = new \App\Models\SportsNoteList();
  329. $upapp->delorder($match_id,'bq');
  330. $status = 4;
  331. }
  332. $res = $newapp->updateInfo($data,$match_id);//联赛id
  333. $addnew = new \App\Models\Comendnotice();
  334. $addnew->addcomendnotice($match_id,'bq');
  335. $twoapp = new \App\Models\SportsBase();
  336. $twoapp->updatestatus('match_id',$match_id,['status'=>$status,'utime'=>date('Y-m-d H:i:s')]);//修改赛事状态
  337. $newapp->updatestatus('match_id',$match_id,['status'=>$status,'update_time'=>date('Y-m-d H:i:s')]);//修改结果状态
  338. //添加赛事结果比较记录
  339. $lastLog = \App\Models\Stbqresultlog::where([
  340. ['match_id', $match_id],
  341. ['type', 2]
  342. ])->orderBy('id', 'desc')->first();
  343. if(empty($lastLog) || !(
  344. $lastLog['u_home_score'] == $data['u_home_score']
  345. && $lastLog['u_guest_score'] == $data['u_guest_score']
  346. && $lastLog['guest_score'] == $data['guest_score']
  347. && $lastLog['home_score'] == $data['home_score']
  348. )){
  349. $logData = $data;
  350. $logData['type'] = 2;
  351. $logData['match_id'] = $match_id;
  352. $logData['user_id'] = session('adminInfo.admin_id');
  353. $logData['create_at'] = now();
  354. \App\Models\Stbqresultlog::insert($logData);
  355. }
  356. return responseToJson(1);
  357. }
  358. }