Authored by wujiexiang

求购 -- 赔偿定金给卖家

... ... @@ -137,7 +137,8 @@ public class ActionStatusHold {
SellerOrderStatus.HAS_PAYED.getCode(),
// 支付成功回调超时,但已经超时取消了,这种场景可以退款
SellerOrderStatus.TIMEOUT_CANCEL.getCode(),
SellerOrderStatus.SELf_CANCEL_PAY.getCode());
SellerOrderStatus.SELf_CANCEL_PAY.getCode(),
SellerOrderStatus.BUYER_BID_CANCEL_PAY_AFTER_BIND.getCode());
}
//
static List<Integer> CanCancelStatus;
... ...
... ... @@ -29,7 +29,6 @@ import com.yohoufo.order.service.IExpressInfoService;
import com.yohoufo.order.service.IOrderDetailService;
import com.yohoufo.order.service.seller.support.SkupTypeCodeSupport;
import com.yohoufo.order.service.support.BuyerOrderMetaMapperSupport;
import com.yohoufo.order.service.support.OrderStatusDetailItemFactory;
import com.yohoufo.order.utils.*;
import lombok.Builder;
import org.apache.commons.collections.CollectionUtils;
... ...
... ... @@ -16,10 +16,9 @@ import com.yohoufo.order.constants.ViewType;
import com.yohoufo.order.model.bo.DetailItem;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.service.IOrderListService;
import com.yohoufo.order.service.support.OrderStatusDetailItemFactory;
import com.yohoufo.order.service.support.BuyerOrderStatusDetailItemFactory;
import com.yohoufo.order.utils.BuyerOrderUtils;
import com.yohoufo.order.utils.OrderAssist;
import com.yohoufo.order.utils.SellerGoodsHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -62,7 +61,7 @@ public abstract class AbsOrderListService extends AbsOrderViewService implements
SellerOrderMapper sellerOrderMapper;
@Autowired
OrderStatusDetailItemFactory orderStatusDetailItemFactory;
BuyerOrderStatusDetailItemFactory orderStatusDetailItemFactory;
/**
* 获取鉴定视频
... ...
... ... @@ -12,7 +12,7 @@ import com.yohoufo.order.model.bo.DetailItem;
import com.yohoufo.order.model.dto.BuyerPenaltyCalResult;
import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler;
import com.yohoufo.order.service.support.BuyerOrderButtonFormatFunction;
import com.yohoufo.order.service.support.OrderStatusDetailItemFactory;
import com.yohoufo.order.service.support.BuyerOrderStatusDetailItemFactory;
import com.yohoufo.order.service.wrapper.OrderTimeoutContext;
import com.yohoufo.order.service.wrapper.OrderTimeoutFactory;
import com.yohoufo.order.service.wrapper.TimeoutWrapper;
... ... @@ -42,7 +42,7 @@ public abstract class AbsOrderViewService {
TradeBillsService tradeBillsService;
@Autowired
protected OrderStatusDetailItemFactory orderStatusDetailItemFactory;
protected BuyerOrderStatusDetailItemFactory orderStatusDetailItemFactory;
public abstract Logger getLogger();
... ...
... ... @@ -401,7 +401,7 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
targetStatus = OrderStatus.BUYER_CANCEL_BEFORE_DEPOSIT_PAY;
break;
case WAITING_PAY:
targetStatus = OrderStatus.BUYER_CANCEL_TIMEOUT;
targetStatus = OrderStatus.BUYER_BID_CANCEL_PAY;;
break;
default:
logger.warn("in buyer auto cancel fail uid {} order code {} expectStatus {}",
... ... @@ -488,8 +488,8 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
buyerOrderStateChangers.selectOneToChange(buyerOrder, OrderStatus.BIDING, targetStatus);
break;
case WAITING_PAY:
targetStatus = OrderStatus.BUYER_CANCEL_BEFORE_PAY;
if (buyerOrder.isBidOrder()) {
targetStatus = OrderStatus.BUYER_BID_CANCEL_PAY;
RequestedCancelEventStatusChangeBuyerOrder statusChangeBuyerOrder = new RequestedCancelEventStatusChangeBuyerOrder(buyerOrder,
expectStatus,
targetStatus,
... ... @@ -497,6 +497,7 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
orderRequest.getOrderCancelEvent());
buyerOrderStateChangers.selectOneToChange(statusChangeBuyerOrder);
} else {
targetStatus = OrderStatus.BUYER_CANCEL_BEFORE_PAY;
cancelBeforePaid(orderRequest, node, expectStatus, targetStatus);
//取消事件
orderChangeListenerContainer.fireAsyncEvent(new BuyerOrderChangeEvent(buyerOrder, BuyerOrderChangeEvent.BizCase.CANCEL_BYBUYER, targetStatus));
... ...
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
... ...
... ... @@ -13,7 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class OrderStatusDetailItemFactory {
public class BuyerOrderStatusDetailItemFactory {
@Autowired
private BuyerOrderMetaMapperSupport buyerOrderMetaMapperSupport;
... ... @@ -47,11 +47,11 @@ public class OrderStatusDetailItemFactory {
case WAITING_PAY:
detailItem = new WaitingPayItem(createTime, tabType);
break;
case BUYER_CANCEL_BEFORE_PAY:
detailItem = new CancelBeforePayItem(tabType);
case BUYER_BID_CANCEL_PAY:
detailItem = new BuyerBidCancelPayItem(tabType);
break;
case BUYER_CANCEL_TIMEOUT:
detailItem = new CancelTimeOutBeforePayItem(tabType);
case BUYER_BID_CANCEL_PAY_TIMEOUT:
detailItem = new BuyerBidCancelPayTimeOutItem(tabType);
break;
default:
break;
... ... @@ -90,6 +90,7 @@ public class OrderStatusDetailItemFactory {
public final static String CANCEL_TIMEOUT_BEFORE_PAY_SELLER_DESC = "买家付款超时,系统取消订单,您已获得买家定金赔偿";
//创建时间 秒
protected int createTime;
//操作限制 单位秒
private int timeOutLimit;
... ... @@ -175,15 +176,15 @@ public class OrderStatusDetailItemFactory {
case BUY:
return WAITING_PAY_BUYER_DESC;
case SELL:
return String.format(WAITING_PAY_SELLER_DESC, DelayTime.BUYER_BID_ORDER_WAITING_PAY);
return String.format(WAITING_PAY_SELLER_DESC, DelayTime.BUYER_BID_ORDER_WAITING_PAY / 60);
default:
return EMPTY_DESC;
}
}
}
private class CancelBeforePayItem extends AbstractOrderDetailItem {
public CancelBeforePayItem(TabType tabType) {
private class BuyerBidCancelPayItem extends AbstractOrderDetailItem {
public BuyerBidCancelPayItem(TabType tabType) {
super(tabType);
}
... ... @@ -200,8 +201,8 @@ public class OrderStatusDetailItemFactory {
}
}
private class CancelTimeOutBeforePayItem extends AbstractOrderDetailItem {
public CancelTimeOutBeforePayItem(TabType tabType) {
private class BuyerBidCancelPayTimeOutItem extends AbstractOrderDetailItem {
public BuyerBidCancelPayTimeOutItem(TabType tabType) {
super(tabType);
}
... ...