WriteSportsController.php 71 KB

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