项目中心-支付模块
This commit is contained in:
@@ -7,6 +7,7 @@ import type {
|
||||
ProjectStatus,
|
||||
RequirementAfterSale,
|
||||
RequirementAttachment,
|
||||
RequirementBill,
|
||||
RequirementBillPlan,
|
||||
RequirementContract,
|
||||
RequirementDetailBundle,
|
||||
@@ -27,7 +28,7 @@ import { PROJECT_STATUS_LABEL } from '@/utils/projectMeta'
|
||||
* (需求表同一行),这里统一取 `bundle.progress` 那一支当基础信息(UI 上它最先渲染)。</p>
|
||||
*
|
||||
* <p><b>未立项是常态</b>:需求在 `vm_rd_project` 里没有对应行时,后端返回的
|
||||
* `projectStage` / `projectMilestones` / `members` / `billPlans` / `invoices` / `contracts`
|
||||
* `projectStage` / `projectMilestones` / `members` / `bills` / `billPlans` / `invoices` / `contracts`
|
||||
* 全为空 —— 这里一律兜底成空数组 / 0 / undefined,详情页显示为空态,不报错。</p>
|
||||
*/
|
||||
|
||||
@@ -107,6 +108,20 @@ function toDate(value: string | null | undefined): string | undefined {
|
||||
return value ? value.slice(0, 10) : undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* 期次占比 → 可展示文本。
|
||||
*
|
||||
* <p>后端 `period_ratio` / 计划 `periodRule` 都是「百分数」语义(30 表示 30%),但一个是
|
||||
* BigDecimal 字符串(`"40.00"`)、一个是逗号串里的一段(`"40,30,30"` 的第 2 段 `"30"`)⇒
|
||||
* 统一走 Number 归一。设计稿卡片标题写的是「比例33%」这种整数口径,非整数(按 3 期均分的
|
||||
* 33.33)保留一位小数,避免出现 `比例33.333333%`。</p>
|
||||
*/
|
||||
function toRatioText(value: string | number | null | undefined): string {
|
||||
const num = Number(value)
|
||||
if (!Number.isFinite(num) || num <= 0) return ''
|
||||
return Number.isInteger(num) ? String(num) : String(Math.round(num * 10) / 10)
|
||||
}
|
||||
|
||||
/** 需求附件 → 详情页文件项(文件 tab 用) */
|
||||
function attachmentToFile(item: RequirementAttachment): FileInfo {
|
||||
return {
|
||||
@@ -114,6 +129,8 @@ function attachmentToFile(item: RequirementAttachment): FileInfo {
|
||||
size: item.fileSize ?? 0,
|
||||
url: item.url ?? '',
|
||||
uploadTime: item.createTime ?? '',
|
||||
// 透传 ossId,供详情页「预览」走同源后端接口(绕开 OSS 桶强制下载)
|
||||
ossId: item.ossId ?? undefined,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,22 +156,73 @@ function contractToFile(item: RequirementContract): FileInfo {
|
||||
}
|
||||
|
||||
/**
|
||||
* 付款计划。
|
||||
* 账单(`vm_bill`)→ 详情页「付款计划」卡片。
|
||||
*
|
||||
* <p>`BillPlan` 没有「单据号」也没有「期次名」,所以:`planName` 用「第 N 期/共 M 期」
|
||||
* (**期次优先**,`periodRule` 的 '30,30,40' 只作兜底——直接把比例当名字显示不可读),
|
||||
* `billNo` 回落到 `projectNo`。</p>
|
||||
* <p><b>这是卡片的正解数据源。</b>设计稿卡片上的「账单号」与三态「已支付/待支付/未到期」
|
||||
* 只有 `vm_bill` 才有:`billNo` 是真账单号、`amount` 是**本期**金额、
|
||||
* `status` 是账单自己的 `PAID/PENDING/UNSTARTED`,而 `id` 正是收银台 `?ids=` 要传的
|
||||
* **账单 id**,所以卡片上的「立即支付」可以直接跳过去。</p>
|
||||
*
|
||||
* <p>期次名直接用后端下发的 `periodName`(如「第2期·进度款」)——不再像过去那样
|
||||
* 从付款计划拼「第N期/共M期」。</p>
|
||||
*/
|
||||
function toProjectBill(item: RequirementBillPlan): ProjectBill {
|
||||
const period = item.currentPeriod != null && item.periods != null
|
||||
? `第${item.currentPeriod}期/共${item.periods}期`
|
||||
: ''
|
||||
function toProjectBill(item: RequirementBill): ProjectBill {
|
||||
return {
|
||||
id: String(item.id),
|
||||
planName: period || item.periodRule || '付款计划',
|
||||
billNo: item.projectNo ?? '',
|
||||
amount: toNumber(item.totalAmount),
|
||||
source: 'bill',
|
||||
planName: item.periodName ?? '',
|
||||
// 设计稿标题「第2期·进度款 比例30%」= 期次名 + 期次占比(后端 period_ratio)
|
||||
periodRatio: toRatioText(item.periodRatio),
|
||||
billNo: item.billNo ?? '',
|
||||
amount: toNumber(item.amount),
|
||||
status: toBillStatus(item.status),
|
||||
// 后端存的是 transactionNo,页面叫 tradeNo(详见 types/business/finance.d.ts 的同一处映射)
|
||||
tradeNo: item.transactionNo ?? undefined,
|
||||
projectName: item.projectName ?? '',
|
||||
}
|
||||
}
|
||||
|
||||
/** 期次名,与后端 `BillServiceImpl#buildPeriodName` 同口径:首期预付款、末期尾款、中间进度款 */
|
||||
function planPeriodLabel(period: number, periods: number): string {
|
||||
if (period <= 1) return '预付款'
|
||||
if (period >= periods) return '尾款'
|
||||
return '进度款'
|
||||
}
|
||||
|
||||
/**
|
||||
* 分期计划(`vm_bill_plan`)→ 卡片。**这是「合同财务」卡片的数据源。**
|
||||
*
|
||||
* <p>为什么是计划而不是账单:本栈的支付口径就是**计划 id** ——
|
||||
* `vm_finance_payment.bill_id` 实测存的是 `vm_bill_plan.id`(该列 5 个取值在
|
||||
* `vm_bill_plan` 全命中、在 `vm_bill` 只命中 2 个)。所以卡片「立即支付」传的也是计划 id,
|
||||
* 下单落库、回调回写全都对得上,链路自洽。</p>
|
||||
*
|
||||
* <p>字段来源:期次名/比例/金额由 `currentPeriod` + `periodRule` 折算(与后端
|
||||
* `BillServiceImpl#resolveRatio/resolveAmount` 同口径);「账单号」= 该期支付单的
|
||||
* `out_trade_no`(后端别名 `orderNo`,未支付时为空 ⇒ 模板显示「—」);
|
||||
* 「交易流水号」= `transactionNo`;状态优先看支付单(`payStatus=SUCCESS` 即已支付),
|
||||
* 否则用计划状态(`DONE/ACTIVE/UNSTARTED`)。</p>
|
||||
*/
|
||||
function toPlanCard(item: RequirementBillPlan): ProjectBill {
|
||||
const period = item.currentPeriod ?? 0
|
||||
const periods = item.periods ?? 0
|
||||
const rule = (item.periodRule ?? '').split(',').map((part) => Number(part.trim()))
|
||||
const segment = rule[period - 1]
|
||||
const ratio = Number.isFinite(segment) ? segment : periods > 0 ? 100 / periods : 0
|
||||
// 支付成功以支付单为准:计划状态可能没被回调推到 DONE,但流水已经是 SUCCESS
|
||||
const paid = (item.payStatus ?? '').toUpperCase() === 'SUCCESS'
|
||||
return {
|
||||
id: String(item.id), // 计划 id —— 与收银台 ?ids= / vm_finance_payment.bill_id 同一口径
|
||||
source: 'plan',
|
||||
planName: period > 0 && periods > 0
|
||||
? `第${period}期·${planPeriodLabel(period, periods)}`
|
||||
: (item.periodRule ?? '付款计划'),
|
||||
// 比例口径与后端一致(见上方 ratio 折算),标题照样带「比例30%」
|
||||
periodRatio: toRatioText(ratio),
|
||||
billNo: item.orderNo ?? '',
|
||||
amount: Math.round(toNumber(item.totalAmount) * ratio) / 100,
|
||||
status: paid ? '已支付' : toBillStatus(item.status),
|
||||
tradeNo: item.transactionNo ?? undefined,
|
||||
projectName: item.projectName ?? '',
|
||||
}
|
||||
}
|
||||
@@ -232,7 +300,16 @@ export function toProjectDetail(bundle: RequirementDetailBundle): Project {
|
||||
.sort((a, b) => Number(b.isOwner ?? false) - Number(a.isOwner ?? false))
|
||||
.map(toTeamMember),
|
||||
files: (files.requirementAttachments ?? []).map(attachmentToFile),
|
||||
paymentPlans: (finance.billPlans ?? []).map(toProjectBill),
|
||||
// ⚠️ 卡片优先 = 真账单(vm_bill)。判别位是 `bills` **这个 key 在不在**:
|
||||
// 新构建无论有没有账单都会下发(无账单 = `[]` ⇒ 走空态,那才是「真的没有账单」);
|
||||
// 旧构建(未重启)压根没这个 key ⇒ 回落`billPlans`(只读卡,`source='plan'`,不带支付按钮)。
|
||||
// 教训:只认 `bills` 会让未重启的后端上整个页签「数据凭空消失」,所以必须留回落。
|
||||
// 卡片主数据源 = 付款计划(`vm_bill_plan`):本栈的支付口径就是计划 id
|
||||
// (`vm_finance_payment.bill_id` 实测存的就是它)。仅当计划为空时才回落 `bills`
|
||||
// (`vm_bill`),不再像上一轮那样优先读 `bills`。
|
||||
paymentPlans: (finance.billPlans ?? []).length > 0
|
||||
? (finance.billPlans ?? []).map(toPlanCard)
|
||||
: (finance.bills ?? []).map(toProjectBill),
|
||||
invoiceRecords: (finance.invoices ?? []).map(invoiceToFile),
|
||||
contractFile: contract ? contractToFile(contract) : undefined,
|
||||
afterSales: afterSales.afterSale
|
||||
|
||||
Reference in New Issue
Block a user