积分模块相关代码
This commit is contained in:
@@ -108,7 +108,7 @@ public class TbPointsExchangeRecordController {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("refund")
|
||||
public Result exchange(@RequestBody TbPointsExchangeRecord record) {
|
||||
public Result refund(@RequestBody TbPointsExchangeRecord record) {
|
||||
tbPointsExchangeRecordService.refund(record);
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
@@ -64,4 +64,9 @@ public class TbMemberPoints {
|
||||
*/
|
||||
@TableField("last_float_points")
|
||||
private Integer lastFloatPoints;
|
||||
/**
|
||||
* 是否会员 1-是 0-否
|
||||
*/
|
||||
@TableField("is_vip")
|
||||
private Integer vip;
|
||||
}
|
||||
@@ -35,6 +35,10 @@ public class TbPointsBasicSetting {
|
||||
* 开启消费赠送积分 1-开启 0-关闭
|
||||
*/
|
||||
private Integer enableRewards;
|
||||
/**
|
||||
* 赠积分适用群体 all-全部 vip-仅会员
|
||||
*/
|
||||
private String rewardsGroup;
|
||||
/**
|
||||
* 每消费xx元赠送1积分
|
||||
*/
|
||||
@@ -44,9 +48,13 @@ public class TbPointsBasicSetting {
|
||||
*/
|
||||
private Integer enableDeduction;
|
||||
/**
|
||||
* 下单积分抵扣门槛
|
||||
* 抵扣适用群体 all-全部 vip-仅会员
|
||||
*/
|
||||
private String deductionGroup;
|
||||
/**
|
||||
* 下单实付抵扣门槛
|
||||
*/
|
||||
private Integer minDeductionPoint;
|
||||
private BigDecimal minPaymentAmount;
|
||||
/**
|
||||
* 下单最高抵扣比例
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,10 @@ public class OrderDeductionPointsDTO {
|
||||
* 根据策略计算出的最多可以抵扣的金额
|
||||
*/
|
||||
private BigDecimal maxDeductionAmount;
|
||||
/**
|
||||
* 下单实付抵扣门槛(实付金额不低于这个值)
|
||||
*/
|
||||
private BigDecimal minPaymentAmount;
|
||||
/**
|
||||
* 下单积分抵扣门槛(每次使用不低于这个值)
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.map.MapProxy;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
@@ -120,9 +121,23 @@ public class TbMemberPointsServiceImpl extends ServiceImpl<TbMemberPointsMapper,
|
||||
dto.setUnusableReason("商家未启用积分抵扣功能");
|
||||
return dto;
|
||||
}
|
||||
dto.setMinDeductionPoints(basic.getMinDeductionPoint());
|
||||
if (accountPoints == 0 || accountPoints < basic.getMinDeductionPoint()) {
|
||||
dto.setUnusableReason("积分不足或小于最低使用门槛" + basic.getMinDeductionPoint());
|
||||
if ("vip".equals(basic.getDeductionGroup()) && ObjectUtil.defaultIfNull(entity.getVip(), 0) != 1) {
|
||||
dto.setUnusableReason("仅VIP用户可用");
|
||||
return dto;
|
||||
}
|
||||
dto.setMinPaymentAmount(basic.getMinPaymentAmount());
|
||||
dto.setOrderAmount(orderAmount);
|
||||
if (NumberUtil.isLess(orderAmount, basic.getMinPaymentAmount())) {
|
||||
dto.setUnusableReason(StrUtil.format("实付金额不足¥{}元,无法进行抵扣", basic.getMinPaymentAmount()));
|
||||
return dto;
|
||||
}
|
||||
dto.setEquivalentPoints(basic.getEquivalentPoints());
|
||||
// 最低抵扣积分 = 1元等值积分 = 1.0元
|
||||
dto.setMinDeductionPoints(basic.getEquivalentPoints());
|
||||
// 计算抵扣门槛=?元
|
||||
dto.setMinDeductionAmount(BigDecimal.ONE);
|
||||
if (accountPoints == 0 || accountPoints < dto.getMinDeductionPoints()) {
|
||||
dto.setUnusableReason("积分不足或小于最低使用门槛" + dto.getMinDeductionPoints());
|
||||
return dto;
|
||||
}
|
||||
// 下单抵扣积分比例 1元=?积分
|
||||
@@ -132,26 +147,17 @@ public class TbMemberPointsServiceImpl extends ServiceImpl<TbMemberPointsMapper,
|
||||
// 下单最高抵扣比例
|
||||
BigDecimal maxDeductionRatio = basic.getMaxDeductionRatio();
|
||||
// 计算订单最多可以抵扣多少元
|
||||
BigDecimal orderYuan = NumberUtil.mul(orderAmount, NumberUtil.div(maxDeductionRatio, new BigDecimal("100")));
|
||||
BigDecimal orderYuan = NumberUtil.roundDown(NumberUtil.mul(orderAmount, NumberUtil.div(maxDeductionRatio, new BigDecimal("100"))), 2);
|
||||
// 积分余额足够
|
||||
if (NumberUtil.isGreaterOrEqual(accountYuan, orderYuan)) {
|
||||
dto.setMaxDeductionAmount(orderYuan);
|
||||
} else {
|
||||
dto.setMaxDeductionAmount(NumberUtil.roundDown(accountYuan, 2));
|
||||
}
|
||||
if (NumberUtil.isLess(dto.getMaxDeductionAmount(), new BigDecimal("0.01"))) {
|
||||
dto.setUnusableReason("积分不足0.01元,无法进行抵扣");
|
||||
if (NumberUtil.isLess(dto.getMaxDeductionAmount(), BigDecimal.ONE)) {
|
||||
dto.setUnusableReason("积分不足1元,无法进行抵扣");
|
||||
return dto;
|
||||
}
|
||||
// 计算抵扣门槛=?元
|
||||
BigDecimal minYuan = NumberUtil.div(basic.getMinDeductionPoint(), equivalentPoints);
|
||||
if (NumberUtil.isLess(minYuan, new BigDecimal("0.01"))) {
|
||||
dto.setMinDeductionAmount(new BigDecimal("0.01"));
|
||||
} else {
|
||||
dto.setMinDeductionAmount(NumberUtil.roundDown(minYuan, 2));
|
||||
}
|
||||
dto.setEquivalentPoints(equivalentPoints);
|
||||
dto.setOrderAmount(orderAmount);
|
||||
dto.setUsable(true);
|
||||
// 计算最多可抵扣的积分
|
||||
BigDecimal mul = NumberUtil.mul(dto.getMaxDeductionAmount(), equivalentPoints);
|
||||
@@ -190,13 +196,12 @@ public class TbMemberPointsServiceImpl extends ServiceImpl<TbMemberPointsMapper,
|
||||
if (points > core.getMaxUsablePoints()) {
|
||||
throw new MsgException(StrUtil.format("使用积分不能超过最大使用限制{}", core.getMaxUsablePoints()));
|
||||
}
|
||||
BigDecimal mul = NumberUtil.mul(new BigDecimal("0.01"), core.getEquivalentPoints());
|
||||
int minPoints = NumberUtil.round(mul, 0, RoundingMode.CEILING).intValue();
|
||||
if (points < minPoints) {
|
||||
throw new MsgException(StrUtil.format("使用积分不能低于{}(0.01元)", minPoints));
|
||||
}
|
||||
BigDecimal money = NumberUtil.mul(points, NumberUtil.div(BigDecimal.ONE, core.getEquivalentPoints()));
|
||||
return NumberUtil.roundDown(money, 2);
|
||||
BigDecimal maxDeductionAmount = NumberUtil.roundDown(money, 2);
|
||||
if (NumberUtil.isGreater(maxDeductionAmount, core.getMaxDeductionAmount())) {
|
||||
return core.getMaxDeductionAmount();
|
||||
}
|
||||
return maxDeductionAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -282,6 +287,17 @@ public class TbMemberPointsServiceImpl extends ServiceImpl<TbMemberPointsMapper,
|
||||
if (enableRewards == 0) {
|
||||
return;
|
||||
}
|
||||
String rewardsGroup = basicSetting.getRewardsGroup();
|
||||
TbMemberPoints entity;
|
||||
try {
|
||||
entity = initMemberPoints(memberId);
|
||||
}catch (Exception e){
|
||||
return;
|
||||
}
|
||||
Integer vip = entity.getVip();
|
||||
if ("vip".equals(rewardsGroup) && ObjectUtil.defaultIfNull(vip, 0) != 1) {
|
||||
return;
|
||||
}
|
||||
BigDecimal consumeAmount = basicSetting.getConsumeAmount();
|
||||
if (consumeAmount == null) {
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.chaozhanggui.system.cashierservice.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbPointsBasicSetting;
|
||||
@@ -11,6 +12,7 @@ import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@@ -32,7 +34,7 @@ public class TbPointsBasicSettingServiceImpl extends ServiceImpl<TbPointsBasicSe
|
||||
Assert.notNull(entity.getEnableRewards(), "{}({})不能为空", "开启消费赠送积分","enableRewards");
|
||||
Assert.notNull(entity.getConsumeAmount(), "{}({})不能为空", "每消费xx元赠送1积分","consumeAmount");
|
||||
Assert.notNull(entity.getEnableDeduction(), "{}({})不能为空", "开启下单积分抵扣","enableDeduction");
|
||||
Assert.notNull(entity.getMinDeductionPoint(), "{}({})不能为空", "下单积分抵扣门槛","minDeductionPoint");
|
||||
Assert.notNull(entity.getMinPaymentAmount(), "{}({})不能为空", "下单实付抵扣门槛","minPaymentAmount");
|
||||
Assert.notNull(entity.getMaxDeductionRatio(), "{}({})不能为空", "下单最高抵扣比例","maxDeductionRatio");
|
||||
Assert.notNull(entity.getEquivalentPoints(), "{}({})不能为空", "下单抵扣积分比例","equivalentPoints");
|
||||
Assert.notNull(entity.getEnablePointsMall(), "{}({})不能为空", "开启积分商城","enablePointsMall");
|
||||
@@ -40,6 +42,15 @@ public class TbPointsBasicSettingServiceImpl extends ServiceImpl<TbPointsBasicSe
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new MsgException(e.getMessage());
|
||||
}
|
||||
if (NumberUtil.isLessOrEqual(entity.getMinPaymentAmount(),BigDecimal.ZERO)) {
|
||||
throw new MsgException("下单实付抵扣门槛不能小于等于0");
|
||||
}
|
||||
if (NumberUtil.isLessOrEqual(entity.getMaxDeductionRatio(), BigDecimal.ZERO)) {
|
||||
throw new MsgException("下单最高抵扣比例不能小于等于0");
|
||||
}
|
||||
if (NumberUtil.isGreater(entity.getMaxDeductionRatio(), new BigDecimal("100"))) {
|
||||
throw new MsgException("下单最高抵扣比例不能大于100");
|
||||
}
|
||||
entity.setCreateTime(new Date());
|
||||
super.remove(Wrappers.<TbPointsBasicSetting>lambdaQuery().eq(TbPointsBasicSetting::getShopId, entity.getShopId()));
|
||||
super.save(entity);
|
||||
|
||||
@@ -474,7 +474,7 @@ public class TbPointsExchangeRecordServiceImpl extends ServiceImpl<TbPointsExcha
|
||||
throw new MsgException(StrUtil.format("发起退款失败:{}", e.getMessage()));
|
||||
}
|
||||
if (publicResp == null) {
|
||||
throw new MsgException("拉起支付失败:无响应");
|
||||
throw new MsgException("发起退款失败:无响应");
|
||||
}
|
||||
if (!"000000".equals(publicResp.getCode())) {
|
||||
throw new MsgException(publicResp.getMsg());
|
||||
|
||||
Reference in New Issue
Block a user