...
|
...
|
@@ -11,10 +11,7 @@ import com.yohoufo.dal.order.model.BuyerOrder; |
|
|
import com.yohoufo.dal.order.model.BuyerOrderGoods;
|
|
|
import com.yohoufo.dal.order.model.SellerOrder;
|
|
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
|
|
import com.yohoufo.order.common.ActionStatusHold;
|
|
|
import com.yohoufo.order.common.OrderCodeType;
|
|
|
import com.yohoufo.order.common.OrderStatus;
|
|
|
import com.yohoufo.order.common.SellerOrderStatus;
|
|
|
import com.yohoufo.order.common.*;
|
|
|
import com.yohoufo.order.event.ErpCancelSellerOrderEvent;
|
|
|
import com.yohoufo.order.event.OrderCancelEvent;
|
|
|
import com.yohoufo.order.model.request.PaymentRequest;
|
...
|
...
|
@@ -27,16 +24,15 @@ import com.yohoufo.order.service.impl.visitor.UserCancelCase; |
|
|
import com.yohoufo.order.service.proxy.ProductProxyService;
|
|
|
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
|
|
|
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
|
|
|
import lombok.experimental.Builder;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Created by chenchao on 2018/9/17.
|
...
|
...
|
@@ -118,7 +114,7 @@ public class SellerOrderCancelService { |
|
|
if (Objects.isNull(status)){
|
|
|
return result;
|
|
|
}
|
|
|
List<Integer> sellerCanCancelStatus = ActionStatusHold.getSellerCanCancelStatus();
|
|
|
List<Integer> sellerCanCancelStatus = ActionStatusHold.getSellerCanRefundStatus();
|
|
|
if (!sellerCanCancelStatus.contains(status)){
|
|
|
logger.warn("seller cancel can not execute in this status, uid {} orderCode {}, status {}", uid, orderCode, status);
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
...
|
...
|
@@ -130,7 +126,10 @@ public class SellerOrderCancelService { |
|
|
//case 1: 未支付时
|
|
|
if (SellerOrderStatus.WAITING_PAY.getCode() == status){
|
|
|
targetSOStatus = SellerOrderStatus.SELf_CANCEL_PAY;
|
|
|
result = cancelBeforePayAction(uid, orderCode, sellerOrder.getSkup(), targetSOStatus);
|
|
|
|
|
|
SellerOrderStatusNode statusNode = SellerOrderStatusNode.builder()
|
|
|
.exceptStatus(SellerOrderStatus.WAITING_PAY).targetStatus(targetSOStatus).build();
|
|
|
result = cancelBeforePayAction(uid, orderCode, sellerOrder.getSkup(), statusNode);
|
|
|
}
|
|
|
|
|
|
//case 2: 支付完成,没有买家下单
|
...
|
...
|
@@ -160,30 +159,26 @@ public class SellerOrderCancelService { |
|
|
//case 1: 未支付时
|
|
|
if (SellerOrderStatus.WAITING_PAY.getCode() == status){
|
|
|
targetSOStatus = SellerOrderStatus.TIMEOUT_CANCEL;
|
|
|
result = cancelBeforePayAction(uid, orderCode, sellerOrder.getSkup(), targetSOStatus);
|
|
|
SellerOrderStatusNode statusNode = SellerOrderStatusNode.builder()
|
|
|
.exceptStatus(SellerOrderStatus.WAITING_PAY)
|
|
|
.targetStatus(targetSOStatus).build();
|
|
|
result = cancelBeforePayAction(uid, orderCode, sellerOrder.getSkup(), statusNode);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private int cancelBeforePayAction(int uid, long orderCode,Integer skup, SellerOrderStatus targetSOStatus){
|
|
|
logger.info("in seller cancel before Buy Action, uid {}, orderCode {}, targetSOStatus {}",
|
|
|
uid, orderCode, targetSOStatus);
|
|
|
SellerOrder target = new SellerOrder();
|
|
|
target.setOrderCode(orderCode);
|
|
|
target.setUid(uid);
|
|
|
target.setStatus(targetSOStatus.getCode());
|
|
|
target.setSkup(skup);
|
|
|
return cancelBeforePayAction(target, targetSOStatus);
|
|
|
@Builder
|
|
|
static class SellerOrderStatusNode{
|
|
|
SellerOrderStatus targetStatus;
|
|
|
SellerOrderStatus exceptStatus;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @param target
|
|
|
* @param targetSOStatus
|
|
|
* @return
|
|
|
*/
|
|
|
private int cancelBeforePayAction(SellerOrder target, SellerOrderStatus targetSOStatus){
|
|
|
private int cancelBeforePayAction(int uid, long orderCode, Integer skup, SellerOrderStatusNode statusNode){
|
|
|
SellerOrderStatus targetSOStatus = statusNode.targetStatus;
|
|
|
SellerOrderStatus exceptStatus = statusNode.exceptStatus;
|
|
|
logger.info("in seller cancel before Buy Action, uid {}, orderCode {}, targetSOStatus {}, exceptStatus {}",
|
|
|
uid, orderCode, targetSOStatus, exceptStatus);
|
|
|
/**case 1: 未支付时
|
|
|
* actions as blow:
|
|
|
* 1. sellerOrder
|
...
|
...
|
@@ -191,9 +186,15 @@ public class SellerOrderCancelService { |
|
|
* 3. 同步product skup状态
|
|
|
*/
|
|
|
int result = 0;
|
|
|
|
|
|
//update seller order
|
|
|
if (Objects.nonNull(targetSOStatus)){
|
|
|
SellerOrder target = new SellerOrder();
|
|
|
target.setOrderCode(orderCode);
|
|
|
target.setUid(uid);
|
|
|
target.setStatus(targetSOStatus.getCode());
|
|
|
target.setSkup(skup);
|
|
|
target.setExceptStatus(exceptStatus.getCode());
|
|
|
target.setStatus(targetSOStatus.getCode());
|
|
|
target.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
result += sellerOrderMapper.updateByOrderCode(target);
|
|
|
}
|
...
|
...
|
@@ -202,17 +203,19 @@ public class SellerOrderCancelService { |
|
|
//sync skup
|
|
|
if (result>0) {
|
|
|
SellerOrderGoods sogCondition = new SellerOrderGoods();
|
|
|
sogCondition.setId(target.getSkup());
|
|
|
sogCondition.setId(skup);
|
|
|
sogCondition.setStatus(targetSOStatus.getSkupStatus().getCode());
|
|
|
sellerOrderGoodsMapper.updateByPrimaryKeySelective(sogCondition);
|
|
|
//sync skup
|
|
|
SellerOrderGoods tsog = new SellerOrderGoods();
|
|
|
tsog.setId(target.getSkup());
|
|
|
tsog.setId(skup);
|
|
|
productProxyService.syncSkup(tsog, targetSOStatus.getSkupStatus());
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int cancelAfterPayButNotBuyAction(SellerOrder sellerOrder){
|
|
|
/**case 2: 支付完成,没有买家下单
|
|
|
* actions as blow:
|
...
|
...
|
@@ -228,8 +231,11 @@ public class SellerOrderCancelService { |
|
|
SellerOrderStatus targetSOStatus;
|
|
|
|
|
|
targetSOStatus = SellerOrderStatus.PLAY_SELF;
|
|
|
SellerOrderStatus expectStatus = SellerOrderStatus.HAS_PAYED;
|
|
|
int skup = sellerOrder.getSkup();
|
|
|
result = cancelBeforePayAction(sellerUid, orderCode, skup, targetSOStatus);
|
|
|
SellerOrderStatusNode statusNode = SellerOrderStatusNode.builder().targetStatus(targetSOStatus)
|
|
|
.exceptStatus(expectStatus).build();
|
|
|
result = cancelBeforePayAction(sellerUid, orderCode, skup, statusNode);
|
|
|
//refund earnestMoney
|
|
|
if (result>0){
|
|
|
double earnestMoney = sellerOrder.getEarnestMoney().doubleValue();
|
...
|
...
|
@@ -280,6 +286,7 @@ public class SellerOrderCancelService { |
|
|
target.setUid(sellerUid);
|
|
|
target.setStatus(targetSOStatus.getCode());
|
|
|
target.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
target.setExceptStatus(SellerOrderStatus.HAS_PAYED.getCode());
|
|
|
result += sellerOrderMapper.updateByOrderCode(target);
|
|
|
|
|
|
//TODO 分赃(分账) 有待考虑使用2比对
|
...
|
...
|
@@ -354,6 +361,7 @@ public class SellerOrderCancelService { |
|
|
|
|
|
|
|
|
/**
|
|
|
* 目前来看 只有支付过保证金的skup才有下架处理
|
|
|
* TODO 如何控制好并发,必须控制不能重复转账 退款
|
|
|
* 使用乐观锁,带着查询到的状态且符合条件时再去更新
|
|
|
* @param offShelveCancelCase
|
...
|
...
|
@@ -362,15 +370,32 @@ public class SellerOrderCancelService { |
|
|
logger.info("in cancel offShelveCancelCase {}", offShelveCancelCase);
|
|
|
ErpCancelSellerOrderEvent event = (ErpCancelSellerOrderEvent)offShelveCancelCase.getEvent();
|
|
|
final int skup = event.getSkup();
|
|
|
if (skup <= 0){
|
|
|
logger.warn("in offShelveCancelCase ,skup is illegal, skup {}", skup);
|
|
|
return;
|
|
|
}
|
|
|
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
|
|
|
Integer skupStatus;
|
|
|
if (psog == null || (skupStatus = psog.getStatus() )== null){
|
|
|
logger.warn("in offShelveCancelCase, SellerOrderGoods or it's status illegal, skup {}", skup);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
SkupStatus expectSkupStatus = SkupStatus.CAN_SELL;
|
|
|
boolean isPayEarnestMoney = expectSkupStatus.getCode() == skupStatus;
|
|
|
if (!isPayEarnestMoney){
|
|
|
logger.warn("in offShelveCancelCase, SellerOrderGoods status illegal, skup {}, status {}", skup, skupStatus);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
final SellerOrderStatus targetSellerOrderStatus = SellerOrderStatus.YOHO_CANCEL_SELL;
|
|
|
//TODO check skup is buy away
|
|
|
SellerOrderGoods targetGoods = new SellerOrderGoods();
|
|
|
targetGoods.setId(skup);
|
|
|
targetGoods.setStatus(targetSellerOrderStatus.getSkupStatus().getCode());
|
|
|
|
|
|
targetGoods.setExceptStatus(skupStatus);
|
|
|
//利用数据库做并发控制
|
|
|
int result = sellerOrderGoodsMapper.updateByPrimaryKeySelective(targetGoods);
|
|
|
int result = sellerOrderGoodsMapper.updateStatusBySkpu(targetGoods);
|
|
|
if (result == 0) {
|
|
|
return;
|
|
|
}
|
...
|
...
|
@@ -380,10 +405,13 @@ public class SellerOrderCancelService { |
|
|
Long orderCode = sellerOrder.getOrderCode();
|
|
|
SellerOrder tso = new SellerOrder();
|
|
|
tso.setOrderCode(sellerOrder.getOrderCode());
|
|
|
tso.setExceptStatus(sellerOrder.getStatus());
|
|
|
tso.setStatus(targetSellerOrderStatus.getCode());
|
|
|
tso.setUid(sellerUid);
|
|
|
tso.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
result = sellerOrderMapper.updateByOrderCode(tso);
|
|
|
//refund earnestMoney
|
|
|
if (result > 0) {
|
|
|
//refund earnestMoney only has payed
|
|
|
if (isPayEarnestMoney && result > 0) {
|
|
|
double earnestMoney = sellerOrder.getEarnestMoney().doubleValue();
|
|
|
PaymentRequest refundReq = PaymentRequest.builder().uid(sellerOrder.getUid())
|
|
|
.orderCode(sellerOrder.getOrderCode())
|
...
|
...
|
|