174 lines
6.3 KiB
TypeScript
174 lines
6.3 KiB
TypeScript
import api from './client';
|
|
import type {
|
|
PlatformFulfillmentAllocationResult,
|
|
PlatformFulfillmentDetail,
|
|
PlatformFulfillmentCollabSyncResult,
|
|
PlatformFulfillmentListResponse,
|
|
PlatformFulfillmentMapping,
|
|
PlatformFulfillmentSettings,
|
|
} from './types';
|
|
|
|
export interface PlatformFulfillmentMappingWrite {
|
|
internal_sku_key: string;
|
|
campaign_key: string;
|
|
campaign_name: string;
|
|
commodity_id: string;
|
|
goods_name?: string;
|
|
required_points?: number | null;
|
|
sale_mode: 'presale' | 'direct' | 'manual' | 'unknown';
|
|
available_from?: string | null;
|
|
available_until?: string | null;
|
|
released_at?: string | null;
|
|
enabled: boolean;
|
|
}
|
|
|
|
export const platformFulfillmentApi = {
|
|
getSettings: () =>
|
|
api.get<PlatformFulfillmentSettings, PlatformFulfillmentSettings>(
|
|
'/platform-fulfillment/settings',
|
|
),
|
|
updateSettings: (data: {
|
|
leaseDurationMinutes: number | null;
|
|
completedReleaseDelayMinutes: number | null;
|
|
manualCompletedReleaseDelayMinutes: number | null;
|
|
presaleWaitingReleaseTtlMinutes: number | null;
|
|
manualRequiredLeaseTtlMinutes: number | null;
|
|
orderMatchStartedAt: string | null;
|
|
}) =>
|
|
api.put<PlatformFulfillmentSettings, PlatformFulfillmentSettings>(
|
|
'/platform-fulfillment/settings',
|
|
{
|
|
lease_duration_minutes: data.leaseDurationMinutes,
|
|
completed_release_delay_minutes: data.completedReleaseDelayMinutes,
|
|
manual_completed_release_delay_minutes:
|
|
data.manualCompletedReleaseDelayMinutes,
|
|
presale_waiting_release_ttl_minutes:
|
|
data.presaleWaitingReleaseTtlMinutes,
|
|
manual_required_lease_ttl_minutes:
|
|
data.manualRequiredLeaseTtlMinutes,
|
|
order_match_started_at: data.orderMatchStartedAt,
|
|
},
|
|
),
|
|
listTasks: (params: {
|
|
status?: string;
|
|
queue_bucket?: string;
|
|
sale_mode?: string;
|
|
keyword?: string;
|
|
page?: number;
|
|
page_size?: number;
|
|
}) =>
|
|
api.get<PlatformFulfillmentListResponse, PlatformFulfillmentListResponse>(
|
|
'/platform-fulfillment/tasks',
|
|
{ params },
|
|
),
|
|
sync: (limit = 100) =>
|
|
api.post<{ fetched: number; created: number; updated: number }, { fetched: number; created: number; updated: number }>(
|
|
'/platform-fulfillment/sync',
|
|
null,
|
|
{ params: { limit } },
|
|
),
|
|
syncCollab: (taskIds: number[]) =>
|
|
api.post<PlatformFulfillmentCollabSyncResult, PlatformFulfillmentCollabSyncResult>(
|
|
'/platform-fulfillment/tasks/sync-collab',
|
|
{ task_ids: taskIds },
|
|
),
|
|
getTask: (taskId: number) =>
|
|
api.get<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
|
`/platform-fulfillment/tasks/${taskId}`,
|
|
),
|
|
listMappings: (params: {
|
|
keyword?: string;
|
|
sale_mode?: string;
|
|
enabled?: boolean;
|
|
include_archived?: boolean;
|
|
} = {}) =>
|
|
api.get<PlatformFulfillmentMapping[], PlatformFulfillmentMapping[]>(
|
|
'/platform-fulfillment/mappings',
|
|
{ params },
|
|
),
|
|
createMapping: (data: PlatformFulfillmentMappingWrite) =>
|
|
api.post<PlatformFulfillmentMapping, PlatformFulfillmentMapping>(
|
|
'/platform-fulfillment/mappings',
|
|
data,
|
|
),
|
|
updateMapping: (mappingId: number, data: PlatformFulfillmentMappingWrite) =>
|
|
api.patch<PlatformFulfillmentMapping, PlatformFulfillmentMapping>(
|
|
`/platform-fulfillment/mappings/${mappingId}`,
|
|
data,
|
|
),
|
|
deleteMapping: (mappingId: number) =>
|
|
api.delete<{ success: boolean }, { success: boolean }>(
|
|
`/platform-fulfillment/mappings/${mappingId}`,
|
|
),
|
|
mappingAction: (mappingId: number, action: 'enable' | 'disable' | 'archive' | 'restore') =>
|
|
api.post<PlatformFulfillmentMapping, PlatformFulfillmentMapping>(
|
|
`/platform-fulfillment/mappings/${mappingId}/${action}`,
|
|
),
|
|
mappingImpact: (mappingId: number) =>
|
|
api.get<{
|
|
mappingId: number;
|
|
internalSkuKey: string;
|
|
affectedTasks: number;
|
|
groups: Array<{ executionStatus: string; saleMode: string; count: number }>;
|
|
}, {
|
|
mappingId: number;
|
|
internalSkuKey: string;
|
|
affectedTasks: number;
|
|
groups: Array<{ executionStatus: string; saleMode: string; count: number }>;
|
|
}>(`/platform-fulfillment/mappings/${mappingId}/impact`),
|
|
allocate: (taskId: number) =>
|
|
api.post<PlatformFulfillmentAllocationResult, PlatformFulfillmentAllocationResult>(
|
|
`/platform-fulfillment/tasks/${taskId}/allocate`,
|
|
),
|
|
startBinding: (taskId: number) =>
|
|
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
|
`/platform-fulfillment/tasks/${taskId}/bind/start`,
|
|
),
|
|
refreshBinding: (taskId: number) =>
|
|
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
|
`/platform-fulfillment/tasks/${taskId}/bind/refresh`,
|
|
),
|
|
resetBinding: (taskId: number, reason = '客服重置角色绑定') =>
|
|
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
|
`/platform-fulfillment/tasks/${taskId}/bind/reset`,
|
|
{ reason },
|
|
),
|
|
confirmBinding: (taskId: number) =>
|
|
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
|
`/platform-fulfillment/tasks/${taskId}/bind/confirm`,
|
|
),
|
|
refreshEligibility: (taskId: number) =>
|
|
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
|
`/platform-fulfillment/tasks/${taskId}/eligibility/refresh`,
|
|
),
|
|
complete: (taskId: number, note = '') =>
|
|
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
|
`/platform-fulfillment/tasks/${taskId}/complete`,
|
|
{ note },
|
|
),
|
|
release: (taskId: number) =>
|
|
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
|
`/platform-fulfillment/tasks/${taskId}/release`,
|
|
),
|
|
releaseToManual: (taskId: number, reason: string) =>
|
|
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
|
`/platform-fulfillment/tasks/${taskId}/release-manual`,
|
|
{ reason },
|
|
),
|
|
markManual: (taskId: number, reason = '') =>
|
|
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
|
`/platform-fulfillment/tasks/${taskId}/manual`,
|
|
{ reason },
|
|
),
|
|
cancel: (taskId: number, reason = '') =>
|
|
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
|
`/platform-fulfillment/tasks/${taskId}/cancel`,
|
|
{ reason },
|
|
),
|
|
restore: (taskId: number, reason: string) =>
|
|
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
|
`/platform-fulfillment/tasks/${taskId}/restore`,
|
|
{ reason },
|
|
),
|
|
};
|