Authored by chenchao

compute price & fee 4 nes

... ... @@ -2,10 +2,7 @@ package com.yohoufo.order.controller;
import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.req.NESChangePriceReq;
import com.yohobuy.ufo.model.order.req.SellerBatchChangeReq;
import com.yohobuy.ufo.model.order.req.SellerGoodsRequest;
import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
import com.yohobuy.ufo.model.order.resp.BatchChangePriceResp;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohobuy.ufo.model.order.resp.SellerGoodsPageResp;
... ... @@ -24,8 +21,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.math.BigDecimal;
/**
* Created by chao.chen on 2018/12/19.
*/
... ... @@ -122,7 +117,7 @@ public class SellerGoodsController {
@RequestParam(name = "skup") int skup,
@RequestParam(name="price", required = true)String price
) throws GatewayException {
SellerOrderComputeReq req = SellerOrderComputeReq.builder().uid(uid)
NESChangePriceReq req = NESChangePriceReq.builder().uid(uid)
.skup(skup)
.price(price).build();
logger.info("in ufo.notEntrySeller.computeChangePricece, req {}", req);
... ...
... ... @@ -34,6 +34,7 @@ import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.service.wrapper.SellerOrderTimeoutWrapper;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.OrderAssist;
import com.yohoufo.order.utils.SellerGoodsHelper;
import com.yohoufo.order.utils.TimeUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -310,7 +311,7 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
try{
PrdPrice prdPriceRange = productProxyService.getPrdPriceRange(storageId);
logger.info("in buildOverPriceTips, prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
boolean isOverflow = sellerOrderPrepareProcessor.isOverSuggestMaxPrice(prdPriceRange.getSuggestMaxPrice(), prdPrice);
boolean isOverflow = SellerGoodsHelper.isOverSuggestMaxPrice(prdPriceRange.getSuggestMaxPrice(), prdPrice);
return isOverflow ? OrderConstant.Tips.SUGGEST_MAX_PRICE_OVERFLOW : defaultResult;
}catch (Exception ex){
logger.warn("in buildOverPriceTips storageId {},prdPrice {}", storageId, prdPrice, ex);
... ...
... ... @@ -54,6 +54,7 @@ import com.yohoufo.order.service.seller.OrderComputeProvider;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.MsgHelper;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -70,7 +71,7 @@ import java.util.stream.Collectors;
* Created by chenchao on 2018/9/13.
*/
@Service
public class SellerOrderService implements IOrderListService, IOrderDetailService {
public class SellerOrderService implements IOrderListService, IOrderDetailService {
private final Logger log = LoggerUtils.getSellerOrderLogger();
... ... @@ -125,7 +126,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
@Autowired
private PriceComputePrepareProcessor priceComputePrepareProcessor;
@Autowired
private ChangePricePrepareProcessor changePricePrepareProcessor;
... ... @@ -153,6 +153,22 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
@Autowired
private SellerDownShelfTaskHandler sellerDownShelfTaskHandler;
@Autowired
private InBoxFacade inBoxFacade;
@Autowired
private SellerService sellerService;
@Autowired
private SellerAuthCheckService sellerAuthCheckService;
@Autowired
private SellerBatchCancelPrepareProcessor sellerBatchCancelPrepareProcessor;
@Autowired
private NESChangePricePrepareProcessor nesChangePricePrepareProcessor;
private static final int MAX_DEAL = 10;
public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException {
log.info("in computePublishPrd, req {}", req);
... ... @@ -162,10 +178,10 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
int num = pcn.getNum();
BigDecimal salePrice = pcn.getPrdPrice();
String tips = null;
PrdPrice prdPrice = sellerOrderPrepareProcessor.checkPriceRange(storageId, salePrice, true);
PrdPrice prdPrice = priceComputePrepareProcessor.checkPriceRange(storageId, salePrice, true);
SkupType skupType = SkupType.getSkupType(req.getSkupType());
try {
sellerOrderPrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
priceComputePrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
}catch (UfoServiceException ex){
tips = ex.getErrorMessage();
}
... ... @@ -178,11 +194,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
public SoldPrdComputeBo computeChangePrice(BatchChangePriceReq req) throws GatewayException {
log.info("in computeChangePrice, req {}", req);
ChangePricePrepareDTO pcn = changePricePrepareProcessor.checkAndAcquire(req);
/*
if (pcn.getTips() != null){
throw new UfoServiceException(SellerOrderPrepareProcessor.TIPS_ERROR_CODE, pcn.getTips() );
}
*/
SellerOrderComputeResult computeResult = pcn.getComputeResult();
SoldPrdComputeBo spc = SellerOrderConvertor.computeResult2SoldPrdComputeBo(computeResult);
spc.setTips(pcn.getTips());
... ... @@ -269,14 +280,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
.actorType(TabType.SELL).cancelType(CancelType.TIME_OUT).build();
eventHandlerContainer.fireAsyncCancelEvent(orderCancelEvent);
}
@Autowired
private InBoxFacade inBoxFacade;
@Autowired
private SellerService sellerService;
@Autowired
private SellerAuthCheckService sellerAuthCheckService;
public OrderSubmitResp batchPublishPrds(SellerOrderContext ctx, SellerOrderSubmitReq req) throws GatewayException {
// 一串校验
... ... @@ -287,7 +291,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
Boolean isSuper = sellerBo.getIsSuper();
SellerOrderComputeResult socr = ctx.getSellerOrderComputeResult();
BigDecimal singleEarestMoney = socr.getEarnestMoney().getEarnestMoney();
BigDecimal mEarestMoney = sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid, singleEarestMoney,
BigDecimal mEarestMoney = priceComputePrepareProcessor.checkNGetMergeEarnestMoney(uid, singleEarestMoney,
num, ctx.getSalePrice(), isSuper);
SellerWalletDetail.Type swdType = SellerWalletDetail.Type.PUBLISH;
MerchantOrderAttachInfo moai = MerchantOrderAttachInfo.builder().uid(uid)
... ... @@ -334,8 +338,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
return true;
}
@Autowired
private SellerBatchCancelPrepareProcessor sellerBatchCancelPrepareProcessor;
/**
* 总指导思想:先下架商品
* @param req
... ... @@ -523,7 +526,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
* 验证是否是入驻商家
*/
if(sellerOrderPrepareProcessor.checkIsEntry(uid)){
sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid,
priceComputePrepareProcessor.checkNGetMergeEarnestMoney(uid,
computeResult.getEarnestMoney().getEarnestMoney(), num, prdPrice, isSuper);
}
... ... @@ -745,7 +748,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
}
private static final int MAX_DEAL = 10;
private class BatchProcessTask implements Callable<SellerOrderSubmitHandler.ForkJoinResult>{
... ... @@ -859,7 +862,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
}
return null;
}
private final static String FLAG_PRE = "#*", FLAG_SUFFIX = "*#";
/**
* 您确定取消出售吗?取消后将根据《卖家须知》扣除对应保证金作为赔偿打入卖家账户
* “扣除对应保证金” 加粗标红
... ... @@ -888,7 +891,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
if (OrderCodeType.BUYER_TYPE.equals(codeType)){
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
String confirmDesc = getConfirmDesc4BuyerOrder(buyerOrder);
String confirmDesc = MsgHelper.getConfirmDesc4BuyerOrder(buyerOrder);
occr.setConfirmDesc(confirmDesc);
//
if (buyerOrder !=null && OrderStatus.HAS_PAYED.getCode() == buyerOrder.getStatus()){
... ... @@ -898,73 +901,20 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
return occr;
}
private String getConfirmDesc4BuyerOrder(BuyerOrder buyerOrder){
String confirmDesc = null;
if (buyerOrder == null){
return "订单不存在";
}
if (ActionStatusHold.sellerCanCancelBuyerOrder(buyerOrder.getStatus())) {
confirmDesc = "您确定取消出售吗?取消后将根据《卖家须知》" + FLAG_PRE + "扣除对应保证金" + FLAG_SUFFIX + "作为赔偿打入卖家账户";
}else {
confirmDesc = "无法取消,请刷新后查看订单最新状态";
}
return confirmDesc;
}
private SellerOrderGoods rebuildNESReq(SellerOrderComputeReq req){
int uid = req.getUid();
if (uid <=0){
log.warn("in rebuildNESReq uid illegal, req {}", req);
throw new UfoServiceException(400, "参数uid非法");
}
int skup = req.getSkup();
if (skup<=0){
log.warn("in rebuildNESReq find illegal skup code, req {}", req);
throw new UfoServiceException(400, "参数skup非法");
}
SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
if (Objects.isNull(psog)){
log.warn("in rebuildNESReq can not find skup in sys, req {}", req);
throw new UfoServiceException(400, "商品不存在");
}
Integer puid = psog.getUid();
if (!puid.equals(uid)){
log.warn("in rebuildNESReq can not find one hacker , req {} sys-uid {}", req, puid);
throw new UfoServiceException(400, "你是猴子么");
}
int storageId = psog.getId();
req.setNum(1);
req.setStorageId(storageId);
return psog;
}
/**
* compute Change Price4 NES(Not Entry Seller)
* @param req
* @return
*/
public SoldPrdComputeBo computeChangePrice4NES(SellerOrderComputeReq req){
public SoldPrdComputeBo computeChangePrice4NES(NESChangePriceReq req){
log.info("in computeChangePrice4NES, req {}", req);
rebuildNESReq(req);
PriceComputePrepareProcessor.PriceComputeNode pcn = priceComputePrepareProcessor.checkBasePrice(req);
int uid = pcn.getUid();
Integer storageId = pcn.getStorageId();
int num = pcn.getNum();
BigDecimal salePrice = pcn.getPrdPrice();
String tips = null;
PrdPrice prdPrice = sellerOrderPrepareProcessor.checkPriceRange(storageId, salePrice, true);
SkupType skupType = SkupType.getSkupType(req.getSkupType());
try {
sellerOrderPrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
}catch (UfoServiceException ex){
tips = ex.getErrorMessage();
}
boolean isSuper = sellerService.isSuperEntrySeller(uid);
SoldPrdComputeBo spc = buildSoldPrdComputeBo(uid, num, salePrice, isSuper, skupType);
spc.setTips(tips);
return spc;
ChangePricePrepareDTO cppDto = nesChangePricePrepareProcessor.checkAndAcquire(req);
SoldPrdComputeBo computeBo = SellerOrderConvertor.computeResult2SoldPrdComputeBo(cppDto.getComputeResult());
return computeBo;
}
/**
... ...
... ... @@ -380,7 +380,7 @@ public class SkupListService {
try {
logger.info("in buildOverPriceTipsMap, prdPrice {}, storageId {} StorageDataResp {}",
prdPrice, storageId, sdr);
boolean isOverflow = sellerOrderPrepareProcessor.isOverSuggestMaxPrice(slp, prdPrice);
boolean isOverflow = SellerGoodsHelper.isOverSuggestMaxPrice(slp, prdPrice);
value = isOverflow ? OrderConstant.Tips.SUGGEST_MAX_PRICE_OVERFLOW : defaultResult;
} catch (Exception ex) {
logger.warn("in buildOverPriceTipsMap storageId {},prdPrice {}", storageId, prdPrice, ex);
... ...
package com.yohoufo.order.service.impl.processor;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.order.service.seller.OrderComputeProvider;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigDecimal;
... ... @@ -9,6 +15,29 @@ import java.math.BigDecimal;
* Created by chao.chen on 2019/3/20.
*/
public abstract class AbsChangePricePrepareProcessor {
@Autowired
BuyerOrderGoodsMapper buyerOrderGoodsMapper;
@Autowired
BuyerOrderMapper buyerOrderMapper;
@Autowired
SellerOrderMapper sellerOrderMapper;
@Autowired
SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
SellerOrderPrepareProcessor sellerOrderPrepareProcessor;
@Autowired
PriceComputePrepareProcessor priceComputePrepareProcessor;
@Autowired
OrderComputeProvider orderComputeProvider;
protected abstract Logger getLogger();
public void checkChangeNecessary(Integer skup, BigDecimal oldPrice, BigDecimal newPrice){
... ... @@ -18,4 +47,8 @@ public abstract class AbsChangePricePrepareProcessor {
throw new UfoServiceException(401, "前后价格没有变化");
}
}
BigDecimal calDiffOfEM(BigDecimal sourceEM, BigDecimal targetEM){
return targetEM.subtract(sourceEM);
}
}
... ...
... ... @@ -33,32 +33,17 @@ import java.util.stream.Collectors;
/**
* Created by jiexiang.wu on 2018/12/19.
*/
public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseChangeReq> extends AbsChangePricePrepareProcessor{
public abstract class AbsEntryChangePricePrepareProcessor<T extends SellerBaseChangeReq> extends AbsChangePricePrepareProcessor{
protected final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
private BuyerOrderGoodsMapper buyerOrderGoodsMapper;
@Autowired
private BuyerOrderMapper buyerOrderMapper;
@Autowired
private SellerOrderMapper sellerOrderMapper;
@Autowired
private SellerOrderPrepareProcessor sellerOrderPrepareProcessor;
@Autowired
private OrderComputeProvider orderComputeProvider;
@Autowired
private PriceComputePrepareProcessor priceComputePrepareProcessor;
@Autowired
private SellerService sellerService;
public ChangePricePrepareDTO checkAndAcquire(T req) throws GatewayException {
public ChangePricePrepareDTO checkAndAcquire(T req) {
int uid = req.getUid();
if (uid <= 0){
logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
... ... @@ -88,10 +73,10 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh
String tips = null;
PrdPrice prdPrice;
prdPrice = sellerOrderPrepareProcessor.checkPriceRange(storageId, salePrice, req.isShowPriceError());
prdPrice = priceComputePrepareProcessor.checkPriceRange(storageId, salePrice, req.isShowPriceError());
SkupType skupType = SkupType.getSkupType(req.getSkupType());
try {
sellerOrderPrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
priceComputePrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
}catch (UfoServiceException ex){
tips = ex.getErrorMessage();
}
... ... @@ -104,9 +89,9 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh
BigDecimal diffEarnestMoney = calDiffOfEM(sourceEM,targetEM);
boolean isSuper = sellerService.isSuperEntrySeller(uid);
if (diffEarnestMoney.compareTo(BigDecimal.ZERO)>0){
sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid, diffEarnestMoney, num, salePrice, isSuper);
priceComputePrepareProcessor.checkNGetMergeEarnestMoney(uid, diffEarnestMoney, num, salePrice, isSuper);
}
sellerOrderPrepareProcessor.checkIncome(storageId, computeResult.getIncome());
priceComputePrepareProcessor.checkIncome(storageId, computeResult.getIncome());
return ChangePricePrepareDTO.builder()
.baseSellerOrderGoods(sampleSog)
... ... @@ -136,9 +121,7 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh
Map<Integer, SkupDto> skupOfSalingMap);
private BigDecimal calDiffOfEM(BigDecimal sourceEM, BigDecimal targetEM){
return targetEM.subtract(sourceEM);
}
/**
* 获取期望变价的skup
* @param req
... ...
... ... @@ -19,14 +19,12 @@ import java.util.*;
* Created by jiexiang.wu on 2018/12/19.
*/
@Service
public class AdjustPricePrepareProcessor extends AbstractChangePricePrepareProcessor<SellerBatchChangeReq> {
public class AdjustPricePrepareProcessor extends AbsEntryChangePricePrepareProcessor<SellerBatchChangeReq> {
@Override
protected Logger getLogger() {
return logger;
}
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Override
protected List<SellerOrderGoods> getRealSkupOrderGoodsList(SellerBatchChangeReq req) {
... ...
... ... @@ -27,13 +27,12 @@ import java.util.stream.Collectors;
* 根据批次号来调价
*/
@Service
public class ChangePricePrepareProcessor extends AbstractChangePricePrepareProcessor<BatchChangePriceReq> {
public class ChangePricePrepareProcessor extends AbsEntryChangePricePrepareProcessor<BatchChangePriceReq> {
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Override
public ChangePricePrepareDTO checkAndAcquire(BatchChangePriceReq req) throws GatewayException {
public ChangePricePrepareDTO checkAndAcquire(BatchChangePriceReq req) {
String skupList = req.getSkupList();
if (StringUtils.isBlank(skupList)) {
logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
... ...
package com.yohoufo.order.service.impl.processor;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.bo.PrdPrice;
import com.yohobuy.ufo.model.order.common.OrderStatus;
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.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.model.dto.ChangePricePrepareDTO;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.model.dto.SkupDto;
import com.yohoufo.order.service.seller.OrderComputeHandler;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* NES -> not entry seller
* Created by chao.chen on 2019/3/21.
*/
@Service
public class NESChangePricePrepareProcessor extends AbsChangePricePrepareProcessor {
protected final Logger logger = LoggerUtils.getSellerOrderLogger();
private void checkGoodsStatus(SellerOrderGoods psog){
if (SkupStatus.CAN_SELL.getCode() != psog.getStatus().intValue()){
logger.warn("in NESChangePricePrepareProcessor.checkGoodsStatus not can sale, SellerOrderGoods {}", psog);
throw new UfoServiceException(400, "商品不是可售状态");
}
}
public ChangePricePrepareDTO checkAndAcquire(NESChangePriceReq req){
int uid = req.getUid();
if (uid <= 0){
logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
throw new UfoServiceException(400, "参数[uid]错误");
}
if (uid <=0){
logger.warn("in ChangePrice 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, "商品不存在");
}
//检查是否有买家下单
checkGoodsStatus(psog);
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 = checkExistWaitingBuyerPay(psog);
BigDecimal salePrice = priceComputePrepareProcessor.checkAndAcquireSalePrice(req.getPrice());
BigDecimal preSalePrice = psog.getGoodsPrice();
//check old price vs new price
checkChangeNecessary(skup, preSalePrice, salePrice);
String tips = null;
PrdPrice prdPrice;
int storageId = psog.getStorageId();
prdPrice = priceComputePrepareProcessor.checkPriceRange(storageId, salePrice, true);
SkupType skupType = SkupType.getSkupType(psog.getAttributes());
try {
priceComputePrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
}catch (UfoServiceException ex){
tips = ex.getErrorMessage();
}
// compute every fee from price
OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType);
SellerOrderComputeResult computeResult = computeHandler.compute(salePrice);
//check income
priceComputePrepareProcessor.checkIncome(storageId, computeResult.getIncome());
//calculate different of earnest Money
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(psog.getId());
BigDecimal sourceEM = sellerOrder.getEarnestMoney();
BigDecimal targetEM = computeResult.getEarnestMoney().getEarnestMoney();
BigDecimal diffEarnestMoney = calDiffOfEM(sourceEM,targetEM);
return ChangePricePrepareDTO.builder()
.baseSellerOrderGoods(psog)
.prdPrice(prdPrice)
.salePrice(salePrice)
.diffEarnestMoney(diffEarnestMoney)
.computeResult(computeResult)
.preEarnestMoney(sourceEM)
.preSalePrice(preSalePrice)
.tips(tips)
.skupType(skupType)
.build();
}
@Override
protected Logger getLogger() {
return logger;
}
SkupDto checkExistWaitingBuyerPay(SellerOrderGoods psog){
List<Integer> skups = Lists.newArrayListWithCapacity(1);
skups.add(psog.getId());
List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectBySkups(skups);
List<BuyerOrder> buyerOrderList = null;
if (CollectionUtils.isNotEmpty(buyerOrderGoodsList)){
List<Long> orderCodeList = buyerOrderGoodsList.parallelStream()
.map(BuyerOrderGoods::getOrderCode).collect(Collectors.toList());
buyerOrderList = buyerOrderMapper.selectByOrderCodes(orderCodeList,
Arrays.asList(OrderStatus.WAITING_PAY.getCode()));
}
if (CollectionUtils.isNotEmpty(buyerOrderList)){
List<Long> waitingPayOrderCodes = buyerOrderList.parallelStream()
.map(BuyerOrder::getOrderCode).collect(Collectors.toList());
logger.warn("ChangePrice checkAndAcquire exist waiting pay buy order , SellerOrderGoods {} waitingPayOrderCodes {}",
psog, waitingPayOrderCodes);
throw new UfoServiceException(400, "商品正在等待买家支付");
}
return SkupDto.builder().skup(psog.getId()).sellerOrderGoods(psog).build();
}
}
... ...
package com.yohoufo.order.service.impl.processor;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.PrdPrice;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.SellerGoodsHelper;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Objects;
/**
* Created by chao.chen on 2018/11/28.
... ... @@ -18,6 +27,15 @@ import java.math.BigDecimal;
public class PriceComputePrepareProcessor {
final Logger log = LoggerUtils.getSellerOrderLogger();
public static final int TIPS_ERROR_CODE = 505;
@Autowired
private ProductProxyService productProxyService;
@Autowired
private SellerAuthCheckService sellerAuthCheckService;
@Data
public static class PriceComputeNode{
int uid;
... ... @@ -88,4 +106,64 @@ public class PriceComputePrepareProcessor {
return new PriceComputeNode(uid, storageId, num, prdPrice);
}
/**
* 判定商品的价格上下限,skc维度,由平台控制
* @param storageId
* @param prdPrice
* @param isShowError
* @return
*/
public PrdPrice checkPriceRange(int storageId, BigDecimal prdPrice, boolean isShowError) {
PrdPrice prdPriceRange = productProxyService.getPrdPriceRange(storageId);
log.info("in checkPriceRange, prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
BigDecimal minPrice = prdPriceRange.getMinPrice();
BigDecimal maxPrice = prdPriceRange.getMaxPrice();
if (prdPrice.subtract(minPrice).doubleValue() < 0D){
log.warn("in computePublishPrd,minPrice {}, storageId {}", minPrice, storageId);
if (isShowError)
throw new UfoServiceException(501, "您的出价过低");
}
if (prdPrice.subtract(maxPrice).doubleValue() > 0D){
log.warn("in computePublishPrd,maxPrice {}, storageId {}", maxPrice, storageId);
if (isShowError)
throw new UfoServiceException(501, "您的出价过高");
}
return prdPriceRange;
}
public void checkSuggestPrice(PrdPrice prdPrice, BigDecimal salePrice, SkupType skupType){
if (Objects.nonNull(skupType) && SkupType.ADVANCE.equals(skupType)){
return;
}
BigDecimal suggestMaxPrice = prdPrice.getSuggestMaxPrice();
if (SellerGoodsHelper.isOverSuggestMaxPrice(suggestMaxPrice, salePrice)){
log.warn("in computePublishPrd,prdPrice {}, prdPriceRange {}", salePrice, prdPrice);
throw new UfoServiceException(TIPS_ERROR_CODE, OrderConstant.Tips.SUGGEST_MAX_PRICE_OVERFLOW);
}
}
public void checkIncome(int storageId, BigDecimal income) {
if (income == null || income.compareTo(BigDecimal.ZERO) <= 0){
log.warn("in checkIncome,storageId {}, income {}", storageId, income);
throw new UfoServiceException(501, "别闹了,这个售价没有收入");
}
}
public BigDecimal checkNGetMergeEarnestMoney(int uid, BigDecimal singleEarestMoney,
int num, BigDecimal prdPrice, boolean isSuper){
BigDecimal mEarestMoney;
mEarestMoney = BigDecimalHelper.halfUp(new BigDecimal(num).multiply(singleEarestMoney));
if(!isSuper) {
boolean isEnough = sellerAuthCheckService.isEnough(uid, mEarestMoney);
if (!isEnough) {
log.warn("in checkNGetMergeEarnestMoney,wallet is not enough,uid {} num {} prdPrice {} singleEarestMoney {}",
uid, num, prdPrice, singleEarestMoney);
throw new ServiceException(ServiceError.WALLET_EARNESTMONEY_IS_NOT_ENOUGH);
}
}
return mEarestMoney;
}
}
... ...
... ... @@ -4,7 +4,10 @@ import com.yohobuy.ufo.model.order.bo.SellerBo;
import com.yohobuy.ufo.model.order.bo.SellerLevelFuncBo;
import com.yohobuy.ufo.model.order.common.EntrySellerType;
import com.yohobuy.ufo.model.order.common.SellerFuncEnum;
import com.yohobuy.ufo.model.order.common.SellerWalletType;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.SellerWalletMapper;
import com.yohoufo.dal.order.model.SellerWallet;
import com.yohoufo.order.service.impl.SellerService;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.SellerHelper;
... ... @@ -13,6 +16,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
/**
... ... @@ -26,6 +30,9 @@ public class SellerAuthCheckService {
@Autowired
private SellerService sellerService;
@Autowired
private SellerWalletMapper sellerWalletMapper;
public SellerBo checkAuth(Integer uid, SellerFuncEnum sellerFunc){
SellerBo sellerBo = sellerService.getSellerWithAuth(uid);
EntrySellerType est;
... ... @@ -51,6 +58,24 @@ public class SellerAuthCheckService {
}
/**
*
* @param uid
* @param mEarestMoney
* @return
*/
public boolean isEnough(int uid, BigDecimal mEarestMoney){
//取出入驻商家的钱包余额,判断保证金总额是否足够扣减
SellerWallet condition = new SellerWallet();
condition.setUid(uid);
condition.setType(SellerWalletType.EARNEAST_MONEY.getCode());
SellerWallet psw = sellerWalletMapper.selectByUidNType(condition);
logger.info("in compare price, uid {}, mEarestMoney {}, SellerWallet {}", uid, mEarestMoney, psw);
if (psw !=null && psw.getAmount().compareTo(mEarestMoney) >= 0){
return true;
}
return false;
}
}
... ...
... ... @@ -5,8 +5,6 @@ import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.GoodsSize;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.bo.PrdPrice;
import com.yohobuy.ufo.model.order.common.SellerWalletType;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
... ... @@ -14,9 +12,6 @@ import com.yohobuy.ufo.model.response.StorageDataResp;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.AddressUtil;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.dal.order.SellerWalletMapper;
import com.yohoufo.dal.order.model.SellerWallet;
import com.yohoufo.order.model.SellerOrderContext;
import com.yohoufo.order.model.dto.SellerOrderComputeResult;
import com.yohoufo.order.service.proxy.ProductProxyService;
... ... @@ -50,11 +45,9 @@ public class SellerOrderPrepareProcessor {
private OrderComputeProvider orderComputeProvider;
@Autowired
private SellerWalletMapper sellerWalletMapper;
@Autowired
private PriceComputePrepareProcessor priceComputePrepareProcessor;
public SellerOrderContext buildPublishPrdCtx(SellerOrderSubmitReq req) throws GatewayException {
SellerOrderContext ctx = buildSellerOrderContext(req);
int uid = ctx.getUid();
... ... @@ -86,16 +79,16 @@ public class SellerOrderPrepareProcessor {
}
public SellerOrderContext buildSellerOrderContext(SellerOrderSubmitReq req) throws GatewayException {
public SellerOrderContext buildSellerOrderContext(SellerOrderSubmitReq req) {
int uid = req.getUid();
if (uid <= 0){
log.warn("uid illegal , uid {}", uid);
throw new GatewayException(400, "Uid 错误");
throw new UfoServiceException(400, "Uid 错误");
}
Integer storageId = req.getStorageId();
if (storageId <=0 ){
log.warn("storageId illegal , uid {}", uid);
throw new GatewayException(400, "storageId 错误");
throw new UfoServiceException(400, "storageId 错误");
}
BigDecimal salePrice = priceComputePrepareProcessor.checkAndAcquireSalePrice(req.getPrice());
... ... @@ -135,10 +128,10 @@ public class SellerOrderPrepareProcessor {
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
}
context.setSoldProduct(goodsInfo);
PrdPrice prdPrice = checkPriceRange(storageId, salePrice, true);
PrdPrice prdPrice = priceComputePrepareProcessor.checkPriceRange(storageId, salePrice, true);
try {
checkSuggestPrice(prdPrice, salePrice, skupType);
priceComputePrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
}catch (UfoServiceException ex){
context.setPriceOverFlowTips( ex.getErrorMessage());
}
... ... @@ -146,7 +139,7 @@ public class SellerOrderPrepareProcessor {
// compute every fee from price
OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType);
SellerOrderComputeResult computeResult = computeHandler.compute(goodsInfo.getPrice());
checkIncome(storageId, computeResult.getIncome());
priceComputePrepareProcessor.checkIncome(storageId, computeResult.getIncome());
log.info("in buildSellerOrderContext , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
goodsInfo.getPrice(), computeResult);
context.setSellerOrderComputeResult(computeResult);
... ... @@ -186,70 +179,6 @@ public class SellerOrderPrepareProcessor {
}
}
public boolean isOverSuggestMaxPrice(BigDecimal suggestMaxPrice, BigDecimal prdPrice){
return Objects.nonNull(suggestMaxPrice) && prdPrice.compareTo(suggestMaxPrice) > 0;
}
public static final int TIPS_ERROR_CODE = 505;
/**
* 判定商品的价格上下限,skc维度,由平台控制
* @param storageId
* @param prdPrice
* @param isShowError
* @return
*/
public PrdPrice checkPriceRange(int storageId, BigDecimal prdPrice, boolean isShowError) {
PrdPrice prdPriceRange = productProxyService.getPrdPriceRange(storageId);
log.info("in checkPriceRange, prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
BigDecimal minPrice = prdPriceRange.getMinPrice();
BigDecimal maxPrice = prdPriceRange.getMaxPrice();
if (prdPrice.subtract(minPrice).doubleValue() < 0D){
log.warn("in computePublishPrd,minPrice {}, storageId {}", minPrice, storageId);
if (isShowError)
throw new UfoServiceException(501, "您的出价过低");
}
if (prdPrice.subtract(maxPrice).doubleValue() > 0D){
log.warn("in computePublishPrd,maxPrice {}, storageId {}", maxPrice, storageId);
if (isShowError)
throw new UfoServiceException(501, "您的出价过高");
}
return prdPriceRange;
}
public void checkSuggestPrice(PrdPrice prdPrice, BigDecimal salePrice, SkupType skupType){
if (Objects.nonNull(skupType) && SkupType.ADVANCE.equals(skupType)){
return;
}
BigDecimal suggestMaxPrice = prdPrice.getSuggestMaxPrice();
if (isOverSuggestMaxPrice(suggestMaxPrice, salePrice)){
log.warn("in computePublishPrd,prdPrice {}, prdPriceRange {}", salePrice, prdPrice);
throw new UfoServiceException(TIPS_ERROR_CODE, OrderConstant.Tips.SUGGEST_MAX_PRICE_OVERFLOW);
}
}
public void checkIncome(int storageId, BigDecimal income) throws GatewayException {
if (income == null || income.compareTo(BigDecimal.ZERO) <= 0){
log.warn("in checkIncome,storageId {}, income {}", storageId, income);
throw new GatewayException(501, "别闹了,这个售价没有收入");
}
}
public BigDecimal checkNGetMergeEarnestMoney(int uid, BigDecimal singleEarestMoney,
int num, BigDecimal prdPrice, boolean isSuper){
BigDecimal mEarestMoney;
mEarestMoney = BigDecimalHelper.halfUp(new BigDecimal(num).multiply(singleEarestMoney));
if(!isSuper) {
boolean isEnough = isEnough(uid, mEarestMoney);
if (!isEnough) {
log.warn("in checkNGetMergeEarnestMoney,wallet is not enough,uid {} num {} prdPrice {} singleEarestMoney {}",
uid, num, prdPrice, singleEarestMoney);
throw new ServiceException(ServiceError.WALLET_EARNESTMONEY_IS_NOT_ENOUGH);
}
}
return mEarestMoney;
}
public boolean checkIsEntry(int uid){
return userProxyService.isEntryShop(uid);
... ... @@ -311,22 +240,5 @@ public class SellerOrderPrepareProcessor {
return context;
}
/**
*
* @param uid
* @param mEarestMoney
* @return
*/
private boolean isEnough(int uid, BigDecimal mEarestMoney){
//取出入驻商家的钱包余额,判断保证金总额是否足够扣减
SellerWallet condition = new SellerWallet();
condition.setUid(uid);
condition.setType(SellerWalletType.EARNEAST_MONEY.getCode());
SellerWallet psw = sellerWalletMapper.selectByUidNType(condition);
log.info("in compare price, uid {}, mEarestMoney {}, SellerWallet {}", uid, mEarestMoney, psw);
if (psw !=null && psw.getAmount().compareTo(mEarestMoney) >= 0){
return true;
}
return false;
}
}
... ...
... ... @@ -49,10 +49,11 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle
result.setEarnestMoney(earnestMoney);
result.setPlatformFee(platformFeeDto);
result.setIncome(halfUp(income));
//TODO 根据配置文件
// 根据配置文件
result.setServiceFeeRate(serviceFeeRate);
result.setBankTransferfee(bankTransferFee);
result.setPenaltyFeeRate(buildStagedCollection());
logger.info("in AbsSellerOrderComputeHandler.compute SellerOrderComputeResult {}", result);
return result;
}
... ...
package com.yohoufo.order.utils;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.order.common.ActionStatusHold;
/**
* Created by chao.chen on 2019/3/21.
*/
public final class MsgHelper {
private final static String FLAG_PRE = "#*", FLAG_SUFFIX = "*#";
public static String getConfirmDesc4BuyerOrder(BuyerOrder buyerOrder){
String confirmDesc = null;
if (buyerOrder == null){
return "订单不存在";
}
if (ActionStatusHold.sellerCanCancelBuyerOrder(buyerOrder.getStatus())) {
confirmDesc = "您确定取消出售吗?取消后将根据《卖家须知》" + FLAG_PRE + "扣除对应保证金" + FLAG_SUFFIX + "作为赔偿打入卖家账户";
}else {
confirmDesc = "无法取消,请刷新后查看订单最新状态";
}
return confirmDesc;
}
}
... ...
... ... @@ -11,4 +11,6 @@ public final class SellerGoodsHelper {
public static boolean isOverSuggestMaxPrice(BigDecimal suggestMaxPrice, BigDecimal prdPrice){
return Objects.nonNull(suggestMaxPrice) && prdPrice.compareTo(suggestMaxPrice) > 0;
}
}
... ...