|
@@ -2,7 +2,6 @@ package com.yohoufo.order.service.impl; |
|
@@ -2,7 +2,6 @@ package com.yohoufo.order.service.impl; |
2
|
|
2
|
|
3
|
import com.google.common.base.Verify;
|
3
|
import com.google.common.base.Verify;
|
4
|
import com.yoho.error.ServiceError;
|
4
|
import com.yoho.error.ServiceError;
|
5
|
-import com.yoho.error.exception.ServiceException;
|
|
|
6
|
import com.yohobuy.ufo.model.order.common.OrderStatus;
|
5
|
import com.yohobuy.ufo.model.order.common.OrderStatus;
|
7
|
import com.yohoufo.common.alarm.EventBusPublisher;
|
6
|
import com.yohoufo.common.alarm.EventBusPublisher;
|
8
|
import com.yohoufo.common.alarm.SmsAlarmEvent;
|
7
|
import com.yohoufo.common.alarm.SmsAlarmEvent;
|
|
@@ -30,11 +29,13 @@ import java.math.BigDecimal; |
|
@@ -30,11 +29,13 @@ import java.math.BigDecimal; |
30
|
import java.util.Objects;
|
29
|
import java.util.Objects;
|
31
|
import java.util.function.BiConsumer;
|
30
|
import java.util.function.BiConsumer;
|
32
|
|
31
|
|
|
|
32
|
+import static com.yohoufo.order.utils.ServiceExceptions.throwServiceException;
|
|
|
33
|
+
|
33
|
/**
|
34
|
/**
|
34
|
* @author LUOXC
|
35
|
* @author LUOXC
|
35
|
* @date 2019/1/8 14:07
|
36
|
* @date 2019/1/8 14:07
|
36
|
*/
|
37
|
*/
|
37
|
-@Slf4j
|
38
|
+@Slf4j(topic = "orderCloseLog")
|
38
|
class BuyerOrderCancelHandler {
|
39
|
class BuyerOrderCancelHandler {
|
39
|
|
40
|
|
40
|
private final int uid;
|
41
|
private final int uid;
|
|
@@ -65,8 +66,6 @@ class BuyerOrderCancelHandler { |
|
@@ -65,8 +66,6 @@ class BuyerOrderCancelHandler { |
65
|
private BuyerRefundCouponEvent.BizCase refundCouponCase;
|
66
|
private BuyerRefundCouponEvent.BizCase refundCouponCase;
|
66
|
|
67
|
|
67
|
|
68
|
|
68
|
-
|
|
|
69
|
-
|
|
|
70
|
private AlarmConfig failAlarm;
|
69
|
private AlarmConfig failAlarm;
|
71
|
|
70
|
|
72
|
BuyerOrderCancelHandler(int uid, long orderCode) {
|
71
|
BuyerOrderCancelHandler(int uid, long orderCode) {
|
|
@@ -132,12 +131,18 @@ class BuyerOrderCancelHandler { |
|
@@ -132,12 +131,18 @@ class BuyerOrderCancelHandler { |
132
|
}
|
131
|
}
|
133
|
|
132
|
|
134
|
public void cancel() {
|
133
|
public void cancel() {
|
|
|
134
|
+ log.info("cancel order {} from {} to {}", orderCode, expectStatus, targetStatus);
|
135
|
verify();
|
135
|
verify();
|
136
|
// 获取买家订单
|
136
|
// 获取买家订单
|
137
|
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCodeUid(orderCode, uid);
|
137
|
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCodeUid(orderCode, uid);
|
|
|
138
|
+ if (Objects.isNull(buyerOrder)) {
|
|
|
139
|
+ log.info("cancel order {} fail, order is not exist", orderCode);
|
|
|
140
|
+ throwServiceException(ServiceError.ORDER_NOT_EXIST);
|
|
|
141
|
+ }
|
138
|
// 当前状态不可取消订单
|
142
|
// 当前状态不可取消订单
|
139
|
if (expectStatus.getCode() != buyerOrder.getStatus()) {
|
143
|
if (expectStatus.getCode() != buyerOrder.getStatus()) {
|
140
|
- throw new ServiceException(ServiceError.ORDER_SERVICE_ERROR);
|
144
|
+ log.info("cancel order {} fail, order status is not expect", orderCode);
|
|
|
145
|
+ throwServiceException("当前状态不可取消订单");
|
141
|
}
|
146
|
}
|
142
|
// 更新订单状态成功
|
147
|
// 更新订单状态成功
|
143
|
if (updateBuyerOrderStatus()) {
|
148
|
if (updateBuyerOrderStatus()) {
|
|
@@ -145,6 +150,9 @@ class BuyerOrderCancelHandler { |
|
@@ -145,6 +150,9 @@ class BuyerOrderCancelHandler { |
145
|
transfer();
|
150
|
transfer();
|
146
|
refundPayGoodsMoney(buyerOrder);
|
151
|
refundPayGoodsMoney(buyerOrder);
|
147
|
noticeSeller();
|
152
|
noticeSeller();
|
|
|
153
|
+ } else {
|
|
|
154
|
+ log.info("cancel order {} fail, order status has changed", orderCode);
|
|
|
155
|
+ throwServiceException("当前状态不可取消订单");
|
148
|
}
|
156
|
}
|
149
|
}
|
157
|
}
|
150
|
|
158
|
|
|
@@ -180,6 +188,7 @@ class BuyerOrderCancelHandler { |
|
@@ -180,6 +188,7 @@ class BuyerOrderCancelHandler { |
180
|
.uid(uid)
|
188
|
.uid(uid)
|
181
|
.orderCode(orderCode)
|
189
|
.orderCode(orderCode)
|
182
|
.build();
|
190
|
.build();
|
|
|
191
|
+ log.info("refund coupon by order {} request is {}", orderCode, buyerRefundCouponEvent);
|
183
|
EventBusPublisher.publishEvent(buyerRefundCouponEvent);
|
192
|
EventBusPublisher.publishEvent(buyerRefundCouponEvent);
|
184
|
}
|
193
|
}
|
185
|
|
194
|
|
|
@@ -193,6 +202,7 @@ class BuyerOrderCancelHandler { |
|
@@ -193,6 +202,7 @@ class BuyerOrderCancelHandler { |
193
|
.transferCase(transferCase)
|
202
|
.transferCase(transferCase)
|
194
|
.swdType(sellerWalletDetailType)
|
203
|
.swdType(sellerWalletDetailType)
|
195
|
.build();
|
204
|
.build();
|
|
|
205
|
+ log.info("transfer by order {} request is {}", orderCode, transferMoneyRequest);
|
196
|
transferService.transfer(transferMoneyRequest);
|
206
|
transferService.transfer(transferMoneyRequest);
|
197
|
}
|
207
|
}
|
198
|
|
208
|
|
|
@@ -215,9 +225,11 @@ class BuyerOrderCancelHandler { |
|
@@ -215,9 +225,11 @@ class BuyerOrderCancelHandler { |
215
|
.refundCase(goodsMoneyRefundCase)
|
225
|
.refundCase(goodsMoneyRefundCase)
|
216
|
.amount(goodsMoney);
|
226
|
.amount(goodsMoney);
|
217
|
try {
|
227
|
try {
|
|
|
228
|
+ log.info("refund pay goods money by order {} request is {} ", orderCode, paymentRequest);
|
218
|
goodsMoneyRefundConsumer.accept(paymentRequest, billLogEventBuilder.skup(getSkup()));
|
229
|
goodsMoneyRefundConsumer.accept(paymentRequest, billLogEventBuilder.skup(getSkup()));
|
219
|
- } catch (Exception ex) {
|
|
|
220
|
- log.warn("pay refund fail,req {}", paymentRequest, ex);
|
230
|
+ log.info("refund pay goods money by order {} success", orderCode);
|
|
|
231
|
+ } catch (Exception e) {
|
|
|
232
|
+ log.info("refund pay goods money by order {} fail request is {}", orderCode, paymentRequest, e);
|
221
|
BillLogEvent billLogEvent = billLogEventBuilder.tradeStatus(BillTradeStatus.FAIL.getCode()).build();
|
233
|
BillLogEvent billLogEvent = billLogEventBuilder.tradeStatus(BillTradeStatus.FAIL.getCode()).build();
|
222
|
EventBusPublisher.publishEvent(billLogEvent);
|
234
|
EventBusPublisher.publishEvent(billLogEvent);
|
223
|
|
235
|
|
|
@@ -235,10 +247,11 @@ class BuyerOrderCancelHandler { |
|
@@ -235,10 +247,11 @@ class BuyerOrderCancelHandler { |
235
|
private void noticeSeller() {
|
247
|
private void noticeSeller() {
|
236
|
if (Objects.nonNull(sellerNoticeSender)) {
|
248
|
if (Objects.nonNull(sellerNoticeSender)) {
|
237
|
try {
|
249
|
try {
|
|
|
250
|
+ log.info("notice seller buyer order has closed by order {}", orderCode);
|
238
|
SellerOrderGoods sog = getSellerOrderGoods();
|
251
|
SellerOrderGoods sog = getSellerOrderGoods();
|
239
|
sellerNoticeSender.notice(sog, orderCode, sellerNoticeSenderTimes);
|
252
|
sellerNoticeSender.notice(sog, orderCode, sellerNoticeSenderTimes);
|
240
|
- } catch (Exception ex) {
|
|
|
241
|
- log.warn("seller deliver notice fail,times {} order code is {}", sellerNoticeSenderTimes, orderCode, ex);
|
253
|
+ } catch (Exception e) {
|
|
|
254
|
+ log.info("notice seller buyer order has closed by order {} fail", orderCode, e);
|
242
|
}
|
255
|
}
|
243
|
}
|
256
|
}
|
244
|
}
|
257
|
}
|