61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { DEFAULT_MARKET_TYPES } from './market-catalog';
|
|
|
|
/** 第一版仅足球;字段预留其他 sportType */
|
|
export const SPORT_TYPE_FOOTBALL = 'FOOTBALL';
|
|
|
|
/** 常规赛事发布时生成的赛前盘口(手动维护,不含冠军盘) */
|
|
export const STANDARD_PREMATCH_MARKET_TYPES = DEFAULT_MARKET_TYPES;
|
|
|
|
export const HANDICAP_TOTAL_MARKET_TYPES = [
|
|
'FT_HANDICAP',
|
|
'HT_HANDICAP',
|
|
'FT_OVER_UNDER',
|
|
'HT_OVER_UNDER',
|
|
'FT_TEAM_TOTAL_HOME',
|
|
'FT_TEAM_TOTAL_AWAY',
|
|
'FT_CORNERS_HANDICAP',
|
|
'FT_CORNERS_OVER_UNDER',
|
|
'FT_CARDS_OVER_UNDER',
|
|
] as const;
|
|
|
|
export type ParlayRejectReason = 'OUTRIGHT' | 'NOT_ALLOWED' | 'QUARTER_LINE';
|
|
|
|
export function isQuarterLine(line: number | null | undefined): boolean {
|
|
if (line == null || Number.isNaN(line)) return false;
|
|
const frac = Math.abs(line % 1);
|
|
return Math.abs(frac - 0.25) < 0.001 || Math.abs(frac - 0.75) < 0.001;
|
|
}
|
|
|
|
export function isQuarterHandicapOrTotal(line: number | null | undefined): boolean {
|
|
return isQuarterLine(line);
|
|
}
|
|
|
|
export function canSelectForParlay(params: {
|
|
marketType: string;
|
|
lineValue?: number | null;
|
|
allowParlay?: boolean;
|
|
isOutright?: boolean;
|
|
}): { ok: true } | { ok: false; reason: ParlayRejectReason } {
|
|
if (params.marketType === 'OUTRIGHT_WINNER' || params.isOutright) {
|
|
return { ok: false, reason: 'OUTRIGHT' };
|
|
}
|
|
if (params.allowParlay === false) {
|
|
return { ok: false, reason: 'NOT_ALLOWED' };
|
|
}
|
|
if (
|
|
(HANDICAP_TOTAL_MARKET_TYPES as readonly string[]).includes(params.marketType) &&
|
|
isQuarterHandicapOrTotal(params.lineValue ?? null)
|
|
) {
|
|
return { ok: false, reason: 'QUARTER_LINE' };
|
|
}
|
|
return { ok: true };
|
|
}
|
|
|
|
export function isPreMatchKickoff(startTime: Date | string): boolean {
|
|
return new Date() < new Date(startTime);
|
|
}
|
|
|
|
export function isSupportedSport(sportType: string | null | undefined): boolean {
|
|
return (sportType ?? SPORT_TYPE_FOOTBALL) === SPORT_TYPE_FOOTBALL;
|
|
}
|