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

This commit is contained in:
张松
2025-09-18 16:50:44 +08:00
parent 8e95d7f68d
commit 4d9773226e
4 changed files with 27 additions and 4 deletions

View File

@@ -9,12 +9,14 @@ import com.czg.exception.ApiNotPrintException;
import com.czg.market.entity.MkConsumeDiscountRandom;
import com.czg.market.service.MkConsumeDiscountService;
import com.czg.market.vo.MkConsumeDiscountVO;
import com.czg.utils.AssertUtil;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.market.entity.MkShopConsumeDiscountRecord;
import com.czg.market.service.MkShopConsumeDiscountRecordService;
import com.czg.service.market.mapper.MkShopConsumeDiscountRecordMapper;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
@@ -36,10 +38,21 @@ public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl<MkShopCo
private ShopUserService shopUserService;
@Override
public boolean useDiscount(Long recordId, Long orderId, BigDecimal amount) {
return updateChain().eq(MkShopConsumeDiscountRecord::getId, recordId)
public boolean useDiscount(Long recordId, Long shopUserId, Long orderId, BigDecimal amount) {
AssertUtil.isTrue(recordId == null || shopUserId == null || orderId == null || amount == null, "参数不能为空");
MkShopConsumeDiscountRecord discountRecord = getOne(new QueryWrapper().eq(MkShopConsumeDiscountRecord::getId, recordId)
.eq(MkShopConsumeDiscountRecord::getShopUserId, shopUserId)
.eq(MkShopConsumeDiscountRecord::getOrderId, orderId));
AssertUtil.isNull(discountRecord, "减免记录不存在");
AssertUtil.isTrue(discountRecord.getIsUse() == 0, "减免记录已使用");
AssertUtil.isTrue(discountRecord.getAmount().compareTo(amount) != 0, "减免金额不同");
boolean flag = updateChain().eq(MkShopConsumeDiscountRecord::getId, recordId)
.eq(MkShopConsumeDiscountRecord::getIsUse, 0)
.set(MkShopConsumeDiscountRecord::getIsUse, 1).update();
AssertUtil.isTrue(!flag, "修改失败");
return true;
}
@Override