...
|
...
|
@@ -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);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|