Authored by chenchao

compute price & fee 4 nes

@@ -2,10 +2,7 @@ package com.yohoufo.order.controller; @@ -2,10 +2,7 @@ package com.yohoufo.order.controller;
2 2
3 import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo; 3 import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
4 import com.yohobuy.ufo.model.order.req.NESChangePriceReq; 4 import com.yohobuy.ufo.model.order.req.NESChangePriceReq;
5 -import com.yohobuy.ufo.model.order.req.SellerBatchChangeReq;  
6 import com.yohobuy.ufo.model.order.req.SellerGoodsRequest; 5 import com.yohobuy.ufo.model.order.req.SellerGoodsRequest;
7 -import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;  
8 -import com.yohobuy.ufo.model.order.resp.BatchChangePriceResp;  
9 import com.yohobuy.ufo.model.order.resp.OrderListInfo; 6 import com.yohobuy.ufo.model.order.resp.OrderListInfo;
10 import com.yohobuy.ufo.model.order.resp.PageResp; 7 import com.yohobuy.ufo.model.order.resp.PageResp;
11 import com.yohobuy.ufo.model.order.resp.SellerGoodsPageResp; 8 import com.yohobuy.ufo.model.order.resp.SellerGoodsPageResp;
@@ -24,8 +21,6 @@ import org.springframework.web.bind.annotation.RequestMapping; @@ -24,8 +21,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
24 import org.springframework.web.bind.annotation.RequestParam; 21 import org.springframework.web.bind.annotation.RequestParam;
25 import org.springframework.web.bind.annotation.ResponseBody; 22 import org.springframework.web.bind.annotation.ResponseBody;
26 23
27 -import java.math.BigDecimal;  
28 -  
29 /** 24 /**
30 * Created by chao.chen on 2018/12/19. 25 * Created by chao.chen on 2018/12/19.
31 */ 26 */
@@ -122,7 +117,7 @@ public class SellerGoodsController { @@ -122,7 +117,7 @@ public class SellerGoodsController {
122 @RequestParam(name = "skup") int skup, 117 @RequestParam(name = "skup") int skup,
123 @RequestParam(name="price", required = true)String price 118 @RequestParam(name="price", required = true)String price
124 ) throws GatewayException { 119 ) throws GatewayException {
125 - SellerOrderComputeReq req = SellerOrderComputeReq.builder().uid(uid) 120 + NESChangePriceReq req = NESChangePriceReq.builder().uid(uid)
126 .skup(skup) 121 .skup(skup)
127 .price(price).build(); 122 .price(price).build();
128 logger.info("in ufo.notEntrySeller.computeChangePricece, req {}", req); 123 logger.info("in ufo.notEntrySeller.computeChangePricece, req {}", req);
@@ -34,6 +34,7 @@ import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; @@ -34,6 +34,7 @@ import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
34 import com.yohoufo.order.service.wrapper.SellerOrderTimeoutWrapper; 34 import com.yohoufo.order.service.wrapper.SellerOrderTimeoutWrapper;
35 import com.yohoufo.order.utils.LoggerUtils; 35 import com.yohoufo.order.utils.LoggerUtils;
36 import com.yohoufo.order.utils.OrderAssist; 36 import com.yohoufo.order.utils.OrderAssist;
  37 +import com.yohoufo.order.utils.SellerGoodsHelper;
37 import com.yohoufo.order.utils.TimeUtils; 38 import com.yohoufo.order.utils.TimeUtils;
38 import org.apache.commons.lang3.StringUtils; 39 import org.apache.commons.lang3.StringUtils;
39 import org.slf4j.Logger; 40 import org.slf4j.Logger;
@@ -310,7 +311,7 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I @@ -310,7 +311,7 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
310 try{ 311 try{
311 PrdPrice prdPriceRange = productProxyService.getPrdPriceRange(storageId); 312 PrdPrice prdPriceRange = productProxyService.getPrdPriceRange(storageId);
312 logger.info("in buildOverPriceTips, prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange); 313 logger.info("in buildOverPriceTips, prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
313 - boolean isOverflow = sellerOrderPrepareProcessor.isOverSuggestMaxPrice(prdPriceRange.getSuggestMaxPrice(), prdPrice); 314 + boolean isOverflow = SellerGoodsHelper.isOverSuggestMaxPrice(prdPriceRange.getSuggestMaxPrice(), prdPrice);
314 return isOverflow ? OrderConstant.Tips.SUGGEST_MAX_PRICE_OVERFLOW : defaultResult; 315 return isOverflow ? OrderConstant.Tips.SUGGEST_MAX_PRICE_OVERFLOW : defaultResult;
315 }catch (Exception ex){ 316 }catch (Exception ex){
316 logger.warn("in buildOverPriceTips storageId {},prdPrice {}", storageId, prdPrice, ex); 317 logger.warn("in buildOverPriceTips storageId {},prdPrice {}", storageId, prdPrice, ex);
@@ -54,6 +54,7 @@ import com.yohoufo.order.service.seller.OrderComputeProvider; @@ -54,6 +54,7 @@ import com.yohoufo.order.service.seller.OrderComputeProvider;
54 import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; 54 import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
55 import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; 55 import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
56 import com.yohoufo.order.utils.LoggerUtils; 56 import com.yohoufo.order.utils.LoggerUtils;
  57 +import com.yohoufo.order.utils.MsgHelper;
57 import org.apache.commons.collections.CollectionUtils; 58 import org.apache.commons.collections.CollectionUtils;
58 import org.slf4j.Logger; 59 import org.slf4j.Logger;
59 import org.springframework.beans.factory.annotation.Autowired; 60 import org.springframework.beans.factory.annotation.Autowired;
@@ -70,7 +71,7 @@ import java.util.stream.Collectors; @@ -70,7 +71,7 @@ import java.util.stream.Collectors;
70 * Created by chenchao on 2018/9/13. 71 * Created by chenchao on 2018/9/13.
71 */ 72 */
72 @Service 73 @Service
73 -public class SellerOrderService implements IOrderListService, IOrderDetailService { 74 +public class SellerOrderService implements IOrderListService, IOrderDetailService {
74 75
75 private final Logger log = LoggerUtils.getSellerOrderLogger(); 76 private final Logger log = LoggerUtils.getSellerOrderLogger();
76 77
@@ -125,7 +126,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -125,7 +126,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
125 @Autowired 126 @Autowired
126 private PriceComputePrepareProcessor priceComputePrepareProcessor; 127 private PriceComputePrepareProcessor priceComputePrepareProcessor;
127 128
128 -  
129 @Autowired 129 @Autowired
130 private ChangePricePrepareProcessor changePricePrepareProcessor; 130 private ChangePricePrepareProcessor changePricePrepareProcessor;
131 131
@@ -153,6 +153,22 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -153,6 +153,22 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
153 @Autowired 153 @Autowired
154 private SellerDownShelfTaskHandler sellerDownShelfTaskHandler; 154 private SellerDownShelfTaskHandler sellerDownShelfTaskHandler;
155 155
  156 + @Autowired
  157 + private InBoxFacade inBoxFacade;
  158 +
  159 + @Autowired
  160 + private SellerService sellerService;
  161 +
  162 + @Autowired
  163 + private SellerAuthCheckService sellerAuthCheckService;
  164 +
  165 + @Autowired
  166 + private SellerBatchCancelPrepareProcessor sellerBatchCancelPrepareProcessor;
  167 +
  168 + @Autowired
  169 + private NESChangePricePrepareProcessor nesChangePricePrepareProcessor;
  170 +
  171 + private static final int MAX_DEAL = 10;
156 172
157 public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException { 173 public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException {
158 log.info("in computePublishPrd, req {}", req); 174 log.info("in computePublishPrd, req {}", req);
@@ -162,10 +178,10 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -162,10 +178,10 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
162 int num = pcn.getNum(); 178 int num = pcn.getNum();
163 BigDecimal salePrice = pcn.getPrdPrice(); 179 BigDecimal salePrice = pcn.getPrdPrice();
164 String tips = null; 180 String tips = null;
165 - PrdPrice prdPrice = sellerOrderPrepareProcessor.checkPriceRange(storageId, salePrice, true); 181 + PrdPrice prdPrice = priceComputePrepareProcessor.checkPriceRange(storageId, salePrice, true);
166 SkupType skupType = SkupType.getSkupType(req.getSkupType()); 182 SkupType skupType = SkupType.getSkupType(req.getSkupType());
167 try { 183 try {
168 - sellerOrderPrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType); 184 + priceComputePrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
169 }catch (UfoServiceException ex){ 185 }catch (UfoServiceException ex){
170 tips = ex.getErrorMessage(); 186 tips = ex.getErrorMessage();
171 } 187 }
@@ -178,11 +194,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -178,11 +194,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
178 public SoldPrdComputeBo computeChangePrice(BatchChangePriceReq req) throws GatewayException { 194 public SoldPrdComputeBo computeChangePrice(BatchChangePriceReq req) throws GatewayException {
179 log.info("in computeChangePrice, req {}", req); 195 log.info("in computeChangePrice, req {}", req);
180 ChangePricePrepareDTO pcn = changePricePrepareProcessor.checkAndAcquire(req); 196 ChangePricePrepareDTO pcn = changePricePrepareProcessor.checkAndAcquire(req);
181 - /*  
182 - if (pcn.getTips() != null){  
183 - throw new UfoServiceException(SellerOrderPrepareProcessor.TIPS_ERROR_CODE, pcn.getTips() );  
184 - }  
185 - */  
186 SellerOrderComputeResult computeResult = pcn.getComputeResult(); 197 SellerOrderComputeResult computeResult = pcn.getComputeResult();
187 SoldPrdComputeBo spc = SellerOrderConvertor.computeResult2SoldPrdComputeBo(computeResult); 198 SoldPrdComputeBo spc = SellerOrderConvertor.computeResult2SoldPrdComputeBo(computeResult);
188 spc.setTips(pcn.getTips()); 199 spc.setTips(pcn.getTips());
@@ -269,14 +280,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -269,14 +280,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
269 .actorType(TabType.SELL).cancelType(CancelType.TIME_OUT).build(); 280 .actorType(TabType.SELL).cancelType(CancelType.TIME_OUT).build();
270 eventHandlerContainer.fireAsyncCancelEvent(orderCancelEvent); 281 eventHandlerContainer.fireAsyncCancelEvent(orderCancelEvent);
271 } 282 }
272 - @Autowired  
273 - private InBoxFacade inBoxFacade;  
274 283
275 - @Autowired  
276 - private SellerService sellerService;  
277 -  
278 - @Autowired  
279 - private SellerAuthCheckService sellerAuthCheckService;  
280 284
281 public OrderSubmitResp batchPublishPrds(SellerOrderContext ctx, SellerOrderSubmitReq req) throws GatewayException { 285 public OrderSubmitResp batchPublishPrds(SellerOrderContext ctx, SellerOrderSubmitReq req) throws GatewayException {
282 // 一串校验 286 // 一串校验
@@ -287,7 +291,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -287,7 +291,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
287 Boolean isSuper = sellerBo.getIsSuper(); 291 Boolean isSuper = sellerBo.getIsSuper();
288 SellerOrderComputeResult socr = ctx.getSellerOrderComputeResult(); 292 SellerOrderComputeResult socr = ctx.getSellerOrderComputeResult();
289 BigDecimal singleEarestMoney = socr.getEarnestMoney().getEarnestMoney(); 293 BigDecimal singleEarestMoney = socr.getEarnestMoney().getEarnestMoney();
290 - BigDecimal mEarestMoney = sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid, singleEarestMoney, 294 + BigDecimal mEarestMoney = priceComputePrepareProcessor.checkNGetMergeEarnestMoney(uid, singleEarestMoney,
291 num, ctx.getSalePrice(), isSuper); 295 num, ctx.getSalePrice(), isSuper);
292 SellerWalletDetail.Type swdType = SellerWalletDetail.Type.PUBLISH; 296 SellerWalletDetail.Type swdType = SellerWalletDetail.Type.PUBLISH;
293 MerchantOrderAttachInfo moai = MerchantOrderAttachInfo.builder().uid(uid) 297 MerchantOrderAttachInfo moai = MerchantOrderAttachInfo.builder().uid(uid)
@@ -334,8 +338,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -334,8 +338,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
334 return true; 338 return true;
335 } 339 }
336 340
337 - @Autowired  
338 - private SellerBatchCancelPrepareProcessor sellerBatchCancelPrepareProcessor; 341 +
339 /** 342 /**
340 * 总指导思想:先下架商品 343 * 总指导思想:先下架商品
341 * @param req 344 * @param req
@@ -523,7 +526,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -523,7 +526,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
523 * 验证是否是入驻商家 526 * 验证是否是入驻商家
524 */ 527 */
525 if(sellerOrderPrepareProcessor.checkIsEntry(uid)){ 528 if(sellerOrderPrepareProcessor.checkIsEntry(uid)){
526 - sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid, 529 + priceComputePrepareProcessor.checkNGetMergeEarnestMoney(uid,
527 computeResult.getEarnestMoney().getEarnestMoney(), num, prdPrice, isSuper); 530 computeResult.getEarnestMoney().getEarnestMoney(), num, prdPrice, isSuper);
528 } 531 }
529 532
@@ -745,7 +748,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -745,7 +748,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
745 } 748 }
746 749
747 750
748 - private static final int MAX_DEAL = 10; 751 +
749 752
750 753
751 private class BatchProcessTask implements Callable<SellerOrderSubmitHandler.ForkJoinResult>{ 754 private class BatchProcessTask implements Callable<SellerOrderSubmitHandler.ForkJoinResult>{
@@ -859,7 +862,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -859,7 +862,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
859 } 862 }
860 return null; 863 return null;
861 } 864 }
862 - private final static String FLAG_PRE = "#*", FLAG_SUFFIX = "*#"; 865 +
863 /** 866 /**
864 * 您确定取消出售吗?取消后将根据《卖家须知》扣除对应保证金作为赔偿打入卖家账户 867 * 您确定取消出售吗?取消后将根据《卖家须知》扣除对应保证金作为赔偿打入卖家账户
865 * “扣除对应保证金” 加粗标红 868 * “扣除对应保证金” 加粗标红
@@ -888,7 +891,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -888,7 +891,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
888 891
889 if (OrderCodeType.BUYER_TYPE.equals(codeType)){ 892 if (OrderCodeType.BUYER_TYPE.equals(codeType)){
890 BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode); 893 BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
891 - String confirmDesc = getConfirmDesc4BuyerOrder(buyerOrder); 894 + String confirmDesc = MsgHelper.getConfirmDesc4BuyerOrder(buyerOrder);
892 occr.setConfirmDesc(confirmDesc); 895 occr.setConfirmDesc(confirmDesc);
893 // 896 //
894 if (buyerOrder !=null && OrderStatus.HAS_PAYED.getCode() == buyerOrder.getStatus()){ 897 if (buyerOrder !=null && OrderStatus.HAS_PAYED.getCode() == buyerOrder.getStatus()){
@@ -898,73 +901,20 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -898,73 +901,20 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
898 return occr; 901 return occr;
899 } 902 }
900 903
901 - private String getConfirmDesc4BuyerOrder(BuyerOrder buyerOrder){  
902 - String confirmDesc = null;  
903 904
904 - if (buyerOrder == null){  
905 - return "订单不存在";  
906 - }  
907 - if (ActionStatusHold.sellerCanCancelBuyerOrder(buyerOrder.getStatus())) {  
908 - confirmDesc = "您确定取消出售吗?取消后将根据《卖家须知》" + FLAG_PRE + "扣除对应保证金" + FLAG_SUFFIX + "作为赔偿打入卖家账户";  
909 - }else {  
910 - confirmDesc = "无法取消,请刷新后查看订单最新状态";  
911 - }  
912 - return confirmDesc;  
913 - }  
914 905
915 906
916 - private SellerOrderGoods rebuildNESReq(SellerOrderComputeReq req){  
917 - int uid = req.getUid();  
918 - if (uid <=0){  
919 - log.warn("in rebuildNESReq uid illegal, req {}", req);  
920 - throw new UfoServiceException(400, "参数uid非法");  
921 - }  
922 - int skup = req.getSkup();  
923 - if (skup<=0){  
924 - log.warn("in rebuildNESReq find illegal skup code, req {}", req);  
925 - throw new UfoServiceException(400, "参数skup非法");  
926 - }  
927 - SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);  
928 - if (Objects.isNull(psog)){  
929 - log.warn("in rebuildNESReq can not find skup in sys, req {}", req);  
930 - throw new UfoServiceException(400, "商品不存在");  
931 - }  
932 - Integer puid = psog.getUid();  
933 - if (!puid.equals(uid)){  
934 - log.warn("in rebuildNESReq can not find one hacker , req {} sys-uid {}", req, puid);  
935 - throw new UfoServiceException(400, "你是猴子么");  
936 - }  
937 -  
938 - int storageId = psog.getId();  
939 - req.setNum(1);  
940 - req.setStorageId(storageId);  
941 - return psog;  
942 - } 907 +
943 /** 908 /**
944 * compute Change Price4 NES(Not Entry Seller) 909 * compute Change Price4 NES(Not Entry Seller)
945 * @param req 910 * @param req
946 * @return 911 * @return
947 */ 912 */
948 - public SoldPrdComputeBo computeChangePrice4NES(SellerOrderComputeReq req){ 913 + public SoldPrdComputeBo computeChangePrice4NES(NESChangePriceReq req){
949 log.info("in computeChangePrice4NES, req {}", req); 914 log.info("in computeChangePrice4NES, req {}", req);
950 - rebuildNESReq(req);  
951 - PriceComputePrepareProcessor.PriceComputeNode pcn = priceComputePrepareProcessor.checkBasePrice(req);  
952 - int uid = pcn.getUid();  
953 - Integer storageId = pcn.getStorageId();  
954 - int num = pcn.getNum();  
955 - BigDecimal salePrice = pcn.getPrdPrice();  
956 - String tips = null;  
957 - PrdPrice prdPrice = sellerOrderPrepareProcessor.checkPriceRange(storageId, salePrice, true);  
958 - SkupType skupType = SkupType.getSkupType(req.getSkupType());  
959 - try {  
960 - sellerOrderPrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);  
961 - }catch (UfoServiceException ex){  
962 - tips = ex.getErrorMessage();  
963 - }  
964 - boolean isSuper = sellerService.isSuperEntrySeller(uid);  
965 - SoldPrdComputeBo spc = buildSoldPrdComputeBo(uid, num, salePrice, isSuper, skupType);  
966 - spc.setTips(tips);  
967 - return spc; 915 + ChangePricePrepareDTO cppDto = nesChangePricePrepareProcessor.checkAndAcquire(req);
  916 + SoldPrdComputeBo computeBo = SellerOrderConvertor.computeResult2SoldPrdComputeBo(cppDto.getComputeResult());
  917 + return computeBo;
968 } 918 }
969 919
970 /** 920 /**
@@ -380,7 +380,7 @@ public class SkupListService { @@ -380,7 +380,7 @@ public class SkupListService {
380 try { 380 try {
381 logger.info("in buildOverPriceTipsMap, prdPrice {}, storageId {} StorageDataResp {}", 381 logger.info("in buildOverPriceTipsMap, prdPrice {}, storageId {} StorageDataResp {}",
382 prdPrice, storageId, sdr); 382 prdPrice, storageId, sdr);
383 - boolean isOverflow = sellerOrderPrepareProcessor.isOverSuggestMaxPrice(slp, prdPrice); 383 + boolean isOverflow = SellerGoodsHelper.isOverSuggestMaxPrice(slp, prdPrice);
384 value = isOverflow ? OrderConstant.Tips.SUGGEST_MAX_PRICE_OVERFLOW : defaultResult; 384 value = isOverflow ? OrderConstant.Tips.SUGGEST_MAX_PRICE_OVERFLOW : defaultResult;
385 } catch (Exception ex) { 385 } catch (Exception ex) {
386 logger.warn("in buildOverPriceTipsMap storageId {},prdPrice {}", storageId, prdPrice, ex); 386 logger.warn("in buildOverPriceTipsMap storageId {},prdPrice {}", storageId, prdPrice, ex);
1 package com.yohoufo.order.service.impl.processor; 1 package com.yohoufo.order.service.impl.processor;
2 2
3 import com.yohoufo.common.exception.UfoServiceException; 3 import com.yohoufo.common.exception.UfoServiceException;
  4 +import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
  5 +import com.yohoufo.dal.order.BuyerOrderMapper;
  6 +import com.yohoufo.dal.order.SellerOrderGoodsMapper;
  7 +import com.yohoufo.dal.order.SellerOrderMapper;
  8 +import com.yohoufo.order.service.seller.OrderComputeProvider;
4 import org.slf4j.Logger; 9 import org.slf4j.Logger;
  10 +import org.springframework.beans.factory.annotation.Autowired;
5 11
6 import java.math.BigDecimal; 12 import java.math.BigDecimal;
7 13
@@ -9,6 +15,29 @@ import java.math.BigDecimal; @@ -9,6 +15,29 @@ import java.math.BigDecimal;
9 * Created by chao.chen on 2019/3/20. 15 * Created by chao.chen on 2019/3/20.
10 */ 16 */
11 public abstract class AbsChangePricePrepareProcessor { 17 public abstract class AbsChangePricePrepareProcessor {
  18 +
  19 + @Autowired
  20 + BuyerOrderGoodsMapper buyerOrderGoodsMapper;
  21 +
  22 + @Autowired
  23 + BuyerOrderMapper buyerOrderMapper;
  24 +
  25 + @Autowired
  26 + SellerOrderMapper sellerOrderMapper;
  27 +
  28 + @Autowired
  29 + SellerOrderGoodsMapper sellerOrderGoodsMapper;
  30 +
  31 + @Autowired
  32 + SellerOrderPrepareProcessor sellerOrderPrepareProcessor;
  33 +
  34 + @Autowired
  35 + PriceComputePrepareProcessor priceComputePrepareProcessor;
  36 +
  37 + @Autowired
  38 + OrderComputeProvider orderComputeProvider;
  39 +
  40 +
12 protected abstract Logger getLogger(); 41 protected abstract Logger getLogger();
13 42
14 public void checkChangeNecessary(Integer skup, BigDecimal oldPrice, BigDecimal newPrice){ 43 public void checkChangeNecessary(Integer skup, BigDecimal oldPrice, BigDecimal newPrice){
@@ -18,4 +47,8 @@ public abstract class AbsChangePricePrepareProcessor { @@ -18,4 +47,8 @@ public abstract class AbsChangePricePrepareProcessor {
18 throw new UfoServiceException(401, "前后价格没有变化"); 47 throw new UfoServiceException(401, "前后价格没有变化");
19 } 48 }
20 } 49 }
  50 +
  51 + BigDecimal calDiffOfEM(BigDecimal sourceEM, BigDecimal targetEM){
  52 + return targetEM.subtract(sourceEM);
  53 + }
21 } 54 }
@@ -33,32 +33,17 @@ import java.util.stream.Collectors; @@ -33,32 +33,17 @@ import java.util.stream.Collectors;
33 /** 33 /**
34 * Created by jiexiang.wu on 2018/12/19. 34 * Created by jiexiang.wu on 2018/12/19.
35 */ 35 */
36 -public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseChangeReq> extends AbsChangePricePrepareProcessor{ 36 +public abstract class AbsEntryChangePricePrepareProcessor<T extends SellerBaseChangeReq> extends AbsChangePricePrepareProcessor{
37 37
38 protected final Logger logger = LoggerUtils.getSellerOrderLogger(); 38 protected final Logger logger = LoggerUtils.getSellerOrderLogger();
39 39
40 - @Autowired  
41 - private BuyerOrderGoodsMapper buyerOrderGoodsMapper;  
42 -  
43 - @Autowired  
44 - private BuyerOrderMapper buyerOrderMapper;  
45 40
46 - @Autowired  
47 - private SellerOrderMapper sellerOrderMapper;  
48 41
49 - @Autowired  
50 - private SellerOrderPrepareProcessor sellerOrderPrepareProcessor;  
51 -  
52 - @Autowired  
53 - private OrderComputeProvider orderComputeProvider;  
54 -  
55 - @Autowired  
56 - private PriceComputePrepareProcessor priceComputePrepareProcessor;  
57 42
58 @Autowired 43 @Autowired
59 private SellerService sellerService; 44 private SellerService sellerService;
60 45
61 - public ChangePricePrepareDTO checkAndAcquire(T req) throws GatewayException { 46 + public ChangePricePrepareDTO checkAndAcquire(T req) {
62 int uid = req.getUid(); 47 int uid = req.getUid();
63 if (uid <= 0){ 48 if (uid <= 0){
64 logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req); 49 logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
@@ -88,10 +73,10 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh @@ -88,10 +73,10 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh
88 73
89 String tips = null; 74 String tips = null;
90 PrdPrice prdPrice; 75 PrdPrice prdPrice;
91 - prdPrice = sellerOrderPrepareProcessor.checkPriceRange(storageId, salePrice, req.isShowPriceError()); 76 + prdPrice = priceComputePrepareProcessor.checkPriceRange(storageId, salePrice, req.isShowPriceError());
92 SkupType skupType = SkupType.getSkupType(req.getSkupType()); 77 SkupType skupType = SkupType.getSkupType(req.getSkupType());
93 try { 78 try {
94 - sellerOrderPrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType); 79 + priceComputePrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
95 }catch (UfoServiceException ex){ 80 }catch (UfoServiceException ex){
96 tips = ex.getErrorMessage(); 81 tips = ex.getErrorMessage();
97 } 82 }
@@ -104,9 +89,9 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh @@ -104,9 +89,9 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh
104 BigDecimal diffEarnestMoney = calDiffOfEM(sourceEM,targetEM); 89 BigDecimal diffEarnestMoney = calDiffOfEM(sourceEM,targetEM);
105 boolean isSuper = sellerService.isSuperEntrySeller(uid); 90 boolean isSuper = sellerService.isSuperEntrySeller(uid);
106 if (diffEarnestMoney.compareTo(BigDecimal.ZERO)>0){ 91 if (diffEarnestMoney.compareTo(BigDecimal.ZERO)>0){
107 - sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid, diffEarnestMoney, num, salePrice, isSuper); 92 + priceComputePrepareProcessor.checkNGetMergeEarnestMoney(uid, diffEarnestMoney, num, salePrice, isSuper);
108 } 93 }
109 - sellerOrderPrepareProcessor.checkIncome(storageId, computeResult.getIncome()); 94 + priceComputePrepareProcessor.checkIncome(storageId, computeResult.getIncome());
110 95
111 return ChangePricePrepareDTO.builder() 96 return ChangePricePrepareDTO.builder()
112 .baseSellerOrderGoods(sampleSog) 97 .baseSellerOrderGoods(sampleSog)
@@ -136,9 +121,7 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh @@ -136,9 +121,7 @@ public abstract class AbstractChangePricePrepareProcessor<T extends SellerBaseCh
136 Map<Integer, SkupDto> skupOfSalingMap); 121 Map<Integer, SkupDto> skupOfSalingMap);
137 122
138 123
139 - private BigDecimal calDiffOfEM(BigDecimal sourceEM, BigDecimal targetEM){  
140 - return targetEM.subtract(sourceEM);  
141 - } 124 +
142 /** 125 /**
143 * 获取期望变价的skup 126 * 获取期望变价的skup
144 * @param req 127 * @param req
@@ -19,14 +19,12 @@ import java.util.*; @@ -19,14 +19,12 @@ import java.util.*;
19 * Created by jiexiang.wu on 2018/12/19. 19 * Created by jiexiang.wu on 2018/12/19.
20 */ 20 */
21 @Service 21 @Service
22 -public class AdjustPricePrepareProcessor extends AbstractChangePricePrepareProcessor<SellerBatchChangeReq> { 22 +public class AdjustPricePrepareProcessor extends AbsEntryChangePricePrepareProcessor<SellerBatchChangeReq> {
23 @Override 23 @Override
24 protected Logger getLogger() { 24 protected Logger getLogger() {
25 return logger; 25 return logger;
26 } 26 }
27 27
28 - @Autowired  
29 - private SellerOrderGoodsMapper sellerOrderGoodsMapper;  
30 28
31 @Override 29 @Override
32 protected List<SellerOrderGoods> getRealSkupOrderGoodsList(SellerBatchChangeReq req) { 30 protected List<SellerOrderGoods> getRealSkupOrderGoodsList(SellerBatchChangeReq req) {
@@ -27,13 +27,12 @@ import java.util.stream.Collectors; @@ -27,13 +27,12 @@ import java.util.stream.Collectors;
27 * 根据批次号来调价 27 * 根据批次号来调价
28 */ 28 */
29 @Service 29 @Service
30 -public class ChangePricePrepareProcessor extends AbstractChangePricePrepareProcessor<BatchChangePriceReq> { 30 +public class ChangePricePrepareProcessor extends AbsEntryChangePricePrepareProcessor<BatchChangePriceReq> {
  31 +
31 32
32 - @Autowired  
33 - private SellerOrderGoodsMapper sellerOrderGoodsMapper;  
34 33
35 @Override 34 @Override
36 - public ChangePricePrepareDTO checkAndAcquire(BatchChangePriceReq req) throws GatewayException { 35 + public ChangePricePrepareDTO checkAndAcquire(BatchChangePriceReq req) {
37 String skupList = req.getSkupList(); 36 String skupList = req.getSkupList();
38 if (StringUtils.isBlank(skupList)) { 37 if (StringUtils.isBlank(skupList)) {
39 logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req); 38 logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
  1 +package com.yohoufo.order.service.impl.processor;
  2 +
  3 +import com.google.common.collect.Lists;
  4 +import com.yohobuy.ufo.model.order.bo.PrdPrice;
  5 +import com.yohobuy.ufo.model.order.common.OrderStatus;
  6 +import com.yohobuy.ufo.model.order.common.SkupStatus;
  7 +import com.yohobuy.ufo.model.order.constants.SkupType;
  8 +import com.yohobuy.ufo.model.order.req.NESChangePriceReq;
  9 +import com.yohoufo.common.exception.UfoServiceException;
  10 +import com.yohoufo.dal.order.model.BuyerOrder;
  11 +import com.yohoufo.dal.order.model.BuyerOrderGoods;
  12 +import com.yohoufo.dal.order.model.SellerOrder;
  13 +import com.yohoufo.dal.order.model.SellerOrderGoods;
  14 +import com.yohoufo.order.model.dto.ChangePricePrepareDTO;
  15 +import com.yohoufo.order.model.dto.SellerOrderComputeResult;
  16 +import com.yohoufo.order.model.dto.SkupDto;
  17 +import com.yohoufo.order.service.seller.OrderComputeHandler;
  18 +import com.yohoufo.order.utils.LoggerUtils;
  19 +import org.apache.commons.collections.CollectionUtils;
  20 +import org.slf4j.Logger;
  21 +import org.springframework.stereotype.Service;
  22 +
  23 +import java.math.BigDecimal;
  24 +import java.util.Arrays;
  25 +import java.util.List;
  26 +import java.util.Objects;
  27 +import java.util.stream.Collectors;
  28 +
  29 +/**
  30 + * NES -> not entry seller
  31 + * Created by chao.chen on 2019/3/21.
  32 + */
  33 +@Service
  34 +public class NESChangePricePrepareProcessor extends AbsChangePricePrepareProcessor {
  35 + protected final Logger logger = LoggerUtils.getSellerOrderLogger();
  36 +
  37 +
  38 + private void checkGoodsStatus(SellerOrderGoods psog){
  39 + if (SkupStatus.CAN_SELL.getCode() != psog.getStatus().intValue()){
  40 + logger.warn("in NESChangePricePrepareProcessor.checkGoodsStatus not can sale, SellerOrderGoods {}", psog);
  41 + throw new UfoServiceException(400, "商品不是可售状态");
  42 + }
  43 + }
  44 +
  45 + public ChangePricePrepareDTO checkAndAcquire(NESChangePriceReq req){
  46 + int uid = req.getUid();
  47 + if (uid <= 0){
  48 + logger.warn("ChangePrice checkAndAcquire uid illegal , req {}", req);
  49 + throw new UfoServiceException(400, "参数[uid]错误");
  50 + }
  51 + if (uid <=0){
  52 + logger.warn("in ChangePrice uid illegal, req {}", req);
  53 + throw new UfoServiceException(400, "参数uid非法");
  54 + }
  55 + int skup = req.getSkup();
  56 + if (skup<=0){
  57 + logger.warn("in ChangePrice find illegal skup code, req {}", req);
  58 + throw new UfoServiceException(400, "参数skup非法");
  59 + }
  60 + SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
  61 + if (Objects.isNull(psog)){
  62 + logger.warn("in ChangePrice can not find skup in sys, req {}", req);
  63 + throw new UfoServiceException(400, "商品不存在");
  64 + }
  65 + //检查是否有买家下单
  66 + checkGoodsStatus(psog);
  67 +
  68 + Integer puid = psog.getUid();
  69 + if (!puid.equals(uid)){
  70 + logger.warn("in ChangePrice can not find one hacker , req {} sys-uid {}", req, puid);
  71 + throw new UfoServiceException(400, "你是猴子么");
  72 + }
  73 + //check whether exists waiting pay order of skup
  74 + SkupDto skupOfUnChange = checkExistWaitingBuyerPay(psog);
  75 +
  76 + BigDecimal salePrice = priceComputePrepareProcessor.checkAndAcquireSalePrice(req.getPrice());
  77 + BigDecimal preSalePrice = psog.getGoodsPrice();
  78 + //check old price vs new price
  79 + checkChangeNecessary(skup, preSalePrice, salePrice);
  80 +
  81 +
  82 + String tips = null;
  83 + PrdPrice prdPrice;
  84 + int storageId = psog.getStorageId();
  85 + prdPrice = priceComputePrepareProcessor.checkPriceRange(storageId, salePrice, true);
  86 + SkupType skupType = SkupType.getSkupType(psog.getAttributes());
  87 + try {
  88 + priceComputePrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
  89 + }catch (UfoServiceException ex){
  90 + tips = ex.getErrorMessage();
  91 + }
  92 + // compute every fee from price
  93 + OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType);
  94 + SellerOrderComputeResult computeResult = computeHandler.compute(salePrice);
  95 + //check income
  96 + priceComputePrepareProcessor.checkIncome(storageId, computeResult.getIncome());
  97 + //calculate different of earnest Money
  98 + SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(psog.getId());
  99 + BigDecimal sourceEM = sellerOrder.getEarnestMoney();
  100 + BigDecimal targetEM = computeResult.getEarnestMoney().getEarnestMoney();
  101 + BigDecimal diffEarnestMoney = calDiffOfEM(sourceEM,targetEM);
  102 +
  103 + return ChangePricePrepareDTO.builder()
  104 + .baseSellerOrderGoods(psog)
  105 + .prdPrice(prdPrice)
  106 + .salePrice(salePrice)
  107 + .diffEarnestMoney(diffEarnestMoney)
  108 + .computeResult(computeResult)
  109 + .preEarnestMoney(sourceEM)
  110 + .preSalePrice(preSalePrice)
  111 + .tips(tips)
  112 + .skupType(skupType)
  113 + .build();
  114 + }
  115 +
  116 + @Override
  117 + protected Logger getLogger() {
  118 + return logger;
  119 + }
  120 +
  121 + SkupDto checkExistWaitingBuyerPay(SellerOrderGoods psog){
  122 + List<Integer> skups = Lists.newArrayListWithCapacity(1);
  123 + skups.add(psog.getId());
  124 + List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectBySkups(skups);
  125 + List<BuyerOrder> buyerOrderList = null;
  126 + if (CollectionUtils.isNotEmpty(buyerOrderGoodsList)){
  127 + List<Long> orderCodeList = buyerOrderGoodsList.parallelStream()
  128 + .map(BuyerOrderGoods::getOrderCode).collect(Collectors.toList());
  129 + buyerOrderList = buyerOrderMapper.selectByOrderCodes(orderCodeList,
  130 + Arrays.asList(OrderStatus.WAITING_PAY.getCode()));
  131 + }
  132 + if (CollectionUtils.isNotEmpty(buyerOrderList)){
  133 + List<Long> waitingPayOrderCodes = buyerOrderList.parallelStream()
  134 + .map(BuyerOrder::getOrderCode).collect(Collectors.toList());
  135 + logger.warn("ChangePrice checkAndAcquire exist waiting pay buy order , SellerOrderGoods {} waitingPayOrderCodes {}",
  136 + psog, waitingPayOrderCodes);
  137 + throw new UfoServiceException(400, "商品正在等待买家支付");
  138 + }
  139 +
  140 + return SkupDto.builder().skup(psog.getId()).sellerOrderGoods(psog).build();
  141 + }
  142 +}
1 package com.yohoufo.order.service.impl.processor; 1 package com.yohoufo.order.service.impl.processor;
2 2
  3 +import com.yoho.error.ServiceError;
  4 +import com.yoho.error.exception.ServiceException;
  5 +import com.yohobuy.ufo.model.order.bo.PrdPrice;
  6 +import com.yohobuy.ufo.model.order.constants.OrderConstant;
  7 +import com.yohobuy.ufo.model.order.constants.SkupType;
3 import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq; 8 import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
4 import com.yohoufo.common.exception.UfoServiceException; 9 import com.yohoufo.common.exception.UfoServiceException;
5 import com.yohoufo.common.utils.BigDecimalHelper; 10 import com.yohoufo.common.utils.BigDecimalHelper;
  11 +import com.yohoufo.order.service.proxy.ProductProxyService;
6 import com.yohoufo.order.utils.LoggerUtils; 12 import com.yohoufo.order.utils.LoggerUtils;
  13 +import com.yohoufo.order.utils.SellerGoodsHelper;
7 import lombok.Data; 14 import lombok.Data;
8 import org.apache.commons.lang3.StringUtils; 15 import org.apache.commons.lang3.StringUtils;
9 import org.slf4j.Logger; 16 import org.slf4j.Logger;
  17 +import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service; 18 import org.springframework.stereotype.Service;
11 19
12 import java.math.BigDecimal; 20 import java.math.BigDecimal;
  21 +import java.util.Objects;
13 22
14 /** 23 /**
15 * Created by chao.chen on 2018/11/28. 24 * Created by chao.chen on 2018/11/28.
@@ -18,6 +27,15 @@ import java.math.BigDecimal; @@ -18,6 +27,15 @@ import java.math.BigDecimal;
18 public class PriceComputePrepareProcessor { 27 public class PriceComputePrepareProcessor {
19 28
20 final Logger log = LoggerUtils.getSellerOrderLogger(); 29 final Logger log = LoggerUtils.getSellerOrderLogger();
  30 +
  31 + public static final int TIPS_ERROR_CODE = 505;
  32 +
  33 + @Autowired
  34 + private ProductProxyService productProxyService;
  35 +
  36 + @Autowired
  37 + private SellerAuthCheckService sellerAuthCheckService;
  38 +
21 @Data 39 @Data
22 public static class PriceComputeNode{ 40 public static class PriceComputeNode{
23 int uid; 41 int uid;
@@ -88,4 +106,64 @@ public class PriceComputePrepareProcessor { @@ -88,4 +106,64 @@ public class PriceComputePrepareProcessor {
88 106
89 return new PriceComputeNode(uid, storageId, num, prdPrice); 107 return new PriceComputeNode(uid, storageId, num, prdPrice);
90 } 108 }
  109 +
  110 +
  111 + /**
  112 + * 判定商品的价格上下限,skc维度,由平台控制
  113 + * @param storageId
  114 + * @param prdPrice
  115 + * @param isShowError
  116 + * @return
  117 + */
  118 + public PrdPrice checkPriceRange(int storageId, BigDecimal prdPrice, boolean isShowError) {
  119 + PrdPrice prdPriceRange = productProxyService.getPrdPriceRange(storageId);
  120 + log.info("in checkPriceRange, prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);
  121 + BigDecimal minPrice = prdPriceRange.getMinPrice();
  122 + BigDecimal maxPrice = prdPriceRange.getMaxPrice();
  123 + if (prdPrice.subtract(minPrice).doubleValue() < 0D){
  124 + log.warn("in computePublishPrd,minPrice {}, storageId {}", minPrice, storageId);
  125 + if (isShowError)
  126 + throw new UfoServiceException(501, "您的出价过低");
  127 + }
  128 +
  129 + if (prdPrice.subtract(maxPrice).doubleValue() > 0D){
  130 + log.warn("in computePublishPrd,maxPrice {}, storageId {}", maxPrice, storageId);
  131 + if (isShowError)
  132 + throw new UfoServiceException(501, "您的出价过高");
  133 + }
  134 + return prdPriceRange;
  135 + }
  136 +
  137 + public void checkSuggestPrice(PrdPrice prdPrice, BigDecimal salePrice, SkupType skupType){
  138 + if (Objects.nonNull(skupType) && SkupType.ADVANCE.equals(skupType)){
  139 + return;
  140 + }
  141 + BigDecimal suggestMaxPrice = prdPrice.getSuggestMaxPrice();
  142 + if (SellerGoodsHelper.isOverSuggestMaxPrice(suggestMaxPrice, salePrice)){
  143 + log.warn("in computePublishPrd,prdPrice {}, prdPriceRange {}", salePrice, prdPrice);
  144 + throw new UfoServiceException(TIPS_ERROR_CODE, OrderConstant.Tips.SUGGEST_MAX_PRICE_OVERFLOW);
  145 + }
  146 + }
  147 +
  148 + public void checkIncome(int storageId, BigDecimal income) {
  149 + if (income == null || income.compareTo(BigDecimal.ZERO) <= 0){
  150 + log.warn("in checkIncome,storageId {}, income {}", storageId, income);
  151 + throw new UfoServiceException(501, "别闹了,这个售价没有收入");
  152 + }
  153 + }
  154 +
  155 + public BigDecimal checkNGetMergeEarnestMoney(int uid, BigDecimal singleEarestMoney,
  156 + int num, BigDecimal prdPrice, boolean isSuper){
  157 + BigDecimal mEarestMoney;
  158 + mEarestMoney = BigDecimalHelper.halfUp(new BigDecimal(num).multiply(singleEarestMoney));
  159 + if(!isSuper) {
  160 + boolean isEnough = sellerAuthCheckService.isEnough(uid, mEarestMoney);
  161 + if (!isEnough) {
  162 + log.warn("in checkNGetMergeEarnestMoney,wallet is not enough,uid {} num {} prdPrice {} singleEarestMoney {}",
  163 + uid, num, prdPrice, singleEarestMoney);
  164 + throw new ServiceException(ServiceError.WALLET_EARNESTMONEY_IS_NOT_ENOUGH);
  165 + }
  166 + }
  167 + return mEarestMoney;
  168 + }
91 } 169 }
@@ -4,7 +4,10 @@ import com.yohobuy.ufo.model.order.bo.SellerBo; @@ -4,7 +4,10 @@ import com.yohobuy.ufo.model.order.bo.SellerBo;
4 import com.yohobuy.ufo.model.order.bo.SellerLevelFuncBo; 4 import com.yohobuy.ufo.model.order.bo.SellerLevelFuncBo;
5 import com.yohobuy.ufo.model.order.common.EntrySellerType; 5 import com.yohobuy.ufo.model.order.common.EntrySellerType;
6 import com.yohobuy.ufo.model.order.common.SellerFuncEnum; 6 import com.yohobuy.ufo.model.order.common.SellerFuncEnum;
  7 +import com.yohobuy.ufo.model.order.common.SellerWalletType;
7 import com.yohoufo.common.exception.UfoServiceException; 8 import com.yohoufo.common.exception.UfoServiceException;
  9 +import com.yohoufo.dal.order.SellerWalletMapper;
  10 +import com.yohoufo.dal.order.model.SellerWallet;
8 import com.yohoufo.order.service.impl.SellerService; 11 import com.yohoufo.order.service.impl.SellerService;
9 import com.yohoufo.order.utils.LoggerUtils; 12 import com.yohoufo.order.utils.LoggerUtils;
10 import com.yohoufo.order.utils.SellerHelper; 13 import com.yohoufo.order.utils.SellerHelper;
@@ -13,6 +16,7 @@ import org.slf4j.Logger; @@ -13,6 +16,7 @@ import org.slf4j.Logger;
13 import org.springframework.beans.factory.annotation.Autowired; 16 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
15 18
  19 +import java.math.BigDecimal;
16 import java.util.List; 20 import java.util.List;
17 21
18 /** 22 /**
@@ -26,6 +30,9 @@ public class SellerAuthCheckService { @@ -26,6 +30,9 @@ public class SellerAuthCheckService {
26 @Autowired 30 @Autowired
27 private SellerService sellerService; 31 private SellerService sellerService;
28 32
  33 + @Autowired
  34 + private SellerWalletMapper sellerWalletMapper;
  35 +
29 public SellerBo checkAuth(Integer uid, SellerFuncEnum sellerFunc){ 36 public SellerBo checkAuth(Integer uid, SellerFuncEnum sellerFunc){
30 SellerBo sellerBo = sellerService.getSellerWithAuth(uid); 37 SellerBo sellerBo = sellerService.getSellerWithAuth(uid);
31 EntrySellerType est; 38 EntrySellerType est;
@@ -51,6 +58,24 @@ public class SellerAuthCheckService { @@ -51,6 +58,24 @@ public class SellerAuthCheckService {
51 } 58 }
52 59
53 60
  61 + /**
  62 + *
  63 + * @param uid
  64 + * @param mEarestMoney
  65 + * @return
  66 + */
  67 + public boolean isEnough(int uid, BigDecimal mEarestMoney){
  68 + //取出入驻商家的钱包余额,判断保证金总额是否足够扣减
  69 + SellerWallet condition = new SellerWallet();
  70 + condition.setUid(uid);
  71 + condition.setType(SellerWalletType.EARNEAST_MONEY.getCode());
  72 + SellerWallet psw = sellerWalletMapper.selectByUidNType(condition);
  73 + logger.info("in compare price, uid {}, mEarestMoney {}, SellerWallet {}", uid, mEarestMoney, psw);
  74 + if (psw !=null && psw.getAmount().compareTo(mEarestMoney) >= 0){
  75 + return true;
  76 + }
  77 + return false;
  78 + }
54 79
55 80
56 } 81 }
@@ -5,8 +5,6 @@ import com.yoho.error.exception.ServiceException; @@ -5,8 +5,6 @@ import com.yoho.error.exception.ServiceException;
5 import com.yohobuy.ufo.model.GoodsSize; 5 import com.yohobuy.ufo.model.GoodsSize;
6 import com.yohobuy.ufo.model.order.bo.GoodsInfo; 6 import com.yohobuy.ufo.model.order.bo.GoodsInfo;
7 import com.yohobuy.ufo.model.order.bo.PrdPrice; 7 import com.yohobuy.ufo.model.order.bo.PrdPrice;
8 -import com.yohobuy.ufo.model.order.common.SellerWalletType;  
9 -import com.yohobuy.ufo.model.order.constants.OrderConstant;  
10 import com.yohobuy.ufo.model.order.constants.SkupType; 8 import com.yohobuy.ufo.model.order.constants.SkupType;
11 import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq; 9 import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq;
12 import com.yohobuy.ufo.model.order.vo.AddressInfo; 10 import com.yohobuy.ufo.model.order.vo.AddressInfo;
@@ -14,9 +12,6 @@ import com.yohobuy.ufo.model.response.StorageDataResp; @@ -14,9 +12,6 @@ import com.yohobuy.ufo.model.response.StorageDataResp;
14 import com.yohoufo.common.exception.GatewayException; 12 import com.yohoufo.common.exception.GatewayException;
15 import com.yohoufo.common.exception.UfoServiceException; 13 import com.yohoufo.common.exception.UfoServiceException;
16 import com.yohoufo.common.utils.AddressUtil; 14 import com.yohoufo.common.utils.AddressUtil;
17 -import com.yohoufo.common.utils.BigDecimalHelper;  
18 -import com.yohoufo.dal.order.SellerWalletMapper;  
19 -import com.yohoufo.dal.order.model.SellerWallet;  
20 import com.yohoufo.order.model.SellerOrderContext; 15 import com.yohoufo.order.model.SellerOrderContext;
21 import com.yohoufo.order.model.dto.SellerOrderComputeResult; 16 import com.yohoufo.order.model.dto.SellerOrderComputeResult;
22 import com.yohoufo.order.service.proxy.ProductProxyService; 17 import com.yohoufo.order.service.proxy.ProductProxyService;
@@ -50,11 +45,9 @@ public class SellerOrderPrepareProcessor { @@ -50,11 +45,9 @@ public class SellerOrderPrepareProcessor {
50 private OrderComputeProvider orderComputeProvider; 45 private OrderComputeProvider orderComputeProvider;
51 46
52 @Autowired 47 @Autowired
53 - private SellerWalletMapper sellerWalletMapper;  
54 -  
55 - @Autowired  
56 private PriceComputePrepareProcessor priceComputePrepareProcessor; 48 private PriceComputePrepareProcessor priceComputePrepareProcessor;
57 49
  50 +
58 public SellerOrderContext buildPublishPrdCtx(SellerOrderSubmitReq req) throws GatewayException { 51 public SellerOrderContext buildPublishPrdCtx(SellerOrderSubmitReq req) throws GatewayException {
59 SellerOrderContext ctx = buildSellerOrderContext(req); 52 SellerOrderContext ctx = buildSellerOrderContext(req);
60 int uid = ctx.getUid(); 53 int uid = ctx.getUid();
@@ -86,16 +79,16 @@ public class SellerOrderPrepareProcessor { @@ -86,16 +79,16 @@ public class SellerOrderPrepareProcessor {
86 } 79 }
87 80
88 81
89 - public SellerOrderContext buildSellerOrderContext(SellerOrderSubmitReq req) throws GatewayException { 82 + public SellerOrderContext buildSellerOrderContext(SellerOrderSubmitReq req) {
90 int uid = req.getUid(); 83 int uid = req.getUid();
91 if (uid <= 0){ 84 if (uid <= 0){
92 log.warn("uid illegal , uid {}", uid); 85 log.warn("uid illegal , uid {}", uid);
93 - throw new GatewayException(400, "Uid 错误"); 86 + throw new UfoServiceException(400, "Uid 错误");
94 } 87 }
95 Integer storageId = req.getStorageId(); 88 Integer storageId = req.getStorageId();
96 if (storageId <=0 ){ 89 if (storageId <=0 ){
97 log.warn("storageId illegal , uid {}", uid); 90 log.warn("storageId illegal , uid {}", uid);
98 - throw new GatewayException(400, "storageId 错误"); 91 + throw new UfoServiceException(400, "storageId 错误");
99 } 92 }
100 93
101 BigDecimal salePrice = priceComputePrepareProcessor.checkAndAcquireSalePrice(req.getPrice()); 94 BigDecimal salePrice = priceComputePrepareProcessor.checkAndAcquireSalePrice(req.getPrice());
@@ -135,10 +128,10 @@ public class SellerOrderPrepareProcessor { @@ -135,10 +128,10 @@ public class SellerOrderPrepareProcessor {
135 throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY); 128 throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
136 } 129 }
137 context.setSoldProduct(goodsInfo); 130 context.setSoldProduct(goodsInfo);
138 - PrdPrice prdPrice = checkPriceRange(storageId, salePrice, true); 131 + PrdPrice prdPrice = priceComputePrepareProcessor.checkPriceRange(storageId, salePrice, true);
139 132
140 try { 133 try {
141 - checkSuggestPrice(prdPrice, salePrice, skupType); 134 + priceComputePrepareProcessor.checkSuggestPrice(prdPrice, salePrice, skupType);
142 }catch (UfoServiceException ex){ 135 }catch (UfoServiceException ex){
143 context.setPriceOverFlowTips( ex.getErrorMessage()); 136 context.setPriceOverFlowTips( ex.getErrorMessage());
144 } 137 }
@@ -146,7 +139,7 @@ public class SellerOrderPrepareProcessor { @@ -146,7 +139,7 @@ public class SellerOrderPrepareProcessor {
146 // compute every fee from price 139 // compute every fee from price
147 OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType); 140 OrderComputeHandler computeHandler = orderComputeProvider.findBySkupType(skupType);
148 SellerOrderComputeResult computeResult = computeHandler.compute(goodsInfo.getPrice()); 141 SellerOrderComputeResult computeResult = computeHandler.compute(goodsInfo.getPrice());
149 - checkIncome(storageId, computeResult.getIncome()); 142 + priceComputePrepareProcessor.checkIncome(storageId, computeResult.getIncome());
150 log.info("in buildSellerOrderContext , uid {}, storageId {}, price {}, computeResult {}", uid, storageId, 143 log.info("in buildSellerOrderContext , uid {}, storageId {}, price {}, computeResult {}", uid, storageId,
151 goodsInfo.getPrice(), computeResult); 144 goodsInfo.getPrice(), computeResult);
152 context.setSellerOrderComputeResult(computeResult); 145 context.setSellerOrderComputeResult(computeResult);
@@ -186,70 +179,6 @@ public class SellerOrderPrepareProcessor { @@ -186,70 +179,6 @@ public class SellerOrderPrepareProcessor {
186 } 179 }
187 } 180 }
188 181
189 - public boolean isOverSuggestMaxPrice(BigDecimal suggestMaxPrice, BigDecimal prdPrice){  
190 - return Objects.nonNull(suggestMaxPrice) && prdPrice.compareTo(suggestMaxPrice) > 0;  
191 - }  
192 -  
193 - public static final int TIPS_ERROR_CODE = 505;  
194 -  
195 - /**  
196 - * 判定商品的价格上下限,skc维度,由平台控制  
197 - * @param storageId  
198 - * @param prdPrice  
199 - * @param isShowError  
200 - * @return  
201 - */  
202 - public PrdPrice checkPriceRange(int storageId, BigDecimal prdPrice, boolean isShowError) {  
203 - PrdPrice prdPriceRange = productProxyService.getPrdPriceRange(storageId);  
204 - log.info("in checkPriceRange, prdPrice {}, storageId {} prdPriceRange {}", prdPrice, storageId, prdPriceRange);  
205 - BigDecimal minPrice = prdPriceRange.getMinPrice();  
206 - BigDecimal maxPrice = prdPriceRange.getMaxPrice();  
207 - if (prdPrice.subtract(minPrice).doubleValue() < 0D){  
208 - log.warn("in computePublishPrd,minPrice {}, storageId {}", minPrice, storageId);  
209 - if (isShowError)  
210 - throw new UfoServiceException(501, "您的出价过低");  
211 - }  
212 -  
213 - if (prdPrice.subtract(maxPrice).doubleValue() > 0D){  
214 - log.warn("in computePublishPrd,maxPrice {}, storageId {}", maxPrice, storageId);  
215 - if (isShowError)  
216 - throw new UfoServiceException(501, "您的出价过高");  
217 - }  
218 - return prdPriceRange;  
219 - }  
220 -  
221 - public void checkSuggestPrice(PrdPrice prdPrice, BigDecimal salePrice, SkupType skupType){  
222 - if (Objects.nonNull(skupType) && SkupType.ADVANCE.equals(skupType)){  
223 - return;  
224 - }  
225 - BigDecimal suggestMaxPrice = prdPrice.getSuggestMaxPrice();  
226 - if (isOverSuggestMaxPrice(suggestMaxPrice, salePrice)){  
227 - log.warn("in computePublishPrd,prdPrice {}, prdPriceRange {}", salePrice, prdPrice);  
228 - throw new UfoServiceException(TIPS_ERROR_CODE, OrderConstant.Tips.SUGGEST_MAX_PRICE_OVERFLOW);  
229 - }  
230 - }  
231 -  
232 - public void checkIncome(int storageId, BigDecimal income) throws GatewayException {  
233 - if (income == null || income.compareTo(BigDecimal.ZERO) <= 0){  
234 - log.warn("in checkIncome,storageId {}, income {}", storageId, income);  
235 - throw new GatewayException(501, "别闹了,这个售价没有收入");  
236 - }  
237 - }  
238 -  
239 - public BigDecimal checkNGetMergeEarnestMoney(int uid, BigDecimal singleEarestMoney,  
240 - int num, BigDecimal prdPrice, boolean isSuper){  
241 - BigDecimal mEarestMoney;  
242 - mEarestMoney = BigDecimalHelper.halfUp(new BigDecimal(num).multiply(singleEarestMoney));  
243 - if(!isSuper) {  
244 - boolean isEnough = isEnough(uid, mEarestMoney);  
245 - if (!isEnough) {  
246 - log.warn("in checkNGetMergeEarnestMoney,wallet is not enough,uid {} num {} prdPrice {} singleEarestMoney {}",  
247 - uid, num, prdPrice, singleEarestMoney);  
248 - throw new ServiceException(ServiceError.WALLET_EARNESTMONEY_IS_NOT_ENOUGH);  
249 - }  
250 - }  
251 - return mEarestMoney;  
252 - }  
253 182
254 public boolean checkIsEntry(int uid){ 183 public boolean checkIsEntry(int uid){
255 return userProxyService.isEntryShop(uid); 184 return userProxyService.isEntryShop(uid);
@@ -311,22 +240,5 @@ public class SellerOrderPrepareProcessor { @@ -311,22 +240,5 @@ public class SellerOrderPrepareProcessor {
311 return context; 240 return context;
312 } 241 }
313 242
314 - /**  
315 - *  
316 - * @param uid  
317 - * @param mEarestMoney  
318 - * @return  
319 - */  
320 - private boolean isEnough(int uid, BigDecimal mEarestMoney){  
321 - //取出入驻商家的钱包余额,判断保证金总额是否足够扣减  
322 - SellerWallet condition = new SellerWallet();  
323 - condition.setUid(uid);  
324 - condition.setType(SellerWalletType.EARNEAST_MONEY.getCode());  
325 - SellerWallet psw = sellerWalletMapper.selectByUidNType(condition);  
326 - log.info("in compare price, uid {}, mEarestMoney {}, SellerWallet {}", uid, mEarestMoney, psw);  
327 - if (psw !=null && psw.getAmount().compareTo(mEarestMoney) >= 0){  
328 - return true;  
329 - }  
330 - return false;  
331 - } 243 +
332 } 244 }
@@ -49,10 +49,11 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle @@ -49,10 +49,11 @@ public abstract class AbsSellerOrderComputeHandler implements OrderComputeHandle
49 result.setEarnestMoney(earnestMoney); 49 result.setEarnestMoney(earnestMoney);
50 result.setPlatformFee(platformFeeDto); 50 result.setPlatformFee(platformFeeDto);
51 result.setIncome(halfUp(income)); 51 result.setIncome(halfUp(income));
52 - //TODO 根据配置文件 52 + // 根据配置文件
53 result.setServiceFeeRate(serviceFeeRate); 53 result.setServiceFeeRate(serviceFeeRate);
54 result.setBankTransferfee(bankTransferFee); 54 result.setBankTransferfee(bankTransferFee);
55 result.setPenaltyFeeRate(buildStagedCollection()); 55 result.setPenaltyFeeRate(buildStagedCollection());
  56 + logger.info("in AbsSellerOrderComputeHandler.compute SellerOrderComputeResult {}", result);
56 return result; 57 return result;
57 } 58 }
58 59
  1 +package com.yohoufo.order.utils;
  2 +
  3 +import com.yohoufo.dal.order.model.BuyerOrder;
  4 +import com.yohoufo.order.common.ActionStatusHold;
  5 +
  6 +/**
  7 + * Created by chao.chen on 2019/3/21.
  8 + */
  9 +public final class MsgHelper {
  10 +
  11 + private final static String FLAG_PRE = "#*", FLAG_SUFFIX = "*#";
  12 + public static String getConfirmDesc4BuyerOrder(BuyerOrder buyerOrder){
  13 + String confirmDesc = null;
  14 +
  15 + if (buyerOrder == null){
  16 + return "订单不存在";
  17 + }
  18 + if (ActionStatusHold.sellerCanCancelBuyerOrder(buyerOrder.getStatus())) {
  19 + confirmDesc = "您确定取消出售吗?取消后将根据《卖家须知》" + FLAG_PRE + "扣除对应保证金" + FLAG_SUFFIX + "作为赔偿打入卖家账户";
  20 + }else {
  21 + confirmDesc = "无法取消,请刷新后查看订单最新状态";
  22 + }
  23 + return confirmDesc;
  24 + }
  25 +}
@@ -11,4 +11,6 @@ public final class SellerGoodsHelper { @@ -11,4 +11,6 @@ public final class SellerGoodsHelper {
11 public static boolean isOverSuggestMaxPrice(BigDecimal suggestMaxPrice, BigDecimal prdPrice){ 11 public static boolean isOverSuggestMaxPrice(BigDecimal suggestMaxPrice, BigDecimal prdPrice){
12 return Objects.nonNull(suggestMaxPrice) && prdPrice.compareTo(suggestMaxPrice) > 0; 12 return Objects.nonNull(suggestMaxPrice) && prdPrice.compareTo(suggestMaxPrice) > 0;
13 } 13 }
  14 +
  15 +
14 } 16 }