vali 6 yıl önce
işleme
7c12a40eea
63 değiştirilmiş dosya ile 5390 ekleme ve 0 silme
  1. 16 0
      app/Http/Model/StBqBroadcast.php
  2. 19 0
      app/Http/Model/StBqLeague.php
  3. 17 0
      app/Http/Model/StBqLeagueResult.php
  4. 17 0
      app/Http/Model/StBqLocalLeague.php
  5. 17 0
      app/Http/Model/StBqLocalMatch.php
  6. 19 0
      app/Http/Model/StBqMatch.php
  7. 18 0
      app/Http/Model/StBqOdds.php
  8. 18 0
      app/Http/Model/StBqOddsRecord.php
  9. 99 0
      app/Http/Model/StBqResult.php
  10. 16 0
      app/Http/Model/StBqResultRecord.php
  11. 16 0
      app/Http/Model/StBroadcast.php
  12. 22 0
      app/Http/Model/StGameType.php
  13. 16 0
      app/Http/Model/StLqBroadcast.php
  14. 19 0
      app/Http/Model/StLqLeague.php
  15. 17 0
      app/Http/Model/StLqLeagueResult.php
  16. 17 0
      app/Http/Model/StLqLocalLeague.php
  17. 17 0
      app/Http/Model/StLqLocalMatch.php
  18. 19 0
      app/Http/Model/StLqMatch.php
  19. 19 0
      app/Http/Model/StLqOdds.php
  20. 18 0
      app/Http/Model/StLqOddsRecord.php
  21. 111 0
      app/Http/Model/StLqResult.php
  22. 16 0
      app/Http/Model/StLqResultRecord.php
  23. 18 0
      app/Http/Model/StSettlementMiddleDetail.php
  24. 16 0
      app/Http/Model/StWqBroadcast.php
  25. 19 0
      app/Http/Model/StWqLeague.php
  26. 17 0
      app/Http/Model/StWqLeagueResult.php
  27. 17 0
      app/Http/Model/StWqLocalLeague.php
  28. 17 0
      app/Http/Model/StWqLocalMatch.php
  29. 19 0
      app/Http/Model/StWqMatch.php
  30. 19 0
      app/Http/Model/StWqOdds.php
  31. 17 0
      app/Http/Model/StWqOddsRecord.php
  32. 99 0
      app/Http/Model/StWqResult.php
  33. 16 0
      app/Http/Model/StWqResultRecord.php
  34. 16 0
      app/Http/Model/StZqBroadcast.php
  35. 19 0
      app/Http/Model/StZqLeague.php
  36. 17 0
      app/Http/Model/StZqLeagueResult.php
  37. 28 0
      app/Http/Model/StZqLocalLeague.php
  38. 28 0
      app/Http/Model/StZqLocalMatch.php
  39. 19 0
      app/Http/Model/StZqMatch.php
  40. 83 0
      app/Http/Model/StZqOdds.php
  41. 29 0
      app/Http/Model/StZqOddsRecord.php
  42. 98 0
      app/Http/Model/StZqResult.php
  43. 16 0
      app/Http/Model/StZqResultRecord.php
  44. 35 0
      app/Http/Model/St_area_country.php
  45. 19 0
      app/Http/Model/SystemUser.php
  46. 104 0
      app/Http/Response/Response.php
  47. 1209 0
      app/Lib/Biz/Sport/Common.php
  48. 62 0
      app/Lib/ModelBase.php
  49. 15 0
      app/Lib/TestModel.php
  50. 1228 0
      app/Logic/DataLogic.php
  51. 231 0
      app/Models/System_user.php
  52. 15 0
      commands/bootHttp.php
  53. 61 0
      commands/clientws3.php
  54. 115 0
      commands/clientws4.php
  55. 3 0
      commands/init.sh
  56. 29 0
      composer.json
  57. 757 0
      composer.lock
  58. 53 0
      datainf/lib/GlobConfigs.php
  59. 18 0
      datainf/lib/Mconsts.php
  60. 28 0
      datainf/lib/boot.php
  61. 180 0
      datainf/logic/HttpServerDataInf.php
  62. 26 0
      datainf/pplus/Instance.php
  63. 12 0
      readme.txt

+ 16 - 0
app/Http/Model/StBqBroadcast.php

@@ -0,0 +1,16 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 足球直播数据
+ */
+class StBqBroadcast extends Model
+{
+    protected $table = 'st_bq_broadcast';
+    public $timestamps = false;
+
+}

+ 19 - 0
app/Http/Model/StBqLeague.php

@@ -0,0 +1,19 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StBqLeague extends Model
+{
+
+    protected $table = 'st_bq_league';
+    public $timestamps = false;
+
+
+}

+ 17 - 0
app/Http/Model/StBqLeagueResult.php

@@ -0,0 +1,17 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StBqLeagueResult extends Model
+{
+
+    protected $table = 'st_bq_league_result';
+    public $timestamps = false;
+
+}

+ 17 - 0
app/Http/Model/StBqLocalLeague.php

@@ -0,0 +1,17 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 足球 联赛 关联
+ */
+class StBqLocalLeague extends Model
+{
+
+    protected $table = 'st_bq_local_league';
+    public $timestamps = false;
+
+}

+ 17 - 0
app/Http/Model/StBqLocalMatch.php

@@ -0,0 +1,17 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 足球 赛事关联
+ */
+class StBqLocalMatch extends Model
+{
+
+    protected $table = 'st_bq_local_match';
+    public $timestamps = false;
+
+}

+ 19 - 0
app/Http/Model/StBqMatch.php

@@ -0,0 +1,19 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StBqMatch extends Model
+{
+
+    protected $table = 'st_bq_competition';
+    public $timestamps = false;
+
+
+}

+ 18 - 0
app/Http/Model/StBqOdds.php

@@ -0,0 +1,18 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StBqOdds extends Model
+{
+    protected $table = 'st_bq_odds';
+    public $timestamps = false;
+    protected $fillable = ['match_id','others_match_id','odds_code','status','sort','p_code','odds','condition','odds_only','sole','source','type','team','lg_id','others_lg_id','ctime','utime','expire_time'];
+
+
+}

+ 18 - 0
app/Http/Model/StBqOddsRecord.php

@@ -0,0 +1,18 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StBqOddsRecord extends Model
+{
+    protected $table = 'st_bq_odds_record';
+    public $timestamps = false;
+    protected $fillable = ['match_id','others_match_id','odds_code','status','sort','p_code','odds','condition','odds_only','source','type','team','lg_id','others_lg_id','ctime','utime'];
+
+
+}

+ 99 - 0
app/Http/Model/StBqResult.php

@@ -0,0 +1,99 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+use App\Http\Response\Response;
+
+/**
+ * Class StBqResult
+ * @package App\Http\Model
+ * 棒球 赛事 结果
+ */
+class StBqResult extends Model
+{
+    protected $table = 'st_bq_result';
+    public $timestamps = false;
+
+    /*
+     * 写赛事结果
+     */
+    public static function BQresult($model){
+        //获取赛事表7天内所有赛事
+        $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
+            ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-7 day"))]])
+            ->get()
+            ->toarray();
+
+        //没有数据,无需操作
+        if(empty($matchData)) return Response::success();
+        //获取赛事结果表 所有当月
+        $matchData_r = $model['model_result']::select('match_id')
+            ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-7 day"))]])
+            ->get()
+            ->toarray();
+
+        //结果表无数据,直接插入
+        if(empty($matchData_r)){
+            foreach ($matchData as $k=>$v){
+                $start_time = ($v['match_date'].' '.$v['match_time']);
+                $time = time()-strtotime($v['match_time']);
+                $match_time = self::secTime($time);
+                $set_match_r[] = [
+                    "match_id"=> $v['id'],
+                    "home_team"=>$v['home_team'],
+                    "guest_team"=>$v['guest_team'],
+                    "lg_id"=>$v['lg_id'],
+                    "status"=>$v['status'],
+                    "tag"=> $v['tag'],
+                    'match_time'=>$match_time,
+                    "ctime"=>date('Y-m-d H:i:s'),
+                    "update_time"=>date('Y-m-d H:i:s'),
+                    "start_time"=>date('Y-m-d H:i:s',strtotime($start_time))
+                ];
+            }
+            $ret = $model['model_result']::insert($set_match_r);
+            if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
+        }else {
+
+            //如果结果表有数据,则获取结果表没有的赛事
+            foreach ($matchData as $k => $v) {
+                foreach ($matchData_r as $kk => $vv) {
+                    if ($v['id'] == $vv['match_id']) {
+                        unset($matchData[$k]);
+                    }
+                }
+            }
+            //如果还有未写入赛事
+            if (!empty($matchData)) {
+                //写入结果表不存在赛事
+                foreach ($matchData as $k => $v) {
+                    $start_time = ($v['match_date'] . ' ' . $v['match_time']);
+                    $time = time() - strtotime($v['match_time']);
+                    $match_time = self::secTime($time);
+                    $set_match_r[] = [
+                        "match_id" => $v['id'],
+                        "home_team" => $v['home_team'],
+                        "guest_team" => $v['guest_team'],
+                        "lg_id" => $v['lg_id'],
+                        "status" => $v['status'],
+                        "tag" => $v['tag'],
+                        'match_time' => $match_time,
+                        "ctime" => date('Y-m-d H:i:s'),
+                        "update_time" => date('Y-m-d H:i:s'),
+                        "start_time" => date('Y-m-d H:i:s', strtotime($start_time))
+                    ];
+                }
+                $ret = $model['model_result']::insert($set_match_r);
+                if ($ret != true) throw new \Exception(Response::generate('', Response::ADD_MATCH_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
+            }
+        }
+        return Response::success();
+    }
+
+    //计算滚球 赛事进行时间
+    public static function secTime($sec=0){
+        $min = floor($sec/60);
+        $res = $min.':'.($sec-$min*60);
+        return $res;
+    }
+}

+ 16 - 0
app/Http/Model/StBqResultRecord.php

@@ -0,0 +1,16 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StBqResultRecord extends Model
+{
+    protected $table = 'st_bq_result_record';
+    public $timestamps = false;
+
+}

+ 16 - 0
app/Http/Model/StBroadcast.php

@@ -0,0 +1,16 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 直播数据
+ */
+class StBroadcast extends Model
+{
+    protected $table = 'st_broadcast';
+    public $timestamps = false;
+
+}

+ 22 - 0
app/Http/Model/StGameType.php

@@ -0,0 +1,22 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 球类代码
+ */
+class StGameType extends Model
+{
+    protected $table = 'st_game_type';
+    public $timestamps = false;
+
+    //根据球类代码 获取球类名称
+    public static function getGameName($game_code= ''){
+        $gameName = self::where('game_code',$game_code)->value('game_name');
+        return $gameName;
+    }
+
+}

+ 16 - 0
app/Http/Model/StLqBroadcast.php

@@ -0,0 +1,16 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 篮球直播数据
+ */
+class StLqBroadcast extends Model
+{
+    protected $table = 'st_lq_broadcast';
+    public $timestamps = false;
+
+}

+ 19 - 0
app/Http/Model/StLqLeague.php

@@ -0,0 +1,19 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StLqLeague extends Model
+{
+
+    protected $table = 'st_lq_league';
+    public $timestamps = false;
+
+
+}

+ 17 - 0
app/Http/Model/StLqLeagueResult.php

@@ -0,0 +1,17 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StLqLeagueResult extends Model
+{
+
+    protected $table = 'st_lq_league_result';
+    public $timestamps = false;
+
+}

+ 17 - 0
app/Http/Model/StLqLocalLeague.php

@@ -0,0 +1,17 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 足球 联赛 关联
+ */
+class StLqLocalLeague extends Model
+{
+
+    protected $table = 'st_lq_local_league';
+    public $timestamps = false;
+
+}

+ 17 - 0
app/Http/Model/StLqLocalMatch.php

@@ -0,0 +1,17 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 足球 赛事关联
+ */
+class StLqLocalMatch extends Model
+{
+
+    protected $table = 'st_lq_local_match';
+    public $timestamps = false;
+
+}

+ 19 - 0
app/Http/Model/StLqMatch.php

@@ -0,0 +1,19 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StLqMatch extends Model
+{
+
+    protected $table = 'st_lq_competition';
+    public $timestamps = false;
+
+
+}

+ 19 - 0
app/Http/Model/StLqOdds.php

@@ -0,0 +1,19 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StLqOdds extends Model
+{
+    protected $table = 'st_lq_odds';
+    public $timestamps = false;
+    protected $fillable = ['match_id','others_match_id','odds_code','status','sort','p_code','odds','condition','odds_only','sole','source','type','team','lg_id','others_lg_id','ctime','utime','expire_time'];
+
+
+
+}

+ 18 - 0
app/Http/Model/StLqOddsRecord.php

@@ -0,0 +1,18 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StLqOddsRecord extends Model
+{
+    protected $table = 'st_lq_odds_record';
+    public $timestamps = false;
+    protected $fillable = ['match_id','others_match_id','odds_code','status','sort','p_code','odds','condition','odds_only','source','type','team','lg_id','others_lg_id','ctime','utime'];
+
+
+}

+ 111 - 0
app/Http/Model/StLqResult.php

@@ -0,0 +1,111 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+use App\Http\Response\Response;
+
+/**
+ * Class StLqResult
+ * @package App\Http\Model
+ * 篮球 赛事 结果
+ */
+class StLqResult extends Model
+{
+    protected $table = 'st_lq_result';
+    public $timestamps = false;
+
+    /*
+     * 写赛事结果
+     */
+    public static function LQresult($model){
+        //获取赛事表7天内所有赛事
+        $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
+            ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-7 day"))]])
+            ->get()
+            ->toarray();
+
+        //没有数据,无需操作
+        if(empty($matchData)) return Response::success();
+        //获取赛事结果表 15天内
+        $matchData_r = $model['model_result']::select('match_id')
+            ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-7 day"))]])
+            ->get()
+            ->toarray();
+        //结果表无数据,直接插入
+        if(empty($matchData_r)){
+            foreach ($matchData as $k=>$v){
+                $process = 0;
+                if((int)$v['status'] == 2){
+                    $process = 4;
+                }
+                if((int)$v['status'] == 1){
+                    $process = 1;
+                }
+                $start_time = ($v['match_date'].' '.$v['match_time']);
+
+                $set_match_r[] = [
+                    "match_id"=> $v['id'],
+                    "home_team"=>$v['home_team'],
+                    "guest_team"=>$v['guest_team'],
+                    "lg_id"=>$v['lg_id'],
+                    "status"=>$v['status'],
+                    "tag"=> $v['tag'],
+                    "match_process"=>$process,
+                    'match_time'=>12,
+                    "ctime"=>date('Y-m-d H:i:s'),
+                    "update_time"=>date('Y-m-d H:i:s'),
+                    "start_time"=>date('Y-m-d H:i:s',strtotime($start_time))
+                ];
+            }
+            $ret = $model['model_result']::insert($set_match_r);
+            if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
+        }else{
+            //如果结果表有数据,则获取结果表没有的赛事
+            foreach ($matchData as $k=>$v){
+                foreach ($matchData_r as $kk=>$vv){
+                    if($v['id'] == $vv['match_id']){
+                        unset($matchData[$k]);
+                    }
+                }
+            }
+            //如果还有未写入赛事
+            if(!empty($matchData)){
+                //写入结果表不存在赛事
+                foreach ($matchData as $k=>$v){
+                    $process = 0;
+                    if((int)$v['status'] == 2){
+                        $process = 4;
+                    }
+                    if((int)$v['status'] == 1){
+                        $process = 1;
+                    }
+                    $start_time = ($v['match_date'].' '.$v['match_time']);
+
+                    $set_match_r[] = [
+                        "match_id"=> $v['id'],
+                        "home_team"=>$v['home_team'],
+                        "guest_team"=>$v['guest_team'],
+                        "lg_id"=>$v['lg_id'],
+                        "status"=>$v['status'],
+                        "tag"=> $v['tag'],
+                        "match_process"=>$process,
+                        'match_time'=>12,
+                        "ctime"=>date('Y-m-d H:i:s'),
+                        "update_time"=>date('Y-m-d H:i:s'),
+                        "start_time"=>date('Y-m-d H:i:s',strtotime($start_time))
+                    ];
+                }
+                $ret = $model['model_result']::insert($set_match_r);
+                if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
+            }
+        }
+        return Response::success();
+    }
+
+    //计算滚球 赛事进行时间
+    public static function secTime($sec=0){
+        $min = floor($sec/60);
+        $res = $min.':'.($sec-$min*60);
+        return $res;
+    }
+}

+ 16 - 0
app/Http/Model/StLqResultRecord.php

@@ -0,0 +1,16 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StLqResultRecord extends Model
+{
+    protected $table = 'st_lq_result_record';
+    public $timestamps = false;
+
+}

+ 18 - 0
app/Http/Model/StSettlementMiddleDetail.php

@@ -0,0 +1,18 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StSettlementMiddleDetail extends Model
+{
+    protected $table = 'settlement_middle_detail';
+    public $timestamps = false;
+
+    protected $fillable = ['game_code','match_id','account_identity','bet_type','order_id','money'];
+
+}

+ 16 - 0
app/Http/Model/StWqBroadcast.php

@@ -0,0 +1,16 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 足球直播数据
+ */
+class StWqBroadcast extends Model
+{
+    protected $table = 'st_wq_broadcast';
+    public $timestamps = false;
+
+}

+ 19 - 0
app/Http/Model/StWqLeague.php

@@ -0,0 +1,19 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StWqLeague extends Model
+{
+
+    protected $table = 'st_wq_league';
+    public $timestamps = false;
+
+
+}

+ 17 - 0
app/Http/Model/StWqLeagueResult.php

@@ -0,0 +1,17 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StWqLeagueResult extends Model
+{
+
+    protected $table = 'st_wq_league_result';
+    public $timestamps = false;
+
+}

+ 17 - 0
app/Http/Model/StWqLocalLeague.php

@@ -0,0 +1,17 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 足球 联赛 关联
+ */
+class StWqLocalLeague extends Model
+{
+
+    protected $table = 'st_wq_local_league';
+    public $timestamps = false;
+
+}

+ 17 - 0
app/Http/Model/StWqLocalMatch.php

@@ -0,0 +1,17 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 足球 赛事关联
+ */
+class StWqLocalMatch extends Model
+{
+
+    protected $table = 'st_wq_local_match';
+    public $timestamps = false;
+
+}

+ 19 - 0
app/Http/Model/StWqMatch.php

@@ -0,0 +1,19 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StWqMatch extends Model
+{
+
+    protected $table = 'st_wq_competition';
+    public $timestamps = false;
+
+
+}

+ 19 - 0
app/Http/Model/StWqOdds.php

@@ -0,0 +1,19 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StWqOdds extends Model
+{
+    protected $table = 'st_wq_odds';
+    public $timestamps = false;
+    protected $fillable = ['match_id','others_match_id','odds_code','status','sort','p_code','odds','condition','odds_only','sole','source','type','team','lg_id','others_lg_id','ctime','utime','expire_time'];
+
+
+
+}

+ 17 - 0
app/Http/Model/StWqOddsRecord.php

@@ -0,0 +1,17 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StWqOddsRecord extends Model
+{
+    protected $table = 'st_wq_odds_record';
+    public $timestamps = false;
+    protected $fillable = ['match_id','others_match_id','odds_code','status','sort','p_code','odds','condition','odds_only','source','type','team','lg_id','others_lg_id','ctime','utime'];
+
+}

+ 99 - 0
app/Http/Model/StWqResult.php

@@ -0,0 +1,99 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+use App\Http\Response\Response;
+
+/**
+ * Class StWqResult
+ * @package App\Http\Model
+ * 网球 赛事 结果
+ */
+class StWqResult extends Model
+{
+    protected $table = 'st_wq_result';
+    public $timestamps = false;
+
+    /*
+     * 写赛事结果
+     */
+    public static function WQresult($model){
+        //获取赛事表7天内所有赛事
+        $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
+            ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-7 day"))]])
+            ->get()
+            ->toarray();
+
+        //没有数据,无需操作
+        if(empty($matchData)) return Response::success();
+        //获取赛事结果表 所有当月
+        $matchData_r = $model['model_result']::select('match_id')
+            ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-7 day"))]])
+            ->get()
+            ->toarray();
+
+        //结果表无数据,直接插入
+        if(empty($matchData_r)){
+            foreach ($matchData as $k=>$v){
+                $start_time = ($v['match_date'].' '.$v['match_time']);
+                $time = time()-strtotime($v['match_time']);
+                $match_time = self::secTime($time);
+                $set_match_r[] = [
+                    "match_id"=> $v['id'],
+                    "home_player_name"=>$v['home_team'],
+                    "guest_player_name"=>$v['guest_team'],
+                    "lg_id"=>$v['lg_id'],
+                    "status"=>$v['status'],
+                    "tag"=> $v['tag'],
+                    'match_time'=>$match_time,
+                    "ctime"=>date('Y-m-d H:i:s'),
+                    "update_time"=>date('Y-m-d H:i:s'),
+                    "start_time"=>date('Y-m-d H:i:s',strtotime($start_time))
+                ];
+            }
+            $ret = $model['model_result']::insert($set_match_r);
+            if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
+        }else {
+
+            //如果结果表有数据,则获取结果表没有的赛事
+            foreach ($matchData as $k => $v) {
+                foreach ($matchData_r as $kk => $vv) {
+                    if ($v['id'] == $vv['match_id']) {
+                        unset($matchData[$k]);
+                    }
+                }
+            }
+            //如果还有未写入赛事
+            if (!empty($matchData)) {
+                //写入结果表不存在赛事
+                foreach ($matchData as $k => $v) {
+                    $start_time = ($v['match_date'] . ' ' . $v['match_time']);
+                    $time = time() - strtotime($v['match_time']);
+                    $match_time = self::secTime($time);
+                    $set_match_r[] = [
+                        "match_id" => $v['id'],
+                        "home_player_name" => $v['home_team'],
+                        "guest_player_name" => $v['guest_team'],
+                        "lg_id" => $v['lg_id'],
+                        "status" => $v['status'],
+                        "tag" => $v['tag'],
+                        'match_time' => $match_time,
+                        "ctime" => date('Y-m-d H:i:s'),
+                        "update_time" => date('Y-m-d H:i:s'),
+                        "start_time" => date('Y-m-d H:i:s', strtotime($start_time))
+                    ];
+                }
+                $ret = $model['model_result']::insert($set_match_r);
+                if ($ret != true) throw new \Exception(Response::generate('', Response::ADD_MATCH_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
+            }
+        }
+        return Response::success();
+    }
+
+    //计算滚球 赛事进行时间
+    public static function secTime($sec=0){
+        $min = floor($sec/60);
+        $res = $min.':'.($sec-$min*60);
+        return $res;
+    }
+}

+ 16 - 0
app/Http/Model/StWqResultRecord.php

@@ -0,0 +1,16 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StWqResultRecord extends Model
+{
+    protected $table = 'st_wq_result_record';
+    public $timestamps = false;
+
+}

+ 16 - 0
app/Http/Model/StZqBroadcast.php

@@ -0,0 +1,16 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 足球直播数据
+ */
+class StZqBroadcast extends Model
+{
+    protected $table = 'st_zq_broadcast';
+    public $timestamps = false;
+
+}

+ 19 - 0
app/Http/Model/StZqLeague.php

@@ -0,0 +1,19 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StZqLeague extends Model
+{
+
+    protected $table = 'st_zq_league';
+    public $timestamps = false;
+
+
+}

+ 17 - 0
app/Http/Model/StZqLeagueResult.php

@@ -0,0 +1,17 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StZqLeagueResult extends Model
+{
+
+    protected $table = 'st_zq_league_result';
+    public $timestamps = false;
+
+}

+ 28 - 0
app/Http/Model/StZqLocalLeague.php

@@ -0,0 +1,28 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class StZqLocalLeague
+ * @package App\Http\Model
+ * 足球联赛 中间表
+ */
+class StZqLocalLeague extends Model
+{
+
+    protected $table = 'st_zq_local_league';
+    public $timestamps = false;
+
+    /*
+     * 获取一段时间内所有联赛数据
+     */
+    public static function getLeagueID($models){
+        $lg_data = $models['model_local_league']::select('lg_id','others_lg_id','source')
+            ->where([['ctime','>',date('Y-m-d H:i:s' , strtotime("-15 day"))]])
+            ->get()
+            ->toArray();
+        return $lg_data;
+    }
+
+}

+ 28 - 0
app/Http/Model/StZqLocalMatch.php

@@ -0,0 +1,28 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class StZqLocalMatch
+ * @package App\Http\Model
+ * 足球 赛事 中间表
+ */
+class StZqLocalMatch extends Model
+{
+
+    protected $table = 'st_zq_local_match';
+    public $timestamps = false;
+
+    /*
+     * 获取一段时间内所有赛事
+     */
+    public static function getMatchID($models){
+        $match_data = $models['model_local_match']::select('match_id','others_match_id','source')
+            ->where([['ctime','>',date('Y-m-d H:i:s' , strtotime("-3 day"))]])
+            ->get()
+            ->toArray();
+        return $match_data;
+    }
+
+}

+ 19 - 0
app/Http/Model/StZqMatch.php

@@ -0,0 +1,19 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StZqMatch extends Model
+{
+
+    protected $table = 'st_zq_competition';
+    public $timestamps = false;
+
+
+}

+ 83 - 0
app/Http/Model/StZqOdds.php

@@ -0,0 +1,83 @@
+<?php
+namespace App\Http\Model;
+
+use function foo\func;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class StZqOdds
+ * @package App\Http\Model
+ * 足球 赔率
+ */
+class StZqOdds extends Model
+{
+    protected $table = 'st_zq_odds';
+    public $timestamps = false;
+    protected $fillable = ['match_id','others_match_id','odds_code','status','sort','p_code','odds','condition','odds_only','sole','source','type','team','lg_id','others_lg_id','ctime','utime','expire_time'];
+
+    /*
+     * 获取一段时间内所有的赔率
+     */
+    public static function getOddsID($models){
+        $Odds_data = $models['model_odds']::select('id','sole','source')
+            ->where([['utime','>',date('Y-m-d H:i:s' , strtotime("-1 day"))]])
+            ->get()
+            ->toArray();
+        return $Odds_data;
+    }
+
+    /*
+     * 获取赛事下所有 不在本次请求的 赔率only 并 更新状态
+     */
+    public static function getMatchSole($model=[],$others_match_id='',$others_lg_id=[],$source='',$odds_only=[]){
+        $where = [];
+        //普通 赔率
+        if(!empty($others_match_id) and !empty($source)){
+            $where = [
+                ['others_match_id','=',$others_match_id],
+                ['source','=',$source]
+            ];
+            //获取当前 赛事 所有 赔率only
+            $odds_data = $model['model_odds']::select('odds_only')
+            ->where($where)
+            ->get()
+            ->toArray();
+        }
+        //冠军联赛 赔率
+        if(!empty($others_lg_id) and !empty($source)){
+            //获取当前 赛事 所有 赔率only
+            $odds_data = $model['model_odds']::select('odds_only')
+            ->whereIn('others_lg_id',$others_lg_id)
+            ->where(['source','=',$source])
+            ->get()
+            ->toArray();
+        }
+       
+
+        if(empty($odds_data)) return true;
+
+        //去除 本次请求的 赔率only
+        if(is_array($odds_data) and !empty($odds_only)){
+            foreach ($odds_data as $k => $v){
+                foreach ($odds_only as $kk => $vv){
+                    if($v['odds_only'] == $vv) unset($odds_data[$k]);
+                }
+            }
+        }
+        if(empty($odds_data)) return true;
+
+        //降维 获取所有only
+        $only = [];
+        if(is_array($odds_data)){
+            foreach ($odds_data as $k => $v){
+                $only[] = $v['odds_only'];
+            }
+        }
+        //批量更新 赔率状态
+        $ds = $model['model_odds']::whereIn('odds_only', $only)
+            ->update(['status' => -1]);
+
+        if($ds > 0 ) return true;
+    }
+}

+ 29 - 0
app/Http/Model/StZqOddsRecord.php

@@ -0,0 +1,29 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class StZqOddsRecord
+ * @package App\Http\Model
+ * 足球 赔率 记录
+ */
+class StZqOddsRecord extends Model
+{
+    protected $table = 'st_zq_odds_record';
+    public $timestamps = false;
+    protected $fillable = ['match_id','others_match_id','odds_code','status','sort','p_code','odds','condition','odds_only','source','type','team','lg_id','others_lg_id','ctime','utime'];
+
+
+    /*
+     * 获取一段时间内所有的赔率记录
+     */
+    public static function getOddsRecordID($models){
+        $OddsRecord_data = $models['model_odds_record']::select('id','odds_only','source')
+            ->where([['ctime','>',date('Y-m-d H:i:s' , strtotime("-1 day"))]])
+            ->get()
+            ->toArray();
+        return $OddsRecord_data;
+    }
+
+}

+ 98 - 0
app/Http/Model/StZqResult.php

@@ -0,0 +1,98 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+use App\Http\Response\Response;
+
+/**
+ * Class StZqResult
+ * @package App\Http\Model
+ * 足球 赛事 结果
+ */
+class StZqResult extends Model
+{
+    protected $table = 'st_zq_result';
+    public $timestamps = false;
+
+    /*
+     * 写赛事结果
+     */
+    public static function ZQresult($model){
+        //获取赛事表7天内所有赛事
+        $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
+            ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-7 day"))]])
+            ->get()
+            ->toarray();
+
+        //没有数据,无需操作
+        if(empty($matchData)) return Response::success();
+        //获取赛事结果表 所有当月
+        $matchData_r = $model['model_result']::select('match_id')
+            ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-7 day"))]])
+            ->get()
+            ->toarray();
+
+        //结果表无数据,直接插入
+        if(empty($matchData_r)){
+            foreach ($matchData as $k=>$v){
+                $start_time = ($v['match_date'].' '.$v['match_time']);
+                $time = time()-strtotime($v['match_time']);
+                $match_time = self::secTime($time);
+                $set_match_r[] = [
+                    "match_id"=> $v['id'],
+                    "home_team"=>$v['home_team'],
+                    "guest_team"=>$v['guest_team'],
+                    "lg_id"=>$v['lg_id'],
+                    "status"=>$v['status'],
+                    "tag"=> $v['tag'],
+                    'match_time'=>$match_time,
+                    "ctime"=>date('Y-m-d H:i:s'),
+                    "update_time"=>date('Y-m-d H:i:s'),
+                    "start_time"=>date('Y-m-d H:i:s',strtotime($start_time))
+                ];
+            }
+            $ret = $model['model_result']::insert($set_match_r);
+            if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
+        }else {
+            //如果结果表有数据,则获取结果表没有的赛事
+            foreach ($matchData as $k => $v) {
+                foreach ($matchData_r as $kk => $vv) {
+                    if ($v['id'] == $vv['match_id']) {
+                        unset($matchData[$k]);
+                    }
+                }
+            }
+            //如果还有未写入赛事
+            if (!empty($matchData)) {
+                //写入结果表不存在赛事
+                foreach ($matchData as $k => $v) {
+                    $start_time = ($v['match_date'] . ' ' . $v['match_time']);
+                    $time = time() - strtotime($v['match_time']);
+                    $match_time = self::secTime($time);
+                    $set_match_r[] = [
+                        "match_id" => $v['id'],
+                        "home_team" => $v['home_team'],
+                        "guest_team" => $v['guest_team'],
+                        "lg_id" => $v['lg_id'],
+                        "status" => $v['status'],
+                        "tag" => $v['tag'],
+                        'match_time' => $match_time,
+                        "ctime" => date('Y-m-d H:i:s'),
+                        "update_time" => date('Y-m-d H:i:s'),
+                        "start_time" => date('Y-m-d H:i:s', strtotime($start_time))
+                    ];
+                }
+                $ret = $model['model_result']::insert($set_match_r);
+                if ($ret != true) throw new \Exception(Response::generate('', Response::ADD_MATCH_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
+            }
+        }
+        return Response::success();
+    }
+
+    //计算滚球 赛事进行时间
+    public static function secTime($sec=0){
+        $min = floor($sec/60);
+        $res = $min.':'.($sec-$min*60);
+        return $res;
+    }
+}

+ 16 - 0
app/Http/Model/StZqResultRecord.php

@@ -0,0 +1,16 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class Account
+ * @package App\Sports\Model
+ * 用户账号
+ */
+class StZqResultRecord extends Model
+{
+    protected $table = 'st_zq_result_record';
+    public $timestamps = false;
+
+}

+ 35 - 0
app/Http/Model/St_area_country.php

@@ -0,0 +1,35 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Class St_country
+ * @package App\Sports\Model
+ * 国家 地区 关系
+ */
+class St_area_country extends Model
+{
+
+    protected $table = 'st_area_country';
+    public $timestamps = false;
+
+
+    //获取国家或地区 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;
+    }
+}

+ 19 - 0
app/Http/Model/SystemUser.php

@@ -0,0 +1,19 @@
+<?php
+namespace App\Http\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+
+/**
+ * Class SystemUser
+ * @package App\Http\Model
+ * 管理员
+ */
+class SystemUser extends Model
+{
+
+    protected $table = 'system_user';
+    public $timestamps = false;
+
+
+}

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

@@ -0,0 +1,104 @@
+<?php
+
+namespace App\Http\Response;
+
+class Response
+{
+    const SUCCESS = 1;
+    const  FAILED = 0;
+    //体育数据入库操作
+    const HANDLE_ERRORS = 10010;
+    const ABNORMAL = 10011;
+    const UPDATE_ERROR = 10012;
+    const INSERT_ERROR = 10013;
+    const COUNTRY_ERROR = 10014;
+    const AREA_ERROR = 10015;
+    const LEAGUE_ERROR = 10016;
+    const MATCH_ERROR = 10017;
+    const LOCAL_LEAGUE_ERROR = 10018;
+    const ADD_ODDS_ERROR = 10019;
+    const ADD_ODDS_R_ERROR = 10020;
+    const ADD_LG_R_ERROR = 10021;
+    const ADD_MATCH_R_ERROR = 10022;
+    const ADD_MATCH_R_R_ERROR = 10023;
+    const LG_LASTTIME_ERROR = 10024;
+    const HALF_MATCH_ERROR = 10025;
+    const AUTH_ERROR = 10026;
+    const LOCAL_MATCH_ERROR = 10027;
+    const BROADCAST_ERROR = 10028;
+    //===更新赛事状态===
+    const MATCHID_NULL = 10029;
+    const UPSTATUS_ERROR = 10030;
+
+    //===更新赔率 状态===
+    const ODDS_SOLE_ERR = 10031;
+
+    //===获取 用户token ==
+    const TOKEN_ERR = 10032;
+
+
+    private static $errorMsgs = [
+        self::SUCCESS => '成功',
+        self:: FAILED => '失败',
+
+        //===体育数据写入===
+        self::HANDLE_ERRORS => '数据处理失败',
+        self::ABNORMAL => '提交数据异常',
+        self::UPDATE_ERROR => '数据更新失败',
+        self::INSERT_ERROR => '数据插入失败',
+        self::COUNTRY_ERROR => '国家不存在',
+        self::AREA_ERROR => '地区不存在',
+        self::LEAGUE_ERROR => '联赛不存在',
+        self::MATCH_ERROR => '赛事不存在',
+        self::LOCAL_LEAGUE_ERROR => '写入联赛关联记录失败',
+        self::ADD_ODDS_ERROR => '赛事赔率写入失败',
+        self::ADD_ODDS_R_ERROR => '赛事赔率记录写入失败',
+        self::ADD_LG_R_ERROR => '联赛结果写入失败',
+        self::ADD_MATCH_R_ERROR => '赛事结果写入失败',
+        self::ADD_MATCH_R_R_ERROR => '赛事结果记录写入失败',
+        self::LG_LASTTIME_ERROR => '联赛赛季结束时间不存在',
+        self::HALF_MATCH_ERROR => '所属上半场赛事不存在',
+        self::AUTH_ERROR => '无权操作',
+        self::LOCAL_MATCH_ERROR => '写入赛事关联记录失败',
+        self::BROADCAST_ERROR => '写入直播数据失败',
+        //===更新赛事状态===
+        self::MATCHID_NULL => '未获取到相关赛事',
+        self::UPSTATUS_ERROR => '赛事状态更新失败',
+        //===更新赔率状态===
+        self::ODDS_SOLE_ERR => '更新赔率状态失败',
+        //===获取用户 token===
+        self::TOKEN_ERR => '用户token异常,请重新获取',
+    ];
+
+    public static function getMsg($code)
+    {
+        return isset(static::$errorMsgs[$code]) ? static::$errorMsgs[$code] : '';
+    }
+
+    public static function generate($front = '', $errCode, $data = [], $errMsg = '', $close = false)
+    {
+        $rs['status'] = $errCode;
+        $rs['msg'] = $errMsg;
+        $rs['msg'] OR $rs['msg'] = static::getMsg($errCode) ?: static::$errorMsgs[static::FAILED];
+        $rs['msg'] = $front . $rs['msg'];
+        $rs['data'] = $data;
+//        return response()->json($rs, 200, ['Content-Type' => 'application/json; charset=UTF-8'], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
+        return json_encode($rs, JSON_UNESCAPED_UNICODE);
+        if ($close) {
+            exit();
+        }
+    }
+
+    public static function success($data = [])
+    {
+        return static::generate('', Response::SUCCESS, $data);
+        exit();
+    }
+
+    public static function throwError($errCode, $errMsg = '', $data = [])
+    {
+        $errMsg OR $errMsg = static::getMsg($errCode);
+        throw new BusinessException($errMsg, $errCode, $data);
+    }
+
+}

+ 1209 - 0
app/Lib/Biz/Sport/Common.php

@@ -0,0 +1,1209 @@
+<?php
+namespace App\Lib\Biz\Sport;
+
+use App\Http\Response\Response;
+
+use App\Http\Model\StZqMatch;
+use App\Http\Model\StZqLeague;
+use App\Http\Model\StZqLeagueResult;
+use App\Http\Model\StZqLocalLeague;
+use App\Http\Model\StZqLocalMatch;
+use App\Http\Model\StZqOdds;
+use App\Http\Model\StZqOddsRecord;
+use App\Http\Model\StZqResult;
+use App\Http\Model\StZqResultRecord;
+use App\Http\Model\StZqBroadcast;
+
+use App\Http\Model\StLqMatch;
+use App\Http\Model\StLqLeague;
+use App\Http\Model\StLqLeagueResult;
+use App\Http\Model\StLqLocalLeague;
+use App\Http\Model\StLqLocalMatch;
+use App\Http\Model\StLqOdds;
+use App\Http\Model\StLqOddsRecord;
+use App\Http\Model\StLqResult;
+use App\Http\Model\StLqResultRecord;
+use App\Http\Model\StLqBroadcast;
+
+use App\Http\Model\StWqResultRecord;
+use App\Http\Model\StWqMatch;
+use App\Http\Model\StWqLeague;
+use App\Http\Model\StWqLeagueResult;
+use App\Http\Model\StWqLocalLeague;
+use App\Http\Model\StWqLocalMatch;
+use App\Http\Model\StWqOdds;
+use App\Http\Model\StWqOddsRecord;
+use App\Http\Model\StWqResult;
+use App\Http\Model\StWqBroadcast;
+
+use App\Http\Model\StBqResultRecord;
+use App\Http\Model\StBqMatch;
+use App\Http\Model\StBqLeague;
+use App\Http\Model\StBqLeagueResult;
+use App\Http\Model\StBqLocalLeague;
+use App\Http\Model\StBqLocalMatch;
+use App\Http\Model\StBqOdds;
+use App\Http\Model\StBqOddsRecord;
+use App\Http\Model\StBqResult;
+use App\Http\Model\StBqBroadcast;
+
+class Common
+{
+    function checkDebug()
+    {
+        return (isset($_GET['debug']) && intval($_GET['debug']) == -99999) || APP_DEBUG == 1 ? 1 : 0;
+    }
+
+    function View($Path = "")
+    {
+        if (!$Path) {
+            global $ViewPath;
+            $ViewPath = explode("\\", $ViewPath);
+            $ViewPath[3] = explode("Controller", $ViewPath[3]);
+            $ViewPath[3] = $ViewPath[3][0];
+            return APP_PATH . "/" . $ViewPath[1] . "/View/" . $ViewPath[3] . "/" . $ViewPath[4] . ".blade.php";
+        } else {
+            return APP_PATH . "/" . $Path . ".blade.php";
+        }
+    }
+
+    function arrayToOptions($data, $key, $val)
+    {
+        $options = array();
+        if (is_array($data) && count($data)) {
+            foreach ($data as $k => $value) {
+                $options[$value[$key]] = $value[$val];
+            }
+        }
+        return $options;
+    }
+
+
+    function M($TABLE_NAME = "")
+    {
+        return new DB($TABLE_NAME);
+    }
+
+    function checkClose()
+    {
+        if (file_exists(ROOT_PATH . '/Cache/system.lock')) {
+            if (is_mobile()) {
+                return appExec("Mobile", "Weihu", "index");
+            } else {
+                return appExec("home", "weihu", "index");
+            }
+        }
+    }
+
+    /**
+     * 发布消息
+     *
+     * @param integer $status
+     * @param string $msg
+     * @param string $data
+     * @return void
+     */
+    function publishNotify($channel, $status = 1, $data = '')
+    {
+        // toLog('publishNotify-'.$channel.'+++'.$data);
+        C()->get('msg')->publish($channel, $data);
+    }
+
+    /**
+     * 数组分类排序
+     * @param [array] $columnsArr [需要进行排序的数组]
+     * @param [int] $plmid [所属分类ID]
+     */
+    function getColumns($columnsArr, $plmid)
+    {
+        $menu = array();
+
+        foreach ($columnsArr as $v) {
+            if ($v['plmid'] == $plmid) {
+                $menu[] = $v;
+
+                $a = getColumns($columnsArr, $v['lmid']);
+                foreach ($a as $vv) {
+                    $menu[] = $vv;
+                }
+            }
+        }
+        return $menu;
+    }
+
+    /**
+     * 获取客户端真实IP
+     */
+    function GETIP()
+    {
+        global $ip;
+
+        if (getenv("HTTP_CLIENT_IP")) {
+            $ip = getenv("HTTP_CLIENT_IP");
+        } else if (getenv("HTTP_X_FORWARDED_FOR")) {
+            $ip = getenv("HTTP_X_FORWARDED_FOR");
+        } else if (getenv("REMOTE_ADDR")) {
+            $ip = getenv("REMOTE_ADDR");
+        } else {
+            $ip = "Unknow";
+        }
+
+        return $ip;
+
+    }
+
+    function dump($data, $exit = 1)
+    {
+        echo "<pre>";
+        print_r($data);
+        echo "</pre>";
+        if ($exit) {
+            exit;
+        }
+
+    }
+
+    function OrderID($prefix = '')
+    {
+        $num = mt_rand(100, 999);
+        list($s, $m) = explode(' ', microtime());
+        $order = date("YmdHis") . ($s * 1000000) . $num;
+        return $prefix . $order;
+    }
+
+    /**
+     * 容器
+     */
+    function C()
+    {
+        static $c = array();
+        if (!isset($c['container'])) {
+            $c['container'] = new \System\Di();
+        }
+        return $c['container'];
+    }
+
+    /**
+     * 全局变量快捷操作
+     * @param [type] $key   [description]
+     * @param [type] $value [description]
+     */
+    function S($key, $value = null)
+    {
+        if ($value != null) {
+            $GLOBALS[$key] = $value;
+        }
+        if (isset($GLOBALS[$key])) {
+            return $GLOBALS[$key];
+        }
+    }
+
+    /**
+     * 载入模型
+     * @param  [type] $name [description]
+     * @param  string $proj [description]
+     * @return [type]       [description]
+     */
+    function lm($name, $proj = '')
+    {
+        $proj = empty($proj) ? S('CUR_PROJECT') : $proj;
+        if (empty($proj)) {
+            throw new \Exception("项目{$proj}不存在", 1);
+        }
+        $cls = "\\App\\" . ucfirst($proj) . "\\Model\\" . ucfirst($name);
+        if (!class_exists($cls)) {
+            return;
+        }
+        $key = 'model_' . $name . $proj;
+        C()->shared($key, $cls);
+        return C()->get($key);
+    }
+
+    /**
+     * 载入语言包
+     * @param  string $key 语言项
+     * @param  string $file 语言文件名
+     * @param  string $proj 项目名称
+     * @return [type]       [description]
+     */
+    function lang($file = '', $proj = '')
+    {
+        $proj = empty($proj) ? S('CUR_PROJECT') : $proj;
+        $file = empty($file) ? S('CUR_CONTROLLER') : $file;
+        $ckey = "Lang_{$proj}_{$file}";
+        if (C()->has($ckey)) {
+            return C()->get($ckey);
+        } else {
+            C()->shared($ckey, function () use ($proj, $file) {
+                $file = ucfirst($file);
+                $proj = ucfirst($proj);
+                $lang = new \System\Lang();
+                $lang_files = array();
+                if (S('CUR_PROJECT') == $proj && S('CUR_CONTROLLER') == $file) {
+                    $lang_files[] = ROOT_PATH . "/Application/Commons/Lang/Common.php";
+                    $lang_files[] = ROOT_PATH . "/Application/{$proj}/Lang/Common.php";
+                }
+                $lang_files[] = ROOT_PATH . "/Application/{$proj}/Lang/{$file}.php";
+                $data = array();
+                foreach ($lang_files as $v) {
+                    if (file_exists($v)) {
+                        $data2 = include $v;
+                        if (is_array($data2)) {
+                            $data = array_merge($data, $data2);
+                        }
+                    }
+                }
+                $lang->load($data);
+                return $lang;
+            });
+            return C()->get($ckey);
+        }
+    }
+
+    /**
+     * 标签替换
+     *
+     * @param [type] $message
+     * @param array $data
+     * @param string $tag
+     * @return void
+     */
+    function parseTag($message, $data = array(), $tag = '#')
+    {
+        if (is_array($data) && count($data) > 0) {
+            foreach ($data as $k => $v) {
+                $message = str_replace($tag . $k . $tag, $v, $message);
+            }
+        }
+
+        return $message;
+    }
+
+    function appExec($proj, $ctrl, $method, $exec = 0)
+    {
+        $proj = ucfirst($proj);
+        $ctrl = ucfirst($ctrl);
+        $method = ucfirst($method);
+        S('CUR_PROJECT', $proj);
+        S('CUR_CONTROLLER', $ctrl);
+        S('CUR_METHOD', $method);
+        checkPlatform();
+        toDomain();
+        //设置REMOTE_KEY
+        lm('setinfo', 'commons')->setKey();
+
+        $cls = "\\App\\{$proj}\\Controller\\{$ctrl}";
+        C()->set($ctrl, $cls);
+        $cls = C()->get($ctrl);
+        if (!$cls) {
+            exit("404 NOT FOUND");
+        }
+        if ($exec) {
+            $result = $cls->$method();
+            if (!empty($result)) {
+                Render($result);
+            }
+        }
+        if (method_exists($cls, $method)) {
+            $result = $cls->$method();
+            if (!empty($result)) {
+                Render($result);
+            }
+        } else {
+            exit("404 METHOD NOT FOUND");
+        }
+
+    }
+
+    /**
+     * UUID 生成
+     */
+    function UUID()
+    {
+        $prefix = '';
+        $uuid = '';
+        $str = md5(uniqid(mt_rand(), true));
+        $uuid = substr($str, 0, 8) . '-';
+        $uuid .= substr($str, 8, 4) . '-';
+        $uuid .= substr($str, 12, 4) . '-';
+        $uuid .= substr($str, 16, 4) . '-';
+        $uuid .= substr($str, 20, 12);
+        return $prefix . $uuid;
+    }
+
+    /**
+     *密码加密码
+     */
+    function GenEncryption()
+    {
+        srand((double)microtime() * 1000000); //create a random number feed.
+        $ychar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
+        $list = explode(",", $ychar);
+        $authnum = "";
+        for ($i = 0; $i < 6; $i++) {
+            $randnum = rand(0, 61); // 10+26;
+            $authnum .= $list[$randnum];
+        }
+        return $authnum;
+    }
+
+//密码加密
+    function GenPassword($password)
+    {
+        $Enc = GenEncryption();
+        $Pwd = md5(md5($Enc . $password));
+        return array("encryption" => $Enc, "password" => $Pwd);
+
+    }
+
+//密码验证
+    function VerPassword($identity, $password)
+    {
+        $account = M("account_password")->where("account_identity = '$identity' and", "status = ", '1')->select("encryption,account_password")->find();
+        $VerPwd = md5(md5($account["encryption"] . $password));
+        if ($VerPwd == $account["account_password"]) {
+            unset($account);
+            unset($VerPwd);
+            return true;
+        } else {
+            unset($account);
+            unset($VerPwd);
+            return false;
+        }
+
+    }
+
+    /**
+     * Json return
+     * @param string $data [description]
+     * @param string $status [description]
+     * @param string $msg [description]
+     * @param string $method [description]
+     */
+    function JsonReturn($data = "", $status = "200", $msg = "", $method = "")
+    {
+        // header("Content-type:application/json;charset:utf-8");
+        // header('content-type:text/html; charset=utf-8');
+        if (isset($_REQUEST['crossdomain']) && !empty($_REQUEST['crossdomain'])) {
+            header("Access-Control-Allow-Origin:{$_REQUEST['crossdomain']}");
+        } else {
+            header("Access-Control-Allow-Origin:*");
+        }
+        header('Access-Control-Allow-Methods:POST,GET,PUT,DELETE,OPTIONS');
+        header('Access-Control-Allow-Credentials:true');
+        $retdata = array("status" => $status, "msg" => $msg, "data" => $data);
+
+        $devicetype = isset($_REQUEST['devicetype']) ? trim($_REQUEST['devicetype']) : '';
+        if (!empty($devicetype) && in_array($devicetype, array('ios', 'android'))) {
+            $path = S('CUR_PROJECT') . '/' . S('CUR_CONTROLLER') . '/' . S('CUR_METHOD');
+            $retdata = C()->get($devicetype . "Result")->update($path, $retdata);
+        }
+
+        if ($method == '') {
+            //dump($devicetype);
+            echo(json_encode($retdata, JSON_UNESCAPED_UNICODE));
+        } else {
+            echo($method . "(" . json_encode($retdata, JSON_UNESCAPED_UNICODE) . ")");
+        }
+    }
+
+    function XmlReturn($data = "", $status = 200, $msg = '')
+    {
+        // header("Content-type:text/xml;charset:utf-8");
+        $xml = '<?xml version="1.0" encoding="utf-8"?>';
+        $xml .= "<root>";
+        $xml .= '<status>' . $status . '</status>';
+        $xml .= '<msg>' . $msg . '</msg>';
+        $xml .= "<rows>";
+        $xml .= toXml($data);
+        $xml .= "</rows>";
+        $xml .= "</root>";
+        echo($xml);
+    }
+
+    function toXml($data)
+    {
+        // print_r($data);
+        $xml = '';
+        if (is_array($data) && count($data) > 0) {
+            foreach ($data as $k => $v) {
+                $key = $k;
+                if (is_numeric($k)) {
+                    $key = 'data';
+                }
+                if (is_array($v)) {
+                    $xml .= "<{$key}>" . toXml($v) . "</{$key}>";
+                    continue;
+                }
+                if (is_string($v)) {
+                    $xml .= "<{$key}>{$v}</{$key}>";
+                }
+            }
+        }
+        return $xml;
+    }
+
+    function WriteLog($Log)
+    {
+        $logger = new Logger('LOGGS');
+        $logURI = "Cache/log/" . date("Y-m-d-H-i") . ".log";
+        $logger->pushHandler(new StreamHandler($logURI, Logger::DEBUG));
+        $logger->pushHandler(new FirePHPHandler());
+        $logger->addInfo(var_export($Log, 1));
+
+    }
+
+    /**
+     * 计算当前用时
+     *
+     * @param string $runName
+     * @param integer $return
+     * @return void
+     */
+    function computeTime($runName = '', $return = 0, $start = 1)
+    {
+        $curTime = get_millisecond();
+        $numTime = $curTime - (intval($GLOBALS['startTime']) * 1000);
+        if ($return) {
+            return array('curTime' => $curTime, 'numTime' => $numTime, 'runName' => $runName);
+        } else {
+            echo "<pre>执行{$runName} 功能,当前时间为:{$curTime},累积用时: {$numTime}</pre>";
+            return;
+        }
+
+    }
+
+    function get_millisecond()
+    {
+        list($usec, $sec) = explode(" ", microtime());
+        $msec = round($usec * 1000);
+        return $sec . $msec;
+
+    }
+
+    function toLog($text, $rewrite = 0)
+    {
+        $data = "=============" . date("Y-m-d H:i", time()) . "==========================================" . chr(13);
+        $data .= var_export($text, 1) . chr(13);
+        $data .= "======================================================================================" . chr(13);
+        $data = iconv('utf-8', 'gb2312', $data);
+        if ($rewrite) {
+            file_put_contents(ROOT_PATH . '/logs.txt', $data);
+        } else {
+            file_put_contents(ROOT_PATH . '/logs.txt', $data, FILE_APPEND);
+        }
+    }
+
+    /**
+     * 发送数据到前台,根据请求的数据格式返回相应的数据
+     * @param [type] $data   [description]
+     * @param string $status [description]
+     * @param string $msg [description]
+     */
+    function Render($data, $status = "1", $msg = "", $method = '')
+    {
+        $format = S('CUR_RETURN_FORMAT');
+        $msg = empty($msg) ? lang('errors', 'api')->get('error' . $status) : $msg;
+
+        if (empty($format) || $format == 'json') {
+            JsonReturn($data, $status, $msg);
+        }
+        if ($format == 'xml') {
+            XmlReturn($data, $status, $msg);
+        }
+        exit;
+    }
+
+
+    function _beginTransaction()
+    {
+        S('DB')->beginTransaction();
+    }
+
+    function _rollBack()
+    {
+        S('DB')->rollBack();
+    }
+
+    function _commit()
+    {
+        S('DB')->commit();
+    }
+
+    /**
+     * 服务
+     *
+     * @param string 服务名称
+     * @param array $params
+     * @return void
+     */
+    function SRV($name, $params = array())
+    {
+        return C()->get($name)->update($params);
+    }
+
+    /**
+     * 是否验证token过期
+     *
+     * @return bool
+     */
+    function isCheckToken()
+    {
+        $result = true;
+        $allowMethod = include ROOT_PATH . "/Config/AllowMethod.php";
+        $key = S('CUR_PROJECT') . '/' . S('CUR_CONTROLLER') . '/' . S('CUR_METHOD');
+        if ($allowMethod[$key] == 1) {
+            $result = false;
+        }
+        return $result;
+    }
+
+    function checkPlatform()
+    {
+
+        if (isset($_GET['platform'])) {
+            $_SESSION['platform'] = $_GET['platform'] == 'wap' ? 1 : 0;
+        }
+        if (isset($_GET['clearPlatform']) && intval($_GET['clearPlatform']) == 1) {
+            $_SESSION['platform'] = null;
+        }
+
+    }
+
+    function is_mobile()
+    {
+        if (isset($_SESSION['platform']) && $mobile = intval($_SESSION['platform']) > 0) {
+            return $mobile == 1 ? true : false;
+        }
+        $user_agent = $_SERVER['HTTP_USER_AGENT'];
+        $mobile_agents = Array("240x320", "acer", "acoon", "acs-", "abacho", "ahong", "airness", "alcatel", "amoi", "android", "anywhereyougo.com", "applewebkit/525", "applewebkit/532", "asus", "audio", "au-mic", "avantogo", "becker", "benq", "bilbo", "bird", "blackberry", "blazer", "bleu", "cdm-", "compal", "coolpad", "danger", "dbtel", "dopod", "elaine", "eric", "etouch", "fly ", "fly_", "fly-", "go.web", "goodaccess", "gradiente", "grundig", "haier", "hedy", "hitachi", "htc", "huawei", "hutchison", "inno", "ipad", "ipaq", "ipod", "jbrowser", "kddi", "kgt", "kwc", "lenovo", "lg ", "lg2", "lg3", "lg4", "lg5", "lg7", "lg8", "lg9", "lg-", "lge-", "lge9", "longcos", "maemo", "mercator", "meridian", "micromax", "midp", "mini", "mitsu", "mmm", "mmp", "mobi", "mot-", "moto", "nec-", "netfront", "newgen", "nexian", "nf-browser", "nintendo", "nitro", "nokia", "nook", "novarra", "obigo", "palm", "panasonic", "pantech", "philips", "phone", "pg-", "playstation", "pocket", "pt-", "qc-", "qtek", "rover", "sagem", "sama", "samu", "sanyo", "samsung", "sch-", "scooter", "sec-", "sendo", "sgh-", "sharp", "siemens", "sie-", "softbank", "sony", "spice", "sprint", "spv", "symbian", "tablet", "talkabout", "tcl-", "teleca", "telit", "tianyu", "tim-", "toshiba", "tsm", "up.browser", "utec", "utstar", "verykool", "virgin", "vk-", "voda", "voxtel", "vx", "wap", "wellco", "wig browser", "wii", "windows ce", "wireless", "xda", "xde", "zte");
+        $is_mobile = false;
+        foreach ($mobile_agents as $device) {
+            if (stristr($user_agent, $device)) {
+                $is_mobile = true;
+                break;
+            }
+        }
+        return $is_mobile;
+    }
+
+    function toDomain()
+    {
+
+        $domain = $_SERVER['HTTP_HOST'];
+        $config = include ROOT_PATH . '/Config/Domain.php';
+        $is_mobile = is_mobile();
+        $curDomain = $old_domain = $domain;
+        if (is_array($config) && count($config) > 0) {
+            $domains = array();
+            $domains[] = $domain;
+            if ($is_mobile) {
+                $domains[] = str_replace('www.', 'm.', $domain);
+                $domains[] = 'm.' . $domain;
+            } else {
+                $domains[] = str_replace('m.', '', $domain);
+                $domains[] = str_replace('m.', 'www.', $domain);
+            }
+            foreach ($domains as $key => $value) {
+                if (isset($config[$value])) {
+                    $v = $config[$value];
+                    if ($v == 'pay') {
+                        return;
+                    }
+                    if ($is_mobile) {
+                        if ($v == 'pc') {
+                            continue;
+                        }
+                    } else {
+                        if ($v != 'pc') {
+                            continue;
+                        }
+                    }
+
+                    $curDomain = $value;
+                    // $_SESSION['domain']=$value;
+                }
+            }
+        }
+        // echo $curDomain;
+        if ($is_mobile) {
+            if (S('CUR_PROJECT') == 'Home') {
+                header("Location:http://" . $curDomain . "/m");
+                //header("Location:http://" . $curDomain . "/mobile-index/index");
+            }
+        } else {
+            if (S('CUR_PROJECT') == 'Mobile') {
+                header("Location:http://" . $curDomain . "/home-index/index");
+            }
+        }
+        /**
+         * 数据签名认证
+         * @param  array $data 被认证的数据
+         * @return string       签名
+         */
+        function data_auth_sign($data)
+        {
+            //数据类型检测
+            if (!is_array($data)) {
+                $data = (array)$data;
+            }
+            ksort($data); //排序
+            $code = http_build_query($data); //url编码并生成query字符串
+            $sign = sha1($code); //生成签名
+            return $sign;
+        }
+
+        /*
+         * 判断用户是否登录
+         * */
+        function isLogin($str = '', $type = 'agent')
+        {
+            $session = $_SESSION[$type . 'Info'];
+            if (empty($session)) {
+                return null;
+            }
+            if ($type == 'agent') {
+                if ($str == 'name') {
+                    return $session['agent_user'];
+                }
+                if ($str == 'uid') {
+                    return $session['user_identity'];
+                }
+            }
+        }
+    }
+
+    function jump($url)
+    {
+        header('Location:' . $url);
+    }
+
+//手机中间星号
+    function phoneHide($phone)
+    {
+        if (!empty($phone)) {
+            $phone = substr_replace($phone, '****', 3, 4);
+        }
+        return $phone;
+    }
+
+    /**
+     * @param $game_code 球类代码
+     * @param int $isJoin 是否用于join
+     * @return array
+     * @throws Exception
+     * 根据球类代码 定义相关model
+     */
+    static function getModels($game_code, $isJoin = 1)
+    {
+        // 获取不同球类model
+        if ($isJoin == 1) {
+            switch ($game_code) {
+                case 'zq':
+                    $model_league = new StZqLeague;
+                    $model_match = new StZqMatch;
+                    $model_odds = new StZqOdds;
+                    $model_odds_record = new StZqOddsRecord;
+                    $model_result = new StZqResult;
+                    $model_result_record = new StZqResultRecord;
+                    $model_league_result = new StZqLeagueResult;
+                    $model_local_league = new StZqLocalLeague;
+                    $model_local_match = new StZqLocalMatch;
+                    $model_broadcast = new StZqBroadcast;
+                    break;
+                case 'lq':
+                    $model_league = new StLqLeague;
+                    $model_match = new StLqMatch;
+                    $model_odds = new StLqOdds;
+                    $model_odds_record = new StLqOddsRecord;
+                    $model_result = new StLqResult;
+                    $model_result_record = new StLqResultRecord;
+                    $model_league_result = new StLqLeagueResult;
+                    $model_local_league = new StLqLocalLeague;
+                    $model_local_match = new StLqLocalMatch;
+                    $model_broadcast = new StLqBroadcast;
+                    break;
+                case 'wq':
+                    $model_league = new StWqLeague;
+                    $model_match = new StWqMatch;
+                    $model_odds = new StWqOdds;
+                    $model_odds_record = new StWqOddsRecord;
+                    $model_result = new StWqResult;
+                    $model_result_record = new StWqResultRecord;
+                    $model_league_result = new StWqLeagueResult;
+                    $model_local_league = new StWqLocalLeague;
+                    $model_local_match = new StWqLocalMatch;
+                    $model_broadcast = new StWqBroadcast;
+                    break;
+                case 'bq':
+                    $model_league = new StBqLeague;
+                    $model_match = new StBqMatch;
+                    $model_odds = new StBqOdds;
+                    $model_odds_record = new StBqOddsRecord;
+                    $model_result = new StBqResult;
+                    $model_result_record = new StBqResultRecord;
+                    $model_league_result = new StBqLeagueResult;
+                    $model_local_league = new StBqLocalLeague;
+                    $model_local_match = new StBqLocalMatch;
+                    $model_broadcast = new StBqBroadcast;
+                    break;
+                default:
+                    throw new \Exception(Response::generate(Response::ABNORMAL));
+            }
+        }
+        $data = [
+            'model_league' => $model_league,//联赛
+            'model_match' => $model_match,//赛事
+            'model_odds' => $model_odds,//赔率
+            'model_result' => $model_result,//赛事结果
+            'model_odds_record' => $model_odds_record,//赔率记录
+            'model_result_record' => $model_result_record,//赛事结果记录
+            'model_league_result' => $model_league_result,//联赛结果
+            'model_local_league' => $model_local_league,//本地关联联赛
+            'model_local_match' => $model_local_match,//本地关联赛事
+            'model_broadcast' => $model_broadcast,
+        ];
+        return $data;
+    }
+
+    /**
+     * @param $type_code
+     * @return array
+     * @throws \Exception
+     * 获取不同状态下的 查询条件
+     */
+    function getState($type_code, $model_match = '')
+    {
+        if ($model_match == '') {
+            switch ($type_code) {
+                case 'StRollBall'://滚球 正在进行
+                    $where = [
+                        ['status', '=', '1'],
+                    ];
+                    break;
+                case 'StSoon'://即将 今日两小时内开始
+                    $where = [
+                        ['status', '=', '0'],
+                        ['match_date', '=', date("Y-m-d")],
+                        ['match_time', '<', date("H:i:s", strtotime("+2 hour"))],
+                        ['match_time', '>', date("H:i:s", time())]
+                    ];
+                    break;
+                case 'StToday'://今日 今日未开始未结束
+                    $where = [
+                        ['match_date', '=', date("Y-m-d")],
+                        ['match_time', '>', date("H:i:s", time())],
+                    ];
+                    break;
+                case 'StMorningPlate'://早盘
+                    $where = [
+                        ['is_morningplate', '=', 1],
+                        ['us_time', '>', $this->qgmdate('Y-m-d H:i:s', '', -4)],
+                    ];
+                    break;
+                case 'StStringScene'://串场
+                    $where = [
+                        ['is_stringscene', '=', 1],
+                        ['us_time', '>', $this->qgmdate('Y-m-d H:i:s', '', -4)],
+                    ];
+                    break;
+                case 'StChampion'://冠军
+                    $where = [
+                        'type' => 1
+                    ];
+                    break;
+                default:
+                    throw new \Exception(Render([], '10002', lang('Tips', 'Sports')->get('PARAM_ERROR')));
+            }
+        } else {
+            switch ($type_code) {
+                case 'StRollBall'://滚球 正在进行
+                    $where = [
+                        [$model_match . '.status', '=', '1'],
+                    ];
+                    break;
+                case 'StSoon'://即将 今日两小时内开始
+                    $where = [
+                        [$model_match . '.status', '=', '0'],
+                        [$model_match . '.match_date', '=', date("Y-m-d")],
+                        [$model_match . '.match_time', '<', date("H:i:s", strtotime("+2 hour"))],
+                        [$model_match . '.match_time', '>', date("H:i:s", time())]
+                    ];
+                    break;
+                case 'StToday'://今日 今日未开始未结束
+                    $where = [
+                        [$model_match . '.match_date', '=', date("Y-m-d")],
+                        [$model_match . '.match_time', '>', date("H:i:s", time())],
+                    ];
+                    break;
+                case 'all'://所有赛事
+                    $where = [
+                        [$model_match . '.status', '<', '2'],
+                    ];
+                    break;
+                case 'StMorningPlate'://早盘
+                    $where = [
+                        [$model_match . '.is_morningplate', '=', 1],
+                        [$model_match . '.us_time', '>', self::qgmdate('Y-m-d H:i:s', '', -4)],
+                    ];
+                    break;
+                case 'StStringScene'://串场 查询串场状态为1 开赛时间大于当前时间
+                    $where = [
+                        [$model_match . '.is_stringscene', '=', 1],
+                        [$model_match . '.us_time', '>', self::qgmdate('Y-m-d H:i:s', '', -4)],
+                    ];
+                    break;
+                case 'StChampion'://冠军
+                    $where = [
+                        'type' => 1
+                    ];
+                    break;
+                default:
+                    throw new \Exception(Render([], '10002', lang('Tips', 'Sports')->get('PARAM_ERROR')));
+            }
+        }
+
+        return $where;
+    }
+
+    /**
+     * @param $data
+     * @return array
+     * 处理当国家下无联赛数据 删除该数组
+     */
+    function handleArr($data)
+    {
+        $hData = [];
+        foreach ($data as $key => $v) {
+            if (empty($v['league_count'])) {
+                $v = [];
+            }
+            $hData[] = $v;
+        }
+        foreach ($hData as $k => $v) {
+            if (empty($v)) {
+                unset($hData[$k]);
+            }
+        }
+        foreach ($hData as $k => $v) {
+            $v['league_count'] = array_values($v['league_count']);
+            $hData[$k] = $v;
+        }
+
+        return array_values($hData);
+    }
+
+
+    /**
+     * @param $arr
+     * @param $key
+     * @return array
+     * 去除二维数组重复项
+     */
+    function array_unset_tt($arr, $key)
+    {
+        //建立一个目标数组
+        $res = array();
+        foreach ($arr as $value) {
+            //查看有没有重复项
+            if (isset($res[$value[$key]])) {
+                unset($value[$key]);  //有:销毁
+            } else {
+                $res[$value[$key]] = $value;
+            }
+        }
+        return $res;
+    }
+
+    /**
+     * 处理冠军盘口 数组结构
+     */
+    function array_gj_tt($data, $oddsData)
+    {
+        foreach ($data as $k => &$v) {
+            foreach ($v['league_count'] as $kk => &$vv) {
+                foreach ($oddsData as $kkk => $vvv) {
+                    if ($vv['lg_id'] == $vvv['lg_id']) {
+                        $vv['oddsData'][] = $vvv;
+                    }
+                }
+
+                if ($vv['oddsData']) {
+                    $vv['oddsData'] = $this->array_unset_tt($vv['oddsData'], 'p_code');
+                    $vv['count'] = count($vv['oddsData']);
+                    unset($vv['oddsData']);
+                }
+
+                if (count($vv) == 5) {
+                    unset($v['league_count'][$kk]);
+                }
+            }
+            $v['league_count'] = array_values($v['league_count']);
+            if (empty($v['league_count'])) {
+                unset($data[$k]);
+            }
+        }
+
+        return array_values($data);
+    }
+
+    /**
+     * 处理冠军以外 数组结构
+     */
+    function array_other_tt($data, $matchData)
+    {
+        foreach ($data as $k => &$v) {
+            foreach ($v['league_count'] as $kk => &$vv) {
+                foreach ($matchData as $kkk => $vvv) {
+                    if ($vv['lg_id'] == $vvv['lg_id']) {
+                        $vv['matchData'][] = $vvv;
+                    }
+                }
+
+                if ($vv['matchData']) {
+                    $vv['matchData'] = $this->array_unset_tt($vv['matchData'], 'match_id');
+                    $vv['count'] = count($vv['matchData']);
+                    unset($vv['matchData']);
+                }
+
+                if (count($vv) == 5) {
+                    unset($v['league_count'][$kk]);
+                }
+            }
+            $v['league_count'] = array_values($v['league_count']);
+            if (empty($v['league_count'])) {
+                unset($data[$k]);
+            }
+        }
+
+        return array_values($data);
+    }
+
+    /**
+     * 时间格式化
+     * @param string $dateformat 时间格式
+     * @param int $timestamp 时间戳
+     * @param int $timeoffset 时区偏差 默认8 北京时间 -4美东时间
+     * @return string
+     */
+    public static function qgmdate($dateformat = 'Y-m-d H:i:s', $timestamp = '', $timeoffset = 8, $type = '')
+    {
+        if (empty($timestamp)) {
+            $timestamp = time();
+        }
+        $result = gmdate($dateformat, $timestamp + $timeoffset * 3600);
+        return $result;
+    }
+
+    /**
+     * 判断二维数组是否包含一维数组
+     * @param mixed $arr 查询条件
+     * @param mixed $arrs 运动类型
+     * @return string
+     */
+    function judgeEqual($arr, $arrs)
+    {
+        foreach ($arrs as $value) {
+            if (count($value) === count($arr)) {
+                $a = 0;
+                foreach ($value as $key => $v) {
+                    $a++;
+                    if ($v != $arr[$key]) {
+                        break;
+                    }
+                    if ($a == count($key)) {    // 到最后一个元素都没有出现不相等,就说明这两个数组相等。
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+// 排列
+    function arrangement($a, $m)
+    {
+        $r = array();
+
+        $n = count($a);
+        if ($m <= 0 || $m > $n) {
+            return $r;
+        }
+
+        for ($i = 0; $i < $n; $i++) {
+            $b = $a;
+            $t = array_splice($b, $i, 1);
+            if ($m == 1) {
+                $r[] = $t;
+            } else {
+                $c = $this->arrangement($b, $m - 1);
+                foreach ($c as $v) {
+                    $r[] = array_merge($t, $v);
+                }
+            }
+        }
+
+        return $r;
+    }
+
+// 组合
+    function combination($a, $m)
+    {
+        $r = array();
+
+        $n = count($a);
+        if ($m <= 0 || $m > $n) {
+            return $r;
+        }
+
+        for ($i = 0; $i < $n; $i++) {
+            $t = array($a[$i]);
+            if ($m == 1) {
+                $r[] = $t;
+            } else {
+                $b = array_slice($a, $i + 1);
+                $c = $this->combination($b, $m - 1);
+                foreach ($c as $v) {
+                    $r[] = array_merge($t, $v);
+                }
+            }
+        }
+
+        return $r;
+    }
+
+// 阶乘
+    function factorial($n)
+    {
+        return array_product(range(1, $n));
+    }
+
+// 排列数
+    function A1($n, $m)
+    {
+        return factorial($n) / factorial($n - $m);
+    }
+
+// 组合数
+    function C1($n, $m)
+    {
+        return A1($n, $m) / factorial($m);
+    }
+
+    /**
+     * @param $lg_id 数据源 联赛id
+     * @param $source 数据源
+     * @param $lg_data 本地关联记录
+     * @return bool|mixed  成功 返回本地联赛id
+     *
+     * 验证本地联赛中是否存在 用于写入联赛/赛事数据验证
+     */
+    static function ver_league($lg_id, $source, $lg_data)
+    {
+        foreach ($lg_data as $item) {
+            if (!is_array($item)) return false;
+            if ($item['others_lg_id'] == $lg_id and $item['source'] == $source) return $item['lg_id'];
+        }
+        return false;
+    }
+
+    /**
+     * @param $match_id 数据源 赛事id
+     * @param $source 数据源
+     * @param $match_data 本地赛事记录
+     * @return bool|mixed 成功返回本地赛事id
+     * 验证本地赛事记录是否存在
+     */
+    static function ver_match($match_id, $source, $match_data)
+    {
+        foreach ($match_data as $item) {
+            if (!is_array($item)) return false;
+            if ($item['others_match_id'] == $match_id and $item['source'] == $source) return $item['match_id'];
+        }
+        return false;
+    }
+
+
+    /**
+     * @param $sole 唯一标识
+     * @param $source 数据源
+     * @param $odds_data 赔率数据
+     * @return bool|mixed 成功返回 赔率id
+     * 验证赔率
+     */
+    static function ver_odds($sole, $source, $odds_data)
+    {
+        foreach ($odds_data as $item) {
+            if (!is_array($item)) return false;
+            if ($item['sole'] == $sole and $item['source'] == $source) return $item['id'];
+        }
+        return false;
+    }
+
+    /**
+     * @param $odds_only 匹配更新
+     * @param $source 数据源
+     * @param $odds_record_data 赔率记录数据
+     * @return bool|mixed 成功返回 赔率记录id
+     * 验证赔率记录
+     */
+    static function ver_odds_record($odds_only, $source, $odds_record_data)
+    {
+        foreach ($odds_record_data as $item) {
+            if (!is_array($item)) return false;
+            if ($item['odds_only'] == $odds_only and $item['source'] == $source) return $item['id'];
+        }
+        return false;
+    }
+
+    /**
+     * 二维数组根据某个字段去重
+     * @param array $array 二维数组
+     * @para array  去重后的数组
+     */
+    static function uniquArr($array, $key)
+    {
+        if (empty($array)) {
+            return [];
+        }
+        $result = [];
+        foreach ($array as $val) {
+            $keyval = $val[$key];
+            if (!isset($result[$keyval])) {
+                $result[$keyval] = $val;
+            }
+        }
+        return array_values($result);
+    }
+
+    /**
+     * 把数据转为带键的数组,注意要唯一性
+     */
+    static function arrayKeyArr($array, $ukey)
+    {
+        if (empty($array)) {
+            return [];
+        }
+        $ret = [];
+        foreach ($array as $val) {
+            $ret[$val[$ukey]] = $val;
+        }
+        return $ret;
+    }
+
+
+    /**
+     * 按字段 搜索 二维数组
+     */
+    static function searcharray($value, $key, $array, $r_key = '')
+    {
+        foreach ($array as $k => $val) {
+            if ($val[$key] == $value) {
+                return $val[$r_key];
+            }
+        }
+        return null;
+    }
+}
+
+?>

+ 62 - 0
app/Lib/ModelBase.php

@@ -0,0 +1,62 @@
+<?php
+
+namespace App\Lib;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Capsule\Manager as DB;
+
+use datainf\lib\GlobConfigs;
+
+/**
+ * model基类
+ */
+class ModelBase extends Model
+{
+    static protected $db = null;
+    public $timestamps = false;
+    protected $table = '';
+
+    function getSql()
+    {
+        return $this->getConnection()->getQueryLog();
+    }
+
+    static function beginTransaction()
+    {
+        return self::$db->getConnection()->getPdo()->beginTransaction();
+    }
+
+    static function getDB()
+    {
+        return self::$db;
+    }
+
+    static function rollBack()
+    {
+        return self::$db->getConnection()->getPdo()->rollBack();
+    }
+
+    static function commit()
+    {
+        return self::$db->getConnection()->getPdo()->commit();
+    }
+
+    public static function init()
+    {
+        $conf = GlobConfigs::getKey('pgsql');
+        self::$db = new DB();
+        self::$db->addConnection($conf);
+        self::$db->setAsGlobal();
+        self::$db->bootEloquent();
+        return self::$db;
+    }
+
+    public static function close()
+    {
+        if (self::$db) {
+            self::$db->getConnection()->disconnect();
+            self::$db = null;
+        }
+    }
+
+}

+ 15 - 0
app/Lib/TestModel.php

@@ -0,0 +1,15 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/26
+ * Time: 14:01
+ */
+namespace  App\Lib;
+use App\Lib\ModelBase;
+
+class TestModel extends  ModelBase
+{
+    protected $table = 'debug';
+
+}

+ 1228 - 0
app/Logic/DataLogic.php

@@ -0,0 +1,1228 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/26
+ * Time: 17:10
+ */
+
+namespace App\Logic;
+
+use  datainf\pplus\Instance;
+
+use App\Http\Response\Response;
+use App\Lib\ModelBase;
+use Illuminate\Database\Capsule\Manager as DB;
+
+use App\Lib\Biz\Sport\Common as commonFunction;
+use App\Http\Model\StBqResult as BqResultModel;
+use App\Http\Model\StBroadcast as broadcastModel;
+use App\Http\Model\StGameType as gameModel;
+use App\Http\Model\StLqResult as LqResultModel;
+use App\Http\Model\StWqResult as WqResultModel;
+use App\Http\Model\StZqLocalLeague as LeagueModel;
+use App\Http\Model\StZqLocalMatch as MatchModel;
+use App\Http\Model\StZqOdds as OddsModel;
+use App\Http\Model\StZqOddsRecord as OddsRecordModel;
+use App\Http\Model\StZqResult as ZqResultModel;
+
+class DataLogic
+{
+    use Instance;
+
+    /*
+      * 写 联赛 数据
+      * 每个请求 包含 N个联赛
+      */
+    public function setLeague($data)
+    {
+        try {
+            //开启事务
+            DB::beginTransaction();
+            $obt = $data['data'];
+            //请求 数据 为空
+            if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
+            $getData = $this->getAddData($obt);
+            //不是 联赛 数据
+            if ($getData['title'] != 'league') throw new \Exception(Response::generate('不是联赛数据,', Response::ABNORMAL));
+
+            //获取球类代码
+            $game_code = $getData['game_code'];
+            //获取数据源
+            $source = $getData['source'];
+            //获取球类名称
+            $gameName = gameModel::getGameName($game_code);
+
+            //获取 model
+            $models = commonFunction::getModels($game_code, 1);
+
+            //获取 联赛 数据
+            $leagueData = $getData['data'];
+
+            //获取 当前请求 所有 lg_id
+            $s_lg_ids = [];
+            foreach ($leagueData as $k => $v) {
+                $s_lg_ids[] = $v['lg_id'];
+            }
+            $s_lg_ids = array_unique($s_lg_ids);
+            sort($s_lg_ids);
+
+            //获取 本地 已存在 联赛
+            $l_lg_data = $models['model_local_league']::whereIn('others_lg_id', $s_lg_ids)->where('source', $source)->select('others_lg_id', 'lg_id')->get()->toArray();
+            //二维数组去重
+            $l_lg_data = commonFunction::uniquArr($l_lg_data, 'others_lg_id');
+            //循环对比 请求lg_id->本地others_lg_id
+            foreach ($l_lg_data as $k => $v) {
+                foreach ($s_lg_ids as $kk => $s_lg_id) {
+                    if ($v['others_lg_id'] == $s_lg_id) {
+                        unset($s_lg_ids[$kk]);
+                    }
+                }
+            }
+            //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则将其写入
+            if (!empty($s_lg_ids)) {
+                //没有 决赛时间 默认获取本年最后一天
+                $last_time = date('Y-12-31 23:59:59');
+                foreach ($leagueData as $k => $v) {
+                    foreach ($s_lg_ids as $kk => $s_lg_id) {
+                        if ($v['lg_id'] == $s_lg_id) {
+                            //如有 决赛时间
+                            if ($v['last_time']) {
+                                $last_time = $v['last_time'];
+                            }
+                            $set_lg['name_chinese'] = $v['name_chinese'];
+                            $set_lg['kind'] = $v['kind'];
+                            $set_lg['match_mode'] = $v['match_mode'];
+                            $set_lg['if_stop'] = $v['if_stop'];
+                            $set_lg['identity'] = $v['uuid'] ?: '';
+                            $set_lg['last_time'] = $last_time;
+                            $set_lg['utime'] = date('Y-m-d H:i:s');
+                            //写入联赛
+                            $id = $models['model_league']::insertGetId($set_lg);
+                            $m_lg_id = $id;
+                            if ($m_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $v['lg_id'] . ';', Response::INSERT_ERROR));
+
+                            //写入 本地 联赛记录
+                            $set_local = [
+                                'lg_id' => $id,
+                                'others_lg_id' => $v['lg_id'],
+                                'source' => $source,
+                                'ctime' => date('Y-m-d H:i:s')
+                            ];
+                            $ret = $models['model_local_league']::insertGetId($set_local);
+                            if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LOCAL_LEAGUE_ERROR));//Render([], '10017', lang('Tips','Sports')->get('local_league_error'));
+
+                        }
+                    }
+                }
+            }
+
+            $this->writeLog($data,Response::success());
+            //提交事务
+            DB::commit();
+            return Response::success();
+        } catch (\Exception $e) {
+            //回滚事务
+            DB::rollBack();
+            $this->writeLog($data,$e->getMessage());
+            return $e->getMessage();
+        }
+    }
+
+    /*
+     * 写 赛事 数据
+     * 每个请求 包含 N个联赛 下 N个赛事
+     */
+    public function setMatch($data)
+    {
+        try {
+            //开启事务
+            DB::beginTransaction();
+            $obt = $data['data'];
+            //请求 数据 为空
+            if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
+            $getData = $this->getAddData($obt);
+            //不是 赛事 数据
+            if ($getData['title'] != 'match') throw new \Exception(Response::generate('不是赛事数据,', Response::ABNORMAL));
+
+            //获取球类代码
+            $game_code = $getData['game_code'];
+            //获取数据源
+            $source = $getData['source'];
+            //获取球类名称
+            $gameName = gameModel::getGameName($game_code);
+            //获取 model
+            $models = commonFunction::getModels($game_code, 1);
+            //获取 赛事 数据
+            $matchData = $getData['data'];
+
+            //获取 当前请求 所有 lg_id /match_id
+            $s_lg_ids = [];
+            $s_match_ids = [];
+            foreach ($matchData as $k => $v) {
+                $s_lg_ids[] = $v['lg_id'];
+                $s_match_ids[] = $v['match_id'];
+            }
+
+            //====验证 赛事 所属 联赛 是否存在====
+            $s_lg_ids = array_unique($s_lg_ids);
+            sort($s_lg_ids);
+
+            //获取 本地 已存在 联赛
+            $l_lg_data = $models['model_local_league']::whereIn('others_lg_id', $s_lg_ids)->where('source', $source)->select('others_lg_id', 'lg_id')->get()->toArray();
+            //二维数组去重
+            $l_lg_data = commonFunction::uniquArr($l_lg_data, 'others_lg_id');
+            //循环对比 请求lg_id->本地others_lg_id
+            foreach ($l_lg_data as $k => $v) {
+                foreach ($s_lg_ids as $kk => $s_lg_id) {
+                    if ($v['others_lg_id'] == $s_lg_id) {
+                        unset($s_lg_ids[$kk]);
+                    }
+                }
+            }
+            //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常
+            if (!empty($s_lg_ids)) throw new \Exception(Response::generate($gameName . '联赛:lg_id-' . $s_lg_ids[0] . ';', Response::LEAGUE_ERROR));
+            //====end====
+
+            //====获取 本地 已存在 赛事====
+            $s_match_ids = array_unique($s_match_ids);
+            sort($s_match_ids);
+
+            $l_match_data = $models['model_local_match']::whereIn('others_match_id', $s_match_ids)->where('source', $source)->select('others_match_id', 'match_id')->get()->toArray();
+            //二维数组去重
+            $l_match_data = commonFunction::uniquArr($l_match_data, 'others_match_id');
+
+            //循环对比 请求match_id->本地others_match_id
+            foreach ($l_match_data as $k => $v) {
+                foreach ($s_match_ids as $kk => $s_match_id) {
+                    if ($v['others_match_id'] == $s_match_id) {
+                        unset($s_match_ids[$kk]);
+                    }
+                }
+            }
+
+            //剩余 赛事 数据 写入
+            if (!empty($s_match_ids)) {
+                foreach ($matchData as $k => $v) {
+                    foreach ($s_match_ids as $kk => $s_match_id) {
+                        if ($v['match_id'] == $s_match_id) {
+                            $data = $v;
+                            $half_match_id = 0;
+                            //获取 本地 联赛 ID
+                            $lg_id = commonFunction::searcharray($data['lg_id'], 'others_lg_id', $l_lg_data, 'lg_id');
+                            //如果有上半场赛事id 获取上半场赛事是否存在
+                            if (!empty($data['half_match_id'])) {
+                                $half_match_id = $models['model_local_match']::where(['others_match_id' => $data['half_match_id'], 'source' => $source])
+                                    ->value('match_id');
+                                if (empty($half_match_id)) throw new \Exception(Response::generate($gameName . '上半场赛事-match_id:' . $data['match_id'] . ';', Response::HALF_MATCH_ERROR));//Render([], '10024', lang('Tips','Sports')->get('half_match_error'));
+                            }
+                            //如果赛事没有开始日期,则为冠军盘口赛事
+                            if (empty($data['match_date'])) {
+                                //冠军盘口赛事获取所属联赛结束时间
+                                $last_time = $models['model_league']::where(['id' => $lg_id])
+                                    ->value('last_time');
+
+                                if (empty($last_time)) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LG_LASTTIME_ERROR));//Render([], '10023', lang('Tips','Sports')->get('lg_lastTime_error'));
+                                //给冠军盘口赛事 赋值时间
+                                $time = strtotime($last_time);
+                                $data['match_date'] = date('Y-m-d', $time);
+                                $data['match_time'] = date('H:i:s', $time);
+                            }
+                            $set_match = [
+                                'ctime' => date('Y-m-d H:i:s'),
+                                'utime' => date('Y-m-d H:i:s'),
+                                'expire_time' => date('Y-m-d H:i:s', time() + 60),
+                                'home_team' => $data['home_team'] ?: '',
+                                'guest_team' => $data['guest_team'] ?: 'no_team',
+                                'lg_id' => $lg_id,
+                                'status' => $data['status'],
+                                'match_date' => $data['match_date'] ?: date('Y-m-d'),
+                                'match_time' => $data['match_time'] ?: date('H:i:s'),
+                                'tag' => $data['tag'] ?: 0,
+                                'is_rollball' => $data['is_rollball'] ?: 0,
+                                'is_today' => $data['is_today'] ?: 0,
+                                'is_morningplate' => $data['is_morningplate'] ?: 0,
+                                'is_stringscene' => $data['is_stringscene'] ?: 0,
+                                'us_time' => $data['us_time'] ?: commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
+                                'half_match_id' => $half_match_id ?: 0,
+                                'identity' => $data['uuid'],
+                            ];
+                            //写入赛事 返回id
+                            $id = $models['model_match']::insertGetId($set_match);
+                            if ($id < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::INSERT_ERROR));
+
+                            //写关联记录
+                            $set_local = [
+                                'match_id' => $id,
+                                'others_match_id' => $data['match_id'],
+                                'source' => $source,
+                                'ctime' => date('Y-m-d H:i:s')
+                            ];
+                            $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'));
+                        }
+                    }
+                }
+            }
+
+            $this->writeLog($data,Response::success());
+            //提交事务
+            DB::commit();
+            return Response::success();
+        } catch (\Exception $e) {
+            //回滚事务
+            DB::rollBack();
+            $this->writeLog($data,$e->getMessage());
+            return $e->getMessage();
+        }
+
+    }
+
+    /*
+     * 写 赛事 结果 记录 数据
+     * 每个请求 包含 N个联赛 下 N个赛事 结果数据
+     */
+    public function setMatchResult($data)
+    {
+        try {
+            //开启事务
+            DB::beginTransaction();
+            $obt = $data['data'];
+            //请求 数据 为空
+            if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
+            $getData = $this->getAddData($obt);
+            //不是 赛事 结果 记录 数据
+            if ($getData['title'] != 'match_result_r') throw new \Exception(Response::generate('不是赛事结果记录数据,', Response::ABNORMAL));
+
+            //获取球类代码
+            $game_code = $getData['game_code'];
+            //获取数据源
+            $source = $getData['source'];
+            //获取球类名称
+            $gameName = gameModel::getGameName($game_code);
+            //获取 model
+            $models = commonFunction::getModels($game_code, 1);
+            //获取 赛事 数据
+            $match_r_data = $getData['data'];
+
+            //获取 当前请求 所有 lg_id /match_id
+            $s_lg_ids = [];
+            $s_match_ids = [];
+            foreach ($match_r_data as $k => $v) {
+                $s_lg_ids[] = $v['lg_id'];
+                $s_match_ids[] = $v['match_id'];
+            }
+
+            //====验证 赛事结果记录 所属 联赛 是否存在====
+            $s_lg_ids = array_unique($s_lg_ids);
+            sort($s_lg_ids);
+
+            //获取 本地 已存在 联赛
+            $l_lg_data = $models['model_local_league']::whereIn('others_lg_id', $s_lg_ids)->where('source', $source)->select('others_lg_id', 'lg_id')->get()->toArray();
+            //二维数组去重
+            $l_lg_data = commonFunction::uniquArr($l_lg_data, 'others_lg_id');
+
+            //循环对比 请求lg_id->本地others_lg_id
+            foreach ($l_lg_data as $k => $v) {
+                foreach ($s_lg_ids as $kk => $s_lg_id) {
+                    if ($v['others_lg_id'] == $s_lg_id) {
+                        unset($s_lg_ids[$kk]);
+                    }
+                }
+            }
+
+            //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常
+            if (!empty($s_lg_ids)) throw new \Exception(Response::generate($gameName . '联赛:lg_id-' . $s_lg_ids[0] . ';', Response::LEAGUE_ERROR));
+            //====end====
+
+            //====验证 赛事结果记录 所属赛事 是否存在====
+            $s_match_ids = array_unique($s_match_ids);
+            sort($s_match_ids);
+
+            //获取 本地 已存在 赛事
+            $l_match_data = $models['model_local_match']::whereIn('others_match_id', $s_match_ids)->where('source', $source)->select('others_match_id', 'match_id')->get()->toArray();
+            //二维数组去重
+            $l_match_data = commonFunction::uniquArr($l_match_data, 'others_match_id');
+
+            //循环对比 请求match_id->本地others_match_id
+            foreach ($l_match_data as $k => $v) {
+                foreach ($s_match_ids as $kk => $s_match_id) {
+                    if ($v['others_match_id'] == $s_match_id) {
+                        unset($s_match_ids[$kk]);
+                    }
+                }
+            }
+
+            //去除本地和请求里都存在的赛事,如果还有剩余赛事id,则返回异常
+            if (!empty($s_match_ids)) throw new \Exception(Response::generate($gameName . '赛事-match_id' . $s_match_ids[0] . ';', Response::MATCH_ERROR));
+            //====end====
+
+            //处理 赛事 结果记录 数据
+            foreach ($match_r_data as $k => $v) {
+                $data = $v;
+                //获取 本地 联赛 ID
+                $lg_id = commonFunction::searcharray($data['lg_id'], 'others_lg_id', $l_lg_data, 'lg_id');
+                //获取 本地 赛事 ID
+                $match_id = commonFunction::searcharray($data['match_id'], 'others_match_id', $l_match_data, 'match_id');
+
+                //根据球类 获取 赛事结果记录字段
+                $set_match_r = $this->get_match_r($game_code, $lg_id, $match_id, $data);
+                //写 赛事 结果 记录
+                $ret = $models['model_result_record']::insert($set_match_r);
+                if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));
+            }
+
+            $this->writeLog($data,Response::success());
+            //提交事务
+            DB::commit();
+            return Response::success();
+        } catch (\Exception $e) {
+            //回滚事务
+            DB::rollBack();
+            $this->writeLog($data,$e->getMessage());
+            return $e->getMessage();
+        }
+
+    }
+
+    /*
+     * 写 普通 赔率 数据
+     * 每个请求 只包含 一场赛事下 N条赔率
+     */
+    public function setOdds($data)
+    {
+
+        try {
+            //开启事务
+            DB::beginTransaction();
+            $obt = $data['data'];
+            //请求 数据 为空
+            if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
+            $getData = $this->getAddData($obt);
+            //不是 赔率 数据
+            if ($getData['title'] != 'odds') throw new \Exception(Response::generate('不是赔率数据,', Response::ABNORMAL));
+
+            //获取球类代码
+            $game_code = $getData['game_code'];
+            //获取数据源
+            $source = $getData['source'];
+            //获取源数据联赛ID
+            $s_lg_id = $getData['lg_id'];
+            //获取源数据赛事ID
+            $s_match_id = $getData['match_id'];
+
+            //获取球类名称
+            $gameName = gameModel::getGameName($game_code);
+            //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
+            $models = commonFunction::getModels($game_code, 1);
+            $lg_id = $this->leagueVerify($models, $s_lg_id, $source, $gameName);
+            $match_id = $this->matchVerify($models, $s_match_id, $source, $gameName);
+
+            //获取 赔率数据
+            $oddsData = $getData['data'];
+            //获取 当前 所有 可用 赔率 sole
+            $odds_only = $getData['odds_only'];
+            //更新赛事下所有 不在本次请求的赔率 状态
+            $ret = OddsModel::getMatchSole($models, $s_match_id, '', $source, $odds_only);
+            if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
+
+            //拼装 待写入 赔率数据
+            foreach ($oddsData as $k => $v) {
+                //组装数据
+                $set_odds = [
+                    'match_id' => $match_id ?: 0,
+                    'others_match_id' => $v['match_id'] ?: 0,
+                    'odds_code' => $v['odds_code'] ?: '',
+                    'status' => $v['status'] ?: 0,
+                    'sort' => $v['sort'] ?: 0,
+                    'p_code' => $v['p_code'] ?: '',
+                    'odds' => $v['odds'] ?: 0,
+                    'condition' => $v['condition'],
+                    'odds_only' => $v['odds_only'] ?: '',
+                    'source' => $v['source'] ?: '',
+                    'type' => $v['type'] ?: 0,
+                    'team' => $v['team'] ?: '',
+                    'lg_id' => $lg_id,
+                    'others_lg_id' => $v['lg_id'],
+                    'ctime' => date('Y-m-d H:i:s'),
+                    'utime' => date('Y-m-d H:i:s'),
+                ];
+                //写赔率记录数据
+                $ret = $models['model_odds_record']->updateOrCreate(
+                    ['odds_only' => $v['odds_only']], $set_odds
+                );
+                if (empty($ret)) throw new \Exception(Response::generate($gameName . '赔率记录-odds_only:' . $v['odds_only'] . ';', Response::ADD_ODDS_R_ERROR));
+
+                //追加参数
+                $set_odds['sole'] = $v['sole'];
+                $set_odds['expire_time'] = date('Y-m-d H:i:s', time() + 60);
+                //写赔率 数据
+                $ret = $models['model_odds']->updateOrCreate(
+                    ['odds_only' => $v['odds_only']], $set_odds
+                );
+                if (empty($ret)) throw new \Exception(Response::generate($gameName . '赔率-odds_only:' . $v['odds_only'] . ';', Response::ADD_ODDS_ERROR));
+            }
+
+            $this->writeLog($data,Response::success());
+            //提交事务
+            DB::commit();
+            return Response::success();
+        } catch (\Exception $e) {
+            //回滚事务
+            DB::rollBack();
+            $this->writeLog($data,$e->getMessage());
+            return $e->getMessage();
+        }
+    }
+
+    /**
+     * @param Req $data
+     * @return string
+     * @throws \App\Lib\Biz\Sport\Exception
+     * 更新赛事状态
+     */
+    public function upMatch($data){
+        try {
+            //开启事务
+            DB::beginTransaction();
+            //获取待更新赛事
+            $obt = $data->data;
+            if($obt){
+                //json转数组
+                $data = $this->getAddData($obt);
+                //获取 球类代码
+                $game_code = $data['game_code'];
+                //获取 数据源
+                $source = $data['source'];
+
+                //获取所有数据源赛事 match_id
+                $others_match_ids = [];
+                foreach ($data['data'] as $k=>$v){
+                    $others_match_ids[] = $v['match_id'];
+                }
+                //根据球类代码 获取model
+                $model =commonFunction::getModels($game_code,1);
+                //获取所有赛事 match_id
+                $local_match = $model['model_local_match']::SELECT('others_match_id','match_id')
+                    ->where(['source'=>$source])
+                    ->whereIn('others_match_id',$others_match_ids)
+                    ->get()->toArray();
+                if(empty($local_match)) throw new \Exception(Response::generate('',Response::MATCHID_NULL));
+                //更新状态字段
+                foreach ($local_match as $k=>$v){
+                    $set_status = [
+                        'status'=>$v['status'],
+                        'is_rollball'=>$v['is_rollball'],
+                        'stais_todaytus'=>$v['is_today'],
+                        'is_morningplate'=>$v['is_morningplate'],
+                        'is_stringscene'=>$v['is_stringscene'],
+                        'is_horn'=>$v['is_horn'],
+                    ];
+                    $ret = $model['model_match']::where(['id'=>$v['match_id']])
+                        -> update($set_status);
+                    if($ret<1) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'赛事-match_id:'.$v['others_match_id'],Response::UPSTATUS_ERROR));
+                }
+            }
+
+            $this->writeLog($data,Response::success());
+            //提交事务
+            DB::commit();
+            return Response::success();
+        } catch (\Exception $e) {
+            //回滚事务
+            DB::rollBack();
+            $this->writeLog($data,$e->getMessage());
+            return $e->getMessage();
+        }
+    }
+
+
+
+    /*
+    *写 冠军联赛 赔率 数据
+    *每个请求 包含 N个联赛 下 N条赔率
+    */
+    public function setOddsCH($data)
+    {
+
+        try {
+            //开启事务
+            DB::beginTransaction();
+            $obt = $data['data'];
+
+            //请求 数据 为空
+            if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
+            $getData = $this->getAddData($obt);
+            //不是 冠军 赔率 数据
+            if ($getData['title'] != 'odds_ch') throw new \Exception(Response::generate('不是冠军赔率数据,', Response::ABNORMAL));
+
+            //获取球类代码
+            $game_code = $getData['game_code'];
+            //获取数据源
+            $source = $getData['source'];
+            //获取球类名称
+            $gameName = gameModel::getGameName($game_code);
+
+            //获取 model
+            $models = commonFunction::getModels($game_code, 1);
+
+            //获取 赔率数据
+            $oddsData = $getData['data'];
+            //获取 当前 所有 可用 赔率 sole
+            // $odds_only = $getData['odds_only'];
+
+            //====验证 请求里 所有赔率 所属联赛 是否存在 ====
+            //获取 当前请求 所有 lg_id
+            foreach ($oddsData as $k => $v) {
+                $s_lg_ids[] = $v['lg_id'];
+            }
+            $s_lg_ids = array_unique($s_lg_ids);
+            sort($s_lg_ids);
+
+            //更新赛事下所有 不在本次请求的赔率 状态
+            // $ret= OddsModel::getMatchSole($models,'',$s_lg_ids,$source,$odds_only);
+            // if($ret != true) throw new \Exception(Response::generate($gameName,Response::ODDS_SOLE_ERR));
+
+            //获取 本地 已存在 联赛
+            $l_lg_data = $models['model_local_league']::whereIn('others_lg_id', $s_lg_ids)->where('source', $source)->select('others_lg_id', 'lg_id')->get()->toArray();
+            //二维数组去重
+            $l_lg_data = commonFunction::uniquArr($l_lg_data, 'others_lg_id');
+            //循环对比 请求lg_id->本地others_lg_id
+            foreach ($l_lg_data as $k => $v) {
+                foreach ($s_lg_ids as $kk => $s_lg_id) {
+                    if ($v['others_lg_id'] == $s_lg_id) {
+                        unset($s_lg_ids[$kk]);
+                    }
+                }
+            }
+
+            //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常;
+            if (!empty($s_lg_ids)) throw new \Exception(Response::generate($gameName . '冠军联赛:lg_id-' . $s_lg_ids[0] . ';', Response::LEAGUE_ERROR));
+            //====end====
+            //拼装 待写入 赔率数据
+            foreach ($oddsData as $k => $v) {
+                //获取 本地 联赛 ID
+                $lg_id = commonFunction::searcharray($v['lg_id'], 'others_lg_id', $l_lg_data, 'lg_id');
+                //组装数据
+                $set_odds = [
+                    'match_id' => 0,
+                    'others_match_id' => $v['match_id'] ?: 0,
+                    'odds_code' => $v['odds_code'] ?: '',
+                    'status' => $v['status'] ?: 0,
+                    'sort' => $v['sort'] ?: 0,
+                    'p_code' => $v['p_code'] ?: '',
+                    'odds' => $v['odds'] ?: 0,
+                    'condition' => $v['condition'],
+                    'odds_only' => $v['odds_only'] ?: '',
+                    'source' => $v['source'] ?: '',
+                    'type' => $v['type'] ?: 1,
+                    'team' => $v['team'] ?: '',
+                    'lg_id' => $lg_id,
+                    'others_lg_id' => $v['lg_id'],
+                    'ctime' => date('Y-m-d H:i:s'),
+                    'utime' => date('Y-m-d H:i:s'),
+                ];
+                //写赔率记录数据
+                $ret = $models['model_odds_record']->updateOrCreate(
+                    ['odds_only' => $v['odds_only']], $set_odds
+                );
+                if (empty($ret)) throw new \Exception(Response::generate($gameName . '赔率记录-odds_only:' . $v['odds_only'] . ';', Response::ADD_ODDS_R_ERROR));
+
+                //追加参数
+                $set_odds['sole'] = $v['sole'];
+                $set_odds['expire_time'] = date('Y-m-d H:i:s', time() + 60);
+                //写赔率 数据
+                $ret = $models['model_odds']->updateOrCreate(
+                    ['odds_only' => $v['odds_only']], $set_odds
+                );
+                if (empty($ret)) throw new \Exception(Response::generate($gameName . '赔率-odds_only:' . $v['odds_only'] . ';', Response::ADD_ODDS_ERROR));
+            }
+
+            $this->writeLog($data,Response::success());
+            //提交事务
+            DB::commit();
+            return Response::success();
+        } catch (\Exception $e) {
+            //回滚事务
+            DB::rollBack();
+            $this->writeLog($data,$e->getMessage());
+            return $e->getMessage();
+        }
+    }
+
+    /*
+    * 写入直播 数据
+    */
+    public function setBroadCast($data)
+    {
+
+        try {
+            //开启事务
+            DB::beginTransaction();
+            $obt = $data['data'];
+            //请求 数据 为空
+            if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
+            $getData = $this->getAddData($obt);
+            //不是 直播 数据
+            if ($getData['title'] != 'broad_cast') throw new \Exception(Response::generate('不是直播数据,', Response::ABNORMAL));
+
+            //获取 球类
+            $game_code = $getData['game_code'];
+            //获取 直播 数据
+            $BroadCast = $getData['data'];
+            $set_broadcast = [];
+            foreach ($BroadCast as $k => $data) {
+                //组装数据
+                $set_broadcast[] = [
+                    "doing" => $data['doing'],
+                    "game_type" => $data['game_type'],
+                    "game_code" => $game_code,
+                    "guest_team" => $data['guest_team'],
+                    "host_team" => $data['host_team'],
+                    "league_name" => $data['league_name'],
+                    "shower" => $data['shower'],
+                    "showid" => (int)$data['showid'],
+                    "start_time" => $data['start_time'],
+                    "ctime" => date('Y-m-d H:i:s'),
+                    "utime" => date('Y-m-d H:i:s'),
+                ];
+            }
+            //写入 直播 数据
+            $ret = broadcastModel::insert($set_broadcast);
+            if ($ret == false) throw new \Exception(Response::generate('', Response::BROADCAST_ERROR));
+
+            $this->writeLog($data,Response::success());
+            //提交事务
+            DB::commit();
+            return Response::success();
+        } catch (\Exception $e) {
+            //回滚事务
+            DB::rollBack();
+            $this->writeLog($data,$e->getMessage());
+            return $e->getMessage();
+        }
+    }
+
+    /*
+     * 验证所属 联赛 是否存在
+     */
+    public function leagueVerify($models = [], $s_lg_id = '', $source = '', $gameName = '')
+    {
+        if (empty($models) || empty($s_lg_id)) throw new \Exception(Response::generate('', Response::ABNORMAL));
+        $l_lg_id = $models['model_local_league']::where(['others_lg_id' => $s_lg_id, 'source' => $source])->value('lg_id');
+
+        if ($l_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛:lg_id-' . $s_lg_id, Response::LEAGUE_ERROR));
+        return $l_lg_id;
+    }
+
+    /*
+     * 验证所属 赛事 是否存在
+     */
+    public function matchVerify($models = [], $s_match_id = '', $source = '', $gameName = '')
+    {
+        if (empty($models) || empty($s_match_id)) throw new \Exception(Response::generate('', Response::ABNORMAL));
+        $l_match_id = $models['model_local_match']::where(['others_match_id' => $s_match_id, 'source' => $source])->value('match_id');
+
+        if ($l_match_id < 1) throw new \Exception(Response::generate($gameName . '赛事:match_id-' . $s_match_id, Response::MATCH_ERROR));
+        return $l_match_id;
+    }
+
+
+    /*
+     * 写入直播 数据
+     */
+    public function broadcast($opt = [], $game_code = '')
+    {
+        $data = $opt['data'];
+        $set_broadcast = [
+            "doing" => $data['doing'],
+            "game_type" => $data['game_type'],
+            "game_code" => $game_code,
+            "guest_team" => $data['guest_team'],
+            "host_team" => $data['host_team'],
+            "league_name" => $data['league_name'],
+            "shower" => $data['shower'],
+            "showid" => (int)$data['showid'],
+            "start_time" => $data['start_time'],
+            "ctime" => date('Y-m-d H:i:s'),
+            "utime" => date('Y-m-d H:i:s'),
+        ];
+        $ret = broadcastModel::insert($set_broadcast);
+        if ($ret == false) throw new \Exception(Response::generate('', Response::BROADCAST_ERROR));
+    }
+
+    /*
+     * 写入 赛事 初始 结果
+     */
+    public function match_result($game_code = '')
+    {
+        $model = commonFunction::getModels($game_code, 1);
+        if ($game_code == 'zq') ZqResultModel::ZQresult($model);
+        if ($game_code == 'lq') LqResultModel::LQresult($model);
+        if ($game_code == 'wq') WqResultModel::WQresult($model);
+        if ($game_code == 'bq') BqResultModel::BQresult($model);
+    }
+
+    /*
+     * 写入联赛数据
+     */
+    public function league($opt = [], $gameName = '')
+    {
+        $game_code = $opt['game_code'];
+        //根据球类代码获取相关model
+        $model = commonFunction::getModels($game_code, 1);
+        $data = $opt['data'];
+
+        //查询联赛是否已存在
+        $id = $model['model_league']::where('name_chinese', '=', $data['name_chinese'])
+            ->value('id');
+        //默认获取本年最后一天
+        $last_time = date('Y-12-31 23:59:59');
+        //决赛时间
+        if ($data['last_time']) {
+            $last_time = $data['last_time'];
+        }
+        $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['identity'] = $data['uuid'] ?: '';
+        $set_lg['last_time'] = $last_time;
+        $set_lg['utime'] = date('Y-m-d H:i:s');
+        if (empty($id)) {
+            //写入联赛
+            $id = $model['model_league']::insertGetId($set_lg);
+            $m_lg_id = $id;
+            if ($m_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::INSERT_ERROR));
+        } else {
+            //更新联赛
+            $ret = $model['model_league']::where(['id' => $id])
+                ->update($set_lg);
+            if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::UPDATE_ERROR));
+        }
+
+        $set_local = [
+            'lg_id' => $id,
+            'others_lg_id' => $data['lg_id'],
+            'source' => $data['source'],
+            'ctime' => date('Y-m-d H:i:s')
+        ];
+        $ret = $model['model_local_league']::insertGetId($set_local);
+        if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LOCAL_LEAGUE_ERROR));//Render([], '10017', lang('Tips','Sports')->get('local_league_error'));
+
+        //执行成功返回源数据 联赛ID
+        $data = ['others_lg_id' => $data['lg_id'], 'lg_id' => $id];
+        return $data;
+    }
+
+    /*
+     * 写入赛事数据
+     */
+    public function competition($opt = [], $gameName = '', $lg_id = '')
+    {
+        $game_code = $opt['game_code'];
+        //根据球类代码获取相关model
+        $model = commonFunction::getModels($game_code, 1);
+        $data = $opt['data'];
+        if (empty($data['lg_id'])) throw new \Exception(Response::generate('', Response::LEAGUE_ERROR));//Render([], '10015', lang('Tips','Sports')->get('league_error'));
+
+        //查询赛事是否存在
+        $id = $model['model_match']::where(['home_team' => $data['home_team'], 'guest_team' => $data['guest_team'], 'match_date' => $data['match_date'], 'match_time' => $data['match_time']])
+            ->value('id');
+
+        $half_match_id = 0;
+        //如果有上半场赛事id 获取上半场赛事是否存在
+        if (!empty($data['half_match_id'])) {
+            $half_match_id = $match_id = $model['model_local_match']::where(['others_match_id' => $data['half_match_id'], 'source' => $data['source']])
+                ->value('match_id');
+            if (empty($half_match_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::HALF_MATCH_ERROR));//Render([], '10024', lang('Tips','Sports')->get('half_match_error'));
+        }
+        //如果赛事没有开始日期,则为冠军盘口赛事
+        if (empty($data['match_date'])) {
+            //冠军盘口赛事获取所属联赛结束时间
+            $last_time = $model['model_league']::where(['id' => $lg_id])
+                ->value('last_time');
+
+            if (empty($last_time)) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LG_LASTTIME_ERROR));//Render([], '10023', lang('Tips','Sports')->get('lg_lastTime_error'));
+            //给冠军盘口赛事 赋值时间
+            $time = strtotime($last_time);
+            $data['match_date'] = date('Y-m-d', $time);
+            $data['match_time'] = date('H:i:s', $time);
+        }
+        $set_match = [
+            'ctime' => date('Y-m-d H:i:s'),
+            'utime' => date('Y-m-d H:i:s'),
+            'expire_time' => date('Y-m-d H:i:s', time() + 60),
+            'home_team' => $data['home_team'] ?: '',
+            'guest_team' => $data['guest_team'] ?: 'no_team',
+            'lg_id' => $lg_id,
+            'status' => $data['status'],
+            'match_date' => $data['match_date'] ?: date('Y-m-d'),
+            'match_time' => $data['match_time'] ?: date('H:i:s'),
+            'tag' => $data['tag'] ?: 0,
+            'is_rollball' => $data['is_rollball'] ?: 0,
+            'is_today' => $data['is_today'] ?: 0,
+            'is_morningplate' => $data['is_morningplate'] ?: 0,
+            'is_stringscene' => $data['is_stringscene'] ?: 0,
+            'us_time' => $data['us_time'] ?: commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
+            'half_match_id' => $half_match_id ?: 0,
+            'identity' => $data['uuid'],
+        ];
+        //写入赛事
+        if (empty($id)) {
+            //写入赛事 返回id
+            $id = $model['model_match']::insertGetId($set_match);
+            if ($id < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::INSERT_ERROR));
+        } else {
+            //更新赛事
+            $ret = $model['model_match']::where(['id' => $id])->update($set_match);
+            if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::UPDATE_ERROR));
+        }
+
+        //写关联记录
+        $set_local = [
+            'match_id' => $id,
+            'others_match_id' => $data['match_id'],
+            'source' => $data['source'],
+            'ctime' => date('Y-m-d H:i:s')
+        ];
+        $ret = $model['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'));
+
+        //返回 源数据 赛事ID
+        $data = ['others_match_id' => $data['match_id'], 'match_id' => $id];
+        return $data;
+    }
+
+    /*
+     * 写入赔率/赔率记录数据
+     */
+    public function odds($opt = [], $gameName = '', $lg_id = 0, $match_id = 0, $oddsID = '', $oddsRecordID = '')
+    {
+        $game_code = $opt['game_code'];
+        //根据球类代码获取相关model
+        $model = commonFunction::getModels($game_code, 1);
+        $data = $opt['data'];
+
+        //获取赛事 本地/源ID
+        $others_match_id = $data['match_id'];
+
+        //获取联赛 本地/源ID
+        $others_lg_id = $data['lg_id'];
+        //===写赔率记录===
+        $set_odds_r = [
+            'match_id' => $match_id ?: 0,
+            'others_match_id' => $others_match_id ?: 0,
+            'odds_code' => $data['odds_code'] ?: '',
+            'status' => $data['status'] ?: 0,
+            'sort' => $data['sort'] ?: 0,
+            'p_code' => $data['p_code'] ?: '',
+            'odds' => $data['odds'] ?: 0,
+            'condition' => $data['condition'],
+            'odds_only' => $data['odds_only'] ?: '',
+            'source' => $data['source'] ?: '',
+            'type' => $data['type'] ?: 0,
+            'team' => $data['team'] ?: '',
+            'lg_id' => $lg_id,
+            'others_lg_id' => $others_lg_id,
+            'ctime' => date('Y-m-d H:i:s'),
+        ];
+        //更新或写入赔率记录
+        if ($oddsRecordID != false) {
+            $ret = $model['model_odds_record']::where(['id' => $oddsRecordID])
+                ->update($set_odds_r);
+            if ($ret < 1) throw new \Exception(Response::generate($gameName . '赔率记录-odds_only:' . $data['odds_only'] . ';', Response::ADD_ODDS_R_ERROR));//Render([], '10020', lang('Tips','Sports')->get('add_odds_r_error'));
+        } else {
+            $ret = $model['model_odds_record']::insert($set_odds_r);
+            if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录-odds_only:' . $data['odds_only'] . ';', Response::ADD_ODDS_R_ERROR));//Render([], '10020', lang('Tips','Sports')->get('add_odds_r_error'));
+        }
+
+        //===写赔率===
+        $set_odds = [
+            'match_id' => $match_id ?: 0,
+            'others_match_id' => $others_match_id ?: 0,
+            'odds_code' => $data['odds_code'] ?: '',
+            'status' => $data['status'] ?: 0,
+            'sort' => $data['sort'] ?: 0,
+            'p_code' => $data['p_code'] ?: '',
+            'odds' => $data['odds'] ?: 0,
+            'condition' => $data['condition'],
+            'odds_only' => $data['odds_only'] ?: '',
+            'sole' => $data['sole'] ?: '',
+            'source' => $data['source'] ?: '',
+            'type' => $data['type'] ?: 0,
+            'team' => $data['team'] ?: '',
+            'lg_id' => $lg_id,
+            'others_lg_id' => $others_lg_id,
+            'ctime' => date('Y-m-d H:i:s'),
+            'utime' => date('Y-m-d H:i:s'),
+            'expire_time' => date('Y-m-d H:i:s', time() + 60),
+        ];
+        //更新或写入赔率数据
+        if ($oddsID != false) {
+            $ret = $model['model_odds']::where(['id' => $oddsID])
+                ->update($set_odds);
+            if ($ret < 1) throw new \Exception(Response::generate($gameName . '赔率-odds_only:' . $data['odds_only'] . ';', Response::ADD_ODDS_ERROR));//Render([], '10019', lang('Tips','Sports')->get('add_odds_error'));
+        } else {
+            $ret = $model['model_odds']::insert($set_odds);
+            if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率-odds_only:' . $data['odds_only'] . ';', Response::ADD_ODDS_ERROR));//Render([], '10019', lang('Tips','Sports')->get('add_odds_error'));
+        }
+        //===end===
+    }
+
+    /*
+     * 更新 赛事下 所有不在本次请求的 赔率状态
+     */
+    public function upOddsStatus($opt = [], $gameName = '')
+    {
+        //获取球类代码
+        $game_code = $opt['game_code'];
+        //获取球类model
+        $model = commonFunction::getModels($game_code, 1);
+        //赛事下 所有 赔率sole
+        $odds_sole = $opt['data'];
+        //数据源 赛事 id
+        $others_match_id = $opt['match_id'];
+        //数据源
+        $source = $opt['source'];
+        //更新赛事下所有 不在本次请求的赔率 状态
+        $ret = OddsModel::getMatchSole($model, $others_match_id, '', $source, $odds_sole);
+        if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
+    }
+
+    /*
+     * 写入联赛结果
+     */
+    public function league_result($opt, $gameName)
+    {
+        $game_code = $opt['game_code'];
+        //根据球类代码获取相关model
+        $model = commonFunction::getModels($game_code, 1);
+        $data = $opt['data'];
+
+        //验证结果所属联赛
+        $lg_id = $model['model_local_league']::where(['others_lg_id' => $data['lg_id'], 'source' => $data['source']])
+            ->value('lg_id');
+        if ($lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LEAGUE_ERROR));
+
+        $lg_result_id = $model['model_league_result']::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' => date('Y-m-d H:i:s'),
+            'utime' => date('Y-m-d H:i:s'),
+        ];
+        //联赛结果数据处理
+        if (!empty($lg_result_id)) {
+            $ret = $model['model_league_result']::where(['id' => $lg_result_id])
+                ->update($set_lg_result);
+            if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::ADD_LG_R_ERROR));//Render([], '10021', lang('Tips','Sports')->get('add_lg_r_error'));
+        } else {
+            $ret = $model['model_league_result']::insert($set_lg_result);
+            if ($ret != true) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::ADD_LG_R_ERROR));//Render([], '10021', lang('Tips','Sports')->get('add_lg_r_error'));
+        }
+    }
+
+    /*
+     * 写入赛事结果
+     */
+    public function com_result($opt = [], $gameName = '', $lg_id = '', $match_id = '')
+    {
+        $game_code = $opt['game_code'];
+        //根据球类代码获取相关model
+        $model = commonFunction::getModels($game_code, 1);
+        $data = $opt['data'];
+        //查询结果是否存在
+        $match_r_id = $model['model_result']::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" => date('Y-m-d H:i:s')
+        ];
+        //赛事结果数据处理
+        if (!empty($match_r_id)) {
+            $ret = $model['model_result']::where(['id' => $match_r_id])
+                ->update($set_match_r);
+            if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
+        } else {
+            $ret = $model['model_result']::insert($set_match_r);
+            if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
+        }
+//        return Response::success();
+    }
+
+    //写入赛事结果记录
+    public function com_result_record($opt = [], $gameName = '', $lg_id = '', $match_id = '')
+    {
+        $game_code = $opt['game_code'];
+        //根据球类代码获取相关model
+        $model = commonFunction::getModels($game_code, 1);
+        $data = $opt['data'];
+
+        $match_r_id = $model['model_result_record']::where(['match_id' => $match_id, 'match_time' => $data['match_time']])
+            ->value('id');
+        //根据球类 获取 赛事结果记录字段
+        $set_match_r = $this->get_match_r($game_code, $lg_id, $match_id, $data);
+
+        //赛事结果记录处理
+        if ($match_r_id > 0) {
+            $ret = $model['model_result_record']::where(['id' => $match_r_id])
+                ->update($set_match_r);
+            if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_r_error'));
+        } else {
+            $ret = $model['model_result_record']::insert($set_match_r);
+            if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_r_error'));
+        }
+    }
+
+    /**
+     * @param $data
+     * @return mixed
+     * json转数组
+     */
+    public function getAddData($data)
+    {
+
+        $data = json_decode($data, true);
+
+        return $data;
+    }
+
+    /*
+     * 根据球类获取 赛事结果记录字段
+     */
+    public function get_match_r($game_code, $lg_id, $match_id, $data)
+    {
+        $set_match_r = [];
+        if ($game_code == 'zq') {
+            $set_match_r = [
+                "home_team" => $data['home_team'] ?: '',
+                "guest_team" => $data['guest_team'] ?: '',
+                "lg_id" => $lg_id,
+                "all_goal" => $data['all_goal'] ?: 0,
+                "home_rate" => $data['home_rate'] ?: 0,
+                "guest_rate" => $data['guest_rate'] ?: 0,
+                "home_score" => $data['home_score'] ?: 0,
+                "guest_score" => $data['guest_score'] ?: 0,
+                "status" => $data['status'] ?: 0,
+                "first_score" => $data['first_score'] ?: 0,
+                "last_score" => $data['last_score'] ?: 0,
+                "match_score" => $data['match_score'] ?: 0,
+                "match_winer" => $data['match_winer'] ?: '',
+                "match_time" => $data['match_time'] ?: 0,
+                "match_process" => $data['match_process'] ?: '',
+                "tag" => $data['tag'] ?: 0,
+                "match_id" => $match_id,
+                "update_time" => date('Y-m-d H:i:s')
+            ];
+        };
+        if ($game_code == 'lq') {
+            $set_match_r = [
+                "home_team" => $data['home_team'] ?: '',
+                "guest_team" => $data['guest_team'] ?: '',
+                "lg_id" => $lg_id,
+                "home_rate" => $data['home_rate'] ?: 0,
+                "guest_rate" => $data['guest_rate'] ?: 0,
+                "home_score" => $data['home_score'] ?: 0,
+                "guest_score" => $data['guest_score'] ?: 0,
+                "status" => $data['status'] ?: 0,
+                "first_score" => $data['first_score'] ?: 0,
+                "last_score" => $data['last_score'] ?: 0,
+                "match_score" => $data['match_score'] ?: 0,
+                "match_winer" => $data['match_winer'] ?: '',
+                "match_time" => $data['match_time'] ?: 0,
+                "match_process" => $data['match_process'] ?: '',
+                "tag" => $data['tag'] ?: 0,
+                "match_id" => $match_id,
+                "update_time" => date('Y-m-d H:i:s')
+            ];
+        }
+        if ($game_code == 'wq') {
+            $set_match_r = [
+                "home_player_name" => $data['home_player_name'] ?: '',
+                "guest_player_name" => $data['guest_player_name'] ?: '',
+                "lg_id" => $lg_id,
+                "home_player_let_plate" => $data['home_player_let_plate'] ?: 0,
+                "guest_player_let_plate" => $data['guest_player_let_plate'] ?: 0,
+                "home_player_let_inning" => $data['home_player_let_inning'] ?: 0,
+                "guest_player_let_inning" => $data['guest_player_let_inning'] ?: 0,
+                "all_inning" => $data['all_inning'] ?: 0,
+                "home_player_score" => $data['home_player_score'] ?: 0,
+                "guest_player_score" => $data['guest_player_score'] ?: 0,
+                "status" => $data['status'] ?: 0,
+                "first_score_player" => $data['first_score_player'] ?: '',
+                "last_score_player" => $data['last_score_player'] ?: '',
+                "first_inning_score" => $data['first_inning_score'] ?: 0,
+                "second_inning_score" => $data['second_inning_score'] ?: 0,
+                "third_inning_score" => $data['third_inning_score'] ?: 0,
+                "match_winer_player" => $data['match_winer_player'] ?: '',
+                "update_time" => date('Y-m-d H:i:s'),
+                "match_time" => $data['match_time'] ?: 0,
+                "match_process" => $data['match_process'] ?: '',
+                "tag" => $data['tag'] ?: 0,
+                "match_id" => $match_id,
+                "result_mark" => $data['result_mark'] ?: '',
+            ];
+        }
+        if ($game_code == 'bq') {
+            $set_match_r = [
+                "home_team" => $data['home_team'] ?: '',
+                "guest_team" => $data['guest_team'] ?: '',
+                "lg_id" => $lg_id,
+                "home_rate" => $data['home_rate'] ?: 0,
+                "guest_rate" => $data['guest_rate'] ?: 0,
+                "home_score" => $data['home_score'] ?: 0,
+                "guest_score" => $data['guest_score'] ?: 0,
+                "status" => $data['status'] ?: 0,
+                "first_score" => $data['first_score'] ?: 0,
+                "last_score" => $data['last_score'] ?: 0,
+                "match_score" => $data['match_score'] ?: 0,
+                "match_winer" => $data['match_winer'] ?: '',
+                "match_time" => $data['match_time'] ?: 0,
+                "match_process" => $data['match_process'] ?: '',
+                "tag" => $data['tag'] ?: 0,
+                "match_id" => $match_id,
+                "all_inning" => $data['all_inning'] ?: 9,
+                "update_time" => date('Y-m-d H:i:s'),
+                "result_mark" => $data['result_mark'] ?: '',
+            ];
+        }
+
+        return $set_match_r;
+    }
+
+    private function writeLog($body, $ret)
+    {
+        if (!is_string($body)) {
+            $body = json_encode([$body], 256);
+        }
+        $data = ['ctime' => date("Y-m-d H:i:s"), 'body' => $body, 'ret' => $ret];
+        $return = DB::table('datainf_log')->insert($data);
+        return $return;
+    }
+
+
+}

+ 231 - 0
app/Models/System_user.php

@@ -0,0 +1,231 @@
+<?php
+namespace App\Models;
+use DB;
+use App\lib\ModelBase;
+
+class System_user extends ModelBase {
+	protected $table = "system_user";
+	public $timestamps = false;
+
+	//获取管理员列表
+	function getAdminlist($value = '', $type = 1, $page = 10, $sort = 5, $ads = 'desc', $jointable = '') {
+		$key = $this->getFeild($type);
+		$sort = is_integer($sort) ? $this->getFeild($sort) : $sort;
+		//DB::connection()->enableQueryLog();
+//		if ($jointable == 'system_root') {
+//			if (is_array($value) && count($value) > 0) {
+//				$data = $this->select('system_user.id', 'loginname', 'system_user.root_id', 'system_root.name', 'system_user.status', 'remarks', 'add_time')->join($jointable, 'system_user.root_id', $jointable . '.id')->where($value)->orderby($sort, $ads)->paginate($page);
+//			} else {
+//				$data = $this->select('system_user.id', 'loginname', 'system_user.root_id', 'system_root.name', 'system_user.status', 'remarks', 'add_time')->join($jointable, 'system_user.root_id', $jointable . '.id')->orderby($sort, $ads)->paginate($page);
+//			}
+//		}else{
+			if (empty($value)) {
+				$data = $this->orderby($sort, $ads)->paginate($page);
+			} else if (is_array($value)) {
+				$data = $this->where($value)->orderby($sort, $ads)->paginate($page);
+			} else {
+				$data = $this->where($key, $value)->orderby($sort, $ads)->paginate($page);
+			}
+//		}
+
+		if (!$data) {
+			return -7010100102; //没有列表数据
+		}
+		return $data->toArray();
+	}
+
+	//获取管理员信息
+	function getAdminInfo($value, $type = 1, $jointable = '', $columnn = '', $columnw = '') {
+		$key = $this->getFeild($type);
+		if (empty($jointable)) {
+			$data = $this->where($key, $value)->first();
+		} elseif ($jointable == 'system_root') {
+			$data = $this->select('system_user.id', 'loginname', 'system_user.root_id', 'system_root.name', 'system_user.status', 'remarks', 'add_time')->where('system_user.' . $key, $value)->join($jointable, $this->table . '.' . $columnn, $jointable . '.' . $columnw)->first();
+		} else {
+			$data = $this->where($key, $value)->join($jointable, $this->table . '.' . $columnn, $jointable . '.' . $columnw)->first();
+		}
+
+		if (!$data) {
+			return -7010100202; //没有管理员信息
+		}
+		return $data->toArray();
+	}
+
+	protected function checkSuperAdmin($admin_id){
+
+	}
+
+	//字段对应值
+	private function getFeild($num) {
+		$data = array(
+			'1' => 'id',
+			'2' => 'loginname',
+			'3' => 'root_id',
+			'4' => 'status',
+			'5' => 'add_time',
+		);
+		return $data[$num];
+	}
+	//更新
+	function updateInfo($data, $id) {
+		$res = $this->where('id', $id)->update($data);
+		if (!$res) {
+			return -7010101202; //更新失败
+		}
+		return 1;
+	}
+
+	/**
+	 *登录验证
+	 * [adminUser description]
+	 * @param  [type] $account [description]
+	 * @param  [type] $pwd     [description]
+	 * @return [type]          [description]
+	 */
+	function adminLogin($account, $password, $checktwo = false) {
+		$account = strtolower($account);
+		if (empty($account) || empty($password)) {
+			return -400844; //密码或用户名不能为空
+		}
+		if (!$user = $this->where(['loginname' => $account, 'status' => 1])->first()) {
+			return -400845; //用户不存在
+		}
+
+		$yecp = ($checktwo == true) ? $user->encryption_2 : $user->encryption;
+		$ypwd = ($checktwo == true) ? $user->password_2 : $user->password;
+
+		$newpasswd = md5(md5($yecp . $password));
+		if ($newpasswd == $ypwd) {
+			return array('admin_name' => $user->loginname, 'admin_id' => $user->id,'passwd'=>$newpasswd);
+		}
+		return -400846; //登录成功
+	}
+
+	/**
+	 * 检查admin信息是否存在
+	 */
+	protected function checkAdmin($admin){
+		if(!is_array($admin)){
+			return 1;
+		}
+		$re=$this->where('loginname',$admin['admin_name'])->where('password',$admin['passwd'])->first();
+		if(!$re){
+			return -400878;
+		}
+		return 1;
+	}
+
+	/**
+	 * 检查同一管理员信息是否存在
+	 */
+	protected function checkAdminname($name){
+		$name = trim($name);
+		$re=$this->where('loginname',$name)->first();
+		if(!$re){
+			return 1;
+		}
+		return -7090100102;
+	}
+
+	function addAdmin($data) {
+		$res = $this->insert($data);
+		if (!$res) {
+			return -7050001022; //添加失败
+		}
+		return 1;
+	}
+
+	//开关
+	function closeGame($data, $loginname) {
+		$res = $this->where('loginname', $loginname)->update($data);
+		if (!$res) {
+			return -5040000122;
+		}
+		return $res;
+	}
+
+	// /**
+	//  * 检查登录密码
+	//  *
+	//  * @param $user
+	//  * @param $password
+	//  * @return bool
+	//  */
+	// public function checkPassword($user, $password) {
+	// 	$accountPassword = $this->where(['id' => $user->id, 'status' => 1])->first();
+	// 	$dataPassword = md5(md5($accountPassword->encryption . $password));
+	// 	return $dataPassword == $accountPassword->account_password ? true : false;
+	// }
+    //权限检测
+    protected function hasRoot($code){
+        $admin_id=session('adminInfo.admin_id');
+        $check=$this->where('id',$admin_id)->where('root_id',0)->first();
+        if($check){
+            return 1;
+        }
+        $data=$this->join('dc_priv_role','dc_priv_role.role_id',$this->table.'.root_id')
+            ->join('dc_priv_code','dc_priv_role.priv_id','dc_priv_code.id')
+            ->where('dc_priv_code.priv_code',$code)
+            ->where('system_user.id',$admin_id)
+            ->get();
+        $data=$data->toArray();
+        if(count($data)>0){
+            return 1;
+        }
+        return -7030050022;//没有权限
+    }
+	
+	function checkActMoney($money){
+		$admin_id=session('adminInfo.admin_id');
+		$sql = "SELECT max(settingmoney) as maxmoney FROM system_root WHERE system_root.id in (SELECT role_id FROM dc_role WHERE admin_id={$admin_id})";
+		
+		$moneydata = DB::select($sql);
+		if(empty($moneydata)){
+			return -7030060102;	//未获取相应权限,权限错误
+		}
+		$limitmoney = current($moneydata)->maxmoney;
+		
+		if($money>$limitmoney){
+			return -7030060002;	//可操作金额超出限额
+		}
+		return 1;
+	}
+	//获取权限名称
+    function getAdminInfoByName($admin_user){
+	    $data=$this->join('system_root',$this->table.'.root_id','system_root.id')
+            ->where('loginname',$admin_user)
+            ->first();
+	    if(!$data){
+	        return -3020034722;
+        }
+        return $data->toArray();
+    }
+    //更新token
+    function refreshToken($admin_id,$token)
+    {
+        $res=$this->where('id',$admin_id)->update(['token'=>$token]);
+        if(!$res){
+            return -2050050022;//更新token失败
+        }
+        return 1;
+    }
+    //检测token
+    function checkToken($admin_id,$token){
+//        if(\App\Model\Role::hasRoot('passToken')){
+//            return 1;
+//        }
+        $res=$this->where('id',$admin_id)->where('token',$token)->first();
+        if(!$res){
+            return -2050050422;//token
+        }
+        return 1;
+    }
+
+    protected function checkOpen($id){
+        $res=$this->where('id',$id)->where('root_id',1)->first();
+        if(!$res){
+            return -20001;
+        }
+        return 1;
+    }
+}

+ 15 - 0
commands/bootHttp.php

@@ -0,0 +1,15 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/5/20
+ * Time: 9:36
+ */
+
+define('START_TIME', microtime(true));
+require __DIR__.'/../vendor/autoload.php';
+\datainf\lib\boot::init();
+
+$ser = new \datainf\logic\HttpServerDataInf(\datainf\lib\GlobConfigs::getKey('HttpServer'));
+$ser->start();
+

+ 61 - 0
commands/clientws3.php

@@ -0,0 +1,61 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/5/23
+ * Time: 17:42
+ */
+
+
+define('START_TIME', microtime(true));
+require __DIR__.'/../vendor/autoload.php';
+\app\lib\boot::init();
+
+
+
+use WebSocket\Client as Client;
+
+$conf = \app\lib\GlobConfigs::getKey('admin_conf');
+$url = "?token=".$conf['admin_token'];
+$client = new Client("ws://192.168.2.200:9090/".$url);
+
+$data = '{"title":"odds","game_code":"zq","match_id":"3740504","lg_id":"2630139","source":"hg0088","data":[{"match_id":"3740504","lg_id":"2630139","odds_code":"ior_HTSY","status":0,"sort":0,"p_code":"sw_HTS","odds":3.14,"condition":"\u662f","odds_only":"2a1fd6f86b9d61545286ceec5b8d9404","sole":"2a1fd6f86b9d61545286ceec5b8d9404","source":"hg0088","type":0,"team":""},{"match_id":"3740504","lg_id":"2630139","odds_code":"","status":0,"sort":0,"p_code":"sw_HTS","odds":4.23,"condition":"\u4e0d\u662f","odds_only":"4f78d4ecabf5c41cf07d9b79eef1fd26","sole":"4f78d4ecabf5c41cf07d9b79eef1fd26","source":"hg0088","type":0,"team":""},{"match_id":"3740504","lg_id":"2630139","odds_code":"half_two_sides_single","status":0,"sort":0,"p_code":"two_sides","odds":3.22,"condition":"\u5355","odds_only":"5702dbf44a3d373379bbd7385315deb5","sole":"5702dbf44a3d373379bbd7385315deb5","source":"hg0088","type":0,"team":""},{"match_id":"3740504","lg_id":"2630139","odds_code":"half_two_sides_double","status":0,"sort":0,"p_code":"two_sides","odds":5.44,"condition":"\u53cc","odds_only":"45478113634bf90d6fef75629bd4a225","sole":"45478113634bf90d6fef75629bd4a225","source":"hg0088","type":0,"team":""}]}';
+$data = htmlentities($data);
+
+$array = [
+    "title"=>"odds",
+    "game_code"=>"zq",
+    "match_id"=>"3740504",
+    "lg_id"=>"2630139",
+    "source"=>"hg0088",
+    "data"=>[
+                [
+                    "match_id"=>"3740504","lg_id"=>"2630139","odds_code"=>"ior_HTSY","status"=>0,"sort"=>0,"p_code"=>"sw_HTS","odds"=>3.14,"condition"=>"大","odds_only"=>"2a1fd6f86b9d61545286ceec5b8d9404","sole"=>"2a1fd6f86b9d61545286ceec5b8d9404","source"=>"hg0088","type"=>0,"team"=>""
+                ],
+                [
+                    "match_id"=>"3740504","lg_id"=>"2630139","odds_code"=>"ior_HTSY","status"=>0,"sort"=>0,"p_code"=>"sw_HTS","odds"=>3.14,"condition"=>"大","odds_only"=>"2a1fd6f86b9d61545286ceec5b8d9404","sole"=>"2a1fd6f86b9d61545286ceec5b8d9404","source"=>"hg0088","type"=>0,"team"=>""
+                ]
+    ]
+];
+
+//str = '{"cmd":"test","act":"odds","data":"'.json_encode($array,256).'","time":1558492565,"token":"aasasfa"}';
+$lastArr = [
+    "cmd"=>"test",
+    "act"=>"odds",
+    "time"=>1558492565,
+    "token"=>"aasasfa",
+    'data'=>$array
+];
+$str = json_encode($lastArr,256);
+
+$r = $client->send($str);
+$msg = $client->receive();
+echo "Recive: ".$msg."\n\n\n";
+
+
+$client->close();
+
+
+
+
+

+ 115 - 0
commands/clientws4.php

@@ -0,0 +1,115 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/5/23
+ * Time: 17:42
+ */
+
+
+define('START_TIME', microtime(true));
+require __DIR__ . '/../vendor/autoload.php';
+\datainf\lib\boot::init();
+
+use  App\Lib\ModelBase;
+//use Illuminate\Database\Capsule\Manager as DB;
+
+ModelBase::init();
+//var_dump($obj);
+//var_dump(DB::table('datainf_log')->where('id',766)->first());
+
+ModelBase::init()->getConnection()->disconnect();
+echo "---------------------\n\n\n";
+
+
+//$obj->getConnection()->disconnect();
+
+//var_dump(DB::table('datainf_log')->where('id',766)->first());
+$sql = "select * from  datainf_log where id in (766,767) ";
+$pdo = ModelBase::init()->getConnection()->getPdo();
+foreach ($pdo->query($sql ) as $row) {
+    print_r($row); //你可以用 echo($GLOBAL); 来看到这些值
+}
+
+
+
+
+
+
+/*
+try{
+    ModelBase::beginTransaction();
+    $model = new \App\Http\Model\StZqResult();
+    $ret = $model->where(['id'=>4314])->first();
+    print_r($ret);
+    ModelBase::commit();
+}catch (\Exception $e){
+    echo $e->getMessage();
+    ModelBase::rollBack();
+}
+
+
+
+$model = new App\Lib\TestModel();
+$model->name = 'name_'.mt_rand(1000,99999) ;
+$model->sex = '男';
+$model->age = mt_rand(10,50);
+
+$ret = $model->save();
+print_r([$ret,$model->toArray()]);
+*/
+
+
+/*
+function request_post($url = '', $param = '') {
+    if (empty($url) || empty($param)) {
+        return false;
+    }
+
+    $postUrl = $url;
+    $curlPost = $param;
+    $ch = curl_init();//初始化curl
+    curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
+    curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
+    curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
+    curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
+    $data = curl_exec($ch);//运行curl
+    curl_close($ch);
+
+    return $data;
+}
+
+$data=[
+    'token'=>'xxxx',
+    'ccav'=>'ccav',
+];
+
+$ret = request_post('http://192.168.2.200:9093/abcd',$data);
+print_r($ret);
+*/
+
+
+/*
+$str = '';
+$arr = json_decode($str,true);
+$arr2 = json_decode( $arr['0']['data'] ,true);
+foreach ($arr2 as $val){
+    print_r($val);
+    echo "\n\n";
+}
+*/
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 3 - 0
commands/init.sh

@@ -0,0 +1,3 @@
+#!/bin/sh
+cd  /home/swooleProV2/dataInterface/commands
+/usr/local/bin/php  /home/swooleProV2/dataInterface/commands/bootHttp.php

+ 29 - 0
composer.json

@@ -0,0 +1,29 @@
+{
+    "name": "swoole/servers",
+    "description": "swoole user ORM",
+    "keywords": ["swole", "ROM"],
+    "license": "MIT",
+    "type": "project",
+    "require": {
+        "php": ">=7.0.0",
+        "illuminate/database": "*",
+        "textalk/websocket":"1.2.*"
+    },
+    "autoload": {
+        "classmap": [
+            "datainf/lib",
+            "datainf/logic",
+            "datainf/logic/cmdpro"
+        ],
+        "psr-4": {
+            "App\\": "app/",
+            "datainf\\":"datainf/"
+        }
+    },
+    "repositories": {
+        "packagist": {
+            "type": "composer",
+            "url": "https://packagist.laravel-china.org"
+        }
+    }
+}

+ 757 - 0
composer.lock

@@ -0,0 +1,757 @@
+{
+    "_readme": [
+        "This file locks the dependencies of your project to a known state",
+        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
+        "This file is @generated automatically"
+    ],
+    "content-hash": "a7bc80d4b7f1c019b3006b02e3589bc3",
+    "packages": [
+        {
+            "name": "doctrine/inflector",
+            "version": "v1.3.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/doctrine/inflector.git",
+                "reference": "5527a48b7313d15261292c149e55e26eae771b0a"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/doctrine/inflector/zipball/5527a48b7313d15261292c149e55e26eae771b0a",
+                "reference": "5527a48b7313d15261292c149e55e26eae771b0a",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "php": "^7.1"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^6.2"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.3.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Doctrine\\Common\\Inflector\\": "lib/Doctrine/Common/Inflector"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Roman Borschel",
+                    "email": "roman@code-factory.org"
+                },
+                {
+                    "name": "Benjamin Eberlei",
+                    "email": "kontakt@beberlei.de"
+                },
+                {
+                    "name": "Guilherme Blanco",
+                    "email": "guilhermeblanco@gmail.com"
+                },
+                {
+                    "name": "Jonathan Wage",
+                    "email": "jonwage@gmail.com"
+                },
+                {
+                    "name": "Johannes Schmitt",
+                    "email": "schmittjoh@gmail.com"
+                }
+            ],
+            "description": "Common String Manipulations with regard to casing and singular/plural rules.",
+            "homepage": "http://www.doctrine-project.org",
+            "keywords": [
+                "inflection",
+                "pluralize",
+                "singularize",
+                "string"
+            ],
+            "time": "2018-01-09T20:05:19+00:00"
+        },
+        {
+            "name": "illuminate/container",
+            "version": "v5.8.24",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/illuminate/container.git",
+                "reference": "9405989993a48c2cd50ad1e5b2b08a33383c3807"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/illuminate/container/zipball/9405989993a48c2cd50ad1e5b2b08a33383c3807",
+                "reference": "9405989993a48c2cd50ad1e5b2b08a33383c3807",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "illuminate/contracts": "5.8.*",
+                "illuminate/support": "5.8.*",
+                "php": "^7.1.3",
+                "psr/container": "^1.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "5.8-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Illuminate\\Container\\": ""
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Taylor Otwell",
+                    "email": "taylor@laravel.com"
+                }
+            ],
+            "description": "The Illuminate Container package.",
+            "homepage": "https://laravel.com",
+            "time": "2019-04-22T13:12:35+00:00"
+        },
+        {
+            "name": "illuminate/contracts",
+            "version": "v5.8.24",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/illuminate/contracts.git",
+                "reference": "33b4e0ffb89eb2216c764235c9e95fed1f3fab82"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/illuminate/contracts/zipball/33b4e0ffb89eb2216c764235c9e95fed1f3fab82",
+                "reference": "33b4e0ffb89eb2216c764235c9e95fed1f3fab82",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "php": "^7.1.3",
+                "psr/container": "^1.0",
+                "psr/simple-cache": "^1.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "5.8-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Illuminate\\Contracts\\": ""
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Taylor Otwell",
+                    "email": "taylor@laravel.com"
+                }
+            ],
+            "description": "The Illuminate Contracts package.",
+            "homepage": "https://laravel.com",
+            "time": "2019-06-11T14:00:26+00:00"
+        },
+        {
+            "name": "illuminate/database",
+            "version": "v5.8.24",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/illuminate/database.git",
+                "reference": "12d54c516df34c668c55a4636f7a3c921ada9c4d"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/illuminate/database/zipball/12d54c516df34c668c55a4636f7a3c921ada9c4d",
+                "reference": "12d54c516df34c668c55a4636f7a3c921ada9c4d",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "ext-json": "*",
+                "illuminate/container": "5.8.*",
+                "illuminate/contracts": "5.8.*",
+                "illuminate/support": "5.8.*",
+                "php": "^7.1.3"
+            },
+            "suggest": {
+                "doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6).",
+                "fzaninotto/faker": "Required to use the eloquent factory builder (^1.4).",
+                "illuminate/console": "Required to use the database commands (5.8.*).",
+                "illuminate/events": "Required to use the observers with Eloquent (5.8.*).",
+                "illuminate/filesystem": "Required to use the migrations (5.8.*).",
+                "illuminate/pagination": "Required to paginate the result set (5.8.*)."
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "5.8-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Illuminate\\Database\\": ""
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Taylor Otwell",
+                    "email": "taylor@laravel.com"
+                }
+            ],
+            "description": "The Illuminate Database package.",
+            "homepage": "https://laravel.com",
+            "keywords": [
+                "database",
+                "laravel",
+                "orm",
+                "sql"
+            ],
+            "time": "2019-06-16T20:03:32+00:00"
+        },
+        {
+            "name": "illuminate/support",
+            "version": "v5.8.24",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/illuminate/support.git",
+                "reference": "b05653f5ecce996734d3facd06a81aff504b6a2f"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/illuminate/support/zipball/b05653f5ecce996734d3facd06a81aff504b6a2f",
+                "reference": "b05653f5ecce996734d3facd06a81aff504b6a2f",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "doctrine/inflector": "^1.1",
+                "ext-json": "*",
+                "ext-mbstring": "*",
+                "illuminate/contracts": "5.8.*",
+                "nesbot/carbon": "^1.26.3 || ^2.0",
+                "php": "^7.1.3"
+            },
+            "conflict": {
+                "tightenco/collect": "<5.5.33"
+            },
+            "suggest": {
+                "illuminate/filesystem": "Required to use the composer class (5.8.*).",
+                "moontoast/math": "Required to use ordered UUIDs (^1.1).",
+                "ramsey/uuid": "Required to use Str::uuid() (^3.7).",
+                "symfony/process": "Required to use the composer class (^4.2).",
+                "symfony/var-dumper": "Required to use the dd function (^4.2).",
+                "vlucas/phpdotenv": "Required to use the env helper (^3.3)."
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "5.8-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Illuminate\\Support\\": ""
+                },
+                "files": [
+                    "helpers.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Taylor Otwell",
+                    "email": "taylor@laravel.com"
+                }
+            ],
+            "description": "The Illuminate Support package.",
+            "homepage": "https://laravel.com",
+            "time": "2019-06-19T14:12:17+00:00"
+        },
+        {
+            "name": "nesbot/carbon",
+            "version": "2.20.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/briannesbitt/Carbon.git",
+                "reference": "bc671b896c276795fad8426b0aa24e8ade0f2498"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/bc671b896c276795fad8426b0aa24e8ade0f2498",
+                "reference": "bc671b896c276795fad8426b0aa24e8ade0f2498",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "ext-json": "*",
+                "php": "^7.1.8 || ^8.0",
+                "symfony/translation": "^3.4 || ^4.0"
+            },
+            "require-dev": {
+                "friendsofphp/php-cs-fixer": "^2.14 || ^3.0",
+                "kylekatarnls/multi-tester": "^1.1",
+                "phpmd/phpmd": "^2.6",
+                "phpstan/phpstan": "^0.11",
+                "phpunit/phpunit": "^7.5 || ^8.0",
+                "squizlabs/php_codesniffer": "^3.4"
+            },
+            "type": "library",
+            "extra": {
+                "laravel": {
+                    "providers": [
+                        "Carbon\\Laravel\\ServiceProvider"
+                    ]
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Carbon\\": "src/Carbon/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Brian Nesbitt",
+                    "email": "brian@nesbot.com",
+                    "homepage": "http://nesbot.com"
+                }
+            ],
+            "description": "A simple API extension for DateTime.",
+            "homepage": "http://carbon.nesbot.com",
+            "keywords": [
+                "date",
+                "datetime",
+                "time"
+            ],
+            "time": "2019-06-25T10:00:57+00:00"
+        },
+        {
+            "name": "psr/container",
+            "version": "1.0.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/php-fig/container.git",
+                "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
+                "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "php": ">=5.3.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.0.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Psr\\Container\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "PHP-FIG",
+                    "homepage": "http://www.php-fig.org/"
+                }
+            ],
+            "description": "Common Container Interface (PHP FIG PSR-11)",
+            "homepage": "https://github.com/php-fig/container",
+            "keywords": [
+                "PSR-11",
+                "container",
+                "container-interface",
+                "container-interop",
+                "psr"
+            ],
+            "time": "2017-02-14T16:28:37+00:00"
+        },
+        {
+            "name": "psr/simple-cache",
+            "version": "1.0.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/php-fig/simple-cache.git",
+                "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b",
+                "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "php": ">=5.3.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.0.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Psr\\SimpleCache\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "PHP-FIG",
+                    "homepage": "http://www.php-fig.org/"
+                }
+            ],
+            "description": "Common interfaces for simple caching",
+            "keywords": [
+                "cache",
+                "caching",
+                "psr",
+                "psr-16",
+                "simple-cache"
+            ],
+            "time": "2017-10-23T01:57:42+00:00"
+        },
+        {
+            "name": "symfony/polyfill-mbstring",
+            "version": "v1.11.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/symfony/polyfill-mbstring.git",
+                "reference": "fe5e94c604826c35a32fa832f35bd036b6799609"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fe5e94c604826c35a32fa832f35bd036b6799609",
+                "reference": "fe5e94c604826c35a32fa832f35bd036b6799609",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "php": ">=5.3.3"
+            },
+            "suggest": {
+                "ext-mbstring": "For best performance"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.11-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Symfony\\Polyfill\\Mbstring\\": ""
+                },
+                "files": [
+                    "bootstrap.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Nicolas Grekas",
+                    "email": "p@tchwork.com"
+                },
+                {
+                    "name": "Symfony Community",
+                    "homepage": "https://symfony.com/contributors"
+                }
+            ],
+            "description": "Symfony polyfill for the Mbstring extension",
+            "homepage": "https://symfony.com",
+            "keywords": [
+                "compatibility",
+                "mbstring",
+                "polyfill",
+                "portable",
+                "shim"
+            ],
+            "time": "2019-02-06T07:57:58+00:00"
+        },
+        {
+            "name": "symfony/translation",
+            "version": "v4.3.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/symfony/translation.git",
+                "reference": "5dda505e5f65d759741dfaf4e54b36010a4b57aa"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/symfony/translation/zipball/5dda505e5f65d759741dfaf4e54b36010a4b57aa",
+                "reference": "5dda505e5f65d759741dfaf4e54b36010a4b57aa",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "php": "^7.1.3",
+                "symfony/polyfill-mbstring": "~1.0",
+                "symfony/translation-contracts": "^1.1.2"
+            },
+            "conflict": {
+                "symfony/config": "<3.4",
+                "symfony/dependency-injection": "<3.4",
+                "symfony/yaml": "<3.4"
+            },
+            "provide": {
+                "symfony/translation-implementation": "1.0"
+            },
+            "require-dev": {
+                "psr/log": "~1.0",
+                "symfony/config": "~3.4|~4.0",
+                "symfony/console": "~3.4|~4.0",
+                "symfony/dependency-injection": "~3.4|~4.0",
+                "symfony/finder": "~2.8|~3.0|~4.0",
+                "symfony/http-kernel": "~3.4|~4.0",
+                "symfony/intl": "~3.4|~4.0",
+                "symfony/service-contracts": "^1.1.2",
+                "symfony/var-dumper": "~3.4|~4.0",
+                "symfony/yaml": "~3.4|~4.0"
+            },
+            "suggest": {
+                "psr/log-implementation": "To use logging capability in translator",
+                "symfony/config": "",
+                "symfony/yaml": ""
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "4.3-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Symfony\\Component\\Translation\\": ""
+                },
+                "exclude-from-classmap": [
+                    "/Tests/"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Fabien Potencier",
+                    "email": "fabien@symfony.com"
+                },
+                {
+                    "name": "Symfony Community",
+                    "homepage": "https://symfony.com/contributors"
+                }
+            ],
+            "description": "Symfony Translation Component",
+            "homepage": "https://symfony.com",
+            "time": "2019-06-03T20:27:40+00:00"
+        },
+        {
+            "name": "symfony/translation-contracts",
+            "version": "v1.1.5",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/symfony/translation-contracts.git",
+                "reference": "cb4b18ad7b92a26e83b65dde940fab78339e6f3c"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/cb4b18ad7b92a26e83b65dde940fab78339e6f3c",
+                "reference": "cb4b18ad7b92a26e83b65dde940fab78339e6f3c",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "php": "^7.1.3"
+            },
+            "suggest": {
+                "symfony/translation-implementation": ""
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.1-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Symfony\\Contracts\\Translation\\": ""
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Nicolas Grekas",
+                    "email": "p@tchwork.com"
+                },
+                {
+                    "name": "Symfony Community",
+                    "homepage": "https://symfony.com/contributors"
+                }
+            ],
+            "description": "Generic abstractions related to translation",
+            "homepage": "https://symfony.com",
+            "keywords": [
+                "abstractions",
+                "contracts",
+                "decoupling",
+                "interfaces",
+                "interoperability",
+                "standards"
+            ],
+            "time": "2019-06-13T11:15:36+00:00"
+        },
+        {
+            "name": "textalk/websocket",
+            "version": "1.2.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/Textalk/websocket-php.git",
+                "reference": "bfa18bb6bf523680c7803f6b04694fbbf2f67bbf"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/Textalk/websocket-php/zipball/bfa18bb6bf523680c7803f6b04694fbbf2f67bbf",
+                "reference": "bfa18bb6bf523680c7803f6b04694fbbf2f67bbf",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://dl.laravel-china.org/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require-dev": {
+                "cboden/ratchet": "0.3.*",
+                "phpunit/phpunit": "4.1.*",
+                "phpunit/phpunit-selenium": "1.3.3",
+                "satooshi/php-coveralls": "dev-master"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "WebSocket\\": "lib"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Fredrik Liljegren",
+                    "email": "fredrik.liljegren@textalk.se"
+                }
+            ],
+            "description": "WebSocket client and server",
+            "time": "2015-10-09T07:32:42+00:00"
+        }
+    ],
+    "packages-dev": [],
+    "aliases": [],
+    "minimum-stability": "stable",
+    "stability-flags": [],
+    "prefer-stable": false,
+    "prefer-lowest": false,
+    "platform": {
+        "php": ">=7.0.0"
+    },
+    "platform-dev": []
+}

+ 53 - 0
datainf/lib/GlobConfigs.php

@@ -0,0 +1,53 @@
+<?php
+namespace  datainf\lib;
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/5/20
+ * Time: 9:17
+ */
+
+
+class GlobConfigs {
+    public static $file = '';
+    public static $configs = [] ;
+    public static $isload = false ;
+    private static $instance = null ;
+
+    public static function  getInstance(){
+        if (self::$instance){
+            return self::$instance;
+        }
+        self::$instance = new  GlobConfigs();
+        return   self::$instance ;
+    }
+
+    public static function  getKey($key,$default=''){
+         if (!self::$isload) { self::load();  }
+         if (isset(self::$configs[$key])){
+             return self::$configs[$key];
+         }
+         return $default ;
+    }
+    public static  function  setKey($key,$val){
+        if (!self::$isload) { self::load();  }
+        self::$configs[$key] = $val;
+    }
+
+    public static function getAll(){
+        if (!self::$isload) { self::load();  }
+        return self::$configs ;
+    }
+
+    public static function  load($file=''){
+        if ( self::$isload  ){            return true ;       }
+
+        if (empty($file)){
+            $file =  CONFIG_PATH.DS.'configs.php';
+        }
+        self::$configs = require_once ($file);
+        self::$isload = true ;
+    }
+
+
+}

+ 18 - 0
datainf/lib/Mconsts.php

@@ -0,0 +1,18 @@
+<?php
+//
+defined('DS') or define("DS", DIRECTORY_SEPARATOR);
+defined('BASE_PATH') or define("BASE_PATH", realpath(dirname(dirname(dirname(__FILE__)))));
+defined('DATAINF_PATH') or define("DATAINF_PATH", BASE_PATH . DS . 'datainf');
+defined('APP_PATH') or define("APP_PATH", BASE_PATH . DS . 'app');
+defined('CONFIG_PATH') or define("CONFIG_PATH", BASE_PATH . DS . 'configs');
+defined('LOG_PATH') or define("LOG_PATH", BASE_PATH . DS . 'logs');
+defined('LOGIC_PATH') or define("LOGIC_PATH", DATAINF_PATH . DS . 'logic');
+defined('CMDPRO_PATH') or define("CMDPRO_PATH", LOGIC_PATH . DS . 'cmdpro');
+
+
+
+////
+
+
+
+

+ 28 - 0
datainf/lib/boot.php

@@ -0,0 +1,28 @@
+<?php
+namespace  datainf\lib;
+ini_set('date.timezone','Asia/Shanghai');
+ini_set('memory_limit', '512M');
+/**
+ *
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/5/20
+ * Time: 9:19
+ */
+use datainf\lib\GlobConfigs;
+
+class boot
+{
+    public static  function init(){
+        self::loadConsts();
+
+    }
+
+    public static function  loadConsts(){
+        require_once(realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Mconsts.php');
+        GlobConfigs::getInstance()->getAll();
+    }
+
+
+}
+

+ 180 - 0
datainf/logic/HttpServerDataInf.php

@@ -0,0 +1,180 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/26
+ * Time: 12:03
+ */
+
+namespace datainf\logic;
+
+use App\Lib\ModelBase;
+use App\Http\Response\Response;
+use App\Logic\DataLogic;
+
+use Illuminate\Database\Capsule\Manager as DB;
+
+class HttpServerDataInf
+{
+    private $httpserver;
+    private $config;
+
+    public function __construct($config)
+    {
+        $this->httpserver = new \swoole\http\server($config['host'], $config['port']);
+        $this->httpserver->set($config['sets']);
+        $this->config = $config;
+
+        $taskWorkingNum = new \swoole\Atomic();
+        $this->httpserver->taskWorkingNum = $taskWorkingNum;
+
+        $this->httpserver->on('request', array($this, 'OnRequest'));
+        $this->httpserver->on('WorkerStart', array($this, 'onWorkerStart'));
+        $this->httpserver->on('task', array($this, 'onTask'));
+        $this->httpserver->on('finish', array($this, 'onFinish'));
+
+    }
+
+    public function onWorkerStart($serv, $worker_id)
+    {
+        $name = $serv->taskworker ? 'Task_' : 'Worker_';
+        $name = 'Data_' . $name . ($serv->worker_id < 10 ? '0' . $serv->worker_id : $serv->worker_id);
+        swoole_set_process_name($name);
+
+        $GLOBALS['model'] = '';
+        $GLOBALS['modeltime'] = 0;
+        $this->InitDb();
+    }
+
+
+    public function OnRequest($request, $response)
+    {
+        $response->header('Content-Type', 'text/html; charset=utf-8');
+        $response->header('Server', 'DataInfaceServer');
+        $paras = array_merge(['request_time' => date("H:i:s")], !empty($request->get) ? $request->get : [], !empty($request->post) ? $request->post : []);
+
+        $request_uri = substr($request->server['request_uri'], 1);
+        $urls = ['setLeague', 'setMatch', 'setMatchResult', 'setOdds', 'setOddsCH', 'setBroadCast'];
+
+        if (!in_array($request_uri, $urls)) {
+            $data = Response::generate('', 0, '', '无效的url');
+            $response->end($data);
+            return;
+        }
+
+        $dataObj = json_decode($paras['data'], true);
+        if (empty($dataObj)) {
+            $data = Response::generate('', 5, '', '无效的data参数');
+            $response->end($data);
+            return;
+        }
+
+        if ($this->httpserver->taskWorkingNum->get() > intval($this->config['sets']['task_worker_num'])) {
+            $data = Response::generate('', 9, '', '任务线程已满,请稍等...');
+            $response->end($data);
+            return;
+        }
+
+        $check_token = true;
+        if ($check_token) {
+            $token = isset($paras['token']) ? $paras['token'] : '';
+            if (empty($token) || empty($this->Tokencheck($token))) {
+                $data = Response::generate('', 6, '', '无效的token');
+                $response->end($data);
+                return;
+            }
+        }
+
+        $this->onTask($this->httpserver, ['url' => $request_uri, 'paras' => $paras, 'respone' => $response]);
+        $data = Response::generate('', 1, '');
+        $response->end($data);
+        return;
+    }
+
+    public function onTask($serv, $task)
+    {
+        $this->httpserver->taskWorkingNum->add();
+
+        $url = $task['url'];
+        $data = $task['paras'];
+
+        switch ($url) {
+            case 'setLeague':
+                $ret = DataLogic::getInstance()->setLeague($data);
+                break;
+            case 'setMatch':
+                $ret = DataLogic::getInstance()->setMatch($data);
+                break;
+            case 'setMatchResult':
+                $ret = DataLogic::getInstance()->setMatchResult($data);
+                break;
+            case 'setOdds':
+                $ret = DataLogic::getInstance()->setOdds($data);
+                break;
+            case 'setOddsCH':
+                $ret = DataLogic::getInstance()->setOddsCH($data);
+                break;
+            case 'setBroadCast':
+                $ret = DataLogic::getInstance()->setBroadCast($data);
+                break;
+            case 'upMatch':
+                $ret = DataLogic::getInstance()->upMatch($data);
+                break;
+            default:
+                $ret = 'false';
+                break;
+        }
+
+        $this->httpserver->taskWorkingNum->sub();
+        //$this->onFinish($serv, 0, $ret);
+    }
+
+
+    public function onFinish($serv, int $task_id, $data)
+    {
+        // print_r(['task_id' => $task_id, 'ret' => $data]);
+    }
+
+    private function Tokencheck($token)
+    {
+        $tokenvel = DB::table('system_user')->where(['token' => $token])->first();
+        return $tokenvel;
+    }
+
+
+    private function InitDb()
+    {
+        $over_time = 60 * 5;
+        $now = microtime(true);
+
+        $debugmsg = 'manager_pid=' . $this->httpserver->manager_pid . ' master_pid=' . $this->httpserver->master_pid;
+        $debugmsg .= ' worker_id=' . $this->httpserver->worker_id . ' worker_pid=' . $this->httpserver->worker_pid . ' istask=' . intval($this->httpserver->taskworker);
+
+
+        if (!$GLOBALS['modeltime']) {
+            $GLOBALS['modeltime'] = $now;
+            $GLOBALS['model'] = $this->httpserver->worker_id;
+            ModelBase::init();
+            //echo "第一次建立数据库连接- $debugmsg .....\n";
+            //echo $GLOBALS['modeltime'] . '--' . $GLOBALS['model'] . "\n";
+            return;
+        }
+
+        if (($now - $GLOBALS['modeltime']) > $over_time) {
+            $GLOBALS['modeltime'] = $now;
+            $GLOBALS['model'] = $this->httpserver->worker_id;
+            ModelBase::close();
+            ModelBase::init();
+            //echo "超时重连数据库-$debugmsg.....\n";
+            //echo $GLOBALS['modeltime'] . '--' . $GLOBALS['model'] . "\n";
+            return;
+        }
+        //echo "用的旧的连接-$debugmsg...." . $GLOBALS['modeltime'] . '--' . $GLOBALS['model'] . ".\n";
+    }
+
+    public function start()
+    {
+        $this->httpserver->start();
+    }
+
+}

+ 26 - 0
datainf/pplus/Instance.php

@@ -0,0 +1,26 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/5/22
+ * Time: 15:24
+ */
+
+namespace datainf\pplus;
+
+
+trait  Instance
+{
+    private static $Instance = null;
+
+    public static function getInstance($cache = true)
+    {
+        if ($cache && self::$Instance) {
+            return self::$Instance;
+        }
+        self::$Instance = new self();
+        return self::$Instance;
+    }
+
+
+}

+ 12 - 0
readme.txt

@@ -0,0 +1,12 @@
+1.安装docker服务进程
+2.下载镜像 docker.io/zaherg/php-swoole (此镜像中有php7.3 swoole4.3扩展  redis扩展)
+3.新建目录  /home/swooleProV2/dataInterface/
+4.上传文件到此目录下面,
+5.运行composer update 更新comoser组件
+6.注意修改配置文件以适应线上环境[复制 config.sample.php 为  config.php]
+7.启动容器  注意目录(建立目录映射)和端口关系(应用启动的默认端口号为:9093)
+8.手动启动脚本 /home/swooleProV2/dataInterface/command/init.sh 启动服务,[也可以在启动容器时启动脚本,一并启动服务]
+9.重启服务:可以重启容器,或kill主进程再重运行启动脚本
+
+
+