Authored by TANLING

Merge branch 'test6.9.22' of http://git.yoho.cn/ufo/yohoufo-fore into test6.9.22

... ... @@ -276,9 +276,7 @@
update seller_order
<set>
income = #{income,jdbcType=DECIMAL},
<if test="couponCutAmount != null">
coupon_cut_amount = #{couponCutAmount,jdbcType=DECIMAL},
</if>
coupon_cut_amount = #{couponCutAmount,jdbcType=DECIMAL}
</set>
where uid = #{uid,jdbcType=INTEGER}
and order_code = #{orderCode,jdbcType=BIGINT}
... ...
... ... @@ -198,9 +198,6 @@
status=1
</set>
where uid= #{uid}
<if test="userType != null">
and user_type= #{userType,jdbcType=INTEGER}
</if>
and coupon_code in
<foreach collection="couponCodes" index="index" item="couponCode"
open="(" separator="," close=")">
... ...
... ... @@ -4,6 +4,8 @@ import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SellerOrderStatus;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import java.util.Arrays;
import java.util.List;
... ... @@ -13,6 +15,8 @@ import java.util.List;
*/
public class ActionStatusHold {
private static final Logger sellerLog = LoggerUtils.getSellerOrderLogger();
public static List<Integer> getSellerCanCancelStatus(){
return SellerASH.CanCancelStatus;
... ... @@ -256,6 +260,29 @@ public class ActionStatusHold {
static List<Integer> SellerCanModifyAddressBySelf = Lists.newArrayList(OrderStatus.HAS_PAYED.getCode());
static List<Integer> SELLER_COMPUTE_BY_BUYERORDER = Lists.newArrayList(OrderStatus.HAS_PAYED.getCode());
/**
* 退券
* 鉴定不通过取消
* 买家订单取消(发货后买家取消)
* 卖家虚假发货(客服 系统自动)
* 质检不通过取消
* 瑕疵确认不通过取消
* 瑕疵确认超时取消
* 无法鉴定
* 商品检测不通过
*/
static List<Integer> SELLER_COUPON_REFUND = Arrays.asList(
OrderStatus.CHECKING_FAKE.getCode(),
OrderStatus.BUYER_CANCEL_BEFORE_DEPOT_RECEIVE.getCode(),
OrderStatus.SELLER_SHAM_SEND_OUT.getCode(),
OrderStatus.SELLER_SHAM_SEND_OUT_AUTO.getCode(),
OrderStatus.QUALITY_CHECK_FAKE.getCode(),
OrderStatus.MINI_FAULT_REJECT.getCode(),
OrderStatus.MINI_FAULT_OUT_TIME_REJECT.getCode(),
OrderStatus.PLATFORM_APPRAISE_UNSURE.getCode(),
OrderStatus.PLATFORM_DETECTION_NOT_PASS.getCode()
);
}
public static List<Integer> getUnfinishedOrderStatusCode(){
... ... @@ -309,4 +336,13 @@ public class ActionStatusHold {
public static boolean sellerCanUseCoupon(Integer buyerOrderStatus){
return SellerASH.SELLER_COMPUTE_BY_BUYERORDER.contains(buyerOrderStatus);
}
public static boolean canRefundSellerCoupon(Integer buyerOrderStatus){
List<Integer> statusList = SellerASH.SELLER_COUPON_REFUND;
boolean result = statusList.contains(buyerOrderStatus);
sellerLog.info("canRefundSellerCoupon statusList {} buyerOrderStatus {} result {}",
statusList,buyerOrderStatus, result);
return result;
}
}
... ...
package com.yohoufo.order.event;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.function.Function;
@ToString(of = {"buyerOrderCode"})
public class CancelSellerCouponAsyncEvent extends AsyncEvent{
@Getter@Setter
private Long buyerOrderCode;
@Getter@Setter
private SellerOrderGoods sellerOrderGoods;
public CancelSellerCouponAsyncEvent(Function<CancelSellerCouponAsyncEvent,Boolean> function) {
super(function);
}
@Override
AsyncEvent getAsyncEvent() {
return this;
}
}
... ...
package com.yohoufo.order.model.bo;
import lombok.Data;
import lombok.ToString;
import lombok.Builder;
import lombok.*;
import java.math.BigDecimal;
... ... @@ -12,6 +10,8 @@ import java.math.BigDecimal;
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CouponBo {
//券code
private String couponCode;
... ...
... ... @@ -46,6 +46,7 @@ import com.yohoufo.order.service.impl.function.BuyerNoticeSender;
import com.yohoufo.order.service.listener.BuyerOrderChangeEvent;
import com.yohoufo.order.service.listener.OrderChangeListenerContainer;
import com.yohoufo.order.service.proxy.*;
import com.yohoufo.order.service.seller.SellerOrderServiceDelegate;
import com.yohoufo.order.service.seller.orderMeta.SellerAddressService;
import com.yohoufo.order.service.seller.orderMeta.SellerOrderMetaService;
import com.yohoufo.order.service.seller.setting.SellerService;
... ... @@ -168,6 +169,9 @@ public class AppraiseService {
@Autowired
private SellerOrderMetaService sellerOrderMetaService;
@Autowired
private SellerOrderServiceDelegate sellerOrderServiceDelegate;
/**
* 触发物流
*/
... ... @@ -732,9 +736,10 @@ public class AppraiseService {
/**
* 更新卖家订单状态,
*/
SellerOrderGoods sellerOrderGoods = updateSellerOrderStatusAndCleanCache(sellerUid, sellerOrderCode, expectSOStatus, targetSoStatus,
int ucnt = updateSellerOrderStatusAndCleanCache(sellerUid, sellerOrderCode, expectSOStatus, targetSoStatus,
skup, orderCode, buyerUid);
//退款给卖家(仅退一次)
PaymentRequest refundReqOfSeller = operateMoneyWhenOk(buyerUid, orderCode, sellerOrder, targetSoStatus);
... ... @@ -755,6 +760,7 @@ public class AppraiseService {
//记录操作记录
orderOperateRecordService.addRecord(orderCode, "买家操作", OperateTypeEnum.OPERATE_TYPE_QUALITY_MINI_FAULT_PASS);
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
sellerNoticeFacade.appraisePass(buyerUid, buyerOrder, sellerOrderGoods, true);
} else {
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE); // 更新失败,可能是因为订单状态已经被并发修改
... ... @@ -847,12 +853,17 @@ public class AppraiseService {
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
long sellerOrderCode = sellerOrder.getOrderCode();
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
//async refund seller coupon
sellerOrderServiceDelegate.getSellerOrderService()
.asyncCancelWithCouponIfPresent(orderCode, targetStatus.getCode(), sellerOrderGoods);
final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED;
final SellerOrderStatus targetSoStatus = SellerOrderStatus.MINI_FAULT_REJECT;
SellerOrderGoods sellerOrderGoods = updateSellerOrderStatusAndCleanCache(sellerUid, sellerOrderCode, expectSOStatus, targetSoStatus,
int ucnt = updateSellerOrderStatusAndCleanCache(sellerUid, sellerOrderCode, expectSOStatus, targetSoStatus,
skup, orderCode, buyerUid);
//将卖家的保证金扣掉10元后,剩余的钱退回给卖家
BigDecimal earnestMoney = sellerOrder.getEarnestMoney().subtract(new BigDecimal(miniFaultRejectPunishFee));
PaymentRequest refundReqOfSeller = refundEarnestMoney(SellerWalletDetail.Type.MINI_FAULT_REJECT, orderCode, sellerUid, sellerOrder, buyerUid, targetSoStatus, earnestMoney.doubleValue());
... ... @@ -937,7 +948,7 @@ public class AppraiseService {
* @param buyerUid
* @return
*/
private SellerOrderGoods updateSellerOrderStatusAndCleanCache(int sellerUid,
private int updateSellerOrderStatusAndCleanCache(int sellerUid,
long sellerOrderCode,
SellerOrderStatus expectSOStatus,
SellerOrderStatus targetSoStatus,
... ... @@ -950,9 +961,8 @@ public class AppraiseService {
tso.setStatus(targetSoStatus.getCode());
tso.setUpdateTime(DateUtil.getCurrentTimeSecond());
int soCnt = sellerOrderMapper.updateByOrderCode(tso);
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
cleanCacheAfterUpdateStatus(orderCode, buyerUid, sellerUid);
return sellerOrderGoods;
return soCnt;
}
... ... @@ -1008,9 +1018,14 @@ public class AppraiseService {
DateUtil.getCurrentTimeSecond());
if (rows > 0) {
RefundMoneyResultModel refundMoneyResultModel = operateMoneyWhenCheckFail(buyerOrder, orderCode, targetStatus);
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(bog.getSkup());
//async refund seller coupon
sellerOrderServiceDelegate.getSellerOrderService()
.asyncCancelWithCouponIfPresent(orderCode, targetStatus.getCode(), sellerOrderGoods);
RefundMoneyResultModel refundMoneyResultModel = operateMoneyWhenCheckFail(buyerOrder, bog, targetStatus);
boolean refundGoodsMoneyFlag = refundMoneyResultModel.isRefundGoodsMoneyFlag();
SellerOrderGoods sellerOrderGoods = refundMoneyResultModel.getSellerOrderGoods();
if (!refundGoodsMoneyFlag) {
apiResponse.setCode(400);
... ... @@ -1143,14 +1158,15 @@ public class AppraiseService {
@Data
class RefundMoneyResultModel {
boolean refundGoodsMoneyFlag;
SellerOrderGoods sellerOrderGoods;
int skup;
}
/**
* 鉴定不通或者质检不通过
* 操作钱
*/
private RefundMoneyResultModel operateMoneyWhenCheckFail(BuyerOrder buyerOrder, Long orderCode, OrderStatus targetStatus) {
private RefundMoneyResultModel operateMoneyWhenCheckFail(BuyerOrder buyerOrder, BuyerOrderGoods bog, OrderStatus targetStatus) {
Long orderCode = buyerOrder.getOrderCode();
LOGGER.info("operateMoney enter , orderCode {},targetStatus {} ", orderCode, targetStatus);
RefundMoneyResultModel model = new RefundMoneyResultModel();
int buyerUid = buyerOrder.getUid();
... ... @@ -1162,7 +1178,7 @@ public class AppraiseService {
EventBusPublisher.publishEvent(brce);
//
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
int skup = bog.getSkup();
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
... ... @@ -1171,9 +1187,10 @@ public class AppraiseService {
final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED;
final SellerOrderStatus targetSoStatus = SellerOrderStatus.APPRAISAL_FAIL_COMPENSATE;
SellerOrderGoods sellerOrderGoods = updateSellerOrderStatusAndCleanCache(sellerUid, sellerOrderCode, expectSOStatus, targetSoStatus,
int updateSOCnt = updateSellerOrderStatusAndCleanCache(sellerUid, sellerOrderCode, expectSOStatus, targetSoStatus,
skup, orderCode, buyerUid);
//将卖家的保证金分账给平台和买家
PenaltyResult penaltyResult = SellerEarnestMoney2BuyerPenaltyCalculator.from(sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee"))
.calculate()
... ... @@ -1215,8 +1232,9 @@ public class AppraiseService {
.loadSellerOrderGoods(sellerUid, skup)
.refund();
model.setRefundGoodsMoneyFlag(refundGoodsMoneyFlag);
model.setSellerOrderGoods(sellerOrderGoods);
model.setSkup(skup);
return model;
}
... ... @@ -1257,9 +1275,14 @@ public class AppraiseService {
DateUtil.getCurrentTimeSecond());
if (rows > 0) {
RefundMoneyResultModel refundMoneyResultModel = operateMoneyWhenCheckFail(buyerOrder, orderCode, targetStatus);
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(bog.getSkup());
//async refund seller coupon
sellerOrderServiceDelegate.getSellerOrderService()
.asyncCancelWithCouponIfPresent(orderCode, targetStatus.getCode(), sellerOrderGoods);
//
RefundMoneyResultModel refundMoneyResultModel = operateMoneyWhenCheckFail(buyerOrder, bog, targetStatus);
boolean refundGoodsMoneyFlag = refundMoneyResultModel.isRefundGoodsMoneyFlag();
SellerOrderGoods sellerOrderGoods = refundMoneyResultModel.getSellerOrderGoods();
if (!refundGoodsMoneyFlag) {
apiResponse.setCode(400);
String content = "后台鉴定商品不通过,退用户" + sellerUid + "货款订单" + orderCode + "失败";
... ... @@ -1351,15 +1374,20 @@ public class AppraiseService {
DateUtil.getCurrentTimeSecond());
if (rows > 0) {
RefundMoneyResultModel refundMoneyResultModel = operateMoneyWhenCheckFail(buyerOrder, orderCode, targetStatus);
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(bog.getSkup());
//async refund seller coupon
sellerOrderServiceDelegate.getSellerOrderService()
.asyncCancelWithCouponIfPresent(orderCode, targetStatus.getCode(), sellerOrderGoods);
RefundMoneyResultModel refundMoneyResultModel = operateMoneyWhenCheckFail(buyerOrder, bog, targetStatus);
boolean refundGoodsMoneyFlag = refundMoneyResultModel.isRefundGoodsMoneyFlag();
SellerOrderGoods sellerOrderGoods = refundMoneyResultModel.getSellerOrderGoods();
if (!refundGoodsMoneyFlag) {
apiResponse.setCode(400);
String content = "后台质检不通过时,退用户" + sellerUid + "货款订单" + orderCode + "失败";
apiResponse.setMessage(content);
}
//记录订单的状态变更信息
LOGGER.info("in qualityCheckReject record status change, orderCode {},uid {} ,sellerUid {}", orderCode, buyerUid, sellerUid);
try {
... ... @@ -1455,8 +1483,9 @@ public class AppraiseService {
/**
* 更新卖家订单状态,
*/
SellerOrderGoods sellerOrderGoods = updateSellerOrderStatusAndCleanCache(sellerUid, sellerOrderCode, expectSOStatus, targetSoStatus,
int updateSOCnt = updateSellerOrderStatusAndCleanCache(sellerUid, sellerOrderCode, expectSOStatus, targetSoStatus,
skup, orderCode, buyerUid);
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
//退款给卖家(仅退一次)
PaymentRequest refundReqOfSeller = operateMoneyWhenOk(buyerUid, orderCode, sellerOrder, targetSoStatus);
try {
... ... @@ -1597,9 +1626,9 @@ public class AppraiseService {
*
*/
//更新卖家订单状态
SellerOrderGoods sellerOrderGoods = updateSellerOrderStatusAndCleanCache(sellerUid, sellerOrderCode, expectSOStatus, targetSoStatus,
int ucnt = updateSellerOrderStatusAndCleanCache(sellerUid, sellerOrderCode, expectSOStatus, targetSoStatus,
skup, orderCode, buyerUid);
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
//退款给卖家(仅退一次)
PaymentRequest refundReqOfSeller = operateMoneyWhenOk(buyerUid, orderCode, sellerOrder, targetSoStatus);
try {
... ... @@ -1704,6 +1733,7 @@ public class AppraiseService {
.withCacheCleaner(cacheCleaner::delete)
.withFailAlarm(AlarmConfig.APPRAISE_UNSURE)
.withOrderChangeListenerContainer(orderChangeListenerContainer)
.withSellerOrderServiceDelegate(sellerOrderServiceDelegate)
.cancel();
}
... ... @@ -1744,6 +1774,7 @@ public class AppraiseService {
.withCacheCleaner(cacheCleaner::delete)
.withFailAlarm(AlarmConfig.DETECTION_NOT_PASS)
.withOrderChangeListenerContainer(orderChangeListenerContainer)
.withSellerOrderServiceDelegate(sellerOrderServiceDelegate)
.cancel(remark);
}
... ...
... ... @@ -34,6 +34,7 @@ import com.yohoufo.order.service.impl.function.RecordSuppleExpressSender;
import com.yohoufo.order.service.impl.function.SellerNoticeSender;
import com.yohoufo.order.service.listener.OrderChangeListenerContainer;
import com.yohoufo.order.service.proxy.OrderStatusFlowService;
import com.yohoufo.order.service.seller.SellerOrderServiceDelegate;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
... ... @@ -173,6 +174,14 @@ class BuyerOrderCancelHandler {
return this;
}
private SellerOrderServiceDelegate sellerOrderServiceDelegate;
public BuyerOrderCancelHandler withSellerOrderServiceDelegate(SellerOrderServiceDelegate sosd){
this.sellerOrderServiceDelegate = sosd;
return this;
}
public void cancel() {
this.cancel(null);
}
... ... @@ -207,6 +216,7 @@ class BuyerOrderCancelHandler {
log.info("cancel order {} from {} to {} success", orderCode, expectStatus, targetStatus);
addSuppleExpress(sellerUid);
refundCoupon();
refundSellerCoupon(sellerOrderGoods);
transferEarnestMoney2Buyer(buyerOrderGoods.getSkup());
refundPayGoodsMoney(buyerOrder, buyerOrderGoods);
refundEarnestMoney(buyerOrderGoods.getSkup());
... ... @@ -220,6 +230,9 @@ class BuyerOrderCancelHandler {
throwServiceException("当前状态不可取消订单");
}
}
private void refundSellerCoupon(SellerOrderGoods sellerOrderGoods){
sellerOrderServiceDelegate.getSellerOrderService().asyncCancelWithCouponIfPresent(orderCode, targetStatus.getCode(), sellerOrderGoods);
}
private void verify() {
... ...
... ... @@ -43,6 +43,7 @@ import com.yohoufo.order.service.handler.RefundEarnestMoneyHandler;
import com.yohoufo.order.service.handler.RefundGoodsMoneyHandler;
import com.yohoufo.order.service.listener.OrderChangeListenerContainer;
import com.yohoufo.order.service.proxy.*;
import com.yohoufo.order.service.seller.SellerOrderServiceDelegate;
import com.yohoufo.order.service.seller.setting.SellerService;
import com.yohoufo.order.service.seller.support.SkupTypeCodeSupport;
import com.yohoufo.order.utils.LoggerUtils;
... ... @@ -152,7 +153,7 @@ public class BuyerOrderCancelService {
private DepositService depositService;
@Autowired
private MetaConfigService metaConfigService;
private SellerOrderServiceDelegate sellerOrderServiceDelegate;
@Autowired
private BuyerOrderAssistant buyerOrderAssistant;
... ... @@ -300,6 +301,7 @@ public class BuyerOrderCancelService {
.withCacheCleaner(cacheCleaner::delete)
.withFailAlarm(AlarmConfig.SELLER_SHAM_SEND_OUT)
.withOrderChangeListenerContainer(orderChangeListenerContainer)
.withSellerOrderServiceDelegate(sellerOrderServiceDelegate)
.cancel();
}
... ... @@ -368,7 +370,7 @@ public class BuyerOrderCancelService {
|| BigDecimal.ZERO.compareTo(penaltyAmount) == 0;
//退还优惠券
asyncRefundCoupon(buyerUid, orderCode, BuyerRefundCouponEvent.BizCase.BUYER_CANCEL_BDR);
//todo async
int skup = bdrEvent.getSkup();
SellerOrderGoods targetGoods = new SellerOrderGoods();
targetGoods.setId(skup);
... ... @@ -381,6 +383,9 @@ public class BuyerOrderCancelService {
soc.setUpdateTime(DateUtil.getCurrentTimeSecond());
sellerOrderMapper.updateBySkups(soc, Arrays.asList(skup));
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
//
asyncRefundSellerCoupon(orderCode, targetOrderStatus, psog);
if (noResponsibility) {
sellerNoticeFacade.noticeSellerWhenBuyerCancelNoResponsibility(psog, orderCode, false);
} else {
... ... @@ -679,6 +684,12 @@ public class BuyerOrderCancelService {
EventBusPublisher.publishEvent(buyerRefundCouponEvent);
}
public void asyncRefundSellerCoupon(long orderCode, OrderStatus targetStatus, SellerOrderGoods sellerOrderGoods){
sellerOrderServiceDelegate.getSellerOrderService()
.asyncCancelWithCouponIfPresent(orderCode, targetStatus.getCode(), sellerOrderGoods);
}
private class ClearanceFailModel {
private final long orderCode;
private final String failReason;
... ...
... ... @@ -15,6 +15,7 @@ import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.common.utils.PageHelper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
... ... @@ -26,11 +27,11 @@ import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.event.*;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.model.SellerOrderRelatedBuyerOrderContext;
import com.yohoufo.order.model.bo.CouponBo;
import com.yohoufo.order.model.bo.CouponBoList;
import com.yohoufo.order.model.dto.*;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.model.request.OrderRequest;
import com.yohobuy.ufo.model.order.resp.OrderDetailInfo;
import com.yohoufo.order.model.response.OrderSubmitResp;
import com.yohoufo.order.mq.DelayTime;
import com.yohoufo.order.service.IOrderDetailService;
... ... @@ -46,16 +47,13 @@ import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase;
import com.yohoufo.order.service.impl.visitor.UserCancelCase;
import com.yohoufo.order.service.proxy.*;
import com.yohoufo.order.service.seller.SellerAuthCheckService;
import com.yohoufo.order.service.seller.SellerOrderCancelService;
import com.yohoufo.order.service.seller.support.SellerOrderContextFactory;
import com.yohoufo.order.service.seller.trade.SellerOrderComputeService;
import com.yohoufo.order.service.seller.SellerOrderServiceDelegate;
import com.yohoufo.order.service.seller.SkupBatchService;
import com.yohoufo.order.service.seller.orderMeta.SellerFeeService;
import com.yohoufo.order.service.seller.processor.*;
import com.yohoufo.order.service.seller.setting.SellerService;
import com.yohoufo.order.service.seller.setting.SellerWrapper;
import com.yohoufo.order.service.seller.trade.SellerOrderSubmitService;
import com.yohoufo.order.service.seller.support.SellerOrderContextFactory;
import com.yohoufo.order.service.support.CouponSupport;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
... ... @@ -137,33 +135,15 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
private SellerDownShelfPrepareProcessor sellerDownShelfPrepareProcessor;
@Autowired
private SellerFeeService sellerFeeService;
@Autowired
private UserProxyService userProxyService;
@Autowired
private SellerTaskProcessor sellerTaskProcessor;
@Autowired
private SellerIncrPriceTaskHandler sellerIncrPriceTaskHandler;
@Autowired
private SellerDecrPriceTaskHandler sellerDecrPriceTaskHandler;
@Autowired
private SellerDownShelfTaskHandler sellerDownShelfTaskHandler;
@Autowired
private SellerOrderComputeService sellerOrderComputeService;
private SellerOrderServiceDelegate sellerOrderServiceDelegate;
@Autowired
private SellerNoticeFacade sellerNoticeFacade;
@Autowired
private SellerAuthCheckService sellerAuthCheckService;
@Autowired
private SellerBatchCancelPrepareProcessor sellerBatchCancelPrepareProcessor;
@Autowired
... ... @@ -176,13 +156,10 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
private MetaConfigService metaConfigService;
@Autowired
private SellerService sellerService;
@Autowired
private BuyerOrderAssistant buyerOrderAssistant;
@Autowired
private SellerOrderSubmitService sellerOrderSubmitService;
private CouponProxyService couponProxyService;
private static final int MAX_DEAL = 10;
... ... @@ -302,7 +279,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
public OrderSubmitResp publishPrd(SellerOrderSubmitReq req) {
protectPublish(req);
int uid = req.getUid();
SellerWrapper sellerWrapper = sellerService.getFullDimensionSeller(uid);
SellerWrapper sellerWrapper = sellerOrderServiceDelegate.getSellerService().getFullDimensionSeller(uid);
SellerBo sellerBo = sellerWrapper.buildSellerBo();
if (sellerBo.isLargeSettlementSuper()){
log.warn("publishPrd user is overseas ,uid {}", uid);
... ... @@ -341,7 +318,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
//扣减保证金
final int num = req.getNum();
int uid = req.getUid();
SellerBo sellerBo = sellerAuthCheckService.checkAuth(uid, ctx.getSkupType(), SellerFuncEnum.BATCH_PUBLISH);
SellerBo sellerBo = sellerOrderServiceDelegate.getSellerAuthCheckService().checkAuth(uid, ctx.getSkupType(), SellerFuncEnum.BATCH_PUBLISH);
Boolean isSuper = sellerBo.isSuper();
SellerOrderComputeResult socr = ctx.getSellerOrderComputeResult();
BigDecimal singleEarestMoney = socr.getEarnestMoney().getEarnestMoney();
... ... @@ -429,7 +406,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
}
SellerWalletDetail.Type swdType = SellerWalletDetail.Type.SELLER_OFF;
int uid = req.getUid();
SellerBo sellerBo = sellerAuthCheckService.checkAuth(uid, null, SellerFuncEnum.BATCH_OFFSHELVE);
SellerBo sellerBo = sellerOrderServiceDelegate.getSellerAuthCheckService().checkAuth(uid, null, SellerFuncEnum.BATCH_OFFSHELVE);
Boolean isSuper = sellerBo.isSuper();
MerchantOrderAttachInfo moai = MerchantOrderAttachInfo.builder().uid(uid)
.earnestMoney(totalRefundEM).productCount(needCancelSkups.size())
... ... @@ -600,11 +577,12 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
* @return
*/
@Deprecated
public BatchChangePriceResp batchChangePrice(BatchChangePriceReq req) throws GatewayException {
public BatchChangePriceResp batchChangePrice(BatchChangePriceReq req) {
ChangePricePrepareDTO cppDto = changePricePrepareProcessor.checkAndAcquire(req);
BigDecimal preSalePrice = cppDto.getPreSalePrice(),
salePrice = cppDto.getSalePrice();
SellerBo sellerBo = sellerAuthCheckService.checkAuth(req.getUid(), null, SellerFuncEnum.BATCH_CHANGEPRICE);
SellerBo sellerBo = sellerOrderServiceDelegate.getSellerAuthCheckService()
.checkAuth(req.getUid(), null, SellerFuncEnum.BATCH_CHANGEPRICE);
boolean isSuper = sellerBo.isSuper();
int uid = req.getUid();
Map<Integer, SkupDto> skupMap = cppDto.getSkupMap();
... ... @@ -642,7 +620,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
sogc.setGoodsPrice(salePrice);
sellerOrderGoodsMapper.updateByPrimaryKeys(sogc, skupSet);
sellerFeeService.updateBatch(skupSet,computeResult );
sellerOrderServiceDelegate.getSellerFeeService().updateBatch(skupSet,computeResult );
//4 划账记录
List<SellerOrder> psoList = sellerOrderMapper.selectBySkups(skupSet);
... ... @@ -708,25 +686,26 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
//校验及计算金额
ChangePricePrepareDTO cppDto = adjustPricePrepareProcessor.checkAndAcquire(req);
final SkupType skupType = cppDto.getSkupType();
SellerBo sellerBo = sellerAuthCheckService.checkAuth(req.getUid(), skupType, SellerFuncEnum.BATCH_CHANGEPRICE);
SellerBo sellerBo = sellerOrderServiceDelegate.getSellerAuthCheckService()
.checkAuth(req.getUid(), skupType, SellerFuncEnum.BATCH_CHANGEPRICE);
SellerTaskDTO<ChangePricePrepareDTO> taskDTO = null;
if (cppDto.getSalePrice().compareTo(cppDto.getPreSalePrice()) > 0) {
//涨价
taskDTO = new SellerTaskDTO(req.getUid(),
SellerWalletDetail.Type.ADD_PRICE.getValue(),
sellerIncrPriceTaskHandler,
sellerOrderServiceDelegate.getSellerIncrPriceTaskHandler(),
JSON.toJSONString(req),cppDto);
} else if (cppDto.getSalePrice().compareTo(cppDto.getPreSalePrice()) < 0) {
//降价
taskDTO = new SellerTaskDTO(req.getUid(),
SellerWalletDetail.Type.SUBTRACT_PRICE.getValue(),
sellerDecrPriceTaskHandler,
sellerOrderServiceDelegate.getSellerDecrPriceTaskHandler(),
JSON.toJSONString(req),cppDto);
} else {
throw new UfoServiceException(400, "价格没有变化");
}
SellerTaskResult result = sellerTaskProcessor.process(taskDTO);
SellerTaskResult result = sellerOrderServiceDelegate.getSellerTaskProcessor().process(taskDTO);
//返还结果
BatchChangePriceResp resp = BatchChangePriceResp.builder().successCnt(result.successCnt).failCnt(result.failCnt)
... ... @@ -743,11 +722,11 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
SkupDownShelfPrepareDto skupDtoMap = sellerDownShelfPrepareProcessor.checkAndAcquire(req);
SellerTaskDTO<SkupDownShelfPrepareDto> taskDTO = new SellerTaskDTO(req.getUid(),
SellerWalletDetail.Type.SELLER_OFF.getValue(),
sellerDownShelfTaskHandler,
sellerOrderServiceDelegate.getSellerDownShelfTaskHandler(),
JSON.toJSONString(req),
skupDtoMap);
SellerTaskResult result = sellerTaskProcessor.process(taskDTO);
SellerTaskResult result = sellerOrderServiceDelegate.getSellerTaskProcessor().process(taskDTO);
return result.successCnt > 0 ? true : false;
}
... ... @@ -971,7 +950,8 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
SellerOrderGoods psog = preparedData.getSellerOrderGoods();
SellerOrderComputeResult computeResult = sellerFeeService.getSellerOrderComputeResult(psog.getUid(), psog.getId());
SellerOrderComputeResult computeResult = sellerOrderServiceDelegate.getSellerFeeService()
.getSellerOrderComputeResult(psog.getUid(), psog.getId());
//todo next version maybe set autoRecommended
boolean autoRecommended = "Y".equalsIgnoreCase(req.getAutoRecommended());
... ... @@ -988,7 +968,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
sorboc.setChargeParam(chargeParam);
sorboc.setSellerOrderComputeResult(computeResult);
sellerOrderComputeService.compute(sorboc);
sellerOrderServiceDelegate.getSellerOrderComputeService().compute(sorboc);
return SellerOrderConvertor.convertWithCoupon(sorboc);
}
... ... @@ -1002,7 +982,8 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
SellerOrderChargeParam chargeParam = SellerOrderChargeParam.builder()
.chargeStage(SellerOrderChargeParam.SUBMIT).build();
Supplier<SellerOrderComputeResult> computeResultSupplier = ()->sellerFeeService.getSellerOrderComputeResult(psog.getUid(), psog.getId());
Supplier<SellerOrderComputeResult> computeResultSupplier = ()->sellerOrderServiceDelegate.getSellerFeeService()
.getSellerOrderComputeResult(psog.getUid(), psog.getId());
SellerOrderRelatedBuyerOrderContext sorboc = SellerOrderContextFactory.builder()
.uid(psog.getUid())
.couponCode(couponCode).businessClient(businessClient)
... ... @@ -1011,9 +992,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
.sellerOrderGoods(psog)
.build().buildSellerOrderRelatedBuyerOrderContext();
sellerOrderComputeService.compute(sorboc);
sellerOrderServiceDelegate.getSellerOrderComputeService().compute(sorboc);
//TODO how to keep atomic,rollback when fail
... ... @@ -1030,13 +1009,73 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic
.couponBoList(couponBoList)
.computeResult(computeResult)
.build();
sellerOrderSubmitService.submitByOld(submitDTO);
sellerOrderServiceDelegate.getSellerOrderSubmitService().submitByOld(submitDTO);
}
public void asyncCancelWithCouponIfPresent(Long buyerOrderCode,Integer orderStatus, SellerOrderGoods sellerOrderGoods){
log.info("asyncCancelWithCouponIfPresent buyerOrderCode {} OrderStatus {}", buyerOrderCode, orderStatus);
if (!ActionStatusHold.canRefundSellerCoupon(orderStatus)){
log.info("asyncCancelWithCouponIfPresent orderStatus not illegal buyerOrderCode {} OrderStatus {}", buyerOrderCode, orderStatus);
return;
}
CancelSellerCouponAsyncEvent asyncEvent = new CancelSellerCouponAsyncEvent(this::cancelWithCouponIfPresent);
asyncEvent.setBuyerOrderCode(buyerOrderCode);
asyncEvent.setSellerOrderGoods(sellerOrderGoods);
EventBusPublisher.publishEvent(asyncEvent);
log.info("asyncCancelWithCouponIfPresent producer finish, buyerOrderCode {}", buyerOrderCode);
}
public boolean cancelWithCouponIfPresent(CancelSellerCouponAsyncEvent asyncEvent){
log.info("async cancelWithCouponIfPresent consumer accept, buyerOrderCode {}", asyncEvent.getBuyerOrderCode());
cancelWithCouponIfPresent(asyncEvent.getBuyerOrderCode(), asyncEvent.getSellerOrderGoods());
return true;
}
/**
*
* @param buyerOrderCode
* @param sellerOrderGoods
*/
public void cancelWithCouponIfPresent(Long buyerOrderCode,SellerOrderGoods sellerOrderGoods){
public void cancelWithCoupon(){
log.info("cancel seller CouponIfPresent, buyerOrderCode {}",buyerOrderCode);
try {
Integer skup = sellerOrderGoods.getId();
//
List<CouponBo> couponBos = sellerOrderServiceDelegate.getSellerOrderMetaService()
.getUsedCoupons(skup, sellerOrderGoods.getUid());
if (CollectionUtils.isEmpty(couponBos)) {
log.warn("cancel seller Coupon not Present, buyerOrderCode {}", buyerOrderCode);
return;
}
List<String> couponCodes = couponBos.stream().map(CouponBo::getCouponCode).collect(Collectors.toList());
SellerOrder pso = sellerOrderMapper.selectBySkup(skup);
couponProxyService.orderCancelCoupon(pso.getUid(), pso.getOrderCode(), couponCodes);
//
CouponBoList couponBoList = CouponBoList.builder().couponBos(couponBos).build();
//
SellerOrderComputeResult computeResult = sellerOrderServiceDelegate.getSellerFeeService()
.getSellerOrderComputeResult(pso.getUid(), skup);
computeResult.setAmountIsReset(true);
//
BigDecimal couponCutAmount = pso.getCouponCutAmount();
BigDecimal oldIncome = pso.getIncome();
BigDecimal newIncome = BigDecimalHelper.sub(oldIncome, couponCutAmount);
BigDecimal newCouponCutAmount = BigDecimal.ZERO;
log.info("cancel seller Coupon, income [{}->{}],couponCutAmount [{}->{}]", oldIncome, newIncome, couponCutAmount, newCouponCutAmount);
computeResult.setIncome(newIncome);
computeResult.setCouponCutAmount(newCouponCutAmount);
SellerOrderSubmitDTO submitDTO = SellerOrderSubmitDTO.builder()
.sellerOrder(pso)
.couponBoList(couponBoList)
.computeResult(computeResult)
.build();
sellerOrderServiceDelegate.getSellerOrderUpdateService().updateCouponAmount(submitDTO);
}catch (Exception ex){
log.warn("cancel seller CouponIfPresent occur some error, buyerOrderCode {}",buyerOrderCode, ex);
}
}
... ...
... ... @@ -146,6 +146,9 @@ public class SellerOrderCancelService {
@Autowired
private BidProductProxyService bidProductProxyService;
@Autowired
private SellerOrderServiceDelegate sellerOrderServiceDelegate;
/**
* TODO 如何控制好并发,必须控制不能重复转账 退款
* 使用乐观锁,带着查询到的状态且符合条件时再去更新
... ... @@ -650,6 +653,10 @@ public class SellerOrderCancelService {
//清理买家、卖家订单相关缓存
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(sellerOrder.getSkup());
//asnyc
sellerOrderServiceDelegate.getSellerOrderService()
.asyncCancelWithCouponIfPresent(buyerOrderCode, targetBOStatus.getCode(), psog);
cacheCleaner.cleanSellerAndBuyerOrderDetailAndList(sellerUid, buyerUid, buyerOrderCode);
ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid);
... ...
package com.yohoufo.order.service.seller;
import com.yohoufo.order.service.handler.SellerDecrPriceTaskHandler;
import com.yohoufo.order.service.handler.SellerDownShelfTaskHandler;
import com.yohoufo.order.service.handler.SellerIncrPriceTaskHandler;
import com.yohoufo.order.service.impl.SellerOrderService;
import com.yohoufo.order.service.seller.orderMeta.SellerFeeService;
import com.yohoufo.order.service.seller.orderMeta.SellerOrderMetaService;
import com.yohoufo.order.service.seller.processor.SellerTaskProcessor;
import com.yohoufo.order.service.seller.setting.SellerService;
import com.yohoufo.order.service.seller.trade.SellerOrderComputeService;
import com.yohoufo.order.service.seller.trade.SellerOrderSubmitService;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class SellerOrderServiceDelegate {
@Autowired
@Getter
private SellerOrderComputeService sellerOrderComputeService;
@Autowired
@Getter
private SellerOrderUpdateService sellerOrderUpdateService;
@Autowired
@Getter
private SellerOrderSubmitService sellerOrderSubmitService;
@Autowired
@Getter
private SellerOrderMetaService sellerOrderMetaService;
@Autowired
@Getter
private SellerFeeService sellerFeeService;
@Autowired
@Getter
private SellerAuthCheckService sellerAuthCheckService;
@Autowired
@Getter
private SellerService sellerService;
@Autowired@Getter
private SellerTaskProcessor sellerTaskProcessor;
@Autowired@Getter
private SellerIncrPriceTaskHandler sellerIncrPriceTaskHandler;
@Autowired@Getter
private SellerDecrPriceTaskHandler sellerDecrPriceTaskHandler;
@Autowired@Getter
private SellerDownShelfTaskHandler sellerDownShelfTaskHandler;
@Autowired@Getter
private SellerOrderService sellerOrderService;
}
... ...
package com.yohoufo.order.service.seller;
import com.google.common.collect.Lists;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.order.model.bo.CouponBo;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.model.dto.SellerOrderSubmitDTO;
import com.yohoufo.order.service.seller.orderMeta.SellerOrderMetaService;
... ... @@ -13,6 +15,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@Service
public class SellerOrderUpdateService {
... ... @@ -21,17 +26,44 @@ public class SellerOrderUpdateService {
private SellerOrderMapper sellerOrderMapper;
@Autowired
private SellerOrderMetaService sellerOrderMetaService;
private SellerOrderServiceDelegate sellerOrderServiceDelegate;
@Transactional(propagation = Propagation.REQUIRED)
@Database(ForceMaster=true, DataSource="ufo_order")
public boolean updateAmount(SellerOrderSubmitDTO submitDTO){
public boolean saveCouponAmount(SellerOrderSubmitDTO submitDTO){
SellerOrder sellerOrder = submitDTO.getSellerOrder();
if (submitDTO.getCouponBoList().isNotEmpty()){
sellerOrderMetaService.saveUsedCoupons(sellerOrder.getSkup(), sellerOrder.getUid(), submitDTO.getCouponBoList().getCouponBos());
sellerOrderServiceDelegate.getSellerOrderMetaService()
.saveUsedCoupons(sellerOrder.getSkup(), sellerOrder.getUid(), submitDTO.getCouponBoList().getCouponBos());
}
SellerOrderComputeResult computeResult = submitDTO.getComputeResult();
if (computeResult.isAmountIsReset()){
SellerOrder condition = new SellerOrder();
condition.setOrderCode(sellerOrder.getOrderCode());
condition.setUid(sellerOrder.getUid());
condition.setCouponCutAmount(computeResult.getCouponCutAmount());
condition.setIncome(computeResult.getIncome());
int updateOrderRusult = sellerOrderMapper.updateAmountByOrderCode(condition);
logger.info("SellerOrderUpdateService.saveCouponAmount sellerOrderMapper.updateAmountByOrderCode condition {} result {}", condition, updateOrderRusult);
//
int updateComputeResult = sellerOrderServiceDelegate.getSellerFeeService().updateBatch(Lists.newArrayList(sellerOrder.getSkup()), computeResult);
logger.info("SellerOrderUpdateService.saveCouponAmount SellerFeeService.update computeResult {} result {}", computeResult, updateComputeResult);
}
return true;
}
@Transactional(propagation = Propagation.REQUIRED)
@Database(ForceMaster=true, DataSource="ufo_order")
public boolean updateCouponAmount(SellerOrderSubmitDTO submitDTO){
SellerOrder sellerOrder = submitDTO.getSellerOrder();
List<CouponBo> couponBos = submitDTO.getCouponBoList().isNotEmpty() ? submitDTO.getCouponBoList().getCouponBos() : new ArrayList<>(0);
sellerOrderServiceDelegate.getSellerOrderMetaService().updateUsedCoupons(sellerOrder.getSkup(), sellerOrder.getUid(), couponBos);
SellerOrderComputeResult computeResult = submitDTO.getComputeResult();
if (computeResult.isAmountIsReset()){
SellerOrder condition = new SellerOrder();
... ... @@ -40,7 +72,10 @@ public class SellerOrderUpdateService {
condition.setCouponCutAmount(computeResult.getCouponCutAmount());
condition.setIncome(computeResult.getIncome());
int updateOrderRusult = sellerOrderMapper.updateAmountByOrderCode(condition);
logger.info("SellerOrderUpdateService.updateAmount sellerOrderMapper.updateAmountByOrderCode condition {} result {}", condition, updateOrderRusult);
logger.info("SellerOrderUpdateService.updateCouponAmount sellerOrderMapper.updateAmountByOrderCode condition {} result {}", condition, updateOrderRusult);
//
int updateComputeResult = sellerOrderServiceDelegate.getSellerFeeService().updateBatch(Lists.newArrayList(sellerOrder.getSkup()), computeResult);
logger.info("SellerOrderUpdateService.updateCouponAmount SellerFeeService.update computeResult {} result {}", computeResult, updateComputeResult);
}
return true;
... ...
package com.yohoufo.order.service.seller.orderMeta;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.google.common.base.Throwables;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yohoufo.dal.order.SellerOrderMetaMapper;
import com.yohoufo.dal.order.model.SellerOrderMeta;
... ... @@ -14,6 +16,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@Service
... ... @@ -55,4 +58,31 @@ public class SellerOrderMetaService {
sellerOrderMetaMapper.insert(som);
return som.getId();
}
public int updateUsedCoupons(int skup,int uid, List<CouponBo> usedCoupons){
String key = MetaKey.SELLER_USED_COUPON;
SellerOrderMeta som = new SellerOrderMeta();
som.setUid(uid);
som.setSkup(skup);
som.setMetaKey(key);
som.setMetaValue(JSONObject.toJSONString(usedCoupons));
int result = sellerOrderMetaMapper.updateValue(som);
return result;
}
public List<CouponBo> getUsedCoupons(int skup,int uid){
String key = MetaKey.SELLER_USED_COUPON;
SellerOrderMeta som = sellerOrderMetaMapper.selectByMetaKey(uid, skup, key);
List<CouponBo> couponBos = null;
if (Objects.nonNull(som)){
try{
couponBos = JSONObject.parseObject(som.getMetaValue(), new TypeReference<List<CouponBo>>(){});
}catch (Exception ex){
logger.warn("get seller coupon parse from DB fail {}, ex {}",som, Throwables.getStackTraceAsString(ex));
}
}
return couponBos;
}
}
... ...
... ... @@ -35,7 +35,7 @@ public class SellerOrderSubmitService {
SellerOrder sellerOrder = submitDTO.getSellerOrder();
logger.info("in SellerOrderSubmitService.submitByOld, {}", sellerOrder);
//修改卖家订单
sellerOrderUpdateService.updateAmount(submitDTO);
sellerOrderUpdateService.saveCouponAmount(submitDTO);
//
try {
//使用优惠券
... ...