Update:任务台订单过滤按 contract_tpl_type 拆分支

- 先用后付分支:仅取 contract_tpl_type=3 的增值先用后付订单
- 普通任务分支:追加 contract_tpl_type=2 的套餐先用后付主订单
- latestOrderFilter 同步纳入两类订单的「较新订单」比较
- 修正 06fb278 中「套餐先用后付主订单被错算成先用后付任务」的问题
This commit is contained in:
cjy 2026-06-09 12:26:24 +08:00
parent 06fb278dcc
commit 8a19225eb5

View File

@ -67,17 +67,26 @@ func normalizeBundleTaskType(bundleTaskType int) int {
func taskStatsQueryOptions(bundleTaskType int) (int, int, string, string) {
taskType := normalizeBundleTaskType(bundleTaskType)
if taskType == model.BundleTaskTypePayLater {
return taskType, model.BillingTypeBNPL, "bor.order_mode = 2 AND bor.pay_later_status IN (1, 2)", ""
// 先用后付任务分支:只取 contract_tpl_type=3 的增值先用后付订单(只有视频额度)
// 套餐先用后付主订单 (contract_tpl_type=2) 归到普通任务分支
return taskType, model.BillingTypeBNPL, "bor.order_mode = 2 AND bor.contract_tpl_type = 3 AND bor.pay_later_status IN (1, 2)", ""
}
return taskType, model.BillingTypeNormal, "bor.status = 2 AND IFNULL(bor.order_mode, 1) = 1", `
// 普通任务分支order_mode=1 的普通套餐 + contract_tpl_type=2 的套餐先用后付主订单
// 套餐先用后付主订单用 BNPL 语义 (pay_later_status IN (1,2)) 判定活跃
return taskType, model.BillingTypeNormal, `
((bor.status = 2 AND IFNULL(bor.order_mode, 1) = 1)
OR (bor.contract_tpl_type = 2 AND bor.pay_later_status IN (1, 2)))
`, `
AND NOT EXISTS (
SELECT 1 FROM bundle_order_records bor2
WHERE bor2.customer_id = bor.customer_id
AND bor2.deleted_at IS NULL
AND bor2.customer_id IS NOT NULL
AND bor2.status = 2
AND IFNULL(bor2.order_mode, 1) = 1
AND (
(bor2.status = 2 AND IFNULL(bor2.order_mode, 1) = 1)
OR (bor2.contract_tpl_type = 2 AND bor2.pay_later_status IN (1, 2))
)
AND (bor2.created_at > bor.created_at OR (bor2.created_at = bor.created_at AND bor2.id > bor.id))
)`
}