Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
package com.czg.market.service;
|
package com.czg.market.service;
|
||||||
|
|
||||||
|
import com.czg.market.vo.MkConsumeDiscountVO;
|
||||||
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;
|
||||||
|
|
||||||
@@ -22,6 +22,14 @@ public interface MkShopConsumeDiscountRecordService extends IService<MkShopConsu
|
|||||||
*/
|
*/
|
||||||
MkShopConsumeDiscountRecord getDiscount(Long shopId, Long userId, Long orderId);
|
MkShopConsumeDiscountRecord getDiscount(Long shopId, Long userId, Long orderId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否可用新客立减
|
||||||
|
*
|
||||||
|
* @param shopId 店铺id
|
||||||
|
* @param userId 用户id
|
||||||
|
*/
|
||||||
|
MkConsumeDiscountVO checkDiscount(Long shopId, Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改记录状态
|
* 修改记录状态
|
||||||
* @param recordId MkShopConsumeDiscountRecord 主键
|
* @param recordId MkShopConsumeDiscountRecord 主键
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import com.czg.account.entity.ShopUser;
|
|||||||
import com.czg.account.service.ShopUserService;
|
import com.czg.account.service.ShopUserService;
|
||||||
import com.czg.constant.TableValueConstant;
|
import com.czg.constant.TableValueConstant;
|
||||||
import com.czg.exception.ApiNotPrintException;
|
import com.czg.exception.ApiNotPrintException;
|
||||||
import com.czg.exception.CzgException;
|
|
||||||
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;
|
||||||
@@ -20,7 +19,6 @@ 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;
|
||||||
|
|
||||||
@@ -43,15 +41,44 @@ public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl<MkShopCo
|
|||||||
@DubboReference
|
@DubboReference
|
||||||
private OrderInfoService orderInfoService;
|
private OrderInfoService orderInfoService;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MkConsumeDiscountVO checkDiscount(Long shopId, Long userId) {
|
||||||
|
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("随机立减配置错误");
|
||||||
|
}
|
||||||
|
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));
|
||||||
|
AssertUtil.isTrue(count > 0, "新客立减仅限新用户使用");
|
||||||
|
|
||||||
|
|
||||||
|
long recordCount = count(new QueryWrapper().eq(MkShopConsumeDiscountRecord::getShopId, shopId).eq(MkShopConsumeDiscountRecord::getShopUserId, shopUser.getId())
|
||||||
|
.eq(MkShopConsumeDiscountRecord::getIsUse, 1));
|
||||||
|
|
||||||
|
AssertUtil.isTrue(recordCount > 0, "新客立减已使用");
|
||||||
|
|
||||||
|
return consumeDiscountVO;
|
||||||
|
}
|
||||||
|
|
||||||
@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 +101,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 = checkDiscount(shopId, userId);
|
||||||
|
|
||||||
DateTime now = DateUtil.date();
|
DateTime now = DateUtil.date();
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,8 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
|
|||||||
if (shopUserInfo.getMemberLevelId() == null) {
|
if (shopUserInfo.getMemberLevelId() == null) {
|
||||||
MemberLevelConfig configServiceOne = levelConfigService.getOne(new QueryWrapper().eq(MemberLevelConfig::getShopId, shopId).orderBy(MemberLevelConfig::getExperienceValue, true)
|
MemberLevelConfig configServiceOne = levelConfigService.getOne(new QueryWrapper().eq(MemberLevelConfig::getShopId, shopId).orderBy(MemberLevelConfig::getExperienceValue, true)
|
||||||
.limit(1));
|
.limit(1));
|
||||||
configVO.setMemberLevel(levelConfigService.detail(configServiceOne.getId()));
|
|
||||||
|
configVO.setMemberLevel(configServiceOne == null ? null : levelConfigService.detail(configServiceOne.getId()));
|
||||||
}else {
|
}else {
|
||||||
configVO.setMemberLevel(levelConfigService.detail(shopUserInfo.getMemberLevelId()));
|
configVO.setMemberLevel(levelConfigService.detail(shopUserInfo.getMemberLevelId()));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user