优化结算单退款计算逻辑
This commit is contained in:
parent
178544fe2d
commit
1302ca6de4
@ -5,6 +5,7 @@ import cn.lili.common.utils.CurrencyUtil;
|
|||||||
import cn.lili.common.utils.SnowFlake;
|
import cn.lili.common.utils.SnowFlake;
|
||||||
import cn.lili.common.vo.PageVO;
|
import cn.lili.common.vo.PageVO;
|
||||||
import cn.lili.modules.order.aftersale.entity.dos.AfterSale;
|
import cn.lili.modules.order.aftersale.entity.dos.AfterSale;
|
||||||
|
import cn.lili.modules.order.aftersale.service.AfterSaleService;
|
||||||
import cn.lili.modules.order.order.entity.dos.Order;
|
import cn.lili.modules.order.order.entity.dos.Order;
|
||||||
import cn.lili.modules.order.order.entity.dos.OrderItem;
|
import cn.lili.modules.order.order.entity.dos.OrderItem;
|
||||||
import cn.lili.modules.order.order.entity.dos.StoreFlow;
|
import cn.lili.modules.order.order.entity.dos.StoreFlow;
|
||||||
@ -61,6 +62,8 @@ public class StoreFlowServiceImpl extends ServiceImpl<StoreFlowMapper, StoreFlow
|
|||||||
@Autowired
|
@Autowired
|
||||||
private BillService billService;
|
private BillService billService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AfterSaleService afterSaleService;
|
||||||
/**
|
/**
|
||||||
* 店铺订单支付流水
|
* 店铺订单支付流水
|
||||||
*
|
*
|
||||||
@ -119,15 +122,27 @@ public class StoreFlowServiceImpl extends ServiceImpl<StoreFlowMapper, StoreFlow
|
|||||||
//分销佣金 =(分销佣金/订单商品数量)* 售后商品数量
|
//分销佣金 =(分销佣金/订单商品数量)* 售后商品数量
|
||||||
storeFlow.setDistributionRebate(CurrencyUtil.mul(CurrencyUtil.div(payStoreFlow.getDistributionRebate(), payStoreFlow.getNum()), afterSale.getNum()));
|
storeFlow.setDistributionRebate(CurrencyUtil.mul(CurrencyUtil.div(payStoreFlow.getDistributionRebate(), payStoreFlow.getNum()), afterSale.getNum()));
|
||||||
//流水金额 = 支付最终结算金额
|
//流水金额 = 支付最终结算金额
|
||||||
storeFlow.setFinalPrice(payStoreFlow.getBillPrice());
|
storeFlow.setFinalPrice(afterSale.getActualRefundPrice());
|
||||||
//最终结算金额 =实际退款金额
|
|
||||||
storeFlow.setBillPrice(afterSale.getActualRefundPrice());
|
|
||||||
//站点优惠券补贴返还金额=(站点优惠券补贴金额/购买商品数量)*退款商品数量
|
//站点优惠券补贴返还金额=(站点优惠券补贴金额/购买商品数量)*退款商品数量
|
||||||
storeFlow.setSiteCouponCommission(CurrencyUtil.mul(CurrencyUtil.div(payStoreFlow.getSiteCouponCommission(), payStoreFlow.getNum()), afterSale.getNum()));
|
storeFlow.setSiteCouponCommission(CurrencyUtil.mul(CurrencyUtil.div(payStoreFlow.getSiteCouponCommission() == null ? 0 : payStoreFlow.getSiteCouponCommission(), payStoreFlow.getNum()), afterSale.getNum()));
|
||||||
//平台优惠券 使用金额
|
//平台优惠券 使用金额
|
||||||
storeFlow.setSiteCouponPrice(payStoreFlow.getSiteCouponPrice());
|
storeFlow.setSiteCouponPrice(payStoreFlow.getSiteCouponPrice());
|
||||||
//站点优惠券佣金比例
|
//站点优惠券佣金比例
|
||||||
storeFlow.setSiteCouponPoint(payStoreFlow.getSiteCouponPoint());
|
storeFlow.setSiteCouponPoint(payStoreFlow.getSiteCouponPoint());
|
||||||
|
|
||||||
|
// 退单结算金额 相当于付款结算金额反计算逻辑,对平台收取的佣金,分销收取的佣金进行返还,对平台优惠券的补贴应该相加
|
||||||
|
// 由于退单的结算金额为正数,所以需要将结算金额计算方式,相较于付款结算金额计算方式进行反转
|
||||||
|
|
||||||
|
// 退款结算金额 = flowPrice(实际退款金额) + storeCouponCommission(getSiteCouponCommission) - platFormCommission(平台收取交易佣金) - distributionCommission(单品分销返现支出) ")
|
||||||
|
|
||||||
|
storeFlow.setBillPrice(
|
||||||
|
CurrencyUtil.add(
|
||||||
|
afterSale.getActualRefundPrice(),
|
||||||
|
storeFlow.getSiteCouponCommission(),
|
||||||
|
-storeFlow.getCommissionPrice(),
|
||||||
|
-storeFlow.getDistributionRebate()
|
||||||
|
)
|
||||||
|
);
|
||||||
//退款日志
|
//退款日志
|
||||||
RefundLog refundLog = refundLogService.queryByAfterSaleSn(afterSale.getSn());
|
RefundLog refundLog = refundLogService.queryByAfterSaleSn(afterSale.getSn());
|
||||||
//第三方流水单号
|
//第三方流水单号
|
||||||
@ -137,6 +152,8 @@ public class StoreFlowServiceImpl extends ServiceImpl<StoreFlowMapper, StoreFlow
|
|||||||
this.save(storeFlow);
|
this.save(storeFlow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<StoreFlow> getStoreFlow(StoreFlowQueryDTO storeFlowQueryDTO) {
|
public IPage<StoreFlow> getStoreFlow(StoreFlowQueryDTO storeFlowQueryDTO) {
|
||||||
|
|
||||||
|
@ -57,6 +57,6 @@ public interface BillMapper extends BaseMapper<Bill> {
|
|||||||
",IFNULL(SUM( site_coupon_commission ),0) AS siteCouponRefundCommission" +
|
",IFNULL(SUM( site_coupon_commission ),0) AS siteCouponRefundCommission" +
|
||||||
",IFNULL(SUM( kanjia_settlement_price ),0) AS kanjiaRefundSettlementPrice" +
|
",IFNULL(SUM( kanjia_settlement_price ),0) AS kanjiaRefundSettlementPrice" +
|
||||||
",IFNULL(SUM( point_settlement_price ),0) AS pointRefundSettlementPrice" +
|
",IFNULL(SUM( point_settlement_price ),0) AS pointRefundSettlementPrice" +
|
||||||
",IFNULL(SUM( final_price ),0) AS billPrice FROM li_store_flow ${ew.customSqlSegment}")
|
",IFNULL(SUM( bill_price ),0) AS billPrice FROM li_store_flow ${ew.customSqlSegment}")
|
||||||
Bill getRefundBill(@Param(Constants.WRAPPER) QueryWrapper<Bill> queryWrapper);
|
Bill getRefundBill(@Param(Constants.WRAPPER) QueryWrapper<Bill> queryWrapper);
|
||||||
}
|
}
|
@ -95,7 +95,6 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
|
|||||||
//退款结算信息
|
//退款结算信息
|
||||||
Bill refundBill = this.baseMapper.getRefundBill(new QueryWrapper<Bill>().eq("store_id", storeId).eq("flow_type", FlowTypeEnum.REFUND.name()).between("create_time", startTime, endTime));
|
Bill refundBill = this.baseMapper.getRefundBill(new QueryWrapper<Bill>().eq("store_id", storeId).eq("flow_type", FlowTypeEnum.REFUND.name()).between("create_time", startTime, endTime));
|
||||||
//店铺退款金额
|
//店铺退款金额
|
||||||
Double refundPrice = 0D;
|
|
||||||
if (refundBill != null) {
|
if (refundBill != null) {
|
||||||
//退单金额
|
//退单金额
|
||||||
bill.setRefundPrice(refundBill.getRefundPrice() != null ? refundBill.getRefundPrice() : 0D);
|
bill.setRefundPrice(refundBill.getRefundPrice() != null ? refundBill.getRefundPrice() : 0D);
|
||||||
@ -109,8 +108,7 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
|
|||||||
bill.setPointRefundSettlementPrice(refundBill.getPointRefundSettlementPrice() != null ? refundBill.getPointRefundSettlementPrice() : 0D);
|
bill.setPointRefundSettlementPrice(refundBill.getPointRefundSettlementPrice() != null ? refundBill.getPointRefundSettlementPrice() : 0D);
|
||||||
//退单 砍价补贴返还
|
//退单 砍价补贴返还
|
||||||
bill.setKanjiaRefundSettlementPrice(refundBill.getKanjiaRefundSettlementPrice() != null ? refundBill.getKanjiaRefundSettlementPrice() : 0D);
|
bill.setKanjiaRefundSettlementPrice(refundBill.getKanjiaRefundSettlementPrice() != null ? refundBill.getKanjiaRefundSettlementPrice() : 0D);
|
||||||
//退款金额=店铺最终退款结算金额
|
|
||||||
refundPrice = refundBill.getBillPrice() != null ? refundBill.getBillPrice() : 0D;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -119,7 +117,6 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
|
|||||||
*/
|
*/
|
||||||
Bill orderBill = this.baseMapper.getOrderBill(new QueryWrapper<Bill>().eq("store_id", storeId).eq("flow_type", FlowTypeEnum.PAY.name()).between("create_time", startTime, endTime));
|
Bill orderBill = this.baseMapper.getOrderBill(new QueryWrapper<Bill>().eq("store_id", storeId).eq("flow_type", FlowTypeEnum.PAY.name()).between("create_time", startTime, endTime));
|
||||||
//店铺入款结算金额
|
//店铺入款结算金额
|
||||||
double orderPrice = 0D;
|
|
||||||
|
|
||||||
if (orderBill != null) {
|
if (orderBill != null) {
|
||||||
//结算周期内订单付款总金额
|
//结算周期内订单付款总金额
|
||||||
@ -135,11 +132,9 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
|
|||||||
//砍价商品结算价格
|
//砍价商品结算价格
|
||||||
bill.setKanjiaSettlementPrice(orderBill.getKanjiaSettlementPrice() != null ? orderBill.getKanjiaSettlementPrice() : 0D);
|
bill.setKanjiaSettlementPrice(orderBill.getKanjiaSettlementPrice() != null ? orderBill.getKanjiaSettlementPrice() : 0D);
|
||||||
|
|
||||||
//入款结算金额= 店铺支付结算金额 + 平台优惠券补贴 + 分销订单退还,返现佣金返还+退单产生退还佣金金额
|
|
||||||
orderPrice = CurrencyUtil.add(orderBill.getBillPrice() == null ? 0 : orderBill.getBillPrice(), bill.getSiteCouponCommission() == null ? 0 : bill.getSiteCouponCommission(), bill.getDistributionRefundCommission() == null ? 0 : bill.getDistributionRefundCommission(), bill.getRefundCommissionPrice() == null ? 0 : bill.getRefundCommissionPrice());
|
|
||||||
}
|
}
|
||||||
//最终结算金额=入款结算金额-退款结算金额-退货平台优惠券补贴返还
|
//最终结算金额=入款结算金额-退款结算金额
|
||||||
Double finalPrice = CurrencyUtil.sub(orderPrice, refundPrice, bill.getSiteCouponRefundCommission() == null ? 0 : bill.getSiteCouponRefundCommission());
|
Double finalPrice = CurrencyUtil.sub(orderBill.getBillPrice(), refundBill.getBillPrice());
|
||||||
//店铺最终结算金额=最终结算金额
|
//店铺最终结算金额=最终结算金额
|
||||||
bill.setBillPrice(finalPrice);
|
bill.setBillPrice(finalPrice);
|
||||||
|
|
||||||
@ -148,6 +143,7 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 立即结算
|
* 立即结算
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user