|
@@ -2375,11 +2375,22 @@ pub async fn bill_list(
|
|
|
if let Err(e) = can_view(&auth) { return json_err(e); }
|
|
if let Err(e) = can_view(&auth) { return json_err(e); }
|
|
|
// 期次缺省=「全部期次」(页面下拉的空值选项),⛔ 回落最近已结束月——
|
|
// 期次缺省=「全部期次」(页面下拉的空值选项),⛔ 回落最近已结束月——
|
|
|
// 否则空值选项与文案语义不符,且会静默丢掉其它期次的明细。
|
|
// 否则空值选项与文案语义不符,且会静默丢掉其它期次的明细。
|
|
|
- let period = req
|
|
|
|
|
- .period
|
|
|
|
|
- .as_deref()
|
|
|
|
|
- .map(normalize_period)
|
|
|
|
|
- .filter(|p| !p.is_empty());
|
|
|
|
|
|
|
+ // 非空但非 YYYY-MM(含长度≠7、月份越界)⇒ 60004,⛔ 静默忽略成全量(O-7)。
|
|
|
|
|
+ let period = match req.period.as_deref().map(str::trim).filter(|x| !x.is_empty()) {
|
|
|
|
|
+ None => None,
|
|
|
|
|
+ Some(raw) => {
|
|
|
|
|
+ let norm = normalize_period(raw);
|
|
|
|
|
+ if norm.is_empty() {
|
|
|
|
|
+ return json_err(BosError::bad_params(format!(
|
|
|
|
|
+ "period 须为 YYYY-MM(11103):{raw}"
|
|
|
|
|
+ )));
|
|
|
|
|
+ }
|
|
|
|
|
+ if let Err(e) = parse_period(&norm) {
|
|
|
|
|
+ return json_err(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ Some(norm)
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
let page = req.page.unwrap_or(0).max(0);
|
|
let page = req.page.unwrap_or(0).max(0);
|
|
|
let size = req.page_size.unwrap_or(20).clamp(1, 100);
|
|
let size = req.page_size.unwrap_or(20).clamp(1, 100);
|
|
|
let offset = page * size;
|
|
let offset = page * size;
|
|
@@ -2393,6 +2404,10 @@ pub async fn bill_list(
|
|
|
w.push(format!("d.period = {}", p.push(json!(pd))));
|
|
w.push(format!("d.period = {}", p.push(json!(pd))));
|
|
|
}
|
|
}
|
|
|
if let Some(t) = req.holder_type.as_deref().filter(|x| !x.is_empty()) {
|
|
if let Some(t) = req.holder_type.as_deref().filter(|x| !x.is_empty()) {
|
|
|
|
|
+ // 与 recon/get_list 同口径:非法枚举 ⇒ 60004,⛔ 静默空集(O-6)。
|
|
|
|
|
+ if holder_table(t).is_none() {
|
|
|
|
|
+ return json_err(BosError::bad_params("holder_type 非法(11103)"));
|
|
|
|
|
+ }
|
|
|
w.push(format!("d.holder_type = {}", p.push(json!(t))));
|
|
w.push(format!("d.holder_type = {}", p.push(json!(t))));
|
|
|
}
|
|
}
|
|
|
if let Some(kw) = req.holder_kw.as_deref().filter(|x| !x.trim().is_empty()) {
|
|
if let Some(kw) = req.holder_kw.as_deref().filter(|x| !x.trim().is_empty()) {
|
|
@@ -2401,9 +2416,14 @@ pub async fn bill_list(
|
|
|
if let Some(kw) = req.customer_kw.as_deref().filter(|x| !x.trim().is_empty()) {
|
|
if let Some(kw) = req.customer_kw.as_deref().filter(|x| !x.trim().is_empty()) {
|
|
|
w.push(format!("(d.customer_name ILIKE {0} OR d.customer_id ILIKE {0})", p.push(json!(format!("%{}%", kw.trim())))));
|
|
w.push(format!("(d.customer_name ILIKE {0} OR d.customer_id ILIKE {0})", p.push(json!(format!("%{}%", kw.trim())))));
|
|
|
}
|
|
}
|
|
|
|
|
+ // keyword 单框与列表 placeholder「分成方、客户、订阅或单号」对齐:并查 holder/客户/订阅/批次号(D-1)。
|
|
|
if let Some(kw) = req.keyword.as_deref().filter(|x| !x.trim().is_empty()) {
|
|
if let Some(kw) = req.keyword.as_deref().filter(|x| !x.trim().is_empty()) {
|
|
|
- w.push(format!("(d.subscription_id ILIKE {0} OR COALESCE(d.subscription_label,'') ILIKE {0} OR d.batch_no ILIKE {0})",
|
|
|
|
|
- p.push(json!(format!("%{}%", kw.trim())))));
|
|
|
|
|
|
|
+ w.push(format!(
|
|
|
|
|
+ "(b.holder_name ILIKE {0} OR d.customer_name ILIKE {0} OR d.customer_id ILIKE {0} \
|
|
|
|
|
+ OR d.subscription_id ILIKE {0} OR COALESCE(d.subscription_label,'') ILIKE {0} \
|
|
|
|
|
+ OR d.batch_no ILIKE {0})",
|
|
|
|
|
+ p.push(json!(format!("%{}%", kw.trim())))
|
|
|
|
|
+ ));
|
|
|
}
|
|
}
|
|
|
// 主体收窄(对账§5.3 行集恒等于本方;✅ 2026-11-18 修复 D-4 追加区域轴):与上面的筛选取「且」,
|
|
// 主体收窄(对账§5.3 行集恒等于本方;✅ 2026-11-18 修复 D-4 追加区域轴):与上面的筛选取「且」,
|
|
|
// ⛔ 用调用方传的 `holder_type` 替他决定行集(传别家类型只会与本谓词取交 ⇒ 空集)。
|
|
// ⛔ 用调用方传的 `holder_type` 替他决定行集(传别家类型只会与本谓词取交 ⇒ 空集)。
|
|
@@ -2511,7 +2531,10 @@ pub async fn bill_detail(
|
|
|
}
|
|
}
|
|
|
let period = s(r, "period");
|
|
let period = s(r, "period");
|
|
|
let sid = s(r, "subscription_id");
|
|
let sid = s(r, "subscription_id");
|
|
|
- let accounts = match qry(&state.db,
|
|
|
|
|
|
|
+ // 在期天数:取数失败只坏⑦格(account_days_failed=true + account_days=null),
|
|
|
|
|
+ // ⛔ 整页 60005/S406、⛔ 回落空数组冒充「无开停记录」(对账§14.3/O-5;同 ticket_gap_failed)。
|
|
|
|
|
+ let mut account_days_failed = false;
|
|
|
|
|
+ let account_days: Option<Vec<Value>> = match qry(&state.db,
|
|
|
"SELECT COALESCE(NULLIF(sa.display_name,''), a.sub_account_id) AS sub_account_label, \
|
|
"SELECT COALESCE(NULLIF(sa.display_name,''), a.sub_account_id) AS sub_account_label, \
|
|
|
a.in_period_days \
|
|
a.in_period_days \
|
|
|
FROM billing_receivable_account a \
|
|
FROM billing_receivable_account a \
|
|
@@ -2519,15 +2542,17 @@ pub async fn bill_detail(
|
|
|
WHERE a.period=$1 AND a.subscription_id=$2 ORDER BY a.sub_account_id",
|
|
WHERE a.period=$1 AND a.subscription_id=$2 ORDER BY a.sub_account_id",
|
|
|
&[json!(period), json!(sid)],
|
|
&[json!(period), json!(sid)],
|
|
|
).await {
|
|
).await {
|
|
|
- Ok(x) => x,
|
|
|
|
|
- Err(e) => return json_err(e),
|
|
|
|
|
|
|
+ Ok(x) => Some(x.iter().map(|x| json!({
|
|
|
|
|
+ "sub_account_label": s(x, "sub_account_label"),
|
|
|
|
|
+ "in_period_days": i(x, "in_period_days"),
|
|
|
|
|
+ })).collect()),
|
|
|
|
|
+ Err(_) => {
|
|
|
|
|
+ account_days_failed = true;
|
|
|
|
|
+ None
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
- let account_days: Vec<Value> = accounts.iter().map(|x| json!({
|
|
|
|
|
- "sub_account_label": s(x, "sub_account_label"),
|
|
|
|
|
- "in_period_days": i(x, "in_period_days"),
|
|
|
|
|
- })).collect();
|
|
|
|
|
let others = match qry(&state.db,
|
|
let others = match qry(&state.db,
|
|
|
- "SELECT d.bill_detail_id, d.batch_no, d.holder_type, b.holder_name, d.share_amount_cents \
|
|
|
|
|
|
|
+ "SELECT d.bill_detail_id, d.batch_no, d.holder_type, d.holder_id, b.holder_name, d.share_amount_cents \
|
|
|
FROM bill_detail d JOIN reconcile_batch b ON b.batch_no=d.batch_no \
|
|
FROM bill_detail d JOIN reconcile_batch b ON b.batch_no=d.batch_no \
|
|
|
WHERE d.period=$1 AND d.subscription_id=$2 AND d.status='active' AND b.status='executed' \
|
|
WHERE d.period=$1 AND d.subscription_id=$2 AND d.status='active' AND b.status='executed' \
|
|
|
AND NOT (d.holder_type=$3 AND d.holder_id=$4) ORDER BY d.holder_type, d.holder_id",
|
|
AND NOT (d.holder_type=$3 AND d.holder_id=$4) ORDER BY d.holder_type, d.holder_id",
|
|
@@ -2536,8 +2561,10 @@ pub async fn bill_detail(
|
|
|
Ok(x) => x,
|
|
Ok(x) => x,
|
|
|
Err(e) => return json_err(e),
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
};
|
|
|
|
|
+ // holder_id 一并下发:前端「其他分成方」子表对账单号可点进批次(与本方「所属对账单号」同形,O-1)。
|
|
|
let other_parties: Vec<Value> = others.iter().map(|x| json!({
|
|
let other_parties: Vec<Value> = others.iter().map(|x| json!({
|
|
|
"holder_type": s(x, "holder_type"),
|
|
"holder_type": s(x, "holder_type"),
|
|
|
|
|
+ "holder_id": s(x, "holder_id"),
|
|
|
"holder_name": s(x, "holder_name"),
|
|
"holder_name": s(x, "holder_name"),
|
|
|
"share_amount_cents": i(x, "share_amount_cents"),
|
|
"share_amount_cents": i(x, "share_amount_cents"),
|
|
|
"batch_no": s(x, "batch_no"),
|
|
"batch_no": s(x, "batch_no"),
|
|
@@ -2576,7 +2603,7 @@ pub async fn bill_detail(
|
|
|
"zero_note": os(r, "zero_note"),
|
|
"zero_note": os(r, "zero_note"),
|
|
|
"other_parties": other_parties,
|
|
"other_parties": other_parties,
|
|
|
"account_days": account_days,
|
|
"account_days": account_days,
|
|
|
- "account_days_failed": false,
|
|
|
|
|
|
|
+ "account_days_failed": account_days_failed,
|
|
|
});
|
|
});
|
|
|
// 三类只读身份**字段不返回**(对账§5.3/06 册接口清单):旁人的分成金额是旁人的商业秘密,
|
|
// 三类只读身份**字段不返回**(对账§5.3/06 册接口清单):旁人的分成金额是旁人的商业秘密,
|
|
|
// ⛔ 置空——前端会把空值渲染成「0 元」,等于替对方否认分成。
|
|
// ⛔ 置空——前端会把空值渲染成「0 元」,等于替对方否认分成。
|