Authored by LUOXC

Merge branch 'test6.8.9' into dev6.8.8

# Conflicts:
#	order/src/main/java/com/yohoufo/order/service/impl/AppraiseService.java
... ... @@ -15,6 +15,10 @@ public enum AlarmConfig {
"buyerOrder.transferEarnestMoney",
"buyerOrder.refundGoodsMoney"),
APPRAISE_UNSURE("鉴定不通过",
"buyerOrder.transferEarnestMoney",
"buyerOrder.refundGoodsMoney"),
SELLER_PLAY_BUYER("卖家取消",
"buyerOrder.transferEarnestMoney",
"buyerOrder.refundGoodsMoney"),
... ... @@ -27,6 +31,8 @@ public enum AlarmConfig {
"buyerOrder.transferEarnestMoney",
"buyerOrder.refundGoodsMoney");
public static final String REFUND_EARNEST_MONEY_NAME = "buyerOrder.refundEarnestMoney";
@Getter
private String desc;
private String transferName;
... ...
package com.yohoufo.order.controller;
import com.yoho.core.rest.annotation.ServiceDesc;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.AppraiseExpressInfoBo;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.req.BuyerOrderCancelReq;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.order.model.request.SaveQualityCheckInfoRequest;
import com.yohoufo.order.service.impl.AppraiseService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -98,6 +96,25 @@ public class AppraiseController {
}
/**
* 已取消:商品无法鉴定
*
* @return
*/
@RequestMapping(value = "/unsure")
@IgnoreSession
@IgnoreSignature
public ApiResponse appraiseUnsure(@RequestBody BuyerOrderCancelReq req) {
logger.info("in appraiseSuccess, req {}", req);
if (req.getUid() <= 0 || req.getOrderCode() <= 0) {
return new ApiResponse.ApiResponseBuilder().code(400).message("参数校验不通过").build();
}
appraiseService.appraiseUnsure(req.getUid(), req.getOrderCode());
return new ApiResponse.ApiResponseBuilder().code(200).build();
}
/**
*
* 质检不通过 -- > 商品鉴定不通过,
* 但是不发物流
... ...
... ... @@ -33,6 +33,7 @@ import com.yohoufo.order.service.handler.RefundEarnestMoneyHandler;
import com.yohoufo.order.service.handler.RefundGoodsMoneyHandler;
import com.yohoufo.order.service.handler.penalty.PenaltyResult;
import com.yohoufo.order.service.handler.penalty.SellerEarnestMoney2BuyerPenaltyCalculator;
import com.yohoufo.order.service.impl.function.BuyerNoticeSender;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.OrderOperateRecordService;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
... ... @@ -1398,4 +1399,42 @@ public class AppraiseService {
return JSON.parseObject(meta.getMetaValue()).getBigDecimal("income");
}
/**
* 鉴定中心无法鉴定商品
*
* @param uid
* @param orderCode
*/
public void appraiseUnsure(Integer uid, Long orderCode) {
new BuyerOrderCancelHandler(uid, orderCode)
.withBuyerOrderSupplier(buyerOrderMapper, buyerOrderGoodsMapper)
.withSellerOrderSupplier(sellerOrderGoodsMapper, sellerOrderMetaMapper)
// 有货平台鉴定中 -> 已取消:商品无法鉴定
.withStateTransition(OrderStatus.PLATFORM_CHECKING, OrderStatus.PLATFORM_APPRAISE_UNSURE, orderStatusFlowService)
// 退保证金给卖家
.withRefundEarnestMoney(payRefundService::refund, sellerOrderMapper::selectBySkup).refundCase(RefundCase.SELLER_EARNEST_MONEY).and()
// 退买家货款
.withRefundGoodsMoney(payRefundService::refund).refundCase(RefundCase.BUYER_GOODS_MONEY).and()
// 通知卖家商品无法鉴定
.withNoticeSeller((soa, code) -> inBoxFacade.noticeSellerAppraiseUnsure(soa, code)).and()
// 通知买家商品无法鉴定(并发券)
.withNoticeBuyer(this::noticeBuyerAndSendCouponForAppraiseUnsure).and()
// 退优惠券
.withRefundCoupon(BuyerRefundCouponEvent.BizCase.SELLER_DELIVER_TIMEOUT)
.withCacheCleaner(cacheCleaner::delete)
.withFailAlarm(AlarmConfig.APPRAISE_UNSURE)
.cancel();
}
/**
* 通知买家商品无法鉴定(并发券)
*
* @param request
*/
private void noticeBuyerAndSendCouponForAppraiseUnsure(BuyerNoticeSender.Request request) {
// 发送优惠券
// 通知买家商品无法鉴定
inBoxFacade.noticeBuyerAppraiseUnsure(request);
}
}
... ...
package com.yohoufo.order.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Verify;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohoufo.common.alarm.EventBusPublisher;
... ... @@ -39,7 +42,7 @@ import java.util.List;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.function.Function;
import static com.yohoufo.order.utils.ServiceExceptions.throwServiceException;
... ... @@ -70,6 +73,8 @@ class BuyerOrderCancelHandler {
private RefundGoodsMoney refundGoodsMoney;
private RefundEarnestMoney refundEarnestMoney;
private NoticeSeller noticeSeller;
private NoticeBuyer noticeBuyer;
... ... @@ -115,6 +120,10 @@ class BuyerOrderCancelHandler {
return new RefundGoodsMoney(goodsMoneyRefundConsumer);
}
public RefundEarnestMoney withRefundEarnestMoney(BiConsumer<PaymentRequest, BillLogEvent.BillLogEventBuilder> goodsMoneyRefundConsumer, Function<Integer, SellerOrder> sellerOrderFunction) {
return new RefundEarnestMoney(goodsMoneyRefundConsumer, sellerOrderFunction);
}
public NoticeSeller withNoticeSeller(SellerNoticeSender sellerNoticeSender) {
return new NoticeSeller(sellerNoticeSender);
}
... ... @@ -169,6 +178,7 @@ class BuyerOrderCancelHandler {
refundCoupon();
transferEarnestMoney2Buyer(buyerOrderGoods.getSkup());
refundPayGoodsMoney(buyerOrder, buyerOrderGoods);
refundEarnestMoney(buyerOrderGoods.getSkup());
noticeSeller(sellerOrderGoods);
noticeBuyer(buyerOrder);
cleanCache(buyerOrder, sellerOrderGoods);
... ... @@ -219,11 +229,11 @@ class BuyerOrderCancelHandler {
if (Objects.isNull(transferService)) {
return;
}
SellerOrderMeta feeMeta = sellerOrderMetaMapper.selectByMetaKey(sellerUid,skup,"fee");
SellerOrderMeta feeMeta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee");
PenaltyResult penaltyResult = SellerEarnestMoney2BuyerPenaltyCalculator.from(feeMeta)
.calculate()
.orElse(null);
if(Objects.nonNull(penaltyResult)){
if (Objects.nonNull(penaltyResult)) {
TranseferCellNode transeferCellNode = new TranseferCellNode();
transeferCellNode.setUid(uid);
transeferCellNode.setAmount(penaltyResult.getPenaltyAmountWithoutYhServiceAmount());
... ... @@ -282,6 +292,72 @@ class BuyerOrderCancelHandler {
}
}
private void refundEarnestMoney(Integer skup) {
if (Objects.isNull(refundEarnestMoney)) {
return;
}
try {
SellerOrderMeta feeMeta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee");
BigDecimal earnestMoney = optEarnestMoney(feeMeta);
if (Objects.isNull(earnestMoney)) {
return;
}
SellerOrder sellerOrder = refundEarnestMoney.sellerOrderFunction().apply(skup);
val paymentRequest = PaymentRequest.builder()
.uid(sellerOrder.getUid())
.refundCase(refundEarnestMoney.refundCase())
.orderCode(sellerOrder.getOrderCode())
.refundAmount(earnestMoney.doubleValue())
.build();
val billLogEventBuilder = BillLogEvent.builder()
.buyerUid(uid)
.sellerUid(sellerOrder.getUid())
.orderCode(sellerOrder.getOrderCode())
.payType(sellerOrder.getPayment())
.refundCase(refundEarnestMoney.refundCase())
.amount(earnestMoney)
.skup(skup);
log.info("refund earnest money by order {} request is {} ", orderCode, paymentRequest);
refundGoodsMoney.refundConsumer().accept(paymentRequest, billLogEventBuilder);
log.info("refund earnest money by order {} success", orderCode);
} catch (Exception e) {
log.warn("refund earnest money by order {} fail", orderCode, e);
if (Objects.nonNull(failAlarm)) {
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(
AlarmConfig.REFUND_EARNEST_MONEY_NAME,
failAlarm.name(),
expectStatus.getDesc() + ",取消订单" + orderCode + "退保证金失败"
);
EventBusPublisher.publishEvent(smsAlarmEvent);
}
}
}
private BigDecimal optEarnestMoney(SellerOrderMeta feeMeta) {
if (feeMeta == null) {
log.warn("feeMeta is null");
throw new ServiceException(500, "计费信息不完整");
}
JSONObject fee;
try {
fee = JSON.parseObject(feeMeta.getMetaValue());
} catch (Exception e) {
log.warn("feeMeta value parse err, uid is {}, skup is {}", feeMeta.getUid(), feeMeta.getSkup(), e);
return null;
}
if (Objects.isNull(fee)) {
log.warn("feeMeta value is null, uid is {}, skup is {}", feeMeta.getUid(), feeMeta.getSkup());
return null;
}
val ensure = fee.getJSONObject("earnestMoney").getBigDecimal("earnestMoney");
if (Objects.isNull(ensure) || ensure.compareTo(BigDecimal.ZERO) < 0) {
log.warn("feeMeta info err, uid is {}, skup is {}, ensure is {}", uid, feeMeta.getSkup(), ensure);
return null;
}
return ensure;
}
private void noticeSeller(SellerOrderGoods sellerOrderGoods) {
if (Objects.nonNull(noticeSeller)) {
try {
... ... @@ -326,6 +402,21 @@ class BuyerOrderCancelHandler {
@Data
@Accessors(fluent = true)
class RefundEarnestMoney {
private final BiConsumer<PaymentRequest, BillLogEvent.BillLogEventBuilder> refundConsumer;
private final Function<Integer, SellerOrder> sellerOrderFunction;
private RefundCase refundCase;
BuyerOrderCancelHandler and() {
BuyerOrderCancelHandler.this.refundEarnestMoney = this;
return BuyerOrderCancelHandler.this;
}
}
@Data
@Accessors(fluent = true)
class RefundGoodsMoney {
private final BiConsumer<PaymentRequest, BillLogEvent.BillLogEventBuilder> refundConsumer;
... ...
... ... @@ -1149,6 +1149,32 @@ public class InBoxFacade {
}
}
public void noticeBuyerAppraiseUnsure(BuyerNoticeSender.Request request){
Integer uid = request.getUid();
Long orderCode = request.getOrderCode();
String params = buildParams(orderCode);
InboxReqVO inboxMessage = buildInboxReqVO(uid, params, InboxBusinessTypeEnum.NOTICE_BUYER_SELLER_SEND_OUT_TIMEOUT);
String smsContent = getReplacedContent(InboxBusinessTypeEnum.SMS_NOTICE_BUYER_SELLER_SEND_OUT_TIMEOUT.getContent(), orderCode);
try {
logger.info("noticeBuyerOfSellerSendOutTimeout,uid {} request is {}", uid, request);
executorService.execute(() -> {
InBoxResponse inBoxResponse = inBoxSDK.addInbox(inboxMessage);
logger.info("noticeBuyerOfSellerSendOutTimeout inbox send success, message is {} res is {}", inboxMessage, inBoxResponse);
String phone = userProxyService.getMobile(uid);
if (StringUtils.isBlank(phone)) {
logger.warn("noticeBuyerOfSellerSendOutTimeout sms send fail,uid {} can not find phone", uid);
return;
}
sendSmsService.smsSendByMobile(smsContent, Arrays.asList(phone));
logger.info("noticeBuyerOfSellerSendOutTimeout sms send success,uid {}", uid);
});
} catch (Exception e) {
logger.warn("noticeBuyerOfSellerSendOutTimeout fail,uid {}", uid, e);
}
}
public void sellerDeliverNotice(SellerOrderGoods sog, long orderCode, int times, int leftTime, String timeUnit) {
Integer sellerUid = sog.getUid();
String prdName = sog.getProductName();
... ... @@ -1176,10 +1202,10 @@ public class InBoxFacade {
executorService.execute(() -> {
logger.info("record sellerDeliverNotice inbox sms msg,sellerUid {}, prdName {}, times {}",
sellerUid, prdName, times);
InboxReqVO req = buildInboxReqVO(sellerUid, params, ibt);
InBoxResponse resp = inBoxSDK.addInbox(req);
logger.info("record sellerDeliverNotice inbox msg,sellerUid {}, prdName {},sizeName {} times {},resp {}",
sellerUid, prdName, sizeName, times, resp);
InboxReqVO req = buildInboxReqVO(sellerUid, params, ibt);
InBoxResponse resp = inBoxSDK.addInbox(req);
logger.info("record sellerDeliverNotice inbox msg,sellerUid {}, prdName {},sizeName {} times {},resp {}",
sellerUid, prdName, sizeName, times, resp);
String phone = userProxyService.getMobile(sellerUid);
if (StringUtils.isBlank(phone)){
... ... @@ -1189,9 +1215,46 @@ public class InBoxFacade {
}
List<String> mobileList = Arrays.asList(phone);
sendSmsService.smsSendByMobile(content, mobileList);
logger.info("record sellerDeliverNotice inbox sms msg,sellerUid {}, prdName {}, times {},resp {}",
sellerUid, prdName, times);
sendSmsService.smsSendByMobile(content, mobileList);
logger.info("record sellerDeliverNotice inbox sms msg,sellerUid {}, prdName {}, times {},resp {}",
sellerUid, prdName, times);
});
} catch (Exception e) {
logger.warn("InBoxFacade sellerDeliverNotice error inbox msg, sellerUid {}, prdName {} ",
sellerUid, prdName, e);
}
}
public void noticeSellerAppraiseUnsure(SellerOrderGoods sog, long orderCode) {
Integer sellerUid = sog.getUid();
String prdName = sog.getProductName();
String sizeName = sog.getSizeName();
InboxBusinessTypeEnum ibt;
InboxBusinessTypeEnum smsInboxBusinessTypeEnum;
String params;
String content;
try {
params = buildParams(prdName, sizeName);
ibt = InboxBusinessTypeEnum.NOTICE_SELLER_DELIVER_GOODS_FAIL;
smsInboxBusinessTypeEnum = InboxBusinessTypeEnum.SMS_NOTIFIED_SEND_FAILED;
content = getReplacedContent(smsInboxBusinessTypeEnum.getContent(), prdName, orderCode);
executorService.execute(() -> {
logger.info("record sellerDeliverNotice inbox sms msg,sellerUid {}, prdName {}", sellerUid, prdName);
InboxReqVO req = buildInboxReqVO(sellerUid, params, ibt);
InBoxResponse resp = inBoxSDK.addInbox(req);
logger.info("record sellerDeliverNotice inbox msg,sellerUid {}, prdName {},sizeName {},resp {}",
sellerUid, prdName, sizeName, resp);
String phone = userProxyService.getMobile(sellerUid);
if (StringUtils.isBlank(phone)) {
logger.warn("sellerDeliverNotice sms send fail,sellerUid {}, prdName {}", sellerUid, prdName);
return;
}
List<String> mobileList = Arrays.asList(phone);
sendSmsService.smsSendByMobile(content, mobileList);
logger.info("record sellerDeliverNotice inbox sms msg,sellerUid {}, prdName {},resp {}",
sellerUid, prdName, resp);
});
} catch (Exception e) {
logger.warn("InBoxFacade sellerDeliverNotice error inbox msg, sellerUid {}, prdName {} ",
... ...