| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Jun.peng
- * Date: 2019/5/13
- * Time: 10:19
- */
- namespace App\Http\Controllers\Api;
- use Illuminate\Routing\Controller as BaseController;
- use App\Http\Response\Response;
- use Illuminate\Http\Request as Req;
- use Illuminate\Support\Facades\DB;
- use App\Lib\Biz\Sport\Common as commonFunction;
- use App\Http\Model\StBqResult as BqResultModel;
- use App\Http\Model\StBroadcast as broadcastModel;
- use App\Http\Model\StGameType as gameModel;
- use App\Http\Model\StLqResult as LqResultModel;
- use App\Http\Model\StWqResult as WqResultModel;
- use App\Http\Model\StZqOdds as OddsModel;
- use App\Http\Model\StZqResult as ZqResultModel;
- use App\Http\Model\St_area_country as StAreaCountryModel;
- use App\Http\Model\St_team as StTeamModel;
- use App\Http\Model\StZqMatch as StMatchModel;
- use App\Models\SportsNoteList as SportsNoteListModel;
- /**
- * 体育数据入库接口
- */
- class WriteSportsController extends BaseController
- {
- //是否启用 数据写入记录
- protected $isRecord;
- public function __construct()
- {
- $this->isRecord = config('record.isRecord');
- }
- //写联赛
- public function setLeague(Req $data)
- {
- $ret = $this->setLeague_v1($data);
- return $ret;
- }
- //写赛事
- public function setMatch(Req $data)
- {
- $ret = $this->setMatch_v2($data);
- return $ret;
- }
- //写赛事结果记录
- public function setMatchResult(Req $data)
- {
- $ret = $this->setMatchResult_v2($data);
- return $ret;
- }
- //写赛事赔率
- public function setOdds(Req $data)
- {
- $ret = $this->setOdds_v3($data);
- return $ret;
- }
- //写冠军联赛赔率
- public function setOddsCH(Req $data)
- {
- $ret = $this->setOddsCH_v2($data);
- return $ret;
- }
- //写直播数据
- public function setBroadCast(Req $data)
- {
- $ret = $this->setBroadCast_v1($data);
- return $ret;
- }
- //写危险球数据
- public function setMatchWarn(Req $data){
- $ret = $this->setMatchWarn_v1($data);
- return $ret;
- }
- //写赛果接口
- public function setResultExpress(Req $data)
- {
- $ret = $this->setResultExpress_v1($data);
- return $ret;
- }
- /*
- * 用户 用户 token
- */
- public function getToken(Req $req)
- {
- if ($req->isMethod('post')) {
- $user = new \App\Models\System_user;
- $str = $user->adminLogin($_POST['account'], $_POST['password']);
- if($str < 0) return Response::generate('', Response::USER_ERR);
- if ($str > 0) {
- $token = refreshToken($str['admin_id']);
- $str['token'] = $token;
- $data = $str;
- $req->session()->put('adminInfo', $str);
- $str = 1;
- }
- $log = array(
- session('adminInfo.admin_name'),
- $_POST['account']
- );
- OperationLog(session('adminInfo.admin_id'), 'login', $log);
- return Response::success($data);
- }
- }
- /**
- * 根据联赛名称 获取 国家 地区
- */
- public function getArea($leagueName = '')
- {
- //如果联赛名称有括号,去除
- $leagueName = preg_replace('/\(.*?\)/', '', $leagueName);
- //获取所有国家/地区
- $areaData = StAreaCountryModel::select('id', 'pid', 'name')->get()->toArray();
- //获取当前联赛所属国家
- if (strpos($leagueName, 'NBA') !== false) {
- $data = [
- 'id' => 247,
- 'pid' => 0,
- 'name' => '世界'
- ];
- return $data;
- }
- //识别本地 国家地区数据
- foreach ($areaData as $v => $k) {
- if (strpos($leagueName, $k['name']) !== false) {
- return $k;
- }
- }
- //如果不能识别,则返回世界
- $data = [
- 'id' => 247,
- 'pid' => 0,
- 'name' => '世界'
- ];
- return $data;
- }
- /*
- * 写 联赛 数据
- * 每个请求 包含 N个联赛
- */
- public function setLeague_v1($data)
- {
- //验证token
- $user = new \App\Models\System_user;
- if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
- $token = $user::where(['token' => $data->token])->value('token');
- if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
- try {
- //开启事务
- DB::beginTransaction();
- $obt = $data->data;
- //请求 数据 为空
- if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
- $getData = $this->getAddData($obt);
- //不是 联赛 数据
- if ($getData['title'] != 'league') throw new \Exception(Response::generate('不是联赛数据,', Response::ABNORMAL));
- /*
- //写请求数据 日志记录
- if($this->isRecord){
- commonFunction::SET_SPORTS_RECORD($obt,$getData['title']);
- $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
- if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
- }
- */
- //获取球类代码
- $game_code = $getData['game_code'];
- //获取数据源
- $source = $getData['source'];
- //获取球类名称
- $gameName = gameModel::getGameName($game_code);
- //获取 model
- $models = commonFunction::getModels($game_code, 1);
- //获取 联赛 数据
- $leagueData = $getData['data'];
- //获取 当前请求 所有 联赛 uuid
- $identity = [];
- foreach ($leagueData as $k => $v) {
- $identity[] = $v['uuid'];
- }
- $identity = array_unique($identity);
- sort($identity);
- //获取 本地 已存在 联赛
- $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id')->get()->toArray();
- //二维数组去重
- $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
- //循环对比 请求identity->本地identity
- foreach ($l_lg_data as $k => $v) {
- foreach ($identity as $kk => $uuid) {
- if ($v['identity'] == $uuid) {
- unset($identity[$kk]);
- }
- }
- }
- //去除本地和请求里都存在的联赛,如果还有剩余联赛uuid,则将其写入
- if (!empty($identity)) {
- //没有 决赛时间 默认获取本年最后一天
- $last_time = date('Y-12-31 23:59:59');
- foreach ($leagueData as $k => $v) {
- foreach ($identity as $kk => $uuid) {
- if ($v['uuid'] == $uuid) {
- //如有 决赛时间
- if ($v['last_time']) {
- $last_time = $v['last_time'];
- }
- //获取联赛所属国家或地区
- $getArea = $this->getArea($v['name_chinese']);
- if ($getArea['pid'] == 0) {
- $area_id = $getArea['id'];
- $country_id = 0;
- } else {
- $area_id = $getArea['pid'];
- $country_id = $getArea['id'];
- }
- if (empty($v['uuid'])) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $v['lg_id'] . ';', Response::LG__UUID_NULL));
- $set_lg['name_chinese'] = $v['name_chinese'];
- $set_lg['kind'] = $v['kind'];
- $set_lg['match_mode'] = $v['match_mode'];
- $set_lg['if_stop'] = $v['if_stop'];
- $set_lg['identity'] = $v['uuid'];
- $set_lg['last_time'] = $last_time;
- $set_lg['utime'] = date('Y-m-d H:i:s');
- $set_lg['area_id'] = $area_id ?: 247;
- $set_lg['country_id'] = $country_id ?: 0;
- //写入联赛
- $id = $models['model_league']::insertGetId($set_lg);
- $m_lg_id = $id;
- if ($m_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $v['lg_id'] . ';', Response::INSERT_ERROR));
- //写入 本地 联赛记录
- $set_local = [
- 'lg_id' => $id,
- 'others_lg_id' => $v['lg_id'],
- 'source' => $source,
- 'ctime' => date('Y-m-d H:i:s'),
- 'identity' => $v['uuid'],
- ];
- $ret = $models['model_local_league']::insertGetId($set_local);
- if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LOCAL_LEAGUE_ERROR));//Render([], '10017', lang('Tips','Sports')->get('local_league_error'));
- }
- }
- }
- }
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
- return $e->getMessage();
- }
- }
- /*
- * 写 赛事 数据
- * 每个请求 包含 N个联赛 下 N个赛事
- * 新增合并赛事 追加赛事uuid字段
- */
- public function setMatch_v2($data)
- {
- //验证token
- $user = new \App\Models\System_user;
- if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
- $token = $user::where(['token' => $data->token])->value('token');
- if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
- try {
- //开启事务
- DB::beginTransaction();
- $obt = $data->data;
- //请求 数据 为空
- if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
- $getData = $this->getAddData($obt);
- //不是 赛事 数据
- if ($getData['title'] != 'match') throw new \Exception(Response::generate('不是赛事数据,', Response::ABNORMAL));
- /*
- //写请求数据 日志记录
- if($this->isRecord){
- $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
- if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
- }
- */
- //获取球类代码
- $game_code = $getData['game_code'];
- //获取数据源
- $source = $getData['source'];
- //获取球类名称
- $gameName = gameModel::getGameName($game_code);
- //获取 model
- $models = commonFunction::getModels($game_code, 1);
- //获取 赛事 数据
- $matchData = $getData['data'];
- //获取 当前请求 所有 uuid
- $identity = [];
- $s_match_ids = [];
- $match_uuids = [];
- foreach ($matchData as $k => $v) {
- $identity[] = $v['uuid'];
- $s_match_ids[] = $v['match_id'];
- }
- //====验证 赛事 所属 联赛 是否存在====
- $identity = array_unique($identity);
- sort($identity);
- //获取 本地 已存在 联赛
- $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id', 'others_lg_id')->get()->toArray();
- //二维数组去重
- $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
- //如果获取不到本地联赛数据,则返回联赛不存在
- if (empty($l_lg_data)) throw new \Exception(Response::generate($gameName . '本次请求的所有赛事都没有联赛数据;', Response::LEAGUE_ERROR));
- //获取到本次请求,所有本地有联赛的赛事
- $mathData_before = $matchData;//接收原赛事
- $matchData = [];//获取新赛事
- foreach ($l_lg_data as $k => $v) {
- foreach ($mathData_before as $kk => $vv) {
- if ($v['identity'] == $vv['uuid']) {
- $matchData[] = $vv;
- }
- }
- }
- //获取当前请求有关联联赛的赛事 match_id
- $s_match_ids = [];
- foreach ($matchData as $k => $v) {
- $s_match_ids[] = $v['match_id'];
- //追加获取赛事uuid
- $match_uuids[] = $v['match_identity'];
- }
- //====获取 本地 已存在 赛事====
- $match_uuids = array_unique($match_uuids);
- sort($match_uuids);
- // $l_match_data = $models['model_local_match']::whereIn('identity', $match_uuids)->where('source', $source)->select('match_id', 'identity')->get()->toArray();
- $l_match_data = $models['model_local_match']::whereIn('identity', $match_uuids)->select('match_id', 'identity')->get()->toArray();
- //二维数组去重
- $l_match_data = commonFunction::uniquArrV2($l_match_data, 'identity');
- //循环对比 请求match_id->本地others_match_id
- //如果本地有 赛事,则分别获取本地已存在/不存在赛事
- if (!empty($l_match_data)) {
- //本地已存在赛事,用于更新
- $matchData_y = [];
- foreach ($l_match_data as $k => $v) {
- foreach ($match_uuids as $kk => $match_identity) {
- if ($v['identity'] == $match_identity) {
- $matchData_y[$k]['match_identity'] = $match_identity;
- $matchData_y[$k]['match_id'] = $v['match_id'];
- unset($match_uuids[$kk]);
- }
- }
- }
- sort($match_uuids);
- }
- //如果 请求中 有本地赛事,则执行更新
- if (!empty($matchData_y)) {
- foreach ($matchData as $k => $v) {
- foreach ($matchData_y as $kk => $vv) {
- if ($v['match_identity'] == $vv['match_identity']) {
- $data = $v;
- $up_match = [];
- $up_match['utime'] = date('Y-m-d H:i:s');
- $up_match['status'] = $data['status'];
- //获取需更新字段
- if ($data['is_rollball'] == 1) {
- $up_match['is_rollball'] = $data['is_rollball'];
- }
- if ($data['is_today'] == 1) {
- $up_match['is_today'] = $data['is_today'];
- }
- if ($data['is_morningplate'] == 1) {
- $up_match['is_morningplate'] = $data['is_morningplate'];
- }
- if ($data['is_stringscene'] == 1) {
- $up_match['is_stringscene'] = $data['is_stringscene'];
- }
- //追加更新开赛日期/时间
- $up_match['match_date'] = $data['match_date'];
- $up_match['match_time'] = $data['match_time'];
- $up_match['us_time'] = $data['us_time'];
- //如果是网球 追加rule 字段
- if ($game_code == 'wq' and !empty($data['rule'])) {
- $up_match['rule'] = $data['rule'];
- }
- //更新赛事 返回成功数量
- $set = $models['model_match']::where(['id' => $vv['match_id']])
- ->update($up_match);
- if ($set < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::UPSTATUS_ERROR));
- }
- }
- }
- }
- //剩余 赛事 数据 写入
- if (!empty($match_uuids)) {
- foreach ($matchData as $k => $v) {
- foreach ($match_uuids as $kk => $match_identity) {
- if ($v['match_identity'] == $match_identity) {
- $data = $v;
- //===追加查询 该赛事 本地是否存在 同联赛同球队 记录
- //查询赛事 如果存在 则更新为 已取消
- $matchData = $models['model_match']::where(['home_team' => $data['home_team'],'guest_team' => $data['guest_team'],'identity'=>$data['uuid']])
- ->update(['status'=>6,'handle_mark'=>'重复赛事取消']);
- //===end===
- $half_match_id = $v['half_match_id'];
- //获取 本地 联赛 ID
- //验证本赛事是否有数据源lg_id
- if (empty($data['lg_id'])) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::S_LG_ID_NULL));
- $lg_id = commonFunction::searcharray($data['uuid'], 'identity', $l_lg_data, 'lg_id');
- //验证 本赛事是否获取到本地lg_id
- if (empty($lg_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::L_LG_ID_NULL));
- //如果赛事没有开始日期,则为冠军盘口赛事
- if (empty($data['match_date'])) {
- //冠军盘口赛事获取所属联赛结束时间
- $last_time = $models['model_league']::where(['id' => $lg_id])
- ->value('last_time');
- if (empty($last_time)) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LG_LASTTIME_ERROR));//Render([], '10023', lang('Tips','Sports')->get('lg_lastTime_error'));
- //给冠军盘口赛事 赋值时间
- $time = strtotime($last_time);
- $data['match_date'] = date('Y-m-d', $time);
- $data['match_time'] = date('H:i:s', $time);
- }
- $set_match = [
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- 'expire_time' => date('Y-m-d H:i:s', time() + 60),
- 'home_team' => $data['home_team'] ?: '',
- 'guest_team' => $data['guest_team'] ?: 'no_team',
- 'lg_id' => $lg_id,
- 'status' => $data['status'],
- 'match_date' => $data['match_date'] ?: date('Y-m-d'),
- 'match_time' => $data['match_time'] ?: date('H:i:s'),
- 'is_rollball' => $data['is_rollball'] ?: 0,
- 'is_today' => $data['is_today'] ?: 0,
- 'is_morningplate' => $data['is_morningplate'] ?: 0,
- 'is_stringscene' => $data['is_stringscene'] ?: 0,
- 'is_horn' => $data['is_horn']?:0,
- 'us_time' => $data['us_time'] ?: commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
- 'half_match_id' => $half_match_id ?: 0,
- 'identity' => $data['uuid'],
- 'match_identity' => $data['match_identity'],
- ];
- //如果是网球 追加rule 字段
- if ($game_code == 'wq') {
- $set_match['rule'] = $data['rule'];
- }
- //写入赛事 返回id
- $id = $models['model_match']::insertGetId($set_match);
- if ($id < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::INSERT_ERROR));
- //写关联记录
- $set_local = [
- 'match_id' => $id,
- 'others_match_id' => $data['match_id'],
- 'source' => $source,
- 'identity' => $data['match_identity'],
- 'ctime' => date('Y-m-d H:i:s')
- ];
- $ret = $models['model_local_match']::insertGetId($set_local);
- if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::LOCAL_MATCH_ERROR));
-
- //追加写球队名称
- $team = [
- 'team_h' => $data['home_team'],
- 'team_g' => $data['guest_team'],
- ];
- StTeamModel::setTeam($game_code, $team, $source);
- //追加写赛事结果
- $opt = [
- 'data' => $data,
- 'lg_id' => $lg_id,
- 'match_id' => $id,
- 'models' => $models,
- 'gameName' => $gameName,
- 'game_code' => $game_code,
- ];
- ZqResultModel::set_result($opt);
- }
- }
- }
- }
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
- return $e->getMessage();
- }
- }
- public function setMatch_v1($data)
- {
- //验证token
- $user = new \App\Models\System_user;
- if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
- $token = $user::where(['token' => $data->token])->value('token');
- if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
- try {
- //开启事务
- DB::beginTransaction();
- $obt = $data->data;
- //请求 数据 为空
- if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
- $getData = $this->getAddData($obt);
- //不是 赛事 数据
- if ($getData['title'] != 'match') throw new \Exception(Response::generate('不是赛事数据,', Response::ABNORMAL));
- /*
- //写请求数据 日志记录
- if($this->isRecord){
- $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
- if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
- }
- */
- //获取球类代码
- $game_code = $getData['game_code'];
- //获取数据源
- $source = $getData['source'];
- //获取球类名称
- $gameName = gameModel::getGameName($game_code);
- //获取 model
- $models = commonFunction::getModels($game_code, 1);
- //获取 赛事 数据
- $matchData = $getData['data'];
- //获取 当前请求 所有 uuid
- $identity = [];
- $s_match_ids = [];
- foreach ($matchData as $k => $v) {
- $identity[] = $v['uuid'];
- $s_match_ids[] = $v['match_id'];
- }
- //====验证 赛事 所属 联赛 是否存在====
- $identity = array_unique($identity);
- sort($identity);
- //获取 本地 已存在 联赛
- $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id', 'others_lg_id')->get()->toArray();
- //二维数组去重
- $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
- //如果获取不到本地联赛数据,则返回联赛不存在
- if (empty($l_lg_data)) throw new \Exception(Response::generate($gameName . '本次请求的所有赛事都没有联赛数据;', Response::LEAGUE_ERROR));
- //获取到本次请求,所有本地有联赛的赛事
- $mathData_before = $matchData;//接收原赛事
- $matchData = [];//获取新赛事
- foreach ($l_lg_data as $k => $v) {
- foreach ($mathData_before as $kk => $vv) {
- if ($v['identity'] == $vv['uuid']) {
- $matchData[] = $vv;
- }
- }
- }
- //获取当前请求有关联联赛的赛事 match_id
- $s_match_ids = [];
- foreach ($matchData as $k => $v) {
- $s_match_ids[] = $v['match_id'];
- }
- //====获取 本地 已存在 赛事====
- $s_match_ids = array_unique($s_match_ids);
- sort($s_match_ids);
- $l_match_data = $models['model_local_match']::whereIn('others_match_id', $s_match_ids)->where('source', $source)->select('others_match_id', 'match_id')->get()->toArray();
- //二维数组去重
- $l_match_data = commonFunction::uniquArrV2($l_match_data, 'others_match_id');
- //循环对比 请求match_id->本地others_match_id
- //如果本地有 赛事,则分别获取本地已存在/不存在赛事
- if (!empty($l_match_data)) {
- //本地已存在赛事,用于更新
- $matchData_y = [];
- foreach ($l_match_data as $k => $v) {
- foreach ($s_match_ids as $kk => $s_match_id) {
- if ($v['others_match_id'] == $s_match_id) {
- $matchData_y[$k]['others_match_id'] = $s_match_id;
- $matchData_y[$k]['match_id'] = $v['match_id'];
- unset($s_match_ids[$kk]);
- }
- }
- }
- sort($s_match_ids);
- }
- //如果 请求中 有本地赛事,则执行更新
- if (!empty($matchData_y)) {
- foreach ($matchData as $k => $v) {
- foreach ($matchData_y as $kk => $vv) {
- if ($v['match_id'] == $vv['others_match_id']) {
- $data = $v;
- $up_match = [];
- $up_match['utime'] = date('Y-m-d H:i:s');
- $up_match['status'] = $data['status'];
- //获取需更新字段
- if ($data['is_rollball'] == 1) {
- $up_match['is_rollball'] = $data['is_rollball'];
- }
- if ($data['is_today'] == 1) {
- $up_match['is_today'] = $data['is_today'];
- }
- if ($data['is_morningplate'] == 1) {
- $up_match['is_morningplate'] = $data['is_morningplate'];
- }
- if ($data['is_stringscene'] == 1) {
- $up_match['is_stringscene'] = $data['is_stringscene'];
- }
- //追加更新开赛日期/时间
- $up_match['match_date'] = $data['match_date'];
- $up_match['match_time'] = $data['match_time'];
- $up_match['us_time'] = $data['us_time'];
- //如果是网球 追加rule 字段
- if ($game_code == 'wq' and !empty($data['rule'])) {
- $up_match['rule'] = $data['rule'];
- }
- //更新赛事 返回成功数量
- $set = $models['model_match']::where(['id' => $vv['match_id']])
- ->update($up_match);
- if ($set < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::UPSTATUS_ERROR));
- }
- }
- }
- }
- //剩余 赛事 数据 写入
- if (!empty($s_match_ids)) {
- foreach ($matchData as $k => $v) {
- foreach ($s_match_ids as $kk => $s_match_id) {
- if ($v['match_id'] == $s_match_id) {
- $data = $v;
- $half_match_id = $v['half_match_id'];
- //获取 本地 联赛 ID
- //验证本赛事是否有数据源lg_id
- if (empty($data['lg_id'])) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::S_LG_ID_NULL));
- $lg_id = commonFunction::searcharray($data['uuid'], 'identity', $l_lg_data, 'lg_id');
- //验证 本赛事是否获取到本地lg_id
- if (empty($lg_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::L_LG_ID_NULL));
- //如果赛事没有开始日期,则为冠军盘口赛事
- if (empty($data['match_date'])) {
- //冠军盘口赛事获取所属联赛结束时间
- $last_time = $models['model_league']::where(['id' => $lg_id])
- ->value('last_time');
- if (empty($last_time)) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LG_LASTTIME_ERROR));//Render([], '10023', lang('Tips','Sports')->get('lg_lastTime_error'));
- //给冠军盘口赛事 赋值时间
- $time = strtotime($last_time);
- $data['match_date'] = date('Y-m-d', $time);
- $data['match_time'] = date('H:i:s', $time);
- }
- $set_match = [
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- 'expire_time' => date('Y-m-d H:i:s', time() + 60),
- 'home_team' => $data['home_team'] ?: '',
- 'guest_team' => $data['guest_team'] ?: 'no_team',
- 'lg_id' => $lg_id,
- 'status' => $data['status'],
- 'match_date' => $data['match_date'] ?: date('Y-m-d'),
- 'match_time' => $data['match_time'] ?: date('H:i:s'),
- 'is_rollball' => $data['is_rollball'] ?: 0,
- 'is_today' => $data['is_today'] ?: 0,
- 'is_morningplate' => $data['is_morningplate'] ?: 0,
- 'is_stringscene' => $data['is_stringscene'] ?: 0,
- 'is_horn' => $data['is_horn']?:0,
- 'us_time' => $data['us_time'] ?: commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
- 'half_match_id' => $half_match_id ?: 0,
- 'identity' => $data['uuid'],
- ];
- //如果是网球 追加rule 字段
- if ($game_code == 'wq') {
- $set_match['rule'] = $data['rule'];
- }
- //写入赛事 返回id
- $id = $models['model_match']::insertGetId($set_match);
- if ($id < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::INSERT_ERROR));
- //写关联记录
- $set_local = [
- 'match_id' => $id,
- 'others_match_id' => $data['match_id'],
- 'source' => $source,
- 'ctime' => date('Y-m-d H:i:s')
- ];
- $ret = $models['model_local_match']::insertGetId($set_local);
- if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::LOCAL_MATCH_ERROR));//Render([], '10018', lang('Tips','Sports')->get('local_match_error'));
- //追加写球队名称
- $team = [
- 'team_h' => $data['home_team'],
- 'team_g' => $data['guest_team'],
- ];
- StTeamModel::setTeam($game_code, $team, $source);
- //追加写赛事结果
- $opt = [
- 'data' => $data,
- 'lg_id' => $lg_id,
- 'match_id' => $id,
- 'models' => $models,
- 'gameName' => $gameName,
- 'game_code' => $game_code,
- ];
- ZqResultModel::set_result($opt);
- }
- }
- }
- }
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
- return $e->getMessage();
- }
- }
- /*
- * 写 赛事 结果 记录 数据
- * 每个请求 包含 N个联赛 下 N个赛事 结果数据
- */
- public function setMatchResult_v2($data)
- {
- //验证token
- $user = new \App\Models\System_user;
- if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
- $token = $user::where(['token' => $data->token])->value('token');
- if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
- try {
- //开启事务
- DB::beginTransaction();
- $obt = $data->data;
- //请求 数据 为空
- if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
- $getData = $this->getAddData($obt);
- //不是 赛事 结果 记录 数据
- if ($getData['title'] != 'match_result_r') throw new \Exception(Response::generate('不是赛事结果记录数据,', Response::ABNORMAL));
- /*
- //写请求数据 日志记录
- if($this->isRecord){
- $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
- if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
- }
- */
- //获取球类代码
- $game_code = $getData['game_code'];
- //获取数据源
- $source = $getData['source'];
- //获取球类名称
- $gameName = gameModel::getGameName($game_code);
- //获取 model
- $models = commonFunction::getModels($game_code, 1);
- //获取 赛事 数据
- $match_r_data = $getData['data'];
- //获取 当前请求 所有 uuid /match_id
- $identity = [];
- $s_match_ids = [];
- $match_uuids = [];
- foreach ($match_r_data as $k => $v) {
- $identity[] = $v['uuid'];
- $s_match_ids[] = $v['match_id'];
- //追加获取赛事uuid
- $match_uuids[] = $v['match_identity'];
- }
- //====验证 赛事 所属 联赛 是否存在====
- $identity = array_unique($identity);
- sort($identity);
- //获取 本地 已存在 联赛
- $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id')->get()->toArray();
- //二维数组去重
- $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
- //循环对比 请求uuid->本地identity
- foreach ($l_lg_data as $k => $v) {
- foreach ($identity as $kk => $uuid) {
- if ($v['identity'] == $uuid) {
- unset($identity[$kk]);
- }
- }
- }
- sort($identity);
- //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常
- if (!empty($identity)) throw new \Exception(Response::generate($gameName . '联赛:uuid-' . $identity[0] . ';', Response::LEAGUE_ERROR));
- //====end====
- //====验证 赛事结果记录 所属赛事 是否存在====
- $match_uuids = array_unique($match_uuids);
- sort($match_uuids);
- //获取 本地 已存在 赛事
- // $l_match_data = $models['model_local_match']::whereIn('identity', $match_uuids)->where('source', $source)->select('identity', 'match_id')->get()->toArray();
- $l_match_data = $models['model_local_match']::whereIn('identity', $match_uuids)->select('identity', 'match_id')->get()->toArray();
- //二维数组去重
- $l_match_data = commonFunction::uniquArrV2($l_match_data, 'identity');
- //循环对比 请求identity->本地identity
- foreach ($l_match_data as $k => $v) {
- foreach ($match_uuids as $kk => $match_identity) {
- if ($v['identity'] == $match_identity) {
- unset($match_uuids[$kk]);
- }
- }
- }
- sort($match_uuids);
- //去除本地和请求里都存在的赛事,如果还有剩余赛事id,则返回异常
- if (!empty($match_uuids)) throw new \Exception(Response::generate($gameName . '赛事-match_id' . $match_uuids[0] . ';', Response::MATCH_ERROR));
- //====end====
- //处理 赛事 结果记录 数据
- foreach ($match_r_data as $k => $v) {
- $data = $v;
- //获取 本地 联赛 ID
- $lg_id = commonFunction::searcharray($data['uuid'], 'identity', $l_lg_data, 'lg_id');
- //获取 本地 赛事 ID
- $match_id = commonFunction::searcharray($data['match_identity'], 'identity', $l_match_data, 'match_id');
- //根据球类 获取 赛事结果记录字段
- $set_match_r = $this->get_match_r($game_code, $lg_id, $match_id, $data);
- //写 赛事 结果 记录
- $ret = $models['model_result_record']::insert($set_match_r);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));
- }
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
- return $e->getMessage();
- }
- }
- public function setMatchResult_v1($data)
- {
- //验证token
- $user = new \App\Models\System_user;
- if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
- $token = $user::where(['token' => $data->token])->value('token');
- if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
- try {
- //开启事务
- DB::beginTransaction();
- $obt = $data->data;
- //请求 数据 为空
- if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
- $getData = $this->getAddData($obt);
- //不是 赛事 结果 记录 数据
- if ($getData['title'] != 'match_result_r') throw new \Exception(Response::generate('不是赛事结果记录数据,', Response::ABNORMAL));
- /*
- //写请求数据 日志记录
- if($this->isRecord){
- // $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
- // if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
- }
- */
- //获取球类代码
- $game_code = $getData['game_code'];
- //获取数据源
- $source = $getData['source'];
- //获取球类名称
- $gameName = gameModel::getGameName($game_code);
- //获取 model
- $models = commonFunction::getModels($game_code, 1);
- //获取 赛事 数据
- $match_r_data = $getData['data'];
- //获取 当前请求 所有 uuid /match_id
- $identity = [];
- $s_match_ids = [];
- $match_uuids = [];
- foreach ($match_r_data as $k => $v) {
- $identity[] = $v['uuid'];
- $s_match_ids[] = $v['match_id'];
- }
- //====验证 赛事 所属 联赛 是否存在====
- $identity = array_unique($identity);
- sort($identity);
- //获取 本地 已存在 联赛
- $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id')->get()->toArray();
- //二维数组去重
- $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
- //循环对比 请求uuid->本地identity
- foreach ($l_lg_data as $k => $v) {
- foreach ($identity as $kk => $uuid) {
- if ($v['identity'] == $uuid) {
- unset($identity[$kk]);
- }
- }
- }
- sort($identity);
- //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常
- if (!empty($identity)) throw new \Exception(Response::generate($gameName . '联赛:uuid-' . $identity[0] . ';', Response::LEAGUE_ERROR));
- //====end====
- //====验证 赛事结果记录 所属赛事 是否存在====$match_uuids
- $s_match_ids = array_unique($s_match_ids);
- sort($s_match_ids);
- //获取 本地 已存在 赛事
- $l_match_data = $models['model_local_match']::whereIn('others_match_id', $s_match_ids)->where('source', $source)->select('others_match_id', 'match_id')->get()->toArray();
- //二维数组去重
- $l_match_data = commonFunction::uniquArrV2($l_match_data, 'others_match_id');
- //循环对比 请求match_id->本地others_match_id
- foreach ($l_match_data as $k => $v) {
- foreach ($s_match_ids as $kk => $s_match_id) {
- if ($v['others_match_id'] == $s_match_id) {
- unset($s_match_ids[$kk]);
- }
- }
- }
- sort($s_match_ids);
- //去除本地和请求里都存在的赛事,如果还有剩余赛事id,则返回异常
- if (!empty($s_match_ids)) throw new \Exception(Response::generate($gameName . '赛事-match_id' . $s_match_ids[0] . ';', Response::MATCH_ERROR));
- //====end====
- //处理 赛事 结果记录 数据
- foreach ($match_r_data as $k => $v) {
- $data = $v;
- //获取 本地 联赛 ID
- $lg_id = commonFunction::searcharray($data['uuid'], 'identity', $l_lg_data, 'lg_id');
- //获取 本地 赛事 ID
- $match_id = commonFunction::searcharray($data['match_id'], 'others_match_id', $l_match_data, 'match_id');
- //根据球类 获取 赛事结果记录字段
- $set_match_r = $this->get_match_r($game_code, $lg_id, $match_id, $data);
- //写 赛事 结果 记录
- $ret = $models['model_result_record']::insert($set_match_r);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));
- }
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
- return $e->getMessage();
- }
- }
- /*
- * 写 普通 赔率 数据
- * 每个请求 只包含 一场赛事下 N条赔率
- */
- //追加赛事uuid
- public function setOdds_v2($data)
- {
- //验证token
- $user = new \App\Models\System_user;
- if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
- $token = $user::where(['token' => $data->token])->value('token');
- if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
- try {
- //开启事务
- DB::beginTransaction();
- $obt = $data->data;
- //请求 数据 为空
- if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
- $getData = $this->getAddData($obt);
- //不是 赔率 数据
- if ($getData['title'] != 'odds') throw new \Exception(Response::generate('不是赔率数据,', Response::ABNORMAL));
- /*
- //写请求数据 日志记录
- if($this->isRecord){
- $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
- if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
- }
- */
- //获取球类代码
- $game_code = $getData['game_code'];
- //获取数据源
- $source = $getData['source'];
- //获取源数据联赛ID
- $uuid = $getData['uuid'];
- //获取源数据赛事ID
- $s_match_id = $getData['match_id'];
- //获取数据源赛事uuid
- $match_identity = $getData['match_identity'];
- //获取赔率所属赛事 tag 值 玩法数量
- $tag = $getData['tag'] ?: 99;
- //获取赔率是否是串场
- $is_stringscene = $getData['is_stringscene'];
- //获取球类名称
- $gameName = gameModel::getGameName($game_code);
- //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
- $models = commonFunction::getModels($game_code, 1);
- $lg_id = $this->leagueVerify($models, $uuid, $source, $gameName);
- $match_id = $this->matchVerify($models, $match_identity, $source, $gameName);
- //更新赛事 tag 值
- //如果未获取到本地赛事id,则返回异常
- if (empty($match_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::L_MATCH_ID_ERR));
- $upMatch = $models['model_match']::where(['id' => $match_id])
- ->update(['tag' => $tag, 'utime' => date('Y-m-d H:i:s')]);
- if ($upMatch < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::UPMATCHTAG_ERROR));
- //获取 赔率数据
- $oddsData = $getData['data'];
- //获取 当前 所有 可用 赔率 sole
- $odds_only = $getData['odds_only'];
- //更新赛事下所有 不在本次请求的赔率 状态
- $ret = OddsModel::upOddsStatus($models, $s_match_id, '', $source, $odds_only, $is_stringscene);
- if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
- //获取当前赛事 在本地的所有赔率
- $l_odds_data = $models['model_odds']::select('odds_only')->where(['match_id' => $match_id])->get()->toArray();
- $set_odds_r = [];
- $set_odds = [];
- if (!empty($oddsData)) {
- //去除本地已有的赔率
- if (!empty($l_odds_data)) {
- foreach ($oddsData as $k => $v) {
- foreach ($l_odds_data as $kk => $vv) {
- if ($v['odds_only'] == $vv['odds_only']) {
- unset($oddsData[$k]);
- }
- }
- }
- sort($oddsData);
- }
- //处理待写入 赔率记录数据
- foreach ($oddsData as $k => $v) {
- //组装数据
- $set_odds_r[] = [
- 'match_id' => $match_id ?: 0,
- 'others_match_id' => $v['match_id'] ?: 0,
- 'odds_code' => $v['odds_code'] ?: '',
- 'status' => $v['status'] ?: 0,
- 'sort' => $v['sort'] ?: 0,
- 'p_code' => $v['p_code'] ?: '',
- 'odds' => $v['odds'] ?: 0,
- 'condition' => $v['condition'],
- 'odds_only' => $v['odds_only'] ?: '',
- 'source' => $v['source'] ?: '',
- 'type' => $v['type'] ?: 0,
- 'team' => $v['team'] ?: '',
- 'lg_id' => $lg_id,
- 'is_stringscene' => $is_stringscene,
- 'others_lg_id' => $v['lg_id'],
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- ];
- }
- //处理待写入 赔率数据
- foreach ($oddsData as $k => $v) {
- //组装数据
- $set_odds[] = [
- 'match_id' => $match_id ?: 0,
- 'others_match_id' => $v['match_id'] ?: 0,
- 'odds_code' => $v['odds_code'] ?: '',
- 'status' => $v['status'] ?: 0,
- 'sort' => $v['sort'] ?: 0,
- 'p_code' => $v['p_code'] ?: '',
- 'odds' => $v['odds'] ?: 0,
- 'condition' => $v['condition'],
- 'odds_only' => $v['odds_only'] ?: '',
- 'source' => $v['source'] ?: '',
- 'type' => $v['type'] ?: 0,
- 'team' => $v['team'] ?: '',
- 'lg_id' => $lg_id,
- 'is_stringscene' => $is_stringscene,
- 'others_lg_id' => $v['lg_id'],
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- 'sole' => $v['sole'],
- 'expire_time' => date('Y-m-d H:i:s', time() + 60)
- ];
- }
- //写赔率记录数据
- $ret = $models['model_odds_record']::insert($set_odds_r);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
- //写赔率 数据
- $ret = $models['model_odds']::insert($set_odds);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
- }
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
- return $e->getMessage();
- }
- }
- //初始版本
- public function setOdds_v1($data)
- {
- //验证token
- $user = new \App\Models\System_user;
- if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
- $token = $user::where(['token' => $data->token])->value('token');
- if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
- try {
- //开启事务
- DB::beginTransaction();
- $obt = $data->data;
- //请求 数据 为空
- if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
- $getData = $this->getAddData($obt);
- //不是 赔率 数据
- if ($getData['title'] != 'odds') throw new \Exception(Response::generate('不是赔率数据,', Response::ABNORMAL));
- /*
- //写请求数据 日志记录
- if($this->isRecord){
- $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
- if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
- }
- */
- //获取球类代码
- $game_code = $getData['game_code'];
- //获取数据源
- $source = $getData['source'];
- //获取源数据联赛ID
- $uuid = $getData['uuid'];
- //获取源数据赛事ID
- $s_match_id = $getData['match_id'];
- //获取赔率所属赛事 tag 值 玩法数量
- $tag = $getData['tag'] ?: 99;
- //获取赔率是否是串场
- $is_stringscene = $getData['is_stringscene'];
- //获取球类名称
- $gameName = gameModel::getGameName($game_code);
- //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
- $models = commonFunction::getModels($game_code, 1);
- $lg_id = $this->leagueVerify($models, $uuid, $source, $gameName);
- $match_id = $this->matchVerify($models, $s_match_id, $source, $gameName);
- //更新赛事 tag 值
- //如果未获取到本地赛事id,则返回异常
- if (empty($match_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::L_MATCH_ID_ERR));
- $upMatch = $models['model_match']::where(['id' => $match_id])
- ->update(['tag' => $tag, 'utime' => date('Y-m-d H:i:s')]);
- if ($upMatch < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::UPMATCHTAG_ERROR));
- //获取 赔率数据
- $oddsData = $getData['data'];
- //获取 当前 所有 可用 赔率 sole
- $odds_only = $getData['odds_only'];
- //更新赛事下所有 不在本次请求的赔率 状态
- $ret = OddsModel::upOddsStatus($models, $s_match_id, '', $source, $odds_only, $is_stringscene);
- if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
- //获取当前赛事 在本地的所有赔率
- $l_odds_data = $models['model_odds']::select('odds_only')->where(['match_id' => $match_id])->get()->toArray();
- $set_odds_r = [];
- $set_odds = [];
- if (!empty($oddsData)) {
- //去除本地已有的赔率
- if (!empty($l_odds_data)) {
- foreach ($oddsData as $k => $v) {
- foreach ($l_odds_data as $kk => $vv) {
- if ($v['odds_only'] == $vv['odds_only']) {
- unset($oddsData[$k]);
- }
- }
- }
- sort($oddsData);
- }
- //处理待写入 赔率记录数据
- foreach ($oddsData as $k => $v) {
- //组装数据
- $set_odds_r[] = [
- 'match_id' => $match_id ?: 0,
- 'others_match_id' => $v['match_id'] ?: 0,
- 'odds_code' => $v['odds_code'] ?: '',
- 'status' => $v['status'] ?: 0,
- 'sort' => $v['sort'] ?: 0,
- 'p_code' => $v['p_code'] ?: '',
- 'odds' => $v['odds'] ?: 0,
- 'condition' => $v['condition'],
- 'odds_only' => $v['odds_only'] ?: '',
- 'source' => $v['source'] ?: '',
- 'type' => $v['type'] ?: 0,
- 'team' => $v['team'] ?: '',
- 'lg_id' => $lg_id,
- 'is_stringscene' => $is_stringscene,
- 'others_lg_id' => $v['lg_id'],
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- ];
- }
- //处理待写入 赔率数据
- foreach ($oddsData as $k => $v) {
- //组装数据
- $set_odds[] = [
- 'match_id' => $match_id ?: 0,
- 'others_match_id' => $v['match_id'] ?: 0,
- 'odds_code' => $v['odds_code'] ?: '',
- 'status' => $v['status'] ?: 0,
- 'sort' => $v['sort'] ?: 0,
- 'p_code' => $v['p_code'] ?: '',
- 'odds' => $v['odds'] ?: 0,
- 'condition' => $v['condition'],
- 'odds_only' => $v['odds_only'] ?: '',
- 'source' => $v['source'] ?: '',
- 'type' => $v['type'] ?: 0,
- 'team' => $v['team'] ?: '',
- 'lg_id' => $lg_id,
- 'is_stringscene' => $is_stringscene,
- 'others_lg_id' => $v['lg_id'],
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- 'sole' => $v['sole'],
- 'expire_time' => date('Y-m-d H:i:s', time() + 60)
- ];
- }
- //写赔率记录数据
- $ret = $models['model_odds_record']::insert($set_odds_r);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
- //写赔率 数据
- $ret = $models['model_odds']::insert($set_odds);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
- }
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
- return $e->getMessage();
- }
- }
- //新增赔率过滤
- public function setOdds_v3($data)
- {
- //验证token
- $user = new \App\Models\System_user;
- if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
- $token = $user::where(['token' => $data->token])->value('token');
- if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
- try {
- //开启事务
- DB::beginTransaction();
- $obt = $data->data;
- //请求 数据 为空
- if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
- $getData = $this->getAddData($obt);
- //不是 赔率 数据
- if ($getData['title'] != 'odds') throw new \Exception(Response::generate('不是赔率数据,', Response::ABNORMAL));
- //获取球类代码
- $game_code = $getData['game_code'];
- //获取数据源
- $source = $getData['source'];
- //获取源数据联赛ID
- $uuid = $getData['uuid'];
- //获取源数据赛事ID
- $s_match_id = $getData['match_id'];
- //获取赔率所属赛事 tag 值 玩法数量
- $tag = $getData['tag'] ?: 99;
- //获取赔率是否是串场
- $is_stringscene = $getData['is_stringscene'];
- //获取数据源赛事uuid
- $match_identity = $getData['match_identity'];
- //获取球类名称
- $gameName = gameModel::getGameName($game_code);
- //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
- $models = commonFunction::getModels($game_code, 1);
- $lg_id = $this->leagueVerify($models, $uuid, $source, $gameName);
- $match_id = $this->matchVerify_v2($models, $match_identity, $source, $gameName);
- //更新赛事 tag 值
- //如果未获取到本地赛事id,则返回异常
- if (empty($match_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::L_MATCH_ID_ERR));
- $upMatch = $models['model_match']::where(['id' => $match_id])
- ->update(['tag' => $tag, 'utime' => date('Y-m-d H:i:s')]);
- if ($upMatch < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::UPMATCHTAG_ERROR));
- //获取 赔率数据
- $oddsData = $getData['data'];
- //===追加处理赔率过滤===
- //获取当前赛事 在本地的所有赔率
- $l_odds_data = $models['model_odds']::select('odds_only')->where(['match_id' => $match_id, 'is_stringscene' => $is_stringscene])->get()->toArray();
- //获取请求待写入数据
- $setOddsData = [];
- //获取本地待删除数据
- $delOddsData = [];
- //本地没有该赛事赔率,则直接全部写入
- if (empty($l_odds_data)) {
- $setOddsData = $oddsData;
- } //本地有该赛事赔率,则分别获取需写入/删除的数据
- else {
- $newodds_t = $this->ArrayKeySet($oddsData, 'odds_only');
- $oldodds_t = $this->ArrayKeySet($l_odds_data, 'odds_only');
- foreach ($newodds_t as $key => $val) {
- if (isset($oldodds_t[$key])) {
- unset($newodds_t[$key]);
- unset($oldodds_t[$key]);
- }
- }
- $oddsData = $newodds_t;
- $l_odds_data = $oldodds_t;
- /*
- foreach ($oddsData as $k => $v) {
- foreach ($l_odds_data as $kk => $vv) {
- if ($v['odds_only'] == $vv['odds_only']) {
- unset($oddsData[$k]);
- unset($l_odds_data[$kk]);
- }
- }
- }
- */
- sort($oddsData);
- sort($l_odds_data);
- //需写入请求数据
- $setOddsData = $oddsData;
- //需删除本地数据
- $delOddsData = $l_odds_data;
- }
- //===end===
- //删除本地不在请求中的数据
- if (!empty($delOddsData)) {
- //所有需删除数据odds_only
- $odds_onlys = [];
- foreach ($delOddsData as $k => $v) {
- $odds_onlys[] = $v['odds_only'];
- }
- $del = $models['model_odds']::whereIn('odds_only', $odds_onlys)->delete();
- if ($del != count($odds_onlys)) throw new \Exception(Response::generate($gameName, Response::DEL_ODDS_ERR));
- }
- //写入请求中本地不存在的数据
- if (!empty($setOddsData)) {
- //处理待写入 赔率记录数据
- foreach ($setOddsData as $k => $v) {
- //组装数据
- $set_odds_r[] = [
- 'match_id' => $match_id ?: 0,
- 'others_match_id' => $v['match_id'] ?: 0,
- 'odds_code' => $v['odds_code'] ?: '',
- 'status' => $v['status'] ?: 0,
- 'sort' => $v['sort'] ?: 0,
- 'p_code' => $v['p_code'] ?: '',
- 'odds' => $v['odds'] ?: 0,
- 'condition' => $v['condition'],
- 'odds_only' => $v['odds_only'] ?: '',
- 'source' => $v['source'] ?: '',
- 'type' => $v['type'] ?: 0,
- 'team' => $v['team'] ?: '',
- 'lg_id' => $lg_id,
- 'is_stringscene' => $is_stringscene,
- 'others_lg_id' => $v['lg_id'],
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- ];
- }
- //处理待写入 赔率数据
- foreach ($oddsData as $k => $v) {
- //组装数据
- $set_odds[] = [
- 'match_id' => $match_id ?: 0,
- 'others_match_id' => $v['match_id'] ?: 0,
- 'odds_code' => $v['odds_code'] ?: '',
- 'status' => $v['status'] ?: 0,
- 'sort' => $v['sort'] ?: 0,
- 'p_code' => $v['p_code'] ?: '',
- 'odds' => $v['odds'] ?: 0,
- 'condition' => $v['condition'],
- 'odds_only' => $v['odds_only'] ?: '',
- 'source' => $v['source'] ?: '',
- 'type' => $v['type'] ?: 0,
- 'team' => $v['team'] ?: '',
- 'lg_id' => $lg_id,
- 'is_stringscene' => $is_stringscene,
- 'others_lg_id' => $v['lg_id'],
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- 'sole' => $v['sole'],
- 'expire_time' => date('Y-m-d H:i:s', time() + 60)
- ];
- }
- //写赔率记录数据
- $ret = $models['model_odds_record']::insert($set_odds_r);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
- //写赔率 数据
- $ret = $models['model_odds']::insert($set_odds);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
- }
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
- return $e->getMessage();
- }
- }
- /*
- *写 冠军联赛 赔率 数据
- *每个请求 包含 N个联赛 下 N条赔率
- *
- */
- public function setOddsCH_v1($data)
- {
- //验证token
- $user = new \App\Models\System_user;
- if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
- $token = $user::where(['token' => $data->token])->value('token');
- if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
- try {
- //开启事务
- DB::beginTransaction();
- $obt = $data->data;
- //请求 数据 为空
- if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
- $getData = $this->getAddData($obt);
- //不是 冠军 赔率 数据
- if ($getData['title'] != 'odds_ch') throw new \Exception(Response::generate('不是冠军赔率数据,', Response::ABNORMAL));
- /*
- //写请求数据 日志记录
- if($this->isRecord){
- $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
- if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
- }
- */
- //获取球类代码
- $game_code = $getData['game_code'];
- //获取数据源
- $source = $getData['source'];
- //获取球类名称
- $gameName = gameModel::getGameName($game_code);
- //获取 model
- $models = commonFunction::getModels($game_code, 1);
- //获取 赔率数据
- $oddsData = $getData['data'];
- //获取 当前 所有 可用 赔率 sole
- $odds_only = $getData['odds_only'];
- //====验证 请求里 所有赔率 所属联赛 是否存在 ====
- //获取 当前请求 所有 联赛 uuid
- $uuids = [];
- $s_lg_ids = [];
- foreach ($oddsData as $k => $v) {
- $uuids[] = $v['uuid'];
- $s_lg_ids[] = $v['lg_id'];
- }
- $s_lg_ids = array_unique($s_lg_ids);
- $uuids = array_unique($uuids);
- sort($uuids);
- sort($s_lg_ids);
- //更新联赛下所有 不在本次请求的赔率 状态
- $ret = OddsModel::upOddsStatus($models, '', $s_lg_ids, $source, $odds_only);
- if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
- //获取 本地 已存在 联赛
- $l_lg_data = $models['model_local_league']::whereIn('identity', $uuids)->select('identity', 'lg_id')->get()->toArray();
- //二维数组去重
- $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
- //循环对比 请求uuid->本地uuid
- foreach ($l_lg_data as $k => $v) {
- foreach ($uuids as $kk => $uuid) {
- if ($v['identity'] == $uuid) {
- unset($uuids[$kk]);
- }
- }
- }
- //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常;
- if (!empty($uuids)) throw new \Exception(Response::generate($gameName . '冠军联赛:uuid-' . $uuids[0] . ';', Response::LEAGUE_ERROR));
- //====end====
- //赔率记录数据
- $set_odds_r = [];
- //赔率数据
- $set_odds = [];
- if (!empty($oddsData)) {
- foreach ($oddsData as $k => $v) {
- //获取 本地 联赛 ID
- $lg_id = commonFunction::searcharray($v['uuid'], 'identity', $l_lg_data, 'lg_id');
- //组装赔率记录数据
- $set_odds_r[] = [
- 'match_id' => 0,
- 'others_match_id' => $v['match_id'] ?: 0,
- 'odds_code' => $v['odds_code'] ?: '',
- 'status' => $v['status'] ?: 0,
- 'sort' => $v['sort'] ?: 0,
- 'p_code' => $v['p_code'] ?: '',
- 'odds' => $v['odds'] ?: 0,
- 'condition' => $v['condition'],
- 'odds_only' => $v['odds_only'] ?: '',
- 'source' => $v['source'] ?: '',
- 'type' => $v['type'] ?: 1,
- 'team' => $v['team'] ?: '',
- 'lg_id' => $lg_id,
- 'others_lg_id' => $v['lg_id'],
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- ];
- }
- foreach ($oddsData as $k => $v) {
- //获取 本地 联赛 ID
- $lg_id = commonFunction::searcharray($v['uuid'], 'identity', $l_lg_data, 'lg_id');
- //组装赔率数据
- $set_odds[] = [
- 'match_id' => 0,
- 'others_match_id' => $v['match_id'] ?: 0,
- 'odds_code' => $v['odds_code'] ?: '',
- 'status' => $v['status'] ?: 0,
- 'sort' => $v['sort'] ?: 0,
- 'p_code' => $v['p_code'] ?: '',
- 'odds' => $v['odds'] ?: 0,
- 'condition' => $v['condition'],
- 'odds_only' => $v['odds_only'] ?: '',
- 'source' => $v['source'] ?: '',
- 'type' => $v['type'] ?: 1,
- 'team' => $v['team'] ?: '',
- 'lg_id' => $lg_id,
- 'others_lg_id' => $v['lg_id'],
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- 'sole' => $v['sole'],
- 'expire_time' => date('Y-m-d H:i:s', time() + 60)
- ];
- }
- //写赔率记录数据
- $ret = $models['model_odds_record']::insert($set_odds_r);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
- //写赔率 数据
- $ret = $models['model_odds']::insert($set_odds);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
- }
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
- return $e->getMessage();
- }
- }
- /*
- *写 冠军联赛 赔率 数据
- *每个请求 包含 1个联赛 下 N条赔率
- *追加赔率过滤
- */
- public function setOddsCH_v2($data)
- {
- //验证token
- $user = new \App\Models\System_user;
- if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
- $token = $user::where(['token' => $data->token])->value('token');
- if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
- try {
- //开启事务
- DB::beginTransaction();
- $obt = $data->data;
- //请求 数据 为空
- if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
- $getData = $this->getAddData($obt);
- //不是 冠军 赔率 数据
- if ($getData['title'] != 'odds_ch') throw new \Exception(Response::generate('不是冠军赔率数据,', Response::ABNORMAL));
- /*
- //写请求数据 日志记录
- if($this->isRecord){
- $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
- if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
- }
- */
- //获取球类代码
- $game_code = $getData['game_code'];
- //获取数据源
- $source = $getData['source'];
- //获取球类名称
- $gameName = gameModel::getGameName($game_code);
- //获取数据源联赛ID
- $s_lg_id = $getData['lg_id'];
- //获取源数据联赛UUID
- $uuid = $getData['uuid'];
- //获取 model
- $models = commonFunction::getModels($game_code, 1);
- //获取 赔率数据
- $oddsData = $getData['data'];
- //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
- $lg_id = $this->leagueVerify($models, $uuid, $source, $gameName);
- //===追加处理赔率过滤===
- //获取当前联赛 在本地的所有赔率
- $l_odds_data = $models['model_odds']::select('odds_only')->where(['lg_id' => $lg_id,'type' => 1])->get()->toArray();
- //获取请求待写入数据
- $setOddsData = [];
- //获取本地待删除数据
- $delOddsData = [];
- //本地没有该赛事赔率,则直接全部写入
- if (empty($l_odds_data)) {
- $setOddsData = $oddsData;
- } //本地有该赛事赔率,则分别获取需写入/删除的数据
- else {
- $newodds_t = $this->ArrayKeySet($oddsData, 'odds_only');
- $oldodds_t = $this->ArrayKeySet($l_odds_data, 'odds_only');
- foreach ($newodds_t as $key => $val) {
- if (isset($oldodds_t[$key])) {
- unset($newodds_t[$key]);
- unset($oldodds_t[$key]);
- }
- }
- $oddsData = $newodds_t;
- $l_odds_data = $oldodds_t;
- sort($oddsData);
- sort($l_odds_data);
- //需写入请求数据
- $setOddsData = $oddsData;
- //需删除本地数据
- $delOddsData = $l_odds_data;
- }
- //===end===
- //删除本地不在请求中的数据
- if (!empty($delOddsData)) {
- //所有需删除数据odds_only
- $odds_onlys = [];
- foreach ($delOddsData as $k => $v) {
- $odds_onlys[] = $v['odds_only'];
- }
- $del = $models['model_odds']::whereIn('odds_only', $odds_onlys)->delete();
- if ($del != count($odds_onlys)) throw new \Exception(Response::generate($gameName, Response::DEL_ODDS_ERR));
- }
- //写入请求中本地不存在的数据
- if (!empty($setOddsData)) {
- foreach ($setOddsData as $k => $v) {
- //组装赔率记录数据
- $set_odds_r[] = [
- 'match_id' => 0,
- 'others_match_id' => $v['match_id'] ?: 0,
- 'odds_code' => $v['odds_code'] ?: '',
- 'status' => $v['status'] ?: 0,
- 'sort' => $v['sort'] ?: 0,
- 'p_code' => $v['p_code'] ?: '',
- 'odds' => $v['odds'] ?: 0,
- 'condition' => $v['condition'],
- 'odds_only' => $v['odds_only'] ?: '',
- 'source' => $v['source'] ?: '',
- 'type' => $v['type'] ?: 1,
- 'team' => $v['team'] ?: '',
- 'lg_id' => $lg_id,
- 'others_lg_id' => $v['lg_id'],
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- ];
- }
- foreach ($oddsData as $k => $v) {
- //组装赔率数据
- $set_odds[] = [
- 'match_id' => 0,
- 'others_match_id' => $v['match_id'] ?: 0,
- 'odds_code' => $v['odds_code'] ?: '',
- 'status' => $v['status'] ?: 0,
- 'sort' => $v['sort'] ?: 0,
- 'p_code' => $v['p_code'] ?: '',
- 'odds' => $v['odds'] ?: 0,
- 'condition' => $v['condition'],
- 'odds_only' => $v['odds_only'] ?: '',
- 'source' => $v['source'] ?: '',
- 'type' => $v['type'] ?: 1,
- 'team' => $v['team'] ?: '',
- 'lg_id' => $lg_id,
- 'others_lg_id' => $v['lg_id'],
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- 'sole' => $v['sole'],
- 'expire_time' => date('Y-m-d H:i:s', time() + 60)
- ];
- }
- //写赔率记录数据
- $ret = $models['model_odds_record']::insert($set_odds_r);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
- //写赔率 数据
- $ret = $models['model_odds']::insert($set_odds);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
- }
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
- return $e->getMessage();
- }
- }
- /*
- * 写入直播 数据
- */
- public function setBroadCast_v1($data)
- {
- //验证token
- $user = new \App\Models\System_user;
- if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
- $token = $user::where(['token' => $data->token])->value('token');
- if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
- try {
- //开启事务
- DB::beginTransaction();
- $obt = $data->data;
- //请求 数据 为空
- if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
- $getData = $this->getAddData($obt);
- //不是 直播 数据
- if ($getData['title'] != 'broad_cast') throw new \Exception(Response::generate('不是直播数据,', Response::ABNORMAL));
- /*
- //写请求数据 日志记录
- if($this->isRecord){
- $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
- if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
- }
- */
- //获取 球类
- $game_code = $getData['game_code'];
- //删除当前球类已存在的直播数据
- $del = broadcastModel::where('game_code', $game_code)->delete();
- if ($del != true) throw new \Exception(Response::generate('', Response::DEL_PAST_BROADCAST_ERR));
- //获取 直播 数据
- $BroadCast = $getData['data'];
- $set_broadcast = [];
- foreach ($BroadCast as $k => $data) {
- //组装数据
- $set_broadcast[] = [
- "doing" => $data['doing'],
- "game_type" => $data['game_type'],
- "game_code" => $game_code,
- "guest_team" => $data['guest_team'],
- "host_team" => $data['host_team'],
- "league_name" => $data['league_name'],
- "shower" => $data['shower'],
- "showid" => (int)$data['showid'],
- "start_time" => $data['start_time'],
- "ctime" => date('Y-m-d H:i:s'),
- "utime" => date('Y-m-d H:i:s'),
- ];
- }
- //写入 直播 数据
- $ret = broadcastModel::insert($set_broadcast);
- if ($ret == false) throw new \Exception(Response::generate('', Response::BROADCAST_ERROR));
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
- return $e->getMessage();
- }
- }
- /**
- * @param Req $data
- * @return string
- * @throws \App\Lib\Biz\Sport\Exception
- * 更新赛事状态
- */
- public function upMatch(Req $data)
- {
- //验证token
- $user = new \App\Models\System_user;
- if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
- $token = $user::where(['token' => $data->token])->value('token');
- if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
- try {
- //开启事务
- DB::beginTransaction();
- //获取待更新赛事
- $obt = $data->data;
- //请求 数据 为空
- if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
- $data = $this->getAddData($obt);
- //不是更新赛事状态数据
- if ($data['title'] != 'match_status') throw new \Exception(Response::generate('不是更新赛事状态数据', Response::ABNORMAL));
- /*
- //写请求数据 日志记录
- if($this->isRecord){
- $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
- if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
- }
- */
- //获取 球类代码
- $game_code = $data['game_code'];
- //获取球类 名称
- $gameName = gameModel::getGameName($game_code);
- //获取 数据源
- $source = $data['source'];
- //获取 当前请求 所有 uuid /match_id
- $others_match_ids = [];
- $match_uuids = [];
- foreach ($data['data'] as $k => $v) {
- $others_match_ids[] = $v['match_id'];
- //追加获取赛事uuid
- $match_uuids[] = $v['match_identity'];
- }
- //根据球类代码 获取model
- $model = commonFunction::getModels($game_code, 1);
- //获取所有赛事 match_id
- $local_match = $model['model_local_match']::SELECT('others_match_id', 'match_id')
- // ->where(['source' => $source])
- ->whereIn('identity',$match_uuids)
- ->get()->toArray();
- if (empty($local_match)) throw new \Exception(Response::generate('', Response::MATCHID_NULL));
- //设置各球类 判断结束时间
- if($game_code == 'zq'){
- //足球 60分钟
- $handle_time = 60*60;
- }
- if($game_code == 'lq'){
- //篮球 40分钟
- $handle_time = 60*40;
- }
- if($game_code == 'wq'){
- //网球 2小时
- $handle_time = 60*60*2;
- }
- if($game_code == 'bq'){
- //棒球 2小时
- $handle_time = 60*60*2;
- }
- //取值 更新字段
- foreach ($local_match as $k => $v) {
- foreach($data['data'] as $kk =>$vv){
- if($v['others_match_id'] == $vv['match_id']){
-
- $set_status = [
- 'status' => $vv['status'],
- 'is_rollball' => $vv['is_rollball'],
- 'is_today' => $vv['is_today'],
- 'is_morningplate' => $vv['is_morningplate'],
- 'is_stringscene' => $vv['is_stringscene'],
- 'utime' => date('Y-m-d H:i:s'),
- ];
- //如果是足球 追加角球状态
- if($game_code == 'zq'){
- $set_status['is_horn'] = $vv['is_horn'];
- }
- $ret = $model['model_match']::where(['id' => $v['match_id']])
- ->update($set_status);
- if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $v['others_match_id'], Response::UPSTATUS_ERROR));
-
- //获取赛事开始时间
- $game_start_time = $model['model_result']::where(['match_id' => $v['match_id']])->first()->start_time;
- //开赛时间 时间戳
- $game_start_time_unx = strtotime($game_start_time);
-
- //===如果赛事已结束 并且 开赛时间< 当前时间-各球类处理时间 ===
- if($vv['status'] == 2 and $game_start_time_unx < (time() - $handle_time)){
- // 新增 更新 赛事结果
- $this->match_result($game_code, $v['match_id']);
-
- // 写入结算通知表 用于自动结算
- $Comendnotice = new \App\Models\Comendnotice();
- $ret_add = $Comendnotice->addcomendnotice($v['match_id'], $game_code, 0, $game_start_time);
- if ($ret_add != 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $v['others_match_id'], Response::ADD_NOTICE_ERR));
- }
- //===end===
- }
- }
- }
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $data, $data['title'], Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $data, $data['title'], $e->getMessage());
- return $e->getMessage();
- }
- }
- /*
- * 验证所属 联赛 是否存在
- */
- public function leagueVerify($models = [], $uuid = '', $source = '', $gameName = '')
- {
- if (empty($models) || empty($uuid)) throw new \Exception(Response::generate('', Response::ABNORMAL));
- $l_lg_id = $models['model_local_league']::where(['identity' => $uuid])->value('lg_id');
- if ($l_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛:lg_id-' . $uuid, Response::LEAGUE_ERROR));
- return $l_lg_id;
- }
- /*
- * 验证所属 赛事 是否存在
- */
- public function matchVerify_v2($models = [], $match_identity = '', $source = '', $gameName = '')
- {
- if (empty($models) || empty($match_identity)) throw new \Exception(Response::generate('', Response::ABNORMAL));
- // $l_match_id = $models['model_local_match']::where(['identity' => $match_identity, 'source' => $source])->value('match_id');
- $l_match_id = $models['model_local_match']::where(['identity' => $match_identity])->value('match_id');
- if ($l_match_id < 1) throw new \Exception(Response::generate($gameName . 'match_identity-' . $match_identity, Response::MATCH_ERROR));
- return $l_match_id;
- }
- public function matchVerify($models = [], $s_match_id = '', $source = '', $gameName = '')
- {
- if (empty($models) || empty($s_match_id)) throw new \Exception(Response::generate('', Response::ABNORMAL));
- $l_match_id = $models['model_local_match']::where(['others_match_id' => $s_match_id, 'source' => $source])->value('match_id');
- if ($l_match_id < 1) throw new \Exception(Response::generate($gameName . '赛事:match_id-' . $s_match_id, Response::MATCH_ERROR));
- return $l_match_id;
- }
- /*
- * 写入数据 接口
- */
- public function setSports(Req $data)
- {
- try {
- //开启事务
- DB::beginTransaction();
- if ($data->game_code) {
- //用于后台 将所有进行中的赛事写入结果
- $this->match_result($data->game_code);
- }
- /*
- else {
- //验证token
- $dd = $data->session()->get('adminInfo');
- if (empty($data->token) || ($dd['token'] != $data->token)) return Response::generate('', Response::TOKEN_ERR);
- //写赛事数据
- $obt = $data->data;
- if ($obt) {
- $getData = $this->getAddData($obt);
- $league = [];
- $competition = [];
- $odds = [];
- $odds_soly = [];
- $league_result = [];
- $match_result = [];
- $match_result_record = [];
- $odds_record = [];
- $broadcast = [];
- //指定排序 联赛->赛事->赔率->联赛结果->赛事结果->赛事结果记录->赔率记录->直播数据
- foreach ($getData as $k => $v) {
- $game_code = $v['game_code'];
- if ($v['title'] == 'league') $league[] = $v;
- if ($v['title'] == 'competition') $competition[] = $v;
- if ($v['title'] == 'odds') $odds[] = $v;
- if ($v['title'] == 'odds_sole') $odds_soly[] = $v;
- if ($v['title'] == 'league_result') $league_result[] = $v;
- if ($v['title'] == 'match_result') $match_result[] = $v;
- if ($v['title'] == 'match_result_record') $match_result_record[] = $v;
- if ($v['title'] == 'odds_record') $odds_record[] = $v;
- if ($v['title'] == 'broadcast') $broadcast[] = $v;
- }
- $matchData = [$league, $competition, $odds_soly, $odds, $league_result, $match_result, $match_result_record, $odds_record, $broadcast];
- //排空处理
- foreach ($matchData as $k => $v) {
- if ($v == []) unset($matchData[$k]);
- }
- sort($matchData);
- //根据顺序写入数据
- //降维数据
- $mentData = [];
- foreach ($matchData as $k => $v) {
- foreach ($v as $kk => $vv) {
- $mentData[] = $vv;
- }
- }
- //获取各球类model
- $models = commonFunction::getModels($game_code, 1);
- //获取球类名称
- $gameName = gameModel::getGameName($game_code);
- //===获取验证数据===
- //获取一段时间内所有联赛本地记录
- $lg_data = LeagueModel::getLeagueID($models);
- //获取一段时间内所有赛事本地记录
- $match_data = MatchModel::getMatchID($models);
- //获取一段时间内所有赔率
- $odds_data = OddsModel::getOddsID($models);
- //获取一段时间内所有赔率记录
- $odds_record_data = OddsRecordModel::getOddsRecordID($models);
- //===获取验证数据===
- $others_lg_id = '';//继承 源联赛id
- $others_match_id = '';//继承 源赛事id
- $s_lg_id = '';//源 联赛ID
- $l_lg_id = '';//本地 联赛 ID
- $s_match_id = '';//源 赛事ID
- $l_match_id = '';//本地 赛事 ID
- foreach ($mentData as $kk => $vv) {
- switch ($vv['title']) {
- case 'area'://地区
- throw new \Exception(Response::generate('地区数据-area:', Response::AUTH_ERROR));
- break;
- case 'country'://国家
- throw new \Exception(Response::generate('国家数据-country:', Response::AUTH_ERROR));
- break;
- case 'league'://联赛
- $others_lg_id = $vv['data']['lg_id'];
- $s_lg_id = $vv['data']['lg_id'];
- $source = $vv['data']['source'];
- //验证联赛记录是否已存在
- $ret_lg = commonFunction::ver_league($s_lg_id, $source, $lg_data);
- if ($ret_lg != false) {
- $l_lg_id = $ret_lg;
- break;
- }
- //执行 联赛数据
- $lg_data = $this->league($vv, $gameName);
- $l_lg_id = $lg_data['lg_id'];
- break;
- case 'competition'://赛事
- $others_match_id = $vv['data']['match_id'];
- $s_lg_id = $vv['data']['lg_id'];
- $s_match_id = $vv['data']['match_id'];
- $source = $vv['data']['source'];
- //本次请求是否包含 联赛数据
- if (empty($others_lg_id)) {
- //验证本地是否存在
- $ret_lg = commonFunction::ver_league($s_lg_id, $source, $lg_data);
- if ($ret_lg == false) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
- $l_lg_id = $ret_lg;
- } else {
- //本次有 联赛数据 验证属于同联赛
- if ($s_lg_id != $others_lg_id) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
- }
- //验证赛事记录是否已存在
- $ret_match = commonFunction::ver_match($s_match_id, $source, $match_data);
- if ($ret_match != false) {
- $l_match_id = $ret_match;
- break;
- }
- //执行 赛事数据
- $match_data = $this->competition($vv, $gameName, $l_lg_id);
- $l_match_id = $match_data['match_id'];
- break;
- case 'odds'://赔率
- $s_lg_id = $vv['data']['lg_id'];
- $s_match_id = $vv['data']['match_id'];
- $source = $vv['data']['source'];
- $odds_only = $vv['data']['odds_only'];
- $sole = $vv['data']['sole'];
- $odds_type = $vv['data']['type'];//0普通 1冠军盘口
- //本次请求是否包含 联赛数据
- if (empty($others_lg_id)) {
- //无联赛数据 验证本地是否存在
- $ret_lg = commonFunction::ver_league($s_lg_id, $source, $lg_data);
- //联赛 不存在
- if ($ret_lg == false) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
- $l_lg_id = $ret_lg;
- } else {
- //有联赛数据 验证属于同请求联赛
- if ($s_lg_id != $others_lg_id) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
- }
- //如果是普通 赔率,则验证所属赛事
- if ($odds_type == 0) {
- //验证赛事记录是否已存在
- if (empty($others_match_id)) {
- //无赛事数据 验证本地是否存在
- $ret_match = commonFunction::ver_match($s_match_id, $source, $match_data);
- //赛事 不存在
- if ($ret_match == false) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::MATCH_ERROR));
- $l_match_id = $ret_match;
- } else {
- //有赛事数据 验证属于同请求赛事
- if ($s_match_id != $others_match_id) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::MATCH_ERROR));
- }
- }
- //验证赔率 是否存在
- $ret_odds = '';
- $ret_odds = commonFunction::ver_odds($sole, $source, $odds_data);
- //验证赔率记录 是否存在
- $ret_odds_record = '';
- $ret_odds_record = commonFunction::ver_odds_record($odds_only, $source, $odds_record_data);
- $this->odds($vv, $gameName, $l_lg_id, $l_match_id, $ret_odds, $ret_odds_record);
- break;
- case 'odds_sole':
- $this->upOddsStatus($vv, $gameName);
- break;
- case 'league_result'://联赛结果
- $this->league_result($vv, $gameName);
- break;
- case 'match_result'://赛事结果
- throw new \Exception(Response::generate('赛事结果数据-match_result:', Response::AUTH_ERROR));
- $this->match_result($vv, $gameName);
- break;
- case 'match_result_record'://赛事结果记录
- $s_lg_id = $vv['data']['lg_id'];
- $s_match_id = $vv['data']['match_id'];
- $source = $vv['data']['source'];
- //如果本次请求没有 联赛数据
- if (empty($others_lg_id)) {
- //验证本地是否存在
- $ret_lg = commonFunction::ver_league($s_lg_id, $source, $lg_data);
- //联赛 不存在
- if ($ret_lg == false) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
- $l_lg_id = $ret_lg;
- } else {
- //有联赛数据 验证属于同请求联赛
- if ($s_lg_id != $others_lg_id) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
- }
- //验证赛事记录是否已存在
- if (empty($others_match_id)) {
- //无赛事数据 验证本地是否存在
- $ret_match = commonFunction::ver_match($s_match_id, $source, $match_data);
- //联赛 不存在
- if ($ret_match == false) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::MATCH_ERROR));
- $l_match_id = $ret_match;
- } else {
- //有赛事数据 验证属于同请求赛事
- if ($s_match_id != $others_match_id) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::MATCH_ERROR));
- }
- //处理 赛事结果 记录
- $this->com_result_record($vv, $gameName, $l_lg_id, $l_match_id);
- break;
- case 'broadcast'://直播数据
- $this->broadcast($vv, $game_code);
- break;
- default:
- throw new \Exception(Response::generate('', Response::ABNORMAL));
- }
- }
- }
- }
- */
- //提交事务
- DB::commit();
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- return $e->getMessage();
- }
- }
- /*
- * 写入直播 数据
- */
- public function broadcast($opt = [], $game_code = '')
- {
- $data = $opt['data'];
- $set_broadcast = [
- "doing" => $data['doing'],
- "game_type" => $data['game_type'],
- "game_code" => $game_code,
- "guest_team" => $data['guest_team'],
- "host_team" => $data['host_team'],
- "league_name" => $data['league_name'],
- "shower" => $data['shower'],
- "showid" => (int)$data['showid'],
- "start_time" => $data['start_time'],
- "ctime" => date('Y-m-d H:i:s'),
- "utime" => date('Y-m-d H:i:s'),
- ];
- $ret = broadcastModel::insert($set_broadcast);
- if ($ret == false) throw new \Exception(Response::generate('', Response::BROADCAST_ERROR));
- }
- /*
- * 写入 赛事 初始 结果
- */
- public function match_result($game_code = '',$match_id = 0)
- {
- $model = commonFunction::getModels($game_code, 1);
- if ($game_code == 'zq') ZqResultModel::ZQresult_v2($model,$match_id);
- if ($game_code == 'lq') LqResultModel::LQresult_v2($model,$match_id);
- if ($game_code == 'wq') WqResultModel::WQresult_v2($model,$match_id);
- if ($game_code == 'bq') BqResultModel::BQresult_v2($model,$match_id);
- }
- /*
- * 写入联赛数据
- */
- public function league($opt = [], $gameName = '')
- {
- $game_code = $opt['game_code'];
- //根据球类代码获取相关model
- $model = commonFunction::getModels($game_code, 1);
- $data = $opt['data'];
- //查询联赛是否已存在
- $id = $model['model_league']::where('name_chinese', '=', $data['name_chinese'])
- ->value('id');
- //默认获取本年最后一天
- $last_time = date('Y-12-31 23:59:59');
- //决赛时间
- if ($data['last_time']) {
- $last_time = $data['last_time'];
- }
- $set_lg['name_chinese'] = $data['name_chinese'];
- $set_lg['kind'] = $data['kind'];
- $set_lg['match_mode'] = $data['match_mode'];
- $set_lg['if_stop'] = $data['if_stop'];
- $set_lg['identity'] = $data['uuid'] ?: '';
- $set_lg['last_time'] = $last_time;
- $set_lg['utime'] = date('Y-m-d H:i:s');
- if (empty($id)) {
- //写入联赛
- $id = $model['model_league']::insertGetId($set_lg);
- $m_lg_id = $id;
- if ($m_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::INSERT_ERROR));
- } else {
- //更新联赛
- $ret = $model['model_league']::where(['id' => $id])
- ->update($set_lg);
- if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::UPDATE_ERROR));
- }
- $set_local = [
- 'lg_id' => $id,
- 'others_lg_id' => $data['lg_id'],
- 'source' => $data['source'],
- 'ctime' => date('Y-m-d H:i:s')
- ];
- $ret = $model['model_local_league']::insertGetId($set_local);
- if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LOCAL_LEAGUE_ERROR));//Render([], '10017', lang('Tips','Sports')->get('local_league_error'));
- //执行成功返回源数据 联赛ID
- $data = ['others_lg_id' => $data['lg_id'], 'lg_id' => $id];
- return $data;
- }
- /*
- * 写入赛事数据
- */
- public function competition($opt = [], $gameName = '', $lg_id = '')
- {
- $game_code = $opt['game_code'];
- //根据球类代码获取相关model
- $model = commonFunction::getModels($game_code, 1);
- $data = $opt['data'];
- if (empty($data['lg_id'])) throw new \Exception(Response::generate('', Response::LEAGUE_ERROR));//Render([], '10015', lang('Tips','Sports')->get('league_error'));
- //查询赛事是否存在
- $id = $model['model_match']::where(['home_team' => $data['home_team'], 'guest_team' => $data['guest_team'], 'match_date' => $data['match_date'], 'match_time' => $data['match_time']])
- ->value('id');
- $half_match_id = 0;
- //如果有上半场赛事id 获取上半场赛事是否存在
- if (!empty($data['half_match_id'])) {
- $half_match_id = $match_id = $model['model_local_match']::where(['others_match_id' => $data['half_match_id'], 'source' => $data['source']])
- ->value('match_id');
- if (empty($half_match_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::HALF_MATCH_ERROR));//Render([], '10024', lang('Tips','Sports')->get('half_match_error'));
- }
- //如果赛事没有开始日期,则为冠军盘口赛事
- if (empty($data['match_date'])) {
- //冠军盘口赛事获取所属联赛结束时间
- $last_time = $model['model_league']::where(['id' => $lg_id])
- ->value('last_time');
- if (empty($last_time)) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LG_LASTTIME_ERROR));//Render([], '10023', lang('Tips','Sports')->get('lg_lastTime_error'));
- //给冠军盘口赛事 赋值时间
- $time = strtotime($last_time);
- $data['match_date'] = date('Y-m-d', $time);
- $data['match_time'] = date('H:i:s', $time);
- }
- $set_match = [
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- 'expire_time' => date('Y-m-d H:i:s', time() + 60),
- 'home_team' => $data['home_team'] ?: '',
- 'guest_team' => $data['guest_team'] ?: 'no_team',
- 'lg_id' => $lg_id,
- 'status' => $data['status'],
- 'match_date' => $data['match_date'] ?: date('Y-m-d'),
- 'match_time' => $data['match_time'] ?: date('H:i:s'),
- 'tag' => $data['tag'] ?: 0,
- 'is_rollball' => $data['is_rollball'] ?: 0,
- 'is_today' => $data['is_today'] ?: 0,
- 'is_morningplate' => $data['is_morningplate'] ?: 0,
- 'is_stringscene' => $data['is_stringscene'] ?: 0,
- 'us_time' => $data['us_time'] ?: commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
- 'half_match_id' => $half_match_id ?: 0,
- 'identity' => $data['uuid'],
- ];
- //写入赛事
- if (empty($id)) {
- //写入赛事 返回id
- $id = $model['model_match']::insertGetId($set_match);
- if ($id < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::INSERT_ERROR));
- } else {
- //更新赛事
- $ret = $model['model_match']::where(['id' => $id])->update($set_match);
- if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::UPDATE_ERROR));
- }
- //写关联记录
- $set_local = [
- 'match_id' => $id,
- 'others_match_id' => $data['match_id'],
- 'source' => $data['source'],
- 'ctime' => date('Y-m-d H:i:s')
- ];
- $ret = $model['model_local_match']::insertGetId($set_local);
- if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::LOCAL_MATCH_ERROR));//Render([], '10018', lang('Tips','Sports')->get('local_match_error'));
- //返回 源数据 赛事ID
- $data = ['others_match_id' => $data['match_id'], 'match_id' => $id];
- return $data;
- }
- /*
- * 写入赔率/赔率记录数据
- */
- public function odds($opt = [], $gameName = '', $lg_id = 0, $match_id = 0, $oddsID = '', $oddsRecordID = '')
- {
- $game_code = $opt['game_code'];
- //根据球类代码获取相关model
- $model = commonFunction::getModels($game_code, 1);
- $data = $opt['data'];
- //获取赛事 本地/源ID
- $others_match_id = $data['match_id'];
- //获取联赛 本地/源ID
- $others_lg_id = $data['lg_id'];
- //===写赔率记录===
- $set_odds_r = [
- 'match_id' => $match_id ?: 0,
- 'others_match_id' => $others_match_id ?: 0,
- 'odds_code' => $data['odds_code'] ?: '',
- 'status' => $data['status'] ?: 0,
- 'sort' => $data['sort'] ?: 0,
- 'p_code' => $data['p_code'] ?: '',
- 'odds' => $data['odds'] ?: 0,
- 'condition' => $data['condition'],
- 'odds_only' => $data['odds_only'] ?: '',
- 'source' => $data['source'] ?: '',
- 'type' => $data['type'] ?: 0,
- 'team' => $data['team'] ?: '',
- 'lg_id' => $lg_id,
- 'others_lg_id' => $others_lg_id,
- 'ctime' => date('Y-m-d H:i:s'),
- ];
- //更新或写入赔率记录
- if ($oddsRecordID != false) {
- $ret = $model['model_odds_record']::where(['id' => $oddsRecordID])
- ->update($set_odds_r);
- if ($ret < 1) throw new \Exception(Response::generate($gameName . '赔率记录-odds_only:' . $data['odds_only'] . ';', Response::ADD_ODDS_R_ERROR));//Render([], '10020', lang('Tips','Sports')->get('add_odds_r_error'));
- } else {
- $ret = $model['model_odds_record']::insert($set_odds_r);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录-odds_only:' . $data['odds_only'] . ';', Response::ADD_ODDS_R_ERROR));//Render([], '10020', lang('Tips','Sports')->get('add_odds_r_error'));
- }
- //===写赔率===
- $set_odds = [
- 'match_id' => $match_id ?: 0,
- 'others_match_id' => $others_match_id ?: 0,
- 'odds_code' => $data['odds_code'] ?: '',
- 'status' => $data['status'] ?: 0,
- 'sort' => $data['sort'] ?: 0,
- 'p_code' => $data['p_code'] ?: '',
- 'odds' => $data['odds'] ?: 0,
- 'condition' => $data['condition'],
- 'odds_only' => $data['odds_only'] ?: '',
- 'sole' => $data['sole'] ?: '',
- 'source' => $data['source'] ?: '',
- 'type' => $data['type'] ?: 0,
- 'team' => $data['team'] ?: '',
- 'lg_id' => $lg_id,
- 'others_lg_id' => $others_lg_id,
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- 'expire_time' => date('Y-m-d H:i:s', time() + 60),
- ];
- //更新或写入赔率数据
- if ($oddsID != false) {
- $ret = $model['model_odds']::where(['id' => $oddsID])
- ->update($set_odds);
- if ($ret < 1) throw new \Exception(Response::generate($gameName . '赔率-odds_only:' . $data['odds_only'] . ';', Response::ADD_ODDS_ERROR));//Render([], '10019', lang('Tips','Sports')->get('add_odds_error'));
- } else {
- $ret = $model['model_odds']::insert($set_odds);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率-odds_only:' . $data['odds_only'] . ';', Response::ADD_ODDS_ERROR));//Render([], '10019', lang('Tips','Sports')->get('add_odds_error'));
- }
- //===end===
- }
- /*
- * 更新 赛事下 所有不在本次请求的 赔率状态
- */
- public function upOddsStatus($opt = [], $gameName = '')
- {
- //获取球类代码
- $game_code = $opt['game_code'];
- //获取球类model
- $model = commonFunction::getModels($game_code, 1);
- //赛事下 所有 赔率sole
- $odds_sole = $opt['data'];
- //数据源 赛事 id
- $others_match_id = $opt['match_id'];
- //数据源
- $source = $opt['source'];
- //更新赛事下所有 不在本次请求的赔率 状态
- $ret = OddsModel::upOddsStatus($model, $others_match_id, '', $source, $odds_sole);
- if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
- }
- /*
- * 写入联赛结果
- */
- public function league_result($opt, $gameName)
- {
- $game_code = $opt['game_code'];
- //根据球类代码获取相关model
- $model = commonFunction::getModels($game_code, 1);
- $data = $opt['data'];
- //验证结果所属联赛
- $lg_id = $model['model_local_league']::where(['others_lg_id' => $data['lg_id'], 'source' => $data['source']])
- ->value('lg_id');
- if ($lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LEAGUE_ERROR));
- $lg_result_id = $model['model_league_result']::where(['lg_id' => $lg_id, 'game_name' => $data['game_name']])
- ->value('id');
- $set_lg_result = [
- 'lg_id' => $lg_id,
- 'game_name' => $data['game_name'],
- 'result' => json_encode($data['result'], JSON_UNESCAPED_UNICODE),
- 'status' => $data['status'],
- 'ctime' => date('Y-m-d H:i:s'),
- 'utime' => date('Y-m-d H:i:s'),
- ];
- //联赛结果数据处理
- if (!empty($lg_result_id)) {
- $ret = $model['model_league_result']::where(['id' => $lg_result_id])
- ->update($set_lg_result);
- if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::ADD_LG_R_ERROR));//Render([], '10021', lang('Tips','Sports')->get('add_lg_r_error'));
- } else {
- $ret = $model['model_league_result']::insert($set_lg_result);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::ADD_LG_R_ERROR));//Render([], '10021', lang('Tips','Sports')->get('add_lg_r_error'));
- }
- }
- /*
- * 写入赛事结果
- */
- public function com_result($opt = [], $gameName = '', $lg_id = '', $match_id = '')
- {
- $game_code = $opt['game_code'];
- //根据球类代码获取相关model
- $model = commonFunction::getModels($game_code, 1);
- $data = $opt['data'];
- //查询结果是否存在
- $match_r_id = $model['model_result']::where(['match_id' => $match_id])
- ->value('id');
- $set_match_r = [
- "home_team" => $data['home_team'],
- "guest_team" => $data['guest_team'],
- "lg_id" => $lg_id,
- "home_rate" => $data['home_rate'],
- "guest_rate" => $data['guest_rate'],
- "home_score" => $data['home_score'],
- "guest_score" => $data['guest_score'],
- "all_goal" => $data['all_goal'],
- "status" => $data['status'],
- "first_score" => $data['first_score'],
- "last_score" => $data['last_score'],
- "match_score" => $data['match_score'],
- "match_winer" => $data['match_winer'],
- "match_time" => $data['match_time'],
- "match_process" => $data['match_process'],
- "tag" => $data['tag'],
- "match_id" => $match_id,
- "u_home_score" => $data['u_home_score'],
- "u_guest_score" => $data['u_guest_score'],
- "p_code" => $data['p_code'],
- "update_time" => date('Y-m-d H:i:s')
- ];
- //赛事结果数据处理
- if (!empty($match_r_id)) {
- $ret = $model['model_result']::where(['id' => $match_r_id])
- ->update($set_match_r);
- if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
- } else {
- $ret = $model['model_result']::insert($set_match_r);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
- }
- // return Response::success();
- }
- //写入赛事结果记录
- public function com_result_record($opt = [], $gameName = '', $lg_id = '', $match_id = '')
- {
- $game_code = $opt['game_code'];
- //根据球类代码获取相关model
- $model = commonFunction::getModels($game_code, 1);
- $data = $opt['data'];
- $match_r_id = $model['model_result_record']::where(['match_id' => $match_id, 'match_time' => $data['match_time']])
- ->value('id');
- //根据球类 获取 赛事结果记录字段
- $set_match_r = $this->get_match_r($game_code, $lg_id, $match_id, $data);
- //赛事结果记录处理
- if ($match_r_id > 0) {
- $ret = $model['model_result_record']::where(['id' => $match_r_id])
- ->update($set_match_r);
- if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_r_error'));
- } else {
- $ret = $model['model_result_record']::insert($set_match_r);
- if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_r_error'));
- }
- }
- /**
- * 写赛果数据
- */
- public function setResultExpress_v1($data){
- //验证token
- $user = new \App\Models\System_user;
- if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
- $token = $user::where(['token' => $data->token])->value('token');
- if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
- try {
- //开启事务
- DB::beginTransaction();
- $obt = $data->data;
- //请求 数据 为空
- if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
- $getData = $this->getAddData($obt);
- //不是 赛事 结果 记录 数据
- if ($getData['title'] != 'result') throw new \Exception(Response::generate('不是赛果数据,', Response::ABNORMAL));
- //获取球类代码
- $game_code = $getData['game_code'];
- //获取数据源
- $source = $getData['source'];
- //获取球类名称
- $gameName = gameModel::getGameName($game_code);
- //获取 model
- $models = commonFunction::getModels($game_code, 1);
- //获取 赛事 数据
- $match_r_data = $getData['data'];
-
- if(!empty($match_r_data)){
- foreach($match_r_data as $k=>$v){
- //删除已存在
- $del = $models['model_result_express']::where('match_id',$v['match_id'])->delete();
- //==处理 赛事时间==
- // dd($v['match_date'].' '.$v['match_time']);
- $match_time_o = strtotime ($v['match_date'].' '.$v['match_time']);//原始美东时间 时间戳
- $match_time_new = strtotime(commonFunction::qgmdate('Y-m-d H:i:s', $match_time_o, 20));//本地时间 时间戳 20=8+12
- $match_date = date('Y-m-d',$match_time_new);
- $match_time = date('H:i:s',$match_time_new);
- //==end==
- $v['match_date'] = $match_date;
- $v['match_time'] = $match_time;
- $v['c_time'] = date('Y-m-d H:i:s',time());
- $v['u_time'] = date('Y-m-d H:i:s',time());
- $v['source'] = $source;
- $v['play_data'] = json_encode($v['play_data'],JSON_UNESCAPED_UNICODE);
- $ret = $models['model_result_express']::insert($v);
- if ($ret != true) throw new \Exception(Response::generate($gameName . ';', Response::SET_MATCH_R_ERR));
- }
-
- //写 赛事 结果 记录
- }
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
- return $e->getMessage();
- }
- }
- /**
- * 写赛事危险球数据
- */
- public function setMatchWarn_v1($data){
- //验证token
- $user = new \App\Models\System_user;
- if (empty($data->token)) return Response::generate('未获取到token:', Response::TOKEN_ERR);
- $token = $user::where(['token' => $data->token])->value('token');
- if (empty($token)) return Response::generate('token验证不通过:', Response::TOKEN_ERR);
-
- try {
- //开启事务
- DB::beginTransaction();
- $obt = $data->data;
- //请求 数据 为空
- if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
- $getData = $this->getAddData($obt);
-
- //不是 赛事 危险球 数据
- if ($getData['title'] != 'match_warn') throw new \Exception(Response::generate('不是危险球数据,', Response::ABNORMAL));
- //获取球类代码
- $game_code = $getData['game_code'];
- //获取数据源
- $source = $getData['source'];
- //获取数据源赛事id
- $others_match_id = $getData['match_id'];
- //获取数据源赛事uuid
- $match_identity = $getData['match_identity'];
- //获取球类名称
- $gameName = gameModel::getGameName($game_code);
- //获取 model
- $models = commonFunction::getModels($game_code, 1);
- //获取 赛事 数据
- $warn_data = $getData['data'];
- //获取赛事 match_id
- $match_id = $models['model_local_match']::SELECT('others_match_id', 'match_id')
- // ->where(['source' => $source,'identity' => $match_identity])
- ->where(['identity' => $match_identity])
- ->first()->match_id;
- if(!empty($match_id)){
- //更新 危险球
- $ret = ZqResultModel::set_result_warn($match_id,$warn_data);
- if($ret < 1) throw new \Exception( Response::generate('',Response::SET_WARN_ERR));
- //追加 滚球投注 危险球审核
- // SportsNoteListModel::WarnHandle($match_id,$warn_data);
- }
-
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
- return $e->getMessage();
- }
- }
- /**
- * 定时执行 滚球投注危险球审核
- * 每分钟执行一次
- */
- public function HandleOrder(){
- try {
- //开启事务
- DB::beginTransaction();
- $time = 60;
- //处理指定时间内的滚球待审核订单
- SportsNoteListModel::getOrderData($time);
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('zq', [], 'HandleOrder', Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('zq', [], 'HandleOrder', $e->getMessage());
- return $e->getMessage();
- }
- }
- /**
- * 定时执行 处理到时间应该开始而未开始的赛事
- * 每分钟执行一次
- */
- public function HandleMatch(){
- try {
- //开启事务
- DB::beginTransaction();
- $time = 60;//60 秒
- //处理指定时间内的赛事
- StMatchModel::HandleMatch($time);
- //提交事务
- DB::commit();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('all', [], 'HandleMatch', Response::success());
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- //写请求数据 日志记录
- if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('all', [], 'HandleMatch', $e->getMessage());
- return $e->getMessage();
- }
- }
- /**
- * @param $data
- * @return mixed
- * json转数组
- */
- public function getAddData($data)
- {
- $data = json_decode($data, true);
- return $data;
- }
- /*
- * 根据球类获取 赛事结果记录字段
- */
- public function get_match_r($game_code, $lg_id, $match_id, $data)
- {
- $set_match_r = [];
- if ($game_code == 'zq') {
- $set_match_r = [
- "home_team" => $data['home_team'] ?: '',
- "guest_team" => $data['guest_team'] ?: '',
- "lg_id" => $lg_id,
- "all_goal" => $data['all_goal'] ?: 0,
- "home_rate" => $data['home_rate'] ?: 0,
- "guest_rate" => $data['guest_rate'] ?: 0,
- "home_score" => $data['home_score'] ?: 0,
- "guest_score" => $data['guest_score'] ?: 0,
- "status" => $data['status'] ?: 0,
- "first_score" => $data['first_score'] ?: 0,
- "last_score" => $data['last_score'] ?: 0,
- "match_score" => $data['match_score'] ?: 0,
- "match_winer" => $data['match_winer'] ?: '',
- "match_time" => $data['match_time'] ?: 0,
- "match_process" => $data['match_process'] ?: '',
- // "tag"=> $data['tag']?:0,
- "match_id" => $match_id,
- "update_time" => date('Y-m-d H:i:s')
- ];
- };
- if ($game_code == 'lq') {
- $set_match_r = [
- "home_team" => $data['home_team'] ?: '',
- "guest_team" => $data['guest_team'] ?: '',
- "lg_id" => $lg_id,
- "home_rate" => $data['home_rate'] ?: 0,
- "guest_rate" => $data['guest_rate'] ?: 0,
- "home_score" => $data['home_score'] ?: 0,
- "guest_score" => $data['guest_score'] ?: 0,
- "status" => $data['status'] ?: 0,
- "first_score" => $data['first_score'] ?: 0,
- "last_score" => $data['last_score'] ?: 0,
- "match_score" => $data['match_score'] ?: 0,
- "match_winer" => $data['match_winer'] ?: '',
- "match_time" => $data['match_time'] ?: 0,
- "match_process" => $data['match_process'] ?: '',
- // "tag"=> $data['tag']?:0,
- "match_id" => $match_id,
- "update_time" => date('Y-m-d H:i:s'),
- "result_mark" => json_encode($data['result_mark']) ?: '',
- ];
- }
- if ($game_code == 'wq') {
- $set_match_r = [
- "home_player_name" => $data['home_player_name'] ?: '',
- "guest_player_name" => $data['guest_player_name'] ?: '',
- "lg_id" => $lg_id,
- "home_player_let_plate" => $data['home_player_let_plate'] ?: 0,
- "guest_player_let_plate" => $data['guest_player_let_plate'] ?: 0,
- "home_player_let_inning" => $data['home_player_let_inning'] ?: 0,
- "guest_player_let_inning" => $data['guest_player_let_inning'] ?: 0,
- "all_inning" => $data['all_inning'] ?: 0,
- "home_player_score" => $data['home_player_score'] ?: 0,
- "guest_player_score" => $data['guest_player_score'] ?: 0,
- "status" => $data['status'] ?: 0,
- "first_score_player" => $data['first_score_player'] ?: '',
- "last_score_player" => $data['last_score_player'] ?: '',
- "first_inning_score" => $data['first_inning_score'] ?: 0,
- "second_inning_score" => $data['second_inning_score'] ?: 0,
- "third_inning_score" => $data['third_inning_score'] ?: 0,
- "match_winer_player" => $data['match_winer_player'] ?: '',
- "update_time" => date('Y-m-d H:i:s'),
- "match_time" => $data['match_time'] ?: 0,
- "match_process" => $data['match_process'] ?: '',
- // "tag"=>$data['tag']?:0,
- "match_id" => $match_id,
- "result_mark" => json_encode($data['result_mark']) ?: '',
- ];
- }
- if ($game_code == 'bq') {
- $set_match_r = [
- "home_team" => $data['home_team'] ?: '',
- "guest_team" => $data['guest_team'] ?: '',
- "lg_id" => $lg_id,
- "home_rate" => $data['home_rate'] ?: 0,
- "guest_rate" => $data['guest_rate'] ?: 0,
- "home_score" => $data['home_score'] ?: 0,
- "guest_score" => $data['guest_score'] ?: 0,
- "status" => $data['status'] ?: 0,
- "first_score" => $data['first_score'] ?: 0,
- "last_score" => $data['last_score'] ?: 0,
- "match_score" => $data['match_score'] ?: 0,
- "match_winer" => $data['match_winer'] ?: '',
- "match_time" => $data['match_time'] ?: 0,
- "match_process" => $data['match_process'] ?: '',
- // "tag"=> $data['tag']?:0,
- "match_id" => $match_id,
- "all_inning" => $data['all_inning'] ?: 9,
- "update_time" => date('Y-m-d H:i:s'),
- "result_mark" => json_encode($data['result_mark']) ?: '',
- ];
- }
- return $set_match_r;
- }
- //将数组按按指定健名,重新生成新的数组,key在存在并且 值不能重复
- private function ArrayKeySet(Array $array, $key)
- {
- $ret = [];
- foreach ($array as $val) {
- $ret[$val[$key]] = $val;
- }
- return $ret;
- }
- }
|