更新多个 API 文件,将 API_V1_PREFIX 替换为直接使用 /admin 路径。 简化 API 路径定义逻辑,提升代码可读性与维护性。 统一后台管理接口的路由配置,确保各管理端 API 端点保持一致性。
111 lines
3.6 KiB
TypeScript
111 lines
3.6 KiB
TypeScript
import { adminRequest } from "@/lib/admin-http";
|
|
|
|
|
|
import type { AdminDrawFinanceSummaryData } from "@/types/api/admin-draw-finance";
|
|
import type {
|
|
AdminDrawBatchesData,
|
|
AdminDrawActionResponse,
|
|
AdminDrawListData,
|
|
AdminDrawBatchCreateResponse,
|
|
AdminDrawManualBatchPayload,
|
|
AdminDrawPublishResponse,
|
|
AdminDrawPlanGenerateResponse,
|
|
AdminDrawShowData,
|
|
AdminDrawCreatePayload,
|
|
AdminDrawCreateResponse,
|
|
} from "@/types/api/admin-draws";
|
|
|
|
const A = `/admin`;
|
|
|
|
export type AdminDrawListQuery = {
|
|
page?: number;
|
|
per_page?: number;
|
|
draw_no?: string;
|
|
status?: string;
|
|
};
|
|
|
|
export async function getAdminDraws(q: AdminDrawListQuery = {}): Promise<AdminDrawListData> {
|
|
return adminRequest.get<AdminDrawListData>(`${A}/draws`, { params: q });
|
|
}
|
|
|
|
export async function getAdminDraw(drawId: number): Promise<AdminDrawShowData> {
|
|
return adminRequest.get<AdminDrawShowData>(`${A}/draws/${drawId}`);
|
|
}
|
|
|
|
export async function getAdminDrawResultBatches(drawId: number): Promise<AdminDrawBatchesData> {
|
|
return adminRequest.get<AdminDrawBatchesData>(`${A}/draws/${drawId}/result-batches`);
|
|
}
|
|
|
|
export async function getAdminDrawFinanceSummary(
|
|
drawId: number,
|
|
): Promise<AdminDrawFinanceSummaryData> {
|
|
return adminRequest.get<AdminDrawFinanceSummaryData>(
|
|
`${A}/draws/${drawId}/finance-summary`,
|
|
);
|
|
}
|
|
|
|
export async function postAdminPublishResultBatch(
|
|
drawId: number,
|
|
batchId: number,
|
|
): Promise<AdminDrawPublishResponse> {
|
|
return adminRequest.post<AdminDrawPublishResponse>(
|
|
`${A}/draws/${drawId}/result-batches/${batchId}/publish`,
|
|
);
|
|
}
|
|
|
|
export async function postAdminGenerateDrawPlan(): Promise<AdminDrawPlanGenerateResponse> {
|
|
return adminRequest.post<AdminDrawPlanGenerateResponse>(`${A}/draws/generate-plan`);
|
|
}
|
|
|
|
export async function postAdminCreateDraw(
|
|
payload: AdminDrawCreatePayload,
|
|
): Promise<AdminDrawCreateResponse> {
|
|
return adminRequest.post<AdminDrawCreateResponse>(`${A}/draws`, payload);
|
|
}
|
|
|
|
export async function putAdminUpdateDraw(
|
|
drawId: number,
|
|
payload: AdminDrawCreatePayload,
|
|
): Promise<AdminDrawCreateResponse> {
|
|
return adminRequest.put<AdminDrawCreateResponse>(`${A}/draws/${drawId}`, payload);
|
|
}
|
|
|
|
export async function deleteAdminDraw(drawId: number): Promise<{ deleted: boolean }> {
|
|
return adminRequest.delete<{ deleted: boolean }>(`${A}/draws/${drawId}`);
|
|
}
|
|
|
|
export async function postAdminBatchDestroyDraws(
|
|
drawIds: number[],
|
|
): Promise<{ success: number[]; failed: Array<{ id: number; reason: string }> }> {
|
|
return adminRequest.post<{ success: number[]; failed: Array<{ id: number; reason: string }> }>(
|
|
`${A}/draws/batch-destroy`,
|
|
{ draw_ids: drawIds },
|
|
);
|
|
}
|
|
|
|
export async function postAdminManualCloseDraw(drawId: number): Promise<AdminDrawActionResponse> {
|
|
return adminRequest.post<AdminDrawActionResponse>(`${A}/draws/${drawId}/manual-close`);
|
|
}
|
|
|
|
export async function postAdminCancelDraw(drawId: number): Promise<AdminDrawActionResponse> {
|
|
return adminRequest.post<AdminDrawActionResponse>(`${A}/draws/${drawId}/cancel`);
|
|
}
|
|
|
|
export async function postAdminRunDrawRng(drawId: number): Promise<AdminDrawBatchCreateResponse> {
|
|
return adminRequest.post<AdminDrawBatchCreateResponse>(`${A}/draws/${drawId}/rng`);
|
|
}
|
|
|
|
export async function postAdminCreateManualResultBatch(
|
|
drawId: number,
|
|
payload: AdminDrawManualBatchPayload,
|
|
): Promise<AdminDrawBatchCreateResponse> {
|
|
return adminRequest.post<AdminDrawBatchCreateResponse>(
|
|
`${A}/draws/${drawId}/result-batches`,
|
|
payload,
|
|
);
|
|
}
|
|
|
|
export async function postAdminReopenDraw(drawId: number): Promise<AdminDrawActionResponse> {
|
|
return adminRequest.post<AdminDrawActionResponse>(`${A}/draws/${drawId}/reopen`);
|
|
}
|