101 lines
3.1 KiB
PHP
Executable File
101 lines
3.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands\Zq;
|
|
|
|
use App\Enums\LottType;
|
|
use App\Model\LotteryType;
|
|
use App\Model\Zq\BjdcOdds;
|
|
use App\Model\Zq\BjdcSfggOdds;
|
|
use App\Service\External\AlStatService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class SyncBjdcSfggOdds extends Command
|
|
{
|
|
/**
|
|
* 这个就是命令名称
|
|
*/
|
|
protected $signature = 'zq:sync_bjdc_sfgg_odds';
|
|
|
|
/**
|
|
* 命令的说明描述
|
|
* @var string
|
|
*/
|
|
protected $description = '';
|
|
|
|
/**
|
|
* 创建命令的构造方法。
|
|
* @param string $words 传入的字符参数
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* 命令的具体执行触发方法
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$this->syncOdds();
|
|
|
|
$sellingCount = BjdcSfggOdds::selling()->where('close_time', '>', date('Y-m-d H:i:s'))->count();
|
|
$lotteryType = LotteryType::withTrashed()->where('type', LottType::BJDC_SFGG)->first();
|
|
if (!$lotteryType) {
|
|
return;
|
|
}
|
|
$lotteryType->info = sprintf('%d场赛事可投', $sellingCount);
|
|
$lotteryType->save();
|
|
|
|
}
|
|
|
|
public function syncOdds() {
|
|
/** @var AlStatService $alStatService */
|
|
$alStatService = app(AlStatService::class);
|
|
$odds = $alStatService->getZqBjdcSfggOdds();
|
|
if (!$odds) {
|
|
return;
|
|
}
|
|
|
|
foreach ($odds as $item) {
|
|
$id = $item['id'];
|
|
$odd = BjdcSfggOdds::where('odds_id',$id)->first();
|
|
if (!$odd) {
|
|
$odd = new BjdcSfggOdds();
|
|
}
|
|
$odd->odds_id = $id;
|
|
$odd->match_id = strval(Arr::get($item, 'matchId'));
|
|
$odd->issue_num = strval(Arr::get($item, 'issueNum'));
|
|
$odd->play_num = strval(Arr::get($item, 'playNum'));
|
|
$odd->bd_competition_name = strval(Arr::get($item, 'bdComptName'));
|
|
$odd->bd_competition_name_full = strval(Arr::get($item, 'bdComptNameFull'));
|
|
$odd->bd_home_team_name = strval(Arr::get($item, 'bdHomeTeamName'));
|
|
$odd->bd_home_team_name_full = strval(Arr::get($item, 'bdHomeTeamNameFull'));
|
|
$odd->bd_away_team_name = strval(Arr::get($item, 'bdAwayTeamName'));
|
|
$odd->bd_away_team_name_full = strval(Arr::get($item, 'bdAwayTeamNameFull'));
|
|
$odd->sale_state = strval(Arr::get($item, 'salesState'));
|
|
$odd->is_reverse = strval(Arr::get($item, 'isReverse'));
|
|
$odd->close_time = strval(Arr::get($item, 'closeTime'));
|
|
$odd->sfgg_odds = Arr::get($item, 'sfggOdds', []);
|
|
$odd->sfgg_odds_last = $this->oddsLast($odd->sfgg_odds_last, $odd->sfgg_odds);
|
|
|
|
$odd->save();
|
|
}
|
|
}
|
|
|
|
protected function oddsLast($fieldOldData, $fieldNewData) {
|
|
if (!$fieldOldData) {
|
|
return $fieldNewData;
|
|
}
|
|
foreach ($fieldNewData as $k => $v) {
|
|
if (Arr::get($fieldOldData, $k) != $v) {
|
|
return $fieldNewData;
|
|
}
|
|
}
|
|
return $fieldOldData;
|
|
}
|
|
|
|
}
|