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

89 lines
2.5 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;
use Illuminate\Support\Facades\Log;
class SyncMatchChange extends Command
{
/**
* 这个就是命令名称
*/
protected $signature = 'zq:sync_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->getZqMatchesChange();
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('SyncZqMatchChange 未知的modify type类型', $item);
continue;
}
if ($type == self::TYPE_DELETE) {
$match = ZqMatch::withTrashed()->where('match_id', $matchId)->first();
if (!$match) {
Log::error('SyncZqMatchChange withTrashed 足比赛id不存在', $item);
continue;
}
if(!$match->trashed()) {
$match->delete();
}
continue;
}
$match = ZqMatch::where('match_id', $matchId)->first();
if (!$match) {
Log::error('SyncZqMatchChange 足比赛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();
}
}
}