新客立减获取减免金额方法

This commit is contained in:
张松
2025-09-18 16:36:27 +08:00
parent 61f1a8de71
commit d9b314df18
4 changed files with 34 additions and 3 deletions

View File

@@ -1,5 +1,8 @@
package com.czg.service.market.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopUserService;
import com.czg.constant.TableValueConstant;
@@ -32,8 +35,16 @@ public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl<MkShopCo
private MkConsumeDiscountService consumeDiscountService;
@DubboReference
private ShopUserService shopUserService;
@Override
public MkShopConsumeDiscountRecord get(Long shopId, Long userId, Long orderId) {
public boolean useDiscount(Long recordId) {
return updateChain().eq(MkShopConsumeDiscountRecord::getId, recordId)
.eq(MkShopConsumeDiscountRecord::getIsUse, 0)
.set(MkShopConsumeDiscountRecord::getIsUse, 1).update();
}
@Override
public MkShopConsumeDiscountRecord getDiscount(Long shopId, Long userId, Long orderId) {
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getUserId, userId).eq(ShopUser::getShopId, shopId));
MkShopConsumeDiscountRecord discountRecord = getOne(new QueryWrapper().eq(MkShopConsumeDiscountRecord::getShopId, shopId)
.eq(MkShopConsumeDiscountRecord::getOrderId, orderId)
@@ -47,6 +58,11 @@ public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl<MkShopCo
throw new ApiNotPrintException("新客立减未开启");
}
DateTime now = DateUtil.date();
if (!now.isAfterOrEquals(DateUtil.date(consumeDiscountVO.getStartTime())) || !now.isBeforeOrEquals(DateUtil.date(consumeDiscountVO.getEndTime()))) {
throw new ApiNotPrintException("此时间段未开启新客立减");
}
MkShopConsumeDiscountRecord shopConsumeDiscountRecord = new MkShopConsumeDiscountRecord();
shopConsumeDiscountRecord.setShopId(shopId);
shopConsumeDiscountRecord.setShopUserId(shopUser.getId());