Authored by sailing-PC\sailing

fix concurrent issue

... ... @@ -21,8 +21,9 @@ public class ActionStatusHold {
static List<Integer> sellerCanRefundStatus;
static {
sellerCanRefundStatus = Arrays.asList(
SellerOrderStatus.HAS_PAYED.getCode());
sellerCanRefundStatus = Arrays.asList(SellerOrderStatus.YOHO_CANCEL_SELL.getCode(),
SellerOrderStatus.FINISH.getCode(),
SellerOrderStatus.PLAY_SELF.getCode());
}
public static List<Integer> getSellerCanRefundEarnestMoneyStatus(){
... ...
... ... @@ -74,49 +74,49 @@ public class SellerOrderCancelDeliverDelayMsgConsumer implements YhConsumer {
int sellerUid = event.getSellerUid();
OrderStatus expectStatus = OrderStatus.HAS_PAYED;
if (expectStatus.getCode() == buyerOrder.getStatus()){
//将卖家的保证金分账给平台和买家
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(TransferCase.SELLER_PLAY_BUYER.getCode()).transferCase(TransferCase.DELIVER_TIME_OUT)
.build();
transferService.transfer(tmReq);
//
BigDecimal goodsMoney = buyerOrder.getAmount();
PaymentRequest req = PaymentRequest.builder().uid(buyerUid)
.orderCode(orderCode).refundAmount(goodsMoney.doubleValue())
.build();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(skup);
try{
paymentService.refund(req);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(100)
OrderStatus targetStatus = OrderStatus.SEND_OUT_TIMEOUT;
int rows = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expectStatus.getCode(), targetStatus.getCode(),
DateUtil.getCurrentTimeSecond());
if(rows > 0){
//将卖家的保证金分账给平台和买家
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(TransferCase.SELLER_PLAY_BUYER.getCode()).transferCase(TransferCase.DELIVER_TIME_OUT)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
transferService.transfer(tmReq);
//
AddressInfo addressInfo = sellerAddressService.getAddressInfo(sellerUid, skup);
inBoxFacade.sellerDeliverNotice(event.getSellerUid(), event.getProductName(), 3, SmsHelper.getPhones(addressInfo));
}catch (Exception ex){
logger.warn("in topic {} , refund fail,req {}", getMessageTopic(), req, ex);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(200)
BigDecimal goodsMoney = buyerOrder.getAmount();
PaymentRequest req = PaymentRequest.builder().uid(buyerUid)
.orderCode(orderCode).refundAmount(goodsMoney.doubleValue())
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
String content = "发货超时后,订单"+ orderCode + "退货款失败";
AlarmConfig alarmConfig = AlarmConfig.DELIVER_TIME_OUT;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}finally {
OrderStatus targetStatus = OrderStatus.SEND_OUT_TIMEOUT;
buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expectStatus.getCode(), targetStatus.getCode(),
DateUtil.getCurrentTimeSecond());
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(skup);
try{
paymentService.refund(req);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(100)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
//
AddressInfo addressInfo = sellerAddressService.getAddressInfo(sellerUid, skup);
inBoxFacade.sellerDeliverNotice(event.getSellerUid(), event.getProductName(), 3, SmsHelper.getPhones(addressInfo));
}catch (Exception ex){
logger.warn("in topic {} , refund fail,req {}", getMessageTopic(), req, ex);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(200)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
String content = "发货超时后,订单"+ orderCode + "退货款失败";
AlarmConfig alarmConfig = AlarmConfig.DELIVER_TIME_OUT;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}
}
}
... ...
... ... @@ -132,8 +132,8 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
return false;
}
final static List<Integer> canRefundStatusList = Arrays.asList(OrderStatus.HAS_PAYED.getCode(),
OrderStatus.PLATFORM_CHECKING.getCode());
final static List<Integer> canRefundStatusList = Arrays.asList(OrderStatus.SELLER_CANCEL_AFTER_PAY.getCode(),
OrderStatus.SEND_OUT_TIMEOUT.getCode(), OrderStatus.CHECKING_FAKE.getCode());
@Override
public boolean canRefund(OrderInfo orderInfo) {
... ...
... ... @@ -35,7 +35,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
/**
... ... @@ -84,88 +83,29 @@ public class AppraiseService {
LOGGER.warn("appraiseSuccess getOrderInfo order not exist, orderCode is {}", orderCode);
throw new ServiceException(ServiceError.ORDER_NULL);
}
Integer buyerUid=buyerOrder.getUid();
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
int skup = bog.getSkup();
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED;
final SellerOrderStatus targetSoStatus = SellerOrderStatus.FINISH;
if (expectSOStatus.getCode() != sellerOrder.getStatus().intValue()){
LOGGER.warn("in appraiseSuccess, seller Order pstatus {}, expect Seller Order Status {}",
sellerOrder.getStatus(), expectSOStatus);
final OrderStatus expectOrderStatus = OrderStatus.PLATFORM_CHECKING;
final OrderStatus targetOrderStatus = OrderStatus.WAITING_RECEIVE;
if (expectOrderStatus.getCode() != buyerOrder.getStatus().intValue()){
LOGGER.warn("in appraiseSuccess, buyer Order orderCode {} pstatus {}, expect Order Status {}",
orderCode, buyerOrder.getStatus(), expectOrderStatus);
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
}
final Integer sellerUid = sellerOrder.getUid();
final Long sellerOrderCode = sellerOrder.getOrderCode();
TransferCase transferCase = TransferCase.APPRAISE_SUCCESS;
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(transferCase.getCode()).transferCase(transferCase).build();
boolean transferSuccessFlag=transferService.transfer(tmReq);
if(!transferSuccessFlag){
apiResponse.setCode(400);
apiResponse.setMessage("保证金分账失败");
}
/**
* 退保证金给卖家
*/
//refund earnestMoney
BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
PaymentRequest req = PaymentRequest.builder().uid(sellerUid)
.orderCode(sellerOrderCode).refundAmount(earnestMoney.doubleValue())
.build();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(sellerOrder.getOrderCode())
.payType(sellerOrder.getPayment()).refundCase(RefundCase.SELLER_EARNEST_MONEY)
.skup(skup);
try {
paymentService.refund(req);
//通知卖家退还保证金
BuyerConfirmEvent buyerConfirmEvent = BuyerConfirmEvent.builder().uid(buyerUid).orderCode(orderCode).build();
EventBusPublisher.publishEvent(buyerConfirmEvent);
//流水
BillLogEvent sellerBillLogEvent = bleb.tradeStatus(100).build();
EventBusPublisher.publishEvent(sellerBillLogEvent);
//记录物流信息
expressInfoService.appraiseSuccess(buyerUid, expressCompanyId, orderCode, wayBillCode, depotNum);
Integer buyerUid = buyerOrder.getUid();
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
int skup = bog.getSkup();
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
AddressInfo addressInfo = buyerOrderMetaService.getAddressInfo(buyerUid, orderCode);
List<String> phones = SmsHelper.getPhones(addressInfo);
//平台已发货给买家
inBoxFacade.depotDeliver2Buyer(buyerUid, orderCode, phones);
}catch (Exception ex){
LOGGER.warn("in appraiseSuccess,refund fail, req {}", req, ex);
BillLogEvent sellerBillLogEvent = bleb.tradeStatus(200)
.build();
EventBusPublisher.publishEvent(sellerBillLogEvent);
String content = "鉴定通过时,订单"+ orderCode + "退还保证金失败";
AlarmConfig alarmConfig = AlarmConfig.APPRAISE_SUCCESS;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
apiResponse.setCode(400);
apiResponse.setMessage(content);
}finally {
// 更新买家订单状态
LOGGER.info("appraiseSuccess update buyer order {} ", buyerOrder);
final OrderStatus expectOrderStatus = OrderStatus.PLATFORM_CHECKING;
final OrderStatus targetOrderStatus = OrderStatus.WAITING_RECEIVE;
int updateBuyerCnt = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid,
expectOrderStatus.getCode(), targetOrderStatus.getCode(), DateUtil.getCurrentTimeSecond());
if (updateBuyerCnt != 1){
LOGGER.warn("in appraiseSuccess, buyer Order pstatus {}, expect expectOrderStatus {}",
buyerOrder.getStatus(), expectOrderStatus);
}
int updateBuyerCnt = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid,
expectOrderStatus.getCode(), targetOrderStatus.getCode(), DateUtil.getCurrentTimeSecond());
if (updateBuyerCnt == 1){
final Integer sellerUid = sellerOrder.getUid();
final Long sellerOrderCode = sellerOrder.getOrderCode();
final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED;
final SellerOrderStatus targetSoStatus = SellerOrderStatus.FINISH;
/**
* 更新卖家订单状态,
* 退款给卖家(仅退一次)
... ... @@ -178,14 +118,72 @@ public class AppraiseService {
tso.setUpdateTime(DateUtil.getCurrentTimeSecond());
tso.setExceptStatus(expectSOStatus.getCode());
int soCnt = sellerOrderMapper.updateByOrderCode(tso);
if (soCnt == 1){
LOGGER.info("in appraiseSuccess, refund earnestMoney finish, seller {}, order code {}, skup {}, earnestMoney {}",
sellerUid, sellerOrderCode, skup, earnestMoney );
}else{
LOGGER.warn("in appraiseSuccess, seller Order pstatus {}, expect Seller Order Status {}",
sellerOrder.getStatus(), expectSOStatus);
TransferCase transferCase = TransferCase.APPRAISE_SUCCESS;
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(transferCase.getCode()).transferCase(transferCase).build();
boolean transferSuccessFlag=transferService.transfer(tmReq);
if(!transferSuccessFlag){
apiResponse.setCode(400);
apiResponse.setMessage("保证金分账失败");
}
/**
* 退保证金给卖家
*/
//refund earnestMoney
BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
PaymentRequest req = PaymentRequest.builder().uid(sellerUid)
.orderCode(sellerOrderCode).refundAmount(earnestMoney.doubleValue())
.build();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(sellerOrder.getOrderCode())
.payType(sellerOrder.getPayment()).refundCase(RefundCase.SELLER_EARNEST_MONEY)
.skup(skup);
try {
paymentService.refund(req);
//通知卖家退还保证金
BuyerConfirmEvent buyerConfirmEvent = BuyerConfirmEvent.builder().uid(buyerUid).orderCode(orderCode).build();
EventBusPublisher.publishEvent(buyerConfirmEvent);
//流水
BillLogEvent sellerBillLogEvent = bleb.tradeStatus(100).build();
EventBusPublisher.publishEvent(sellerBillLogEvent);
//记录物流信息
expressInfoService.appraiseSuccess(buyerUid, expressCompanyId, orderCode, wayBillCode, depotNum);
AddressInfo addressInfo = buyerOrderMetaService.getAddressInfo(buyerUid, orderCode);
List<String> phones = SmsHelper.getPhones(addressInfo);
//平台已发货给买家
inBoxFacade.depotDeliver2Buyer(buyerUid, orderCode, phones);
}catch (Exception ex){
LOGGER.warn("in appraiseSuccess,refund fail, req {}", req, ex);
BillLogEvent sellerBillLogEvent = bleb.tradeStatus(200)
.build();
EventBusPublisher.publishEvent(sellerBillLogEvent);
String content = "鉴定通过时,订单"+ orderCode + "退还保证金失败";
AlarmConfig alarmConfig = AlarmConfig.APPRAISE_SUCCESS;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
apiResponse.setCode(400);
apiResponse.setMessage(content);
}
LOGGER.info("in appraiseSuccess, refund earnestMoney finish, seller {}, order code {}, skup {}, earnestMoney {}",
sellerUid, sellerOrderCode, skup, earnestMoney );
}else{
LOGGER.warn("in appraiseSuccess, buyer Order pstatus {}, expect expectOrderStatus {}",
buyerOrder.getStatus(), expectOrderStatus);
}
return apiResponse;
}
... ... @@ -214,68 +212,88 @@ public class AppraiseService {
buyerOrder.getStatus(), orderCode);
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
}
// 更新买家订单状态 为鉴定不通过
int buyerUid = buyerOrder.getUid();
OrderStatus targetStatus = OrderStatus.CHECKING_FAKE;
LOGGER.info("appraiseFail update buyer order {} ", buyerOrder);
int rows = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expectStatus.getCode(), targetStatus.getCode(),
DateUtil.getCurrentTimeSecond());
if (rows > 0){
int buyerUid = buyerOrder.getUid();
int sellerUid = buyerOrder.getSellerUid();
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
int skup = bog.getSkup();
int sellerUid = buyerOrder.getSellerUid();
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
int skup = bog.getSkup();
//将卖家的保证金分账给平台和买家
TransferCase transferCase = TransferCase.APPRAISE_FAIL;
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(transferCase.getCode()).transferCase(transferCase).build();
boolean transferSuccessFlag=transferService.transfer(tmReq);
if(!transferSuccessFlag){
apiResponse.setCode(400);
apiResponse.setMessage("保证金分账失败");
}
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
long sellerOrderCode = sellerOrder.getOrderCode();
BigDecimal goodsMoney = buyerOrder.getAmount();
PaymentRequest req = PaymentRequest.builder().uid(buyerUid)
.orderCode(orderCode).refundAmount(goodsMoney.doubleValue())
.build();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(skup);
try{
paymentService.refund(req);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(100)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
inBoxFacade.noticeSellerWhenAppraiseFail(sellerUid, sellerOrderGoods.getProductName());
final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED;
final SellerOrderStatus targetSoStatus = SellerOrderStatus.APPRAISAL_FAIL_COMPENSATE;
SellerOrder tso = new SellerOrder();
tso.setUid(sellerUid);
tso.setOrderCode(sellerOrderCode);
tso.setStatus(targetSoStatus.getCode());
tso.setUpdateTime(DateUtil.getCurrentTimeSecond());
tso.setExceptStatus(expectSOStatus.getCode());
int soCnt = sellerOrderMapper.updateByOrderCode(tso);
//将卖家的保证金分账给平台和买家
TransferCase transferCase = TransferCase.APPRAISE_FAIL;
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(orderCode)
.type(transferCase.getCode()).transferCase(transferCase).build();
boolean transferSuccessFlag=transferService.transfer(tmReq);
if(!transferSuccessFlag){
apiResponse.setCode(400);
apiResponse.setMessage("保证金分账失败");
}
AddressInfo addressInfo = buyerOrderMetaService.getAddressInfo(buyerUid, buyerOrder.getOrderCode());
inBoxFacade.buyerGetEarnestMoneyWhenAppraiseFail(buyerUid, buyerOrder.getOrderCode(), SmsHelper.getPhones(addressInfo));
}catch (Exception ex){
LOGGER.warn("in appraiseFail ,refund fail,req {}", req, ex);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(200)
BigDecimal goodsMoney = buyerOrder.getAmount();
PaymentRequest req = PaymentRequest.builder().uid(buyerUid)
.orderCode(orderCode).refundAmount(goodsMoney.doubleValue())
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
String content = "鉴定不通过时,退用户" + sellerUid + "货款订单"+ orderCode +"失败";
AlarmConfig alarmConfig = AlarmConfig.APPRAISE_FAIL;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
apiResponse.setCode(400);
apiResponse.setMessage(content);
}finally {
// 更新买家订单状态 为鉴定不通过
OrderStatus targetStatus = OrderStatus.CHECKING_FAKE;
LOGGER.info("appraiseFail update buyer order {} ", buyerOrder);
buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expectStatus.getCode(), targetStatus.getCode(),
DateUtil.getCurrentTimeSecond());
//更新物流信息,写到最后
expressInfoService.appraiseFail(sellerUid, expressCompanyId, orderCode, wayBillCode, depotNum);
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(skup);
try{
paymentService.refund(req);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(100)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
//
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
inBoxFacade.noticeSellerWhenAppraiseFail(sellerUid, sellerOrderGoods.getProductName());
AddressInfo addressInfo = buyerOrderMetaService.getAddressInfo(buyerUid, buyerOrder.getOrderCode());
inBoxFacade.buyerGetEarnestMoneyWhenAppraiseFail(buyerUid, buyerOrder.getOrderCode(), SmsHelper.getPhones(addressInfo));
}catch (Exception ex){
LOGGER.warn("in appraiseFail ,refund fail,req {}", req, ex);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(200)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
String content = "鉴定不通过时,退用户" + sellerUid + "货款订单"+ orderCode +"失败";
AlarmConfig alarmConfig = AlarmConfig.APPRAISE_FAIL;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
apiResponse.setCode(400);
apiResponse.setMessage(content);
}finally {
//更新物流信息,写到最后
expressInfoService.appraiseFail(sellerUid, expressCompanyId, orderCode, wayBillCode, depotNum);
}
}
return apiResponse;
}
}
... ...
... ... @@ -133,7 +133,7 @@ public class SellerOrderCancelService {
if (Objects.isNull(sellerOrder)){
return result;
}
final int skup = sellerOrder.getSkup();
Integer status = Optional.ofNullable(sellerOrder).map(SellerOrder::getStatus).orElse(null);
logger.info("in seller cancel, uid {}, orderCode {}, SellerOrder status {}", uid, orderCode, status);
if (Objects.isNull(status)){
... ... @@ -150,16 +150,18 @@ public class SellerOrderCancelService {
SellerOrderStatus targetSOStatus;
//case 1: 未支付时
if (SellerOrderStatus.WAITING_PAY.getCode() == status){
logger.info("in seller cancel waiting pay, uid {} skup {} orderCode {}", uid, skup, orderCode);
targetSOStatus = SellerOrderStatus.SELf_CANCEL_PAY;
SellerOrderStatusNode statusNode = SellerOrderStatusNode.builder()
.exceptStatus(SellerOrderStatus.WAITING_PAY).targetStatus(targetSOStatus).build();
result = cancelBeforePayAction(uid, orderCode, sellerOrder.getSkup(), statusNode);
result = cancelBeforePayAction(uid, orderCode, skup, statusNode);
}
//case 2: 支付完成,没有买家下单
//case 3: 支付完成,有买家下单
if (SellerOrderStatus.HAS_PAYED.getCode() == status){
logger.info("in seller cancel after paid, uid {} skup {} orderCode {}", uid, skup, orderCode);
result = cancelAfterPayAction(sellerOrder, buyerOrder);
}
... ... @@ -202,17 +204,28 @@ public class SellerOrderCancelService {
private int cancelBeforePayAction(int uid, long orderCode, Integer skup, SellerOrderStatusNode statusNode){
SellerOrderStatus targetSOStatus = statusNode.targetStatus;
SellerOrderStatus exceptStatus = statusNode.exceptStatus;
logger.info("in seller cancel before Buy Action, uid {}, orderCode {}, targetSOStatus {}, exceptStatus {}",
uid, orderCode, targetSOStatus, exceptStatus);
logger.info("in seller cancel before Buy Action, uid {} skup {} orderCode {} targetSOStatus {}, exceptStatus {}",
uid, skup, orderCode, targetSOStatus, exceptStatus);
/**case 1: 未支付时
* actions as blow:
* 1. sellerOrder
* 2. sellerOrderGoods
* 3. 同步product skup状态
* 1. 同步product skup状态
* 2. sellerOrder
* 3. sellerOrderGoods
*
*/
//并发控制
//refund earnestMoney
//sync skup
int result = 0;
//update seller order
if (Objects.nonNull(targetSOStatus)){
SellerOrderGoods sogCondition = new SellerOrderGoods();
sogCondition.setId(skup);
sogCondition.setStatus(targetSOStatus.getSkupStatus().getCode());
sogCondition.setExceptStatus(exceptStatus.getSkupStatus().getCode());
result += sellerOrderGoodsMapper.updateByPrimaryKeySelective(sogCondition);
if (result > 0) {
//update seller order
SellerOrder target = new SellerOrder();
target.setOrderCode(orderCode);
target.setUid(uid);
... ... @@ -222,21 +235,21 @@ public class SellerOrderCancelService {
target.setStatus(targetSOStatus.getCode());
target.setUpdateTime(DateUtil.getCurrentTimeSecond());
result += sellerOrderMapper.updateByOrderCode(target);
//sync skup
SellerOrderGoods tsog = new SellerOrderGoods();
tsog.setId(skup);
try{
productProxyService.syncSkup(tsog, targetSOStatus.getSkupStatus());
}catch(Exception ex){
logger.warn("in seller cancel before Buy Action syncSkup fail, uid {}, skup {}", uid, skup, ex);
}
//TODO 1. cache goods 2. async execute msg
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
inBoxFacade.sellerPlaySelf(uid,psog.getProductName());
}
//并发控制
//refund earnestMoney
//sync skup
SellerOrderGoods sogCondition = new SellerOrderGoods();
sogCondition.setId(skup);
sogCondition.setStatus(targetSOStatus.getSkupStatus().getCode());
result += sellerOrderGoodsMapper.updateByPrimaryKeySelective(sogCondition);
//TODO 1. cache goods 2. async execute msg
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
inBoxFacade.sellerPlaySelf(uid,psog.getProductName());
//sync skup
SellerOrderGoods tsog = new SellerOrderGoods();
tsog.setId(skup);
productProxyService.syncSkup(tsog, targetSOStatus.getSkupStatus());
return result;
}
... ... @@ -252,43 +265,43 @@ public class SellerOrderCancelService {
final int sellerUid = sellerOrder.getUid();
final long orderCode = sellerOrder.getOrderCode();
int skup = sellerOrder.getSkup();
logger.info("in seller cancel when Seller Pay But Not Buy Action, uid {}, orderCode {}",
sellerUid, orderCode);
double earnestMoney = sellerOrder.getEarnestMoney().doubleValue();
PaymentRequest refundReq = PaymentRequest.builder().uid(sellerUid)
.orderCode(orderCode)
.refundAmount(earnestMoney).build();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.sellerUid(sellerUid).orderCode(orderCode)
.payType(sellerOrder.getPayment()).refundCase(RefundCase.SELLER_EARNEST_MONEY)
.skup(skup);
try {
paymentService.refund(refundReq);
logger.info("in cancelAfterPayButNotBuyAction, refund earnestMoney finish, seller {}, order code {}, skup {}, earnestMoney {}",
sellerUid, orderCode, skup, earnestMoney);
//fail bill log
BillLogEvent sellerBillLogEvent = bleb.tradeStatus(100)
.build();
EventBusPublisher.publishEvent(sellerBillLogEvent);
}catch (Exception ex){
logger.warn("in appraiseSuccess, refund fail, req {}", refundReq, ex);
BillLogEvent sellerBillLogEvent = bleb.tradeStatus(200)
.build();
EventBusPublisher.publishEvent(sellerBillLogEvent);
String content = "用户" + sellerUid + "退保证金订单"+ orderCode +"失败";
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("notPaidSellerOrder.selfCancel", "cancelBeforeBuy", content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}
int result = 0;
SellerOrderStatus targetSOStatus;
targetSOStatus = SellerOrderStatus.PLAY_SELF;
logger.info("in seller cancel when Seller Pay But Not Buy Action, uid {} orderCode {} skup {}",
sellerUid, orderCode, skup);
SellerOrderStatus targetSOStatus = SellerOrderStatus.PLAY_SELF;
SellerOrderStatus expectStatus = SellerOrderStatus.HAS_PAYED;
SellerOrderStatusNode statusNode = SellerOrderStatusNode.builder().targetStatus(targetSOStatus)
.exceptStatus(expectStatus).build();
result = cancelBeforePayAction(sellerUid, orderCode, skup, statusNode);
int result = cancelBeforePayAction(sellerUid, orderCode, skup, statusNode);
if(result > 0 ){
double earnestMoney = sellerOrder.getEarnestMoney().doubleValue();
PaymentRequest refundReq = PaymentRequest.builder().uid(sellerUid)
.orderCode(orderCode)
.refundAmount(earnestMoney).build();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.sellerUid(sellerUid).orderCode(orderCode)
.payType(sellerOrder.getPayment()).refundCase(RefundCase.SELLER_EARNEST_MONEY)
.skup(skup);
try {
paymentService.refund(refundReq);
logger.info("in cancelAfterPayButNotBuyAction, refund earnestMoney finish, seller {}, order code {}, skup {}, earnestMoney {}",
sellerUid, orderCode, skup, earnestMoney);
//fail bill log
BillLogEvent sellerBillLogEvent = bleb.tradeStatus(100)
.build();
EventBusPublisher.publishEvent(sellerBillLogEvent);
}catch (Exception ex){
logger.warn("in appraiseSuccess, refund fail, req {}", refundReq, ex);
BillLogEvent sellerBillLogEvent = bleb.tradeStatus(200)
.build();
EventBusPublisher.publishEvent(sellerBillLogEvent);
String content = "用户" + sellerUid + "退保证金订单"+ orderCode +"失败";
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("notPaidSellerOrder.selfCancel", "cancelBeforeBuy", content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}
}
return result;
}
... ... @@ -305,60 +318,22 @@ public class SellerOrderCancelService {
final int sellerUid = sellerOrder.getUid(), buyerUid = buyerOrder.getUid();
final long sellerOrderCode = sellerOrder.getOrderCode(), buyerOrderCode = buyerOrder.getOrderCode();
logger.info("in seller cancel After Pay while Exist Buy Action, uid {}, orderCode {}, buyerOrderCode {}",
logger.info("in seller cancel After Paid while Exist Buy Action, uid {}, orderCode {}, buyerOrderCode {}",
sellerUid, sellerOrderCode, buyerOrderCode);
BigDecimal goodsMoney = buyerOrder.getAmount();
PaymentRequest req = PaymentRequest.builder().uid(buyerUid)
.orderCode(buyerOrderCode).refundAmount(goodsMoney.doubleValue())
.build();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(buyerOrderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(sellerOrder.getSkup());
try{
//分赃(分账) 有待考虑使用2比对
TransferCase transferCase = TransferCase.SELLER_PLAY_BUYER;
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(buyerOrderCode)
.type(transferCase.getCode()).transferCase(transferCase).build();
transferService.transfer(tmReq);
paymentService.refund(req);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(100)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
//
AddressInfo addressInfo = buyerOrderMetaService.getAddressInfo(buyerUid, buyerOrderCode);
inBoxFacade.noticeBuyerWhenSellerCancelAfterPaid(buyerUid, buyerOrderCode, SmsHelper.getPhones(addressInfo));
//TODO 异步
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(sellerOrder.getSkup());
inBoxFacade.sellerCancelAfterBuyerPaid(sellerUid, psog.getProductName());
}catch (Exception ex){
logger.warn("in cancelAfterPayExistBuyAction , refund fail,req {}", req, ex);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(200)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
String content = "订单"+ buyerOrderCode + "退货款失败";
AlarmConfig alarmConfig = AlarmConfig.SELLER_PLAY_BUYER;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}finally{
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);
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);
if(result > 0) {
//update seller order
SellerOrderStatus targetSOStatus;
targetSOStatus = SellerOrderStatus.PLAY_BUYER;
... ... @@ -370,19 +345,54 @@ public class SellerOrderCancelService {
target.setExceptStatus(SellerOrderStatus.HAS_PAYED.getCode());
result += sellerOrderMapper.updateByOrderCode(target);
return result;
BigDecimal goodsMoney = buyerOrder.getAmount();
PaymentRequest req = PaymentRequest.builder().uid(buyerUid)
.orderCode(buyerOrderCode).refundAmount(goodsMoney.doubleValue())
.build();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(buyerOrderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(sellerOrder.getSkup());
try{
//分赃(分账) 有待考虑使用2比对
TransferCase transferCase = TransferCase.SELLER_PLAY_BUYER;
TransferMoneyRequest tmReq = TransferMoneyRequest.builder().buyerOrderCode(buyerOrderCode)
.type(transferCase.getCode()).transferCase(transferCase).build();
transferService.transfer(tmReq);
paymentService.refund(req);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(100)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
//
AddressInfo addressInfo = buyerOrderMetaService.getAddressInfo(buyerUid, buyerOrderCode);
inBoxFacade.noticeBuyerWhenSellerCancelAfterPaid(buyerUid, buyerOrderCode, SmsHelper.getPhones(addressInfo));
//TODO 异步
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(sellerOrder.getSkup());
inBoxFacade.sellerCancelAfterBuyerPaid(sellerUid, psog.getProductName());
}catch (Exception ex){
logger.warn("in cancelAfterPayExistBuyAction , refund fail,req {}", req, ex);
BillLogEvent buyererBillLogEvent = bleb.tradeStatus(200)
.build();
EventBusPublisher.publishEvent(buyererBillLogEvent);
String content = "订单"+ buyerOrderCode + "退货款失败";
AlarmConfig alarmConfig = AlarmConfig.SELLER_PLAY_BUYER;
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(alarmConfig.getRefundName(), alarmConfig.name(), content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}
}
return result;
}
private int cancelAfterPayAction(SellerOrder sellerOrder, BuyerOrder buyerOrder){
final int sellerUid = sellerOrder.getUid();
final long orderCode = sellerOrder.getOrderCode();
logger.info("in seller cancel After Buy Action, uid {}, orderCode {}",
sellerUid, orderCode);
int skup = sellerOrder.getSkup();
logger.info("in seller cancel After paid Action, uid {}, orderCode {} skup {}",
sellerUid, orderCode, skup);
int result = 0;
int buyOrderCnt = buyerOrder== null ? 0 : 1;
... ... @@ -466,9 +476,32 @@ public class SellerOrderCancelService {
logger.warn("in offShelveCancelCase, SellerOrderGoods status illegal, skup {}, status {}", skup, skupStatus);
return;
}
final SellerOrderStatus targetSellerOrderStatus = SellerOrderStatus.YOHO_CANCEL_SELL;
//TODO check skup is buy away
SellerOrderGoods targetGoods = new SellerOrderGoods();
targetGoods.setId(skup);
targetGoods.setStatus(targetSellerOrderStatus.getSkupStatus().getCode());
targetGoods.setExceptStatus(skupStatus);
//利用数据库做并发控制
int result = sellerOrderGoodsMapper.updateStatusBySkpu(targetGoods);
if (result == 0) {
logger.warn("in offShelveCancelCase, update status fail, skup {}, skupStatus {}", skup, skupStatus);
return;
}
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
Integer sellerUid = sellerOrder.getUid();
Long orderCode = sellerOrder.getOrderCode();
//update
SellerOrder tso = new SellerOrder();
tso.setOrderCode(sellerOrder.getOrderCode());
tso.setExceptStatus(sellerOrder.getStatus());
tso.setStatus(targetSellerOrderStatus.getCode());
tso.setUid(sellerUid);
tso.setUpdateTime(DateUtil.getCurrentTimeSecond());
sellerOrderMapper.updateByOrderCode(tso);
double earnestMoney = sellerOrder.getEarnestMoney().doubleValue();
PaymentRequest refundReq = PaymentRequest.builder().uid(sellerOrder.getUid())
.orderCode(sellerOrder.getOrderCode())
... ... @@ -498,26 +531,6 @@ public class SellerOrderCancelService {
String content = "下架skup时,退用户" + sellerUid + "保证金订单"+ orderCode +"失败";
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent("PaidSellerOrder.PlatformCancel", "cancelBeforeBuy", content);
EventBusPublisher.publishEvent(smsAlarmEvent);
}finally {
final SellerOrderStatus targetSellerOrderStatus = SellerOrderStatus.YOHO_CANCEL_SELL;
//TODO check skup is buy away
SellerOrderGoods targetGoods = new SellerOrderGoods();
targetGoods.setId(skup);
targetGoods.setStatus(targetSellerOrderStatus.getSkupStatus().getCode());
targetGoods.setExceptStatus(skupStatus);
//利用数据库做并发控制
int result = sellerOrderGoodsMapper.updateStatusBySkpu(targetGoods);
if (result == 0) {
return;
}
SellerOrder tso = new SellerOrder();
tso.setOrderCode(sellerOrder.getOrderCode());
tso.setExceptStatus(sellerOrder.getStatus());
tso.setStatus(targetSellerOrderStatus.getCode());
tso.setUid(sellerUid);
tso.setUpdateTime(DateUtil.getCurrentTimeSecond());
result = sellerOrderMapper.updateByOrderCode(tso);
}
}
... ...