| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use App\Models\Sport as SportModel;
- class SportOdds extends Command
- {
- /**
- * 命令名称和签名
- *
- * @var string
- */
- protected $signature = 'sport:odds {is_roll=0}';
- protected $is_roll = 0;
- /**
- * 命令描述
- *
- * @var string
- */
- protected $description = '赔率(滚球5秒更新一次,普通的3小时更新一次)';
- /**
- * 执行命令
- *
- * @return int
- */
- public function handle()
- {
- $this->is_roll = $this->argument('is_roll');
- if ($this->is_roll == 1) {
- $this->info('滚球开始执行赔率任务...');
- $this->sportOddsData($this->is_roll);
- } else {
- $this->info('普通开始执行赔率任务...');
- $this->sportOddsData($this->is_roll);
- }
-
- $this->info('结束执行赔率任务');
- }
- public function sportOddsData($is_roll)
- {
- try {
- $host = env('SPORT_HOST');
- $where['status'] = 1;
- $where['is_roll'] = $is_roll;
- //滚球(滚球是开赛后随时可以买,更新数据)
- if ($is_roll == 1) {
- $where['state'] = 1; //比赛状态:0未开始1进行中2已完场3延期4取消
- $url = "{$host}/api/sport/oddsLive";
- } else {
- //普通球赛是开赛前购买,更新数据
- $where['state'] = 0;
- $url = "{$host}/api/sport/odds";
- }
- $list = SportModel::where($where)->get()->toArray();
- foreach ($list as $item) {
- $url .= "?data_id={$item['data_id']}";
- $result = file_get_contents($url);
- $result = $result ? json_decode($result, true) : [];
- }
-
- } catch (\Exception $e) {
- $this->error($e->getMessage());
- }
-
-
-
- return true;
- }
- }
|