235 lines
6.8 KiB
TypeScript
235 lines
6.8 KiB
TypeScript
import { adminClient } from '@/shared/api/adminClient'
|
|
import type { ApiResponse } from '@/shared/api/types'
|
|
import type {
|
|
AdminCaptcha,
|
|
AdminListing,
|
|
AdminListingPage,
|
|
AdminListingQuery,
|
|
AdminLoginData,
|
|
AdminOrderDetail,
|
|
AdminOrderPage,
|
|
AdminOrderQuery,
|
|
AdminUser,
|
|
AdminUserItem,
|
|
AdminUserPage,
|
|
AdminUserQuery,
|
|
DashboardData,
|
|
} from '@/features/admin/types'
|
|
|
|
export async function fetchAdminCaptcha() {
|
|
const { data } = await adminClient.get<ApiResponse<AdminCaptcha>>('/admin/auth/captcha')
|
|
return data.data
|
|
}
|
|
|
|
export async function loginAdmin(
|
|
username: string,
|
|
password: string,
|
|
captchaId: string,
|
|
captchaCode: string
|
|
) {
|
|
const { data } = await adminClient.post<ApiResponse<AdminLoginData>>('/admin/auth/login', {
|
|
username,
|
|
password,
|
|
captcha_id: captchaId,
|
|
captcha_code: captchaCode,
|
|
})
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchAdminMe() {
|
|
const { data } = await adminClient.get<ApiResponse<AdminUser>>('/admin/me')
|
|
return data.data
|
|
}
|
|
|
|
export async function logoutAdmin() {
|
|
await adminClient.post('/admin/auth/logout')
|
|
}
|
|
|
|
export async function changeAdminPassword(oldPassword: string, newPassword: string) {
|
|
await adminClient.put('/admin/admin-users/me/password', {
|
|
old_password: oldPassword,
|
|
new_password: newPassword,
|
|
})
|
|
}
|
|
|
|
export async function fetchAdminDashboard() {
|
|
const { data } = await adminClient.get<ApiResponse<DashboardData>>('/admin/dashboard')
|
|
return data.data
|
|
}
|
|
|
|
function compactParams<T extends object>(query: T) {
|
|
return Object.fromEntries(
|
|
Object.entries(query).filter(([, value]) => value !== '' && value != null)
|
|
)
|
|
}
|
|
|
|
export async function fetchAdminOrders(query: AdminOrderQuery) {
|
|
const { data } = await adminClient.get<ApiResponse<Partial<AdminOrderPage>>>('/admin/orders', {
|
|
params: compactParams(query),
|
|
})
|
|
return {
|
|
items: data.data.items ?? [],
|
|
total: data.data.total ?? 0,
|
|
page: data.data.page ?? query.page ?? 1,
|
|
page_size: data.data.page_size ?? query.page_size ?? 20,
|
|
}
|
|
}
|
|
|
|
export async function fetchAdminOrder(id: number | string) {
|
|
const { data } = await adminClient.get<ApiResponse<AdminOrderDetail>>(`/admin/orders/${id}`)
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchAdminListings(query: AdminListingQuery) {
|
|
const { data } = await adminClient.get<ApiResponse<Partial<AdminListingPage>>>('/admin/listings', {
|
|
params: compactParams(query),
|
|
})
|
|
return {
|
|
items: data.data.items ?? [],
|
|
total: data.data.total ?? 0,
|
|
page: data.data.page ?? query.page ?? 1,
|
|
page_size: data.data.page_size ?? query.page_size ?? 20,
|
|
}
|
|
}
|
|
|
|
export async function fetchAdminListing(id: number | string) {
|
|
const { data } = await adminClient.get<ApiResponse<AdminListing>>(`/admin/listings/${id}`)
|
|
return data.data
|
|
}
|
|
|
|
/** 审核队列使用独立接口:权限为 listing:approve,且返回全部待审商品。 */
|
|
export async function fetchAdminPendingListings() {
|
|
const { data } = await adminClient.get<ApiResponse<{ items: AdminListing[] }>>(
|
|
'/admin/listings/pending'
|
|
)
|
|
return data.data.items ?? []
|
|
}
|
|
|
|
export async function approveAdminListing(id: number | string) {
|
|
const { data } = await adminClient.post<ApiResponse<AdminListing>>(`/admin/listings/${id}/approve`)
|
|
return data.data
|
|
}
|
|
|
|
export async function rejectAdminListing(id: number | string, reason: string) {
|
|
const { data } = await adminClient.post<ApiResponse<AdminListing>>(
|
|
`/admin/listings/${id}/reject`,
|
|
{ reason }
|
|
)
|
|
return data.data
|
|
}
|
|
|
|
export async function offlineAdminListing(id: number | string, reason: string) {
|
|
const { data } = await adminClient.post<ApiResponse<AdminListing>>(
|
|
`/admin/listings/${id}/offline`,
|
|
{ reason }
|
|
)
|
|
return data.data
|
|
}
|
|
|
|
export async function markAbnormalAdminListing(id: number | string, reason: string) {
|
|
const { data } = await adminClient.post<ApiResponse<AdminListing>>(
|
|
`/admin/listings/${id}/mark-abnormal`,
|
|
{ reason }
|
|
)
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchAdminUsers(query: AdminUserQuery) {
|
|
const params: Record<string, unknown> = { ...compactParams(query) }
|
|
if (query.has_deposit_free_quota) {
|
|
params.has_deposit_free_quota = true
|
|
} else {
|
|
delete params.has_deposit_free_quota
|
|
}
|
|
const { data } = await adminClient.get<ApiResponse<Partial<AdminUserPage>>>('/admin/users', {
|
|
params,
|
|
})
|
|
return {
|
|
items: data.data.items ?? [],
|
|
total: data.data.total ?? 0,
|
|
page: data.data.page ?? query.page ?? 1,
|
|
page_size: data.data.page_size ?? query.page_size ?? 20,
|
|
}
|
|
}
|
|
|
|
export async function freezeAdminUser(id: number | string, reason: string) {
|
|
const { data } = await adminClient.post<ApiResponse<AdminUserItem>>(
|
|
`/admin/users/${id}/freeze`,
|
|
{ reason }
|
|
)
|
|
return data.data
|
|
}
|
|
|
|
export async function unfreezeAdminUser(id: number | string, reason: string) {
|
|
const { data } = await adminClient.post<ApiResponse<AdminUserItem>>(
|
|
`/admin/users/${id}/unfreeze`,
|
|
{ reason }
|
|
)
|
|
return data.data
|
|
}
|
|
|
|
export async function setAdminUserDepositFreeQuota(id: number | string, amountCent: number) {
|
|
const { data } = await adminClient.post<ApiResponse<AdminUserItem>>(
|
|
`/admin/users/${id}/deposit-free-quota`,
|
|
{ amount_cent: amountCent }
|
|
)
|
|
return data.data
|
|
}
|
|
|
|
export async function adjustAdminUserGrowthPoints(
|
|
id: number | string,
|
|
targetPoints: number,
|
|
reason: string
|
|
) {
|
|
const { data } = await adminClient.post<ApiResponse<AdminUserItem>>(
|
|
`/admin/users/${id}/growth-points`,
|
|
{ target_points: targetPoints, reason }
|
|
)
|
|
return data.data
|
|
}
|
|
|
|
export async function manualAdminUserRealname(
|
|
id: number | string,
|
|
payload: { name: string; id_no: string; reason: string }
|
|
) {
|
|
const { data } = await adminClient.post<ApiResponse<AdminUserItem>>(
|
|
`/admin/users/${id}/manual-realname`,
|
|
payload
|
|
)
|
|
return data.data
|
|
}
|
|
|
|
export async function revokeAdminUserRealname(id: number | string, reason: string) {
|
|
const { data } = await adminClient.post<ApiResponse<AdminUserItem>>(
|
|
`/admin/users/${id}/revoke-realname`,
|
|
{ reason }
|
|
)
|
|
return data.data
|
|
}
|
|
|
|
export async function adjustAdminUserWallet(
|
|
id: number | string,
|
|
payload: { direction: 'in' | 'out'; amount_cent: number; reason: string; reference_no?: string }
|
|
) {
|
|
const { data } = await adminClient.post<ApiResponse<AdminUserItem>>(
|
|
`/admin/users/${id}/wallet/adjust`,
|
|
payload
|
|
)
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchPendingRefundOrders() {
|
|
const { data } = await adminClient.get<ApiResponse<{ items: AdminOrderDetail[] }>>(
|
|
'/admin/orders/refund-pending'
|
|
)
|
|
return data.data.items ?? []
|
|
}
|
|
|
|
export async function approveAdminRefund(id: number | string) {
|
|
await adminClient.post(`/admin/orders/${id}/refund/approve`)
|
|
}
|
|
|
|
export async function rejectAdminRefund(id: number | string, action: 'restore' | 'close') {
|
|
await adminClient.post(`/admin/orders/${id}/refund/reject`, { action })
|
|
}
|