DataLogic.php 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/6/26
  6. * Time: 17:10
  7. */
  8. namespace App\Logic;
  9. use datainf\pplus\Instance;
  10. use App\Http\Response\Response;
  11. use App\Lib\ModelBase;
  12. use Illuminate\Database\Capsule\Manager as 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. class DataLogic
  28. {
  29. use Instance;
  30. private $isRecord = 0;
  31. /*
  32. * 写 联赛 数据
  33. * 每个请求 包含 N个联赛
  34. */
  35. public function setLeague($data)
  36. {
  37. try {
  38. //开启事务
  39. DB::beginTransaction();
  40. $obt = $data['data'];
  41. //请求 数据 为空
  42. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  43. $getData = $this->getAddData($obt);
  44. //不是 联赛 数据
  45. if ($getData['title'] != 'league') throw new \Exception(Response::generate('不是联赛数据,', Response::ABNORMAL));
  46. /*
  47. //写请求数据 日志记录
  48. if($this->isRecord){
  49. commonFunction::SET_SPORTS_RECORD($obt,$getData['title']);
  50. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  51. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  52. }
  53. */
  54. //获取球类代码
  55. $game_code = $getData['game_code'];
  56. //获取数据源
  57. $source = $getData['source'];
  58. //获取球类名称
  59. $gameName = gameModel::getGameName($game_code);
  60. //获取 model
  61. $models = commonFunction::getModels($game_code, 1);
  62. //获取 联赛 数据
  63. $leagueData = $getData['data'];
  64. //获取 当前请求 所有 联赛 uuid
  65. $identity = [];
  66. foreach ($leagueData as $k => $v) {
  67. $identity[] = $v['uuid'];
  68. }
  69. $identity = array_unique($identity);
  70. sort($identity);
  71. //获取 本地 已存在 联赛
  72. $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id')->get()->toArray();
  73. //二维数组去重
  74. $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
  75. //循环对比 请求identity->本地identity
  76. foreach ($l_lg_data as $k => $v) {
  77. foreach ($identity as $kk => $uuid) {
  78. if ($v['identity'] == $uuid) {
  79. unset($identity[$kk]);
  80. }
  81. }
  82. }
  83. //去除本地和请求里都存在的联赛,如果还有剩余联赛uuid,则将其写入
  84. if (!empty($identity)) {
  85. //没有 决赛时间 默认获取本年最后一天
  86. $last_time = date('Y-12-31 23:59:59');
  87. foreach ($leagueData as $k => $v) {
  88. foreach ($identity as $kk => $uuid) {
  89. if ($v['uuid'] == $uuid) {
  90. //如有 决赛时间
  91. if ($v['last_time']) {
  92. $last_time = $v['last_time'];
  93. }
  94. //获取联赛所属国家或地区
  95. $getArea = $this->getArea($v['name_chinese']);
  96. if ($getArea['pid'] == 0) {
  97. $area_id = $getArea['id'];
  98. $country_id = 0;
  99. } else {
  100. $area_id = $getArea['pid'];
  101. $country_id = $getArea['id'];
  102. }
  103. if (empty($v['uuid'])) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $v['lg_id'] . ';', Response::LG__UUID_NULL));
  104. $set_lg['name_chinese'] = $v['name_chinese'];
  105. $set_lg['kind'] = $v['kind'];
  106. $set_lg['match_mode'] = $v['match_mode'];
  107. $set_lg['if_stop'] = $v['if_stop'];
  108. $set_lg['identity'] = $v['uuid'];
  109. $set_lg['last_time'] = $last_time;
  110. $set_lg['utime'] = date('Y-m-d H:i:s');
  111. $set_lg['area_id'] = $area_id ?: 247;
  112. $set_lg['country_id'] = $country_id ?: 0;
  113. //写入联赛
  114. $id = $models['model_league']::insertGetId($set_lg);
  115. $m_lg_id = $id;
  116. if ($m_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $v['lg_id'] . ';', Response::INSERT_ERROR));
  117. //写入 本地 联赛记录
  118. $set_local = [
  119. 'lg_id' => $id,
  120. 'others_lg_id' => $v['lg_id'],
  121. 'source' => $source,
  122. 'ctime' => date('Y-m-d H:i:s'),
  123. 'identity' => $v['uuid'],
  124. ];
  125. $ret = $models['model_local_league']::insertGetId($set_local);
  126. 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'));
  127. }
  128. }
  129. }
  130. }
  131. $this->writeLog($data, Response::success());
  132. //提交事务
  133. DB::commit();
  134. return Response::success();
  135. } catch (\Exception $e) {
  136. //回滚事务
  137. DB::rollBack();
  138. $this->writeLog($data, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  139. return $e->getMessage();
  140. }
  141. }
  142. /*
  143. * 写 赛事 数据
  144. * 每个请求 包含 N个联赛 下 N个赛事
  145. */
  146. public function setMatch($data)
  147. {
  148. $logdata = $data;
  149. try {
  150. //开启事务
  151. DB::beginTransaction();
  152. $obt = $data['data'];
  153. //请求 数据 为空
  154. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  155. $getData = $this->getAddData($obt);
  156. //不是 赛事 数据
  157. if ($getData['title'] != 'match') throw new \Exception(Response::generate('不是赛事数据,', Response::ABNORMAL));
  158. /*
  159. //写请求数据 日志记录
  160. if($this->isRecord){
  161. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  162. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  163. }
  164. */
  165. //获取球类代码
  166. $game_code = $getData['game_code'];
  167. //获取数据源
  168. $source = $getData['source'];
  169. //获取球类名称
  170. $gameName = gameModel::getGameName($game_code);
  171. //获取 model
  172. $models = commonFunction::getModels($game_code, 1);
  173. //获取 赛事 数据
  174. $matchData = $getData['data'];
  175. //获取 当前请求 所有 uuid
  176. $identity = [];
  177. $s_match_ids = [];
  178. foreach ($matchData as $k => $v) {
  179. $identity[] = $v['uuid'];
  180. $s_match_ids[] = $v['match_id'];
  181. }
  182. //====验证 赛事 所属 联赛 是否存在====
  183. $identity = array_unique($identity);
  184. sort($identity);
  185. //获取 本地 已存在 联赛
  186. $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id', 'others_lg_id')->get()->toArray();
  187. //二维数组去重
  188. $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
  189. //如果获取不到本地联赛数据,则返回联赛不存在
  190. if (empty($l_lg_data)) throw new \Exception(Response::generate($gameName . '本次请求的所有赛事都没有联赛数据;', Response::LEAGUE_ERROR));
  191. //获取到本次请求,所有本地有联赛的赛事
  192. $mathData_before = $matchData;//接收原赛事
  193. $matchData = [];//获取新赛事
  194. foreach ($l_lg_data as $k => $v) {
  195. foreach ($mathData_before as $kk => $vv) {
  196. if ($v['identity'] == $vv['uuid']) {
  197. $matchData[] = $vv;
  198. }
  199. }
  200. }
  201. //获取当前请求有关联联赛的赛事 match_id
  202. $s_match_ids = [];
  203. foreach ($matchData as $k => $v) {
  204. $s_match_ids[] = $v['match_id'];
  205. }
  206. //====获取 本地 已存在 赛事====
  207. $s_match_ids = array_unique($s_match_ids);
  208. sort($s_match_ids);
  209. $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();
  210. //二维数组去重
  211. $l_match_data = commonFunction::uniquArrV2($l_match_data, 'others_match_id');
  212. //循环对比 请求match_id->本地others_match_id
  213. //如果本地有 赛事,则分别获取本地已存在/不存在赛事
  214. if (!empty($l_match_data)) {
  215. //本地已存在赛事,用于更新
  216. $matchData_y = [];
  217. foreach ($l_match_data as $k => $v) {
  218. foreach ($s_match_ids as $kk => $s_match_id) {
  219. if ($v['others_match_id'] == $s_match_id) {
  220. $matchData_y[$k]['others_match_id'] = $s_match_id;
  221. $matchData_y[$k]['match_id'] = $v['match_id'];
  222. unset($s_match_ids[$kk]);
  223. }
  224. }
  225. }
  226. sort($s_match_ids);
  227. }
  228. //如果 请求中 有本地赛事,则执行更新
  229. if (!empty($matchData_y)) {
  230. foreach ($matchData as $k => $v) {
  231. foreach ($matchData_y as $kk => $vv) {
  232. if ($v['match_id'] == $vv['others_match_id']) {
  233. $data = $v;
  234. $up_match = [];
  235. $up_match['utime'] = date('Y-m-d H:i:s');
  236. $up_match['status'] = $data['status'];
  237. //获取需更新字段
  238. if ($data['is_rollball'] == 1) {
  239. $up_match['is_rollball'] = $data['is_rollball'];
  240. }
  241. if ($data['is_today'] == 1) {
  242. $up_match['is_today'] = $data['is_today'];
  243. }
  244. if ($data['is_morningplate'] == 1) {
  245. $up_match['is_morningplate'] = $data['is_morningplate'];
  246. }
  247. if ($data['is_stringscene'] == 1) {
  248. $up_match['is_stringscene'] = $data['is_stringscene'];
  249. }
  250. //追加更新开赛日期/时间
  251. $up_match['match_date'] = $data['match_date'];
  252. $up_match['match_time'] = $data['match_time'];
  253. $up_match['us_time'] = $data['us_time'];
  254. //如果是网球 追加rule 字段
  255. if ($game_code == 'wq' and !empty($data['rule'])) {
  256. $up_match['rule'] = $data['rule'];
  257. }
  258. //更新赛事 返回成功数量
  259. $set = $models['model_match']::where(['id' => $vv['match_id']])
  260. ->update($up_match);
  261. if ($set < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::UPSTATUS_ERROR));
  262. }
  263. }
  264. }
  265. }
  266. //剩余 赛事 数据 写入
  267. if (!empty($s_match_ids)) {
  268. foreach ($matchData as $k => $v) {
  269. foreach ($s_match_ids as $kk => $s_match_id) {
  270. if ($v['match_id'] == $s_match_id) {
  271. $data = $v;
  272. $half_match_id = $v['half_match_id'];
  273. //获取 本地 联赛 ID
  274. //验证本赛事是否有数据源lg_id
  275. if (empty($data['lg_id'])) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::S_LG_ID_NULL));
  276. $lg_id = commonFunction::searcharray($data['uuid'], 'identity', $l_lg_data, 'lg_id');
  277. //验证 本赛事是否获取到本地lg_id
  278. if (empty($lg_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::L_LG_ID_NULL));
  279. //如果赛事没有开始日期,则为冠军盘口赛事
  280. if (empty($data['match_date'])) {
  281. //冠军盘口赛事获取所属联赛结束时间
  282. $last_time = $models['model_league']::where(['id' => $lg_id])
  283. ->value('last_time');
  284. 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'));
  285. //给冠军盘口赛事 赋值时间
  286. $time = strtotime($last_time);
  287. $data['match_date'] = date('Y-m-d', $time);
  288. $data['match_time'] = date('H:i:s', $time);
  289. }
  290. $set_match = [
  291. 'ctime' => date('Y-m-d H:i:s'),
  292. 'utime' => date('Y-m-d H:i:s'),
  293. 'expire_time' => date('Y-m-d H:i:s', time() + 60),
  294. 'home_team' => $data['home_team'] ?: '',
  295. 'guest_team' => $data['guest_team'] ?: 'no_team',
  296. 'lg_id' => $lg_id,
  297. 'status' => $data['status'],
  298. 'match_date' => $data['match_date'] ?: date('Y-m-d'),
  299. 'match_time' => $data['match_time'] ?: date('H:i:s'),
  300. 'is_rollball' => $data['is_rollball'] ?: 0,
  301. 'is_today' => $data['is_today'] ?: 0,
  302. 'is_morningplate' => $data['is_morningplate'] ?: 0,
  303. 'is_stringscene' => $data['is_stringscene'] ?: 0,
  304. 'us_time' => $data['us_time'] ?: commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
  305. 'half_match_id' => $half_match_id ?: 0,
  306. 'identity' => $data['uuid'],
  307. ];
  308. //如果是网球 追加rule 字段
  309. if ($game_code == 'wq') {
  310. $set_match['rule'] = $data['rule'];
  311. }
  312. //写入赛事 返回id
  313. $id = $models['model_match']::insertGetId($set_match);
  314. if ($id < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::INSERT_ERROR));
  315. //写关联记录
  316. $set_local = [
  317. 'match_id' => $id,
  318. 'others_match_id' => $data['match_id'],
  319. 'source' => $source,
  320. 'ctime' => date('Y-m-d H:i:s')
  321. ];
  322. $ret = $models['model_local_match']::insertGetId($set_local);
  323. 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'));
  324. //追加写球队名称
  325. $team = [
  326. 'team_h' => $data['home_team'],
  327. 'team_g' => $data['guest_team'],
  328. ];
  329. StTeamModel::setTeam($game_code, $team, $source);
  330. }
  331. }
  332. }
  333. }
  334. $this->writeLog($logdata, Response::success());
  335. //提交事务
  336. DB::commit();
  337. return Response::success();
  338. } catch (\Exception $e) {
  339. //回滚事务
  340. DB::rollBack();
  341. $this->writeLog($logdata, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  342. return $e->getMessage();
  343. }
  344. }
  345. /*
  346. * 写 赛事 结果 记录 数据
  347. * 每个请求 包含 N个联赛 下 N个赛事 结果数据
  348. */
  349. public function setMatchResult($data)
  350. {
  351. $logdata = $data;
  352. try {
  353. //开启事务
  354. DB::beginTransaction();
  355. $obt = $data['data'];
  356. //请求 数据 为空
  357. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  358. $getData = $this->getAddData($obt);
  359. //不是 赛事 结果 记录 数据
  360. if ($getData['title'] != 'match_result_r') throw new \Exception(Response::generate('不是赛事结果记录数据,', Response::ABNORMAL));
  361. /*
  362. //写请求数据 日志记录
  363. if($this->isRecord){
  364. // $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  365. // if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  366. }
  367. */
  368. //获取球类代码
  369. $game_code = $getData['game_code'];
  370. //获取数据源
  371. $source = $getData['source'];
  372. //获取球类名称
  373. $gameName = gameModel::getGameName($game_code);
  374. //获取 model
  375. $models = commonFunction::getModels($game_code, 1);
  376. //获取 赛事 数据
  377. $match_r_data = $getData['data'];
  378. //获取 当前请求 所有 uuid /match_id
  379. $identity = [];
  380. $s_match_ids = [];
  381. $match_uuids = [];
  382. foreach ($match_r_data as $k => $v) {
  383. $identity[] = $v['uuid'];
  384. $s_match_ids[] = $v['match_id'];
  385. }
  386. //====验证 赛事 所属 联赛 是否存在====
  387. $identity = array_unique($identity);
  388. sort($identity);
  389. //获取 本地 已存在 联赛
  390. $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id')->get()->toArray();
  391. //二维数组去重
  392. $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
  393. //循环对比 请求uuid->本地identity
  394. foreach ($l_lg_data as $k => $v) {
  395. foreach ($identity as $kk => $uuid) {
  396. if ($v['identity'] == $uuid) {
  397. unset($identity[$kk]);
  398. }
  399. }
  400. }
  401. sort($identity);
  402. //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常
  403. if (!empty($identity)) throw new \Exception(Response::generate($gameName . '联赛:uuid-' . $identity[0] . ';', Response::LEAGUE_ERROR));
  404. //====end====
  405. //====验证 赛事结果记录 所属赛事 是否存在====$match_uuids
  406. $s_match_ids = array_unique($s_match_ids);
  407. sort($s_match_ids);
  408. //获取 本地 已存在 赛事
  409. $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();
  410. //二维数组去重
  411. $l_match_data = commonFunction::uniquArrV2($l_match_data, 'others_match_id');
  412. //循环对比 请求match_id->本地others_match_id
  413. foreach ($l_match_data as $k => $v) {
  414. foreach ($s_match_ids as $kk => $s_match_id) {
  415. if ($v['others_match_id'] == $s_match_id) {
  416. unset($s_match_ids[$kk]);
  417. }
  418. }
  419. }
  420. sort($s_match_ids);
  421. //去除本地和请求里都存在的赛事,如果还有剩余赛事id,则返回异常
  422. if (!empty($s_match_ids)) throw new \Exception(Response::generate($gameName . '赛事-match_id' . $s_match_ids[0] . ';', Response::MATCH_ERROR));
  423. //====end====
  424. //处理 赛事 结果记录 数据
  425. foreach ($match_r_data as $k => $v) {
  426. $data = $v;
  427. //获取 本地 联赛 ID
  428. $lg_id = commonFunction::searcharray($data['uuid'], 'identity', $l_lg_data, 'lg_id');
  429. //获取 本地 赛事 ID
  430. $match_id = commonFunction::searcharray($data['match_id'], 'others_match_id', $l_match_data, 'match_id');
  431. //根据球类 获取 赛事结果记录字段
  432. $set_match_r = $this->get_match_r($game_code, $lg_id, $match_id, $data);
  433. //写 赛事 结果 记录
  434. $ret = $models['model_result_record']::insert($set_match_r);
  435. if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));
  436. }
  437. $this->writeLog($logdata, Response::success());
  438. //提交事务
  439. DB::commit();
  440. return Response::success();
  441. } catch (\Exception $e) {
  442. //回滚事务
  443. DB::rollBack();
  444. $this->writeLog($logdata, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  445. return $e->getMessage();
  446. }
  447. }
  448. //将数组按按指定健名,重新生成新的数组,key在存在并且 值不能重复
  449. private function ArrayKeySet(Array $array, $key)
  450. {
  451. $ret = [];
  452. foreach ($array as $val) {
  453. $ret[$val[$key]] = $val;
  454. }
  455. return $ret;
  456. }
  457. /*
  458. * 写 普通 赔率 数据
  459. * 每个请求 只包含 一场赛事下 N条赔率
  460. */
  461. public function setOdds($data)
  462. {
  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'] != 'odds') throw new \Exception(Response::generate('不是赔率数据,', Response::ABNORMAL));
  472. //获取球类代码
  473. $game_code = $getData['game_code'];
  474. //获取数据源
  475. $source = $getData['source'];
  476. //获取源数据联赛ID
  477. $uuid = $getData['uuid'];
  478. //获取源数据赛事ID
  479. $s_match_id = $getData['match_id'];
  480. //获取赔率所属赛事 tag 值 玩法数量
  481. $tag = $getData['tag'] ?: 99;
  482. //获取赔率是否是串场
  483. $is_stringscene = $getData['is_stringscene'];
  484. //获取球类名称
  485. $gameName = gameModel::getGameName($game_code);
  486. //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
  487. $models = commonFunction::getModels($game_code, 1);
  488. $lg_id = $this->leagueVerify($models, $uuid, $source, $gameName);
  489. $match_id = $this->matchVerify($models, $s_match_id, $source, $gameName);
  490. //更新赛事 tag 值
  491. //如果未获取到本地赛事id,则返回异常
  492. if (empty($match_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::L_MATCH_ID_ERR));
  493. $upMatch = $models['model_match']::where(['id' => $match_id])
  494. ->update(['tag' => $tag, 'utime' => date('Y-m-d H:i:s')]);
  495. if ($upMatch < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::UPMATCHTAG_ERROR));
  496. //获取 赔率数据
  497. $oddsData = $getData['data'];
  498. //===追加处理赔率过滤===
  499. //获取当前赛事 在本地的所有赔率
  500. $l_odds_data = $models['model_odds']::select('odds_only')->where(['match_id' => $match_id, 'is_stringscene' => $is_stringscene])->get()->toArray();
  501. //获取请求待写入数据
  502. $setOddsData = [];
  503. //获取本地待删除数据
  504. $delOddsData = [];
  505. //本地没有该赛事赔率,则直接全部写入
  506. if (empty($l_odds_data)) {
  507. $setOddsData = $oddsData;
  508. } //本地有该赛事赔率,则分别获取需写入/删除的数据
  509. else {
  510. $newodds_t = $this->ArrayKeySet($oddsData, 'odds_only');
  511. $oldodds_t = $this->ArrayKeySet($l_odds_data, 'odds_only');
  512. foreach ($newodds_t as $key => $val) {
  513. if (isset($oldodds_t[$key])) {
  514. unset($newodds_t[$key]);
  515. unset($oldodds_t[$key]);
  516. }
  517. }
  518. $oddsData = $newodds_t;
  519. $l_odds_data = $oldodds_t;
  520. /*
  521. foreach ($oddsData as $k => $v) {
  522. foreach ($l_odds_data as $kk => $vv) {
  523. if ($v['odds_only'] == $vv['odds_only']) {
  524. unset($oddsData[$k]);
  525. unset($l_odds_data[$kk]);
  526. }
  527. }
  528. }
  529. */
  530. sort($oddsData);
  531. sort($l_odds_data);
  532. //需写入请求数据
  533. $setOddsData = $oddsData;
  534. //需删除本地数据
  535. $delOddsData = $l_odds_data;
  536. }
  537. //===end===
  538. //删除本地不在请求中的数据
  539. if (!empty($delOddsData)) {
  540. //所有需删除数据odds_only
  541. $odds_onlys = [];
  542. foreach ($delOddsData as $k => $v) {
  543. $odds_onlys[] = $v['odds_only'];
  544. }
  545. $del = $models['model_odds']::whereIn('odds_only', $odds_onlys)->delete();
  546. if ($del != count($odds_onlys)) throw new \Exception(Response::generate($gameName, Response::DEL_ODDS_ERR));
  547. }
  548. //写入请求中本地不存在的数据
  549. if (!empty($setOddsData)) {
  550. //处理待写入 赔率记录数据
  551. foreach ($setOddsData as $k => $v) {
  552. //组装数据
  553. $set_odds_r[] = [
  554. 'match_id' => $match_id ?: 0,
  555. 'others_match_id' => $v['match_id'] ?: 0,
  556. 'odds_code' => $v['odds_code'] ?: '',
  557. 'status' => $v['status'] ?: 0,
  558. 'sort' => $v['sort'] ?: 0,
  559. 'p_code' => $v['p_code'] ?: '',
  560. 'odds' => $v['odds'] ?: 0,
  561. 'condition' => $v['condition'],
  562. 'odds_only' => $v['odds_only'] ?: '',
  563. 'source' => $v['source'] ?: '',
  564. 'type' => $v['type'] ?: 0,
  565. 'team' => $v['team'] ?: '',
  566. 'lg_id' => $lg_id,
  567. 'is_stringscene' => $is_stringscene,
  568. 'others_lg_id' => $v['lg_id'],
  569. 'ctime' => date('Y-m-d H:i:s'),
  570. 'utime' => date('Y-m-d H:i:s'),
  571. ];
  572. }
  573. //处理待写入 赔率数据
  574. foreach ($oddsData as $k => $v) {
  575. //组装数据
  576. $set_odds[] = [
  577. 'match_id' => $match_id ?: 0,
  578. 'others_match_id' => $v['match_id'] ?: 0,
  579. 'odds_code' => $v['odds_code'] ?: '',
  580. 'status' => $v['status'] ?: 0,
  581. 'sort' => $v['sort'] ?: 0,
  582. 'p_code' => $v['p_code'] ?: '',
  583. 'odds' => $v['odds'] ?: 0,
  584. 'condition' => $v['condition'],
  585. 'odds_only' => $v['odds_only'] ?: '',
  586. 'source' => $v['source'] ?: '',
  587. 'type' => $v['type'] ?: 0,
  588. 'team' => $v['team'] ?: '',
  589. 'lg_id' => $lg_id,
  590. 'is_stringscene' => $is_stringscene,
  591. 'others_lg_id' => $v['lg_id'],
  592. 'ctime' => date('Y-m-d H:i:s'),
  593. 'utime' => date('Y-m-d H:i:s'),
  594. 'sole' => $v['sole'],
  595. 'expire_time' => date('Y-m-d H:i:s', time() + 60)
  596. ];
  597. }
  598. //写赔率记录数据
  599. $ret = $models['model_odds_record']::insert($set_odds_r);
  600. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
  601. //写赔率 数据
  602. $ret = $models['model_odds']::insert($set_odds);
  603. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
  604. }
  605. $this->writeLog($data, Response::success());
  606. //提交事务
  607. DB::commit();
  608. return Response::success();
  609. } catch (\Exception $e) {
  610. //回滚事务
  611. DB::rollBack();
  612. $this->writeLog($data, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  613. return $e->getMessage();
  614. }
  615. }
  616. /*
  617. * 写 普通 赔率 数据
  618. * 每个请求 只包含 一场赛事下 N条赔率
  619. */
  620. public function setOdds_old($data)
  621. {
  622. try {
  623. //开启事务
  624. DB::beginTransaction();
  625. $obt = $data['data'];
  626. //请求 数据 为空
  627. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  628. $getData = $this->getAddData($obt);
  629. //不是 赔率 数据
  630. if ($getData['title'] != 'odds') throw new \Exception(Response::generate('不是赔率数据,', Response::ABNORMAL));
  631. /*
  632. //写请求数据 日志记录
  633. if($this->isRecord){
  634. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  635. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  636. }
  637. */
  638. //获取球类代码
  639. $game_code = $getData['game_code'];
  640. //获取数据源
  641. $source = $getData['source'];
  642. //获取源数据联赛ID
  643. $uuid = $getData['uuid'];
  644. //获取源数据赛事ID
  645. $s_match_id = $getData['match_id'];
  646. //获取赔率所属赛事 tag 值 玩法数量
  647. $tag = $getData['tag'] ?: 99;
  648. //获取赔率是否是串场
  649. $is_stringscene = $getData['is_stringscene'];
  650. //获取球类名称
  651. $gameName = gameModel::getGameName($game_code);
  652. //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
  653. $models = commonFunction::getModels($game_code, 1);
  654. $lg_id = $this->leagueVerify($models, $uuid, $source, $gameName);
  655. $match_id = $this->matchVerify($models, $s_match_id, $source, $gameName);
  656. //更新赛事 tag 值
  657. //如果未获取到本地赛事id,则返回异常
  658. if (empty($match_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::L_MATCH_ID_ERR));
  659. $upMatch = $models['model_match']::where(['id' => $match_id])
  660. ->update(['tag' => $tag, 'utime' => date('Y-m-d H:i:s')]);
  661. if ($upMatch < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::UPMATCHTAG_ERROR));
  662. //获取 赔率数据
  663. $oddsData = $getData['data'];
  664. //获取 当前 所有 可用 赔率 sole
  665. $odds_only = $getData['odds_only'];
  666. //更新赛事下所有 不在本次请求的赔率 状态
  667. $ret = OddsModel::upOddsStatus($models, $s_match_id, '', $source, $odds_only, $is_stringscene);
  668. if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
  669. //获取当前赛事 在本地的所有赔率
  670. $l_odds_data = $models['model_odds']::select('odds_only')->where(['match_id' => $match_id])->get()->toArray();
  671. $set_odds_r = [];
  672. $set_odds = [];
  673. if (!empty($oddsData)) {
  674. //去除本地已有的赔率
  675. if (!empty($l_odds_data)) {
  676. foreach ($oddsData as $k => $v) {
  677. foreach ($l_odds_data as $kk => $vv) {
  678. if ($v['odds_only'] == $vv['odds_only']) {
  679. unset($oddsData[$k]);
  680. }
  681. }
  682. }
  683. sort($oddsData);
  684. }
  685. //处理待写入 赔率记录数据
  686. foreach ($oddsData as $k => $v) {
  687. //组装数据
  688. $set_odds_r[] = [
  689. 'match_id' => $match_id ?: 0,
  690. 'others_match_id' => $v['match_id'] ?: 0,
  691. 'odds_code' => $v['odds_code'] ?: '',
  692. 'status' => $v['status'] ?: 0,
  693. 'sort' => $v['sort'] ?: 0,
  694. 'p_code' => $v['p_code'] ?: '',
  695. 'odds' => $v['odds'] ?: 0,
  696. 'condition' => $v['condition'],
  697. 'odds_only' => $v['odds_only'] ?: '',
  698. 'source' => $v['source'] ?: '',
  699. 'type' => $v['type'] ?: 0,
  700. 'team' => $v['team'] ?: '',
  701. 'lg_id' => $lg_id,
  702. 'is_stringscene' => $is_stringscene,
  703. 'others_lg_id' => $v['lg_id'],
  704. 'ctime' => date('Y-m-d H:i:s'),
  705. 'utime' => date('Y-m-d H:i:s'),
  706. ];
  707. }
  708. //处理待写入 赔率数据
  709. foreach ($oddsData as $k => $v) {
  710. //组装数据
  711. $set_odds[] = [
  712. 'match_id' => $match_id ?: 0,
  713. 'others_match_id' => $v['match_id'] ?: 0,
  714. 'odds_code' => $v['odds_code'] ?: '',
  715. 'status' => $v['status'] ?: 0,
  716. 'sort' => $v['sort'] ?: 0,
  717. 'p_code' => $v['p_code'] ?: '',
  718. 'odds' => $v['odds'] ?: 0,
  719. 'condition' => $v['condition'],
  720. 'odds_only' => $v['odds_only'] ?: '',
  721. 'source' => $v['source'] ?: '',
  722. 'type' => $v['type'] ?: 0,
  723. 'team' => $v['team'] ?: '',
  724. 'lg_id' => $lg_id,
  725. 'is_stringscene' => $is_stringscene,
  726. 'others_lg_id' => $v['lg_id'],
  727. 'ctime' => date('Y-m-d H:i:s'),
  728. 'utime' => date('Y-m-d H:i:s'),
  729. 'sole' => $v['sole'],
  730. 'expire_time' => date('Y-m-d H:i:s', time() + 60)
  731. ];
  732. }
  733. //写赔率记录数据
  734. $ret = $models['model_odds_record']::insert($set_odds_r);
  735. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
  736. //写赔率 数据
  737. $ret = $models['model_odds']::insert($set_odds);
  738. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
  739. }
  740. $this->writeLog($data, Response::success());
  741. //提交事务
  742. DB::commit();
  743. return Response::success();
  744. } catch (\Exception $e) {
  745. //回滚事务
  746. DB::rollBack();
  747. $this->writeLog($data, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  748. return $e->getMessage();
  749. }
  750. }
  751. /**
  752. * @param Req $data
  753. * @return string
  754. * @throws \App\Lib\Biz\Sport\Exception
  755. * 更新赛事状态
  756. */
  757. public function upMatch($data)
  758. {
  759. try {
  760. //开启事务
  761. DB::beginTransaction();
  762. //获取待更新赛事
  763. $obt = $data['data'];
  764. //请求 数据 为空
  765. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  766. $getData = $this->getAddData($obt);
  767. //不是 直播 数据
  768. if ($getData['title'] != '"match_status",') throw new \Exception(Response::generate('不是更新赛事状态数据', Response::ABNORMAL));
  769. //写请求数据 日志记录
  770. if ($this->isRecord) {
  771. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'], $obt, $getData);
  772. if ($setSportsRecord < 1) throw new \Exception(Response::generate('', Response::SPORTS_RECORD_ERR));
  773. }
  774. //获取 球类代码
  775. $game_code = $data['game_code'];
  776. //获取 数据源
  777. $source = $data['source'];
  778. //获取所有数据源赛事 match_id
  779. $others_match_ids = [];
  780. foreach ($data['data'] as $k => $v) {
  781. $others_match_ids[] = $v['match_id'];
  782. }
  783. //根据球类代码 获取model
  784. $model = commonFunction::getModels($game_code, 1);
  785. //获取所有赛事 match_id
  786. $local_match = $model['model_local_match']::SELECT('others_match_id', 'match_id')
  787. ->where(['source' => $source])
  788. ->whereIn('others_match_id', $others_match_ids)
  789. ->get()->toArray();
  790. if (empty($local_match)) throw new \Exception(Response::generate('', Response::MATCHID_NULL));
  791. //更新状态字段
  792. foreach ($local_match as $k => $v) {
  793. $set_status = [
  794. 'status' => $v['status'],
  795. 'is_rollball' => $v['is_rollball'],
  796. 'stais_todaytus' => $v['is_today'],
  797. 'is_morningplate' => $v['is_morningplate'],
  798. 'is_stringscene' => $v['is_stringscene'],
  799. 'is_horn' => $v['is_horn'],
  800. ];
  801. $ret = $model['model_match']::where(['id' => $v['match_id']])
  802. ->update($set_status);
  803. if ($ret < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code) . '赛事-match_id:' . $v['others_match_id'], Response::UPSTATUS_ERROR));
  804. }
  805. $this->writeLog($data, Response::success());
  806. //提交事务
  807. DB::commit();
  808. return Response::success();
  809. } catch (\Exception $e) {
  810. //回滚事务
  811. DB::rollBack();
  812. $this->writeLog($data, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  813. return $e->getMessage();
  814. }
  815. }
  816. /*
  817. *写 冠军联赛 赔率 数据
  818. *每个请求 包含 N个联赛 下 N条赔率
  819. */
  820. public function setOddsCH($data)
  821. {
  822. try {
  823. //开启事务
  824. DB::beginTransaction();
  825. $obt = $data['data'];
  826. //请求 数据 为空
  827. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  828. $getData = $this->getAddData($obt);
  829. //不是 冠军 赔率 数据
  830. if ($getData['title'] != 'odds_ch') throw new \Exception(Response::generate('不是冠军赔率数据,', Response::ABNORMAL));
  831. //写请求数据 日志记录
  832. if ($this->isRecord) {
  833. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'], $obt, $getData);
  834. if ($setSportsRecord < 1) throw new \Exception(Response::generate('', Response::SPORTS_RECORD_ERR));
  835. }
  836. //获取球类代码
  837. $game_code = $getData['game_code'];
  838. //获取数据源
  839. $source = $getData['source'];
  840. //获取球类名称
  841. $gameName = gameModel::getGameName($game_code);
  842. //获取 model
  843. $models = commonFunction::getModels($game_code, 1);
  844. //获取 赔率数据
  845. $oddsData = $getData['data'];
  846. //获取 当前 所有 可用 赔率 sole
  847. $odds_only = $getData['odds_only'];
  848. //====验证 请求里 所有赔率 所属联赛 是否存在 ====
  849. //获取 当前请求 所有 联赛 uuid
  850. $uuids = [];
  851. $s_lg_ids = [];
  852. foreach ($oddsData as $k => $v) {
  853. $uuids[] = $v['uuid'];
  854. $s_lg_ids[] = $v['lg_id'];
  855. }
  856. $s_lg_ids = array_unique($s_lg_ids);
  857. $uuids = array_unique($uuids);
  858. sort($uuids);
  859. sort($s_lg_ids);
  860. //更新联赛下所有 不在本次请求的赔率 状态
  861. $ret = OddsModel::upOddsStatus($models, '', $s_lg_ids, $source, $odds_only);
  862. if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
  863. //获取 本地 已存在 联赛
  864. $l_lg_data = $models['model_local_league']::whereIn('identity', $uuids)->select('identity', 'lg_id')->get()->toArray();
  865. //二维数组去重
  866. $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
  867. //循环对比 请求uuid->本地uuid
  868. foreach ($l_lg_data as $k => $v) {
  869. foreach ($uuids as $kk => $uuid) {
  870. if ($v['identity'] == $uuid) {
  871. unset($uuids[$kk]);
  872. }
  873. }
  874. }
  875. //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常;
  876. if (!empty($uuids)) throw new \Exception(Response::generate($gameName . '冠军联赛:uuid-' . $uuids[0] . ';', Response::LEAGUE_ERROR));
  877. //====end====
  878. //赔率记录数据
  879. $set_odds_r = [];
  880. //赔率数据
  881. $set_odds = [];
  882. if (!empty($oddsData)) {
  883. foreach ($oddsData as $k => $v) {
  884. //获取 本地 联赛 ID
  885. $lg_id = commonFunction::searcharray($v['uuid'], 'identity', $l_lg_data, 'lg_id');
  886. //组装赔率记录数据
  887. $set_odds_r[] = [
  888. 'match_id' => 0,
  889. 'others_match_id' => $v['match_id'] ?: 0,
  890. 'odds_code' => $v['odds_code'] ?: '',
  891. 'status' => $v['status'] ?: 0,
  892. 'sort' => $v['sort'] ?: 0,
  893. 'p_code' => $v['p_code'] ?: '',
  894. 'odds' => $v['odds'] ?: 0,
  895. 'condition' => $v['condition'],
  896. 'odds_only' => $v['odds_only'] ?: '',
  897. 'source' => $v['source'] ?: '',
  898. 'type' => $v['type'] ?: 1,
  899. 'team' => $v['team'] ?: '',
  900. 'lg_id' => $lg_id,
  901. 'others_lg_id' => $v['lg_id'],
  902. 'ctime' => date('Y-m-d H:i:s'),
  903. 'utime' => date('Y-m-d H:i:s'),
  904. ];
  905. }
  906. foreach ($oddsData as $k => $v) {
  907. //获取 本地 联赛 ID
  908. $lg_id = commonFunction::searcharray($v['uuid'], 'identity', $l_lg_data, 'lg_id');
  909. //组装赔率数据
  910. $set_odds[] = [
  911. 'match_id' => 0,
  912. 'others_match_id' => $v['match_id'] ?: 0,
  913. 'odds_code' => $v['odds_code'] ?: '',
  914. 'status' => $v['status'] ?: 0,
  915. 'sort' => $v['sort'] ?: 0,
  916. 'p_code' => $v['p_code'] ?: '',
  917. 'odds' => $v['odds'] ?: 0,
  918. 'condition' => $v['condition'],
  919. 'odds_only' => $v['odds_only'] ?: '',
  920. 'source' => $v['source'] ?: '',
  921. 'type' => $v['type'] ?: 1,
  922. 'team' => $v['team'] ?: '',
  923. 'lg_id' => $lg_id,
  924. 'others_lg_id' => $v['lg_id'],
  925. 'ctime' => date('Y-m-d H:i:s'),
  926. 'utime' => date('Y-m-d H:i:s'),
  927. 'sole' => $v['sole'],
  928. 'expire_time' => date('Y-m-d H:i:s', time() + 60)
  929. ];
  930. }
  931. //写赔率记录数据
  932. $ret = $models['model_odds_record']::insert($set_odds_r);
  933. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
  934. //写赔率 数据
  935. $ret = $models['model_odds']::insert($set_odds);
  936. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
  937. }
  938. $this->writeLog($data, Response::success());
  939. //提交事务
  940. DB::commit();
  941. return Response::success();
  942. } catch (\Exception $e) {
  943. //回滚事务
  944. DB::rollBack();
  945. $this->writeLog($data, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  946. return $e->getMessage();
  947. }
  948. }
  949. /*
  950. * 写入直播 数据
  951. */
  952. public function setBroadCast($data)
  953. {
  954. try {
  955. //开启事务
  956. DB::beginTransaction();
  957. $obt = $data['data'];
  958. //请求 数据 为空
  959. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  960. $getData = $this->getAddData($obt);
  961. //不是 直播 数据
  962. if ($getData['title'] != 'broad_cast') throw new \Exception(Response::generate('不是直播数据,', Response::ABNORMAL));
  963. //写请求数据 日志记录
  964. if ($this->isRecord) {
  965. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'], $obt, $getData);
  966. if ($setSportsRecord < 1) throw new \Exception(Response::generate('', Response::SPORTS_RECORD_ERR));
  967. }
  968. //获取 球类
  969. $game_code = $getData['game_code'];
  970. //删除当前球类已存在的直播数据
  971. $del = broadcastModel::where('game_code', $game_code)->delete();
  972. if ($del != true) throw new \Exception(Response::generate('', Response::DEL_PAST_BROADCAST_ERR));
  973. //获取 直播 数据
  974. $BroadCast = $getData['data'];
  975. $set_broadcast = [];
  976. foreach ($BroadCast as $k => $data) {
  977. //组装数据
  978. $set_broadcast[] = [
  979. "doing" => $data['doing'],
  980. "game_type" => $data['game_type'],
  981. "game_code" => $game_code,
  982. "guest_team" => $data['guest_team'],
  983. "host_team" => $data['host_team'],
  984. "league_name" => $data['league_name'],
  985. "shower" => $data['shower'],
  986. "showid" => (int)$data['showid'],
  987. "start_time" => $data['start_time'],
  988. "ctime" => date('Y-m-d H:i:s'),
  989. "utime" => date('Y-m-d H:i:s'),
  990. ];
  991. }
  992. //写入 直播 数据
  993. $ret = broadcastModel::insert($set_broadcast);
  994. if ($ret == false) throw new \Exception(Response::generate('', Response::BROADCAST_ERROR));
  995. $this->writeLog($data, Response::success());
  996. //提交事务
  997. DB::commit();
  998. return Response::success();
  999. } catch (\Exception $e) {
  1000. //回滚事务
  1001. DB::rollBack();
  1002. $this->writeLog($data, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  1003. return $e->getMessage();
  1004. }
  1005. }
  1006. /*
  1007. * 验证所属 联赛 是否存在
  1008. */
  1009. public function leagueVerify($models = [], $uuid = '', $source = '', $gameName = '')
  1010. {
  1011. if (empty($models) || empty($uuid)) throw new \Exception(Response::generate('', Response::ABNORMAL));
  1012. $l_lg_id = $models['model_local_league']::where(['identity' => $uuid])->value('lg_id');
  1013. if ($l_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛:lg_id-' . $uuid, Response::LEAGUE_ERROR));
  1014. return $l_lg_id;
  1015. }
  1016. /*
  1017. * 验证所属 赛事 是否存在
  1018. */
  1019. public function matchVerify($models = [], $s_match_id = '', $source = '', $gameName = '')
  1020. {
  1021. if (empty($models) || empty($s_match_id)) throw new \Exception(Response::generate('', Response::ABNORMAL));
  1022. $l_match_id = $models['model_local_match']::where(['others_match_id' => $s_match_id, 'source' => $source])->value('match_id');
  1023. if ($l_match_id < 1) throw new \Exception(Response::generate($gameName . '赛事:match_id-' . $s_match_id, Response::MATCH_ERROR));
  1024. return $l_match_id;
  1025. }
  1026. /*
  1027. * 写入直播 数据
  1028. */
  1029. public function broadcast($opt = [], $game_code = '')
  1030. {
  1031. $data = $opt['data'];
  1032. $set_broadcast = [
  1033. "doing" => $data['doing'],
  1034. "game_type" => $data['game_type'],
  1035. "game_code" => $game_code,
  1036. "guest_team" => $data['guest_team'],
  1037. "host_team" => $data['host_team'],
  1038. "league_name" => $data['league_name'],
  1039. "shower" => $data['shower'],
  1040. "showid" => (int)$data['showid'],
  1041. "start_time" => $data['start_time'],
  1042. "ctime" => date('Y-m-d H:i:s'),
  1043. "utime" => date('Y-m-d H:i:s'),
  1044. ];
  1045. $ret = broadcastModel::insert($set_broadcast);
  1046. if ($ret == false) throw new \Exception(Response::generate('', Response::BROADCAST_ERROR));
  1047. }
  1048. /*
  1049. * 写入 赛事 初始 结果
  1050. */
  1051. public function match_result($game_code = '')
  1052. {
  1053. $model = commonFunction::getModels($game_code, 1);
  1054. if ($game_code == 'zq') ZqResultModel::ZQresult($model);
  1055. if ($game_code == 'lq') LqResultModel::LQresult($model);
  1056. if ($game_code == 'wq') WqResultModel::WQresult($model);
  1057. if ($game_code == 'bq') BqResultModel::BQresult($model);
  1058. }
  1059. /*
  1060. * 写入联赛数据
  1061. */
  1062. public function league($opt = [], $gameName = '')
  1063. {
  1064. $game_code = $opt['game_code'];
  1065. //根据球类代码获取相关model
  1066. $model = commonFunction::getModels($game_code, 1);
  1067. $data = $opt['data'];
  1068. //查询联赛是否已存在
  1069. $id = $model['model_league']::where('name_chinese', '=', $data['name_chinese'])
  1070. ->value('id');
  1071. //默认获取本年最后一天
  1072. $last_time = date('Y-12-31 23:59:59');
  1073. //决赛时间
  1074. if ($data['last_time']) {
  1075. $last_time = $data['last_time'];
  1076. }
  1077. $set_lg['name_chinese'] = $data['name_chinese'];
  1078. $set_lg['kind'] = $data['kind'];
  1079. $set_lg['match_mode'] = $data['match_mode'];
  1080. $set_lg['if_stop'] = $data['if_stop'];
  1081. $set_lg['identity'] = $data['uuid'] ?: '';
  1082. $set_lg['last_time'] = $last_time;
  1083. $set_lg['utime'] = date('Y-m-d H:i:s');
  1084. if (empty($id)) {
  1085. //写入联赛
  1086. $id = $model['model_league']::insertGetId($set_lg);
  1087. $m_lg_id = $id;
  1088. if ($m_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::INSERT_ERROR));
  1089. } else {
  1090. //更新联赛
  1091. $ret = $model['model_league']::where(['id' => $id])
  1092. ->update($set_lg);
  1093. if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::UPDATE_ERROR));
  1094. }
  1095. $set_local = [
  1096. 'lg_id' => $id,
  1097. 'others_lg_id' => $data['lg_id'],
  1098. 'source' => $data['source'],
  1099. 'ctime' => date('Y-m-d H:i:s')
  1100. ];
  1101. $ret = $model['model_local_league']::insertGetId($set_local);
  1102. 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'));
  1103. //执行成功返回源数据 联赛ID
  1104. $data = ['others_lg_id' => $data['lg_id'], 'lg_id' => $id];
  1105. return $data;
  1106. }
  1107. /*
  1108. * 写入赛事数据
  1109. */
  1110. public function competition($opt = [], $gameName = '', $lg_id = '')
  1111. {
  1112. $game_code = $opt['game_code'];
  1113. //根据球类代码获取相关model
  1114. $model = commonFunction::getModels($game_code, 1);
  1115. $data = $opt['data'];
  1116. if (empty($data['lg_id'])) throw new \Exception(Response::generate('', Response::LEAGUE_ERROR));//Render([], '10015', lang('Tips','Sports')->get('league_error'));
  1117. //查询赛事是否存在
  1118. $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']])
  1119. ->value('id');
  1120. $half_match_id = 0;
  1121. //如果有上半场赛事id 获取上半场赛事是否存在
  1122. if (!empty($data['half_match_id'])) {
  1123. $half_match_id = $match_id = $model['model_local_match']::where(['others_match_id' => $data['half_match_id'], 'source' => $data['source']])
  1124. ->value('match_id');
  1125. 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'));
  1126. }
  1127. //如果赛事没有开始日期,则为冠军盘口赛事
  1128. if (empty($data['match_date'])) {
  1129. //冠军盘口赛事获取所属联赛结束时间
  1130. $last_time = $model['model_league']::where(['id' => $lg_id])
  1131. ->value('last_time');
  1132. 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'));
  1133. //给冠军盘口赛事 赋值时间
  1134. $time = strtotime($last_time);
  1135. $data['match_date'] = date('Y-m-d', $time);
  1136. $data['match_time'] = date('H:i:s', $time);
  1137. }
  1138. $set_match = [
  1139. 'ctime' => date('Y-m-d H:i:s'),
  1140. 'utime' => date('Y-m-d H:i:s'),
  1141. 'expire_time' => date('Y-m-d H:i:s', time() + 60),
  1142. 'home_team' => $data['home_team'] ?: '',
  1143. 'guest_team' => $data['guest_team'] ?: 'no_team',
  1144. 'lg_id' => $lg_id,
  1145. 'status' => $data['status'],
  1146. 'match_date' => $data['match_date'] ?: date('Y-m-d'),
  1147. 'match_time' => $data['match_time'] ?: date('H:i:s'),
  1148. 'tag' => $data['tag'] ?: 0,
  1149. 'is_rollball' => $data['is_rollball'] ?: 0,
  1150. 'is_today' => $data['is_today'] ?: 0,
  1151. 'is_morningplate' => $data['is_morningplate'] ?: 0,
  1152. 'is_stringscene' => $data['is_stringscene'] ?: 0,
  1153. 'us_time' => $data['us_time'] ?: commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
  1154. 'half_match_id' => $half_match_id ?: 0,
  1155. 'identity' => $data['uuid'],
  1156. ];
  1157. //写入赛事
  1158. if (empty($id)) {
  1159. //写入赛事 返回id
  1160. $id = $model['model_match']::insertGetId($set_match);
  1161. if ($id < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::INSERT_ERROR));
  1162. } else {
  1163. //更新赛事
  1164. $ret = $model['model_match']::where(['id' => $id])->update($set_match);
  1165. if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::UPDATE_ERROR));
  1166. }
  1167. //写关联记录
  1168. $set_local = [
  1169. 'match_id' => $id,
  1170. 'others_match_id' => $data['match_id'],
  1171. 'source' => $data['source'],
  1172. 'ctime' => date('Y-m-d H:i:s')
  1173. ];
  1174. $ret = $model['model_local_match']::insertGetId($set_local);
  1175. 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'));
  1176. //返回 源数据 赛事ID
  1177. $data = ['others_match_id' => $data['match_id'], 'match_id' => $id];
  1178. return $data;
  1179. }
  1180. /*
  1181. * 写入赔率/赔率记录数据
  1182. */
  1183. public function odds($opt = [], $gameName = '', $lg_id = 0, $match_id = 0, $oddsID = '', $oddsRecordID = '')
  1184. {
  1185. $game_code = $opt['game_code'];
  1186. //根据球类代码获取相关model
  1187. $model = commonFunction::getModels($game_code, 1);
  1188. $data = $opt['data'];
  1189. //获取赛事 本地/源ID
  1190. $others_match_id = $data['match_id'];
  1191. //获取联赛 本地/源ID
  1192. $others_lg_id = $data['lg_id'];
  1193. //===写赔率记录===
  1194. $set_odds_r = [
  1195. 'match_id' => $match_id ?: 0,
  1196. 'others_match_id' => $others_match_id ?: 0,
  1197. 'odds_code' => $data['odds_code'] ?: '',
  1198. 'status' => $data['status'] ?: 0,
  1199. 'sort' => $data['sort'] ?: 0,
  1200. 'p_code' => $data['p_code'] ?: '',
  1201. 'odds' => $data['odds'] ?: 0,
  1202. 'condition' => $data['condition'],
  1203. 'odds_only' => $data['odds_only'] ?: '',
  1204. 'source' => $data['source'] ?: '',
  1205. 'type' => $data['type'] ?: 0,
  1206. 'team' => $data['team'] ?: '',
  1207. 'lg_id' => $lg_id,
  1208. 'others_lg_id' => $others_lg_id,
  1209. 'ctime' => date('Y-m-d H:i:s'),
  1210. ];
  1211. //更新或写入赔率记录
  1212. if ($oddsRecordID != false) {
  1213. $ret = $model['model_odds_record']::where(['id' => $oddsRecordID])
  1214. ->update($set_odds_r);
  1215. 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'));
  1216. } else {
  1217. $ret = $model['model_odds_record']::insert($set_odds_r);
  1218. 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'));
  1219. }
  1220. //===写赔率===
  1221. $set_odds = [
  1222. 'match_id' => $match_id ?: 0,
  1223. 'others_match_id' => $others_match_id ?: 0,
  1224. 'odds_code' => $data['odds_code'] ?: '',
  1225. 'status' => $data['status'] ?: 0,
  1226. 'sort' => $data['sort'] ?: 0,
  1227. 'p_code' => $data['p_code'] ?: '',
  1228. 'odds' => $data['odds'] ?: 0,
  1229. 'condition' => $data['condition'],
  1230. 'odds_only' => $data['odds_only'] ?: '',
  1231. 'sole' => $data['sole'] ?: '',
  1232. 'source' => $data['source'] ?: '',
  1233. 'type' => $data['type'] ?: 0,
  1234. 'team' => $data['team'] ?: '',
  1235. 'lg_id' => $lg_id,
  1236. 'others_lg_id' => $others_lg_id,
  1237. 'ctime' => date('Y-m-d H:i:s'),
  1238. 'utime' => date('Y-m-d H:i:s'),
  1239. 'expire_time' => date('Y-m-d H:i:s', time() + 60),
  1240. ];
  1241. //更新或写入赔率数据
  1242. if ($oddsID != false) {
  1243. $ret = $model['model_odds']::where(['id' => $oddsID])
  1244. ->update($set_odds);
  1245. 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'));
  1246. } else {
  1247. $ret = $model['model_odds']::insert($set_odds);
  1248. 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'));
  1249. }
  1250. //===end===
  1251. }
  1252. /*
  1253. * 更新 赛事下 所有不在本次请求的 赔率状态
  1254. */
  1255. public function upOddsStatus($opt = [], $gameName = '')
  1256. {
  1257. //获取球类代码
  1258. $game_code = $opt['game_code'];
  1259. //获取球类model
  1260. $model = commonFunction::getModels($game_code, 1);
  1261. //赛事下 所有 赔率sole
  1262. $odds_sole = $opt['data'];
  1263. //数据源 赛事 id
  1264. $others_match_id = $opt['match_id'];
  1265. //数据源
  1266. $source = $opt['source'];
  1267. //更新赛事下所有 不在本次请求的赔率 状态
  1268. $ret = OddsModel::getMatchSole($model, $others_match_id, '', $source, $odds_sole);
  1269. if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
  1270. }
  1271. /*
  1272. * 写入联赛结果
  1273. */
  1274. public function league_result($opt, $gameName)
  1275. {
  1276. $game_code = $opt['game_code'];
  1277. //根据球类代码获取相关model
  1278. $model = commonFunction::getModels($game_code, 1);
  1279. $data = $opt['data'];
  1280. //验证结果所属联赛
  1281. $lg_id = $model['model_local_league']::where(['others_lg_id' => $data['lg_id'], 'source' => $data['source']])
  1282. ->value('lg_id');
  1283. if ($lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LEAGUE_ERROR));
  1284. $lg_result_id = $model['model_league_result']::where(['lg_id' => $lg_id, 'game_name' => $data['game_name']])
  1285. ->value('id');
  1286. $set_lg_result = [
  1287. 'lg_id' => $lg_id,
  1288. 'game_name' => $data['game_name'],
  1289. 'result' => json_encode($data['result'], JSON_UNESCAPED_UNICODE),
  1290. 'status' => $data['status'],
  1291. 'ctime' => date('Y-m-d H:i:s'),
  1292. 'utime' => date('Y-m-d H:i:s'),
  1293. ];
  1294. //联赛结果数据处理
  1295. if (!empty($lg_result_id)) {
  1296. $ret = $model['model_league_result']::where(['id' => $lg_result_id])
  1297. ->update($set_lg_result);
  1298. 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'));
  1299. } else {
  1300. $ret = $model['model_league_result']::insert($set_lg_result);
  1301. 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'));
  1302. }
  1303. }
  1304. /*
  1305. * 写入赛事结果
  1306. */
  1307. public function com_result($opt = [], $gameName = '', $lg_id = '', $match_id = '')
  1308. {
  1309. $game_code = $opt['game_code'];
  1310. //根据球类代码获取相关model
  1311. $model = commonFunction::getModels($game_code, 1);
  1312. $data = $opt['data'];
  1313. //查询结果是否存在
  1314. $match_r_id = $model['model_result']::where(['match_id' => $match_id])
  1315. ->value('id');
  1316. $set_match_r = [
  1317. "home_team" => $data['home_team'],
  1318. "guest_team" => $data['guest_team'],
  1319. "lg_id" => $lg_id,
  1320. "home_rate" => $data['home_rate'],
  1321. "guest_rate" => $data['guest_rate'],
  1322. "home_score" => $data['home_score'],
  1323. "guest_score" => $data['guest_score'],
  1324. "all_goal" => $data['all_goal'],
  1325. "status" => $data['status'],
  1326. "first_score" => $data['first_score'],
  1327. "last_score" => $data['last_score'],
  1328. "match_score" => $data['match_score'],
  1329. "match_winer" => $data['match_winer'],
  1330. "match_time" => $data['match_time'],
  1331. "match_process" => $data['match_process'],
  1332. "tag" => $data['tag'],
  1333. "match_id" => $match_id,
  1334. "u_home_score" => $data['u_home_score'],
  1335. "u_guest_score" => $data['u_guest_score'],
  1336. "p_code" => $data['p_code'],
  1337. "update_time" => date('Y-m-d H:i:s')
  1338. ];
  1339. //赛事结果数据处理
  1340. if (!empty($match_r_id)) {
  1341. $ret = $model['model_result']::where(['id' => $match_r_id])
  1342. ->update($set_match_r);
  1343. 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'));
  1344. } else {
  1345. $ret = $model['model_result']::insert($set_match_r);
  1346. 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'));
  1347. }
  1348. // return Response::success();
  1349. }
  1350. //写入赛事结果记录
  1351. public function com_result_record($opt = [], $gameName = '', $lg_id = '', $match_id = '')
  1352. {
  1353. $game_code = $opt['game_code'];
  1354. //根据球类代码获取相关model
  1355. $model = commonFunction::getModels($game_code, 1);
  1356. $data = $opt['data'];
  1357. $match_r_id = $model['model_result_record']::where(['match_id' => $match_id, 'match_time' => $data['match_time']])
  1358. ->value('id');
  1359. //根据球类 获取 赛事结果记录字段
  1360. $set_match_r = $this->get_match_r($game_code, $lg_id, $match_id, $data);
  1361. //赛事结果记录处理
  1362. if ($match_r_id > 0) {
  1363. $ret = $model['model_result_record']::where(['id' => $match_r_id])
  1364. ->update($set_match_r);
  1365. 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'));
  1366. } else {
  1367. $ret = $model['model_result_record']::insert($set_match_r);
  1368. 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'));
  1369. }
  1370. }
  1371. /**
  1372. * @param $data
  1373. * @return mixed
  1374. * json转数组
  1375. */
  1376. public function getAddData($data)
  1377. {
  1378. $data = json_decode($data, true);
  1379. return $data;
  1380. }
  1381. /*
  1382. * 根据球类获取 赛事结果记录字段
  1383. */
  1384. public function get_match_r($game_code, $lg_id, $match_id, $data)
  1385. {
  1386. $set_match_r = [];
  1387. if ($game_code == 'zq') {
  1388. $set_match_r = [
  1389. "home_team" => $data['home_team'] ?: '',
  1390. "guest_team" => $data['guest_team'] ?: '',
  1391. "lg_id" => $lg_id,
  1392. "all_goal" => $data['all_goal'] ?: 0,
  1393. "home_rate" => $data['home_rate'] ?: 0,
  1394. "guest_rate" => $data['guest_rate'] ?: 0,
  1395. "home_score" => $data['home_score'] ?: 0,
  1396. "guest_score" => $data['guest_score'] ?: 0,
  1397. "status" => $data['status'] ?: 0,
  1398. "first_score" => $data['first_score'] ?: 0,
  1399. "last_score" => $data['last_score'] ?: 0,
  1400. "match_score" => $data['match_score'] ?: 0,
  1401. "match_winer" => $data['match_winer'] ?: '',
  1402. "match_time" => $data['match_time'] ?: 0,
  1403. "match_process" => $data['match_process'] ?: '',
  1404. //"tag" => $data['tag'] ?: 0,
  1405. "match_id" => $match_id,
  1406. "update_time" => date('Y-m-d H:i:s')
  1407. ];
  1408. };
  1409. if ($game_code == 'lq') {
  1410. $set_match_r = [
  1411. "home_team" => $data['home_team'] ?: '',
  1412. "guest_team" => $data['guest_team'] ?: '',
  1413. "lg_id" => $lg_id,
  1414. "home_rate" => $data['home_rate'] ?: 0,
  1415. "guest_rate" => $data['guest_rate'] ?: 0,
  1416. "home_score" => $data['home_score'] ?: 0,
  1417. "guest_score" => $data['guest_score'] ?: 0,
  1418. "status" => $data['status'] ?: 0,
  1419. "first_score" => $data['first_score'] ?: 0,
  1420. "last_score" => $data['last_score'] ?: 0,
  1421. "match_score" => $data['match_score'] ?: 0,
  1422. "match_winer" => $data['match_winer'] ?: '',
  1423. "match_time" => $data['match_time'] ?: 0,
  1424. "match_process" => $data['match_process'] ?: '',
  1425. //"tag" => $data['tag'] ?: 0,
  1426. "match_id" => $match_id,
  1427. "update_time" => date('Y-m-d H:i:s'),
  1428. "result_mark" => json_encode($data['result_mark']) ?: '',
  1429. ];
  1430. }
  1431. if ($game_code == 'wq') {
  1432. $set_match_r = [
  1433. "home_player_name" => $data['home_player_name'] ?: '',
  1434. "guest_player_name" => $data['guest_player_name'] ?: '',
  1435. "lg_id" => $lg_id,
  1436. "home_player_let_plate" => $data['home_player_let_plate'] ?: 0,
  1437. "guest_player_let_plate" => $data['guest_player_let_plate'] ?: 0,
  1438. "home_player_let_inning" => $data['home_player_let_inning'] ?: 0,
  1439. "guest_player_let_inning" => $data['guest_player_let_inning'] ?: 0,
  1440. "all_inning" => $data['all_inning'] ?: 0,
  1441. "home_player_score" => $data['home_player_score'] ?: 0,
  1442. "guest_player_score" => $data['guest_player_score'] ?: 0,
  1443. "status" => $data['status'] ?: 0,
  1444. "first_score_player" => $data['first_score_player'] ?: '',
  1445. "last_score_player" => $data['last_score_player'] ?: '',
  1446. "first_inning_score" => $data['first_inning_score'] ?: 0,
  1447. "second_inning_score" => $data['second_inning_score'] ?: 0,
  1448. "third_inning_score" => $data['third_inning_score'] ?: 0,
  1449. "match_winer_player" => $data['match_winer_player'] ?: '',
  1450. "update_time" => date('Y-m-d H:i:s'),
  1451. "match_time" => $data['match_time'] ?: 0,
  1452. "match_process" => $data['match_process'] ?: '',
  1453. //"tag" => $data['tag'] ?: 0,
  1454. "match_id" => $match_id,
  1455. "result_mark" => $data['result_mark'] ?: '',
  1456. ];
  1457. }
  1458. if ($game_code == 'bq') {
  1459. $set_match_r = [
  1460. "home_team" => $data['home_team'] ?: '',
  1461. "guest_team" => $data['guest_team'] ?: '',
  1462. "lg_id" => $lg_id,
  1463. "home_rate" => $data['home_rate'] ?: 0,
  1464. "guest_rate" => $data['guest_rate'] ?: 0,
  1465. "home_score" => $data['home_score'] ?: 0,
  1466. "guest_score" => $data['guest_score'] ?: 0,
  1467. "status" => $data['status'] ?: 0,
  1468. "first_score" => $data['first_score'] ?: 0,
  1469. "last_score" => $data['last_score'] ?: 0,
  1470. "match_score" => $data['match_score'] ?: 0,
  1471. "match_winer" => $data['match_winer'] ?: '',
  1472. "match_time" => $data['match_time'] ?: 0,
  1473. "match_process" => $data['match_process'] ?: '',
  1474. //"tag" => $data['tag'] ?: 0,
  1475. "match_id" => $match_id,
  1476. "all_inning" => $data['all_inning'] ?: 9,
  1477. "update_time" => date('Y-m-d H:i:s'),
  1478. "result_mark" => $data['result_mark'] ?: '',
  1479. ];
  1480. }
  1481. return $set_match_r;
  1482. }
  1483. /**
  1484. * 根据联赛名称 获取 国家 地区
  1485. */
  1486. public function getArea($leagueName = '')
  1487. {
  1488. //如果联赛名称有括号,去除
  1489. $leagueName = preg_replace('/\(.*?\)/', '', $leagueName);
  1490. //获取所有国家/地区
  1491. $areaData = StAreaCountryModel::select('id', 'pid', 'name')->get()->toArray();
  1492. //获取当前联赛所属国家
  1493. if (strpos($leagueName, 'NBA') !== false) {
  1494. $data = [
  1495. 'id' => 247,
  1496. 'pid' => 0,
  1497. 'name' => '世界'
  1498. ];
  1499. return $data;
  1500. }
  1501. //识别本地 国家地区数据
  1502. foreach ($areaData as $v => $k) {
  1503. if (strpos($leagueName, $k['name']) !== false) {
  1504. return $k;
  1505. }
  1506. }
  1507. //如果不能识别,则返回未知
  1508. $data = [
  1509. 'id' => 0,
  1510. 'pid' => 0,
  1511. 'name' => '未知国家或地区'
  1512. ];
  1513. return $data;
  1514. }
  1515. private function writeLog($body, $ret)
  1516. {
  1517. if (!is_string($body)) {
  1518. $body = json_encode([$body], 256);
  1519. }
  1520. if (!is_string($ret)) {
  1521. $ret = json_encode([$ret], 256);
  1522. }
  1523. $data = ['ctime' => date("Y-m-d H:i:s"), 'body' => $body, 'ret' => $ret];
  1524. $return = DB::table('datainf_log')->insert($data);
  1525. return $return;
  1526. }
  1527. }