新客立减修改

This commit is contained in:
张松 2025-09-17 17:28:30 +08:00
parent 84acedfff6
commit 78f3c5e0bc
1 changed files with 11 additions and 10 deletions

View File

@ -24,7 +24,7 @@ import java.math.BigDecimal;
* @since 2025-09-16
*/
@Service
public class MkConsumeDiscountServiceImpl extends ServiceImpl<MkConsumeDiscountMapper, MkConsumeDiscount> implements MkConsumeDiscountService{
public class MkConsumeDiscountServiceImpl extends ServiceImpl<MkConsumeDiscountMapper, MkConsumeDiscount> implements MkConsumeDiscountService {
@Override
public MkConsumeDiscountVO detail(Long shopId) {
MkConsumeDiscount consumeDiscount = getOne(new QueryWrapper().eq(MkConsumeDiscount::getShopId, shopId));
@ -51,28 +51,29 @@ public class MkConsumeDiscountServiceImpl extends ServiceImpl<MkConsumeDiscountM
if (consumeDiscountDTO.getRandomDiscountList() == null && consumeDiscountDTO.getDiscountAmount() == null) {
throw new ApiNotPrintException("优惠金额和随机优惠金额不能同时为空");
}
MkConsumeDiscount consumeDiscount = getOne(new QueryWrapper().eq(MkConsumeDiscount::getShopId, shopId));
if (TableValueConstant.ConsumeDiscount.DiscountType.RANDOM.getCode().equals(consumeDiscountDTO.getDiscountType())) {
if (consumeDiscountDTO.getRandomDiscountList() == null || consumeDiscountDTO.getRandomDiscountList().isEmpty()) {
throw new ApiNotPrintException("随机优惠金额不能为空");
}
}else {
if (consumeDiscountDTO.getRandomDiscountList().stream().map(MkConsumeDiscountRandom::getProbability).reduce(BigDecimal.ZERO, BigDecimal::add).compareTo(new BigDecimal("100")) != 0) {
throw new ApiNotPrintException("随机概率综合必须为100%");
}
consumeDiscount.setRandomDiscountList(JSONArray.toJSONString(consumeDiscountDTO.getRandomDiscountList()));
} else {
if (consumeDiscountDTO.getDiscountAmount() == null) {
throw new ApiNotPrintException("减免金额不能为空");
}
if (consumeDiscountDTO.getDiscountAmount().compareTo(BigDecimal.ZERO) <= 0) {
throw new ApiNotPrintException("减免金额不能等于0");
}
}
MkConsumeDiscount consumeDiscount = getOne(new QueryWrapper().eq(MkConsumeDiscount::getShopId, shopId));
BeanUtil.copyProperties(consumeDiscountDTO, consumeDiscount);
if (consumeDiscountDTO.getRandomDiscountList() != null) {
if (consumeDiscountDTO.getRandomDiscountList().stream().map(MkConsumeDiscountRandom::getProbability).reduce(BigDecimal.ZERO, BigDecimal::add).compareTo(new BigDecimal("100")) != 0) {
throw new ApiNotPrintException("随机概率综合必须为100%");
}
consumeDiscount.setRandomDiscountList(JSONArray.toJSONString(consumeDiscountDTO.getRandomDiscountList()));
}
if (consumeDiscountDTO.getUseTypeList() != null) {
consumeDiscount.setUseTypeList(JSONArray.toJSONString(consumeDiscountDTO.getUseTypeList()));