You've already forked FrameTour-BE
feat(pricing): 增加景区优惠券统计功能并优化优惠券使用逻辑
- 新增景区优惠券统计接口和相关查询方法 - 为优惠券配置和使用记录添加景区ID字段 - 实现优惠券使用时的景区限制检查 - 优化优惠券适用性的判断逻辑,增加对景区和商品类型的检查
This commit is contained in:
@@ -126,12 +126,12 @@ public class CouponManagementServiceImpl implements ICouponManagementService {
|
||||
|
||||
@Override
|
||||
public PageInfo<PriceCouponConfig> getCouponConfigsPage(Integer pageNum, Integer pageSize,
|
||||
Boolean isActive, String couponName) {
|
||||
log.info("分页查询优惠券配置,页码: {}, 页大小: {}, 状态: {}, 名称: {}",
|
||||
pageNum, pageSize, isActive, couponName);
|
||||
Boolean isActive, String couponName, String scenicId) {
|
||||
log.info("分页查询优惠券配置,页码: {}, 页大小: {}, 状态: {}, 名称: {}, 景区ID: {}",
|
||||
pageNum, pageSize, isActive, couponName, scenicId);
|
||||
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<PriceCouponConfig> configs = couponConfigMapper.selectByConditionsForAdmin(isActive, couponName);
|
||||
List<PriceCouponConfig> configs = couponConfigMapper.selectByConditionsForAdmin(isActive, couponName, scenicId);
|
||||
return new PageInfo<>(configs);
|
||||
}
|
||||
|
||||
@@ -158,12 +158,12 @@ public class CouponManagementServiceImpl implements ICouponManagementService {
|
||||
@Override
|
||||
public PageInfo<PriceCouponClaimRecord> getClaimRecordsPage(Integer pageNum, Integer pageSize,
|
||||
Long userId, Long couponId, CouponStatus status,
|
||||
String startTime, String endTime) {
|
||||
log.info("分页查询优惠券领取记录,页码: {}, 页大小: {}, 用户ID: {}, 优惠券ID: {}, 状态: {}, 开始时间: {}, 结束时间: {}",
|
||||
pageNum, pageSize, userId, couponId, status, startTime, endTime);
|
||||
String startTime, String endTime, String scenicId) {
|
||||
log.info("分页查询优惠券领取记录,页码: {}, 页大小: {}, 用户ID: {}, 优惠券ID: {}, 状态: {}, 开始时间: {}, 结束时间: {}, 景区ID: {}",
|
||||
pageNum, pageSize, userId, couponId, status, startTime, endTime, scenicId);
|
||||
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<PriceCouponClaimRecord> records = claimRecordMapper.selectByConditionsForAdmin(userId, couponId, status, startTime, endTime);
|
||||
List<PriceCouponClaimRecord> records = claimRecordMapper.selectByConditionsForAdmin(userId, couponId, status, startTime, endTime, scenicId);
|
||||
return new PageInfo<>(records);
|
||||
}
|
||||
|
||||
@@ -198,9 +198,9 @@ public class CouponManagementServiceImpl implements ICouponManagementService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getPeriodStats(String startDate, String endDate) {
|
||||
log.info("查询时间范围统计,开始日期: {}, 结束日期: {}", startDate, endDate);
|
||||
return claimRecordMapper.selectPeriodStats(startDate, endDate);
|
||||
public Map<String, Object> getPeriodStats(String startDate, String endDate, String scenicId) {
|
||||
log.info("查询时间范围统计,开始日期: {}, 结束日期: {}, 景区ID: {}", startDate, endDate, scenicId);
|
||||
return claimRecordMapper.selectPeriodStats(startDate, endDate, scenicId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -231,4 +231,23 @@ public class CouponManagementServiceImpl implements ICouponManagementService {
|
||||
|
||||
return overview;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getScenicCouponStats(String scenicId) {
|
||||
log.info("查询景区优惠券统计,景区ID: {}", scenicId);
|
||||
|
||||
// 获取景区优惠券配置统计
|
||||
Map<String, Object> configStats = couponConfigMapper.selectScenicCouponConfigStats(scenicId);
|
||||
|
||||
// 获取景区优惠券使用统计
|
||||
Map<String, Object> usageStats = claimRecordMapper.selectScenicCouponUsageStats(scenicId);
|
||||
|
||||
// 合并统计结果
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("scenic_id", scenicId);
|
||||
result.putAll(configStats);
|
||||
result.putAll(usageStats);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -82,10 +82,29 @@ public class CouponServiceImpl implements ICouponService {
|
||||
|
||||
@Override
|
||||
public boolean isCouponApplicable(PriceCouponConfig coupon, List<ProductItem> products, BigDecimal totalAmount) {
|
||||
// 1. 检查最小使用金额
|
||||
if (totalAmount.compareTo(coupon.getMinAmount()) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. 检查景区限制
|
||||
if (coupon.getScenicId() != null && !coupon.getScenicId().isEmpty()) {
|
||||
boolean hasMatchingScenicProduct = false;
|
||||
for (ProductItem product : products) {
|
||||
if (coupon.getScenicId().equals(product.getScenicId())) {
|
||||
hasMatchingScenicProduct = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasMatchingScenicProduct) {
|
||||
log.debug("优惠券景区限制不匹配: 优惠券景区={}, 商品景区={}",
|
||||
coupon.getScenicId(),
|
||||
products.stream().map(ProductItem::getScenicId).distinct().toList());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 检查商品类型限制
|
||||
if (coupon.getApplicableProducts() == null || coupon.getApplicableProducts().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
@@ -127,14 +146,19 @@ public class CouponServiceImpl implements ICouponService {
|
||||
|
||||
LocalDateTime useTime = LocalDateTime.now();
|
||||
|
||||
// 设置使用时间和订单信息
|
||||
// 设置使用时间、订单信息和景区信息
|
||||
record.setStatus(CouponStatus.USED);
|
||||
record.setUseTime(useTime);
|
||||
record.setOrderId(request.getOrderId());
|
||||
record.setUpdatedTime(LocalDateTime.now());
|
||||
|
||||
// 如果请求中包含景区ID,记录到使用记录中
|
||||
if (request.getScenicId() != null && !request.getScenicId().isEmpty()) {
|
||||
record.setScenicId(request.getScenicId());
|
||||
}
|
||||
|
||||
couponClaimRecordMapper.updateCouponStatus(
|
||||
record.getId(), CouponStatus.USED, useTime, request.getOrderId());
|
||||
record.getId(), CouponStatus.USED, useTime, request.getOrderId(), request.getScenicId());
|
||||
|
||||
CouponUseResult result = new CouponUseResult();
|
||||
result.setCouponId(request.getCouponId());
|
||||
|
Reference in New Issue
Block a user