import api from './client'; export type DouyuCollabStatus = | 'incomplete' | 'to_recharge' | 'recharged' | 'scripted' | 'done' | 'points_error' | 'failed' | 'void'; export interface DouyuCollabGoods { commodity_id: string; name: string; score: number | null; status: string; open_status: number | null; start_time: number | null; end_time: number | null; mark: string; count: number | null; elite_limited: number | null; is_limited: boolean; raw?: Record; } export interface DouyuCollabOrder { id: number; order_no: string; shop: string; owner_id: number | null; owner_name: string; source_type: string; source_task_id: number | null; source_order_id: string; source_order_item_id: string; source_platform_order_id: string; last_synced_at: string | null; account_id: number | null; account_username: string; account_uid: string; account_nickname: string; account_exists: boolean; has_cookie: boolean; account_ck_status: string; account_status: string; bind_game_account: string; bind_game_role: string; bind_game_channel: string; bind_snapshot_at: string | null; home_images: string[]; home_image_urls: string[]; home_image_thumb_urls: string[]; gift_name: string; commodity_id: string; required_points: number | null; remark: string; status: DouyuCollabStatus; status_label: string; next_status: DouyuCollabStatus | null; missing_fields: string[]; fish_fin_balance: number | null; points_balance: number | null; points_required_total: number | null; points_surplus: number | null; points_threshold: number | null; points_checked_at: string | null; points_check_reason: string; points_check_message: string; points_check_detail: Record | null; recharged_at: string | null; scripted_at: string | null; done_at: string | null; void_reason: string; is_archived: boolean; archived_at: string | null; archived_by: number | null; archived_by_name: string; archive_reason: string; created_by: number | null; created_by_name: string; updated_by: number | null; updated_by_name: string; version: number; created_at: string | null; updated_at: string | null; account_cluster: { total: number; orders: Array<{ id: number; order_no: string; status: DouyuCollabStatus; status_label: string; gift_name: string; }>; } | null; last_metric_at: string | null; last_metric_message: string; last_verdict: string; last_verdict_label: string; last_records_total: number; last_records_matched: number; } export interface DouyuCollabOrderList { items: DouyuCollabOrder[]; total: number; page: number; page_size: number; } export interface DouyuCollabCkExportItem { id: number; order_no: string; account_id: number | null; account_username: string; account_password: string; account_nickname: string; status: DouyuCollabStatus; status_label: string; ck_status: string; ck_status_label: string; ck_text: string; } export interface DouyuCollabCkExportSkipped { id: number; order_no: string; reason: string; } export interface DouyuCollabCkExportResult { total: number; exported: number; skipped: DouyuCollabCkExportSkipped[]; items: DouyuCollabCkExportItem[]; } export interface DouyuCollabUsernameExportItem { id: number; order_no: string; account_username: string; } export interface DouyuCollabUsernameExportSkipped { id: number; order_no: string; reason: string; } export interface DouyuCollabUsernameExportResult { total: number; exported: number; unique: number; skipped: DouyuCollabUsernameExportSkipped[]; items: DouyuCollabUsernameExportItem[]; usernames: string[]; } export interface DouyuCollabSummary { total: number; by_status: Record; account_missing: number; ck_invalid: number; archived_total: number; } export interface DouyuCollabOwner { id: number; username: string; } export interface DouyuCollabShop { id: number; name: string; sort_order: number; is_active: boolean; remark: string; } export interface DouyuCollabGift { id: number; name: string; points: number; sort_order: number; is_active: boolean; remark: string; } export interface DouyuCollabAccountLookup { found: boolean; ok: boolean; message: string; errors: string[]; account_id: number | null; account_username: string; account_uid: string; account_nickname: string; ck_status: string; ck_status_label: string; manual_type: number | null; manual_score: number | null; expire_time: number | null; manual_opened: boolean; bind_game_account: string; bind_game_role: string; bind_game_channel: string; fish_fin_balance: number | null; goods: DouyuCollabGoods[]; goods_count: number; orders_using_account: Array<{ id: number; order_no: string; status: DouyuCollabStatus; }>; } export interface DouyuCollabOrderCreate { order_no: string; shop?: string; owner_id?: number | null; account_username?: string; gift_name?: string; commodity_id?: string; required_points?: number | null; home_images?: string[]; remark?: string; draft?: boolean; require_verified?: boolean; } export interface DouyuCollabOrderUpdate { order_no?: string; shop?: string; owner_id?: number | null; account_username?: string; gift_name?: string; commodity_id?: string; required_points?: number | null; home_images?: string[]; remark?: string; expected_version?: number; } export interface DouyuCollabMetric { id: number; order_id: number; order_no: string; account_username: string; fish_fin_balance: number | null; points_balance: number | null; points_required_total: number | null; points_surplus: number | null; records_total: number; records_matched: number; verdict: string; verdict_label: string; message: string; source: string; created_at: string | null; } export interface DouyuCollabTimeline { id: number; action: string; username: string; detail: string; success: boolean | null; created_at: string | null; } export interface DouyuCollabQueryResult { order: DouyuCollabOrder; metric: DouyuCollabMetric; scope: 'activity' | 'balances'; verdict: string; message: string; points_reason: string; fish_fin_balance: number | null; points_balance: number | null; required_total: number | null; surplus: number | null; errors: string[]; } export const douyuCollabApi = { listOrders: (params: { page?: number; page_size?: number; include_void?: boolean; archive_scope?: 'active' | 'archived' | 'all'; status?: string; shop?: string; owner_id?: number; gift_name?: string; keyword?: string; ck_status?: string; } = {}) => api.get('/douyu/external-orders', { params }), summary: (params: { include_void?: boolean; archive_scope?: 'active' | 'archived' | 'all' } = {}) => api.get('/douyu/external-orders/summary', { params }), owners: () => api.get('/douyu/external-orders/owners'), shops: () => api.get('/douyu/external-orders/shops'), shopRecords: () => api.get('/douyu/collab-shops'), createShop: (data: { name: string; remark?: string }) => api.post('/douyu/collab-shops', data), updateShop: ( id: number, data: { name?: string; sort_order?: number; is_active?: boolean; remark?: string }, ) => api.put(`/douyu/collab-shops/${id}`, data), deleteShop: (id: number) => api.delete<{ success: boolean; name: string; id: number }, { success: boolean; name: string; id: number }>( `/douyu/collab-shops/${id}`, ), giftRecords: () => api.get('/douyu/collab-gifts'), createGift: (data: { name: string; points: number; remark?: string }) => api.post('/douyu/collab-gifts', data), updateGift: ( id: number, data: { name?: string; points?: number; sort_order?: number; is_active?: boolean; remark?: string; }, ) => api.put(`/douyu/collab-gifts/${id}`, data), deleteGift: (id: number) => api.delete<{ success: boolean; name: string; id: number }, { success: boolean; name: string; id: number }>( `/douyu/collab-gifts/${id}`, ), gifts: () => api.get('/douyu/external-orders/gifts'), goods: () => api.get('/douyu/external-orders/goods'), refreshGoods: (accountId?: number) => api.post<{ count: number; goods: DouyuCollabGoods[] }, { count: number; goods: DouyuCollabGoods[] }>( '/douyu/external-orders/goods/refresh', undefined, { params: accountId ? { account_id: accountId } : undefined }, ), lookupAccount: (username: string, withGoods = true) => api.post( '/douyu/external-orders/accounts/lookup', { username, with_goods: withGoods }, ), createOrder: (data: DouyuCollabOrderCreate) => api.post('/douyu/external-orders', data), exportOrderCk: (ids: number[]) => api.post( '/douyu/external-orders/ck/export', { ids }, ), /** 单行复制 CK(仅超级管理员;后端再次校验角色) */ copyOrderCk: (id: number) => api.post( `/douyu/external-orders/${id}/ck/copy`, ), exportUsernames: (ids: number[]) => api.post( '/douyu/external-orders/usernames/export', { ids }, ), getOrder: (id: number) => api.get(`/douyu/external-orders/${id}`), updateOrder: (id: number, data: DouyuCollabOrderUpdate) => api.put(`/douyu/external-orders/${id}`, data), setAccount: (id: number, account_username: string, expected_version?: number) => api.post(`/douyu/external-orders/${id}/account`, { account_username, expected_version, }), verifyOrder: (id: number) => api.post<{ order: DouyuCollabOrder; probe: DouyuCollabAccountLookup }, { order: DouyuCollabOrder; probe: DouyuCollabAccountLookup }>( `/douyu/external-orders/${id}/verify`, ), batchVerify: (ids: number[]) => api.post< { results: Array<{ id: number; success: boolean; ck_status?: string; role?: string; message?: string }>; success: boolean }, { results: Array<{ id: number; success: boolean; ck_status?: string; role?: string; message?: string }>; success: boolean } >('/douyu/external-orders/verify/batch', ids), queryActivity: (id: number) => api.post( `/douyu/external-orders/${id}/activity/query`, ), /** 只刷新鱼翅与手册积分,不查兑换记录、不判定、不改状态 */ queryBalances: (id: number) => api.post( `/douyu/external-orders/${id}/balances/query`, ), setStatus: (id: number, data: { status: DouyuCollabStatus; reason?: string; rollback?: boolean; expected_version?: number; }) => api.post(`/douyu/external-orders/${id}/status`, data), batchStatus: (data: { ids: number[]; status: DouyuCollabStatus; reason?: string; rollback?: boolean; }) => api.post<{ results: Array<{ id: number; success: boolean; message?: string }>; success: boolean }, { results: Array<{ id: number; success: boolean; message?: string }>; success: boolean }>( '/douyu/external-orders/status/batch', data, ), batchActivity: (ids: number[]) => api.post<{ results: Array>; success: boolean }, { results: Array>; success: boolean }>( '/douyu/external-orders/activity/query', ids, ), /** 批量只刷新鱼翅/积分,不查兑换记录、不判定、不改状态 */ batchBalances: (ids: number[]) => api.post<{ results: Array>; success: boolean }, { results: Array>; success: boolean }>( '/douyu/external-orders/balances/query', ids, ), updateImages: (id: number, home_images: string[], expected_version?: number) => api.post(`/douyu/external-orders/${id}/images`, { home_images, expected_version, }), archive: (ids: number[], reason = '') => api.post<{ archived: number }, { archived: number }>('/douyu/external-orders/archive', { ids, reason }), unarchive: (ids: number[]) => api.post<{ unarchived: number }, { unarchived: number }>('/douyu/external-orders/unarchive', ids), timeline: (id: number) => api.get(`/douyu/external-orders/${id}/timeline`), metrics: (id: number) => api.get(`/douyu/external-orders/${id}/metrics`), deleteOrder: (id: number) => api.delete<{ success: boolean; order_no: string }, { success: boolean; order_no: string }>( `/douyu/external-orders/${id}`, ), };