StLqResult.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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','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. // $time = time()-strtotime($v['match_time']);
  39. // $match_time = self::secTime($time);
  40. $set_match_r[] = [
  41. "match_id"=> $v['id'],
  42. "home_team"=>$v['home_team'],
  43. "guest_team"=>$v['guest_team'],
  44. "lg_id"=>$v['lg_id'],
  45. "status"=>$v['status'],
  46. "tag"=> $v['tag'],
  47. "match_process"=>$process,
  48. 'match_time'=>12,
  49. "ctime"=>date('Y-m-d H:m:i'),
  50. "update_time"=>date('Y-m-d H:m:i'),
  51. 'start_time'=>$v['match_date'].' '.$v['match_time'],
  52. ];
  53. }
  54. $ret = $model['model_result']::insert($set_match_r);
  55. if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
  56. }else{
  57. //如果结果表有数据,则获取结果表没有的赛事
  58. foreach ($matchData as $k=>$v){
  59. foreach ($matchData_r as $kk=>$vv){
  60. if($v['id'] == $vv['match_id']){
  61. unset($matchData[$k]);
  62. }
  63. }
  64. }
  65. //如果还有未写入赛事
  66. if(!empty($matchData)){
  67. //写入结果表不存在赛事
  68. foreach ($matchData as $k=>$v){
  69. $process = 0;
  70. if((int)$v['status'] == 2){
  71. $process = 4;
  72. }
  73. if((int)$v['status'] == 1){
  74. $process = 1;
  75. }
  76. // $time = time()-strtotime($v['match_time']);
  77. // $match_time = self::secTime($time);
  78. $set_match_r[] = [
  79. "match_id"=> $v['id'],
  80. "home_team"=>$v['home_team'],
  81. "guest_team"=>$v['guest_team'],
  82. "lg_id"=>$v['lg_id'],
  83. "status"=>$v['status'],
  84. "tag"=> $v['tag'],
  85. "match_process"=>$process,
  86. 'match_time'=>12,
  87. "ctime"=>date('Y-m-d H:m:i'),
  88. "update_time"=>date('Y-m-d H:m:i'),
  89. 'start_time'=>$v['match_date'].' '.$v['match_time'],
  90. ];
  91. }
  92. $ret = $model['model_result']::insert($set_match_r);
  93. if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
  94. }
  95. }
  96. }
  97. //计算滚球 赛事进行时间
  98. public static function secTime($sec=0){
  99. $min = floor($sec/60);
  100. $res = $min.':'.($sec-$min*60);
  101. return $res;
  102. }
  103. }