新客立减
This commit is contained in:
@@ -22,6 +22,8 @@ public interface MkShopConsumeDiscountRecordService extends IService<MkShopConsu
|
|||||||
*/
|
*/
|
||||||
MkShopConsumeDiscountRecord getDiscount(Long shopId, Long userId, Long orderId);
|
MkShopConsumeDiscountRecord getDiscount(Long shopId, Long userId, Long orderId);
|
||||||
|
|
||||||
|
boolean canUseDiscount(Long shopId, Long userId, BigDecimal amount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改记录状态
|
* 修改记录状态
|
||||||
* @param recordId MkShopConsumeDiscountRecord 主键
|
* @param recordId MkShopConsumeDiscountRecord 主键
|
||||||
|
|||||||
@@ -43,15 +43,48 @@ public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl<MkShopCo
|
|||||||
@DubboReference
|
@DubboReference
|
||||||
private OrderInfoService orderInfoService;
|
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
|
@Override
|
||||||
public void useDiscount(Long recordId, Long shopUserId, Long orderId, BigDecimal amount) {
|
public void useDiscount(Long recordId, Long shopUserId, Long orderId, BigDecimal amount) {
|
||||||
AssertUtil.isTrue(recordId == null || shopUserId == null || orderId == null || amount == null, "参数不能为空");
|
AssertUtil.isTrue(recordId == null || shopUserId == null || orderId == null || amount == null, "参数不能为空");
|
||||||
ShopUser shopUser = shopUserService.getById(shopUserId);
|
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)
|
MkShopConsumeDiscountRecord discountRecord = getOne(new QueryWrapper().eq(MkShopConsumeDiscountRecord::getId, recordId)
|
||||||
.eq(MkShopConsumeDiscountRecord::getShopUserId, shopUserId)
|
.eq(MkShopConsumeDiscountRecord::getShopUserId, shopUserId)
|
||||||
.eq(MkShopConsumeDiscountRecord::getOrderId, orderId));
|
.eq(MkShopConsumeDiscountRecord::getOrderId, orderId));
|
||||||
@@ -74,11 +107,12 @@ public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl<MkShopCo
|
|||||||
if (discountRecord != null) {
|
if (discountRecord != null) {
|
||||||
return discountRecord;
|
return discountRecord;
|
||||||
}
|
}
|
||||||
|
long count = orderInfoService.count(new QueryWrapper().eq(OrderInfo::getUserId, shopUser.getUserId())
|
||||||
MkConsumeDiscountVO consumeDiscountVO = consumeDiscountService.detail(shopId);
|
.eq(OrderInfo::getShopId, shopUser.getSourceShopId()).eq(OrderInfo::getStatus, OrderStatusEnums.DONE));
|
||||||
if (consumeDiscountVO.getIsEnable() != 1) {
|
if (count > 0) {
|
||||||
throw new ApiNotPrintException("新客立减未开启");
|
throw new ApiNotPrintException("新客立减仅新用户可用");
|
||||||
}
|
}
|
||||||
|
MkConsumeDiscountVO consumeDiscountVO = checkOpen(shopId);
|
||||||
|
|
||||||
DateTime now = DateUtil.date();
|
DateTime now = DateUtil.date();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user