feat(consignment): 匹配弹窗增加付款金额与售价差价
一键查询待匹配订单与手动匹配寄卖新增「工单用户付款金额」列, 售价后括号显示「用户付款金额 - 售价」差价:正数绿、负数红、 0 黄;拼单不显示差价,付款未知显示 -。
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
/** 分 → 元;null / 非法值返回 `-`,与后台金额展示一致。 */
|
||||
export function formatFenMoney(fen: number | null | undefined): string {
|
||||
if (fen === null || fen === undefined) return '-'
|
||||
const value = Number(fen)
|
||||
if (!Number.isFinite(value)) return '-'
|
||||
return `¥${(value / 100).toFixed(2)}`
|
||||
}
|
||||
|
||||
/** 分 → 带符号元:正数 `+`,负数 `-`,0 不带符号。 */
|
||||
export function formatSignedFenMoney(fen: number): string {
|
||||
const value = Math.round(Number(fen) || 0)
|
||||
const sign = value > 0 ? '+' : value < 0 ? '-' : ''
|
||||
return `${sign}¥${(Math.abs(value) / 100).toFixed(2)}`
|
||||
}
|
||||
|
||||
/** 差价配色:正数绿、负数红、0 黄。 */
|
||||
export const PAYMENT_PRICE_DIFF_COLOR = {
|
||||
positive: '#389e0d',
|
||||
negative: '#cf1322',
|
||||
zero: '#d4b106',
|
||||
} as const
|
||||
|
||||
export type PaymentPriceDiffView = {
|
||||
diffFen: number
|
||||
text: string
|
||||
color: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户付款金额 - 售价(分)。
|
||||
*
|
||||
* 拼单是多份售价,不能直接拿整单用户付款与单价相减,因此不显示差价;
|
||||
* 用户付款未知时同样返回 null,由调用方只展示售价。
|
||||
*/
|
||||
export function resolvePaymentPriceDiff(
|
||||
userPaymentFen: number | null | undefined,
|
||||
salePriceFen: number | null | undefined,
|
||||
options: { sharingEnabled?: boolean } = {},
|
||||
): PaymentPriceDiffView | null {
|
||||
if (options.sharingEnabled) return null
|
||||
if (userPaymentFen === null || userPaymentFen === undefined) return null
|
||||
if (salePriceFen === null || salePriceFen === undefined) return null
|
||||
const payment = Number(userPaymentFen)
|
||||
const price = Number(salePriceFen)
|
||||
if (!Number.isFinite(payment) || !Number.isFinite(price)) return null
|
||||
const diffFen = Math.round(payment) - Math.round(price)
|
||||
const color =
|
||||
diffFen > 0
|
||||
? PAYMENT_PRICE_DIFF_COLOR.positive
|
||||
: diffFen < 0
|
||||
? PAYMENT_PRICE_DIFF_COLOR.negative
|
||||
: PAYMENT_PRICE_DIFF_COLOR.zero
|
||||
return { diffFen, text: formatSignedFenMoney(diffFen), color }
|
||||
}
|
||||
Reference in New Issue
Block a user