Authored by chenchao

Merge branch 'dev_order' into test6.8.2

@@ -213,4 +213,17 @@ public class SellerOrderController { @@ -213,4 +213,17 @@ public class SellerOrderController {
213 return new ApiResponse.ApiResponseBuilder().data(result).code(200).message(result.getTips()).build(); 213 return new ApiResponse.ApiResponseBuilder().data(result).code(200).message(result.getTips()).build();
214 } 214 }
215 215
  216 + @RequestMapping(params = "method=ufo.sellerOrder.computeChangePrice")
  217 + @ResponseBody
  218 + public ApiResponse computeChangePrice(@RequestParam(name = "uid", required = true)int uid,
  219 + @RequestParam(name = "storage_id", required = true)int storage_id,
  220 + @RequestParam(name="price", required = true)String price,
  221 + @RequestParam(name="num", defaultValue = "1", required = false)int num) throws GatewayException {
  222 + SellerOrderComputeReq req = SellerOrderComputeReq.builder().uid(uid).storageId(storage_id).price(price)
  223 + .num(num).build();
  224 + logger.info("in ufo.sellerOrder.computeChangePrice, req {}", req);
  225 + SoldPrdComputeBo computeBo = sellerOrderService.computeChangePrice(req);
  226 + return new ApiResponse.ApiResponseBuilder().code(200).data(computeBo).message("算费成功").build();
  227 + }
  228 +
216 } 229 }
@@ -30,4 +30,7 @@ public class ChangePricePrepareDTO { @@ -30,4 +30,7 @@ public class ChangePricePrepareDTO {
30 BigDecimal preSalePrice; 30 BigDecimal preSalePrice;
31 31
32 BigDecimal preEarnestMoney; 32 BigDecimal preEarnestMoney;
  33 +
  34 +
  35 + private String tips;
33 } 36 }
@@ -50,6 +50,7 @@ import com.yohoufo.order.service.concurrent.ThreadPoolFactory; @@ -50,6 +50,7 @@ import com.yohoufo.order.service.concurrent.ThreadPoolFactory;
50 import com.yohoufo.order.service.handler.SellerOrderComputeHandler; 50 import com.yohoufo.order.service.handler.SellerOrderComputeHandler;
51 import com.yohoufo.order.service.handler.SellerOrderSubmitHandler; 51 import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
52 import com.yohoufo.order.service.impl.processor.ChangePricePrepareProcessor; 52 import com.yohoufo.order.service.impl.processor.ChangePricePrepareProcessor;
  53 +import com.yohoufo.order.service.impl.processor.PriceComputePrepareProcessor;
53 import com.yohoufo.order.service.impl.processor.SellerBatchCancelPrepareProcessor; 54 import com.yohoufo.order.service.impl.processor.SellerBatchCancelPrepareProcessor;
54 import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor; 55 import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor;
55 import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase; 56 import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase;
@@ -128,58 +129,56 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -128,58 +129,56 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
128 @Autowired 129 @Autowired
129 private MerchantOrderPaymentService merchantOrderPaymentService; 130 private MerchantOrderPaymentService merchantOrderPaymentService;
130 131
  132 + @Autowired
  133 + private PriceComputePrepareProcessor priceComputePrepareProcessor;
131 134
132 public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException { 135 public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException {
133 log.info("in computePublishPrd, req {}", req); 136 log.info("in computePublishPrd, req {}", req);
134 - int uid = req.getUid();  
135 - if(uid <= 0){  
136 - log.warn("in computePublishPrd uid illegal , req {}", req);  
137 - throw new GatewayException(400, "用户ID错误"); 137 + PriceComputePrepareProcessor.PriceComputeNode pcn = priceComputePrepareProcessor.checkBasePrice(req);
  138 + int uid = pcn.getUid();
  139 + Integer storageId = pcn.getStorageId();
  140 + int num = pcn.getNum();
  141 + BigDecimal prdPrice = pcn.getPrdPrice();
  142 + String tips = null;
  143 + try {
  144 + sellerOrderPrepareProcessor.checkPrice(storageId, prdPrice, false);
  145 + }catch (Exception ex){
  146 + if (ex instanceof UfoServiceException && ((UfoServiceException) ex).getCode() == SellerOrderPrepareProcessor.TIPS_ERROR_CODE){
  147 + tips = ((UfoServiceException) ex).getMessage();
138 } 148 }
139 - //  
140 - Integer storageId = req.getStorageId();  
141 - if (storageId <=0 ){  
142 - log.warn("in computePublishPrd storageId illegal , req {}", req);  
143 - throw new GatewayException(400, "storageId 错误");  
144 } 149 }
145 - int num;  
146 - if ((num = req.getNum())<=0){  
147 - log.warn("in computePublishPrd num illegal , req {}", req);  
148 - throw new GatewayException(400, "非法数量值"); 150 +
  151 + SoldPrdComputeBo spc = buildSoldPrdComputeBo(uid, num, prdPrice);
  152 + spc.setTips(tips);
  153 + return spc;
149 } 154 }
150 155
151 - /*商品鉴定费 ¥10.00  
152 - 商品包装费 ¥10.00  
153 - 平台服务费(5%,优惠期间0%) ¥0.00 156 + public SoldPrdComputeBo computeChangePrice(SellerOrderComputeReq req) throws GatewayException {
  157 + log.info("in computeChangePrice, req {}", req);
  158 + PriceComputePrepareProcessor.PriceComputeNode pcn = priceComputePrepareProcessor.checkBasePrice(req);
  159 + int uid = pcn.getUid();
  160 + Integer storageId = pcn.getStorageId();
  161 + int num = pcn.getNum();
  162 + BigDecimal prdPrice = pcn.getPrdPrice();
  163 +
  164 + SellerOrderComputeResult computeResult = computeHandler.compute(prdPrice);
  165 + /**
  166 + * 验证是否是入驻商家
154 */ 167 */
155 - String price = req.getPrice();  
156 - if (StringUtils.isBlank(price)){  
157 - log.warn("in computePublishPrd price illegal , req {}", req);  
158 - throw new GatewayException(400, "没有价格");  
159 - }  
160 - /*  
161 - if(!price.endsWith("9")){  
162 - log.warn("in computePublishPrd price illegal , req {}", req);  
163 - throw new GatewayException(400, "价格须为以9结尾的正整数");  
164 - }*/  
165 -  
166 - BigDecimal prdPrice = null;  
167 - try{  
168 - prdPrice = new BigDecimal(price);  
169 - }catch (Exception e){  
170 - log.warn("in computePublishPrd price convert BigDecimal fail, {}", req);  
171 - throw new GatewayException(400, "非法数字"); 168 + if(sellerOrderPrepareProcessor.checkIsEntry(uid)){
  169 + sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid, computeResult.getEarnestMoney().getEarnestMoney(), num, prdPrice);
172 } 170 }
  171 +
  172 + SoldPrdComputeBo spc = SellerOrderConvertor.computeResult2SoldPrdComputeBo(computeResult);
  173 +
173 String tips = null; 174 String tips = null;
174 try { 175 try {
175 - sellerOrderPrepareProcessor.checkPrice(storageId, prdPrice, false); 176 + sellerOrderPrepareProcessor.checkPrice(storageId, prdPrice, true);
176 }catch (Exception ex){ 177 }catch (Exception ex){
177 if (ex instanceof UfoServiceException && ((UfoServiceException) ex).getCode() == SellerOrderPrepareProcessor.TIPS_ERROR_CODE){ 178 if (ex instanceof UfoServiceException && ((UfoServiceException) ex).getCode() == SellerOrderPrepareProcessor.TIPS_ERROR_CODE){
178 tips = ((UfoServiceException) ex).getMessage(); 179 tips = ((UfoServiceException) ex).getMessage();
179 } 180 }
180 } 181 }
181 -  
182 - SoldPrdComputeBo spc = buildSoldPrdComputeBo(uid, num, prdPrice);  
183 spc.setTips(tips); 182 spc.setTips(tips);
184 return spc; 183 return spc;
185 } 184 }
@@ -553,7 +552,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -553,7 +552,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
553 @Autowired 552 @Autowired
554 private SellerFeeService sellerFeeService; 553 private SellerFeeService sellerFeeService;
555 /** 554 /**
556 - * todo 555 + * 批量调价
557 * @param req 556 * @param req
558 * @return 557 * @return
559 */ 558 */
@@ -615,7 +614,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -615,7 +614,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
615 failCnt = skupMap.size(); 614 failCnt = skupMap.size();
616 } 615 }
617 BatchChangePriceResp resp = BatchChangePriceResp.builder().successCnt(successCnt).failCnt(failCnt) 616 BatchChangePriceResp resp = BatchChangePriceResp.builder().successCnt(successCnt).failCnt(failCnt)
618 - .tips("变价成功").build(); 617 + .tips(cppDto.getTips()).build();
619 return resp; 618 return resp;
620 } 619 }
621 620
@@ -96,7 +96,21 @@ public class ChangePricePrepareProcessor { @@ -96,7 +96,21 @@ public class ChangePricePrepareProcessor {
96 SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(sampleSkup); 96 SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(sampleSkup);
97 BigDecimal sourceEM = sellerOrder.getEarnestMoney(); 97 BigDecimal sourceEM = sellerOrder.getEarnestMoney();
98 int storageId = sampleSog.getStorageId(); 98 int storageId = sampleSog.getStorageId();
  99 +
  100 + String tips = null;
  101 + try {
99 sellerOrderPrepareProcessor.checkPrice(storageId, salePrice, true); 102 sellerOrderPrepareProcessor.checkPrice(storageId, salePrice, true);
  103 + }catch (Exception ex){
  104 + if (ex instanceof UfoServiceException
  105 + && ((UfoServiceException) ex).getCode() == SellerOrderPrepareProcessor.TIPS_ERROR_CODE){
  106 + tips = ((UfoServiceException) ex).getMessage();
  107 + }else{
  108 + throw ex;
  109 + }
  110 +
  111 + }
  112 +
  113 +
100 // compute every fee from price 114 // compute every fee from price
101 SellerOrderComputeResult computeResult = computeHandler.compute(salePrice); 115 SellerOrderComputeResult computeResult = computeHandler.compute(salePrice);
102 int num = skupMap.size(); 116 int num = skupMap.size();
@@ -115,6 +129,7 @@ public class ChangePricePrepareProcessor { @@ -115,6 +129,7 @@ public class ChangePricePrepareProcessor {
115 .computeResult(computeResult) 129 .computeResult(computeResult)
116 .preEarnestMoney(sourceEM) 130 .preEarnestMoney(sourceEM)
117 .preSalePrice(sampleSog.getGoodsPrice()) 131 .preSalePrice(sampleSog.getGoodsPrice())
  132 + .tips(tips)
118 .build(); 133 .build();
119 } 134 }
120 135
  1 +package com.yohoufo.order.service.impl.processor;
  2 +
  3 +import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
  4 +import com.yohoufo.common.exception.GatewayException;
  5 +import lombok.Data;
  6 +import org.apache.commons.lang3.StringUtils;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +import java.math.BigDecimal;
  12 +
  13 +/**
  14 + * Created by chao.chen on 2018/11/28.
  15 + */
  16 +@Service
  17 +public class PriceComputePrepareProcessor {
  18 +
  19 + final Logger log = LoggerFactory.getLogger(getClass());
  20 + @Data
  21 + public static class PriceComputeNode{
  22 + int uid;
  23 + Integer storageId;
  24 + int num;
  25 + BigDecimal prdPrice;
  26 +
  27 + public PriceComputeNode(int uid, Integer storageId, int num, BigDecimal prdPrice) {
  28 + this.uid = uid;
  29 + this.storageId = storageId;
  30 + this.num = num;
  31 + this.prdPrice = prdPrice;
  32 + }
  33 + }
  34 +
  35 + public PriceComputeNode checkBasePrice(SellerOrderComputeReq req) throws GatewayException {
  36 + int uid = req.getUid();
  37 + if(uid <= 0){
  38 + log.warn("in computePublishPrd uid illegal , req {}", req);
  39 + throw new GatewayException(400, "用户ID错误");
  40 + }
  41 + //
  42 + Integer storageId = req.getStorageId();
  43 + if (storageId <=0 ){
  44 + log.warn("in computePublishPrd storageId illegal , req {}", req);
  45 + throw new GatewayException(400, "storageId 错误");
  46 + }
  47 + int num;
  48 + if ((num = req.getNum())<=0){
  49 + log.warn("in computePublishPrd num illegal , req {}", req);
  50 + throw new GatewayException(400, "非法数量值");
  51 + }
  52 +
  53 + /*商品鉴定费 ¥10.00
  54 + 商品包装费 ¥10.00
  55 + 平台服务费(5%,优惠期间0%) ¥0.00
  56 + */
  57 + String price = req.getPrice();
  58 + if (StringUtils.isBlank(price)){
  59 + log.warn("in computePublishPrd price illegal , req {}", req);
  60 + throw new GatewayException(400, "没有价格");
  61 + }
  62 + /*
  63 + if(!price.endsWith("9")){
  64 + log.warn("in computePublishPrd price illegal , req {}", req);
  65 + throw new GatewayException(400, "价格须为以9结尾的正整数");
  66 + }*/
  67 +
  68 + BigDecimal prdPrice = null;
  69 + try{
  70 + prdPrice = new BigDecimal(price);
  71 + }catch (Exception e){
  72 + log.warn("in computePublishPrd price convert BigDecimal fail, {}", req);
  73 + throw new GatewayException(400, "非法数字");
  74 + }
  75 +
  76 + return new PriceComputeNode(uid, storageId, num, prdPrice);
  77 + }
  78 +}