新客立减

This commit is contained in:
张松
2025-09-25 17:43:32 +08:00
parent aafe9937a8
commit d0e230a1b8
2 changed files with 45 additions and 9 deletions

View File

@@ -22,6 +22,8 @@ public interface MkShopConsumeDiscountRecordService extends IService<MkShopConsu
*/
MkShopConsumeDiscountRecord getDiscount(Long shopId, Long userId, Long orderId);
boolean canUseDiscount(Long shopId, Long userId, BigDecimal amount);
/**
* 修改记录状态
* @param recordId MkShopConsumeDiscountRecord 主键

View File

@@ -43,15 +43,48 @@ public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl<MkShopCo
@DubboReference
private OrderInfoService orderInfoService;
private MkConsumeDiscountVO checkOpen(Long shopId) {
MkConsumeDiscountVO consumeDiscountVO = consumeDiscountService.detail(shopId);
if (consumeDiscountVO.getIsEnable() != 1) {
throw new ApiNotPrintException("新客立减未开启");
}
DateTime now = DateUtil.date();
if (!now.isAfterOrEquals(DateUtil.date(consumeDiscountVO.getStartTime())) || !now.isBeforeOrEquals(DateUtil.date(consumeDiscountVO.getEndTime()))) {
throw new ApiNotPrintException("此时间段未开启新客立减");
}
// 随机金额概率加起来是100
List<MkConsumeDiscountRandom> randomList = consumeDiscountVO.getRandomDiscountList();
if ("RANDOM".equals(consumeDiscountVO.getDiscountType()) && (randomList == null || randomList.isEmpty()) ){
throw new ApiNotPrintException("随机立减配置错误");
}
return consumeDiscountVO;
}
@Override
public boolean canUseDiscount(Long shopId, Long userId, BigDecimal amount) {
checkOpen(shopId);
ShopUser shopUser = shopUserService.getShopUserInfo(shopId, userId);
long count = orderInfoService.count(new QueryWrapper().eq(OrderInfo::getUserId, shopUser.getUserId())
.eq(OrderInfo::getShopId, shopUser.getSourceShopId()).eq(OrderInfo::getStatus, OrderStatusEnums.DONE));
if (count > 0) {
return false;
}
long recordCount = count(new QueryWrapper().eq(MkShopConsumeDiscountRecord::getShopId, shopId).eq(MkShopConsumeDiscountRecord::getShopUserId, shopUser.getId())
.eq(MkShopConsumeDiscountRecord::getIsUse, 1));
return recordCount <= 0;
}
@Override
public void useDiscount(Long recordId, Long shopUserId, Long orderId, BigDecimal amount) {
AssertUtil.isTrue(recordId == null || shopUserId == null || orderId == null || amount == null, "参数不能为空");
ShopUser shopUser = shopUserService.getById(shopUserId);
long count = orderInfoService.count(new QueryWrapper().eq(OrderInfo::getUserId, shopUser.getUserId())
.eq(OrderInfo::getShopId, shopUser.getSourceShopId()).eq(OrderInfo::getStatus, OrderStatusEnums.DONE));
if (count > 0) {
throw new CzgException("新客立减仅新用户可用");
}
MkShopConsumeDiscountRecord discountRecord = getOne(new QueryWrapper().eq(MkShopConsumeDiscountRecord::getId, recordId)
.eq(MkShopConsumeDiscountRecord::getShopUserId, shopUserId)
.eq(MkShopConsumeDiscountRecord::getOrderId, orderId));
@@ -74,11 +107,12 @@ public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl<MkShopCo
if (discountRecord != null) {
return discountRecord;
}
MkConsumeDiscountVO consumeDiscountVO = consumeDiscountService.detail(shopId);
if (consumeDiscountVO.getIsEnable() != 1) {
throw new ApiNotPrintException("新客立减未开启");
long count = orderInfoService.count(new QueryWrapper().eq(OrderInfo::getUserId, shopUser.getUserId())
.eq(OrderInfo::getShopId, shopUser.getSourceShopId()).eq(OrderInfo::getStatus, OrderStatusEnums.DONE));
if (count > 0) {
throw new ApiNotPrintException("新客立减仅新用户可用");
}
MkConsumeDiscountVO consumeDiscountVO = checkOpen(shopId);
DateTime now = DateUtil.date();