| | |
| | | type WholeDiscountType int |
| | | |
| | | const ( |
| | | WholeDiscountTypeDefault WholeDiscountType = 0 //无折扣 |
| | | WholeDiscountTypePercent WholeDiscountType = 1 //百分比降价 |
| | | WholeDiscountTypeDiscount WholeDiscountType = 2 //直接降价 |
| | | ) |
| | | |
| | | func (wdt WholeDiscountType) IsValid(totalPrice, value decimal.Decimal) bool { |
| | | if wdt != WholeDiscountTypePercent && wdt != WholeDiscountTypeDiscount { |
| | | if wdt != WholeDiscountTypePercent && wdt != WholeDiscountTypeDiscount && wdt != WholeDiscountTypeDefault { |
| | | return false |
| | | } |
| | | if wdt == WholeDiscountTypeDiscount && value.GreaterThanOrEqual(totalPrice) { |
| | | if wdt == WholeDiscountTypeDiscount && value.GreaterThan(totalPrice) { |
| | | return false |
| | | } |
| | | if wdt == WholeDiscountTypePercent && totalPrice.Mul(value).Div(decimal.NewFromInt(100)).GreaterThanOrEqual(totalPrice) { |
| | | if wdt == WholeDiscountTypePercent && totalPrice.Mul(value).Div(decimal.NewFromInt(100)).GreaterThan(totalPrice) { |
| | | return false |
| | | } |
| | | return true |
| | |
| | | if pat != PriceAdjustmentTypeAdd && pat != PriceAdjustmentTypeSub { |
| | | return false |
| | | } |
| | | if pat == PriceAdjustmentTypeSub && value.GreaterThanOrEqual(totalPrice) { |
| | | if pat == PriceAdjustmentTypeSub && value.GreaterThan(totalPrice) { |
| | | return false |
| | | } |
| | | return true |