SportsbqController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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. //赛事比分数据
  124. $res = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  125. $scores = json_decode($res['manual_result'],true);
  126. //结算验证
  127. if(in_array('one',$process)){
  128. if(strlen($scores['1']['home'])==0 || strlen($scores['1']['guest'])==0){
  129. return json_encode(['status'=>6,'msg'=>'没有第一局结果,无法结算第一局']);
  130. }
  131. }
  132. if(in_array('two',$process)){
  133. if(strlen($scores['2']['home'])==0 || strlen($scores['2']['guest'])==0){
  134. return json_encode(['status'=>7,'msg'=>'没有第二局结果,无法结算第二局']);
  135. }
  136. }
  137. if(in_array('three',$process)){
  138. if(strlen($scores['3']['home'])==0 || strlen($scores['3']['guest'])==0){
  139. return json_encode(['status'=>8,'msg'=>'没有第三局结果,无法结算第三局']);
  140. }
  141. }
  142. if(in_array('four',$process)){
  143. if(strlen($scores['4']['home'])==0 || strlen($scores['4']['guest'])==0){
  144. return json_encode(['status'=>9,'msg'=>'没有第四局结果,无法结算第四局']);
  145. }
  146. }
  147. if(in_array('five',$process)){
  148. if(strlen($scores['5']['home'])==0 || strlen($scores['5']['guest'])==0){
  149. return json_encode(['status'=>10,'msg'=>'没有第五局结果,无法结算第五局']);
  150. }
  151. }
  152. if(in_array('six',$process)){
  153. if(strlen($scores['6']['home'])==0 || strlen($scores['6']['guest'])==0){
  154. return json_encode(['status'=>11,'msg'=>'没有第六局结果,无法结算第六局']);
  155. }
  156. }
  157. if(in_array('seven',$process)){
  158. if(strlen($scores['7']['home'])==0 || strlen($scores['7']['guest'])==0){
  159. return json_encode(['status'=>12,'msg'=>'没有第七局结果,无法结算第七局']);
  160. }
  161. }
  162. if(in_array('eight',$process)){
  163. if(strlen($scores['8']['home'])==0 || strlen($scores['8']['guest'])==0){
  164. return json_encode(['status'=>13,'msg'=>'没有第八局结果,无法结算第八局']);
  165. }
  166. }
  167. if(in_array('nine',$process)){
  168. if(strlen($scores['9']['home'])==0 || strlen($scores['9']['guest'])==0){
  169. return json_encode(['status'=>14,'msg'=>'没有第九局结果,无法结算第九局']);
  170. }
  171. }
  172. if(in_array('other',$process)){
  173. if(strlen($scores['other']['home'])==0 || strlen($scores['other']['guest'])==0){
  174. return json_encode(['status'=>15,'msg'=>'没有第十局结果,无法结算第十局']);
  175. }
  176. }
  177. if(in_array('sfive',$process)){
  178. if(strlen($scores['five']['home'])==0 || strlen($scores['five']['guest'])==0){
  179. return json_encode(['status'=>16,'msg'=>'没有前五局结果,无法结算前五局']);
  180. }
  181. }
  182. if(in_array('all',$process)){
  183. if(strlen($scores['all']['home'])==0 || strlen($scores['all']['guest'])==0){
  184. return json_encode(['status'=>17,'msg'=>'没有全场结果,无法结算全场']);
  185. }
  186. }
  187. $token = session('adminInfo.token');
  188. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  189. if(!$notice){
  190. return json_encode(['status'=>5,'msg'=>'请先核对结果,并提交结果']);
  191. }
  192. $noticeid = $notice['id'];
  193. //查询赛事单式是否有订单(棒球)
  194. $newapp = new \App\Models\MoneyBuyMatch();
  195. $simplex = $newapp->simsettleorder($match_id,$type);
  196. $str = $newapp->strsettleorder($match_id);
  197. //获取赛事结算进程下的注单
  198. $simplex = commonFunction::getOrderData($data = [],$simplex,$type,$process);
  199. $str = commonFunction::getOrderData($data = [],$str,$type,$process);
  200. //获取注单id组成一维数组
  201. $simplex_ids = array_column($simplex['settle'],'order_id');
  202. $str_ids = array_column($str['settle'],'order_id');
  203. //去重
  204. $simplex_ids = array_unique($simplex_ids);
  205. $str_ids = array_unique($str_ids);
  206. //判断赛事下注单输赢
  207. $datas = array('noticeid' => $noticeid , 'token' => $token);
  208. $settlementAuto = new \App\Lib\Settlement\SettlementAuto();
  209. $winfail = $settlementAuto->SubmitSettelement('w',$datas);
  210. if($winfail == false){
  211. return json_encode(['status'=>2,'msg'=>'判断输赢错误,请联系管理员!!!']);//输赢错误
  212. }
  213. $sim = array(
  214. 'token'=>$token,
  215. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  216. 'bettype'=>1, //结算类型 1单式 2串式
  217. 'settype'=>2, //结算次数 1首次 2非首次
  218. 'game_code'=>$type, //赛事类型 zq lq wq bq
  219. 'match_id'=>$match_id, // 赛事ID
  220. 'change_status'=>1 //是否改状态
  221. );
  222. $str = array(
  223. 'token'=>$token,
  224. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  225. 'bettype'=>2, //结算类型 1单式 2串式
  226. 'settype'=>2, //结算次数 1首次 2非首次
  227. 'game_code'=>$type, //赛事类型 zq lq wq bq
  228. 'match_id'=>$match_id, // 赛事ID
  229. 'change_status'=>1 //是否改状态
  230. );
  231. if(count($simplex_ids)>0 || count($str_ids)>0){
  232. //单式结算
  233. if(count($simplex_ids)>0 && count($str_ids)==0){
  234. $sim['order_ids'] = implode(',',$simplex_ids);
  235. $settlesim = $settlementAuto->SubmitSettelement('s',$sim);
  236. if($settlesim == false){
  237. return json_encode(['status'=>3,'msg'=>'单式注单结算有误,请联系管理员!!!']);
  238. }else{
  239. return json_encode(['status'=>1,'msg'=>'单式结算成功,没有串式订单']);
  240. }
  241. }
  242. //串式结算
  243. elseif(count($str_ids)>0 && count($simplex_ids)==0){
  244. $str['order_ids'] = implode(',',$str_ids);
  245. $settlestr = $settlementAuto->SubmitSettelement('s',$str);
  246. if($settlestr == false){
  247. return json_encode(['status'=>3,'msg'=>'串式注单结算有误,请联系管理员!!!']);
  248. }else{
  249. return json_encode(['status'=>1,'msg'=>'串式结算成功,没有单式订单']);
  250. }
  251. }
  252. //既有单式也有串式
  253. elseif(count($str_ids)>0 && count($simplex_ids)>0){
  254. $sim['order_ids'] = implode(',',$simplex_ids);
  255. $str['order_ids'] = implode(',',$str_ids);
  256. $settlesim = $settlementAuto->SubmitSettelement('s',$sim);
  257. $settlestr = $settlementAuto->SubmitSettelement('s',$str);
  258. if($settlesim == true || $settlestr == true){
  259. return json_encode(['status'=>1,'msg'=>'结算成功']);
  260. }else{
  261. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!']);
  262. }
  263. }
  264. }else{
  265. $log = array(
  266. session('adminInfo.admin_name'),
  267. );
  268. OperationLog(session('adminInfo.admin_id'), '足球结算', $log);
  269. $res = \App\Models\SportsBase::where ('id', $match_id)->first();
  270. if($res['status'] == 1){
  271. return json_encode(['status'=>4,'msg'=>'该赛事进程下没有任何订单']);
  272. }
  273. $res = \App\Models\Stbqresult::where ('match_id', $match_id)->update(['status' =>3]);
  274. $res = \App\Models\SportsBase::where ('id', $match_id)->update(['status' =>3]);
  275. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  276. }
  277. }
  278. //结算
  279. function Settlement(Req $req){
  280. $jsurl = config('sconstant.url');//结算请求域名地址
  281. $match_id = $req->match_id;
  282. $type = $req->type;
  283. $token = session('adminInfo.token');
  284. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  285. $noticeid = $notice['id'];
  286. if(!$notice){
  287. return json_encode(['status'=>5,'msg'=>'请先核对结果,并提交结果']);
  288. }
  289. //查询赛事单式是否有订单(棒球)
  290. $newapp = new \App\Models\MoneyBuyMatch();
  291. $simplex_ids = array_column($newapp->simsettleorder($match_id,'bq'),'order_id');
  292. $str_ids = array_column($newapp->strsettleorder($match_id),'order_id');
  293. //去重
  294. $simplex_ids = array_unique($simplex_ids);
  295. $str_ids = array_unique($str_ids);
  296. //判断赛事下注单输赢
  297. $datas = array('noticeid' => $noticeid , 'token' => $token);
  298. $settlementAuto = new \App\Lib\Settlement\SettlementAuto();
  299. $winfail = $settlementAuto->SubmitSettelement('w',$datas);
  300. if($winfail == false){
  301. return json_encode(['status'=>2,'msg'=>'判断输赢错误,请联系管理员!!!']);//输赢错误
  302. }
  303. $sim = array(
  304. 'token'=>$token,
  305. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  306. 'bettype'=>1, //结算类型 1单式 2串式
  307. 'settype'=>2, //结算次数 1首次 2非首冷饮
  308. 'game_code'=>$type, //赛事类型 zq lq wq bq
  309. 'match_id'=>$match_id, // 赛事ID
  310. 'change_status'=>1 //是否改状态
  311. );
  312. $str = array(
  313. 'token'=>$token,
  314. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  315. 'bettype'=>2, //结算类型 1单式 2串式
  316. 'settype'=>2, //结算次数 1首次 2非首冷饮
  317. 'game_code'=>$type, //赛事类型 zq lq wq bq
  318. 'match_id'=>$match_id, // 赛事ID
  319. 'change_status'=>1 //是否改状态
  320. );
  321. if(count($simplex_ids)>0 || count($str_ids)>0){
  322. //单式结算
  323. if(count($simplex_ids)>0 && count($str_ids)==0){
  324. $sim['order_ids'] = implode(',',$simplex_ids);
  325. $settlesim = $settlementAuto->SubmitSettelement('s',$sim);
  326. if($settlesim == false){
  327. return json_encode(['status'=>3,'msg'=>'单式注单结算有误,请联系管理员!!!']);
  328. }else{
  329. return json_encode(['status'=>1,'msg'=>'单式结算成功,没有串式订单']);
  330. }
  331. }
  332. elseif(count($str_ids)>0 && count($simplex_ids)==0){
  333. $str['order_ids'] = implode(',',$str_ids);
  334. $settlestr = $settlementAuto->SubmitSettelement('s',$str);
  335. if($settlestr == false){
  336. return json_encode(['status'=>3,'msg'=>'串式注单结算有误,请联系管理员!!!']);
  337. }else{
  338. return json_encode(['status'=>1,'msg'=>'串式结算成功,没有单式订单']);
  339. }
  340. }
  341. elseif(count($str_ids)>0 && count($simplex_ids)>0){
  342. $sim['order_ids'] = implode(',',$simplex_ids);
  343. $str['order_ids'] = implode(',',$str_ids);
  344. $settlesim = $settlementAuto->SubmitSettelement('s',$sim);
  345. $settlestr = $settlementAuto->SubmitSettelement('s',$str);
  346. if($settlesim == true || $settlestr == true){
  347. return json_encode(['status'=>1,'msg'=>'结算成功']);
  348. }else{
  349. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!']);
  350. }
  351. }
  352. }else{
  353. $log = array(
  354. session('adminInfo.admin_name'),
  355. );
  356. OperationLog(session('adminInfo.admin_id'), '棒球结算', $log);
  357. $res = \App\Models\Stbqresult::where ('match_id', $match_id)->update(['status' =>3]);
  358. $res = \App\Models\SportsBase::where ('id', $match_id)->update(['status' =>3]);
  359. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  360. }
  361. }
  362. //查询赛事结果
  363. function Matchresult(Req $req){
  364. $match_id = $req->match_id;
  365. $newapp = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  366. $jieguo =array(
  367. 'bqresult' => json_decode($newapp['manual_result'],true),
  368. 'newapp' => $newapp,
  369. );
  370. return $jieguo;
  371. }
  372. //查询赛事结果
  373. function resultLog(Req $req){
  374. $match_id = $req->match_id;
  375. $list = \App\Models\Stbqresultlog::leftJoin('system_user', 'user_id', '=', 'system_user.id')
  376. ->select('st_bq_result_log.*', 'system_user.loginname')->where('match_id', $match_id)->orderBy('id', 'asc')->get();
  377. foreach ($list as $key=>$value){
  378. $list[$key]['match_score_t'] = json_decode($value['match_score_t'], true);
  379. }
  380. $result =array(
  381. 'status' => 200,
  382. 'list' => $list
  383. );
  384. echo json_encode($result);die;
  385. }
  386. function onlyresult(Req $req){
  387. $match_id = $req->matchid;
  388. $newapp = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  389. return $newapp;
  390. }
  391. //结果添加
  392. function addend(Req $req){
  393. $match_id = $req->match_id;
  394. $model = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  395. $match = \App\Models\SportsBase::where('id', $match_id)->first();
  396. $match_status = $match['status'];
  397. $uscore = array(
  398. "1" => array(
  399. 'home' => strlen($req->homea)?$req->homea:'',
  400. 'guest' => strlen($req->guesta)?$req->guesta:'',
  401. ),
  402. "2" => array(
  403. 'home' => strlen($req->homeb)?$req->homeb:'',
  404. 'guest' => strlen($req->guestb)?$req->guestb:'',
  405. ),
  406. "3" => array(
  407. 'home' => strlen($req->homec)?$req->homec:'',
  408. 'guest' => strlen($req->guestc)?$req->guestc:'',
  409. ),
  410. "4" => array(
  411. 'home' => strlen($req->homed)?$req->homed:'',
  412. 'guest' => strlen($req->guestd)?$req->guestd:'',
  413. ),
  414. "5" => array(
  415. 'home' => strlen($req->homee)?$req->homee:'',
  416. 'guest' => strlen($req->gueste)?$req->gueste:'',
  417. ),
  418. "6" => array(
  419. 'home' => strlen($req->homef)?$req->homef:'',
  420. 'guest' => strlen($req->guestf)?$req->guestf:'',
  421. ),
  422. "7" => array(
  423. 'home' => strlen($req->homeg)?$req->homeg:'',
  424. 'guest' => strlen($req->guestg)?$req->guestg:'',
  425. ),
  426. "8" => array(
  427. 'home' => strlen($req->homeh)?$req->homeh:'',
  428. 'guest' => strlen($req->guesth)?$req->guesth:'',
  429. ),
  430. "9" => array(
  431. 'home' => strlen($req->homei)?$req->homei:'',
  432. 'guest' => strlen($req->guesti)?$req->guesti:'',
  433. ),
  434. "other" => array(
  435. 'home' => strlen($req->homej)?$req->homej:'',
  436. 'guest' => strlen($req->guestj)?$req->guestj:'',
  437. ),
  438. "five" => array(
  439. 'home' => strlen($req->homek)?$req->homek:'',
  440. 'guest' => strlen($req->guestk)?$req->guestk:'',
  441. ),
  442. "all" => array(
  443. 'home' => strlen($req->homel)?$req->homel:'',
  444. 'guest' => strlen($req->guestl)?$req->guestl:'',
  445. ),
  446. );
  447. //修改棒球比分前的比分数据
  448. $res = \App\Models\Stbqresult::where('match_id', $match_id)->first();
  449. $scores = json_decode($res['manual_result'],true);
  450. $process = array();//进程
  451. if($scores[1]['home'] != $uscore[1]['home'] || $scores[1]['guest'] != $uscore[1]['guest']){
  452. $process[] = 'one';
  453. }
  454. if($scores[2]['home'] != $uscore[2]['home'] || $scores[2]['guest'] != $uscore[2]['guest']){
  455. $process[] = 'two';
  456. }
  457. if($scores[3]['home'] != $uscore[3]['home'] || $scores[3]['guest'] != $uscore[3]['guest']){
  458. $process[] = 'three';
  459. }
  460. if($scores[4]['home'] != $uscore[4]['home'] || $scores[4]['guest'] != $uscore[4]['guest']){
  461. $process[] = 'four';
  462. }
  463. if($scores[5]['home'] != $uscore[5]['home'] || $scores[5]['guest'] != $uscore[5]['guest']){
  464. $process[] = 'five';
  465. }
  466. if($scores[6]['home'] != $uscore[6]['home'] || $scores[6]['guest'] != $uscore[6]['guest']){
  467. $process[] = 'six';
  468. }
  469. if($scores[7]['home'] != $uscore[7]['home'] || $scores[7]['guest'] != $uscore[7]['guest']){
  470. $process[] = 'seven';
  471. }
  472. if($scores[8]['home'] != $uscore[8]['home'] || $scores[8]['guest'] != $uscore[8]['guest']){
  473. $process[] = 'eight';
  474. }
  475. if($scores[9]['home'] != $uscore[9]['home'] || $scores[9]['guest'] != $uscore[9]['guest']){
  476. $process[] = 'nine';
  477. }
  478. if($scores['other']['home'] != $uscore['other']['home'] || $scores['other']['guest'] != $uscore['other']['guest']){
  479. $process[] = 'other';
  480. }
  481. if($scores['five']['home'] != $uscore['five']['home'] || $scores['five']['guest'] != $uscore['five']['guest']){
  482. $process[] = 'sfive';
  483. }
  484. if($scores['all']['home'] != $uscore['all']['home'] || $scores['all']['guest'] != $uscore['all']['guest']){
  485. $process[] = 'all';
  486. }
  487. if(!empty($process)){
  488. //赛事下注单作废 处理
  489. commonFunction::HandleInvalid($uscore,$match_id,$match_status,'bq',$process);
  490. $updatainfo = [
  491. "match_score_t"=>json_encode($uscore),
  492. "manual_result"=>json_encode($uscore),
  493. 'is_correct'=>1,
  494. ];
  495. \App\Models\Stbqresult::where('match_id', $match_id)->update($updatainfo);
  496. $addnew = new \App\Models\Comendnotice();
  497. $addnew->addcomendnotice($match_id,'bq');
  498. //赛事下所有注单状态都改变时,修改赛事,赛事结果状态
  499. if(count($process) == count($uscore)){
  500. $twoapp = new \App\Models\SportsBase();
  501. $twoapp->updatestatus('id',$match_id,['status'=>2,'utime'=>date('Y-m-d H:i:s')]);//修改赛事状态
  502. $newapp = new \App\Models\Stbqresult();
  503. $newapp->updatestatus('match_id',$match_id,['status'=>2,'update_time'=>date('Y-m-d H:i:s')]);//修改结果状态
  504. }
  505. //添加赛事结果记录
  506. $lastLog = \App\Models\Stbqresultlog::where([
  507. ['match_id', $match_id],
  508. ['type', 1]
  509. ])->orderBy('id', 'desc')->first();
  510. if(empty($lastLog) || $lastLog['match_score_t'] != json_encode($uscore)){
  511. \App\Models\Stbqresultlog::insert([
  512. 'match_id' => $match_id,
  513. 'match_score_t' => json_encode($uscore),
  514. 'user_id' => session('adminInfo.admin_id'),
  515. 'type' => 1,
  516. 'create_at' => now()
  517. ]);
  518. }
  519. }
  520. return responseToJson(1);
  521. }
  522. //更新赛事比分
  523. function updatascore(Req $req){
  524. $only = $req->only;
  525. $num = $req->num;
  526. $match_id = $req->match_id;
  527. $newapp = new \App\Models\Stbqresult();
  528. //赛事状态
  529. $match_status = intval($req->match_status)?intval($req->match_status):0;
  530. // $data['update_time'] = data('Y-m-d H:i:s');//更新时间
  531. $data['u_home_score'] = intval($req->u_home_score)?intval($req->u_home_score):0;
  532. $data['u_guest_score'] = intval($req->u_guest_score)?intval($req->u_guest_score):0;
  533. $data['guest_score'] = intval($req->guest_score)?intval($req->guest_score):0;
  534. $data['home_score'] = intval($req->home_score)?intval($req->home_score):0;
  535. $data['is_correct'] = 1;//追加手动更改标识
  536. //更新比分 默认 status
  537. $status = 2;
  538. //追加判断比分 如果都== -1,则作废该赛事
  539. if($data['u_home_score'] < 0 and $data['u_guest_score'] < 0 and $data['home_score'] < 0 and $data['guest_score'] < 0){
  540. //已结算作废赛事处理
  541. if($match_status == 3){
  542. $url = 'http://stadmin.bocai108.com:9094/UnSettelement';
  543. $data_up = [
  544. 'token'=>session('adminInfo.token'),
  545. 'game_code'=>'bq',
  546. 'match_id'=>$match_id,
  547. ];
  548. $ret_json = commonFunction::https_request($url,$data_up);
  549. // $ret_json = '{"status":1,"msg":"撤销成功!2019-10-26 16:28:30 取消赛事处理--结束end:game_code= zq match_id= 40986 \n","data":[]}';
  550. $ret_arr = json_decode($ret_json,true);
  551. if($ret_arr['status'] != 1){
  552. return responseToJson(-20003);
  553. }
  554. }
  555. //赛事下单式注单作废,串关注单下此赛事按平局处理
  556. $upapp = new \App\Models\SportsNoteList();
  557. $upapp->delorder($match_id,'bq');
  558. $status = 4;
  559. }
  560. $res = $newapp->updateInfo($data,$match_id);//联赛id
  561. $addnew = new \App\Models\Comendnotice();
  562. $addnew->addcomendnotice($match_id,'bq');
  563. $twoapp = new \App\Models\SportsBase();
  564. $twoapp->updatestatus('match_id',$match_id,['status'=>$status,'utime'=>date('Y-m-d H:i:s')]);//修改赛事状态
  565. $newapp->updatestatus('match_id',$match_id,['status'=>$status,'update_time'=>date('Y-m-d H:i:s')]);//修改结果状态
  566. //添加赛事结果比较记录
  567. $lastLog = \App\Models\Stbqresultlog::where([
  568. ['match_id', $match_id],
  569. ['type', 2]
  570. ])->orderBy('id', 'desc')->first();
  571. if(empty($lastLog) || !(
  572. $lastLog['u_home_score'] == $data['u_home_score']
  573. && $lastLog['u_guest_score'] == $data['u_guest_score']
  574. && $lastLog['guest_score'] == $data['guest_score']
  575. && $lastLog['home_score'] == $data['home_score']
  576. )){
  577. $logData = $data;
  578. $logData['type'] = 2;
  579. $logData['match_id'] = $match_id;
  580. $logData['user_id'] = session('adminInfo.admin_id');
  581. $logData['create_at'] = now();
  582. \App\Models\Stbqresultlog::insert($logData);
  583. }
  584. return responseToJson(1);
  585. }
  586. //获取赛事进程数据
  587. function getprocess(Req $req){
  588. $type = $req->type;
  589. $process = commonFunction::getprocess($type);
  590. return json_encode($process);
  591. }
  592. }