Sport.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\Sport as SportModel;
  5. class Sport extends Command
  6. {
  7. /**
  8. * 命令名称和签名
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'sport';
  13. /**
  14. * 命令描述
  15. *
  16. * @var string
  17. */
  18. protected $description = '当天会去更新明天的赛事(23:59:00执行一次)';
  19. /**
  20. * 执行命令
  21. *
  22. * @return int
  23. */
  24. public function handle()
  25. {
  26. $this->info('开始执行统计比赛数据任务...');
  27. $this->sportData();
  28. $this->info('结束执行统计比赛数据任务');
  29. }
  30. public function sportData()
  31. {
  32. try {
  33. $today = date('Y-m-d');
  34. $host = env('SPORT_HOST');
  35. $url = "{$host}/api/sport";
  36. $url .= "?date={$today}";
  37. $result = file_get_contents($url);
  38. $result = $result ? json_decode($result, true) : [];
  39. foreach ($result as $item) {
  40. $info = SportModel::where('data_id',$item['data_id'])->first();
  41. $data = [
  42. 'home_team_id' => $item['home_team_id'] ?? '',
  43. 'home_team_en' => $item['home_team_en'] ?? '',
  44. 'home_team' => $item['home_team'] ?? '',
  45. 'home_team_logo' => $item['home_team_logo'] ?? '',
  46. 'guest_team_id' => $item['guest_team_id'] ?? '',
  47. 'guest_team_en' => $item['guest_team_en'] ?? '',
  48. 'guest_team' => $item['guest_team'] ?? '',
  49. 'guest_team_logo' => $item['guest_team_logo'] ?? '',
  50. 'half_score' => $item['half_score'] ?? '',
  51. 'rbt' => $item['rbt'] ?? '',
  52. 'is_roll' => $item['is_roll'] ?? 0,
  53. 'score' => $item['score'] ?? '',
  54. 'league_en' => $item['league_en'] ?? '',
  55. 'league' => $item['league'] ?? '',
  56. 'odds' => $item['odds'] ?? '',
  57. 'state' => $item['state'] ?? 0,
  58. 'game_time' => $item['game_time'] ?? 0,
  59. 'status' => $item['status'] ?? 0,
  60. 'handicap_limit' => $item['handicap_limit'] ?? '',
  61. 'over_under_limit' => $item['over_under_limit'] ?? '',
  62. 'duying_limit' => $item['duying_limit'] ?? '',
  63. 'correct_core_limit' => $item['correct_core_limit'] ?? '',
  64. 'odd_even_limit' => $item['odd_even_limit'] ?? '',
  65. 'total_goal_limit' => $item['total_goal_limit'] ?? '',
  66. 'is_handicap' => $item['is_handicap'] ?? 0,
  67. 'is_over_under' => $item['is_over_under'] ?? 0,
  68. 'is_duying' => $item['is_duying'] ?? 0,
  69. 'is_correct_core' => $item['is_correct_core'] ?? 0,
  70. 'is_odd_even' => $item['is_odd_even'] ?? 0,
  71. 'is_total_goal' => $item['is_total_goal'] ?? 0,
  72. 'is_locked' => $item['is_locked'] ?? 0,
  73. ];
  74. if ($info) {
  75. //更新数据
  76. SportModel::where('data_id',$item['data_id'])->update($data);
  77. } else {
  78. $data['data_id'] = $item['data_id'];
  79. SportModel::create($data);
  80. }
  81. }
  82. } catch (\Exception $e) {
  83. $this->error($e->getMessage());
  84. }
  85. return true;
  86. }
  87. }