|
|
package com.yohoufo.order.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Sets;
|
|
|
import com.yoho.core.rabbitmq.YhProducer;
|
...
|
...
|
@@ -821,7 +821,7 @@ public class AppraiseService { |
|
|
public ApiResponse miniFaultReject(Long orderCode, OrderStatus targetStatus, boolean outTimeFlag) {
|
|
|
LOGGER.info("miniFaultReject enter , orderCode {} ,targetStatus {},outTimeFlag {}", orderCode, targetStatus, outTimeFlag);
|
|
|
OrderStatus expectStatus = OrderStatus.MINI_FAULT_WAITING;
|
|
|
ApiResponse apiResponse = new ApiResponse();
|
|
|
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
|
|
|
|
|
|
if (buyerOrder == null) {
|
...
|
...
|
@@ -841,99 +841,195 @@ public class AppraiseService { |
|
|
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();
|
|
|
return miniFaultRejected(orderCode, targetStatus, outTimeFlag, buyerOrder, buyerUid);
|
|
|
} else {
|
|
|
ApiResponse apiResponse = new ApiResponse();
|
|
|
LOGGER.warn("in miniFaultReject, buyer Order now status {}, expect expectStatus {}",
|
|
|
buyerOrder.getStatus(), expectStatus);
|
|
|
apiResponse.setCode(400);
|
|
|
apiResponse.setMessage("订单状态发生变化");
|
|
|
return apiResponse;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
|
|
|
long sellerOrderCode = sellerOrder.getOrderCode();
|
|
|
private ApiResponse miniFaultRejected(Long orderCode, OrderStatus targetStatus, boolean outTimeFlag, BuyerOrder buyerOrder, int buyerUid) {
|
|
|
|
|
|
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();
|
|
|
|
|
|
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
|
|
|
//async refund seller coupon
|
|
|
sellerOrderServiceDelegate.getSellerOrderService()
|
|
|
.asyncCancelWithCouponIfPresent(orderCode, targetStatus.getCode(), sellerOrderGoods);
|
|
|
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
|
|
|
long sellerOrderCode = sellerOrder.getOrderCode();
|
|
|
|
|
|
final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED;
|
|
|
final SellerOrderStatus targetSoStatus = SellerOrderStatus.MINI_FAULT_REJECT;
|
|
|
|
|
|
int ucnt = updateSellerOrderStatusAndCleanCache(sellerUid, sellerOrderCode, expectSOStatus, targetSoStatus,
|
|
|
skup, orderCode, buyerUid);
|
|
|
//将卖家的保证金扣掉10元后,剩余的钱退回给卖家
|
|
|
BigDecimal earnestMoney = sellerOrder.getEarnestMoney().subtract(new BigDecimal(miniFaultRejectPunishFee));
|
|
|
PaymentRequest refundReqOfSeller = refundEarnestMoney(SellerWalletDetail.Type.MINI_FAULT_REJECT, orderCode, sellerUid, sellerOrder, buyerUid, targetSoStatus, earnestMoney.doubleValue());
|
|
|
LOGGER.info("in miniFaultReject,refund ok, refundReqOfSeller {}", refundReqOfSeller);
|
|
|
|
|
|
//退买家的钱
|
|
|
BigDecimal goodsMoney = buyerOrder.getAmount();
|
|
|
boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler()
|
|
|
.loadPaymentRequest(buyerUid, orderCode, buyerOrder.getPayment(), goodsMoney)
|
|
|
.loadTargetOrderStatus(targetStatus)
|
|
|
.loadRefundAction(payRefundService::refund)
|
|
|
.loadLogger(LOGGER)
|
|
|
.loadSellerOrderGoods(sellerUid, skup)
|
|
|
.refund();
|
|
|
if (!refundGoodsMoneyFlag) {
|
|
|
apiResponse.setCode(400);
|
|
|
String content = "瑕疵不接受时,退用户" + sellerUid + "货款订单" + orderCode + "失败";
|
|
|
apiResponse.setMessage(content);
|
|
|
}
|
|
|
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
|
|
|
//async refund seller coupon
|
|
|
sellerOrderServiceDelegate.getSellerOrderService()
|
|
|
.asyncCancelWithCouponIfPresent(orderCode, targetStatus.getCode(), sellerOrderGoods);
|
|
|
|
|
|
//记录订单的状态变更信息
|
|
|
LOGGER.info("in miniFaultReject record status change, orderCode {},uid {} ,sellerUid {}", orderCode, buyerUid, sellerUid);
|
|
|
try {
|
|
|
//记录订单状态流转
|
|
|
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(), targetStatus.getCode());
|
|
|
final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED;
|
|
|
final SellerOrderStatus targetSoStatus = SellerOrderStatus.MINI_FAULT_REJECT;
|
|
|
|
|
|
//瑕疵不接受(用户不接受和超时不接受),只给买家发消息
|
|
|
buyerNoticeFacade.miniFaultUnAccept(buyerOrder, sellerOrderGoods, outTimeFlag);
|
|
|
sellerNoticeFacade.sellerMiniFaultUnAccept(sellerOrderGoods, orderCode, outTimeFlag);
|
|
|
int ucnt = updateSellerOrderStatusAndCleanCache(sellerUid, sellerOrderCode, expectSOStatus, targetSoStatus,
|
|
|
skup, orderCode, buyerUid);
|
|
|
//将卖家的保证金扣掉10元后,剩余的钱退回给卖家
|
|
|
BigDecimal earnestMoney = sellerOrder.getEarnestMoney().subtract(new BigDecimal(miniFaultRejectPunishFee));
|
|
|
PaymentRequest refundReqOfSeller = refundEarnestMoney(SellerWalletDetail.Type.MINI_FAULT_REJECT, orderCode, sellerUid, sellerOrder, buyerUid, targetSoStatus, earnestMoney.doubleValue());
|
|
|
LOGGER.info("in miniFaultReject,refund ok, refundReqOfSeller {}", refundReqOfSeller);
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
LOGGER.warn("in miniFaultReject orderStatusFlowService or notice fail orderCode {}", orderCode, ex);
|
|
|
} finally {
|
|
|
/// 物流信息异步执行
|
|
|
executorService.execute(() -> {
|
|
|
//退买家的钱
|
|
|
BigDecimal goodsMoney = buyerOrder.getAmount();
|
|
|
boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler()
|
|
|
.loadPaymentRequest(buyerUid, orderCode, buyerOrder.getPayment(), goodsMoney)
|
|
|
.loadTargetOrderStatus(targetStatus)
|
|
|
.loadRefundAction(payRefundService::refund)
|
|
|
.loadLogger(LOGGER)
|
|
|
.loadSellerOrderGoods(sellerUid, skup)
|
|
|
.refund();
|
|
|
if (!refundGoodsMoneyFlag) {
|
|
|
ApiResponse apiResponse = new ApiResponse();
|
|
|
apiResponse.setCode(400);
|
|
|
String content = "瑕疵不接受时,退用户" + sellerUid + "货款订单" + orderCode + "失败";
|
|
|
apiResponse.setMessage(content);
|
|
|
return apiResponse;
|
|
|
}
|
|
|
|
|
|
//记下订单的操作记录
|
|
|
if (outTimeFlag) {
|
|
|
//更新瑕疵确认结果
|
|
|
int updateNum = qualityCheckMapper.updateByOrderCode(orderCode, EnumQualityCheckStatus.REJECT_BY_OUTER_TIME.getCode(), DateUtil.getCurrentTimeSecond());
|
|
|
LOGGER.info("Buyer Order miniFaultReject by auto orderCode {} ,update quality check record status num {} ", orderCode, updateNum);
|
|
|
orderOperateRecordService.addRecord(orderCode, "系统操作", OperateTypeEnum.OPERATE_TYPE_QUALITY_MINI_FAULT_REJECT_BY_OUT_TIME);
|
|
|
} else {
|
|
|
//更新瑕疵确认结果
|
|
|
int updateNum = qualityCheckMapper.updateByOrderCode(orderCode, EnumQualityCheckStatus.REJECT_BY_BUYER.getCode(), DateUtil.getCurrentTimeSecond());
|
|
|
LOGGER.info("Buyer Order miniFaultReject by buyer orderCode {} ,update quality check record status num {} ", orderCode, updateNum);
|
|
|
orderOperateRecordService.addRecord(orderCode, "买家操作", OperateTypeEnum.OPERATE_TYPE_QUALITY_MINI_FAULT_REJECT);
|
|
|
}
|
|
|
//记录订单的状态变更信息
|
|
|
LOGGER.info("in miniFaultReject record status change, orderCode {},uid {} ,sellerUid {}", orderCode, buyerUid, sellerUid);
|
|
|
try {
|
|
|
//记录订单状态流转
|
|
|
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(), targetStatus.getCode());
|
|
|
|
|
|
//更新物流信息,写到最后
|
|
|
//先补加一条鉴定中物流
|
|
|
EnumExpressType expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
|
|
|
EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
|
|
|
EnumExpressDataOperateTransferCode operateTransferCode = EnumExpressDataOperateTransferCode.mini_fault_reject;
|
|
|
expressInfoService.saveOperateTransferExpressInfo(sellerUid, orderCode, expressType.getCode(), expressDataType, operateTransferCode);
|
|
|
//瑕疵不接受(用户不接受和超时不接受),只给买家发消息
|
|
|
buyerNoticeFacade.miniFaultUnAccept(buyerOrder, sellerOrderGoods, outTimeFlag);
|
|
|
sellerNoticeFacade.sellerMiniFaultUnAccept(sellerOrderGoods, orderCode, outTimeFlag);
|
|
|
|
|
|
operateTransferCode = EnumExpressDataOperateTransferCode.mini_fault_not_pass;
|
|
|
expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
|
|
|
expressDataType = EnumExpressDataType.operate_transfer;
|
|
|
expressInfoService.saveOperateTransferExpressInfo(sellerUid, orderCode, expressType.getCode(), expressDataType, operateTransferCode);
|
|
|
});
|
|
|
} catch (Exception ex) {
|
|
|
LOGGER.warn("in miniFaultReject orderStatusFlowService or notice fail orderCode {}", orderCode, ex);
|
|
|
} finally {
|
|
|
/// 物流信息异步执行
|
|
|
executorService.execute(() -> {
|
|
|
|
|
|
}
|
|
|
//记下订单的操作记录
|
|
|
if (outTimeFlag) {
|
|
|
//更新瑕疵确认结果
|
|
|
int updateNum = qualityCheckMapper.updateByOrderCode(orderCode, EnumQualityCheckStatus.REJECT_BY_OUTER_TIME.getCode(), DateUtil.getCurrentTimeSecond());
|
|
|
LOGGER.info("Buyer Order miniFaultReject by auto orderCode {} ,update quality check record status num {} ", orderCode, updateNum);
|
|
|
orderOperateRecordService.addRecord(orderCode, "系统操作", OperateTypeEnum.OPERATE_TYPE_QUALITY_MINI_FAULT_REJECT_BY_OUT_TIME);
|
|
|
} else {
|
|
|
//更新瑕疵确认结果
|
|
|
int updateNum = qualityCheckMapper.updateByOrderCode(orderCode, EnumQualityCheckStatus.REJECT_BY_BUYER.getCode(), DateUtil.getCurrentTimeSecond());
|
|
|
LOGGER.info("Buyer Order miniFaultReject by buyer orderCode {} ,update quality check record status num {} ", orderCode, updateNum);
|
|
|
orderOperateRecordService.addRecord(orderCode, "买家操作", OperateTypeEnum.OPERATE_TYPE_QUALITY_MINI_FAULT_REJECT);
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
LOGGER.warn("in miniFaultReject, buyer Order now status {}, expect expectStatus {}",
|
|
|
buyerOrder.getStatus(), expectStatus);
|
|
|
//更新物流信息,写到最后
|
|
|
//先补加一条鉴定中物流
|
|
|
EnumExpressType expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
|
|
|
EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
|
|
|
EnumExpressDataOperateTransferCode operateTransferCode = EnumExpressDataOperateTransferCode.mini_fault_reject;
|
|
|
expressInfoService.saveOperateTransferExpressInfo(sellerUid, orderCode, expressType.getCode(), expressDataType, operateTransferCode);
|
|
|
|
|
|
operateTransferCode = EnumExpressDataOperateTransferCode.mini_fault_not_pass;
|
|
|
expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
|
|
|
expressDataType = EnumExpressDataType.operate_transfer;
|
|
|
expressInfoService.saveOperateTransferExpressInfo(sellerUid, orderCode, expressType.getCode(), expressDataType, operateTransferCode);
|
|
|
});
|
|
|
|
|
|
}
|
|
|
ApiResponse apiResponse = new ApiResponse();
|
|
|
return apiResponse;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
public ApiResponse miniFaultRejectedHelp0407(Long orderCode, OrderStatus targetStatus, boolean outTimeFlag) {
|
|
|
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
|
|
|
Integer buyerUid = buyerOrder.getUid();
|
|
|
int sellerUid = buyerOrder.getSellerUid();
|
|
|
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
|
|
|
int skup = bog.getSkup();
|
|
|
|
|
|
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
|
|
|
|
|
|
|
|
|
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
|
|
|
|
|
|
final SellerOrderStatus targetSoStatus = SellerOrderStatus.MINI_FAULT_REJECT;
|
|
|
|
|
|
//将卖家的保证金扣掉10元后,剩余的钱退回给卖家
|
|
|
BigDecimal earnestMoney = sellerOrder.getEarnestMoney().subtract(new BigDecimal(miniFaultRejectPunishFee));
|
|
|
PaymentRequest refundReqOfSeller = refundEarnestMoney(SellerWalletDetail.Type.MINI_FAULT_REJECT, orderCode, sellerUid, sellerOrder, buyerUid, targetSoStatus, earnestMoney.doubleValue());
|
|
|
LOGGER.info("in miniFaultReject,refund ok, refundReqOfSeller {}", refundReqOfSeller);
|
|
|
|
|
|
//退买家的钱
|
|
|
BigDecimal goodsMoney = buyerOrder.getAmount();
|
|
|
boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler()
|
|
|
.loadPaymentRequest(buyerUid, orderCode, buyerOrder.getPayment(), goodsMoney)
|
|
|
.loadTargetOrderStatus(targetStatus)
|
|
|
.loadRefundAction(payRefundService::refund)
|
|
|
.loadLogger(LOGGER)
|
|
|
.loadSellerOrderGoods(sellerUid, skup)
|
|
|
.refund();
|
|
|
if (!refundGoodsMoneyFlag) {
|
|
|
ApiResponse apiResponse = new ApiResponse();
|
|
|
apiResponse.setCode(400);
|
|
|
apiResponse.setMessage("订单状态发生变化");
|
|
|
String content = "瑕疵不接受时,退用户" + sellerUid + "货款订单" + orderCode + "失败";
|
|
|
apiResponse.setMessage(content);
|
|
|
return apiResponse;
|
|
|
}
|
|
|
|
|
|
//记录订单的状态变更信息
|
|
|
LOGGER.info("in miniFaultReject record status change, orderCode {},uid {} ,sellerUid {}", orderCode, buyerUid, sellerUid);
|
|
|
try {
|
|
|
//记录订单状态流转
|
|
|
orderStatusFlowService.addAsy(buyerOrder.getOrderCode(), targetStatus.getCode());
|
|
|
|
|
|
//瑕疵不接受(用户不接受和超时不接受),只给买家发消息
|
|
|
buyerNoticeFacade.miniFaultUnAccept(buyerOrder, sellerOrderGoods, outTimeFlag);
|
|
|
sellerNoticeFacade.sellerMiniFaultUnAccept(sellerOrderGoods, orderCode, outTimeFlag);
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
LOGGER.warn("in miniFaultReject orderStatusFlowService or notice fail orderCode {}", orderCode, ex);
|
|
|
} finally {
|
|
|
/// 物流信息异步执行
|
|
|
executorService.execute(() -> {
|
|
|
|
|
|
//记下订单的操作记录
|
|
|
if (outTimeFlag) {
|
|
|
//更新瑕疵确认结果
|
|
|
int updateNum = qualityCheckMapper.updateByOrderCode(orderCode, EnumQualityCheckStatus.REJECT_BY_OUTER_TIME.getCode(), DateUtil.getCurrentTimeSecond());
|
|
|
LOGGER.info("Buyer Order miniFaultReject by auto orderCode {} ,update quality check record status num {} ", orderCode, updateNum);
|
|
|
orderOperateRecordService.addRecord(orderCode, "系统操作", OperateTypeEnum.OPERATE_TYPE_QUALITY_MINI_FAULT_REJECT_BY_OUT_TIME);
|
|
|
} else {
|
|
|
//更新瑕疵确认结果
|
|
|
int updateNum = qualityCheckMapper.updateByOrderCode(orderCode, EnumQualityCheckStatus.REJECT_BY_BUYER.getCode(), DateUtil.getCurrentTimeSecond());
|
|
|
LOGGER.info("Buyer Order miniFaultReject by buyer orderCode {} ,update quality check record status num {} ", orderCode, updateNum);
|
|
|
orderOperateRecordService.addRecord(orderCode, "买家操作", OperateTypeEnum.OPERATE_TYPE_QUALITY_MINI_FAULT_REJECT);
|
|
|
}
|
|
|
|
|
|
//更新物流信息,写到最后
|
|
|
//先补加一条鉴定中物流
|
|
|
EnumExpressType expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
|
|
|
EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
|
|
|
EnumExpressDataOperateTransferCode operateTransferCode = EnumExpressDataOperateTransferCode.mini_fault_reject;
|
|
|
expressInfoService.saveOperateTransferExpressInfo(sellerUid, orderCode, expressType.getCode(), expressDataType, operateTransferCode);
|
|
|
|
|
|
operateTransferCode = EnumExpressDataOperateTransferCode.mini_fault_not_pass;
|
|
|
expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
|
|
|
expressDataType = EnumExpressDataType.operate_transfer;
|
|
|
expressInfoService.saveOperateTransferExpressInfo(sellerUid, orderCode, expressType.getCode(), expressDataType, operateTransferCode);
|
|
|
});
|
|
|
|
|
|
}
|
|
|
ApiResponse apiResponse = new ApiResponse();
|
|
|
return apiResponse;
|
|
|
}
|
|
|
|
...
|
...
|
|