Authored by qinchao

鉴定不通过和质检不通过状态分开

... ... @@ -63,9 +63,7 @@ public class AppraiseController {
@IgnoreSignature
public ApiResponse appraiseFail(@RequestBody AppraiseExpressInfoBo appraiseExpressInfoBo) {
logger.info("in appraise Fail, req {}", appraiseExpressInfoBo);
OrderStatus expectStatus = OrderStatus.PLATFORM_CHECKING;
//1 鉴定不通过 ;2 质检不通过 ;
return appraiseService.appraiseFail(appraiseExpressInfoBo,expectStatus,true);
return appraiseService.appraiseFail(appraiseExpressInfoBo);
}
/**
... ... @@ -80,9 +78,7 @@ public class AppraiseController {
@IgnoreSignature
public ApiResponse appraiseFailWithoutExpress(@RequestBody AppraiseExpressInfoBo appraiseExpressInfoBo) {
logger.info("in appraiseFailWithoutExpress , req {}", appraiseExpressInfoBo);
OrderStatus expectStatus = OrderStatus.PLATFORM_RECEIVE;
//1 鉴定不通过 ;2 质检不通过 ;
return appraiseService.appraiseFail( appraiseExpressInfoBo,expectStatus,false);
return appraiseService.qualityCheckReject(appraiseExpressInfoBo);
}
... ...
... ... @@ -32,6 +32,7 @@ import com.yohoufo.order.service.proxy.OrderOperateRecordService;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import com.yohoufo.order.utils.PaymentHelper;
import com.yohoufo.order.utils.PubThreadFactory;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -408,14 +409,168 @@ public class AppraiseService {
}
/**
* 质检不通过 31->20
* 不发物流
*/
public ApiResponse qualityCheckReject(AppraiseExpressInfoBo appraiseExpressInfoBo){
LOGGER.info("qualityCheckReject enter , appraiseExpressInfoBo {} ", appraiseExpressInfoBo );
OrderStatus expectStatus = OrderStatus.PLATFORM_RECEIVE;
OrderStatus targetStatus = OrderStatus.QUALITY_CHECK_FAKE;
Long orderCode = appraiseExpressInfoBo.getOrderCode();
ApiResponse apiResponse=new ApiResponse();
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
if (buyerOrder == null){
LOGGER.warn("qualityCheckReject getOrderInfo order not exist, orderCode {}", orderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
}
if (buyerOrder.getStatus() != expectStatus.getCode()){
LOGGER.warn("qualityCheckReject expectStatus {}, actual status {}, orderCode {}", expectStatus,
buyerOrder.getStatus(), orderCode);
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
}
// 更新买家订单状态
int buyerUid = buyerOrder.getUid();
int sellerUid = buyerOrder.getSellerUid();
LOGGER.info("qualityCheckReject update buyer order {} ", buyerOrder);
int rows = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expectStatus.getCode(), targetStatus.getCode(),
DateUtil.getCurrentTimeSecond());
if (rows > 0){
RefundMoneyResultModel refundMoneyResultModel= operateMoneyWhenCheckFail(buyerOrder,orderCode,targetStatus);
boolean refundGoodsMoneyFlag = refundMoneyResultModel.isRefundGoodsMoneyFlag();
SellerOrderGoods sellerOrderGoods = refundMoneyResultModel.getSellerOrderGoods();
if (!refundGoodsMoneyFlag){
apiResponse.setCode(400);
String content = "质检不通过时,退用户" + sellerUid + "货款订单"+ orderCode +"失败";
apiResponse.setMessage(content);
}
//记录订单的状态变更信息
LOGGER.info("in qualityCheckReject record status change, orderCode {},uid {} ,sellerUid {}", orderCode,buyerUid,sellerUid);
try {
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(), targetStatus.getCode());
//质检不通过
inBoxFacade.noticeBuyerWhenQualityCheckNotPass(buyerUid, buyerOrder.getOrderCode(), sellerOrderGoods.getProductName());
inBoxFacade.sellerQualityCheckNotPass(sellerOrderGoods,orderCode);
}catch(Exception ex) {
LOGGER.warn("in qualityCheckReject orderStatusFlowService or notice fail orderCode {}", orderCode, ex);
}finally {
/// 物流信息异步执行
executorService.execute(()->{
//质检不通过,不发物流
//先补加一条鉴定中物流
EnumExpressType expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
EnumExpressDataOperateTransferCode operateTransferCode = EnumExpressDataOperateTransferCode.judging;
expressInfoService.saveOperateTransferExpressInfo(sellerUid,orderCode,expressType.getCode(),expressDataType,operateTransferCode);
//再加一个鉴定不通过的物流
operateTransferCode = EnumExpressDataOperateTransferCode.quality_check_reject;
expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
expressDataType = EnumExpressDataType.operate_transfer;
expressInfoService.saveOperateTransferExpressInfo(sellerUid,orderCode,expressType.getCode(),expressDataType,operateTransferCode);
});
}
}else{
LOGGER.warn("in qualityCheckReject, buyer Order now status {}, expect expectStatus {}",
buyerOrder.getStatus(), expectStatus);
apiResponse.setCode(400);
apiResponse.setMessage("订单状态发生变化");
}
return apiResponse;
}
@Data
class RefundMoneyResultModel{
boolean refundGoodsMoneyFlag;
SellerOrderGoods sellerOrderGoods;
}
/**
* 鉴定不通或者直接不通过
* 操作钱
*/
private RefundMoneyResultModel operateMoneyWhenCheckFail(BuyerOrder buyerOrder,Long orderCode,OrderStatus targetStatus){
LOGGER.info("operateMoney enter , orderCode {},targetStatus {} ", orderCode ,targetStatus);
RefundMoneyResultModel model = new RefundMoneyResultModel();
int buyerUid = buyerOrder.getUid();
int sellerUid = buyerOrder.getSellerUid();
//refund coupons of buyer
BuyerRefundCouponEvent brce = BuyerRefundCouponEvent.builder().bizCase(BuyerRefundCouponEvent.BizCase.APPRAISE_FAIL)
.uid(buyerUid).orderCode(orderCode).build();
EventBusPublisher.publishEvent(brce);
//
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
int skup = bog.getSkup();
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
long sellerOrderCode = sellerOrder.getOrderCode();
final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED;
final SellerOrderStatus targetSoStatus = SellerOrderStatus.APPRAISAL_FAIL_COMPENSATE;
SellerOrderGoods sellerOrderGoods = updateSellerOrderStatusAndCleanCache(sellerUid ,sellerOrderCode,expectSOStatus,targetSoStatus,
skup, orderCode, buyerUid);
//将卖家的保证金分账给平台和买家
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);
//再分账
//改成异步的分账,不关心分账执行结果
executorService.execute(()->{
LOGGER.info("in operateMoney,begin transfer async");
transferService.transfer(tmReq);
});
//退钱给买家
BigDecimal goodsMoney = buyerOrder.getAmount();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(skup);
boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler().loadPaymentRequest(buyerUid,orderCode,goodsMoney)
.loadBillLogEventBuilder(bleb)
.loadTargetOrderStatus(targetStatus)
.loadRefundAction(payRefundService::refund)
.loadLogger(LOGGER)
.refund();
model.setRefundGoodsMoneyFlag(refundGoodsMoneyFlag);
model.setSellerOrderGoods(sellerOrderGoods);
return model;
}
/**
* 鉴定不通过 3->13
* 更新发到卖家的物流信息
* 将卖家的保证金分账给平台和买家
* 更新买家订单状态
* appraiseFlag 鉴定标志,//true 鉴定不通过 ;false 质检不通过 ;
* @return
*/
public ApiResponse appraiseFail(AppraiseExpressInfoBo appraiseExpressInfoBo,OrderStatus expectStatus,boolean appraiseNotPassFlag){
LOGGER.info("appraiseFail enter , appraiseExpressInfoBo {} ,appraiseNotPassFlag {}", appraiseExpressInfoBo ,appraiseNotPassFlag);
public ApiResponse appraiseFail(AppraiseExpressInfoBo appraiseExpressInfoBo ){
LOGGER.info("appraiseFail enter , appraiseExpressInfoBo {} ,appraiseNotPassFlag {}", appraiseExpressInfoBo );
OrderStatus expectStatus = OrderStatus.PLATFORM_CHECKING;
OrderStatus targetStatus = OrderStatus.CHECKING_FAKE;
Long orderCode = appraiseExpressInfoBo.getOrderCode();
Integer expressCompanyId = appraiseExpressInfoBo.getExpressCompanyId();
String wayBillCode = appraiseExpressInfoBo.getWayBillCode();
... ... @@ -437,64 +592,16 @@ public class AppraiseService {
}
// 更新买家订单状态 为鉴定不通过
int buyerUid = buyerOrder.getUid();
OrderStatus targetStatus = OrderStatus.CHECKING_FAKE;
int sellerUid = buyerOrder.getSellerUid();
LOGGER.info("appraiseFail update buyer order {} ", buyerOrder);
int rows = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expectStatus.getCode(), targetStatus.getCode(),
DateUtil.getCurrentTimeSecond());
if (rows > 0){
//refund coupons of buyer
BuyerRefundCouponEvent brce = BuyerRefundCouponEvent.builder().bizCase(BuyerRefundCouponEvent.BizCase.APPRAISE_FAIL)
.uid(buyerUid).orderCode(orderCode).build();
EventBusPublisher.publishEvent(brce);
//
int sellerUid = buyerOrder.getSellerUid();
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
int skup = bog.getSkup();
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
long sellerOrderCode = sellerOrder.getOrderCode();
final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED;
final SellerOrderStatus targetSoStatus = SellerOrderStatus.APPRAISAL_FAIL_COMPENSATE;
SellerOrderGoods sellerOrderGoods = updateSellerOrderStatusAndCleanCache(sellerUid ,sellerOrderCode,expectSOStatus,targetSoStatus,
skup, orderCode, buyerUid);
//将卖家的保证金分账给平台和买家
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);
//再分账
//改成异步的分账,不关心分账执行结果
executorService.execute(()->{
LOGGER.info("in appraiseFail,begin transfer async");
transferService.transfer(tmReq);
});
RefundMoneyResultModel refundMoneyResultModel= operateMoneyWhenCheckFail(buyerOrder,orderCode,targetStatus);
boolean refundGoodsMoneyFlag = refundMoneyResultModel.isRefundGoodsMoneyFlag();
SellerOrderGoods sellerOrderGoods = refundMoneyResultModel.getSellerOrderGoods();
//退钱给买家
BigDecimal goodsMoney = buyerOrder.getAmount();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(skup);
boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler().loadPaymentRequest(buyerUid,orderCode,goodsMoney)
.loadBillLogEventBuilder(bleb)
.loadTargetOrderStatus(targetStatus)
.loadRefundAction(payRefundService::refund)
.loadLogger(LOGGER)
.refund();
if (!refundGoodsMoneyFlag){
apiResponse.setCode(400);
String content = "鉴定不通过时,退用户" + sellerUid + "货款订单"+ orderCode +"失败";
... ... @@ -506,16 +613,9 @@ public class AppraiseService {
try {
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(), targetStatus.getCode());
//TODO 消息
if(appraiseNotPassFlag){
//鉴定不通过 ,其余的情况不发消息,改成寄回的时候再发消息
inBoxFacade.noticeSellerWhenAppraiseFail(sellerOrderGoods, orderCode, wayBillCode);
inBoxFacade.buyerGetEarnestMoneyWhenAppraiseFail(buyerUid, buyerOrder.getOrderCode(), sellerOrderGoods.getProductName());
}else {
//质检不通过
inBoxFacade.noticeBuyerWhenQualityCheckNotPass(buyerUid, buyerOrder.getOrderCode(), sellerOrderGoods.getProductName());
inBoxFacade.sellerQualityCheckNotPass(sellerOrderGoods,orderCode);
}
//鉴定不通过 ,其余的情况不发消息,改成寄回的时候再发消息
inBoxFacade.noticeSellerWhenAppraiseFail(sellerOrderGoods, orderCode, wayBillCode);
inBoxFacade.buyerGetEarnestMoneyWhenAppraiseFail(buyerUid, buyerOrder.getOrderCode(), sellerOrderGoods.getProductName());
}catch(Exception ex) {
LOGGER.warn("in appraiseFail orderStatusFlowService or notice fail orderCode {}", orderCode, ex);
... ... @@ -524,30 +624,14 @@ public class AppraiseService {
executorService.execute(()->{
//更新物流信息,写到最后
//鉴定不通过,发物流
if(appraiseNotPassFlag){
//补:鉴定不通过
EnumExpressType expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
EnumExpressDataOperateTransferCode operateTransferCode = EnumExpressDataOperateTransferCode.judge_reject;
expressInfoService.saveOperateTransferExpressInfo(sellerUid,orderCode,expressType.getCode(),expressDataType,operateTransferCode);
//发货物流(平台已发货)
expressInfoService.returnBackOrderCauseOfJudgeFailure(sellerUid, expressCompanyId, orderCode, wayBillCode, depotNum,mobile);
}else {
//质检不通过,不发物流
//先补加一条鉴定中物流
EnumExpressType expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
EnumExpressDataOperateTransferCode operateTransferCode = EnumExpressDataOperateTransferCode.judging;
expressInfoService.saveOperateTransferExpressInfo(sellerUid,orderCode,expressType.getCode(),expressDataType,operateTransferCode);
//再加一个鉴定不通过的物流
operateTransferCode = EnumExpressDataOperateTransferCode.quality_check_reject;
expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
expressDataType = EnumExpressDataType.operate_transfer;
expressInfoService.saveOperateTransferExpressInfo(sellerUid,orderCode,expressType.getCode(),expressDataType,operateTransferCode);
}
//补:鉴定不通过
EnumExpressType expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
EnumExpressDataOperateTransferCode operateTransferCode = EnumExpressDataOperateTransferCode.judge_reject;
expressInfoService.saveOperateTransferExpressInfo(sellerUid,orderCode,expressType.getCode(),expressDataType,operateTransferCode);
//发货物流(平台已发货)
expressInfoService.returnBackOrderCauseOfJudgeFailure(sellerUid, expressCompanyId, orderCode, wayBillCode, depotNum,mobile);
});
}
... ...