...
|
...
|
@@ -714,7 +714,173 @@ public class AppraiseService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
public ApiResponse appraiseSuccess(Integer expressCompanyId, Long orderCode, String wayBillCode,Integer depotNum,String mobile){
|
|
|
/**
|
|
|
* 正常发货
|
|
|
* 鉴定通过 -- 待收货
|
|
|
*/
|
|
|
public void deliveryGoodsToBuyer(AppraiseExpressInfoBo appraiseExpressInfoBo){
|
|
|
LOGGER.info("deliveryGoodsToBuyer enter req {}", appraiseExpressInfoBo);
|
|
|
final OrderStatus expectOrderStatus = OrderStatus.JUDGE_PASS;
|
|
|
final OrderStatus targetOrderStatus = OrderStatus.WAITING_RECEIVE;
|
|
|
Long orderCode = appraiseExpressInfoBo.getOrderCode();
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
|
|
|
|
|
|
if (buyerOrder == null){
|
|
|
LOGGER.warn("deliveryGoodsToBuyer getOrderInfo order not exist, orderCode is {}", orderCode);
|
|
|
throw new ServiceException(ServiceError.ORDER_NULL);
|
|
|
}
|
|
|
|
|
|
if (expectOrderStatus.getCode() != buyerOrder.getStatus().intValue()){
|
|
|
LOGGER.warn("in deliveryGoodsToBuyer, buyer Order orderCode {} pstatus {}, expect Order Status {}",
|
|
|
orderCode, buyerOrder.getStatus(), expectOrderStatus);
|
|
|
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
|
|
|
}
|
|
|
|
|
|
Integer buyerUid = buyerOrder.getUid();
|
|
|
int updateBuyerCnt = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid,
|
|
|
expectOrderStatus.getCode(), targetOrderStatus.getCode(), DateUtil.getCurrentTimeSecond());
|
|
|
if (updateBuyerCnt == 1){
|
|
|
//发货,这个时候产生:买家确认收货的mq
|
|
|
BuyerConfirmEvent buyerConfirmEvent = BuyerConfirmEvent.builder().uid(buyerUid).orderCode(orderCode).build();
|
|
|
EventBusPublisher.publishEvent(buyerConfirmEvent);
|
|
|
|
|
|
//记录物流信息
|
|
|
//发物流
|
|
|
expressInfoService.deliverGoods(buyerUid, appraiseExpressInfoBo.getExpressCompanyId(), orderCode, appraiseExpressInfoBo.getWayBillCode(), appraiseExpressInfoBo.getDepotNum(),appraiseExpressInfoBo.getMobile());
|
|
|
|
|
|
//记录订单的状态变更信息
|
|
|
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetOrderStatus.getCode());
|
|
|
|
|
|
//TODO 平台已发货给买家
|
|
|
|
|
|
//清缓存
|
|
|
cleanCacheAfterUpdateStatus(buyerOrder.getOrderCode(),buyerOrder.getUid(),buyerOrder.getSellerUid());
|
|
|
}else{
|
|
|
LOGGER.warn("in deliveryGoodsToBuyer update status number zero, buyer Order orderCode {} pstatus {}, expect Order Status {}",
|
|
|
orderCode, buyerOrder.getStatus(), expectOrderStatus);
|
|
|
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 鉴定通过,但是不发货
|
|
|
* @return
|
|
|
*/
|
|
|
public ApiResponse judgeCenterPass(Long orderCode){
|
|
|
LOGGER.info("judgeCenterPass enter req orderCode {}", orderCode);
|
|
|
ApiResponse apiResponse=new ApiResponse();
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
|
|
|
|
|
|
if (buyerOrder == null){
|
|
|
LOGGER.warn("judgeCenterPass getOrderInfo order not exist, orderCode is {}", orderCode);
|
|
|
throw new ServiceException(ServiceError.ORDER_NULL);
|
|
|
}
|
|
|
final OrderStatus expectOrderStatus ;
|
|
|
final OrderStatus targetOrderStatus = OrderStatus.JUDGE_PASS;
|
|
|
if( OrderStatus.PLATFORM_CHECKING.getCode() == buyerOrder.getStatus().intValue()){
|
|
|
expectOrderStatus = OrderStatus.PLATFORM_CHECKING;
|
|
|
}else{
|
|
|
LOGGER.warn("in judgeCenterPass, buyer Order orderCode {} status {}, expect Order Status is OrderStatus.PLATFORM_CHECKING or OrderStatus.MINI_FAULT_ACCEPT ",
|
|
|
orderCode, buyerOrder.getStatus());
|
|
|
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;
|
|
|
|
|
|
/**
|
|
|
* 更新卖家订单状态,
|
|
|
*/
|
|
|
SellerOrderGoods sellerOrderGoods = updateSellerOrderStatusAndCleanCache(sellerUid ,sellerOrderCode,expectSOStatus,targetSoStatus,
|
|
|
skup, orderCode, buyerUid);
|
|
|
|
|
|
|
|
|
//退款给卖家(仅退一次)
|
|
|
PaymentRequest refundReqOfSeller = operateMoneyWhenOk(buyerUid,orderCode,skup,sellerOrder,targetSoStatus);
|
|
|
|
|
|
try {
|
|
|
//记录订单的状态变更信息
|
|
|
LOGGER.info("in judgeCenterPass record status change, orderCode {},uid {} ,sellerUid {}", orderCode,buyerUid,sellerUid);
|
|
|
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetOrderStatus.getCode());
|
|
|
|
|
|
//TODO 鉴定通过,等待发货,消息
|
|
|
//inBoxFacade.appraisePassNotice(buyerUid, orderCode, sellerOrderGoods);
|
|
|
}catch (Exception ex){
|
|
|
LOGGER.warn("in judgeCenterPass,refund fail, refundReqOfSeller {}", refundReqOfSeller, ex);
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
LOGGER.info("in judgeCenterPass, refund earnestMoney finish, seller {}, order code {}, skup {}, earnestMoney {}",
|
|
|
sellerUid, sellerOrderCode, skup, sellerOrder.getEarnestMoney() );
|
|
|
|
|
|
|
|
|
}else{
|
|
|
LOGGER.warn("in judgeCenterPass, buyer Order pstatus {}, expect expectOrderStatus {}",
|
|
|
buyerOrder.getStatus(), expectOrderStatus);
|
|
|
apiResponse.setCode(400);
|
|
|
apiResponse.setMessage("订单状态发生变化");
|
|
|
}
|
|
|
|
|
|
return apiResponse;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 通过时 ,操作钱
|
|
|
*/
|
|
|
private PaymentRequest operateMoneyWhenOk(Integer buyerUid,Long orderCode,int skup,SellerOrder sellerOrder,SellerOrderStatus targetSoStatus){
|
|
|
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);
|
|
|
|
|
|
//改成异步的分账,不关心分账执行结果
|
|
|
executorService.execute(()->{
|
|
|
LOGGER.info("in appraiseSuccess,begin transfer async");
|
|
|
transferService.transfer(tmReq);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 退保证金给卖家
|
|
|
*/
|
|
|
final Integer sellerUid = sellerOrder.getUid();
|
|
|
BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
|
|
|
//refund earnestMoney
|
|
|
PaymentRequest refundReqOfSeller = refundEarnestMoney(SellerWalletDetail.Type.APPRAISE_OK,orderCode,sellerUid ,sellerOrder,skup,buyerUid,targetSoStatus,earnestMoney.doubleValue());
|
|
|
LOGGER.info("in appraiseSuccess,refund ok, refundReqOfSeller {}", refundReqOfSeller);
|
|
|
return refundReqOfSeller;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 鉴定通过并发货
|
|
|
*/
|
|
|
public ApiResponse appraiseSuccessAndDelivery(Integer expressCompanyId, Long orderCode, String wayBillCode,Integer depotNum,String mobile){
|
|
|
LOGGER.info("appraiseSuccessAndDelivery enter req orderCode {},wayBillCode {},mobile {}", orderCode,wayBillCode,mobile);
|
|
|
ApiResponse apiResponse=new ApiResponse();
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
|
|
|
|
...
|
...
|
@@ -744,19 +910,14 @@ public class AppraiseService { |
|
|
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;
|
|
|
|
|
|
//更新卖家订单状态
|
|
|
SellerOrderGoods sellerOrderGoods = updateSellerOrderStatusAndCleanCache(sellerUid ,sellerOrderCode,expectSOStatus,targetSoStatus,
|
|
|
skup, orderCode, buyerUid);
|
|
|
//退款给卖家(仅退一次)
|
|
|
PaymentRequest refundReqOfSeller = operateMoneyWhenOk(buyerUid,orderCode,skup,sellerOrder,targetSoStatus);
|
|
|
|
|
|
/*TransferCase transferCase = TransferCase.ALL_GOODS_MONEY_TO_SELLER;
|
|
|
TransferMoneyRequest tmReq = TransferMoneyRequest.builder()
|
|
|
.buyerOrderCode(orderCode)
|
|
|
.type(transferCase.getCode())
|
...
|
...
|
@@ -773,15 +934,13 @@ public class AppraiseService { |
|
|
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();
|
...
|
...
|
@@ -809,18 +968,8 @@ public class AppraiseService { |
|
|
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 );
|
|
|
sellerUid, sellerOrderCode, skup, sellerOrder.getEarnestMoney() );
|
|
|
|
|
|
|
|
|
}else{
|
...
|
...
|
|