75 lines
1.8 KiB
TypeScript
75 lines
1.8 KiB
TypeScript
"use server"
|
|
|
|
import type { PageRecord } from "@/lib/api"
|
|
import type { Product } from "@/models/product"
|
|
import type { ProductSku } from "@/models/product_sku"
|
|
import { callByUser } from "./base"
|
|
|
|
export async function getAllProduct() {
|
|
return callByUser<Product[]>("/api/admin/product/all")
|
|
}
|
|
|
|
export async function getPageProductSku(params: {
|
|
page: number
|
|
size: number
|
|
product_id?: number
|
|
}) {
|
|
return callByUser<PageRecord<ProductSku>>(
|
|
"/api/admin/product/sku/page",
|
|
params,
|
|
)
|
|
}
|
|
|
|
export async function createProductSku(data: {
|
|
product_id: number
|
|
code: string
|
|
name: string
|
|
price: string
|
|
discount_id?: number
|
|
price_min?: string
|
|
}) {
|
|
return callByUser<ProductSku>("/api/admin/product/sku/create", {
|
|
product_id: data.product_id,
|
|
code: data.code,
|
|
name: data.name,
|
|
price: data.price,
|
|
discount_id: data.discount_id,
|
|
price_min: data.price_min,
|
|
})
|
|
}
|
|
|
|
export async function updateProductSku(data: {
|
|
id: number
|
|
code?: string
|
|
name?: string
|
|
price?: string
|
|
discount_id?: number | null
|
|
price_min?: string
|
|
}) {
|
|
return callByUser<ProductSku>("/api/admin/product/sku/update", {
|
|
id: data.id,
|
|
code: data.code,
|
|
name: data.name,
|
|
price: data.price,
|
|
discount_id: data.discount_id,
|
|
price_min: data.price_min,
|
|
})
|
|
}
|
|
|
|
export async function deleteProductSku(id: number) {
|
|
return callByUser<ProductSku>("/api/admin/product/sku/remove", { id })
|
|
}
|
|
|
|
export async function batchUpdateProductSkuDiscount(data: {
|
|
product_id: number
|
|
discount_id: number | null
|
|
}) {
|
|
return callByUser<void>("/api/admin/product/sku/update/discount/batch", {
|
|
product_id: data.product_id,
|
|
discount_id: data.discount_id,
|
|
})
|
|
}
|
|
export async function activeProductSku(data: { id: number; status: number }) {
|
|
return callByUser<ProductSku>("/api/admin/product/sku/update/status", data)
|
|
}
|