Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.market.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.market.entity.MkShopConsumeDiscountRecord;
|
||||
|
||||
/**
|
||||
* 新客立减减免记录 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-09-17
|
||||
*/
|
||||
public interface MkShopConsumeDiscountRecordMapper extends BaseMapper<MkShopConsumeDiscountRecord> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import com.czg.constant.TableValueConstant;
|
||||
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.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 org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 新客立减减免记录 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-09-17
|
||||
*/
|
||||
@Service
|
||||
public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl<MkShopConsumeDiscountRecordMapper, MkShopConsumeDiscountRecord> implements MkShopConsumeDiscountRecordService{
|
||||
@Resource
|
||||
private MkConsumeDiscountService consumeDiscountService;
|
||||
@Override
|
||||
public MkShopConsumeDiscountRecord get(Long shopId) {
|
||||
MkConsumeDiscountVO consumeDiscountVO = consumeDiscountService.detail(shopId);
|
||||
if (consumeDiscountVO.getIsEnable() != 1) {
|
||||
throw new ApiNotPrintException("新客立减未开启");
|
||||
}
|
||||
|
||||
MkShopConsumeDiscountRecord shopConsumeDiscountRecord = new MkShopConsumeDiscountRecord();
|
||||
shopConsumeDiscountRecord.setShopId(shopId);
|
||||
|
||||
// 固定金额
|
||||
if (TableValueConstant.ConsumeDiscount.DiscountType.FIXED.getCode().equals(consumeDiscountVO.getDiscountType())) {
|
||||
shopConsumeDiscountRecord.setAmount(consumeDiscountVO.getDiscountAmount());
|
||||
return shopConsumeDiscountRecord;
|
||||
}
|
||||
|
||||
// 随机金额(概率加起来是100)
|
||||
List<MkConsumeDiscountRandom> randomList = consumeDiscountVO.getRandomDiscountList();
|
||||
if (randomList == null || randomList.isEmpty()) {
|
||||
throw new ApiNotPrintException("随机立减配置错误");
|
||||
}
|
||||
|
||||
// 生成 1~100 的随机数
|
||||
int rand = new Random().nextInt(100) + 1;
|
||||
int current = 0;
|
||||
|
||||
for (MkConsumeDiscountRandom item : randomList) {
|
||||
int prob = item.getProbability().intValue();
|
||||
current += prob;
|
||||
if (rand <= current) {
|
||||
shopConsumeDiscountRecord.setAmount(item.getAmount());
|
||||
save(shopConsumeDiscountRecord);
|
||||
return shopConsumeDiscountRecord;
|
||||
}
|
||||
}
|
||||
|
||||
throw new ApiNotPrintException("随机立减计算失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.market.mapper.MkShopConsumeDiscountRecordMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user