WriteSportsController.php 71 KB

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