SportsbkController.php 22 KB

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