|
|
@@ -18,13 +18,13 @@ use bos_core::error::KltCode;
|
|
|
use bos_core::{BosError, RoleCode};
|
|
|
use bos_platform::audit::AuditEvent;
|
|
|
use bos_platform::clients::uds::UdsClient;
|
|
|
-use bos_scope::AuthContext;
|
|
|
+use bos_scope::{AuthContext, ScopedSelect};
|
|
|
use chrono::{Datelike, Duration, NaiveDate, Utc};
|
|
|
use serde::Deserialize;
|
|
|
use serde_json::{json, Value};
|
|
|
use std::collections::{HashMap, HashSet};
|
|
|
|
|
|
-use super::listq::{leaf_of_path, next_seq, next_seq_n, Params};
|
|
|
+use super::listq::{self, leaf_of_path, next_seq, next_seq_n, push_in, Params};
|
|
|
|
|
|
// ───────────────────────────── 通用小工具 ─────────────────────────────
|
|
|
|
|
|
@@ -120,25 +120,61 @@ fn self_scope_only(auth: &AuthContext) -> bool {
|
|
|
|
|
|
/// 读口主体收窄谓词(批次/明细两表都有 `holder_type`/`holder_id`,同一段谓词可复用)。
|
|
|
///
|
|
|
-/// * `admin`/运维主/运维子:`TRUE`——本域对账不按区域切,区域轴由各自页面另行收窄;
|
|
|
+/// * `admin`:`TRUE`(全量);
|
|
|
+/// * 区域运营主/子(✅ 2026-11-18 修复 D-4):`holder` 所属**省份落在当前账号负责范围(含下级)**内
|
|
|
+/// ——按三张分成方档案的 `region_node_id` 判定。此前返回 `TRUE` =运营侧可看到、可导出
|
|
|
+/// 范围外省份的批次/明细与金额。区域轴为空 ⇒ **失败关闭** `1 = 0`;
|
|
|
/// * `partner`/`operator`:`holder_type` 等值 + `holder_id`=本人主体号
|
|
|
/// (`partner_id`/`operator_id`;⚠️ 取的是 `AuthContext::subject`,即 `bos_user_binding`
|
|
|
/// 的业务主体号,⛔ JWT 里的平台用户号 `sub`——两者不同域);
|
|
|
/// * `teamLead`:`ops_team` 团队轴(主体号=`team_id`);主体不是团队 ⇒ **失败关闭** `1 = 0`;
|
|
|
/// * 其余:`1 = 0`(`can_view` 已在更外层拦,这里只兜底,⛔ 放行)。
|
|
|
-fn holder_scope_pred(auth: &AuthContext, p: &mut Params, alias: &str) -> String {
|
|
|
+///
|
|
|
+/// ⚠️ 区域轴刻意用 `IN (SELECT … FROM dim_node_ancestor WHERE ancestor_id IN (…))` 而**不是**
|
|
|
+/// 相关 `EXISTS`:UDS 引擎在派生表/聚合外层遇到 `Exists(...)` 会报
|
|
|
+/// `Physical plan does not support logical expression Exists`(`partner::customer_scope_pred`
|
|
|
+/// 的同一实测结论),本谓词会被塞进 `COUNT(1)` 与卡片聚合,必须避开该形态。
|
|
|
+async fn holder_scope_pred(
|
|
|
+ state: &AppState,
|
|
|
+ auth: &AuthContext,
|
|
|
+ p: &mut Params,
|
|
|
+ alias: &str,
|
|
|
+) -> Result<String, BosError> {
|
|
|
let (kind, id) = match auth.role {
|
|
|
- RoleCode::Admin | RoleCode::OpsMain | RoleCode::OpsSub => return "TRUE".to_string(),
|
|
|
+ RoleCode::Admin => return Ok("TRUE".to_string()),
|
|
|
+ RoleCode::OpsMain | RoleCode::OpsSub => {
|
|
|
+ let ids = state.scope.visible_region_node_ids(auth).await?;
|
|
|
+ if ids.is_empty() {
|
|
|
+ return Ok("1 = 0".to_string());
|
|
|
+ }
|
|
|
+ let in_pred = push_in(p, "ancestor_id", &ids, "text");
|
|
|
+ let node_in = format!(
|
|
|
+ "SELECT node_id FROM dim_node_ancestor WHERE {in_pred}"
|
|
|
+ );
|
|
|
+ let mut axes: Vec<String> = Vec::new();
|
|
|
+ for (ht, table, col) in [
|
|
|
+ ("operator", "operator", "operator_id"),
|
|
|
+ ("partner", "partner", "partner_id"),
|
|
|
+ ("ops_team", "ops_team", "team_id"),
|
|
|
+ ] {
|
|
|
+ let t = p.push(json!(ht));
|
|
|
+ axes.push(format!(
|
|
|
+ "({alias}.holder_type = {t}::text AND {alias}.holder_id IN (\
|
|
|
+ SELECT {col} FROM {table} WHERE region_node_id IN ({node_in})))"
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ return Ok(format!("({})", axes.join(" OR ")));
|
|
|
+ }
|
|
|
RoleCode::Partner => ("partner", auth.subject.subject_id.clone()),
|
|
|
RoleCode::Operator => ("operator", auth.subject.subject_id.clone()),
|
|
|
RoleCode::TeamLead if auth.subject.subject_type == "ops_team" => {
|
|
|
("ops_team", auth.subject.subject_id.clone())
|
|
|
}
|
|
|
- _ => return "1 = 0".to_string(),
|
|
|
+ _ => return Ok("1 = 0".to_string()),
|
|
|
};
|
|
|
let t = p.push(json!(kind));
|
|
|
let i = p.push(json!(id));
|
|
|
- format!("{alias}.holder_type = {t}::text AND {alias}.holder_id = {i}::text")
|
|
|
+ Ok(format!("{alias}.holder_type = {t}::text AND {alias}.holder_id = {i}::text"))
|
|
|
}
|
|
|
|
|
|
/// 单行读口(详情/单批导出)的行后判定:与 [`holder_scope_pred`] **同一口径**。
|
|
|
@@ -146,9 +182,19 @@ fn holder_scope_pred(auth: &AuthContext, p: &mut Params, alias: &str) -> String
|
|
|
/// 为什么行后判而不是先拼谓词:这两条路由的 SQL 还要联 `bos_user_binding`/
|
|
|
/// `bill_detail`,把谓词塞进 WHERE 会让「查无此批」与「不是本方的批」在 SQL 层不可分,
|
|
|
/// 而口径要求两者**同码同文案**(`11104`,越权⛔ 暴露存在性)。
|
|
|
-fn holder_scope_allows(auth: &AuthContext, holder_type: &str, holder_id: &str) -> bool {
|
|
|
- match auth.role {
|
|
|
- RoleCode::Admin | RoleCode::OpsMain | RoleCode::OpsSub => true,
|
|
|
+async fn holder_scope_allows(
|
|
|
+ state: &AppState,
|
|
|
+ auth: &AuthContext,
|
|
|
+ holder_type: &str,
|
|
|
+ holder_id: &str,
|
|
|
+) -> Result<bool, BosError> {
|
|
|
+ Ok(match auth.role {
|
|
|
+ // ✅ 2026-11-18 修复 D-4:运维三档不再一律放行,按 holder 档案的省份判范围。
|
|
|
+ RoleCode::Admin => true,
|
|
|
+ RoleCode::OpsMain | RoleCode::OpsSub => match holder_region_node(state, holder_type, holder_id).await? {
|
|
|
+ Some(node) => listq::region_in_scope(state, auth, &node).await?,
|
|
|
+ None => false,
|
|
|
+ },
|
|
|
RoleCode::Partner => holder_type == "partner" && holder_id == auth.subject.subject_id,
|
|
|
RoleCode::Operator => holder_type == "operator" && holder_id == auth.subject.subject_id,
|
|
|
RoleCode::TeamLead => {
|
|
|
@@ -157,6 +203,103 @@ fn holder_scope_allows(auth: &AuthContext, holder_type: &str, holder_id: &str) -
|
|
|
&& holder_id == auth.subject.subject_id
|
|
|
}
|
|
|
_ => false,
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+/// 单行读口的收窄判定+「越权=查无」出参:`Ok(())` 才继续,范围外回 `11104` 同码同文案。
|
|
|
+///
|
|
|
+/// 判据全在 [`holder_scope_allows`](与列表谓词同一口径),本函数只负责把 `false`
|
|
|
+/// 折成**与「查无此对象」逐字相同**的 `NotFound`——⛔ 回 403:那会让调用方凭码差确认
|
|
|
+/// 「这个批次号/明细号存在」,接口就成了枚举器。
|
|
|
+async fn assert_holder_visible(
|
|
|
+ state: &AppState,
|
|
|
+ auth: &AuthContext,
|
|
|
+ holder_type: &str,
|
|
|
+ holder_id: &str,
|
|
|
+ not_found: impl FnOnce() -> String,
|
|
|
+) -> Result<(), BosError> {
|
|
|
+ if holder_scope_allows(state, auth, holder_type, holder_id).await? {
|
|
|
+ Ok(())
|
|
|
+ } else {
|
|
|
+ Err(BosError::not_found(not_found()))
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/// 分成方档案的`region_node_id`(批次/明细只存 `holder_type`+`holder_id`,省份在档案上)。
|
|
|
+/// 档案行缺失/类型未知 ⇒ `None`(调用方按「不可见」处理,⛔ 放行)。
|
|
|
+async fn holder_region_node(
|
|
|
+ state: &AppState,
|
|
|
+ holder_type: &str,
|
|
|
+ holder_id: &str,
|
|
|
+) -> Result<Option<String>, BosError> {
|
|
|
+ let (table, id_col) = match holder_type {
|
|
|
+ "operator" => ("operator", "operator_id"),
|
|
|
+ "partner" => ("partner", "partner_id"),
|
|
|
+ "ops_team" => ("ops_team", "team_id"),
|
|
|
+ _ => return Ok(None),
|
|
|
+ };
|
|
|
+ #[derive(Deserialize)]
|
|
|
+ struct Row {
|
|
|
+ #[serde(deserialize_with = "bos_platform::clients::uds::de::as_opt_string")]
|
|
|
+ region_node_id: Option<String>,
|
|
|
+ }
|
|
|
+ let sql = format!("SELECT region_node_id FROM {table} WHERE {id_col} = $1::text LIMIT 1");
|
|
|
+ let row = state
|
|
|
+ .db
|
|
|
+ .query_one::<Row>(&sql, &[json!(holder_id)])
|
|
|
+ .await?;
|
|
|
+ Ok(row.and_then(|r| r.region_node_id).filter(|s| !s.trim().is_empty()))
|
|
|
+}
|
|
|
+
|
|
|
+/// 出账更正的行级收窄谓词(✅ 2026-11-18 修复 D-4:`correction_list` 原本以 `1=1` 起手)。
|
|
|
+///
|
|
|
+/// 判据按身份分档:
|
|
|
+/// * `admin`:`TRUE`(全量);
|
|
|
+/// * 区域运营主/子:更正行自带的 `region_node_id`(登记时按客户归属解析)落在负责范围子树内
|
|
|
+/// ——与对账批次/明细的区域轴同一真源,⛔ 另起一套;
|
|
|
+/// * `partner`/`operator`:`matched_holder_id`=本人主体号(本方更正);
|
|
|
+/// * `teamLead`:团队轴。⚠️ 更正表**没有** `holder_type`,而团队轴只认 `ops_team` 的更正,
|
|
|
+/// 故 `matched_holder_id`=本团队号是**必要但不足以**证明归属(同一 ID 可能属运营商)⇒
|
|
|
+/// 额外要求该行关联的批次自身是团队轴(`matched_batch_no` 上有批次时按批次判,无批次按客户轴)。
|
|
|
+/// 基线 8 条全属 `OP-05`(江苏运营商)⇒ 团队主账号诚实地看到 0 行;
|
|
|
+/// * 其余:`1 = 0`(失败关闭)。
|
|
|
+async fn correction_scope_pred(
|
|
|
+ state: &AppState,
|
|
|
+ auth: &AuthContext,
|
|
|
+ p: &mut Params,
|
|
|
+ alias: &str,
|
|
|
+) -> Result<String, BosError> {
|
|
|
+ match auth.role {
|
|
|
+ RoleCode::Admin => Ok("TRUE".to_string()),
|
|
|
+ RoleCode::OpsMain | RoleCode::OpsSub => {
|
|
|
+ // ⚠️ 刻意写成 `IN (SELECT …)` 而**不是** `region_scope_pred` 的相关 `EXISTS`:
|
|
|
+ // 本谓词会同时进列表与 `COUNT(*)`,避开 UDS 对 `Exists(...)` 的计划限制。
|
|
|
+ // NULL `region_node_id`(无法证明归属)⇒ 失败关闭,不计入。
|
|
|
+ let ids = state.scope.visible_region_node_ids(auth).await?;
|
|
|
+ if ids.is_empty() {
|
|
|
+ return Ok("1 = 0".to_string());
|
|
|
+ }
|
|
|
+ let in_pred = push_in(p, "ancestor_id", &ids, "text");
|
|
|
+ Ok(format!(
|
|
|
+ "{alias}.region_node_id IN (\
|
|
|
+ SELECT node_id FROM dim_node_ancestor WHERE {in_pred})"
|
|
|
+ ))
|
|
|
+ }
|
|
|
+ RoleCode::Partner | RoleCode::Operator => {
|
|
|
+ let ph = p.push(json!(auth.subject.subject_id.clone()));
|
|
|
+ Ok(format!("{alias}.matched_holder_id = {ph}::text"))
|
|
|
+ }
|
|
|
+ RoleCode::TeamLead if auth.subject.subject_type == "ops_team" => {
|
|
|
+ // 团队轴=「该更正关联的批次就是本团队的批次」。⛔ 只比 `matched_holder_id`:
|
|
|
+ // 更正表没有 `holder_type`,运营商的 ID 也可能同名;经批次回连才能确认类型。
|
|
|
+ let t = p.push(json!(auth.subject.subject_id.clone()));
|
|
|
+ Ok(format!(
|
|
|
+ "{alias}.matched_batch_no IN (\
|
|
|
+ SELECT batch_no FROM reconcile_batch \
|
|
|
+ WHERE holder_type = 'ops_team' AND holder_id = {t}::text)"
|
|
|
+ ))
|
|
|
+ }
|
|
|
+ _ => Ok("1 = 0".to_string()),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -693,7 +836,9 @@ pub async fn recon_periods(State(state): State<AppState>, RequireAuth(auth): Req
|
|
|
if let Err(e) = can_view(&auth) { return json_err(e); }
|
|
|
// 自然月下拉只列**本方**实际有批次或有明细的月份(对账§5.3 末段,倒序):
|
|
|
// 全量下拉会把「别家在哪几个月出过账」直接摊开,且点了也查不出行(空页)。
|
|
|
- let full = matches!(auth.role, RoleCode::Admin | RoleCode::OpsMain | RoleCode::OpsSub);
|
|
|
+ // ✅ 2026-11-18 修复 D-4:运营主/子账号不再走全量分支(原 `full` 含 OpsMain/OpsSub,
|
|
|
+ // 期次下拉因此含范围外批次出过账的月份——与列表不同口径)。
|
|
|
+ let full = matches!(auth.role, RoleCode::Admin);
|
|
|
let mut p = Params::default();
|
|
|
let sql = if full {
|
|
|
"SELECT period FROM ( \
|
|
|
@@ -702,8 +847,14 @@ pub async fn recon_periods(State(state): State<AppState>, RequireAuth(auth): Req
|
|
|
UNION SELECT period FROM bill_detail WHERE status = 'active' \
|
|
|
) p ORDER BY period DESC LIMIT 36".to_string()
|
|
|
} else {
|
|
|
- let pb = holder_scope_pred(&auth, &mut p, "b");
|
|
|
- let pd = holder_scope_pred(&auth, &mut p, "d");
|
|
|
+ let pb = match holder_scope_pred(&state, &auth, &mut p, "b").await {
|
|
|
+ Ok(v) => v,
|
|
|
+ Err(e) => return json_err(e),
|
|
|
+ };
|
|
|
+ let pd = match holder_scope_pred(&state, &auth, &mut p, "d").await {
|
|
|
+ Ok(v) => v,
|
|
|
+ Err(e) => return json_err(e),
|
|
|
+ };
|
|
|
// 应收表没有持有者列 ⇒ 收到「本方有明细行」的期次(与另两源同一本体口径,
|
|
|
// ⛔ 用「全部应收期次」把本方的下拉放大成全站期次)。
|
|
|
format!(
|
|
|
@@ -825,7 +976,7 @@ async fn recon_rowset(
|
|
|
let mut w = recon_filters(req, period, "b", &mut p)?;
|
|
|
// 主体收窄先入 WHERE:与筛选条件是「且」,⛔ 让调用方传 `holder_type` 绕开本方口径
|
|
|
// (传别家类型只会与本谓词取交 ⇒ 空集,⛔ 放大;见 `holder_scope_pred`)。
|
|
|
- w.push(holder_scope_pred(auth, &mut p, "b"));
|
|
|
+ w.push(holder_scope_pred(state, auth, &mut p, "b").await?);
|
|
|
if !req.include_zero_lines.unwrap_or(false) {
|
|
|
w.push("COALESCE(d.cnt, 0) > 0".to_string());
|
|
|
}
|
|
|
@@ -920,7 +1071,7 @@ async fn recon_list_body(
|
|
|
// 基数/成本按应收去重(period × subscription_id);分成按(应收 × 分成方)且只认 executed。
|
|
|
let mut sp = Params::default();
|
|
|
let mut sw = recon_filters(req, period, "b", &mut sp)?;
|
|
|
- sw.push(holder_scope_pred(auth, &mut sp, "b"));
|
|
|
+ sw.push(holder_scope_pred(state, auth, &mut sp, "b").await?);
|
|
|
let share_rows = qry(&state.db,
|
|
|
&format!(
|
|
|
"SELECT COALESCE(SUM(d.share_amount_cents),0) AS share \
|
|
|
@@ -936,7 +1087,7 @@ async fn recon_list_body(
|
|
|
let mut qp = Params::default();
|
|
|
let mut inner_preds = recon_filters(req, None, "b2", &mut qp)?;
|
|
|
// 同一套主体收窄下推进 EXISTS(别名 `b2`=批次):与分成卡同判据,⛔ 让「基数/成本」按全量算。
|
|
|
- inner_preds.push(holder_scope_pred(auth, &mut qp, "b2"));
|
|
|
+ inner_preds.push(holder_scope_pred(state, auth, &mut qp, "b2").await?);
|
|
|
let period_pred = match period {
|
|
|
Some(pt) => format!(" AND r.period = {}", qp.push(json!(pt))),
|
|
|
None => String::new(),
|
|
|
@@ -962,7 +1113,7 @@ async fn recon_list_body(
|
|
|
// 已出账期次汇总同样按本体口径收窄:否则三类只读身份能从「已出账 N 个期次/最近期次」
|
|
|
// 读到全站节奏(含他家的出账进度)。
|
|
|
let mut mp = Params::default();
|
|
|
- let mp_pred = holder_scope_pred(auth, &mut mp, "reconcile_batch");
|
|
|
+ let mp_pred = holder_scope_pred(state, auth, &mut mp, "reconcile_batch").await?;
|
|
|
let sum_rows = qry(&state.db,
|
|
|
&format!(
|
|
|
"SELECT COUNT(DISTINCT period) AS n, COALESCE(MAX(period),'') AS latest \
|
|
|
@@ -980,7 +1131,7 @@ async fn recon_list_body(
|
|
|
|
|
|
// 进度只随自然月变化(③-1)⇒「全部自然月」⛔ 下发进度,回 `null` 让前端不渲进度行。
|
|
|
let progress = match period {
|
|
|
- Some(pt) => period_progress(&state.db, auth, pt).await?,
|
|
|
+ Some(pt) => period_progress(state, auth, pt).await?,
|
|
|
None => Value::Null,
|
|
|
};
|
|
|
|
|
|
@@ -1206,8 +1357,16 @@ pub async fn recon_export_detail(
|
|
|
};
|
|
|
// 越权与查无此批**同码同文案**(11104):⛔ 让「不是本方的批」与「不存在」可分,
|
|
|
// 否则本接口就是一张批次号枚举器。
|
|
|
- if !holder_scope_allows(&auth, &s(b, "holder_type"), &s(b, "holder_id")) {
|
|
|
- return json_err(BosError::not_found(format!("批次不存在(11104):{batch_no}")));
|
|
|
+ if let Err(e) = assert_holder_visible(
|
|
|
+ &state,
|
|
|
+ &auth,
|
|
|
+ &s(b, "holder_type"),
|
|
|
+ &s(b, "holder_id"),
|
|
|
+ || format!("批次不存在(11104):{batch_no}"),
|
|
|
+ )
|
|
|
+ .await
|
|
|
+ {
|
|
|
+ return json_err(e);
|
|
|
}
|
|
|
let status = s(b, "status");
|
|
|
let details = match qry(&state.db,
|
|
|
@@ -1303,17 +1462,18 @@ async fn write_recon_audit(
|
|
|
/// ③-1 期次出账进度:只随自然月变化(⛔ 随其余筛选变)。
|
|
|
/// 口径:分成方集合=该期分成快照里的去重 (holder_type, holder_id);应出账日=该方对账日(无档案列则取默认对账日)。
|
|
|
async fn period_progress(
|
|
|
- db: &UdsClient,
|
|
|
+ state: &AppState,
|
|
|
auth: &AuthContext,
|
|
|
period: &str,
|
|
|
) -> Result<Value, BosError> {
|
|
|
+ let db = state.db.as_ref();
|
|
|
let (default_day, op_days) = recon_day_map(db).await;
|
|
|
|
|
|
// 分成方清单按本体口径收窄:这一栏是「本期每个分成方是否已出账」,全量下发等于把
|
|
|
// 他家的分成方名单与出账节奏一并给出(对账§5.3 三类只读身份行集恒等于本方)。
|
|
|
let mut hp = Params::default();
|
|
|
let period_ph = hp.push(json!(period));
|
|
|
- let hpred = holder_scope_pred(auth, &mut hp, "v");
|
|
|
+ let hpred = holder_scope_pred(state, auth, &mut hp, "v").await?;
|
|
|
let holders = qry(db,
|
|
|
&format!(
|
|
|
"SELECT DISTINCT v.holder_type, v.holder_id, v.holder_name \
|
|
|
@@ -1446,8 +1606,16 @@ pub async fn recon_detail(
|
|
|
};
|
|
|
// 越权与查无此批同码同文案(11104,对账§5.3):本方的批才可展开,其余一律按「不存在」答,
|
|
|
// ⛔ 用 403 与 404 的差别把「这个单号存在」这一位信息漏给对方。
|
|
|
- if !holder_scope_allows(&auth, &s(b, "holder_type"), &s(b, "holder_id")) {
|
|
|
- return json_err(BosError::not_found(format!("批次不存在(11104):{batch_no}")));
|
|
|
+ if let Err(e) = assert_holder_visible(
|
|
|
+ &state,
|
|
|
+ &auth,
|
|
|
+ &s(b, "holder_type"),
|
|
|
+ &s(b, "holder_id"),
|
|
|
+ || format!("批次不存在(11104):{batch_no}"),
|
|
|
+ )
|
|
|
+ .await
|
|
|
+ {
|
|
|
+ return json_err(e);
|
|
|
}
|
|
|
let period = s(b, "period");
|
|
|
let status = s(b, "status");
|
|
|
@@ -2110,9 +2278,12 @@ pub async fn bill_list(
|
|
|
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())))));
|
|
|
}
|
|
|
- // 主体收窄(对账§5.3 行集恒等于本方):与上面的筛选取「且」,⛔ 用调用方传的
|
|
|
- // `holder_type` 替他决定行集(传别家类型只会与本谓词取交 ⇒ 空集)。
|
|
|
- w.push(holder_scope_pred(&auth, &mut p, "d"));
|
|
|
+ // 主体收窄(对账§5.3 行集恒等于本方;✅ 2026-11-18 修复 D-4 追加区域轴):与上面的筛选取「且」,
|
|
|
+ // ⛔ 用调用方传的 `holder_type` 替他决定行集(传别家类型只会与本谓词取交 ⇒ 空集)。
|
|
|
+ match holder_scope_pred(&state, &auth, &mut p, "d").await {
|
|
|
+ Ok(v) => w.push(v),
|
|
|
+ Err(e) => return json_err(e),
|
|
|
+ }
|
|
|
let from = format!(
|
|
|
"FROM bill_detail d JOIN reconcile_batch b ON b.batch_no = d.batch_no \
|
|
|
LEFT JOIN billing_receivable r ON r.period=d.period AND r.subscription_id=d.subscription_id \
|
|
|
@@ -2200,8 +2371,16 @@ pub async fn bill_detail(
|
|
|
return json_err(BosError::not_found(format!("账单明细不存在或未出账(11104):{id}")));
|
|
|
};
|
|
|
// 越权与查无同码同文案(11104):本方的明细才可展开,⛔ 靠 403/404 的差别确认「这条存在」。
|
|
|
- if !holder_scope_allows(&auth, &s(r, "holder_type"), &s(r, "holder_id")) {
|
|
|
- return json_err(BosError::not_found(format!("账单明细不存在或未出账(11104):{id}")));
|
|
|
+ if let Err(e) = assert_holder_visible(
|
|
|
+ &state,
|
|
|
+ &auth,
|
|
|
+ &s(r, "holder_type"),
|
|
|
+ &s(r, "holder_id"),
|
|
|
+ || format!("账单明细不存在或未出账(11104):{id}"),
|
|
|
+ )
|
|
|
+ .await
|
|
|
+ {
|
|
|
+ return json_err(e);
|
|
|
}
|
|
|
let period = s(r, "period");
|
|
|
let sid = s(r, "subscription_id");
|
|
|
@@ -2574,7 +2753,15 @@ pub async fn correction_list(
|
|
|
let size = req.page_size.unwrap_or(20).clamp(1, 100);
|
|
|
let offset = page * size;
|
|
|
let mut p = Params::default();
|
|
|
- let mut w: Vec<String> = vec!["1=1".to_string()];
|
|
|
+ let mut w: Vec<String> = Vec::new();
|
|
|
+ // 行级收窄(✅ 2026-11-18 修复 D-4):此前 `where` 以 `1=1` 起手、**完全没有主体谓词**,
|
|
|
+ // 运营两档可看到全部省份的更正、`teamLead` 可看到运营商侧全部更正。
|
|
|
+ // 判据:运营两档按 `c.region_node_id` 落在负责范围子树;合伙人/运营商/运维团队按
|
|
|
+ // `matched_holder_id`=本人主体号(团队轴无 `ops_team` 更正 ⇒ 诚实空集)。
|
|
|
+ match correction_scope_pred(&state, &auth, &mut p, "c").await {
|
|
|
+ Ok(v) => w.push(v),
|
|
|
+ Err(e) => return json_err(e),
|
|
|
+ }
|
|
|
if let Some(pd) = req.period.as_deref().map(normalize_period).filter(|x| !x.is_empty()) {
|
|
|
w.push(format!("c.period = {}", p.push(json!(pd))));
|
|
|
}
|