jingcai-php/app/Console/Commands/Zq/SyncCompetition.php

68 lines
2.1 KiB
PHP
Executable File

<?php
namespace App\Console\Commands\Zq;
use App\Model\Zq\ZqCompetition;
use App\Service\External\AlStatService;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
class SyncCompetition extends Command
{
/**
* 这个就是命令名称
*/
protected $signature = 'zq:sync_competition';
/**
* 命令的说明描述
* @var string
*/
protected $description = '';
/**
* 创建命令的构造方法。
* @param string $words 传入的字符参数
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* 命令的具体执行触发方法
* @return mixed
*/
public function handle()
{
/** @var AlStatService $alStatService */
$alStatService = app(AlStatService::class);
$competitions = $alStatService->getZqCompetition();
if (!$competitions) {
return;
}
foreach ($competitions as $item) {
$competition = ZqCompetition::where('competition_id', $item['id'])->first();
if (!$competition) {
$competition = new ZqCompetition();
}
$competition->competition_id = $item['id'];
$competition->name = strval(Arr::get($item, 'name'));
$competition->name_full = strval(Arr::get($item, 'nameFull'));
$competition->name_en = strval(Arr::get($item, 'nameEn'));
$competition->name_en_full = strval(Arr::get($item, 'nameEnFull'));
$competition->competition_type = strval(Arr::get($item, 'competitionType'));
$competition->team_type = strval(Arr::get($item, 'teamType'));
$competition->country = strval( Arr::get($item, 'country'));
$competition->curr_season = strval(Arr::get($item, 'currSeason'));
$competition->seasons = Arr::get($item, 'seasons', []);
$competition->colour = strval(Arr::get($item, 'colour'));
$competition->has_detail = strval(Arr::get($item, 'hasDetail'));
$competition->save();
}
}
}