...
|
...
|
@@ -3,6 +3,8 @@ package com.yohoufo.order.service.seller.deposit; |
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.order.bo.AppraiseOrderBo;
|
|
|
import com.yohobuy.ufo.model.order.bo.DepositOrderStatisticInfo;
|
|
|
import com.yohobuy.ufo.model.order.bo.OrderInfo;
|
|
|
import com.yohobuy.ufo.model.order.common.AppraiseOrderStatus;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderAttributes;
|
...
|
...
|
@@ -29,6 +31,7 @@ import com.yohoufo.order.constants.MetaKey; |
|
|
import com.yohoufo.order.event.OrderCancelEvent;
|
|
|
import com.yohoufo.order.event.PayConfirmEvent;
|
|
|
import com.yohoufo.order.event.SellerDepositOrderCancelAsyncEvent;
|
|
|
import com.yohoufo.order.event.SellerDepositOrderStatusConsistencyAsyncEvent;
|
|
|
import com.yohoufo.order.model.PayQueryBo;
|
|
|
import com.yohoufo.order.model.dto.PlatformFeeDto;
|
|
|
import com.yohoufo.order.model.dto.SellerDepositOrderContext;
|
...
|
...
|
@@ -52,8 +55,8 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class SellerDepositOrderService extends AbsGoodsServiceOrderService implements IGoodsService {
|
...
|
...
|
@@ -329,14 +332,20 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple |
|
|
*/
|
|
|
@Override
|
|
|
public int appraisePass(AppraiseOrder pao){
|
|
|
int rows = super.appraisePass(pao);
|
|
|
long orderCode = pao.getOrderCode();
|
|
|
AppraiseOrderStatus targetStatus = AppraiseOrderStatus.JUDGE_PASS_WAIT_WAREHOUSE,
|
|
|
expectedStatus = AppraiseOrderStatus.PLATFORM_RECEIVE;
|
|
|
|
|
|
int rows = triggerStatusChange(orderCode, targetStatus, expectedStatus);
|
|
|
|
|
|
if (rows == 0){
|
|
|
return rows;
|
|
|
}
|
|
|
Long orderCode = pao.getOrderCode();
|
|
|
//
|
|
|
triggerStatusConsistencyCheck(orderCode);
|
|
|
|
|
|
Long paidCode = pao.getParentOrderCode();
|
|
|
AppraiseOrderStatus targetOrderStatus = AppraiseOrderStatus.JUDGE_PASS;
|
|
|
inBoxFacade.sellerDepositOrderNotice(pao.getUid(), orderCode, targetOrderStatus);
|
|
|
inBoxFacade.sellerDepositOrderNotice(pao.getUid(), orderCode, targetStatus);
|
|
|
BigDecimal left = calLeftMoney(pao.getAmount(), orderCode);
|
|
|
if (left.compareTo(BigDecimal.ZERO)>0){
|
|
|
|
...
|
...
|
@@ -397,6 +406,10 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple |
|
|
if (rows == 0){
|
|
|
return rows;
|
|
|
}
|
|
|
//
|
|
|
Long orderCode = appraiseOrder.getOrderCode();
|
|
|
triggerStatusConsistencyCheck(orderCode);
|
|
|
//
|
|
|
AppraiseOrderStatus targetOrderStatus = AppraiseOrderStatus.CHECKING_FAKE;
|
|
|
inBoxFacade.sellerDepositOrderNotice(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), targetOrderStatus);
|
|
|
depositService.insertFakeDeposit(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode());
|
...
|
...
|
@@ -413,6 +426,18 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple |
|
|
if (rows == 0){
|
|
|
return rows;
|
|
|
}
|
|
|
//
|
|
|
Long orderCode = appraiseOrder.getOrderCode();
|
|
|
triggerStatusConsistencyCheck(orderCode);
|
|
|
//refund amount
|
|
|
new GoodsServiceRefundHandler()
|
|
|
.loadLogger(logger)
|
|
|
.loadUser(appraiseOrder.getUid())
|
|
|
.loadActionCase(SellerWalletDetail.Type.APPRAISE_UNSURE)
|
|
|
.loadRefundAction(payRefundService::refund)
|
|
|
.loadOrder(appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode(), appraiseOrder.getPayment(), appraiseOrder.getAmount())
|
|
|
.refund();
|
|
|
|
|
|
AppraiseOrderStatus targetOrderStatus = AppraiseOrderStatus.PLATFORM_APPRAISE_UNSURE;
|
|
|
inBoxFacade.sellerDepositOrderNotice(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), targetOrderStatus);
|
|
|
depositService.insertFakeDeposit(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode());
|
...
|
...
|
@@ -430,6 +455,10 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple |
|
|
if (rows == 0){
|
|
|
return rows;
|
|
|
}
|
|
|
//
|
|
|
Long orderCode = appraiseOrder.getOrderCode();
|
|
|
triggerStatusConsistencyCheck(orderCode);
|
|
|
//
|
|
|
AppraiseOrderStatus targetOrderStatus = AppraiseOrderStatus.SHAM_SEND_OUT;
|
|
|
inBoxFacade.sellerDepositOrderNotice(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), targetOrderStatus);
|
|
|
//refund amount
|
...
|
...
|
@@ -550,16 +579,18 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple |
|
|
if (rows == 0){
|
|
|
return rows;
|
|
|
}
|
|
|
Long orderCode = appraiseOrder.getOrderCode();
|
|
|
triggerStatusConsistencyCheck(orderCode);
|
|
|
AppraiseOrderStatus targetOrderStatus = AppraiseOrderStatus.QUALITY_CHECK_FAKE;
|
|
|
inBoxFacade.sellerDepositOrderNotice(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), targetOrderStatus);
|
|
|
inBoxFacade.sellerDepositOrderNotice(appraiseOrder.getUid(), orderCode, targetOrderStatus);
|
|
|
new GoodsServiceRefundHandler()
|
|
|
.loadLogger(logger)
|
|
|
.loadUser(appraiseOrder.getUid())
|
|
|
.loadActionCase(SellerWalletDetail.Type.FLAW)
|
|
|
.loadRefundAction(payRefundService::refund)
|
|
|
.loadOrder(appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode(), appraiseOrder.getPayment(), appraiseOrder.getAmount())
|
|
|
.loadOrder(orderCode, appraiseOrder.getParentOrderCode(), appraiseOrder.getPayment(), appraiseOrder.getAmount())
|
|
|
.refund();
|
|
|
depositService.insertFakeDeposit(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode());
|
|
|
depositService.insertFakeDeposit(appraiseOrder.getUid(), orderCode, appraiseOrder.getParentOrderCode());
|
|
|
return rows;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -587,4 +618,121 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple |
|
|
logger.info("processAfterPay seller deposit order , SellerDepositOrderCancelAsyncEvent send out, event {}", event);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<AppraiseOrderBo> getSubOrderStatistic(long orderCode){
|
|
|
List<AppraiseOrder> paoList = buildSubOrderStatisticList(orderCode);
|
|
|
return paoList.parallelStream().map(pao->AppraiseOrderBo.builder()
|
|
|
.parentOrderCode(pao.getParentOrderCode())
|
|
|
.orderCode(orderCode).status(pao.getStatus()).statusCnt(pao.getStatusCnt()).build())
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
private List<AppraiseOrder> buildSubOrderStatisticList(long orderCode){
|
|
|
AppraiseOrder appraiseOrder = appraiseOrderMapper.selectByOrderCode(orderCode);
|
|
|
if (Objects.isNull(appraiseOrder)){
|
|
|
logger.warn("in getSubOrderStatistic selectByOrderCode null, orderCode {}", orderCode);
|
|
|
return new ArrayList<>(0);
|
|
|
}
|
|
|
long occ = findoutParentOrderCode(orderCode);
|
|
|
List<AppraiseOrder> paoList = appraiseOrderMapper.selectSubOrderStatistic(occ);
|
|
|
logger.info("getSubOrderStatistic orderCode {} ParentOrderCode {} AppraiseOrder list {}", orderCode, occ, paoList);
|
|
|
return paoList;
|
|
|
}
|
|
|
|
|
|
private Long findoutParentOrderCode(long orderCode){
|
|
|
AppraiseOrder appraiseOrder = appraiseOrderMapper.selectByOrderCode(orderCode);
|
|
|
if (Objects.isNull(appraiseOrder)){
|
|
|
logger.warn("in getSubOrderStatistic selectByOrderCode null, orderCode {}", orderCode);
|
|
|
return orderCode;
|
|
|
}
|
|
|
return appraiseOrder.getParentOrderCode()==null ? orderCode : appraiseOrder.getParentOrderCode();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DepositOrderStatisticInfo getAppraiseProgress(int uid, long orderCode){
|
|
|
List<AppraiseOrder> paoList = buildSubOrderStatisticList(orderCode);
|
|
|
|
|
|
//申请
|
|
|
int applyTotal = 0;
|
|
|
int shamNum = 0;
|
|
|
//鉴定为假
|
|
|
Integer fakeNum = 0;
|
|
|
//无法鉴定
|
|
|
Integer unsureNum = 0;
|
|
|
//鉴定通过
|
|
|
Integer passNum = 0;
|
|
|
//鉴定瑕疵
|
|
|
Integer flawNum = 0;
|
|
|
int waitingAppraiseNum = 0;
|
|
|
for (AppraiseOrder pao : paoList){
|
|
|
int cnt = pao.getStatusCnt();
|
|
|
AppraiseOrderStatus orderStatus = AppraiseOrderStatus.getByCode(pao.getStatus());
|
|
|
switch (orderStatus){
|
|
|
case SHAM_SEND_OUT:
|
|
|
shamNum = cnt;
|
|
|
break;
|
|
|
case PLATFORM_APPRAISE_UNSURE:
|
|
|
unsureNum = cnt;
|
|
|
break;
|
|
|
case JUDGE_PASS:
|
|
|
passNum = cnt;
|
|
|
break;
|
|
|
case CHECKING_FAKE:
|
|
|
fakeNum = cnt;
|
|
|
break;
|
|
|
case QUALITY_CHECK_FAKE:
|
|
|
flawNum = cnt;
|
|
|
break;
|
|
|
case PLATFORM_RECEIVE:
|
|
|
waitingAppraiseNum = cnt;
|
|
|
break;
|
|
|
}
|
|
|
applyTotal += cnt;
|
|
|
}
|
|
|
//实收
|
|
|
Integer receiveTotal = applyTotal - shamNum;
|
|
|
DepositOrderStatisticInfo dosi = DepositOrderStatisticInfo.builder()
|
|
|
.applyTotal(applyTotal)
|
|
|
.unsureNum(unsureNum)
|
|
|
.passNum(passNum)
|
|
|
.fakeNum(fakeNum)
|
|
|
.flawNum(flawNum)
|
|
|
.receiveTotal(receiveTotal)
|
|
|
.waitingAppraiseNum(waitingAppraiseNum)
|
|
|
.build();
|
|
|
|
|
|
return dosi;
|
|
|
}
|
|
|
|
|
|
public int platformFinishReceiveGoods(long parentCode){
|
|
|
AppraiseOrderStatus targetStatus = AppraiseOrderStatus.FINISH,
|
|
|
expectedStatus = AppraiseOrderStatus.PLATFORM_RECEIVE;
|
|
|
return triggerStatusChange(parentCode,targetStatus,expectedStatus);
|
|
|
}
|
|
|
|
|
|
|
|
|
public int detectAppraiseFinish(SellerDepositOrderStatusConsistencyAsyncEvent event ){
|
|
|
logger.info("detectAppraiseFinish event {}", event);
|
|
|
long orderCode = event.getOrderCode();
|
|
|
long parentOrderCode = findoutParentOrderCode(orderCode);
|
|
|
int cnt =appraiseOrderMapper.selectSubOrderCntIncludeStatus(parentOrderCode,Arrays.asList(AppraiseOrderStatus.PLATFORM_RECEIVE.getCode()));
|
|
|
logger.info("detectAppraiseFinish event {},parentOrderCode {} PLATFORM_RECEIVE count {}", event, parentOrderCode, cnt);
|
|
|
if (cnt == 0){
|
|
|
int prows = platformFinishReceiveGoods(parentOrderCode);
|
|
|
logger.info("detectAppraiseFinish platformFinishReceiveGoods, orderCode {},parentOrderCode {} parent count {}",
|
|
|
orderCode, parentOrderCode, prows);
|
|
|
return prows;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
public void triggerStatusConsistencyCheck(long orderCode){
|
|
|
SellerDepositOrderStatusConsistencyAsyncEvent asyncEvent
|
|
|
= new SellerDepositOrderStatusConsistencyAsyncEvent(this::detectAppraiseFinish);
|
|
|
asyncEvent.setOrderCode(orderCode);
|
|
|
EventBusPublisher.publishEvent(asyncEvent);
|
|
|
}
|
|
|
} |
...
|
...
|
|