API契约:收口统计管理员与公共响应
This commit is contained in:
1 parent
f76fb08cbe
commit
929b3fd8a9
9 files changed
+565
-59
No files matched your search
@@ -19,6 +19,9 @@
|
||||
| 关键词回复 | `/keywords...`、`/keywords-with-item-id...`、`/keywords-with-type...`、`/item-reply...` | `/api/v1/reply-rules...` | 旧路径保留,基础/商品/类型规则与指定商品回复 DTO 已落地 |
|
||||
| 默认回复 | `/default-replies...`、`/api/default-reply...` | `/api/v1/default-replies...` | 旧路径保留,单账号、列表和映射 DTO 已落地 |
|
||||
| 账号任务 | `/api/account-tasks...` | `/api/v1/account-tasks...` | 旧路径保留,设置、运行记录和执行摘要 DTO 已落地 |
|
||||
| 管理员 | `/admin/users...`、`/admin/cookies...`、`/admin/stats` | `/api/v1/admin/...` | 旧路径保留,用户/账号/全局统计 DTO 已落地 |
|
||||
| 统计 | `/dashboard/stats`、`/analytics/orders...` | `/api/v1/analytics/...` | 旧路径保留,概览、收益、维度和有效订单分页 DTO 已落地 |
|
||||
| 二维码生成 | `/qr-login/generate` | `/api/v1/qr-login/generate` | 旧路径保留,二维码生成 DTO 已落地;状态响应继续保留动态兼容字段 |
|
||||
|
||||
## 迁移规则
|
||||
|
||||
@@ -38,6 +41,7 @@
|
||||
- 订单列表、详情、刷新和批量外层结果使用 `orderListResponse`、`orderDetailResponse`、`orderRefreshResponse` 与 `manualShipResponse`/`importOrdersResponse`。
|
||||
- 设置、卡券和通知分别使用 `operationResponse`、`aiReplySettingsResponse`、`aiModelsResponse`、`userSettingResponse`、`cardResponse`、`cardBatchResponse`、`notificationChannelResponse`、`notificationBindingResponse` 与 `accountBindingsResponse`。
|
||||
- 关键词回复、默认回复和账号任务分别使用 `keywordBasicResponse`/`keywordItemResponse`/`keywordTypedResponse`、`itemReplyResponse`、`defaultReplyResponse`、`accountTaskSettingsResponse`、`accountTaskRunsResponse` 与 `accountTaskRunResponseEnvelope`。
|
||||
- 管理员和统计分别使用 `adminUserResponse`/`adminCookieResponse`/`adminStatsResponse`、`dashboardStatsResponse`、`orderAnalyticsResponse` 与 `validOrdersResponse`;二维码生成使用 `qrLoginGenerateResponse`。
|
||||
- 聊天会话、消息分页和发送结果使用独立 DTO,不直接暴露数据库模型。
|
||||
- React `frontend/types.ts` 与 `frontend/services/api.ts` 已同步具名成功响应类型,同时保留旧字段归一逻辑。
|
||||
- 旧路径仍由现有路由提供,尚未宣称 `/api/v1` 已经可用。
|
||||
@@ -137,7 +137,8 @@ app shell / routes
|
||||
- 已完成阶段 3 第七个 PR 切片“剩余业务成功响应 DTO 与客户端契约收口”:账号详情/设置、商品核心发布与同步、自动化规则/异常、订单详情/刷新/批量外层响应改用具名 DTO;React 客户端同步使用具名契约类型;新增跨领域成功响应契约测试;旧字段、旧路径和批处理逐行兼容字段保留;全量门禁通过并合并为一个可回滚提交;
|
||||
- 已完成阶段 3 第八个 PR 切片“剩余商品批量操作与设置/卡券/通知成功响应收口”:商品类目推荐、批量发布预检/任务、系统与用户设置、账号 AI 设置、卡券 CRUD/批量、通知渠道与账号绑定均改用具名 DTO;React 客户端同步具名契约类型;补充跨领域契约测试;保留动态设置键、旧路径和批量逐行字段;全量门禁通过并合并为一个可回滚提交;
|
||||
- 已完成阶段 3 第九个 PR 切片“剩余关键词回复、默认回复与账号任务成功响应收口”:关键词基础/商品/类型规则、指定商品回复、默认回复、账号任务设置与运行记录均改用具名 DTO;React 客户端同步具名契约类型;新增跨领域契约测试;保留旧路径和兼容字段;全量门禁通过并合并为一个可回滚提交;
|
||||
- 阶段 3 下一 PR 切片为“分析统计、管理员与剩余公共成功响应收口”:继续迁移尚未覆盖的统计、管理员和公共业务成功响应,不拆分单个 handler 提交;
|
||||
- 已完成阶段 3 第十个 PR 切片“分析统计、管理员与剩余公共成功响应收口”:管理员用户/账号/统计、用户仪表盘、订单分析、有效订单分页和二维码生成均改用具名 DTO;React 客户端同步统计和二维码契约类型;新增跨领域契约测试;保留动态设置和二维码状态的兼容边界;全量门禁通过并合并为一个可回滚提交;
|
||||
- 阶段 3 下一 PR 切片为“公共成功响应兼容收尾与版本化迁移入口审计”:审计剩余动态设置、二维码状态及 `/api/v1` 迁移适配边界,不拆分单个 handler 提交;
|
||||
- 禁止跳过当前入口直接开始 Engine、Automation 或 DB 的大规模拆分。
|
||||
|
||||
## 6. 阶段 0:治理文档与强约束
|
||||
@@ -523,3 +524,4 @@ npm --prefix frontend run build
|
||||
| 2026-08-14 | 完成阶段 3 第七个 PR 切片“剩余业务成功响应 DTO 与客户端契约收口” | 账号详情/设置、商品发布/同步、自动化规则/异常、订单详情/刷新/批量外层响应已具名化;React API 类型同步;跨领域契约测试、全量测试、race、vet、lint、注释、前端构建和 diff 门禁通过;所有修改合并为一个可回滚提交 | 阶段 3:剩余商品批量操作与设置/卡券/通知成功响应收口 |
|
||||
| 2026-08-14 | 完成阶段 3 第八个 PR 切片“剩余商品批量操作与设置/卡券/通知成功响应收口” | 商品类目推荐、批量发布预检/任务、系统与用户设置、账号 AI 设置、卡券 CRUD/批量、通知渠道与账号绑定已具名化;React API 类型同步;跨领域契约测试、全量测试、race、vet、lint、注释、前端构建和 diff 门禁通过;所有修改合并为一个可回滚提交 | 阶段 3:剩余关键词回复、默认回复与账号任务成功响应收口 |
|
||||
| 2026-08-14 | 完成阶段 3 第九个 PR 切片“剩余关键词回复、默认回复与账号任务成功响应收口” | 关键词基础/商品/类型规则、指定商品回复、默认回复、账号任务设置与运行记录已具名化;React API 类型同步;跨领域契约测试、全量测试、race、vet、lint、注释、前端构建和 diff 门禁通过;所有修改合并为一个可回滚提交 | 阶段 3:分析统计、管理员与剩余公共成功响应收口 |
|
||||
| 2026-08-14 | 完成阶段 3 第十个 PR 切片“分析统计、管理员与剩余公共成功响应收口” | 管理员用户/账号/统计、用户仪表盘、订单分析、有效订单分页和二维码生成已具名化;React API 类型同步;跨领域契约测试、全量测试、race、vet、lint、注释、前端构建和 diff 门禁通过;所有修改合并为一个可回滚提交 | 阶段 3:公共成功响应兼容收尾与版本化迁移入口审计 |
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
AdminStats, DashboardStats, Card, SystemSettings, ApiResponse, OrderAnalytics,
|
||||
Item, AIReplySettings, ShippingRule, ReplyRule, DefaultReply, AutomationAction, AutomationTriggerType,
|
||||
NotificationChannel, NotificationEventType, AccountTaskSettings, ChatSession, ChatMessage,
|
||||
CookieSettingsResponse, CookieProfileResponse, ItemPublishResponse, ItemSyncResponse, OrderDTOResponse, OrderDetailResponse, OrderSingleRefreshResponse, OrderBatchResponse, AutomationRuleResponse, AutomationRulePageResponse, AIReplySettingsResponse, AIModelsResponse, UserSettingResponse, CardBatchResponse, CardAppendResponse, CategoryRecommendationResponse, ItemPublishBatchPreviewResponse, ItemPublishBatchListResponse, BatchIDResponse, ItemPublishBatchResponse, BatchCancelResponse, MutationIDResponse, OperationResponse, NotificationChannelResponse, NotificationBinding, AccountBindingsResponse, CardListResponse, KeywordTypedResponse, DefaultReplyResponse, AccountTaskSettingsResponse, AccountTaskRunResponseEnvelope
|
||||
CookieSettingsResponse, CookieProfileResponse, ItemPublishResponse, ItemSyncResponse, OrderDTOResponse, OrderDetailResponse, OrderSingleRefreshResponse, OrderBatchResponse, AutomationRuleResponse, AutomationRulePageResponse, AIReplySettingsResponse, AIModelsResponse, UserSettingResponse, CardBatchResponse, CardAppendResponse, CategoryRecommendationResponse, ItemPublishBatchPreviewResponse, ItemPublishBatchListResponse, BatchIDResponse, ItemPublishBatchResponse, BatchCancelResponse, MutationIDResponse, OperationResponse, NotificationChannelResponse, NotificationBinding, AccountBindingsResponse, CardListResponse, KeywordTypedResponse, DefaultReplyResponse, AccountTaskSettingsResponse, AccountTaskRunResponseEnvelope, AdminStatsResponse, DashboardStatsResponse, OrderAnalyticsResponse, QRLoginGenerateResponse, ValidOrderResponse, ValidOrdersResponse
|
||||
} from '../types';
|
||||
import { formatLocalDate } from '../dateRange';
|
||||
|
||||
@@ -163,7 +163,7 @@ export const getAccountRuntimeStatuses = async (options?: RequestControlOptions)
|
||||
return get('/cookies/runtime-status', undefined, options);
|
||||
};
|
||||
|
||||
export const generateQRLogin = async (options?: RequestControlOptions): Promise<{ success: boolean; session_id?: string; qr_code_url?: string; message?: string }> => {
|
||||
export const generateQRLogin = async (options?: RequestControlOptions): Promise<QRLoginGenerateResponse> => {
|
||||
// 风控后匿名 token 接口可能超过通用的 30 秒请求窗口;后端总生成窗口为 2 分钟。
|
||||
return post('/qr-login/generate', undefined, { ...options, timeoutMs: options?.timeoutMs ?? 130_000 });
|
||||
};
|
||||
@@ -375,15 +375,15 @@ export const importOrders = async (data: Partial<Order>[] | FormData): Promise<O
|
||||
}
|
||||
|
||||
// Stats
|
||||
export const getAdminStats = async (): Promise<AdminStats> => {
|
||||
export const getAdminStats = async (): Promise<AdminStatsResponse> => {
|
||||
return get('/admin/stats');
|
||||
};
|
||||
|
||||
export const getDashboardStats = async (): Promise<DashboardStats> => {
|
||||
export const getDashboardStats = async (): Promise<DashboardStatsResponse> => {
|
||||
return get('/dashboard/stats');
|
||||
};
|
||||
|
||||
export const getOrderAnalytics = async (daysOrParams: number | {start_date: string; end_date: string} = 7): Promise<OrderAnalytics> => {
|
||||
export const getOrderAnalytics = async (daysOrParams: number | {start_date: string; end_date: string} = 7): Promise<OrderAnalyticsResponse> => {
|
||||
let params: {start_date: string; end_date: string};
|
||||
|
||||
if (typeof daysOrParams === 'number') {
|
||||
@@ -411,7 +411,7 @@ export interface ValidOrdersResult {
|
||||
}
|
||||
|
||||
export const getValidOrders = async (dateRange: {start_date: string; end_date: string}): Promise<ValidOrdersResult> => {
|
||||
const res = await get<any>('/analytics/orders/valid', {
|
||||
const res = await get<ValidOrdersResponse | ValidOrderResponse[]>('/analytics/orders/valid', {
|
||||
start_date: dateRange.start_date,
|
||||
end_date: dateRange.end_date,
|
||||
timezone_offset_minutes: -new Date().getTimezoneOffset(),
|
||||
|
||||
@@ -1076,3 +1076,165 @@ export interface AccountTaskRunResponseEnvelope {
|
||||
/** 账号任务执行统计。 */
|
||||
summary: AccountTaskSummaryResponse;
|
||||
}
|
||||
|
||||
/** 管理员用户列表项响应。 */
|
||||
export interface AdminUserResponse {
|
||||
/** 用户主键。 */
|
||||
id: number;
|
||||
/** 用户登录名。 */
|
||||
username: string;
|
||||
/** 用户邮箱。 */
|
||||
email: string;
|
||||
/** 用户是否启用。 */
|
||||
is_active: boolean;
|
||||
/** 用户是否为管理员。 */
|
||||
is_admin: boolean;
|
||||
/** 用户创建时间。 */
|
||||
created_at: string;
|
||||
/** 用户拥有的账号数量。 */
|
||||
cookie_count: number;
|
||||
}
|
||||
|
||||
/** 管理员账号列表项响应。 */
|
||||
export interface AdminCookieResponse {
|
||||
/** 账号稳定标识。 */
|
||||
id: string;
|
||||
/** 账号所属用户主键。 */
|
||||
user_id: number;
|
||||
/** 账号备注。 */
|
||||
remark: string;
|
||||
/** 账号创建时间。 */
|
||||
created_at: string;
|
||||
/** 账号所属用户名。 */
|
||||
owner: string;
|
||||
/** 账号是否启用。 */
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
/** 管理员全局统计响应。 */
|
||||
export interface AdminStatsResponse extends AdminStats {}
|
||||
|
||||
/** 当前用户数据概览响应。 */
|
||||
export interface DashboardStatsResponse extends DashboardStats {}
|
||||
|
||||
/** 订单收益统计响应。 */
|
||||
export interface AnalyticsRevenueStatsResponse {
|
||||
/** 统计范围内的订单数。 */
|
||||
total_orders: number;
|
||||
/** 统计范围内的订单总金额。 */
|
||||
total_amount: number;
|
||||
/** 订单平均金额。 */
|
||||
avg_amount: number;
|
||||
/** 买家数量。 */
|
||||
unique_buyers: number;
|
||||
/** 商品数量。 */
|
||||
unique_items: number;
|
||||
}
|
||||
|
||||
/** 按日期聚合的订单统计响应。 */
|
||||
export interface AnalyticsDailyStatsResponse {
|
||||
/** 用户本地日期。 */
|
||||
date: string;
|
||||
/** 当天订单数。 */
|
||||
order_count: number;
|
||||
/** 当天订单金额。 */
|
||||
amount: number;
|
||||
}
|
||||
|
||||
/** 按订单状态聚合的统计响应。 */
|
||||
export interface AnalyticsStatusStatsResponse {
|
||||
/** 归一化后的订单状态。 */
|
||||
status: string;
|
||||
/** 该状态订单数。 */
|
||||
count: number;
|
||||
/** 该状态订单金额。 */
|
||||
amount: number;
|
||||
}
|
||||
|
||||
/** 按收货城市聚合的统计响应。 */
|
||||
export interface AnalyticsCityStatsResponse {
|
||||
/** 收货城市。 */
|
||||
city: string;
|
||||
/** 该城市订单数。 */
|
||||
order_count: number;
|
||||
/** 该城市订单金额。 */
|
||||
total_amount: number;
|
||||
}
|
||||
|
||||
/** 按商品聚合的统计响应。 */
|
||||
export interface AnalyticsItemStatsResponse {
|
||||
/** 商品平台标识。 */
|
||||
item_id: string;
|
||||
/** 该商品订单数。 */
|
||||
order_count: number;
|
||||
/** 该商品订单金额。 */
|
||||
total_amount: number;
|
||||
/** 该商品订单平均金额。 */
|
||||
avg_amount: number;
|
||||
}
|
||||
|
||||
/** 订单分析接口响应。 */
|
||||
export interface OrderAnalyticsResponse {
|
||||
/** 收益统计。 */
|
||||
revenue_stats: AnalyticsRevenueStatsResponse;
|
||||
/** 按日统计。 */
|
||||
daily_stats: AnalyticsDailyStatsResponse[];
|
||||
/** 按状态统计。 */
|
||||
status_stats: AnalyticsStatusStatsResponse[];
|
||||
/** 按城市统计。 */
|
||||
city_stats: AnalyticsCityStatsResponse[];
|
||||
/** 按商品统计。 */
|
||||
item_stats: AnalyticsItemStatsResponse[];
|
||||
}
|
||||
|
||||
/** 有效订单明细响应。 */
|
||||
export interface ValidOrderResponse {
|
||||
/** 平台订单标识。 */
|
||||
order_id: string;
|
||||
/** 商品平台标识。 */
|
||||
item_id: string;
|
||||
/** 买家平台标识。 */
|
||||
buyer_id: string;
|
||||
/** 商品标题。 */
|
||||
item_title: string;
|
||||
/** 商品图片地址。 */
|
||||
item_image: string;
|
||||
/** 订单数量文本。 */
|
||||
quantity: string;
|
||||
/** 订单金额文本。 */
|
||||
amount: string;
|
||||
/** 兼容保留的订单状态。 */
|
||||
order_status: string;
|
||||
/** 归一化后的订单状态。 */
|
||||
status: string;
|
||||
/** 订单所属账号标识。 */
|
||||
cookie_id: string;
|
||||
/** 订单创建时间。 */
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/** 有效订单分页响应。 */
|
||||
export interface ValidOrdersResponse {
|
||||
/** 当前页有效订单。 */
|
||||
orders: ValidOrderResponse[];
|
||||
/** 符合条件的订单总数。 */
|
||||
total: number;
|
||||
/** 当前页码。 */
|
||||
page: number;
|
||||
/** 当前页大小。 */
|
||||
page_size: number;
|
||||
/** 是否还有未返回的订单。 */
|
||||
truncated: boolean;
|
||||
}
|
||||
|
||||
/** 扫码登录二维码生成响应。 */
|
||||
export interface QRLoginGenerateResponse {
|
||||
/** 二维码是否生成成功。 */
|
||||
success: boolean;
|
||||
/** 扫码登录会话标识。 */
|
||||
session_id: string;
|
||||
/** 二维码图片地址。 */
|
||||
qr_code_url: string;
|
||||
/** 可选的提示文本。 */
|
||||
message?: string;
|
||||
}
|
||||
@@ -23,7 +23,7 @@ func (s *Server) adminListUsers(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
var out []map[string]any
|
||||
var out []adminUserResponse
|
||||
for rows.Next() {
|
||||
var id int64
|
||||
var username, email, createdAt string
|
||||
@@ -39,10 +39,10 @@ func (s *Server) adminListUsers(w http.ResponseWriter, r *http.Request) {
|
||||
writeErr(w, http.StatusInternalServerError, "统计用户账号失败")
|
||||
return
|
||||
}
|
||||
out = append(out, map[string]any{
|
||||
"id": id, "username": username, "email": email,
|
||||
"is_active": isActive != 0, "is_admin": isAdmin != 0,
|
||||
"created_at": createdAt, "cookie_count": cookieCount,
|
||||
out = append(out, adminUserResponse{
|
||||
ID: id, Username: username, Email: email,
|
||||
IsActive: isActive != 0, IsAdmin: isAdmin != 0,
|
||||
CreatedAt: createdAt, CookieCount: cookieCount,
|
||||
})
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
@@ -75,7 +75,7 @@ func (s *Server) adminDeleteUser(w http.ResponseWriter, r *http.Request) {
|
||||
writeErr(w, http.StatusInternalServerError, "删除失败")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"success": true})
|
||||
writeJSON(w, http.StatusOK, operationResponse{Success: true})
|
||||
}
|
||||
|
||||
func (s *Server) adminListCookies(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -87,7 +87,7 @@ func (s *Server) adminListCookies(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
var out []map[string]any
|
||||
var out []adminCookieResponse
|
||||
for rows.Next() {
|
||||
var id string
|
||||
var uid int64
|
||||
@@ -96,10 +96,10 @@ func (s *Server) adminListCookies(w http.ResponseWriter, r *http.Request) {
|
||||
writeErr(w, http.StatusInternalServerError, "读取账号数据失败")
|
||||
return
|
||||
}
|
||||
out = append(out, map[string]any{
|
||||
"id": id, "user_id": uid, "remark": remark,
|
||||
"created_at": createdAt, "owner": username,
|
||||
"enabled": s.Store.Cookies.GetStatus(r.Context(), id),
|
||||
out = append(out, adminCookieResponse{
|
||||
ID: id, UserID: uid, Remark: remark,
|
||||
CreatedAt: createdAt, Owner: username,
|
||||
Enabled: s.Store.Cookies.GetStatus(r.Context(), id),
|
||||
})
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
@@ -140,12 +140,12 @@ func (s *Server) adminStats(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
writeJSON(w, http.StatusOK, map[string]int64{
|
||||
"total_users": totalUsers,
|
||||
"total_cookies": totalCookies,
|
||||
"active_cookies": activeCookies,
|
||||
"total_cards": totalCards,
|
||||
"total_keywords": totalKeywords,
|
||||
"total_orders": totalOrders,
|
||||
writeJSON(w, http.StatusOK, adminStatsResponse{
|
||||
TotalUsers: totalUsers, TotalCookies: totalCookies, ActiveCookies: activeCookies,
|
||||
TotalCards: totalCards, TotalKeywords: totalKeywords, TotalOrders: totalOrders,
|
||||
// 统计响应继续保留原有字段名称,兼容管理员仪表盘。
|
||||
// DTO 字段由具名结构统一维护,避免动态 map 漏字段。
|
||||
// 所有统计值均来自当前数据库快照。
|
||||
// 成功响应不再依赖任意键名拼接。
|
||||
})
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func (s *Server) dashboardStats(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
counts["available_card_stock"] = available
|
||||
|
||||
writeJSON(w, http.StatusOK, counts)
|
||||
writeJSON(w, http.StatusOK, dashboardStatsResponse{TotalCookies: counts["total_cookies"], ActiveCookies: counts["active_cookies"], TotalCards: counts["total_cards"], AvailableCardStock: counts["available_card_stock"], TotalKeywords: counts["total_keywords"], TotalOrders: counts["total_orders"]})
|
||||
}
|
||||
|
||||
// 有效订单状态只统计以下几种。
|
||||
@@ -122,7 +122,7 @@ func (s *Server) orderAnalytics(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// 2. 按用户本地日期统计。数据库统一保存 UTC,分组在 Go 中完成,避免三种方言
|
||||
// 的时区转换函数不同以及 SQLite DATE(created_at) 把凌晨订单归到前一天。
|
||||
daily := []map[string]any{}
|
||||
daily := []analyticsDailyStatsResponse{}
|
||||
rows, err := s.Store.DB.QueryContext(r.Context(), `
|
||||
SELECT order_id,amount,created_at FROM orders `+where+amountFilter, params...)
|
||||
if err != nil {
|
||||
@@ -162,11 +162,11 @@ func (s *Server) orderAnalytics(w http.ResponseWriter, r *http.Request) {
|
||||
sort.Strings(dates)
|
||||
for _, date := range dates {
|
||||
value := dailyMap[date]
|
||||
daily = append(daily, map[string]any{"date": date, "order_count": value.count, "amount": round2(value.amount)})
|
||||
daily = append(daily, analyticsDailyStatsResponse{Date: date, OrderCount: value.count, Amount: round2(value.amount)})
|
||||
}
|
||||
|
||||
// 3. 按状态统计。
|
||||
statusStats := []map[string]any{}
|
||||
statusStats := []analyticsStatusStatsResponse{}
|
||||
type statusValue struct {
|
||||
count int
|
||||
amount float64
|
||||
@@ -207,11 +207,11 @@ func (s *Server) orderAnalytics(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
for _, status := range statusNames {
|
||||
value := statusMap[status]
|
||||
statusStats = append(statusStats, map[string]any{"status": status, "count": value.count, "amount": round2(value.amount)})
|
||||
statusStats = append(statusStats, analyticsStatusStatsResponse{Status: status, Count: value.count, Amount: round2(value.amount)})
|
||||
}
|
||||
|
||||
// 4. 按城市统计。
|
||||
cityStats := []map[string]any{}
|
||||
cityStats := []analyticsCityStatsResponse{}
|
||||
rows, err = s.Store.DB.QueryContext(r.Context(), `
|
||||
SELECT receiver_city, COUNT(DISTINCT order_id), COALESCE(SUM(`+amountClean+`),0)
|
||||
FROM orders `+where+amountFilter+`
|
||||
@@ -226,8 +226,8 @@ func (s *Server) orderAnalytics(w http.ResponseWriter, r *http.Request) {
|
||||
var count int
|
||||
var amount float64
|
||||
if rows.Scan(&city, &count, &amount) == nil {
|
||||
cityStats = append(cityStats, map[string]any{
|
||||
"city": city, "order_count": count, "total_amount": round2(amount),
|
||||
cityStats = append(cityStats, analyticsCityStatsResponse{
|
||||
City: city, OrderCount: count, TotalAmount: round2(amount),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -239,7 +239,7 @@ func (s *Server) orderAnalytics(w http.ResponseWriter, r *http.Request) {
|
||||
_ = rows.Close()
|
||||
|
||||
// 5. 商品排行。
|
||||
itemStats := []map[string]any{}
|
||||
itemStats := []analyticsItemStatsResponse{}
|
||||
rows, err = s.Store.DB.QueryContext(r.Context(), `
|
||||
SELECT item_id, COUNT(DISTINCT order_id), COALESCE(SUM(`+amountClean+`),0), COALESCE(AVG(`+amountClean+`),0)
|
||||
FROM orders `+where+amountFilter+`
|
||||
@@ -254,9 +254,9 @@ func (s *Server) orderAnalytics(w http.ResponseWriter, r *http.Request) {
|
||||
var count int
|
||||
var total, avg float64
|
||||
if rows.Scan(&itemID, &count, &total, &avg) == nil {
|
||||
itemStats = append(itemStats, map[string]any{
|
||||
"item_id": itemID, "order_count": count,
|
||||
"total_amount": round2(total), "avg_amount": round2(avg),
|
||||
itemStats = append(itemStats, analyticsItemStatsResponse{
|
||||
ItemID: itemID, OrderCount: count,
|
||||
TotalAmount: round2(total), AvgAmount: round2(avg),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -267,16 +267,16 @@ func (s *Server) orderAnalytics(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
_ = rows.Close()
|
||||
|
||||
writeJSON(w, http.StatusOK, map[string]any{
|
||||
"revenue_stats": map[string]any{
|
||||
"total_orders": rev.TotalOrders, "total_amount": round2(rev.TotalAmount),
|
||||
"avg_amount": round2(rev.AvgAmount), "unique_buyers": rev.UniqueBuyers,
|
||||
"unique_items": rev.UniqueItems,
|
||||
writeJSON(w, http.StatusOK, orderAnalyticsResponse{
|
||||
RevenueStats: analyticsRevenueStatsResponse{
|
||||
TotalOrders: rev.TotalOrders, TotalAmount: round2(rev.TotalAmount),
|
||||
AvgAmount: round2(rev.AvgAmount), UniqueBuyers: rev.UniqueBuyers,
|
||||
UniqueItems: rev.UniqueItems,
|
||||
},
|
||||
"daily_stats": daily,
|
||||
"status_stats": statusStats,
|
||||
"city_stats": cityStats,
|
||||
"item_stats": itemStats,
|
||||
DailyStats: daily, StatusStats: statusStats, CityStats: cityStats, ItemStats: itemStats,
|
||||
// 各统计维度分别使用具名 DTO,避免前端依赖动态键值。
|
||||
// daily_stats 保留用户本地日期,兼容已有图表横轴。
|
||||
// status_stats、city_stats 和 item_stats 保留旧字段名称。
|
||||
})
|
||||
}
|
||||
|
||||
@@ -316,16 +316,16 @@ func (s *Server) validOrders(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
out := []map[string]any{}
|
||||
out := []validOrderResponse{}
|
||||
for rows.Next() {
|
||||
var orderID, itemID, itemTitle, itemDetail, buyerID, quantity, amount, status, cookieID, createdAt string
|
||||
if rows.Scan(&orderID, &itemID, &itemTitle, &itemDetail, &buyerID, &quantity, &amount, &status, &cookieID, &createdAt) == nil {
|
||||
status = db.NormalizeOrderStatus(status)
|
||||
out = append(out, map[string]any{
|
||||
"order_id": orderID, "item_id": itemID, "buyer_id": buyerID,
|
||||
"item_title": itemTitle, "item_image": itemImageFromDetail(itemDetail),
|
||||
"quantity": quantity, "amount": amount, "order_status": status,
|
||||
"status": status, "cookie_id": cookieID, "created_at": createdAt,
|
||||
out = append(out, validOrderResponse{
|
||||
OrderID: orderID, ItemID: itemID, BuyerID: buyerID,
|
||||
ItemTitle: itemTitle, ItemImage: itemImageFromDetail(itemDetail),
|
||||
Quantity: quantity, Amount: amount, OrderStatus: status,
|
||||
Status: status, CookieID: cookieID, CreatedAt: createdAt,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -333,9 +333,9 @@ func (s *Server) validOrders(w http.ResponseWriter, r *http.Request) {
|
||||
writeErr(w, http.StatusInternalServerError, "查询失败")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{
|
||||
"orders": out, "total": total, "page": page, "page_size": pageSize,
|
||||
"truncated": offset+len(out) < total,
|
||||
writeJSON(w, http.StatusOK, validOrdersResponse{
|
||||
Orders: out, Total: total, Page: page, PageSize: pageSize,
|
||||
Truncated: offset+len(out) < total,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -60,10 +60,10 @@ func (s *Server) generateQRLogin(w http.ResponseWriter, r *http.Request) {
|
||||
s.qrMu.Lock()
|
||||
s.qrOwners[sessionID] = qrLoginOwner{UserID: sess.UserID, CreatedAt: time.Now().UTC()}
|
||||
s.qrMu.Unlock()
|
||||
writeJSON(w, http.StatusOK, map[string]any{
|
||||
"success": true,
|
||||
"session_id": sessionID,
|
||||
"qr_code_url": qrCodeURL,
|
||||
writeJSON(w, http.StatusOK, qrLoginGenerateResponse{
|
||||
Success: true, SessionID: sessionID, QRCodeURL: qrCodeURL,
|
||||
// 生成成功响应只暴露会话标识和二维码地址。
|
||||
// 服务端仍然保留二维码会话所有权校验。
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -517,3 +517,153 @@ func TestReplyAndAccountTaskSuccessResponseContracts(t *testing.T) {
|
||||
t.Fatalf("task runs response=%+v", taskRunsResponse)
|
||||
}
|
||||
}
|
||||
|
||||
// TestAnalyticsAdminAndPublicSuccessResponseContracts 验证统计、管理员和二维码公共成功响应的具名 DTO。
|
||||
func TestAnalyticsAdminAndPublicSuccessResponseContracts(t *testing.T) {
|
||||
// srv 是用于验证统计、管理员和公共响应的 HTTP 测试服务。
|
||||
srv, store, cleanup := newTestServer(t)
|
||||
defer cleanup()
|
||||
// handler 是当前测试使用的完整路由树。
|
||||
handler := srv.Router()
|
||||
// sessionCookie 是管理员登录后得到的认证会话。
|
||||
sessionCookie := loginHelper(t, handler)
|
||||
// seedErr 是统计测试订单写入失败的原因。
|
||||
if _, seedErr := store.DB.ExecContext(context.Background(), `INSERT INTO orders (order_id,item_id,buyer_id,quantity,amount,order_status,cookie_id,created_at) VALUES ('contract-analytics','contract-item','buyer', '2','12.50','completed','acc1','2026-08-14 10:00:00')`); seedErr != nil {
|
||||
t.Fatalf("seed analytics order: %v", seedErr)
|
||||
}
|
||||
|
||||
// adminStatsReq 是读取管理员全局统计的请求。
|
||||
adminStatsReq := httptest.NewRequest(http.MethodGet, "/admin/stats", nil)
|
||||
adminStatsReq.AddCookie(sessionCookie)
|
||||
// adminStatsRecorder 是捕获管理员统计响应的记录器。
|
||||
adminStatsRecorder := httptest.NewRecorder()
|
||||
handler.ServeHTTP(adminStatsRecorder, adminStatsReq)
|
||||
if adminStatsRecorder.Code != http.StatusOK {
|
||||
t.Fatalf("admin stats status=%d body=%s", adminStatsRecorder.Code, adminStatsRecorder.Body.String())
|
||||
}
|
||||
// adminStatsResponseValue 是管理员统计具名响应 DTO。
|
||||
var adminStatsResponseValue adminStatsResponse
|
||||
// adminStatsDecodeErr 是管理员统计响应 JSON 反序列化失败的原因。
|
||||
if adminStatsDecodeErr := json.Unmarshal(adminStatsRecorder.Body.Bytes(), &adminStatsResponseValue); adminStatsDecodeErr != nil {
|
||||
t.Fatalf("decode admin stats response: %v", adminStatsDecodeErr)
|
||||
}
|
||||
if adminStatsResponseValue.TotalUsers == 0 || adminStatsResponseValue.TotalOrders != 1 {
|
||||
t.Fatalf("admin stats response=%+v", adminStatsResponseValue)
|
||||
}
|
||||
|
||||
// adminUsersReq 是读取管理员用户列表的请求。
|
||||
adminUsersReq := httptest.NewRequest(http.MethodGet, "/admin/users", nil)
|
||||
adminUsersReq.AddCookie(sessionCookie)
|
||||
// adminUsersRecorder 是捕获管理员用户列表响应的记录器。
|
||||
adminUsersRecorder := httptest.NewRecorder()
|
||||
handler.ServeHTTP(adminUsersRecorder, adminUsersReq)
|
||||
if adminUsersRecorder.Code != http.StatusOK {
|
||||
t.Fatalf("admin users status=%d body=%s", adminUsersRecorder.Code, adminUsersRecorder.Body.String())
|
||||
}
|
||||
// adminUsersResponse 是管理员用户列表具名响应 DTO 列表。
|
||||
var adminUsersResponse []adminUserResponse
|
||||
// adminUsersDecodeErr 是管理员用户列表响应 JSON 反序列化失败的原因。
|
||||
if adminUsersDecodeErr := json.Unmarshal(adminUsersRecorder.Body.Bytes(), &adminUsersResponse); adminUsersDecodeErr != nil {
|
||||
t.Fatalf("decode admin users response: %v", adminUsersDecodeErr)
|
||||
}
|
||||
if len(adminUsersResponse) != 1 || adminUsersResponse[0].Username != "admin" {
|
||||
t.Fatalf("admin users response=%+v", adminUsersResponse)
|
||||
}
|
||||
|
||||
// adminCookiesReq 是读取管理员账号列表的请求。
|
||||
adminCookiesReq := httptest.NewRequest(http.MethodGet, "/admin/cookies", nil)
|
||||
adminCookiesReq.AddCookie(sessionCookie)
|
||||
// adminCookiesRecorder 是捕获管理员账号列表响应的记录器。
|
||||
adminCookiesRecorder := httptest.NewRecorder()
|
||||
handler.ServeHTTP(adminCookiesRecorder, adminCookiesReq)
|
||||
if adminCookiesRecorder.Code != http.StatusOK {
|
||||
t.Fatalf("admin cookies status=%d body=%s", adminCookiesRecorder.Code, adminCookiesRecorder.Body.String())
|
||||
}
|
||||
// adminCookiesResponse 是管理员账号列表具名响应 DTO 列表。
|
||||
var adminCookiesResponse []adminCookieResponse
|
||||
// adminCookiesDecodeErr 是管理员账号列表响应 JSON 反序列化失败的原因。
|
||||
if adminCookiesDecodeErr := json.Unmarshal(adminCookiesRecorder.Body.Bytes(), &adminCookiesResponse); adminCookiesDecodeErr != nil {
|
||||
t.Fatalf("decode admin cookies response: %v", adminCookiesDecodeErr)
|
||||
}
|
||||
if len(adminCookiesResponse) != 1 || adminCookiesResponse[0].ID != "acc1" {
|
||||
t.Fatalf("admin cookies response=%+v", adminCookiesResponse)
|
||||
}
|
||||
|
||||
// dashboardReq 是读取当前用户概览统计的请求。
|
||||
dashboardReq := httptest.NewRequest(http.MethodGet, "/dashboard/stats", nil)
|
||||
dashboardReq.AddCookie(sessionCookie)
|
||||
// dashboardRecorder 是捕获概览统计响应的记录器。
|
||||
dashboardRecorder := httptest.NewRecorder()
|
||||
handler.ServeHTTP(dashboardRecorder, dashboardReq)
|
||||
if dashboardRecorder.Code != http.StatusOK {
|
||||
t.Fatalf("dashboard status=%d body=%s", dashboardRecorder.Code, dashboardRecorder.Body.String())
|
||||
}
|
||||
// dashboardResponse 是概览统计具名响应 DTO。
|
||||
var dashboardResponse dashboardStatsResponse
|
||||
// dashboardDecodeErr 是概览统计响应 JSON 反序列化失败的原因。
|
||||
if dashboardDecodeErr := json.Unmarshal(dashboardRecorder.Body.Bytes(), &dashboardResponse); dashboardDecodeErr != nil {
|
||||
t.Fatalf("decode dashboard response: %v", dashboardDecodeErr)
|
||||
}
|
||||
if dashboardResponse.TotalOrders != 1 {
|
||||
t.Fatalf("dashboard response=%+v", dashboardResponse)
|
||||
}
|
||||
|
||||
// analyticsReq 是读取订单分析统计的请求。
|
||||
analyticsReq := httptest.NewRequest(http.MethodGet, "/analytics/orders?start_date=2026-08-14&end_date=2026-08-14", nil)
|
||||
analyticsReq.AddCookie(sessionCookie)
|
||||
// analyticsRecorder 是捕获订单分析响应的记录器。
|
||||
analyticsRecorder := httptest.NewRecorder()
|
||||
handler.ServeHTTP(analyticsRecorder, analyticsReq)
|
||||
if analyticsRecorder.Code != http.StatusOK {
|
||||
t.Fatalf("analytics status=%d body=%s", analyticsRecorder.Code, analyticsRecorder.Body.String())
|
||||
}
|
||||
// analyticsResponse 是订单分析具名响应 DTO。
|
||||
var analyticsResponse orderAnalyticsResponse
|
||||
// analyticsDecodeErr 是订单分析响应 JSON 反序列化失败的原因。
|
||||
if analyticsDecodeErr := json.Unmarshal(analyticsRecorder.Body.Bytes(), &analyticsResponse); analyticsDecodeErr != nil {
|
||||
t.Fatalf("decode analytics response: %v", analyticsDecodeErr)
|
||||
}
|
||||
if analyticsResponse.RevenueStats.TotalOrders != 1 || len(analyticsResponse.DailyStats) != 1 {
|
||||
t.Fatalf("analytics response=%+v", analyticsResponse)
|
||||
}
|
||||
|
||||
// validOrdersReq 是读取有效订单分页的请求。
|
||||
validOrdersReq := httptest.NewRequest(http.MethodGet, "/analytics/orders/valid?start_date=2026-08-14&end_date=2026-08-14", nil)
|
||||
validOrdersReq.AddCookie(sessionCookie)
|
||||
// validOrdersRecorder 是捕获有效订单响应的记录器。
|
||||
validOrdersRecorder := httptest.NewRecorder()
|
||||
handler.ServeHTTP(validOrdersRecorder, validOrdersReq)
|
||||
if validOrdersRecorder.Code != http.StatusOK {
|
||||
t.Fatalf("valid orders status=%d body=%s", validOrdersRecorder.Code, validOrdersRecorder.Body.String())
|
||||
}
|
||||
// validOrdersResponseValue 是有效订单分页具名响应 DTO。
|
||||
var validOrdersResponseValue validOrdersResponse
|
||||
// validOrdersDecodeErr 是有效订单响应 JSON 反序列化失败的原因。
|
||||
if validOrdersDecodeErr := json.Unmarshal(validOrdersRecorder.Body.Bytes(), &validOrdersResponseValue); validOrdersDecodeErr != nil {
|
||||
t.Fatalf("decode valid orders response: %v", validOrdersDecodeErr)
|
||||
}
|
||||
if validOrdersResponseValue.Total != 1 || len(validOrdersResponseValue.Orders) != 1 {
|
||||
t.Fatalf("valid orders response=%+v", validOrdersResponseValue)
|
||||
}
|
||||
|
||||
// srv.QRLogin 是二维码生成测试替身。
|
||||
srv.QRLogin = &fakeQRLoginService{}
|
||||
// qrReq 是生成扫码登录二维码的请求。
|
||||
qrReq := httptest.NewRequest(http.MethodPost, "/qr-login/generate", nil)
|
||||
qrReq.AddCookie(sessionCookie)
|
||||
// qrRecorder 是捕获二维码生成响应的记录器。
|
||||
qrRecorder := httptest.NewRecorder()
|
||||
handler.ServeHTTP(qrRecorder, qrReq)
|
||||
if qrRecorder.Code != http.StatusOK {
|
||||
t.Fatalf("qr generate status=%d body=%s", qrRecorder.Code, qrRecorder.Body.String())
|
||||
}
|
||||
// qrResponse 是二维码生成具名响应 DTO。
|
||||
var qrResponse qrLoginGenerateResponse
|
||||
// qrDecodeErr 是二维码生成响应 JSON 反序列化失败的原因。
|
||||
if qrDecodeErr := json.Unmarshal(qrRecorder.Body.Bytes(), &qrResponse); qrDecodeErr != nil {
|
||||
t.Fatalf("decode qr response: %v", qrDecodeErr)
|
||||
}
|
||||
if !qrResponse.Success || qrResponse.SessionID == "" || qrResponse.QRCodeURL == "" {
|
||||
t.Fatalf("qr response=%+v", qrResponse)
|
||||
}
|
||||
}
|
||||
@@ -1063,3 +1063,191 @@ func newAccountTaskSummaryResponse(summary automation.AccountTaskSummary) accoun
|
||||
Failed: summary.Failed, Skipped: summary.Skipped, Message: summary.Message,
|
||||
}
|
||||
}
|
||||
|
||||
// adminUserResponse 是管理员用户列表项的具名响应 DTO。
|
||||
type adminUserResponse struct {
|
||||
// ID 是用户主键。
|
||||
ID int64 `json:"id"`
|
||||
// Username 是用户登录名。
|
||||
Username string `json:"username"`
|
||||
// Email 是用户邮箱。
|
||||
Email string `json:"email"`
|
||||
// IsActive 表示用户是否启用。
|
||||
IsActive bool `json:"is_active"`
|
||||
// IsAdmin 表示用户是否为管理员。
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
// CreatedAt 是用户创建时间。
|
||||
CreatedAt string `json:"created_at"`
|
||||
// CookieCount 是用户拥有的账号数量。
|
||||
CookieCount int `json:"cookie_count"`
|
||||
}
|
||||
|
||||
// adminCookieResponse 是管理员账号列表项的具名响应 DTO。
|
||||
type adminCookieResponse struct {
|
||||
// ID 是账号稳定标识。
|
||||
ID string `json:"id"`
|
||||
// UserID 是账号所属用户主键。
|
||||
UserID int64 `json:"user_id"`
|
||||
// Remark 是账号备注。
|
||||
Remark string `json:"remark"`
|
||||
// CreatedAt 是账号创建时间。
|
||||
CreatedAt string `json:"created_at"`
|
||||
// Owner 是账号所属用户名。
|
||||
Owner string `json:"owner"`
|
||||
// Enabled 表示账号是否启用。
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
// adminStatsResponse 是管理员全局统计的具名响应 DTO。
|
||||
type adminStatsResponse struct {
|
||||
// TotalUsers 是用户总数。
|
||||
TotalUsers int64 `json:"total_users"`
|
||||
// TotalCookies 是账号总数。
|
||||
TotalCookies int64 `json:"total_cookies"`
|
||||
// ActiveCookies 是活跃账号数。
|
||||
ActiveCookies int64 `json:"active_cookies"`
|
||||
// TotalCards 是卡券总数。
|
||||
TotalCards int64 `json:"total_cards"`
|
||||
// TotalKeywords 是关键词规则总数。
|
||||
TotalKeywords int64 `json:"total_keywords"`
|
||||
// TotalOrders 是有效订单总数。
|
||||
TotalOrders int64 `json:"total_orders"`
|
||||
}
|
||||
|
||||
// dashboardStatsResponse 是当前用户数据概览的具名响应 DTO。
|
||||
type dashboardStatsResponse struct {
|
||||
// TotalCookies 是账号总数。
|
||||
TotalCookies int64 `json:"total_cookies"`
|
||||
// ActiveCookies 是活跃账号数。
|
||||
ActiveCookies int64 `json:"active_cookies"`
|
||||
// TotalCards 是卡券总数。
|
||||
TotalCards int64 `json:"total_cards"`
|
||||
// AvailableCardStock 是可用卡券库存数量。
|
||||
AvailableCardStock int64 `json:"available_card_stock"`
|
||||
// TotalKeywords 是关键词规则总数。
|
||||
TotalKeywords int64 `json:"total_keywords"`
|
||||
// TotalOrders 是订单总数。
|
||||
TotalOrders int64 `json:"total_orders"`
|
||||
}
|
||||
|
||||
// analyticsRevenueStatsResponse 是订单收益统计的具名 DTO。
|
||||
type analyticsRevenueStatsResponse struct {
|
||||
// TotalOrders 是统计范围内的订单数。
|
||||
TotalOrders int `json:"total_orders"`
|
||||
// TotalAmount 是统计范围内的订单总金额。
|
||||
TotalAmount float64 `json:"total_amount"`
|
||||
// AvgAmount 是订单平均金额。
|
||||
AvgAmount float64 `json:"avg_amount"`
|
||||
// UniqueBuyers 是买家数量。
|
||||
UniqueBuyers int `json:"unique_buyers"`
|
||||
// UniqueItems 是商品数量。
|
||||
UniqueItems int `json:"unique_items"`
|
||||
}
|
||||
|
||||
// analyticsDailyStatsResponse 是按日期聚合的订单统计 DTO。
|
||||
type analyticsDailyStatsResponse struct {
|
||||
// Date 是用户本地日期。
|
||||
Date string `json:"date"`
|
||||
// OrderCount 是当天订单数。
|
||||
OrderCount int `json:"order_count"`
|
||||
// Amount 是当天订单金额。
|
||||
Amount float64 `json:"amount"`
|
||||
}
|
||||
|
||||
// analyticsStatusStatsResponse 是按订单状态聚合的统计 DTO。
|
||||
type analyticsStatusStatsResponse struct {
|
||||
// Status 是归一化后的订单状态。
|
||||
Status string `json:"status"`
|
||||
// Count 是该状态订单数。
|
||||
Count int `json:"count"`
|
||||
// Amount 是该状态订单金额。
|
||||
Amount float64 `json:"amount"`
|
||||
}
|
||||
|
||||
// analyticsCityStatsResponse 是按收货城市聚合的统计 DTO。
|
||||
type analyticsCityStatsResponse struct {
|
||||
// City 是收货城市。
|
||||
City string `json:"city"`
|
||||
// OrderCount 是该城市订单数。
|
||||
OrderCount int `json:"order_count"`
|
||||
// TotalAmount 是该城市订单金额。
|
||||
TotalAmount float64 `json:"total_amount"`
|
||||
}
|
||||
|
||||
// analyticsItemStatsResponse 是按商品聚合的统计 DTO。
|
||||
type analyticsItemStatsResponse struct {
|
||||
// ItemID 是商品平台标识。
|
||||
ItemID string `json:"item_id"`
|
||||
// OrderCount 是该商品订单数。
|
||||
OrderCount int `json:"order_count"`
|
||||
// TotalAmount 是该商品订单金额。
|
||||
TotalAmount float64 `json:"total_amount"`
|
||||
// AvgAmount 是该商品订单平均金额。
|
||||
AvgAmount float64 `json:"avg_amount"`
|
||||
}
|
||||
|
||||
// orderAnalyticsResponse 是订单分析接口的具名响应 DTO。
|
||||
type orderAnalyticsResponse struct {
|
||||
// RevenueStats 是收益统计。
|
||||
RevenueStats analyticsRevenueStatsResponse `json:"revenue_stats"`
|
||||
// DailyStats 是按日统计。
|
||||
DailyStats []analyticsDailyStatsResponse `json:"daily_stats"`
|
||||
// StatusStats 是按状态统计。
|
||||
StatusStats []analyticsStatusStatsResponse `json:"status_stats"`
|
||||
// CityStats 是按城市统计。
|
||||
CityStats []analyticsCityStatsResponse `json:"city_stats"`
|
||||
// ItemStats 是按商品统计。
|
||||
ItemStats []analyticsItemStatsResponse `json:"item_stats"`
|
||||
}
|
||||
|
||||
// validOrderResponse 是有效订单明细项的具名响应 DTO。
|
||||
type validOrderResponse struct {
|
||||
// OrderID 是平台订单标识。
|
||||
OrderID string `json:"order_id"`
|
||||
// ItemID 是商品平台标识。
|
||||
ItemID string `json:"item_id"`
|
||||
// BuyerID 是买家平台标识。
|
||||
BuyerID string `json:"buyer_id"`
|
||||
// ItemTitle 是商品标题。
|
||||
ItemTitle string `json:"item_title"`
|
||||
// ItemImage 是商品图片地址。
|
||||
ItemImage string `json:"item_image"`
|
||||
// Quantity 是订单数量文本。
|
||||
Quantity string `json:"quantity"`
|
||||
// Amount 是订单金额文本。
|
||||
Amount string `json:"amount"`
|
||||
// OrderStatus 是兼容保留的订单状态字段。
|
||||
OrderStatus string `json:"order_status"`
|
||||
// Status 是归一化后的订单状态。
|
||||
Status string `json:"status"`
|
||||
// CookieID 是订单所属账号标识。
|
||||
CookieID string `json:"cookie_id"`
|
||||
// CreatedAt 是订单创建时间。
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
// validOrdersResponse 是有效订单分页查询的具名响应 DTO。
|
||||
type validOrdersResponse struct {
|
||||
// Orders 是当前页有效订单。
|
||||
Orders []validOrderResponse `json:"orders"`
|
||||
// Total 是符合条件的订单总数。
|
||||
Total int `json:"total"`
|
||||
// Page 是当前页码。
|
||||
Page int `json:"page"`
|
||||
// PageSize 是当前页大小。
|
||||
PageSize int `json:"page_size"`
|
||||
// Truncated 表示是否还有未返回的订单。
|
||||
Truncated bool `json:"truncated"`
|
||||
}
|
||||
|
||||
// qrLoginGenerateResponse 是扫码登录二维码生成的具名响应 DTO。
|
||||
type qrLoginGenerateResponse struct {
|
||||
// Success 表示二维码是否生成成功。
|
||||
Success bool `json:"success"`
|
||||
// SessionID 是扫码登录会话标识。
|
||||
SessionID string `json:"session_id"`
|
||||
// QRCodeURL 是二维码图片地址。
|
||||
QRCodeURL string `json:"qr_code_url"`
|
||||
// Message 是可选的提示文本。
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
Reference in new issue
Block a user