|
|
package com.yohoufo.order.service.support;
|
|
|
|
|
|
import com.yohobuy.ufo.model.order.common.OrderStatus;
|
|
|
import com.yohobuy.ufo.model.order.common.TabType;
|
|
|
import com.yohoufo.dal.order.model.BuyerOrder;
|
|
|
import com.yohoufo.order.constants.MetaKey;
|
|
|
import com.yohoufo.order.model.bo.BidOrderMetaBo;
|
|
|
import com.yohoufo.order.model.bo.DetailItem;
|
|
|
import com.yohoufo.order.mq.DelayTime;
|
|
|
import com.yohoufo.order.utils.TimeUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
@Component
|
|
|
public class OrderStatusDetailItemFactory {
|
|
|
|
|
|
@Autowired
|
|
|
private BuyerOrderMetaMapperSupport buyerOrderMetaMapperSupport;
|
|
|
|
|
|
/**
|
|
|
* @param buyerOrder
|
|
|
* @param orderStatus
|
|
|
* @param tabType
|
|
|
* @return
|
|
|
*/
|
|
|
public DetailItem get(BuyerOrder buyerOrder, OrderStatus orderStatus, TabType tabType) {
|
|
|
DetailItem detailItem = null;
|
|
|
if (buyerOrder.isBidOrder()) {
|
|
|
detailItem = getBidOrderDetailItem(buyerOrder, orderStatus, tabType);
|
|
|
}
|
|
|
|
|
|
return detailItem;
|
|
|
}
|
|
|
|
|
|
private DetailItem getBidOrderDetailItem(BuyerOrder buyerOrder, OrderStatus orderStatus, TabType tabType) {
|
|
|
DetailItem detailItem = null;
|
|
|
int createTime = buyerOrder.getCreateTime();
|
|
|
switch (orderStatus) {
|
|
|
case WAITING_PAY_DEPOSIT:
|
|
|
detailItem = new WaitingPayDepositItem(createTime, tabType);
|
|
|
break;
|
|
|
case BIDING:
|
|
|
BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectByMetaKey(buyerOrder.getUid(), buyerOrder.getOrderCode(), MetaKey.BID_KEY, BidOrderMetaBo.class);
|
|
|
detailItem = new BidingOrderItem(bidOrderMetaBo.getDay());
|
|
|
break;
|
|
|
case WAITING_PAY:
|
|
|
detailItem = new WaitingPayItem(createTime, tabType);
|
|
|
break;
|
|
|
case BUYER_CANCEL_BEFORE_PAY:
|
|
|
detailItem = new CancelBeforePayItem(tabType);
|
|
|
break;
|
|
|
case BUYER_CANCEL_TIMEOUT:
|
|
|
detailItem = new CancelTimeOutBeforePayItem(tabType);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
return detailItem;
|
|
|
}
|
|
|
|
|
|
|
|
|
private abstract class AbstractOrderDetailItem implements DetailItem {
|
|
|
|
|
|
public final static String EMPTY_DESC = "";
|
|
|
|
|
|
/**
|
|
|
* 求购定金支付
|
|
|
*/
|
|
|
public final static String WAITING_PAY_DEPOSIT_DESC = "请在%s分钟内支付,超时将自动取消";
|
|
|
|
|
|
/**
|
|
|
* 买家求购中
|
|
|
*/
|
|
|
public final static String BIDING_DESC = "如果%s天内未完成匹配,定金将退回你的支付账户";
|
|
|
|
|
|
/**
|
|
|
* 卖家变现后买家未支付
|
|
|
*/
|
|
|
public final static String WAITING_PAY_BUYER_DESC = "支付完成后,定金将原路返回,如果超时未能完成支付,定金将补偿给卖家";
|
|
|
|
|
|
|
|
|
public final static String WAITING_PAY_SELLER_DESC = "如果买家未能在%s小时完成支付,你将获得定金赔偿";
|
|
|
|
|
|
public final static String CANCEL_BEFORE_PAY_BUYER_DESC = "您已取消商品购买,您的定金已赔偿给卖家";
|
|
|
|
|
|
public final static String CANCEL_BEFORE_PAY_SELLER_DESC = "买家取消订单,您的商品已下架,您已获得买家定金赔偿";
|
|
|
|
|
|
public final static String CANCEL_TIMEOUT_BEFORE_PAY_BUYER_DESC = "您支付超时,您的定金已赔偿给卖家";
|
|
|
|
|
|
public final static String CANCEL_TIMEOUT_BEFORE_PAY_SELLER_DESC = "买家付款超时,系统取消订单,您已获得买家定金赔偿";
|
|
|
|
|
|
protected int createTime;
|
|
|
protected TabType tabType;
|
|
|
|
|
|
public AbstractOrderDetailItem() {
|
|
|
this(0, TabType.BUY);
|
|
|
}
|
|
|
|
|
|
public AbstractOrderDetailItem(TabType tabType) {
|
|
|
this(0, tabType);
|
|
|
}
|
|
|
|
|
|
public AbstractOrderDetailItem(int createTime, TabType tabType) {
|
|
|
this.createTime = createTime;
|
|
|
this.tabType = tabType;
|
|
|
}
|
|
|
|
|
|
public int getLeftTime() {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
protected int calLeftTime(int timeout) {
|
|
|
return TimeUtils.calLeftTime(timeout, this.createTime);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 待付定金
|
|
|
*/
|
|
|
private class WaitingPayDepositItem extends AbstractOrderDetailItem {
|
|
|
public WaitingPayDepositItem(int createTime, TabType tabType) {
|
|
|
super(createTime, tabType);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getDetailDesc() {
|
|
|
return String.format(WAITING_PAY_DEPOSIT_DESC, DelayTime.BUYER_ORDER_WAITING_PAY_DEPOSIT);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int getLeftTime() {
|
|
|
return calLeftTime(DelayTime.BUYER_ORDER_WAITING_PAY_DEPOSIT);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 求购中
|
|
|
*/
|
|
|
private class BidingOrderItem extends AbstractOrderDetailItem {
|
|
|
int day = 1;
|
|
|
|
|
|
public BidingOrderItem(int day) {
|
|
|
this.day = day;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getDetailDesc() {
|
|
|
return String.format(BIDING_DESC, day);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 待支付
|
|
|
*/
|
|
|
private class WaitingPayItem extends AbstractOrderDetailItem {
|
|
|
public WaitingPayItem(int createTime, TabType tabType) {
|
|
|
super(createTime, tabType);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getDetailDesc() {
|
|
|
switch (tabType) {
|
|
|
case BUY:
|
|
|
return WAITING_PAY_BUYER_DESC;
|
|
|
case SELL:
|
|
|
return String.format(WAITING_PAY_SELLER_DESC, DelayTime.BUYER_BID_ORDER_WAITING_PAY);
|
|
|
default:
|
|
|
return EMPTY_DESC;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int getLeftTime() {
|
|
|
return calLeftTime(DelayTime.BUYER_BID_ORDER_WAITING_PAY);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private class CancelBeforePayItem extends AbstractOrderDetailItem {
|
|
|
public CancelBeforePayItem(TabType tabType) {
|
|
|
super(tabType);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getDetailDesc() {
|
|
|
switch (tabType) {
|
|
|
case BUY:
|
|
|
return CANCEL_BEFORE_PAY_BUYER_DESC;
|
|
|
case SELL:
|
|
|
return CANCEL_BEFORE_PAY_SELLER_DESC;
|
|
|
default:
|
|
|
return EMPTY_DESC;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private class CancelTimeOutBeforePayItem extends AbstractOrderDetailItem {
|
|
|
public CancelTimeOutBeforePayItem(TabType tabType) {
|
|
|
super(tabType);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getDetailDesc() {
|
|
|
switch (tabType) {
|
|
|
case BUY:
|
|
|
return CANCEL_TIMEOUT_BEFORE_PAY_BUYER_DESC;
|
|
|
case SELL:
|
|
|
return CANCEL_TIMEOUT_BEFORE_PAY_SELLER_DESC;
|
|
|
default:
|
|
|
return EMPTY_DESC;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|