...
|
...
|
@@ -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,6 +335,87 @@ public class BuyerOrderCancelService { |
|
|
this.transferCase = transferCase;
|
|
|
}
|
|
|
|
|
|
private PayRefundBo refundSellerEarnestMoney(SellerOrder sellerOrder){
|
|
|
PayRefundBo prb = null;
|
|
|
int sellerUid = sellerOrder.getUid();
|
|
|
long sellerOrderCode = sellerOrder.getOrderCode();
|
|
|
BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
|
|
|
PaymentRequest refundReqOfSeller = PaymentRequest.builder().uid(sellerUid).refundCase(RefundCase.SELLER_EARNEST_MONEY)
|
|
|
.orderCode(sellerOrderCode).refundAmount(earnestMoney.doubleValue())
|
|
|
.build();
|
|
|
boolean sellerIsSuper = sellerService.isSuperEntrySeller(sellerUid);
|
|
|
refundReqOfSeller.setSuper(sellerIsSuper);
|
|
|
if (!sellerIsSuper && PaymentHelper.isWallet(sellerOrder.getPayment())){
|
|
|
|
|
|
MerchantOrderAttachInfo moai = MerchantOrderAttachInfo.builder().uid(sellerUid)
|
|
|
.orderCode(sellerOrderCode).skup(skup).earnestMoney(sellerOrder.getEarnestMoney())
|
|
|
.type(swdType.getValue()).build();
|
|
|
refundReqOfSeller.setRefundattch(moai);
|
|
|
}
|
|
|
|
|
|
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
|
|
|
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(sellerOrder.getOrderCode())
|
|
|
.payType(sellerOrder.getPayment()).refundCase(RefundCase.SELLER_EARNEST_MONEY)
|
|
|
.skup(skup);
|
|
|
logger.info("in BuyerCancelAfterProcessTask call begin payRefundService.refund seller, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, refundReqOfSeller );
|
|
|
try {
|
|
|
prb = payRefundService.refund(refundReqOfSeller, bleb);
|
|
|
}catch (Exception ex){
|
|
|
if (!sellerIsSuper) {
|
|
|
BillLogEvent sellerBillLogEvent = bleb.tradeStatus(BillTradeStatus.FAIL.getCode())
|
|
|
.build();
|
|
|
EventBusPublisher.publishEvent(sellerBillLogEvent);
|
|
|
}
|
|
|
String content = "用户" + sellerUid + "退保证金订单"+ orderCode +"失败";
|
|
|
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("buyerPaidOrder.selfCancel", "cancel", content);
|
|
|
EventBusPublisher.publishEvent(smsAlarmEvent);
|
|
|
}
|
|
|
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)
|
|
|
.transeferCellNode(transeferCellNode).build();
|
|
|
logger.info("in BuyerCancelAfterProcessTask call begin paymentService.transferMon, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, tmReq );
|
|
|
transferService.transfer(tmReq);
|
|
|
logger.info("in BuyerCancelAfterProcessTask call after paymentService.transferMon, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, tmReq );
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
BillLogEvent.BillLogEventBuilder blebOfBuyer = BillLogEvent.builder()
|
|
|
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
|
|
|
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
|
|
|
.amount(leftBuyerMoney)
|
|
|
.skup(skup);
|
|
|
logger.info("in BuyerCancelAfterProcessTask call begin payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, rprOfBuyer );
|
|
|
try {
|
|
|
payRefundService.refund(rprOfBuyer, blebOfBuyer);
|
|
|
}catch (Exception ex){
|
|
|
BillLogEvent buyerBillLogEvent = blebOfBuyer.tradeStatus(BillTradeStatus.FAIL.getCode()).build();
|
|
|
EventBusPublisher.publishEvent(buyerBillLogEvent);
|
|
|
String content = "用户" + buyerUid + "订单"+ orderCode +"退货款失败";
|
|
|
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("buyerPaidOrder.selfCancel", "cancel", content);
|
|
|
EventBusPublisher.publishEvent(smsAlarmEvent);
|
|
|
}
|
|
|
logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, rprOfBuyer );
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PayRefundBo call() throws Exception {
|
|
|
// 整个过程异步去执行(考虑退费依赖订单状态)
|
...
|
...
|
@@ -342,80 +427,21 @@ public class BuyerOrderCancelService { |
|
|
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();
|
|
|
PaymentRequest refundReqOfSeller = PaymentRequest.builder().uid(sellerUid).refundCase(RefundCase.SELLER_EARNEST_MONEY)
|
|
|
.orderCode(sellerOrderCode).refundAmount(earnestMoney.doubleValue())
|
|
|
.build();
|
|
|
boolean sellerIsSuper = sellerService.isSuperEntrySeller(sellerUid);
|
|
|
refundReqOfSeller.setSuper(sellerIsSuper);
|
|
|
if (!sellerIsSuper && PaymentHelper.isWallet(sellerOrder.getPayment())){
|
|
|
|
|
|
MerchantOrderAttachInfo moai = MerchantOrderAttachInfo.builder().uid(sellerUid)
|
|
|
.orderCode(sellerOrderCode).skup(skup).earnestMoney(sellerOrder.getEarnestMoney())
|
|
|
.type(swdType.getValue()).build();
|
|
|
refundReqOfSeller.setRefundattch(moai);
|
|
|
}
|
|
|
prb = refundSellerEarnestMoney(sellerOrder);
|
|
|
|
|
|
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
|
|
|
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(sellerOrder.getOrderCode())
|
|
|
.payType(sellerOrder.getPayment()).refundCase(RefundCase.SELLER_EARNEST_MONEY)
|
|
|
.skup(skup);
|
|
|
logger.info("in BuyerCancelAfterProcessTask call begin payRefundService.refund seller, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, refundReqOfSeller );
|
|
|
try {
|
|
|
prb = payRefundService.refund(refundReqOfSeller, bleb);
|
|
|
}catch (Exception ex){
|
|
|
if (!sellerIsSuper) {
|
|
|
BillLogEvent sellerBillLogEvent = bleb.tradeStatus(BillTradeStatus.FAIL.getCode())
|
|
|
.build();
|
|
|
EventBusPublisher.publishEvent(sellerBillLogEvent);
|
|
|
}
|
|
|
String content = "用户" + sellerUid + "退保证金订单"+ orderCode +"失败";
|
|
|
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("buyerPaidOrder.selfCancel", "cancel", content);
|
|
|
EventBusPublisher.publishEvent(smsAlarmEvent);
|
|
|
}
|
|
|
logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund seller, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, refundReqOfSeller );
|
|
|
//(转账)瓜分指定赔偿款给卖家和平台
|
|
|
|
|
|
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
|
|
|
.type(transferCase.getCode()).transferCase(transferCase).build();
|
|
|
logger.info("in BuyerCancelAfterProcessTask call begin paymentService.transferMon, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, tmReq );
|
|
|
paymentService.transferMon(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);
|
|
|
PaymentRequest rprOfBuyer = PaymentRequest.builder().uid(buyerUid)
|
|
|
.orderCode(orderCode).refundAmount(leftBuyerMoney.doubleValue())
|
|
|
.build();
|
|
|
BillLogEvent.BillLogEventBuilder blebOfBuyer = BillLogEvent.builder()
|
|
|
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
|
|
|
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
|
|
|
.amount(leftBuyerMoney)
|
|
|
.skup(skup);
|
|
|
logger.info("in BuyerCancelAfterProcessTask call begin payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, rprOfBuyer );
|
|
|
try {
|
|
|
payRefundService.refund(rprOfBuyer, blebOfBuyer);
|
|
|
}catch (Exception ex){
|
|
|
BillLogEvent buyerBillLogEvent = blebOfBuyer.tradeStatus(BillTradeStatus.FAIL.getCode()).build();
|
|
|
EventBusPublisher.publishEvent(buyerBillLogEvent);
|
|
|
String content = "用户" + buyerUid + "订单"+ orderCode +"退货款失败";
|
|
|
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("buyerPaidOrder.selfCancel", "cancel", content);
|
|
|
EventBusPublisher.publishEvent(smsAlarmEvent);
|
|
|
}
|
|
|
logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, rprOfBuyer );
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|