StLqResult.php 4.0 KB

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