SportsbkController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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. if(count($simplex_ids)>0 || count($str_ids)>0){
  308. //单式结算
  309. if(count($simplex_ids)>0 && count($str_ids)==0){
  310. $sim['order_ids'] = implode(',',$simplex_ids);
  311. $settlesim = $settlementAuto->SubmitSettelement('s',$sim);
  312. if($settlesim == false){
  313. return json_encode(['status'=>3,'msg'=>'单式注单结算有误,请联系管理员!!!']);
  314. }else{
  315. return json_encode(['status'=>1,'msg'=>'单式结算成功,没有串式订单']);
  316. }
  317. }
  318. //串式结算
  319. elseif(count($str_ids)>0 && count($simplex_ids)==0){
  320. $str['order_ids'] = implode(',',$str_ids);
  321. $settlestr = $settlementAuto->SubmitSettelement('s',$str);
  322. if($settlestr == false){
  323. return json_encode(['status'=>3,'msg'=>'串式注单结算有误,请联系管理员!!!']);
  324. }else{
  325. return json_encode(['status'=>1,'msg'=>'串式结算成功,没有单式订单']);
  326. }
  327. }
  328. //既有单式也有串式
  329. elseif(count($str_ids)>0 && count($simplex_ids)>0){
  330. $sim['order_ids'] = implode(',',$simplex_ids);
  331. $str['order_ids'] = implode(',',$str_ids);
  332. $settlesim = $settlementAuto->SubmitSettelement('s',$sim);
  333. $settlestr = $settlementAuto->SubmitSettelement('s',$str);
  334. if($settlesim == true || $settlestr == true){
  335. return json_encode(['status'=>1,'msg'=>'结算成功']);
  336. }else{
  337. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!']);
  338. }
  339. }
  340. }else{
  341. $log = array(
  342. session('adminInfo.admin_name'),
  343. );
  344. OperationLog(session('adminInfo.admin_id'), '蓝球结算', $log);
  345. if($match['status'] == 0 || $match['status'] == 1){
  346. return json_encode(['status'=>4,'msg'=>'该赛事进程下没有任何订单']);
  347. }
  348. $res = \App\Models\Stlqresult::where ('match_id', $match_id)->update(['status' =>3]);
  349. $res = \App\Models\SportsBasket::where ('id', $match_id)->update(['status' =>3]);
  350. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  351. }
  352. }
  353. //结算
  354. function Settlementlq(Req $req){
  355. $jsurl = config('sconstant.url');//结算请求域名地址
  356. $match_id = $req->match_id;
  357. $type = $req->type;
  358. $token = session('adminInfo.token');
  359. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  360. $noticeid = $notice['id'];
  361. if(!$notice){
  362. return json_encode(['status'=>5,'msg'=>'请先核对结果,并提交结果']);
  363. }
  364. //查询赛事单式是否有订单(篮球)
  365. $newapp = new \App\Models\MoneyBuyMatch();
  366. $simplex_ids = array_column($newapp->simsettleorder($match_id,'lq'),'order_id');
  367. $str_ids = array_column($newapp->strsettleorder($match_id),'order_id');
  368. //去重
  369. $simplex_ids = array_unique($simplex_ids);
  370. $str_ids = array_unique($str_ids);
  371. //判断赛事下注单输赢
  372. $datas = array('noticeid' => $noticeid , 'token' => $token);
  373. $settlementAuto = new \App\Lib\Settlement\SettlementAuto();
  374. $winfail = $settlementAuto->SubmitSettelement('w',$datas);
  375. if($winfail == false){
  376. return json_encode(['status'=>2,'msg'=>'判断输赢错误,请联系管理员!!!']);//输赢错误
  377. }
  378. $sim = array(
  379. 'token'=>$token,
  380. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  381. 'bettype'=>1, //结算类型 1单式 2串式
  382. 'settype'=>2, //结算次数 1首次 2非首冷饮
  383. 'game_code'=>$type, //赛事类型 zq lq wq bq
  384. 'match_id'=>$match_id, // 赛事ID
  385. 'change_status'=>1 //是否改状态
  386. );
  387. $str = array(
  388. 'token'=>$token,
  389. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  390. 'bettype'=>2, //结算类型 1单式 2串式
  391. 'settype'=>2, //结算次数 1首次 2非首冷饮
  392. 'game_code'=>$type, //赛事类型 zq lq wq bq
  393. 'match_id'=>$match_id, // 赛事ID
  394. 'change_status'=>1 //是否改状态
  395. );
  396. if(count($simplex_ids)>0 || count($str_ids)>0){
  397. //单式结算
  398. if(count($simplex_ids)>0 && count($str_ids)==0){
  399. $sim['order_ids'] = implode(',',$simplex_ids);
  400. $settlesim = $settlementAuto->SubmitSettelement('s',$sim);
  401. if($settlesim == false){
  402. return json_encode(['status'=>3,'msg'=>'单式注单结算有误,请联系管理员!!!']);
  403. }else{
  404. return json_encode(['status'=>1,'msg'=>'单式结算成功,没有串式订单']);
  405. }
  406. }
  407. elseif(count($str_ids)>0 && count($simplex_ids)==0){
  408. $str['order_ids'] = implode(',',$str_ids);
  409. $settlestr = $settlementAuto->SubmitSettelement('s',$str);
  410. if($settlestr == false){
  411. return json_encode(['status'=>3,'msg'=>'串式注单结算有误,请联系管理员!!!']);
  412. }else{
  413. return json_encode(['status'=>1,'msg'=>'串式结算成功,没有单式订单']);
  414. }
  415. }
  416. elseif(count($str_ids)>0 && count($simplex_ids)>0){
  417. $sim['order_ids'] = implode(',',$simplex_ids);
  418. $str['order_ids'] = implode(',',$str_ids);
  419. $settlesim = $settlementAuto->SubmitSettelement('s',$sim);
  420. $settlestr = $settlementAuto->SubmitSettelement('s',$str);
  421. if($settlesim == true || $settlestr == true){
  422. return json_encode(['status'=>1,'msg'=>'结算成功']);
  423. }else{
  424. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!']);
  425. }
  426. }
  427. }else{
  428. $log = array(
  429. session('adminInfo.admin_name'),
  430. );
  431. OperationLog(session('adminInfo.admin_id'), '篮球结算', $log);
  432. $res = \App\Models\Stlqresult::where ('match_id', $match_id)->update(['status' =>3]);
  433. $res = \App\Models\SportsBasket::where ('id', $match_id)->update(['status' =>3]);
  434. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  435. }
  436. }
  437. function info() {
  438. $page = Request::has('page') ? Request::get('page') : '';
  439. $list = Request::has('limit') ? Request::get('limit') : 1;
  440. $home_team = Request::has('home_team') ? Request::get('home_team') : '';
  441. $sureblurs = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  442. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  443. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  444. $status = Request::has('status') ? Request::get('status') : '';
  445. $if_order = Request::has('if_order') ? Request::get('if_order') : '';
  446. $where = array();
  447. $orwhere = array();
  448. if (!empty($home_team)) {
  449. if (empty($sureblurs) || $sureblurs == 'off') {
  450. $where[] = array('st_lq_result.home_team', 'like', '%' . $home_team . '%');
  451. $orwhere[] = array('st_lq_result.guest_team', 'like', '%' . $home_team . '%');
  452. } else {
  453. if(is_numeric($home_team)){
  454. $where[] = array('st_lq_result.match_id', '=', $home_team);
  455. $orwhere[] = array('st_lq_result.match_id', '=', $home_team);
  456. }else{
  457. $where[] = array('st_lq_result.home_team', '=', $home_team);
  458. $orwhere[] = array('st_lq_result.guest_team', '=', $home_team);
  459. }
  460. }
  461. }
  462. if (!empty($star_time) and empty($home_team)) {
  463. $star_time = date('Y-m-d H:i:s', strtotime($star_time));
  464. $where[] = array('st_lq_result.start_time', '>', $star_time);
  465. $orwhere[] = array('st_lq_result.start_time', '>', $star_time);
  466. }
  467. if (!empty($end_time) and empty($home_team)) {
  468. $end_time = date('Y-m-d H:i:s', strtotime($end_time));
  469. $where[] = array('st_lq_result.start_time', '<', $end_time);
  470. $orwhere[] = array('st_lq_result.start_time', '<', $end_time);
  471. }
  472. if ($status != -1) {
  473. $where[] = array('st_lq_competition.status', '=', $status);
  474. $orwhere[] = array('st_lq_competition.status', '=', $status);
  475. }
  476. $newapp = new \App\Models\Stlqresult();
  477. $data = $newapp->resultbklist($list, $page, $where, $orwhere,$if_order);
  478. for ($i=0; $i < count($data['data']); $i++) {
  479. $home_score = json_decode($data['data'][$i]['home_score'],true);
  480. $guest_score = json_decode($data['data'][$i]['guest_score'],true);
  481. $data['data'][$i]['okteamscore'] = $guest_score[1];//第一节客队比分
  482. $data['data'][$i]['ozteamscore'] = $home_score[1];//第一节主队比分
  483. $data['data'][$i]['tkteamscore'] = $guest_score[2];//第二节客队比分
  484. $data['data'][$i]['tzteamscore'] = $home_score[2];//第二节主队比分
  485. $data['data'][$i]['skteamscore'] = $guest_score[3];//第三节客队比分
  486. $data['data'][$i]['szteamscore'] = $home_score[3];//第三节主队比分
  487. $data['data'][$i]['akteamscore'] = $guest_score[4];//第四节客队比分
  488. $data['data'][$i]['azteamscore'] = $home_score[4];//第四节主队比分
  489. if(empty($data['data'][$i]['match_score'])){
  490. $data['data'][$i]['home_scores'] = 0;
  491. $data['data'][$i]['guest_scores'] = 0;
  492. }else{
  493. $scores = explode(':',$data['data'][$i]['match_score']);
  494. $data['data'][$i]['home_scores'] = $scores[0];
  495. $data['data'][$i]['guest_scores'] = $scores[1];
  496. }
  497. }
  498. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  499. }
  500. //修改添加赛事比分
  501. function updatascore(Req $req){
  502. $match_id = $req->match_id;//节数唯一标识
  503. $model = \App\Models\Stlqresult::where('match_id', $match_id)->first();
  504. $model->update_time = date('Y-m-d H:i:s');
  505. //赛事状态
  506. $match_status = intval($req->match_status)?intval($req->match_status):0;
  507. $guestscore =array(
  508. '1' => intval($req->okteamscore)?intval($req->okteamscore):0,//第一节客队比分
  509. '2' => intval($req->tkteamscore)?intval($req->tkteamscore):0,//第二节客队比分
  510. '3' => intval($req->skteamscore)?intval($req->skteamscore):0,//第三节客队比分
  511. '4' => intval($req->akteamscore)?intval($req->akteamscore):0,//第四节客队比分
  512. );
  513. $homescore =array(
  514. '1' => intval($req->ozteamscore)?intval($req->ozteamscore):0,//第一节主队比分
  515. '2' => intval($req->tzteamscore)?intval($req->tzteamscore):0,//第二节主队比分
  516. '3' => intval($req->szteamscore)?intval($req->szteamscore):0,//第三节主队比分
  517. '4' => intval($req->azteamscore)?intval($req->azteamscore):0,//第四节主队比分
  518. );
  519. $model->guest_score = json_encode($guestscore);
  520. $model->home_score = json_encode($homescore);
  521. $model->is_correct = 1;//追加手动更改标识
  522. $model->save();
  523. //更新比分 默认 status
  524. $status = 2;
  525. //赛事下注单作废 处理
  526. $data = array_merge($guestscore,$homescore);
  527. if(in_array(-1,$data)){
  528. commonFunction::HandleInvalid($data,$match_id,$match_status,'lq');
  529. }
  530. /*
  531. //追加判断比分 如果都== -1,则作废该赛事
  532. 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 ){
  533. //已结算作废赛事处理
  534. if($match_status == 3){
  535. $url = 'http://stadmin.bocai108.com:9094/UnSettelement';
  536. $data_up = [
  537. 'token'=>session('adminInfo.token'),
  538. 'game_code'=>'lq',
  539. 'match_id'=>$match_id,
  540. ];
  541. $ret_json = commonFunction::https_request($url,$data_up);
  542. // $ret_json = '{"status":1,"msg":"撤销成功!2019-10-26 16:28:30 取消赛事处理--结束end:game_code= zq match_id= 40986 \n","data":[]}';
  543. $ret_arr = json_decode($ret_json,true);
  544. if($ret_arr['status'] != 1){
  545. return responseToJson(-20003);
  546. }
  547. }
  548. //赛事下单式注单作废,串关注单下此赛事按平局处理
  549. $upapp = new \App\Models\SportsNoteList();
  550. $upapp->delorder($match_id,'lq');
  551. $status = 4;
  552. }
  553. */
  554. $addnew = new \App\Models\Comendnotice();
  555. $addnew->addcomendnotice($match_id,'lq');
  556. $twoapp = new \App\Models\SportsBasket();
  557. $twoapp->updatestatus('match_id',$match_id,['status'=>$status,'utime'=>date('Y-m-d H:i:s')]);//修改赛事状态
  558. $newapp = new \App\Models\Stlqresult();
  559. $newapp->updatestatus('match_id',$match_id,['status'=>$status,'update_time'=>date('Y-m-d H:i:s')]);//修改结果状态
  560. //添加赛事结果比较记录
  561. $lastLog = \App\Models\Stlqresultlog::where([
  562. ['match_id', $match_id],
  563. ['type', 2]
  564. ])->orderBy('id', 'desc')->first();
  565. if(empty($lastLog) || !(
  566. $lastLog['guest_score'] == $model->guest_score
  567. && $lastLog['home_score'] == $model->home_score
  568. )){
  569. $logData = [
  570. 'guest_score' => $model->guest_score,
  571. 'home_score' => $model->home_score,
  572. 'type' => 2,
  573. 'match_id' => $match_id,
  574. 'user_id' => session('adminInfo.admin_id'),
  575. 'create_at' => now()
  576. ];
  577. \App\Models\Stlqresultlog::insert($logData);
  578. }
  579. return responseToJson(1);
  580. }
  581. function saislist(){
  582. $lgid = $_POST['lgid'];//赛事id
  583. $newstzqcompetition = new \App\Models\SportsBasket();
  584. $league_data = $newstzqcompetition->allcompetition($lgid);//赛事id
  585. return $league_data;
  586. }
  587. function addoutcome(Req $req) {
  588. if (!$req->isMethod('post')) {
  589. $lange = trans('menu');
  590. $newapp = new \App\Models\BasketLeague();
  591. $league_data = $newapp->allleague();//联赛id
  592. return view('admin.sportsbk/addoutcome',['data'=>$league_data]);
  593. }else{
  594. $model = new \App\Models\Stlqresult();
  595. $model->lg_id = trim($req->input('lg_id'));//联赛id
  596. $model->home_team = trim($req->input('home_team'));
  597. $model->guest_team = trim($req->input('guest_team'));
  598. $model->home_rate = trim($req->input('home_rate'));
  599. $model->guest_rate = trim($req->input('guest_rate'));
  600. $model->home_score = trim($req->input('home_score'));
  601. $model->guest_score = trim($req->input('guest_score'));
  602. $model->all_goal = trim($req->input('all_goal'));
  603. $model->match_score = trim($req->input('match_score'));
  604. $model->u_home_score = trim($req->input('u_home_score'));
  605. $model->u_guest_score = trim($req->input('u_guest_score'));
  606. $model->update_time = date('Y-m-d h:i:s', time());//更新时间
  607. $model->match_time = "11:22";//trim($req->input('match_time'));
  608. $model->tag = trim($req->input('tag'));
  609. $model->status = trim($req->input('status'));
  610. $model->match_process = trim($req->input('match_process'));
  611. $model->match_id = trim($req->input('match_id'));//赛事id
  612. $model->save();
  613. return responseToJson(1);
  614. }
  615. }
  616. //赛事结果修改
  617. function edit(Req $req) {
  618. $id = $req->id;
  619. if (intval($id) < 1) {
  620. return -1;
  621. }
  622. if (!$req->isMethod('post')) {
  623. $data = \App\Models\Stlqresult::where('id', $id)->first();
  624. if (!$data) {
  625. return -2;
  626. }
  627. $data = $data->toArray();
  628. return view('admin.sportsbk/edit', $data);
  629. } else {
  630. $model = \App\Models\Stlqresult::where('id', $id)->first();
  631. $model->home_team = $req->input('home_team');
  632. $model->guest_team = $req->input('guest_team');
  633. $model->home_rate = $req->input('home_rate');
  634. $model->guest_rate = $req->input('guest_rate');
  635. $model->status = $req->input('status');
  636. //$model->update_time = time();
  637. $model->save();
  638. return responseToJson(1);
  639. }
  640. }
  641. //删除赛事结果
  642. function deleteoutcome(Req $req) {
  643. $id = $req->input('id');
  644. if (empty($id)) {
  645. return responseToJson(-2001); //
  646. }
  647. $ids = explode(',', $id);
  648. if (!is_array($ids) && intval($ids) < 0) {
  649. return responseToJson(-2002); //
  650. }
  651. if (is_array($ids) && count($ids) > 0) {
  652. foreach ($ids as $k => $v) {
  653. if (intval($v) < 1) {
  654. unset($ids[$k]);
  655. }
  656. }
  657. }
  658. // echo '敬请期待';die;
  659. $rows = \App\Models\Stlqresult::whereIn('id', $ids)->delete();
  660. if (!$rows) {
  661. return responseToJson(-2003);
  662. }
  663. return responseToJson(1);
  664. }
  665. //获取赛事进程数据
  666. function getprocess(Req $req){
  667. $type = $req->type;
  668. $process = commonFunction::getprocess($type);
  669. return json_encode($process);
  670. }
  671. }