Authored by LUOXC

refactor

... ... @@ -6,13 +6,13 @@ import java.util.Optional;
import java.util.function.Supplier;
/**
* 1:鉴定通过(货款-->卖家 + 平台);
* 1:鉴定通过(货款-->卖家 + 平台);
* 2:鉴定不通过(保证金 --> 买家 + 平台);
* 3:有买家时卖家不卖了(保证金 --> 买家+ 平台)
* 4:超时发货(保证金 --> 买家 + 平台)
* Created by chenchao on 2018/10/9.
* 5:买家付款后[卖家未发货],取消订单(货款部分-->卖家);
* 5:买家付款后[卖家未发货],取消订单(货款部分-->卖家);
* 6:买家付款后[卖家已发货],取消订单(货款部分-->卖家);
* 100:保证金->买家
*/
public enum TransferCase {
... ... @@ -23,7 +23,7 @@ public enum TransferCase {
DELIVER_TIME_OUT(4,"卖家超时发货[保证金->买家]"),
BUYER_CANCEL_BEFORE_SELLER_DELIVER(5,"卖家未发货时买家取消[部分货款->卖家]"),
BUYER_CANCEL_BEFORE_DEPOT_RECEIVE(6,"卖家已发货时买家取消[部分货款->卖家]"),
CS_CANCEL_BEFORE_DEPOT_RECEIVE(7,"鉴定中心收货前客服取消[保证金->买家]");
EARNEST_MONEY_TO_BUYER(100,"保证金->买家");
private int code;
private String info;
... ...
package com.yohoufo.order.constants;
import lombok.Getter;
/**
* Created by chenchao on 2018/10/16.
*/
public enum AlarmConfig {
APPRAISE_SUCCESS("鉴定通过", "buyerOrder.transferGoodsMoney", "buyerOrder.refundEarnestMoney"),
APPRAISE_FAIL("鉴定不通过", "buyerOrder.transferEarnestMoney", "buyerOrder.refundGoodsMoney"),
SELLER_PLAY_BUYER("卖家取消", "buyerOrder.transferEarnestMoney", "buyerOrder.refundGoodsMoney"),
DELIVER_TIME_OUT("卖家发货超时", "buyerOrder.transferEarnestMoney", "buyerOrder.refundGoodsMoney"),
CS_CANCEL_BEFORE_DEPOT_RECEIVE("鉴定中心收货前客服取消", "buyerOrder.transferEarnestMoney", "buyerOrder.refundGoodsMoney");
APPRAISE_SUCCESS("buyerOrder.transferGoodsMoney","buyerOrder.refundEarnestMoney"),
APPRAISE_FAIL("buyerOrder.transferEarnestMoney","buyerOrder.refundGoodsMoney"),
SELLER_PLAY_BUYER("buyerOrder.transferEarnestMoney","buyerOrder.refundGoodsMoney"),
DELIVER_TIME_OUT("buyerOrder.transferEarnestMoney","buyerOrder.refundGoodsMoney"),
CS_CANCEL_BEFORE_DEPOT_RECEIVE("buyerOrder.transferEarnestMoney","buyerOrder.refundGoodsMoney");
@Getter
private String desc;
private String transferName;
private String refundName;
AlarmConfig(String transferName, String refundName) {
AlarmConfig(String desc, String transferName, String refundName) {
this.desc = desc;
this.transferName = transferName;
this.refundName = refundName;
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yohoufo.order.model.request;
import com.yohoufo.dal.order.model.SellerWalletDetail;
import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.constants.AlarmConfig;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
... ... @@ -37,9 +38,12 @@ public class TransferMoneyRequest {
private TransferCase transferCase;
private AlarmConfig alarmConfig;
public TransferMoneyRequest(long buyerOrderCode, long sellerOrderCode, int type) {
this.buyerOrderCode = buyerOrderCode;
this.sellerOrderCode = sellerOrderCode;
this.type = type;
}
}
... ...
... ... @@ -141,8 +141,12 @@ public class AppraiseService {
tso.setExceptStatus(expectSOStatus.getCode());
int soCnt = sellerOrderMapper.updateByOrderCode(tso);
TransferCase transferCase = TransferCase.APPRAISE_SUCCESS;
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(transferCase.getCode()).transferCase(transferCase).build();
TransferMoneyRequest tmReq = TransferMoneyRequest.builder()
.buyerOrderCode(orderCode)
.type(transferCase.getCode())
.transferCase(transferCase)
.alarmConfig(AlarmConfig.APPRAISE_SUCCESS)
.build();
//先校验,提前把错误抛出
paymentService.transferMonCheck(tmReq);
... ... @@ -491,8 +495,13 @@ public class AppraiseService {
//将卖家的保证金分账给平台和买家
TransferCase transferCase = TransferCase.APPRAISE_FAIL;
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(transferCase.getCode()).swdType(SellerWalletDetail.Type.APPRAISE_FAIL).transferCase(transferCase).build();
TransferMoneyRequest tmReq = TransferMoneyRequest.builder()
.buyerOrderCode(orderCode)
.type(transferCase.getCode())
.transferCase(transferCase)
.swdType(SellerWalletDetail.Type.APPRAISE_FAIL)
.alarmConfig(AlarmConfig.APPRAISE_FAIL)
.build();
//先校验,提前把错误抛出
paymentService.transferMonCheck(tmReq);
... ...
... ... @@ -54,7 +54,6 @@ class BuyerOrderCancelHandler {
private BuyerOrderGoodsMapper buyerOrderGoodsMapper;
private TransferService transferService;
private int transferType;
private TransferCase transferCase;
private SellerWalletDetail.Type sellerWalletDetailType;
... ... @@ -85,11 +84,9 @@ class BuyerOrderCancelHandler {
}
public BuyerOrderCancelHandler withTransfer(TransferService transferService,
int transferType,
TransferCase transferCase,
SellerWalletDetail.Type sellerWalletDetailType) {
this.transferService = transferService;
this.transferType = transferType;
this.transferCase = transferCase;
this.sellerWalletDetailType = sellerWalletDetailType;
return this;
... ... @@ -182,9 +179,10 @@ class BuyerOrderCancelHandler {
}
val transferMoneyRequest = TransferMoneyRequest.builder()
.buyerOrderCode(orderCode)
.type(transferType)
.type(transferCase.getCode())
.transferCase(transferCase)
.swdType(sellerWalletDetailType)
.alarmConfig(failAlarm)
.build();
log.info("transfer by order {} request is {}", orderCode, transferMoneyRequest);
transferService.transfer(transferMoneyRequest);
... ...
... ... @@ -154,7 +154,7 @@ public class BuyerOrderCancelService {
// 已付款 -> 超时未发货取消
.withStateTransition(OrderStatus.HAS_PAYED, OrderStatus.SEND_OUT_TIMEOUT, orderStatusFlowService)
// 保证金分账给平台和买家
.withTransfer(transferService, TransferCase.SELLER_PLAY_BUYER.getCode(), TransferCase.DELIVER_TIME_OUT, SellerWalletDetail.Type.SELLER_OVER_TIME)
.withTransfer(transferService, TransferCase.EARNEST_MONEY_TO_BUYER, SellerWalletDetail.Type.SELLER_OVER_TIME)
// 退买家货款
.withRefundGoodsMoney(payRefundService::refund).refundCase(RefundCase.BUYER_GOODS_MONEY).skup(skup).and()
.withFailAlarm(AlarmConfig.DELIVER_TIME_OUT)
... ... @@ -171,7 +171,7 @@ public class BuyerOrderCancelService {
// 卖家发货 -> 鉴定中心收货前客服取消
.withStateTransition(OrderStatus.SELLER_SEND_OUT, OrderStatus.CS_CANCEL_BEFORE_DEPOT_RECEIVE, orderStatusFlowService)
// 保证金分账给平台和买家
.withTransfer(transferService, TransferCase.CS_CANCEL_BEFORE_DEPOT_RECEIVE.getCode(), TransferCase.CS_CANCEL_BEFORE_DEPOT_RECEIVE, SellerWalletDetail.Type.CS_CANCEL_BEFORE_DEPOT_RECEIVE)
.withTransfer(transferService, TransferCase.EARNEST_MONEY_TO_BUYER, SellerWalletDetail.Type.CS_CANCEL_BEFORE_DEPOT_RECEIVE)
// 退买家货款
.withRefundGoodsMoney(payRefundService::refund).refundCase(RefundCase.BUYER_GOODS_MONEY).and()
// 通知卖家涉及虚假发货
... ...
... ... @@ -46,17 +46,13 @@ import com.yohoufo.order.utils.PaymentHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;
import javax.annotation.PostConstruct;
@Service
public class PaymentServiceImpl implements IPaymentService {
... ... @@ -532,7 +528,7 @@ public class PaymentServiceImpl implements IPaymentService {
TargetUserType targetUserType = (transferCase == TransferCase.APPRAISE_FAIL
|| transferCase == TransferCase.SELLER_PLAY_BUYER
|| transferCase == TransferCase.DELIVER_TIME_OUT
|| transferCase == TransferCase.CS_CANCEL_BEFORE_DEPOT_RECEIVE) ? TargetUserType.buyer : TargetUserType.seller;
|| transferCase == TransferCase.EARNEST_MONEY_TO_BUYER) ? TargetUserType.buyer : TargetUserType.seller;
Integer targetUid = targetUserType == TargetUserType.buyer ? buyerOrder.getUid() : sellerUid;
if (targetUid == null || targetUid < 1) {
... ...
... ... @@ -474,8 +474,13 @@ public class SellerOrderCancelService {
try{
//分赃(分账) 有待考虑使用2比对
TransferCase transferCase = TransferCase.SELLER_PLAY_BUYER;
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(buyerOrderCode)
.type(transferCase.getCode()).swdType(SellerWalletDetail.Type.SELLER_CANCEL).transferCase(transferCase).build();
TransferMoneyRequest tmReq = TransferMoneyRequest.builder()
.buyerOrderCode(buyerOrderCode)
.type(transferCase.getCode())
.transferCase(transferCase)
.swdType(SellerWalletDetail.Type.SELLER_CANCEL)
.alarmConfig(AlarmConfig.SELLER_PLAY_BUYER)
.build();
transferService.transfer(tmReq);
PayRefundBo refundResp = payRefundService.refund(refundReq, bleb);
... ...
... ... @@ -4,90 +4,63 @@ import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.order.common.TransferCase;
import com.yohoufo.order.constants.AlarmConfig;
import com.yohoufo.order.event.BillLogEvent;
import com.yohoufo.order.model.request.TransferMoneyRequest;
import com.yohoufo.order.service.IPaymentService;
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.Service;
import java.util.Objects;
/**
* Created by chenchao on 2018/10/16.
*/
@Service
public class TransferService {
private final Logger closeLogger = LoggerUtils.getOrderCloseLogger();
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private IPaymentService paymentService;
public boolean transfer(TransferMoneyRequest req){
public boolean transfer(TransferMoneyRequest req) {
logger.info("in transfer, req is {}", req);
TransferCase transferCase = req.getTransferCase();
if (transferCase == null){
if (transferCase == null) {
return true;
}
boolean transferFlag=true;
try{
boolean transferFlag = true;
try {
paymentService.transferMon(req);
}catch (Exception ex){
} catch (Exception ex) {
transferFlag = false;
logger.warn("in transfer, transfer fail,req {}", req, ex);
SmsAlarmEvent smsAlarmEvent = getSmsAlarmEvent(req, transferCase);
EventBusPublisher.publishEvent(smsAlarmEvent);
}
return transferFlag;
}
SmsAlarmEvent getSmsAlarmEvent(TransferMoneyRequest req, TransferCase transferCase){
String content;
SmsAlarmEvent smsAlarmEvent;
AlarmConfig alarmConfig ;
switch (transferCase){
case APPRAISE_SUCCESS:
content = "鉴定通过时,订单"+ req.getBuyerOrderCode() + "货款分账失败";
alarmConfig = AlarmConfig.APPRAISE_SUCCESS;
break;
case APPRAISE_FAIL:
content = "鉴定不通过时,订单"+ req.getBuyerOrderCode() + "保证金分账失败";
alarmConfig = AlarmConfig.APPRAISE_FAIL;
break;
case SELLER_PLAY_BUYER:
closeLogger.warn("in cancelAfterPayExistBuyAction , transfer fail,req {}", req);
content = "卖家取消,订单"+ req.getBuyerOrderCode() + "保证金分账失败";
alarmConfig = AlarmConfig.SELLER_PLAY_BUYER;
break;
case DELIVER_TIME_OUT:
closeLogger.warn("in deliver timeout , transfer fail,req {}", req);
content = "卖家发货超时,订单"+ req.getBuyerOrderCode() + "保证金分账失败";
alarmConfig = AlarmConfig.DELIVER_TIME_OUT;
break;
case CS_CANCEL_BEFORE_DEPOT_RECEIVE:
closeLogger.warn("in deliver timeout , transfer fail,req {}", req);
content = "鉴定中心收货前客服取消,订单"+ req.getBuyerOrderCode() + "保证金分账失败";
alarmConfig = AlarmConfig.CS_CANCEL_BEFORE_DEPOT_RECEIVE;
break;
default:
return null;
SmsAlarmEvent getSmsAlarmEvent(TransferMoneyRequest req, TransferCase transferCase) {
AlarmConfig alarmConfig = req.getAlarmConfig();
if (Objects.isNull(alarmConfig)) {
switch (transferCase) {
case APPRAISE_FAIL:
alarmConfig = AlarmConfig.APPRAISE_FAIL;
break;
default:
return null;
}
}
if (Objects.nonNull(alarmConfig)) {
String content = alarmConfig.getDesc() + "分账失败,订单" + req.getBuyerOrderCode();
return new SmsAlarmEvent(alarmConfig.getTransferName(), alarmConfig.name(), content);
} else {
String content = "买家订单分账失败,订单" + req.getBuyerOrderCode();
return new SmsAlarmEvent("buyerOrder.transfer", "transfer", content);
}
smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getTransferName(), alarmConfig.name(), content);
return smsAlarmEvent;
}
}
... ...