22 lines
964 B
TypeScript
22 lines
964 B
TypeScript
/**
|
|
* 后台按份数撤销拼单份额:校验并算出保留下来的份数。
|
|
*
|
|
* 口径(已确认):
|
|
* - 只能部分撤销,撤到 0 份走「单人撤单」,所以 `1 ≤ 撤掉份数 ≤ 当前份数 − 1`;
|
|
* - 押金不随份数减少而退还(保持原冻结额),这里只算数量。
|
|
*/
|
|
export function resolveShareReduceTargetQuantity(input: {
|
|
currentQuantity: number
|
|
reduceQuantity: number
|
|
}): { nextQuantity: number; failureReason: 'invalid_quantity' | null } {
|
|
const current = Math.floor(Number(input.currentQuantity) || 0)
|
|
const reduce = Math.floor(Number(input.reduceQuantity) || 0)
|
|
if (!Number.isFinite(current) || !Number.isFinite(reduce)) {
|
|
return { nextQuantity: 0, failureReason: 'invalid_quantity' }
|
|
}
|
|
if (current < 2 || reduce < 1 || reduce > current - 1) {
|
|
return { nextQuantity: 0, failureReason: 'invalid_quantity' }
|
|
}
|
|
return { nextQuantity: current - reduce, failureReason: null }
|
|
}
|