SportswqController.php 23 KB

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