108 lines
4.1 KiB
PHP
Executable File
108 lines
4.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands\Lq;
|
|
|
|
use App\Model\Lq\JclqCompany;
|
|
use App\Model\Lq\JclqCompetition;
|
|
use App\Model\Lq\JclqMatch;
|
|
use App\Model\Lq\JclqSeason;
|
|
use App\Service\External\AlStatService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class SyncLqMatch extends Command
|
|
{
|
|
/**
|
|
* 这个就是命令名称
|
|
*/
|
|
protected $signature = 'lq:sync_lq_match';
|
|
|
|
/**
|
|
* 命令的说明描述
|
|
* @var string
|
|
*/
|
|
protected $description = '';
|
|
|
|
/**
|
|
* 创建命令的构造方法。
|
|
* @param string $words 传入的字符参数
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* 命令的具体执行触发方法
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
JclqSeason::select(['id', 'season_id'])
|
|
->chunkById(500, function ($seasons) {
|
|
foreach ($seasons as $season) {
|
|
$this->syncMatch($season->season_id);
|
|
}
|
|
});
|
|
}
|
|
|
|
public function syncMatch($seasonId)
|
|
{
|
|
/** @var AlStatService $alStatService */
|
|
$alStatService = app(AlStatService::class);
|
|
$matches = $alStatService->getLqMatch($seasonId);
|
|
if (!$matches) {
|
|
return;
|
|
}
|
|
|
|
foreach ($matches as $item) {
|
|
$match =JclqMatch::withTrashed()->select('id')->where('match_id', $item['id'])->first();
|
|
if (!$match) {
|
|
$match = new JclqMatch();
|
|
}
|
|
|
|
$match->match_id = $item['id'];
|
|
$match->season_id = intval(Arr::get($item, 'seasonId'));
|
|
$match->competition_id = intval(Arr::get($item, 'competitionId'));
|
|
$match->competition_name = strval(Arr::get($item, 'competitionName'));
|
|
$match->season = strval(Arr::get($item, 'season'));
|
|
$match->stage_id = intval(Arr::get($item, 'stageId'));
|
|
$match->stage_name = strval(Arr::get($item, 'stageName'));
|
|
$match->group_id = intval(Arr::get($item, 'groupId'));
|
|
$match->group_name = strval(Arr::get($item, 'groupName'));
|
|
$match->playoff_id = intval(Arr::get($item, 'playoffId'));
|
|
$match->round_num = intval(Arr::get($item, 'roundNum'));
|
|
$match->start_time = Arr::get($item, 'startTime');
|
|
$match->home_team_id = intval(Arr::get($item, 'homeTeamId'));
|
|
$match->home_team_name = strval(Arr::get($item, 'homeTeamName'));
|
|
$match->away_team_id = intval(Arr::get($item, 'awayTeamId'));
|
|
$match->away_team_name = strval(Arr::get($item, 'awayTeamName'));
|
|
$match->status = intval(Arr::get($item, 'status'));
|
|
$match->quarter_num = intval(Arr::get($item, 'quarterNum'));
|
|
$match->home_score = intval(Arr::get($item, 'homeScore'));
|
|
$match->away_score = intval(Arr::get($item, 'awayScore'));
|
|
$match->q1home_score = intval(Arr::get($item, 'q1homeScore'));
|
|
$match->q1away_score = intval(Arr::get($item, 'q1awayScore'));
|
|
$match->q2home_score = intval(Arr::get($item, 'q2homeScore'));
|
|
$match->q2away_score = intval(Arr::get($item, 'q2awayScore'));
|
|
$match->q3home_score = intval(Arr::get($item, 'q3homeScore'));
|
|
$match->q3away_score = intval(Arr::get($item, 'q3awayScore'));
|
|
$match->q4home_score = intval(Arr::get($item, 'q4homeScore'));
|
|
$match->q4away_score = intval(Arr::get($item, 'q4awayScore'));
|
|
$match->over_time_num = intval(Arr::get($item, 'overTimeNum'));
|
|
|
|
$overTimeScore = [];
|
|
if (Arr::get($item, 'overTimeScore')) {
|
|
$overTimeScore = Arr::get($item, 'overTimeScore');
|
|
}
|
|
$match->ot1_home_score = intval(Arr::get($overTimeScore, 'ot1homeScore'));
|
|
$match->ot1_away_score = intval(Arr::get($overTimeScore, 'ot1awayScore'));
|
|
$match->win_team_id = intval(Arr::get($item, 'winTeamId'));
|
|
$match->is_neutral = intval(Arr::get($item, 'isNeutral'));
|
|
$match->venue_id = intval(Arr::get($item, 'venueId'));
|
|
$match->save();
|
|
}
|
|
}
|
|
}
|