WriteSportsController.php 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533
  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. foreach ($local_match as $k => $v) {
  1581. $set_status = [
  1582. 'status' => $v['status'],
  1583. 'is_rollball' => $v['is_rollball'],
  1584. 'is_today' => $v['is_today'],
  1585. 'is_morningplate' => $v['is_morningplate'],
  1586. 'is_stringscene' => $v['is_stringscene'],
  1587. 'is_horn' => $v['is_horn'],
  1588. 'utime' => date('Y-m-d H:i:s'),
  1589. ];
  1590. $ret = $model['model_match']::where(['id' => $v['match_id']])
  1591. ->update($set_status);
  1592. if ($ret < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code) . '赛事-match_id:' . $v['others_match_id'], Response::UPSTATUS_ERROR));
  1593. }
  1594. //提交事务
  1595. DB::commit();
  1596. //写请求数据 日志记录
  1597. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $data, $data['title'], Response::success());
  1598. return Response::success();
  1599. } catch (\Exception $e) {
  1600. //回滚事务
  1601. DB::rollBack();
  1602. //写请求数据 日志记录
  1603. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $data, $data['title'], $e->getMessage());
  1604. return $e->getMessage();
  1605. }
  1606. }
  1607. /*
  1608. * 验证所属 联赛 是否存在
  1609. */
  1610. public function leagueVerify($models = [], $uuid = '', $source = '', $gameName = '')
  1611. {
  1612. if (empty($models) || empty($uuid)) throw new \Exception(Response::generate('', Response::ABNORMAL));
  1613. $l_lg_id = $models['model_local_league']::where(['identity' => $uuid])->value('lg_id');
  1614. if ($l_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛:lg_id-' . $uuid, Response::LEAGUE_ERROR));
  1615. return $l_lg_id;
  1616. }
  1617. /*
  1618. * 验证所属 赛事 是否存在
  1619. */
  1620. public function matchVerify_v2($models = [], $match_identity = '', $source = '', $gameName = '')
  1621. {
  1622. if (empty($models) || empty($match_identity)) throw new \Exception(Response::generate('', Response::ABNORMAL));
  1623. $l_match_id = $models['model_local_match']::where(['identity' => $match_identity, 'source' => $source])->value('match_id');
  1624. if ($l_match_id < 1) throw new \Exception(Response::generate($gameName . 'match_identity-' . $match_identity, Response::MATCH_ERROR));
  1625. return $l_match_id;
  1626. }
  1627. public function matchVerify($models = [], $s_match_id = '', $source = '', $gameName = '')
  1628. {
  1629. if (empty($models) || empty($s_match_id)) throw new \Exception(Response::generate('', Response::ABNORMAL));
  1630. $l_match_id = $models['model_local_match']::where(['others_match_id' => $s_match_id, 'source' => $source])->value('match_id');
  1631. if ($l_match_id < 1) throw new \Exception(Response::generate($gameName . '赛事:match_id-' . $s_match_id, Response::MATCH_ERROR));
  1632. return $l_match_id;
  1633. }
  1634. /*
  1635. * 写入数据 接口
  1636. */
  1637. public function setSports(Req $data)
  1638. {
  1639. try {
  1640. //开启事务
  1641. DB::beginTransaction();
  1642. if ($data->game_code) {
  1643. //用于后台 将所有进行中的赛事写入结果
  1644. $this->match_result($data->game_code);
  1645. } else {
  1646. //验证token
  1647. $dd = $data->session()->get('adminInfo');
  1648. if (empty($data->token) || ($dd['token'] != $data->token)) return Response::generate('', Response::TOKEN_ERR);
  1649. //写赛事数据
  1650. $obt = $data->data;
  1651. if ($obt) {
  1652. $getData = $this->getAddData($obt);
  1653. $league = [];
  1654. $competition = [];
  1655. $odds = [];
  1656. $odds_soly = [];
  1657. $league_result = [];
  1658. $match_result = [];
  1659. $match_result_record = [];
  1660. $odds_record = [];
  1661. $broadcast = [];
  1662. //指定排序 联赛->赛事->赔率->联赛结果->赛事结果->赛事结果记录->赔率记录->直播数据
  1663. foreach ($getData as $k => $v) {
  1664. $game_code = $v['game_code'];
  1665. if ($v['title'] == 'league') $league[] = $v;
  1666. if ($v['title'] == 'competition') $competition[] = $v;
  1667. if ($v['title'] == 'odds') $odds[] = $v;
  1668. if ($v['title'] == 'odds_sole') $odds_soly[] = $v;
  1669. if ($v['title'] == 'league_result') $league_result[] = $v;
  1670. if ($v['title'] == 'match_result') $match_result[] = $v;
  1671. if ($v['title'] == 'match_result_record') $match_result_record[] = $v;
  1672. if ($v['title'] == 'odds_record') $odds_record[] = $v;
  1673. if ($v['title'] == 'broadcast') $broadcast[] = $v;
  1674. }
  1675. $matchData = [$league, $competition, $odds_soly, $odds, $league_result, $match_result, $match_result_record, $odds_record, $broadcast];
  1676. //排空处理
  1677. foreach ($matchData as $k => $v) {
  1678. if ($v == []) unset($matchData[$k]);
  1679. }
  1680. sort($matchData);
  1681. //根据顺序写入数据
  1682. //降维数据
  1683. $mentData = [];
  1684. foreach ($matchData as $k => $v) {
  1685. foreach ($v as $kk => $vv) {
  1686. $mentData[] = $vv;
  1687. }
  1688. }
  1689. //获取各球类model
  1690. $models = commonFunction::getModels($game_code, 1);
  1691. //获取球类名称
  1692. $gameName = gameModel::getGameName($game_code);
  1693. //===获取验证数据===
  1694. //获取一段时间内所有联赛本地记录
  1695. $lg_data = LeagueModel::getLeagueID($models);
  1696. //获取一段时间内所有赛事本地记录
  1697. $match_data = MatchModel::getMatchID($models);
  1698. //获取一段时间内所有赔率
  1699. $odds_data = OddsModel::getOddsID($models);
  1700. //获取一段时间内所有赔率记录
  1701. $odds_record_data = OddsRecordModel::getOddsRecordID($models);
  1702. //===获取验证数据===
  1703. $others_lg_id = '';//继承 源联赛id
  1704. $others_match_id = '';//继承 源赛事id
  1705. $s_lg_id = '';//源 联赛ID
  1706. $l_lg_id = '';//本地 联赛 ID
  1707. $s_match_id = '';//源 赛事ID
  1708. $l_match_id = '';//本地 赛事 ID
  1709. foreach ($mentData as $kk => $vv) {
  1710. switch ($vv['title']) {
  1711. case 'area'://地区
  1712. throw new \Exception(Response::generate('地区数据-area:', Response::AUTH_ERROR));
  1713. break;
  1714. case 'country'://国家
  1715. throw new \Exception(Response::generate('国家数据-country:', Response::AUTH_ERROR));
  1716. break;
  1717. case 'league'://联赛
  1718. $others_lg_id = $vv['data']['lg_id'];
  1719. $s_lg_id = $vv['data']['lg_id'];
  1720. $source = $vv['data']['source'];
  1721. //验证联赛记录是否已存在
  1722. $ret_lg = commonFunction::ver_league($s_lg_id, $source, $lg_data);
  1723. if ($ret_lg != false) {
  1724. $l_lg_id = $ret_lg;
  1725. break;
  1726. }
  1727. //执行 联赛数据
  1728. $lg_data = $this->league($vv, $gameName);
  1729. $l_lg_id = $lg_data['lg_id'];
  1730. break;
  1731. case 'competition'://赛事
  1732. $others_match_id = $vv['data']['match_id'];
  1733. $s_lg_id = $vv['data']['lg_id'];
  1734. $s_match_id = $vv['data']['match_id'];
  1735. $source = $vv['data']['source'];
  1736. //本次请求是否包含 联赛数据
  1737. if (empty($others_lg_id)) {
  1738. //验证本地是否存在
  1739. $ret_lg = commonFunction::ver_league($s_lg_id, $source, $lg_data);
  1740. if ($ret_lg == false) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
  1741. $l_lg_id = $ret_lg;
  1742. } else {
  1743. //本次有 联赛数据 验证属于同联赛
  1744. if ($s_lg_id != $others_lg_id) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
  1745. }
  1746. //验证赛事记录是否已存在
  1747. $ret_match = commonFunction::ver_match($s_match_id, $source, $match_data);
  1748. if ($ret_match != false) {
  1749. $l_match_id = $ret_match;
  1750. break;
  1751. }
  1752. //执行 赛事数据
  1753. $match_data = $this->competition($vv, $gameName, $l_lg_id);
  1754. $l_match_id = $match_data['match_id'];
  1755. break;
  1756. case 'odds'://赔率
  1757. $s_lg_id = $vv['data']['lg_id'];
  1758. $s_match_id = $vv['data']['match_id'];
  1759. $source = $vv['data']['source'];
  1760. $odds_only = $vv['data']['odds_only'];
  1761. $sole = $vv['data']['sole'];
  1762. $odds_type = $vv['data']['type'];//0普通 1冠军盘口
  1763. //本次请求是否包含 联赛数据
  1764. if (empty($others_lg_id)) {
  1765. //无联赛数据 验证本地是否存在
  1766. $ret_lg = commonFunction::ver_league($s_lg_id, $source, $lg_data);
  1767. //联赛 不存在
  1768. if ($ret_lg == false) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
  1769. $l_lg_id = $ret_lg;
  1770. } else {
  1771. //有联赛数据 验证属于同请求联赛
  1772. if ($s_lg_id != $others_lg_id) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
  1773. }
  1774. //如果是普通 赔率,则验证所属赛事
  1775. if ($odds_type == 0) {
  1776. //验证赛事记录是否已存在
  1777. if (empty($others_match_id)) {
  1778. //无赛事数据 验证本地是否存在
  1779. $ret_match = commonFunction::ver_match($s_match_id, $source, $match_data);
  1780. //赛事 不存在
  1781. if ($ret_match == false) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::MATCH_ERROR));
  1782. $l_match_id = $ret_match;
  1783. } else {
  1784. //有赛事数据 验证属于同请求赛事
  1785. if ($s_match_id != $others_match_id) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::MATCH_ERROR));
  1786. }
  1787. }
  1788. //验证赔率 是否存在
  1789. $ret_odds = '';
  1790. $ret_odds = commonFunction::ver_odds($sole, $source, $odds_data);
  1791. //验证赔率记录 是否存在
  1792. $ret_odds_record = '';
  1793. $ret_odds_record = commonFunction::ver_odds_record($odds_only, $source, $odds_record_data);
  1794. $this->odds($vv, $gameName, $l_lg_id, $l_match_id, $ret_odds, $ret_odds_record);
  1795. break;
  1796. case 'odds_sole':
  1797. $this->upOddsStatus($vv, $gameName);
  1798. break;
  1799. case 'league_result'://联赛结果
  1800. $this->league_result($vv, $gameName);
  1801. break;
  1802. case 'match_result'://赛事结果
  1803. throw new \Exception(Response::generate('赛事结果数据-match_result:', Response::AUTH_ERROR));
  1804. $this->match_result($vv, $gameName);
  1805. break;
  1806. case 'match_result_record'://赛事结果记录
  1807. $s_lg_id = $vv['data']['lg_id'];
  1808. $s_match_id = $vv['data']['match_id'];
  1809. $source = $vv['data']['source'];
  1810. //如果本次请求没有 联赛数据
  1811. if (empty($others_lg_id)) {
  1812. //验证本地是否存在
  1813. $ret_lg = commonFunction::ver_league($s_lg_id, $source, $lg_data);
  1814. //联赛 不存在
  1815. if ($ret_lg == false) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
  1816. $l_lg_id = $ret_lg;
  1817. } else {
  1818. //有联赛数据 验证属于同请求联赛
  1819. if ($s_lg_id != $others_lg_id) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $s_lg_id . ';', Response::LEAGUE_ERROR));
  1820. }
  1821. //验证赛事记录是否已存在
  1822. if (empty($others_match_id)) {
  1823. //无赛事数据 验证本地是否存在
  1824. $ret_match = commonFunction::ver_match($s_match_id, $source, $match_data);
  1825. //联赛 不存在
  1826. if ($ret_match == false) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::MATCH_ERROR));
  1827. $l_match_id = $ret_match;
  1828. } else {
  1829. //有赛事数据 验证属于同请求赛事
  1830. if ($s_match_id != $others_match_id) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::MATCH_ERROR));
  1831. }
  1832. //处理 赛事结果 记录
  1833. $this->com_result_record($vv, $gameName, $l_lg_id, $l_match_id);
  1834. break;
  1835. case 'broadcast'://直播数据
  1836. $this->broadcast($vv, $game_code);
  1837. break;
  1838. default:
  1839. throw new \Exception(Response::generate('', Response::ABNORMAL));
  1840. }
  1841. }
  1842. }
  1843. }
  1844. //提交事务
  1845. DB::commit();
  1846. return Response::success();
  1847. } catch (\Exception $e) {
  1848. //回滚事务
  1849. DB::rollBack();
  1850. return $e->getMessage();
  1851. }
  1852. }
  1853. /*
  1854. * 写入直播 数据
  1855. */
  1856. public function broadcast($opt = [], $game_code = '')
  1857. {
  1858. $data = $opt['data'];
  1859. $set_broadcast = [
  1860. "doing" => $data['doing'],
  1861. "game_type" => $data['game_type'],
  1862. "game_code" => $game_code,
  1863. "guest_team" => $data['guest_team'],
  1864. "host_team" => $data['host_team'],
  1865. "league_name" => $data['league_name'],
  1866. "shower" => $data['shower'],
  1867. "showid" => (int)$data['showid'],
  1868. "start_time" => $data['start_time'],
  1869. "ctime" => date('Y-m-d H:i:s'),
  1870. "utime" => date('Y-m-d H:i:s'),
  1871. ];
  1872. $ret = broadcastModel::insert($set_broadcast);
  1873. if ($ret == false) throw new \Exception(Response::generate('', Response::BROADCAST_ERROR));
  1874. }
  1875. /*
  1876. * 写入 赛事 初始 结果
  1877. */
  1878. public function match_result($game_code = '')
  1879. {
  1880. $model = commonFunction::getModels($game_code, 1);
  1881. if ($game_code == 'zq') ZqResultModel::ZQresult($model);
  1882. if ($game_code == 'lq') LqResultModel::LQresult($model);
  1883. if ($game_code == 'wq') WqResultModel::WQresult($model);
  1884. if ($game_code == 'bq') BqResultModel::BQresult($model);
  1885. }
  1886. /*
  1887. * 写入联赛数据
  1888. */
  1889. public function league($opt = [], $gameName = '')
  1890. {
  1891. $game_code = $opt['game_code'];
  1892. //根据球类代码获取相关model
  1893. $model = commonFunction::getModels($game_code, 1);
  1894. $data = $opt['data'];
  1895. //查询联赛是否已存在
  1896. $id = $model['model_league']::where('name_chinese', '=', $data['name_chinese'])
  1897. ->value('id');
  1898. //默认获取本年最后一天
  1899. $last_time = date('Y-12-31 23:59:59');
  1900. //决赛时间
  1901. if ($data['last_time']) {
  1902. $last_time = $data['last_time'];
  1903. }
  1904. $set_lg['name_chinese'] = $data['name_chinese'];
  1905. $set_lg['kind'] = $data['kind'];
  1906. $set_lg['match_mode'] = $data['match_mode'];
  1907. $set_lg['if_stop'] = $data['if_stop'];
  1908. $set_lg['identity'] = $data['uuid'] ?: '';
  1909. $set_lg['last_time'] = $last_time;
  1910. $set_lg['utime'] = date('Y-m-d H:i:s');
  1911. if (empty($id)) {
  1912. //写入联赛
  1913. $id = $model['model_league']::insertGetId($set_lg);
  1914. $m_lg_id = $id;
  1915. if ($m_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::INSERT_ERROR));
  1916. } else {
  1917. //更新联赛
  1918. $ret = $model['model_league']::where(['id' => $id])
  1919. ->update($set_lg);
  1920. if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::UPDATE_ERROR));
  1921. }
  1922. $set_local = [
  1923. 'lg_id' => $id,
  1924. 'others_lg_id' => $data['lg_id'],
  1925. 'source' => $data['source'],
  1926. 'ctime' => date('Y-m-d H:i:s')
  1927. ];
  1928. $ret = $model['model_local_league']::insertGetId($set_local);
  1929. 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'));
  1930. //执行成功返回源数据 联赛ID
  1931. $data = ['others_lg_id' => $data['lg_id'], 'lg_id' => $id];
  1932. return $data;
  1933. }
  1934. /*
  1935. * 写入赛事数据
  1936. */
  1937. public function competition($opt = [], $gameName = '', $lg_id = '')
  1938. {
  1939. $game_code = $opt['game_code'];
  1940. //根据球类代码获取相关model
  1941. $model = commonFunction::getModels($game_code, 1);
  1942. $data = $opt['data'];
  1943. if (empty($data['lg_id'])) throw new \Exception(Response::generate('', Response::LEAGUE_ERROR));//Render([], '10015', lang('Tips','Sports')->get('league_error'));
  1944. //查询赛事是否存在
  1945. $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']])
  1946. ->value('id');
  1947. $half_match_id = 0;
  1948. //如果有上半场赛事id 获取上半场赛事是否存在
  1949. if (!empty($data['half_match_id'])) {
  1950. $half_match_id = $match_id = $model['model_local_match']::where(['others_match_id' => $data['half_match_id'], 'source' => $data['source']])
  1951. ->value('match_id');
  1952. 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'));
  1953. }
  1954. //如果赛事没有开始日期,则为冠军盘口赛事
  1955. if (empty($data['match_date'])) {
  1956. //冠军盘口赛事获取所属联赛结束时间
  1957. $last_time = $model['model_league']::where(['id' => $lg_id])
  1958. ->value('last_time');
  1959. 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'));
  1960. //给冠军盘口赛事 赋值时间
  1961. $time = strtotime($last_time);
  1962. $data['match_date'] = date('Y-m-d', $time);
  1963. $data['match_time'] = date('H:i:s', $time);
  1964. }
  1965. $set_match = [
  1966. 'ctime' => date('Y-m-d H:i:s'),
  1967. 'utime' => date('Y-m-d H:i:s'),
  1968. 'expire_time' => date('Y-m-d H:i:s', time() + 60),
  1969. 'home_team' => $data['home_team'] ?: '',
  1970. 'guest_team' => $data['guest_team'] ?: 'no_team',
  1971. 'lg_id' => $lg_id,
  1972. 'status' => $data['status'],
  1973. 'match_date' => $data['match_date'] ?: date('Y-m-d'),
  1974. 'match_time' => $data['match_time'] ?: date('H:i:s'),
  1975. 'tag' => $data['tag'] ?: 0,
  1976. 'is_rollball' => $data['is_rollball'] ?: 0,
  1977. 'is_today' => $data['is_today'] ?: 0,
  1978. 'is_morningplate' => $data['is_morningplate'] ?: 0,
  1979. 'is_stringscene' => $data['is_stringscene'] ?: 0,
  1980. 'us_time' => $data['us_time'] ?: commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
  1981. 'half_match_id' => $half_match_id ?: 0,
  1982. 'identity' => $data['uuid'],
  1983. ];
  1984. //写入赛事
  1985. if (empty($id)) {
  1986. //写入赛事 返回id
  1987. $id = $model['model_match']::insertGetId($set_match);
  1988. if ($id < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::INSERT_ERROR));
  1989. } else {
  1990. //更新赛事
  1991. $ret = $model['model_match']::where(['id' => $id])->update($set_match);
  1992. if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::UPDATE_ERROR));
  1993. }
  1994. //写关联记录
  1995. $set_local = [
  1996. 'match_id' => $id,
  1997. 'others_match_id' => $data['match_id'],
  1998. 'source' => $data['source'],
  1999. 'ctime' => date('Y-m-d H:i:s')
  2000. ];
  2001. $ret = $model['model_local_match']::insertGetId($set_local);
  2002. 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'));
  2003. //返回 源数据 赛事ID
  2004. $data = ['others_match_id' => $data['match_id'], 'match_id' => $id];
  2005. return $data;
  2006. }
  2007. /*
  2008. * 写入赔率/赔率记录数据
  2009. */
  2010. public function odds($opt = [], $gameName = '', $lg_id = 0, $match_id = 0, $oddsID = '', $oddsRecordID = '')
  2011. {
  2012. $game_code = $opt['game_code'];
  2013. //根据球类代码获取相关model
  2014. $model = commonFunction::getModels($game_code, 1);
  2015. $data = $opt['data'];
  2016. //获取赛事 本地/源ID
  2017. $others_match_id = $data['match_id'];
  2018. //获取联赛 本地/源ID
  2019. $others_lg_id = $data['lg_id'];
  2020. //===写赔率记录===
  2021. $set_odds_r = [
  2022. 'match_id' => $match_id ?: 0,
  2023. 'others_match_id' => $others_match_id ?: 0,
  2024. 'odds_code' => $data['odds_code'] ?: '',
  2025. 'status' => $data['status'] ?: 0,
  2026. 'sort' => $data['sort'] ?: 0,
  2027. 'p_code' => $data['p_code'] ?: '',
  2028. 'odds' => $data['odds'] ?: 0,
  2029. 'condition' => $data['condition'],
  2030. 'odds_only' => $data['odds_only'] ?: '',
  2031. 'source' => $data['source'] ?: '',
  2032. 'type' => $data['type'] ?: 0,
  2033. 'team' => $data['team'] ?: '',
  2034. 'lg_id' => $lg_id,
  2035. 'others_lg_id' => $others_lg_id,
  2036. 'ctime' => date('Y-m-d H:i:s'),
  2037. ];
  2038. //更新或写入赔率记录
  2039. if ($oddsRecordID != false) {
  2040. $ret = $model['model_odds_record']::where(['id' => $oddsRecordID])
  2041. ->update($set_odds_r);
  2042. 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'));
  2043. } else {
  2044. $ret = $model['model_odds_record']::insert($set_odds_r);
  2045. 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'));
  2046. }
  2047. //===写赔率===
  2048. $set_odds = [
  2049. 'match_id' => $match_id ?: 0,
  2050. 'others_match_id' => $others_match_id ?: 0,
  2051. 'odds_code' => $data['odds_code'] ?: '',
  2052. 'status' => $data['status'] ?: 0,
  2053. 'sort' => $data['sort'] ?: 0,
  2054. 'p_code' => $data['p_code'] ?: '',
  2055. 'odds' => $data['odds'] ?: 0,
  2056. 'condition' => $data['condition'],
  2057. 'odds_only' => $data['odds_only'] ?: '',
  2058. 'sole' => $data['sole'] ?: '',
  2059. 'source' => $data['source'] ?: '',
  2060. 'type' => $data['type'] ?: 0,
  2061. 'team' => $data['team'] ?: '',
  2062. 'lg_id' => $lg_id,
  2063. 'others_lg_id' => $others_lg_id,
  2064. 'ctime' => date('Y-m-d H:i:s'),
  2065. 'utime' => date('Y-m-d H:i:s'),
  2066. 'expire_time' => date('Y-m-d H:i:s', time() + 60),
  2067. ];
  2068. //更新或写入赔率数据
  2069. if ($oddsID != false) {
  2070. $ret = $model['model_odds']::where(['id' => $oddsID])
  2071. ->update($set_odds);
  2072. 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'));
  2073. } else {
  2074. $ret = $model['model_odds']::insert($set_odds);
  2075. 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'));
  2076. }
  2077. //===end===
  2078. }
  2079. /*
  2080. * 更新 赛事下 所有不在本次请求的 赔率状态
  2081. */
  2082. public function upOddsStatus($opt = [], $gameName = '')
  2083. {
  2084. //获取球类代码
  2085. $game_code = $opt['game_code'];
  2086. //获取球类model
  2087. $model = commonFunction::getModels($game_code, 1);
  2088. //赛事下 所有 赔率sole
  2089. $odds_sole = $opt['data'];
  2090. //数据源 赛事 id
  2091. $others_match_id = $opt['match_id'];
  2092. //数据源
  2093. $source = $opt['source'];
  2094. //更新赛事下所有 不在本次请求的赔率 状态
  2095. $ret = OddsModel::upOddsStatus($model, $others_match_id, '', $source, $odds_sole);
  2096. if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
  2097. }
  2098. /*
  2099. * 写入联赛结果
  2100. */
  2101. public function league_result($opt, $gameName)
  2102. {
  2103. $game_code = $opt['game_code'];
  2104. //根据球类代码获取相关model
  2105. $model = commonFunction::getModels($game_code, 1);
  2106. $data = $opt['data'];
  2107. //验证结果所属联赛
  2108. $lg_id = $model['model_local_league']::where(['others_lg_id' => $data['lg_id'], 'source' => $data['source']])
  2109. ->value('lg_id');
  2110. if ($lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LEAGUE_ERROR));
  2111. $lg_result_id = $model['model_league_result']::where(['lg_id' => $lg_id, 'game_name' => $data['game_name']])
  2112. ->value('id');
  2113. $set_lg_result = [
  2114. 'lg_id' => $lg_id,
  2115. 'game_name' => $data['game_name'],
  2116. 'result' => json_encode($data['result'], JSON_UNESCAPED_UNICODE),
  2117. 'status' => $data['status'],
  2118. 'ctime' => date('Y-m-d H:i:s'),
  2119. 'utime' => date('Y-m-d H:i:s'),
  2120. ];
  2121. //联赛结果数据处理
  2122. if (!empty($lg_result_id)) {
  2123. $ret = $model['model_league_result']::where(['id' => $lg_result_id])
  2124. ->update($set_lg_result);
  2125. 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'));
  2126. } else {
  2127. $ret = $model['model_league_result']::insert($set_lg_result);
  2128. 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'));
  2129. }
  2130. }
  2131. /*
  2132. * 写入赛事结果
  2133. */
  2134. public function com_result($opt = [], $gameName = '', $lg_id = '', $match_id = '')
  2135. {
  2136. $game_code = $opt['game_code'];
  2137. //根据球类代码获取相关model
  2138. $model = commonFunction::getModels($game_code, 1);
  2139. $data = $opt['data'];
  2140. //查询结果是否存在
  2141. $match_r_id = $model['model_result']::where(['match_id' => $match_id])
  2142. ->value('id');
  2143. $set_match_r = [
  2144. "home_team" => $data['home_team'],
  2145. "guest_team" => $data['guest_team'],
  2146. "lg_id" => $lg_id,
  2147. "home_rate" => $data['home_rate'],
  2148. "guest_rate" => $data['guest_rate'],
  2149. "home_score" => $data['home_score'],
  2150. "guest_score" => $data['guest_score'],
  2151. "all_goal" => $data['all_goal'],
  2152. "status" => $data['status'],
  2153. "first_score" => $data['first_score'],
  2154. "last_score" => $data['last_score'],
  2155. "match_score" => $data['match_score'],
  2156. "match_winer" => $data['match_winer'],
  2157. "match_time" => $data['match_time'],
  2158. "match_process" => $data['match_process'],
  2159. "tag" => $data['tag'],
  2160. "match_id" => $match_id,
  2161. "u_home_score" => $data['u_home_score'],
  2162. "u_guest_score" => $data['u_guest_score'],
  2163. "p_code" => $data['p_code'],
  2164. "update_time" => date('Y-m-d H:i:s')
  2165. ];
  2166. //赛事结果数据处理
  2167. if (!empty($match_r_id)) {
  2168. $ret = $model['model_result']::where(['id' => $match_r_id])
  2169. ->update($set_match_r);
  2170. 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'));
  2171. } else {
  2172. $ret = $model['model_result']::insert($set_match_r);
  2173. 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'));
  2174. }
  2175. // return Response::success();
  2176. }
  2177. //写入赛事结果记录
  2178. public function com_result_record($opt = [], $gameName = '', $lg_id = '', $match_id = '')
  2179. {
  2180. $game_code = $opt['game_code'];
  2181. //根据球类代码获取相关model
  2182. $model = commonFunction::getModels($game_code, 1);
  2183. $data = $opt['data'];
  2184. $match_r_id = $model['model_result_record']::where(['match_id' => $match_id, 'match_time' => $data['match_time']])
  2185. ->value('id');
  2186. //根据球类 获取 赛事结果记录字段
  2187. $set_match_r = $this->get_match_r($game_code, $lg_id, $match_id, $data);
  2188. //赛事结果记录处理
  2189. if ($match_r_id > 0) {
  2190. $ret = $model['model_result_record']::where(['id' => $match_r_id])
  2191. ->update($set_match_r);
  2192. 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'));
  2193. } else {
  2194. $ret = $model['model_result_record']::insert($set_match_r);
  2195. 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'));
  2196. }
  2197. }
  2198. /**
  2199. * @param $data
  2200. * @return mixed
  2201. * json转数组
  2202. */
  2203. public function getAddData($data)
  2204. {
  2205. $data = json_decode($data, true);
  2206. return $data;
  2207. }
  2208. /*
  2209. * 根据球类获取 赛事结果记录字段
  2210. */
  2211. public function get_match_r($game_code, $lg_id, $match_id, $data)
  2212. {
  2213. $set_match_r = [];
  2214. if ($game_code == 'zq') {
  2215. $set_match_r = [
  2216. "home_team" => $data['home_team'] ?: '',
  2217. "guest_team" => $data['guest_team'] ?: '',
  2218. "lg_id" => $lg_id,
  2219. "all_goal" => $data['all_goal'] ?: 0,
  2220. "home_rate" => $data['home_rate'] ?: 0,
  2221. "guest_rate" => $data['guest_rate'] ?: 0,
  2222. "home_score" => $data['home_score'] ?: 0,
  2223. "guest_score" => $data['guest_score'] ?: 0,
  2224. "status" => $data['status'] ?: 0,
  2225. "first_score" => $data['first_score'] ?: 0,
  2226. "last_score" => $data['last_score'] ?: 0,
  2227. "match_score" => $data['match_score'] ?: 0,
  2228. "match_winer" => $data['match_winer'] ?: '',
  2229. "match_time" => $data['match_time'] ?: 0,
  2230. "match_process" => $data['match_process'] ?: '',
  2231. // "tag"=> $data['tag']?:0,
  2232. "match_id" => $match_id,
  2233. "update_time" => date('Y-m-d H:i:s')
  2234. ];
  2235. };
  2236. if ($game_code == 'lq') {
  2237. $set_match_r = [
  2238. "home_team" => $data['home_team'] ?: '',
  2239. "guest_team" => $data['guest_team'] ?: '',
  2240. "lg_id" => $lg_id,
  2241. "home_rate" => $data['home_rate'] ?: 0,
  2242. "guest_rate" => $data['guest_rate'] ?: 0,
  2243. "home_score" => $data['home_score'] ?: 0,
  2244. "guest_score" => $data['guest_score'] ?: 0,
  2245. "status" => $data['status'] ?: 0,
  2246. "first_score" => $data['first_score'] ?: 0,
  2247. "last_score" => $data['last_score'] ?: 0,
  2248. "match_score" => $data['match_score'] ?: 0,
  2249. "match_winer" => $data['match_winer'] ?: '',
  2250. "match_time" => $data['match_time'] ?: 0,
  2251. "match_process" => $data['match_process'] ?: '',
  2252. // "tag"=> $data['tag']?:0,
  2253. "match_id" => $match_id,
  2254. "update_time" => date('Y-m-d H:i:s'),
  2255. "result_mark" => json_encode($data['result_mark']) ?: '',
  2256. ];
  2257. }
  2258. if ($game_code == 'wq') {
  2259. $set_match_r = [
  2260. "home_player_name" => $data['home_player_name'] ?: '',
  2261. "guest_player_name" => $data['guest_player_name'] ?: '',
  2262. "lg_id" => $lg_id,
  2263. "home_player_let_plate" => $data['home_player_let_plate'] ?: 0,
  2264. "guest_player_let_plate" => $data['guest_player_let_plate'] ?: 0,
  2265. "home_player_let_inning" => $data['home_player_let_inning'] ?: 0,
  2266. "guest_player_let_inning" => $data['guest_player_let_inning'] ?: 0,
  2267. "all_inning" => $data['all_inning'] ?: 0,
  2268. "home_player_score" => $data['home_player_score'] ?: 0,
  2269. "guest_player_score" => $data['guest_player_score'] ?: 0,
  2270. "status" => $data['status'] ?: 0,
  2271. "first_score_player" => $data['first_score_player'] ?: '',
  2272. "last_score_player" => $data['last_score_player'] ?: '',
  2273. "first_inning_score" => $data['first_inning_score'] ?: 0,
  2274. "second_inning_score" => $data['second_inning_score'] ?: 0,
  2275. "third_inning_score" => $data['third_inning_score'] ?: 0,
  2276. "match_winer_player" => $data['match_winer_player'] ?: '',
  2277. "update_time" => date('Y-m-d H:i:s'),
  2278. "match_time" => $data['match_time'] ?: 0,
  2279. "match_process" => $data['match_process'] ?: '',
  2280. // "tag"=>$data['tag']?:0,
  2281. "match_id" => $match_id,
  2282. "result_mark" => json_encode($data['result_mark']) ?: '',
  2283. ];
  2284. }
  2285. if ($game_code == 'bq') {
  2286. $set_match_r = [
  2287. "home_team" => $data['home_team'] ?: '',
  2288. "guest_team" => $data['guest_team'] ?: '',
  2289. "lg_id" => $lg_id,
  2290. "home_rate" => $data['home_rate'] ?: 0,
  2291. "guest_rate" => $data['guest_rate'] ?: 0,
  2292. "home_score" => $data['home_score'] ?: 0,
  2293. "guest_score" => $data['guest_score'] ?: 0,
  2294. "status" => $data['status'] ?: 0,
  2295. "first_score" => $data['first_score'] ?: 0,
  2296. "last_score" => $data['last_score'] ?: 0,
  2297. "match_score" => $data['match_score'] ?: 0,
  2298. "match_winer" => $data['match_winer'] ?: '',
  2299. "match_time" => $data['match_time'] ?: 0,
  2300. "match_process" => $data['match_process'] ?: '',
  2301. // "tag"=> $data['tag']?:0,
  2302. "match_id" => $match_id,
  2303. "all_inning" => $data['all_inning'] ?: 9,
  2304. "update_time" => date('Y-m-d H:i:s'),
  2305. "result_mark" => json_encode($data['result_mark']) ?: '',
  2306. ];
  2307. }
  2308. return $set_match_r;
  2309. }
  2310. //将数组按按指定健名,重新生成新的数组,key在存在并且 值不能重复
  2311. private function ArrayKeySet(Array $array, $key)
  2312. {
  2313. $ret = [];
  2314. foreach ($array as $val) {
  2315. $ret[$val[$key]] = $val;
  2316. }
  2317. return $ret;
  2318. }
  2319. }