SportsbkController.php 28 KB

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