WriteSportsController.php 72 KB

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