69 lines
1.6 KiB
Plaintext
69 lines
1.6 KiB
Plaintext
import { rpcOrNull, rpcOrValue } from '@/services/analytics/rpc.uts'
|
|
|
|
export type AdminProduct = {
|
|
id: string
|
|
name: string
|
|
image: string
|
|
price: number
|
|
stock: number
|
|
sales: number
|
|
status: number
|
|
created_at: string
|
|
category_name: string
|
|
}
|
|
|
|
export type ProductPageResult = {
|
|
total: number
|
|
items: Array<AdminProduct>
|
|
}
|
|
|
|
/**
|
|
* 分页获取商品列表
|
|
*/
|
|
export async function fetchAdminProductPage(
|
|
page: number,
|
|
pageSize: number,
|
|
filters: {
|
|
name?: string,
|
|
status?: number,
|
|
categoryId?: string
|
|
}
|
|
): Promise<ProductPageResult> {
|
|
const res = await rpcOrNull('rpc_admin_product_list', {
|
|
p_page: page,
|
|
p_page_size: pageSize,
|
|
p_name: filters.name ?? null,
|
|
p_status: filters.status ?? null,
|
|
p_category_id: filters.categoryId ?? null
|
|
} as UTSJSONObject)
|
|
|
|
if (res == null) {
|
|
return { total: 0, items: [] as Array<AdminProduct> }
|
|
}
|
|
|
|
const anyTotal = (res as any).total
|
|
const anyItems = (res as any).items
|
|
|
|
return {
|
|
total: typeof anyTotal === 'number' ? anyTotal : 0,
|
|
items: Array.isArray(anyItems) ? anyItems : [] as Array<AdminProduct>
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 更新商品状态 (上架/下架/回收站)
|
|
* @param status 1:上架 2:下架 3:草稿 4:删除
|
|
*/
|
|
export async function updateAdminProductStatus(productId: string, status: number): Promise<boolean> {
|
|
try {
|
|
const ok = await rpcOrValue('rpc_admin_product_update_status', {
|
|
p_product_id: productId,
|
|
p_status: status
|
|
} as UTSJSONObject)
|
|
return ok === true
|
|
} catch (e: any) {
|
|
console.error('更新商品状态失败:', e)
|
|
return false
|
|
}
|
|
}
|