SportswqController.php 23 KB

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