86 lines
2.7 KiB
Plaintext
86 lines
2.7 KiB
Plaintext
import { rpcOrValue } from '@/services/analytics/rpc.uts'
|
|
import supa from '@/components/supadb/aksupainstance.uts'
|
|
|
|
export type ProductReviewItem = {
|
|
id: string
|
|
product_id: string
|
|
product_name: string
|
|
product_image: string | null
|
|
user_id: string
|
|
username: string | null
|
|
rating: number
|
|
content: string | null
|
|
merchant_reply: string | null
|
|
status: number
|
|
created_at: string
|
|
total_count: number
|
|
}
|
|
|
|
export type ProductReviewQuery = {
|
|
searchProduct?: string | null
|
|
searchUser?: string | null
|
|
status?: number | null
|
|
startTime?: string | null
|
|
endTime?: string | null
|
|
page?: number
|
|
pageSize?: number
|
|
}
|
|
|
|
export async function fetchAdminProductReviews(query?: ProductReviewQuery): Promise<{ total: number; items: Array<ProductReviewItem> }> {
|
|
const payload = {
|
|
p_search_product: query?.searchProduct ?? null,
|
|
p_search_user: query?.searchUser ?? null,
|
|
p_status: query?.status ?? null,
|
|
p_start_time: query?.startTime ?? null,
|
|
p_end_time: query?.endTime ?? null,
|
|
p_page: query?.page ?? 1,
|
|
p_page_size: query?.pageSize ?? 20
|
|
} as any
|
|
|
|
const res = await rpcOrValue('rpc_admin_get_product_reviews', payload as any)
|
|
const arr = Array.isArray(res) ? (res as Array<any>) : ([] as Array<any>)
|
|
const total = arr.length > 0 ? parseInt(String(arr[0]?.total_count ?? '0')) : 0
|
|
return { total, items: arr as Array<ProductReviewItem> }
|
|
}
|
|
|
|
export async function approveProductReview(id: string): Promise<boolean> {
|
|
const { error } = await supa.from('ml_product_reviews').update({ status: 1, updated_at: new Date().toISOString() }).eq('id', id).execute()
|
|
if (error != null) {
|
|
console.error('审核通过失败:', error)
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
export async function rejectProductReview(id: string): Promise<boolean> {
|
|
const { error } = await supa.from('ml_product_reviews').update({ status: 3, updated_at: new Date().toISOString() }).eq('id', id).execute()
|
|
if (error != null) {
|
|
console.error('审核驳回/隐藏失败:', error)
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
export async function replyProductReview(id: string, reply: string): Promise<boolean> {
|
|
const { error } = await supa
|
|
.from('ml_product_reviews')
|
|
.update({ merchant_reply: reply, merchant_replied_at: new Date().toISOString(), updated_at: new Date().toISOString() })
|
|
.eq('id', id)
|
|
.execute()
|
|
|
|
if (error != null) {
|
|
console.error('回复失败:', error)
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
export async function deleteProductReview(id: string): Promise<boolean> {
|
|
const { error } = await supa.from('ml_product_reviews').update({ status: 2, updated_at: new Date().toISOString() }).eq('id', id).execute()
|
|
if (error != null) {
|
|
console.error('删除失败:', error)
|
|
return false
|
|
}
|
|
return true
|
|
}
|