...
|
...
|
@@ -72,50 +72,88 @@ public class SellerOrderCancelService { |
|
|
//case 1: 未支付时
|
|
|
//case 2: 支付完成,没有买家下单
|
|
|
//case 3: 支付完成,有买家下单
|
|
|
doCancel(uid, orderCode);
|
|
|
cancel(uid, orderCode);
|
|
|
}
|
|
|
|
|
|
|
|
|
private int doCancel(int uid, long orderCode){
|
|
|
public int cancel(int uid, long orderCode){
|
|
|
int result = 0;
|
|
|
SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid);
|
|
|
|
|
|
|
|
|
if (Objects.isNull(sellerOrder)){
|
|
|
return result;
|
|
|
}
|
|
|
Integer status = Optional.ofNullable(sellerOrder).map(SellerOrder::getStatus).orElse(null);
|
|
|
if (Objects.isNull(status)){
|
|
|
return result;
|
|
|
}
|
|
|
logger.info("in seller cancel, uid {}, orderCode {}, SellerOrder status {}", uid, orderCode, status);
|
|
|
//target seller Order Status
|
|
|
SellerOrderStatus targetSOStatus;
|
|
|
//case 1: 未支付时
|
|
|
if (SellerOrderStatus.WAITING_PAY.getCode() == status){
|
|
|
targetSOStatus = SellerOrderStatus.SELf_CANCEL_PAY;
|
|
|
doCancelBeforeBuyAction(uid, orderCode, targetSOStatus);
|
|
|
|
|
|
result = cancelBeforePayAction(uid, orderCode, sellerOrder.getSkup(), targetSOStatus);
|
|
|
}
|
|
|
|
|
|
//case 2: 支付完成,没有买家下单
|
|
|
//case 3: 支付完成,有买家下单
|
|
|
if (SellerOrderStatus.HAS_PAYED.getCode() == status){
|
|
|
doCancelAfterBuyAction(sellerOrder);
|
|
|
result = cancelAfterPayAction(sellerOrder);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public int doCancelBeforeBuyAction(int uid, long orderCode, SellerOrderStatus targetSOStatus){
|
|
|
|
|
|
public int cancelByTimeout(int uid, long orderCode){
|
|
|
int result = 0;
|
|
|
SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid);
|
|
|
|
|
|
if (Objects.isNull(sellerOrder)){
|
|
|
return result;
|
|
|
}
|
|
|
Integer status = Optional.ofNullable(sellerOrder).map(SellerOrder::getStatus).orElse(null);
|
|
|
if (Objects.isNull(status)){
|
|
|
return result;
|
|
|
}
|
|
|
logger.info("in seller timeout cancel, uid {}, orderCode {}, SellerOrder status {}", uid, orderCode, status);
|
|
|
//target seller Order Status
|
|
|
SellerOrderStatus targetSOStatus;
|
|
|
//case 1: 未支付时
|
|
|
if (SellerOrderStatus.WAITING_PAY.getCode() == status){
|
|
|
targetSOStatus = SellerOrderStatus.TIMEOUT_CANCEL;
|
|
|
result = cancelBeforePayAction(uid, orderCode, sellerOrder.getSkup(), targetSOStatus);
|
|
|
}
|
|
|
|
|
|
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());
|
|
|
return doCancelBeforeBuyAction(target, targetSOStatus);
|
|
|
target.setSkup(skup);
|
|
|
return cancelBeforePayAction(target, targetSOStatus);
|
|
|
}
|
|
|
|
|
|
|
|
|
private int doCancelBeforeBuyAction(SellerOrder target, SellerOrderStatus targetSOStatus){
|
|
|
/**
|
|
|
*
|
|
|
* @param target
|
|
|
* @param targetSOStatus
|
|
|
* @return
|
|
|
*/
|
|
|
private int cancelBeforePayAction(SellerOrder target, SellerOrderStatus targetSOStatus){
|
|
|
/**case 1: 未支付时
|
|
|
* actions as blow:
|
|
|
* 1. sellerOrder
|
|
|
* 2. sellerOrderGoods
|
|
|
* 3. 同步product skup状态
|
|
|
*/
|
|
|
int result = 0;
|
|
|
int uid = target.getUid();
|
|
|
long orderCode = target.getOrderCode();
|
|
|
|
|
|
//update seller order
|
|
|
if (Objects.nonNull(targetSOStatus)){
|
...
|
...
|
@@ -126,10 +164,10 @@ public class SellerOrderCancelService { |
|
|
//refund earnestMoney
|
|
|
//sync skup
|
|
|
if (result>0) {
|
|
|
double earnestMoney = target.getEarnestMoney().doubleValue();
|
|
|
PaymentRequest refundReq = PaymentRequest.builder().uid(uid).orderCode(orderCode)
|
|
|
.refundAmount(earnestMoney).build();
|
|
|
paymentService.refund(refundReq);
|
|
|
SellerOrderGoods sogCondition = new SellerOrderGoods();
|
|
|
sogCondition.setId(target.getSkup());
|
|
|
sogCondition.setStatus(targetSOStatus.getSkupStatus().getCode());
|
|
|
sellerOrderGoodsMapper.updateByPrimaryKeySelective(sogCondition);
|
|
|
//sync skup
|
|
|
SellerOrderGoods tsog = new SellerOrderGoods();
|
|
|
tsog.setId(target.getSkup());
|
...
|
...
|
@@ -138,27 +176,49 @@ public class SellerOrderCancelService { |
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private int doCancelAfterBuyAction(SellerOrder sellerOrder){
|
|
|
private int cancelAfterPayButNotBuyAction(SellerOrder sellerOrder){
|
|
|
/**case 2: 支付完成,没有买家下单
|
|
|
* actions as blow:
|
|
|
* 1. sellerOrder
|
|
|
* 2. sellerOrderGoods
|
|
|
* 3. 同步product skup状态
|
|
|
*/
|
|
|
final int sellerUid = sellerOrder.getUid();
|
|
|
final long orderCode = sellerOrder.getOrderCode();
|
|
|
logger.info("in seller cancel when Seller Pay But Not Buy Action, uid {}, orderCode {}",
|
|
|
sellerUid, 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);
|
|
|
SellerOrderStatus targetSOStatus;
|
|
|
//case 2: 支付完成,没有买家下单
|
|
|
if (canCancelCnt == 0){
|
|
|
targetSOStatus = SellerOrderStatus.PLAY_SELF;
|
|
|
result = doCancelBeforeBuyAction(sellerUid, orderCode, targetSOStatus);
|
|
|
return result;
|
|
|
|
|
|
targetSOStatus = SellerOrderStatus.PLAY_SELF;
|
|
|
result = cancelBeforePayAction(sellerUid, orderCode, sellerOrder.getSkup(), targetSOStatus);
|
|
|
//refund earnestMoney
|
|
|
if (result>0){
|
|
|
double earnestMoney = sellerOrder.getEarnestMoney().doubleValue();
|
|
|
PaymentRequest refundReq = PaymentRequest.builder().uid(sellerUid)
|
|
|
.orderCode(orderCode)
|
|
|
.refundAmount(earnestMoney).build();
|
|
|
paymentService.refund(refundReq);
|
|
|
}
|
|
|
//case 3: 支付完成,有买家下单
|
|
|
List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListBySellerUidStatus(sellerUid, sellerCanCancelStatus, 0, canCancelCnt);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private int cancelAfterPayExistBuyAction(SellerOrder sellerOrder,List<Integer> sellerCanCancelStatus,
|
|
|
int buyOrderCnt){
|
|
|
/**
|
|
|
* case 3: 支付完成,有买家下单
|
|
|
* actions as blow:
|
|
|
* 1. buyerOrder
|
|
|
* 2. sellerOrder
|
|
|
* 3. sellerOrderGoods
|
|
|
* 4. 瓜分保证金
|
|
|
*/
|
|
|
final int sellerUid = sellerOrder.getUid();
|
|
|
final long orderCode = sellerOrder.getOrderCode();
|
|
|
logger.info("in seller cancel After Pay while Exist Buy Action, uid {}, orderCode {}",
|
|
|
sellerUid, orderCode);
|
|
|
int result = 0;
|
|
|
List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListBySellerUidStatus(sellerUid, sellerCanCancelStatus, 0, buyOrderCnt);
|
|
|
List<Long> orderCodes = buyerOrderList.parallelStream().map(BuyerOrder::getOrderCode).collect(Collectors.toList());
|
|
|
|
|
|
if (orderCodes.size() > 1){
|
...
|
...
|
@@ -166,11 +226,14 @@ public class SellerOrderCancelService { |
|
|
}
|
|
|
//actions of buyer order and related
|
|
|
//update buyer Order
|
|
|
//target Buyer Order Status
|
|
|
Integer targetBOStatus;
|
|
|
targetBOStatus = OrderStatus.SELLER_CANCEL_AFTER_PAY.getCode();
|
|
|
result += buyerOrderMapper.updateBatchByOrderCodes(orderCodes, targetBOStatus, DateUtil.getCurrentTimeSecond());
|
|
|
//TODO 分赃(分账)
|
|
|
|
|
|
|
|
|
//update seller order
|
|
|
SellerOrderStatus targetSOStatus;
|
|
|
targetSOStatus = SellerOrderStatus.PLAY_BUYER;
|
|
|
SellerOrder target = new SellerOrder();
|
|
|
target.setOrderCode(orderCode);
|
...
|
...
|
@@ -179,6 +242,46 @@ public class SellerOrderCancelService { |
|
|
target.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
result += sellerOrderMapper.updateByOrderCode(target);
|
|
|
|
|
|
//TODO 分赃(分账) 有待考虑使用2比对
|
|
|
if(result == 2){
|
|
|
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private int cancelAfterPayAction(SellerOrder sellerOrder){
|
|
|
|
|
|
final int sellerUid = sellerOrder.getUid();
|
|
|
final long orderCode = sellerOrder.getOrderCode();
|
|
|
logger.info("in seller cancel After Buy Action, uid {}, orderCode {}",
|
|
|
sellerUid, orderCode);
|
|
|
int result = 0;
|
|
|
List<Integer> sellerCanCancelStatus;
|
|
|
int buyOrderCnt;
|
|
|
|
|
|
|
|
|
//查询买家订单,状态是支付成功的
|
|
|
sellerCanCancelStatus = Arrays.asList(OrderStatus.HAS_PAYED.getCode());
|
|
|
buyOrderCnt = buyerOrderMapper.selectCntBySellerUidStatus(sellerUid, sellerCanCancelStatus);
|
|
|
if (buyOrderCnt == 0){
|
|
|
/**case 2: 支付完成,没有买家下单
|
|
|
* actions as blow:
|
|
|
* 1. sellerOrder
|
|
|
* 2. sellerOrderGoods
|
|
|
* 3. 同步product skup状态
|
|
|
*/
|
|
|
result = cancelAfterPayButNotBuyAction(sellerOrder);
|
|
|
return result;
|
|
|
}
|
|
|
/**
|
|
|
* case 3: 支付完成,有买家下单
|
|
|
* actions as blow:
|
|
|
* 1. buyerOrder
|
|
|
* 2. sellerOrder
|
|
|
* 3. sellerOrderGoods
|
|
|
* 4. 瓜分保证金
|
|
|
*/
|
|
|
result = cancelAfterPayExistBuyAction(sellerOrder, sellerCanCancelStatus, buyOrderCnt);
|
|
|
return result;
|
|
|
}
|
|
|
|
...
|
...
|
|