package com.nq.utils;
|
|
import com.nq.common.ServerResponse;
|
import com.nq.pojo.SiteSetting;
|
|
import java.math.BigDecimal;
|
|
public final class RechargeAmtValidator {
|
|
private RechargeAmtValidator() {
|
}
|
|
public static ServerResponse validate(SiteSetting siteSetting, BigDecimal amt) {
|
if (siteSetting == null) {
|
return ServerResponse.createByErrorMsg("设置set未初始化");
|
}
|
if (amt == null) {
|
return ServerResponse.createByErrorMsg("充值金额不能为空");
|
}
|
if (siteSetting.getChargeMinAmt() != null) {
|
BigDecimal min = new BigDecimal(siteSetting.getChargeMinAmt());
|
if (amt.compareTo(min) < 0) {
|
return ServerResponse.createByErrorMsg("充值金额不得低于" + siteSetting.getChargeMinAmt() + "元");
|
}
|
}
|
if (siteSetting.getChargeMaxAmt() != null && siteSetting.getChargeMaxAmt() > 0) {
|
BigDecimal max = new BigDecimal(siteSetting.getChargeMaxAmt());
|
if (amt.compareTo(max) > 0) {
|
return ServerResponse.createByErrorMsg("超过充值最大金额,请联系客服");
|
}
|
}
|
return ServerResponse.createBySuccess();
|
}
|
}
|