Просмотр исходного кода

feat(coupon): 新增收回家庭人口券方法支持成员被踢出时回收

Sisyphus 2 недель назад
Родитель
Сommit
9acf5a3724
1 измененных файлов с 30 добавлено и 0 удалено
  1. 30 0
      cfc-backend/src/main/java/com/etotem/cfc/service/CouponService.java

+ 30 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/CouponService.java

@@ -341,6 +341,36 @@ public class CouponService {
         }
         }
     }
     }
 
 
+    /**
+     * 收回家庭人口券:成员被管理员踢出时,撤销该家庭发放给该成员的 POPULATION 券。
+     * 仅作废仍为 AVAILABLE 的券(已 USED 的券不追溯)。
+     */
+    @Transactional
+    public void revokeFamilyPopulationCoupons(Long familyId, Long memberId) {
+        String source = "member:" + memberId;
+        List<FamilyCouponGrantLog> logs = familyCouponGrantLogMapper.selectList(
+                new LambdaQueryWrapper<FamilyCouponGrantLog>()
+                        .eq(FamilyCouponGrantLog::getFamilyId, familyId)
+                        .eq(FamilyCouponGrantLog::getGrantType, "POPULATION")
+                        .eq(FamilyCouponGrantLog::getSource, source));
+        if (logs == null || logs.isEmpty()) {
+            return;
+        }
+        for (FamilyCouponGrantLog grantLog : logs) {
+            List<FamilyCoupon> coupons = familyCouponMapper.selectList(
+                    new LambdaQueryWrapper<FamilyCoupon>()
+                            .eq(FamilyCoupon::getFamilyId, familyId)
+                            .eq(FamilyCoupon::getCouponId, grantLog.getCouponId())
+                            .eq(FamilyCoupon::getStatus, "AVAILABLE"));
+            for (FamilyCoupon fc : coupons) {
+                fc.setStatus("REVOKED");
+                familyCouponMapper.updateById(fc);
+            }
+        }
+        logger.info("收回家庭人口券完成: familyId={}, memberId={}, 作废券数={}", familyId, memberId,
+                logs.stream().mapToInt(l -> l.getQuantity() != null ? l.getQuantity() : 0).sum());
+    }
+
     /** PERIODIC: 返回所有周期性补发券模板 */
     /** PERIODIC: 返回所有周期性补发券模板 */
     public List<Coupon> listPeriodicTemplates() {
     public List<Coupon> listPeriodicTemplates() {
         return couponMapper.selectList(
         return couponMapper.selectList(