src/main/java/cc/mrbird/febs/mall/dto/CouponRuleAddDto.java
@@ -17,6 +17,7 @@ @NotNull(message = "过期天数不能为空") @Min(value = 0, message = "整数字段不能小于0") private Integer expireDay; private Integer type; //满1000减100,满0减50; //满足金额 @NotNull(message = "满足金额不能为空") src/main/java/cc/mrbird/febs/mall/entity/MallGoodsCoupon.java
@@ -14,6 +14,10 @@ private String name; //过期天数 private Integer expireDay; //类型 1:满100只减10 2:每满100减10 private Integer type; public static final Integer TYPE_ONE = 1; public static final Integer TYPE_TWO = 2; //1:未生效 2:生效中 private Integer state; //满1000减100,满0减50; @@ -21,4 +25,6 @@ private BigDecimal costAmount; //减免金额 private BigDecimal realAmount; } src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
@@ -2,6 +2,7 @@ import cc.mrbird.febs.common.entity.FebsResponse; import cc.mrbird.febs.common.entity.QueryRequest; import cc.mrbird.febs.common.utils.AppContants; import cc.mrbird.febs.mall.conversion.MallGoodsConversion; import cc.mrbird.febs.mall.dto.*; import cc.mrbird.febs.mall.entity.*; @@ -863,6 +864,7 @@ mallGoodsCoupon.setName(name); mallGoodsCoupon.setExpireDay(couponRuleAddDto.getExpireDay()); mallGoodsCoupon.setCostAmount(couponRuleAddDto.getCostAmount()); mallGoodsCoupon.setType(MallGoodsCoupon.TYPE_ONE); mallGoodsCoupon.setRealAmount(couponRuleAddDto.getRealAmount()); mallGoodsCouponMapper.insert(mallGoodsCoupon); src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -201,14 +201,6 @@ //卷是否和商品绑定 Long skuGoodsId = sku.getGoodsId(); Long couponId = mallMemberCoupon.getCouponId(); List<CouponGoods> couponGoods = couponGoodsMapper.selectByGoodIdAndCouponId(skuGoodsId, couponId); if(ObjectUtil.isEmpty(couponGoods)){ throw new FebsException(sku.getGoodsName()+"无法使用"+mallMemberCoupon.getCouponName()); } // Long goodsId = mallMemberCoupon.getGoodsId(); // if(goodsId != sku.getGoodsId()){ // throw new FebsException(sku.getGoodsName()+"无法使用"+mallMemberCoupon.getCouponName()); // } MallGoodsCoupon mallGoodsCoupon = mallGoodsCouponMapper.selectById(mallMemberCoupon.getCouponId()); if(ObjectUtil.isEmpty(mallGoodsCoupon)){ throw new FebsException(mallGoodsCoupon.getName()+"无法使用"); @@ -217,10 +209,26 @@ if(2 != stateCoupon){ throw new FebsException(mallGoodsCoupon.getName()+"无法使用"); } List<CouponGoods> couponGoods = couponGoodsMapper.selectByGoodIdAndCouponId(skuGoodsId, couponId); if(ObjectUtil.isEmpty(couponGoods)){ throw new FebsException(sku.getGoodsName()+"无法使用"+mallMemberCoupon.getCouponName()); } // Long goodsId = mallMemberCoupon.getGoodsId(); // if(goodsId != sku.getGoodsId()){ // throw new FebsException(sku.getGoodsName()+"无法使用"+mallMemberCoupon.getCouponName()); // } BigDecimal costAmount = mallGoodsCoupon.getCostAmount(); BigDecimal realAmount = mallGoodsCoupon.getRealAmount(); if(amount.compareTo(costAmount) >= 0){ amount = (amount.subtract(realAmount).compareTo(BigDecimal.ZERO) > 0 ? amount.subtract(realAmount) : BigDecimal.ZERO); Integer type = mallGoodsCoupon.getType(); if(MallGoodsCoupon.TYPE_TWO == type){ BigDecimal divideTime = amount.divide(costAmount, 0, BigDecimal.ROUND_DOWN);//累计减免次数 BigDecimal multiply = divideTime.multiply(realAmount);//实际减免金额 amount = (amount.subtract(multiply).compareTo(BigDecimal.ZERO) > 0 ? amount.subtract(multiply) : BigDecimal.ZERO); } if(MallGoodsCoupon.TYPE_ONE == type){ amount = (amount.subtract(realAmount).compareTo(BigDecimal.ZERO) > 0 ? amount.subtract(realAmount) : BigDecimal.ZERO); } orderItem.setMemberCouponId(memberCouponId); mallMemberCoupon.setState(2); mallMemberCouponMapper.updateById(mallMemberCoupon); @@ -280,6 +288,12 @@ //过期时间修改成24小时 agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(), 24 * 60 * 60 * 1000L); return orderInfo.getId(); } public static void main(String[] args) { BigDecimal bigDecimal = new BigDecimal(980); BigDecimal divide = bigDecimal.divide(new BigDecimal(100), 0, BigDecimal.ROUND_DOWN); System.out.println(divide); } @@ -922,10 +936,6 @@ } return new FebsResponse().success(); } public static void main(String[] args) { System.out.print(AgentLevelEnum.ZERO_LEVEL.name()); } } src/main/java/cc/mrbird/febs/mall/vo/AdminMallGoodsCouponVo.java
@@ -18,6 +18,7 @@ @NotNull(message = "过期天数不能为空") @Min(value = 0, message = "整数字段不能小于0") private Integer expireDay; private Integer type; //满1000减100,满0减50; //满足金额 @NotNull(message = "满足金额不能为空") src/main/resources/templates/febs/views/modules/goods/goodsCouponAdd.html
@@ -34,6 +34,13 @@ <blockquote class="layui-elem-quote blue-border">规则</blockquote> <div class="layui-form-item"> <label class="layui-form-label">满减规则:</label> <div class="layui-input-block"> <input type="radio" name="type" value="1" title="满减卷。满100只减10" checked/> <input type="radio" name="type" value="2" title="累计满减卷。每满100减10" /> </div> </div> <div class="layui-form-item"> <label class="layui-form-label febs-form-item-require">满足:</label> <div class="layui-input-inline" style="width: 80px"> <input type="text" name="costAmount" lay-verify="required" autocomplete="off" class="layui-input" > @@ -131,6 +138,12 @@ form.on('submit(coupon-rule-add-form-submit)', function (data) { let type = data.field.type; let costAmount = data.field.costAmount; if(type == 2 && costAmount <= 0){ febs.alert.warn("累计满减卷,满足金额不能为0"); return false; } let couponRuleList = couponRule.getValue(); if (couponRuleList.length > 0) { var couponIds = []; src/main/resources/templates/febs/views/modules/goods/goodsCouponUpdate.html
@@ -33,6 +33,13 @@ <blockquote class="layui-elem-quote blue-border">规则</blockquote> <div class="layui-form-item"> <label class="layui-form-label">满减规则:</label> <div class="layui-input-block"> <input type="radio" name="type" value="1" title="满减卷。满100只减10" checked/> <input type="radio" name="type" value="2" title="累计满减卷。每满100减10" /> </div> </div> <div class="layui-form-item"> <label class="layui-form-label febs-form-item-require">满足:</label> <div class="layui-input-inline" style="width: 80px"> <input type="text" name="costAmount" lay-verify="required" autocomplete="off" class="layui-input" > @@ -135,6 +142,7 @@ form.val("coupon-rule-update-form", { "id": couponRule.id, "name": couponRule.name, "type": couponRule.type, "expireDay": couponRule.expireDay, "costAmount": couponRule.costAmount, "realAmount": couponRule.realAmount @@ -143,6 +151,12 @@ } form.on('submit(coupon-rule-update-form-submit)', function (data) { let type = data.field.type; let costAmount = data.field.costAmount; if(type == 2 && costAmount <= 0){ febs.alert.warn("累计满减卷,满足金额不能为0"); return false; } let couponRuleList = couponRuleGoodsIds.getValue(); if (couponRuleList.length > 0) { var couponIds = [];