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

110 lines
3.2 KiB
PHP
Executable File

<?php
namespace App\Console\Commands\Zq;
use App\Jobs\RefreshOrderGuanResult;
use App\Model\Zq\JczqGuan;
use App\Model\Zq\JczqGuanOdds;
use App\Service\External\AlStatService;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;
class SyncGuan extends Command
{
/**
* 这个就是命令名称
*/
protected $signature = 'zq:sync_guan';
/**
* 命令的说明描述
* @var string
*/
protected $description = '竞彩足球冠军数据';
/**
* 创建命令的构造方法。
* @param string $words 传入的字符参数
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* 命令的具体执行触发方法
* @return mixed
*/
public function handle()
{
$this->syncOdds();
}
public function syncOdds()
{
/** @var AlStatService $alStatService */
$alStatService = app(AlStatService::class);
$odds = $alStatService->getZqGuan();
if (!$odds) {
return;
}
foreach ($odds as $item) {
$id = $item['id'];
$odd = JczqGuan::where('guan_id', $id)->first();
if (!$odd) {
$odd = new JczqGuan();
}
$options = Arr::get($item, 'options');
$odd->guan_id = $id;
$odd->competition = intval(Arr::get($item, 'competition'));
$odd->competition_name = strval(Arr::get($item, 'competitionName'));
$odd->season = strval(Arr::get($item, 'season'));
$odd->type = strval(Arr::get($item, 'type'));
$odd->sales_state = strval(Arr::get($item, 'salesState'));
$odd->lott_state = strval(Arr::get($item, 'lottState'));
$odd->close_time = strval(Arr::get($item, 'closeTime'));
$odd->options = $options;
$odd->save();
$this->saveGuanOdds($odd->id, $options);
}
}
protected function saveGuanOdds($jczqGuanId, $options)
{
if (!is_array($options)) {
return;
}
foreach ($options as $item) {
$id = $item['id'];
$odd = JczqGuanOdds::where('odds_id', $id)->where('jczq_guan_id', $jczqGuanId)->first();
if (!$odd) {
$odd = new JczqGuanOdds();
}
$odd->jczq_guan_id = $jczqGuanId;
$odd->odds_id = $id;
$odd->team_id = intval(Arr::get($item, 'teamId'));
$odd->team_name = strval(Arr::get($item, 'teamName'));
$odd->option_num = intval(Arr::get($item, 'optionNum'));
$odd->odds = Arr::get($item, 'odds');
$odd->season = strval(Arr::get($item, 'season'));
$odd->sales_state = strval(Arr::get($item, 'salesState'));
$odd->show_state = strval(Arr::get($item, 'showState'));
$odd->order_state = strval(Arr::get($item, 'orderState'));
$odd->save();
if ($odd->show_state == 'win' || $odd->show_state == 'out') {
Log::info('guankaijiang will dispath RefreshOrderGuanResult, guanOddsId:' .$odd->id);
RefreshOrderGuanResult::dispatch($odd->id);
}
}
}
}