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

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

@@ -41,6 +41,7 @@ public class UShopConsumeDiscountController {
*/ */
@GetMapping @GetMapping
public CzgResult<MkShopConsumeDiscountRecord> get(@RequestParam Long shopId, @RequestParam Long orderId) { public CzgResult<MkShopConsumeDiscountRecord> get(@RequestParam Long shopId, @RequestParam Long orderId) {
shopConsumeDiscountRecordService.useDiscount(null, null,null,null);
return CzgResult.success(shopConsumeDiscountRecordService.getDiscount(shopId, StpKit.USER.getLoginIdAsLong(), orderId)); return CzgResult.success(shopConsumeDiscountRecordService.getDiscount(shopId, StpKit.USER.getLoginIdAsLong(), orderId));
} }

View File

@@ -2,6 +2,7 @@ package com.czg.market.service;
import com.mybatisflex.core.service.IService; import com.mybatisflex.core.service.IService;
import com.czg.market.entity.MkShopConsumeDiscountRecord; import com.czg.market.entity.MkShopConsumeDiscountRecord;
import jakarta.validation.constraints.NotNull;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -26,5 +27,5 @@ public interface MkShopConsumeDiscountRecordService extends IService<MkShopConsu
* @param recordId MkShopConsumeDiscountRecord 主键 * @param recordId MkShopConsumeDiscountRecord 主键
* @return 是否成功 * @return 是否成功
*/ */
boolean useDiscount(Long recordId, Long orderId, BigDecimal amount); boolean useDiscount(Long recordId, Long shopUserId, Long orderId, BigDecimal amount);
} }

View File

@@ -77,6 +77,12 @@ public class AssertUtil {
public static void isNull(Object object, String errorMsgTemplate, Object... params) { public static void isNull(Object object, String errorMsgTemplate, Object... params) {
isNull(object, StrUtil.format(errorMsgTemplate, params)); isNull(object, StrUtil.format(errorMsgTemplate, params));
} }
public static void isTrue(boolean flag, String errorMsgTemplate, Object... params) {
if (flag) {
throw new ValidateException(StrUtil.format(errorMsgTemplate, params));
}
}
/** /**
* 检查数组是否不为空,如果为空则抛出异常 * 检查数组是否不为空,如果为空则抛出异常
* *
@@ -150,4 +156,6 @@ public class AssertUtil {
public static <K, V> void isMapEmpty(Map<K, V> map, String errorMsgTemplate, Object... params) { public static <K, V> void isMapEmpty(Map<K, V> map, String errorMsgTemplate, Object... params) {
isMapEmpty(map, StrUtil.format(errorMsgTemplate, params)); isMapEmpty(map, StrUtil.format(errorMsgTemplate, params));
} }
} }

View File

@@ -9,12 +9,14 @@ import com.czg.exception.ApiNotPrintException;
import com.czg.market.entity.MkConsumeDiscountRandom; import com.czg.market.entity.MkConsumeDiscountRandom;
import com.czg.market.service.MkConsumeDiscountService; import com.czg.market.service.MkConsumeDiscountService;
import com.czg.market.vo.MkConsumeDiscountVO; import com.czg.market.vo.MkConsumeDiscountVO;
import com.czg.utils.AssertUtil;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl; import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.market.entity.MkShopConsumeDiscountRecord; import com.czg.market.entity.MkShopConsumeDiscountRecord;
import com.czg.market.service.MkShopConsumeDiscountRecordService; import com.czg.market.service.MkShopConsumeDiscountRecordService;
import com.czg.service.market.mapper.MkShopConsumeDiscountRecordMapper; import com.czg.service.market.mapper.MkShopConsumeDiscountRecordMapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -36,10 +38,21 @@ public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl<MkShopCo
private ShopUserService shopUserService; private ShopUserService shopUserService;
@Override @Override
public boolean useDiscount(Long recordId, Long orderId, BigDecimal amount) { public boolean useDiscount(Long recordId, Long shopUserId, Long orderId, BigDecimal amount) {
return updateChain().eq(MkShopConsumeDiscountRecord::getId, recordId) 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) .eq(MkShopConsumeDiscountRecord::getIsUse, 0)
.set(MkShopConsumeDiscountRecord::getIsUse, 1).update(); .set(MkShopConsumeDiscountRecord::getIsUse, 1).update();
AssertUtil.isTrue(!flag, "修改失败");
return true;
} }
@Override @Override