Bläddra i källkod

追加推送 重写联赛数据写入接口 5/17

彭俊 6 år sedan
förälder
incheckning
9fb6f33878

+ 51 - 0
Application/Sports/Controller/WriteSports.php

@@ -7,6 +7,7 @@
  */
 namespace App\Sports\Controller;
 use BaseController\Controller;
+use App\Sports\Model\St_area_country as St_area_countryModel;
 
 class WriteSports extends Controller{
     public function init() {
@@ -82,6 +83,55 @@ class WriteSports extends Controller{
         //根据球类代码获取相关model
         $model = $this->commonFunction->getModels($game_code,1);
         $data = $opt['data'];
+        if(empty($data['belong'])) Render([], '10013', lang('Tips','Sports')->get('country_error'));
+        //获取联赛所属 国家/地区id
+        $belong = St_area_countryModel::getID($data['belong']);
+        $set_lg['area_id'] = $belong['area_id'];
+        $set_lg['country_id'] = $belong['country_id'];
+
+        //查询是否 已存在
+        $post = lm($model['model_league'],'Sports')
+            ->select('id as m_lg_id')
+            ->where('name_chinese','=',$data['name_chinese'])
+            ->first();
+
+        $m_lg_id = $post->m_lg_id;
+        //如果不存在,则写入联赛表
+        if(empty($m_lg_id)){
+            $set_lg['name_chinese'] = $data['name_chinese'];
+            $set_lg['kind'] = $data['kind'];
+            $set_lg['match_mode'] = $data['match_mode'];
+            $set_lg['if_stop'] = $data['if_stop'];
+            $set_lg['last_time'] = $data['last_time'];
+
+            $ret = lm($model['model_league'],'Sports')->insertGetId($set_lg);
+            $m_lg_id = $ret;
+            if($m_lg_id < 1) Render([], '10012', lang('Tips','Sports')->get('insert_error'));
+        }
+
+        //查询关联表是否 记录
+        $local_r = lm($model['model_local_league'],'Sports')
+            ->where(['m_lg_id'=>$m_lg_id,'lg_id'=>$data['lg_id'],'source'=>$data['source']])
+            ->count('*');
+
+        //没有记录则插入
+        if($local_r == 0){
+            $set_local = [
+                'm_lg_id'=>$m_lg_id,
+                'lg_id'=>$data['lg_id'],
+                'source'=>$data['source'],
+            ];
+            $ret = lm($model['model_local_league'],'Sports')-> insertGetId($set_local);
+            if($ret < 1) Render([], '10017', lang('Tips','Sports')->get('local_league_error'));
+        }
+        Render([], '1', lang('Tips','Sports')->get('success'));
+    }
+    //弃用
+    public function __league($opt = []){
+        $game_code = $opt['game_code'];
+        //根据球类代码获取相关model
+        $model = $this->commonFunction->getModels($game_code,1);
+        $data = $opt['data'];
 //        foreach ($opt['data'] as $k => $v){
             //验证联赛所属国家
             if(!empty($data['country_id'])){
@@ -115,6 +165,7 @@ class WriteSports extends Controller{
         Render([], '1', lang('Tips','Sports')->get('success'));
     }
 
+
     //写入赛事数据
     public function competition($opt = []){
         $game_code = $opt['game_code'];

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

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

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

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

+ 33 - 0
Application/Sports/Model/St_area_country.php

@@ -0,0 +1,33 @@
+<?php
+namespace App\Sports\Model;
+
+use \System\Model;
+
+/**
+ * Class St_country
+ * @package App\Sports\Model
+ * 国家 地区 关系
+ */
+class St_area_country extends Model
+{
+
+    protected $table = 'st_area_country';
+
+    //获取国家或地区 id
+    public static function getID($opt = ''){
+        $name = $opt;//国家或地区名称
+        $ret = self::select('id','pid')
+            ->where(['name'=>$name])
+            ->first();
+
+        if($ret->pid > 0){
+            $data['area_id'] = $ret->pid;
+            $data['country_id'] = $ret->id;
+        }else{
+            $data['area_id'] = $ret->id;
+            $data['country_id'] = 0;
+        }
+
+        return $data;
+    }
+}

+ 15 - 0
Application/Sports/Model/St_zq_local_league.php

@@ -0,0 +1,15 @@
+<?php
+namespace App\Sports\Model;
+
+use \System\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 足球 联赛 关联
+ */
+class St_zq_local_league extends Model
+{
+
+    protected $table = 'st_zq_local_league';
+}

+ 9 - 1
Biz/Common/CommonFunction.php

@@ -609,6 +609,7 @@ class CommonFunction {
                     $model_result = 'st_zq_result';
                     $model_result_record = 'st_zq_result_record';
                     $model_league_result = 'st_zq_league_result';
+                    $model_local_league = 'st_zq_local_league';
 
                     break;
                 case 'lq':
@@ -619,6 +620,8 @@ class CommonFunction {
                     $model_result = 'st_lq_result';
                     $model_result_record = 'st_lq_result_record';
                     $model_league_result = 'st_lq_league_result';
+                    $model_local_league = 'st_lq_local_league';
+
                     break;
                 case 'wq':
                     $model_league = 'st_wq_league';
@@ -628,6 +631,8 @@ class CommonFunction {
                     $model_result = 'st_wq_result';
                     $model_result_record = 'st_wq_result_record';
                     $model_league_result = 'st_wq_league_result';
+                    $model_local_league = 'st_wq_local_league';
+
                     break;
                 case 'bq':
                     $model_league = 'st_bq_league';
@@ -637,6 +642,8 @@ class CommonFunction {
                     $model_result = 'st_bq_result';
                     $model_result_record = 'st_bq_result_record';
                     $model_league_result = 'st_bq_league_result';
+                    $model_local_league = 'st_bq_local_league';
+
                     break;
                 case 'gj':
                     $model_league = 'st_zq_league';
@@ -692,7 +699,8 @@ class CommonFunction {
             'model_result' =>$model_result,
             'model_odds_record' => $model_odds_record,
             'model_result_record' =>$model_result_record,
-            'model_league_result'=>$model_league_result
+            'model_league_result'=>$model_league_result,
+            'model_local_league'=>$model_local_league,
         ];
         return $data;
     }