SportsbqController.php 26 KB

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