SportsbkController.php 18 KB

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