|
@@ -59,11 +59,12 @@ use super::succession;
|
|
|
use bos_core::KltCode;
|
|
use bos_core::KltCode;
|
|
|
// 第 3 册判据一律走 `bos-invariant`(订阅§10.1 纪律①:⛔ 在 handler 里重写第二套判据)。
|
|
// 第 3 册判据一律走 `bos-invariant`(订阅§10.1 纪律①:⛔ 在 handler 里重写第二套判据)。
|
|
|
use bos_invariant::{
|
|
use bos_invariant::{
|
|
|
- check_contract_deletable, check_contract_items, contract_attachment_object_key,
|
|
|
|
|
- contract_edit_scope, contracts_opened, normalize_line_exits,
|
|
|
|
|
- replaced_attachment_object, resolve_contract_no, validate_contract_payload, AxisLock,
|
|
|
|
|
- ContractDraft, ContractEditScope, ContractItemRaw, ContractRaw, CrossRead, ItemMode, Opened,
|
|
|
|
|
- OpenedProbe, PlanFamily, PlanRef, CONTRACT_ATTACHMENT_KEY_PREFIX,
|
|
|
|
|
|
|
+ apply_discount_cents, check_contract_deletable, check_contract_items,
|
|
|
|
|
+ contract_attachment_object_key, contract_edit_scope, contracts_opened, discount_rate_text,
|
|
|
|
|
+ normalize_line_exits, package_line_cents, parse_scaled_decimal, replaced_attachment_object,
|
|
|
|
|
+ resolve_contract_no, validate_contract_payload, AxisLock, ContractDraft, ContractEditScope,
|
|
|
|
|
+ ContractItemRaw, ContractRaw, CrossRead, ItemMode, Opened, OpenedProbe, PlanFamily, PlanRef,
|
|
|
|
|
+ CONTRACT_ATTACHMENT_KEY_PREFIX, DISCOUNT_PCT_SCALE, PRICE_FACTOR_SCALE,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/// 补列后设计列**全部在册** ⇒ 无缺列;键仍回给前端(值=空数组),契约形状不变。
|
|
/// 补列后设计列**全部在册** ⇒ 无缺列;键仍回给前端(值=空数组),契约形状不变。
|
|
@@ -108,8 +109,8 @@ const SERVICE_ITEM_BANNED_KEYS: [&str; 10] = [
|
|
|
const ROW_VERSION_INIT: i64 = 1;
|
|
const ROW_VERSION_INIT: i64 = 1;
|
|
|
|
|
|
|
|
const CONTRACT_COLS: &str = "k.contract_id, k.customer_id, k.contract_no, k.status, \
|
|
const CONTRACT_COLS: &str = "k.contract_id, k.customer_id, k.contract_no, k.status, \
|
|
|
- k.amount_cents, k.created_at, k.external_no, k.contract_type, \
|
|
|
|
|
- k.sign_date, k.service_months, \
|
|
|
|
|
|
|
+ k.amount_cents, k.discount_rate_pct, k.created_at, k.external_no, \
|
|
|
|
|
+ k.contract_type, k.sign_date, k.service_months, \
|
|
|
k.start_date, k.end_date, k.agent_name, k.agent_mobile, \
|
|
k.start_date, k.end_date, k.agent_name, k.agent_mobile, \
|
|
|
k.agent_handover_on, k.agent_org, k.attachment_url, k.row_version, \
|
|
k.agent_handover_on, k.agent_org, k.attachment_url, k.row_version, \
|
|
|
k.source, k.created_by, \
|
|
k.source, k.created_by, \
|
|
@@ -136,14 +137,14 @@ const CONTRACT_FROM: &str = "FROM contract k \
|
|
|
/// `source`):本语句=合同录入=唯一写入口,`import`/`operator_sync` 要等各自的
|
|
/// `source`):本语句=合同录入=唯一写入口,`import`/`operator_sync` 要等各自的
|
|
|
/// 同步写入口落地才可能出现在库里。
|
|
/// 同步写入口落地才可能出现在库里。
|
|
|
const CONTRACT_INSERT: &str = "INSERT INTO contract (contract_id, customer_id, contract_no, \
|
|
const CONTRACT_INSERT: &str = "INSERT INTO contract (contract_id, customer_id, contract_no, \
|
|
|
- external_no, amount_cents, contract_type, sign_date, service_months, start_date, end_date, \
|
|
|
|
|
- agent_name, agent_mobile, \
|
|
|
|
|
|
|
+ external_no, amount_cents, discount_rate_pct, contract_type, sign_date, service_months, \
|
|
|
|
|
+ start_date, end_date, agent_name, agent_mobile, \
|
|
|
agent_handover_on, agent_org, attachment_url, row_version, source, created_by, \
|
|
agent_handover_on, agent_org, attachment_url, row_version, source, created_by, \
|
|
|
renew_from_contract_id) \
|
|
renew_from_contract_id) \
|
|
|
- VALUES ($1::text, $2::text, $3::text, $4::text, $5::bigint, $6::text, $7::date, $8::int, \
|
|
|
|
|
- $9::date, $10::date, \
|
|
|
|
|
- $11::text, $12::text, $13::date, $14::text, $15::text, $16::int, 'manual', $17::text, \
|
|
|
|
|
- $18::text)";
|
|
|
|
|
|
|
+ VALUES ($1::text, $2::text, $3::text, $4::text, $5::bigint, $6::numeric, $7::text, $8::date, \
|
|
|
|
|
+ $9::int, $10::date, $11::date, \
|
|
|
|
|
+ $12::text, $13::text, $14::date, $15::text, $16::text, $17::int, 'manual', $18::text, \
|
|
|
|
|
+ $19::text)";
|
|
|
|
|
|
|
|
/// 条目删除(三向对比里「库有载荷无」的一支;删前先过订阅引用=`KLT-L213`)。
|
|
/// 条目删除(三向对比里「库有载荷无」的一支;删前先过订阅引用=`KLT-L213`)。
|
|
|
const ITEM_DELETE: &str =
|
|
const ITEM_DELETE: &str =
|
|
@@ -157,11 +158,11 @@ const IP_DELETE_ALL: &str = "DELETE FROM contract_ip_entry WHERE contract_id = $
|
|
|
/// 为什么全列写回:判据跑在**合并后的整份载荷**上(请求 ?? 库里现值),落库⛔ 只写请求
|
|
/// 为什么全列写回:判据跑在**合并后的整份载荷**上(请求 ?? 库里现值),落库⛔ 只写请求
|
|
|
/// 带来的那几个字段——否则「判据校验过的值」与「写进库的值」就是两套账。
|
|
/// 带来的那几个字段——否则「判据校验过的值」与「写进库的值」就是两套账。
|
|
|
const CONTRACT_UPDATE_ALL: &str = "UPDATE contract SET external_no = $2::text, \
|
|
const CONTRACT_UPDATE_ALL: &str = "UPDATE contract SET external_no = $2::text, \
|
|
|
- amount_cents = $3::bigint, contract_type = $4::text, sign_date = $5::date, \
|
|
|
|
|
- service_months = $6::int, start_date = $7::date, end_date = $8::date, \
|
|
|
|
|
- agent_name = $9::text, agent_mobile = $10::text, agent_handover_on = $11::date, \
|
|
|
|
|
- agent_org = $12::text, attachment_url = $13::text, row_version = row_version + 1, \
|
|
|
|
|
- updated_at = NOW() WHERE contract_id = $1::text AND row_version = $14::int";
|
|
|
|
|
|
|
+ amount_cents = $3::bigint, discount_rate_pct = $4::numeric, contract_type = $5::text, \
|
|
|
|
|
+ sign_date = $6::date, service_months = $7::int, start_date = $8::date, end_date = $9::date, \
|
|
|
|
|
+ agent_name = $10::text, agent_mobile = $11::text, agent_handover_on = $12::date, \
|
|
|
|
|
+ agent_org = $13::text, attachment_url = $14::text, row_version = row_version + 1, \
|
|
|
|
|
+ updated_at = NOW() WHERE contract_id = $1::text AND row_version = $15::int";
|
|
|
|
|
|
|
|
/// 条目新增的**全列**形态(D-15:六列=主键、合同、档位、份数、形态、出口;
|
|
/// 条目新增的**全列**形态(D-15:六列=主键、合同、档位、份数、形态、出口;
|
|
|
/// P1 加三列=条目形态、父条目、增量引用订阅)。
|
|
/// P1 加三列=条目形态、父条目、增量引用订阅)。
|
|
@@ -249,9 +250,9 @@ pub struct ServiceItemReq {
|
|
|
pub line_exits: Option<Value>,
|
|
pub line_exits: Option<Value>,
|
|
|
/// 条目形态(D-9):`new`(缺省)/`increment`。
|
|
/// 条目形态(D-9):`new`(缺省)/`increment`。
|
|
|
pub item_mode: Option<String>,
|
|
pub item_mode: Option<String>,
|
|
|
- /// 附加项在**本合同内**的父条目主键(编辑态用;新建态还没有服务端主键)。
|
|
|
|
|
|
|
+ /// 叠加服务在**本合同内**的父条目主键(编辑态用;新建态还没有服务端主键)。
|
|
|
pub serves_item_id: Option<String>,
|
|
pub serves_item_id: Option<String>,
|
|
|
- /// 附加项父条目在本载荷 `service_items` 里的 **0 基序号**(新建态用;编辑态也可用)。
|
|
|
|
|
|
|
+ /// 叠加服务父条目在本载荷 `service_items` 里的 **0 基序号**(新建态用;编辑态也可用)。
|
|
|
/// ⚠️ 与 D-7 导入模板的「父条目序号」同一口径(0 基)。
|
|
/// ⚠️ 与 D-7 导入模板的「父条目序号」同一口径(0 基)。
|
|
|
pub serves_item_index: Option<Value>,
|
|
pub serves_item_index: Option<Value>,
|
|
|
/// 增量条目引用的既有 `link` 订阅号(跨合同,D-9)。
|
|
/// 增量条目引用的既有 `link` 订阅号(跨合同,D-9)。
|
|
@@ -310,6 +311,8 @@ pub struct ContractCreateReq {
|
|
|
/// 签署日期(YYYY-MM-DD,选填;缺省按经办交接日期兜底)。
|
|
/// 签署日期(YYYY-MM-DD,选填;缺省按经办交接日期兜底)。
|
|
|
pub sign_date: Option<String>,
|
|
pub sign_date: Option<String>,
|
|
|
pub contract_amount_cents: Option<Value>,
|
|
pub contract_amount_cents: Option<Value>,
|
|
|
|
|
+ /// 折扣率(百分数,默认 100);接口收数字或十进制字符串。
|
|
|
|
|
+ pub discount_rate_pct: Option<Value>,
|
|
|
/// 服务期(月):替代原 `pay_cycle`,结束日=生效日+服务期−1 天。
|
|
/// 服务期(月):替代原 `pay_cycle`,结束日=生效日+服务期−1 天。
|
|
|
pub service_months: Option<Value>,
|
|
pub service_months: Option<Value>,
|
|
|
pub start_date: Option<String>,
|
|
pub start_date: Option<String>,
|
|
@@ -343,6 +346,8 @@ pub struct ContractUpdateReq {
|
|
|
/// 签署日期(YYYY-MM-DD)。
|
|
/// 签署日期(YYYY-MM-DD)。
|
|
|
pub sign_date: Option<String>,
|
|
pub sign_date: Option<String>,
|
|
|
pub contract_amount_cents: Option<Value>,
|
|
pub contract_amount_cents: Option<Value>,
|
|
|
|
|
+ /// 折扣率(百分数,默认 100)。
|
|
|
|
|
+ pub discount_rate_pct: Option<Value>,
|
|
|
/// 服务期(月):替代原 `pay_cycle`。
|
|
/// 服务期(月):替代原 `pay_cycle`。
|
|
|
pub service_months: Option<Value>,
|
|
pub service_months: Option<Value>,
|
|
|
pub start_date: Option<String>,
|
|
pub start_date: Option<String>,
|
|
@@ -370,6 +375,8 @@ struct ContractRow {
|
|
|
status: String,
|
|
status: String,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
amount_cents: String,
|
|
amount_cents: String,
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ discount_rate_pct: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
created_at: String,
|
|
created_at: String,
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
@@ -428,7 +435,7 @@ struct ItemRow {
|
|
|
/// 条目形态(D-9):`new`/`increment`。
|
|
/// 条目形态(D-9):`new`/`increment`。
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
item_mode: Option<String>,
|
|
item_mode: Option<String>,
|
|
|
- /// 附加项在本合同内的父条目(D-7)。
|
|
|
|
|
|
|
+ /// 叠加服务在本合同内的父条目(D-7)。
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
serves_item_id: Option<String>,
|
|
serves_item_id: Option<String>,
|
|
|
/// 增量条目引用的既有链路订阅(D-9)。
|
|
/// 增量条目引用的既有链路订阅(D-9)。
|
|
@@ -527,6 +534,7 @@ fn base_json(r: &ContractRow, customer_name: Option<&str>) -> Value {
|
|
|
"status": r.status,
|
|
"status": r.status,
|
|
|
"amount_cents": as_num(&r.amount_cents),
|
|
"amount_cents": as_num(&r.amount_cents),
|
|
|
"contract_amount_cents": as_num(&r.amount_cents),
|
|
"contract_amount_cents": as_num(&r.amount_cents),
|
|
|
|
|
+ "discount_rate_pct": discount_rate_num(r.discount_rate_pct.as_deref()),
|
|
|
"external_no": r.external_no,
|
|
"external_no": r.external_no,
|
|
|
"contract_type": blank(&r.contract_type).unwrap_or("new"),
|
|
"contract_type": blank(&r.contract_type).unwrap_or("new"),
|
|
|
"sign_date": r.sign_date,
|
|
"sign_date": r.sign_date,
|
|
@@ -744,40 +752,72 @@ async fn customer_profile(
|
|
|
state: &AppState,
|
|
state: &AppState,
|
|
|
customer_id: &str,
|
|
customer_id: &str,
|
|
|
) -> Result<Option<Value>, BosError> {
|
|
) -> Result<Option<Value>, BosError> {
|
|
|
|
|
+ /// 合同详情「01 客户资料」联查:字段面与新增合同同段对齐(技术/财务联系人、备注、
|
|
|
|
|
+ /// 运维团队、营业执照摘要、挂载节点),⛔ 再靠客户列表命中。
|
|
|
#[derive(Deserialize)]
|
|
#[derive(Deserialize)]
|
|
|
struct Row {
|
|
struct Row {
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
customer_id: String,
|
|
customer_id: String,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
customer_name: String,
|
|
customer_name: String,
|
|
|
- #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
subject_type: Option<String>,
|
|
subject_type: Option<String>,
|
|
|
- #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
acct_status: Option<String>,
|
|
acct_status: Option<String>,
|
|
|
- #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
contact_name: Option<String>,
|
|
contact_name: Option<String>,
|
|
|
- #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
contact_mobile: Option<String>,
|
|
contact_mobile: Option<String>,
|
|
|
- #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ tech_contact_name: Option<String>,
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ tech_contact_mobile: Option<String>,
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ finance_contact_name: Option<String>,
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ finance_contact_mobile: Option<String>,
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ remark: Option<String>,
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
address: Option<String>,
|
|
address: Option<String>,
|
|
|
- #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
identity_no_cipher: Option<String>,
|
|
identity_no_cipher: Option<String>,
|
|
|
- #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
operator_name: Option<String>,
|
|
operator_name: Option<String>,
|
|
|
- #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
partner_name: Option<String>,
|
|
partner_name: Option<String>,
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ license_object_key: Option<String>,
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ license_file_name: Option<String>,
|
|
|
|
|
+ /// SQL 侧一次算好的超期判据(起算点=建档日);`true` ⇒ 不下发下载签名。
|
|
|
|
|
+ #[serde(default)]
|
|
|
|
|
+ license_expired: Option<bool>,
|
|
|
}
|
|
}
|
|
|
#[derive(Deserialize)]
|
|
#[derive(Deserialize)]
|
|
|
struct Mount {
|
|
struct Mount {
|
|
|
- #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ parent_node_id: Option<String>,
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
path_name: Option<String>,
|
|
path_name: Option<String>,
|
|
|
}
|
|
}
|
|
|
|
|
+ #[derive(Deserialize)]
|
|
|
|
|
+ struct TeamRow {
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ team_id: Option<String>,
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ team_name: Option<String>,
|
|
|
|
|
+ }
|
|
|
|
|
+ let retention = crate::license_storage::license_retention_days();
|
|
|
let mut p = Params::default();
|
|
let mut p = Params::default();
|
|
|
let Some(cph) = p.push_eq(Some(customer_id)) else { return Ok(None) };
|
|
let Some(cph) = p.push_eq(Some(customer_id)) else { return Ok(None) };
|
|
|
let sql = format!(
|
|
let sql = format!(
|
|
|
"SELECT c.customer_id, c.customer_name, c.subject_type, c.acct_status, c.contact_name, \
|
|
"SELECT c.customer_id, c.customer_name, c.subject_type, c.acct_status, c.contact_name, \
|
|
|
- c.contact_mobile, c.address, c.identity_no_cipher, op.name AS operator_name, \
|
|
|
|
|
- pa.name AS partner_name \
|
|
|
|
|
|
|
+ c.contact_mobile, c.tech_contact_name, c.tech_contact_mobile, \
|
|
|
|
|
+ c.finance_contact_name, c.finance_contact_mobile, c.remark, c.address, \
|
|
|
|
|
+ c.identity_no_cipher, op.name AS operator_name, pa.name AS partner_name, \
|
|
|
|
|
+ c.license_object_key, c.license_file_name, \
|
|
|
|
|
+ (c.created_at < now() - INTERVAL '{retention} day') AS license_expired \
|
|
|
FROM customer c LEFT JOIN operator op ON op.operator_id = c.operator_id \
|
|
FROM customer c LEFT JOIN operator op ON op.operator_id = c.operator_id \
|
|
|
LEFT JOIN partner pa ON pa.partner_id = c.partner_id \
|
|
LEFT JOIN partner pa ON pa.partner_id = c.partner_id \
|
|
|
WHERE c.customer_id = {cph}::text AND c.deleted_at IS NULL LIMIT 1"
|
|
WHERE c.customer_id = {cph}::text AND c.deleted_at IS NULL LIMIT 1"
|
|
@@ -792,7 +832,7 @@ async fn customer_profile(
|
|
|
let mounts: Vec<Mount> = state.db
|
|
let mounts: Vec<Mount> = state.db
|
|
|
.query_all::<Mount>(
|
|
.query_all::<Mount>(
|
|
|
&format!(
|
|
&format!(
|
|
|
- "SELECT r.path_name FROM customer_region_mount m \
|
|
|
|
|
|
|
+ "SELECT m.parent_node_id, r.path_name FROM customer_region_mount m \
|
|
|
LEFT JOIN bos_region_meta r ON r.node_id = m.parent_node_id \
|
|
LEFT JOIN bos_region_meta r ON r.node_id = m.parent_node_id \
|
|
|
WHERE m.terminal_state = 'mounted' AND m.customer_id = {mph}::text \
|
|
WHERE m.terminal_state = 'mounted' AND m.customer_id = {mph}::text \
|
|
|
ORDER BY m.created_at"
|
|
ORDER BY m.created_at"
|
|
@@ -807,8 +847,76 @@ async fn customer_profile(
|
|
|
.into_iter()
|
|
.into_iter()
|
|
|
.collect::<Vec<&str>>()
|
|
.collect::<Vec<&str>>()
|
|
|
.join("、");
|
|
.join("、");
|
|
|
|
|
+ // 挂载节点取最早一条(与客户档案「所属区域」单挂点口径一致);供前端反查运营团队。
|
|
|
|
|
+ let region_node_id = mounts
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .find_map(|m| blank(&m.parent_node_id).map(str::to_string));
|
|
|
|
|
+ let mut tp = Params::default();
|
|
|
|
|
+ let Some(tph) = tp.push_eq(Some(customer_id)) else {
|
|
|
|
|
+ return Ok(None);
|
|
|
|
|
+ };
|
|
|
|
|
+ let teams: Vec<TeamRow> = state
|
|
|
|
|
+ .db
|
|
|
|
|
+ .query_all::<TeamRow>(
|
|
|
|
|
+ &format!(
|
|
|
|
|
+ "SELECT b.team_id, o.team_name FROM customer_team_belong b \
|
|
|
|
|
+ LEFT JOIN ops_team o ON o.team_id = b.team_id \
|
|
|
|
|
+ WHERE b.customer_id = {tph}::text AND b.is_current = TRUE \
|
|
|
|
|
+ ORDER BY b.team_id"
|
|
|
|
|
+ ),
|
|
|
|
|
+ tp.values(),
|
|
|
|
|
+ )
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ let ops_team_names: Vec<String> = teams
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .filter_map(|t| {
|
|
|
|
|
+ blank(&t.team_name)
|
|
|
|
|
+ .map(str::to_string)
|
|
|
|
|
+ .or_else(|| blank(&t.team_id).map(str::to_string))
|
|
|
|
|
+ })
|
|
|
|
|
+ .collect();
|
|
|
let identity_no_masked =
|
|
let identity_no_masked =
|
|
|
super::customer::masked_identity(state, r.identity_no_cipher.clone(), &r.customer_id).await;
|
|
super::customer::masked_identity(state, r.identity_no_cipher.clone(), &r.customer_id).await;
|
|
|
|
|
+ // 营业执照摘要:对象键⛔ 上响应体;超期只挡签名,不删对象(与 /customer/get 同纪律)。
|
|
|
|
|
+ let license = match (
|
|
|
|
|
+ r.license_object_key.as_deref().map(str::trim).filter(|s| !s.is_empty()),
|
|
|
|
|
+ r.license_file_name.as_deref().map(str::trim).filter(|s| !s.is_empty()),
|
|
|
|
|
+ ) {
|
|
|
|
|
+ (Some(_key), Some(file_name)) if r.license_expired.unwrap_or(false) => json!({
|
|
|
|
|
+ "file_name": file_name,
|
|
|
|
|
+ "status": "expired",
|
|
|
|
|
+ "view_url": Value::Null,
|
|
|
|
|
+ "view_url_expires_at": Value::Null,
|
|
|
|
|
+ }),
|
|
|
|
|
+ (Some(key), Some(file_name)) => {
|
|
|
|
|
+ let sig = state
|
|
|
|
|
+ .platform
|
|
|
|
|
+ .oss_presign_get(&state.tenant_id, &state.project_id, key)
|
|
|
|
|
+ .await
|
|
|
|
|
+ .map_err(|e| {
|
|
|
|
|
+ BosError::biz(
|
|
|
|
|
+ ErrorCode::Downstream,
|
|
|
|
|
+ format!(
|
|
|
|
|
+ "客户 {} 的营业执照影像下载签名获取失败({e})⇒ 本次不下发 license.view_url;\
|
|
|
|
|
+ 合同其余字段可正常读取,请稍后重试",
|
|
|
|
|
+ r.customer_id
|
|
|
|
|
+ ),
|
|
|
|
|
+ )
|
|
|
|
|
+ })?;
|
|
|
|
|
+ json!({
|
|
|
|
|
+ "file_name": file_name,
|
|
|
|
|
+ "status": "viewable",
|
|
|
|
|
+ "view_url": sig.presigned_url,
|
|
|
|
|
+ "view_url_expires_at": sig.expires_at,
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ _ => json!({
|
|
|
|
|
+ "file_name": Value::Null,
|
|
|
|
|
+ "status": "none",
|
|
|
|
|
+ "view_url": Value::Null,
|
|
|
|
|
+ "view_url_expires_at": Value::Null,
|
|
|
|
|
+ }),
|
|
|
|
|
+ };
|
|
|
Ok(Some(json!({
|
|
Ok(Some(json!({
|
|
|
"customer_id": r.customer_id,
|
|
"customer_id": r.customer_id,
|
|
|
"customer_name": r.customer_name,
|
|
"customer_name": r.customer_name,
|
|
@@ -817,11 +925,19 @@ async fn customer_profile(
|
|
|
"acct_status": r.acct_status,
|
|
"acct_status": r.acct_status,
|
|
|
"region_paths": mounts.iter().map(|m| m.path_name.clone()).collect::<Vec<Option<String>>>(),
|
|
"region_paths": mounts.iter().map(|m| m.path_name.clone()).collect::<Vec<Option<String>>>(),
|
|
|
"region_path": if region.is_empty() { Value::Null } else { Value::String(region) },
|
|
"region_path": if region.is_empty() { Value::Null } else { Value::String(region) },
|
|
|
|
|
+ "region_node_id": region_node_id,
|
|
|
"operator_name": r.operator_name,
|
|
"operator_name": r.operator_name,
|
|
|
"partner_name": r.partner_name,
|
|
"partner_name": r.partner_name,
|
|
|
"contact_name": r.contact_name,
|
|
"contact_name": r.contact_name,
|
|
|
"contact_mobile": r.contact_mobile,
|
|
"contact_mobile": r.contact_mobile,
|
|
|
|
|
+ "tech_contact_name": r.tech_contact_name,
|
|
|
|
|
+ "tech_contact_mobile": r.tech_contact_mobile,
|
|
|
|
|
+ "finance_contact_name": r.finance_contact_name,
|
|
|
|
|
+ "finance_contact_mobile": r.finance_contact_mobile,
|
|
|
|
|
+ "remark": r.remark,
|
|
|
"address": r.address,
|
|
"address": r.address,
|
|
|
|
|
+ "ops_team_names": ops_team_names,
|
|
|
|
|
+ "license": license,
|
|
|
"columns_pending": json!(["credit_code", "province_name"]),
|
|
"columns_pending": json!(["credit_code", "province_name"]),
|
|
|
})))
|
|
})))
|
|
|
}
|
|
}
|
|
@@ -920,6 +1036,103 @@ fn want_index(v: Option<&Value>, field: &str) -> Result<Option<usize>, BosError>
|
|
|
.map_err(|_| BosError::bad_params(format!("{field} 须为 ≥0 的整数(0 基序号),收到 {n}")))
|
|
.map_err(|_| BosError::bad_params(format!("{field} 须为 ≥0 的整数(0 基序号),收到 {n}")))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/// 读口折扣率:缺列/非法 ⇒ 默认 100。合法区间 `[1, 100]`。
|
|
|
|
|
+fn discount_rate_num(raw: Option<&str>) -> Value {
|
|
|
|
|
+ let scaled = raw
|
|
|
|
|
+ .and_then(|s| parse_scaled_decimal(s, DISCOUNT_PCT_SCALE))
|
|
|
|
|
+ .filter(|v| *v >= DISCOUNT_PCT_SCALE && *v <= DISCOUNT_PCT_SCALE * 100)
|
|
|
|
|
+ .unwrap_or(DISCOUNT_PCT_SCALE * 100);
|
|
|
|
|
+ json!(scaled as f64 / DISCOUNT_PCT_SCALE as f64)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 请求折扣率 → 定点值(缺省 100.00%;门禁 `[1, 100]`)。
|
|
|
|
|
+fn parse_discount_rate(raw: Option<&Value>) -> Result<i64, BosError> {
|
|
|
|
|
+ let Some(v) = raw.filter(|v| !v.is_null()) else {
|
|
|
|
|
+ return Ok(DISCOUNT_PCT_SCALE * 100);
|
|
|
|
|
+ };
|
|
|
|
|
+ let text = match v {
|
|
|
|
|
+ Value::Number(n) => n.to_string(),
|
|
|
|
|
+ Value::String(s) => s.clone(),
|
|
|
|
|
+ other => {
|
|
|
|
|
+ return Err(BosError::bad_params(format!(
|
|
|
|
|
+ "discount_rate_pct 须为 1~100 的百分数,收到 {other}"
|
|
|
|
|
+ )));
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ let scaled = parse_scaled_decimal(&text, DISCOUNT_PCT_SCALE).ok_or_else(|| {
|
|
|
|
|
+ BosError::bad_params(format!(
|
|
|
|
|
+ "discount_rate_pct 须为 1~100 的百分数(最多两位小数),收到 {text}"
|
|
|
|
|
+ ))
|
|
|
|
|
+ })?;
|
|
|
|
|
+ if scaled < DISCOUNT_PCT_SCALE || scaled > DISCOUNT_PCT_SCALE * 100 {
|
|
|
|
|
+ return Err(BosError::bad_params(format!(
|
|
|
|
|
+ "discount_rate_pct 须为 1~100 的百分数,收到 {text}"
|
|
|
|
|
+ )));
|
|
|
|
|
+ }
|
|
|
|
|
+ Ok(scaled)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 服务端按「Σ(年价×份数×出口系数)×折扣率」复核客户端合同金额(与前端 `deriveContractAmount` 同源)。
|
|
|
|
|
+async fn reconcile_contract_amount(
|
|
|
|
|
+ db: &UdsClient,
|
|
|
|
|
+ items: &[ItemIns],
|
|
|
|
|
+ discount_scaled: i64,
|
|
|
|
|
+ claimed: i64,
|
|
|
|
|
+) -> Result<(), BosError> {
|
|
|
|
|
+ let plan_ids: Vec<String> = items
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .map(|it| it.plan_id.clone())
|
|
|
|
|
+ .collect::<BTreeSet<_>>()
|
|
|
|
|
+ .into_iter()
|
|
|
|
|
+ .collect();
|
|
|
|
|
+ let plans = load_plans(db, &plan_ids).await?;
|
|
|
|
|
+ let factors = super::line_exit::price_factor_map(db).await?;
|
|
|
|
|
+ let mut package = 0i64;
|
|
|
|
|
+ for (index, it) in items.iter().enumerate() {
|
|
|
|
|
+ let plan = plans.get(&it.plan_id).ok_or_else(|| {
|
|
|
|
|
+ BosError::bad_params(format!(
|
|
|
|
|
+ "service_items[{index}] 档位 {} 不在册,无法复核合同金额",
|
|
|
|
|
+ it.plan_id
|
|
|
|
|
+ ))
|
|
|
|
|
+ })?;
|
|
|
|
|
+ let exits = match &it.line_exits {
|
|
|
|
|
+ Value::Array(arr) => arr
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .filter_map(|v| v.as_str().map(str::to_string))
|
|
|
|
|
+ .collect::<Vec<_>>(),
|
|
|
|
|
+ _ => Vec::new(),
|
|
|
|
|
+ };
|
|
|
|
|
+ let factor = match normalize_line_exits(&exits) {
|
|
|
|
|
+ Ok(n) => n
|
|
|
|
|
+ .line_exits
|
|
|
|
|
+ .first()
|
|
|
|
|
+ .and_then(|k| factors.get(k).copied())
|
|
|
|
|
+ .filter(|v| *v > 0)
|
|
|
|
|
+ .unwrap_or(PRICE_FACTOR_SCALE),
|
|
|
|
|
+ Err(_) => PRICE_FACTOR_SCALE,
|
|
|
|
|
+ };
|
|
|
|
|
+ package = package.saturating_add(package_line_cents(
|
|
|
|
|
+ plan.annual_price_cents,
|
|
|
|
|
+ it.quantity,
|
|
|
|
|
+ factor,
|
|
|
|
|
+ ));
|
|
|
|
|
+ }
|
|
|
|
|
+ let expected = apply_discount_cents(package, discount_scaled);
|
|
|
|
|
+ if expected != claimed {
|
|
|
|
|
+ return Err(BosError::bad_params(format!(
|
|
|
|
|
+ "合同金额与服务构成不符:按档位年价×份数×出口系数×折扣率应得 {expected} 分,\
|
|
|
|
|
+ 收到 {claimed} 分(套餐总 {package} 分,折扣率 {}%)",
|
|
|
|
|
+ discount_rate_text(discount_scaled)
|
|
|
|
|
+ )));
|
|
|
|
|
+ }
|
|
|
|
|
+ if expected <= 0 {
|
|
|
|
|
+ return Err(BosError::bad_params(
|
|
|
|
|
+ "折后合同金额须大于 0(请检查服务构成价格、出口系数与折扣率)",
|
|
|
|
|
+ ));
|
|
|
|
|
+ }
|
|
|
|
|
+ Ok(())
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/// 库里已存的日期列(认不出来=当没有,⛔ 因脏数据卡住一次合法改写)。
|
|
/// 库里已存的日期列(认不出来=当没有,⛔ 因脏数据卡住一次合法改写)。
|
|
|
fn stored_date(v: Option<&String>) -> Option<NaiveDate> {
|
|
fn stored_date(v: Option<&String>) -> Option<NaiveDate> {
|
|
|
v.as_deref()
|
|
v.as_deref()
|
|
@@ -948,7 +1161,7 @@ struct ItemIns {
|
|
|
plan_family: PlanFamily,
|
|
plan_family: PlanFamily,
|
|
|
/// 条目形态(D-9):`new`/`increment`。
|
|
/// 条目形态(D-9):`new`/`increment`。
|
|
|
item_mode: ItemMode,
|
|
item_mode: ItemMode,
|
|
|
- /// 附加项在本载荷里的父条目 **0 基序号**(发号后换成 `serves_item_id` 落库)。
|
|
|
|
|
|
|
+ /// 叠加服务在本载荷里的父条目 **0 基序号**(发号后换成 `serves_item_id` 落库)。
|
|
|
parent_index: Option<usize>,
|
|
parent_index: Option<usize>,
|
|
|
/// 落库父条目主键(发号后填;`increment` 与 `link` 恒 `None`)。
|
|
/// 落库父条目主键(发号后填;`increment` 与 `link` 恒 `None`)。
|
|
|
serves_item_id: Option<String>,
|
|
serves_item_id: Option<String>,
|
|
@@ -1269,7 +1482,7 @@ async fn check_increment_refs(
|
|
|
return Err(BosError::klt(
|
|
return Err(BosError::klt(
|
|
|
KltCode::L216,
|
|
KltCode::L216,
|
|
|
format!(
|
|
format!(
|
|
|
- "{at}:订阅 {rid} 不在期(status={},到期 {})⇒ 不能再往上叠加附加项",
|
|
|
|
|
|
|
+ "{at}:订阅 {rid} 不在期(status={},到期 {})⇒ 不能再往上叠加叠加服务",
|
|
|
row.status,
|
|
row.status,
|
|
|
row.end_date.as_deref().unwrap_or("—")
|
|
row.end_date.as_deref().unwrap_or("—")
|
|
|
),
|
|
),
|
|
@@ -1914,7 +2127,7 @@ fn inline_failure_note(e: BosError, customer_id: &str, info: &Value) -> BosError
|
|
|
/// * 缺省=`new`;兼容旧客户端:只带 `renew_from_contract_id` 不带类型 ⇒ 视为续签,
|
|
/// * 缺省=`new`;兼容旧客户端:只带 `renew_from_contract_id` 不带类型 ⇒ 视为续签,
|
|
|
/// 服务构成整批为增量条目 ⇒ 视为扩容补充协议(显式给了别的类型则按下面的规则报错)。
|
|
/// 服务构成整批为增量条目 ⇒ 视为扩容补充协议(显式给了别的类型则按下面的规则报错)。
|
|
|
/// * `renew` **必须**有续签来源(否则类型在撒谎);
|
|
/// * `renew` **必须**有续签来源(否则类型在撒谎);
|
|
|
-/// * `expand` **必须**全部条目都是增量附加项(扩容补充协议不新开链路)。
|
|
|
|
|
|
|
+/// * `expand` **必须**全部条目都是增量叠加服务(扩容补充协议不新开链路)。
|
|
|
fn resolve_contract_type(
|
|
fn resolve_contract_type(
|
|
|
declared: Option<&str>,
|
|
declared: Option<&str>,
|
|
|
renew_from: Option<&str>,
|
|
renew_from: Option<&str>,
|
|
@@ -1932,7 +2145,7 @@ fn resolve_contract_type(
|
|
|
"new" if renew_from.is_some() => Ok("renew".to_string()),
|
|
"new" if renew_from.is_some() => Ok("renew".to_string()),
|
|
|
"new" if has_increment && all_increment => Ok("expand".to_string()),
|
|
"new" if has_increment && all_increment => Ok("expand".to_string()),
|
|
|
"new" if has_increment => Err(BosError::bad_params(
|
|
"new" if has_increment => Err(BosError::bad_params(
|
|
|
- "服务构成混有增量条目与自建链路:扩容补充协议须整批为增量附加项,新建合同须整批自建链路",
|
|
|
|
|
|
|
+ "服务构成混有增量条目与自建链路:扩容补充协议须整批为增量叠加服务,新建合同须整批自建链路",
|
|
|
)),
|
|
)),
|
|
|
"renew" if renew_from.is_none() => Err(BosError::bad_params(
|
|
"renew" if renew_from.is_none() => Err(BosError::bad_params(
|
|
|
"合同类型为续签,但没有给出 renew_from_contract_id(续签须指定续签自哪份旧合同)",
|
|
"合同类型为续签,但没有给出 renew_from_contract_id(续签须指定续签自哪份旧合同)",
|
|
@@ -1941,7 +2154,7 @@ fn resolve_contract_type(
|
|
|
"续签合同(带 renew_from_contract_id)的合同类型只能是 renew",
|
|
"续签合同(带 renew_from_contract_id)的合同类型只能是 renew",
|
|
|
)),
|
|
)),
|
|
|
"expand" if !all_increment => Err(BosError::bad_params(
|
|
"expand" if !all_increment => Err(BosError::bad_params(
|
|
|
- "合同类型为扩容补充协议,但服务构成不是整批增量附加项(扩容不新开跨境链路)",
|
|
|
|
|
|
|
+ "合同类型为扩容补充协议,但服务构成不是整批增量叠加服务(扩容不新开跨境链路)",
|
|
|
)),
|
|
)),
|
|
|
other => Ok(other.to_string()),
|
|
other => Ok(other.to_string()),
|
|
|
}
|
|
}
|
|
@@ -1985,6 +2198,9 @@ async fn do_create_for_customer(
|
|
|
// 签署日期选填:缺省按经办交接日期兜底(旧口径只有交接日期)。
|
|
// 签署日期选填:缺省按经办交接日期兜底(旧口径只有交接日期)。
|
|
|
let sign_date = trimmed(&b.sign_date).or_else(|| trimmed(&b.agent_handover_on));
|
|
let sign_date = trimmed(&b.sign_date).or_else(|| trimmed(&b.agent_handover_on));
|
|
|
let attachment: Vec<&str> = trimmed(&b.attachment_url).into_iter().collect();
|
|
let attachment: Vec<&str> = trimmed(&b.attachment_url).into_iter().collect();
|
|
|
|
|
+ let discount_rate_scaled = parse_discount_rate(b.discount_rate_pct.as_ref())?;
|
|
|
|
|
+ let claimed_amount = want_int(b.contract_amount_cents.as_ref(), "contract_amount_cents")?;
|
|
|
|
|
+ reconcile_contract_amount(db, &items, discount_rate_scaled, claimed_amount.unwrap_or(0)).await?;
|
|
|
let mut draft = validate_contract_payload(&ContractRaw {
|
|
let mut draft = validate_contract_payload(&ContractRaw {
|
|
|
customer_id,
|
|
customer_id,
|
|
|
original_customer_id: None,
|
|
original_customer_id: None,
|
|
@@ -1993,7 +2209,8 @@ async fn do_create_for_customer(
|
|
|
external_no: trimmed(&b.external_no),
|
|
external_no: trimmed(&b.external_no),
|
|
|
contract_type: trimmed(&b.contract_type),
|
|
contract_type: trimmed(&b.contract_type),
|
|
|
sign_date,
|
|
sign_date,
|
|
|
- total_amount_cents: want_int(b.contract_amount_cents.as_ref(), "contract_amount_cents")?,
|
|
|
|
|
|
|
+ total_amount_cents: claimed_amount,
|
|
|
|
|
+ discount_rate_scaled: Some(discount_rate_scaled),
|
|
|
service_months,
|
|
service_months,
|
|
|
start_date: trimmed(&b.start_date),
|
|
start_date: trimmed(&b.start_date),
|
|
|
end_date: end_date.as_deref(),
|
|
end_date: end_date.as_deref(),
|
|
@@ -2110,6 +2327,7 @@ async fn do_create_for_customer(
|
|
|
Value::String(no.contract_no.clone()),
|
|
Value::String(no.contract_no.clone()),
|
|
|
text_param(draft.external_no.as_deref()),
|
|
text_param(draft.external_no.as_deref()),
|
|
|
Value::from(draft.total_amount_cents),
|
|
Value::from(draft.total_amount_cents),
|
|
|
|
|
+ Value::String(discount_rate_text(draft.discount_rate_scaled)),
|
|
|
Value::String(draft.contract_type.clone()),
|
|
Value::String(draft.contract_type.clone()),
|
|
|
text_param(draft.sign_date.as_deref()),
|
|
text_param(draft.sign_date.as_deref()),
|
|
|
Value::from(draft.service_months),
|
|
Value::from(draft.service_months),
|
|
@@ -2635,6 +2853,7 @@ async fn plan_contract_subs(
|
|
|
}
|
|
}
|
|
|
let existing = super::subscription::subs_of_customer(state, customer_id).await?;
|
|
let existing = super::subscription::subs_of_customer(state, customer_id).await?;
|
|
|
let today = super::subscription::today();
|
|
let today = super::subscription::today();
|
|
|
|
|
+ let factor_map = super::line_exit::price_factor_map(state.db.as_ref()).await?;
|
|
|
// 订阅开始日=**合同开始日**(2026-11-17 定案:订阅跟着合同起算,⛔ 一律从业务当天起)。
|
|
// 订阅开始日=**合同开始日**(2026-11-17 定案:订阅跟着合同起算,⛔ 一律从业务当天起)。
|
|
|
let start_owned = contract_start.to_string();
|
|
let start_owned = contract_start.to_string();
|
|
|
let mut seen: HashSet<String> = HashSet::new();
|
|
let mut seen: HashSet<String> = HashSet::new();
|
|
@@ -2667,6 +2886,7 @@ async fn plan_contract_subs(
|
|
|
let Some(req) = it.succession.as_ref() else {
|
|
let Some(req) = it.succession.as_ref() else {
|
|
|
// 续签整批带出,或增量条目(D-9:本合同要交付的那部分)⇒ 建订阅。
|
|
// 续签整批带出,或增量条目(D-9:本合同要交付的那部分)⇒ 建订阅。
|
|
|
if renew_from.is_some() || it.item_mode == ItemMode::Increment {
|
|
if renew_from.is_some() || it.item_mode == ItemMode::Increment {
|
|
|
|
|
+ let exits = super::subscription::derive_exits(Some(&item_row), &plan)?;
|
|
|
let pin = succession::PlanInput {
|
|
let pin = succession::PlanInput {
|
|
|
plan: &plan,
|
|
plan: &plan,
|
|
|
item: Some(&item_row),
|
|
item: Some(&item_row),
|
|
@@ -2679,6 +2899,10 @@ async fn plan_contract_subs(
|
|
|
row_version: None,
|
|
row_version: None,
|
|
|
parent_subscription_id: parent_id.as_deref(),
|
|
parent_subscription_id: parent_id.as_deref(),
|
|
|
mode: succession::MatchMode::SameCategoryAndExit,
|
|
mode: succession::MatchMode::SameCategoryAndExit,
|
|
|
|
|
+ price_factor_scaled: super::subscription::factor_scaled_for_exits(
|
|
|
|
|
+ &factor_map,
|
|
|
|
|
+ &exits,
|
|
|
|
|
+ ),
|
|
|
};
|
|
};
|
|
|
let planned = succession::plan_fresh(
|
|
let planned = succession::plan_fresh(
|
|
|
customer_id,
|
|
customer_id,
|
|
@@ -2724,6 +2948,7 @@ async fn plan_contract_subs(
|
|
|
contract_start,
|
|
contract_start,
|
|
|
Some(contract_end),
|
|
Some(contract_end),
|
|
|
) {
|
|
) {
|
|
|
|
|
+ let exits = super::subscription::derive_exits(Some(&item_row), &plan)?;
|
|
|
let pin = succession::PlanInput {
|
|
let pin = succession::PlanInput {
|
|
|
plan: &plan,
|
|
plan: &plan,
|
|
|
item: Some(&item_row),
|
|
item: Some(&item_row),
|
|
@@ -2736,6 +2961,10 @@ async fn plan_contract_subs(
|
|
|
row_version: None,
|
|
row_version: None,
|
|
|
parent_subscription_id: parent_id.as_deref(),
|
|
parent_subscription_id: parent_id.as_deref(),
|
|
|
mode: succession::MatchMode::SameCategoryAndExit,
|
|
mode: succession::MatchMode::SameCategoryAndExit,
|
|
|
|
|
+ price_factor_scaled: super::subscription::factor_scaled_for_exits(
|
|
|
|
|
+ &factor_map,
|
|
|
|
|
+ &exits,
|
|
|
|
|
+ ),
|
|
|
};
|
|
};
|
|
|
let planned =
|
|
let planned =
|
|
|
succession::plan_fresh(customer_id, &new_id, &pin, &today, &format!("{prefix}:"))?;
|
|
succession::plan_fresh(customer_id, &new_id, &pin, &today, &format!("{prefix}:"))?;
|
|
@@ -2743,6 +2972,7 @@ async fn plan_contract_subs(
|
|
|
out.fresh.push((idx, planned));
|
|
out.fresh.push((idx, planned));
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
+ let exits = super::subscription::derive_exits(Some(&item_row), &plan)?;
|
|
|
let pin = succession::PlanInput {
|
|
let pin = succession::PlanInput {
|
|
|
plan: &plan,
|
|
plan: &plan,
|
|
|
item: Some(&item_row),
|
|
item: Some(&item_row),
|
|
@@ -2756,6 +2986,7 @@ async fn plan_contract_subs(
|
|
|
row_version: None,
|
|
row_version: None,
|
|
|
parent_subscription_id: parent_id.as_deref(),
|
|
parent_subscription_id: parent_id.as_deref(),
|
|
|
mode: succession::MatchMode::SameCategoryAndExit,
|
|
mode: succession::MatchMode::SameCategoryAndExit,
|
|
|
|
|
+ price_factor_scaled: super::subscription::factor_scaled_for_exits(&factor_map, &exits),
|
|
|
};
|
|
};
|
|
|
let planned =
|
|
let planned =
|
|
|
succession::plan_change(state, customer_id, orig, &new_id, &pin, &today, &format!("{prefix}:"))
|
|
succession::plan_change(state, customer_id, orig, &new_id, &pin, &today, &format!("{prefix}:"))
|
|
@@ -2989,6 +3220,15 @@ async fn do_update(
|
|
|
Some(v) => want_int(Some(v), "contract_amount_cents")?,
|
|
Some(v) => want_int(Some(v), "contract_amount_cents")?,
|
|
|
None => parse_i64(Some(&cur.amount_cents)),
|
|
None => parse_i64(Some(&cur.amount_cents)),
|
|
|
};
|
|
};
|
|
|
|
|
+ let discount_rate_scaled = match b.discount_rate_pct.as_ref() {
|
|
|
|
|
+ Some(v) => parse_discount_rate(Some(v))?,
|
|
|
|
|
+ None => cur
|
|
|
|
|
+ .discount_rate_pct
|
|
|
|
|
+ .as_deref()
|
|
|
|
|
+ .and_then(|s| parse_scaled_decimal(s, DISCOUNT_PCT_SCALE))
|
|
|
|
|
+ .filter(|v| *v >= DISCOUNT_PCT_SCALE && *v <= DISCOUNT_PCT_SCALE * 100)
|
|
|
|
|
+ .unwrap_or(DISCOUNT_PCT_SCALE * 100),
|
|
|
|
|
+ };
|
|
|
let touched_main = [
|
|
let touched_main = [
|
|
|
&b.external_no,
|
|
&b.external_no,
|
|
|
&b.contract_no,
|
|
&b.contract_no,
|
|
@@ -3006,6 +3246,7 @@ async fn do_update(
|
|
|
.iter()
|
|
.iter()
|
|
|
.any(|v| v.is_some())
|
|
.any(|v| v.is_some())
|
|
|
|| b.contract_amount_cents.is_some()
|
|
|| b.contract_amount_cents.is_some()
|
|
|
|
|
+ || b.discount_rate_pct.is_some()
|
|
|
|| b.service_months.is_some();
|
|
|| b.service_months.is_some();
|
|
|
|
|
|
|
|
// 结束日锁定为推算值(2026-11-19 定案):生效日/服务期**确实被改**而没显式给结束日 ⇒ 按同一式重算,
|
|
// 结束日锁定为推算值(2026-11-19 定案):生效日/服务期**确实被改**而没显式给结束日 ⇒ 按同一式重算,
|
|
@@ -3037,6 +3278,7 @@ async fn do_update(
|
|
|
contract_type: eff(&b.contract_type, &cur.contract_type),
|
|
contract_type: eff(&b.contract_type, &cur.contract_type),
|
|
|
sign_date: eff(&b.sign_date, &cur.sign_date),
|
|
sign_date: eff(&b.sign_date, &cur.sign_date),
|
|
|
total_amount_cents: amount,
|
|
total_amount_cents: amount,
|
|
|
|
|
+ discount_rate_scaled: Some(discount_rate_scaled),
|
|
|
service_months: eff_months,
|
|
service_months: eff_months,
|
|
|
start_date: eff_start,
|
|
start_date: eff_start,
|
|
|
end_date: end_date.as_deref(),
|
|
end_date: end_date.as_deref(),
|
|
@@ -3047,6 +3289,46 @@ async fn do_update(
|
|
|
attachment_urls: &attachment,
|
|
attachment_urls: &attachment,
|
|
|
})?;
|
|
})?;
|
|
|
|
|
|
|
|
|
|
+ // 金额/折扣/条目任一变动 ⇒ 按「档位×份数×出口系数×折扣率」复核(与新建同源)。
|
|
|
|
|
+ if b.contract_amount_cents.is_some()
|
|
|
|
|
+ || b.discount_rate_pct.is_some()
|
|
|
|
|
+ || b.service_items.is_some()
|
|
|
|
|
+ {
|
|
|
|
|
+ let amount_items = if let Some(raw) = b.service_items.as_ref() {
|
|
|
|
|
+ let (items, _) = resolve_items(db, &cur.customer_id, raw).await?;
|
|
|
|
|
+ items
|
|
|
|
|
+ } else {
|
|
|
|
|
+ stored_items(db, contract_id)
|
|
|
|
|
+ .await?
|
|
|
|
|
+ .into_iter()
|
|
|
|
|
+ .map(|r| ItemIns {
|
|
|
|
|
+ item_id: Some(r.item_id),
|
|
|
|
|
+ plan_id: r.plan_id,
|
|
|
|
|
+ quantity: parse_i64(r.quantity.as_ref()).unwrap_or(1).max(1),
|
|
|
|
|
+ plan_family: r
|
|
|
|
|
+ .item_family
|
|
|
|
|
+ .as_deref()
|
|
|
|
|
+ .and_then(|s| PlanFamily::parse(s).ok())
|
|
|
|
|
+ .unwrap_or(PlanFamily::Link),
|
|
|
|
|
+ item_mode: ItemMode::New,
|
|
|
|
|
+ parent_index: None,
|
|
|
|
|
+ serves_item_id: None,
|
|
|
|
|
+ ref_subscription_id: None,
|
|
|
|
|
+ line_exits: r.line_exits.unwrap_or_else(|| Value::Array(vec![])),
|
|
|
|
|
+ line_exit_key: String::new(),
|
|
|
|
|
+ succession: None,
|
|
|
|
|
+ })
|
|
|
|
|
+ .collect()
|
|
|
|
|
+ };
|
|
|
|
|
+ reconcile_contract_amount(
|
|
|
|
|
+ db,
|
|
|
|
|
+ &amount_items,
|
|
|
|
|
+ draft.discount_rate_scaled,
|
|
|
|
|
+ draft.total_amount_cents,
|
|
|
|
|
+ )
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 外部单号查重(TC-CU-40):编辑把单号改成**别的合同**已用过的值 ⇒ 同客户提示/跨客户 `KLT-L218`。
|
|
// 外部单号查重(TC-CU-40):编辑把单号改成**别的合同**已用过的值 ⇒ 同客户提示/跨客户 `KLT-L218`。
|
|
|
if let Some(ext) = draft.external_no.as_deref() {
|
|
if let Some(ext) = draft.external_no.as_deref() {
|
|
|
if ext != cur.external_no.as_deref().unwrap_or_default() {
|
|
if ext != cur.external_no.as_deref().unwrap_or_default() {
|
|
@@ -3058,7 +3340,13 @@ async fn do_update(
|
|
|
// 判据=`bos-invariant::contract_edit_scope`(与读口下发同一枚函数;⛔ 本层另写一套)。
|
|
// 判据=`bos-invariant::contract_edit_scope`(与读口下发同一枚函数;⛔ 本层另写一套)。
|
|
|
// 「是否改了」按**合并后的生效值 vs 库里现值**判,⛔ 按"请求里有没有这个键"判——
|
|
// 「是否改了」按**合并后的生效值 vs 库里现值**判,⛔ 按"请求里有没有这个键"判——
|
|
|
// 页面保存是整份回传,按键判会把没动过的字段全算成改动、给冻结合同报假错。
|
|
// 页面保存是整份回传,按键判会把没动过的字段全算成改动、给冻结合同报假错。
|
|
|
|
|
+ let cur_discount = cur
|
|
|
|
|
+ .discount_rate_pct
|
|
|
|
|
+ .as_deref()
|
|
|
|
|
+ .and_then(|s| parse_scaled_decimal(s, DISCOUNT_PCT_SCALE))
|
|
|
|
|
+ .unwrap_or(DISCOUNT_PCT_SCALE * 100);
|
|
|
let billing_touched = amount != parse_i64(Some(&cur.amount_cents))
|
|
let billing_touched = amount != parse_i64(Some(&cur.amount_cents))
|
|
|
|
|
+ || discount_rate_scaled != cur_discount
|
|
|
|| eff_months != cur.service_months.as_ref().and_then(|v| parse_i64(Some(v)))
|
|
|| eff_months != cur.service_months.as_ref().and_then(|v| parse_i64(Some(v)))
|
|
|
|| !same_text(Some(draft.start_date.as_str()), cur.start_date.as_deref())
|
|
|| !same_text(Some(draft.start_date.as_str()), cur.start_date.as_deref())
|
|
|
|| !same_text(Some(draft.end_date.as_str()), cur.end_date.as_deref())
|
|
|| !same_text(Some(draft.end_date.as_str()), cur.end_date.as_deref())
|
|
@@ -3149,6 +3437,7 @@ async fn do_update(
|
|
|
Value::String(contract_id.to_string()),
|
|
Value::String(contract_id.to_string()),
|
|
|
text_param(draft.external_no.as_deref()),
|
|
text_param(draft.external_no.as_deref()),
|
|
|
Value::from(draft.total_amount_cents),
|
|
Value::from(draft.total_amount_cents),
|
|
|
|
|
+ Value::String(discount_rate_text(draft.discount_rate_scaled)),
|
|
|
Value::String(draft.contract_type.clone()),
|
|
Value::String(draft.contract_type.clone()),
|
|
|
text_param(draft.sign_date.as_deref()),
|
|
text_param(draft.sign_date.as_deref()),
|
|
|
Value::from(draft.service_months),
|
|
Value::from(draft.service_months),
|
|
@@ -3458,7 +3747,7 @@ struct SubBrief {
|
|
|
/// 订阅份数(2026-11-17):可叠加档可 > 1(例:境外 IP 按个),其余恒 1。
|
|
/// 订阅份数(2026-11-17):可叠加档可 > 1(例:境外 IP 按个),其余恒 1。
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
quantity: Option<String>,
|
|
quantity: Option<String>,
|
|
|
- /// P1(D-2/D-7):附加订阅的父订阅;非空即页面上平铺标「附加于 SUB-xxx」。
|
|
|
|
|
|
|
+ /// P1(D-2/D-7):附加订阅的父订阅;非空即页面上平铺标「叠加于 SUB-xxx」。
|
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
#[serde(deserialize_with = "de::as_opt_string")]
|
|
|
parent_subscription_id: Option<String>,
|
|
parent_subscription_id: Option<String>,
|
|
|
}
|
|
}
|
|
@@ -3691,7 +3980,7 @@ async fn subscriptions_of(db: &UdsClient, contract_id: &str) -> Result<Vec<Value
|
|
|
"contract_item_id": s.contract_item_id,
|
|
"contract_item_id": s.contract_item_id,
|
|
|
"replaces_subscription_id": s.replaces_subscription_id,
|
|
"replaces_subscription_id": s.replaces_subscription_id,
|
|
|
"quantity": s.quantity,
|
|
"quantity": s.quantity,
|
|
|
- // P1(D-7):附加订阅的父;界面据此平铺标「附加于 SUB-xxx」。
|
|
|
|
|
|
|
+ // P1(D-7):附加订阅的父;界面据此平铺标「叠加于 SUB-xxx」。
|
|
|
"parent_subscription_id": s.parent_subscription_id,
|
|
"parent_subscription_id": s.parent_subscription_id,
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|