...
|
...
|
@@ -6,13 +6,16 @@ import com.yohobuy.ufo.model.order.req.SellerOrderCancelReq; |
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.dal.order.BuyerOrderMapper;
|
|
|
import com.yohoufo.dal.order.SellerOrderMapper;
|
|
|
import com.yohoufo.dal.order.model.BuyerOrder;
|
|
|
import com.yohoufo.dal.order.model.SellerOrder;
|
|
|
import com.yohoufo.order.common.CancelType;
|
|
|
import com.yohoufo.order.common.OrderStatus;
|
|
|
import com.yohoufo.order.common.SellerOrderStatus;
|
|
|
import com.yohoufo.order.event.OrderCancelEvent;
|
|
|
import com.yohoufo.order.model.request.PaymentRequest;
|
|
|
import com.yohoufo.order.mq.TopicConstants;
|
|
|
import com.yohoufo.order.mq.producer.TradeMqSender;
|
|
|
import com.yohoufo.order.service.IPaymentService;
|
|
|
import com.yohoufo.order.service.impl.visitor.AutoCancelCase;
|
|
|
import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase;
|
|
|
import com.yohoufo.order.service.impl.visitor.UserCancelCase;
|
...
|
...
|
@@ -25,6 +28,7 @@ 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.
|
...
|
...
|
@@ -43,18 +47,10 @@ public class SellerOrderCancelService { |
|
|
@Autowired
|
|
|
private TradeMqSender tradeMqSender;
|
|
|
|
|
|
public boolean cancel(SellerOrderCancelReq req){
|
|
|
logger.info("seller self cancel order,req {}", req);
|
|
|
int uid = req.getUid();
|
|
|
long orderCode = req.getOrderCode();
|
|
|
@Autowired
|
|
|
private IPaymentService paymentService;
|
|
|
|
|
|
if (uid <= 0 || orderCode <= 0L){
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
|
|
|
|
|
int result = doCancel(uid, orderCode);
|
|
|
return result > 0;
|
|
|
}
|
|
|
|
|
|
public void cancel(UserCancelCase cancelCase){
|
|
|
logger.info("in cancel UserCancelCase {}", cancelCase);
|
...
|
...
|
@@ -64,10 +60,8 @@ public class SellerOrderCancelService { |
|
|
|
|
|
//未支付时
|
|
|
//支付完成,没有买家下单
|
|
|
|
|
|
|
|
|
|
|
|
//支付完成,有买家下单
|
|
|
doCancel(uid, orderCode);
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -80,34 +74,94 @@ public class SellerOrderCancelService { |
|
|
if (Objects.isNull(status)){
|
|
|
return result;
|
|
|
}
|
|
|
Integer targetStatus = null;
|
|
|
//target seller Order Status
|
|
|
Integer targetSOStatus;
|
|
|
//未支付时
|
|
|
|
|
|
if (SellerOrderStatus.WAITING_PAY.getCode() == status){
|
|
|
targetStatus = SellerOrderStatus.SELf_CANCEL_PAY.getCode();
|
|
|
targetSOStatus = SellerOrderStatus.SELf_CANCEL_PAY.getCode();
|
|
|
doCancelBeforeBuyAction(uid, orderCode, targetSOStatus);
|
|
|
}
|
|
|
|
|
|
if (SellerOrderStatus.HAS_PAYED.getCode() == status){
|
|
|
List<Integer> sellerCanCancelStatus = Arrays.asList(OrderStatus.HAS_PAYED.getCode());
|
|
|
buyerOrderMapper.selectCntBySellerUidStatus(uid, sellerCanCancelStatus);
|
|
|
|
|
|
targetStatus = SellerOrderStatus.SELf_CANCEL_PAY.getCode();
|
|
|
if (SellerOrderStatus.HAS_PAYED.getCode() == status){
|
|
|
doCancelAfterBuyAction(uid, orderCode);
|
|
|
}
|
|
|
|
|
|
if (Objects.nonNull(targetStatus)){
|
|
|
SellerOrder target = new SellerOrder();
|
|
|
target.setOrderCode(orderCode);
|
|
|
target.setUid(uid);
|
|
|
target.setStatus(targetStatus);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private int doCancelBeforeBuyAction(int uid, long orderCode, Integer targetSOStatus){
|
|
|
SellerOrder target = new SellerOrder();
|
|
|
target.setOrderCode(orderCode);
|
|
|
target.setUid(uid);
|
|
|
target.setStatus(targetSOStatus);
|
|
|
return doCancelBeforeBuyAction(target);
|
|
|
}
|
|
|
|
|
|
|
|
|
private int doCancelBeforeBuyAction(SellerOrder target){
|
|
|
int result = 0;
|
|
|
int uid = target.getUid();
|
|
|
long orderCode = target.getOrderCode();
|
|
|
Integer targetSOStatus = target.getStatus();
|
|
|
|
|
|
//update seller order
|
|
|
if (Objects.nonNull(targetSOStatus)){
|
|
|
|
|
|
target.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
result = sellerOrderMapper.updateByOrderCode(target);
|
|
|
result += sellerOrderMapper.updateByOrderCode(target);
|
|
|
//refund earnestMoney
|
|
|
double earnestMoney = target.getEarnestMoney().doubleValue();
|
|
|
PaymentRequest refundReq = PaymentRequest.builder().uid(uid).orderCode(orderCode)
|
|
|
.refundAmount(earnestMoney).build();
|
|
|
paymentService.refund(refundReq);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private int doCancelAfterBuyAction(int sellerUid, long orderCode){
|
|
|
int result = 0;
|
|
|
List<Integer> sellerCanCancelStatus;
|
|
|
int canCancelCnt = 0;
|
|
|
//target Buyer Order Status
|
|
|
Integer targetBOStatus;
|
|
|
|
|
|
//查询买家订单,状态是支付成功的
|
|
|
sellerCanCancelStatus = Arrays.asList(OrderStatus.HAS_PAYED.getCode());
|
|
|
canCancelCnt = buyerOrderMapper.selectCntBySellerUidStatus(sellerUid, sellerCanCancelStatus);
|
|
|
Integer targetSOStatus = SellerOrderStatus.SELF_CANCEL_COMPENSATE.getCode();
|
|
|
if (canCancelCnt == 0){
|
|
|
//支付完成,没有买家下单
|
|
|
result = doCancelBeforeBuyAction(sellerUid, orderCode, targetSOStatus);
|
|
|
return result;
|
|
|
}
|
|
|
targetBOStatus = OrderStatus.SELLER_CANCEL_AFTER_PAY.getCode();
|
|
|
|
|
|
List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListBySellerUidStatus(sellerUid, sellerCanCancelStatus, 0, canCancelCnt);
|
|
|
List<Long> orderCodes = buyerOrderList.parallelStream().map(BuyerOrder::getOrderCode).collect(Collectors.toList());
|
|
|
|
|
|
if (orderCodes.size() > 1){
|
|
|
throw new ServiceException(ServiceError.ERP_ORDER_CANCEL_FAILED);
|
|
|
}
|
|
|
//actions of buyer order and related
|
|
|
//update buyer Order
|
|
|
result += buyerOrderMapper.updateBatchByOrderCodes(orderCodes, targetBOStatus, DateUtil.getCurrentTimeSecond());
|
|
|
//TODO 分赃(分账)
|
|
|
|
|
|
SellerOrder target = new SellerOrder();
|
|
|
target.setOrderCode(orderCode);
|
|
|
target.setUid(sellerUid);
|
|
|
target.setStatus(targetSOStatus);
|
|
|
target.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
result += sellerOrderMapper.updateByOrderCode(target);
|
|
|
|
|
|
//TODO sync skup
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void cancel(AutoCancelCase autoCancelCase){
|
|
|
logger.info("in cancel autoCancelCase {}", autoCancelCase);
|
|
|
OrderCancelEvent event = autoCancelCase.getOrderCancelEvent();
|
...
|
...
|
|