SportsbkController.php 28 KB

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