添加赔率
This commit is contained in:
@@ -18,7 +18,7 @@ use app\common\service\match\MatchLiveService;
|
||||
|
||||
class MatchController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = ['lists', 'detail', 'leagues', 'sportTypes', 'liveText', 'lineup', 'worldCupStandings', 'worldCupRankings', 'worldCupSchedule', 'worldCupLiveCards', 'worldCupOdds'];
|
||||
public array $notNeedLogin = ['lists', 'detail', 'leagues', 'sportTypes', 'liveText', 'lineup', 'liveCards', 'odds', 'worldCupStandings', 'worldCupRankings', 'worldCupSchedule', 'worldCupLiveCards', 'worldCupOdds'];
|
||||
|
||||
protected int $worldCupSeasonId = 26123;
|
||||
protected string $worldCupLeagueName = '世界杯';
|
||||
@@ -513,16 +513,71 @@ class MatchController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
public function liveCards()
|
||||
{
|
||||
$sportType = $this->request->get('sport_type/d', 0);
|
||||
$leagueName = trim($this->request->get('league_name/s', ''));
|
||||
|
||||
return $this->data([
|
||||
'list' => MatchLiveService::getLiveCards($sportType, $leagueName),
|
||||
]);
|
||||
}
|
||||
|
||||
public function odds()
|
||||
{
|
||||
return $this->data([
|
||||
'list' => $this->getOddsList(
|
||||
$this->request->get('show_type/s', ''),
|
||||
strtolower(trim($this->request->get('source_site/s', ''))),
|
||||
trim($this->request->get('keyword/s', '')),
|
||||
$this->request->get('include_special/d', 0),
|
||||
min(max($this->request->get('limit/d', 120), 1), 300),
|
||||
$this->request->get('sport_type/d', 0),
|
||||
trim($this->request->get('league_name/s', ''))
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
public function worldCupOdds()
|
||||
{
|
||||
$showType = $this->request->get('show_type/s', '');
|
||||
$sourceSite = strtolower(trim($this->request->get('source_site/s', '')));
|
||||
$keyword = trim($this->request->get('keyword/s', ''));
|
||||
$includeSpecial = $this->request->get('include_special/d', 0);
|
||||
$limit = min(max($this->request->get('limit/d', 120), 1), 300);
|
||||
return $this->data([
|
||||
'season_id' => $this->worldCupSeasonId,
|
||||
'list' => $this->getOddsList(
|
||||
$this->request->get('show_type/s', ''),
|
||||
strtolower(trim($this->request->get('source_site/s', ''))),
|
||||
trim($this->request->get('keyword/s', '')),
|
||||
$this->request->get('include_special/d', 0),
|
||||
min(max($this->request->get('limit/d', 120), 1), 300),
|
||||
1,
|
||||
'',
|
||||
true
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
private function getOddsList(
|
||||
string $showType,
|
||||
string $sourceSite,
|
||||
string $keyword,
|
||||
int $includeSpecial,
|
||||
int $limit,
|
||||
int $sportType = 0,
|
||||
string $leagueName = '',
|
||||
bool $worldCupEventOnly = false
|
||||
): array {
|
||||
$validShowTypes = ['live', 'today', 'early'];
|
||||
|
||||
$query = MatchOdds::where('sport_type', 'FT');
|
||||
$query = MatchOdds::where([]);
|
||||
if ($sportType > 0) {
|
||||
$oddsSportType = $this->resolveOddsSportType($sportType);
|
||||
if ($oddsSportType === '') {
|
||||
return [];
|
||||
}
|
||||
$query->where('sport_type', $oddsSportType);
|
||||
}
|
||||
if ($leagueName !== '') {
|
||||
$query->where('league_name', $leagueName);
|
||||
}
|
||||
if (!$includeSpecial) {
|
||||
$query->where('league_name', 'not like', '%特定球员%');
|
||||
}
|
||||
@@ -553,7 +608,7 @@ class MatchController extends BaseApiController
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$eventMap = $this->buildWorldCupEventMap();
|
||||
$eventMap = $this->buildOddsEventMap($sportType, $leagueName, $worldCupEventOnly);
|
||||
$matches = [];
|
||||
foreach ($rows as $row) {
|
||||
$platform = $this->formatOddsPlatform($row);
|
||||
@@ -604,17 +659,30 @@ class MatchController extends BaseApiController
|
||||
return (int)$right['update_time'] <=> (int)$left['update_time'];
|
||||
});
|
||||
|
||||
return $this->data([
|
||||
'season_id' => $this->worldCupSeasonId,
|
||||
'list' => $list,
|
||||
]);
|
||||
return $list;
|
||||
}
|
||||
|
||||
private function buildWorldCupEventMap(): array
|
||||
private function buildOddsEventMap(
|
||||
int $sportType = 0,
|
||||
string $leagueName = '',
|
||||
bool $worldCupOnly = false
|
||||
): array
|
||||
{
|
||||
$rows = MatchEvent::where('league_name', $this->worldCupLeagueName)
|
||||
->where('sport_type', 1)
|
||||
->where('is_show', 1)
|
||||
$query = MatchEvent::where('is_show', 1);
|
||||
if ($sportType > 0) {
|
||||
$query->where('sport_type', $sportType);
|
||||
}
|
||||
if ($leagueName !== '') {
|
||||
$query->where('league_name', $leagueName);
|
||||
}
|
||||
if ($worldCupOnly) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('league_name', $this->worldCupLeagueName)
|
||||
->whereOr('competition_id', 61);
|
||||
});
|
||||
}
|
||||
|
||||
$rows = $query
|
||||
->field('id,match_id,home_team,home_icon,home_score,away_team,away_icon,away_score,status,match_time,current_minute')
|
||||
->select()
|
||||
->toArray();
|
||||
@@ -629,15 +697,41 @@ class MatchController extends BaseApiController
|
||||
return $map;
|
||||
}
|
||||
|
||||
private function resolveOddsSportType(int $sportType): string
|
||||
{
|
||||
$map = [
|
||||
1 => 'FT',
|
||||
];
|
||||
return $map[$sportType] ?? '';
|
||||
}
|
||||
|
||||
private function buildOddsMatchKey(array $row): string
|
||||
{
|
||||
$teamPairKey = $this->buildTeamPairKey(
|
||||
$row['home_team'] ?? '',
|
||||
$row['away_team'] ?? ''
|
||||
);
|
||||
$dateKey = $this->buildOddsMatchDateKey(
|
||||
(string)($row['match_time_text'] ?? '')
|
||||
);
|
||||
if ($teamPairKey !== '') {
|
||||
return $teamPairKey . '|' . $dateKey;
|
||||
}
|
||||
return implode('|', [
|
||||
trim((string)($row['league_name'] ?? '')),
|
||||
trim((string)($row['match_time_text'] ?? '')),
|
||||
$this->buildTeamPairKey($row['home_team'] ?? '', $row['away_team'] ?? ''),
|
||||
(string)($row['source_match_id'] ?? ''),
|
||||
]);
|
||||
}
|
||||
|
||||
private function buildOddsMatchDateKey(string $matchTimeText): string
|
||||
{
|
||||
if (preg_match('/(?:\d{4}[-\/])?(\d{1,2})[-\/](\d{1,2})/', $matchTimeText, $matches)) {
|
||||
return sprintf('%02d-%02d', (int)$matches[1], (int)$matches[2]);
|
||||
}
|
||||
return trim($matchTimeText);
|
||||
}
|
||||
|
||||
private function buildTeamPairKey(string $homeTeam, string $awayTeam): string
|
||||
{
|
||||
$homeTeam = preg_replace('/\s+/u', '', trim($homeTeam));
|
||||
@@ -703,6 +797,7 @@ class MatchController extends BaseApiController
|
||||
{
|
||||
$map = [
|
||||
'hg' => '滚球',
|
||||
'titan007' => '球探',
|
||||
];
|
||||
return $map[$sourceSite] ?? ($sourceSite !== '' ? strtoupper($sourceSite) : '平台');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user