StLqResult.php 3.5 KB

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