256 lines
9.6 KiB
PHP
Executable File
256 lines
9.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands\Zq;
|
|
|
|
use App\Enums\LottType;
|
|
use App\Jobs\RefreshOrderCtzqBqcResult;
|
|
use App\Jobs\RefreshOrderCtzqJqcResult;
|
|
use App\Jobs\RefreshOrderCtzqSfc14Result;
|
|
use App\Jobs\RefreshOrderCtzqSfc9Result;
|
|
use App\Model\Zq\CtzqBqc;
|
|
use App\Model\Zq\CtzqBqcMatch;
|
|
use App\Model\Zq\CtzqJqc;
|
|
use App\Model\Zq\CtzqJqcMatch;
|
|
use App\Model\Zq\CtzqSfc;
|
|
use App\Model\Zq\CtzqSfcMatch;
|
|
use App\Service\External\AlStatService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class SyncCtzq extends Command
|
|
{
|
|
/**
|
|
* 这个就是命令名称
|
|
*/
|
|
protected $signature = 'zq:sync_ctzq';
|
|
|
|
/**
|
|
* 命令的说明描述
|
|
* @var string
|
|
*/
|
|
protected $description = '';
|
|
|
|
/**
|
|
* 创建命令的构造方法。
|
|
* @param string $words 传入的字符参数
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* 命令的具体执行触发方法
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
Log::info('SyncCtzq 同步传统足球数据');
|
|
/** @var AlStatService $alStatService */
|
|
$alStatService = app(AlStatService::class);
|
|
$data = $alStatService->getZqCtzq();
|
|
|
|
$jqcData = Arr::get($data, LottType::CTZQ_JQC);
|
|
$this->saveJqc($jqcData);
|
|
|
|
$bqcData = Arr::get($data, LottType::CTZQ_BQC);
|
|
$this->saveBqc($bqcData);
|
|
|
|
$sfcData = Arr::get($data, 'sfc');
|
|
$this->saveSfc($sfcData);
|
|
}
|
|
|
|
private function saveJqc($data)
|
|
{
|
|
if (!$data) {
|
|
Log::error('SyncCtzq::saveJqc data is null');
|
|
return;
|
|
}
|
|
foreach ($data as $item) {
|
|
$ctzq = CtzqJqc::where('jqc_id', $item['id'])
|
|
->first();
|
|
if (!$ctzq) {
|
|
$ctzq = new CtzqJqc();
|
|
}
|
|
$ctzq->jqc_id = $item['id'];
|
|
$ctzq->issue_num = strval(Arr::get($item, 'issueNum'));
|
|
$ctzq->state = strval(Arr::get($item, 'state'));
|
|
$ctzq->start_time =strval(Arr::get($item, 'startTime'));
|
|
$ctzq->end_time = strval(Arr::get($item, 'endTime'));
|
|
$ctzq->prize_time = strval(Arr::get($item, 'prizeTime'));
|
|
$ctzq->result_info = strval(Arr::get($item, 'resultInfo'));
|
|
$ctzq->sales = floatval(Arr::get($item, 'sales'));
|
|
$ctzq->jackpot = floatval(Arr::get($item, 'jackpot'));
|
|
$ctzq->first_prize_num = intval(Arr::get($item, 'firstPrizeNum'));
|
|
$ctzq->first_prize_value =floatval(Arr::get($item, 'firstPrizeValue'));
|
|
$ctzq->matchs = Arr::get($item, 'matchs', []);
|
|
$ctzq->save();
|
|
|
|
$this->saveCtzqJqcMatches($ctzq, Arr::get($item, 'matchs'));
|
|
|
|
// 如果win
|
|
if ($ctzq->result_info) {
|
|
RefreshOrderCtzqJqcResult::dispatch($ctzq->id);
|
|
}
|
|
}
|
|
}
|
|
private function saveCtzqJqcMatches(CtzqJqc $ctzq, $matches)
|
|
{
|
|
if (!$matches) {
|
|
return;
|
|
}
|
|
|
|
foreach ($matches as $item) {
|
|
$match = CtzqJqcMatch::where('ctzq_jqc_id', $ctzq->id)->where('match_id', $item['matchId'])->first();
|
|
if (!$match) {
|
|
$match = new CtzqJqcMatch();
|
|
}
|
|
$match->ctzq_jqc_id = $ctzq->id;
|
|
$match->match_id = $item['matchId'];
|
|
$match->jc_home_team_name = strval(Arr::get($item, 'jcHomeTeamName'));
|
|
$match->jc_home_team_name_full = strval(Arr::get($item, 'jcHomeTeamNameFull'));
|
|
$match->jc_away_team_name = strval(Arr::get($item, 'jcAwayTeamName'));
|
|
$match->jc_away_team_name_full = strval(Arr::get($item, 'jcAwayTeamNameFull'));
|
|
$match->is_reverse = intval(Arr::get($item, 'isReverse'));
|
|
$no = $item['no'];
|
|
if ($no % 2 == 0) {
|
|
$match->away_result = $item['result'];
|
|
} else {
|
|
$match->home_result = $item['result'];
|
|
}
|
|
$match->save();
|
|
}
|
|
}
|
|
|
|
|
|
private function saveBqc($data)
|
|
{
|
|
if (!$data) {
|
|
Log::error('SyncCtzq::saveBqc data is null');
|
|
|
|
return;
|
|
}
|
|
foreach ($data as $item) {
|
|
$ctzq = CtzqBqc::where('bqc_id', $item['id'])
|
|
->first();
|
|
if (!$ctzq) {
|
|
$ctzq = new CtzqBqc();
|
|
}
|
|
$ctzq->bqc_id = $item['id'];
|
|
$ctzq->issue_num = strval(Arr::get($item, 'issueNum'));
|
|
$ctzq->state = strval(Arr::get($item, 'state'));
|
|
$ctzq->start_time =strval(Arr::get($item, 'startTime'));
|
|
$ctzq->end_time = strval(Arr::get($item, 'endTime'));
|
|
$ctzq->prize_time = strval(Arr::get($item, 'prizeTime'));
|
|
$ctzq->result_info = strval(Arr::get($item, 'resultInfo'));
|
|
$ctzq->sales = floatval(Arr::get($item, 'sales'));
|
|
$ctzq->jackpot = floatval(Arr::get($item, 'jackpot'));
|
|
$ctzq->first_prize_num = intval(Arr::get($item, 'firstPrizeNum'));
|
|
$ctzq->first_prize_value =floatval(Arr::get($item, 'firstPrizeValue'));
|
|
$ctzq->matchs = Arr::get($item, 'matchs', []);
|
|
$ctzq->save();
|
|
$this->saveCtzqBqcMatches($ctzq,Arr::get($item, 'matchs', []));
|
|
// 如果win
|
|
if ($ctzq->result_info) {
|
|
RefreshOrderCtzqBqcResult::dispatch($ctzq->id);
|
|
}
|
|
}
|
|
}
|
|
private function saveCtzqBqcMatches(CtzqBqc $ctzq, $matches)
|
|
{
|
|
if (!$matches) {
|
|
return;
|
|
}
|
|
|
|
foreach ($matches as $item) {
|
|
$match = CtzqBqcMatch::where('ctzq_bqc_id', $ctzq->id)->where('match_id', $item['matchId'])->first();
|
|
if (!$match) {
|
|
$match = new CtzqBqcMatch();
|
|
}
|
|
$match->ctzq_bqc_id = $ctzq->id;
|
|
$match->match_id = $item['matchId'];
|
|
$match->jc_home_team_name = strval(Arr::get($item, 'jcHomeTeamName'));
|
|
$match->jc_home_team_name_full = strval(Arr::get($item, 'jcHomeTeamNameFull'));
|
|
$match->jc_away_team_name = strval(Arr::get($item, 'jcAwayTeamName'));
|
|
$match->jc_away_team_name_full = strval(Arr::get($item, 'jcAwayTeamNameFull'));
|
|
$match->is_reverse = intval(Arr::get($item, 'isReverse'));
|
|
|
|
// 序号是奇数为半场胜平负、序号是偶数为全场胜平负
|
|
$no = $item['no'];
|
|
if ($no % 2 == 0) {
|
|
$match->half_result = $item['result'];
|
|
} else {
|
|
$match->whole_result = $item['result'];
|
|
}
|
|
$match->save();
|
|
}
|
|
}
|
|
|
|
private function saveSfc($data)
|
|
{
|
|
if (!$data) {
|
|
Log::error('SyncCtzq::saveSfc data is null');
|
|
return;
|
|
}
|
|
foreach ($data as $item) {
|
|
$ctzqSfc = CtzqSfc::where('sfc_id', $item['id'])
|
|
->first();
|
|
if (!$ctzqSfc) {
|
|
$ctzqSfc = new CtzqSfc();
|
|
}
|
|
$ctzqSfc->sfc_id = $item['id'];
|
|
$ctzqSfc->issue_num = strval(Arr::get($item, 'issueNum'));
|
|
$ctzqSfc->state = strval(Arr::get($item, 'state'));
|
|
$ctzqSfc->start_time = strval(Arr::get($item, 'startTime'));
|
|
$ctzqSfc->end_time = strval(Arr::get($item, 'endTime'));
|
|
$ctzqSfc->prize_time = strval(Arr::get($item, 'prizeTime'));
|
|
$ctzqSfc->result_info = strval(Arr::get($item, 'resultInfo'));
|
|
$ctzqSfc->sale_frtn = floatval(Arr::get($item, 'salesFrtn'));
|
|
$ctzqSfc->jackpot_frtn = floatval(Arr::get($item, 'jackpotFrtn'));
|
|
$ctzqSfc->first_prize_num_frtn = intval(Arr::get($item, 'firstPrizeValFrtn'));
|
|
$ctzqSfc->first_prize_val_frtn = floatval(Arr::get($item, 'firstPrizeValue'));
|
|
$ctzqSfc->second_prize_num_frtn = intval(Arr::get($item, 'secondPrizeNumFrtn'));
|
|
$ctzqSfc->second_prize_val_frtn = floatval(Arr::get($item, 'secondPrizeValFrtn'));
|
|
$ctzqSfc->sale_nine = floatval(Arr::get($item, 'salesNine'));
|
|
$ctzqSfc->jackpot_nine = floatval(Arr::get($item, 'jackpotNine'));
|
|
$ctzqSfc->first_prize_num_nine = intval(Arr::get($item, 'firstPrizeNumNine'));
|
|
$ctzqSfc->first_prize_val_nine = floatval(Arr::get($item, 'firstPrizeValNine'));
|
|
$ctzqSfc->matchs = Arr::get($item, 'matchs', []);
|
|
$ctzqSfc->save();
|
|
$this->saveCtzqSfcMatches($ctzqSfc,Arr::get($item, 'matchs', []));
|
|
|
|
// 如果win
|
|
if ($ctzqSfc->result_info) {
|
|
RefreshOrderCtzqSfc9Result::dispatch($ctzqSfc->id);
|
|
RefreshOrderCtzqSfc14Result::dispatch($ctzqSfc->id);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function saveCtzqSfcMatches(CtzqSfc $ctzqSfc, $matches)
|
|
{
|
|
if (!$matches) {
|
|
return;
|
|
}
|
|
|
|
foreach ($matches as $item) {
|
|
$match = CtzqSfcMatch::where('ctzq_sfc_id', $ctzqSfc->id)->where('match_id', $item['matchId'])->first();
|
|
if (!$match) {
|
|
$match = new CtzqSfcMatch();
|
|
}
|
|
$match->ctzq_sfc_id = $ctzqSfc->id;
|
|
$match->no = $item['no'];
|
|
$match->match_id = $item['matchId'];
|
|
$match->jc_home_team_name = strval(Arr::get($item, 'jcHomeTeamName'));
|
|
$match->jc_home_team_name_full = strval(Arr::get($item, 'jcHomeTeamNameFull'));
|
|
$match->jc_away_team_name = strval(Arr::get($item, 'jcAwayTeamName'));
|
|
$match->jc_away_team_name_full = strval(Arr::get($item, 'jcAwayTeamNameFull'));
|
|
$match->is_reverse = intval(Arr::get($item, 'isReverse'));
|
|
$match->result = strval(Arr::get($item, 'result'));
|
|
$match->save();
|
|
}
|
|
}
|
|
}
|