feat(mall): 添加商品佣金设置并调整相关功能
- 在商品添加和编辑页面添加佣金设置字段
- 实现佣金相关校验逻辑,包括非空校验和与成本价的比较
- 更新订单相关功能,支持佣金计算
- 调整团长返佣计算逻辑,基于商品佣金而非订单金额
| | |
| | | private BigDecimal amount; |
| | | |
| | | private BigDecimal costPrice; |
| | | //一级佣金 |
| | | private BigDecimal levelOnePrice; |
| | | |
| | | private Integer isNormal; |
| | | |
| | |
| | | if (StrUtil.isEmpty(presentPrice)) { |
| | | return new FebsResponse().fail().message("商品规格现价不能为空"); |
| | | } |
| | | // if (StrUtil.isEmpty(addSku.getLevelOnePrice()) |
| | | // || StrUtil.isEmpty(addSku.getLevelTwoPrice()) |
| | | // || StrUtil.isEmpty(addSku.getLevelThreePrice())) { |
| | | // return new FebsResponse().fail().message("商品规格级别价格不能为空"); |
| | | // } |
| | | if (StrUtil.isEmpty(addSku.getLevelOnePrice())) { |
| | | return new FebsResponse().fail().message("佣金不能为空"); |
| | | } |
| | | |
| | | BigDecimal costPrice = addSku.getCostPrice(); |
| | | BigDecimal levelOnePrice = new BigDecimal(addSku.getLevelOnePrice()); |
| | | if (levelOnePrice.compareTo(costPrice) >= 0) { |
| | | return new FebsResponse().fail().message("佣金要小于成本价"); |
| | | } |
| | | BigDecimal goodsWeight = addSku.getGoodsWeight(); |
| | | if(BigDecimal.ZERO.compareTo(goodsWeight) > 0){ |
| | | return new FebsResponse().fail().message("重量不能小于零"); |
| | |
| | | sku.setCostPrice(mallGoods.getCostPrice()); |
| | | sku.setPresentPrice(new BigDecimal(mallGoods.getPresentPrice())); |
| | | sku.setOriginalPrice(new BigDecimal(mallGoods.getOriginalPrice())); |
| | | // sku.setLevelOnePrice(mallGoods.getLevelOnePrice()); |
| | | sku.setLevelOnePrice(mallGoods.getLevelOnePrice()); |
| | | // sku.setLevelTwoPrice(mallGoods.getLevelTwoPrice()); |
| | | // sku.setLevelThreePrice(mallGoods.getLevelThreePrice()); |
| | | sku.setSkuVolume(mallGoods.getVolume()); |
| | |
| | | mallGoodsSku.setOriginalPrice(new BigDecimal(addMallGoodsSkuDto.getOriginalPrice())); |
| | | mallGoodsSku.setPresentPrice(new BigDecimal(addMallGoodsSkuDto.getPresentPrice())); |
| | | // mallGoodsSku.setPresentPrice(new BigDecimal(addMallGoodsSkuDto.getOriginalPrice())); |
| | | // mallGoodsSku.setLevelOnePrice(new BigDecimal(addMallGoodsSkuDto.getLevelOnePrice())); |
| | | mallGoodsSku.setLevelOnePrice(new BigDecimal(addMallGoodsSkuDto.getLevelOnePrice())); |
| | | // mallGoodsSku.setLevelTwoPrice(new BigDecimal(addMallGoodsSkuDto.getLevelTwoPrice())); |
| | | // mallGoodsSku.setLevelThreePrice(new BigDecimal(addMallGoodsSkuDto.getLevelThreePrice())); |
| | | mallGoodsSku.setStyleId(mallGoodsStyleSku.getId()); |
| | |
| | | if (presentPrice.compareTo(BigDecimal.ZERO) < 0) { |
| | | return new FebsResponse().fail().message("商品规格现价不能小于0"); |
| | | } |
| | | if (ObjectUtil.isEmpty(addSku.getLevelOnePrice())) { |
| | | return new FebsResponse().fail().message("佣金不能为空"); |
| | | } |
| | | |
| | | BigDecimal costPrice = addSku.getCostPrice(); |
| | | BigDecimal levelOnePrice = addSku.getLevelOnePrice(); |
| | | if (levelOnePrice.compareTo(costPrice) >= 0) { |
| | | return new FebsResponse().fail().message("佣金要小于成本价"); |
| | | } |
| | | BigDecimal goodsWeight = addSku.getGoodsWeight(); |
| | | if(BigDecimal.ZERO.compareTo(goodsWeight) > 0){ |
| | | return new FebsResponse().fail().message("重量不能小于零"); |
| | |
| | | |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId()); |
| | | // todo 纯积分商品一个账号限制购买一次 |
| | | // if (new BigDecimal(mallGoods.getPresentPrice()).compareTo(BigDecimal.ZERO) == 0) { |
| | | // List<MallOrderItem> items = mallOrderItemMapper.selectItemByGoodsIdUnCancel(mallGoods.getId(), member.getId()); |
| | | // if (CollUtil.isNotEmpty(items)) { |
| | | // throw new FebsException("积分商品一个账号只能购买一次"); |
| | | // } |
| | | // } |
| | | if (new BigDecimal(mallGoods.getPresentPrice()).compareTo(BigDecimal.ZERO) == 0) { |
| | | Integer cnt = item.getCnt(); |
| | | if(1 < cnt){ |
| | | throw new FebsException("积分商品限购一件"); |
| | | } |
| | | List<MallOrderItem> items = mallOrderItemMapper.selectItemByGoodsIdUnCancel(mallGoods.getId(), member.getId()); |
| | | if (CollUtil.isNotEmpty(items)) { |
| | | throw new FebsException("积分商品一个账号限购一次"); |
| | | } |
| | | } |
| | | |
| | | if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) { |
| | | throw new FebsException(mallGoods.getGoodsName() + "已下架"); |
| | |
| | | } |
| | | |
| | | BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt())); |
| | | BigDecimal levelOnePrice = sku.getLevelOnePrice().multiply(BigDecimal.valueOf(item.getCnt())); |
| | | //是否使用优惠卷 |
| | | if(ObjectUtil.isNotEmpty(addOrderDto.getMemberCouponId())){ |
| | | Long memberCouponId = addOrderDto.getMemberCouponId(); |
| | |
| | | } |
| | | } |
| | | orderItem.setAmount(amount); |
| | | orderItem.setLevelOnePrice(levelOnePrice); |
| | | orderItem.setScoreAmount(scoreAmountMap.get(item.getSkuId())); |
| | | orderItem.setCnt(item.getCnt()); |
| | | orderItem.setOrderId(orderInfo.getId()); |
| | |
| | | public class VipCommonServiceImpl implements IVipCommonService { |
| | | |
| | | private final MallOrderInfoMapper mallOrderInfoMapper; |
| | | private final MallOrderItemMapper mallOrderItemMapper; |
| | | private final IMallVipConfigService mallVipConfigService; |
| | | private final IMallMoneyFlowService mallMoneyFlowService; |
| | | private final IApiMallMemberWalletService mallMemberWalletService; |
| | |
| | | return; |
| | | } |
| | | // 计算返佣金额 |
| | | List<MallOrderItem> mallOrderItems = mallOrderItemMapper.selectList( |
| | | new LambdaQueryWrapper<MallOrderItem>() |
| | | .eq(MallOrderItem::getOrderId, orderId) |
| | | .eq(MallOrderItem::getState, 1) |
| | | ); |
| | | if(CollUtil.isEmpty(mallOrderItems)){ |
| | | return; |
| | | } |
| | | BigDecimal amount = mallOrderItems.stream().map(MallOrderItem::getLevelOnePrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal returnPercent = happySaleLevel.getReturnPercent(); |
| | | BigDecimal multiply = mallOrderInfo.getAmount().multiply(returnPercent).setScale(2, RoundingMode.HALF_DOWN); |
| | | BigDecimal multiply = amount.multiply(returnPercent).setScale(2, RoundingMode.HALF_DOWN); |
| | | log.info("团长获得返佣:{}",multiply); |
| | | // 如果返佣金额小于等于0,则直接返回 |
| | | if(BigDecimal.ZERO.compareTo(multiply) >=0){ |
| | | return; |
| | | } |
| | | // 如果返佣金额大于等于订单金额,则直接返回 |
| | | if(multiply.compareTo(mallOrderInfo.getAmount()) >= 0){ |
| | | if(multiply.compareTo(amount) > 0){ |
| | | return; |
| | | } |
| | | // 记录团长获得返佣 |
| | |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <!-- <blockquote class="layui-elem-quote blue-border">代理价格</blockquote>--> |
| | | <!-- <div class="layui-row layui-col-space10 layui-form-item">--> |
| | | <!-- <div class="layui-col-lg6">--> |
| | | <!-- <label class="layui-form-label febs-form-item-require">一级价格:</label>--> |
| | | <!-- <div class="layui-input-block">--> |
| | | <!-- <input type="text" name="levelOnePrice" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">--> |
| | | <!-- </div>--> |
| | | <!-- </div>--> |
| | | <!-- <div class="layui-col-lg6">--> |
| | | <!-- <label class="layui-form-label febs-form-item-require">二级价格:</label>--> |
| | | <!-- <div class="layui-input-block">--> |
| | | <!-- <input type="text" name="levelTwoPrice" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">--> |
| | | <!-- </div>--> |
| | | <!-- </div>--> |
| | | <!-- </div>--> |
| | | <!-- <div class="layui-row layui-col-space10 layui-form-item">--> |
| | | <!-- <div class="layui-col-lg6">--> |
| | | <!-- <label class="layui-form-label febs-form-item-require">三级价格:</label>--> |
| | | <!-- <div class="layui-input-block">--> |
| | | <!-- <input type="text" name="levelThreePrice" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">--> |
| | | <!-- </div>--> |
| | | <!-- </div>--> |
| | | <!-- </div>--> |
| | | |
| | | <div class="layui-form-item"> |
| | | <div class="layui-col-lg6"> |
| | |
| | | <div class="layui-form-mid layui-word-aux">全部使用积分设置成:大于等于100%</div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | |
| | | <blockquote class="layui-elem-quote blue-border">佣金设置</blockquote> |
| | | <div class="layui-row layui-col-space10 layui-form-item"> |
| | | <div class="layui-col-lg6"> |
| | | <label class="layui-form-label febs-form-item-require">佣金:</label> |
| | | <div class="layui-input-block"> |
| | | <input type="text" name="levelOnePrice" lay-verify="required" placeholder="" autocomplete="off" class="layui-input"> |
| | | <div class="layui-form-mid layui-word-aux">佣金要小于成本价,实际佣金等于每个分销级别的比例乘以佣金。</div> |
| | | <div class="layui-form-mid layui-word-aux">没有佣金设置成:0</div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <blockquote class="layui-elem-quote blue-border">运费设置</blockquote> |
| | | <div class="layui-form-item"> |
| | |
| | | ,{field: 'skuName', title: '规格', edit:'text', width:200} |
| | | // ,{field: 'sample', title:'样品', width:100} |
| | | ,{field: 'goodsWeight', title: '重量', edit:'text', width:100} |
| | | // ,{field: 'levelOnePrice', title: '一级价格', edit:'text', width:100} |
| | | ,{field: 'levelOnePrice', title: '佣金', edit:'text', width:100} |
| | | // ,{field: 'levelTwoPrice', title: '二级价格', edit:'text', width:100} |
| | | // ,{field: 'levelThreePrice', title: '三级价格', edit:'text', width:100} |
| | | ,{field: 'originalPrice', title: '原价', edit:'text', width:100} |
| | |
| | | <!-- </div>--> |
| | | <!-- </div>--> |
| | | <!-- </div>--> |
| | | |
| | | <blockquote class="layui-elem-quote blue-border">佣金设置</blockquote> |
| | | <div class="layui-row layui-col-space10 layui-form-item"> |
| | | <div class="layui-col-lg6"> |
| | | <label class="layui-form-label febs-form-item-require">佣金:</label> |
| | | <div class="layui-input-block"> |
| | | <input type="text" name="levelOnePrice" lay-verify="required" placeholder="" autocomplete="off" class="layui-input"> |
| | | <div class="layui-form-mid layui-word-aux">佣金要小于成本价,实际佣金等于每个分销级别的比例乘以佣金。</div> |
| | | <div class="layui-form-mid layui-word-aux">没有佣金设置成:0</div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <blockquote class="layui-elem-quote blue-border">运费设置</blockquote> |
| | | <div class="layui-form-item"> |
| | | <label class="layui-form-label">运费:</label> |
| | |
| | | ,{field: 'goodsWeight', title: '重量', edit:'text', width:100} |
| | | ,{field: 'originalPrice', title: '原价', edit:'text', width:100} |
| | | ,{field: 'presentPrice', title: '现价', edit:'text', width:100} |
| | | // ,{field: 'levelOnePrice', title: '一级价格', edit:'text', width:100} |
| | | ,{field: 'levelOnePrice', title: '佣金', edit:'text', width:100} |
| | | // ,{field: 'levelTwoPrice', title: '二级价格', edit:'text', width:100} |
| | | // ,{field: 'levelThreePrice', title: '三级价格', edit:'text', width:100} |
| | | ,{field: 'costPrice', title: '成本价', edit:'text', width:100} |