WriteSports.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Jun.peng
  5. * Date: 2019/5/13
  6. * Time: 10:19
  7. */
  8. namespace App\Sports\Controller;
  9. use BaseController\Controller;
  10. use App\Sports\Model\St_area_country as St_area_countryModel;
  11. class WriteSports extends Controller{
  12. public function init() {
  13. $this->commonFunction = C()->get('commonFunction');
  14. //当前时间
  15. $this->newTime = date('Y-m-d H:m:i');
  16. }
  17. /**
  18. * 体育数据入库接口
  19. */
  20. public function setSports(){
  21. $obt = $_POST['data'];
  22. //写文件
  23. // file_put_contents("C:/Users/Jun.peng/Desktop/abc/as.txt",$obt);
  24. $data = $this->getAddData($obt);
  25. //验证二维数组内是否有空值
  26. // foreach ($data['data'] as $v){
  27. // if(in_array('', $v)) Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR'));
  28. // }
  29. switch ($data['title']){
  30. case 'area'://地区
  31. Render([], '10025', lang('Tips','Sports')->get('auth_error'));
  32. // $ret = $this->area($data['data']);
  33. break;
  34. case 'country'://国家
  35. Render([], '10025', lang('Tips','Sports')->get('auth_error'));
  36. // $ret = $this->country($data['data']);
  37. break;
  38. case 'league'://联赛
  39. $ret = $this->league($data);
  40. break;
  41. case 'competition'://赛事
  42. $ret = $this->competition($data);
  43. break;
  44. case 'odds'://赔率
  45. $ret = $this->odds($data);
  46. break;
  47. case 'league_result'://联赛结果
  48. Render([], '10025', lang('Tips','Sports')->get('auth_error'));
  49. // $ret = $this->league_result($data);
  50. break;
  51. case 'match_result'://赛事结果
  52. Render([], '10025', lang('Tips','Sports')->get('auth_error'));
  53. // $ret = $this->com_result($data);
  54. break;
  55. case 'match_result_record'://赛事结果记录
  56. $ret = $this->com_result_record($data);
  57. break;
  58. case 'odds_record'://赔率记录
  59. $ret = $this->odds_record($data);
  60. break;
  61. case ''://将所有进行中的赛事写入结果
  62. if(empty($data['game_code'])) Render([], '10007', lang('Tips','Sports')->get('abnormal'));
  63. // if($data['game_code'] != 'zq' || $data['game_code'] != 'lq' || $data['game_code'] != 'wq' || $data['game_code'] != 'bq') Render([], '10007', lang('Tips','Sports')->get('abnormal'));
  64. $ret = $this->match_result($data);
  65. default:
  66. Render([], '10007', lang('Tips','Sports')->get('abnormal'));
  67. }
  68. //写入成功
  69. if($ret) Render([], '1', lang('Tips','Sports')->get('success'));
  70. //写入失败
  71. Render([], '10010', lang('Tips','Sports')->get('HANDLE_ERRORS'));
  72. }
  73. //计算滚球 赛事进行时间
  74. private function secTime($sec=0){
  75. $min = floor($sec/60);
  76. $res = $min.':'.($sec-$min*60);
  77. return $res;
  78. }
  79. //将进行中赛事写入 赛事结果
  80. public function match_result($opt = []){
  81. $game_code = $opt['game_code'];
  82. $data = $opt['data'];
  83. $model = $this->commonFunction->getModels($game_code,1);
  84. if(empty($data)){
  85. //获取赛事表所有滚球
  86. $matchData = lm($model['model_match'],'Sports')
  87. ->select('id','home_team','guest_team','lg_id','status','tag','match_time')
  88. ->where(['status'=> 1])
  89. ->get()
  90. ->toarray();
  91. // dd($matchData);
  92. //没有滚球数据,无需操作
  93. if(empty($matchData)) Render([], '1', lang('Tips','Sports')->get('success'));
  94. //获取赛事结果表 所有滚球
  95. $matchData_r = lm($model['model_result'],'Sports')
  96. ->select()
  97. ->where(['status'=> 1])
  98. ->get()
  99. ->toarray();
  100. //没有滚球结果,直接插入结果表
  101. if(empty($matchData_r)){
  102. foreach ($matchData as $k=>$v){
  103. $time = time()-strtotime($v['match_time']);
  104. $match_time = $this->secTime($time);
  105. $set_match_r[] = [
  106. "match_id"=> $v['id'],
  107. "home_team"=>$v['home_team'],
  108. "guest_team"=>$v['guest_team'],
  109. "lg_id"=>$v['lg_id'],
  110. "status"=>$v['status'],
  111. "tag"=> $v['tag'],
  112. 'match_time'=>$match_time,
  113. "update_time"=>$this->newTime
  114. ];
  115. }
  116. $ret = lm($model['model_result'],'Sports')->insert($set_match_r);
  117. if($ret != true) Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
  118. }
  119. //如果结果表有数据,则获取结果表没有的赛事
  120. foreach ($matchData as $k=>$v){
  121. foreach ($matchData_r as $kk=>$vv){
  122. if($v['id'] == $vv['match_id']){
  123. unset($matchData[$k]);
  124. }
  125. }
  126. }
  127. //如果还有未写入赛事
  128. if(!empty($matchData)){
  129. //写入结果表不存在赛事
  130. foreach ($matchData as $k=>$v){
  131. $time = time()-strtotime($v['match_time']);
  132. $match_time = $this->secTime($time);
  133. $set_match_r[] = [
  134. "match_id"=> $v['id'],
  135. "home_team"=>$v['home_team'],
  136. "guest_team"=>$v['guest_team'],
  137. "lg_id"=>$v['lg_id'],
  138. "status"=>$v['status'],
  139. "tag"=> $v['tag'],
  140. 'match_time'=>$match_time,
  141. "update_time"=>$this->newTime
  142. ];
  143. }
  144. $ret = lm($model['model_result'],'Sports')->insert($set_match_r);
  145. if($ret != true) Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
  146. }
  147. }
  148. Render([], '1', lang('Tips','Sports')->get('success'));
  149. }
  150. //写入地区数据 弃用
  151. public function area($opt = []){
  152. $ret = lm('st_area','Sports')->insert($opt);
  153. return $ret;
  154. }
  155. //写入国家数据 弃用
  156. public function country($opt = []){
  157. $ret = lm('st_country','Sports')->insert($opt);
  158. return $ret;
  159. }
  160. //写入联赛数据
  161. public function league($opt = []){
  162. $game_code = $opt['game_code'];
  163. //根据球类代码获取相关model
  164. $model = $this->commonFunction->getModels($game_code,1);
  165. $data = $opt['data'];
  166. if(empty($data['belong'])) Render([], '10013', lang('Tips','Sports')->get('country_error'));
  167. //获取联赛所属 国家/地区id
  168. $belong = St_area_countryModel::getID($data['belong']);
  169. $set_lg['area_id'] = $belong['area_id'];
  170. $set_lg['country_id'] = $belong['country_id'];
  171. //查询中间表 是否已记录
  172. $lg_id = lm($model['model_local_league'],'Sports')
  173. ->select('lg_id')
  174. ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
  175. ->first()->lg_id;
  176. //如果没有记录
  177. if(empty($lg_id)){
  178. //查询联赛是否已存在
  179. $id = lm($model['model_league'],'Sports')
  180. ->select('id')
  181. ->where('name_chinese','=',$data['name_chinese'])
  182. ->first()->id;
  183. if(empty($id)){
  184. $set_lg['name_chinese'] = $data['name_chinese'];
  185. $set_lg['kind'] = $data['kind'];
  186. $set_lg['match_mode'] = $data['match_mode'];
  187. $set_lg['if_stop'] = $data['if_stop'];
  188. $set_lg['last_time'] = $data['last_time'];
  189. $set_lg['utime'] = $this->newTime;
  190. $id = lm($model['model_league'],'Sports')->insertGetId($set_lg);
  191. $m_lg_id = $id;
  192. if($m_lg_id < 1) Render([], '10012', lang('Tips','Sports')->get('insert_error'));
  193. }
  194. $set_local = [
  195. 'lg_id'=>$id,
  196. 'others_lg_id'=>$data['lg_id'],
  197. 'source'=>$data['source'],
  198. ];
  199. $ret = lm($model['model_local_league'],'Sports')-> insertGetId($set_local);
  200. if($ret < 1) Render([], '10017', lang('Tips','Sports')->get('local_league_error'));
  201. }
  202. Render([], '1', lang('Tips','Sports')->get('success'));
  203. }
  204. //写入赛事数据
  205. public function competition($opt = []){
  206. $game_code = $opt['game_code'];
  207. //根据球类代码获取相关model
  208. $model = $this->commonFunction->getModels($game_code,1);
  209. $data = $opt['data'];
  210. if(empty($data['lg_id'])) Render([], '10015', lang('Tips','Sports')->get('league_error'));
  211. //根据源联赛ID 获取本地关联id
  212. $lg_id = lm($model['model_local_league'],'Sports')
  213. ->select('lg_id')
  214. ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
  215. ->first()->lg_id;
  216. if(empty($lg_id)) Render([], '10015', lang('Tips','Sports')->get('league_error'));
  217. //查询关联记录是否存在
  218. $match_id = lm($model['model_local_match'],'Sports')
  219. ->where(['others_match_id'=>$data['match_id'],'source'=>$data['source']])
  220. ->value('match_id');
  221. if(empty($match_id)){
  222. //查询赛事是否存在
  223. $id = lm($model['model_match'],'Sports')
  224. ->where(['home_team'=>$data['home_team'],'guest_team'=>$data['guest_team'],'match_date'=>$data['match_date'],'match_time'=>$data['match_time']])
  225. ->value('id');
  226. //如果有上半场赛事id 获取上半场赛事是否存在
  227. if(!empty($data['half_match_id'])){
  228. $half_match_id = $match_id = lm($model['model_local_match'],'Sports')
  229. ->where(['others_match_id'=>$data['half_match_id'],'source'=>$data['source']])
  230. ->value('match_id');
  231. if(empty($half_match_id)) Render([], '10024', lang('Tips','Sports')->get('half_match_error'));
  232. }
  233. //写入赛事
  234. if(empty($id)){
  235. //如果赛事没有开始日期,则为冠军盘口赛事
  236. if(empty($data['match_date'])){
  237. //冠军盘口赛事获取所属联赛结束时间
  238. $last_time = lm($model['model_league'],'Sports')
  239. ->where(['id'=>$lg_id])
  240. ->value('last_time');
  241. if(empty($last_time)) Render([], '10023', lang('Tips','Sports')->get('lg_lastTime_error'));
  242. //给冠军盘口赛事 赋值时间
  243. $time = strtotime($last_time);
  244. $data['match_date'] = date('Y-m-d',$time);
  245. $data['match_time'] = date('H:m:i',$time);
  246. }
  247. $set_match = [
  248. 'ctime'=>$this->newTime,
  249. 'utime'=>$this->newTime,
  250. 'expire_time'=>date('Y-m-d H:m:i',time()+60),
  251. 'home_team'=>$data['home_team']?:'',
  252. 'guest_team'=>$data['guest_team']?:'no_team',
  253. 'lg_id'=>$lg_id,
  254. 'status'=>$data['status'],
  255. 'match_date'=>$data['match_date']?:'',
  256. 'match_time'=>$data['match_time']?:'',
  257. 'tag'=>$data['tag']?:0,
  258. 'is_rollball'=>$data['is_rollball']?:0,
  259. 'is_today'=>$data['is_today']?:0,
  260. 'is_morningplate'=>$data['is_morningplate']?:0,
  261. 'is_stringscene'=>$data['is_stringscene']?:0,
  262. 'us_time'=>$data['us_time']?:'',
  263. 'half_match_id'=>$half_match_id?:0,
  264. ];
  265. //写入赛事 返回id
  266. $id = lm($model['model_match'],'Sports')->insertGetId($set_match);
  267. if($id < 1) Render([], '10012', lang('Tips','Sports')->get('insert_error'));
  268. }
  269. $set_local = [
  270. 'match_id'=>$id,
  271. 'others_match_id'=>$data['match_id'],
  272. 'source'=>$data['source'],
  273. ];
  274. $ret = lm($model['model_local_match'],'Sports')-> insertGetId($set_local);
  275. if($ret < 1) Render([], '10018', lang('Tips','Sports')->get('local_match_error'));
  276. }
  277. Render([], '1', lang('Tips','Sports')->get('success'));
  278. }
  279. //写入赔率数据
  280. public function odds($opt){
  281. $game_code = $opt['game_code'];
  282. //根据球类代码获取相关model
  283. $model = $this->commonFunction->getModels($game_code,1);
  284. $data = $opt['data'];
  285. $match = lm($model['model_local_match'],'Sports')
  286. ->select('match_id','others_match_id')
  287. ->where(['others_match_id'=>$data['match_id'],'source'=>$data['source']])
  288. ->first();
  289. if(count($match) < 1) Render([], '10016', lang('Tips','Sports')->get('match_error'));
  290. //获取赛事 本地/源ID
  291. $others_match_id = $match->others_match_id;
  292. $match_id = $match->match_id;
  293. $lg = lm($model['model_local_league'],'Sports')
  294. ->select('lg_id','others_lg_id')
  295. ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
  296. ->first();
  297. if(count($lg) < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
  298. //获取联赛 本地/源ID
  299. $others_lg_id = $lg->others_lg_id;
  300. $lg_id = $lg->lg_id;
  301. //查询 赔率数据是否存在
  302. $oddsID = lm($model['model_odds'],'Sports')
  303. ->where(['lg_id'=>$lg_id,'others_lg_id'=>$others_lg_id,'match_id'=>$match_id,'others_match_id'=>$others_match_id,'odds_code'=>$data['odds_code'],'sort'=>$data['sort']])
  304. ->value('id');
  305. $set_odds = [
  306. 'match_id'=> $match_id,
  307. 'others_match_id'=> $others_match_id,
  308. 'odds_code'=> $data['odds_code'],
  309. 'status'=> $data['status'],
  310. 'sort'=> $data['sort'],
  311. 'p_code'=> $data['p_code'],
  312. 'odds'=> $data['odds'],
  313. 'condition'=> $data['condition'],
  314. 'odds_only'=> $data['odds_only'],
  315. 'sole'=> $data['sole'],
  316. 'source'=> $data['source'],
  317. 'type'=> $data['type'],
  318. 'team'=> $data['team'],
  319. 'lg_id'=> $lg_id,
  320. 'others_lg_id'=> $others_lg_id,
  321. 'ctime'=> $this->newTime,
  322. 'utime'=> $this->newTime,
  323. 'expire_time'=>date('Y-m-d H:m:i',time()+60),
  324. ];
  325. //更新或写入赔率数据
  326. if(!empty($oddsID)){
  327. $ret = lm($model['model_odds'],'Sports')
  328. ->where(['id'=>$oddsID])
  329. -> update($set_odds);
  330. if($ret < 1) Render([], '10019', lang('Tips','Sports')->get('add_odds_error'));
  331. }else{
  332. $ret = lm($model['model_odds'],'Sports')->insert($set_odds);
  333. if($ret != true) Render([], '10019', lang('Tips','Sports')->get('add_odds_error'));
  334. }
  335. Render([], '1', lang('Tips','Sports')->get('success'));
  336. }
  337. //写入联赛结果
  338. public function league_result($opt){
  339. $game_code = $opt['game_code'];
  340. //根据球类代码获取相关model
  341. $model = $this->commonFunction->getModels($game_code,1);
  342. $data = $opt['data'];
  343. //验证结果所属联赛
  344. $lg_id = lm($model['model_local_league'],'Sports')
  345. ->select('lg_id')
  346. ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
  347. ->first()->lg_id;
  348. if($lg_id < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
  349. $lg_result_id = lm($model['model_league_result'],'Sports')
  350. ->where(['lg_id'=>$lg_id,'game_name'=>$data['game_name']])
  351. ->value('id');
  352. $set_lg_result = [
  353. 'lg_id'=>$lg_id,
  354. 'game_name'=>$data['game_name'],
  355. 'result'=>json_encode($data['result'],JSON_UNESCAPED_UNICODE),
  356. 'status'=>$data['status'],
  357. 'ctime'=> $this->newTime,
  358. 'utime'=> $this->newTime,
  359. ];
  360. //联赛结果数据处理
  361. if(!empty($lg_result_id)){
  362. $ret = lm($model['model_league_result'],'Sports')
  363. ->where(['id'=>$lg_result_id])
  364. -> update($set_lg_result);
  365. if($ret < 1) Render([], '10021', lang('Tips','Sports')->get('add_lg_r_error'));
  366. }else{
  367. $ret = lm($model['model_league_result'],'Sports')->insert($set_lg_result);
  368. if($ret != true) Render([], '10021', lang('Tips','Sports')->get('add_lg_r_error'));
  369. }
  370. Render([], '1', lang('Tips','Sports')->get('success'));
  371. }
  372. //写入赛事结果
  373. public function com_result($opt){
  374. $game_code = $opt['game_code'];
  375. //根据球类代码获取相关model
  376. $model = $this->commonFunction->getModels($game_code,1);
  377. $data = $opt['data'];
  378. //验证结果所属联赛
  379. $lg_id = lm($model['model_local_league'],'Sports')
  380. ->select('lg_id')
  381. ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
  382. ->first()->lg_id;
  383. if($lg_id < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
  384. //验证结果所属赛事
  385. $match_id = lm($model['model_local_match'],'Sports')
  386. ->select('match_id')
  387. ->where(['others_match_id'=>$data['match_id'],'source'=>$data['source']])
  388. ->value('match_id');
  389. if($match_id < 1) Render([], '10016', lang('Tips','Sports')->get('match_error'));
  390. //查询结果是否存在
  391. $match_r_id = lm($model['model_result'],'Sports')
  392. ->where(['match_id'=>$match_id])
  393. ->value('id');
  394. $set_match_r = [
  395. "home_team"=>$data['home_team'],
  396. "guest_team"=>$data['guest_team'],
  397. "lg_id"=>$lg_id,
  398. "home_rate"=> $data['home_rate'],
  399. "guest_rate"=> $data['guest_rate'],
  400. "home_score"=> $data['home_score'],
  401. "guest_score"=> $data['guest_score'],
  402. "all_goal"=> $data['all_goal'],
  403. "status"=>$data['status'],
  404. "first_score"=>$data['first_score'],
  405. "last_score"=> $data['last_score'],
  406. "match_score"=> $data['match_score'],
  407. "match_winer"=> $data['match_winer'],
  408. "match_time"=> $data['match_time'],
  409. "match_process"=> $data['match_process'],
  410. "tag"=> $data['tag'],
  411. "match_id"=> $match_id,
  412. "u_home_score"=> $data['u_home_score'],
  413. "u_guest_score"=> $data['u_guest_score'],
  414. "p_code"=> $data['p_code'],
  415. "update_time"=>$this->newTime
  416. ];
  417. //赛事结果数据处理
  418. if(!empty($match_r_id)){
  419. $ret = lm($model['model_result'],'Sports')
  420. -> where(['id'=>$match_r_id])
  421. -> update($set_match_r);
  422. if($ret < 1) Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
  423. }else{
  424. $ret = lm($model['model_result'],'Sports')->insert($set_match_r);
  425. if($ret != true) Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
  426. }
  427. Render([], '1', lang('Tips','Sports')->get('success'));
  428. }
  429. //写入赛事结果记录
  430. public function com_result_record($opt){
  431. $game_code = $opt['game_code'];
  432. //根据球类代码获取相关model
  433. $model = $this->commonFunction->getModels($game_code,1);
  434. $data = $opt['data'];
  435. //验证结果所属联赛
  436. $lg_id = lm($model['model_local_league'],'Sports')
  437. ->select('lg_id')
  438. ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
  439. ->first()->lg_id;
  440. if($lg_id < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
  441. //验证结果所属赛事
  442. $match_id = lm($model['model_local_match'],'Sports')
  443. ->select('match_id')
  444. ->where(['others_match_id'=>$data['match_id'],'source'=>$data['source']])
  445. ->value('match_id');
  446. if($match_id < 1) Render([], '10016', lang('Tips','Sports')->get('match_error'));
  447. $match_r_id = lm($model['model_result_record'],'Sports')
  448. ->where(['match_id'=>$match_id,'match_time'=>$data['match_time']])
  449. ->value('id');
  450. $set_match_r = [
  451. "home_team"=>$data['home_team'],
  452. "guest_team"=>$data['guest_team'],
  453. "lg_id"=>$lg_id,
  454. "home_rate"=> $data['home_rate'],
  455. "guest_rate"=> $data['guest_rate'],
  456. "home_score"=> $data['home_score'],
  457. "guest_score"=> $data['guest_score'],
  458. "all_goal"=> $data['all_goal'],
  459. "status"=>$data['status'],
  460. "first_score"=>$data['first_score'],
  461. "last_score"=> $data['last_score'],
  462. "match_score"=> $data['match_score'],
  463. "match_winer"=> $data['match_winer'],
  464. "match_time"=> $data['match_time'],
  465. "match_process"=> $data['match_process'],
  466. "tag"=> $data['tag'],
  467. "match_id"=> $match_id,
  468. "p_code"=> $data['p_code'],
  469. "update_time"=>$this->newTime
  470. ];
  471. //赛事结果记录处理
  472. if($match_r_id > 0){
  473. $ret = lm($model['model_result_record'],'Sports')
  474. ->where(['id'=>$match_r_id])
  475. ->update($set_match_r);
  476. if($ret < 1) Render([], '10022', lang('Tips','Sports')->get('add_match_r_r_error'));
  477. }else{
  478. $ret = lm($model['model_result_record'],'Sports')->insert($set_match_r);
  479. if($ret != true) Render([], '10022', lang('Tips','Sports')->get('add_match_r_r_error'));
  480. }
  481. Render([], '1', lang('Tips','Sports')->get('success'));
  482. }
  483. //写入赔率记录
  484. public function odds_record($opt){
  485. $game_code = $opt['game_code'];
  486. //根据球类代码获取相关model
  487. $model = $this->commonFunction->getModels($game_code,1);
  488. $data = $opt['data'];
  489. $match = lm($model['model_local_match'],'Sports')
  490. ->select('match_id','others_match_id')
  491. ->where(['others_match_id'=>$data['match_id'],'source'=>$data['source']])
  492. ->first();
  493. if(count($match) < 1) Render([], '10016', lang('Tips','Sports')->get('match_error'));
  494. //获取赛事 本地/源ID
  495. $others_match_id = $match->others_match_id;
  496. $match_id = $match->match_id;
  497. $lg = lm($model['model_local_league'],'Sports')
  498. ->select('lg_id','others_lg_id')
  499. ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
  500. ->first();
  501. if(count($lg) < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
  502. //获取联赛 本地/源ID
  503. $others_lg_id = $lg->others_lg_id;
  504. $lg_id = $lg->lg_id;
  505. //查询 赔率数据是否存在
  506. $oddsID = lm($model['model_odds_record'],'Sports')
  507. ->where(['odds_only'=>$data['odds_only']])
  508. ->value('id');
  509. $set_odds = [
  510. 'match_id'=> $match_id,
  511. 'others_match_id'=> $others_match_id,
  512. 'odds_code'=> $data['odds_code'],
  513. 'status'=> $data['status'],
  514. 'sort'=> $data['sort'],
  515. 'p_code'=> $data['p_code'],
  516. 'odds'=> $data['odds'],
  517. 'condition'=> $data['condition'],
  518. 'odds_only'=> $data['odds_only'],
  519. 'source'=> $data['source'],
  520. 'type'=> $data['type'],
  521. 'team'=> $data['team'],
  522. 'lg_id'=> $lg_id,
  523. 'others_lg_id'=> $others_lg_id,
  524. 'ctime'=> $this->newTime,
  525. 'utime'=> $this->newTime,
  526. ];
  527. //更新或写入赔率记录
  528. if(!empty($oddsID)){
  529. $ret = lm($model['model_odds_record'],'Sports')
  530. ->where(['id'=>$oddsID])
  531. -> update($set_odds);
  532. if($ret < 1) Render([], '10020', lang('Tips','Sports')->get('add_odds_r_error'));
  533. }else{
  534. $ret = lm($model['model_odds_record'],'Sports')->insert($set_odds);
  535. if($ret != true) Render([], '10020', lang('Tips','Sports')->get('add_odds_r_error'));
  536. }
  537. Render([], '1', lang('Tips','Sports')->get('success'));
  538. }
  539. /**
  540. * @param $data
  541. * @return mixed
  542. * json转数组
  543. */
  544. public function getAddData($data){
  545. $data = json_decode($data,true);
  546. return $data;
  547. }
  548. }