Forráskód Böngészése

赛事接口追加球队数据处理

彭俊 6 éve
szülő
commit
f0775002b5

+ 10 - 0
app/Http/Controllers/Api/WriteSportsController.php

@@ -23,6 +23,7 @@ use App\Http\Model\StZqOddsRecord as OddsRecordModel;
 use App\Http\Model\StZqResult as ZqResultModel;
 use App\Http\Model\St_area_country as StAreaCountryModel;
 use App\Http\Model\St_set_sports_record  as St_set_sports_recordModel;
+use App\Http\Model\St_team as StTeamModel;
 
 /**
  * 体育数据入库接口
@@ -518,6 +519,8 @@ class WriteSportsController extends BaseController{
                 $s_match_ids[] = $v['match_id'];
             }
 
+            
+
             //====验证 赛事 所属 联赛 是否存在====
             $identity = array_unique($identity);
             sort($identity);
@@ -670,6 +673,13 @@ class WriteSportsController extends BaseController{
                             ];
                             $ret = $models['model_local_match']::insertGetId($set_local);
                             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'));
+                        
+                            //追加写球队名称
+                            $team = [
+                                'team_h'=>$data['home_team'],
+                                'team_g'=>$data['guest_team'],
+                            ];
+                            $setTeame = StTeamModel::setTeam($game_code,$team);
                         }
                     }
                 }

+ 46 - 0
app/Http/Model/St_team.php

@@ -0,0 +1,46 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+use App\Http\Response\Response;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 数据源球队model
+ */
+class St_team extends Model
+{
+
+    protected $table = 'st_team';
+    public $timestamps = false;
+
+    /**
+     * 写入数据源球队数据
+     * $game_code 球类代码
+     * $team 球队名称
+     */
+    public static function setTeam($game_code,$teamNameArr=[]){
+        if(!empty($game_code) and !empty($teamNameArr)){
+            //拼装数据
+            foreach($teamNameArr as $k => $teamName){
+                $set_arr[] = [
+                    'game_type' => $game_code,
+                    'team_name_cn' => $teamName,
+                    'status' => 1,
+                    'update_time' => date('Y-m-d H:i:s')
+                ];
+            }
+
+            //循环写入/更新
+            foreach($set_arr as $k =>$set){
+                $ret = self::updateOrInsert(
+                    ['game_type' => $game_code, 'team_name_cn' => $set['team_name_cn']],
+                    ['status' => $set['status'],'update_time' => $set['update_time']]
+                );
+
+                if(empty($ret)) return Response::generate('',Response::SET_TEAM_ERR);
+            }
+        }
+    }
+}

+ 5 - 0
app/Http/Response/Response.php

@@ -50,6 +50,9 @@ class Response
     //删除历史直播数据
     const DEL_PAST_BROADCAST_ERR = 10039;
 
+    //球队数据处理失败
+    const SET_TEAM_ERR = 10040;
+
 
     private static $errorMsgs = [
         self::SUCCESS => '成功',
@@ -93,6 +96,8 @@ class Response
         self::L_MATCH_ID_ERR=>'未获取到赔率所属本地赛事id',
         //===删除历史直播数据失败===
         self::DEL_PAST_BROADCAST_ERR=>'删除历史直播数据失败',
+        //===球队数据处理失败===
+        self::SET_TEAM_ERR =>'球队数据处理失败'
 
     ];