113 lines
3.7 KiB
PHP
Executable File
113 lines
3.7 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands\Zq;
|
|
|
|
use App\Enums\LottType;
|
|
use App\Model\LotteryType;
|
|
use App\Model\Zq\JczqOdds;
|
|
use App\Service\External\AlStatService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class SyncJczqOdds extends Command
|
|
{
|
|
/**
|
|
* 这个就是命令名称
|
|
*/
|
|
protected $signature = 'zq:sync_jczq_odds';
|
|
|
|
/**
|
|
* 命令的说明描述
|
|
* @var string
|
|
*/
|
|
protected $description = '';
|
|
|
|
/**
|
|
* 创建命令的构造方法。
|
|
* @param string $words 传入的字符参数
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* 命令的具体执行触发方法
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
Log::info('SyncJczqOdds 足球赔率数据');
|
|
|
|
$this->syncOdds();
|
|
|
|
$sellingCount = JczqOdds::selling()->where('real_close_time', '>', date('Y-m-d H:i:s'))->count();
|
|
$lotteryType = LotteryType::withTrashed()->where('type', LottType::JCZQ)->first();
|
|
$lotteryType->info = sprintf('%d场赛事可投', $sellingCount);
|
|
$lotteryType->save();
|
|
|
|
}
|
|
|
|
public function syncOdds() {
|
|
/** @var AlStatService $alStatService */
|
|
$alStatService = app(AlStatService::class);
|
|
$odds = $alStatService->getZqJczqOdds();
|
|
if (!$odds) {
|
|
return;
|
|
}
|
|
|
|
foreach ($odds as $item) {
|
|
$id = $item['id'];
|
|
$odd = JczqOdds::where('odds_id',$id)->first();
|
|
if (!$odd) {
|
|
$odd = new JczqOdds();
|
|
}
|
|
$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->jc_competition_name = strval(Arr::get($item, 'jcComptName'));
|
|
$odd->jc_competition_name_full = strval(Arr::get($item, 'jcComptNameFull'));
|
|
$odd->jc_home_team_name = strval(Arr::get($item, 'jcHomeTeamName'));
|
|
$odd->jc_home_team_name_full = strval(Arr::get($item, 'jcHomeTeamNameFull'));
|
|
$odd->jc_away_team_name = strval(Arr::get($item, 'jcAwayTeamName'));
|
|
$odd->jc_away_team_name_full = strval(Arr::get($item, 'jcAwayTeamNameFull'));
|
|
$odd->sale_state = strval(Arr::get($item, 'salesState'));
|
|
$odd->is_reverse = strval(Arr::get($item, 'isReverse'));
|
|
$odd->real_close_time = strval(Arr::get($item, 'closeTime'));
|
|
$odd->order_state = strval(Arr::get($item, 'orderState'));
|
|
$odd->spf_odds = Arr::get($item, 'spfOdds', []);
|
|
$odd->spf_odds_last = $this->oddsLast($odd->spf_odds_last, $odd->spf_odds);
|
|
|
|
$odd->rq_odds = Arr::get($item, 'rqOdds', []);
|
|
$odd->rq_odds_last = $this->oddsLast($odd->rq_odds_last, $odd->rq_odds);
|
|
|
|
$odd->bf_odds =Arr::get($item, 'bfOdds', []);
|
|
$odd->bf_odds_last = $this->oddsLast($odd->bf_odds_last, $odd->bf_odds);
|
|
|
|
$odd->jq_odds = Arr::get($item, 'jqOdds', []);
|
|
$odd->jq_odds_last = $this->oddsLast($odd->jq_odds_last, $odd->jq_odds);
|
|
|
|
$odd->bqc_odds = Arr::get($item, 'bqcOdds', []);
|
|
$odd->bqc_odds_last = $this->oddsLast($odd->bqc_odds_last, $odd->bqc_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;
|
|
}
|
|
|
|
}
|