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 StLqResult
  7. * @package App\Http\Model
  8. * 篮球 赛事 结果
  9. */
  10. class StLqResult extends Model
  11. {
  12. protected $table = 'st_lq_result';
  13. public $timestamps = false;
  14. /*
  15. * 写赛事结果
  16. */
  17. public static function LQresult($model){
  18. //获取赛事表7天内所有赛事
  19. $matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
  20. ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-7 day"))]])
  21. ->get()
  22. ->toarray();
  23. //没有数据,无需操作
  24. if(empty($matchData)) return Response::success();
  25. //获取赛事结果表 15天内
  26. $matchData_r = $model['model_result']::select('match_id')
  27. ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-7 day"))]])
  28. ->get()
  29. ->toarray();
  30. //结果表无数据,直接插入
  31. if(empty($matchData_r)){
  32. foreach ($matchData as $k=>$v){
  33. $process = 0;
  34. if((int)$v['status'] == 2){
  35. $process = 4;
  36. }
  37. if((int)$v['status'] == 1){
  38. $process = 1;
  39. }
  40. $start_time = ($v['match_date'].' '.$v['match_time']);
  41. $set_match_r[] = [
  42. "match_id"=> $v['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:i:s'),
  51. "update_time"=>date('Y-m-d H:i:s'),
  52. "start_time"=>date('Y-m-d H:i:s',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. $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:i:s'),
  88. "update_time"=>date('Y-m-d H:i:s'),
  89. "start_time"=>date('Y-m-d H:i:s',strtotime($start_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. return Response::success();
  97. }
  98. //计算滚球 赛事进行时间
  99. public static function secTime($sec=0){
  100. $min = floor($sec/60);
  101. $res = $min.':'.($sec-$min*60);
  102. return $res;
  103. }
  104. }