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

143 lines
4.6 KiB
PHP
Executable File

<?php
namespace App\Console\Commands\Zq;
use App\Model\Zq\JczqZhishuDaxiao;
use App\Model\Zq\JczqZhishuOu;
use App\Model\Zq\JczqZhishuYa;
use App\Service\External\AlStatService;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;
class SyncZqMainOdds extends Command
{
/**
* 这个就是命令名称
*/
protected $signature = 'zq:sync_zq_main_odds';
/**
* 命令的说明描述
* @var string
*/
protected $description = '';
/**
* 创建命令的构造方法。
* @param string $words 传入的字符参数
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* 命令的具体执行触发方法
* @return mixed
*/
public function handle()
{
Log::debug('----------- run sync main odds');
/** @var AlStatService $alStatService */
$alStatService = app(AlStatService::class);
$dates = [date('Ymd'), date('Ymd', strtotime('+1 day')), date('Ymd', strtotime('+2 day'))];
foreach ($dates as $date) {
$mainOdds = $alStatService->getZqMainOdds($date);
if (!$mainOdds) {
return;
}
foreach ($mainOdds as $item) {
$this->syncZhiShuOu($item['matchId'],$date, Arr::get($item, 'ouzhiOdds'));
$this->syncZhiShuYa($item['matchId'], $date,Arr::get($item, 'yazhiOdds'));
$this->syncZhiShuDaXiao($item['matchId'],$date, Arr::get($item, 'daxiaoOdds'));
}
}
}
protected function syncZhiShuOu($matchId,$date, $data) {
if (!$data) {
return;
}
foreach ($data as $item) {
$companyId = intval(Arr::get($item, 'companyId'));
$type = intval(Arr::get($item, 'type'));
$zhishu = JczqZhishuOu::where('cdate', $date)
->where('company_id', $companyId)
->where('match_id', $matchId)
->where('type', $type)
->first();
if (!$zhishu) {
$zhishu = new JczqZhishuOu();
}
$zhishu->match_id = $matchId;
$zhishu->cdate = $date;
$zhishu->company_id = $companyId;
$zhishu->type = $type;
$zhishu->win = floatval(Arr::get($item, 'win'));
$zhishu->draw = floatval(Arr::get($item, 'draw'));
$zhishu->loss = floatval(Arr::get($item, 'loss'));
$zhishu->change_time = Arr::get($item, 'changeTime');
$zhishu->save();
}
}
protected function syncZhiShuYa($matchId, $date,$data) {
if (!$data) {
return;
}
foreach ($data as $item) {
$companyId = intval(Arr::get($item, 'companyId'));
$type = intval(Arr::get($item, 'type'));
$zhishu = JczqZhishuYa::where('cdate', $date)
->where('company_id', $companyId)
->where('match_id', $matchId)
->where('type', $type)
->first();
if (!$zhishu) {
$zhishu = new JczqZhishuYa();
}
$zhishu->match_id = $matchId;
$zhishu->cdate = $date;
$zhishu->company_id = $companyId;
$zhishu->type = $type;
$zhishu->handicap = floatval(Arr::get($item, 'handicap'));
$zhishu->home = floatval(Arr::get($item, 'home'));
$zhishu->away = floatval(Arr::get($item, 'away'));
$zhishu->change_time = Arr::get($item, 'changeTime');
$zhishu->save();
}
}
protected function syncZhiShuDaXiao($matchId, $date,$data) {
if (!$data) {
return;
}
foreach ($data as $item) {
$companyId = intval(Arr::get($item, 'companyId'));
$type = intval(Arr::get($item, 'type'));
$zhishu = JczqZhishuDaxiao::where('cdate', $date)
->where('company_id', $companyId)
->where('match_id', $matchId)
->where('type', $type)
->first();
if (!$zhishu) {
$zhishu = new JczqZhishuDaxiao();
}
$zhishu->match_id = $matchId;
$zhishu->cdate = $date;
$zhishu->company_id = $companyId;
$zhishu->type = $type;
$zhishu->handicap = floatval(Arr::get($item, 'handicap'));
$zhishu->over = floatval(Arr::get($item, 'over'));
$zhishu->under = floatval(Arr::get($item, 'under'));
$zhishu->change_time = Arr::get($item, 'changeTime');
$zhishu->save();
}
}
}