feat: 斗鱼外部单协作台账与店铺实时同步

This commit is contained in:
yml2213
2026-10-20 20:11:35 +08:00
parent c778ae9a09
commit 71574908ff
18 changed files with 6187 additions and 4 deletions
+326
View File
@@ -0,0 +1,326 @@
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<string, unknown>;
}
export interface DouyuCollabOrder {
id: number;
order_no: string;
shop: string;
owner_id: number | null;
owner_name: string;
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<string, unknown> | 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 DouyuCollabSummary {
total: number;
by_status: Record<string, number>;
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 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;
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<DouyuCollabOrderList, DouyuCollabOrderList>('/douyu/external-orders', { params }),
summary: (params: { include_void?: boolean; archive_scope?: 'active' | 'archived' | 'all' } = {}) =>
api.get<DouyuCollabSummary, DouyuCollabSummary>('/douyu/external-orders/summary', { params }),
owners: () => api.get<DouyuCollabOwner[], DouyuCollabOwner[]>('/douyu/external-orders/owners'),
shops: () => api.get<string[], string[]>('/douyu/external-orders/shops'),
shopRecords: () => api.get<DouyuCollabShop[], DouyuCollabShop[]>('/douyu/collab-shops'),
createShop: (data: { name: string; remark?: string }) =>
api.post<DouyuCollabShop, DouyuCollabShop>('/douyu/collab-shops', data),
updateShop: (
id: number,
data: { name?: string; sort_order?: number; is_active?: boolean; remark?: string },
) => api.put<DouyuCollabShop, DouyuCollabShop>(`/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}`,
),
gifts: () => api.get<string[], string[]>('/douyu/external-orders/gifts'),
goods: () => api.get<DouyuCollabGoods[], DouyuCollabGoods[]>('/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<DouyuCollabAccountLookup, DouyuCollabAccountLookup>(
'/douyu/external-orders/accounts/lookup',
{ username, with_goods: withGoods },
),
createOrder: (data: DouyuCollabOrderCreate) =>
api.post<DouyuCollabOrder, DouyuCollabOrder>('/douyu/external-orders', data),
getOrder: (id: number) =>
api.get<DouyuCollabOrder, DouyuCollabOrder>(`/douyu/external-orders/${id}`),
updateOrder: (id: number, data: DouyuCollabOrderUpdate) =>
api.put<DouyuCollabOrder, DouyuCollabOrder>(`/douyu/external-orders/${id}`, data),
setAccount: (id: number, account_username: string, expected_version?: number) =>
api.post<DouyuCollabOrder, DouyuCollabOrder>(`/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<DouyuCollabQueryResult, DouyuCollabQueryResult>(
`/douyu/external-orders/${id}/activity/query`,
),
setStatus: (id: number, data: {
status: DouyuCollabStatus;
reason?: string;
rollback?: boolean;
expected_version?: number;
}) => api.post<DouyuCollabOrder, DouyuCollabOrder>(`/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<Record<string, unknown>>; success: boolean }, { results: Array<Record<string, unknown>>; success: boolean }>(
'/douyu/external-orders/activity/query',
ids,
),
updateImages: (id: number, home_images: string[], expected_version?: number) =>
api.post<DouyuCollabOrder, DouyuCollabOrder>(`/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<DouyuCollabTimeline[], DouyuCollabTimeline[]>(`/douyu/external-orders/${id}/timeline`),
metrics: (id: number) =>
api.get<DouyuCollabMetric[], DouyuCollabMetric[]>(`/douyu/external-orders/${id}/metrics`),
deleteOrder: (id: number) =>
api.delete<{ success: boolean; order_no: string }, { success: boolean; order_no: string }>(
`/douyu/external-orders/${id}`,
),
};