|
@@ -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,17 +335,8 @@ public class BuyerOrderCancelService { |
|
@@ -331,17 +335,8 @@ public class BuyerOrderCancelService { |
331
|
this.transferCase = transferCase;
|
335
|
this.transferCase = transferCase;
|
332
|
}
|
336
|
}
|
333
|
|
337
|
|
334
|
- @Override
|
|
|
335
|
- public PayRefundBo call() throws Exception {
|
|
|
336
|
- // 整个过程异步去执行(考虑退费依赖订单状态)
|
|
|
337
|
- //(退费)退保证金给卖家
|
|
|
338
|
- logger.info("in BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}",
|
|
|
339
|
- buyerUid, orderCode, skup, transferCase, compensate);
|
338
|
+ private PayRefundBo refundSellerEarnestMoney(SellerOrder sellerOrder){
|
340
|
PayRefundBo prb = null;
|
339
|
PayRefundBo prb = null;
|
341
|
- try {
|
|
|
342
|
- SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
|
|
|
343
|
- logger.info("in BuyerCancelAfterProcessTask call sellerOrderMapper.selectBySkup, buyerUid {}, orderCode {}, skup {}",
|
|
|
344
|
- buyerUid, orderCode, skup );
|
|
|
345
|
int sellerUid = sellerOrder.getUid();
|
340
|
int sellerUid = sellerOrder.getUid();
|
346
|
long sellerOrderCode = sellerOrder.getOrderCode();
|
341
|
long sellerOrderCode = sellerOrder.getOrderCode();
|
347
|
BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
|
342
|
BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
|
|
@@ -378,22 +373,26 @@ public class BuyerOrderCancelService { |
|
@@ -378,22 +373,26 @@ public class BuyerOrderCancelService { |
378
|
}
|
373
|
}
|
379
|
logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund seller, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
374
|
logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund seller, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
380
|
buyerUid, orderCode, skup, refundReqOfSeller );
|
375
|
buyerUid, orderCode, skup, refundReqOfSeller );
|
381
|
- //(转账)瓜分指定赔偿款给卖家和平台
|
376
|
+ return prb;
|
|
|
377
|
+ }
|
382
|
|
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)
|
383
|
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
|
384
|
- .type(transferCase.getCode()).transferCase(transferCase).build();
|
384
|
+ .type(transferCase.getCode()).transferCase(transferCase)
|
|
|
385
|
+ .transeferCellNode(transeferCellNode).build();
|
385
|
logger.info("in BuyerCancelAfterProcessTask call begin paymentService.transferMon, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
386
|
logger.info("in BuyerCancelAfterProcessTask call begin paymentService.transferMon, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
386
|
buyerUid, orderCode, skup, tmReq );
|
387
|
buyerUid, orderCode, skup, tmReq );
|
387
|
- paymentService.transferMon(tmReq);
|
388
|
+ transferService.transfer(tmReq);
|
388
|
logger.info("in BuyerCancelAfterProcessTask call after paymentService.transferMon, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
389
|
logger.info("in BuyerCancelAfterProcessTask call after paymentService.transferMon, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
389
|
buyerUid, orderCode, skup, tmReq );
|
390
|
buyerUid, orderCode, skup, tmReq );
|
|
|
391
|
+ }
|
390
|
|
392
|
|
391
|
- //(退费)扣除赔偿款,计算剩余的货款,退给买家
|
|
|
392
|
- BigDecimal compensateMoney = compensate.getBuyerCompensateMoney();
|
|
|
393
|
- BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
|
|
|
394
|
- logger.info("in BuyerCancelAfterProcessTask call begin buyerOrderMapper.selectByOrderCode, buyerUid {}, orderCode {}, skup {} buyerOrder {}",
|
|
|
395
|
- buyerUid, orderCode, skup, buyerOrder );
|
|
|
396
|
- BigDecimal leftBuyerMoney = buyerOrder.getAmount().subtract(compensateMoney);
|
393
|
+ void refundLeftOrderAmount(BuyerPenaltyCalResult bpcr, BuyerOrder buyerOrder){
|
|
|
394
|
+ Integer sellerUid = buyerOrder.getSellerUid();
|
|
|
395
|
+ BigDecimal leftBuyerMoney = bpcr.getLeftAmount();
|
397
|
PaymentRequest rprOfBuyer = PaymentRequest.builder().uid(buyerUid)
|
396
|
PaymentRequest rprOfBuyer = PaymentRequest.builder().uid(buyerUid)
|
398
|
.orderCode(orderCode).refundAmount(leftBuyerMoney.doubleValue())
|
397
|
.orderCode(orderCode).refundAmount(leftBuyerMoney.doubleValue())
|
399
|
.build();
|
398
|
.build();
|
|
@@ -415,7 +414,34 @@ public class BuyerOrderCancelService { |
|
@@ -415,7 +414,34 @@ public class BuyerOrderCancelService { |
415
|
}
|
414
|
}
|
416
|
logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
415
|
logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
417
|
buyerUid, orderCode, skup, rprOfBuyer );
|
416
|
buyerUid, orderCode, skup, rprOfBuyer );
|
|
|
417
|
+ }
|
418
|
|
418
|
|
|
|
419
|
+ @Override
|
|
|
420
|
+ public PayRefundBo call() throws Exception {
|
|
|
421
|
+ // 整个过程异步去执行(考虑退费依赖订单状态)
|
|
|
422
|
+ //(退费)退保证金给卖家
|
|
|
423
|
+ logger.info("in BuyerCancelAfterProcessTask call buyerUid {}, orderCode {}, skup {}, transferCase {}, compensate {}",
|
|
|
424
|
+ buyerUid, orderCode, skup, transferCase, compensate);
|
|
|
425
|
+ PayRefundBo prb = null;
|
|
|
426
|
+ try {
|
|
|
427
|
+ SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
|
|
|
428
|
+ logger.info("in BuyerCancelAfterProcessTask call sellerOrderMapper.selectBySkup, buyerUid {}, orderCode {}, skup {}",
|
|
|
429
|
+ buyerUid, orderCode, skup );
|
|
|
430
|
+ prb = refundSellerEarnestMoney(sellerOrder);
|
|
|
431
|
+
|
|
|
432
|
+ //(转账)瓜分指定赔偿款给卖家和平台
|
|
|
433
|
+ BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
|
|
|
434
|
+ logger.info("in BuyerCancelAfterProcessTask call begin buyerOrderMapper.selectByOrderCode, buyerUid {}, orderCode {}, skup {} buyerOrder {}",
|
|
|
435
|
+ buyerUid, orderCode, skup, buyerOrder );
|
|
|
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
|
|