...
|
...
|
@@ -38,6 +38,7 @@ import org.apache.commons.lang3.StringUtils; |
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
...
|
...
|
@@ -107,6 +108,12 @@ public class AppraiseService { |
|
|
@Autowired
|
|
|
private OrderOperateRecordService orderOperateRecordService;
|
|
|
|
|
|
/**
|
|
|
* 瑕疵确认不通过的情况,卖家的保证金扣掉一部分给平台,暂定10元
|
|
|
*/
|
|
|
@Value("${order.seller.earnestmoney.miniFaultRejectPunishFee:10}")
|
|
|
private Double miniFaultRejectPunishFee ;
|
|
|
|
|
|
public ApiResponse appraiseSuccess(Integer expressCompanyId, Long orderCode, String wayBillCode,Integer depotNum,String mobile){
|
|
|
ApiResponse apiResponse=new ApiResponse();
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
|
...
|
...
|
@@ -178,41 +185,12 @@ public class AppraiseService { |
|
|
*/
|
|
|
//refund earnestMoney
|
|
|
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())){
|
|
|
SellerWalletDetail.Type swdType = SellerWalletDetail.Type.APPRAISE_OK;
|
|
|
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);
|
|
|
SellerOrderGoods sellerOrderGoods;
|
|
|
sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
|
|
|
|
|
|
new RefundEarnestMoneyHandler()
|
|
|
.loadRefundAction(payRefundService::refund)
|
|
|
.loadBillLogEventBuilder(bleb)
|
|
|
.loadPaymentRequest(refundReqOfSeller)
|
|
|
.loadBuyer(null, null, null)
|
|
|
.loadSeller(sellerUid, sellerIsSuper, orderCode, targetSoStatus)
|
|
|
.loadLogger(LOGGER)
|
|
|
.refund();
|
|
|
PaymentRequest refundReqOfSeller = refundEarnestMoney(SellerWalletDetail.Type.APPRAISE_OK,orderCode,sellerUid ,sellerOrder,skup,buyerUid,targetSoStatus,earnestMoney.doubleValue());
|
|
|
LOGGER.info("in appraiseSuccess,refund ok, refundReqOfSeller {}", refundReqOfSeller);
|
|
|
|
|
|
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
|
|
|
try {
|
|
|
/*
|
|
|
payRefundService.refund(refundReqOfSeller, bleb);
|
|
|
*/
|
|
|
//通知卖家退还保证金
|
|
|
//鉴定通过后自动发货,这个时候产生:买家确认收货的mq
|
|
|
BuyerConfirmEvent buyerConfirmEvent = BuyerConfirmEvent.builder().uid(buyerUid).orderCode(orderCode).build();
|
|
|
EventBusPublisher.publishEvent(buyerConfirmEvent);
|
|
|
//记录物流信息
|
...
|
...
|
@@ -273,6 +251,42 @@ public class AppraiseService { |
|
|
return apiResponse;
|
|
|
}
|
|
|
|
|
|
//退保证金给卖家
|
|
|
private PaymentRequest refundEarnestMoney(SellerWalletDetail.Type swdType,Long orderCode,Integer sellerUid ,SellerOrder sellerOrder,int skup,Integer buyerUid,SellerOrderStatus targetSoStatus ,double refundMoney){
|
|
|
Long sellerOrderCode = sellerOrder.getOrderCode();
|
|
|
PaymentRequest refundReqOfSeller = PaymentRequest.builder().uid(sellerUid)
|
|
|
.refundCase(RefundCase.SELLER_EARNEST_MONEY)
|
|
|
.orderCode(sellerOrderCode).refundAmount(refundMoney)
|
|
|
.build();
|
|
|
boolean sellerIsSuper = sellerService.isSuperEntrySeller(sellerUid);
|
|
|
refundReqOfSeller.setSuper(sellerIsSuper);
|
|
|
LOGGER.info("in refundEarnestMoney begin, swdType {} seller uid {},sellerIsSuper {},seller order code {}, skup {}, refundMoney {},refundReqOfSeller {}",swdType,
|
|
|
sellerUid,sellerIsSuper, sellerOrderCode, skup, refundMoney ,refundReqOfSeller);
|
|
|
if (!sellerIsSuper && PaymentHelper.isWallet(sellerOrder.getPayment())){
|
|
|
//SellerWalletDetail.Type swdType = SellerWalletDetail.Type.APPRAISE_OK;
|
|
|
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);
|
|
|
|
|
|
new RefundEarnestMoneyHandler()
|
|
|
.loadRefundAction(payRefundService::refund)
|
|
|
.loadBillLogEventBuilder(bleb)
|
|
|
.loadPaymentRequest(refundReqOfSeller)
|
|
|
.loadBuyer(null, null, null)
|
|
|
.loadSeller(sellerUid, sellerIsSuper, orderCode, targetSoStatus)
|
|
|
.loadLogger(LOGGER)
|
|
|
.refund();
|
|
|
|
|
|
return refundReqOfSeller;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 触发物流
|
|
|
*/
|
...
|
...
|
@@ -484,27 +498,33 @@ public class AppraiseService { |
|
|
ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid);
|
|
|
EventBusPublisher.publishEvent(event);
|
|
|
|
|
|
//将卖家的保证金分账给平台和买家
|
|
|
TransferCase transferCase = TransferCase.EARNEST_MONEY_TO_BUYER;
|
|
|
TransferMoneyRequest tmReq = TransferMoneyRequest.builder()
|
|
|
.sellerUid(sellerUid)
|
|
|
.buyerOrderCode(orderCode)
|
|
|
.type(transferCase.getCode())
|
|
|
.transferCase(transferCase)
|
|
|
.swdType(SellerWalletDetail.Type.APPRAISE_FAIL)
|
|
|
.alarmConfig(AlarmConfig.APPRAISE_FAIL)
|
|
|
.build();
|
|
|
|
|
|
//先校验,提前把错误抛出
|
|
|
paymentService.transferMonCheck(tmReq);
|
|
|
//再分账
|
|
|
if(type==3 || type==4){
|
|
|
//将卖家的保证金扣掉10元后,剩余的钱退回给卖家
|
|
|
BigDecimal earnestMoney = sellerOrder.getEarnestMoney().subtract(new BigDecimal(miniFaultRejectPunishFee));
|
|
|
PaymentRequest refundReqOfSeller = refundEarnestMoney(SellerWalletDetail.Type.MINI_FAULT_REJECT,orderCode,sellerUid ,sellerOrder,skup,buyerUid,targetSoStatus,earnestMoney.doubleValue());
|
|
|
LOGGER.info("in appraiseFail,refund ok, refundReqOfSeller {}", refundReqOfSeller);
|
|
|
}else{
|
|
|
//将卖家的保证金分账给平台和买家
|
|
|
TransferCase transferCase = TransferCase.EARNEST_MONEY_TO_BUYER;
|
|
|
TransferMoneyRequest tmReq = TransferMoneyRequest.builder()
|
|
|
.sellerUid(sellerUid)
|
|
|
.buyerOrderCode(orderCode)
|
|
|
.type(transferCase.getCode())
|
|
|
.transferCase(transferCase)
|
|
|
.swdType(SellerWalletDetail.Type.APPRAISE_FAIL)
|
|
|
.alarmConfig(AlarmConfig.APPRAISE_FAIL)
|
|
|
.build();
|
|
|
|
|
|
//改成异步的分账,不关心分账执行结果
|
|
|
executorService.execute(()->{
|
|
|
LOGGER.info("in appraiseFail,begin transfer async");
|
|
|
transferService.transfer(tmReq);
|
|
|
});
|
|
|
//先校验,提前把错误抛出
|
|
|
paymentService.transferMonCheck(tmReq);
|
|
|
//再分账
|
|
|
|
|
|
//改成异步的分账,不关心分账执行结果
|
|
|
executorService.execute(()->{
|
|
|
LOGGER.info("in appraiseFail,begin transfer async");
|
|
|
transferService.transfer(tmReq);
|
|
|
});
|
|
|
}
|
|
|
BigDecimal goodsMoney = buyerOrder.getAmount();
|
|
|
/*
|
|
|
PaymentRequest req = PaymentRequest.builder().uid(buyerUid)
|
...
|
...
|
|