jingcai-php/app/Console/Commands/Lq/SyncLqSeason.php

72 lines
1.9 KiB
PHP
Executable File

<?php
namespace App\Console\Commands\Lq;
use App\Model\Lq\JclqCompany;
use App\Model\Lq\JclqCompetition;
use App\Model\Lq\JclqSeason;
use App\Service\External\AlStatService;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
class SyncLqSeason extends Command
{
/**
* 这个就是命令名称
*/
protected $signature = 'lq:sync_lq_season';
/**
* 命令的说明描述
* @var string
*/
protected $description = '';
/**
* 创建命令的构造方法。
* @param string $words 传入的字符参数
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* 命令的具体执行触发方法
* @return mixed
*/
public function handle()
{
JclqCompetition::select(['id', 'competition_id'])
->chunkById(500, function ($competitions) {
foreach ($competitions as $competition) {
$this->syncSeason($competition->competition_id);
}
});
}
public function syncSeason($competitionId)
{
/** @var AlStatService $alStatService */
$alStatService = app(AlStatService::class);
$seasons = $alStatService->getLqSeason($competitionId);
if (!$seasons) {
return;
}
foreach ($seasons as $item) {
$season = JclqSeason::where('season_id', $item['id'])->first();
if (!$season) {
$season = new JclqSeason();
}
$season->season_id = $item['id'];
$season->competition_id = intval(Arr::get($item, 'competitionId'));
$season->season = strval(Arr::get($item, 'season'));
$season->start_date = strval( Arr::get($item, 'startDate'));
$season->end_date = strval(Arr::get($item, 'endDate'));
$season->save();
}
}
}