deploy: auto commit repo-root changes 2026-07-14 09:42:08
This commit is contained in:
@@ -96,7 +96,7 @@ class MatchController extends BaseApiController
|
||||
$endedPageSize = $this->request->get('ended_page_size/d', 20);
|
||||
$endedOnly = $this->request->get('ended_only/d', 0);
|
||||
|
||||
$field = 'id,league_name,league_icon,home_team,home_icon,home_score,away_team,away_icon,away_score,sport_type,status,match_time,current_minute,half_score,home_odds,draw_odds,away_odds,home_corner,away_corner,home_yellow,away_yellow,home_red,away_red,is_hot,round_name';
|
||||
$field = 'id,competition_id,league_name,league_icon,home_team,home_icon,home_score,away_team,away_icon,away_score,sport_type,status,match_time,current_minute,half_score,home_odds,draw_odds,away_odds,home_corner,away_corner,home_yellow,away_yellow,home_red,away_red,is_hot,round_name';
|
||||
|
||||
// 基础筛选
|
||||
$baseWhere = [['is_show', '=', 1]];
|
||||
@@ -121,6 +121,7 @@ class MatchController extends BaseApiController
|
||||
|
||||
// 加载更多时只返回已结束数据
|
||||
if ($endedOnly) {
|
||||
$ended = $this->attachMoneylineOdds($ended);
|
||||
return $this->data([
|
||||
'ended' => [
|
||||
'lists' => $ended,
|
||||
@@ -139,6 +140,13 @@ class MatchController extends BaseApiController
|
||||
$upcoming = MatchEvent::where($baseWhere)->where('status', 0)
|
||||
->field($field)->order('match_time asc')->limit(20)->select()->toArray();
|
||||
|
||||
$liveCount = count($live);
|
||||
$upcomingCount = count($upcoming);
|
||||
$matches = $this->attachMoneylineOdds(array_merge($live, $upcoming, $ended));
|
||||
$live = array_slice($matches, 0, $liveCount);
|
||||
$upcoming = array_slice($matches, $liveCount, $upcomingCount);
|
||||
$ended = array_slice($matches, $liveCount + $upcomingCount);
|
||||
|
||||
return $this->data([
|
||||
'live' => $live,
|
||||
'upcoming' => $upcoming,
|
||||
@@ -151,6 +159,106 @@ class MatchController extends BaseApiController
|
||||
]);
|
||||
}
|
||||
|
||||
private function attachMoneylineOdds(array $matches): array
|
||||
{
|
||||
if (empty($matches)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$homeTeams = [];
|
||||
$awayTeams = [];
|
||||
$matchKeys = [];
|
||||
foreach ($matches as $index => &$match) {
|
||||
$match['home_odds'] = $this->normalizeMoneylineOdds($match['home_odds'] ?? '');
|
||||
$match['draw_odds'] = $this->normalizeMoneylineOdds($match['draw_odds'] ?? '');
|
||||
$match['away_odds'] = $this->normalizeMoneylineOdds($match['away_odds'] ?? '');
|
||||
|
||||
if ((int)($match['sport_type'] ?? 0) !== 1) {
|
||||
continue;
|
||||
}
|
||||
$key = $this->buildEventOddsMatchKey($match);
|
||||
if ($key === '') {
|
||||
continue;
|
||||
}
|
||||
$matchKeys[$index] = $key;
|
||||
$homeTeams[] = trim((string)($match['home_team'] ?? ''));
|
||||
$awayTeams[] = trim((string)($match['away_team'] ?? ''));
|
||||
}
|
||||
unset($match);
|
||||
|
||||
$homeTeams = array_values(array_unique(array_filter($homeTeams)));
|
||||
$awayTeams = array_values(array_unique(array_filter($awayTeams)));
|
||||
if (empty($matchKeys) || empty($homeTeams) || empty($awayTeams)) {
|
||||
return $matches;
|
||||
}
|
||||
|
||||
$rows = MatchOdds::where('sport_type', 'FT')
|
||||
->whereIn('home_team', $homeTeams)
|
||||
->whereIn('away_team', $awayTeams)
|
||||
->where(function ($query) {
|
||||
$query->where('home_win_odds', '<>', '')
|
||||
->whereOr('draw_odds', '<>', '')
|
||||
->whereOr('away_win_odds', '<>', '');
|
||||
})
|
||||
->field('home_team,away_team,match_time_text,home_win_odds,draw_odds,away_win_odds,update_time')
|
||||
->order('update_time desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$oddsMap = [];
|
||||
$scoreMap = [];
|
||||
foreach ($rows as $row) {
|
||||
$key = $this->buildOddsMatchKey($row);
|
||||
if (!in_array($key, $matchKeys, true)) {
|
||||
continue;
|
||||
}
|
||||
$odds = [
|
||||
'home_odds' => $this->normalizeMoneylineOdds($row['home_win_odds'] ?? ''),
|
||||
'draw_odds' => $this->normalizeMoneylineOdds($row['draw_odds'] ?? ''),
|
||||
'away_odds' => $this->normalizeMoneylineOdds($row['away_win_odds'] ?? ''),
|
||||
];
|
||||
$score = count(array_filter($odds, static fn($value) => $value !== ''));
|
||||
if ($score === 0 || $score <= ($scoreMap[$key] ?? -1)) {
|
||||
continue;
|
||||
}
|
||||
$oddsMap[$key] = $odds;
|
||||
$scoreMap[$key] = $score;
|
||||
}
|
||||
|
||||
foreach ($matchKeys as $index => $key) {
|
||||
if (!isset($oddsMap[$key])) {
|
||||
continue;
|
||||
}
|
||||
$matches[$index] = array_merge($matches[$index], $oddsMap[$key]);
|
||||
}
|
||||
return $matches;
|
||||
}
|
||||
|
||||
private function buildEventOddsMatchKey(array $match): string
|
||||
{
|
||||
$teamPairKey = $this->buildTeamPairKey(
|
||||
(string)($match['home_team'] ?? ''),
|
||||
(string)($match['away_team'] ?? '')
|
||||
);
|
||||
$timestamp = (int)($match['match_time'] ?? 0);
|
||||
if ($teamPairKey === '' || $timestamp <= 0) {
|
||||
return '';
|
||||
}
|
||||
if ($this->isWorldCupMatch($match)) {
|
||||
$timestamp += 8 * 60 * 60;
|
||||
}
|
||||
return $teamPairKey . '|' . date('m-d', $timestamp);
|
||||
}
|
||||
|
||||
private function normalizeMoneylineOdds($value): string
|
||||
{
|
||||
$value = trim((string)$value);
|
||||
if ($value === '' || !is_numeric($value) || (float)$value <= 0) {
|
||||
return '';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function detail()
|
||||
{
|
||||
$id = $this->request->get('id/d');
|
||||
|
||||
Reference in New Issue
Block a user