1
This commit is contained in:
@@ -27,6 +27,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -717,13 +718,15 @@ private void handleGiftMoneyFlow(String fromWxid, String message, UserInteractio
|
|||||||
}
|
}
|
||||||
|
|
||||||
amount = Double.parseDouble(message);
|
amount = Double.parseDouble(message);
|
||||||
logger.debug("校验金额:{} 元(商品价格的80%:{})", amount, 0.8 * Double.parseDouble(state.getCollectedFields().get("price"))); // 新增
|
// 格式化后输出日志
|
||||||
|
String formattedAmount = String.format("%.2f", amount);
|
||||||
|
logger.debug("校验金额:{} 元(商品价格的80%:{})", formattedAmount, 0.8 * Double.parseDouble(state.getCollectedFields().get("price"))); // 新增
|
||||||
if (amount < 1 || amount > 0.8 * Double.parseDouble(state.getCollectedFields().get("price"))) {
|
if (amount < 1 || amount > 0.8 * Double.parseDouble(state.getCollectedFields().get("price"))) {
|
||||||
wxUtil.sendTextMessage(fromWxid, "❌ 金额需≥1元且≤商品价格的80%", 1, fromWxid);
|
wxUtil.sendTextMessage(fromWxid, "❌ 金额需≥1元且≤商品价格的80%", 1, fromWxid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.getCollectedFields().put("amount", String.valueOf(amount));
|
state.getCollectedFields().put("amount", formattedAmount);
|
||||||
state.setCurrentStep(STEP_QUANTITY);
|
state.setCurrentStep(STEP_QUANTITY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -896,9 +899,21 @@ public boolean stopGiftCoupon(String giftKey) throws Exception {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean isValidAmount(String input) {
|
private boolean isValidAmount(String input) {
|
||||||
return input.matches("^\\d+(\\.\\d{1,2})?$");
|
if (Util.isNotEmpty(input)) {
|
||||||
|
try {
|
||||||
|
double amount = Double.parseDouble(input);
|
||||||
|
// 校验是否为两位小数(可选)
|
||||||
|
BigDecimal bd = new BigDecimal(input);
|
||||||
|
if (bd.scale() > 2) return false; // 精度超过两位返回 false
|
||||||
|
return amount >= 1 && amount <= 50;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user