|
|
@@ -2,6 +2,9 @@ package com.etotem.cfc.service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.etotem.cfc.common.OrderNoGenerator;
|
|
|
+import com.etotem.cfc.config.ConfigService;
|
|
|
+import com.etotem.cfc.constant.CfConfigKeys;
|
|
|
+import com.etotem.cfc.dto.CfEarnResult;
|
|
|
import com.etotem.cfc.dto.QuotaStatusDTO;
|
|
|
import com.etotem.cfc.entity.*;
|
|
|
import com.etotem.cfc.mapper.*;
|
|
|
@@ -30,8 +33,6 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class GutHealthProjectService {
|
|
|
|
|
|
- /** 默认项目价格(分) */
|
|
|
- private static final int DEFAULT_PRICE = 1990;
|
|
|
/** 任务列表默认总数(一周 7 天) */
|
|
|
private static final int DEFAULT_TASK_TOTAL = 7;
|
|
|
|
|
|
@@ -48,11 +49,14 @@ public class GutHealthProjectService {
|
|
|
private FamilyMembershipMapper familyMembershipMapper;
|
|
|
|
|
|
@Resource
|
|
|
- private PlatformPointsService platformPointsService;
|
|
|
+ private CfEarnDispatchService cfEarnDispatchService;
|
|
|
|
|
|
@Resource
|
|
|
private SysConfigService sysConfigService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ConfigService configService;
|
|
|
+
|
|
|
@Resource
|
|
|
private MemberUpgradeRecordMapper memberUpgradeRecordMapper;
|
|
|
|
|
|
@@ -264,6 +268,14 @@ public class GutHealthProjectService {
|
|
|
project.setUpdatedAt(new Date());
|
|
|
projectMapper.insert(project);
|
|
|
|
|
|
+ // F02 消费返 CF:调研订单属消费订单(N6 所有消费都返),金额取订单实付(分)
|
|
|
+ try {
|
|
|
+ cfEarnDispatchService.earnConsumeCf(project.getUserId(), "gut_health", order.getId(), order.getAmount());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("调研订单返CF失败(F02): orderId={}, userId={}, error={}",
|
|
|
+ order.getId(), project.getUserId(), e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
log.info("菌群健康项目创建成功: orderNo={}, projectId={}, userId={}, amount={}",
|
|
|
orderNo, project.getId(), project.getUserId(), order.getAmount());
|
|
|
return true;
|
|
|
@@ -440,8 +452,13 @@ public class GutHealthProjectService {
|
|
|
amount = getProjectPrice();
|
|
|
}
|
|
|
try {
|
|
|
- platformPointsService.earn(project.getUserId(), amount, "GUT_HEALTH", project.getId(),
|
|
|
- "菌群健康调研一周打卡完成,返还CF值");
|
|
|
+ CfEarnResult result = cfEarnDispatchService.earnGutHealthRefundCf(
|
|
|
+ project.getUserId(), project.getId(), amount);
|
|
|
+ if (result == null || !Boolean.TRUE.equals(result.getEarned())) {
|
|
|
+ log.warn("菌群健康项目CF返还未发放: userId={}, projectId={}, reason={}",
|
|
|
+ project.getUserId(), project.getId(), result != null ? result.getReason() : "null");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
project.setCfRefunded(1);
|
|
|
project.setUpdatedAt(new Date());
|
|
|
projectMapper.updateById(project);
|
|
|
@@ -804,15 +821,29 @@ public class GutHealthProjectService {
|
|
|
return project;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 项目价格(分)。读取顺序:旧 sys_config.gut_health_project_price → service_config cf.product.gut_health_price
|
|
|
+ * (W0.2 已迁移,兜底 1990 分 = 19.9 元仅注册在 CfConfigKeys,代码内无硬编码常量)。
|
|
|
+ */
|
|
|
private int getProjectPrice() {
|
|
|
- String priceStr = sysConfigService.getValue("gut_health_project_price");
|
|
|
- if (priceStr != null) {
|
|
|
+ String legacy = null;
|
|
|
+ try {
|
|
|
+ legacy = sysConfigService.getValue("gut_health_project_price");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("读取 sys_config.gut_health_project_price 失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ if (legacy != null && !legacy.trim().isEmpty()) {
|
|
|
try {
|
|
|
- return Integer.parseInt(priceStr);
|
|
|
- } catch (NumberFormatException ignored) {
|
|
|
+ return Integer.parseInt(legacy.trim());
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.warn("sys_config.gut_health_project_price 非整数:{}", legacy);
|
|
|
}
|
|
|
}
|
|
|
- return DEFAULT_PRICE;
|
|
|
+ int price = configService.getIntConfig(CfConfigKeys.PRODUCT_GUT_HEALTH_PRICE, 0);
|
|
|
+ if (price <= 0) {
|
|
|
+ throw new IllegalStateException("缺少菌群健康项目价格配置: " + CfConfigKeys.PRODUCT_GUT_HEALTH_PRICE);
|
|
|
+ }
|
|
|
+ return price;
|
|
|
}
|
|
|
|
|
|
private Long getUserFamilyId(Long userId) {
|