|
|
@@ -57,7 +57,7 @@ const COLUMNS_PENDING: &[&str] = &[];
|
|
|
const TERMS: [&str; 3] = ["yearly", "quarterly", "monthly"];
|
|
|
|
|
|
/// 在用状态(§4 额度口径:仅待生效与生效中占额度)。
|
|
|
-const IN_USE_STATUS: [&str; 2] = ["pending", "active"];
|
|
|
+pub(crate) const IN_USE_STATUS: [&str; 2] = ["pending", "active"];
|
|
|
|
|
|
/// 六项只读派生列+变更链指针:新建载荷出现即 `11103`(§5.2 段 3/4、§2.3)。
|
|
|
const CREATE_READ_ONLY: [&str; 8] = [
|
|
|
@@ -101,7 +101,7 @@ const COST_UNCONFIGURED_NOTE: &str = "套餐月成本只读口本轮未接线(
|
|
|
`plan_cost_item` 在册但成本折算属第 4 册口径,不以 0 冒充无成本。";
|
|
|
|
|
|
/// 开户工单只读口未接线的原文说明(§2.1/§5.2 第 6 步)。
|
|
|
-const TICKET_UNCONFIGURED_NOTE: &str = "开户工单只读口本轮未接线(`open_tickets=unconfigured`):\
|
|
|
+pub(crate) const TICKET_UNCONFIGURED_NOTE: &str = "开户工单只读口本轮未接线(`open_tickets=unconfigured`):\
|
|
|
开通态判定只用了本域自读的 `actual_opened_at` 一维,不据此认定合同未开通;\
|
|
|
新订第 6 步「回写开户工单号与订单号」同样未接线,本轮未回写。";
|
|
|
|
|
|
@@ -237,7 +237,7 @@ fn trimmed(raw: &str) -> String {
|
|
|
}
|
|
|
|
|
|
/// 必填串;空白=显式失败(⛔ 落成空串)。
|
|
|
-fn req_field(field: &str, raw: &str) -> Result<String, BosError> {
|
|
|
+pub(crate) fn req_field(field: &str, raw: &str) -> Result<String, BosError> {
|
|
|
let s = trimmed(raw);
|
|
|
if s.is_empty() {
|
|
|
return Err(BosError::bad_params(format!("{field} 必填")));
|
|
|
@@ -246,20 +246,20 @@ fn req_field(field: &str, raw: &str) -> Result<String, BosError> {
|
|
|
}
|
|
|
|
|
|
/// `YYYY-MM-DD` 解析(同时兜住「日期不可比」与「非法值传给 `::date` 后 UDS 报错」两种失效形态)。
|
|
|
-fn parse_date(field: &str, raw: &str) -> Result<NaiveDate, BosError> {
|
|
|
+pub(crate) fn parse_date(field: &str, raw: &str) -> Result<NaiveDate, BosError> {
|
|
|
NaiveDate::parse_from_str(raw.trim(), "%Y-%m-%d")
|
|
|
.map_err(|_| BosError::bad_params(format!("{field} 须为 YYYY-MM-DD,实得 {raw}")))
|
|
|
}
|
|
|
|
|
|
-fn date_text(d: NaiveDate) -> String {
|
|
|
+pub(crate) fn date_text(d: NaiveDate) -> String {
|
|
|
d.format("%Y-%m-%d").to_string()
|
|
|
}
|
|
|
|
|
|
-fn today() -> String {
|
|
|
+pub(crate) fn today() -> String {
|
|
|
chrono::Local::now().format("%Y-%m-%d").to_string()
|
|
|
}
|
|
|
|
|
|
-fn opt_trim(v: Option<&String>) -> Option<&str> {
|
|
|
+pub(crate) fn opt_trim(v: Option<&String>) -> Option<&str> {
|
|
|
v.map(String::as_str).map(str::trim).filter(|s| !s.is_empty())
|
|
|
}
|
|
|
|
|
|
@@ -276,7 +276,7 @@ fn reject_read_only(rest: &Map<String, Value>, keys: &[&str]) -> Result<(), BosE
|
|
|
}
|
|
|
|
|
|
/// 月数折算(§2.3:年=12/季=3/月=1)。
|
|
|
-fn term_months(term: &str) -> Result<u32, BosError> {
|
|
|
+pub(crate) fn term_months(term: &str) -> Result<u32, BosError> {
|
|
|
match term {
|
|
|
"yearly" => Ok(12),
|
|
|
"quarterly" => Ok(3),
|
|
|
@@ -288,7 +288,7 @@ fn term_months(term: &str) -> Result<u32, BosError> {
|
|
|
}
|
|
|
|
|
|
/// 加 `n` 个月并把不存在的日期折到月末(§5.2「该月无对应日取月末」)。
|
|
|
-fn add_months_clamped(d: NaiveDate, n: u32) -> NaiveDate {
|
|
|
+pub(crate) fn add_months_clamped(d: NaiveDate, n: u32) -> NaiveDate {
|
|
|
let total = d.year() as u64 * 12 + (d.month0() as u64) + n as u64;
|
|
|
let year = (total / 12) as i64;
|
|
|
let month = ((total % 12) + 1) as u32;
|
|
|
@@ -314,7 +314,7 @@ fn days_in_month(year: i64, month: u64) -> u32 {
|
|
|
}
|
|
|
|
|
|
/// 年订阅价格=`term` × 月结算标准金额(季=月×3、月=月;年取档位年价原值)。
|
|
|
-fn annual_by_term(plan_annual: i64, monthly: i64, term: &str) -> i64 {
|
|
|
+pub(crate) fn annual_by_term(plan_annual: i64, monthly: i64, term: &str) -> i64 {
|
|
|
match term {
|
|
|
"monthly" => monthly,
|
|
|
"quarterly" => monthly.saturating_mul(3),
|
|
|
@@ -323,7 +323,7 @@ fn annual_by_term(plan_annual: i64, monthly: i64, term: &str) -> i64 {
|
|
|
}
|
|
|
|
|
|
/// JSONB 出口列 → 字符串数组(dev 用 JSONB 承载 `TEXT[]`,可能回数组也可能回 JSON 串)。
|
|
|
-fn exits_of(v: Option<&Value>, field: &str) -> Result<Vec<String>, BosError> {
|
|
|
+pub(crate) fn exits_of(v: Option<&Value>, field: &str) -> Result<Vec<String>, BosError> {
|
|
|
let bad = || BosError::bad_params(format!("{field} 须为字符串数组(线路出口原值)"));
|
|
|
match v {
|
|
|
None | Some(Value::Null) => Ok(Vec::new()),
|
|
|
@@ -368,7 +368,7 @@ fn end_text(r: &SubRow) -> Option<String> {
|
|
|
///
|
|
|
/// 为什么不直接回库值:库里 `status` 由日终任务翻转,而 `SUB-EFF` 本轮⛔ 未做 ⇒ 直接回库值
|
|
|
/// 会把「已到期」显示成「生效中」;也不⛔ 在日期不可判时硬套三态(会凭空判成到期)。
|
|
|
-fn status_display(r: &SubRow, today: &str) -> (String, String, Option<String>) {
|
|
|
+pub(crate) fn status_display(r: &SubRow, today: &str) -> (String, String, Option<String>) {
|
|
|
let terminal = |s: &str| s == "cancelled" || s == "replaced";
|
|
|
let label = |k: &str| match k {
|
|
|
"pending" => "待生效",
|
|
|
@@ -419,63 +419,64 @@ fn editability(r: &SubRow, display_key: &str) -> (bool, Option<String>) {
|
|
|
|
|
|
// ───────────────────────── 行与出参 ─────────────────────────
|
|
|
|
|
|
+/// 订阅行(读侧快照):`succession` 公共层与合同写口共用同一形态 ⇒ 字段 `pub(crate)`。
|
|
|
#[derive(Clone, Deserialize)]
|
|
|
-struct SubRow {
|
|
|
+pub(crate) struct SubRow {
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- subscription_id: String,
|
|
|
+ pub(crate) subscription_id: String,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- customer_id: String,
|
|
|
+ pub(crate) customer_id: String,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- contract_id: Option<String>,
|
|
|
+ pub(crate) contract_id: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- contract_item_id: Option<String>,
|
|
|
+ pub(crate) contract_item_id: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- plan_id: Option<String>,
|
|
|
+ pub(crate) plan_id: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- plan_name: Option<String>,
|
|
|
+ pub(crate) plan_name: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- plan_kind: Option<String>,
|
|
|
+ pub(crate) plan_kind: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- plan_owner_customer_id: Option<String>,
|
|
|
+ pub(crate) plan_owner_customer_id: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- status: String,
|
|
|
+ pub(crate) status: String,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- use_category: Option<String>,
|
|
|
+ pub(crate) use_category: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- sub_mode: Option<String>,
|
|
|
- line_exits: Option<Value>,
|
|
|
+ pub(crate) sub_mode: Option<String>,
|
|
|
+ pub(crate) line_exits: Option<Value>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- line_exit_key: Option<String>,
|
|
|
+ pub(crate) line_exit_key: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- start_date: Option<String>,
|
|
|
+ pub(crate) start_date: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- end_date: Option<String>,
|
|
|
+ pub(crate) end_date: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- term: Option<String>,
|
|
|
+ pub(crate) term: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- trial_months: Option<String>,
|
|
|
+ pub(crate) trial_months: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- discount_monthly_cents: Option<String>,
|
|
|
+ pub(crate) discount_monthly_cents: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- annual_price_cents: Option<String>,
|
|
|
+ pub(crate) annual_price_cents: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- monthly_settle_cents: Option<String>,
|
|
|
+ pub(crate) monthly_settle_cents: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- quota_slots: String,
|
|
|
+ pub(crate) quota_slots: String,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- replaces_subscription_id: Option<String>,
|
|
|
+ pub(crate) replaces_subscription_id: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- order_no: Option<String>,
|
|
|
+ pub(crate) order_no: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- actual_opened_at: Option<String>,
|
|
|
+ pub(crate) actual_opened_at: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- effective_date: Option<String>,
|
|
|
+ pub(crate) effective_date: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- expire_date: Option<String>,
|
|
|
+ pub(crate) expire_date: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- created_at: String,
|
|
|
+ pub(crate) created_at: String,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- row_version: String,
|
|
|
+ pub(crate) row_version: String,
|
|
|
}
|
|
|
|
|
|
/// 列表行的钱列形态(§5.2 段 4「¥20,000(折算 ¥1,667/月)」)。
|
|
|
@@ -621,7 +622,7 @@ async fn customers_under_regions(state: &AppState, region_ids: &[String]) -> Res
|
|
|
}
|
|
|
|
|
|
/// 某客户的全部订阅(I6/额度对齐/变更链的取数底座)。
|
|
|
-async fn subs_of_customer(state: &AppState, customer_id: &str) -> Result<Vec<SubRow>, BosError> {
|
|
|
+pub(crate) async fn subs_of_customer(state: &AppState, customer_id: &str) -> Result<Vec<SubRow>, BosError> {
|
|
|
let mut p = Params::default();
|
|
|
let c = p.push(Value::String(customer_id.to_string()));
|
|
|
let sql = format!(
|
|
|
@@ -630,37 +631,37 @@ async fn subs_of_customer(state: &AppState, customer_id: &str) -> Result<Vec<Sub
|
|
|
state.db.query_all::<SubRow>(&sql, p.values()).await
|
|
|
}
|
|
|
|
|
|
-/// 档位行(含可用区间与派生链)。
|
|
|
+/// 档位行(含可用区间与派生链)。`succession` 公共层读同一形态 ⇒ 字段 `pub(crate)`。
|
|
|
#[derive(Deserialize)]
|
|
|
-struct PlanRow {
|
|
|
+pub(crate) struct PlanRow {
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- plan_id: String,
|
|
|
+ pub(crate) plan_id: String,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- plan_name: String,
|
|
|
+ pub(crate) plan_name: String,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- plan_kind: String,
|
|
|
+ pub(crate) plan_kind: String,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- customer_id: Option<String>,
|
|
|
+ pub(crate) customer_id: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- status: String,
|
|
|
+ pub(crate) status: String,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- use_category: Option<String>,
|
|
|
+ pub(crate) use_category: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- sub_account_quota: Option<String>,
|
|
|
+ pub(crate) sub_account_quota: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- annual_price_cents: String,
|
|
|
+ pub(crate) annual_price_cents: String,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- monthly_settle_cents: Option<String>,
|
|
|
- line_exits: Option<Value>,
|
|
|
+ pub(crate) monthly_settle_cents: Option<String>,
|
|
|
+ pub(crate) line_exits: Option<Value>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- derived_from_contract_item_id: Option<String>,
|
|
|
+ pub(crate) derived_from_contract_item_id: Option<String>,
|
|
|
/// 首次引用打点:`Some` ⇒ 该档已被引用过(§5.2「已引用过的档位⛔ 下架」同源)。
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- first_referred_at: Option<String>,
|
|
|
+ pub(crate) first_referred_at: Option<String>,
|
|
|
}
|
|
|
|
|
|
impl PlanRow {
|
|
|
- fn to_ref(&self) -> PlanRef {
|
|
|
+ pub(crate) fn to_ref(&self) -> PlanRef {
|
|
|
PlanRef {
|
|
|
plan_id: self.plan_id.clone(),
|
|
|
plan_name: self.plan_name.clone(),
|
|
|
@@ -684,12 +685,12 @@ impl PlanRow {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fn monthly(&self) -> i64 {
|
|
|
+ pub(crate) fn monthly(&self) -> i64 {
|
|
|
monthly_settle_of(self.monthly_settle_cents.as_deref().and_then(|s| s.trim().parse().ok()), self.annual_price_cents.trim().parse().unwrap_or(0))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-async fn plan_rows(state: &AppState, ids: &[String]) -> Result<Vec<PlanRow>, BosError> {
|
|
|
+pub(crate) async fn plan_rows(state: &AppState, ids: &[String]) -> Result<Vec<PlanRow>, BosError> {
|
|
|
if ids.is_empty() {
|
|
|
return Ok(Vec::new());
|
|
|
}
|
|
|
@@ -699,33 +700,33 @@ async fn plan_rows(state: &AppState, ids: &[String]) -> Result<Vec<PlanRow>, Bos
|
|
|
state.db.query_all::<PlanRow>(&sql, p.values()).await
|
|
|
}
|
|
|
|
|
|
-async fn plan_row(state: &AppState, plan_id: &str) -> Result<Option<PlanRow>, BosError> {
|
|
|
+pub(crate) async fn plan_row(state: &AppState, plan_id: &str) -> Result<Option<PlanRow>, BosError> {
|
|
|
Ok(plan_rows(state, &[plan_id.to_string()]).await?.pop())
|
|
|
}
|
|
|
|
|
|
/// 合同行。
|
|
|
#[derive(Deserialize)]
|
|
|
-struct ContractRow {
|
|
|
+pub(crate) struct ContractRow {
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- contract_id: String,
|
|
|
+ pub(crate) contract_id: String,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- customer_id: String,
|
|
|
+ pub(crate) customer_id: String,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- contract_no: String,
|
|
|
+ pub(crate) contract_no: String,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- external_no: Option<String>,
|
|
|
+ pub(crate) external_no: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- status: String,
|
|
|
+ pub(crate) status: String,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- end_date: Option<String>,
|
|
|
+ pub(crate) end_date: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- attachment_url: Option<String>,
|
|
|
+ pub(crate) attachment_url: Option<String>,
|
|
|
}
|
|
|
|
|
|
const CONTRACT_COLS: &str = "SELECT k.contract_id, k.customer_id, k.contract_no, k.external_no, k.status, \
|
|
|
k.end_date, k.attachment_url";
|
|
|
|
|
|
-async fn contracts_of_customer(
|
|
|
+pub(crate) async fn contracts_of_customer(
|
|
|
state: &AppState,
|
|
|
customer_id: &str,
|
|
|
) -> Result<Vec<ContractRow>, BosError> {
|
|
|
@@ -737,37 +738,37 @@ async fn contracts_of_customer(
|
|
|
state.db.query_all::<ContractRow>(&sql, p.values()).await
|
|
|
}
|
|
|
|
|
|
-async fn contract_row(state: &AppState, contract_id: &str) -> Result<Option<ContractRow>, BosError> {
|
|
|
+pub(crate) async fn contract_row(state: &AppState, contract_id: &str) -> Result<Option<ContractRow>, BosError> {
|
|
|
let mut p = Params::default();
|
|
|
let c = p.push(Value::String(contract_id.to_string()));
|
|
|
let sql = format!("{CONTRACT_COLS} FROM contract k WHERE k.contract_id = {c}::text");
|
|
|
state.db.query_one::<ContractRow>(&sql, p.values()).await
|
|
|
}
|
|
|
|
|
|
-/// 合同服务构成条目(`custom_spec`=合同条目派生档的来源)。
|
|
|
+/// 合同服务构成条目(`custom_spec`=合同条目派生档的来源)。`succession` 共用 ⇒ 字段 `pub(crate)`。
|
|
|
#[derive(Deserialize)]
|
|
|
-struct ItemRow {
|
|
|
+pub(crate) struct ItemRow {
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- item_id: String,
|
|
|
+ pub(crate) item_id: String,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- contract_id: String,
|
|
|
+ pub(crate) contract_id: String,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
- item_kind: String,
|
|
|
+ pub(crate) item_kind: String,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- plan_id: Option<String>,
|
|
|
+ pub(crate) plan_id: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- derived_plan_id: Option<String>,
|
|
|
+ pub(crate) derived_plan_id: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- use_category: Option<String>,
|
|
|
+ pub(crate) use_category: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
- annual_price_cents: Option<String>,
|
|
|
- line_exits: Option<Value>,
|
|
|
+ pub(crate) annual_price_cents: Option<String>,
|
|
|
+ pub(crate) line_exits: Option<Value>,
|
|
|
}
|
|
|
|
|
|
const ITEM_COLS: &str = "SELECT i.item_id, i.contract_id, i.item_kind, i.plan_id, i.derived_plan_id, \
|
|
|
i.use_category, i.annual_price_cents, i.line_exits";
|
|
|
|
|
|
-async fn items_of_contracts(
|
|
|
+pub(crate) async fn items_of_contracts(
|
|
|
state: &AppState,
|
|
|
contract_ids: &[String],
|
|
|
) -> Result<Vec<ItemRow>, BosError> {
|
|
|
@@ -931,7 +932,7 @@ pub async fn plan_options(
|
|
|
///
|
|
|
/// ⚠️ 档位⛔ 有「可用日期窗口」列(`catalog_plan` 在册列只到 `status`/`first_referred_at`,
|
|
|
/// 设计稿未给 `available_from`/`available_to`)⇒ 停用只按 `status` 判,⛔ 造列。
|
|
|
-fn plan_selectability(pr: &PlanRef, customer_id: &str) -> (bool, Option<String>) {
|
|
|
+pub(crate) fn plan_selectability(pr: &PlanRef, customer_id: &str) -> (bool, Option<String>) {
|
|
|
if !pr.available {
|
|
|
return (false, Some("档位已停用,不被新订阅选中".to_string()));
|
|
|
}
|
|
|
@@ -949,7 +950,7 @@ fn plan_selectability(pr: &PlanRef, customer_id: &str) -> (bool, Option<String>)
|
|
|
///
|
|
|
/// 金额一律按「分」记(§8.1);`line_exits` 记编码数组;⛔ 把整表原文塞进审计。
|
|
|
#[derive(Clone)]
|
|
|
-struct SubAuditView {
|
|
|
+pub(crate) struct SubAuditView {
|
|
|
subscription_id: String,
|
|
|
customer_id: String,
|
|
|
status: String,
|
|
|
@@ -972,7 +973,7 @@ struct SubAuditView {
|
|
|
}
|
|
|
|
|
|
impl SubAuditView {
|
|
|
- fn of_row(r: &SubRow) -> Self {
|
|
|
+ pub(crate) fn of_row(r: &SubRow) -> Self {
|
|
|
Self {
|
|
|
subscription_id: r.subscription_id.clone(),
|
|
|
customer_id: r.customer_id.clone(),
|
|
|
@@ -996,7 +997,7 @@ impl SubAuditView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fn to_json(&self) -> Value {
|
|
|
+ pub(crate) fn to_json(&self) -> Value {
|
|
|
json!({
|
|
|
"subscription_id": self.subscription_id,
|
|
|
"customer_id": self.customer_id,
|
|
|
@@ -1044,7 +1045,7 @@ impl SubAuditView {
|
|
|
/// `subscription.create`/`subscription.replace`/`subscription.update`/`subscription.delete`)。
|
|
|
///
|
|
|
/// 与其余域同口径:业务短批落库后同请求内补写,⛔ 审计失败把主流程带崩 ⇒ 只回 `audit_written:false`。
|
|
|
-async fn write_sub_audit(
|
|
|
+pub(crate) async fn write_sub_audit(
|
|
|
state: &AppState,
|
|
|
auth: &bos_scope::AuthContext,
|
|
|
action: &str,
|
|
|
@@ -1300,54 +1301,40 @@ fn category_of(payload: Option<&String>, plan: &PlanRow) -> Result<UseCategory,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/// 周期与价格的派生结果(§5.2 段 3/4)。
|
|
|
-struct Period {
|
|
|
- term: String,
|
|
|
- start: String,
|
|
|
- end: String,
|
|
|
- annual: i64,
|
|
|
- monthly: i64,
|
|
|
+/// 周期与价格的派生结果(§5.2 段 3/4)。`succession` 公共层共用 ⇒ 字段 `pub(crate)`。
|
|
|
+#[derive(Clone)]
|
|
|
+pub(crate) struct Period {
|
|
|
+ pub(crate) term: String,
|
|
|
+ pub(crate) start: String,
|
|
|
+ pub(crate) end: String,
|
|
|
+ pub(crate) annual: i64,
|
|
|
+ pub(crate) monthly: i64,
|
|
|
}
|
|
|
|
|
|
/// `term` → 起止与年费/月结算的唯一折算点(⛔ 落库月数、⛔ 手工填价、⛔ 手工改到期日)。
|
|
|
-fn derive_period(
|
|
|
+///
|
|
|
+/// 实现收口在 [`super::succession::derive_period_of`]:合同新建页的逐条替换同样要按档位派生,
|
|
|
+/// 两处共用一份算式(⛔ 各写一套)。
|
|
|
+pub(crate) fn derive_period(
|
|
|
plan: &PlanRow,
|
|
|
term_raw: Option<&String>,
|
|
|
start_raw: Option<&String>,
|
|
|
contract_end: Option<&str>,
|
|
|
today: &str,
|
|
|
) -> Result<Period, BosError> {
|
|
|
- let term = opt_trim(term_raw).unwrap_or("yearly").to_string();
|
|
|
- let months = term_months(&term)?;
|
|
|
- let start = parse_date("start_date", opt_trim(start_raw).unwrap_or(today))?;
|
|
|
- if let Some(ce) = contract_end {
|
|
|
- let ced = parse_date("合同止期", ce)?;
|
|
|
- if start > ced {
|
|
|
- return Err(BosError::bad_params(format!(
|
|
|
- "订阅开始日 {} 晚于合同止期 {ce}(§5.2 校验合同止期)",
|
|
|
- date_text(start)
|
|
|
- )));
|
|
|
- }
|
|
|
- }
|
|
|
- // 下一周期生效日=开始日 + N 个月(无对应日折月末);结束日=再减一天(含开始日共 N×30 天口径)。
|
|
|
- let next_cycle = add_months_clamped(start, months);
|
|
|
- let end = (next_cycle - chrono::Duration::days(1)).format("%Y-%m-%d").to_string();
|
|
|
- let monthly = plan.monthly();
|
|
|
- let annual = annual_by_term(
|
|
|
+ super::succession::derive_period_of(
|
|
|
plan.annual_price_cents.trim().parse::<i64>().unwrap_or(0),
|
|
|
- monthly,
|
|
|
- &term,
|
|
|
- );
|
|
|
- if annual <= 0 || annual > MAX_AMOUNT_CENTS {
|
|
|
- return Err(BosError::bad_params(format!(
|
|
|
- "折算年订阅价格 {annual} 越界(须∈ 1..={MAX_AMOUNT_CENTS} 分):档位年价不可用"
|
|
|
- )));
|
|
|
- }
|
|
|
- Ok(Period { term, start: date_text(start), end, annual, monthly })
|
|
|
+ plan.monthly(),
|
|
|
+ &plan.plan_id,
|
|
|
+ term_raw,
|
|
|
+ start_raw,
|
|
|
+ super::succession::EndMode::TermMonths(contract_end),
|
|
|
+ today,
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
/// 出口集合的解析+归一化(条目优先,缺省取档位;空集合=`KLT-L216`)。
|
|
|
-fn derive_exits(item: Option<&ItemRow>, plan: &PlanRow) -> Result<NormalizedExits, BosError> {
|
|
|
+pub(crate) fn derive_exits(item: Option<&ItemRow>, plan: &PlanRow) -> Result<NormalizedExits, BosError> {
|
|
|
let raw = match item {
|
|
|
Some(i) => exits_of(i.line_exits.as_ref(), "合同条目 line_exits")?,
|
|
|
None => Vec::new(),
|
|
|
@@ -1367,7 +1354,7 @@ fn derive_exits(item: Option<&ItemRow>, plan: &PlanRow) -> Result<NormalizedExit
|
|
|
}
|
|
|
|
|
|
/// I6 取数:该客户全部订阅(判据在 `check_i6_subscription` 内部,本处⛔ 预筛状态)。
|
|
|
-async fn i6_rows(state: &AppState, customer_id: &str, exclude: Option<&str>) -> Result<Vec<SubRow>, BosError> {
|
|
|
+pub(crate) async fn i6_rows(state: &AppState, customer_id: &str, exclude: Option<&str>) -> Result<Vec<SubRow>, BosError> {
|
|
|
Ok(subs_of_customer(state, customer_id)
|
|
|
.await?
|
|
|
.into_iter()
|
|
|
@@ -1375,7 +1362,7 @@ async fn i6_rows(state: &AppState, customer_id: &str, exclude: Option<&str>) ->
|
|
|
.collect())
|
|
|
}
|
|
|
|
|
|
-fn i6_borrow(rows: &[SubRow]) -> Vec<ActiveSubscriptionRow<'_>> {
|
|
|
+pub(crate) fn i6_borrow(rows: &[SubRow]) -> Vec<ActiveSubscriptionRow<'_>> {
|
|
|
rows.iter()
|
|
|
.map(|r| ActiveSubscriptionRow {
|
|
|
subscription_id: r.subscription_id.as_str(),
|
|
|
@@ -1398,7 +1385,7 @@ fn i6_borrow(rows: &[SubRow]) -> Vec<ActiveSubscriptionRow<'_>> {
|
|
|
///
|
|
|
/// `extra_plan` = 本次要写入/要摘除的订阅所引档位:`Some` 计入(新订、升降配),
|
|
|
/// 摘除一行时由调用方先从 `rows` 里剔掉再求和(§5.7 第 6 步回退对齐)。
|
|
|
-async fn quota_target(
|
|
|
+pub(crate) async fn quota_target(
|
|
|
state: &AppState,
|
|
|
customer_id: &str,
|
|
|
rows: &[SubRow],
|
|
|
@@ -1424,7 +1411,7 @@ async fn quota_target(
|
|
|
Ok(sums.get(customer_id).copied().unwrap_or(0))
|
|
|
}
|
|
|
|
|
|
-async fn customer_quota(state: &AppState, customer_id: &str) -> Result<i64, BosError> {
|
|
|
+pub(crate) async fn customer_quota(state: &AppState, customer_id: &str) -> Result<i64, BosError> {
|
|
|
let mut p = Params::default();
|
|
|
let c = p.push(Value::String(customer_id.to_string()));
|
|
|
let sql = format!("SELECT c.quota_cents AS v FROM customer c WHERE c.customer_id = {c}::text");
|
|
|
@@ -1437,7 +1424,7 @@ async fn customer_quota(state: &AppState, customer_id: &str) -> Result<i64, BosE
|
|
|
}
|
|
|
|
|
|
/// 额度对齐语句(§5.7 第 3/6 步:与库里现值不符 ⇒ 以应占额度为准修正)。
|
|
|
-fn quota_stmt(customer_id: &str, target: i64) -> DmlStatement {
|
|
|
+pub(crate) fn quota_stmt(customer_id: &str, target: i64) -> DmlStatement {
|
|
|
let mut p = Params::default();
|
|
|
let c = p.push(Value::String(customer_id.to_string()));
|
|
|
let q = p.push(Value::from(target));
|
|
|
@@ -1589,7 +1576,7 @@ pub(crate) async fn align_quota_for_customers(
|
|
|
}
|
|
|
|
|
|
/// 新订阅行 INSERT(六项快照+派生价格;`order_no`/`actual_opened_at` 由工单竣工回传,本轮留空)。
|
|
|
-fn insert_stmt(v: &NewValues) -> DmlStatement {
|
|
|
+pub(crate) fn insert_stmt(v: &NewValues) -> DmlStatement {
|
|
|
let mut p = Params::default();
|
|
|
let ph = |p: &mut Params, val: Value, cast: &str| -> String {
|
|
|
let s = p.push(val);
|
|
|
@@ -1678,7 +1665,7 @@ fn insert_stmt(v: &NewValues) -> DmlStatement {
|
|
|
/// 并回 `KLT-S20007`——而短批已原子提交(新订阅早已落库),调用方看到失败却查得到数据。
|
|
|
/// ⇒ 用 `COALESCE(first_referred_at, NOW())`:已打点的档位写回原值(⛔ 追溯改首次引用时间),
|
|
|
/// 命中行数恒为 1,语义仍是「首次引用时刻」。
|
|
|
-fn first_referred_stmt(plan_id: &str) -> DmlStatement {
|
|
|
+pub(crate) fn first_referred_stmt(plan_id: &str) -> DmlStatement {
|
|
|
let mut p = Params::default();
|
|
|
let a = p.push(Value::String(plan_id.to_string()));
|
|
|
DmlStatement::new(
|
|
|
@@ -1691,34 +1678,35 @@ fn first_referred_stmt(plan_id: &str) -> DmlStatement {
|
|
|
}
|
|
|
|
|
|
/// 待写入的新订阅行(已折算完全部派生值)。
|
|
|
-struct NewValues {
|
|
|
+#[derive(Clone)]
|
|
|
+pub(crate) struct NewValues {
|
|
|
/// 服务端发号(`SUB-{6位}`);[`insert_stmt`] 的 `subscription_id` 列靠它落库。
|
|
|
- subscription_id: String,
|
|
|
- customer_id: String,
|
|
|
- status: String,
|
|
|
- plan_id: String,
|
|
|
- plan_name: String,
|
|
|
- plan_kind: String,
|
|
|
- plan_owner_customer_id: Option<String>,
|
|
|
- use_category: String,
|
|
|
- sub_mode: String,
|
|
|
- line_exits: Value,
|
|
|
- line_exit_key: String,
|
|
|
- term: String,
|
|
|
- start_date: String,
|
|
|
- end_date: String,
|
|
|
- annual_price_cents: i64,
|
|
|
- monthly_settle_cents: i64,
|
|
|
- quota_slots: i64,
|
|
|
- contract_id: Option<String>,
|
|
|
- contract_item_id: Option<String>,
|
|
|
- trial_months: Option<i64>,
|
|
|
- discount_monthly_cents: Option<i64>,
|
|
|
- replaces_subscription_id: Option<String>,
|
|
|
+ pub(crate) subscription_id: String,
|
|
|
+ pub(crate) customer_id: String,
|
|
|
+ pub(crate) status: String,
|
|
|
+ pub(crate) plan_id: String,
|
|
|
+ pub(crate) plan_name: String,
|
|
|
+ pub(crate) plan_kind: String,
|
|
|
+ pub(crate) plan_owner_customer_id: Option<String>,
|
|
|
+ pub(crate) use_category: String,
|
|
|
+ pub(crate) sub_mode: String,
|
|
|
+ pub(crate) line_exits: Value,
|
|
|
+ pub(crate) line_exit_key: String,
|
|
|
+ pub(crate) term: String,
|
|
|
+ pub(crate) start_date: String,
|
|
|
+ pub(crate) end_date: String,
|
|
|
+ pub(crate) annual_price_cents: i64,
|
|
|
+ pub(crate) monthly_settle_cents: i64,
|
|
|
+ pub(crate) quota_slots: i64,
|
|
|
+ pub(crate) contract_id: Option<String>,
|
|
|
+ pub(crate) contract_item_id: Option<String>,
|
|
|
+ pub(crate) trial_months: Option<i64>,
|
|
|
+ pub(crate) discount_monthly_cents: Option<i64>,
|
|
|
+ pub(crate) replaces_subscription_id: Option<String>,
|
|
|
}
|
|
|
|
|
|
/// 发号(`SUB-000123`,与 customer/import_batch 的发号器同一张表)。
|
|
|
-async fn new_subscription_id(state: &AppState) -> Result<String, BosError> {
|
|
|
+pub(crate) async fn new_subscription_id(state: &AppState) -> Result<String, BosError> {
|
|
|
let year = chrono::Local::now()
|
|
|
.format("%Y")
|
|
|
.to_string()
|
|
|
@@ -1729,7 +1717,7 @@ async fn new_subscription_id(state: &AppState) -> Result<String, BosError> {
|
|
|
}
|
|
|
|
|
|
/// 六步短批的事后自检(UDS ⛔ 批内条件中止 ⇒ 只能事后核影响行数并如实点名)。
|
|
|
-fn assert_batch(results: &[bos_platform::clients::uds::DmlStatementResult], want: &[(&str, u64)]) -> Result<(), BosError> {
|
|
|
+pub(crate) fn assert_batch(results: &[bos_platform::clients::uds::DmlStatementResult], want: &[(&str, u64)]) -> Result<(), BosError> {
|
|
|
let hit = |i: usize| results.get(i).and_then(|r| r.affected_rows).unwrap_or(0);
|
|
|
let mut bad: Vec<String> = Vec::new();
|
|
|
for (i, (label, n)) in want.iter().enumerate() {
|
|
|
@@ -2053,6 +2041,7 @@ pub async fn create(
|
|
|
line_exits: exits.line_exits.clone(),
|
|
|
quota_slots: pr.sub_account_quota,
|
|
|
actor_user_id: actor,
|
|
|
+ original: None,
|
|
|
},
|
|
|
)
|
|
|
.await
|
|
|
@@ -2138,7 +2127,7 @@ pub async fn create(
|
|
|
}
|
|
|
|
|
|
/// 客户在册且在可见范围内 ⇒ 回客户名;越权或不在册=`KLT-M221`。
|
|
|
-async fn require_customer(
|
|
|
+pub(crate) async fn require_customer(
|
|
|
state: &AppState,
|
|
|
auth: &bos_scope::AuthContext,
|
|
|
customer_id: &str,
|
|
|
@@ -2156,7 +2145,7 @@ async fn require_customer(
|
|
|
// ───────────────────────── 写侧:升降配 ─────────────────────────
|
|
|
|
|
|
/// 原订阅已被换过的次数(`replaces_subscription_id` 唯一 ⇒ ≥1 即⛔ 再换)。
|
|
|
-async fn replacement_count(state: &AppState, origin_id: &str) -> Result<i64, BosError> {
|
|
|
+pub(crate) async fn replacement_count(state: &AppState, origin_id: &str) -> Result<i64, BosError> {
|
|
|
let mut p = Params::default();
|
|
|
let a = p.push(Value::String(origin_id.to_string()));
|
|
|
let sql = format!(
|
|
|
@@ -2336,108 +2325,53 @@ pub async fn change(
|
|
|
Ok(v) => v,
|
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
|
- let period = match derive_period(
|
|
|
- &plan,
|
|
|
- body.term.as_ref(),
|
|
|
- body.start_date.as_ref(),
|
|
|
- opt_trim(contract.end_date.as_ref()),
|
|
|
- &t,
|
|
|
- ) {
|
|
|
- Ok(v) => v,
|
|
|
- Err(e) => return json_err(e),
|
|
|
- };
|
|
|
- // I6(升降配照常;⛔ 出口一致性校验)
|
|
|
+ // I6/额度按**最终态**判一次(§5.3):剔除原订阅、加入新订阅后再复检。
|
|
|
// 候选集必须**排除被替换的原订阅**:升降配正是「用新行顶掉原行」,原行本就还在库里,
|
|
|
// ⛔ 把它算进「同分类×同出口已有一份」——旧写法让任何一次升降配都被自己的原行拦下
|
|
|
// (KLT-M224/60217「请在该行点『升降配』」,而用户点的正是升降配;缺陷 D-74)。
|
|
|
- let actives = match i6_rows(&state, &cid, Some(&rid)).await {
|
|
|
+ let existing = match subs_of_customer(&state, &cid).await {
|
|
|
Ok(v) => v,
|
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
|
- if let Err(e) = check_i6_subscription(&cid, category, &exits.line_exit_key, &i6_borrow(&actives)) {
|
|
|
- return json_err(e);
|
|
|
- }
|
|
|
let id = match new_subscription_id(&state).await {
|
|
|
Ok(v) => v,
|
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
|
- let nv = NewValues {
|
|
|
- subscription_id: id.clone(),
|
|
|
- customer_id: cid.clone(),
|
|
|
- status: subscription_status_of(&period.start, &period.end, &t).as_str().to_string(),
|
|
|
- plan_id: plan.plan_id.clone(),
|
|
|
- plan_name: plan.plan_name.clone(),
|
|
|
- plan_kind: plan.plan_kind.clone(),
|
|
|
- plan_owner_customer_id: opt_trim(plan.customer_id.as_ref()).map(str::to_string),
|
|
|
- use_category: category.as_str().to_string(),
|
|
|
- sub_mode: sub_mode_of(category).as_str().to_string(),
|
|
|
- line_exits: Value::Array(exits.line_exits.iter().cloned().map(Value::String).collect()),
|
|
|
- line_exit_key: exits.line_exit_key.clone(),
|
|
|
- term: period.term.clone(),
|
|
|
- start_date: period.start.clone(),
|
|
|
- end_date: period.end.clone(),
|
|
|
- annual_price_cents: period.annual,
|
|
|
- monthly_settle_cents: period.monthly,
|
|
|
- quota_slots: pr.sub_account_quota,
|
|
|
- contract_id: Some(contract_id.clone()),
|
|
|
- contract_item_id: item.map(|i| i.item_id.clone()),
|
|
|
+ let pin = super::succession::PlanInput {
|
|
|
+ plan: &plan,
|
|
|
+ item,
|
|
|
+ contract_id: &contract_id,
|
|
|
+ contract_end: opt_trim(contract.end_date.as_ref()),
|
|
|
+ term: body.term.as_ref(),
|
|
|
+ start_date: body.start_date.as_ref(),
|
|
|
trial_months: body.trial_months,
|
|
|
discount_monthly_cents: body.discount_monthly_cents,
|
|
|
- replaces_subscription_id: Some(rid.clone()),
|
|
|
- };
|
|
|
- // 截原(§5.3):结束日=新生效日前一天、状态到期。前置条件写进谓词(无行锁能力)。
|
|
|
- // ⚠️ P5-D4:同日升降配(原订阅也是今天生效)时「前一天」会落到 start−1 ⇒ 原订阅期间倒挂
|
|
|
- // (start > end),出账按期间天数折月费会算出负天数。这里把结束日钳到原订阅生效日,
|
|
|
- // 保证 start ≤ end;回执里如实说明「为零天期间,仅保留生效当日」。
|
|
|
- let (prev_end, same_day_cut) = match NaiveDate::parse_from_str(&period.start, "%Y-%m-%d") {
|
|
|
- Ok(d) => {
|
|
|
- let mut cand = d - chrono::Duration::days(1);
|
|
|
- let mut clamped = false;
|
|
|
- if let Some(s0) = orig.start_date.as_deref() {
|
|
|
- if let Ok(s) = NaiveDate::parse_from_str(s0, "%Y-%m-%d") {
|
|
|
- if cand < s {
|
|
|
- cand = s;
|
|
|
- clamped = true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- (date_text(cand), clamped)
|
|
|
- }
|
|
|
- Err(e) => return json_err(BosError::bad_params(format!("开始日不可解析:{e}"))),
|
|
|
+ row_version: body.row_version,
|
|
|
+ mode: super::succession::MatchMode::FollowPlan,
|
|
|
};
|
|
|
- let mut up = Params::default();
|
|
|
- let mut set: Vec<String> = Vec::new();
|
|
|
- set.push(format!("end_date = {}::date", up.push(Value::String(prev_end.clone()))));
|
|
|
- set.push(format!("status = {}::text", up.push(Value::String("expired".to_string()))));
|
|
|
- set.push("row_version = row_version + 1".to_string());
|
|
|
- let mut preds: Vec<String> = Vec::new();
|
|
|
- preds.push(format!("subscription_id = {}::text", up.push(Value::String(rid.clone()))));
|
|
|
- let in_use: Vec<String> = IN_USE_STATUS.iter().map(|s| up.push(Value::String(s.to_string()))).collect();
|
|
|
- preds.push(format!(
|
|
|
- "status IN ({})",
|
|
|
- in_use.iter().map(|s| format!("{s}::text")).collect::<Vec<_>>().join(",")
|
|
|
- ));
|
|
|
- if let Some(v) = body.row_version {
|
|
|
- preds.push(format!("row_version = {}::int", up.push(Value::from(v))));
|
|
|
- }
|
|
|
- let cut = DmlStatement::new(
|
|
|
- format!("UPDATE subscription SET {} {}", set.join(", "), up.where_clause(&preds)),
|
|
|
- up.values().to_vec(),
|
|
|
- );
|
|
|
- let mut for_quota = actives.clone();
|
|
|
- if let Some(pos) = for_quota.iter().position(|r| r.subscription_id == rid) {
|
|
|
- for_quota.remove(pos);
|
|
|
- }
|
|
|
- for_quota.push(SubRowPlaceholder::for_new(&id, &nv));
|
|
|
- let target = match quota_target(&state, &cid, &for_quota).await {
|
|
|
+ let planned = match super::succession::plan_change(&state, &cid, &orig, &id, &pin, &t, "").await
|
|
|
+ {
|
|
|
Ok(v) => v,
|
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
|
+ let planned_once = std::slice::from_ref(&planned);
|
|
|
+ if let Err(e) = super::succession::check_i6_final(&cid, &existing, planned_once) {
|
|
|
+ return json_err(e);
|
|
|
+ }
|
|
|
+ let nv = planned.new.clone();
|
|
|
+ let period = planned.period.clone();
|
|
|
+ let prev_end = planned.prev_end.clone();
|
|
|
+ let same_day_cut = planned.same_day_cut;
|
|
|
+ let target =
|
|
|
+ match super::succession::quota_target_final(&state, &cid, &existing, planned_once).await {
|
|
|
+ Ok(v) => v,
|
|
|
+ Err(e) => return json_err(e),
|
|
|
+ };
|
|
|
let before = match customer_quota(&state, &cid).await {
|
|
|
Ok(v) => v,
|
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
|
- let mut stmts: Vec<DmlStatement> = vec![cut, insert_stmt(&nv), first_referred_stmt(&pid)];
|
|
|
+ let mut stmts: Vec<DmlStatement> = super::succession::change_dml(&planned);
|
|
|
if before != target {
|
|
|
stmts.push(quota_stmt(&cid, target));
|
|
|
}
|
|
|
@@ -2445,16 +2379,15 @@ pub async fn change(
|
|
|
Ok(r) => r,
|
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
|
- let mut want: Vec<(&str, u64)> = vec![
|
|
|
- ("原订阅截原", 1),
|
|
|
- ("新订阅 INSERT", 1),
|
|
|
- ("catalog_plan.first_referred_at 打点", 1),
|
|
|
- ];
|
|
|
+ let mut want: Vec<(&str, u64)> = super::succession::CHANGE_DML_LABELS
|
|
|
+ .iter()
|
|
|
+ .map(|s| (*s, 1))
|
|
|
+ .collect();
|
|
|
if stmts.len() > 3 {
|
|
|
want.push(("客户额度对齐", 1));
|
|
|
}
|
|
|
if let Err(e) = assert_batch(&results, &want) {
|
|
|
- // ⛔ 把任何行数异常都冒充成「乐观锁冲突」:只有**截原**落空才是 §5.3 的承接前置不符
|
|
|
+ // ⛔ 把任何行数异常都冒充成「乐观锁冲突」:只有**截原**落空才是 §5.3 的前置不符
|
|
|
let cut_rows = results.first().and_then(|r| r.affected_rows).unwrap_or(0);
|
|
|
if cut_rows == 0 {
|
|
|
return json_err(BosError::klt(
|
|
|
@@ -2502,6 +2435,7 @@ pub async fn change(
|
|
|
line_exits: exits.line_exits.clone(),
|
|
|
quota_slots: pr.sub_account_quota,
|
|
|
actor_user_id: actor,
|
|
|
+ original: Some(super::succession::original_sub(&state, &orig).await),
|
|
|
},
|
|
|
)
|
|
|
.await
|
|
|
@@ -2574,10 +2508,10 @@ pub async fn change(
|
|
|
}
|
|
|
|
|
|
/// 升降配额度对齐用的行占位(把 [`NewValues`] 折算成一行「将来在册」的订阅行)。
|
|
|
-struct SubRowPlaceholder;
|
|
|
+pub(crate) struct SubRowPlaceholder;
|
|
|
|
|
|
impl SubRowPlaceholder {
|
|
|
- fn for_new(id: &str, v: &NewValues) -> SubRow {
|
|
|
+ pub(crate) fn for_new(id: &str, v: &NewValues) -> SubRow {
|
|
|
SubRow {
|
|
|
subscription_id: id.to_string(),
|
|
|
customer_id: v.customer_id.clone(),
|