完善接单平台上传与物品规则
This commit is contained in:
@@ -4,11 +4,7 @@ import type {
|
||||
OrderListQueryInput,
|
||||
OrderUpdateInput,
|
||||
} from '../types/repository/inputs.js'
|
||||
import type {
|
||||
OrderListQueryResult,
|
||||
OrderListRow,
|
||||
OrderRow,
|
||||
} from '../types/repository/rows.js'
|
||||
import type { OrderListQueryResult, OrderListRow, OrderRow } from '../types/repository/rows.js'
|
||||
|
||||
type OrderPlatformLookupInput = {
|
||||
provider?: string
|
||||
@@ -55,6 +51,23 @@ export async function findLatestOrderByPlatformOrderId({
|
||||
return result.rows[0] || null
|
||||
}
|
||||
|
||||
export async function findLatestOrderByAnyPlatformOrderId(
|
||||
platformOrderId: string,
|
||||
): Promise<OrderRow | null> {
|
||||
const result = await query<OrderRow>(
|
||||
`
|
||||
SELECT *
|
||||
FROM orders
|
||||
WHERE platform_order_id = $1
|
||||
ORDER BY id DESC
|
||||
LIMIT 1
|
||||
`,
|
||||
[String(platformOrderId || '').trim()],
|
||||
)
|
||||
|
||||
return result.rows[0] || null
|
||||
}
|
||||
|
||||
export async function createOrder(input: OrderCreateInput): Promise<OrderRow | null> {
|
||||
const result = await query<OrderRow>(
|
||||
`
|
||||
@@ -101,7 +114,10 @@ export async function createOrder(input: OrderCreateInput): Promise<OrderRow | n
|
||||
return result.rows[0] || null
|
||||
}
|
||||
|
||||
export async function updateOrder(orderId: number | string, input: OrderUpdateInput): Promise<OrderRow | null> {
|
||||
export async function updateOrder(
|
||||
orderId: number | string,
|
||||
input: OrderUpdateInput,
|
||||
): Promise<OrderRow | null> {
|
||||
const result = await query<OrderRow>(
|
||||
`
|
||||
UPDATE orders
|
||||
@@ -146,7 +162,9 @@ export async function updateOrder(orderId: number | string, input: OrderUpdateIn
|
||||
}
|
||||
|
||||
export async function getOrderById(orderId: number | string): Promise<OrderRow | null> {
|
||||
const result = await query<OrderRow>('SELECT * FROM orders WHERE id = $1 LIMIT 1', [Number(orderId)])
|
||||
const result = await query<OrderRow>('SELECT * FROM orders WHERE id = $1 LIMIT 1', [
|
||||
Number(orderId),
|
||||
])
|
||||
return result.rows[0] || null
|
||||
}
|
||||
|
||||
@@ -175,7 +193,9 @@ export async function listOrders({
|
||||
|
||||
if (skuCode) {
|
||||
params.push(skuCode)
|
||||
filters.push(`EXISTS (SELECT 1 FROM order_items oi WHERE oi.order_id = o.id AND oi.sku_code = $${params.length})`)
|
||||
filters.push(
|
||||
`EXISTS (SELECT 1 FROM order_items oi WHERE oi.order_id = o.id AND oi.sku_code = $${params.length})`,
|
||||
)
|
||||
}
|
||||
|
||||
if (dateFrom) {
|
||||
@@ -189,7 +209,7 @@ export async function listOrders({
|
||||
}
|
||||
|
||||
const whereClause = filters.length > 0 ? `WHERE ${filters.join(' AND ')}` : ''
|
||||
const totalResult = await query<{ [column: string]: unknown, total: number }>(
|
||||
const totalResult = await query<{ [column: string]: unknown; total: number }>(
|
||||
`SELECT COUNT(*)::int AS total FROM orders o ${whereClause}`,
|
||||
params,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user