WriteSportsController.php 121 KB

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