|
|
package com.yohoufo.order.service.seller.processor;
|
|
|
package com.yohoufo.order.service.seller.changePrice;
|
|
|
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
|
|
|
import com.yohobuy.ufo.model.order.bo.PrdPrice;
|
|
|
import com.yohobuy.ufo.model.order.common.SkupStatus;
|
|
|
import com.yohobuy.ufo.model.order.constants.SkupType;
|
|
|
import com.yohobuy.ufo.model.order.req.NESChangePriceReq;
|
|
|
import com.yohobuy.ufo.model.order.vo.AddressInfo;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
|
|
|
import com.yohoufo.dal.order.SellerOrderMapper;
|
|
|
import com.yohoufo.dal.order.model.SellerOrder;
|
|
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
|
|
import com.yohoufo.order.common.Payment;
|
|
|
import com.yohoufo.order.model.NESCPOrderContext;
|
|
|
import com.yohoufo.order.model.SellerOrderContext;
|
|
|
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
|
|
|
import com.yohoufo.order.model.dto.SkupDto;
|
|
|
import com.yohoufo.order.model.request.PrdQueryReq;
|
|
|
import com.yohoufo.order.model.dto.SingleChangePricePrepareDTO;
|
|
|
import com.yohoufo.order.service.impl.SellerAddressService;
|
|
|
import com.yohoufo.order.service.impl.SkupService;
|
|
|
import com.yohoufo.order.service.seller.OrderComputeHandler;
|
|
|
import com.yohoufo.order.service.seller.OrderComputeProvider;
|
|
|
import com.yohoufo.order.service.seller.PublishProcessor;
|
|
|
import com.yohoufo.order.utils.LoggerUtils;
|
|
|
import com.yohoufo.order.utils.OrderAssist;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
...
|
...
|
@@ -34,6 +25,7 @@ import java.math.BigDecimal; |
|
|
import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* 单个非钱包支付(非入驻时上架)skup变价
|
|
|
* Created by chao.chen on 2019/3/22.
|
|
|
*/
|
|
|
@Service
|
...
|
...
|
@@ -41,17 +33,6 @@ public class NESChangePricePublishProcessor |
|
|
implements PublishProcessor<NESChangePriceReq, SellerOrderContext> {
|
|
|
|
|
|
final Logger logger = LoggerUtils.getSellerOrderLogger();
|
|
|
@Autowired
|
|
|
SellerOrderGoodsMapper sellerOrderGoodsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
PriceComputePrepareProcessor priceComputePrepareProcessor;
|
|
|
|
|
|
@Autowired
|
|
|
OrderComputeProvider orderComputeProvider;
|
|
|
|
|
|
@Autowired
|
|
|
private NESChangePricePrepareProcessor nesChangePricePrepareProcessor;
|
|
|
|
|
|
@Autowired
|
|
|
private SellerAddressService sellerAddressService;
|
...
|
...
|
@@ -60,10 +41,8 @@ public class NESChangePricePublishProcessor |
|
|
private SkupService skupService;
|
|
|
|
|
|
@Autowired
|
|
|
SellerOrderMapper sellerOrderMapper;
|
|
|
private NESChangePricePrepareProcessor nesChangePricePrepareProcessor;
|
|
|
|
|
|
@Autowired
|
|
|
private ChangePriceCommonPrepareProcessor changePriceCommonPrepareProcessor;
|
|
|
|
|
|
@Override
|
|
|
public NESCPOrderContext buildPublishCtx(NESChangePriceReq im) {
|
...
|
...
|
@@ -71,58 +50,26 @@ public class NESChangePricePublishProcessor |
|
|
}
|
|
|
|
|
|
private NESCPOrderContext buildSellerOrderContext(NESChangePriceReq req) {
|
|
|
|
|
|
int uid = req.getUid();
|
|
|
if (uid <= 0){
|
|
|
logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
|
|
|
throw new UfoServiceException(400, "参数[uid]错误");
|
|
|
}
|
|
|
int skup = req.getSkup();
|
|
|
if (skup<=0){
|
|
|
logger.warn("in ChangePrice find illegal skup code, req {}", req);
|
|
|
throw new UfoServiceException(400, "参数skup非法");
|
|
|
}
|
|
|
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
|
|
|
if (Objects.isNull(psog)){
|
|
|
logger.warn("in ChangePrice can not find skup in sys, req {}", req);
|
|
|
throw new UfoServiceException(400, "商品不存在");
|
|
|
}
|
|
|
//check payment type
|
|
|
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
|
|
|
if (Payment.WALLET.getCode() == sellerOrder.getPayment()){
|
|
|
logger.warn("in ChangePrice seller order paid by wallet, req {}", req);
|
|
|
throw new UfoServiceException(400, "请移步库存管理中变价");
|
|
|
}
|
|
|
SingleChangePricePrepareDTO scppDto = nesChangePricePrepareProcessor.checkAndAcquire(req);
|
|
|
SkupType skupType = scppDto.getSkupType();
|
|
|
|
|
|
Integer puid = psog.getUid();
|
|
|
if (!puid.equals(uid)){
|
|
|
logger.warn("in ChangePrice can not find one hacker , req {} sys-uid {}", req, puid);
|
|
|
throw new UfoServiceException(400, "你是猴子么");
|
|
|
}
|
|
|
|
|
|
//check whether exists waiting pay order of skup
|
|
|
SkupDto skupOfUnChange = nesChangePricePrepareProcessor.checkExistWaitingBuyerPay(psog);
|
|
|
//检查是否有买家下单
|
|
|
nesChangePricePrepareProcessor.checkGoodsStatus(psog);
|
|
|
SkupType skupType = SkupType.getSkupType(psog.getAttributes());
|
|
|
BigDecimal salePrice = priceComputePrepareProcessor.checkAndAcquireSalePrice(req.getPrice(), skupType);
|
|
|
BigDecimal preSalePrice = psog.getGoodsPrice();
|
|
|
//check old price vs new price
|
|
|
changePriceCommonPrepareProcessor.checkChangeNecessary(skup, preSalePrice, salePrice);
|
|
|
PrdPrice prdPrice;
|
|
|
SellerOrderGoods psog = scppDto.getPsog();
|
|
|
int storageId = psog.getStorageId();
|
|
|
PrdQueryReq pqr = PrdQueryReq.builder()
|
|
|
.uid(uid).prdPrice(salePrice).storageId(storageId).build();
|
|
|
prdPrice = priceComputePrepareProcessor.checkPriceRange(pqr, true);
|
|
|
|
|
|
String tips = priceComputePrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
|
|
|
|
|
|
// compute every fee from price
|
|
|
SellerOrderComputeResult pcc = OrderAssist.buildPersonalComputeConfig(prdPrice);
|
|
|
OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType);
|
|
|
SellerOrderComputeResult computeResult = computeHandler.compute(salePrice, pcc);
|
|
|
//check income
|
|
|
priceComputePrepareProcessor.checkIncome(storageId, computeResult.getIncome());
|
|
|
SellerOrder sellerOrder = scppDto.getSellerOrder();
|
|
|
BigDecimal salePrice = scppDto.getSalePrice();
|
|
|
//step 1: rpc get product detail by storage id
|
|
|
//ufo.product.storage.data
|
|
|
GoodsInfo goodsInfo = skupService.getProductDetail(uid, storageId, salePrice, skupType);
|
|
|
//step 2: generate skup ,action :set price status(unsaleable)
|
|
|
if (Objects.isNull(goodsInfo)){
|
|
|
logger.warn("in buildSellerOrderContext storageId not exist in prd service , uid {}, storageId {}", uid, storageId);
|
|
|
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
|
|
|
}
|
|
|
goodsInfo.setTargetSkupStatus(SkupStatus.CAN_NOT_SELL);
|
|
|
SellerOrderComputeResult computeResult = scppDto.getComputeResult();
|
|
|
String tips = scppDto.getPriceOverFlowTips();
|
|
|
|
|
|
//the address of send back 2 seller
|
|
|
AddressInfo hiddenBackAddress = sellerAddressService.getHiddenAddressInfo(uid, skup);
|
...
|
...
|
@@ -140,15 +87,7 @@ public class NESChangePricePublishProcessor |
|
|
context.setBackHiddenAddress(hiddenBackAddress);
|
|
|
//
|
|
|
context.setSkupType(skupType);
|
|
|
//step 1: rpc get product detail by storage id
|
|
|
//ufo.product.storage.data
|
|
|
GoodsInfo goodsInfo = skupService.getProductDetail(uid, storageId, salePrice, skupType);
|
|
|
//step 2: generate skup ,action :set price status(unsaleable)
|
|
|
if (Objects.isNull(goodsInfo)){
|
|
|
logger.warn("in buildSellerOrderContext storageId not exist in prd service , uid {}, storageId {}", uid, storageId);
|
|
|
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
|
|
|
}
|
|
|
goodsInfo.setTargetSkupStatus(SkupStatus.CAN_NOT_SELL);
|
|
|
|
|
|
context.setSoldProduct(goodsInfo);
|
|
|
|
|
|
logger.info("in build not entry Seller Order Context , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
|
...
|
...
|
|