|
|
@@ -1,6 +1,7 @@
|
|
|
package com.etotem.cfc.service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.etotem.cfc.entity.AssessmentOrder;
|
|
|
import com.etotem.cfc.entity.AssessmentQuota;
|
|
|
import com.etotem.cfc.entity.ProductOrder;
|
|
|
import com.etotem.cfc.mapper.AssessmentQuotaMapper;
|
|
|
@@ -26,13 +27,49 @@ public class AssessmentQuotaService {
|
|
|
|
|
|
@Transactional
|
|
|
public void grantQuota(ProductOrder order, Integer totalSessions, Integer validityDays) {
|
|
|
+ AssessmentQuota quota = insertQuota(order.getFamilyId(), null, order.getId(),
|
|
|
+ order.getProductId(), order.getProductName(), totalSessions, validityDays);
|
|
|
+ log.info("已为订单{}发放测评额度: quotaNo={}, familyId={}, 次数={}",
|
|
|
+ order.getOrderNo(), quota.getQuotaNo(), quota.getFamilyId(), quota.getTotalSessions());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测评订单(assessment_orders)支付成功发放额度。
|
|
|
+ *
|
|
|
+ * <p>SC-P-34/SC-P-35:支付成功(pending→paid)后生成一条额度,含有效期(validity_end)。
|
|
|
+ * 额度来源订单 ID 复用 {@code product_order_id} 列(预约创建时按
|
|
|
+ * {@code quota.getProductOrderId()} 回填执行记录的 assessmentOrderId)。</p>
|
|
|
+ *
|
|
|
+ * @param totalSessions 总次数,null 默认 1
|
|
|
+ * @param validityDays 有效天数,null 默认 365
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void grantQuota(AssessmentOrder order, Integer totalSessions, Integer validityDays) {
|
|
|
+ AssessmentQuota quota = insertQuota(order.getFamilyId(), order.getMemberId(), order.getId(),
|
|
|
+ order.getPackageId() != null ? order.getPackageId() : 0L,
|
|
|
+ order.getPackageName() != null ? order.getPackageName() : "测评套餐",
|
|
|
+ totalSessions, validityDays);
|
|
|
+ log.info("测评订单{}支付成功,已发放测评额度: quotaNo={}, familyId={}, memberId={}, 次数={}",
|
|
|
+ order.getOrderNo(), quota.getQuotaNo(), quota.getFamilyId(), quota.getMemberId(),
|
|
|
+ quota.getTotalSessions());
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 测评订单支付成功发放额度(默认 1 次 / 365 天有效) */
|
|
|
+ @Transactional
|
|
|
+ public void grantQuota(AssessmentOrder order) {
|
|
|
+ grantQuota(order, null, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private AssessmentQuota insertQuota(Long familyId, Long memberId, Long sourceOrderId,
|
|
|
+ Long productId, String productName,
|
|
|
+ Integer totalSessions, Integer validityDays) {
|
|
|
AssessmentQuota quota = new AssessmentQuota();
|
|
|
quota.setQuotaNo(generateQuotaNo());
|
|
|
- quota.setFamilyId(order.getFamilyId() != null ? order.getFamilyId() : 0L);
|
|
|
- quota.setMemberId(null); // 不绑定具体家庭成员
|
|
|
- quota.setProductOrderId(order.getId());
|
|
|
- quota.setProductId(order.getProductId());
|
|
|
- quota.setProductName(order.getProductName());
|
|
|
+ quota.setFamilyId(familyId != null ? familyId : 0L);
|
|
|
+ quota.setMemberId(memberId);
|
|
|
+ quota.setProductOrderId(sourceOrderId);
|
|
|
+ quota.setProductId(productId);
|
|
|
+ quota.setProductName(productName);
|
|
|
quota.setTotalSessions(totalSessions != null ? totalSessions : 1);
|
|
|
quota.setRemainingSessions(totalSessions != null ? totalSessions : 1);
|
|
|
Date now = new Date();
|
|
|
@@ -43,8 +80,7 @@ public class AssessmentQuotaService {
|
|
|
quota.setCreatedAt(now);
|
|
|
quota.setUpdatedAt(now);
|
|
|
mapper.insert(quota);
|
|
|
- log.info("已为订单{}发放测评额度: quotaNo={}, familyId={}, 次数={}",
|
|
|
- order.getOrderNo(), quota.getQuotaNo(), quota.getFamilyId(), quota.getTotalSessions());
|
|
|
+ return quota;
|
|
|
}
|
|
|
|
|
|
@Transactional
|