会员:会员配置的积分相关字段加上point前缀

This commit is contained in:
owen 2023-10-01 10:41:21 +08:00
parent ab35fcbe9b
commit 2168145c3e
6 changed files with 25 additions and 25 deletions

View File

@ -815,10 +815,10 @@ COMMIT;
DROP TABLE IF EXISTS `member_config`; DROP TABLE IF EXISTS `member_config`;
CREATE TABLE `member_config` ( CREATE TABLE `member_config` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '自增主键', `id` bigint NOT NULL AUTO_INCREMENT COMMENT '自增主键',
`trade_deduct_enable` bit(1) NOT NULL COMMENT '是否开启积分抵扣', `point_trade_deduct_enable` bit(1) NOT NULL COMMENT '是否开启积分抵扣',
`trade_deduct_unit_price` int NOT NULL COMMENT '积分抵扣(单位)', `point_trade_deduct_unit_price` int NOT NULL COMMENT '积分抵扣(单位)',
`trade_deduct_max_price` int NULL DEFAULT NULL COMMENT '积分抵扣最大值', `point_trade_deduct_max_price` int NULL DEFAULT NULL COMMENT '积分抵扣最大值',
`trade_give_point` bigint NULL DEFAULT NULL COMMENT '1 元赠送多少分', `point_trade_give_point` bigint NULL DEFAULT NULL COMMENT '1 元赠送多少分',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
@ -832,7 +832,7 @@ CREATE TABLE `member_config` (
-- Records of member_config -- Records of member_config
-- ---------------------------- -- ----------------------------
BEGIN; BEGIN;
INSERT INTO `member_config` (`id`, `trade_deduct_enable`, `trade_deduct_unit_price`, `trade_deduct_max_price`, `trade_give_point`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (5, b'1', 100, 2, 3, '1', '2023-08-20 09:54:42', '1', '2023-08-20 09:54:42', b'0', 1); INSERT INTO `member_config` (`id`, `point_trade_deduct_enable`, `point_trade_deduct_unit_price`, `point_trade_deduct_max_price`, `point_trade_give_point`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (5, b'1', 100, 2, 3, '1', '2023-08-20 09:54:42', '1', '2023-08-20 09:54:42', b'0', 1);
COMMIT; COMMIT;
-- ---------------------------- -- ----------------------------

View File

@ -34,8 +34,8 @@ public class TradePointGiveCalculator implements TradePriceCalculator {
public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) {
// 1.1 校验积分功能是否开启 // 1.1 校验积分功能是否开启
int givePointPerYuan = Optional.ofNullable(memberConfigApi.getConfig()) int givePointPerYuan = Optional.ofNullable(memberConfigApi.getConfig())
.filter(config -> BooleanUtil.isTrue(config.getTradeDeductEnable())) .filter(config -> BooleanUtil.isTrue(config.getPointTradeDeductEnable()))
.map(MemberConfigRespDTO::getTradeGivePoint) .map(MemberConfigRespDTO::getPointTradeGivePoint)
.orElse(0); .orElse(0);
if (givePointPerYuan <= 0) { if (givePointPerYuan <= 0) {
return; return;

View File

@ -78,18 +78,18 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator {
private boolean isDeductPointEnable(MemberConfigRespDTO config) { private boolean isDeductPointEnable(MemberConfigRespDTO config) {
return config != null && return config != null &&
!BooleanUtil.isTrue(config.getTradeDeductEnable()) && // 积分功能是否启用 !BooleanUtil.isTrue(config.getPointTradeDeductEnable()) && // 积分功能是否启用
config.getTradeDeductUnitPrice() != null && config.getTradeDeductUnitPrice() > 0; // 有没有配置1 积分抵扣多少分 config.getPointTradeDeductUnitPrice() != null && config.getPointTradeDeductUnitPrice() > 0; // 有没有配置1 积分抵扣多少分
} }
private Integer calculatePointPrice(MemberConfigRespDTO config, Integer usePoint, TradePriceCalculateRespBO result) { private Integer calculatePointPrice(MemberConfigRespDTO config, Integer usePoint, TradePriceCalculateRespBO result) {
// 每个订单最多可以使用的积分数量 // 每个订单最多可以使用的积分数量
if (config.getTradeDeductMaxPrice() != null && config.getTradeDeductMaxPrice() > 0) { if (config.getPointTradeDeductMaxPrice() != null && config.getPointTradeDeductMaxPrice() > 0) {
usePoint = Math.min(usePoint, config.getTradeDeductMaxPrice()); usePoint = Math.min(usePoint, config.getPointTradeDeductMaxPrice());
} }
// TODO @疯狂这里应该是抵扣到只剩下 0.01 // TODO @疯狂这里应该是抵扣到只剩下 0.01
// 积分优惠金额 // 积分优惠金额
int pointPrice = usePoint * config.getTradeDeductUnitPrice(); int pointPrice = usePoint * config.getPointTradeDeductUnitPrice();
if (result.getPrice().getPayPrice() <= pointPrice) { if (result.getPrice().getPayPrice() <= pointPrice) {
// 禁止 0 元购 // 禁止 0 元购
throw exception(PRICE_CALCULATE_PAY_PRICE_ILLEGAL); throw exception(PRICE_CALCULATE_PAY_PRICE_ILLEGAL);
@ -99,7 +99,7 @@ public class TradePointUsePriceCalculator implements TradePriceCalculator {
// pointPrice = result.getPrice().getPayPrice(); // pointPrice = result.getPrice().getPayPrice();
// // 反推需要扣除的积分 // // 反推需要扣除的积分
// usePoint = NumberUtil.toBigDecimal(pointPrice) // usePoint = NumberUtil.toBigDecimal(pointPrice)
// .divide(NumberUtil.toBigDecimal(config.getTradeDeductUnitPrice()), 0, RoundingMode.HALF_UP) // .divide(NumberUtil.toBigDecimal(config.getPointTradeDeductUnitPrice()), 0, RoundingMode.HALF_UP)
// .intValue(); // .intValue();
// } // }
// 记录使用的积分 // 记录使用的积分

View File

@ -13,20 +13,20 @@ public class MemberConfigRespDTO {
/** /**
* 积分抵扣开关 * 积分抵扣开关
*/ */
private Boolean tradeDeductEnable; private Boolean pointTradeDeductEnable;
/** /**
* 积分抵扣单位 * 积分抵扣单位
* <p> * <p>
* 1 积分抵扣多少分 * 1 积分抵扣多少分
*/ */
private Integer tradeDeductUnitPrice; private Integer pointTradeDeductUnitPrice;
/** /**
* 积分抵扣最大值 * 积分抵扣最大值
*/ */
private Integer tradeDeductMaxPrice; private Integer pointTradeDeductMaxPrice;
/** /**
* 1 元赠送多少分 * 1 元赠送多少分
*/ */
private Integer tradeGivePoint; private Integer pointTradeGivePoint;
} }

View File

@ -14,18 +14,18 @@ public class MemberConfigBaseVO {
@Schema(description = "积分抵扣开关", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") @Schema(description = "积分抵扣开关", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "积分抵扣开发不能为空") @NotNull(message = "积分抵扣开发不能为空")
private Boolean tradeDeductEnable; private Boolean pointTradeDeductEnable;
@Schema(description = "积分抵扣,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "13506") @Schema(description = "积分抵扣,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "13506")
@NotNull(message = "积分抵扣不能为空") @NotNull(message = "积分抵扣不能为空")
private Integer tradeDeductUnitPrice; private Integer pointTradeDeductUnitPrice;
@Schema(description = "积分抵扣最大值", requiredMode = Schema.RequiredMode.REQUIRED, example = "32428") @Schema(description = "积分抵扣最大值", requiredMode = Schema.RequiredMode.REQUIRED, example = "32428")
@NotNull(message = "积分抵扣最大值不能为空") @NotNull(message = "积分抵扣最大值不能为空")
private Integer tradeDeductMaxPrice; private Integer pointTradeDeductMaxPrice;
@Schema(description = "1 元赠送多少分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") @Schema(description = "1 元赠送多少分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
@NotNull(message = "1 元赠送积分不能为空") @NotNull(message = "1 元赠送积分不能为空")
private Integer tradeGivePoint; private Integer pointTradeGivePoint;
} }

View File

@ -29,20 +29,20 @@ public class MemberConfigDO extends BaseDO {
/** /**
* 积分抵扣开关 * 积分抵扣开关
*/ */
private Boolean tradeDeductEnable; private Boolean pointTradeDeductEnable;
/** /**
* 积分抵扣单位 * 积分抵扣单位
* *
* 1 积分抵扣多少分 * 1 积分抵扣多少分
*/ */
private Integer tradeDeductUnitPrice; private Integer pointTradeDeductUnitPrice;
/** /**
* 积分抵扣最大值 * 积分抵扣最大值
*/ */
private Integer tradeDeductMaxPrice; private Integer pointTradeDeductMaxPrice;
/** /**
* 1 元赠送多少分 * 1 元赠送多少分
*/ */
private Integer tradeGivePoint; private Integer pointTradeGivePoint;
} }