|
|
package com.yohoufo.order.service.impl.statechange;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderStatus;
|
|
|
import com.yohobuy.ufo.model.order.common.Payment;
|
|
|
import com.yohobuy.ufo.model.order.common.SellerOrderStatus;
|
|
|
import com.yohobuy.ufo.model.order.common.SkupStatus;
|
|
|
import com.yohoufo.common.alarm.EventBusPublisher;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.dal.order.SellerOrderMapper;
|
|
|
import com.yohoufo.dal.order.model.*;
|
|
|
import com.yohoufo.order.common.RefundCase;
|
|
|
import com.yohoufo.order.common.TransferCase;
|
|
|
import com.yohoufo.order.event.BillLogEvent;
|
|
|
import com.yohoufo.order.event.PayConfirmEvent;
|
|
|
import com.yohoufo.order.model.PayQueryBo;
|
|
|
import com.yohoufo.order.model.RequestedCancelEventStatusChangeBuyerOrder;
|
|
|
import com.yohoufo.order.model.RequestedStatusChangeBuyerOrder;
|
|
|
import com.yohoufo.order.model.request.PaymentRequest;
|
|
|
import com.yohoufo.order.model.request.TranseferCellNode;
|
|
|
import com.yohoufo.order.model.request.TransferMoneyRequest;
|
|
|
import com.yohoufo.order.service.AbstractBuyerOrderStateChanger;
|
|
|
import com.yohoufo.order.service.handler.RefundEarnestMoneyHandler;
|
|
|
import com.yohoufo.order.service.impl.PayRefundService;
|
|
|
import com.yohoufo.order.service.impl.TransferService;
|
|
|
import com.yohoufo.order.service.listener.BuyerOrderChangeEvent;
|
|
|
import com.yohoufo.order.service.pay.AbstractPayService;
|
|
|
import com.yohoufo.order.service.seller.setting.SellerService;
|
|
|
import com.yohoufo.order.utils.PaymentHelper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
import static com.yohobuy.ufo.model.order.common.OrderStatus.*;
|
|
|
|
...
|
...
|
@@ -38,6 +51,15 @@ public class BuyerOrderWaitingPayCancelChanger extends AbstractBuyerOrderStateCh |
|
|
@Autowired
|
|
|
private TransferService transferService;
|
|
|
|
|
|
@Autowired
|
|
|
private SellerOrderMapper sellerOrderMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private SellerService sellerService;
|
|
|
|
|
|
@Autowired
|
|
|
private PayRefundService payRefundService;
|
|
|
|
|
|
@Override
|
|
|
protected boolean beforeChange(RequestedCancelEventStatusChangeBuyerOrder statusChangeBuyerOrder) {
|
|
|
BuyerOrder buyerOrder = statusChangeBuyerOrder.getBuyerOrder();
|
...
|
...
|
@@ -84,22 +106,36 @@ public class BuyerOrderWaitingPayCancelChanger extends AbstractBuyerOrderStateCh |
|
|
@Override
|
|
|
protected Collection<Statement> afterStatements(RequestedCancelEventStatusChangeBuyerOrder statusChangeBuyerOrder) {
|
|
|
BuyerOrder buyerOrder = statusChangeBuyerOrder.getBuyerOrder();
|
|
|
List<Statement> statements = new ArrayList<>();
|
|
|
if (buyerOrder.isBidOrder()) {
|
|
|
statements.add(() -> bidOrderAfterStatement(buyerOrder));
|
|
|
statements.add(() -> cacheCleaner.cleanSellerAndBuyerOrderDetailAndList(buyerOrder.getSellerUid(), buyerOrder.getUid(), buyerOrder.getOrderCode()));
|
|
|
} else {
|
|
|
//nothing
|
|
|
|
|
|
if (!buyerOrder.isBidOrder()) {
|
|
|
logger.warn("[{}] is not bid order", buyerOrder.getOrderCode());
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
return statements;
|
|
|
|
|
|
final AtomicReference<Integer> skupRefer = new AtomicReference();
|
|
|
skupRefer.get();
|
|
|
return Lists.newArrayList(
|
|
|
() -> transferDepositToSeller(buyerOrder),
|
|
|
() -> skupRefer.set(getSkup(buyerOrder)),
|
|
|
() -> cancelSellerOrder(skupRefer.get()),
|
|
|
() -> refundSellerEarnestMoney(skupRefer.get(), buyerOrder, statusChangeBuyerOrder.getTargetStatus()),
|
|
|
() -> cacheCleaner.cleanSellerAndBuyerOrderDetailAndList(buyerOrder.getSellerUid(), buyerOrder.getUid(), buyerOrder.getOrderCode())
|
|
|
);
|
|
|
}
|
|
|
|
|
|
|
|
|
private int getSkup(BuyerOrder buyerOrder) {
|
|
|
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(), buyerOrder.getOrderCode());
|
|
|
int skup = buyerOrderGoods.getSkup();
|
|
|
return skup;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 求购订单
|
|
|
* 定金赔偿给卖家
|
|
|
*
|
|
|
* @param buyerOrder
|
|
|
*/
|
|
|
private void bidOrderAfterStatement(BuyerOrder buyerOrder) {
|
|
|
private void transferDepositToSeller(BuyerOrder buyerOrder) {
|
|
|
//定金金额
|
|
|
double depositAmount = getDepositAmount(buyerOrder);
|
|
|
// //定金赔偿给卖家
|
...
|
...
|
@@ -113,6 +149,74 @@ public class BuyerOrderWaitingPayCancelChanger extends AbstractBuyerOrderStateCh |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 取消seller order
|
|
|
*
|
|
|
* @param skup
|
|
|
*/
|
|
|
private void cancelSellerOrder(int skup) {
|
|
|
logger.info("cancel seller order by skup:{}", skup);
|
|
|
SellerOrderGoods targetGoods = new SellerOrderGoods();
|
|
|
targetGoods.setId(skup);
|
|
|
targetGoods.setStatus(SkupStatus.BUYER_BID_CANCEL_PAY_AFTER_BIND.getCode());
|
|
|
targetGoods.setExceptStatus(SkupStatus.SELL_OUT.getCode());
|
|
|
boolean result = sellerOrderGoodsMapper.updateStatusBySkpu(targetGoods) > 0;
|
|
|
logger.info("seller order goods was updated by skup:{},result:{}", skup, result);
|
|
|
SellerOrder soc = new SellerOrder();
|
|
|
soc.setStatus(SellerOrderStatus.BUYER_BID_CANCEL_PAY_AFTER_BIND.getCode());
|
|
|
soc.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
result = sellerOrderMapper.updateBySkups(soc, Arrays.asList(skup)) > 0;
|
|
|
logger.info("seller order goods updated by skup:{},result:{}", skup, result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 退还卖家的保证金
|
|
|
* @param skup
|
|
|
* @param buyerOrder
|
|
|
* @param targetOrderStatus
|
|
|
*/
|
|
|
private void refundSellerEarnestMoney(int skup, BuyerOrder buyerOrder, OrderStatus targetOrderStatus) {
|
|
|
int buyerUid = buyerOrder.getUid();
|
|
|
long orderCode = buyerOrder.getOrderCode();
|
|
|
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
|
|
|
int sellerUid = sellerOrder.getUid();
|
|
|
long sellerOrderCode = sellerOrder.getOrderCode();
|
|
|
BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
|
|
|
Integer payment = sellerOrder.getPayment() == null ? 0 : sellerOrder.getPayment();
|
|
|
PaymentRequest refundReqOfSeller = PaymentRequest.builder().uid(sellerUid).refundCase(RefundCase.SELLER_EARNEST_MONEY)
|
|
|
.orderCode(sellerOrderCode).refundAmount(earnestMoney.doubleValue())
|
|
|
.payment(payment)
|
|
|
.build();
|
|
|
boolean sellerIsSuper = sellerService.isSuperEntrySeller(sellerUid);
|
|
|
refundReqOfSeller.setSuper(sellerIsSuper);
|
|
|
if (!sellerIsSuper && PaymentHelper.isWallet(payment)) {
|
|
|
|
|
|
MerchantOrderAttachInfo moai = MerchantOrderAttachInfo.builder().uid(sellerUid)
|
|
|
.orderCode(sellerOrderCode).skup(skup).earnestMoney(sellerOrder.getEarnestMoney())
|
|
|
.type(SellerWalletDetail.Type.BUYER_CANCEL_NO_DELIVERY.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);
|
|
|
logger.info("in refundSellerEarnestMoney call begin payRefundService.refund seller, buyerUid {}, orderCode {}, skup {} refundReqOfSeller {}",
|
|
|
buyerUid, orderCode, skup, refundReqOfSeller);
|
|
|
boolean result = new RefundEarnestMoneyHandler()
|
|
|
.loadRefundAction(payRefundService::refund)
|
|
|
.loadBillLogEventBuilder(bleb)
|
|
|
.loadPaymentRequest(refundReqOfSeller)
|
|
|
.loadBuyer(buyerUid, orderCode, targetOrderStatus)
|
|
|
.loadSeller(sellerUid, sellerIsSuper, null, null)
|
|
|
.loadLogger(logger)
|
|
|
.refund();
|
|
|
|
|
|
logger.info("in refundSellerEarnestMoney call after payRefundService.refund seller, buyerUid {}, orderCode {}, skup {} result {}",
|
|
|
buyerUid, orderCode, skup, result);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @param buyerUid
|
|
|
* @param buyerOrderCode
|
|
|
* @param sellerUid
|
...
|
...
|
@@ -143,6 +247,6 @@ public class BuyerOrderWaitingPayCancelChanger extends AbstractBuyerOrderStateCh |
|
|
OrderStatus targetStatus = statusChangeBuyerOrder.getTargetStatus();
|
|
|
return statusChangeBuyerOrder instanceof RequestedCancelEventStatusChangeBuyerOrder
|
|
|
&& sourceStatus == WAITING_PAY
|
|
|
&& (targetStatus == BUYER_CANCEL_BEFORE_PAY || targetStatus == BUYER_CANCEL_TIMEOUT);
|
|
|
&& (targetStatus == BUYER_BID_CANCEL_PAY || targetStatus == BUYER_BID_CANCEL_PAY_TIMEOUT);
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|