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

70 lines
2.1 KiB
PHP
Executable File

<?php
namespace App\Console\Commands\Zq;
use App\Model\Zq\JczqScore;
use App\Service\External\AlStatService;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
class SyncScore extends Command
{
/**
* 这个就是命令名称
*/
protected $signature = 'zq:sync_score';
/**
* 命令的说明描述
* @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);
$scores = $alStatService->getZqScore();
if (!$scores) {
return;
}
foreach ($scores as $item) {
$id = $item['id'];
$match = JczqScore::withTrashed()->select('id')->where('score_id', $id)->first();
if (!$match) {
$match = new JczqScore();
}
$match->score_id = $id;
$match->match_id = intval(Arr::get($item, 'matchId'));
$match->elapsed = strval(Arr::get($item, 'elapsed'));
$match->status = intval(Arr::get($item, 'status'));
$match->period = intval(Arr::get($item, 'period'));
$match->score = strval(Arr::get($item, 'score'));
$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->win_team_id = intval(Arr::get($item, 'winTeamId'));
$match->home_team_red_cards = intval(Arr::get($item, 'homeTeamRedNum'));
$match->away_team_red_cards = intval(Arr::get($item, 'awayTeamRedNum'));
$match->save();
}
}
}