新增快手电子凭证后台工具

This commit is contained in:
yml2213
2026-07-09 18:39:34 +08:00
parent 1bfb32dcd0
commit c61078d3f6
29 changed files with 3034 additions and 474 deletions
@@ -13,6 +13,16 @@ type VoucherPatchColumn = {
cast?: string
}
export type KuaishouIndustryVoucherAdminListQuery = {
oid?: string
voucherCode?: string
taskId?: number | string
sellerId?: string
status?: string
page?: number | string
pageSize?: number | string
}
const VOUCHER_CODE_PREFIX = 'KSV'
const VOUCHER_CODE_RANDOM_BYTES = 10
const VOUCHER_CODE_MAX_GENERATE_ATTEMPTS = 5
@@ -217,6 +227,75 @@ export async function listKuaishouIndustryVouchersByTaskId(
return result.rows
}
export async function listKuaishouIndustryVouchersForAdmin(
input: KuaishouIndustryVoucherAdminListQuery = {},
): Promise<{ items: KuaishouIndustryVoucherRow[]; total: number; page: number; pageSize: number }> {
const page = normalizePositiveLimit(input.page, 1)
const pageSize = Math.min(normalizePositiveLimit(input.pageSize, 50), 200)
const where: string[] = []
const params: unknown[] = []
const oid = String(input.oid || '').trim()
if (oid) {
params.push(oid)
where.push(`oid = $${params.length}`)
}
const voucherCode = String(input.voucherCode || '').trim()
if (voucherCode) {
params.push(Array.from(new Set([voucherCode, voucherCode.toUpperCase()])))
where.push(`voucher_code = ANY($${params.length}::text[])`)
}
const taskId = Number(input.taskId || 0)
if (Number.isFinite(taskId) && taskId > 0) {
params.push(Math.trunc(taskId))
where.push(`task_id = $${params.length}`)
}
const sellerId = String(input.sellerId || '').trim()
if (sellerId) {
params.push(sellerId)
where.push(`seller_id = $${params.length}`)
}
const status = String(input.status || '').trim().toUpperCase()
if (status) {
params.push(status)
where.push(`status = $${params.length}`)
}
const whereSql = where.length > 0 ? `WHERE ${where.join(' AND ')}` : ''
const totalResult = await query<{ total: string | number }>(
`
SELECT COUNT(*) AS total
FROM kuaishou_industry_vouchers
${whereSql}
`,
params,
)
const listParams = [...params, pageSize, (page - 1) * pageSize]
const listResult = await query<KuaishouIndustryVoucherRow>(
`
SELECT *
FROM kuaishou_industry_vouchers
${whereSql}
ORDER BY updated_at DESC, id DESC
LIMIT $${params.length + 1}
OFFSET $${params.length + 2}
`,
listParams,
)
return {
items: listResult.rows,
total: Number(totalResult.rows[0]?.total || 0) || 0,
page,
pageSize,
}
}
export async function findKuaishouIndustryVoucherByCode(
voucherCode: string,
oid = '',