Authored by qinchao

瑕疵分等级扣款

... ... @@ -111,178 +111,7 @@ public class AppraiseService {
@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);
if (buyerOrder == null){
LOGGER.warn("appraiseSuccess getOrderInfo order not exist, orderCode is {}", orderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
}
final OrderStatus expectOrderStatus = OrderStatus.PLATFORM_CHECKING;
final OrderStatus targetOrderStatus = OrderStatus.WAITING_RECEIVE;
if (expectOrderStatus.getCode() != buyerOrder.getStatus().intValue()){
LOGGER.warn("in appraiseSuccess, buyer Order orderCode {} pstatus {}, expect Order Status {}",
orderCode, buyerOrder.getStatus(), expectOrderStatus);
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
}
Integer buyerUid = buyerOrder.getUid();
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
int skup = bog.getSkup();
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
int updateBuyerCnt = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid,
expectOrderStatus.getCode(), targetOrderStatus.getCode(), DateUtil.getCurrentTimeSecond());
if (updateBuyerCnt == 1){
final Integer sellerUid = sellerOrder.getUid();
final Long sellerOrderCode = sellerOrder.getOrderCode();
final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED;
final SellerOrderStatus targetSoStatus = SellerOrderStatus.FINISH;
/**
* 更新卖家订单状态,
* 退款给卖家(仅退一次)
*
*/
SellerOrder tso = new SellerOrder();
tso.setUid(sellerUid);
tso.setOrderCode(sellerOrderCode);
tso.setStatus(targetSoStatus.getCode());
tso.setUpdateTime(DateUtil.getCurrentTimeSecond());
tso.setExceptStatus(expectSOStatus.getCode());
int soCnt = sellerOrderMapper.updateByOrderCode(tso);
TransferCase transferCase = TransferCase.ALL_GOODS_MONEY_TO_SELLER;
TransferMoneyRequest tmReq = TransferMoneyRequest.builder()
.buyerOrderCode(orderCode)
.type(transferCase.getCode())
.transferCase(transferCase)
.alarmConfig(AlarmConfig.APPRAISE_SUCCESS)
.build();
//先校验,提前把错误抛出
paymentService.transferMonCheck(tmReq);
//再分账
/**
boolean transferSuccessFlag=transferService.transfer(tmReq);
if(!transferSuccessFlag){
apiResponse.setCode(400);
apiResponse.setMessage("保证金分账失败");
}
*/
//改成异步的分账,不关心分账执行结果
executorService.execute(()->{
LOGGER.info("in appraiseSuccess,begin transfer async");
transferService.transfer(tmReq);
});
/**
* 退保证金给卖家
*/
//refund earnestMoney
BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
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 {
//鉴定通过后自动发货,这个时候产生:买家确认收货的mq
BuyerConfirmEvent buyerConfirmEvent = BuyerConfirmEvent.builder().uid(buyerUid).orderCode(orderCode).build();
EventBusPublisher.publishEvent(buyerConfirmEvent);
//记录物流信息
//发物流
expressInfoService.deliverGoods(buyerUid, expressCompanyId, orderCode, wayBillCode, depotNum,mobile);
//记录订单的状态变更信息
LOGGER.info("in appraiseSuccess record status change, orderCode {},uid {} ,sellerUid {}", orderCode,buyerUid,sellerUid);
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetOrderStatus.getCode());
//平台已发货给买家
inBoxFacade.appraisePassNotice(buyerUid, orderCode, sellerOrderGoods);
}catch (Exception ex){
LOGGER.warn("in appraiseSuccess,refund fail, refundReqOfSeller {}", refundReqOfSeller, ex);
/*
if (!sellerIsSuper) {
BillLogEvent sellerBillLogEvent = bleb.tradeStatus(BillTradeStatus.FAIL.getCode())
.build();
EventBusPublisher.publishEvent(sellerBillLogEvent);
}
String content = "鉴定通过时,订单"+ orderCode + "退还保证金失败";
AlarmConfig alarmConfig = AlarmConfig.APPRAISE_SUCCESS;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
*/
String content = "鉴定通过时,订单"+ orderCode + "退还保证金失败";
apiResponse.setCode(400);
apiResponse.setMessage(content);
}finally {
//记录调拨信息
EnumExpressType expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
EnumExpressDataOperateTransferCode operateTransferCode = EnumExpressDataOperateTransferCode.judge_pass;
expressInfoService.saveOperateTransferExpressInfo(sellerUid,orderCode,expressType.getCode(),expressDataType,operateTransferCode);
}
cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()),
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(sellerOrderGoods),
CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), orderCode),
CacheKeyBuilder.orderDetailKey(buyerUid,TabType.BUY.getValue(), orderCode),
CacheKeyBuilder.buyerOrderNums(buyerUid)));
ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid);
EventBusPublisher.publishEvent(event);
LOGGER.info("in appraiseSuccess, refund earnestMoney finish, seller {}, order code {}, skup {}, earnestMoney {}",
sellerUid, sellerOrderCode, skup, earnestMoney );
}else{
LOGGER.warn("in appraiseSuccess, buyer Order pstatus {}, expect expectOrderStatus {}",
buyerOrder.getStatus(), expectOrderStatus);
apiResponse.setCode(400);
apiResponse.setMessage("订单状态发生变化");
}
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;
}
/**
* 触发物流
... ... @@ -549,21 +378,7 @@ public class AppraiseService {
String content = "鉴定不通过时,退用户" + sellerUid + "货款订单"+ orderCode +"失败";
apiResponse.setMessage(content);
}
/*
try{
payRefundService.refund(req, bleb);
}catch (Exception ex){
LOGGER.warn("in appraiseFail ,refund fail,req {}", req, ex);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(BillTradeStatus.FAIL.getCode())
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
String content = "鉴定不通过时,退用户" + sellerUid + "货款订单"+ orderCode +"失败";
AlarmConfig alarmConfig = AlarmConfig.APPRAISE_FAIL;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}
*/
//记录订单的状态变更信息
LOGGER.info("in appraiseFail record status change, orderCode {},uid {} ,sellerUid {}", orderCode,buyerUid,sellerUid);
try {
... ... @@ -657,4 +472,178 @@ 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;
}
public ApiResponse appraiseSuccess(Integer expressCompanyId, Long orderCode, String wayBillCode,Integer depotNum,String mobile){
ApiResponse apiResponse=new ApiResponse();
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
if (buyerOrder == null){
LOGGER.warn("appraiseSuccess getOrderInfo order not exist, orderCode is {}", orderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
}
final OrderStatus expectOrderStatus = OrderStatus.PLATFORM_CHECKING;
final OrderStatus targetOrderStatus = OrderStatus.WAITING_RECEIVE;
if (expectOrderStatus.getCode() != buyerOrder.getStatus().intValue()){
LOGGER.warn("in appraiseSuccess, buyer Order orderCode {} pstatus {}, expect Order Status {}",
orderCode, buyerOrder.getStatus(), expectOrderStatus);
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
}
Integer buyerUid = buyerOrder.getUid();
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
int skup = bog.getSkup();
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
int updateBuyerCnt = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid,
expectOrderStatus.getCode(), targetOrderStatus.getCode(), DateUtil.getCurrentTimeSecond());
if (updateBuyerCnt == 1){
final Integer sellerUid = sellerOrder.getUid();
final Long sellerOrderCode = sellerOrder.getOrderCode();
final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED;
final SellerOrderStatus targetSoStatus = SellerOrderStatus.FINISH;
/**
* 更新卖家订单状态,
* 退款给卖家(仅退一次)
*
*/
SellerOrder tso = new SellerOrder();
tso.setUid(sellerUid);
tso.setOrderCode(sellerOrderCode);
tso.setStatus(targetSoStatus.getCode());
tso.setUpdateTime(DateUtil.getCurrentTimeSecond());
tso.setExceptStatus(expectSOStatus.getCode());
int soCnt = sellerOrderMapper.updateByOrderCode(tso);
TransferCase transferCase = TransferCase.ALL_GOODS_MONEY_TO_SELLER;
TransferMoneyRequest tmReq = TransferMoneyRequest.builder()
.buyerOrderCode(orderCode)
.type(transferCase.getCode())
.transferCase(transferCase)
.alarmConfig(AlarmConfig.APPRAISE_SUCCESS)
.build();
//先校验,提前把错误抛出
paymentService.transferMonCheck(tmReq);
//再分账
/**
boolean transferSuccessFlag=transferService.transfer(tmReq);
if(!transferSuccessFlag){
apiResponse.setCode(400);
apiResponse.setMessage("保证金分账失败");
}
*/
//改成异步的分账,不关心分账执行结果
executorService.execute(()->{
LOGGER.info("in appraiseSuccess,begin transfer async");
transferService.transfer(tmReq);
});
/**
* 退保证金给卖家
*/
//refund earnestMoney
BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
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 {
//鉴定通过后自动发货,这个时候产生:买家确认收货的mq
BuyerConfirmEvent buyerConfirmEvent = BuyerConfirmEvent.builder().uid(buyerUid).orderCode(orderCode).build();
EventBusPublisher.publishEvent(buyerConfirmEvent);
//记录物流信息
//发物流
expressInfoService.deliverGoods(buyerUid, expressCompanyId, orderCode, wayBillCode, depotNum,mobile);
//记录订单的状态变更信息
LOGGER.info("in appraiseSuccess record status change, orderCode {},uid {} ,sellerUid {}", orderCode,buyerUid,sellerUid);
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetOrderStatus.getCode());
//平台已发货给买家
inBoxFacade.appraisePassNotice(buyerUid, orderCode, sellerOrderGoods);
}catch (Exception ex){
LOGGER.warn("in appraiseSuccess,refund fail, refundReqOfSeller {}", refundReqOfSeller, ex);
/*
if (!sellerIsSuper) {
BillLogEvent sellerBillLogEvent = bleb.tradeStatus(BillTradeStatus.FAIL.getCode())
.build();
EventBusPublisher.publishEvent(sellerBillLogEvent);
}
String content = "鉴定通过时,订单"+ orderCode + "退还保证金失败";
AlarmConfig alarmConfig = AlarmConfig.APPRAISE_SUCCESS;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
*/
String content = "鉴定通过时,订单"+ orderCode + "退还保证金失败";
apiResponse.setCode(400);
apiResponse.setMessage(content);
}finally {
//记录调拨信息
EnumExpressType expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
EnumExpressDataOperateTransferCode operateTransferCode = EnumExpressDataOperateTransferCode.judge_pass;
expressInfoService.saveOperateTransferExpressInfo(sellerUid,orderCode,expressType.getCode(),expressDataType,operateTransferCode);
}
cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()),
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
CacheKeyBuilder.sellerOrderDetailKey(sellerOrderGoods),
CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), orderCode),
CacheKeyBuilder.orderDetailKey(buyerUid,TabType.BUY.getValue(), orderCode),
CacheKeyBuilder.buyerOrderNums(buyerUid)));
ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid);
EventBusPublisher.publishEvent(event);
LOGGER.info("in appraiseSuccess, refund earnestMoney finish, seller {}, order code {}, skup {}, earnestMoney {}",
sellerUid, sellerOrderCode, skup, earnestMoney );
}else{
LOGGER.warn("in appraiseSuccess, buyer Order pstatus {}, expect expectOrderStatus {}",
buyerOrder.getStatus(), expectOrderStatus);
apiResponse.setCode(400);
apiResponse.setMessage("订单状态发生变化");
}
return apiResponse;
}
}
... ...