فهرست منبع

新增推送 完成体育赛事数据写入接口 5/20

彭俊 6 سال پیش
والد
کامیت
c08d63ba20
3فایلهای تغییر یافته به همراه27 افزوده شده و 9 حذف شده
  1. 23 9
      Application/Sports/Controller/WriteSports.php
  2. 2 0
      Application/Sports/Lang/Errors.php
  3. 2 0
      Application/Sports/Lang/Tips.php

+ 23 - 9
Application/Sports/Controller/WriteSports.php

@@ -184,20 +184,34 @@ class WriteSports extends Controller{
             if(empty($lg)) Render([], '10015', lang('Tips','Sports')->get('league_error'));
         }
 
+        //查询关联记录是否存在
         $match_id = lm($model['model_local_match'],'Sports')
             ->select('m_match_id')
             ->where(['match_id'=>$data['match_id'],'source'=>$data['source']])
             ->first()->m_match_id;
-        //更新操作
         if(empty($match_id)){
-            $ret = lm($model['model_match'],'Sports')
-                -> where(['match_id'=>$data['match_id']])
-                -> update($data);
-            if($ret < 1) Render([], '10011', lang('Tips','Sports')->get('update_error'));
-        }else{
-            //写入操作
-            $ret = lm($model['model_match'],'Sports')->insert($data);
-            if($ret != true) Render([], '10012', lang('Tips','Sports')->get('insert_error'));
+            //查询赛事是否存在
+            $id = lm($model['model_match'],'Sports')
+                ->select('id')
+                ->where(['home_team'=>$data['home_team'],'guest_team'=>$data['guest_team'],'match_date'=>$data['match_date'],'match_time'=>$data['match_time']])
+                ->first()->id;
+
+            //写入赛事
+            if(empty($id)){
+                $data['ctime'] = $this->newTime;
+                $data['utime'] = $this->newTime;
+                $data['expire_time'] = date('Y-m-d H:m:i',(time()+60));
+
+                $id = lm($model['model_match'],'Sports')->insertGetId($data);
+                if($id < 1) Render([], '10012', lang('Tips','Sports')->get('insert_error'));
+            }
+            $set_local = [
+                'm_match_id'=>$id,
+                'match_id'=>$data['match_id'],
+                'source'=>$data['source'],
+            ];
+            $ret = lm($model['model_local_match'],'Sports')-> insertGetId($set_local);
+            if($ret < 1) Render([], '10018', lang('Tips','Sports')->get('local_match_error'));
         }
         Render([], '1', lang('Tips','Sports')->get('success'));
     }

+ 2 - 0
Application/Sports/Lang/Errors.php

@@ -45,6 +45,8 @@ return array(
     'error-10015' => '联赛不存在',
     'error-10016' => '赛事不存在',
     'error-10017' => '插入联赛关联记录失败',
+    'error-10018' => '插入赛事关联记录失败',
+
 
 
 

+ 2 - 0
Application/Sports/Lang/Tips.php

@@ -15,6 +15,8 @@ return array(
     'league_error' =>'联赛不存在',
     'match_error' =>'赛事不存在',
     'local_league_error' =>'插入联赛关联记录失败',
+    'local_match_error' =>'插入联赛关联记录失败',
+
 
 
     // ====end===