fix(consignment): 寄售价支持低于1元并按分类校验寄售数量上限
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import type { ConsignmentProfileConfig } from '../types/consignment'
|
||||
|
||||
/** 寄售价允许低于 1 元:配置了最低价就按最低价,否则只要求大于 0(输入框用 0.01)。 */
|
||||
export function resolveConsignmentPriceMinYuan(minPriceFen: number | null | undefined): number {
|
||||
const fen = Math.max(0, Math.round(Number(minPriceFen || 0)))
|
||||
return fen > 0 ? fen / 100 : 0.01
|
||||
}
|
||||
|
||||
export type ConsignmentQuantityLimit = {
|
||||
enabled: boolean
|
||||
maxActiveQuantity: number
|
||||
activeQuantity: number
|
||||
remainingQuantity: number
|
||||
blocked: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个分类的寄售数量上限:后端按配置 profile_id 统计「在售 + 待审核」件数,
|
||||
* 这里用接口返回的 activeQuantity 计算当前还能寄卖多少件。
|
||||
*/
|
||||
export function resolveConsignmentQuantityLimit(
|
||||
config: Pick<ConsignmentProfileConfig, 'inventoryLimit'> | null | undefined,
|
||||
activeQuantity: number | null | undefined,
|
||||
): ConsignmentQuantityLimit {
|
||||
const maxActiveQuantity = Math.max(
|
||||
0,
|
||||
Math.round(Number(config?.inventoryLimit?.maxActiveQuantity || 0)),
|
||||
)
|
||||
const active = Math.max(0, Math.round(Number(activeQuantity || 0)))
|
||||
const enabled = config?.inventoryLimit?.enabled === true
|
||||
const remainingQuantity = enabled ? Math.max(0, maxActiveQuantity - active) : 0
|
||||
return {
|
||||
enabled,
|
||||
maxActiveQuantity,
|
||||
activeQuantity: active,
|
||||
remainingQuantity,
|
||||
blocked: enabled && remainingQuantity <= 0,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user