|
@@ -69,7 +69,7 @@ public class BuyerOrderCancelService { |
|
@@ -69,7 +69,7 @@ public class BuyerOrderCancelService { |
69
|
private CouponProxyService couponProxyService;
|
69
|
private CouponProxyService couponProxyService;
|
70
|
|
70
|
|
71
|
@Autowired
|
71
|
@Autowired
|
72
|
- private IPaymentService paymentService;
|
72
|
+ private TransferService transferService;
|
73
|
|
73
|
|
74
|
@Autowired
|
74
|
@Autowired
|
75
|
private SellerOrderMapper sellerOrderMapper;
|
75
|
private SellerOrderMapper sellerOrderMapper;
|
|
@@ -100,6 +100,7 @@ public class BuyerOrderCancelService { |
|
@@ -100,6 +100,7 @@ public class BuyerOrderCancelService { |
100
|
*/
|
100
|
*/
|
101
|
public BuyerPenaltyCalResult calBuyerPenalty(Integer buyerUid, Long orderCode, OrderStatus orderStatus,
|
101
|
public BuyerPenaltyCalResult calBuyerPenalty(Integer buyerUid, Long orderCode, OrderStatus orderStatus,
|
102
|
BigDecimal orderActualAmount,
|
102
|
BigDecimal orderActualAmount,
|
|
|
103
|
+ BigDecimal shipFee,
|
103
|
OrderAttributes orderAttributes
|
104
|
OrderAttributes orderAttributes
|
104
|
){
|
105
|
){
|
105
|
if (Objects.isNull(orderAttributes)){
|
106
|
if (Objects.isNull(orderAttributes)){
|
|
@@ -144,7 +145,7 @@ public class BuyerOrderCancelService { |
|
@@ -144,7 +145,7 @@ public class BuyerOrderCancelService { |
144
|
}
|
145
|
}
|
145
|
}
|
146
|
}
|
146
|
//TODO quick deliver
|
147
|
//TODO quick deliver
|
147
|
- BuyerPenaltyCalResult bpcr = calBuyerPenalty( mfee,buyerUid, orderCode, orderActualAmount);
|
148
|
+ BuyerPenaltyCalResult bpcr = calBuyerPenalty( mfee,buyerUid, orderCode, orderActualAmount, shipFee);
|
148
|
if (bpcr.getLeftAmount().compareTo(BigDecimal.ZERO)<=0){
|
149
|
if (bpcr.getLeftAmount().compareTo(BigDecimal.ZERO)<=0){
|
149
|
throw new UfoServiceException(501, "left amount not enough");
|
150
|
throw new UfoServiceException(501, "left amount not enough");
|
150
|
}
|
151
|
}
|
|
@@ -152,16 +153,19 @@ public class BuyerOrderCancelService { |
|
@@ -152,16 +153,19 @@ public class BuyerOrderCancelService { |
152
|
}
|
153
|
}
|
153
|
|
154
|
|
154
|
public BuyerPenaltyCalResult calBuyerPenalty(BuyerPenalty.Fee mfee,Integer buyerUid, Long orderCode,
|
155
|
public BuyerPenaltyCalResult calBuyerPenalty(BuyerPenalty.Fee mfee,Integer buyerUid, Long orderCode,
|
155
|
- BigDecimal orderActualAmount){
|
156
|
+ BigDecimal orderActualAmount, BigDecimal shipFee){
|
156
|
BigDecimal penaltyRate = mfee.getRate();
|
157
|
BigDecimal penaltyRate = mfee.getRate();
|
157
|
- BigDecimal penaltyAmount = BigDecimalHelper.halfUp(orderActualAmount.multiply(penaltyRate));
|
158
|
+ BigDecimal goodsActualAmount = orderActualAmount.subtract(shipFee);
|
|
|
159
|
+ BigDecimal penaltyAmount = BigDecimalHelper.halfUp(goodsActualAmount.multiply(penaltyRate));
|
158
|
BuyerPenalty.Range moneyRange = mfee.getMoneyRange();
|
160
|
BuyerPenalty.Range moneyRange = mfee.getMoneyRange();
|
159
|
if (penaltyAmount.compareTo(moneyRange.getMin()) < 0){
|
161
|
if (penaltyAmount.compareTo(moneyRange.getMin()) < 0){
|
160
|
penaltyAmount = moneyRange.getMin();
|
162
|
penaltyAmount = moneyRange.getMin();
|
161
|
}
|
163
|
}
|
162
|
BigDecimal leftAmount = orderActualAmount.subtract(penaltyAmount);
|
164
|
BigDecimal leftAmount = orderActualAmount.subtract(penaltyAmount);
|
163
|
BuyerPenaltyCalResult bpcr = BuyerPenaltyCalResult.builder().uid(buyerUid).orderCode(orderCode)
|
165
|
BuyerPenaltyCalResult bpcr = BuyerPenaltyCalResult.builder().uid(buyerUid).orderCode(orderCode)
|
164
|
- .orderActualAmount(orderActualAmount).penaltyRate(penaltyRate)
|
166
|
+ .orderActualAmount(orderActualAmount)
|
|
|
167
|
+ .goodsActualAmount(goodsActualAmount)
|
|
|
168
|
+ .penaltyRate(penaltyRate)
|
165
|
.penaltyAmount(penaltyAmount).leftAmount(leftAmount).build();
|
169
|
.penaltyAmount(penaltyAmount).leftAmount(leftAmount).build();
|
166
|
logger.info("calBuyerPenalty mfee {} BuyerPenaltyCalResult {}", mfee, bpcr);
|
170
|
logger.info("calBuyerPenalty mfee {} BuyerPenaltyCalResult {}", mfee, bpcr);
|
167
|
return bpcr;
|
171
|
return bpcr;
|
|
@@ -331,6 +335,87 @@ public class BuyerOrderCancelService { |
|
@@ -331,6 +335,87 @@ public class BuyerOrderCancelService { |
331
|
this.transferCase = transferCase;
|
335
|
this.transferCase = transferCase;
|
332
|
}
|
336
|
}
|
333
|
|
337
|
|
|
|
338
|
+ private PayRefundBo refundSellerEarnestMoney(SellerOrder sellerOrder){
|
|
|
339
|
+ PayRefundBo prb = null;
|
|
|
340
|
+ int sellerUid = sellerOrder.getUid();
|
|
|
341
|
+ long sellerOrderCode = sellerOrder.getOrderCode();
|
|
|
342
|
+ BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
|
|
|
343
|
+ PaymentRequest refundReqOfSeller = PaymentRequest.builder().uid(sellerUid).refundCase(RefundCase.SELLER_EARNEST_MONEY)
|
|
|
344
|
+ .orderCode(sellerOrderCode).refundAmount(earnestMoney.doubleValue())
|
|
|
345
|
+ .build();
|
|
|
346
|
+ boolean sellerIsSuper = sellerService.isSuperEntrySeller(sellerUid);
|
|
|
347
|
+ refundReqOfSeller.setSuper(sellerIsSuper);
|
|
|
348
|
+ if (!sellerIsSuper && PaymentHelper.isWallet(sellerOrder.getPayment())){
|
|
|
349
|
+
|
|
|
350
|
+ MerchantOrderAttachInfo moai = MerchantOrderAttachInfo.builder().uid(sellerUid)
|
|
|
351
|
+ .orderCode(sellerOrderCode).skup(skup).earnestMoney(sellerOrder.getEarnestMoney())
|
|
|
352
|
+ .type(swdType.getValue()).build();
|
|
|
353
|
+ refundReqOfSeller.setRefundattch(moai);
|
|
|
354
|
+ }
|
|
|
355
|
+
|
|
|
356
|
+ BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
|
|
|
357
|
+ .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(sellerOrder.getOrderCode())
|
|
|
358
|
+ .payType(sellerOrder.getPayment()).refundCase(RefundCase.SELLER_EARNEST_MONEY)
|
|
|
359
|
+ .skup(skup);
|
|
|
360
|
+ logger.info("in BuyerCancelAfterProcessTask call begin payRefundService.refund seller, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
361
|
+ buyerUid, orderCode, skup, refundReqOfSeller );
|
|
|
362
|
+ try {
|
|
|
363
|
+ prb = payRefundService.refund(refundReqOfSeller, bleb);
|
|
|
364
|
+ }catch (Exception ex){
|
|
|
365
|
+ if (!sellerIsSuper) {
|
|
|
366
|
+ BillLogEvent sellerBillLogEvent = bleb.tradeStatus(BillTradeStatus.FAIL.getCode())
|
|
|
367
|
+ .build();
|
|
|
368
|
+ EventBusPublisher.publishEvent(sellerBillLogEvent);
|
|
|
369
|
+ }
|
|
|
370
|
+ String content = "用户" + sellerUid + "退保证金订单"+ orderCode +"失败";
|
|
|
371
|
+ SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("buyerPaidOrder.selfCancel", "cancel", content);
|
|
|
372
|
+ EventBusPublisher.publishEvent(smsAlarmEvent);
|
|
|
373
|
+ }
|
|
|
374
|
+ logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund seller, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
375
|
+ buyerUid, orderCode, skup, refundReqOfSeller );
|
|
|
376
|
+ return prb;
|
|
|
377
|
+ }
|
|
|
378
|
+
|
|
|
379
|
+ void transferPenalty(BuyerPenaltyCalResult bpcr){
|
|
|
380
|
+ TranseferCellNode transeferCellNode = new TranseferCellNode();
|
|
|
381
|
+ transeferCellNode.setUid(buyerUid);
|
|
|
382
|
+ transeferCellNode.setAmount(bpcr.getPenaltyAmount());
|
|
|
383
|
+ TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
|
|
|
384
|
+ .type(transferCase.getCode()).transferCase(transferCase)
|
|
|
385
|
+ .transeferCellNode(transeferCellNode).build();
|
|
|
386
|
+ logger.info("in BuyerCancelAfterProcessTask call begin paymentService.transferMon, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
387
|
+ buyerUid, orderCode, skup, tmReq );
|
|
|
388
|
+ transferService.transfer(tmReq);
|
|
|
389
|
+ logger.info("in BuyerCancelAfterProcessTask call after paymentService.transferMon, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
390
|
+ buyerUid, orderCode, skup, tmReq );
|
|
|
391
|
+ }
|
|
|
392
|
+
|
|
|
393
|
+ void refundLeftOrderAmount(BuyerPenaltyCalResult bpcr, BuyerOrder buyerOrder){
|
|
|
394
|
+ Integer sellerUid = buyerOrder.getSellerUid();
|
|
|
395
|
+ BigDecimal leftBuyerMoney = bpcr.getLeftAmount();
|
|
|
396
|
+ PaymentRequest rprOfBuyer = PaymentRequest.builder().uid(buyerUid)
|
|
|
397
|
+ .orderCode(orderCode).refundAmount(leftBuyerMoney.doubleValue())
|
|
|
398
|
+ .build();
|
|
|
399
|
+ BillLogEvent.BillLogEventBuilder blebOfBuyer = BillLogEvent.builder()
|
|
|
400
|
+ .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
|
|
|
401
|
+ .payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
|
|
|
402
|
+ .amount(leftBuyerMoney)
|
|
|
403
|
+ .skup(skup);
|
|
|
404
|
+ logger.info("in BuyerCancelAfterProcessTask call begin payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
405
|
+ buyerUid, orderCode, skup, rprOfBuyer );
|
|
|
406
|
+ try {
|
|
|
407
|
+ payRefundService.refund(rprOfBuyer, blebOfBuyer);
|
|
|
408
|
+ }catch (Exception ex){
|
|
|
409
|
+ BillLogEvent buyerBillLogEvent = blebOfBuyer.tradeStatus(BillTradeStatus.FAIL.getCode()).build();
|
|
|
410
|
+ EventBusPublisher.publishEvent(buyerBillLogEvent);
|
|
|
411
|
+ String content = "用户" + buyerUid + "订单"+ orderCode +"退货款失败";
|
|
|
412
|
+ SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("buyerPaidOrder.selfCancel", "cancel", content);
|
|
|
413
|
+ EventBusPublisher.publishEvent(smsAlarmEvent);
|
|
|
414
|
+ }
|
|
|
415
|
+ logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
416
|
+ buyerUid, orderCode, skup, rprOfBuyer );
|
|
|
417
|
+ }
|
|
|
418
|
+
|
334
|
@Override
|
419
|
@Override
|
335
|
public PayRefundBo call() throws Exception {
|
420
|
public PayRefundBo call() throws Exception {
|
336
|
// 整个过程异步去执行(考虑退费依赖订单状态)
|
421
|
// 整个过程异步去执行(考虑退费依赖订单状态)
|
|
@@ -342,80 +427,21 @@ public class BuyerOrderCancelService { |
|
@@ -342,80 +427,21 @@ public class BuyerOrderCancelService { |
342
|
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
|
427
|
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
|
343
|
logger.info("in BuyerCancelAfterProcessTask call sellerOrderMapper.selectBySkup, buyerUid {}, orderCode {}, skup {}",
|
428
|
logger.info("in BuyerCancelAfterProcessTask call sellerOrderMapper.selectBySkup, buyerUid {}, orderCode {}, skup {}",
|
344
|
buyerUid, orderCode, skup );
|
429
|
buyerUid, orderCode, skup );
|
345
|
- int sellerUid = sellerOrder.getUid();
|
|
|
346
|
- long sellerOrderCode = sellerOrder.getOrderCode();
|
|
|
347
|
- BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
|
|
|
348
|
- PaymentRequest refundReqOfSeller = PaymentRequest.builder().uid(sellerUid).refundCase(RefundCase.SELLER_EARNEST_MONEY)
|
|
|
349
|
- .orderCode(sellerOrderCode).refundAmount(earnestMoney.doubleValue())
|
|
|
350
|
- .build();
|
|
|
351
|
- boolean sellerIsSuper = sellerService.isSuperEntrySeller(sellerUid);
|
|
|
352
|
- refundReqOfSeller.setSuper(sellerIsSuper);
|
|
|
353
|
- if (!sellerIsSuper && PaymentHelper.isWallet(sellerOrder.getPayment())){
|
|
|
354
|
-
|
|
|
355
|
- MerchantOrderAttachInfo moai = MerchantOrderAttachInfo.builder().uid(sellerUid)
|
|
|
356
|
- .orderCode(sellerOrderCode).skup(skup).earnestMoney(sellerOrder.getEarnestMoney())
|
|
|
357
|
- .type(swdType.getValue()).build();
|
|
|
358
|
- refundReqOfSeller.setRefundattch(moai);
|
|
|
359
|
- }
|
430
|
+ prb = refundSellerEarnestMoney(sellerOrder);
|
360
|
|
431
|
|
361
|
- BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
|
|
|
362
|
- .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(sellerOrder.getOrderCode())
|
|
|
363
|
- .payType(sellerOrder.getPayment()).refundCase(RefundCase.SELLER_EARNEST_MONEY)
|
|
|
364
|
- .skup(skup);
|
|
|
365
|
- logger.info("in BuyerCancelAfterProcessTask call begin payRefundService.refund seller, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
366
|
- buyerUid, orderCode, skup, refundReqOfSeller );
|
|
|
367
|
- try {
|
|
|
368
|
- prb = payRefundService.refund(refundReqOfSeller, bleb);
|
|
|
369
|
- }catch (Exception ex){
|
|
|
370
|
- if (!sellerIsSuper) {
|
|
|
371
|
- BillLogEvent sellerBillLogEvent = bleb.tradeStatus(BillTradeStatus.FAIL.getCode())
|
|
|
372
|
- .build();
|
|
|
373
|
- EventBusPublisher.publishEvent(sellerBillLogEvent);
|
|
|
374
|
- }
|
|
|
375
|
- String content = "用户" + sellerUid + "退保证金订单"+ orderCode +"失败";
|
|
|
376
|
- SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("buyerPaidOrder.selfCancel", "cancel", content);
|
|
|
377
|
- EventBusPublisher.publishEvent(smsAlarmEvent);
|
|
|
378
|
- }
|
|
|
379
|
- logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund seller, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
380
|
- buyerUid, orderCode, skup, refundReqOfSeller );
|
|
|
381
|
//(转账)瓜分指定赔偿款给卖家和平台
|
432
|
//(转账)瓜分指定赔偿款给卖家和平台
|
382
|
-
|
|
|
383
|
- TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
|
|
|
384
|
- .type(transferCase.getCode()).transferCase(transferCase).build();
|
|
|
385
|
- logger.info("in BuyerCancelAfterProcessTask call begin paymentService.transferMon, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
386
|
- buyerUid, orderCode, skup, tmReq );
|
|
|
387
|
- paymentService.transferMon(tmReq);
|
|
|
388
|
- logger.info("in BuyerCancelAfterProcessTask call after paymentService.transferMon, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
389
|
- buyerUid, orderCode, skup, tmReq );
|
|
|
390
|
-
|
|
|
391
|
- //(退费)扣除赔偿款,计算剩余的货款,退给买家
|
|
|
392
|
- BigDecimal compensateMoney = compensate.getBuyerCompensateMoney();
|
|
|
393
|
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
|
433
|
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
|
394
|
logger.info("in BuyerCancelAfterProcessTask call begin buyerOrderMapper.selectByOrderCode, buyerUid {}, orderCode {}, skup {} buyerOrder {}",
|
434
|
logger.info("in BuyerCancelAfterProcessTask call begin buyerOrderMapper.selectByOrderCode, buyerUid {}, orderCode {}, skup {} buyerOrder {}",
|
395
|
buyerUid, orderCode, skup, buyerOrder );
|
435
|
buyerUid, orderCode, skup, buyerOrder );
|
396
|
- BigDecimal leftBuyerMoney = buyerOrder.getAmount().subtract(compensateMoney);
|
|
|
397
|
- PaymentRequest rprOfBuyer = PaymentRequest.builder().uid(buyerUid)
|
|
|
398
|
- .orderCode(orderCode).refundAmount(leftBuyerMoney.doubleValue())
|
|
|
399
|
- .build();
|
|
|
400
|
- BillLogEvent.BillLogEventBuilder blebOfBuyer = BillLogEvent.builder()
|
|
|
401
|
- .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
|
|
|
402
|
- .payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
|
|
|
403
|
- .amount(leftBuyerMoney)
|
|
|
404
|
- .skup(skup);
|
|
|
405
|
- logger.info("in BuyerCancelAfterProcessTask call begin payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
406
|
- buyerUid, orderCode, skup, rprOfBuyer );
|
|
|
407
|
- try {
|
|
|
408
|
- payRefundService.refund(rprOfBuyer, blebOfBuyer);
|
|
|
409
|
- }catch (Exception ex){
|
|
|
410
|
- BillLogEvent buyerBillLogEvent = blebOfBuyer.tradeStatus(BillTradeStatus.FAIL.getCode()).build();
|
|
|
411
|
- EventBusPublisher.publishEvent(buyerBillLogEvent);
|
|
|
412
|
- String content = "用户" + buyerUid + "订单"+ orderCode +"退货款失败";
|
|
|
413
|
- SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("buyerPaidOrder.selfCancel", "cancel", content);
|
|
|
414
|
- EventBusPublisher.publishEvent(smsAlarmEvent);
|
|
|
415
|
- }
|
|
|
416
|
- logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
417
|
- buyerUid, orderCode, skup, rprOfBuyer );
|
|
|
418
|
-
|
436
|
+ OrderStatus orderStatus = OrderStatus.getOrderStatus(buyerOrder.getStatus());
|
|
|
437
|
+ BigDecimal orderActualAmount = buyerOrder.getAmount();
|
|
|
438
|
+ BigDecimal shipFee = buyerOrder.getShipFee();
|
|
|
439
|
+ OrderAttributes orderAttributes = OrderAttributes.getOrderAttributes(buyerOrder.getAttributes());
|
|
|
440
|
+ //TODO try catch to record fail transfer
|
|
|
441
|
+ BuyerPenaltyCalResult bpcr = calBuyerPenalty(buyerUid, orderCode, orderStatus, orderActualAmount, shipFee, orderAttributes);
|
|
|
442
|
+ transferPenalty(bpcr);
|
|
|
443
|
+ //(退费)扣除赔偿款,计算剩余的货款,退给买家
|
|
|
444
|
+ refundLeftOrderAmount(bpcr, buyerOrder);
|
419
|
logger.info("out BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}",
|
445
|
logger.info("out BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}",
|
420
|
buyerUid, orderCode, skup, transferCase, compensate);
|
446
|
buyerUid, orderCode, skup, transferCase, compensate);
|
421
|
}catch (Exception ex){
|
447
|
}catch (Exception ex){
|
|
@@ -423,7 +449,6 @@ public class BuyerOrderCancelService { |
|
@@ -423,7 +449,6 @@ public class BuyerOrderCancelService { |
423
|
buyerUid, orderCode, skup, transferCase, compensate, ex);
|
449
|
buyerUid, orderCode, skup, transferCase, compensate, ex);
|
424
|
}
|
450
|
}
|
425
|
return prb;
|
451
|
return prb;
|
426
|
-
|
|
|
427
|
}
|
452
|
}
|
428
|
}
|
453
|
}
|
429
|
|
454
|
|