发送消息ok

This commit is contained in:
yml
2026-04-12 13:48:32 +08:00
parent 0029147bc4
commit 381d18f3c9
11 changed files with 608 additions and 4 deletions
@@ -115,3 +115,92 @@ export async function findLatestSuccessfulMessageDeliveryByTask(taskId, channel)
return result.rows[0] || null
}
export async function listMessageDeliveries({
page = 1,
pageSize = 20,
provider = '',
platform = '',
status = '',
shopId = '',
platformOrderId = '',
taskNo = '',
dateFrom = '',
dateTo = '',
} = {}) {
const offset = (page - 1) * pageSize
const filters = []
const params = []
if (provider) {
params.push(provider)
filters.push(`md.provider = $${params.length}`)
}
if (platform) {
params.push(platform)
filters.push(`md.platform = $${params.length}`)
}
if (status) {
params.push(status)
filters.push(`md.status = $${params.length}`)
}
if (shopId) {
params.push(shopId)
filters.push(`md.shop_id = $${params.length}`)
}
if (platformOrderId) {
params.push(`%${platformOrderId}%`)
filters.push(`md.platform_order_id ILIKE $${params.length}`)
}
if (taskNo) {
params.push(`%${taskNo}%`)
filters.push(`ft.task_no ILIKE $${params.length}`)
}
if (dateFrom) {
params.push(dateFrom)
filters.push(`md.created_at >= $${params.length}`)
}
if (dateTo) {
params.push(dateTo)
filters.push(`md.created_at <= $${params.length}`)
}
const whereClause = filters.length > 0 ? `WHERE ${filters.join(' AND ')}` : ''
const fromClause = `
FROM message_deliveries md
LEFT JOIN fulfillment_tasks ft ON ft.id = md.task_id
`
const totalResult = await query(
`SELECT COUNT(*)::int AS total ${fromClause} ${whereClause}`,
params,
)
params.push(pageSize)
params.push(offset)
const itemsResult = await query(
`
SELECT
md.*,
ft.task_no,
ft.task_status
${fromClause}
${whereClause}
ORDER BY md.id DESC
LIMIT $${params.length - 1} OFFSET $${params.length}
`,
params,
)
return {
items: itemsResult.rows,
total: Number(totalResult.rows[0]?.total || 0),
}
}