SportsbqController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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['if_order'] = isset($req->if_order) ? trim($req->if_order) : '1';
  18. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  19. $request['home_team'] = isset($req->home_team) ? trim($req->home_team) : null;
  20. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) :trans('status.default_time.seven_day') ;
  21. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : trans('status.default_time.etime');
  22. $dt = \App\Lib\DataTable\DataTable::init();
  23. $dt->setDataSource('/admin/Sportsbq/info');
  24. $dt->setLang('Sportsbq');
  25. $dt->addColsFields('newtime', array('templet' => '#newtime', 'sort' => false, 'width' => 200));
  26. $dt->addColsFields('totime', array('templet' => '#totime', 'sort' => false, 'width' => 200));
  27. $dt->addColsFields('home_team', array('templet' => '#home_team', 'sort' => false, 'width' => 80));
  28. $dt->addColsFields('guest_team', array('templet' => '#guest_team', 'sort' => false, 'width' => 80));
  29. $dt->addColsFields('dsnum', array('templet' => '#dsnum', 'sort' => false, 'width' => 100));
  30. // $dt->addColsFields('csnum', array('templet' => '#home_rate', 'sort' => false, 'width' => 80));
  31. $dt->addColsFields('csnum', array('templet' => '#csnum', 'sort' => false, 'width' => 100));
  32. $dt->addColsFields('match_score', array( 'templet' => '#match_score','sort' => false, 'width' => 220));//
  33. $dt->addColsFields('statusmatch', array('templet' => '#statusmatch', 'sort' => false, 'width' => 80));
  34. $dt->addColsFields('operation', array('templet' => '#operation', 'sort' => false, 'width' => 300));
  35. $dt->enableCheckBox();
  36. return view('admin.Sportsbq/outcome', $dt->render($request));
  37. }
  38. function info(){
  39. $page = Request::has('page') ? Request::get('page') : '';
  40. $list = Request::has('limit') ? Request::get('limit') : 10;
  41. $home_team = Request::has('home_team') ? Request::get('home_team') : '';
  42. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  43. $status = Request::has('status') ? Request::get('status') : '';
  44. $if_order = Request::has('if_order') ? Request::get('if_order') : '';
  45. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  46. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  47. $where = array();
  48. $orwhere = array();
  49. if (!empty($home_team)) {
  50. if (empty($sureblur) || $sureblur == 'off') {
  51. $where[] = array('st_bq_result.home_team', 'like', '%' . $home_team . '%');
  52. $orwhere[] = array('st_bq_result.guest_team', 'like', '%' . $home_team . '%');
  53. } else {
  54. if(is_numeric($home_team)){
  55. $where[] = array('st_bq_result.match_id', '=', $home_team);
  56. $orwhere[] = array('st_bq_result.match_id', '=', $home_team);
  57. }else{
  58. $where[] = array('st_bq_result.home_team', '=', $home_team);
  59. $orwhere[] = array('st_bq_result.guest_team', '=', $home_team);
  60. }
  61. }
  62. }
  63. //
  64. if ($status != -1) {
  65. $where[] = array('st_bq_competition.status', '=', $status);
  66. $orwhere[] = array('st_bq_competition.status', '=', $status);
  67. }
  68. if (!empty($star_time) and empty($home_team)) {
  69. $star_time = date('Y-m-d H:i:s', strtotime($star_time));
  70. $where[] = array('st_bq_result.start_time', '>', $star_time);
  71. $orwhere[] = array('st_bq_result.start_time', '>', $star_time);
  72. }
  73. if (!empty($end_time) and empty($home_team)) {
  74. $end_time = date('Y-m-d H:i:s', strtotime($end_time));
  75. $where[] = array('st_bq_result.start_time', '<', $end_time);
  76. $orwhere[] = array('st_bq_result.start_time', '<', $end_time);
  77. }
  78. $newapp = new \App\Models\Stbqresult();
  79. $data = $newapp->getinfo($list, $page, $where,$orwhere,$if_order);
  80. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  81. }
  82. //作废
  83. function revoke(Req $req){
  84. $match_id = $req->match_id;//赛事id
  85. $model = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  86. $model->status = 4;
  87. $model->save();
  88. $smodel = \App\Models\SportsBase::where('id', $match_id)->first();
  89. if($smodel){
  90. $smodel->status = 4;
  91. $smodel->save();
  92. }
  93. //赛事下单式注单作废,串关注单下此赛事按平局处理
  94. $upapp = new \App\Models\SportsNoteList();
  95. $upapp->delorder($match_id,'bq');
  96. // $upapp = new \App\Models\SportsNoteList();
  97. // $data = $upapp->updatesimplex($match_id,'bq');//修改单式状态
  98. //
  99. // //单式撤单返现
  100. // $newapp = new \App\Models\MoneyBuyMatch();
  101. // $all = $newapp->allsimplexorder($match_id,'bq');
  102. // for ($i=0; $i < count($all); $i++) {
  103. // $appgx = new \App\Lib\Settlement\SettlementOrder();
  104. // $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']);
  105. // }
  106. //
  107. // //串式撤单只改状态
  108. // $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  109. // $csapp = new \App\Models\MoneyBuyStr();
  110. // $csapp->updatestatus($str_ids);//var_dump($ss);die;
  111. // //修改money_buy_match 投注结果result=2为平
  112. // $newapp->updatast($match_id);
  113. return responseToJson(1);
  114. }
  115. //结算
  116. function Settlement1(Req $req){
  117. $match_id = $req->match_id;
  118. $type = $req->type;
  119. $process = $req->process;
  120. if(empty($process)){
  121. $process = array();
  122. }
  123. $token = session('adminInfo.token');
  124. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  125. if(!$notice){
  126. return json_encode(['status'=>5,'msg'=>'请先核对结果,并提交结果']);
  127. }
  128. $noticeid = $notice['id'];
  129. //查询赛事单式是否有订单(棒球)
  130. $newapp = new \App\Models\MoneyBuyMatch();
  131. $simplex = $newapp->simsettleorder($match_id,$type);
  132. $str = $newapp->strsettleorder($match_id);
  133. //获取赛事结算进程下的注单
  134. $simplex = commonFunction::getOrderData($data = [],$simplex,$type,$process);
  135. $str = commonFunction::getOrderData($data = [],$str,$type,$process);
  136. //获取注单id组成一维数组
  137. $simplex_ids = array_column($simplex['settle'],'order_id');
  138. $str_ids = array_column($str['settle'],'order_id');
  139. //去重
  140. $simplex_ids = array_unique($simplex_ids);
  141. $str_ids = array_unique($str_ids);
  142. //判断赛事下注单输赢
  143. $datas = array('noticeid' => $noticeid , 'token' => $token);
  144. $settlementAuto = new \App\Lib\Settlement\SettlementAuto();
  145. $winfail = $settlementAuto->SubmitSettelement('w',$datas);
  146. if($winfail == false){
  147. return json_encode(['status'=>2,'msg'=>'判断输赢错误,请联系管理员!!!']);//输赢错误
  148. }
  149. $sim = array(
  150. 'token'=>$token,
  151. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  152. 'bettype'=>1, //结算类型 1单式 2串式
  153. 'settype'=>2, //结算次数 1首次 2非首次
  154. 'game_code'=>$type, //赛事类型 zq lq wq bq
  155. 'match_id'=>$match_id, // 赛事ID
  156. 'change_status'=>1 //是否改状态
  157. );
  158. $str = array(
  159. 'token'=>$token,
  160. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  161. 'bettype'=>2, //结算类型 1单式 2串式
  162. 'settype'=>2, //结算次数 1首次 2非首次
  163. 'game_code'=>$type, //赛事类型 zq lq wq bq
  164. 'match_id'=>$match_id, // 赛事ID
  165. 'change_status'=>1 //是否改状态
  166. );
  167. if(count($simplex_ids)>0 || count($str_ids)>0){
  168. //单式结算
  169. if(count($simplex_ids)>0 && count($str_ids)==0){
  170. $sim['order_ids'] = implode(',',$simplex_ids);
  171. $settlesim = $settlementAuto->SubmitSettelement('s',$sim);
  172. if($settlesim == false){
  173. return json_encode(['status'=>3,'msg'=>'单式注单结算有误,请联系管理员!!!']);
  174. }else{
  175. return json_encode(['status'=>1,'msg'=>'单式结算成功,没有串式订单']);
  176. }
  177. }
  178. //串式结算
  179. elseif(count($str_ids)>0 && count($simplex_ids)==0){
  180. $str['order_ids'] = implode(',',$str_ids);
  181. $settlestr = $settlementAuto->SubmitSettelement('s',$str);
  182. if($settlestr == false){
  183. return json_encode(['status'=>3,'msg'=>'串式注单结算有误,请联系管理员!!!']);
  184. }else{
  185. return json_encode(['status'=>1,'msg'=>'串式结算成功,没有单式订单']);
  186. }
  187. }
  188. //既有单式也有串式
  189. elseif(count($str_ids)>0 && count($simplex_ids)>0){
  190. $sim['order_ids'] = implode(',',$simplex_ids);
  191. $str['order_ids'] = implode(',',$str_ids);
  192. $settlesim = $settlementAuto->SubmitSettelement('s',$sim);
  193. $settlestr = $settlementAuto->SubmitSettelement('s',$str);
  194. if($settlesim == true || $settlestr == true){
  195. return json_encode(['status'=>1,'msg'=>'结算成功']);
  196. }else{
  197. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!']);
  198. }
  199. }
  200. }else{
  201. $log = array(
  202. session('adminInfo.admin_name'),
  203. );
  204. OperationLog(session('adminInfo.admin_id'), '足球结算', $log);
  205. $res = \App\Models\SportsBase::where ('id', $match_id)->first();
  206. if($res['status'] == 1){
  207. return json_encode(['status'=>4,'msg'=>'该赛事进程下没有任何订单']);
  208. }
  209. $res = \App\Models\Stbqresult::where ('match_id', $match_id)->update(['status' =>3]);
  210. $res = \App\Models\SportsBase::where ('id', $match_id)->update(['status' =>3]);
  211. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  212. }
  213. }
  214. //结算
  215. function Settlement(Req $req){
  216. $jsurl = config('sconstant.url');//结算请求域名地址
  217. $match_id = $req->match_id;
  218. $type = $req->type;
  219. $token = session('adminInfo.token');
  220. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  221. $noticeid = $notice['id'];
  222. if(!$notice){
  223. return json_encode(['status'=>5,'msg'=>'请先核对结果,并提交结果']);
  224. }
  225. //查询赛事单式是否有订单(棒球)
  226. $newapp = new \App\Models\MoneyBuyMatch();
  227. $simplex_ids = array_column($newapp->simsettleorder($match_id,'bq'),'order_id');
  228. $str_ids = array_column($newapp->strsettleorder($match_id),'order_id');
  229. //去重
  230. $simplex_ids = array_unique($simplex_ids);
  231. $str_ids = array_unique($str_ids);
  232. //判断赛事下注单输赢
  233. $datas = array('noticeid' => $noticeid , 'token' => $token);
  234. $settlementAuto = new \App\Lib\Settlement\SettlementAuto();
  235. $winfail = $settlementAuto->SubmitSettelement('w',$datas);
  236. if($winfail == false){
  237. return json_encode(['status'=>2,'msg'=>'判断输赢错误,请联系管理员!!!']);//输赢错误
  238. }
  239. $sim = array(
  240. 'token'=>$token,
  241. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  242. 'bettype'=>1, //结算类型 1单式 2串式
  243. 'settype'=>2, //结算次数 1首次 2非首冷饮
  244. 'game_code'=>$type, //赛事类型 zq lq wq bq
  245. 'match_id'=>$match_id, // 赛事ID
  246. 'change_status'=>1 //是否改状态
  247. );
  248. $str = array(
  249. 'token'=>$token,
  250. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  251. 'bettype'=>2, //结算类型 1单式 2串式
  252. 'settype'=>2, //结算次数 1首次 2非首冷饮
  253. 'game_code'=>$type, //赛事类型 zq lq wq bq
  254. 'match_id'=>$match_id, // 赛事ID
  255. 'change_status'=>1 //是否改状态
  256. );
  257. if(count($simplex_ids)>0 || count($str_ids)>0){
  258. //单式结算
  259. if(count($simplex_ids)>0 && count($str_ids)==0){
  260. $sim['order_ids'] = implode(',',$simplex_ids);
  261. $settlesim = $settlementAuto->SubmitSettelement('s',$sim);
  262. if($settlesim == false){
  263. return json_encode(['status'=>3,'msg'=>'单式注单结算有误,请联系管理员!!!']);
  264. }else{
  265. return json_encode(['status'=>1,'msg'=>'单式结算成功,没有串式订单']);
  266. }
  267. }
  268. elseif(count($str_ids)>0 && count($simplex_ids)==0){
  269. $str['order_ids'] = implode(',',$str_ids);
  270. $settlestr = $settlementAuto->SubmitSettelement('s',$str);
  271. if($settlestr == false){
  272. return json_encode(['status'=>3,'msg'=>'串式注单结算有误,请联系管理员!!!']);
  273. }else{
  274. return json_encode(['status'=>1,'msg'=>'串式结算成功,没有单式订单']);
  275. }
  276. }
  277. elseif(count($str_ids)>0 && count($simplex_ids)>0){
  278. $sim['order_ids'] = implode(',',$simplex_ids);
  279. $str['order_ids'] = implode(',',$str_ids);
  280. $settlesim = $settlementAuto->SubmitSettelement('s',$sim);
  281. $settlestr = $settlementAuto->SubmitSettelement('s',$str);
  282. if($settlesim == true || $settlestr == true){
  283. return json_encode(['status'=>1,'msg'=>'结算成功']);
  284. }else{
  285. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!']);
  286. }
  287. }
  288. }else{
  289. $log = array(
  290. session('adminInfo.admin_name'),
  291. );
  292. OperationLog(session('adminInfo.admin_id'), '棒球结算', $log);
  293. $res = \App\Models\Stbqresult::where ('match_id', $match_id)->update(['status' =>3]);
  294. $res = \App\Models\SportsBase::where ('id', $match_id)->update(['status' =>3]);
  295. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  296. }
  297. }
  298. //查询赛事结果
  299. function Matchresult(Req $req){
  300. $match_id = $req->match_id;
  301. $newapp = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  302. $jieguo =array(
  303. 'bqresult' => json_decode($newapp['manual_result'],true),
  304. 'newapp' => $newapp,
  305. );
  306. return $jieguo;
  307. }
  308. //查询赛事结果
  309. function resultLog(Req $req){
  310. $match_id = $req->match_id;
  311. $list = \App\Models\Stbqresultlog::leftJoin('system_user', 'user_id', '=', 'system_user.id')
  312. ->select('st_bq_result_log.*', 'system_user.loginname')->where('match_id', $match_id)->orderBy('id', 'asc')->get();
  313. foreach ($list as $key=>$value){
  314. $list[$key]['match_score_t'] = json_decode($value['match_score_t'], true);
  315. }
  316. $result =array(
  317. 'status' => 200,
  318. 'list' => $list
  319. );
  320. echo json_encode($result);die;
  321. }
  322. function onlyresult(Req $req){
  323. $match_id = $req->matchid;
  324. $newapp = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  325. return $newapp;
  326. }
  327. //结果添加
  328. function addend(Req $req){
  329. $match_id = $req->match_id;
  330. $model = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  331. $match = \App\Models\SportsBase::where('id', $match_id)->first();
  332. $match_status = $match['status'];
  333. $uscore = array(
  334. "1" => array(
  335. 'home' => strlen($req->homea)?$req->homea:'',
  336. 'guest' => strlen($req->guesta)?$req->guesta:'',
  337. ),
  338. "2" => array(
  339. 'home' => strlen($req->homeb)?$req->homeb:'',
  340. 'guest' => strlen($req->guestb)?$req->guestb:'',
  341. ),
  342. "3" => array(
  343. 'home' => strlen($req->homec)?$req->homec:'',
  344. 'guest' => strlen($req->guestc)?$req->guestc:'',
  345. ),
  346. "4" => array(
  347. 'home' => strlen($req->homed)?$req->homed:'',
  348. 'guest' => strlen($req->guestd)?$req->guestd:'',
  349. ),
  350. "5" => array(
  351. 'home' => strlen($req->homee)?$req->homee:'',
  352. 'guest' => strlen($req->gueste)?$req->gueste:'',
  353. ),
  354. "6" => array(
  355. 'home' => strlen($req->homef)?$req->homef:'',
  356. 'guest' => strlen($req->guestf)?$req->guestf:'',
  357. ),
  358. "7" => array(
  359. 'home' => strlen($req->homeg)?$req->homeg:'',
  360. 'guest' => strlen($req->guestg)?$req->guestg:'',
  361. ),
  362. "8" => array(
  363. 'home' => strlen($req->homeh)?$req->homeh:'',
  364. 'guest' => strlen($req->guesth)?$req->guesth:'',
  365. ),
  366. "9" => array(
  367. 'home' => strlen($req->homei)?$req->homei:'',
  368. 'guest' => strlen($req->guesti)?$req->guesti:'',
  369. ),
  370. "other" => array(
  371. 'home' => strlen($req->homej)?$req->homej:'',
  372. 'guest' => strlen($req->guestj)?$req->guestj:'',
  373. ),
  374. "five" => array(
  375. 'home' => strlen($req->homek)?$req->homek:'',
  376. 'guest' => strlen($req->guestk)?$req->guestk:'',
  377. ),
  378. "all" => array(
  379. 'home' => strlen($req->homel)?$req->homel:'',
  380. 'guest' => strlen($req->guestl)?$req->guestl:'',
  381. ),
  382. );
  383. // foreach($uscore as $key){
  384. // $data[] = $key['home'];
  385. // $data[] = $key['guest'];
  386. // }
  387. //修改棒球比分前的比分数据
  388. $res = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  389. $scores = json_decode($res['manual_result'],true);
  390. $process = array();//进程
  391. if($scores[1]['home'] != $uscore[1]['home'] || $scores[1]['guest'] != $uscore[1]['guest']){
  392. $process[] = 'one';
  393. }
  394. if($scores[2]['home'] != $uscore[2]['home'] || $scores[2]['guest'] != $uscore[2]['guest']){
  395. $process[] = 'two';
  396. }
  397. if($scores[3]['home'] != $uscore[3]['home'] || $scores[3]['guest'] != $uscore[3]['guest']){
  398. $process[] = 'three';
  399. }
  400. if($scores[4]['home'] != $uscore[4]['home'] || $scores[4]['guest'] != $uscore[4]['guest']){
  401. $process[] = 'four';
  402. }
  403. if($scores[5]['home'] != $uscore[5]['home'] || $scores[5]['guest'] != $uscore[5]['guest']){
  404. $process[] = 'five';
  405. }
  406. if($scores[6]['home'] != $uscore[6]['home'] || $scores[6]['guest'] != $uscore[6]['guest']){
  407. $process[] = 'six';
  408. }
  409. if($scores[7]['home'] != $uscore[7]['home'] || $scores[7]['guest'] != $uscore[7]['guest']){
  410. $process[] = 'seven';
  411. }
  412. if($scores[8]['home'] != $uscore[8]['home'] || $scores[8]['guest'] != $uscore[8]['guest']){
  413. $process[] = 'eight';
  414. }
  415. if($scores[9]['home'] != $uscore[9]['home'] || $scores[9]['guest'] != $uscore[9]['guest']){
  416. $process[] = 'nine';
  417. }
  418. if($scores['other']['home'] != $uscore['other']['home'] || $scores['other']['guest'] != $uscore['other']['guest']){
  419. $process[] = 'other';
  420. }
  421. if($scores['five']['home'] != $uscore['five']['home'] || $scores['five']['guest'] != $uscore['five']['guest']){
  422. $process[] = 'sfive';
  423. }
  424. if($scores['all']['home'] != $uscore['all']['home'] || $scores['all']['guest'] != $uscore['all']['guest']){
  425. $process[] = 'all';
  426. }
  427. if(!empty($process)){
  428. //赛事下注单作废 处理
  429. commonFunction::HandleInvalid($uscore,$match_id,$match_status,'bq',$process);
  430. $updatainfo = [
  431. // "home_score"=>$uscore['all']['home'],
  432. // "guest_score"=>$uscore['all']['guest'],
  433. "match_score_t"=>json_encode($uscore),
  434. "manual_result"=>json_encode($uscore),
  435. // "match_score"=>$uscore['all']['home'].':'.$uscore['all']['guest'],
  436. // "u_home_score"=>$uscore['five']['home'],
  437. // "u_guest_score"=>$uscore['five']['guest'],
  438. 'is_correct'=>1,
  439. ];
  440. if(strlen($uscore['all']['home'])>0 && strlen($uscore['all']['guest'])>0){
  441. $updatainfo['home_score'] = $uscore['all']['home'];
  442. $updatainfo['guest_score'] = $uscore['all']['guest'];
  443. }
  444. if(strlen($uscore['five']['home'])>0 && strlen($uscore['five']['guest'])>0){
  445. $updatainfo['u_home_score'] = $uscore['all']['home'];
  446. $updatainfo['u_guest_score'] = $uscore['all']['guest'];
  447. }
  448. \App\Models\Stbqresult::where('match_id', $match_id)->update($updatainfo);
  449. $addnew = new \App\Models\Comendnotice();
  450. $addnew->addcomendnotice($match_id,'bq');
  451. //赛事下所有注单状态都改变时,修改赛事,赛事结果状态
  452. if(count($process) == count($uscore)){
  453. $twoapp = new \App\Models\SportsBase();
  454. $twoapp->updatestatus('id',$match_id,['status'=>2,'utime'=>date('Y-m-d H:i:s')]);//修改赛事状态
  455. $newapp = new \App\Models\Stbqresult();
  456. $newapp->updatestatus('match_id',$match_id,['status'=>2,'update_time'=>date('Y-m-d H:i:s')]);//修改结果状态
  457. }
  458. //添加赛事结果记录
  459. $lastLog = \App\Models\Stbqresultlog::where([
  460. ['match_id', $match_id],
  461. ['type', 1]
  462. ])->orderBy('id', 'desc')->first();
  463. if(empty($lastLog) || $lastLog['match_score_t'] != json_encode($uscore)){
  464. \App\Models\Stbqresultlog::insert([
  465. 'match_id' => $match_id,
  466. 'match_score_t' => json_encode($uscore),
  467. 'user_id' => session('adminInfo.admin_id'),
  468. 'type' => 1,
  469. 'create_at' => now()
  470. ]);
  471. }
  472. }
  473. return responseToJson(1);
  474. }
  475. //更新赛事比分
  476. function updatascore(Req $req){
  477. $only = $req->only;
  478. $num = $req->num;
  479. $match_id = $req->match_id;
  480. $newapp = new \App\Models\Stbqresult();
  481. //赛事状态
  482. $match_status = intval($req->match_status)?intval($req->match_status):0;
  483. // $data['update_time'] = data('Y-m-d H:i:s');//更新时间
  484. $data['u_home_score'] = intval($req->u_home_score)?intval($req->u_home_score):0;
  485. $data['u_guest_score'] = intval($req->u_guest_score)?intval($req->u_guest_score):0;
  486. $data['guest_score'] = intval($req->guest_score)?intval($req->guest_score):0;
  487. $data['home_score'] = intval($req->home_score)?intval($req->home_score):0;
  488. $data['is_correct'] = 1;//追加手动更改标识
  489. //更新比分 默认 status
  490. $status = 2;
  491. //追加判断比分 如果都== -1,则作废该赛事
  492. if($data['u_home_score'] < 0 and $data['u_guest_score'] < 0 and $data['home_score'] < 0 and $data['guest_score'] < 0){
  493. //已结算作废赛事处理
  494. if($match_status == 3){
  495. $url = 'http://stadmin.bocai108.com:9094/UnSettelement';
  496. $data_up = [
  497. 'token'=>session('adminInfo.token'),
  498. 'game_code'=>'bq',
  499. 'match_id'=>$match_id,
  500. ];
  501. $ret_json = commonFunction::https_request($url,$data_up);
  502. // $ret_json = '{"status":1,"msg":"撤销成功!2019-10-26 16:28:30 取消赛事处理--结束end:game_code= zq match_id= 40986 \n","data":[]}';
  503. $ret_arr = json_decode($ret_json,true);
  504. if($ret_arr['status'] != 1){
  505. return responseToJson(-20003);
  506. }
  507. }
  508. //赛事下单式注单作废,串关注单下此赛事按平局处理
  509. $upapp = new \App\Models\SportsNoteList();
  510. $upapp->delorder($match_id,'bq');
  511. $status = 4;
  512. }
  513. $res = $newapp->updateInfo($data,$match_id);//联赛id
  514. $addnew = new \App\Models\Comendnotice();
  515. $addnew->addcomendnotice($match_id,'bq');
  516. $twoapp = new \App\Models\SportsBase();
  517. $twoapp->updatestatus('match_id',$match_id,['status'=>$status,'utime'=>date('Y-m-d H:i:s')]);//修改赛事状态
  518. $newapp->updatestatus('match_id',$match_id,['status'=>$status,'update_time'=>date('Y-m-d H:i:s')]);//修改结果状态
  519. //添加赛事结果比较记录
  520. $lastLog = \App\Models\Stbqresultlog::where([
  521. ['match_id', $match_id],
  522. ['type', 2]
  523. ])->orderBy('id', 'desc')->first();
  524. if(empty($lastLog) || !(
  525. $lastLog['u_home_score'] == $data['u_home_score']
  526. && $lastLog['u_guest_score'] == $data['u_guest_score']
  527. && $lastLog['guest_score'] == $data['guest_score']
  528. && $lastLog['home_score'] == $data['home_score']
  529. )){
  530. $logData = $data;
  531. $logData['type'] = 2;
  532. $logData['match_id'] = $match_id;
  533. $logData['user_id'] = session('adminInfo.admin_id');
  534. $logData['create_at'] = now();
  535. \App\Models\Stbqresultlog::insert($logData);
  536. }
  537. return responseToJson(1);
  538. }
  539. //获取赛事进程数据
  540. function getprocess(Req $req){
  541. $type = $req->type;
  542. $process = commonFunction::getprocess($type);
  543. return json_encode($process);
  544. }
  545. }