Files
tangzhuan-yu/frontend/types.ts
T
jinghui b3377dccd6 feat: 躺赚鱼 v3.6.2 —— xianyu-auto-reply 深度定制版首发
新增: 实时热卖榜(11分类/想要人数排序/热门搜索词热度)、价格监控(目标价通知/卖家信用筛选/销量下限/AI精准监控)、
一键转卖(收藏自动加载/改价直发/详情直达)、AI回复免费token(ai.88531.cn)、API密钥掩码、
推理模型兼容修复、商品本地编辑、授权系统接入(在线人数/版本/公告)、品牌更名躺赚鱼。

README 重写为项目介绍(改动清单/优势/真实截图/两种安装方式/体验地址 tzy.88531.cn/使用引导),
原版 README 完整保留为 README.upstream.md。
2026-11-16 01:00:59 +08:00

895 lines
21 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// API Response Bases
export interface ApiResponse {
success?: boolean;
message?: string;
msg?: string;
}
export interface PaginatedResponse<T> {
success: boolean;
data: T[];
total: number;
page: number;
page_size: number;
total_pages: number;
// 各状态的全量条数,不受分页和筛选影响
status_counts?: Record<string, number>;
}
// Auth
export interface LoginResponse {
success: boolean;
token?: string;
message?: string;
user_id?: number;
username?: string;
is_admin?: boolean;
/** true 表示连续登录失败已达阈值,下一次登录必须携带图形验证码 */
captcha_required?: boolean;
}
// Accounts
export interface AccountDetail {
id: string;
value?: string; // cookie value from backend
cookie?: string; // alias for value
enabled: boolean;
auto_confirm: boolean;
remark?: string;
note?: string; // alias for remark
pause_duration?: number;
// 登录信息
username?: string;
login_password?: string;
show_browser?: boolean;
// Frontend helpers
nickname?: string;
avatar_url?: string;
location?: string;
bio?: string;
followers?: number;
following?: number;
profile_updated_at?: string;
runtime_state?: 'running' | 'connecting' | 'need_relogin' | 'stopped' | 'cancelled' | 'failed';
// AI设置
ai_enabled?: boolean;
max_discount_percent?: number;
max_discount_amount?: number;
max_bargain_rounds?: number;
custom_prompts?: string;
}
// Orders
export type OrderStatus =
| 'processing'
| 'pending_ship'
| 'shipped'
| 'completed'
| 'cancelled'
| 'refunding';
export interface Order {
id: string;
order_id: string;
cookie_id: string;
item_id: string;
item_title?: string;
item_image?: string;
item_price?: string;
buyer_id: string;
quantity: number;
amount: string;
buy_num?: number;
auction_price?: string;
confirm_fee?: string;
refund_fee?: string;
post_fee?: string;
status: OrderStatus;
order_status?: OrderStatus;
receiver_name?: string;
receiver_phone?: string;
receiver_address?: string;
/** 卖家自用订单备注,不会发送给买家;空串/未定义表示无备注 */
seller_note?: string;
created_at?: string;
updated_at?: string;
}
// 快捷短语:人工客服常用话术
export interface QuickPhrase {
id: number;
category: string;
title: string;
content: string;
sort_order: number;
enabled: boolean;
use_count: number;
created_at?: string;
updated_at?: string;
}
// Cards
export interface Card {
id: number;
name: string;
type: 'api' | 'text' | 'data' | 'image';
description?: string;
enabled: boolean;
// 文本类型
text_content?: string;
// 批量数据类型
data_content?: string;
// API 类型配置
api_config?: {
url: string;
method: 'GET' | 'POST';
timeout?: number;
headers?: string;
params?: string;
};
// 图片类型
image_url?: string;
// 通用配置
delay_seconds?: number;
// 发货详情文案:开关、文案内容({参数}/{分隔符}/{图片N})、图片映射(N -> url)
delivery_template?: string;
delivery_template_enabled?: boolean;
delivery_template_images?: Record<string, string>;
created_at: string;
updated_at: string;
}
/** 批量卡密每发出一行生成一条已发货记录。 */
export interface CardShipment {
id: number;
card_id?: number;
card_name: string;
content: string;
order_id: string;
item_id: string;
buyer_id: string;
cookie_id: string;
shipped_at: string;
}
// Items
export interface Item {
id: string | number;
cookie_id: string;
item_id: string;
item_title?: string;
item_description?: string;
item_detail?: string;
item_price?: string;
item_image?: string; // Inferred from common usage, though not explicitly in list model sometimes
item_category?: string;
is_multi_spec?: number | boolean;
multi_quantity_delivery?: number | boolean;
/** 'on_sale' | 'off_shelf':闲鱼接口是否还返回这件商品。
* 同步只做 upsert,下架或删除的商品会留在库里,靠这个字段区分。 */
listing_status?: string;
/** 最后一次被闲鱼接口返回的时间,用于在误判时提供依据。 */
last_seen_at?: string;
created_at?: string;
updated_at?: string;
}
export interface ProductVariantBinding {
id?: number;
binding_id?: number;
display_name: string;
spec_text: string;
spec_payload?: Record<string, string>;
canonical_spec_key?: string;
platform_sku_id: string;
card_id: number;
card_name?: string;
card_type?: Card['type'];
card_enabled?: boolean;
stock_count?: number | null;
delivery_count: number;
delivery_times?: number;
enabled: boolean;
binding_enabled: boolean;
source?: string;
}
export interface ItemDeliveryConfigSummary {
cookie_id: string;
item_id: string;
enabled: boolean;
is_multi_spec: boolean;
variant_count: number;
configured_count: number;
complete: boolean;
delivery_times: number;
}
export interface ItemDeliveryConfig extends ItemDeliveryConfigSummary {
configured: boolean;
variants: ProductVariantBinding[];
}
export type ProductPublishStatus = 'draft' | 'published' | 'failed' | string;
export interface ProductMaterial {
id: number;
user_id: number;
cookie_id: string;
rule_id?: number;
source_item_id: string;
title: string;
description: string;
category: string;
price?: number;
images: string[];
source_url: string;
short_url: string;
delivery_content: string;
publish_status: ProductPublishStatus;
published_item_id: string;
publish_trace_code: string;
auto_card_id?: number;
created_at?: string;
updated_at?: string;
}
export interface ProductFilterRule {
id: number;
user_id: number;
cookie_id: string;
name: string;
include_keywords: string[];
exclude_keywords: string[];
min_price?: number;
max_price?: number;
category: string;
daily_limit: number;
enabled: boolean;
today_count: number;
total_count: number;
counter_date?: string;
last_run_at?: string;
last_run_status?: string;
created_at?: string;
updated_at?: string;
}
export interface ProductDeleteRule {
id: number;
user_id: number;
cookie_id: string;
name: string;
min_publish_days: number;
daily_limit: number;
skip_reply_activity: boolean;
skip_order_activity: boolean;
enabled: boolean;
execution_mode: 'dry_run';
last_run_at?: string;
last_run_status?: string;
created_at?: string;
updated_at?: string;
}
export interface AutomationTaskRun {
id: number;
user_id: number;
cookie_id?: string;
task_type: string;
rule_id?: number;
execution_mode: string;
checked_count: number;
matched_count: number;
changed_count: number;
failed_count: number;
summary: string;
details: Array<Record<string, unknown>>;
error_message?: string;
created_at: string;
}
export interface ProductAutomationResult {
run_id: number;
summary: string;
details?: Array<Record<string, unknown>>;
}
export interface ProductDeletePreview extends ProductAutomationResult {
mode: 'dry_run';
candidates: Array<{
item_id: string;
item_title?: string;
created_at?: string;
age_days?: number;
reason: string;
}>;
skipped: Array<{
item_id: string;
item_title?: string;
created_at?: string;
age_days?: number;
reason: string;
}>;
}
// Rules
export interface ShippingRule {
id: string;
name: string;
item_keyword: string; // Matches item title
cookie_id?: string;
item_id?: string;
item_title?: string;
card_group_id: number; // ID from Card list
card_group_name?: string; // UI helper
priority: number;
enabled: boolean;
delivery_times?: number;
}
export interface DeliveryBlockRule {
rule_code: string;
rule_name: string;
rule_description: string;
enabled: boolean;
priority: number;
block_reason: string;
auto_close_order: boolean;
only_card_after_close: boolean;
excluded_item_ids: string[];
config: Record<string, unknown>;
}
export interface PersonalBlacklistEntry {
id: number;
owner_id: number;
account_id?: string;
buyer_id: string;
buyer_nick: string;
item_id?: string;
reason: string;
is_enabled: boolean;
created_at?: string;
updated_at?: string;
}
export type NotificationChannelType =
| 'dingtalk'
| 'feishu'
| 'bark'
| 'email'
| 'webhook'
| 'wechat'
| 'telegram';
export interface NotificationChannel {
id: string;
name: string;
type: NotificationChannelType;
config: Record<string, unknown>;
enabled: boolean;
created_at?: string;
updated_at?: string;
}
export interface MessageNotification {
id: string;
cookie_id: string;
channel_id: number;
channel_name: string;
channel_type?: NotificationChannelType;
channel_enabled?: boolean;
name?: string | null;
event_types?: string[] | null;
enabled: boolean;
}
export type NotificationPriority = 'critical' | 'warning' | 'info';
export interface NotificationEventDefinition {
id: string;
label: string;
priority: NotificationPriority;
description: string;
}
export interface NotificationPriorityDefinition {
id: NotificationPriority;
label: string;
}
export interface RiskControlLog {
id: number;
cookie_id: string;
cookie_name?: string;
event_type: string;
event_description?: string;
processing_result?: string;
processing_status: 'processing' | 'success' | 'failed' | string;
error_message?: string;
created_at: string;
updated_at?: string;
}
export interface SystemLog {
timestamp: string;
level: string;
source: string;
function?: string;
line?: number;
message: string;
}
export type MessageFilterType = 'skip_reply' | 'skip_notify';
export interface MessageFilter {
id: number;
cookie_id: string;
keyword: string;
filter_type: MessageFilterType;
enabled: boolean;
created_at?: string;
updated_at?: string;
}
export interface AutoReplyLog {
id: number;
cookie_id: string;
chat_id?: string;
item_id?: string;
source_message_id?: string;
sender_user_id?: string;
sender_user_name?: string;
source_message?: string;
process_status: 'success' | 'skipped' | 'failed' | string;
decision_reason?: string;
reply_strategy: 'keyword' | 'ai' | 'default' | 'api' | 'none' | string;
matched_keyword?: string;
reply_text?: string;
error_message?: string;
send_status: 'success' | 'failed' | 'unknown' | string;
created_at?: string;
updated_at?: string;
}
export interface ChatAccount {
accountId: string;
displayName: string;
avatarUrl?: string;
connected: boolean;
xianyuUserId?: string;
}
export interface ChatConversation {
cid: string;
rawCid: string;
otherUserId: string;
otherUserName: string;
otherUserAvatar?: string;
itemId?: string;
itemTitle?: string;
itemImage?: string;
lastMessageSummary: string;
lastMessageTime: number;
unreadCount: number;
}
export interface ChatMessage {
messageId: string;
senderId: string;
senderName: string;
isSelf: boolean;
type: 'text' | 'image' | 'system' | 'card';
text: string;
images: string[];
time: number;
}
export interface ReplyRule {
id: string;
keyword: string;
reply_content: string;
match_type: 'exact' | 'fuzzy';
enabled: boolean;
/** 绑定的商品 ID;空串/未定义为通用关键词(后端按 keyword+item_id 做唯一键) */
item_id?: string;
}
// Stats
export interface AdminStats {
total_users: number;
total_cookies: number;
active_cookies: number;
total_cards: number;
total_keywords: number;
total_orders: number;
}
// 用户管理(管理员专用)。内置 admin 是唯一管理员,其余注册用户均为普通用户。
export interface AdminUser {
id: number;
username: string;
email: string;
is_active?: boolean;
cookie_count?: number;
card_count?: number;
created_at?: string;
updated_at?: string;
}
export interface OrderAnalytics {
revenue_stats: {
total_amount: number;
total_orders: number;
avg_amount?: number;
unique_buyers?: number;
unique_items?: number;
// 确认收货后卖家实收,退款订单为 0
confirmed_amount?: number;
refunded_amount?: number;
total_items_sold?: number;
// 全部状态的口径,与订单页数字一致
all_orders?: number;
all_amount?: number;
};
daily_stats: Array<{
date: string;
amount: number;
order_count?: number;
confirmed_amount?: number;
refunded_amount?: number;
}>;
item_stats?: Array<{
item_id: string;
order_count: number;
total_amount: number;
avg_amount: number;
}>;
}
// Settings
export interface SystemSettings {
ai_model?: string;
ai_api_key?: string;
ai_base_url?: string;
default_reply?: string;
registration_enabled?: boolean;
// 注册是否必须填邮箱验证码。没配 SMTP 时关掉,否则注册会卡在收不到验证码
email_verification_enabled?: boolean;
// 定时从卖家端拉取订单,默认开启
order_sync_enabled?: boolean;
order_sync_interval?: number;
// 商品擦亮,默认关闭
auto_polish_enabled?: boolean;
auto_polish_interval?: number;
// 对买家产生实际动作,默认关闭
auto_rate_enabled?: boolean;
// 订单页评价框的预填文案,避免每单重复手打
auto_rate_template?: string;
/** 确认收货致谢文案,全账号共用 */
auto_thanks_template?: string;
/** 买家互动兜底轮询间隔(秒)。确认收货已由消息事件即时触发,这里只是兜底。 */
buyer_interaction_interval?: string | number;
auto_flower_enabled?: boolean;
// 公告与更新:地址存为字符串,开关也用字符串以复用通用设置接口
announcement_source_url?: string;
announcement_enabled?: string;
// 公告与版本提示分开控制展示,未设置时按展示处理
announcement_show_notice?: boolean;
announcement_show_update?: boolean;
smtp_server?: string;
[key: string]: any;
}
export interface AIReplySettings {
ai_enabled: boolean;
model_name: string;
api_key: string;
api_key_configured?: boolean;
base_url: string;
user_agent?: string;
max_discount_percent: number;
max_discount_amount?: number;
max_bargain_rounds: number;
context_enabled: boolean;
context_message_limit: number;
context_expire_minutes: number;
custom_prompts: string;
}
// Default Reply
export interface DefaultReply {
cookie_id: string;
enabled: boolean;
reply_content: string;
reply_once: boolean;
reply_image_url?: string;
}
// 全局公告与版本检查
export interface AnnouncementItem {
id: string;
title: string;
content: string;
level: 'info' | 'warning' | 'danger';
published_at: string;
}
export interface AnnouncementPayload {
local_version: string;
latest_version: string;
download_url: string;
release_notes: string;
has_update: boolean;
source_configured: boolean;
error: string;
announcements: AnnouncementItem[];
}
// ==================== 一键转卖 ====================
export interface ResellItem {
item_id: string;
title: string;
price: string;
original_price?: string;
image?: string;
images?: string[];
area?: string;
seller?: string;
want_count?: number;
item_status?: number;
favor_time?: string;
/** 闲鱼商品详情页地址(卡片点击跳转用,缺失时前端按 item_id 拼) */
url?: string;
}
export interface ResellPreviewItem {
item_id: string;
title: string;
desc: string;
price: number | string | null;
original_price: number | string | null;
quantity: number;
images: { url: string; width: number; height: number }[];
cat: Record<string, any>;
cat_name: string;
labels: Record<string, any>[];
seller: string;
area: string;
}
// ==================== AI 一键优化建议 ====================
/** 单件商品的优化建议(模型逐件分析结果) */
export interface AiOptimizeItem {
item_id: string;
title: string;
score: number;
priority: 'high' | 'medium' | 'low';
issues: string[];
suggestions: string[];
}
/** 实时热卖榜:单个商品条目(按「人想要」数排序) */
export interface HotlistItem {
rank: number;
item_id: string;
title: string;
price: string;
image?: string;
area?: string;
seller?: string;
/** 想要人数——闲鱼不公开销量,这是唯一的真实热度指标 */
want_count: number;
/** 发布时间(毫秒时间戳) */
publish_time: number;
url: string;
/** 命中该条目的搜索关键词 */
keywords: string[];
}
/** 实时热卖榜:类目配置 */
export interface HotlistCategory {
id: string;
name: string;
icon: string;
keywords: string[];
}
/** 实时热卖榜:单个类目的榜单状态 */
export interface HotlistBoard {
category: string;
name: string;
keywords: string[];
items: HotlistItem[];
/** 榜单生成时间(秒级时间戳),0/缺失=还没抓过 */
updated_at: number;
age_seconds: number | null;
/** 超过新鲜度阈值(10 分钟)视为过期,前端提示可刷新 */
stale: boolean;
/** 参与排序的去重商品总数(榜单只展示前 N 条) */
source_count: number;
refreshing: boolean;
progress?: {
state: string;
done: number;
total: number;
keyword: string;
error?: string;
} | null;
/** 冷却剩余秒数,>0 时禁止再次刷新 */
cooldown_remaining: number;
}
/** 实时热卖榜:GET /hotlist 响应 */
export interface HotlistResponse {
success: boolean;
categories: HotlistCategory[];
boards: Record<string, HotlistBoard>;
server_time: number;
top_n: number;
}
/** 价格监控:单次检查记录(后端 pricewatch_records 表) */
export interface PriceWatchRecord {
id: number;
rule_id: number;
/** 检查时间(秒级时间戳) */
checked_at: number;
/** 参与比价的去重商品数(价格无法解析的已剔除) */
item_count: number;
/** 本次最低价(元),null=没搜到可比价商品 */
lowest_price: number | null;
lowest_item_id: string | null;
lowest_title: string | null;
lowest_image: string | null;
lowest_url: string | null;
lowest_seller: string | null;
lowest_area: string | null;
/** manual=手动检查,auto=后台自动 */
source: string;
notified: number;
notify_error?: string;
error?: string;
}
/** 价格监控:规则(后端 pricewatch_rules 表 + 列表接口附加字段) */
export interface PriceWatchRule {
id: number;
name: string;
keyword: string;
/** 价格区间(元),null=不限 */
min_price: number | null;
max_price: number | null;
/** 目标价:最低价 ≤ 它才通知;null=出现新低价就通知 */
target_price: number | null;
interval_minutes: number;
pages: number;
enabled: boolean;
cookie_id: string | null;
/** 卖家信用度下限(极好/优秀/良好),null=不限(含未标注) */
min_seller_credit: string | null;
/** 卖家成交量下限(按「N条评价」计),null=不限 */
min_seller_deals: number | null;
/** 是否启用 AI 精准监控 */
ai_precise: boolean;
created_at: number;
updated_at: number;
/** 上次检查时间(秒级),0/缺失=还没跑过 */
last_run_at: number | null;
last_lowest_price: number | null;
last_lowest_item_id: string | null;
/** 距下次自动检查的秒数(停用时为 null) */
next_run_in: number | null;
history_count: number;
last_record: PriceWatchRecord | null;
running: boolean;
progress: {
state: string;
done: number;
total: number;
keyword: string;
error?: string;
} | null;
/** 手动检查冷却剩余秒数 */
manual_cooldown_remaining: number;
}
/** 价格监控:GET /pricewatch/rules 响应 */
export interface PriceWatchListResponse {
success: boolean;
rules: PriceWatchRule[];
server_time: number;
manual_cooldown: number;
history_limit: number;
}
/** 价格监控:POST /pricewatch/preview 响应(实时试搜,不落库) */
export interface PriceWatchPreviewResponse {
success: boolean;
keyword: string;
/** 参与比价的去重商品数 */
count: number;
/** 价格区间/信用度/销量过滤后剩下的条数 */
matched: number;
/** AI 精准过滤的说明(未启用或失败时为空/跳过说明) */
ai_note?: string;
lowest: {
item_id: string;
title: string;
price: string;
price_value: number;
image?: string;
url: string;
area?: string;
seller?: string;
} | null;
items: Array<{
item_id: string;
title: string;
price: string;
price_value: number;
image?: string;
url: string;
area?: string;
seller?: string;
}>;
error: string;
searched_at: number;
}
/** 价格监控:POST /pricewatch/rules/{id}/run 响应 */
export interface PriceWatchRunResponse {
success: boolean;
started: boolean;
reason?: 'busy' | 'cooldown';
message?: string;
record?: PriceWatchRecord;
notified?: boolean;
notify_reason?: string;
notify_error?: string;
matched?: number;
count?: number;
}
/** 价格监控:新建/编辑规则入参 */
export interface PriceWatchRuleInput {
name: string;
keyword: string;
min_price?: number | null;
max_price?: number | null;
target_price?: number | null;
interval_minutes: number;
pages: number;
enabled: boolean;
cookie_id?: string | null;
min_seller_credit?: string | null;
min_seller_deals?: number | null;
ai_precise?: boolean;
}
export interface AiOptimizeResult {
/** ok=分析完成;need_api_key=未配置模型 KEY;need_sync=该账号还没同步商品 */
status: 'ok' | 'need_api_key' | 'need_sync';
message?: string;
summary?: string;
items?: AiOptimizeItem[];
stats?: {
total: number;
on_sale: number;
off_shelf: number;
no_desc: number;
avg_price: number | null;
};
analyzed_count?: number;
truncated?: boolean;
model?: string;
}