WriteSportsController.php 142 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Jun.peng
  5. * Date: 2019/5/13
  6. * Time: 10:19
  7. */
  8. namespace App\Http\Controllers\Api;
  9. use Illuminate\Routing\Controller as BaseController;
  10. use App\Http\Response\Response;
  11. use Illuminate\Http\Request as Req;
  12. use Illuminate\Support\Facades\DB;
  13. use App\Lib\Biz\Sport\Common as commonFunction;
  14. use App\Http\Model\StBqResult as BqResultModel;
  15. use App\Http\Model\StBroadcast as broadcastModel;
  16. use App\Http\Model\StGameType as gameModel;
  17. use App\Http\Model\StLqResult as LqResultModel;
  18. use App\Http\Model\StWqResult as WqResultModel;
  19. use App\Http\Model\StZqOdds as OddsModel;
  20. use App\Http\Model\StZqResult as ZqResultModel;
  21. use App\Http\Model\St_area_country as StAreaCountryModel;
  22. use App\Http\Model\St_team as StTeamModel;
  23. use App\Http\Model\StZqMatch as StMatchModel;
  24. use App\Models\SportsNoteList as SportsNoteListModel;
  25. /**
  26. * 体育数据入库接口
  27. */
  28. class WriteSportsController extends BaseController
  29. {
  30. //是否启用 数据写入记录
  31. protected $isRecord;
  32. public function __construct()
  33. {
  34. $this->isRecord = config('record.isRecord');
  35. }
  36. //写联赛
  37. public function setLeague(Req $data)
  38. {
  39. $ret = $this->setLeague_v1($data);
  40. return $ret;
  41. }
  42. //写赛事
  43. public function setMatch(Req $data)
  44. {
  45. $ret = $this->setMatch_v2($data);
  46. return $ret;
  47. }
  48. //写赛事结果记录
  49. public function setMatchResult(Req $data)
  50. {
  51. $ret = $this->setMatchResult_v2($data);
  52. return $ret;
  53. }
  54. //写赛事赔率
  55. public function setOdds(Req $data)
  56. {
  57. $ret = $this->setOdds_v3($data);
  58. return $ret;
  59. }
  60. //写冠军联赛赔率
  61. public function setOddsCH(Req $data)
  62. {
  63. $ret = $this->setOddsCH_v2($data);
  64. return $ret;
  65. }
  66. //写直播数据
  67. public function setBroadCast(Req $data)
  68. {
  69. $ret = $this->setBroadCast_v1($data);
  70. return $ret;
  71. }
  72. //写危险球数据
  73. public function setMatchWarn(Req $data){
  74. $ret = $this->setMatchWarn_v1($data);
  75. return $ret;
  76. }
  77. //写赛果接口
  78. public function setResultExpress(Req $data)
  79. {
  80. $ret = $this->setResultExpress_v1($data);
  81. return $ret;
  82. }
  83. //更新投注数据接口
  84. public function upOrder(Req $data){
  85. $ret = $this->upOrder_v1($data);
  86. return $ret;
  87. }
  88. /*
  89. * 用户 用户 token
  90. */
  91. public function getToken(Req $req)
  92. {
  93. if ($req->isMethod('post')) {
  94. $user = new \App\Models\System_user;
  95. $str = $user->adminLogin($_POST['account'], $_POST['password']);
  96. if($str < 0) return Response::generate('', Response::USER_ERR);
  97. if ($str > 0) {
  98. $token = refreshToken($str['admin_id']);
  99. $str['token'] = $token;
  100. $data = $str;
  101. $req->session()->put('adminInfo', $str);
  102. $str = 1;
  103. }
  104. $log = array(
  105. session('adminInfo.admin_name'),
  106. $_POST['account']
  107. );
  108. OperationLog(session('adminInfo.admin_id'), 'login', $log);
  109. return Response::success($data);
  110. }
  111. }
  112. /**
  113. * 根据联赛名称 获取 国家 地区
  114. */
  115. public function getArea($leagueName = '')
  116. {
  117. //如果联赛名称有括号,去除
  118. $leagueName = preg_replace('/\(.*?\)/', '', $leagueName);
  119. //获取所有国家/地区
  120. $areaData = StAreaCountryModel::select('id', 'pid', 'name')->get()->toArray();
  121. //获取当前联赛所属国家
  122. if (strpos($leagueName, 'NBA') !== false) {
  123. $data = [
  124. 'id' => 247,
  125. 'pid' => 0,
  126. 'name' => '世界'
  127. ];
  128. return $data;
  129. }
  130. //识别本地 国家地区数据
  131. foreach ($areaData as $v => $k) {
  132. if (strpos($leagueName, $k['name']) !== false) {
  133. return $k;
  134. }
  135. }
  136. //如果不能识别,则返回世界
  137. $data = [
  138. 'id' => 247,
  139. 'pid' => 0,
  140. 'name' => '世界'
  141. ];
  142. return $data;
  143. }
  144. /*
  145. * 写 联赛 数据
  146. * 每个请求 包含 N个联赛
  147. */
  148. public function setLeague_v1($data)
  149. {
  150. //验证token
  151. $user = new \App\Models\System_user;
  152. if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
  153. $token = $user::where(['token' => $data->token])->value('token');
  154. if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
  155. try {
  156. //开启事务
  157. DB::beginTransaction();
  158. $obt = $data->data;
  159. //请求 数据 为空
  160. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  161. $getData = $this->getAddData($obt);
  162. //不是 联赛 数据
  163. if ($getData['title'] != 'league') throw new \Exception(Response::generate('不是联赛数据,', Response::ABNORMAL));
  164. /*
  165. //写请求数据 日志记录
  166. if($this->isRecord){
  167. commonFunction::SET_SPORTS_RECORD($obt,$getData['title']);
  168. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  169. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  170. }
  171. */
  172. //获取球类代码
  173. $game_code = $getData['game_code'];
  174. //获取数据源
  175. $source = $getData['source'];
  176. //获取球类名称
  177. $gameName = gameModel::getGameName($game_code);
  178. //获取 model
  179. $models = commonFunction::getModels($game_code, 1);
  180. //获取 联赛 数据
  181. $leagueData = $getData['data'];
  182. //获取 当前请求 所有 联赛 uuid
  183. $identity = [];
  184. foreach ($leagueData as $k => $v) {
  185. $identity[] = $v['uuid'];
  186. }
  187. $identity = array_unique($identity);
  188. sort($identity);
  189. //获取 本地 已存在 联赛
  190. $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id')->get()->toArray();
  191. //二维数组去重
  192. $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
  193. //循环对比 请求identity->本地identity
  194. foreach ($l_lg_data as $k => $v) {
  195. foreach ($identity as $kk => $uuid) {
  196. if ($v['identity'] == $uuid) {
  197. unset($identity[$kk]);
  198. }
  199. }
  200. }
  201. //去除本地和请求里都存在的联赛,如果还有剩余联赛uuid,则将其写入
  202. if (!empty($identity)) {
  203. //没有 决赛时间 默认获取本年最后一天
  204. $last_time = date('Y-12-31 23:59:59');
  205. foreach ($leagueData as $k => $v) {
  206. foreach ($identity as $kk => $uuid) {
  207. if ($v['uuid'] == $uuid) {
  208. //如有 决赛时间
  209. if ($v['last_time']) {
  210. $last_time = $v['last_time'];
  211. }
  212. //获取联赛所属国家或地区
  213. $getArea = $this->getArea($v['name_chinese']);
  214. if ($getArea['pid'] == 0) {
  215. $area_id = $getArea['id'];
  216. $country_id = 0;
  217. } else {
  218. $area_id = $getArea['pid'];
  219. $country_id = $getArea['id'];
  220. }
  221. if (empty($v['uuid'])) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $v['lg_id'] . ';', Response::LG__UUID_NULL));
  222. $set_lg['name_chinese'] = $v['name_chinese'];
  223. $set_lg['kind'] = $v['kind'];
  224. $set_lg['match_mode'] = $v['match_mode'];
  225. $set_lg['if_stop'] = $v['if_stop'];
  226. $set_lg['identity'] = $v['uuid'];
  227. $set_lg['last_time'] = $last_time;
  228. $set_lg['utime'] = date('Y-m-d H:i:s');
  229. $set_lg['area_id'] = $area_id ?: 247;
  230. $set_lg['country_id'] = $country_id ?: 0;
  231. //写入联赛
  232. $id = $models['model_league']::insertGetId($set_lg);
  233. $m_lg_id = $id;
  234. if ($m_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $v['lg_id'] . ';', Response::INSERT_ERROR));
  235. //写入 本地 联赛记录
  236. $set_local = [
  237. 'lg_id' => $id,
  238. 'others_lg_id' => $v['lg_id'],
  239. 'source' => $source,
  240. 'ctime' => date('Y-m-d H:i:s'),
  241. 'identity' => $v['uuid'],
  242. ];
  243. $ret = $models['model_local_league']::insertGetId($set_local);
  244. 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'));
  245. }
  246. }
  247. }
  248. }
  249. //提交事务
  250. DB::commit();
  251. //写请求数据 日志记录
  252. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
  253. return Response::success();
  254. } catch (\Exception $e) {
  255. //回滚事务
  256. DB::rollBack();
  257. //写请求数据 日志记录
  258. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
  259. return $e->getMessage();
  260. }
  261. }
  262. /*
  263. * 写 赛事 数据
  264. * 每个请求 包含 N个联赛 下 N个赛事
  265. * 新增合并赛事 追加赛事uuid字段
  266. */
  267. public function setMatch_v2($data)
  268. {
  269. //验证token
  270. $user = new \App\Models\System_user;
  271. if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
  272. $token = $user::where(['token' => $data->token])->value('token');
  273. if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
  274. try {
  275. //开启事务
  276. DB::beginTransaction();
  277. $obt = $data->data;
  278. //请求 数据 为空
  279. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  280. $getData = $this->getAddData($obt);
  281. //不是 赛事 数据
  282. if ($getData['title'] != 'match') throw new \Exception(Response::generate('不是赛事数据,', Response::ABNORMAL));
  283. /*
  284. //写请求数据 日志记录
  285. if($this->isRecord){
  286. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  287. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  288. }
  289. */
  290. //获取球类代码
  291. $game_code = $getData['game_code'];
  292. //获取数据源
  293. $source = $getData['source'];
  294. //获取球类名称
  295. $gameName = gameModel::getGameName($game_code);
  296. //获取 model
  297. $models = commonFunction::getModels($game_code, 1);
  298. //获取 赛事 数据
  299. $matchData = $getData['data'];
  300. //获取 当前请求 所有 uuid
  301. $identity = [];
  302. $s_match_ids = [];
  303. $match_uuids = [];
  304. foreach ($matchData as $k => $v) {
  305. $identity[] = $v['uuid'];
  306. $s_match_ids[] = $v['match_id'];
  307. }
  308. //====验证 赛事 所属 联赛 是否存在====
  309. $identity = array_unique($identity);
  310. sort($identity);
  311. //获取 本地 已存在 联赛
  312. $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id', 'others_lg_id')->get()->toArray();
  313. //二维数组去重
  314. $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
  315. //如果获取不到本地联赛数据,则返回联赛不存在
  316. if (empty($l_lg_data)) throw new \Exception(Response::generate($gameName . '本次请求的所有赛事都没有联赛数据;', Response::LEAGUE_ERROR));
  317. //获取到本次请求,所有本地有联赛的赛事
  318. $mathData_before = $matchData;//接收原赛事
  319. $matchData = [];//获取新赛事
  320. foreach ($l_lg_data as $k => $v) {
  321. foreach ($mathData_before as $kk => $vv) {
  322. if ($v['identity'] == $vv['uuid']) {
  323. $matchData[] = $vv;
  324. }
  325. }
  326. }
  327. //获取当前请求有关联联赛的赛事 match_id
  328. $s_match_ids = [];
  329. foreach ($matchData as $k => $v) {
  330. $s_match_ids[] = $v['match_id'];
  331. //追加获取赛事uuid
  332. $match_uuids[] = $v['match_identity'];
  333. }
  334. //====获取 本地 已存在 赛事====
  335. $match_uuids = array_unique($match_uuids);
  336. sort($match_uuids);
  337. // $l_match_data = $models['model_local_match']::whereIn('identity', $match_uuids)->where('source', $source)->select('match_id', 'identity')->get()->toArray();
  338. $l_match_data = $models['model_local_match']::whereIn('identity', $match_uuids)->select('match_id', 'identity')->get()->toArray();
  339. //二维数组去重
  340. $l_match_data = commonFunction::uniquArrV2($l_match_data, 'identity');
  341. //循环对比 请求match_id->本地others_match_id
  342. //如果本地有 赛事,则分别获取本地已存在/不存在赛事
  343. if (!empty($l_match_data)) {
  344. //本地已存在赛事,用于更新
  345. $matchData_y = [];
  346. foreach ($l_match_data as $k => $v) {
  347. foreach ($match_uuids as $kk => $match_identity) {
  348. if ($v['identity'] == $match_identity) {
  349. $matchData_y[$k]['match_identity'] = $match_identity;
  350. $matchData_y[$k]['match_id'] = $v['match_id'];
  351. unset($match_uuids[$kk]);
  352. }
  353. }
  354. }
  355. sort($match_uuids);
  356. }
  357. //如果 请求中 有本地赛事,则执行更新
  358. if (!empty($matchData_y)) {
  359. foreach ($matchData as $k => $v) {
  360. foreach ($matchData_y as $kk => $vv) {
  361. if ($v['match_identity'] == $vv['match_identity']) {
  362. $data = $v;
  363. $up_match = [];
  364. $up_match['utime'] = date('Y-m-d H:i:s');
  365. $up_match['status'] = $data['status'];
  366. //获取需更新字段
  367. if ($data['is_rollball'] == 1) {
  368. $up_match['is_rollball'] = $data['is_rollball'];
  369. }
  370. if ($data['is_today'] == 1) {
  371. $up_match['is_today'] = $data['is_today'];
  372. }
  373. if ($data['is_morningplate'] == 1) {
  374. $up_match['is_morningplate'] = $data['is_morningplate'];
  375. }
  376. if ($data['is_stringscene'] == 1) {
  377. $up_match['is_stringscene'] = $data['is_stringscene'];
  378. }
  379. //追加更新开赛日期/时间
  380. $up_match['match_date'] = $data['match_date'];
  381. $up_match['match_time'] = $data['match_time'];
  382. $up_match['us_time'] = $data['us_time'];
  383. //如果是网球 追加rule 字段
  384. if ($game_code == 'wq' and !empty($data['rule'])) {
  385. $up_match['rule'] = $data['rule'];
  386. }
  387. //更新赛事 返回成功数量
  388. $set = $models['model_match']::where(['id' => $vv['match_id']])
  389. ->update($up_match);
  390. if ($set < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::UPSTATUS_ERROR));
  391. }
  392. }
  393. }
  394. }
  395. //剩余 赛事 数据 写入
  396. if (!empty($match_uuids)) {
  397. foreach ($matchData as $k => $v) {
  398. foreach ($match_uuids as $kk => $match_identity) {
  399. if ($v['match_identity'] == $match_identity) {
  400. $data = $v;
  401. //===追加查询 该赛事 本地是否存在 同联赛同球队 记录
  402. //查询赛事 如果存在 则更新为 已取消
  403. $matchData = $models['model_match']::where(['home_team' => $data['home_team'],'guest_team' => $data['guest_team'],'identity'=>$data['uuid']])
  404. ->update(['status'=>6,'utime'=>date('Y-m-d H:i:s'),'handle_mark'=>'重复赛事取消']);
  405. //===end===
  406. $half_match_id = $v['half_match_id'];
  407. //获取 本地 联赛 ID
  408. //验证本赛事是否有数据源lg_id
  409. if (empty($data['lg_id'])) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::S_LG_ID_NULL));
  410. $lg_id = commonFunction::searcharray($data['uuid'], 'identity', $l_lg_data, 'lg_id');
  411. //验证 本赛事是否获取到本地lg_id
  412. if (empty($lg_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::L_LG_ID_NULL));
  413. //如果赛事没有开始日期,则为冠军盘口赛事
  414. if (empty($data['match_date'])) {
  415. //冠军盘口赛事获取所属联赛结束时间
  416. $last_time = $models['model_league']::where(['id' => $lg_id])
  417. ->value('last_time');
  418. 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'));
  419. //给冠军盘口赛事 赋值时间
  420. $time = strtotime($last_time);
  421. $data['match_date'] = date('Y-m-d', $time);
  422. $data['match_time'] = date('H:i:s', $time);
  423. }
  424. $set_match = [
  425. 'ctime' => date('Y-m-d H:i:s'),
  426. 'utime' => date('Y-m-d H:i:s'),
  427. 'expire_time' => date('Y-m-d H:i:s', time() + 60),
  428. 'home_team' => $data['home_team'] ?: '',
  429. 'guest_team' => $data['guest_team'] ?: 'no_team',
  430. 'lg_id' => $lg_id,
  431. 'status' => $data['status'],
  432. 'match_date' => $data['match_date'] ?: date('Y-m-d'),
  433. 'match_time' => $data['match_time'] ?: date('H:i:s'),
  434. 'is_rollball' => $data['is_rollball'] ?: 0,
  435. 'is_today' => $data['is_today'] ?: 0,
  436. 'is_morningplate' => $data['is_morningplate'] ?: 0,
  437. 'is_stringscene' => $data['is_stringscene'] ?: 0,
  438. 'is_horn' => $data['is_horn']?:0,
  439. 'us_time' => $data['us_time'] ?: commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
  440. 'half_match_id' => $half_match_id ?: 0,
  441. 'identity' => $data['uuid'],
  442. 'match_identity' => $data['match_identity'],
  443. ];
  444. //如果是网球 追加rule 字段
  445. if ($game_code == 'wq') {
  446. $set_match['rule'] = $data['rule'];
  447. }
  448. //写入赛事 返回id
  449. $id = $models['model_match']::insertGetId($set_match);
  450. if ($id < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::INSERT_ERROR));
  451. //写关联记录
  452. $set_local = [
  453. 'match_id' => $id,
  454. 'others_match_id' => $data['match_id'],
  455. 'source' => $source,
  456. 'identity' => $data['match_identity'],
  457. 'ctime' => date('Y-m-d H:i:s')
  458. ];
  459. $ret = $models['model_local_match']::insertGetId($set_local);
  460. if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::LOCAL_MATCH_ERROR));
  461. //追加写球队名称
  462. $team = [
  463. 'team_h' => $data['home_team'],
  464. 'team_g' => $data['guest_team'],
  465. ];
  466. StTeamModel::setTeam($game_code, $team, $source);
  467. //追加写赛事结果
  468. $opt = [
  469. 'data' => $data,
  470. 'lg_id' => $lg_id,
  471. 'match_id' => $id,
  472. 'models' => $models,
  473. 'gameName' => $gameName,
  474. 'game_code' => $game_code,
  475. ];
  476. ZqResultModel::set_result($opt);
  477. }
  478. }
  479. }
  480. }
  481. //提交事务
  482. DB::commit();
  483. //写请求数据 日志记录
  484. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
  485. return Response::success();
  486. } catch (\Exception $e) {
  487. //回滚事务
  488. DB::rollBack();
  489. //写请求数据 日志记录
  490. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
  491. return $e->getMessage();
  492. }
  493. }
  494. public function setMatch_v1($data)
  495. {
  496. //验证token
  497. $user = new \App\Models\System_user;
  498. if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
  499. $token = $user::where(['token' => $data->token])->value('token');
  500. if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
  501. try {
  502. //开启事务
  503. DB::beginTransaction();
  504. $obt = $data->data;
  505. //请求 数据 为空
  506. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  507. $getData = $this->getAddData($obt);
  508. //不是 赛事 数据
  509. if ($getData['title'] != 'match') throw new \Exception(Response::generate('不是赛事数据,', Response::ABNORMAL));
  510. /*
  511. //写请求数据 日志记录
  512. if($this->isRecord){
  513. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  514. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  515. }
  516. */
  517. //获取球类代码
  518. $game_code = $getData['game_code'];
  519. //获取数据源
  520. $source = $getData['source'];
  521. //获取球类名称
  522. $gameName = gameModel::getGameName($game_code);
  523. //获取 model
  524. $models = commonFunction::getModels($game_code, 1);
  525. //获取 赛事 数据
  526. $matchData = $getData['data'];
  527. //获取 当前请求 所有 uuid
  528. $identity = [];
  529. $s_match_ids = [];
  530. foreach ($matchData as $k => $v) {
  531. $identity[] = $v['uuid'];
  532. $s_match_ids[] = $v['match_id'];
  533. }
  534. //====验证 赛事 所属 联赛 是否存在====
  535. $identity = array_unique($identity);
  536. sort($identity);
  537. //获取 本地 已存在 联赛
  538. $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id', 'others_lg_id')->get()->toArray();
  539. //二维数组去重
  540. $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
  541. //如果获取不到本地联赛数据,则返回联赛不存在
  542. if (empty($l_lg_data)) throw new \Exception(Response::generate($gameName . '本次请求的所有赛事都没有联赛数据;', Response::LEAGUE_ERROR));
  543. //获取到本次请求,所有本地有联赛的赛事
  544. $mathData_before = $matchData;//接收原赛事
  545. $matchData = [];//获取新赛事
  546. foreach ($l_lg_data as $k => $v) {
  547. foreach ($mathData_before as $kk => $vv) {
  548. if ($v['identity'] == $vv['uuid']) {
  549. $matchData[] = $vv;
  550. }
  551. }
  552. }
  553. //获取当前请求有关联联赛的赛事 match_id
  554. $s_match_ids = [];
  555. foreach ($matchData as $k => $v) {
  556. $s_match_ids[] = $v['match_id'];
  557. }
  558. //====获取 本地 已存在 赛事====
  559. $s_match_ids = array_unique($s_match_ids);
  560. sort($s_match_ids);
  561. $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();
  562. //二维数组去重
  563. $l_match_data = commonFunction::uniquArrV2($l_match_data, 'others_match_id');
  564. //循环对比 请求match_id->本地others_match_id
  565. //如果本地有 赛事,则分别获取本地已存在/不存在赛事
  566. if (!empty($l_match_data)) {
  567. //本地已存在赛事,用于更新
  568. $matchData_y = [];
  569. foreach ($l_match_data as $k => $v) {
  570. foreach ($s_match_ids as $kk => $s_match_id) {
  571. if ($v['others_match_id'] == $s_match_id) {
  572. $matchData_y[$k]['others_match_id'] = $s_match_id;
  573. $matchData_y[$k]['match_id'] = $v['match_id'];
  574. unset($s_match_ids[$kk]);
  575. }
  576. }
  577. }
  578. sort($s_match_ids);
  579. }
  580. //如果 请求中 有本地赛事,则执行更新
  581. if (!empty($matchData_y)) {
  582. foreach ($matchData as $k => $v) {
  583. foreach ($matchData_y as $kk => $vv) {
  584. if ($v['match_id'] == $vv['others_match_id']) {
  585. $data = $v;
  586. $up_match = [];
  587. $up_match['utime'] = date('Y-m-d H:i:s');
  588. $up_match['status'] = $data['status'];
  589. //获取需更新字段
  590. if ($data['is_rollball'] == 1) {
  591. $up_match['is_rollball'] = $data['is_rollball'];
  592. }
  593. if ($data['is_today'] == 1) {
  594. $up_match['is_today'] = $data['is_today'];
  595. }
  596. if ($data['is_morningplate'] == 1) {
  597. $up_match['is_morningplate'] = $data['is_morningplate'];
  598. }
  599. if ($data['is_stringscene'] == 1) {
  600. $up_match['is_stringscene'] = $data['is_stringscene'];
  601. }
  602. //追加更新开赛日期/时间
  603. $up_match['match_date'] = $data['match_date'];
  604. $up_match['match_time'] = $data['match_time'];
  605. $up_match['us_time'] = $data['us_time'];
  606. //如果是网球 追加rule 字段
  607. if ($game_code == 'wq' and !empty($data['rule'])) {
  608. $up_match['rule'] = $data['rule'];
  609. }
  610. //更新赛事 返回成功数量
  611. $set = $models['model_match']::where(['id' => $vv['match_id']])
  612. ->update($up_match);
  613. if ($set < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::UPSTATUS_ERROR));
  614. }
  615. }
  616. }
  617. }
  618. //剩余 赛事 数据 写入
  619. if (!empty($s_match_ids)) {
  620. foreach ($matchData as $k => $v) {
  621. foreach ($s_match_ids as $kk => $s_match_id) {
  622. if ($v['match_id'] == $s_match_id) {
  623. $data = $v;
  624. $half_match_id = $v['half_match_id'];
  625. //获取 本地 联赛 ID
  626. //验证本赛事是否有数据源lg_id
  627. if (empty($data['lg_id'])) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::S_LG_ID_NULL));
  628. $lg_id = commonFunction::searcharray($data['uuid'], 'identity', $l_lg_data, 'lg_id');
  629. //验证 本赛事是否获取到本地lg_id
  630. if (empty($lg_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::L_LG_ID_NULL));
  631. //如果赛事没有开始日期,则为冠军盘口赛事
  632. if (empty($data['match_date'])) {
  633. //冠军盘口赛事获取所属联赛结束时间
  634. $last_time = $models['model_league']::where(['id' => $lg_id])
  635. ->value('last_time');
  636. 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'));
  637. //给冠军盘口赛事 赋值时间
  638. $time = strtotime($last_time);
  639. $data['match_date'] = date('Y-m-d', $time);
  640. $data['match_time'] = date('H:i:s', $time);
  641. }
  642. $set_match = [
  643. 'ctime' => date('Y-m-d H:i:s'),
  644. 'utime' => date('Y-m-d H:i:s'),
  645. 'expire_time' => date('Y-m-d H:i:s', time() + 60),
  646. 'home_team' => $data['home_team'] ?: '',
  647. 'guest_team' => $data['guest_team'] ?: 'no_team',
  648. 'lg_id' => $lg_id,
  649. 'status' => $data['status'],
  650. 'match_date' => $data['match_date'] ?: date('Y-m-d'),
  651. 'match_time' => $data['match_time'] ?: date('H:i:s'),
  652. 'is_rollball' => $data['is_rollball'] ?: 0,
  653. 'is_today' => $data['is_today'] ?: 0,
  654. 'is_morningplate' => $data['is_morningplate'] ?: 0,
  655. 'is_stringscene' => $data['is_stringscene'] ?: 0,
  656. 'is_horn' => $data['is_horn']?:0,
  657. 'us_time' => $data['us_time'] ?: commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
  658. 'half_match_id' => $half_match_id ?: 0,
  659. 'identity' => $data['uuid'],
  660. ];
  661. //如果是网球 追加rule 字段
  662. if ($game_code == 'wq') {
  663. $set_match['rule'] = $data['rule'];
  664. }
  665. //写入赛事 返回id
  666. $id = $models['model_match']::insertGetId($set_match);
  667. if ($id < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::INSERT_ERROR));
  668. //写关联记录
  669. $set_local = [
  670. 'match_id' => $id,
  671. 'others_match_id' => $data['match_id'],
  672. 'source' => $source,
  673. 'ctime' => date('Y-m-d H:i:s')
  674. ];
  675. $ret = $models['model_local_match']::insertGetId($set_local);
  676. 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'));
  677. //追加写球队名称
  678. $team = [
  679. 'team_h' => $data['home_team'],
  680. 'team_g' => $data['guest_team'],
  681. ];
  682. StTeamModel::setTeam($game_code, $team, $source);
  683. //追加写赛事结果
  684. $opt = [
  685. 'data' => $data,
  686. 'lg_id' => $lg_id,
  687. 'match_id' => $id,
  688. 'models' => $models,
  689. 'gameName' => $gameName,
  690. 'game_code' => $game_code,
  691. ];
  692. ZqResultModel::set_result($opt);
  693. }
  694. }
  695. }
  696. }
  697. //提交事务
  698. DB::commit();
  699. //写请求数据 日志记录
  700. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
  701. return Response::success();
  702. } catch (\Exception $e) {
  703. //回滚事务
  704. DB::rollBack();
  705. //写请求数据 日志记录
  706. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
  707. return $e->getMessage();
  708. }
  709. }
  710. /*
  711. * 写 赛事 结果 记录 数据
  712. * 每个请求 包含 N个联赛 下 N个赛事 结果数据
  713. */
  714. public function setMatchResult_v2($data)
  715. {
  716. //验证token
  717. $user = new \App\Models\System_user;
  718. if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
  719. $token = $user::where(['token' => $data->token])->value('token');
  720. if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
  721. try {
  722. //开启事务
  723. DB::beginTransaction();
  724. $obt = $data->data;
  725. //请求 数据 为空
  726. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  727. $getData = $this->getAddData($obt);
  728. //不是 赛事 结果 记录 数据
  729. if ($getData['title'] != 'match_result_r') throw new \Exception(Response::generate('不是赛事结果记录数据,', Response::ABNORMAL));
  730. /*
  731. //写请求数据 日志记录
  732. if($this->isRecord){
  733. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  734. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  735. }
  736. */
  737. //获取球类代码
  738. $game_code = $getData['game_code'];
  739. //获取数据源
  740. $source = $getData['source'];
  741. //获取球类名称
  742. $gameName = gameModel::getGameName($game_code);
  743. //获取 model
  744. $models = commonFunction::getModels($game_code, 1);
  745. //获取 赛事 数据
  746. $match_r_data = $getData['data'];
  747. //获取 当前请求 所有 uuid /match_id
  748. $identity = [];
  749. $s_match_ids = [];
  750. $match_uuids = [];
  751. foreach ($match_r_data as $k => $v) {
  752. $identity[] = $v['uuid'];
  753. $s_match_ids[] = $v['match_id'];
  754. //追加获取赛事uuid
  755. $match_uuids[] = $v['match_identity'];
  756. }
  757. //====验证 赛事 所属 联赛 是否存在====
  758. $identity = array_unique($identity);
  759. sort($identity);
  760. //获取 本地 已存在 联赛
  761. $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id')->get()->toArray();
  762. //二维数组去重
  763. $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
  764. //循环对比 请求uuid->本地identity
  765. foreach ($l_lg_data as $k => $v) {
  766. foreach ($identity as $kk => $uuid) {
  767. if ($v['identity'] == $uuid) {
  768. unset($identity[$kk]);
  769. }
  770. }
  771. }
  772. sort($identity);
  773. //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常
  774. if (!empty($identity)) throw new \Exception(Response::generate($gameName . '联赛:uuid-' . $identity[0] . ';', Response::LEAGUE_ERROR));
  775. //====end====
  776. //====验证 赛事结果记录 所属赛事 是否存在====
  777. $match_uuids = array_unique($match_uuids);
  778. sort($match_uuids);
  779. //获取 本地 已存在 赛事
  780. // $l_match_data = $models['model_local_match']::whereIn('identity', $match_uuids)->where('source', $source)->select('identity', 'match_id')->get()->toArray();
  781. $l_match_data = $models['model_local_match']::whereIn('identity', $match_uuids)->select('identity', 'match_id')->get()->toArray();
  782. //二维数组去重
  783. $l_match_data = commonFunction::uniquArrV2($l_match_data, 'identity');
  784. //循环对比 请求identity->本地identity
  785. foreach ($l_match_data as $k => $v) {
  786. foreach ($match_uuids as $kk => $match_identity) {
  787. if ($v['identity'] == $match_identity) {
  788. unset($match_uuids[$kk]);
  789. }
  790. }
  791. }
  792. sort($match_uuids);
  793. //去除本地和请求里都存在的赛事,如果还有剩余赛事id,则返回异常
  794. if (!empty($match_uuids)) throw new \Exception(Response::generate($gameName . '赛事-match_id' . $match_uuids[0] . ';', Response::MATCH_ERROR));
  795. //====end====
  796. //处理 赛事 结果记录 数据
  797. foreach ($match_r_data as $k => $v) {
  798. $data = $v;
  799. //获取 本地 联赛 ID
  800. $lg_id = commonFunction::searcharray($data['uuid'], 'identity', $l_lg_data, 'lg_id');
  801. //获取 本地 赛事 ID
  802. $match_id = commonFunction::searcharray($data['match_identity'], 'identity', $l_match_data, 'match_id');
  803. //根据球类 获取 赛事结果记录字段
  804. $set_match_r = $this->get_match_r($game_code, $lg_id, $match_id, $data);
  805. //写 赛事 结果 记录
  806. $ret = $models['model_result_record']::insert($set_match_r);
  807. if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));
  808. }
  809. //提交事务
  810. DB::commit();
  811. //写请求数据 日志记录
  812. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
  813. return Response::success();
  814. } catch (\Exception $e) {
  815. //回滚事务
  816. DB::rollBack();
  817. //写请求数据 日志记录
  818. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
  819. return $e->getMessage();
  820. }
  821. }
  822. public function setMatchResult_v1($data)
  823. {
  824. //验证token
  825. $user = new \App\Models\System_user;
  826. if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
  827. $token = $user::where(['token' => $data->token])->value('token');
  828. if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
  829. try {
  830. //开启事务
  831. DB::beginTransaction();
  832. $obt = $data->data;
  833. //请求 数据 为空
  834. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  835. $getData = $this->getAddData($obt);
  836. //不是 赛事 结果 记录 数据
  837. if ($getData['title'] != 'match_result_r') throw new \Exception(Response::generate('不是赛事结果记录数据,', Response::ABNORMAL));
  838. /*
  839. //写请求数据 日志记录
  840. if($this->isRecord){
  841. // $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  842. // if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  843. }
  844. */
  845. //获取球类代码
  846. $game_code = $getData['game_code'];
  847. //获取数据源
  848. $source = $getData['source'];
  849. //获取球类名称
  850. $gameName = gameModel::getGameName($game_code);
  851. //获取 model
  852. $models = commonFunction::getModels($game_code, 1);
  853. //获取 赛事 数据
  854. $match_r_data = $getData['data'];
  855. //获取 当前请求 所有 uuid /match_id
  856. $identity = [];
  857. $s_match_ids = [];
  858. $match_uuids = [];
  859. foreach ($match_r_data as $k => $v) {
  860. $identity[] = $v['uuid'];
  861. $s_match_ids[] = $v['match_id'];
  862. }
  863. //====验证 赛事 所属 联赛 是否存在====
  864. $identity = array_unique($identity);
  865. sort($identity);
  866. //获取 本地 已存在 联赛
  867. $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id')->get()->toArray();
  868. //二维数组去重
  869. $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
  870. //循环对比 请求uuid->本地identity
  871. foreach ($l_lg_data as $k => $v) {
  872. foreach ($identity as $kk => $uuid) {
  873. if ($v['identity'] == $uuid) {
  874. unset($identity[$kk]);
  875. }
  876. }
  877. }
  878. sort($identity);
  879. //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常
  880. if (!empty($identity)) throw new \Exception(Response::generate($gameName . '联赛:uuid-' . $identity[0] . ';', Response::LEAGUE_ERROR));
  881. //====end====
  882. //====验证 赛事结果记录 所属赛事 是否存在====$match_uuids
  883. $s_match_ids = array_unique($s_match_ids);
  884. sort($s_match_ids);
  885. //获取 本地 已存在 赛事
  886. $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();
  887. //二维数组去重
  888. $l_match_data = commonFunction::uniquArrV2($l_match_data, 'others_match_id');
  889. //循环对比 请求match_id->本地others_match_id
  890. foreach ($l_match_data as $k => $v) {
  891. foreach ($s_match_ids as $kk => $s_match_id) {
  892. if ($v['others_match_id'] == $s_match_id) {
  893. unset($s_match_ids[$kk]);
  894. }
  895. }
  896. }
  897. sort($s_match_ids);
  898. //去除本地和请求里都存在的赛事,如果还有剩余赛事id,则返回异常
  899. if (!empty($s_match_ids)) throw new \Exception(Response::generate($gameName . '赛事-match_id' . $s_match_ids[0] . ';', Response::MATCH_ERROR));
  900. //====end====
  901. //处理 赛事 结果记录 数据
  902. foreach ($match_r_data as $k => $v) {
  903. $data = $v;
  904. //获取 本地 联赛 ID
  905. $lg_id = commonFunction::searcharray($data['uuid'], 'identity', $l_lg_data, 'lg_id');
  906. //获取 本地 赛事 ID
  907. $match_id = commonFunction::searcharray($data['match_id'], 'others_match_id', $l_match_data, 'match_id');
  908. //根据球类 获取 赛事结果记录字段
  909. $set_match_r = $this->get_match_r($game_code, $lg_id, $match_id, $data);
  910. //写 赛事 结果 记录
  911. $ret = $models['model_result_record']::insert($set_match_r);
  912. if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));
  913. }
  914. //提交事务
  915. DB::commit();
  916. //写请求数据 日志记录
  917. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
  918. return Response::success();
  919. } catch (\Exception $e) {
  920. //回滚事务
  921. DB::rollBack();
  922. //写请求数据 日志记录
  923. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
  924. return $e->getMessage();
  925. }
  926. }
  927. /*
  928. * 写 普通 赔率 数据
  929. * 每个请求 只包含 一场赛事下 N条赔率
  930. */
  931. //追加赛事uuid
  932. public function setOdds_v2($data)
  933. {
  934. //验证token
  935. $user = new \App\Models\System_user;
  936. if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
  937. $token = $user::where(['token' => $data->token])->value('token');
  938. if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
  939. try {
  940. //开启事务
  941. DB::beginTransaction();
  942. $obt = $data->data;
  943. //请求 数据 为空
  944. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  945. $getData = $this->getAddData($obt);
  946. //不是 赔率 数据
  947. if ($getData['title'] != 'odds') throw new \Exception(Response::generate('不是赔率数据,', Response::ABNORMAL));
  948. /*
  949. //写请求数据 日志记录
  950. if($this->isRecord){
  951. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  952. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  953. }
  954. */
  955. //获取球类代码
  956. $game_code = $getData['game_code'];
  957. //获取数据源
  958. $source = $getData['source'];
  959. //获取源数据联赛ID
  960. $uuid = $getData['uuid'];
  961. //获取源数据赛事ID
  962. $s_match_id = $getData['match_id'];
  963. //获取数据源赛事uuid
  964. $match_identity = $getData['match_identity'];
  965. //获取赔率所属赛事 tag 值 玩法数量
  966. $tag = $getData['tag'] ?: 99;
  967. //获取赔率是否是串场
  968. $is_stringscene = $getData['is_stringscene'];
  969. //获取球类名称
  970. $gameName = gameModel::getGameName($game_code);
  971. //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
  972. $models = commonFunction::getModels($game_code, 1);
  973. $lg_id = $this->leagueVerify($models, $uuid, $source, $gameName);
  974. $match_id = $this->matchVerify($models, $match_identity, $source, $gameName);
  975. //更新赛事 tag 值
  976. //如果未获取到本地赛事id,则返回异常
  977. if (empty($match_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::L_MATCH_ID_ERR));
  978. $upMatch = $models['model_match']::where(['id' => $match_id])
  979. ->update(['tag' => $tag, 'utime' => date('Y-m-d H:i:s')]);
  980. if ($upMatch < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::UPMATCHTAG_ERROR));
  981. //获取 赔率数据
  982. $oddsData = $getData['data'];
  983. //获取 当前 所有 可用 赔率 sole
  984. $odds_only = $getData['odds_only'];
  985. //更新赛事下所有 不在本次请求的赔率 状态
  986. $ret = OddsModel::upOddsStatus($models, $s_match_id, '', $source, $odds_only, $is_stringscene);
  987. if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
  988. //获取当前赛事 在本地的所有赔率
  989. $l_odds_data = $models['model_odds']::select('odds_only')->where(['match_id' => $match_id])->get()->toArray();
  990. $set_odds_r = [];
  991. $set_odds = [];
  992. if (!empty($oddsData)) {
  993. //去除本地已有的赔率
  994. if (!empty($l_odds_data)) {
  995. foreach ($oddsData as $k => $v) {
  996. foreach ($l_odds_data as $kk => $vv) {
  997. if ($v['odds_only'] == $vv['odds_only']) {
  998. unset($oddsData[$k]);
  999. }
  1000. }
  1001. }
  1002. sort($oddsData);
  1003. }
  1004. //处理待写入 赔率记录数据
  1005. foreach ($oddsData as $k => $v) {
  1006. //组装数据
  1007. $set_odds_r[] = [
  1008. 'match_id' => $match_id ?: 0,
  1009. 'others_match_id' => $v['match_id'] ?: 0,
  1010. 'odds_code' => $v['odds_code'] ?: '',
  1011. 'status' => $v['status'] ?: 0,
  1012. 'sort' => $v['sort'] ?: 0,
  1013. 'p_code' => $v['p_code'] ?: '',
  1014. 'odds' => $v['odds'] ?: 0,
  1015. 'condition' => $v['condition'],
  1016. 'odds_only' => $v['odds_only'] ?: '',
  1017. 'source' => $v['source'] ?: '',
  1018. 'type' => $v['type'] ?: 0,
  1019. 'team' => $v['team'] ?: '',
  1020. 'lg_id' => $lg_id,
  1021. 'is_stringscene' => $is_stringscene,
  1022. 'others_lg_id' => $v['lg_id'],
  1023. 'ctime' => date('Y-m-d H:i:s'),
  1024. 'utime' => date('Y-m-d H:i:s'),
  1025. ];
  1026. }
  1027. //处理待写入 赔率数据
  1028. foreach ($oddsData as $k => $v) {
  1029. //组装数据
  1030. $set_odds[] = [
  1031. 'match_id' => $match_id ?: 0,
  1032. 'others_match_id' => $v['match_id'] ?: 0,
  1033. 'odds_code' => $v['odds_code'] ?: '',
  1034. 'status' => $v['status'] ?: 0,
  1035. 'sort' => $v['sort'] ?: 0,
  1036. 'p_code' => $v['p_code'] ?: '',
  1037. 'odds' => $v['odds'] ?: 0,
  1038. 'condition' => $v['condition'],
  1039. 'odds_only' => $v['odds_only'] ?: '',
  1040. 'source' => $v['source'] ?: '',
  1041. 'type' => $v['type'] ?: 0,
  1042. 'team' => $v['team'] ?: '',
  1043. 'lg_id' => $lg_id,
  1044. 'is_stringscene' => $is_stringscene,
  1045. 'others_lg_id' => $v['lg_id'],
  1046. 'ctime' => date('Y-m-d H:i:s'),
  1047. 'utime' => date('Y-m-d H:i:s'),
  1048. 'sole' => $v['sole'],
  1049. 'expire_time' => date('Y-m-d H:i:s', time() + 60)
  1050. ];
  1051. }
  1052. //写赔率记录数据
  1053. $ret = $models['model_odds_record']::insert($set_odds_r);
  1054. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
  1055. //写赔率 数据
  1056. $ret = $models['model_odds']::insert($set_odds);
  1057. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
  1058. }
  1059. //提交事务
  1060. DB::commit();
  1061. //写请求数据 日志记录
  1062. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
  1063. return Response::success();
  1064. } catch (\Exception $e) {
  1065. //回滚事务
  1066. DB::rollBack();
  1067. //写请求数据 日志记录
  1068. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
  1069. return $e->getMessage();
  1070. }
  1071. }
  1072. //初始版本
  1073. public function setOdds_v1($data)
  1074. {
  1075. //验证token
  1076. $user = new \App\Models\System_user;
  1077. if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
  1078. $token = $user::where(['token' => $data->token])->value('token');
  1079. if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
  1080. try {
  1081. //开启事务
  1082. DB::beginTransaction();
  1083. $obt = $data->data;
  1084. //请求 数据 为空
  1085. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  1086. $getData = $this->getAddData($obt);
  1087. //不是 赔率 数据
  1088. if ($getData['title'] != 'odds') throw new \Exception(Response::generate('不是赔率数据,', Response::ABNORMAL));
  1089. /*
  1090. //写请求数据 日志记录
  1091. if($this->isRecord){
  1092. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  1093. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  1094. }
  1095. */
  1096. //获取球类代码
  1097. $game_code = $getData['game_code'];
  1098. //获取数据源
  1099. $source = $getData['source'];
  1100. //获取源数据联赛ID
  1101. $uuid = $getData['uuid'];
  1102. //获取源数据赛事ID
  1103. $s_match_id = $getData['match_id'];
  1104. //获取赔率所属赛事 tag 值 玩法数量
  1105. $tag = $getData['tag'] ?: 99;
  1106. //获取赔率是否是串场
  1107. $is_stringscene = $getData['is_stringscene'];
  1108. //获取球类名称
  1109. $gameName = gameModel::getGameName($game_code);
  1110. //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
  1111. $models = commonFunction::getModels($game_code, 1);
  1112. $lg_id = $this->leagueVerify($models, $uuid, $source, $gameName);
  1113. $match_id = $this->matchVerify($models, $s_match_id, $source, $gameName);
  1114. //更新赛事 tag 值
  1115. //如果未获取到本地赛事id,则返回异常
  1116. if (empty($match_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::L_MATCH_ID_ERR));
  1117. $upMatch = $models['model_match']::where(['id' => $match_id])
  1118. ->update(['tag' => $tag, 'utime' => date('Y-m-d H:i:s')]);
  1119. if ($upMatch < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::UPMATCHTAG_ERROR));
  1120. //获取 赔率数据
  1121. $oddsData = $getData['data'];
  1122. //获取 当前 所有 可用 赔率 sole
  1123. $odds_only = $getData['odds_only'];
  1124. //更新赛事下所有 不在本次请求的赔率 状态
  1125. $ret = OddsModel::upOddsStatus($models, $s_match_id, '', $source, $odds_only, $is_stringscene);
  1126. if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
  1127. //获取当前赛事 在本地的所有赔率
  1128. $l_odds_data = $models['model_odds']::select('odds_only')->where(['match_id' => $match_id])->get()->toArray();
  1129. $set_odds_r = [];
  1130. $set_odds = [];
  1131. if (!empty($oddsData)) {
  1132. //去除本地已有的赔率
  1133. if (!empty($l_odds_data)) {
  1134. foreach ($oddsData as $k => $v) {
  1135. foreach ($l_odds_data as $kk => $vv) {
  1136. if ($v['odds_only'] == $vv['odds_only']) {
  1137. unset($oddsData[$k]);
  1138. }
  1139. }
  1140. }
  1141. sort($oddsData);
  1142. }
  1143. //处理待写入 赔率记录数据
  1144. foreach ($oddsData as $k => $v) {
  1145. //组装数据
  1146. $set_odds_r[] = [
  1147. 'match_id' => $match_id ?: 0,
  1148. 'others_match_id' => $v['match_id'] ?: 0,
  1149. 'odds_code' => $v['odds_code'] ?: '',
  1150. 'status' => $v['status'] ?: 0,
  1151. 'sort' => $v['sort'] ?: 0,
  1152. 'p_code' => $v['p_code'] ?: '',
  1153. 'odds' => $v['odds'] ?: 0,
  1154. 'condition' => $v['condition'],
  1155. 'odds_only' => $v['odds_only'] ?: '',
  1156. 'source' => $v['source'] ?: '',
  1157. 'type' => $v['type'] ?: 0,
  1158. 'team' => $v['team'] ?: '',
  1159. 'lg_id' => $lg_id,
  1160. 'is_stringscene' => $is_stringscene,
  1161. 'others_lg_id' => $v['lg_id'],
  1162. 'ctime' => date('Y-m-d H:i:s'),
  1163. 'utime' => date('Y-m-d H:i:s'),
  1164. ];
  1165. }
  1166. //处理待写入 赔率数据
  1167. foreach ($oddsData as $k => $v) {
  1168. //组装数据
  1169. $set_odds[] = [
  1170. 'match_id' => $match_id ?: 0,
  1171. 'others_match_id' => $v['match_id'] ?: 0,
  1172. 'odds_code' => $v['odds_code'] ?: '',
  1173. 'status' => $v['status'] ?: 0,
  1174. 'sort' => $v['sort'] ?: 0,
  1175. 'p_code' => $v['p_code'] ?: '',
  1176. 'odds' => $v['odds'] ?: 0,
  1177. 'condition' => $v['condition'],
  1178. 'odds_only' => $v['odds_only'] ?: '',
  1179. 'source' => $v['source'] ?: '',
  1180. 'type' => $v['type'] ?: 0,
  1181. 'team' => $v['team'] ?: '',
  1182. 'lg_id' => $lg_id,
  1183. 'is_stringscene' => $is_stringscene,
  1184. 'others_lg_id' => $v['lg_id'],
  1185. 'ctime' => date('Y-m-d H:i:s'),
  1186. 'utime' => date('Y-m-d H:i:s'),
  1187. 'sole' => $v['sole'],
  1188. 'expire_time' => date('Y-m-d H:i:s', time() + 60)
  1189. ];
  1190. }
  1191. //写赔率记录数据
  1192. $ret = $models['model_odds_record']::insert($set_odds_r);
  1193. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
  1194. //写赔率 数据
  1195. $ret = $models['model_odds']::insert($set_odds);
  1196. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
  1197. }
  1198. //提交事务
  1199. DB::commit();
  1200. //写请求数据 日志记录
  1201. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
  1202. return Response::success();
  1203. } catch (\Exception $e) {
  1204. //回滚事务
  1205. DB::rollBack();
  1206. //写请求数据 日志记录
  1207. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
  1208. return $e->getMessage();
  1209. }
  1210. }
  1211. //新增赔率过滤
  1212. public function setOdds_v3($data)
  1213. {
  1214. //验证token
  1215. $user = new \App\Models\System_user;
  1216. if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
  1217. $token = $user::where(['token' => $data->token])->value('token');
  1218. if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
  1219. try {
  1220. //开启事务
  1221. DB::beginTransaction();
  1222. $obt = $data->data;
  1223. //请求 数据 为空
  1224. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  1225. $getData = $this->getAddData($obt);
  1226. //不是 赔率 数据
  1227. if ($getData['title'] != 'odds') throw new \Exception(Response::generate('不是赔率数据,', Response::ABNORMAL));
  1228. //获取球类代码
  1229. $game_code = $getData['game_code'];
  1230. //获取数据源
  1231. $source = $getData['source'];
  1232. //获取源数据联赛ID
  1233. $uuid = $getData['uuid'];
  1234. //获取源数据赛事ID
  1235. $s_match_id = $getData['match_id'];
  1236. //获取赔率所属赛事 tag 值 玩法数量
  1237. $tag = $getData['tag'] ?: 99;
  1238. //获取赔率是否是串场
  1239. $is_stringscene = $getData['is_stringscene'];
  1240. //获取数据源赛事uuid
  1241. $match_identity = $getData['match_identity'];
  1242. //获取球类名称
  1243. $gameName = gameModel::getGameName($game_code);
  1244. //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
  1245. $models = commonFunction::getModels($game_code, 1);
  1246. $lg_id = $this->leagueVerify($models, $uuid, $source, $gameName);
  1247. $match_id = $this->matchVerify_v2($models, $match_identity, $source, $gameName);
  1248. //更新赛事 tag 值
  1249. //如果未获取到本地赛事id,则返回异常
  1250. if (empty($match_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::L_MATCH_ID_ERR));
  1251. $upMatch = $models['model_match']::where(['id' => $match_id])
  1252. ->update(['tag' => $tag, 'utime' => date('Y-m-d H:i:s')]);
  1253. if ($upMatch < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::UPMATCHTAG_ERROR));
  1254. //获取 赔率数据
  1255. $oddsData = $getData['data'];
  1256. //===追加处理赔率过滤===
  1257. //获取当前赛事 在本地的所有赔率
  1258. $l_odds_data = $models['model_odds']::select('odds_only')->where(['match_id' => $match_id, 'is_stringscene' => $is_stringscene])->get()->toArray();
  1259. //获取请求待写入数据
  1260. $setOddsData = [];
  1261. //获取本地待删除数据
  1262. $delOddsData = [];
  1263. //本地没有该赛事赔率,则直接全部写入
  1264. if (empty($l_odds_data)) {
  1265. $setOddsData = $oddsData;
  1266. } //本地有该赛事赔率,则分别获取需写入/删除的数据
  1267. else {
  1268. $newodds_t = $this->ArrayKeySet($oddsData, 'odds_only');
  1269. $oldodds_t = $this->ArrayKeySet($l_odds_data, 'odds_only');
  1270. foreach ($newodds_t as $key => $val) {
  1271. if (isset($oldodds_t[$key])) {
  1272. unset($newodds_t[$key]);
  1273. unset($oldodds_t[$key]);
  1274. }
  1275. }
  1276. $oddsData = $newodds_t;
  1277. $l_odds_data = $oldodds_t;
  1278. /*
  1279. foreach ($oddsData as $k => $v) {
  1280. foreach ($l_odds_data as $kk => $vv) {
  1281. if ($v['odds_only'] == $vv['odds_only']) {
  1282. unset($oddsData[$k]);
  1283. unset($l_odds_data[$kk]);
  1284. }
  1285. }
  1286. }
  1287. */
  1288. sort($oddsData);
  1289. sort($l_odds_data);
  1290. //需写入请求数据
  1291. $setOddsData = $oddsData;
  1292. //需删除本地数据
  1293. $delOddsData = $l_odds_data;
  1294. }
  1295. //===end===
  1296. //删除本地不在请求中的数据
  1297. if (!empty($delOddsData)) {
  1298. //所有需删除数据odds_only
  1299. $odds_onlys = [];
  1300. foreach ($delOddsData as $k => $v) {
  1301. $odds_onlys[] = $v['odds_only'];
  1302. }
  1303. $del = $models['model_odds']::whereIn('odds_only', $odds_onlys)->delete();
  1304. if ($del != count($odds_onlys)) throw new \Exception(Response::generate($gameName, Response::DEL_ODDS_ERR));
  1305. }
  1306. //写入请求中本地不存在的数据
  1307. if (!empty($setOddsData)) {
  1308. //处理待写入 赔率记录数据
  1309. foreach ($setOddsData as $k => $v) {
  1310. //组装数据
  1311. $set_odds_r[] = [
  1312. 'match_id' => $match_id ?: 0,
  1313. 'others_match_id' => $v['match_id'] ?: 0,
  1314. 'odds_code' => $v['odds_code'] ?: '',
  1315. 'status' => $v['status'] ?: 0,
  1316. 'sort' => $v['sort'] ?: 0,
  1317. 'p_code' => $v['p_code'] ?: '',
  1318. 'odds' => $v['odds'] ?: 0,
  1319. 'condition' => $v['condition'],
  1320. 'odds_only' => $v['odds_only'] ?: '',
  1321. 'source' => $v['source'] ?: '',
  1322. 'type' => $v['type'] ?: 0,
  1323. 'team' => $v['team'] ?: '',
  1324. 'lg_id' => $lg_id,
  1325. 'is_stringscene' => $is_stringscene,
  1326. 'others_lg_id' => $v['lg_id'],
  1327. 'ctime' => date('Y-m-d H:i:s'),
  1328. 'utime' => date('Y-m-d H:i:s'),
  1329. ];
  1330. }
  1331. //处理待写入 赔率数据
  1332. foreach ($oddsData as $k => $v) {
  1333. //组装数据
  1334. $set_odds[] = [
  1335. 'match_id' => $match_id ?: 0,
  1336. 'others_match_id' => $v['match_id'] ?: 0,
  1337. 'odds_code' => $v['odds_code'] ?: '',
  1338. 'status' => $v['status'] ?: 0,
  1339. 'sort' => $v['sort'] ?: 0,
  1340. 'p_code' => $v['p_code'] ?: '',
  1341. 'odds' => $v['odds'] ?: 0,
  1342. 'condition' => $v['condition'],
  1343. 'odds_only' => $v['odds_only'] ?: '',
  1344. 'source' => $v['source'] ?: '',
  1345. 'type' => $v['type'] ?: 0,
  1346. 'team' => $v['team'] ?: '',
  1347. 'lg_id' => $lg_id,
  1348. 'is_stringscene' => $is_stringscene,
  1349. 'others_lg_id' => $v['lg_id'],
  1350. 'ctime' => date('Y-m-d H:i:s'),
  1351. 'utime' => date('Y-m-d H:i:s'),
  1352. 'sole' => $v['sole'],
  1353. 'expire_time' => date('Y-m-d H:i:s', time() + 60)
  1354. ];
  1355. }
  1356. //写赔率记录数据
  1357. $ret = $models['model_odds_record']::insert($set_odds_r);
  1358. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
  1359. //写赔率 数据
  1360. $ret = $models['model_odds']::insert($set_odds);
  1361. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
  1362. }
  1363. //提交事务
  1364. DB::commit();
  1365. //写请求数据 日志记录
  1366. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
  1367. return Response::success();
  1368. } catch (\Exception $e) {
  1369. //回滚事务
  1370. DB::rollBack();
  1371. //写请求数据 日志记录
  1372. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
  1373. return $e->getMessage();
  1374. }
  1375. }
  1376. /*
  1377. *写 冠军联赛 赔率 数据
  1378. *每个请求 包含 N个联赛 下 N条赔率
  1379. *
  1380. */
  1381. public function setOddsCH_v1($data)
  1382. {
  1383. //验证token
  1384. $user = new \App\Models\System_user;
  1385. if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
  1386. $token = $user::where(['token' => $data->token])->value('token');
  1387. if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
  1388. try {
  1389. //开启事务
  1390. DB::beginTransaction();
  1391. $obt = $data->data;
  1392. //请求 数据 为空
  1393. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  1394. $getData = $this->getAddData($obt);
  1395. //不是 冠军 赔率 数据
  1396. if ($getData['title'] != 'odds_ch') throw new \Exception(Response::generate('不是冠军赔率数据,', Response::ABNORMAL));
  1397. /*
  1398. //写请求数据 日志记录
  1399. if($this->isRecord){
  1400. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  1401. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  1402. }
  1403. */
  1404. //获取球类代码
  1405. $game_code = $getData['game_code'];
  1406. //获取数据源
  1407. $source = $getData['source'];
  1408. //获取球类名称
  1409. $gameName = gameModel::getGameName($game_code);
  1410. //获取 model
  1411. $models = commonFunction::getModels($game_code, 1);
  1412. //获取 赔率数据
  1413. $oddsData = $getData['data'];
  1414. //获取 当前 所有 可用 赔率 sole
  1415. $odds_only = $getData['odds_only'];
  1416. //====验证 请求里 所有赔率 所属联赛 是否存在 ====
  1417. //获取 当前请求 所有 联赛 uuid
  1418. $uuids = [];
  1419. $s_lg_ids = [];
  1420. foreach ($oddsData as $k => $v) {
  1421. $uuids[] = $v['uuid'];
  1422. $s_lg_ids[] = $v['lg_id'];
  1423. }
  1424. $s_lg_ids = array_unique($s_lg_ids);
  1425. $uuids = array_unique($uuids);
  1426. sort($uuids);
  1427. sort($s_lg_ids);
  1428. //更新联赛下所有 不在本次请求的赔率 状态
  1429. $ret = OddsModel::upOddsStatus($models, '', $s_lg_ids, $source, $odds_only);
  1430. if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
  1431. //获取 本地 已存在 联赛
  1432. $l_lg_data = $models['model_local_league']::whereIn('identity', $uuids)->select('identity', 'lg_id')->get()->toArray();
  1433. //二维数组去重
  1434. $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
  1435. //循环对比 请求uuid->本地uuid
  1436. foreach ($l_lg_data as $k => $v) {
  1437. foreach ($uuids as $kk => $uuid) {
  1438. if ($v['identity'] == $uuid) {
  1439. unset($uuids[$kk]);
  1440. }
  1441. }
  1442. }
  1443. //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常;
  1444. if (!empty($uuids)) throw new \Exception(Response::generate($gameName . '冠军联赛:uuid-' . $uuids[0] . ';', Response::LEAGUE_ERROR));
  1445. //====end====
  1446. //赔率记录数据
  1447. $set_odds_r = [];
  1448. //赔率数据
  1449. $set_odds = [];
  1450. if (!empty($oddsData)) {
  1451. foreach ($oddsData as $k => $v) {
  1452. //获取 本地 联赛 ID
  1453. $lg_id = commonFunction::searcharray($v['uuid'], 'identity', $l_lg_data, 'lg_id');
  1454. //组装赔率记录数据
  1455. $set_odds_r[] = [
  1456. 'match_id' => 0,
  1457. 'others_match_id' => $v['match_id'] ?: 0,
  1458. 'odds_code' => $v['odds_code'] ?: '',
  1459. 'status' => $v['status'] ?: 0,
  1460. 'sort' => $v['sort'] ?: 0,
  1461. 'p_code' => $v['p_code'] ?: '',
  1462. 'odds' => $v['odds'] ?: 0,
  1463. 'condition' => $v['condition'],
  1464. 'odds_only' => $v['odds_only'] ?: '',
  1465. 'source' => $v['source'] ?: '',
  1466. 'type' => $v['type'] ?: 1,
  1467. 'team' => $v['team'] ?: '',
  1468. 'lg_id' => $lg_id,
  1469. 'others_lg_id' => $v['lg_id'],
  1470. 'ctime' => date('Y-m-d H:i:s'),
  1471. 'utime' => date('Y-m-d H:i:s'),
  1472. ];
  1473. }
  1474. foreach ($oddsData as $k => $v) {
  1475. //获取 本地 联赛 ID
  1476. $lg_id = commonFunction::searcharray($v['uuid'], 'identity', $l_lg_data, 'lg_id');
  1477. //组装赔率数据
  1478. $set_odds[] = [
  1479. 'match_id' => 0,
  1480. 'others_match_id' => $v['match_id'] ?: 0,
  1481. 'odds_code' => $v['odds_code'] ?: '',
  1482. 'status' => $v['status'] ?: 0,
  1483. 'sort' => $v['sort'] ?: 0,
  1484. 'p_code' => $v['p_code'] ?: '',
  1485. 'odds' => $v['odds'] ?: 0,
  1486. 'condition' => $v['condition'],
  1487. 'odds_only' => $v['odds_only'] ?: '',
  1488. 'source' => $v['source'] ?: '',
  1489. 'type' => $v['type'] ?: 1,
  1490. 'team' => $v['team'] ?: '',
  1491. 'lg_id' => $lg_id,
  1492. 'others_lg_id' => $v['lg_id'],
  1493. 'ctime' => date('Y-m-d H:i:s'),
  1494. 'utime' => date('Y-m-d H:i:s'),
  1495. 'sole' => $v['sole'],
  1496. 'expire_time' => date('Y-m-d H:i:s', time() + 60)
  1497. ];
  1498. }
  1499. //写赔率记录数据
  1500. $ret = $models['model_odds_record']::insert($set_odds_r);
  1501. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
  1502. //写赔率 数据
  1503. $ret = $models['model_odds']::insert($set_odds);
  1504. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
  1505. }
  1506. //提交事务
  1507. DB::commit();
  1508. //写请求数据 日志记录
  1509. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
  1510. return Response::success();
  1511. } catch (\Exception $e) {
  1512. //回滚事务
  1513. DB::rollBack();
  1514. //写请求数据 日志记录
  1515. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
  1516. return $e->getMessage();
  1517. }
  1518. }
  1519. /*
  1520. *写 冠军联赛 赔率 数据
  1521. *每个请求 包含 1个联赛 下 N条赔率
  1522. *追加赔率过滤
  1523. */
  1524. public function setOddsCH_v2($data)
  1525. {
  1526. //验证token
  1527. $user = new \App\Models\System_user;
  1528. if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
  1529. $token = $user::where(['token' => $data->token])->value('token');
  1530. if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
  1531. try {
  1532. //开启事务
  1533. DB::beginTransaction();
  1534. $obt = $data->data;
  1535. //请求 数据 为空
  1536. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  1537. $getData = $this->getAddData($obt);
  1538. //不是 冠军 赔率 数据
  1539. if ($getData['title'] != 'odds_ch') throw new \Exception(Response::generate('不是冠军赔率数据,', Response::ABNORMAL));
  1540. /*
  1541. //写请求数据 日志记录
  1542. if($this->isRecord){
  1543. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  1544. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  1545. }
  1546. */
  1547. //获取球类代码
  1548. $game_code = $getData['game_code'];
  1549. //获取数据源
  1550. $source = $getData['source'];
  1551. //获取球类名称
  1552. $gameName = gameModel::getGameName($game_code);
  1553. //获取数据源联赛ID
  1554. $s_lg_id = $getData['lg_id'];
  1555. //获取源数据联赛UUID
  1556. $uuid = $getData['uuid'];
  1557. //获取 model
  1558. $models = commonFunction::getModels($game_code, 1);
  1559. //获取 赔率数据
  1560. $oddsData = $getData['data'];
  1561. //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
  1562. $lg_id = $this->leagueVerify($models, $uuid, $source, $gameName);
  1563. //===追加处理赔率过滤===
  1564. //获取当前联赛 在本地的所有赔率
  1565. $l_odds_data = $models['model_odds']::select('odds_only')->where(['lg_id' => $lg_id,'type' => 1])->get()->toArray();
  1566. //获取请求待写入数据
  1567. $setOddsData = [];
  1568. //获取本地待删除数据
  1569. $delOddsData = [];
  1570. //本地没有该赛事赔率,则直接全部写入
  1571. if (empty($l_odds_data)) {
  1572. $setOddsData = $oddsData;
  1573. } //本地有该赛事赔率,则分别获取需写入/删除的数据
  1574. else {
  1575. $newodds_t = $this->ArrayKeySet($oddsData, 'odds_only');
  1576. $oldodds_t = $this->ArrayKeySet($l_odds_data, 'odds_only');
  1577. foreach ($newodds_t as $key => $val) {
  1578. if (isset($oldodds_t[$key])) {
  1579. unset($newodds_t[$key]);
  1580. unset($oldodds_t[$key]);
  1581. }
  1582. }
  1583. $oddsData = $newodds_t;
  1584. $l_odds_data = $oldodds_t;
  1585. sort($oddsData);
  1586. sort($l_odds_data);
  1587. //需写入请求数据
  1588. $setOddsData = $oddsData;
  1589. //需删除本地数据
  1590. $delOddsData = $l_odds_data;
  1591. }
  1592. //===end===
  1593. //删除本地不在请求中的数据
  1594. if (!empty($delOddsData)) {
  1595. //所有需删除数据odds_only
  1596. $odds_onlys = [];
  1597. foreach ($delOddsData as $k => $v) {
  1598. $odds_onlys[] = $v['odds_only'];
  1599. }
  1600. $del = $models['model_odds']::whereIn('odds_only', $odds_onlys)->delete();
  1601. if ($del != count($odds_onlys)) throw new \Exception(Response::generate($gameName, Response::DEL_ODDS_ERR));
  1602. }
  1603. //写入请求中本地不存在的数据
  1604. if (!empty($setOddsData)) {
  1605. foreach ($setOddsData as $k => $v) {
  1606. //组装赔率记录数据
  1607. $set_odds_r[] = [
  1608. 'match_id' => 0,
  1609. 'others_match_id' => $v['match_id'] ?: 0,
  1610. 'odds_code' => $v['odds_code'] ?: '',
  1611. 'status' => $v['status'] ?: 0,
  1612. 'sort' => $v['sort'] ?: 0,
  1613. 'p_code' => $v['p_code'] ?: '',
  1614. 'odds' => $v['odds'] ?: 0,
  1615. 'condition' => $v['condition'],
  1616. 'odds_only' => $v['odds_only'] ?: '',
  1617. 'source' => $v['source'] ?: '',
  1618. 'type' => $v['type'] ?: 1,
  1619. 'team' => $v['team'] ?: '',
  1620. 'lg_id' => $lg_id,
  1621. 'others_lg_id' => $v['lg_id'],
  1622. 'ctime' => date('Y-m-d H:i:s'),
  1623. 'utime' => date('Y-m-d H:i:s'),
  1624. ];
  1625. }
  1626. foreach ($oddsData as $k => $v) {
  1627. //组装赔率数据
  1628. $set_odds[] = [
  1629. 'match_id' => 0,
  1630. 'others_match_id' => $v['match_id'] ?: 0,
  1631. 'odds_code' => $v['odds_code'] ?: '',
  1632. 'status' => $v['status'] ?: 0,
  1633. 'sort' => $v['sort'] ?: 0,
  1634. 'p_code' => $v['p_code'] ?: '',
  1635. 'odds' => $v['odds'] ?: 0,
  1636. 'condition' => $v['condition'],
  1637. 'odds_only' => $v['odds_only'] ?: '',
  1638. 'source' => $v['source'] ?: '',
  1639. 'type' => $v['type'] ?: 1,
  1640. 'team' => $v['team'] ?: '',
  1641. 'lg_id' => $lg_id,
  1642. 'others_lg_id' => $v['lg_id'],
  1643. 'ctime' => date('Y-m-d H:i:s'),
  1644. 'utime' => date('Y-m-d H:i:s'),
  1645. 'sole' => $v['sole'],
  1646. 'expire_time' => date('Y-m-d H:i:s', time() + 60)
  1647. ];
  1648. }
  1649. //写赔率记录数据
  1650. $ret = $models['model_odds_record']::insert($set_odds_r);
  1651. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
  1652. //写赔率 数据
  1653. $ret = $models['model_odds']::insert($set_odds);
  1654. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
  1655. }
  1656. //提交事务
  1657. DB::commit();
  1658. //写请求数据 日志记录
  1659. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
  1660. return Response::success();
  1661. } catch (\Exception $e) {
  1662. //回滚事务
  1663. DB::rollBack();
  1664. //写请求数据 日志记录
  1665. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
  1666. return $e->getMessage();
  1667. }
  1668. }
  1669. /*
  1670. * 写入直播 数据
  1671. */
  1672. public function setBroadCast_v1($data)
  1673. {
  1674. //验证token
  1675. $user = new \App\Models\System_user;
  1676. if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
  1677. $token = $user::where(['token' => $data->token])->value('token');
  1678. if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
  1679. try {
  1680. //开启事务
  1681. DB::beginTransaction();
  1682. $obt = $data->data;
  1683. //请求 数据 为空
  1684. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  1685. $getData = $this->getAddData($obt);
  1686. //不是 直播 数据
  1687. if ($getData['title'] != 'broad_cast') throw new \Exception(Response::generate('不是直播数据,', Response::ABNORMAL));
  1688. /*
  1689. //写请求数据 日志记录
  1690. if($this->isRecord){
  1691. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  1692. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  1693. }
  1694. */
  1695. //获取 球类
  1696. $game_code = $getData['game_code'];
  1697. //删除当前球类已存在的直播数据
  1698. $del = broadcastModel::where('game_code', $game_code)->delete();
  1699. if ($del != true) throw new \Exception(Response::generate('', Response::DEL_PAST_BROADCAST_ERR));
  1700. //获取 直播 数据
  1701. $BroadCast = $getData['data'];
  1702. $set_broadcast = [];
  1703. foreach ($BroadCast as $k => $data) {
  1704. //组装数据
  1705. $set_broadcast[] = [
  1706. "doing" => $data['doing'],
  1707. "game_type" => $data['game_type'],
  1708. "game_code" => $game_code,
  1709. "guest_team" => $data['guest_team'],
  1710. "host_team" => $data['host_team'],
  1711. "league_name" => $data['league_name'],
  1712. "shower" => $data['shower'],
  1713. "showid" => (int)$data['showid'],
  1714. "start_time" => $data['start_time'],
  1715. "ctime" => date('Y-m-d H:i:s'),
  1716. "utime" => date('Y-m-d H:i:s'),
  1717. ];
  1718. }
  1719. //写入 直播 数据
  1720. $ret = broadcastModel::insert($set_broadcast);
  1721. if ($ret == false) throw new \Exception(Response::generate('', Response::BROADCAST_ERROR));
  1722. //提交事务
  1723. DB::commit();
  1724. //写请求数据 日志记录
  1725. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
  1726. return Response::success();
  1727. } catch (\Exception $e) {
  1728. //回滚事务
  1729. DB::rollBack();
  1730. //写请求数据 日志记录
  1731. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
  1732. return $e->getMessage();
  1733. }
  1734. }
  1735. /**
  1736. * @param Req $data
  1737. * @return string
  1738. * @throws \App\Lib\Biz\Sport\Exception
  1739. * 更新赛事状态
  1740. */
  1741. public function upMatch(Req $data)
  1742. {
  1743. //验证token
  1744. $user = new \App\Models\System_user;
  1745. if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
  1746. $token = $user::where(['token' => $data->token])->value('token');
  1747. if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
  1748. try {
  1749. //开启事务
  1750. DB::beginTransaction();
  1751. //获取待更新赛事
  1752. $obt = $data->data;
  1753. //请求 数据 为空
  1754. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  1755. $data = $this->getAddData($obt);
  1756. //不是更新赛事状态数据
  1757. if ($data['title'] != 'match_status') throw new \Exception(Response::generate('不是更新赛事状态数据', Response::ABNORMAL));
  1758. /*
  1759. //写请求数据 日志记录
  1760. if($this->isRecord){
  1761. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  1762. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  1763. }
  1764. */
  1765. //获取 球类代码
  1766. $game_code = $data['game_code'];
  1767. //获取球类 名称
  1768. $gameName = gameModel::getGameName($game_code);
  1769. //获取 数据源
  1770. $source = $data['source'];
  1771. //获取 当前请求 所有 uuid /match_id
  1772. $others_match_ids = [];
  1773. $match_uuids = [];
  1774. foreach ($data['data'] as $k => $v) {
  1775. $others_match_ids[] = $v['match_id'];
  1776. //追加获取赛事uuid
  1777. $match_uuids[] = $v['match_identity'];
  1778. }
  1779. //根据球类代码 获取model
  1780. $model = commonFunction::getModels($game_code, 1);
  1781. //获取所有赛事 match_id
  1782. $local_match = $model['model_local_match']::SELECT('others_match_id', 'match_id')
  1783. // ->where(['source' => $source])
  1784. ->whereIn('identity',$match_uuids)
  1785. ->get()->toArray();
  1786. if (empty($local_match)) throw new \Exception(Response::generate('', Response::MATCHID_NULL));
  1787. //设置各球类 判断结束时间
  1788. if($game_code == 'zq'){
  1789. //足球 60分钟
  1790. $handle_time = 60*60;
  1791. }
  1792. if($game_code == 'lq'){
  1793. //篮球 40分钟
  1794. $handle_time = 60*40;
  1795. }
  1796. if($game_code == 'wq'){
  1797. //网球 2小时
  1798. $handle_time = 60*60*2;
  1799. }
  1800. if($game_code == 'bq'){
  1801. //棒球 2小时
  1802. $handle_time = 60*60*2;
  1803. }
  1804. //取值 更新字段
  1805. foreach ($local_match as $k => $v) {
  1806. foreach($data['data'] as $kk =>$vv){
  1807. if($v['others_match_id'] == $vv['match_id']){
  1808. $set_status = [
  1809. 'status' => $vv['status'],
  1810. 'is_rollball' => $vv['is_rollball'],
  1811. 'is_today' => $vv['is_today'],
  1812. 'is_morningplate' => $vv['is_morningplate'],
  1813. 'is_stringscene' => $vv['is_stringscene'],
  1814. 'utime' => date('Y-m-d H:i:s'),
  1815. ];
  1816. //如果是足球 追加角球状态
  1817. if($game_code == 'zq'){
  1818. $set_status['is_horn'] = $vv['is_horn'];
  1819. }
  1820. $ret = $model['model_match']::where(['id' => $v['match_id']])
  1821. ->update($set_status);
  1822. if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $v['others_match_id'], Response::UPSTATUS_ERROR));
  1823. //获取赛事开始时间
  1824. $game_start_time = $model['model_result']::where(['match_id' => $v['match_id']])->first()->start_time;
  1825. //开赛时间 时间戳
  1826. $game_start_time_unx = strtotime($game_start_time);
  1827. //===如果赛事已结束 并且 开赛时间< 当前时间-各球类处理时间 ===
  1828. if($vv['status'] == 2 and $game_start_time_unx < (time() - $handle_time)){
  1829. // 新增 更新 赛事结果
  1830. $this->match_result($game_code, $v['match_id']);
  1831. // 更新 赛事结果表 状态 为已结束
  1832. $ret_up_r = $model['model_result']::where(['match_id' => $v['match_id']])
  1833. ->update(["status"=>2,'is_correct'=>-1,"update_time"=>date('Y-m-d H:i:s')]);
  1834. if($ret_up_r < 1) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
  1835. // 写入结算通知表 用于自动结算
  1836. $Comendnotice = new \App\Models\Comendnotice();
  1837. $ret_add = $Comendnotice->addcomendnotice($v['match_id'], $game_code, 0, $game_start_time);
  1838. if ($ret_add != 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $v['others_match_id'], Response::ADD_NOTICE_ERR));
  1839. }
  1840. //===end===
  1841. }
  1842. }
  1843. }
  1844. //提交事务
  1845. DB::commit();
  1846. //写请求数据 日志记录
  1847. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $data, $data['title'], Response::success());
  1848. return Response::success();
  1849. } catch (\Exception $e) {
  1850. //回滚事务
  1851. DB::rollBack();
  1852. //写请求数据 日志记录
  1853. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $data, $data['title'], $e->getMessage());
  1854. return $e->getMessage();
  1855. }
  1856. }
  1857. /**
  1858. * 更新投注数据
  1859. */
  1860. public function upOrder_v1($data){
  1861. //验证token
  1862. $user = new \App\Models\System_user;
  1863. if (empty($data->token)) return Response::generate('未获取到token:', Response::TOKEN_ERR);
  1864. $token = $user::where(['token' => $data->token])->value('token');
  1865. if (empty($token)) return Response::generate('token验证不通过:', Response::TOKEN_ERR);
  1866. try {
  1867. //开启事务
  1868. DB::beginTransaction();
  1869. //获取待更新赛事
  1870. $obt = $data->data;
  1871. //请求 数据 为空
  1872. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  1873. $data = $this->getAddData($obt);
  1874. //不是更新投注数据
  1875. if ($data['title'] != 'up_order_data') throw new \Exception(Response::generate('不是更新投注数据', Response::ABNORMAL));
  1876. //获取订单类型 1 单式 2串式
  1877. $order_type = $data['order_type'];
  1878. //获取订单号
  1879. $order_id = $data['order_id'];
  1880. //获取订单下赛事投注数据
  1881. $order_match = $data['matchData'];
  1882. if(empty($order_type) || empty($order_id) || empty($order_match)) throw new \Exception( Response::generate('',Response::ABNORMAL));
  1883. //更新投注数据
  1884. $SportsNoteList = new SportsNoteListModel();
  1885. $SportsNoteList->upOrder($order_type,$order_id,$order_match);
  1886. //提交事务
  1887. DB::commit();
  1888. //写请求数据 日志记录
  1889. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('all', $data, $data['title'], Response::success());
  1890. return Response::success();
  1891. } catch (\Exception $e) {
  1892. //回滚事务
  1893. DB::rollBack();
  1894. //写请求数据 日志记录
  1895. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('all', $data, $data['title'], $e->getMessage());
  1896. return $e->getMessage();
  1897. }
  1898. }
  1899. /*
  1900. * 验证所属 联赛 是否存在
  1901. */
  1902. public function leagueVerify($models = [], $uuid = '', $source = '', $gameName = '')
  1903. {
  1904. if (empty($models) || empty($uuid)) throw new \Exception(Response::generate('', Response::ABNORMAL));
  1905. $l_lg_id = $models['model_local_league']::where(['identity' => $uuid])->value('lg_id');
  1906. if ($l_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛:lg_id-' . $uuid, Response::LEAGUE_ERROR));
  1907. return $l_lg_id;
  1908. }
  1909. /*
  1910. * 验证所属 赛事 是否存在
  1911. */
  1912. public function matchVerify_v2($models = [], $match_identity = '', $source = '', $gameName = '')
  1913. {
  1914. if (empty($models) || empty($match_identity)) throw new \Exception(Response::generate('', Response::ABNORMAL));
  1915. // $l_match_id = $models['model_local_match']::where(['identity' => $match_identity, 'source' => $source])->value('match_id');
  1916. $l_match_id = $models['model_local_match']::where(['identity' => $match_identity])->value('match_id');
  1917. if ($l_match_id < 1) throw new \Exception(Response::generate($gameName . 'match_identity-' . $match_identity, Response::MATCH_ERROR));
  1918. return $l_match_id;
  1919. }
  1920. public function matchVerify($models = [], $s_match_id = '', $source = '', $gameName = '')
  1921. {
  1922. if (empty($models) || empty($s_match_id)) throw new \Exception(Response::generate('', Response::ABNORMAL));
  1923. $l_match_id = $models['model_local_match']::where(['others_match_id' => $s_match_id, 'source' => $source])->value('match_id');
  1924. if ($l_match_id < 1) throw new \Exception(Response::generate($gameName . '赛事:match_id-' . $s_match_id, Response::MATCH_ERROR));
  1925. return $l_match_id;
  1926. }
  1927. /*
  1928. * 写入数据 接口
  1929. */
  1930. public function setSports(Req $data)
  1931. {
  1932. try {
  1933. //开启事务
  1934. DB::beginTransaction();
  1935. if ($data->game_code) {
  1936. //用于后台 将所有进行中的赛事写入结果
  1937. $this->match_result($data->game_code);
  1938. }
  1939. /*
  1940. else {
  1941. //验证token
  1942. $dd = $data->session()->get('adminInfo');
  1943. if (empty($data->token) || ($dd['token'] != $data->token)) return Response::generate('', Response::TOKEN_ERR);
  1944. //写赛事数据
  1945. $obt = $data->data;
  1946. if ($obt) {
  1947. $getData = $this->getAddData($obt);
  1948. $league = [];
  1949. $competition = [];
  1950. $odds = [];
  1951. $odds_soly = [];
  1952. $league_result = [];
  1953. $match_result = [];
  1954. $match_result_record = [];
  1955. $odds_record = [];
  1956. $broadcast = [];
  1957. //指定排序 联赛->赛事->赔率->联赛结果->赛事结果->赛事结果记录->赔率记录->直播数据
  1958. foreach ($getData as $k => $v) {
  1959. $game_code = $v['game_code'];
  1960. if ($v['title'] == 'league') $league[] = $v;
  1961. if ($v['title'] == 'competition') $competition[] = $v;
  1962. if ($v['title'] == 'odds') $odds[] = $v;
  1963. if ($v['title'] == 'odds_sole') $odds_soly[] = $v;
  1964. if ($v['title'] == 'league_result') $league_result[] = $v;
  1965. if ($v['title'] == 'match_result') $match_result[] = $v;
  1966. if ($v['title'] == 'match_result_record') $match_result_record[] = $v;
  1967. if ($v['title'] == 'odds_record') $odds_record[] = $v;
  1968. if ($v['title'] == 'broadcast') $broadcast[] = $v;
  1969. }
  1970. $matchData = [$league, $competition, $odds_soly, $odds, $league_result, $match_result, $match_result_record, $odds_record, $broadcast];
  1971. //排空处理
  1972. foreach ($matchData as $k => $v) {
  1973. if ($v == []) unset($matchData[$k]);
  1974. }
  1975. sort($matchData);
  1976. //根据顺序写入数据
  1977. //降维数据
  1978. $mentData = [];
  1979. foreach ($matchData as $k => $v) {
  1980. foreach ($v as $kk => $vv) {
  1981. $mentData[] = $vv;
  1982. }
  1983. }
  1984. //获取各球类model
  1985. $models = commonFunction::getModels($game_code, 1);
  1986. //获取球类名称
  1987. $gameName = gameModel::getGameName($game_code);
  1988. //===获取验证数据===
  1989. //获取一段时间内所有联赛本地记录
  1990. $lg_data = LeagueModel::getLeagueID($models);
  1991. //获取一段时间内所有赛事本地记录
  1992. $match_data = MatchModel::getMatchID($models);
  1993. //获取一段时间内所有赔率
  1994. $odds_data = OddsModel::getOddsID($models);
  1995. //获取一段时间内所有赔率记录
  1996. $odds_record_data = OddsRecordModel::getOddsRecordID($models);
  1997. //===获取验证数据===
  1998. $others_lg_id = '';//继承 源联赛id
  1999. $others_match_id = '';//继承 源赛事id
  2000. $s_lg_id = '';//源 联赛ID
  2001. $l_lg_id = '';//本地 联赛 ID
  2002. $s_match_id = '';//源 赛事ID
  2003. $l_match_id = '';//本地 赛事 ID
  2004. foreach ($mentData as $kk => $vv) {
  2005. switch ($vv['title']) {
  2006. case 'area'://地区
  2007. throw new \Exception(Response::generate('地区数据-area:', Response::AUTH_ERROR));
  2008. break;
  2009. case 'country'://国家
  2010. throw new \Exception(Response::generate('国家数据-country:', Response::AUTH_ERROR));
  2011. break;
  2012. case 'league'://联赛
  2013. $others_lg_id = $vv['data']['lg_id'];
  2014. $s_lg_id = $vv['data']['lg_id'];
  2015. $source = $vv['data']['source'];
  2016. //验证联赛记录是否已存在
  2017. $ret_lg = commonFunction::ver_league($s_lg_id, $source, $lg_data);
  2018. if ($ret_lg != false) {
  2019. $l_lg_id = $ret_lg;
  2020. break;
  2021. }
  2022. //执行 联赛数据
  2023. $lg_data = $this->league($vv, $gameName);
  2024. $l_lg_id = $lg_data['lg_id'];
  2025. break;
  2026. case 'competition'://赛事
  2027. $others_match_id = $vv['data']['match_id'];
  2028. $s_lg_id = $vv['data']['lg_id'];
  2029. $s_match_id = $vv['data']['match_id'];
  2030. $source = $vv['data']['source'];
  2031. //本次请求是否包含 联赛数据
  2032. if (empty($others_lg_id)) {
  2033. //验证本地是否存在
  2034. $ret_lg = commonFunction::ver_league($s_lg_id, $source, $lg_data);
  2035. if ($ret_lg == false) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
  2036. $l_lg_id = $ret_lg;
  2037. } else {
  2038. //本次有 联赛数据 验证属于同联赛
  2039. if ($s_lg_id != $others_lg_id) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
  2040. }
  2041. //验证赛事记录是否已存在
  2042. $ret_match = commonFunction::ver_match($s_match_id, $source, $match_data);
  2043. if ($ret_match != false) {
  2044. $l_match_id = $ret_match;
  2045. break;
  2046. }
  2047. //执行 赛事数据
  2048. $match_data = $this->competition($vv, $gameName, $l_lg_id);
  2049. $l_match_id = $match_data['match_id'];
  2050. break;
  2051. case 'odds'://赔率
  2052. $s_lg_id = $vv['data']['lg_id'];
  2053. $s_match_id = $vv['data']['match_id'];
  2054. $source = $vv['data']['source'];
  2055. $odds_only = $vv['data']['odds_only'];
  2056. $sole = $vv['data']['sole'];
  2057. $odds_type = $vv['data']['type'];//0普通 1冠军盘口
  2058. //本次请求是否包含 联赛数据
  2059. if (empty($others_lg_id)) {
  2060. //无联赛数据 验证本地是否存在
  2061. $ret_lg = commonFunction::ver_league($s_lg_id, $source, $lg_data);
  2062. //联赛 不存在
  2063. if ($ret_lg == false) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
  2064. $l_lg_id = $ret_lg;
  2065. } else {
  2066. //有联赛数据 验证属于同请求联赛
  2067. if ($s_lg_id != $others_lg_id) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
  2068. }
  2069. //如果是普通 赔率,则验证所属赛事
  2070. if ($odds_type == 0) {
  2071. //验证赛事记录是否已存在
  2072. if (empty($others_match_id)) {
  2073. //无赛事数据 验证本地是否存在
  2074. $ret_match = commonFunction::ver_match($s_match_id, $source, $match_data);
  2075. //赛事 不存在
  2076. if ($ret_match == false) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::MATCH_ERROR));
  2077. $l_match_id = $ret_match;
  2078. } else {
  2079. //有赛事数据 验证属于同请求赛事
  2080. if ($s_match_id != $others_match_id) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::MATCH_ERROR));
  2081. }
  2082. }
  2083. //验证赔率 是否存在
  2084. $ret_odds = '';
  2085. $ret_odds = commonFunction::ver_odds($sole, $source, $odds_data);
  2086. //验证赔率记录 是否存在
  2087. $ret_odds_record = '';
  2088. $ret_odds_record = commonFunction::ver_odds_record($odds_only, $source, $odds_record_data);
  2089. $this->odds($vv, $gameName, $l_lg_id, $l_match_id, $ret_odds, $ret_odds_record);
  2090. break;
  2091. case 'odds_sole':
  2092. $this->upOddsStatus($vv, $gameName);
  2093. break;
  2094. case 'league_result'://联赛结果
  2095. $this->league_result($vv, $gameName);
  2096. break;
  2097. case 'match_result'://赛事结果
  2098. throw new \Exception(Response::generate('赛事结果数据-match_result:', Response::AUTH_ERROR));
  2099. $this->match_result($vv, $gameName);
  2100. break;
  2101. case 'match_result_record'://赛事结果记录
  2102. $s_lg_id = $vv['data']['lg_id'];
  2103. $s_match_id = $vv['data']['match_id'];
  2104. $source = $vv['data']['source'];
  2105. //如果本次请求没有 联赛数据
  2106. if (empty($others_lg_id)) {
  2107. //验证本地是否存在
  2108. $ret_lg = commonFunction::ver_league($s_lg_id, $source, $lg_data);
  2109. //联赛 不存在
  2110. if ($ret_lg == false) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
  2111. $l_lg_id = $ret_lg;
  2112. } else {
  2113. //有联赛数据 验证属于同请求联赛
  2114. if ($s_lg_id != $others_lg_id) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
  2115. }
  2116. //验证赛事记录是否已存在
  2117. if (empty($others_match_id)) {
  2118. //无赛事数据 验证本地是否存在
  2119. $ret_match = commonFunction::ver_match($s_match_id, $source, $match_data);
  2120. //联赛 不存在
  2121. if ($ret_match == false) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::MATCH_ERROR));
  2122. $l_match_id = $ret_match;
  2123. } else {
  2124. //有赛事数据 验证属于同请求赛事
  2125. if ($s_match_id != $others_match_id) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::MATCH_ERROR));
  2126. }
  2127. //处理 赛事结果 记录
  2128. $this->com_result_record($vv, $gameName, $l_lg_id, $l_match_id);
  2129. break;
  2130. case 'broadcast'://直播数据
  2131. $this->broadcast($vv, $game_code);
  2132. break;
  2133. default:
  2134. throw new \Exception(Response::generate('', Response::ABNORMAL));
  2135. }
  2136. }
  2137. }
  2138. }
  2139. */
  2140. //提交事务
  2141. DB::commit();
  2142. return Response::success();
  2143. } catch (\Exception $e) {
  2144. //回滚事务
  2145. DB::rollBack();
  2146. return $e->getMessage();
  2147. }
  2148. }
  2149. /*
  2150. * 写入直播 数据
  2151. */
  2152. public function broadcast($opt = [], $game_code = '')
  2153. {
  2154. $data = $opt['data'];
  2155. $set_broadcast = [
  2156. "doing" => $data['doing'],
  2157. "game_type" => $data['game_type'],
  2158. "game_code" => $game_code,
  2159. "guest_team" => $data['guest_team'],
  2160. "host_team" => $data['host_team'],
  2161. "league_name" => $data['league_name'],
  2162. "shower" => $data['shower'],
  2163. "showid" => (int)$data['showid'],
  2164. "start_time" => $data['start_time'],
  2165. "ctime" => date('Y-m-d H:i:s'),
  2166. "utime" => date('Y-m-d H:i:s'),
  2167. ];
  2168. $ret = broadcastModel::insert($set_broadcast);
  2169. if ($ret == false) throw new \Exception(Response::generate('', Response::BROADCAST_ERROR));
  2170. }
  2171. /*
  2172. * 写入 赛事 初始 结果1
  2173. */
  2174. public function match_result($game_code = '',$match_id = 0)
  2175. {
  2176. $model = commonFunction::getModels($game_code, 1);
  2177. if ($game_code == 'zq') ZqResultModel::ZQresult_v2($model,$match_id);
  2178. if ($game_code == 'lq') LqResultModel::LQresult_v2($model,$match_id);
  2179. if ($game_code == 'wq') WqResultModel::WQresult_v2($model,$match_id);
  2180. if ($game_code == 'bq') BqResultModel::BQresult_v2($model,$match_id);
  2181. }
  2182. /*
  2183. * 写入联赛数据
  2184. */
  2185. public function league($opt = [], $gameName = '')
  2186. {
  2187. $game_code = $opt['game_code'];
  2188. //根据球类代码获取相关model
  2189. $model = commonFunction::getModels($game_code, 1);
  2190. $data = $opt['data'];
  2191. //查询联赛是否已存在
  2192. $id = $model['model_league']::where('name_chinese', '=', $data['name_chinese'])
  2193. ->value('id');
  2194. //默认获取本年最后一天
  2195. $last_time = date('Y-12-31 23:59:59');
  2196. //决赛时间
  2197. if ($data['last_time']) {
  2198. $last_time = $data['last_time'];
  2199. }
  2200. $set_lg['name_chinese'] = $data['name_chinese'];
  2201. $set_lg['kind'] = $data['kind'];
  2202. $set_lg['match_mode'] = $data['match_mode'];
  2203. $set_lg['if_stop'] = $data['if_stop'];
  2204. $set_lg['identity'] = $data['uuid'] ?: '';
  2205. $set_lg['last_time'] = $last_time;
  2206. $set_lg['utime'] = date('Y-m-d H:i:s');
  2207. if (empty($id)) {
  2208. //写入联赛
  2209. $id = $model['model_league']::insertGetId($set_lg);
  2210. $m_lg_id = $id;
  2211. if ($m_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::INSERT_ERROR));
  2212. } else {
  2213. //更新联赛
  2214. $ret = $model['model_league']::where(['id' => $id])
  2215. ->update($set_lg);
  2216. if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::UPDATE_ERROR));
  2217. }
  2218. $set_local = [
  2219. 'lg_id' => $id,
  2220. 'others_lg_id' => $data['lg_id'],
  2221. 'source' => $data['source'],
  2222. 'ctime' => date('Y-m-d H:i:s')
  2223. ];
  2224. $ret = $model['model_local_league']::insertGetId($set_local);
  2225. 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'));
  2226. //执行成功返回源数据 联赛ID
  2227. $data = ['others_lg_id' => $data['lg_id'], 'lg_id' => $id];
  2228. return $data;
  2229. }
  2230. /*
  2231. * 写入赛事数据
  2232. */
  2233. public function competition($opt = [], $gameName = '', $lg_id = '')
  2234. {
  2235. $game_code = $opt['game_code'];
  2236. //根据球类代码获取相关model
  2237. $model = commonFunction::getModels($game_code, 1);
  2238. $data = $opt['data'];
  2239. if (empty($data['lg_id'])) throw new \Exception(Response::generate('', Response::LEAGUE_ERROR));//Render([], '10015', lang('Tips','Sports')->get('league_error'));
  2240. //查询赛事是否存在
  2241. $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']])
  2242. ->value('id');
  2243. $half_match_id = 0;
  2244. //如果有上半场赛事id 获取上半场赛事是否存在
  2245. if (!empty($data['half_match_id'])) {
  2246. $half_match_id = $match_id = $model['model_local_match']::where(['others_match_id' => $data['half_match_id'], 'source' => $data['source']])
  2247. ->value('match_id');
  2248. 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'));
  2249. }
  2250. //如果赛事没有开始日期,则为冠军盘口赛事
  2251. if (empty($data['match_date'])) {
  2252. //冠军盘口赛事获取所属联赛结束时间
  2253. $last_time = $model['model_league']::where(['id' => $lg_id])
  2254. ->value('last_time');
  2255. 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'));
  2256. //给冠军盘口赛事 赋值时间
  2257. $time = strtotime($last_time);
  2258. $data['match_date'] = date('Y-m-d', $time);
  2259. $data['match_time'] = date('H:i:s', $time);
  2260. }
  2261. $set_match = [
  2262. 'ctime' => date('Y-m-d H:i:s'),
  2263. 'utime' => date('Y-m-d H:i:s'),
  2264. 'expire_time' => date('Y-m-d H:i:s', time() + 60),
  2265. 'home_team' => $data['home_team'] ?: '',
  2266. 'guest_team' => $data['guest_team'] ?: 'no_team',
  2267. 'lg_id' => $lg_id,
  2268. 'status' => $data['status'],
  2269. 'match_date' => $data['match_date'] ?: date('Y-m-d'),
  2270. 'match_time' => $data['match_time'] ?: date('H:i:s'),
  2271. 'tag' => $data['tag'] ?: 0,
  2272. 'is_rollball' => $data['is_rollball'] ?: 0,
  2273. 'is_today' => $data['is_today'] ?: 0,
  2274. 'is_morningplate' => $data['is_morningplate'] ?: 0,
  2275. 'is_stringscene' => $data['is_stringscene'] ?: 0,
  2276. 'us_time' => $data['us_time'] ?: commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
  2277. 'half_match_id' => $half_match_id ?: 0,
  2278. 'identity' => $data['uuid'],
  2279. ];
  2280. //写入赛事
  2281. if (empty($id)) {
  2282. //写入赛事 返回id
  2283. $id = $model['model_match']::insertGetId($set_match);
  2284. if ($id < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::INSERT_ERROR));
  2285. } else {
  2286. //更新赛事
  2287. $ret = $model['model_match']::where(['id' => $id])->update($set_match);
  2288. if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::UPDATE_ERROR));
  2289. }
  2290. //写关联记录
  2291. $set_local = [
  2292. 'match_id' => $id,
  2293. 'others_match_id' => $data['match_id'],
  2294. 'source' => $data['source'],
  2295. 'ctime' => date('Y-m-d H:i:s')
  2296. ];
  2297. $ret = $model['model_local_match']::insertGetId($set_local);
  2298. 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'));
  2299. //返回 源数据 赛事ID
  2300. $data = ['others_match_id' => $data['match_id'], 'match_id' => $id];
  2301. return $data;
  2302. }
  2303. /*
  2304. * 写入赔率/赔率记录数据
  2305. */
  2306. public function odds($opt = [], $gameName = '', $lg_id = 0, $match_id = 0, $oddsID = '', $oddsRecordID = '')
  2307. {
  2308. $game_code = $opt['game_code'];
  2309. //根据球类代码获取相关model
  2310. $model = commonFunction::getModels($game_code, 1);
  2311. $data = $opt['data'];
  2312. //获取赛事 本地/源ID
  2313. $others_match_id = $data['match_id'];
  2314. //获取联赛 本地/源ID
  2315. $others_lg_id = $data['lg_id'];
  2316. //===写赔率记录===
  2317. $set_odds_r = [
  2318. 'match_id' => $match_id ?: 0,
  2319. 'others_match_id' => $others_match_id ?: 0,
  2320. 'odds_code' => $data['odds_code'] ?: '',
  2321. 'status' => $data['status'] ?: 0,
  2322. 'sort' => $data['sort'] ?: 0,
  2323. 'p_code' => $data['p_code'] ?: '',
  2324. 'odds' => $data['odds'] ?: 0,
  2325. 'condition' => $data['condition'],
  2326. 'odds_only' => $data['odds_only'] ?: '',
  2327. 'source' => $data['source'] ?: '',
  2328. 'type' => $data['type'] ?: 0,
  2329. 'team' => $data['team'] ?: '',
  2330. 'lg_id' => $lg_id,
  2331. 'others_lg_id' => $others_lg_id,
  2332. 'ctime' => date('Y-m-d H:i:s'),
  2333. ];
  2334. //更新或写入赔率记录
  2335. if ($oddsRecordID != false) {
  2336. $ret = $model['model_odds_record']::where(['id' => $oddsRecordID])
  2337. ->update($set_odds_r);
  2338. 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'));
  2339. } else {
  2340. $ret = $model['model_odds_record']::insert($set_odds_r);
  2341. 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'));
  2342. }
  2343. //===写赔率===
  2344. $set_odds = [
  2345. 'match_id' => $match_id ?: 0,
  2346. 'others_match_id' => $others_match_id ?: 0,
  2347. 'odds_code' => $data['odds_code'] ?: '',
  2348. 'status' => $data['status'] ?: 0,
  2349. 'sort' => $data['sort'] ?: 0,
  2350. 'p_code' => $data['p_code'] ?: '',
  2351. 'odds' => $data['odds'] ?: 0,
  2352. 'condition' => $data['condition'],
  2353. 'odds_only' => $data['odds_only'] ?: '',
  2354. 'sole' => $data['sole'] ?: '',
  2355. 'source' => $data['source'] ?: '',
  2356. 'type' => $data['type'] ?: 0,
  2357. 'team' => $data['team'] ?: '',
  2358. 'lg_id' => $lg_id,
  2359. 'others_lg_id' => $others_lg_id,
  2360. 'ctime' => date('Y-m-d H:i:s'),
  2361. 'utime' => date('Y-m-d H:i:s'),
  2362. 'expire_time' => date('Y-m-d H:i:s', time() + 60),
  2363. ];
  2364. //更新或写入赔率数据
  2365. if ($oddsID != false) {
  2366. $ret = $model['model_odds']::where(['id' => $oddsID])
  2367. ->update($set_odds);
  2368. 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'));
  2369. } else {
  2370. $ret = $model['model_odds']::insert($set_odds);
  2371. 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'));
  2372. }
  2373. //===end===
  2374. }
  2375. /*
  2376. * 更新 赛事下 所有不在本次请求的 赔率状态
  2377. */
  2378. public function upOddsStatus($opt = [], $gameName = '')
  2379. {
  2380. //获取球类代码
  2381. $game_code = $opt['game_code'];
  2382. //获取球类model
  2383. $model = commonFunction::getModels($game_code, 1);
  2384. //赛事下 所有 赔率sole
  2385. $odds_sole = $opt['data'];
  2386. //数据源 赛事 id
  2387. $others_match_id = $opt['match_id'];
  2388. //数据源
  2389. $source = $opt['source'];
  2390. //更新赛事下所有 不在本次请求的赔率 状态
  2391. $ret = OddsModel::upOddsStatus($model, $others_match_id, '', $source, $odds_sole);
  2392. if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
  2393. }
  2394. /*
  2395. * 写入联赛结果
  2396. */
  2397. public function league_result($opt, $gameName)
  2398. {
  2399. $game_code = $opt['game_code'];
  2400. //根据球类代码获取相关model
  2401. $model = commonFunction::getModels($game_code, 1);
  2402. $data = $opt['data'];
  2403. //验证结果所属联赛
  2404. $lg_id = $model['model_local_league']::where(['others_lg_id' => $data['lg_id'], 'source' => $data['source']])
  2405. ->value('lg_id');
  2406. if ($lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LEAGUE_ERROR));
  2407. $lg_result_id = $model['model_league_result']::where(['lg_id' => $lg_id, 'game_name' => $data['game_name']])
  2408. ->value('id');
  2409. $set_lg_result = [
  2410. 'lg_id' => $lg_id,
  2411. 'game_name' => $data['game_name'],
  2412. 'result' => json_encode($data['result'], JSON_UNESCAPED_UNICODE),
  2413. 'status' => $data['status'],
  2414. 'ctime' => date('Y-m-d H:i:s'),
  2415. 'utime' => date('Y-m-d H:i:s'),
  2416. ];
  2417. //联赛结果数据处理
  2418. if (!empty($lg_result_id)) {
  2419. $ret = $model['model_league_result']::where(['id' => $lg_result_id])
  2420. ->update($set_lg_result);
  2421. 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'));
  2422. } else {
  2423. $ret = $model['model_league_result']::insert($set_lg_result);
  2424. 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'));
  2425. }
  2426. }
  2427. /*
  2428. * 写入赛事结果
  2429. */
  2430. public function com_result($opt = [], $gameName = '', $lg_id = '', $match_id = '')
  2431. {
  2432. $game_code = $opt['game_code'];
  2433. //根据球类代码获取相关model
  2434. $model = commonFunction::getModels($game_code, 1);
  2435. $data = $opt['data'];
  2436. //查询结果是否存在
  2437. $match_r_id = $model['model_result']::where(['match_id' => $match_id])
  2438. ->value('id');
  2439. $set_match_r = [
  2440. "home_team" => $data['home_team'],
  2441. "guest_team" => $data['guest_team'],
  2442. "lg_id" => $lg_id,
  2443. "home_rate" => $data['home_rate'],
  2444. "guest_rate" => $data['guest_rate'],
  2445. "home_score" => $data['home_score'],
  2446. "guest_score" => $data['guest_score'],
  2447. "all_goal" => $data['all_goal'],
  2448. "status" => $data['status'],
  2449. "first_score" => $data['first_score'],
  2450. "last_score" => $data['last_score'],
  2451. "match_score" => $data['match_score'],
  2452. "match_winer" => $data['match_winer'],
  2453. "match_time" => $data['match_time'],
  2454. "match_process" => $data['match_process'],
  2455. "tag" => $data['tag'],
  2456. "match_id" => $match_id,
  2457. "u_home_score" => $data['u_home_score'],
  2458. "u_guest_score" => $data['u_guest_score'],
  2459. "p_code" => $data['p_code'],
  2460. "update_time" => date('Y-m-d H:i:s')
  2461. ];
  2462. //赛事结果数据处理
  2463. if (!empty($match_r_id)) {
  2464. $ret = $model['model_result']::where(['id' => $match_r_id])
  2465. ->update($set_match_r);
  2466. 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'));
  2467. } else {
  2468. $ret = $model['model_result']::insert($set_match_r);
  2469. 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'));
  2470. }
  2471. // return Response::success();
  2472. }
  2473. //写入赛事结果记录
  2474. public function com_result_record($opt = [], $gameName = '', $lg_id = '', $match_id = '')
  2475. {
  2476. $game_code = $opt['game_code'];
  2477. //根据球类代码获取相关model
  2478. $model = commonFunction::getModels($game_code, 1);
  2479. $data = $opt['data'];
  2480. $match_r_id = $model['model_result_record']::where(['match_id' => $match_id, 'match_time' => $data['match_time']])
  2481. ->value('id');
  2482. //根据球类 获取 赛事结果记录字段
  2483. $set_match_r = $this->get_match_r($game_code, $lg_id, $match_id, $data);
  2484. //赛事结果记录处理
  2485. if ($match_r_id > 0) {
  2486. $ret = $model['model_result_record']::where(['id' => $match_r_id])
  2487. ->update($set_match_r);
  2488. 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'));
  2489. } else {
  2490. $ret = $model['model_result_record']::insert($set_match_r);
  2491. 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'));
  2492. }
  2493. }
  2494. /**
  2495. * 写赛果数据
  2496. */
  2497. public function setResultExpress_v1($data){
  2498. //验证token
  2499. $user = new \App\Models\System_user;
  2500. if (empty($data->token)) return Response::generate('未获取到token', Response::TOKEN_ERR);
  2501. $token = $user::where(['token' => $data->token])->value('token');
  2502. if (empty($token)) return Response::generate('token验证不通过', Response::TOKEN_ERR);
  2503. try {
  2504. //开启事务
  2505. DB::beginTransaction();
  2506. $obt = $data->data;
  2507. //请求 数据 为空
  2508. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  2509. $getData = $this->getAddData($obt);
  2510. //不是 赛事 结果 记录 数据
  2511. if ($getData['title'] != 'result') throw new \Exception(Response::generate('不是赛果数据,', Response::ABNORMAL));
  2512. //获取球类代码
  2513. $game_code = $getData['game_code'];
  2514. //获取数据源
  2515. $source = $getData['source'];
  2516. //获取球类名称
  2517. $gameName = gameModel::getGameName($game_code);
  2518. //获取 model
  2519. $models = commonFunction::getModels($game_code, 1);
  2520. //获取 赛事 数据
  2521. $match_r_data = $getData['data'];
  2522. if(!empty($match_r_data)){
  2523. foreach($match_r_data as $k=>$v){
  2524. //删除已存在
  2525. $del = $models['model_result_express']::where('match_id',$v['match_id'])->delete();
  2526. //==处理 赛事时间==
  2527. // dd($v['match_date'].' '.$v['match_time']);
  2528. $match_time_o = strtotime ($v['match_date'].' '.$v['match_time']);//原始美东时间 时间戳
  2529. $match_time_new = strtotime(commonFunction::qgmdate('Y-m-d H:i:s', $match_time_o, 20));//本地时间 时间戳 20=8+12
  2530. $match_date = date('Y-m-d',$match_time_new);
  2531. $match_time = date('H:i:s',$match_time_new);
  2532. //==end==
  2533. $v['match_date'] = $match_date;
  2534. $v['match_time'] = $match_time;
  2535. $v['c_time'] = date('Y-m-d H:i:s',time());
  2536. $v['u_time'] = date('Y-m-d H:i:s',time());
  2537. $v['source'] = $source;
  2538. $v['play_data'] = json_encode($v['play_data'],JSON_UNESCAPED_UNICODE);
  2539. $ret = $models['model_result_express']::insert($v);
  2540. if ($ret != true) throw new \Exception(Response::generate($gameName . ';', Response::SET_MATCH_R_ERR));
  2541. }
  2542. //写 赛事 结果 记录
  2543. }
  2544. //提交事务
  2545. DB::commit();
  2546. //写请求数据 日志记录
  2547. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
  2548. return Response::success();
  2549. } catch (\Exception $e) {
  2550. //回滚事务
  2551. DB::rollBack();
  2552. //写请求数据 日志记录
  2553. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
  2554. return $e->getMessage();
  2555. }
  2556. }
  2557. /**
  2558. * 写赛事危险球数据
  2559. */
  2560. public function setMatchWarn_v1($data){
  2561. //验证token
  2562. $user = new \App\Models\System_user;
  2563. if (empty($data->token)) return Response::generate('未获取到token:', Response::TOKEN_ERR);
  2564. $token = $user::where(['token' => $data->token])->value('token');
  2565. if (empty($token)) return Response::generate('token验证不通过:', Response::TOKEN_ERR);
  2566. try {
  2567. //开启事务
  2568. DB::beginTransaction();
  2569. $obt = $data->data;
  2570. //请求 数据 为空
  2571. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  2572. $getData = $this->getAddData($obt);
  2573. //不是 赛事 危险球 数据
  2574. if ($getData['title'] != 'match_warn') throw new \Exception(Response::generate('不是危险球数据,', Response::ABNORMAL));
  2575. //获取球类代码
  2576. $game_code = $getData['game_code'];
  2577. //获取数据源
  2578. $source = $getData['source'];
  2579. //获取数据源赛事id
  2580. $others_match_id = $getData['match_id'];
  2581. //获取数据源赛事uuid
  2582. $match_identity = $getData['match_identity'];
  2583. //获取球类名称
  2584. $gameName = gameModel::getGameName($game_code);
  2585. //获取 model
  2586. $models = commonFunction::getModels($game_code, 1);
  2587. //获取 赛事 数据
  2588. $warn_data = $getData['data'];
  2589. //获取赛事 match_id
  2590. $match_id = $models['model_local_match']::SELECT('others_match_id', 'match_id')
  2591. // ->where(['source' => $source,'identity' => $match_identity])
  2592. ->where(['identity' => $match_identity])
  2593. ->first()->match_id;
  2594. if(!empty($match_id)){
  2595. //更新 危险球
  2596. $ret = ZqResultModel::set_result_warn($match_id,$warn_data);
  2597. if($ret < 1) throw new \Exception( Response::generate('',Response::SET_WARN_ERR));
  2598. //追加 滚球投注 危险球审核
  2599. // SportsNoteListModel::WarnHandle($match_id,$warn_data);
  2600. }
  2601. //提交事务
  2602. DB::commit();
  2603. //写请求数据 日志记录
  2604. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], Response::success());
  2605. return Response::success();
  2606. } catch (\Exception $e) {
  2607. //回滚事务
  2608. DB::rollBack();
  2609. //写请求数据 日志记录
  2610. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
  2611. return $e->getMessage();
  2612. }
  2613. }
  2614. /**
  2615. * 定时执行 滚球投注危险球审核
  2616. * 每分钟执行一次
  2617. */
  2618. public function HandleOrder(){
  2619. try {
  2620. //开启事务
  2621. DB::beginTransaction();
  2622. $time = 60;
  2623. //处理指定时间内的滚球待审核订单
  2624. SportsNoteListModel::getOrderData($time);
  2625. //提交事务
  2626. DB::commit();
  2627. //写请求数据 日志记录
  2628. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('zq', [], 'HandleOrder', Response::success());
  2629. return Response::success();
  2630. } catch (\Exception $e) {
  2631. //回滚事务
  2632. DB::rollBack();
  2633. //写请求数据 日志记录
  2634. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('zq', [], 'HandleOrder', $e->getMessage());
  2635. return $e->getMessage();
  2636. }
  2637. }
  2638. /**
  2639. * 定时执行 处理到时间应该开始而未开始的赛事
  2640. * 每分钟执行一次
  2641. */
  2642. public function HandleMatch(){
  2643. try {
  2644. //开启事务
  2645. DB::beginTransaction();
  2646. $time = 60;//60 秒
  2647. //处理指定时间内的赛事
  2648. StMatchModel::HandleMatch($time);
  2649. //提交事务
  2650. DB::commit();
  2651. //写请求数据 日志记录
  2652. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('all', [], 'HandleMatch', Response::success());
  2653. return Response::success();
  2654. } catch (\Exception $e) {
  2655. //回滚事务
  2656. DB::rollBack();
  2657. //写请求数据 日志记录
  2658. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('all', [], 'HandleMatch', $e->getMessage());
  2659. return $e->getMessage();
  2660. }
  2661. }
  2662. /**
  2663. * @param $data
  2664. * @return mixed
  2665. * json转数组
  2666. */
  2667. public function getAddData($data)
  2668. {
  2669. $data = json_decode($data, true);
  2670. return $data;
  2671. }
  2672. /*
  2673. * 根据球类获取 赛事结果记录字段
  2674. */
  2675. public function get_match_r($game_code, $lg_id, $match_id, $data)
  2676. {
  2677. $set_match_r = [];
  2678. if ($game_code == 'zq') {
  2679. $set_match_r = [
  2680. "home_team" => $data['home_team'] ?: '',
  2681. "guest_team" => $data['guest_team'] ?: '',
  2682. "lg_id" => $lg_id,
  2683. "all_goal" => $data['all_goal'] ?: 0,
  2684. "home_rate" => $data['home_rate'] ?: 0,
  2685. "guest_rate" => $data['guest_rate'] ?: 0,
  2686. "home_score" => $data['home_score'] ?: 0,
  2687. "guest_score" => $data['guest_score'] ?: 0,
  2688. "status" => $data['status'] ?: 0,
  2689. "first_score" => $data['first_score'] ?: 0,
  2690. "last_score" => $data['last_score'] ?: 0,
  2691. "match_score" => $data['match_score'] ?: 0,
  2692. "match_winer" => $data['match_winer'] ?: '',
  2693. "match_time" => $data['match_time'] ?: 0,
  2694. "match_process" => $data['match_process'] ?: '',
  2695. // "tag"=> $data['tag']?:0,
  2696. "match_id" => $match_id,
  2697. "update_time" => date('Y-m-d H:i:s'),
  2698. "corner_result" => json_encode($data['corner_result']),//角球
  2699. "penalty_result" => json_encode($data['penalty_result']),//罚牌
  2700. ];
  2701. };
  2702. if ($game_code == 'lq') {
  2703. $set_match_r = [
  2704. "home_team" => $data['home_team'] ?: '',
  2705. "guest_team" => $data['guest_team'] ?: '',
  2706. "lg_id" => $lg_id,
  2707. "home_rate" => $data['home_rate'] ?: 0,
  2708. "guest_rate" => $data['guest_rate'] ?: 0,
  2709. "home_score" => $data['home_score'] ?: 0,
  2710. "guest_score" => $data['guest_score'] ?: 0,
  2711. "status" => $data['status'] ?: 0,
  2712. "first_score" => $data['first_score'] ?: 0,
  2713. "last_score" => $data['last_score'] ?: 0,
  2714. "match_score" => $data['match_score'] ?: 0,
  2715. "match_winer" => $data['match_winer'] ?: '',
  2716. "match_time" => $data['match_time'] ?: 0,
  2717. "match_process" => $data['match_process'] ?: '',
  2718. // "tag"=> $data['tag']?:0,
  2719. "match_id" => $match_id,
  2720. "update_time" => date('Y-m-d H:i:s'),
  2721. "result_mark" => json_encode($data['result_mark']) ?: '',
  2722. ];
  2723. }
  2724. if ($game_code == 'wq') {
  2725. $set_match_r = [
  2726. "home_player_name" => $data['home_player_name'] ?: '',
  2727. "guest_player_name" => $data['guest_player_name'] ?: '',
  2728. "lg_id" => $lg_id,
  2729. "home_player_let_plate" => $data['home_player_let_plate'] ?: 0,
  2730. "guest_player_let_plate" => $data['guest_player_let_plate'] ?: 0,
  2731. "home_player_let_inning" => $data['home_player_let_inning'] ?: 0,
  2732. "guest_player_let_inning" => $data['guest_player_let_inning'] ?: 0,
  2733. "all_inning" => $data['all_inning'] ?: 0,
  2734. "home_player_score" => $data['home_player_score'] ?: 0,
  2735. "guest_player_score" => $data['guest_player_score'] ?: 0,
  2736. "status" => $data['status'] ?: 0,
  2737. "first_score_player" => $data['first_score_player'] ?: '',
  2738. "last_score_player" => $data['last_score_player'] ?: '',
  2739. "first_inning_score" => $data['first_inning_score'] ?: 0,
  2740. "second_inning_score" => $data['second_inning_score'] ?: 0,
  2741. "third_inning_score" => $data['third_inning_score'] ?: 0,
  2742. "match_winer_player" => $data['match_winer_player'] ?: '',
  2743. "update_time" => date('Y-m-d H:i:s'),
  2744. "match_time" => $data['match_time'] ?: 0,
  2745. "match_process" => $data['match_process'] ?: '',
  2746. // "tag"=>$data['tag']?:0,
  2747. "match_id" => $match_id,
  2748. "result_mark" => json_encode($data['result_mark']) ?: '',
  2749. ];
  2750. }
  2751. if ($game_code == 'bq') {
  2752. $set_match_r = [
  2753. "home_team" => $data['home_team'] ?: '',
  2754. "guest_team" => $data['guest_team'] ?: '',
  2755. "lg_id" => $lg_id,
  2756. "home_rate" => $data['home_rate'] ?: 0,
  2757. "guest_rate" => $data['guest_rate'] ?: 0,
  2758. "home_score" => $data['home_score'] ?: 0,
  2759. "guest_score" => $data['guest_score'] ?: 0,
  2760. "status" => $data['status'] ?: 0,
  2761. "first_score" => $data['first_score'] ?: 0,
  2762. "last_score" => $data['last_score'] ?: 0,
  2763. "match_score" => $data['match_score'] ?: 0,
  2764. "match_winer" => $data['match_winer'] ?: '',
  2765. "match_time" => $data['match_time'] ?: 0,
  2766. "match_process" => $data['match_process'] ?: '',
  2767. // "tag"=> $data['tag']?:0,
  2768. "match_id" => $match_id,
  2769. "all_inning" => $data['all_inning'] ?: 9,
  2770. "update_time" => date('Y-m-d H:i:s'),
  2771. "result_mark" => json_encode($data['result_mark']) ?: '',
  2772. ];
  2773. }
  2774. return $set_match_r;
  2775. }
  2776. //将数组按按指定健名,重新生成新的数组,key在存在并且 值不能重复
  2777. private function ArrayKeySet(Array $array, $key)
  2778. {
  2779. $ret = [];
  2780. foreach ($array as $val) {
  2781. $ret[$val[$key]] = $val;
  2782. }
  2783. return $ret;
  2784. }
  2785. }