Authored by chenchao

buyer overseas order cancel

package com.yohoufo.order.controller;
import com.yohobuy.ufo.model.order.common.OrderListType;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SellerOrderListType;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.req.BuyerOrderCancelReq;
... ... @@ -11,11 +12,13 @@ import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.order.constants.CutomsClearanceFailType;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.model.request.OrderRequest;
import com.yohoufo.order.model.request.SaveQualityCheckInfoRequest;
import com.yohoufo.order.service.IBuyerOrderService;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.impl.BuyerOrderCancelService;
import com.yohoufo.order.service.impl.SellerOrderService;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
... ... @@ -39,6 +42,10 @@ public class ErpGWOrderController {
@Autowired
SellerOrderService sellerOrderService;
@Autowired
BuyerOrderCancelService buyerOrderCancelService;
@RequestMapping(params = "method=ufo.buyer.orderNums")
@IgnoreSession
public BuyerOrderNums getBuyerOrderNums(@RequestParam("uid") int uid){
... ... @@ -148,4 +155,33 @@ public class ErpGWOrderController {
LOG.info("method ufo.depot.confirmReceive out, req is {}", request);
return new ApiResponse.ApiResponseBuilder().code(200).message("鉴定中心确认收货成功").build();
}
/**
* 平台确认收货
*/
@IgnoreSession
@IgnoreSignature
@RequestMapping(value = "/cancelOverseasOrder")
public ApiResponse cancelOverseasOrder(@RequestBody BuyerOrderCancelReq request) {
LOG.info("api cancelOverseasOrder in, req is {}", request);
int cancelType = request.getCancelType();
final OrderStatus orderStatus = OrderStatus.getOrderStatus(cancelType);
CutomsClearanceFailType ccft = null;
switch (orderStatus){
case PLATFORM_BLOWN_CUSTOMS_CLEARANCE:
ccft = CutomsClearanceFailType.PLATFORM;
break;
case BUYER_BLOWN_CUSTOMS_CLEARANCE:
ccft = CutomsClearanceFailType.BUYER;
break;
}
if (ccft == null){
LOG.warn("in api cancelOverseasOrder CutomsClearanceFailType null, req {}", request);
return new ApiResponse.ApiResponseBuilder().code(400).message("param cancelType wrong").build();
}
buyerOrderCancelService.cancelOverseasOrder(request.getOrderCode(), ccft);
LOG.info("api cancelOverseasOrder out, req is {}", request);
return new ApiResponse.ApiResponseBuilder().code(200).message("取消海外直邮订单成功").build();
}
}
... ...
... ... @@ -15,7 +15,22 @@ import lombok.Builder;
@AllArgsConstructor
public class BuyerRefundCouponEvent extends Event {
public enum BizCase{
APPRAISE_FAIL, APPRAISE_UNSURE,SELLER_DELIVER_TIMEOUT, SELLER_PLAY_BUYER, BUYER_CANCEL_BSD, BUYER_CANCEL_BDR, SELLER_SHAM_SEND_OUT
APPRAISE_FAIL,
APPRAISE_UNSURE,
SELLER_DELIVER_TIMEOUT,
SELLER_PLAY_BUYER,
/**
* 卖家发货前
* BSC: before seller delivery
*/
BUYER_CANCEL_BSD,
/**
* 鉴定中心收货钱
* BDR:before depot receive
*/
BUYER_CANCEL_BDR,
SELLER_SHAM_SEND_OUT,
PLATFORM_BLOWN_CUSTOMS_CLEARANCE
}
Integer uid;
... ...
... ... @@ -75,7 +75,7 @@ public class RefundGoodsMoneyHandler extends AbsRefundOrderHandler{
.skup(skup);
return blebOfBuyer;
}
@Deprecated
public RefundGoodsMoneyHandler loadBillLogEventBuilder(BillLogEvent.BillLogEventBuilder bleb){
this.bleb = bleb;
... ...
... ... @@ -40,7 +40,10 @@ import com.yohoufo.order.service.seller.support.SkupTypeCodeSupport;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.OrderAssist;
import com.yohoufo.order.utils.PaymentHelper;
import lombok.Builder;
import lombok.Data;
import lombok.Setter;
import lombok.val;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -137,7 +140,7 @@ public class BuyerOrderCancelService {
boolean noResponsibility = Objects.isNull(penaltyAmount)
|| BigDecimal.ZERO.compareTo(penaltyAmount) == 0;
//退还优惠券
refundCouponIfNeed(buyerUid, orderCode);
asyncRefundCoupon(buyerUid, orderCode, BuyerRefundCouponEvent.BizCase.BUYER_CANCEL_BSD);
int skup = bsdEvent.getSkup();
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
int targetGoodsStatus = SkupStatus.BUYER_CANCEL_BEFORE_SELLER_DELIVER.getCode();
... ... @@ -275,7 +278,7 @@ public class BuyerOrderCancelService {
boolean noResponsibility = Objects.isNull(penaltyAmount)
|| BigDecimal.ZERO.compareTo(penaltyAmount) == 0;
//退还优惠券
refundCouponIfNeed(buyerUid, orderCode);
asyncRefundCoupon(buyerUid, orderCode, BuyerRefundCouponEvent.BizCase.BUYER_CANCEL_BDR);
int skup = bdrEvent.getSkup();
SellerOrderGoods targetGoods = new SellerOrderGoods();
... ... @@ -346,10 +349,12 @@ public class BuyerOrderCancelService {
return;
}
OrderStatus targetStatus = null;
Consumer<BuyerOrder> consumer = null;
Consumer<RefundGoodsAmoutNode> consumer = null;
boolean needCompensateCoupon = false;
switch (failType){
case PLATFORM:
targetStatus = OrderStatus.PLATFORM_BLOWN_CUSTOMS_CLEARANCE;
needCompensateCoupon = true;
consumer = (buyerOrder1) -> cancelOverseasOrderByPlatform(buyerOrder1);
break;
case BUYER:
... ... @@ -372,9 +377,23 @@ public class BuyerOrderCancelService {
logger.warn("cancelOverseasOrder fail -> buyerOrderMapper.updateStatusByOrderCode, orderCode {}", orderCode);
return;
}
BigDecimal leftGoodsMoney = buyerOrder.getAmount();
BuyerOrderGoods pbog = buyerOrderGoodsMapper.selectOnlyByOrderCode(orderCode);
Integer skup = pbog.getSkup();
//
buyerOrder.setStatus(targetStatus.getCode());
consumer.accept(buyerOrder);
RefundGoodsAmoutNode rgaNode = RefundGoodsAmoutNode.builder()
.buyerOrder(buyerOrder)
.skup(skup)
.targetOrderStatus(targetStatus)
.leftBuyerMoney(leftGoodsMoney)
.needCompensateCoupon(needCompensateCoupon)
.build();
//
consumer.accept(rgaNode);
//
orderStatusFlowService.addAsy(orderCode,targetStatus.getCode());
}
... ... @@ -384,20 +403,42 @@ public class BuyerOrderCancelService {
* 货品平台自己吃了
* 买家钱退给买家
* 赔偿卖家ufo券 券金额还未定
* @param buyerOrder
* @param rgaNode
*/
private void cancelOverseasOrderByPlatform(BuyerOrder buyerOrder){
private void cancelOverseasOrderByPlatform(RefundGoodsAmoutNode rgaNode){
BuyerOrder buyerOrder = rgaNode.buyerOrder;
int skup = rgaNode.skup;
OrderStatus targetOrderStatus = rgaNode.targetOrderStatus;
BigDecimal leftBuyerMoney = rgaNode.leftBuyerMoney;
boolean needCompensateCoupon = rgaNode.needCompensateCoupon;
if (needCompensateCoupon){
asyncRefundCoupon(buyerOrder.getUid(), buyerOrder.getOrderCode(), BuyerRefundCouponEvent.BizCase.PLATFORM_BLOWN_CUSTOMS_CLEARANCE);
}
refundGoodsAmount(buyerOrder, skup, targetOrderStatus, leftBuyerMoney);
}
/**
* 买家原因失败
* 货品平台自己吃了
* 货款钱退给买家
* @param buyerOrder
* @param rgaNode
*/
private void cancelOverseasOrderByBuyer(BuyerOrder buyerOrder){
private void cancelOverseasOrderByBuyer(RefundGoodsAmoutNode rgaNode){
BuyerOrder buyerOrder = rgaNode.buyerOrder;
int skup = rgaNode.skup;
OrderStatus targetOrderStatus = rgaNode.targetOrderStatus;
BigDecimal leftBuyerMoney = rgaNode.leftBuyerMoney;
refundGoodsAmount(buyerOrder, skup, targetOrderStatus, leftBuyerMoney);
}
@Data@Builder
private static class RefundGoodsAmoutNode{
BuyerOrder buyerOrder;
int skup;
OrderStatus targetOrderStatus;
BigDecimal leftBuyerMoney;
boolean needCompensateCoupon;
}
private void refundGoodsAmount(BuyerOrder buyerOrder,int skup, OrderStatus targetOrderStatus, BigDecimal leftBuyerMoney){
... ... @@ -428,7 +469,8 @@ public class BuyerOrderCancelService {
BuyerOrder buyerOrder;
TransferCase transferCase;
OrderStatus targetOrderStatus;
boolean reSellFlag;//重新上架标志,重新上架则不退保证金了
//重新上架标志,重新上架则不退保证金了
boolean reSellFlag;
@Setter
SellerWalletDetail.Type swdType;
... ... @@ -578,4 +620,14 @@ public class BuyerOrderCancelService {
logger.warn("refund coupon error,uid:{},orderCode:{}", uid, orderCode, ex);
}
}
public void asyncRefundCoupon(int uid, long orderCode, BuyerRefundCouponEvent.BizCase refundCouponCase) {
val buyerRefundCouponEvent = BuyerRefundCouponEvent.builder()
.bizCase(refundCouponCase)
.uid(uid)
.orderCode(orderCode)
.build();
logger.info("async refund coupon by order {} request is {}", orderCode, buyerRefundCouponEvent);
EventBusPublisher.publishEvent(buyerRefundCouponEvent);
}
}
... ...