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

86 lines
3.0 KiB
PHP
Executable File

<?php
namespace App\Console\Commands\Zq;
use App\Model\Zq\ZqCompetition;
use App\Model\Zq\ZqMatch;
use App\Model\Zq\ZqTeam;
use App\Service\External\AlStatService;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
class SyncMatch extends Command
{
/**
* 这个就是命令名称
*/
protected $signature = 'zq:sync_match';
/**
* 命令的说明描述
* @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'])
->chunkById(500, function($competitions) {
foreach ($competitions as $competition) {
$this->syncMatch($competition->competition_id, $competition->curr_season);
}
});
}
public function syncMatch($competitionId, $season) {
/** @var AlStatService $alStatService */
$alStatService = app(AlStatService::class);
$matches = $alStatService->getZqMatches($competitionId, $season);
if (!$matches) {
return;
}
foreach ($matches as $item) {
$matchId = $item['id'];
$match = ZqMatch::withTrashed()->select('id')->where('match_id', $matchId)->first();
if (!$match) {
$match = new ZqMatch();
}
$match->match_id = $matchId;
$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 = strval(Arr::get($item, 'stage'));
$match->group_id = intval(Arr::get($item, 'groupId'));
$match->group_name = strval(Arr::get($item, 'groupName'));
$match->start_time = Arr::get($item, 'startTime', null);
$match->home_team_id = intval(Arr::get($item, 'homeTeamId'));
$match->away_team_id = intval(Arr::get($item, 'awayTeamId'));
$match->home_team_name = strval(Arr::get($item, 'homeTeamName'));
$match->away_team_name = strval(Arr::get($item, 'awayTeamName'));
$match->status = intval(Arr::get($item, 'status'));
$match->half_time_score = strval(Arr::get($item, 'halfTimeScore'));
$match->full_time_score = strval(Arr::get($item, 'fullTimeScore'));
$match->extra_time_score = strval(Arr::get($item, 'extraTimeScore'));
$match->penal_score = strval(Arr::get($item, 'penalScore'));
$match->final_score = strval(Arr::get($item, 'finalScore'));
$match->win_team_id = intval(Arr::get($item, 'winTeamId'));
$match->man_id = strval(Arr::get($item, 'manId'));
$match->save();
}
}
}