...
|
...
|
@@ -69,7 +69,7 @@ public class BuyerOrderCancelService { |
|
|
private CouponProxyService couponProxyService;
|
|
|
|
|
|
@Autowired
|
|
|
private IPaymentService paymentService;
|
|
|
private TransferService transferService;
|
|
|
|
|
|
@Autowired
|
|
|
private SellerOrderMapper sellerOrderMapper;
|
...
|
...
|
@@ -100,6 +100,7 @@ public class BuyerOrderCancelService { |
|
|
*/
|
|
|
public BuyerPenaltyCalResult calBuyerPenalty(Integer buyerUid, Long orderCode, OrderStatus orderStatus,
|
|
|
BigDecimal orderActualAmount,
|
|
|
BigDecimal shipFee,
|
|
|
OrderAttributes orderAttributes
|
|
|
){
|
|
|
if (Objects.isNull(orderAttributes)){
|
...
|
...
|
@@ -144,7 +145,7 @@ public class BuyerOrderCancelService { |
|
|
}
|
|
|
}
|
|
|
//TODO quick deliver
|
|
|
BuyerPenaltyCalResult bpcr = calBuyerPenalty( mfee,buyerUid, orderCode, orderActualAmount);
|
|
|
BuyerPenaltyCalResult bpcr = calBuyerPenalty( mfee,buyerUid, orderCode, orderActualAmount, shipFee);
|
|
|
if (bpcr.getLeftAmount().compareTo(BigDecimal.ZERO)<=0){
|
|
|
throw new UfoServiceException(501, "left amount not enough");
|
|
|
}
|
...
|
...
|
@@ -152,16 +153,19 @@ public class BuyerOrderCancelService { |
|
|
}
|
|
|
|
|
|
public BuyerPenaltyCalResult calBuyerPenalty(BuyerPenalty.Fee mfee,Integer buyerUid, Long orderCode,
|
|
|
BigDecimal orderActualAmount){
|
|
|
BigDecimal orderActualAmount, BigDecimal shipFee){
|
|
|
BigDecimal penaltyRate = mfee.getRate();
|
|
|
BigDecimal penaltyAmount = BigDecimalHelper.halfUp(orderActualAmount.multiply(penaltyRate));
|
|
|
BigDecimal goodsActualAmount = orderActualAmount.subtract(shipFee);
|
|
|
BigDecimal penaltyAmount = BigDecimalHelper.halfUp(goodsActualAmount.multiply(penaltyRate));
|
|
|
BuyerPenalty.Range moneyRange = mfee.getMoneyRange();
|
|
|
if (penaltyAmount.compareTo(moneyRange.getMin()) < 0){
|
|
|
penaltyAmount = moneyRange.getMin();
|
|
|
}
|
|
|
BigDecimal leftAmount = orderActualAmount.subtract(penaltyAmount);
|
|
|
BuyerPenaltyCalResult bpcr = BuyerPenaltyCalResult.builder().uid(buyerUid).orderCode(orderCode)
|
|
|
.orderActualAmount(orderActualAmount).penaltyRate(penaltyRate)
|
|
|
.orderActualAmount(orderActualAmount)
|
|
|
.goodsActualAmount(goodsActualAmount)
|
|
|
.penaltyRate(penaltyRate)
|
|
|
.penaltyAmount(penaltyAmount).leftAmount(leftAmount).build();
|
|
|
logger.info("calBuyerPenalty mfee {} BuyerPenaltyCalResult {}", mfee, bpcr);
|
|
|
return bpcr;
|
...
|
...
|
@@ -331,17 +335,8 @@ public class BuyerOrderCancelService { |
|
|
this.transferCase = transferCase;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PayRefundBo call() throws Exception {
|
|
|
// 整个过程异步去执行(考虑退费依赖订单状态)
|
|
|
//(退费)退保证金给卖家
|
|
|
logger.info("in BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}",
|
|
|
buyerUid, orderCode, skup, transferCase, compensate);
|
|
|
private PayRefundBo refundSellerEarnestMoney(SellerOrder sellerOrder){
|
|
|
PayRefundBo prb = null;
|
|
|
try {
|
|
|
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
|
|
|
logger.info("in BuyerCancelAfterProcessTask call sellerOrderMapper.selectBySkup, buyerUid {}, orderCode {}, skup {}",
|
|
|
buyerUid, orderCode, skup );
|
|
|
int sellerUid = sellerOrder.getUid();
|
|
|
long sellerOrderCode = sellerOrder.getOrderCode();
|
|
|
BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
|
...
|
...
|
@@ -378,22 +373,26 @@ public class BuyerOrderCancelService { |
|
|
}
|
|
|
logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund seller, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, refundReqOfSeller );
|
|
|
//(转账)瓜分指定赔偿款给卖家和平台
|
|
|
return prb;
|
|
|
}
|
|
|
|
|
|
void transferPenalty(BuyerPenaltyCalResult bpcr){
|
|
|
TranseferCellNode transeferCellNode = new TranseferCellNode();
|
|
|
transeferCellNode.setUid(buyerUid);
|
|
|
transeferCellNode.setAmount(bpcr.getPenaltyAmount());
|
|
|
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
|
|
|
.type(transferCase.getCode()).transferCase(transferCase).build();
|
|
|
.type(transferCase.getCode()).transferCase(transferCase)
|
|
|
.transeferCellNode(transeferCellNode).build();
|
|
|
logger.info("in BuyerCancelAfterProcessTask call begin paymentService.transferMon, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, tmReq );
|
|
|
paymentService.transferMon(tmReq);
|
|
|
transferService.transfer(tmReq);
|
|
|
logger.info("in BuyerCancelAfterProcessTask call after paymentService.transferMon, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, tmReq );
|
|
|
}
|
|
|
|
|
|
//(退费)扣除赔偿款,计算剩余的货款,退给买家
|
|
|
BigDecimal compensateMoney = compensate.getBuyerCompensateMoney();
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
|
|
|
logger.info("in BuyerCancelAfterProcessTask call begin buyerOrderMapper.selectByOrderCode, buyerUid {}, orderCode {}, skup {} buyerOrder {}",
|
|
|
buyerUid, orderCode, skup, buyerOrder );
|
|
|
BigDecimal leftBuyerMoney = buyerOrder.getAmount().subtract(compensateMoney);
|
|
|
void refundLeftOrderAmount(BuyerPenaltyCalResult bpcr, BuyerOrder buyerOrder){
|
|
|
Integer sellerUid = buyerOrder.getSellerUid();
|
|
|
BigDecimal leftBuyerMoney = bpcr.getLeftAmount();
|
|
|
PaymentRequest rprOfBuyer = PaymentRequest.builder().uid(buyerUid)
|
|
|
.orderCode(orderCode).refundAmount(leftBuyerMoney.doubleValue())
|
|
|
.build();
|
...
|
...
|
@@ -415,7 +414,34 @@ public class BuyerOrderCancelService { |
|
|
}
|
|
|
logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, rprOfBuyer );
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PayRefundBo call() throws Exception {
|
|
|
// 整个过程异步去执行(考虑退费依赖订单状态)
|
|
|
//(退费)退保证金给卖家
|
|
|
logger.info("in BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}",
|
|
|
buyerUid, orderCode, skup, transferCase, compensate);
|
|
|
PayRefundBo prb = null;
|
|
|
try {
|
|
|
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
|
|
|
logger.info("in BuyerCancelAfterProcessTask call sellerOrderMapper.selectBySkup, buyerUid {}, orderCode {}, skup {}",
|
|
|
buyerUid, orderCode, skup );
|
|
|
prb = refundSellerEarnestMoney(sellerOrder);
|
|
|
|
|
|
//(转账)瓜分指定赔偿款给卖家和平台
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
|
|
|
logger.info("in BuyerCancelAfterProcessTask call begin buyerOrderMapper.selectByOrderCode, buyerUid {}, orderCode {}, skup {} buyerOrder {}",
|
|
|
buyerUid, orderCode, skup, buyerOrder );
|
|
|
OrderStatus orderStatus = OrderStatus.getOrderStatus(buyerOrder.getStatus());
|
|
|
BigDecimal orderActualAmount = buyerOrder.getAmount();
|
|
|
BigDecimal shipFee = buyerOrder.getShipFee();
|
|
|
OrderAttributes orderAttributes = OrderAttributes.getOrderAttributes(buyerOrder.getAttributes());
|
|
|
//TODO try catch to record fail transfer
|
|
|
BuyerPenaltyCalResult bpcr = calBuyerPenalty(buyerUid, orderCode, orderStatus, orderActualAmount, shipFee, orderAttributes);
|
|
|
transferPenalty(bpcr);
|
|
|
//(退费)扣除赔偿款,计算剩余的货款,退给买家
|
|
|
refundLeftOrderAmount(bpcr, buyerOrder);
|
|
|
logger.info("out BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}",
|
|
|
buyerUid, orderCode, skup, transferCase, compensate);
|
|
|
}catch (Exception ex){
|
...
|
...
|
@@ -423,7 +449,6 @@ public class BuyerOrderCancelService { |
|
|
buyerUid, orderCode, skup, transferCase, compensate, ex);
|
|
|
}
|
|
|
return prb;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|