|
|
@@ -122,27 +122,15 @@ public class PointsExchangeService {
|
|
|
}
|
|
|
|
|
|
int totalCost = product.getPointsPrice() * quantity;
|
|
|
- int minPoints = 100;
|
|
|
- try {
|
|
|
- String minStr = sysConfigService.getValue("exchange_points_min");
|
|
|
- if (minStr != null && !minStr.isEmpty()) {
|
|
|
- minPoints = Integer.parseInt(minStr);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- minPoints = 100;
|
|
|
- }
|
|
|
+ int minPoints = configService.getIntConfig(CfConfigKeys.SPEND_EXCHANGE_MIN_POINTS, 100);
|
|
|
if (totalCost < minPoints) {
|
|
|
throw new RuntimeException("兑换积分不得低于最低限制");
|
|
|
}
|
|
|
|
|
|
- int deductResult = pointsService.deductCfPoints(targetFamilyMemberId, totalCost,
|
|
|
- "积分兑换商品: " + product.getName());
|
|
|
- if (deductResult < 0) {
|
|
|
- throw new RuntimeException("积分不足");
|
|
|
- }
|
|
|
-
|
|
|
String redeemCode = UUID.randomUUID().toString().replace("-", "").substring(0, 12).toUpperCase();
|
|
|
|
|
|
+ // F-5:先落兑换记录(以记录 ID 作为扣减幂等 refId),再扣统一账本 cf_balance;
|
|
|
+ // 扣减失败(余额不足)抛业务异常并由 @Transactional 回滚记录
|
|
|
PointsExchangeRecord record = new PointsExchangeRecord();
|
|
|
record.setUserId(userId);
|
|
|
record.setFamilyMemberId(targetFamilyMemberId);
|
|
|
@@ -161,6 +149,9 @@ public class PointsExchangeService {
|
|
|
record.setUpdatedAt(new Date());
|
|
|
pointsExchangeRecordMapper.insert(record);
|
|
|
|
|
|
+ cfSpendDispatchService.spendForMember(targetFamilyMemberId, totalCost, "exchange_product",
|
|
|
+ record.getId(), "积分兑换商品: " + product.getName());
|
|
|
+
|
|
|
if (product.getStock() != null && product.getStock() >= 0) {
|
|
|
product.setStock(product.getStock() - quantity);
|
|
|
pointsExchangeProductMapper.updateById(product);
|
|
|
@@ -206,16 +197,8 @@ public class PointsExchangeService {
|
|
|
throw new RuntimeException("未找到关联的家庭成员信息");
|
|
|
}
|
|
|
|
|
|
- // 全局日限次(复用 exchange_daily_limit)
|
|
|
- int dailyLimit = 5;
|
|
|
- try {
|
|
|
- String limitStr = sysConfigService.getValue("exchange_daily_limit");
|
|
|
- if (limitStr != null && !limitStr.isEmpty()) {
|
|
|
- dailyLimit = Integer.parseInt(limitStr);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- dailyLimit = 5;
|
|
|
- }
|
|
|
+ // 个人级日限次(L2:cf.spend.exchange.daily_limit,默认5)
|
|
|
+ int dailyLimit = configService.getIntConfig(CfConfigKeys.SPEND_EXCHANGE_DAILY_LIMIT, 5);
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
cal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
cal.set(Calendar.MINUTE, 0);
|