refactor(types): align entity types with backend API responses
Adjust all entity types to match actual backend response shapes. String-typed numeric fields (Shop.rating, Shop.commissionValue, WalletTransaction.amount) now correctly typed as strings. Post.linkedOrderId changed from SnowflakeId to number (backend int64). Removed fields absent from backend: Order consumer/player/shopName, Review fromUserAvatar/toUserId, Dispute initiatorId/initiatorName, Post authorRole/quotedPostId, Comment postId, ChatSession readonly/lastMessageAt, ChatMessage senderName/senderAvatar. Added Player.gender field.
This commit is contained in:
@@ -19,15 +19,17 @@ export function calculateOrderIncome(totalPrice: number, shop?: ShopCommission):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const commission = Number(shop.commissionValue)
|
||||||
|
|
||||||
if (shop.commissionType === "percentage") {
|
if (shop.commissionType === "percentage") {
|
||||||
return {
|
return {
|
||||||
income: roundCurrency(totalPrice * (1 - shop.commissionValue / 100)),
|
income: roundCurrency(totalPrice * (1 - commission / 100)),
|
||||||
commissionLabel: `扣除${shop.commissionValue}%抽成`,
|
commissionLabel: `扣除${shop.commissionValue}%抽成`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
income: roundCurrency(Math.max(0, totalPrice - shop.commissionValue)),
|
income: roundCurrency(Math.max(0, totalPrice - commission)),
|
||||||
commissionLabel: `扣除¥${shop.commissionValue}固定抽成`,
|
commissionLabel: `扣除¥${shop.commissionValue}固定抽成`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ export function searchCatalog(
|
|||||||
__index: nextIndex++,
|
__index: nextIndex++,
|
||||||
type: "shop",
|
type: "shop",
|
||||||
shop,
|
shop,
|
||||||
rating: shop.rating,
|
rating: Number(shop.rating),
|
||||||
orders: shop.totalOrders,
|
orders: shop.totalOrders,
|
||||||
minPrice: derived.minPrice,
|
minPrice: derived.minPrice,
|
||||||
unit: derived.unit,
|
unit: derived.unit,
|
||||||
@@ -148,7 +148,7 @@ export function searchCatalog(
|
|||||||
if (item.type === "player") {
|
if (item.type === "player") {
|
||||||
if (item.player.rating < minRating) return false
|
if (item.player.rating < minRating) return false
|
||||||
} else {
|
} else {
|
||||||
if (item.shop.rating < minRating) return false
|
if (Number(item.shop.rating) < minRating) return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|||||||
+16
-24
@@ -9,7 +9,6 @@ export type VerificationStatus = "pending" | "approved" | "rejected"
|
|||||||
export interface User {
|
export interface User {
|
||||||
id: SnowflakeId
|
id: SnowflakeId
|
||||||
username: string
|
username: string
|
||||||
email?: string
|
|
||||||
nickname: string
|
nickname: string
|
||||||
avatar: string
|
avatar: string
|
||||||
role: UserRole
|
role: UserRole
|
||||||
@@ -24,7 +23,7 @@ export interface Game {
|
|||||||
id: SnowflakeId
|
id: SnowflakeId
|
||||||
name: string
|
name: string
|
||||||
icon: string
|
icon: string
|
||||||
category: "MOBA" | "FPS" | "动作" | "RPG"
|
category: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PlayerService {
|
export interface PlayerService {
|
||||||
@@ -51,6 +50,7 @@ export interface Player {
|
|||||||
services: PlayerService[]
|
services: PlayerService[]
|
||||||
shopId?: SnowflakeId
|
shopId?: SnowflakeId
|
||||||
shopName?: string
|
shopName?: string
|
||||||
|
gender: boolean
|
||||||
tags: string[]
|
tags: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,11 +60,11 @@ export interface Shop {
|
|||||||
name: string
|
name: string
|
||||||
banner?: string
|
banner?: string
|
||||||
description: string
|
description: string
|
||||||
rating: number
|
rating: string
|
||||||
totalOrders: number
|
totalOrders: number
|
||||||
playerCount: number
|
playerCount: number
|
||||||
commissionType: "fixed" | "percentage"
|
commissionType: "fixed" | "percentage"
|
||||||
commissionValue: number
|
commissionValue: string
|
||||||
allowMultiShop: boolean
|
allowMultiShop: boolean
|
||||||
allowIndependentOrders: boolean
|
allowIndependentOrders: boolean
|
||||||
dispatchMode: "manual" | "auto"
|
dispatchMode: "manual" | "auto"
|
||||||
@@ -95,18 +95,14 @@ export type OrderStatus =
|
|||||||
export interface Order {
|
export interface Order {
|
||||||
id: SnowflakeId
|
id: SnowflakeId
|
||||||
consumerId: SnowflakeId
|
consumerId: SnowflakeId
|
||||||
consumerName: string
|
|
||||||
playerId: SnowflakeId
|
playerId: SnowflakeId
|
||||||
playerName: string
|
|
||||||
shopId?: SnowflakeId
|
shopId?: SnowflakeId
|
||||||
shopName?: string
|
|
||||||
service: PlayerService
|
service: PlayerService
|
||||||
status: OrderStatus
|
status: OrderStatus
|
||||||
totalPrice: number
|
totalPrice: number
|
||||||
note?: string
|
note?: string
|
||||||
createdAt: string
|
createdAt: string
|
||||||
acceptedAt?: string
|
acceptedAt?: string
|
||||||
closedAt?: string
|
|
||||||
completedAt?: string
|
completedAt?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,10 +111,8 @@ export interface Review {
|
|||||||
orderId: SnowflakeId
|
orderId: SnowflakeId
|
||||||
fromUserId: SnowflakeId
|
fromUserId: SnowflakeId
|
||||||
fromUserName: string
|
fromUserName: string
|
||||||
fromUserAvatar: string
|
|
||||||
toUserId: SnowflakeId
|
|
||||||
rating: number
|
rating: number
|
||||||
content?: string
|
content: string
|
||||||
sealed: boolean
|
sealed: boolean
|
||||||
createdAt: string
|
createdAt: string
|
||||||
}
|
}
|
||||||
@@ -126,8 +120,6 @@ export interface Review {
|
|||||||
export interface Dispute {
|
export interface Dispute {
|
||||||
id: SnowflakeId
|
id: SnowflakeId
|
||||||
orderId: SnowflakeId
|
orderId: SnowflakeId
|
||||||
initiatorId: SnowflakeId
|
|
||||||
initiatorName: string
|
|
||||||
reason: string
|
reason: string
|
||||||
evidence: string[]
|
evidence: string[]
|
||||||
status: "open" | "reviewing" | "resolved" | "appealed"
|
status: "open" | "reviewing" | "resolved" | "appealed"
|
||||||
@@ -135,13 +127,17 @@ export interface Dispute {
|
|||||||
createdAt: string
|
createdAt: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ChatParticipant {
|
||||||
|
id: SnowflakeId
|
||||||
|
nickname: string
|
||||||
|
avatar: string
|
||||||
|
}
|
||||||
|
|
||||||
interface BaseChatSession {
|
interface BaseChatSession {
|
||||||
id: SnowflakeId
|
id: SnowflakeId
|
||||||
participants: { id: SnowflakeId; name: string; avatar: string }[]
|
participants: ChatParticipant[]
|
||||||
lastMessage?: string
|
lastMessage?: string
|
||||||
lastMessageAt?: string
|
|
||||||
unreadCount: number
|
unreadCount: number
|
||||||
readonly: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface OrderChatSession extends BaseChatSession {
|
export interface OrderChatSession extends BaseChatSession {
|
||||||
@@ -160,8 +156,6 @@ export interface ChatMessage {
|
|||||||
id: SnowflakeId
|
id: SnowflakeId
|
||||||
sessionId: SnowflakeId
|
sessionId: SnowflakeId
|
||||||
senderId: SnowflakeId
|
senderId: SnowflakeId
|
||||||
senderName: string
|
|
||||||
senderAvatar: string
|
|
||||||
type: "text" | "image" | "system"
|
type: "text" | "image" | "system"
|
||||||
content: string
|
content: string
|
||||||
createdAt: string
|
createdAt: string
|
||||||
@@ -170,23 +164,20 @@ export interface ChatMessage {
|
|||||||
export interface Post {
|
export interface Post {
|
||||||
id: SnowflakeId
|
id: SnowflakeId
|
||||||
author: User
|
author: User
|
||||||
authorRole: UserRole
|
|
||||||
title: string
|
title: string
|
||||||
content: string
|
content: string
|
||||||
images: string[]
|
images: string[]
|
||||||
tags: string[]
|
tags: string[]
|
||||||
linkedOrderId?: SnowflakeId
|
linkedOrderId?: number
|
||||||
quotedPostId?: SnowflakeId
|
pinned: boolean
|
||||||
likeCount: number
|
likeCount: number
|
||||||
commentCount: number
|
commentCount: number
|
||||||
liked: boolean
|
liked: boolean
|
||||||
pinned: boolean
|
|
||||||
createdAt: string
|
createdAt: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Comment {
|
export interface Comment {
|
||||||
id: SnowflakeId
|
id: SnowflakeId
|
||||||
postId: SnowflakeId
|
|
||||||
author: User
|
author: User
|
||||||
content: string
|
content: string
|
||||||
likeCount: number
|
likeCount: number
|
||||||
@@ -207,8 +198,9 @@ export interface Notification {
|
|||||||
export interface WalletTransaction {
|
export interface WalletTransaction {
|
||||||
id: SnowflakeId
|
id: SnowflakeId
|
||||||
type: "topup" | "payment" | "income" | "withdrawal" | "refund"
|
type: "topup" | "payment" | "income" | "withdrawal" | "refund"
|
||||||
amount: number
|
amount: string
|
||||||
description: string
|
description: string
|
||||||
|
orderId?: string
|
||||||
createdAt: string
|
createdAt: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ describe("calculateOrderIncome", () => {
|
|||||||
it("calculates percentage commission income", () => {
|
it("calculates percentage commission income", () => {
|
||||||
const result = calculateOrderIncome(100, {
|
const result = calculateOrderIncome(100, {
|
||||||
commissionType: "percentage",
|
commissionType: "percentage",
|
||||||
commissionValue: 12,
|
commissionValue: "12",
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
@@ -17,7 +17,7 @@ describe("calculateOrderIncome", () => {
|
|||||||
it("calculates fixed commission income", () => {
|
it("calculates fixed commission income", () => {
|
||||||
const result = calculateOrderIncome(60, {
|
const result = calculateOrderIncome(60, {
|
||||||
commissionType: "fixed",
|
commissionType: "fixed",
|
||||||
commissionValue: 8,
|
commissionValue: "8",
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
@@ -38,7 +38,7 @@ describe("calculateOrderIncome", () => {
|
|||||||
it("does not return negative income for fixed commission", () => {
|
it("does not return negative income for fixed commission", () => {
|
||||||
const result = calculateOrderIncome(6, {
|
const result = calculateOrderIncome(6, {
|
||||||
commissionType: "fixed",
|
commissionType: "fixed",
|
||||||
commissionValue: 8,
|
commissionValue: "8",
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result.income).toBe(0)
|
expect(result.income).toBe(0)
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ const players: SearchCatalogData["players"] = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
shopId: "3002",
|
shopId: "3002",
|
||||||
|
gender: true,
|
||||||
tags: ["moba"],
|
tags: ["moba"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -65,6 +66,7 @@ const players: SearchCatalogData["players"] = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
shopId: "3003",
|
shopId: "3003",
|
||||||
|
gender: true,
|
||||||
tags: [],
|
tags: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -96,6 +98,7 @@ const players: SearchCatalogData["players"] = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
shopId: "3001",
|
shopId: "3001",
|
||||||
|
gender: false,
|
||||||
tags: ["fps"],
|
tags: ["fps"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -127,6 +130,7 @@ const players: SearchCatalogData["players"] = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
shopId: "3003",
|
shopId: "3003",
|
||||||
|
gender: true,
|
||||||
tags: [],
|
tags: [],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -144,13 +148,13 @@ const shops: SearchCatalogData["shops"] = [
|
|||||||
},
|
},
|
||||||
name: "CS2 Hub",
|
name: "CS2 Hub",
|
||||||
description: "",
|
description: "",
|
||||||
rating: 4.6,
|
rating: "4.6",
|
||||||
totalOrders: 300,
|
totalOrders: 300,
|
||||||
playerCount: 1,
|
playerCount: 1,
|
||||||
commissionType: "fixed",
|
commissionType: "fixed",
|
||||||
commissionValue: 0,
|
commissionValue: "0",
|
||||||
allowMultiShop: false,
|
allowMultiShop: false,
|
||||||
allowIndependentOrders: true,
|
allowIndependentOrders: false,
|
||||||
dispatchMode: "manual",
|
dispatchMode: "manual",
|
||||||
announcements: [],
|
announcements: [],
|
||||||
templateConfig: { sections: [] },
|
templateConfig: { sections: [] },
|
||||||
@@ -167,13 +171,13 @@ const shops: SearchCatalogData["shops"] = [
|
|||||||
},
|
},
|
||||||
name: "Yuki Studio",
|
name: "Yuki Studio",
|
||||||
description: "",
|
description: "",
|
||||||
rating: 4.2,
|
rating: "4.2",
|
||||||
totalOrders: 50,
|
totalOrders: 50,
|
||||||
playerCount: 1,
|
playerCount: 1,
|
||||||
commissionType: "fixed",
|
commissionType: "fixed",
|
||||||
commissionValue: 0,
|
commissionValue: "0",
|
||||||
allowMultiShop: false,
|
allowMultiShop: false,
|
||||||
allowIndependentOrders: true,
|
allowIndependentOrders: false,
|
||||||
dispatchMode: "manual",
|
dispatchMode: "manual",
|
||||||
announcements: [],
|
announcements: [],
|
||||||
templateConfig: { sections: [] },
|
templateConfig: { sections: [] },
|
||||||
@@ -190,13 +194,13 @@ const shops: SearchCatalogData["shops"] = [
|
|||||||
},
|
},
|
||||||
name: "Quiet Shop",
|
name: "Quiet Shop",
|
||||||
description: "",
|
description: "",
|
||||||
rating: 3.8,
|
rating: "3.8",
|
||||||
totalOrders: 10,
|
totalOrders: 10,
|
||||||
playerCount: 2,
|
playerCount: 2,
|
||||||
commissionType: "fixed",
|
commissionType: "fixed",
|
||||||
commissionValue: 0,
|
commissionValue: "0",
|
||||||
allowMultiShop: false,
|
allowMultiShop: false,
|
||||||
allowIndependentOrders: true,
|
allowIndependentOrders: false,
|
||||||
dispatchMode: "manual",
|
dispatchMode: "manual",
|
||||||
announcements: [],
|
announcements: [],
|
||||||
templateConfig: { sections: [] },
|
templateConfig: { sections: [] },
|
||||||
|
|||||||
Reference in New Issue
Block a user