75 lines
2.1 KiB
PHP
Executable File
75 lines
2.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands\Zq;
|
|
|
|
use App\Model\Zq\ZqCompetition;
|
|
use App\Model\Zq\ZqTeam;
|
|
use App\Service\External\AlStatService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class SyncTeam extends Command
|
|
{
|
|
/**
|
|
* 这个就是命令名称
|
|
*/
|
|
protected $signature = 'zq:sync_team';
|
|
|
|
/**
|
|
* 命令的说明描述
|
|
* @var string
|
|
*/
|
|
protected $description = '';
|
|
|
|
/**
|
|
* 创建命令的构造方法。
|
|
* @param string $words 传入的字符参数
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* 命令的具体执行触发方法
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
|
|
// ZqCompetition::select(['id','competition_id', 'curr_season'])
|
|
//// ->where('id', 3)
|
|
// ->chunkById(500, function($competitions) {
|
|
// foreach ($competitions as $competition) {
|
|
// $this->syncTeam($competition->competition_id, '');
|
|
// }
|
|
// });
|
|
|
|
/** @var AlStatService $alStatService */
|
|
$alStatService = app(AlStatService::class);
|
|
$teams = $alStatService->getZqTeam();
|
|
if (!$teams) {
|
|
return;
|
|
}
|
|
foreach ($teams as $item) {
|
|
$teamId = $item['id'];
|
|
$team = ZqTeam::where('team_id', $teamId)->first();
|
|
if (!$team) {
|
|
$team = new ZqTeam();
|
|
}
|
|
$team->team_id = $teamId;
|
|
$team->competition_id = intval(Arr::get($item, 'competitionId'));
|
|
$team->name = strval(Arr::get($item, 'name'));
|
|
$team->name_full = strval(Arr::get($item, 'nameFull'));
|
|
$team->name_en = strval(Arr::get($item, 'nameEn'));
|
|
$team->name_en_full = strval(Arr::get($item, 'nameEnFull'));
|
|
$team->team_type = strval(Arr::get($item, 'teamType'));
|
|
$team->league_id = intval(Arr::get($item, 'leagueId'));
|
|
$team->country = strval(Arr::get($item, 'country'));
|
|
$team->save();
|
|
}
|
|
}
|
|
|
|
}
|