Authored by chenchao

add judge num

@@ -50,7 +50,8 @@ public class SellerOrderController { @@ -50,7 +50,8 @@ public class SellerOrderController {
50 @RequestParam(name = "storage_id", required = true)int storage_id, 50 @RequestParam(name = "storage_id", required = true)int storage_id,
51 @RequestParam(name="price", required = true)String price, 51 @RequestParam(name="price", required = true)String price,
52 @RequestParam(name="num", defaultValue = "1", required = false)int num) throws GatewayException { 52 @RequestParam(name="num", defaultValue = "1", required = false)int num) throws GatewayException {
53 - SellerOrderComputeReq req = SellerOrderComputeReq.builder().uid(uid).storageId(storage_id).price(price).build(); 53 + SellerOrderComputeReq req = SellerOrderComputeReq.builder().uid(uid).storageId(storage_id).price(price)
  54 + .num(num).build();
54 logger.info("in ufo.sellerOrder.computePublishPrd, req {}", req); 55 logger.info("in ufo.sellerOrder.computePublishPrd, req {}", req);
55 SoldPrdComputeBo computeBo = sellerOrderService.computePublishPrd(req); 56 SoldPrdComputeBo computeBo = sellerOrderService.computePublishPrd(req);
56 return new ApiResponse.ApiResponseBuilder().code(200).data(computeBo).message("算费成功").build(); 57 return new ApiResponse.ApiResponseBuilder().code(200).data(computeBo).message("算费成功").build();
@@ -12,6 +12,7 @@ import com.yohoufo.common.alarm.EventBusPublisher; @@ -12,6 +12,7 @@ import com.yohoufo.common.alarm.EventBusPublisher;
12 import com.yohoufo.common.alarm.SmsAlarmEvent; 12 import com.yohoufo.common.alarm.SmsAlarmEvent;
13 import com.yohoufo.common.exception.GatewayException; 13 import com.yohoufo.common.exception.GatewayException;
14 import com.yohoufo.common.utils.AddressUtil; 14 import com.yohoufo.common.utils.AddressUtil;
  15 +import com.yohoufo.common.utils.BigDecimalHelper;
15 import com.yohoufo.common.utils.DateUtil; 16 import com.yohoufo.common.utils.DateUtil;
16 import com.yohoufo.dal.order.*; 17 import com.yohoufo.dal.order.*;
17 import com.yohoufo.dal.order.model.*; 18 import com.yohoufo.dal.order.model.*;
@@ -23,6 +24,8 @@ import com.yohoufo.order.event.OrderCancelEvent; @@ -23,6 +24,8 @@ import com.yohoufo.order.event.OrderCancelEvent;
23 import com.yohoufo.order.model.AddressInfo; 24 import com.yohoufo.order.model.AddressInfo;
24 import com.yohobuy.ufo.model.order.bo.GoodsInfo; 25 import com.yohobuy.ufo.model.order.bo.GoodsInfo;
25 import com.yohoufo.order.model.SellerOrderContext; 26 import com.yohoufo.order.model.SellerOrderContext;
  27 +import com.yohoufo.order.model.dto.EarnestMoney;
  28 +import com.yohoufo.order.model.dto.PlatformFeeDto;
26 import com.yohoufo.order.model.dto.SellerOrderComputeResult; 29 import com.yohoufo.order.model.dto.SellerOrderComputeResult;
27 import com.yohoufo.order.model.request.OrderListRequest; 30 import com.yohoufo.order.model.request.OrderListRequest;
28 import com.yohoufo.order.model.request.OrderRequest; 31 import com.yohoufo.order.model.request.OrderRequest;
@@ -110,13 +113,22 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -110,13 +113,22 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
110 113
111 public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException { 114 public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException {
112 log.info("in computePublishPrd, req {}", req); 115 log.info("in computePublishPrd, req {}", req);
113 - 116 + int uid = req.getUid();
  117 + if(uid <= 0){
  118 + log.warn("in computePublishPrd uid illegal , req {}", req);
  119 + throw new GatewayException(400, "用户ID错误");
  120 + }
114 // 121 //
115 Integer storageId = req.getStorageId(); 122 Integer storageId = req.getStorageId();
116 if (storageId <=0 ){ 123 if (storageId <=0 ){
117 log.warn("in computePublishPrd storageId illegal , req {}", req); 124 log.warn("in computePublishPrd storageId illegal , req {}", req);
118 throw new GatewayException(400, "storageId 错误"); 125 throw new GatewayException(400, "storageId 错误");
119 } 126 }
  127 + int num;
  128 + if ((num = req.getNum())<=0){
  129 + log.warn("in computePublishPrd num illegal , req {}", req);
  130 + throw new GatewayException(400, "非法数量值");
  131 + }
120 132
121 /*商品鉴定费 ¥10.00 133 /*商品鉴定费 ¥10.00
122 商品包装费 ¥10.00 134 商品包装费 ¥10.00
@@ -133,19 +145,15 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -133,19 +145,15 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
133 throw new GatewayException(400, "价格须为以9结尾的正整数"); 145 throw new GatewayException(400, "价格须为以9结尾的正整数");
134 } 146 }
135 147
136 -  
137 BigDecimal prdPrice = null; 148 BigDecimal prdPrice = null;
138 try{ 149 try{
139 prdPrice = new BigDecimal(price); 150 prdPrice = new BigDecimal(price);
140 }catch (Exception e){ 151 }catch (Exception e){
141 log.warn("in computePublishPrd price convert BigDecimal fail, {}", req); 152 log.warn("in computePublishPrd price convert BigDecimal fail, {}", req);
142 - return null; 153 + throw new GatewayException(400, "非法数字");
143 } 154 }
144 -  
145 checkPrice(storageId, prdPrice, false); 155 checkPrice(storageId, prdPrice, false);
146 -  
147 -  
148 - return buildSoldPrdComputeBo(prdPrice); 156 + return buildSoldPrdComputeBo(uid, num, prdPrice);
149 } 157 }
150 158
151 159
@@ -481,9 +489,28 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -481,9 +489,28 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
481 489
482 490
483 491
  492 + private boolean isEnough(int uid, BigDecimal mEarestMoney){
  493 +
  494 + //todo 取出入驻商家的钱包余额,判断保证金总额是否足够扣减
  495 + return false;
  496 + }
484 497
485 - public SoldPrdComputeBo buildSoldPrdComputeBo(BigDecimal prdPrice){ 498 + private SoldPrdComputeBo buildSoldPrdComputeBo(int uid, int num, BigDecimal prdPrice){
486 SellerOrderComputeResult computeResult = computeHandler.compute(prdPrice); 499 SellerOrderComputeResult computeResult = computeHandler.compute(prdPrice);
  500 + /**
  501 + * 验证是否是入驻商家
  502 + */
  503 + boolean isEntryShop = userProxyService.isEntryShop(uid);
  504 + if(isEntryShop){
  505 + BigDecimal singleEarestMoney = computeResult.getEarnestMoney().getEarnestMoney();
  506 + BigDecimal mEarestMoney = BigDecimalHelper.halfUp(new BigDecimal(num).multiply(singleEarestMoney));
  507 +
  508 + boolean isEnough = isEnough(uid, mEarestMoney);
  509 + if (!isEnough){
  510 +
  511 + throw new ServiceException(ServiceError.WALLET_EARNESTMONEY_IS_NOT_ENOUGH);
  512 + }
  513 + }
487 SoldPrdComputeBo computeBo = SellerOrderConvertor.computeResult2SoldPrdComputeBo(computeResult); 514 SoldPrdComputeBo computeBo = SellerOrderConvertor.computeResult2SoldPrdComputeBo(computeResult);
488 return computeBo; 515 return computeBo;
489 } 516 }
@@ -8,6 +8,7 @@ import com.yoho.error.ServiceError; @@ -8,6 +8,7 @@ import com.yoho.error.ServiceError;
8 import com.yoho.error.exception.ServiceException; 8 import com.yoho.error.exception.ServiceException;
9 import com.yoho.service.model.request.UserAddressReqBO; 9 import com.yoho.service.model.request.UserAddressReqBO;
10 import com.yohoufo.common.ApiResponse; 10 import com.yohoufo.common.ApiResponse;
  11 +import com.yohoufo.common.caller.UfoServiceCaller;
11 import com.yohoufo.order.convert.AddressInfoConvertor; 12 import com.yohoufo.order.convert.AddressInfoConvertor;
12 import com.yohoufo.order.model.AddressInfo; 13 import com.yohoufo.order.model.AddressInfo;
13 import org.apache.commons.lang3.StringUtils; 14 import org.apache.commons.lang3.StringUtils;
@@ -38,6 +39,9 @@ public class UserProxyService { @@ -38,6 +39,9 @@ public class UserProxyService {
38 39
39 @Value("${uic.url:http://uic.yohoops.org/uic}") 40 @Value("${uic.url:http://uic.yohoops.org/uic}")
40 private String uicUrl; 41 private String uicUrl;
  42 +
  43 + @Autowired
  44 + private UfoServiceCaller ufoServiceCaller;
41 /** 45 /**
42 * 获取用户信息 46 * 获取用户信息
43 * @param uid 47 * @param uid
@@ -133,4 +137,20 @@ public class UserProxyService { @@ -133,4 +137,20 @@ public class UserProxyService {
133 } 137 }
134 return mobile; 138 return mobile;
135 } 139 }
  140 +
  141 + public boolean isEntryShop(int uid){
  142 +
  143 + //入驻商户 method=ufo.user.isStoredSeller ,入参 uid
  144 + ApiResponse userInfo ;
  145 + try {
  146 + userInfo = ufoServiceCaller.call("ufo.user.isStoredSeller", uid);
  147 +
  148 +
  149 + }catch (Exception ex){
  150 + logger.warn("in getMobile fail, uid {}", uid, ex);
  151 + throw new ServiceException(ServiceError.USER_IS_NOT_EXIST);
  152 + }
  153 + logger.info("judge user is entry shop, uid {} resp {}", uid, userInfo);
  154 + return (userInfo == null || userInfo.getData() == null) ? false : (boolean) userInfo.getData();
  155 + }
136 } 156 }
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 <parent> 6 <parent>
7 <groupId>com.yoho</groupId> 7 <groupId>com.yoho</groupId>
8 <artifactId>parent</artifactId> 8 <artifactId>parent</artifactId>
9 - <version>1.4.7-SNAPSHOT</version> 9 + <version>1.4.8-SNAPSHOT</version>
10 </parent> 10 </parent>
11 11
12 <groupId>com.yohoufo.fore</groupId> 12 <groupId>com.yohoufo.fore</groupId>
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 <properties> 18 <properties>
19 <qiniu.version>7.0.5</qiniu.version> 19 <qiniu.version>7.0.5</qiniu.version>
20 <project-name>yohoufo-fore</project-name> 20 <project-name>yohoufo-fore</project-name>
21 - <model.version>test-1.0-SNAPSHOT</model.version> 21 + <model.version>2.0-SNAPSHOT</model.version>
22 </properties> 22 </properties>
23 23
24 <dependencyManagement> 24 <dependencyManagement>