86 lines
2.5 KiB
PHP
Executable File
86 lines
2.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands\Lq;
|
|
|
|
use App\Model\Lq\JclqMatch;
|
|
use App\Service\External\AlStatService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class SyncLqMatchChange extends Command
|
|
{
|
|
/**
|
|
* 这个就是命令名称
|
|
*/
|
|
protected $signature = 'lq:sync_lq_match_change';
|
|
|
|
/**
|
|
* 命令的说明描述
|
|
* @var string
|
|
*/
|
|
protected $description = '';
|
|
|
|
const TYPE_DELETE = 'delete';
|
|
const TYPE_MODIFY = 'modify';
|
|
|
|
/**
|
|
* 创建命令的构造方法。
|
|
* @param string $words 传入的字符参数
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* 命令的具体执行触发方法
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
/** @var AlStatService $alStatService */
|
|
$alStatService = app(AlStatService::class);
|
|
$matches = $alStatService->getLqMatchChange();
|
|
if (!$matches) {
|
|
return;
|
|
}
|
|
foreach ($matches as $item) {
|
|
$matchId = $item['matchId'];
|
|
$type = Arr::get($item, 'type');
|
|
if (!in_array($type, [self::TYPE_DELETE, self::TYPE_MODIFY])) {
|
|
Log::error('SyncLqMatchChange 未知的modify type类型', $item);
|
|
continue;
|
|
}
|
|
|
|
if ($type == self::TYPE_DELETE) {
|
|
$match = JclqMatch::withTrashed()->where('match_id', $matchId)->first();
|
|
if (!$match) {
|
|
Log::error('SyncLqMatchChange withTrashed比赛id不存在', $item);
|
|
continue;
|
|
}
|
|
if (!$match->trashed()) {
|
|
$match->delete();
|
|
}
|
|
continue;
|
|
}
|
|
|
|
$match = JclqMatch::where('match_id', $matchId)->first();
|
|
if (!$match) {
|
|
Log::error('SyncLqMatchChange 比赛id不存在', $item);
|
|
continue;
|
|
}
|
|
$match->status = intval(Arr::get($item, 'matchStatus'));
|
|
$match->start_time = Arr::get($item, 'matchStartTime', 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->save();
|
|
}
|
|
}
|
|
|
|
}
|