Authored by chenchao

1. refund coupons 2 buyer

2. optimized seller cancel logic
package com.yohoufo.order.event;
import com.yohoufo.common.alarm.Event;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
/**
* Created by chao.chen on 2018/12/27.
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BuyerRefundCouponEvent extends Event {
public enum BizCase{
APPRAISE_FAIL, SELLER_DELIVER_TIMEOUT, SELLER_PLAY_BUYER, BUYER_CANCEL_BSD, BUYER_CANCEL_BDR
}
Integer uid;
Long orderCode;
BizCase bizCase;
}
... ...
... ... @@ -16,6 +16,7 @@ import com.yohoufo.order.common.RefundCase;
import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.constants.AlarmConfig;
import com.yohoufo.order.event.BillLogEvent;
import com.yohoufo.order.event.BuyerRefundCouponEvent;
import com.yohoufo.order.event.SellerCancelDeliverEvent;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.request.TransferMoneyRequest;
... ... @@ -30,7 +31,7 @@ import org.springframework.stereotype.Component;
import java.math.BigDecimal;
/**
/** 卖家超时发货
* Created by chenchao on 2018/9/30.
*/
@Component
... ... @@ -78,6 +79,9 @@ public class SellerOrderCancelDeliverDelayMsgConsumer implements YhConsumer {
DateUtil.getCurrentTimeSecond());
if(rows > 0){
BuyerRefundCouponEvent brce = BuyerRefundCouponEvent.builder().bizCase(BuyerRefundCouponEvent.BizCase.SELLER_DELIVER_TIMEOUT)
.uid(buyerUid).orderCode(orderCode).build();
EventBusPublisher.publishEvent(brce);
//将卖家的保证金分账给平台和买家
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(TransferCase.SELLER_PLAY_BUYER.getCode()).transferCase(TransferCase.DELIVER_TIME_OUT)
... ...
package com.yohoufo.order.service.handler;
import com.google.common.eventbus.Subscribe;
import com.yohoufo.common.alarm.IEventHandler;
import com.yohoufo.order.event.BuyerRefundCouponEvent;
import com.yohoufo.order.service.impl.BuyerOrderCancelService;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Created by chao.chen on 2018/12/27.
*/
@Component
public class BuyerRefundCouponAsyncHandler implements IEventHandler<BuyerRefundCouponEvent> {
private final Logger logger = LoggerUtils.getBuyerOrderLogger();
@Autowired
private BuyerOrderCancelService buyerOrderCancelService;
@Override
@Subscribe
public void handle(BuyerRefundCouponEvent event) {
logger.info("in handle BuyerRefundCouponEvent {}", event);
if (event == null){
return;
}
buyerOrderCancelService.refundCouponIfNeed(event.getUid(), event.getOrderCode());
}
}
... ...
... ... @@ -19,6 +19,7 @@ import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.constants.AlarmConfig;
import com.yohoufo.order.event.BillLogEvent;
import com.yohoufo.order.event.BuyerConfirmEvent;
import com.yohoufo.order.event.BuyerRefundCouponEvent;
import com.yohoufo.order.model.request.PaymentRequest;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.model.response.AppraiseAddressResp;
... ... @@ -329,7 +330,11 @@ public class AppraiseService {
DateUtil.getCurrentTimeSecond());
if (rows > 0){
//refund coupons of buyer
BuyerRefundCouponEvent brce = BuyerRefundCouponEvent.builder().bizCase(BuyerRefundCouponEvent.BizCase.APPRAISE_FAIL)
.uid(buyerUid).orderCode(orderCode).build();
EventBusPublisher.publishEvent(brce);
//
int sellerUid = buyerOrder.getSellerUid();
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
int skup = bog.getSkup();
... ... @@ -361,13 +366,7 @@ public class AppraiseService {
//先校验,提前把错误抛出
paymentService.transferMonCheck(tmReq);
//再分账
/*
boolean transferSuccessFlag=transferService.transfer(tmReq);
if(!transferSuccessFlag){
apiResponse.setCode(400);
apiResponse.setMessage("保证金分账失败");
}
*/
//改成异步的分账,不关心分账执行结果
executorService.execute(()->{
LOGGER.info("in appraiseFail,begin transfer async");
... ...
... ... @@ -305,6 +305,7 @@ public class BuyerOrderCancelService {
*/
public void refundCouponIfNeed(int uid, long orderCode) {
try {
logger.info("buyer order cancel,refundCouponIfNeed uid {} orderCode {}", uid, orderCode);
OrderCoupon orderCoupon = orderCouponMapper.selectByUidAndOrderCode(uid, orderCode);
if (orderCoupon == null) {
logger.info("[{}] not need to refund coupon", orderCode);
... ...
... ... @@ -15,10 +15,7 @@ import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.*;
import com.yohoufo.order.constants.AlarmConfig;
import com.yohoufo.order.event.BillLogEvent;
import com.yohoufo.order.event.ErpCancelSellerOrderEvent;
import com.yohoufo.order.event.OrderCancelEvent;
import com.yohoufo.order.event.PayConfirmEvent;
import com.yohoufo.order.event.*;
import com.yohoufo.order.model.PayQueryBo;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.model.request.OrderRequest;
... ... @@ -411,24 +408,33 @@ public class SellerOrderCancelService {
* 根据codeType判断即可
*/
if (OrderCodeType.getSellerTypes().contains(codeType)){
logger.warn("cancelAfterPayExistBuyAction canceling order buyer operated, seller [uid:{} orderCode:{}],buyer [uid:{} orderCode:{}] codeType {} buyerOrderStatus {}",
logger.warn("cancelAfterPayExistBuyAction seller cancel self-order_code , seller [uid:{} orderCode:{}],buyer [uid:{} orderCode:{}] codeType {} buyerOrderStatus {}",
sellerUid, sellerOrderCode, buyerUid, buyerOrderCode, codeType, buyerOrderStatus);
String errorMsg = "您的商品已经被购买,不能下架该商品!";
throw new UfoServiceException(501, errorMsg);
}
if (!Objects.equals(buyerOrderStatus, OrderStatus.HAS_PAYED.getCode())){
logger.warn("cancelAfterPayExistBuyAction canceling buyer order status not normal, seller [uid:{} orderCode:{}],buyer [uid:{} orderCode:{}] codeType {} buyerOrderStatus {}",
sellerUid, sellerOrderCode, buyerUid, buyerOrderCode, codeType, buyerOrderStatus);
String errorMsg = "买家订单不可取消";
throw new UfoServiceException(501, errorMsg);
}
int result = 0;
//actions of buyer order and related
//update buyer Order
//target Buyer Order Status
Integer targetBOStatus;
targetBOStatus = OrderStatus.SELLER_CANCEL_AFTER_PAY.getCode();
BuyerOrder tbo = new BuyerOrder();
tbo.setUid(buyerUid);
tbo.setOrderCode(buyerOrderCode);
tbo.setStatus(targetBOStatus);
tbo.setUpdateTime(DateUtil.getCurrentTimeSecond());
result += buyerOrderMapper.updateByOrderCode(tbo);
OrderStatus targetBOStatus = OrderStatus.SELLER_CANCEL_AFTER_PAY;
int currentDT = DateUtil.getCurrentTimeSecond();
result += buyerOrderMapper.updateStatusByOrderCode(buyerOrderCode, buyerUid, buyerOrderStatus,
targetBOStatus.getCode(), currentDT);
if(result > 0) {
BuyerRefundCouponEvent brce = BuyerRefundCouponEvent.builder().bizCase(BuyerRefundCouponEvent.BizCase.SELLER_PLAY_BUYER)
.uid(buyerUid).orderCode(buyerOrderCode).build();
EventBusPublisher.publishEvent(brce);
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(sellerOrder.getSkup());
cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()),
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
... ...