feat: 查积分、支付、拆弹、取消订单
This commit is contained in:
@@ -1,11 +1,69 @@
|
||||
import type { Context } from '@netlify/functions'
|
||||
import { guardMethod } from '../utils/method.js'
|
||||
import { ok } from '../utils/http.js'
|
||||
import { prisma } from '../utils/prisma.js'
|
||||
import { withErrorBoundary } from '../utils/handler.js'
|
||||
|
||||
const categories = [
|
||||
{ id: 'recommend', name: '推荐' },
|
||||
{ id: 'homeLiving', name: '居家生活' },
|
||||
{ id: 'digitalAppliance', name: '数码家电' },
|
||||
{ id: 'beautyCare', name: '美妆个护' },
|
||||
{ id: 'foodDrink', name: '食品饮料' },
|
||||
{ id: 'motherBaby', name: '母婴玩具' },
|
||||
{ id: 'fashionBag', name: '服饰鞋包' },
|
||||
{ id: 'sportsOutdoor', name: '运动户外' }
|
||||
]
|
||||
|
||||
const toProductItem = (product: Awaited<ReturnType<typeof prisma.supplierProduct.findMany>>[number]) => {
|
||||
const picInfo = Array.isArray(product.picInfo) ? product.picInfo : []
|
||||
const image = product.imageUrl || String(picInfo[0] || '')
|
||||
const price = product.price.toFixed(2)
|
||||
|
||||
return {
|
||||
id: product.id,
|
||||
sku: product.sku,
|
||||
number: product.number,
|
||||
price,
|
||||
name: product.name,
|
||||
taxRate: Number(product.taxRate),
|
||||
picInfo,
|
||||
desc: product.description || '',
|
||||
detail: product.detail || product.description || '',
|
||||
originPrice: product.originPrice ? product.originPrice.toFixed(2) : price,
|
||||
image,
|
||||
imageUrl: image,
|
||||
categoryId: product.categoryId || '',
|
||||
category: product.category || '',
|
||||
tag: product.tag || '',
|
||||
sales: product.sales || '',
|
||||
stock: product.stock
|
||||
}
|
||||
}
|
||||
|
||||
export default withErrorBoundary(async (request: Request, _context: Context) => {
|
||||
const methodResponse = guardMethod(request, ['GET'])
|
||||
if (methodResponse) return methodResponse
|
||||
|
||||
return ok({ message: '商品列表接口待实现' })
|
||||
const url = new URL(request.url)
|
||||
const keyword = (url.searchParams.get('keyword') || '').trim()
|
||||
const categoryId = (url.searchParams.get('categoryId') || '').trim()
|
||||
|
||||
const products = await prisma.supplierProduct.findMany({
|
||||
where: {
|
||||
enabled: true,
|
||||
deleted: 0,
|
||||
...(keyword ? { name: { contains: keyword } } : {}),
|
||||
...(categoryId && categoryId !== 'recommend' ? { categoryId } : {})
|
||||
},
|
||||
orderBy: [
|
||||
{ sortOrder: 'asc' },
|
||||
{ createdAt: 'desc' }
|
||||
]
|
||||
})
|
||||
|
||||
return ok({
|
||||
categories,
|
||||
products: products.map(toProductItem)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user