SportsfootController.php 22 KB

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