|
@@ -3,11 +3,11 @@ package com.etotem.cfc.service;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.etotem.cfc.entity.Coupon;
|
|
import com.etotem.cfc.entity.Coupon;
|
|
|
-import com.etotem.cfc.entity.CouponGrantLog;
|
|
|
|
|
|
|
+import com.etotem.cfc.entity.FamilyCouponGrantLog;
|
|
|
import com.etotem.cfc.entity.FamilyMember;
|
|
import com.etotem.cfc.entity.FamilyMember;
|
|
|
import com.etotem.cfc.entity.PointsExchangeProduct;
|
|
import com.etotem.cfc.entity.PointsExchangeProduct;
|
|
|
import com.etotem.cfc.entity.PointsExchangeRecord;
|
|
import com.etotem.cfc.entity.PointsExchangeRecord;
|
|
|
-import com.etotem.cfc.mapper.CouponGrantLogMapper;
|
|
|
|
|
|
|
+import com.etotem.cfc.mapper.FamilyCouponGrantLogMapper;
|
|
|
import com.etotem.cfc.mapper.CouponMapper;
|
|
import com.etotem.cfc.mapper.CouponMapper;
|
|
|
import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
|
import com.etotem.cfc.mapper.PointsExchangeProductMapper;
|
|
import com.etotem.cfc.mapper.PointsExchangeProductMapper;
|
|
@@ -47,7 +47,7 @@ public class PointsExchangeService {
|
|
|
private CouponService couponService;
|
|
private CouponService couponService;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
- private CouponGrantLogMapper couponGrantLogMapper;
|
|
|
|
|
|
|
+ private FamilyCouponGrantLogMapper familyCouponGrantLogMapper;
|
|
|
|
|
|
|
|
public Page<PointsExchangeProduct> getProductList(String category, Integer pageNum, Integer pageSize) {
|
|
public Page<PointsExchangeProduct> getProductList(String category, Integer pageNum, Integer pageSize) {
|
|
|
Page<PointsExchangeProduct> pageParam = new Page<>(pageNum, pageSize);
|
|
Page<PointsExchangeProduct> pageParam = new Page<>(pageNum, pageSize);
|
|
@@ -234,6 +234,12 @@ public class PointsExchangeService {
|
|
|
throw new RuntimeException("今日兑换次数已达上限");
|
|
throw new RuntimeException("今日兑换次数已达上限");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 目标家庭(单券日限次按家庭统计,发券也落到该家庭)
|
|
|
|
|
+ Long targetFamilyId = null;
|
|
|
|
|
+ FamilyMember targetMember = familyMemberMapper.selectById(targetFamilyMemberId);
|
|
|
|
|
+ if (targetMember != null) targetFamilyId = targetMember.getFamilyId();
|
|
|
|
|
+ if (targetFamilyId == null) throw new RuntimeException("未找到目标成员所在家庭");
|
|
|
|
|
+
|
|
|
// 单券模板日限次(coupon_exchange_daily_limit 默认1)
|
|
// 单券模板日限次(coupon_exchange_daily_limit 默认1)
|
|
|
int couponDailyLimit = 1;
|
|
int couponDailyLimit = 1;
|
|
|
try {
|
|
try {
|
|
@@ -244,12 +250,14 @@ public class PointsExchangeService {
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
couponDailyLimit = 1;
|
|
couponDailyLimit = 1;
|
|
|
}
|
|
}
|
|
|
- long couponTodayCount = couponGrantLogMapper.selectCount(
|
|
|
|
|
- new LambdaQueryWrapper<CouponGrantLog>()
|
|
|
|
|
- .eq(CouponGrantLog::getUserId, userId)
|
|
|
|
|
- .eq(CouponGrantLog::getCouponId, couponId)
|
|
|
|
|
- .eq(CouponGrantLog::getGrantType, "EXCHANGE")
|
|
|
|
|
- .ge(CouponGrantLog::getCreatedAt, todayStart)
|
|
|
|
|
|
|
+ // 统计源必须是实际发券写入的 family_coupon_grant_log(EXCHANGE 由 grantFamily 落库),
|
|
|
|
|
+ // 原 coupon_grant_log 为遗留死表,永远查不到记录导致日限次失效。
|
|
|
|
|
+ long couponTodayCount = familyCouponGrantLogMapper.selectCount(
|
|
|
|
|
+ new LambdaQueryWrapper<FamilyCouponGrantLog>()
|
|
|
|
|
+ .eq(FamilyCouponGrantLog::getFamilyId, targetFamilyId)
|
|
|
|
|
+ .eq(FamilyCouponGrantLog::getCouponId, couponId)
|
|
|
|
|
+ .eq(FamilyCouponGrantLog::getGrantType, "EXCHANGE")
|
|
|
|
|
+ .ge(FamilyCouponGrantLog::getCreatedAt, todayStart)
|
|
|
);
|
|
);
|
|
|
if (couponTodayCount >= couponDailyLimit) {
|
|
if (couponTodayCount >= couponDailyLimit) {
|
|
|
throw new RuntimeException("该优惠券今日兑换次数已达上限");
|
|
throw new RuntimeException("该优惠券今日兑换次数已达上限");
|
|
@@ -276,10 +284,6 @@ public class PointsExchangeService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 发券 + 流水(EXCHANGE,period=null)— 发到用户所在家庭
|
|
// 发券 + 流水(EXCHANGE,period=null)— 发到用户所在家庭
|
|
|
- Long targetFamilyId = null;
|
|
|
|
|
- FamilyMember targetMember = familyMemberMapper.selectById(targetFamilyMemberId);
|
|
|
|
|
- if (targetMember != null) targetFamilyId = targetMember.getFamilyId();
|
|
|
|
|
- if (targetFamilyId == null) throw new RuntimeException("未找到目标成员所在家庭");
|
|
|
|
|
couponService.grantFamily(targetFamilyId, couponId, "EXCHANGE", null, null);
|
|
couponService.grantFamily(targetFamilyId, couponId, "EXCHANGE", null, null);
|
|
|
|
|
|
|
|
String redeemCode = UUID.randomUUID().toString().replace("-", "").substring(0, 12).toUpperCase();
|
|
String redeemCode = UUID.randomUUID().toString().replace("-", "").substring(0, 12).toUpperCase();
|