status) ? trim($req->status) : '-1'; $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on'; $request['home_team'] = isset($req->home_team) ? trim($req->home_team) : null; $request['star_time'] = isset($req->star_time) ? trim($req->star_time) :trans('status.default_time.seven_day') ; $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : trans('status.default_time.etime'); $dt = \App\Lib\DataTable\DataTable::init(); $dt->setDataSource('/admin/Sportsbq/info'); $dt->setLang('Sportsbq'); $dt->addColsFields('newtime', array('templet' => '#newtime', 'sort' => false, 'width' => 200)); $dt->addColsFields('totime', array('templet' => '#totime', 'sort' => false, 'width' => 200)); $dt->addColsFields('home_team', array('templet' => '#home_team', 'sort' => false, 'width' => 80)); $dt->addColsFields('guest_team', array('templet' => '#guest_team', 'sort' => false, 'width' => 80)); $dt->addColsFields('dsnum', array('templet' => '#dsnum', 'sort' => false, 'width' => 100)); // $dt->addColsFields('csnum', array('templet' => '#home_rate', 'sort' => false, 'width' => 80)); $dt->addColsFields('csnum', array('templet' => '#csnum', 'sort' => false, 'width' => 100)); $dt->addColsFields('match_score', array( 'templet' => '#match_score','sort' => false, 'width' => 220));// $dt->addColsFields('statusmatch', array('templet' => '#statusmatch', 'sort' => false, 'width' => 80)); $dt->addColsFields('operation', array('templet' => '#operation', 'sort' => false, 'width' => 300)); $dt->enableCheckBox(); return view('admin.Sportsbq/outcome', $dt->render($request)); } function info(){ $page = Request::has('page') ? Request::get('page') : ''; $list = Request::has('limit') ? Request::get('limit') : 10; $home_team = Request::has('home_team') ? Request::get('home_team') : ''; $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off'; $status = Request::has('status') ? Request::get('status') : ''; $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : ''; $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : ''; $where = array(); $orwhere = array(); if (!empty($home_team)) { if (empty($sureblur) || $sureblur == 'off') { $where[] = array('st_bq_result.home_team', 'like', '%' . $home_team . '%'); $orwhere[] = array('st_bq_result.guest_team', 'like', '%' . $home_team . '%'); } else { if(is_numeric($home_team)){ $where[] = array('st_bq_result.match_id', '=', $home_team); $orwhere[] = array('st_bq_result.match_id', '=', $home_team); }else{ $where[] = array('st_bq_result.home_team', '=', $home_team); $orwhere[] = array('st_bq_result.guest_team', '=', $home_team); } } } // if ($status != -1) { $where[] = array('st_bq_competition.status', '=', $status); $orwhere[] = array('st_bq_competition.status', '=', $status); } if (!empty($star_time) and empty($home_team)) { $star_time = date('Y-m-d H:i:s', strtotime($star_time)); $where[] = array('st_bq_result.start_time', '>', $star_time); $orwhere[] = array('st_bq_result.start_time', '>', $star_time); } if (!empty($end_time) and empty($home_team)) { $end_time = date('Y-m-d H:i:s', strtotime($end_time)); $where[] = array('st_bq_result.start_time', '<', $end_time); $orwhere[] = array('st_bq_result.start_time', '<', $end_time); } $newapp = new \App\Models\Stbqresult(); $data = $newapp->getinfo($list, $page, $where,$orwhere); return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']); } //作废 function revoke(Req $req){ $match_id = $req->match_id;//赛事id $model = \App\Models\Stbqresult::where('match_id', $match_id)->first(); $model->status = 4; $model->save(); $smodel = \App\Models\SportsBase::where('id', $match_id)->first(); if($smodel){ $smodel->status = 4; $smodel->save(); } //赛事下单式注单作废,串关注单下此赛事按平局处理 $upapp = new \App\Models\SportsNoteList(); $upapp->delorder($match_id,'bq'); // $upapp = new \App\Models\SportsNoteList(); // $data = $upapp->updatesimplex($match_id,'bq');//修改单式状态 // // //单式撤单返现 // $newapp = new \App\Models\MoneyBuyMatch(); // $all = $newapp->allsimplexorder($match_id,'bq'); // for ($i=0; $i < count($all); $i++) { // $appgx = new \App\Lib\Settlement\SettlementOrder(); // $appgx->insertData($all[$i]['order_id'], $all[$i]['money'], $all[$i]['account_identity'], '1', 'bq', $all[$i]['info_identity'], $all[$i]['money'],$all[$i]['match_id']); // } // // //串式撤单只改状态 // $str_ids = array_column($newapp->allstrorder($match_id),'order_id'); // $csapp = new \App\Models\MoneyBuyStr(); // $csapp->updatestatus($str_ids);//var_dump($ss);die; // //修改money_buy_match 投注结果result=2为平 // $newapp->updatast($match_id); return responseToJson(1); } //结算 function Settlement(Req $req){ $jsurl = config('sconstant.url');//结算请求域名地址 $match_id = $req->match_id; $type = $req->type; $token = session('adminInfo.token'); $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first(); $noticeid = $notice['id']; if(!$notice){ return json_encode(['status'=>5,'msg'=>'请先核对结果,并提交结果']); } //查询赛事单式是否有订单(棒球) $newapp = new \App\Models\MoneyBuyMatch(); $simplex_ids = array_column($newapp->simsettleorder($match_id,'bq'),'order_id'); $str_ids = array_column($newapp->strsettleorder($match_id),'order_id'); //去重 $simplex_ids = array_unique($simplex_ids); $str_ids = array_unique($str_ids); //判断赛事下注单输赢 $datas = array('noticeid' => $noticeid , 'token' => $token); $settlementAuto = new \App\Lib\Settlement\SettlementAuto(); $winfail = $settlementAuto->SubmitSettelement('w',$datas); if($winfail == false){ return json_encode(['status'=>2,'msg'=>'判断输赢错误,请联系管理员!!!']);//输赢错误 } $sim = array( 'token'=>$token, 'order_ids'=>'', //订单id字符串,用半角都好分隔 'bettype'=>1, //结算类型 1单式 2串式 'settype'=>2, //结算次数 1首次 2非首冷饮 'game_code'=>$type, //赛事类型 zq lq wq bq 'match_id'=>$match_id, // 赛事ID 'change_status'=>1 //是否改状态 ); $str = array( 'token'=>$token, 'order_ids'=>'', //订单id字符串,用半角都好分隔 'bettype'=>2, //结算类型 1单式 2串式 'settype'=>2, //结算次数 1首次 2非首冷饮 'game_code'=>$type, //赛事类型 zq lq wq bq 'match_id'=>$match_id, // 赛事ID 'change_status'=>1 //是否改状态 ); if(count($simplex_ids)>0 || count($str_ids)>0){ //单式结算 if(count($simplex_ids)>0 && count($str_ids)==0){ $sim['order_ids'] = implode(',',$simplex_ids); $settlesim = $settlementAuto->SubmitSettelement('s',$sim); if($settlesim == false){ return json_encode(['status'=>3,'msg'=>'单式注单结算有误,请联系管理员!!!']); }else{ return json_encode(['status'=>1,'msg'=>'单式结算成功,没有串式订单']); } } elseif(count($str_ids)>0 && count($simplex_ids)==0){ $str['order_ids'] = implode(',',$str_ids); $settlestr = $settlementAuto->SubmitSettelement('s',$str); if($settlestr == false){ return json_encode(['status'=>3,'msg'=>'串式注单结算有误,请联系管理员!!!']); }else{ return json_encode(['status'=>1,'msg'=>'串式结算成功,没有单式订单']); } } elseif(count($str_ids)>0 && count($simplex_ids)>0){ $sim['order_ids'] = implode(',',$simplex_ids); $str['order_ids'] = implode(',',$str_ids); $settlesim = $settlementAuto->SubmitSettelement('s',$sim); $settlestr = $settlementAuto->SubmitSettelement('s',$str); if($settlesim == true || $settlestr == true){ return json_encode(['status'=>1,'msg'=>'结算成功']); }else{ return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!']); } } }else{ $log = array( session('adminInfo.admin_name'), ); OperationLog(session('adminInfo.admin_id'), '棒球结算', $log); $res = \App\Models\Stbqresult::where ('match_id', $match_id)->update(['status' =>3]); $res = \App\Models\SportsBase::where ('id', $match_id)->update(['status' =>3]); return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']); } } //查询赛事结果 function Matchresult(Req $req){ $match_id = $req->match_id; $newapp = \App\Models\Stbqresult::where('match_id', $match_id)->first(); $jieguo =array( 'bqresult' => json_decode($newapp['match_score_t'],true), ); return $jieguo; } //查询赛事结果 function resultLog(Req $req){ $match_id = $req->match_id; $list = \App\Models\Stbqresultlog::leftJoin('system_user', 'user_id', '=', 'system_user.id') ->select('st_bq_result_log.*', 'system_user.loginname')->where('match_id', $match_id)->orderBy('id', 'asc')->get(); foreach ($list as $key=>$value){ $list[$key]['match_score_t'] = json_decode($value['match_score_t'], true); } $result =array( 'status' => 200, 'list' => $list ); echo json_encode($result);die; } function onlyresult(Req $req){ $match_id = $req->matchid; $newapp = \App\Models\Stbqresult::where('match_id', $match_id)->first(); return $newapp; } //结果添加 function addend(Req $req){ $match_id = $req->match_id; $model = \App\Models\Stbqresult::where('match_id', $match_id)->first(); $match = \App\Models\SportsBase::where('id', $match_id)->first(); $match_status = $match['status']; $uscore = array( "1" => array( 'home' => intval($req->homea)?intval($req->homea):1, 'guest' => intval($req->guesta)?intval($req->guesta):0, ), "2" => array( 'home' => intval($req->homeb)?intval($req->homeb):0, 'guest' => intval($req->guestb)?intval($req->guestb):0, ), "3" => array( 'home' => intval($req->homec)?intval($req->homec):0, 'guest' => intval($req->guestc)?intval($req->guestc):0, ), "4" => array( 'home' => intval($req->homed)?intval($req->homed):0, 'guest' => intval($req->guestd)?intval($req->guestd):0, ), "5" => array( 'home' => intval($req->homee)?intval($req->homee):0, 'guest' => intval($req->gueste)?intval($req->gueste):0, ), "6" => array( 'home' => intval($req->homef)?intval($req->homef):0, 'guest' => intval($req->guestf)?intval($req->guestf):0, ), "7" => array( 'home' => intval($req->homeg)?intval($req->homeg):0, 'guest' => intval($req->guestg)?intval($req->guestg):0, ), "8" => array( 'home' => intval($req->homeh)?intval($req->homeh):0, 'guest' => intval($req->guesth)?intval($req->guesth):0, ), "9" => array( 'home' => intval($req->homei)?intval($req->homei):0, 'guest' => intval($req->guesti)?intval($req->guesti):0, ), "other" => array( 'home' => intval($req->homej)?intval($req->homej):0, 'guest' => intval($req->guestj)?intval($req->guestj):0, ), "five" => array( 'home' => intval($req->homek)?intval($req->homek):0, 'guest' => intval($req->guestk)?intval($req->guestk):0, ), "all" => array( 'home' => intval($req->homel)?intval($req->homel):0, 'guest' => intval($req->guestl)?intval($req->guestl):0, ), ); // foreach($uscore as $key){ // $data[] = $key['home']; // $data[] = $key['guest']; // } //修改棒球比分前的比分数据 $res = \App\Models\Stbqresult::where('match_id', $match_id)->first(); $scores = json_decode($res['match_score_t'],true); $process = array();//进程 if($scores[1]['home'] != $uscore[1]['home'] || $scores[1]['guest'] != $uscore[1]['guest']){ $process[] = 'one'; } if($scores[2]['home'] != $uscore[2]['home'] || $scores[2]['guest'] != $uscore[2]['guest']){ $process[] = 'two'; } if($scores[3]['home'] != $uscore[3]['home'] || $scores[3]['guest'] != $uscore[3]['guest']){ $process[] = 'three'; } if($scores[4]['home'] != $uscore[4]['home'] || $scores[4]['guest'] != $uscore[4]['guest']){ $process[] = 'four'; } if($scores[5]['home'] != $uscore[5]['home'] || $scores[5]['guest'] != $uscore[5]['guest']){ $process[] = 'five'; } if($scores[6]['home'] != $uscore[6]['home'] || $scores[6]['guest'] != $uscore[6]['guest']){ $process[] = 'six'; } if($scores[7]['home'] != $uscore[7]['home'] || $scores[7]['guest'] != $uscore[7]['guest']){ $process[] = 'seven'; } if($scores[8]['home'] != $uscore[8]['home'] || $scores[8]['guest'] != $uscore[8]['guest']){ $process[] = 'eight'; } if($scores[9]['home'] != $uscore[9]['home'] || $scores[9]['guest'] != $uscore[9]['guest']){ $process[] = 'nine'; } if($scores['other']['home'] != $uscore['other']['home'] || $scores['other']['guest'] != $uscore['other']['guest']){ $process[] = 'other'; } if($scores['five']['home'] != $uscore['five']['home'] || $scores['five']['guest'] != $uscore['five']['guest']){ $process[] = 'sfive'; } if($scores['all']['home'] != $uscore['all']['home'] || $scores['all']['guest'] != $uscore['all']['guest']){ $process[] = 'all'; } if(!empty($process)){ //赛事下注单作废 处理 commonFunction::HandleInvalid($uscore,$match_id,$match_status,'bq',$process); $updatainfo = [ "home_score"=>$uscore['all']['home'], "guest_score"=>$uscore['all']['guest'], "match_score_t"=>json_encode($uscore), "match_score"=>$uscore['all']['home'].':'.$uscore['all']['guest'], "u_home_score"=>$uscore['five']['home'], "u_guest_score"=>$uscore['five']['guest'], 'is_correct'=>1, ]; \App\Models\Stbqresult::where('match_id', $match_id)->update($updatainfo); $addnew = new \App\Models\Comendnotice(); $addnew->addcomendnotice($match_id,'bq'); $twoapp = new \App\Models\SportsBase(); $twoapp->updatestatus('id',$match_id,['status'=>2,'utime'=>date('Y-m-d H:i:s')]);//修改赛事状态 $newapp = new \App\Models\Stbqresult(); $newapp->updatestatus('match_id',$match_id,['status'=>2,'update_time'=>date('Y-m-d H:i:s')]);//修改结果状态 //添加赛事结果记录 $lastLog = \App\Models\Stbqresultlog::where([ ['match_id', $match_id], ['type', 1] ])->orderBy('id', 'desc')->first(); if(empty($lastLog) || $lastLog['match_score_t'] != json_encode($uscore)){ \App\Models\Stbqresultlog::insert([ 'match_id' => $match_id, 'match_score_t' => json_encode($uscore), 'user_id' => session('adminInfo.admin_id'), 'type' => 1, 'create_at' => now() ]); } } return responseToJson(1); } //更新赛事比分 function updatascore(Req $req){ $only = $req->only; $num = $req->num; $match_id = $req->match_id; $newapp = new \App\Models\Stbqresult(); //赛事状态 $match_status = intval($req->match_status)?intval($req->match_status):0; // $data['update_time'] = data('Y-m-d H:i:s');//更新时间 $data['u_home_score'] = intval($req->u_home_score)?intval($req->u_home_score):0; $data['u_guest_score'] = intval($req->u_guest_score)?intval($req->u_guest_score):0; $data['guest_score'] = intval($req->guest_score)?intval($req->guest_score):0; $data['home_score'] = intval($req->home_score)?intval($req->home_score):0; $data['is_correct'] = 1;//追加手动更改标识 //更新比分 默认 status $status = 2; //追加判断比分 如果都== -1,则作废该赛事 if($data['u_home_score'] < 0 and $data['u_guest_score'] < 0 and $data['home_score'] < 0 and $data['guest_score'] < 0){ //已结算作废赛事处理 if($match_status == 3){ $url = 'http://stadmin.bocai108.com:9094/UnSettelement'; $data_up = [ 'token'=>session('adminInfo.token'), 'game_code'=>'bq', 'match_id'=>$match_id, ]; $ret_json = commonFunction::https_request($url,$data_up); // $ret_json = '{"status":1,"msg":"撤销成功!2019-10-26 16:28:30 取消赛事处理--结束end:game_code= zq match_id= 40986 \n","data":[]}'; $ret_arr = json_decode($ret_json,true); if($ret_arr['status'] != 1){ return responseToJson(-20003); } } //赛事下单式注单作废,串关注单下此赛事按平局处理 $upapp = new \App\Models\SportsNoteList(); $upapp->delorder($match_id,'bq'); $status = 4; } $res = $newapp->updateInfo($data,$match_id);//联赛id $addnew = new \App\Models\Comendnotice(); $addnew->addcomendnotice($match_id,'bq'); $twoapp = new \App\Models\SportsBase(); $twoapp->updatestatus('match_id',$match_id,['status'=>$status,'utime'=>date('Y-m-d H:i:s')]);//修改赛事状态 $newapp->updatestatus('match_id',$match_id,['status'=>$status,'update_time'=>date('Y-m-d H:i:s')]);//修改结果状态 //添加赛事结果比较记录 $lastLog = \App\Models\Stbqresultlog::where([ ['match_id', $match_id], ['type', 2] ])->orderBy('id', 'desc')->first(); if(empty($lastLog) || !( $lastLog['u_home_score'] == $data['u_home_score'] && $lastLog['u_guest_score'] == $data['u_guest_score'] && $lastLog['guest_score'] == $data['guest_score'] && $lastLog['home_score'] == $data['home_score'] )){ $logData = $data; $logData['type'] = 2; $logData['match_id'] = $match_id; $logData['user_id'] = session('adminInfo.admin_id'); $logData['create_at'] = now(); \App\Models\Stbqresultlog::insert($logData); } return responseToJson(1); } }