Authored by mali

Merge branch 'master' of http://git.yoho.cn/ufo/yohoufo-fore

Showing 33 changed files with 149 additions and 41 deletions
... ... @@ -25,9 +25,7 @@ public class SellerOrderAutoCancelDelayMsgConsumer extends AbsOrderAutoCancelDel
public void cancel(OrderCancelEvent orderCancelEvent) {
int uid = orderCancelEvent.getUid();
long orderCode = orderCancelEvent.getOrderCode();
SellerOrderStatus targetSOStatus;
targetSOStatus = SellerOrderStatus.TIMEOUT_CANCEL;
sellerOrderCancelService.doCancelBeforeBuyAction(uid, orderCode, targetSOStatus);
sellerOrderCancelService.cancelByTimeout(uid, orderCode);
}
@Override
... ...
... ... @@ -9,6 +9,7 @@ import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.SellerOrderMetaMapper;
import com.yohoufo.dal.order.model.BuyerOrderMeta;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.dal.order.model.SellerOrderMeta;
import com.yohoufo.order.common.OrderCodeType;
import com.yohoufo.order.common.SellerOrderStatus;
... ... @@ -17,6 +18,7 @@ import com.yohoufo.order.constants.OrderConstant;
import com.yohoufo.order.model.OrderInfo;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.response.PrepayResponse;
import com.yohoufo.order.service.proxy.ProductProxyService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -36,6 +38,8 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService {
@Autowired
SellerOrderMetaMapper sellerOrderMetaMapper;
@Autowired
private ProductProxyService productProxyService;
/**
* 更新订单状态
... ... @@ -46,13 +50,16 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService {
SellerOrder sellerOrder = new SellerOrder();
sellerOrder.setOrderCode(orderInfo.getOrderCode());
sellerOrder.setUid(orderInfo.getUid());
sellerOrder.setStatus(SellerOrderStatus.HAS_PAYED.getCode());
SellerOrderStatus sellerOrderStatus = SellerOrderStatus.HAS_PAYED;
sellerOrder.setStatus(sellerOrderStatus.getCode());
orderInfo.setStatus(SellerOrderStatus.HAS_PAYED.getCode());
orderInfo.setStatus(sellerOrderStatus.getCode());
sellerOrderMapper.updateByOrderCode(sellerOrder);
//
SellerOrderGoods tsog = new SellerOrderGoods();
tsog.setId(orderInfo.getSkup());
productProxyService.syncSkup(tsog,sellerOrderStatus.getSkupStatus());
}
... ... @@ -156,7 +163,7 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService {
/**
* 获取订单情报
* @param request
* @param orderCode
* @return
*/
public OrderInfo getOrderInfo(long orderCode, int uid) {
... ... @@ -187,7 +194,7 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService {
/**
* 获取订单情报
* @param request
* @param orderCode
* @return
*/
public OrderInfo getOrderInfo(long orderCode) {
... ...
... ... @@ -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;
}
... ...