新增摸大红业务并修复后台链接按钮白字
支持分类筛选、搜索、下单支付建群与固定二维码;合并迁移种子数据;后台表格编辑/详情链接恢复主题色可见。
This commit is contained in:
@@ -0,0 +1,290 @@
|
||||
import { apiClient } from '@/shared/api/client'
|
||||
import type { ApiResponse } from '@/shared/types/types'
|
||||
import type { PaymentOrder, PaymentPayWay } from '@/features/orders/api/orders'
|
||||
|
||||
export interface MohongCategory {
|
||||
id: number
|
||||
name: string
|
||||
code: string
|
||||
sort_order: number
|
||||
status: string
|
||||
product_count: number
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface MohongProduct {
|
||||
id: number
|
||||
category_id?: number | null
|
||||
category_name?: string
|
||||
title: string
|
||||
cover_url: string
|
||||
image_urls: string[]
|
||||
description: string
|
||||
price_cent: number
|
||||
price: string
|
||||
original_price_cent: number
|
||||
original_price?: string
|
||||
unit: string
|
||||
stock: number
|
||||
sort_order: number
|
||||
status: string
|
||||
qrcode_image_url?: string
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface MohongOrder {
|
||||
id: number
|
||||
order_no: string
|
||||
user_id: number
|
||||
product_id: number
|
||||
quantity: number
|
||||
unit_price_cent: number
|
||||
unit_price: string
|
||||
amount_cent: number
|
||||
amount: string
|
||||
status: string
|
||||
product_title: string
|
||||
product_cover_url: string
|
||||
product_unit: string
|
||||
qrcode_url_snapshot: string
|
||||
copy_text: string
|
||||
conversation_id?: number | null
|
||||
buyer_nickname?: string
|
||||
buyer_phone?: string
|
||||
admin_remark?: string
|
||||
cancel_reason?: string
|
||||
paid_at?: string | null
|
||||
completed_at?: string | null
|
||||
cancelled_at?: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface MohongConfig {
|
||||
default_qrcode_url: string
|
||||
group_welcome_text: string
|
||||
order_copy_template: string
|
||||
}
|
||||
|
||||
export interface Paginated<T> {
|
||||
items: T[]
|
||||
total: number
|
||||
page: number
|
||||
page_size: number
|
||||
}
|
||||
|
||||
export async function fetchMohongCategories() {
|
||||
const { data } = await apiClient.get<ApiResponse<MohongCategory[]>>('/mohong/categories')
|
||||
return data.data || []
|
||||
}
|
||||
|
||||
export async function fetchMohongProducts(params?: {
|
||||
keyword?: string
|
||||
category_id?: number
|
||||
page?: number
|
||||
page_size?: number
|
||||
}) {
|
||||
const { data } = await apiClient.get<ApiResponse<Paginated<MohongProduct>>>('/mohong/products', {
|
||||
params,
|
||||
})
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function fetchMohongProduct(id: number | string) {
|
||||
const { data } = await apiClient.get<ApiResponse<MohongProduct>>(`/mohong/products/${id}`)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function createMohongOrder(productId: number, quantity: number) {
|
||||
const { data } = await apiClient.post<ApiResponse<MohongOrder>>('/mohong/orders', {
|
||||
product_id: productId,
|
||||
quantity,
|
||||
})
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function fetchMyMohongOrders(params?: {
|
||||
status?: string
|
||||
page?: number
|
||||
page_size?: number
|
||||
}) {
|
||||
const { data } = await apiClient.get<ApiResponse<Paginated<MohongOrder>>>('/mohong/orders', {
|
||||
params,
|
||||
})
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function fetchMyMohongOrder(id: number | string) {
|
||||
const { data } = await apiClient.get<ApiResponse<MohongOrder>>(`/mohong/orders/${id}`)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function cancelMyMohongOrder(id: number | string, reason?: string) {
|
||||
const { data } = await apiClient.post<ApiResponse<MohongOrder>>(`/mohong/orders/${id}/cancel`, {
|
||||
reason: reason || '',
|
||||
})
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function startMohongPayment(
|
||||
orderId: number,
|
||||
payWay: PaymentPayWay | string,
|
||||
jsPayFlag?: string
|
||||
) {
|
||||
const { data } = await apiClient.post<ApiResponse<PaymentOrder>>(
|
||||
`/mohong/orders/${orderId}/start-payment`,
|
||||
{
|
||||
pay_way: payWay || 'ZFBZF',
|
||||
jspay_flag: jsPayFlag || '',
|
||||
}
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function queryMohongPayment(orderId: number) {
|
||||
const { data } = await apiClient.get<ApiResponse<PaymentOrder>>(
|
||||
`/mohong/orders/${orderId}/query-payment`
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
// Admin APIs
|
||||
export async function fetchAdminMohongCategories() {
|
||||
const { data } = await apiClient.get<ApiResponse<MohongCategory[]>>('/admin/mohong/categories')
|
||||
return data.data || []
|
||||
}
|
||||
|
||||
export async function createAdminMohongCategory(payload: {
|
||||
name: string
|
||||
code?: string
|
||||
sort_order?: number
|
||||
status?: string
|
||||
}) {
|
||||
const { data } = await apiClient.post<ApiResponse<MohongCategory>>(
|
||||
'/admin/mohong/categories',
|
||||
payload
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function updateAdminMohongCategory(
|
||||
id: number,
|
||||
payload: Partial<{ name: string; code: string; sort_order: number; status: string }>
|
||||
) {
|
||||
const { data } = await apiClient.put<ApiResponse<MohongCategory>>(
|
||||
`/admin/mohong/categories/${id}`,
|
||||
payload
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function deleteAdminMohongCategory(id: number) {
|
||||
const { data } = await apiClient.delete<ApiResponse<{ message: string }>>(
|
||||
`/admin/mohong/categories/${id}`
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function fetchAdminMohongProducts(params?: {
|
||||
keyword?: string
|
||||
status?: string
|
||||
category_id?: number
|
||||
page?: number
|
||||
page_size?: number
|
||||
}) {
|
||||
const { data } = await apiClient.get<ApiResponse<Paginated<MohongProduct>>>(
|
||||
'/admin/mohong/products',
|
||||
{ params }
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function fetchAdminMohongProduct(id: number | string) {
|
||||
const { data } = await apiClient.get<ApiResponse<MohongProduct>>(`/admin/mohong/products/${id}`)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function createAdminMohongProduct(payload: Partial<MohongProduct> & { title: string; price_cent: number }) {
|
||||
const { data } = await apiClient.post<ApiResponse<MohongProduct>>('/admin/mohong/products', payload)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function updateAdminMohongProduct(id: number, payload: Record<string, unknown>) {
|
||||
const { data } = await apiClient.put<ApiResponse<MohongProduct>>(
|
||||
`/admin/mohong/products/${id}`,
|
||||
payload
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function deleteAdminMohongProduct(id: number) {
|
||||
const { data } = await apiClient.delete<ApiResponse<{ message: string }>>(
|
||||
`/admin/mohong/products/${id}`
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function fetchAdminMohongOrders(params?: {
|
||||
status?: string
|
||||
keyword?: string
|
||||
page?: number
|
||||
page_size?: number
|
||||
}) {
|
||||
const { data } = await apiClient.get<ApiResponse<Paginated<MohongOrder>>>('/admin/mohong/orders', {
|
||||
params,
|
||||
})
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function fetchAdminMohongOrder(id: number | string) {
|
||||
const { data } = await apiClient.get<ApiResponse<MohongOrder>>(`/admin/mohong/orders/${id}`)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function completeAdminMohongOrder(id: number, remark?: string) {
|
||||
const { data } = await apiClient.post<ApiResponse<MohongOrder>>(
|
||||
`/admin/mohong/orders/${id}/complete`,
|
||||
{ remark: remark || '' }
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function cancelAdminMohongOrder(id: number, reason?: string) {
|
||||
const { data } = await apiClient.post<ApiResponse<MohongOrder>>(
|
||||
`/admin/mohong/orders/${id}/cancel`,
|
||||
{ reason: reason || '' }
|
||||
)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function fetchAdminMohongConfig() {
|
||||
const { data } = await apiClient.get<ApiResponse<MohongConfig>>('/admin/mohong/config')
|
||||
return data.data
|
||||
}
|
||||
|
||||
export async function updateAdminMohongConfig(payload: Partial<MohongConfig>) {
|
||||
const { data } = await apiClient.put<ApiResponse<MohongConfig>>('/admin/mohong/config', payload)
|
||||
return data.data
|
||||
}
|
||||
|
||||
export function mohongOrderStatusLabel(status: string) {
|
||||
const map: Record<string, string> = {
|
||||
pending_payment: '待支付',
|
||||
paid: '已支付',
|
||||
completed: '已完成',
|
||||
cancelled: '已取消',
|
||||
refunded: '已退款',
|
||||
}
|
||||
return map[status] || status
|
||||
}
|
||||
|
||||
export function mohongProductStatusLabel(status: string) {
|
||||
const map: Record<string, string> = {
|
||||
draft: '草稿',
|
||||
on_sale: '上架中',
|
||||
off_sale: '已下架',
|
||||
}
|
||||
return map[status] || status
|
||||
}
|
||||
Reference in New Issue
Block a user