修复电子凭证销毁与飞飞订单金额

This commit is contained in:
yml2213
2026-07-08 19:17:01 +08:00
parent 6647e815a8
commit 487d586492
6 changed files with 111 additions and 2 deletions
@@ -1,3 +1,5 @@
import { getOrderItemById } from '../../../repositories/order-item-repo.js'
import { getOrderById } from '../../../repositories/order-repo.js'
import { createTaskEvent } from '../../../repositories/task-event-repo.js'
import { updateTask } from '../../../repositories/task-repo.js'
import { createHttpError } from '../../../utils/http.js'
@@ -59,11 +61,17 @@ export async function prepareKuaishouFeifeiTask(task: TaskRow) {
}
const platformOrderNo = flow.platformOrderNo || buildFeifeiPlatformOrderNo(task)
const order = await createKuaishouFeifeiOrder({
const platformAmount = await resolveKuaishouFeifeiTaskPlatformAmount(task)
const orderInput: Parameters<typeof createKuaishouFeifeiOrder>[0] = {
platformOrderNo,
productCode: flow.productCode,
platformBuyNum: 1,
})
}
if (platformAmount > 0) {
orderInput.platformAmount = platformAmount
}
const order = await createKuaishouFeifeiOrder(orderInput)
const feifeiClaimUrl = resolveKuaishouFeifeiOrderClaimUrl(order)
if (!feifeiClaimUrl) {
throw createHttpError('kuaishou-feifei 未返回领取链接', {
@@ -96,6 +104,7 @@ export async function prepareKuaishouFeifeiTask(task: TaskRow) {
platformOrderNo,
orderNo: order.orderNo,
productCode: flow.productCode,
platformAmount,
rechargeStatus: order.rechargeStatus,
rechargeStatusLabel: order.rechargeStatusLabel,
rechargeUrl: order.h5.rechargeUrl,
@@ -356,3 +365,36 @@ export function buildFeifeiPlatformOrderNo(task: TaskRow) {
return `OS-FEIFEI-${task.id}`
}
export async function resolveKuaishouFeifeiTaskPlatformAmount(task: TaskRow) {
const [order, orderItem] = await Promise.all([
getOrderById(task.order_id),
getOrderItemById(task.order_item_id),
])
return resolveKuaishouFeifeiPlatformAmount({
totalAmountFen: order?.total_amount,
quantity: orderItem?.quantity,
})
}
export function resolveKuaishouFeifeiPlatformAmount({
totalAmountFen,
quantity,
}: {
totalAmountFen?: unknown
quantity?: unknown
} = {}) {
const totalFen = normalizePositiveFen(totalAmountFen)
if (totalFen <= 0) {
return 0
}
const normalizedQuantity = Math.max(1, Math.trunc(Number(quantity || 1)) || 1)
return Number((totalFen / normalizedQuantity / 100).toFixed(2))
}
function normalizePositiveFen(value: unknown) {
const parsed = Number(value)
return Number.isFinite(parsed) && parsed > 0 ? Math.round(parsed) : 0
}