| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?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;
- }
- }
|