SportsbkController.php 27 KB

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