WriteSportsController.php 71 KB

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