浏览代码

新增推送 追加数据入库接口调整 5/21

彭俊 6 年之前
父节点
当前提交
b51645c0dc

+ 20 - 14
Application/Api/Controller/Betorder.php

@@ -100,7 +100,7 @@ class Betorder extends BaseController{
             $num = $k + 1;
             if(empty($v['bet_amount'])){
                 $msg = '第'.$num.'条'.lang('Errors','Api')->get('error-5105');
-                Render([], '510511111',$msg);
+                Render([], '5105',$msg);
             }
             //根据类型分组
             if(!isset($res[$v['ballId']])){
@@ -160,7 +160,7 @@ class Betorder extends BaseController{
                 //插入数据源
                 $moneyBuyMatch = lm('MoneyBuyMatch','Api')->insert($matchData);
                 if(!$moneyBuyMatch){
-                    Render('','-1005',lang('errors','Api')->get('error-3205'));
+                    Render('','3205',lang('errors','Api')->get('error-3205'));
                 }
             }
             $order =[
@@ -178,7 +178,7 @@ class Betorder extends BaseController{
             ];
             $insert = lm("MoneyBuySimplex",'Api')->insert($order);
             if(!$insert){
-                Render('','-1005',lang('errors','Api')->get('error-3205'));
+                Render('','3205',lang('errors','Api')->get('error-3205'));
             }
             $insertMoney  = $this->M->insertMoney($userInfo['account_identity'],$bet_money,$OrderID,1,"",$UUID,$userInfo);
             if($insertMoney!=1){
@@ -189,6 +189,7 @@ class Betorder extends BaseController{
     }
 
     public function Bet(){
+
         $userInfo = $this->getAgent();//获取用户信息
         $data = $_REQUEST['data'];
         $bet_money = $_REQUEST['bet_money'];
@@ -304,24 +305,29 @@ class Betorder extends BaseController{
         $models = $this->commonFunction->getModels($game_code);
         $model_odds = $models['model_odds'];
         $model_odds_record = $models['model_odds_record'];
-
+        //查询赔率记录是否存在该赔率
+        $is_odds = lm($model_odds_record,'Sports')
+            ->select('odds')
+            ->where($model_odds_record.'.odds_only',$odds_only)
+            ->first();
+        if(empty($is_odds)){
+            $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7026');
+            Render([], '7026', $msg);
+        }
+        //匹配赔率是否过期
         $odds_info = lm($model_odds,'Sports')
             ->join($model_odds_record,$model_odds_record.'.odds_only',$model_odds.'.odds_only')
             ->select($model_odds_record.'.odds',$model_odds_record.'.condition')
             ->where($model_odds.'.odds_only',$odds_only)
             ->first();
         if(empty($odds_info)){
-            $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7029');
-            Render([], '70291', $msg);
+            $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7027');
+            Render([], '7027', $msg);
         }
         $odds_info = $odds_info->toarray();
-        if($odds != $odds_info['odds']){
-            $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7029');
-            Render([], '70292', $msg);
-        }
         if($condition != $odds_info['condition']){
-            $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7029');
-            Render([], '70293', $msg);
+            $msg = '第'.$num.'条数据'.lang('Errors','Api')->get('error-7025');
+            Render([], '7025', $msg);
         }
         return $odds_info;
     }
@@ -479,7 +485,7 @@ class Betorder extends BaseController{
         $moneyBuy = lm('MoneyBuyStr','Api')->insert($orderData);
 
         if(!$moneyBuy){
-            Render('','-1005',lang('errors','Api')->get('error-3205'));
+            Render('','3205',lang('errors','Api')->get('error-3205'));
         }
 
 
@@ -509,7 +515,7 @@ class Betorder extends BaseController{
         //写赔率数据表
         $moneyBuyMatch = lm('MoneyBuyMatch','Api')->insert($matchData);
         if(!$moneyBuyMatch){
-            Render('','-1005',lang('errors','Api')->get('error-3205'));
+            Render('','3205',lang('errors','Api')->get('error-3205'));
         }
 
         return true;

+ 1 - 0
Application/Api/Controller/UserBuy.php

@@ -87,6 +87,7 @@ class UserBuy extends BaseController {
             $moneyRechargeClass = new MoneyRecharge();
             // 获取充值记录
             $result = $moneyRechargeClass -> rechargeRecord();
+            $result['code'] = 1;
             $code = 1;
             $msg = lang('Index','Api') -> get('success');
 

+ 5 - 1
Application/Api/Lang/Errors.php

@@ -421,9 +421,13 @@ return array(
     'error-500144' => '添加充值REMARK记录失败',
     'error-500145' => '增加用户账户资金失败',
     'error-500146' => '扣减用户账户资金失败',
+    'error-500147' => '未获取到流水信息',
 
+    'error-7025' => '赔率条件不匹配',
+    'error-7026' => '赔率数据不匹配',
+    'error-7027' => '赔率数据过期',
     'error-7028' => '请传入集合',
-    'error-7029' => '赔率数据不存在',
+    'error-7029' => '未获取到赔率数据',
     'error-7030' => '未提交用户名',
     'error-7031' => '缺少用户名前缀',
     'error-7032' => '注册失败',

+ 6 - 6
Application/Api/Model/MoneyBuy.php

@@ -115,7 +115,7 @@ class MoneyBuy extends Model {
         $begin = ($currentPage - 1) * $pageSize;
         // 获取注单
         $moneyBuyMthMdl = lm('Money_buy_match', "commons");
-        $moneyBuyMthSlt = ['status', 'bet_money', 'home_team', 'guest_team', 'condition', 'odds', 'odds_name', 'match_id', 'game_type', 'money_buy_match.odds_code'];
+        $moneyBuyMthSlt = ['status', 'bet_money', 'home_team', 'guest_team', 'condition', 'odds', 'odds_name', 'match_id', 'money_buy_match.game_code', 'money_buy_match.odds_code'];
         $getMoneyBuyMth = $moneyBuyMthMdl -> moneyBuyMatch($moneyBuyMthSlt, $moneyBuyMthWhere, $moneyBuyMthOr, $begin, $pageSize);
         $allCount = $moneyBuyMthMdl -> moneyBuyMatchTotal($moneyBuyMthWhere, $moneyBuyMthOr);
         // 获取可加注所需要的查询条件
@@ -124,7 +124,7 @@ class MoneyBuy extends Model {
         foreach ($getMoneyBuyMth as $key => $value) {
             $match_id = $value -> match_id;
             $odds_code = $value -> odds_code;
-            $gameType = $value -> game_type;
+            $gameType = $value -> game_code;
             $where = [
                 'match_id' => $match_id,
                 'odds_code' => $odds_code,
@@ -146,7 +146,7 @@ class MoneyBuy extends Model {
         }
         // 循环添加玩法和判断玩法是否可加注
         foreach ($getMoneyBuyMth as $key => $value) {
-            $typeSstOdds = $getSstOdds[$value -> game_type];
+            $typeSstOdds = $getSstOdds[$value -> game_code];
             $thisSstOdds = [
                 'match_id' => $value -> match_id,
                 'odds_code' => $value -> odds_code,
@@ -213,7 +213,7 @@ class MoneyBuy extends Model {
         $moneyBuyMthWhere['bet_type'] = 2;
         // 获取注单
         $moneyBuyMthMdl = lm('Money_buy_match', "commons");
-        $moneyBuyMthSlt = ['status', 'bet_money', 'home_team', 'guest_team', 'condition', 'odds', 'odds_name', 'match_id', 'batch_id', 'game_type', 'money_buy_match.odds_code'];
+        $moneyBuyMthSlt = ['status', 'bet_money', 'home_team', 'guest_team', 'condition', 'odds', 'odds_name', 'match_id', 'batch_id', 'money_buy_match.game_code', 'money_buy_match.odds_code'];
         $getMoneyBuyMth = $moneyBuyMthMdl -> moneyBuyMatch($moneyBuyMthSlt, $moneyBuyMthWhere, $moneyBuyMthOr, $begin, $pageSize);
         // 获取可加注所需要的查询条件
         $commonFunction = C() -> get('commonFunction');
@@ -221,7 +221,7 @@ class MoneyBuy extends Model {
         foreach ($getMoneyBuyMth as $key => $value) {
             $match_id = $value -> match_id;
             $odds_code = $value -> odds_code;
-            $gameType = $value -> game_type;
+            $gameType = $value -> game_code;
             $where = [
                 'match_id' => $match_id,
                 'odds_code' => $odds_code,
@@ -243,7 +243,7 @@ class MoneyBuy extends Model {
         }
         // 循环添加玩法和判断玩法是否可加注
         foreach ($getMoneyBuyMth as $key => $value) {
-            $typeSstOdds = $getSstOdds[$value -> game_type];
+            $typeSstOdds = $getSstOdds[$value -> game_code];
             $thisSstOdds = [
                 'match_id' => $value -> match_id,
                 'odds_code' => $value -> odds_code,

+ 2 - 1
Application/InApi/Controller/Index.php

@@ -154,7 +154,8 @@ class Index extends Controller {
 	    $key = md5(base64_encode($string).'58f306c11e6a9d4cc74723bb76b17500');
 
 	    if (isset($_REQUEST['debug'])){
-            $url = 'http://www.kaiyou-dev.com/InApi-index/dobusiness?params='.base64_encode($string).'&Key='.$key;
+            $host = $_SERVER['HTTP_HOST'];
+            $url = 'http://' . $host . '/InApi-index/dobusiness?params='.base64_encode($string).'&Key='.$key;
         }else{
             $url = 'http://sports.5gogo.com/InApi-index/dobusiness?params='.base64_encode($string).'&Key='.$key;
         }

+ 1 - 0
Application/Sports/Controller/Sports.php

@@ -78,6 +78,7 @@ class Sports extends Controller{
             ->get();
         if (!empty($data['league'])) {
             $data['league'] = $data['league']->toarray();
+//            $data['league'] = array_column($data['league'],'lg_id');
             foreach($data['league'] as $k => $v){
                 //统计当前联赛下的联赛
                 $data['league'][$k]['game_code'] = $game_code;

+ 287 - 179
Application/Sports/Controller/WriteSports.php

@@ -30,12 +30,12 @@ class WriteSports extends Controller{
 //            if(in_array('', $v)) Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR'));
 //        }
         switch ($data['title']){
-            case 'area'://地区
-                $ret = $this->area($data['data']);
-                break;
-            case 'country'://国家
-                $ret = $this->country($data['data']);
-                break;
+//            case 'area'://地区
+//                $ret = $this->area($data['data']);
+//                break;
+//            case 'country'://国家
+//                $ret = $this->country($data['data']);
+//                break;
             case 'league'://联赛
                 $ret = $this->league($data);
                 break;
@@ -48,10 +48,10 @@ class WriteSports extends Controller{
             case 'league_result'://联赛结果
                 $ret = $this->league_result($data);
                 break;
-            case 'competition_result'://赛事结果
+            case 'match_result'://赛事结果
                 $ret = $this->com_result($data);
                 break;
-            case 'competition_result_record'://赛事结果记录
+            case 'match_result_record'://赛事结果记录
                 $ret = $this->com_result_record($data);
                 break;
             case 'odds_record'://赔率记录
@@ -67,14 +67,14 @@ class WriteSports extends Controller{
         Render([], '10010', lang('Tips','Sports')->get('HANDLE_ERRORS'));
     }
 
-    //写入地区数据
-    public function area($opt = []){
+    //写入地区数据 弃用
+    public function __area($opt = []){
         $ret = lm('st_area','Sports')->insert($opt);
         return $ret;
     }
 
-    //写入国家数据
-    public function country($opt = []){
+    //写入国家数据 弃用
+    public function __country($opt = []){
         $ret = lm('st_country','Sports')->insert($opt);
         return $ret;
     }
@@ -92,13 +92,13 @@ class WriteSports extends Controller{
         $set_lg['country_id'] = $belong['country_id'];
 
         //查询中间表 是否已记录
-        $m_lg_id = lm($model['model_local_league'],'Sports')
-            ->select('m_lg_id')
-            ->where(['lg_id'=>$data['lg_id'],'source'=>$data['source']])
-            ->first()->m_lg_id;
+        $g_id = lm($model['model_local_league'],'Sports')
+            ->select('lg_id')
+            ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
+            ->first()->lg_id;
 
         //如果没有记录
-        if(empty($m_lg_id)){
+        if(empty($lg_id)){
             //查询联赛是否已存在
             $id = lm($model['model_league'],'Sports')
                 ->select('id')
@@ -117,8 +117,8 @@ class WriteSports extends Controller{
                 if($m_lg_id < 1) Render([], '10012', lang('Tips','Sports')->get('insert_error'));
             }
             $set_local = [
-                'm_lg_id'=>$id,
-                'lg_id'=>$data['lg_id'],
+                'lg_id'=>$id,
+                'others_lg_id'=>$data['lg_id'],
                 'source'=>$data['source'],
             ];
             $ret = lm($model['model_local_league'],'Sports')-> insertGetId($set_local);
@@ -175,20 +175,18 @@ class WriteSports extends Controller{
 
         if(empty($data['lg_id'])) Render([], '10015', lang('Tips','Sports')->get('league_error'));
 
-        //验证赛事所属联赛
-        if(!empty($data['lg_id'])){
-            $lg = lm($model['model_local_league'],'Sports')
-                ->select('m_lg_id')
-                ->where(['lg_id'=>$data['lg_id'],'source'=>$data['source']])
-                ->first()->m_lg_id;
-            if(empty($lg)) Render([], '10015', lang('Tips','Sports')->get('league_error'));
-        }
+        //根据源联赛ID 获取本地关联id
+        $lg_id = lm($model['model_local_league'],'Sports')
+            ->select('lg_id')
+            ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
+            ->first()->lg_id;
+        if(empty($lg_id)) 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;
+            ->select('match_id')
+            ->where(['others_match_id'=>$data['match_id'],'source'=>$data['source']])
+            ->first()->match_id;
         if(empty($match_id)){
             //查询赛事是否存在
             $id = lm($model['model_match'],'Sports')
@@ -198,16 +196,30 @@ class WriteSports extends Controller{
 
             //写入赛事
             if(empty($id)){
-                $data['ctime'] = $this->newTime;
-                $data['utime'] = $this->newTime;
-                $data['expire_time'] = date('Y-m-d H:m:i',(time()+60));
+                $set_match = [
+                    'ctime'=>$this->newTime,
+                    'utime'=>$this->newTime,
+                    'expire_time'=>date('Y-m-d H:m:i',time()+60),
+                    'home_team'=>$data['home_team'],
+                    'guest_team'=>$data['guest_team'],
+                    'lg_id'=>$lg_id,
+                    'status'=>$data['status'],
+                    'match_date'=>$data['match_date'],
+                    'match_time'=>$data['match_time'],
+                    'tag'=>$data['tag'],
+                    'is_rollball'=>$data['is_rollball'],
+                    'is_today'=>$data['is_today'],
+                    'is_morningplate'=>$data['is_morningplate'],
+                    'is_stringscene'=>$data['is_stringscene'],
+                    'us_time'=>$data['us_time'],
+                ];
 
-                $id = lm($model['model_match'],'Sports')->insertGetId($data);
+                $id = lm($model['model_match'],'Sports')->insertGetId($set_match);
                 if($id < 1) Render([], '10012', lang('Tips','Sports')->get('insert_error'));
             }
             $set_local = [
-                'm_match_id'=>$id,
-                'match_id'=>$data['match_id'],
+                'match_id'=>$id,
+                'others_match_id'=>$data['match_id'],
                 'source'=>$data['source'],
             ];
             $ret = lm($model['model_local_match'],'Sports')-> insertGetId($set_local);
@@ -254,36 +266,61 @@ class WriteSports extends Controller{
         //根据球类代码获取相关model
         $model = $this->commonFunction->getModels($game_code,1);
         $data = $opt['data'];
-//        foreach ($opt['data'] as $k => $v){
-            //验证赔率所属赛事
-            if(!empty($data['match_id'])){
-                $match = lm($model['model_match'],'Sports')
-                    ->where(['match_id'=>$data['match_id']])
-                    ->count();
-                if($match < 1) Render([], '10016', lang('Tips','Sports')->get('match_error'));
-            }
-            //验证赔率所属联赛 冠军盘口
-            if(!empty($data['lg_id'])){
-                $lg = lm($model['model_league'],'Sports')
-                    ->where(['lg_id'=>$data['lg_id']])
-                    ->count();
-                if($lg < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
-            }
-            $post = lm($model['model_odds'],'Sports')
-                ->where(['match_id'=>$data['match_id'],'odds_code'=>$data['odds_code'],'sort'=>$data['sort']])
-                ->count();
-            //更新操作
-            if($post > 0){
-                $ret = lm($model['model_odds'],'Sports')
-                    ->where(['match_id'=>$data['match_id'],'odds_code'=>$data['odds_code'],'sort'=>$data['sort']])
-                    -> update($data);
-                if($ret < 1) Render([], '10011', lang('Tips','Sports')->get('update_error'));
-            }else{
-                //写入操作
-                $ret = lm($model['model_odds'],'Sports')->insert($data);
-                if($ret != true) Render([], '10012', lang('Tips','Sports')->get('insert_error'));
-            }
-//        }
+
+        $match = lm($model['model_local_match'],'Sports')
+            ->select('match_id','others_match_id')
+            ->where(['others_match_id'=>$data['match_id'],'source'=>$data['source']])
+            ->first();
+        if(count($match) < 1) Render([], '10016', lang('Tips','Sports')->get('match_error'));
+
+        //获取赛事 本地/源ID
+        $others_match_id = $match->others_match_id;
+        $match_id = $match->match_id;
+
+        $lg = lm($model['model_local_league'],'Sports')
+            ->select('lg_id','others_lg_id')
+            ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
+            ->first();
+        if(count($lg) < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
+
+        //获取联赛 本地/源ID
+        $others_lg_id = $lg->others_lg_id;
+        $lg_id = $lg->lg_id;
+        //查询 赔率数据是否存在
+        $oddsID = lm($model['model_odds'],'Sports')
+            ->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']])
+            ->value('id');
+
+        $set_odds = [
+            'match_id'=> $match_id,
+            'others_match_id'=> $others_match_id,
+            'odds_code'=> $data['odds_code'],
+            'status'=> $data['status'],
+            'sort'=> $data['sort'],
+            'p_code'=> $data['p_code'],
+            'odds'=> $data['odds'],
+            'condition'=> $data['condition'],
+            'odds_only'=> $data['odds_only'],
+            'sole'=> $data['sole'],
+            'source'=> $data['source'],
+            'type'=> $data['type'],
+            'team'=> $data['team'],
+            'lg_id'=> $lg_id,
+            'others_lg_id'=> $others_lg_id,
+            'ctime'=> $this->newTime,
+            'utime'=> $this->newTime,
+            'expire_time'=>date('Y-m-d H:m:i',time()+60),
+        ];
+        //更新或写入赔率数据
+        if(!empty($oddsID)){
+            $ret = lm($model['model_odds'],'Sports')
+                ->where(['id'=>$oddsID])
+                -> update($set_odds);
+            if($ret < 1) Render([], '10019', lang('Tips','Sports')->get('add_odds_error'));
+        }else{
+            $ret = lm($model['model_odds'],'Sports')->insert($set_odds);
+            if($ret != true) Render([], '10019', lang('Tips','Sports')->get('add_odds_error'));
+        }
         Render([], '1', lang('Tips','Sports')->get('success'));
     }
 
@@ -293,29 +330,35 @@ class WriteSports extends Controller{
         //根据球类代码获取相关model
         $model = $this->commonFunction->getModels($game_code,1);
         $data = $opt['data'];
-//        foreach ($opt['data'] as $k => $v){
-            //验证结果所属联赛
-            if(!empty($data['lg_id'])){
-                $lg = lm($model['model_league'],'Sports')
-                    ->where(['lg_id'=>$data['lg_id']])
-                    ->count();
-                if($lg < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
-            }
-            $post = lm($model['model_league_result'],'Sports')
-                ->where(['lg_id'=>$data['lg_id'],'game_name'=>$data['game_name']])
-                ->count();
-            //更新操作
-            if($post > 0){
-                $ret = lm($model['model_league_result'],'Sports')
-                    ->where(['lg_id'=>$data['lg_id'],'game_name'=>$data['game_name']])
-                    -> update($data);
-                if($ret < 1) Render([], '10011', lang('Tips','Sports')->get('update_error'));
-            }else{
-                //写入操作
-                $ret = lm($model['model_league_result'],'Sports')->insert($data);
-                if($ret != true) Render([], '10012', lang('Tips','Sports')->get('insert_error'));
-            }
-//        }
+
+        //验证结果所属联赛
+        $lg_id = lm($model['model_local_league'],'Sports')
+            ->select('lg_id')
+            ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
+            ->first()->lg_id;
+        if($lg_id < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
+
+        $lg_result_id = lm($model['model_league_result'],'Sports')
+            ->where(['lg_id'=>$lg_id,'game_name'=>$data['game_name']])
+            ->value('id');
+        $set_lg_result = [
+            'lg_id'=>$lg_id,
+            'game_name'=>$data['game_name'],
+            'result'=>json_encode($data['result'],JSON_UNESCAPED_UNICODE),
+            'status'=>$data['status'],
+            'ctime'=> $this->newTime,
+            'utime'=> $this->newTime,
+        ];
+        //联赛结果数据处理
+        if(!empty($lg_result_id)){
+            $ret = lm($model['model_league_result'],'Sports')
+                ->where(['id'=>$lg_result_id])
+                -> update($set_lg_result);
+            if($ret < 1) Render([], '10021', lang('Tips','Sports')->get('add_lg_r_error'));
+        }else{
+            $ret = lm($model['model_league_result'],'Sports')->insert($set_lg_result);
+            if($ret != true) Render([], '10021', lang('Tips','Sports')->get('add_lg_r_error'));
+        }
         Render([], '1', lang('Tips','Sports')->get('success'));
     }
 
@@ -325,36 +368,56 @@ class WriteSports extends Controller{
         //根据球类代码获取相关model
         $model = $this->commonFunction->getModels($game_code,1);
         $data = $opt['data'];
-//        foreach ($opt['data'] as $k => $v){
-            //验证结果所属联赛
-            if(!empty($data['lg_id'])){
-                $lg = lm($model['model_league'],'Sports')
-                    ->where(['lg_id'=>$data['lg_id']])
-                    ->count();
-                if($lg < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
-            }
-            //验证结果所属赛事
-            if(!empty($data['match_id'])){
-                $lg = lm($model['model_match'],'Sports')
-                    ->where(['match_id'=>$data['match_id']])
-                    ->count();
-                if($lg < 1) Render([], '10016', lang('Tips','Sports')->get('match_error'));
-            }
-            $post = lm($model['model_result'],'Sports')
-                ->where(['match_id'=>$data['match_id']])
-                ->count();
-            //更新操作
-            if($post > 0){
-                $ret = lm($model['model_result'],'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_result'],'Sports')->insert($data);
-                if($ret != true) Render([], '10012', lang('Tips','Sports')->get('insert_error'));
-            }
-//        }
+        //验证结果所属联赛
+        $lg_id = lm($model['model_local_league'],'Sports')
+            ->select('lg_id')
+            ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
+            ->first()->lg_id;
+        if($lg_id < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
+        //验证结果所属赛事
+        $match_id = lm($model['model_local_match'],'Sports')
+            ->select('match_id')
+            ->where(['others_match_id'=>$data['match_id'],'source'=>$data['source']])
+            ->value('match_id');
+        if($match_id < 1) Render([], '10016', lang('Tips','Sports')->get('match_error'));
+        //查询结果是否存在
+        $match_r_id = lm($model['model_result'],'Sports')
+            ->where(['match_id'=>$match_id])
+            ->value('id');
+
+        $set_match_r = [
+            "home_team"=>$data['home_team'],
+            "guest_team"=>$data['guest_team'],
+            "lg_id"=>$lg_id,
+            "home_rate"=> $data['home_rate'],
+            "guest_rate"=> $data['guest_rate'],
+            "home_score"=> $data['home_score'],
+            "guest_score"=> $data['guest_score'],
+            "all_goal"=> $data['all_goal'],
+            "status"=>$data['status'],
+            "first_score"=>$data['first_score'],
+            "last_score"=> $data['last_score'],
+            "match_score"=> $data['match_score'],
+            "match_winer"=> $data['match_winer'],
+            "match_time"=> $data['match_time'],
+            "match_process"=> $data['match_process'],
+            "tag"=> $data['tag'],
+            "match_id"=> $match_id,
+            "u_home_score"=> $data['u_home_score'],
+            "u_guest_score"=> $data['u_guest_score'],
+            "p_code"=> $data['p_code'],
+            "update_time"=>$this->newTime
+        ];
+        //赛事结果数据处理
+        if(!empty($match_r_id)){
+            $ret = lm($model['model_result'],'Sports')
+                -> where(['id'=>$match_r_id])
+                -> update($set_match_r);
+            if($ret < 1) Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
+        }else{
+            $ret = lm($model['model_result'],'Sports')->insert($set_match_r);
+            if($ret != true) Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
+        }
         Render([], '1', lang('Tips','Sports')->get('success'));
     }
 
@@ -364,36 +427,56 @@ class WriteSports extends Controller{
         //根据球类代码获取相关model
         $model = $this->commonFunction->getModels($game_code,1);
         $data = $opt['data'];
-//        foreach ($opt['data'] as $k => $v){
-            //验证结果所属联赛
-            if(!empty($data['lg_id'])){
-                $lg = lm($model['model_league'],'Sports')
-                    ->where(['lg_id'=>$data['lg_id']])
-                    ->count();
-                if($lg < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
-            }
-            //验证结果所属赛事
-            if(!empty($data['match_id'])){
-                $lg = lm($model['model_match'],'Sports')
-                    ->where(['match_id'=>$data['match_id']])
-                    ->count();
-                if($lg < 1) Render([], '10016', lang('Tips','Sports')->get('match_error'));
-            }
-            $post = lm($model['model_result_record'],'Sports')
-                ->where(['match_id'=>$data['match_id'],'match_time'=>$data['match_time']])
-                ->count();
-            //更新操作
-            if($post > 0){
-                $ret = lm($model['model_result_record'],'Sports')
-                    ->where(['match_id'=>$data['match_id'],'match_time'=>$data['match_time']])
-                    -> update($data);
-                if($ret < 1) Render([], '10011', lang('Tips','Sports')->get('update_error'));
-            }else{
-                //写入操作
-                $ret = lm($model['model_result_record'],'Sports')->insert($data);
-                if($ret != true) Render([], '10012', lang('Tips','Sports')->get('insert_error'));
-            }
-//        }
+        //验证结果所属联赛
+        $lg_id = lm($model['model_local_league'],'Sports')
+            ->select('lg_id')
+            ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
+            ->first()->lg_id;
+        if($lg_id < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
+        //验证结果所属赛事
+        $match_id = lm($model['model_local_match'],'Sports')
+            ->select('match_id')
+            ->where(['others_match_id'=>$data['match_id'],'source'=>$data['source']])
+            ->value('match_id');
+        if($match_id < 1) Render([], '10016', lang('Tips','Sports')->get('match_error'));
+
+        $match_r_id = lm($model['model_result_record'],'Sports')
+            ->where(['match_id'=>$match_id,'match_time'=>$data['match_time']])
+            ->value('id');
+        $set_match_r = [
+            "home_team"=>$data['home_team'],
+            "guest_team"=>$data['guest_team'],
+            "lg_id"=>$lg_id,
+            "home_rate"=> $data['home_rate'],
+            "guest_rate"=> $data['guest_rate'],
+            "home_score"=> $data['home_score'],
+            "guest_score"=> $data['guest_score'],
+            "all_goal"=> $data['all_goal'],
+            "status"=>$data['status'],
+            "first_score"=>$data['first_score'],
+            "last_score"=> $data['last_score'],
+            "match_score"=> $data['match_score'],
+            "match_winer"=> $data['match_winer'],
+            "match_time"=> $data['match_time'],
+            "match_process"=> $data['match_process'],
+            "tag"=> $data['tag'],
+            "match_id"=> $match_id,
+            "p_code"=> $data['p_code'],
+            "update_time"=>$this->newTime
+        ];
+        //更新操作
+        if($match_r_id > 0){
+            $ret = lm($model['model_result_record'],'Sports')
+                ->where(['id'=>$match_r_id])
+                ->update($set_match_r);
+
+            dd($ret);
+            if($ret < 1) Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
+        }else{
+            //写入操作
+            $ret = lm($model['model_result_record'],'Sports')->insert($set_match_r);
+            if($ret != true) Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
+        }
         Render([], '1', lang('Tips','Sports')->get('success'));
     }
 
@@ -403,36 +486,59 @@ class WriteSports extends Controller{
         //根据球类代码获取相关model
         $model = $this->commonFunction->getModels($game_code,1);
         $data = $opt['data'];
-//        foreach ($opt['data'] as $k => $v){
-            //验证赔率所属赛事
-            if(!empty($data['match_id'])){
-                $match = lm($model['model_match'],'Sports')
-                    ->where(['match_id'=>$data['match_id']])
-                    ->count();
-                if($match < 1) Render([], '10016', lang('Tips','Sports')->get('match_error'));
-            }
-            //验证赔率所属联赛 冠军盘口
-            if(!empty($data['lg_id'])){
-                $lg = lm($model['model_league'],'Sports')
-                    ->where(['lg_id'=>$data['lg_id']])
-                    ->count();
-                if($lg < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
-            }
-            $post = lm($model['model_odds_record'],'Sports')
-                ->where(['match_id'=>$data['match_id'],'odds_code'=>$data['odds_code'],'sort'=>$data['sort']])
-                ->count();
-            //更新操作
-            if($post > 0){
-                $ret = lm($model['model_odds_record'],'Sports')
-                    ->where(['match_id'=>$data['match_id'],'odds_code'=>$data['odds_code'],'sort'=>$data['sort']])
-                    ->update($data);
-                if($ret < 1) Render([], '10011', lang('Tips','Sports')->get('update_error'));
-            }else{
-                //写入操作
-                $ret = lm($model['model_odds_record'],'Sports')->insert($data);
-                if($ret != true) Render([], '10012', lang('Tips','Sports')->get('insert_error'));
-            }
-//        }
+
+        $match = lm($model['model_local_match'],'Sports')
+            ->select('match_id','others_match_id')
+            ->where(['others_match_id'=>$data['match_id'],'source'=>$data['source']])
+            ->first();
+        if(count($match) < 1) Render([], '10016', lang('Tips','Sports')->get('match_error'));
+
+        //获取赛事 本地/源ID
+        $others_match_id = $match->others_match_id;
+        $match_id = $match->match_id;
+
+        $lg = lm($model['model_local_league'],'Sports')
+            ->select('lg_id','others_lg_id')
+            ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
+            ->first();
+        if(count($lg) < 1) Render([], '10015', lang('Tips','Sports')->get('league_error'));
+
+        //获取联赛 本地/源ID
+        $others_lg_id = $lg->others_lg_id;
+        $lg_id = $lg->lg_id;
+        //查询 赔率数据是否存在
+        $oddsID = lm($model['model_odds_record'],'Sports')
+            ->where(['odds_only'=>$data['odds_only']])
+            ->value('id');
+
+        $set_odds = [
+            'match_id'=> $match_id,
+            'others_match_id'=> $others_match_id,
+            'odds_code'=> $data['odds_code'],
+            'status'=> $data['status'],
+            'sort'=> $data['sort'],
+            'p_code'=> $data['p_code'],
+            'odds'=> $data['odds'],
+            'condition'=> $data['condition'],
+            'odds_only'=> $data['odds_only'],
+            'source'=> $data['source'],
+            'type'=> $data['type'],
+            'team'=> $data['team'],
+            'lg_id'=> $lg_id,
+            'others_lg_id'=> $others_lg_id,
+            'ctime'=> $this->newTime,
+            'utime'=> $this->newTime,
+        ];
+        //更新或写入赔率记录
+        if(!empty($oddsID)){
+            $ret = lm($model['model_odds_record'],'Sports')
+                ->where(['id'=>$oddsID])
+                -> update($set_odds);
+            if($ret < 1) Render([], '10020', lang('Tips','Sports')->get('add_odds_r_error'));
+        }else{
+            $ret = lm($model['model_odds_record'],'Sports')->insert($set_odds);
+            if($ret != true) Render([], '10020', lang('Tips','Sports')->get('add_odds_r_error'));
+        }
         Render([], '1', lang('Tips','Sports')->get('success'));
     }
 
@@ -442,7 +548,9 @@ class WriteSports extends Controller{
      * json转数组
      */
     public function getAddData($data){
+
         $data = json_decode($data,true);
+
         return $data;
     }
 }

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

@@ -44,8 +44,15 @@ return array(
     'error-10014' => '地区不存在',
     'error-10015' => '联赛不存在',
     'error-10016' => '赛事不存在',
-    'error-10017' => '插入联赛关联记录失败',
-    'error-10018' => '插入赛事关联记录失败',
+    'error-10017' => '写入联赛关联记录失败',
+    'error-10018' => '写入赛事关联记录失败',
+    'error-10019' => '赛事赔率数据写入失败',
+    'error-10020' => '赛事赔率记录写入失败',
+    'error-10021' => '联赛结果写入失败',
+    'error-10022' => '赛事结果写入失败',
+
+
+
 
 
 

+ 5 - 3
Application/Sports/Lang/Tips.php

@@ -14,9 +14,11 @@ return array(
     'area_error' =>'地区不存在',
     'league_error' =>'联赛不存在',
     'match_error' =>'赛事不存在',
-    'local_league_error' =>'插入联赛关联记录失败',
-    'local_match_error' =>'插入联赛关联记录失败',
-
+    'local_league_error' =>'写入联赛关联记录失败',
+    'add_odds_error' =>'赛事赔率写入失败',
+    'add_odds_r_error' =>'赛事赔率记录写入失败',
+    'add_lg_r_error' =>'联赛结果写入失败',
+    'add_match_r_error' =>'赛事结果写入失败',
 
 
     // ====end===

+ 2 - 3
Biz/Money/Money.php

@@ -204,8 +204,8 @@ class Money {
 	{
 		//查询最后一条资金余额
 		$last_data = lm($this->money_details, 'commons')->where('account_identity', $account_identity)->orderBy('id', 'desc')->first();
-		if (!$last_data) {
-			return -2113;
+		if (empty($last_data)) {
+			return -500147;
 		}
 		$last_data = $last_data->toArray();
 		if ($last_data['money_cash'] != $NowCash) {
@@ -214,7 +214,6 @@ class Money {
 		return 1;
 	}
 
-
 	/**
 	 * 验证交易密码
 	 * @param  [type] $account_identity 用户唯一id