Authored by wujiexiang

fixbug:调价,系统先校验,后锁库存

... ... @@ -25,7 +25,7 @@ public class BuyerOrderPayDiffTimeHandler {
OrdersPay ordersPay = ordersPayMapper.selectOrdersPayByPayLevel(orderCode, buyerUid, payLevel);
Integer payTime;
if (Objects.isNull(ordersPay) || Objects.isNull(payTime = ordersPay.getCreateTime())) {
logger.warn("in calBuyerPenalty not exist paid record.orderCode {}", orderCode);
logger.warn("in calBuyerPenalty not exist paid record.orderCode {},payLevel {}", orderCode, payLevel);
throw new ServiceException(ServiceError.ORDER_HAS_NOT_PAID);
}
int currentTime = DateUtil.getCurrentTimeSecond();
... ...
... ... @@ -104,13 +104,6 @@ public class BuyerBidPriceService {
//校验
context.validate(true);
int oldSkup = context.sellerOrderGoods.getId();
logger.info("[{}] will change price,orderCode:{},oldSkup:{}", uid, context.buyerOrder.getOrderCode(), oldSkup);
//调价前将原skup取消,若生成新skup失败,则需要手动恢复原skup
bidProductProxyService.cancelSaleBeforeChangePrice(oldSkup);
logger.info("[{}] was canceled success", oldSkup);
//构建参数
BuyerBidPublishRequest req = BuyerBidPublishRequest.builder().uid(uid)
.storageId(context.sellerOrderGoods.getStorageId())
... ... @@ -120,7 +113,19 @@ public class BuyerBidPriceService {
.userAddressPair(context.userAddressPair)
.businessClient(request.getBusinessClient())
.build();
BidPublishResult bidPublishResult = buyerBidPublishService.bidPublish(req);
//先计算
BuyerBidPublishService.BidComputeResult bidComputeResult = buyerBidPublishService.doCompute(req);
//计算无问题,锁定oldSkup
int oldSkup = context.sellerOrderGoods.getId();
logger.info("[{}] will change price,orderCode:{},oldSkup:{}", uid, context.buyerOrder.getOrderCode(), oldSkup);
//调价前将原skup取消,若生成新skup失败,则需要手动恢复原skup
bidProductProxyService.cancelSaleBeforeChangePrice(oldSkup);
logger.info("[{}] was canceled success", oldSkup);
//发布
BidPublishResult bidPublishResult = buyerBidPublishService.doBidPublish(req,bidComputeResult);
try {
//记录变价明细
recordChangePriceDetail(context, bidPublishResult);
... ...
... ... @@ -31,7 +31,6 @@ import com.yohoufo.order.model.response.BidPrePublishResponse;
import com.yohoufo.order.model.response.BidPublishResponse;
import com.yohoufo.order.mq.DelayTime;
import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.service.BuyerOrderStateChangers;
import com.yohoufo.order.service.cache.CacheCleaner;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.listener.BuyerOrderChangeEvent;
... ... @@ -101,9 +100,6 @@ public class BuyerBidPublishService {
@Autowired
private OrderChangeListenerContainer orderChangeListenerContainer;
@Autowired
private BuyerOrderStateChangers buyerOrderStateChangers;
/**
* 计算
... ... @@ -112,22 +108,11 @@ public class BuyerBidPublishService {
* 2.商品金额 + 运费
*/
public BidComputeResponse compute(BuyerBidPublishRequest request) {
int uid = request.getUid();
//1.校验如下规则
//1.1 sku必须存在的
//1.2求购价格满足商品的最低和最高红线价,不满足提示价格过低,或者价格过高
//求购金额
BuyerBidConfig buyerBidConfig = metaConfigService.getBuyerBidConfig();
BidAndSuggestPrice bidPrice = new BidAndSuggestPrice(request.getPrice(),
productProxyService.getPrdPriceRange(request.getUid(), request.getStorageId()),
buyerBidConfig.getBasConfig());
//2.计算定金
Deposit deposit = computeDeposit(bidPrice, buyerBidConfig.getDConfig());
logger.info("[{}] buyerBid compute deposit result:{}", uid, deposit);
//3.计算商品金额 + 运费
ChargeContext chargeContext = computeGoods(request, bidPrice);
//计算
BidComputeResult bidComputeResult = doCompute(request);
Deposit deposit = bidComputeResult.deposit;
ChargeContext chargeContext = bidComputeResult.chargeContext;
//算费结果
ChargeResult chargeResult = chargeContext.getChargeResult();
//返回结果
... ... @@ -249,6 +234,11 @@ public class BuyerBidPublishService {
* @return
*/
public BidPublishResult bidPublish(BuyerBidPublishRequest request) {
BidComputeResult bidComputeResult = doCompute(request);
return doBidPublish(request,bidComputeResult);
}
public BidComputeResult doCompute(BuyerBidPublishRequest request) {
int uid = request.getUid();
int storageId = request.getStorageId();
//1.校验如下规则
... ... @@ -264,6 +254,21 @@ public class BuyerBidPublishService {
//3.计算商品金额 + 运费
ChargeContext chargeContext = computeGoods(request, bidPrice);
return new BidComputeResult(buyerBidConfig, bidPrice, deposit, chargeContext);
}
/**
* 发布
* @param request
* @param bidComputeResult
* @return
*/
public BidPublishResult doBidPublish(BuyerBidPublishRequest request, BidComputeResult bidComputeResult) {
int uid = request.getUid();
int storageId = request.getStorageId();
BidAndSuggestPrice bidPrice = bidComputeResult.bidPrice;
Deposit deposit = bidComputeResult.deposit;
ChargeContext chargeContext = bidComputeResult.chargeContext;
//获取商品信息
GoodsInfo goodsInfo = skupService.getProductDetail(uid, storageId, bidPrice.getPrice(), SkupType.getSkupType(request.getSkupType()));
... ... @@ -300,6 +305,7 @@ public class BuyerBidPublishService {
}
/**
* skup 发布
* 记录到seller_order_goods中
... ... @@ -365,4 +371,18 @@ public class BuyerBidPublishService {
return request.getUserAddressPair();
}
}
public class BidComputeResult {
BuyerBidConfig buyerBidConfig;
BidAndSuggestPrice bidPrice;
Deposit deposit;
ChargeContext chargeContext;
public BidComputeResult(BuyerBidConfig buyerBidConfig, BidAndSuggestPrice bidPrice, Deposit deposit, ChargeContext chargeContext) {
this.buyerBidConfig = buyerBidConfig;
this.bidPrice = bidPrice;
this.deposit = deposit;
this.chargeContext = chargeContext;
}
}
}
... ...