WriteSportsController.php 73 KB

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