SportsfootController.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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. /**
  10. *足球结算
  11. */
  12. class SportsfootController extends Controller {
  13. function Settlement(Req $req){
  14. $jsurl = config('sconstant.url');//结算请求域名地址
  15. $match_id = $req->match_id;
  16. $type = $req->type;
  17. $token = session('adminInfo.token');
  18. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  19. $noticeid = $notice['id'];
  20. //查询赛事单式是否有订单(足球)
  21. $newapp = new \App\Models\MoneyBuyMatch();
  22. $simplex_ids = array_column($newapp->allsimplexorder($match_id,'zq'),'order_id');
  23. $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  24. if(count($simplex_ids)>0 || count($str_ids)>0){
  25. $requet = file_get_contents($jsurl."/WinFail?noticeid=".$noticeid."&token=".$token);
  26. if(json_decode($requet,true)['status']==1){
  27. $napp = new \App\Models\Stzqresult();
  28. //单式结算
  29. if($simplex_ids){
  30. $simplex = array(
  31. 'token'=>$token,
  32. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  33. 'bettype'=>1, //结算类型 1单式 2串式
  34. 'settype'=>2, //结算次数 1首次 2非首冷饮
  35. 'game_code'=>'zq', //赛事类型 zq lq wq bq
  36. 'match_id'=>$match_id, // 赛事ID
  37. 'change_status'=>1 //是否改状态
  38. );
  39. $url=$jsurl.'/Settelement';
  40. $simplex_res = $napp->post_curls($url,$simplex);//返回json
  41. $huawei_res = json_decode($simplex_res,true);
  42. }else{
  43. $huawei_res['status'] =1;
  44. }
  45. //串式结算
  46. if($str_ids){
  47. $tandem = array(
  48. 'token'=>$token,
  49. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  50. 'bettype'=>2, //结算类型 1单式 2串式
  51. 'settype'=>2, //结算次数 1首次 2非首冷饮
  52. 'game_code'=>'zq', //赛事类型 zq lq wq bq
  53. 'match_id'=>$match_id, // 赛事ID
  54. 'change_status'=>1 //是否改状态
  55. );
  56. $url=$jsurl.'/Settelement';
  57. $tandem_res = $napp->post_curls($url,$tandem);//返回json
  58. $tandem_res = json_decode($tandem_res,true);
  59. }else{
  60. $tandem_res['status'] =1;
  61. }
  62. if($huawei_res['status']==1 || $tandem_res['status']==1){
  63. return json_encode(['status'=>1,'msg'=>'结算成功']);
  64. }else{
  65. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!']);//结算错误
  66. }
  67. }else{
  68. return json_encode(['status'=>2,'msg'=>'结算有错,请联系管理员!!!']);;//输赢错误
  69. }
  70. }else{
  71. $res = \App\Models\Stzqresult::where ('match_id', $match_id)->update(['status' =>3]);
  72. $res = \App\Models\SportsSoccer::where ('match_id', $match_id)->update(['status' =>3]);
  73. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  74. }
  75. }
  76. //添加危险球列表
  77. function addwarn(Req $req){
  78. $match_id = $req->match_id;
  79. $warn = \App\Models\Stzqresult::where('match_id', $match_id)->select("warn_more")->first();
  80. $request['warnmore'] = json_decode($warn['warn_more'],true);
  81. // $sousuo = $req->sousuo;
  82. // if($sousuo){
  83. // for ($i=0; $i < count($request['warnmore']); $i++) {
  84. // if($request['warnmore'][$i]['rtype']==$sousuo){
  85. // $array[$i]['timei'] = $request['warnmore'][$i]['timei'];
  86. // $array[$i]['rtype'] = $request['warnmore'][$i]['rtype'];
  87. // }
  88. // // unset($array2D[2]);//删除
  89. // }
  90. // $request['warnmore'] = $array;
  91. // }
  92. $request['match_id'] = $match_id;
  93. return view('admin.sportsfoot/addwarn', $request);
  94. }
  95. //危险球查询
  96. function warnresult(Req $req){
  97. $match_id = $req->match_id;
  98. $wid = $req->wid;
  99. $warnonlys = \App\Models\Stzqresult::where('match_id', $match_id)->select("warn_more","start_time")->first();
  100. $warno = array(
  101. 'warn_more' => json_decode($warnonlys['warn_more'],true),
  102. 'starttime' => $warnonlys['start_time'],
  103. );
  104. return $warno;
  105. }
  106. //添加编辑危险球
  107. function addwarnonly(Req $req){
  108. $matchid = $req->matchid;
  109. $wid = $req->wid;//编辑对象值
  110. $timei = $req->timei?$req->timei:"1970-11-1 0:0:1";
  111. $rtype = $req->warntype?$req->warntype:0;
  112. $typenum = $req->typenum;
  113. $model = \App\Models\Stzqresult::where('match_id', $matchid)->select("warn_more","start_time")->first()->toArray();
  114. $sel = json_decode($model['warn_more'],true);
  115. $addru = array(
  116. array(
  117. 'timei'=>$timei,
  118. 'rtype'=>$rtype,
  119. ),
  120. );
  121. $only =$model['start_time'];
  122. $t = strtotime($only);
  123. $tt = date('Y-m-d H:i:s', $t+1*3*60*60);
  124. if($only<$timei && $timei<$tt){
  125. if($typenum==10000){
  126. if($sel[0]['rtype']==0){
  127. //首次添加
  128. $res = \App\Models\Stzqresult::where ('match_id', $matchid)->update(['warn_more' => json_encode($addru)]);
  129. }else{
  130. //再次添加
  131. $upnum = array_merge_recursive($sel,$addru);
  132. $res = \App\Models\Stzqresult::where ('match_id', $matchid)->update(['warn_more' => json_encode($upnum)]);
  133. }
  134. }else{
  135. //编辑
  136. for ($i=0; $i < count($sel); $i++) {
  137. $sel[$wid]['timei'] = $timei;
  138. $sel[$wid]['rtype'] = $rtype;
  139. }
  140. $res = \App\Models\Stzqresult::where ('match_id', $matchid)->update(['warn_more' => json_encode($sel)]);
  141. }
  142. }else{
  143. return json_encode(['status'=>2,'msg'=>'请设置正确时间']);
  144. }
  145. return responseToJson(1);
  146. }
  147. //足球结果列表
  148. function outcome(Req $req) {
  149. $request=array();
  150. $request['home_team'] = isset($req->home_team) ? trim($req->home_team) : null;
  151. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  152. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  153. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) :trans('status.default_time.seven_day') ;
  154. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : trans('status.default_time.etime');
  155. $newapp = new \App\Models\SoccerLeague();
  156. $data = $newapp->allleague();
  157. $request['league'] = $data;//联赛id
  158. $request['token'] = session('adminInfo.token');//token 变量
  159. $dt = \App\Lib\DataTable\DataTable::init();
  160. $dt->setDataSource('/admin/sportsfoot/outcomeinfo');
  161. $dt->setLang('sportsfoot');
  162. $dt->addColsFields('newtime', array('templet' => '#newtime', 'sort' => false, 'width' => 200));
  163. $dt->addColsFields('totime', array('templet' => '#totime', 'sort' => false, 'width' => 80));
  164. $dt->addColsFields('home_team', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  165. $dt->addColsFields('guest_team', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  166. $dt->addColsFields('dsnum', array('templet' => '#dsnum', 'sort' => false, 'width' => 70));
  167. $dt->addColsFields('csnum', array('templet' => '#csnum', 'sort' => false, 'width' => 110));
  168. $dt->addColsFields('sxalfcourt', array('templet' => '#sxalfcourt', 'sort' => false, 'width' => 300));
  169. $dt->addColsFields('statusmatch', array('templet' => '#statusmatch', 'sort' => false, 'width' => 150,'align' => 'left'));
  170. $dt->addColsFields('operation', array('templet' => '#status', 'sort' => false, 'width' => 300));
  171. // $arr[] = 'view';
  172. // if (checkRriv('/admin/sportsfoot/edit')) {
  173. // $arr[] = 'edit';
  174. // }
  175. // $dt->setToolBar($arr, array('width' => 200));
  176. $dt->enableCheckBox();
  177. return view('admin.sportsfoot/outcome', $dt->render($request));
  178. }
  179. //结果添加
  180. function addend(Req $req){
  181. $match_id = $req->matchid;
  182. $model = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  183. $penaltycard = array(
  184. 'home'=>intval($req->homeallcard)?intval($req->homeallcard):0,
  185. 'guest'=>intval($req->guestallcard)?intval($req->guestallcard):0,
  186. 'home_half'=>intval($req->homehalfcard)?intval($req->homehalfcard):0,
  187. 'guest_half'=>intval($req->guesthalfcard)?intval($req->guesthalfcard):0,
  188. );
  189. $cornerball = array(
  190. 'home'=>intval($req->homeallcorner)?intval($req->homeallcorner):0,
  191. 'guest'=>intval($req->guestallcorner)?intval($req->guestallcorner):0,
  192. 'home_half'=>intval($req->homehalfcorner)?intval($req->homehalfcorner):0,
  193. 'guest_half'=>intval($req->guesthalfcorner)?intval($req->guesthalfcorner):0,
  194. );
  195. $firstone = array(
  196. 'teamscore'=>$req->firstscore ? $req->firstscore:0,
  197. 'scoretime'=>intval($req->onescoretime)?intval($req->onescoretime):0,
  198. 'scoretype'=>$req->firststye ? $req->firststye:0,
  199. );
  200. $model->last_score = $req->lastscore;
  201. $model->match_winer = $req->matchwiner;
  202. $model->penalty_card = json_encode($penaltycard);
  203. $model->corner_ball = json_encode($cornerball);
  204. $model->first_score = json_encode($firstone);
  205. $model->save();
  206. return responseToJson(1);
  207. }
  208. //查询赛事结果
  209. function Matchresult(Req $req){
  210. $match_id = $req->match_id;
  211. $newapp = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  212. $array =array(
  213. 'corner_ball' => json_decode($newapp['corner_ball'],true),
  214. 'penalty_card' => json_decode($newapp['penalty_card'],true),
  215. 'first_score' => json_decode($newapp['first_score'],true),
  216. 'newapp' => $newapp,
  217. );
  218. return $array;
  219. }
  220. function onlyresult(Req $req){
  221. $match_id = $req->matchid;
  222. $newapp = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  223. return $newapp;
  224. }
  225. //结算 allhalf全场1,半场0
  226. // function Settlement(Req $req){
  227. // $allhalf = $req->allhalf?$req->allhalf:'';
  228. // if(intval($allhalf)){
  229. // //赛事id
  230. // $id = $req->input('id');
  231. // if (empty($id)) {
  232. // return responseToJson(-2001); //
  233. // }
  234. // $ids = explode(',', $id);
  235. // if (!is_array($ids) && intval($ids) < 0) {
  236. // return responseToJson(-2002); //
  237. // }
  238. // if (is_array($ids) && count($ids) > 0) {
  239. // foreach ($ids as $k => $v) {
  240. // if (intval($v) < 1) {
  241. // unset($ids[$k]);
  242. // }
  243. // }
  244. // }
  245. // for ($i=0; $i < count($ids); $i++) {
  246. // $model = \App\Models\Stzqresult::where('id', $ids[$i])->select("match_id","status")->first();
  247. // //查询赛事下所有订单
  248. // $ssid = $model['match_id'];//赛事id
  249. // if($model['status']==2){
  250. // $type = 1;;//是否再结算1,首次结算2,再次结算
  251. // }else{
  252. // $type = 2;
  253. // }
  254. // $newapp = new \App\Models\MoneyBuyMatch();
  255. // $simplex_ids = array_column($newapp->allsimplexorder($ssid,'zq'),'order_id');
  256. // $str_ids = array_column($newapp->allstrorder($ssid),'order_id');
  257. // $data = \App\Models\Comendnotice::where(['match_id'=>$ssid,'game_code'=>'zq'])->first();
  258. // if($data){
  259. // $tapp = new \App\Lib\Settlement\SettlementWinFail();
  260. // \App\Models\Comendnotice::where(['match_id'=>$ssid,'game_code'=>'zq'])->update(['status'=>0]);
  261. // $ret = $tapp->doRun($data->toArray()['id']);
  262. // $ret2 =$data->toArray()['id'];
  263. // if ($ret2['status']==1){
  264. // \App\Models\Comendnotice::where(['match_id'=>$ssid,'game_code'=>'zq'])->update(['status'=>4]);
  265. // }
  266. // }
  267. // $SettlementOrder = new SettlementOrder();
  268. // $SettlementOrder->reSettlement($str_ids, 2,$type,'zq',$ssid,$allhalf);//串式
  269. // $data = $SettlementOrder->reSettlement($simplex_ids, 1,$type,'zq',$ssid,$allhalf);//单式注单
  270. // }
  271. // return responseToJson(1);
  272. // }else{
  273. // //查询赛事下所有订单
  274. // $ssid = $req->match_id;//赛事id
  275. // $type = $req->type;//是否再结算1,首次结算2,再次结算
  276. // $newapp = new \App\Models\MoneyBuyMatch();
  277. // $simplex_ids = array_column($newapp->allsimplexorder($ssid,'zq'),'order_id');
  278. // $str_ids = array_column($newapp->allstrorder($ssid),'order_id');
  279. // $data = \App\Models\Comendnotice::where(['match_id'=>$ssid,'game_code'=>'zq'])->first();
  280. // if($data){
  281. // $tapp = new \App\Lib\Settlement\SettlementWinFail();
  282. // \App\Models\Comendnotice::where(['match_id'=>$ssid,'game_code'=>'zq'])->update(['status'=>0]);
  283. // $ret = $tapp->doRun($data->toArray()['id']);
  284. // $ret2 =$data->toArray()['id'];
  285. // if ($ret2['status']==1){
  286. // \App\Models\Comendnotice::where(['match_id'=>$ssid,'game_code'=>'zq'])->update(['status'=>4]);
  287. // }
  288. // if($ret['status']==1){
  289. // $SettlementOrder = new SettlementOrder();
  290. // $SettlementOrder->reSettlement($str_ids, 2,$type,'zq',$ssid);//串式
  291. // $nda = $SettlementOrder->reSettlement($simplex_ids, 1,$type,'zq',$ssid);//单式注单
  292. // return responseToJson($nda);
  293. // }else{
  294. // return responseToJson($ret);
  295. // }
  296. // }
  297. // }
  298. // }
  299. //作废
  300. function revokeft(Req $req){
  301. $iszf = $req->iszf?$req->iszf:'';//赛事id
  302. if(intval($iszf)){
  303. $id = $req->input('id');
  304. if (empty($id)) {
  305. return responseToJson(-2001); //
  306. }
  307. $ids = explode(',', $id);
  308. if (!is_array($ids) && intval($ids) < 0) {
  309. return responseToJson(-2002); //
  310. }
  311. if (is_array($ids) && count($ids) > 0) {
  312. foreach ($ids as $k => $v) {
  313. if (intval($v) < 1) {
  314. unset($ids[$k]);
  315. }
  316. }
  317. }
  318. for ($ii=0; $ii < count($ids); $ii++) {
  319. $model = \App\Models\Stzqresult::where('id', $ids[$ii])->first();
  320. $model->status = 4;
  321. $model->save();
  322. $ssid = $model['match_id'];//赛事id
  323. $smodel = \App\Models\SportsSoccer::where('match_id', $ssid)->first();
  324. if($smodel){
  325. $smodel->status = 4;
  326. $smodel->save();
  327. }
  328. $upapp = new \App\Models\SportsNoteList();
  329. $data = $upapp->updatesimplex($ssid,'zq');//修改单式状态
  330. //单式撤单返现
  331. $newapp = new \App\Models\MoneyBuyMatch();
  332. $all = $newapp->allsimplexorder($ssid,'zq');
  333. for ($i=0; $i < count($all); $i++) {
  334. $appgx = new \App\Lib\Settlement\SettlementOrder();
  335. $appgx->insertData($all[$i]['order_id'], $all[$i]['money'], $all[$i]['account_identity'], '1', 'zq', $all[$i]['info_identity'], $all[$i]['money'],$all[$i]['match_id']);
  336. }
  337. //串式撤单只改状态
  338. $str_ids = array_column($newapp->allstrorder($ssid),'order_id');
  339. $csapp = new \App\Models\MoneyBuyStr();
  340. $csapp->updatestatus($str_ids);//var_dump($ss);die;
  341. //修改money_buy_match 投注结果result=2为平
  342. $newapp->updatast($ssid);
  343. }
  344. return responseToJson(1);
  345. }else{
  346. $match_id = $req->match_id;//赛事id
  347. $model = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  348. $model->status = 4;
  349. $model->save();
  350. $smodel = \App\Models\SportsSoccer::where('match_id', $match_id)->first();
  351. if($smodel){
  352. $smodel->status = 4;
  353. $smodel->save();
  354. }
  355. $upapp = new \App\Models\SportsNoteList();
  356. $data = $upapp->updatesimplex($match_id,'zq');//修改单式状态
  357. //单式撤单返现
  358. $newapp = new \App\Models\MoneyBuyMatch();
  359. $all = $newapp->allsimplexorder($match_id,'zq');
  360. for ($i=0; $i < count($all); $i++) {
  361. $appgx = new \App\Lib\Settlement\SettlementOrder();
  362. $appgx->insertData($all[$i]['order_id'], $all[$i]['money'], $all[$i]['account_identity'], '1', 'zq', $all[$i]['info_identity'], $all[$i]['money'],$all[$i]['match_id']);
  363. }
  364. //串式撤单只改状态
  365. $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  366. $csapp = new \App\Models\MoneyBuyStr();
  367. $csapp->updatestatus($str_ids);//var_dump($ss);die;
  368. //修改money_buy_match 投注结果result=2为平
  369. $newapp->updatast($match_id);
  370. return responseToJson(1);
  371. }
  372. }
  373. //赛事结果修改
  374. function edit(Req $req) {
  375. $id = $req->id;
  376. if (intval($id) < 1) {
  377. return -1;
  378. }
  379. if (!$req->isMethod('post')) {
  380. $data = \App\Models\Stzqresult::where('id', $id)->first();
  381. if (!$data) {
  382. return -2;
  383. }
  384. $data = $data->toArray();
  385. return view('admin.sportsfoot/edit', $data);
  386. } else {
  387. $model = \App\Models\Stzqresult::where('id', $id)->first();
  388. $model->home_team = $req->input('home_team');
  389. $model->guest_team = $req->input('guest_team');
  390. $model->home_rate = $req->input('home_rate');
  391. $model->guest_rate = $req->input('guest_rate');
  392. $model->status = $req->input('status');
  393. //$model->update_time = time();
  394. $model->save();
  395. return responseToJson(1);
  396. }
  397. }
  398. function outcomeinfo() {
  399. $page = Request::has('page') ? Request::get('page') : '';
  400. $list = Request::has('limit') ? Request::get('limit') : 10;
  401. $home_team = Request::has('home_team') ? Request::get('home_team') : '';
  402. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  403. $status = Request::has('status') ? Request::get('status') : '';
  404. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  405. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  406. $where = array();
  407. $orwhere = array();
  408. if (!empty($home_team)) {
  409. if (empty($sureblur) || $sureblur == 'off') {
  410. $where[] = array('st_zq_result.home_team', 'like', '%' . $home_team . '%');
  411. $orwhere[] = array('st_zq_result.guest_team', 'like', '%' . $home_team . '%');
  412. } else {
  413. if(is_numeric($home_team)){
  414. $where[] = array('st_zq_result.match_id', '=', $home_team);
  415. }else{
  416. $where[] = array('st_zq_result.home_team', '=', $home_team);
  417. $orwhere[] = array('st_zq_result.guest_team', '=', $home_team);
  418. }
  419. }
  420. }
  421. if ($status != -1) {
  422. $where[] = array('st_zq_result.status', '=', $status);
  423. $orwhere[] = array('st_zq_result.status', '=', $status);
  424. }
  425. if(!is_numeric($home_team)){
  426. if (!empty($star_time)) {
  427. $star_time = date('Y-m-d H:i:s', strtotime($star_time));
  428. $where[] = array('st_zq_result.start_time', '>', $star_time);
  429. $orwhere[] = array('st_zq_result.start_time', '>', $star_time);
  430. }
  431. if (!empty($end_time)) {
  432. $end_time = date('Y-m-d H:i:s', strtotime($end_time));
  433. $where[] = array('st_zq_result.start_time', '<', $end_time);
  434. $orwhere[] = array('st_zq_result.start_time', '<', $end_time);
  435. }
  436. }
  437. $newapp = new \App\Models\Stzqresult();
  438. $data = $newapp->resultlist($list, $page, $where, $orwhere);
  439. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  440. }
  441. function saislist(Req $req){
  442. $lgid = $req->lgid;//赛事id
  443. $newstzqcompetition = new \App\Models\Stzqcompetition();
  444. $league_data = $newstzqcompetition->allcompetition($lgid);//赛事id
  445. return $league_data;
  446. }
  447. //赛事结果添加 guest_score 客队进球 all_goal总进球数
  448. function addoutcome(Req $req) {
  449. if (!$req->isMethod('post')) {
  450. $lange = trans('menu');
  451. $newapp = new \App\Models\SoccerLeague();
  452. $league_data = $newapp->allleague();//联赛id
  453. return view('admin.sportsfoot/addoutcome',['data'=>$league_data]);
  454. } else {
  455. $match_id = trim($req->input('match_id'));//赛事id
  456. //添加足球比赛结果表
  457. $alldata = $req->input();
  458. unset($alldata['_token']);
  459. $all_goal = intval($alldata['home_score'])+intval($alldata['guest_score']);//总进球数
  460. $penaltycard = array(
  461. 'home'=>intval($alldata['homeallcard'])?intval($alldata['homeallcard']):0,
  462. 'guest'=>intval($alldata['guestallcard'])?intval($alldata['guestallcard']):0,
  463. 'home_half'=>intval($alldata['homehalfcard'])?intval($alldata['homehalfcard']):0,
  464. 'guest_half'=>intval($alldata['guesthalfcard'])?intval($alldata['guesthalfcard']):0,
  465. );
  466. $cornerball = array(
  467. 'home'=>intval($alldata['homeallcorner'])?intval($alldata['homeallcorner']):0,
  468. 'guest'=>intval($alldata['guestallcorner'])?intval($alldata['guestallcorner']):0,
  469. 'home_half'=>intval($alldata['homehalfcorner'])?intval($alldata['homehalfcorner']):0,
  470. 'guest_half'=>intval($alldata['guesthalfcorner'])?intval($alldata['guesthalfcorner']):0,
  471. );
  472. $ret = \App\Models\Stzqresult::updateOrCreate(['match_id'=>$match_id],array_merge($alldata,['match_time'=>'00:01','update_time'=>date('Y-m-d H:i:s'),'all_goal'=>$all_goal,'penalty_card'=>json_encode($penaltycard),'corner_ball'=>json_encode($cornerball)]));
  473. //添加足球比赛结果记录表
  474. \App\Models\Stzqresultrecord::updateOrCreate(['match_id'=>$match_id,'update_time'=>date('Y-m-d H:i:s')],array_merge($alldata,['match_time'=>'00:01','update_time'=>date('Y-m-d H:i:s')]));
  475. }
  476. return responseToJson(1);
  477. }
  478. //删除赛事结果
  479. function deleteoutcome(Req $req) {
  480. $id = $req->input('id');
  481. if (empty($id)) {
  482. return responseToJson(-2001); //
  483. }
  484. $ids = explode(',', $id);
  485. if (!is_array($ids) && intval($ids) < 0) {
  486. return responseToJson(-2002); //
  487. }
  488. if (is_array($ids) && count($ids) > 0) {
  489. foreach ($ids as $k => $v) {
  490. if (intval($v) < 1) {
  491. unset($ids[$k]);
  492. }
  493. }
  494. }
  495. $rows = \App\Models\Stzqresult::whereIn('id', $ids)->delete();
  496. if (!$rows) {
  497. return responseToJson(-2003);
  498. }
  499. return responseToJson(1);
  500. }
  501. //更新赛事比分
  502. function updatenum(Req $req){
  503. $type = $req->type;
  504. $id = $req->id;
  505. $num = $req->num;
  506. $match_id = $req->match_id;
  507. $newapp = new \App\Models\Stzqresult();
  508. if($type==1){
  509. $data['u_home_score'] = $num;
  510. $res = $newapp->updateInfo($data,$id);//联赛id
  511. }else if($type==2){
  512. $data['u_guest_score'] = $num;
  513. $res = $newapp->updateInfo($data,$id);//联赛id
  514. }else if($type==3){
  515. $data['home_score'] = $num;
  516. $res = $newapp->updateInfo($data,$id);//联赛id
  517. }else{
  518. $data['guest_score'] = $num;
  519. $res = $newapp->updateInfo($data,$id);//联赛id
  520. }
  521. $newapp->totalgoal($match_id);
  522. $update = $this->addcomendnotice($match_id);
  523. $twoapp = new \App\Models\SportsSoccer();
  524. $twoapp->updatestatus('match_id',$match_id,['status'=>2]);//修改赛事状态
  525. $newapp->updatestatus('match_id',$match_id,['status'=>2]);//修改结果状态
  526. return responseToJson(1);
  527. }
  528. //添加赛事结束纪录
  529. function addcomendnotice($match_id){
  530. $data = \App\Models\Comendnotice::where(['match_id'=>$match_id,'game_code'=>'zq'])->first();
  531. if(!$data){
  532. $model = new \App\Models\Comendnotice();
  533. $model->status = 0;//联赛id
  534. $model->game_code = 'zq';
  535. $model->match_id = $match_id;//赛事id
  536. $model->ctime = date('Y-m-d H:i:s');
  537. $model->save();
  538. }
  539. return responseToJson(1);
  540. }
  541. }