568 lines
15 KiB
PHP
Executable File
568 lines
15 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Service\External;
|
|
|
|
use App\Enums\LottType;
|
|
use App\Exceptions\JingCaiException;
|
|
use App\Utils\ThrowException;
|
|
use GuzzleHttp\Client;
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class AlStatService
|
|
{
|
|
const TYPE_ZQ = 'zq';
|
|
const TYPE_LQ = 'lq';
|
|
|
|
protected $zqKey;
|
|
protected $lqKey;
|
|
|
|
protected $timeout = 30;
|
|
|
|
protected $client;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->zqKey = config('alstat.zq.key');
|
|
$this->lqKey = config('alstat.lq.key');
|
|
|
|
$this->client = new Client([
|
|
'timeout' => $this->timeout
|
|
]);
|
|
}
|
|
|
|
protected function commonZqParam()
|
|
{
|
|
return [
|
|
'key' => $this->zqKey
|
|
];
|
|
}
|
|
|
|
protected function commonLqParam()
|
|
{
|
|
return [
|
|
'key' => $this->lqKey
|
|
];
|
|
}
|
|
public function getZqCompany()
|
|
{
|
|
|
|
$res = $this->httpGet(AlStatUrl::ZQ_COMPANY, [], self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'companies');
|
|
|
|
}
|
|
public function getZqCompetition()
|
|
{
|
|
|
|
$res = $this->httpGet(AlStatUrl::ZQ_COMPETITION, [], self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'competitions');
|
|
|
|
}
|
|
|
|
public function getZqTeam($competitionId = 0, $season = '')
|
|
{
|
|
$param = [];
|
|
if ($competitionId) {
|
|
$param['competitionId'] = $competitionId;
|
|
}
|
|
if ($season) {
|
|
$param['season'] = $season;
|
|
}
|
|
|
|
$res = $this->httpGet(AlStatUrl::ZQ_TEAM, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'teams');
|
|
|
|
}
|
|
|
|
public function getZqMatchesByDate($dateStart = null, $dateEnd = null) {
|
|
if (!$dateStart) {
|
|
$dateStart = date('Ymd');
|
|
}
|
|
if (!$dateEnd) {
|
|
$dateEnd = date('Ymd', strtotime('+6 day', strtotime($dateStart)));
|
|
}
|
|
$param = [
|
|
'beginDate' => $dateStart,
|
|
'endDate' => $dateEnd,
|
|
];
|
|
$res = $this->httpGet(AlStatUrl::ZQ_MATCH_BY_DATE, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'matchs');
|
|
}
|
|
public function getZqMatches($competitionId, $season) {
|
|
|
|
$param = [
|
|
'competitionId' => $competitionId,
|
|
'season' => $season,
|
|
];
|
|
$res = $this->httpGet(AlStatUrl::ZQ_MATCH, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'matchs');
|
|
}
|
|
|
|
public function getZqScore() {
|
|
$param = [];
|
|
$res = $this->httpGet(AlStatUrl::ZQ_SCORE, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'liveScores');
|
|
}
|
|
public function getZqMatchesChange() {
|
|
|
|
$param = [ ];
|
|
$res = $this->httpGet(AlStatUrl::ZQ_MATCH_CHANGE, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'modifyLogs');
|
|
}
|
|
|
|
public function getZqJczqOdds($issueNum = '')
|
|
{
|
|
$param = [];
|
|
if ($issueNum) {
|
|
$param['issueNum'] = $issueNum;
|
|
}
|
|
|
|
$res = $this->httpGet(AlStatUrl::ZQ_JCZQ_ODDS, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'jczqOdds');
|
|
|
|
}
|
|
|
|
public function getJczqResult($issueNum = '')
|
|
{
|
|
$param = [];
|
|
if ($issueNum) {
|
|
$param['issueNum'] = $issueNum;
|
|
}
|
|
|
|
$res = $this->httpGet(AlStatUrl::ZQ_JCZQ_RESULT, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'jczqResults');
|
|
|
|
}
|
|
|
|
public function getZqCtzq($issueNum = '')
|
|
{
|
|
$param = [];
|
|
if ($issueNum) {
|
|
$param['issueNum'] = $issueNum;
|
|
}
|
|
|
|
$res = $this->httpGet(AlStatUrl::ZQ_CTZQ, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return [
|
|
LottType::CTZQ_BQC => Arr::get($res, 'bqc'),
|
|
LottType::CTZQ_JQC => Arr::get($res, 'jqc'),
|
|
'sfc' => Arr::get($res, 'sfc'),
|
|
];
|
|
|
|
}
|
|
|
|
// 全盘
|
|
public function getZqMainOdds($date = null)
|
|
{
|
|
$param = [];
|
|
if (!$date) {
|
|
$param['date'] = date('Ymd');
|
|
} else {
|
|
$param['date'] = $date;
|
|
}
|
|
$res = $this->httpGet(AlStatUrl::ZQ_MAIN_ODDS, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return $res['mainOdds'];
|
|
}
|
|
|
|
// 变盘
|
|
public function getZqMainOddsChange()
|
|
{
|
|
$param = [];
|
|
$res = $this->httpGet(AlStatUrl::ZQ_MAIN_ODDS_CHANGE, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
public function getZqQingBao($matchId, $date = null)
|
|
{
|
|
$param = [];
|
|
if (!$date) {
|
|
$param['date'] = date('Ymd');
|
|
}
|
|
$param['matchIds'] = $matchId;
|
|
$res = $this->httpGet(AlStatUrl::ZQ_QINGBAO, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'qingbao.0');
|
|
}
|
|
|
|
public function getZqLiveTrend($matchId)
|
|
{
|
|
$param = [];
|
|
$param['matchId'] = $matchId;
|
|
$res = $this->httpGet(AlStatUrl::ZQ_LIVE_TREND, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'matchs.0');
|
|
}
|
|
|
|
public function getZqLiveTeamStats($matchId)
|
|
{
|
|
$param = [];
|
|
$res = $this->httpGet(AlStatUrl::ZQ_LIVE_TEAM_STATS, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
$matchs = Arr::get($res, 'matchs');
|
|
if ($matchId) {
|
|
foreach ($matchs as $item) {
|
|
if ($item['id'] == $matchId) {
|
|
return $item;
|
|
}
|
|
}
|
|
return [];
|
|
}
|
|
return $matchs;
|
|
}
|
|
public function getZqLiveTimeLine($matchId) {
|
|
$param = [
|
|
'matchId' => $matchId
|
|
];
|
|
$res = $this->httpGet(AlStatUrl::ZQ_LIVE_TIME_LINE, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
public function getZqLeaqueTable($competitionId, $season)
|
|
{
|
|
$param = [];
|
|
$param['competitionId'] = $competitionId;
|
|
$param['season'] = $season;
|
|
$res = $this->httpGet(AlStatUrl::ZQ_LEAQUE_TABLE, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'leagueTables');
|
|
}
|
|
|
|
public function getZqLeaqueTableDetail($competitionId, $season)
|
|
{
|
|
$param = [];
|
|
$param['competitionId'] = $competitionId;
|
|
$param['season'] = $season;
|
|
$res = $this->httpGet(AlStatUrl::ZQ_LEAQUE_TABLE_DETAIL, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'leagueTables');
|
|
}
|
|
|
|
public function getZqSuspensions($competitionId, $teamId)
|
|
{
|
|
$param = [];
|
|
if ($competitionId) {
|
|
$param['competitionId'] = $competitionId;
|
|
}
|
|
if ($teamId) {
|
|
$param['teamId'] = $teamId;
|
|
}
|
|
$res = $this->httpGet(AlStatUrl::ZQ_SUSPENSIONS, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'suspensions');
|
|
}
|
|
|
|
public function getZqPredict($date)
|
|
{
|
|
$param = [];
|
|
$param['date'] = $date;
|
|
$res = $this->httpGet(AlStatUrl::ZQ_PREDICT, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
|
|
return Arr::get($res, 'predict');
|
|
}
|
|
|
|
public function getZqBjdcOdds()
|
|
{
|
|
$param = [];
|
|
$res = $this->httpGet(AlStatUrl::ZQ_BJDC_ODDS, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'bjdcOdds');
|
|
}
|
|
public function getZqBjdcResult()
|
|
{
|
|
$param = [];
|
|
$res = $this->httpGet(AlStatUrl::ZQ_BJDC_RESULT, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'bjdcResults');
|
|
}
|
|
|
|
public function getZqBjdcSfggOdds()
|
|
{
|
|
$param = [];
|
|
$res = $this->httpGet(AlStatUrl::ZQ_BJDC_SFGG_ODDS, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
|
|
return Arr::get($res, 'bjdcSfggOdds');
|
|
}
|
|
public function getZqBjdcSfggResult()
|
|
{
|
|
$param = [];
|
|
$res = $this->httpGet(AlStatUrl::ZQ_BJDC_SFGG_RESULT, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'bjdcSfggResults');
|
|
}
|
|
|
|
public function getZqGuan()
|
|
{
|
|
$param = [];
|
|
$res = $this->httpGet(AlStatUrl::ZQ_GUAN, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'guanOdds');
|
|
}
|
|
|
|
public function getZqGuanYa()
|
|
{
|
|
$param = [];
|
|
$res = $this->httpGet(AlStatUrl::ZQ_GUAN_YA, $param, self::TYPE_ZQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'guanyaOdds');
|
|
}
|
|
|
|
//------------------------ lq start ---------------
|
|
public function getLqCompany()
|
|
{
|
|
$res = $this->httpGet(AlStatUrl::LQ_COMPANY, [], self::TYPE_LQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'companies');
|
|
}
|
|
public function getLqCompetition()
|
|
{
|
|
$res = $this->httpGet(AlStatUrl::LQ_COMPETITION, [], self::TYPE_LQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'competitions');
|
|
}
|
|
|
|
public function getLqSeason($competitionId)
|
|
{
|
|
$param = [
|
|
'competitionId' => $competitionId
|
|
];
|
|
$res = $this->httpGet(AlStatUrl::LQ_SEASON, $param, self::TYPE_LQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'seasons');
|
|
}
|
|
public function getLqMatch($id, $type='season')
|
|
{
|
|
$param = [
|
|
'id' => $id,
|
|
'type' => $type,
|
|
];
|
|
$res = $this->httpGet(AlStatUrl::LQ_MATCH, $param, self::TYPE_LQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'matchs');
|
|
}
|
|
|
|
public function getLqMatchChange()
|
|
{
|
|
$res = $this->httpGet(AlStatUrl::LQ_MATCH_CHANGE, [], self::TYPE_LQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
|
|
return Arr::get($res, 'modifyLogs');
|
|
}
|
|
|
|
public function getLqScore()
|
|
{
|
|
$res = $this->httpGet(AlStatUrl::LQ_JCLQ_SCORE, [], self::TYPE_LQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'liveScores');
|
|
}
|
|
|
|
public function getLqOdds()
|
|
{
|
|
$res = $this->httpGet(AlStatUrl::LQ_JCLQ_ODDS, [], self::TYPE_LQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'jclqOdds');
|
|
}
|
|
|
|
public function getLqResult()
|
|
{
|
|
$res = $this->httpGet(AlStatUrl::LQ_JCLQ_RESULT, [], self::TYPE_LQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'jclqResults');
|
|
}
|
|
|
|
public function getLqMainOdds()
|
|
{
|
|
$res = $this->httpGet(AlStatUrl::LQ_MAIN_ODDS, [], self::TYPE_LQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'mainOdds');
|
|
}
|
|
public function getLqMainOddsChange()
|
|
{
|
|
$res = $this->httpGet(AlStatUrl::LQ_MAIN_ODDS_CHANGE, [], self::TYPE_LQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return Arr::get($res, 'mainOddsChange');
|
|
}
|
|
public function getLqLiveScores()
|
|
{
|
|
$res = $this->httpGet(AlStatUrl::LQ_LIVE_SCORES, [], self::TYPE_LQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
|
|
return Arr::get($res, 'liveScores');
|
|
}
|
|
public function getLqLeaqueTable($seasonId)
|
|
{
|
|
$param = [];
|
|
$param['seasonId'] = $seasonId;
|
|
$res = $this->httpGet(AlStatUrl::LQ_LEAQUE_TABLE, $param, self::TYPE_LQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return $res;
|
|
return Arr::get($res, 'liveScores');
|
|
}
|
|
|
|
public function getLqTeamStats($matchId)
|
|
{
|
|
$param = [
|
|
'matchIds' => $matchId,
|
|
];
|
|
$res = $this->httpGet(AlStatUrl::LQ_TEAM_STATS, $param, self::TYPE_LQ);
|
|
if (!$res) {
|
|
return $res;
|
|
}
|
|
return $res;
|
|
return Arr::get($res, 'liveScores');
|
|
}
|
|
|
|
|
|
protected function httpGet($url, $param, $type)
|
|
{
|
|
if (!in_array($type, [self::TYPE_LQ, self::TYPE_ZQ])) {
|
|
ThrowException::run('alstat::httpGet无效的type:' . $type);
|
|
}
|
|
$commonParam = $this->commonZqParam();
|
|
if ($type == self::TYPE_LQ) {
|
|
$commonParam = $this->commonLqParam();
|
|
}
|
|
|
|
if (!$param) {
|
|
$param = [];
|
|
}
|
|
$param = array_merge($param, $commonParam);
|
|
|
|
$urlQuery = sprintf('%s?%s', $url, http_build_query($param));
|
|
$logInfo = [
|
|
'url' => $url,
|
|
'param' => $param,
|
|
'url_query' => $urlQuery,
|
|
'stack_trace' => $this->getStackTrace()
|
|
];
|
|
try {
|
|
$rep = $this->client->request('GET', $urlQuery);
|
|
$content = $rep->getBody()->getContents();
|
|
$res = json_decode($content, true);
|
|
if (!$res) {
|
|
$logInfo['json_error'] = json_last_error_msg();
|
|
Log::error('http response json error', $logInfo);
|
|
return null;
|
|
}
|
|
$logInfo['content'] = $res;
|
|
if ($rep->getStatusCode() != 200) {
|
|
Log::error('http response code 不等于200', $logInfo);
|
|
return null;
|
|
}
|
|
if (Arr::get($res, 'state') !== 'success') {
|
|
Log::error('http response state 不等于success', $logInfo);
|
|
return null;
|
|
}
|
|
return $res;
|
|
} catch (\Exception $exception) {
|
|
$logInfo['error'] = $exception->getMessage();
|
|
Log::error('http response exception error', $logInfo);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function getStackTrace()
|
|
{
|
|
$array = debug_backtrace();
|
|
//print_r($array);//信息很齐全
|
|
unset($array[0]);
|
|
unset($array[1]);
|
|
$stack = '';
|
|
$i = 0;
|
|
foreach ($array as $row) {
|
|
$stack = str_replace(base_path(), '', $row['file']) . ':' . $row['line'] . '行,调用方法:' . $row['function'];
|
|
break;
|
|
}
|
|
return $stack;
|
|
}
|
|
}
|