StLqResult.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace App\Http\Model;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Http\Response\Response;
  5. /**
  6. * Class Account
  7. * @package App\Sports\Model
  8. * 用户账号
  9. */
  10. class StLqResult extends Model
  11. {
  12. protected $table = 'st_lq_result';
  13. public $timestamps = false;
  14. //写赛事结果
  15. public static function LQresult($model){
  16. //获取赛事表15天内所有非 未开始赛事
  17. $matchData = $model['model_match']::select('id','match_id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
  18. ->where([['ctime','>',date('Y-m-d H:m:i', strtotime("-7 day"))]])
  19. ->get()
  20. ->toarray();
  21. //没有数据,无需操作
  22. if(empty($matchData)) return Response::success();
  23. //获取赛事结果表 15天内
  24. $matchData_r = $model['model_result']::select('match_id')
  25. ->where([['ctime','>',date('Y-m-d H:m:i', strtotime("-7 day"))]])
  26. ->get()
  27. ->toarray();
  28. //结果表无数据,直接插入
  29. if(empty($matchData_r)){
  30. foreach ($matchData as $k=>$v){
  31. $process = 0;
  32. if((int)$v['status'] == 2){
  33. $process = 4;
  34. }
  35. if((int)$v['status'] == 1){
  36. $process = 1;
  37. }
  38. $start_time = ($v['match_date'].' '.$v['match_time']);
  39. // $time = time()-strtotime($v['match_time']);
  40. // $match_time = self::secTime($time);
  41. $set_match_r[] = [
  42. "match_id"=> $v['match_id'],
  43. "home_team"=>$v['home_team'],
  44. "guest_team"=>$v['guest_team'],
  45. "lg_id"=>$v['lg_id'],
  46. "status"=>$v['status'],
  47. "tag"=> $v['tag'],
  48. "match_process"=>$process,
  49. 'match_time'=>12,
  50. "ctime"=>date('Y-m-d H:m:i'),
  51. "update_time"=>date('Y-m-d H:m:i'),
  52. "start_time"=>date('Y-m-d H:m:i',strtotime($start_time))
  53. ];
  54. }
  55. $ret = $model['model_result']::insert($set_match_r);
  56. if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
  57. }else{
  58. //如果结果表有数据,则获取结果表没有的赛事
  59. foreach ($matchData as $k=>$v){
  60. foreach ($matchData_r as $kk=>$vv){
  61. if($v['id'] == $vv['match_id']){
  62. unset($matchData[$k]);
  63. }
  64. }
  65. }
  66. //如果还有未写入赛事
  67. if(!empty($matchData)){
  68. //写入结果表不存在赛事
  69. foreach ($matchData as $k=>$v){
  70. $process = 0;
  71. if((int)$v['status'] == 2){
  72. $process = 4;
  73. }
  74. if((int)$v['status'] == 1){
  75. $process = 1;
  76. }
  77. $start_time = ($v['match_date'].' '.$v['match_time']);
  78. // $time = time()-strtotime($v['match_time']);
  79. // $match_time = self::secTime($time);
  80. $set_match_r[] = [
  81. "match_id"=> $v['match_id'],
  82. "home_team"=>$v['home_team'],
  83. "guest_team"=>$v['guest_team'],
  84. "lg_id"=>$v['lg_id'],
  85. "status"=>$v['status'],
  86. "tag"=> $v['tag'],
  87. "match_process"=>$process,
  88. 'match_time'=>12,
  89. "ctime"=>date('Y-m-d H:m:i'),
  90. "update_time"=>date('Y-m-d H:m:i'),
  91. "start_time"=>date('Y-m-d H:m:i',strtotime($start_time))
  92. ];
  93. }
  94. $ret = $model['model_result']::insert($set_match_r);
  95. if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
  96. }
  97. }
  98. }
  99. //计算滚球 赛事进行时间
  100. public static function secTime($sec=0){
  101. $min = floor($sec/60);
  102. $res = $min.':'.($sec-$min*60);
  103. return $res;
  104. }
  105. }