Authored by chenchao

Merge branch 'dev_order' into test6.8.2

... ... @@ -213,4 +213,17 @@ public class SellerOrderController {
return new ApiResponse.ApiResponseBuilder().data(result).code(200).message(result.getTips()).build();
}
@RequestMapping(params = "method=ufo.sellerOrder.computeChangePrice")
@ResponseBody
public ApiResponse computeChangePrice(@RequestParam(name = "uid", required = true)int uid,
@RequestParam(name = "storage_id", required = true)int storage_id,
@RequestParam(name="price", required = true)String price,
@RequestParam(name="num", defaultValue = "1", required = false)int num) throws GatewayException {
SellerOrderComputeReq req = SellerOrderComputeReq.builder().uid(uid).storageId(storage_id).price(price)
.num(num).build();
logger.info("in ufo.sellerOrder.computeChangePrice, req {}", req);
SoldPrdComputeBo computeBo = sellerOrderService.computeChangePrice(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(computeBo).message("算费成功").build();
}
}
... ...
... ... @@ -30,4 +30,7 @@ public class ChangePricePrepareDTO {
BigDecimal preSalePrice;
BigDecimal preEarnestMoney;
private String tips;
}
... ...
... ... @@ -50,6 +50,7 @@ import com.yohoufo.order.service.concurrent.ThreadPoolFactory;
import com.yohoufo.order.service.handler.SellerOrderComputeHandler;
import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
import com.yohoufo.order.service.impl.processor.ChangePricePrepareProcessor;
import com.yohoufo.order.service.impl.processor.PriceComputePrepareProcessor;
import com.yohoufo.order.service.impl.processor.SellerBatchCancelPrepareProcessor;
import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor;
import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase;
... ... @@ -128,58 +129,56 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
@Autowired
private MerchantOrderPaymentService merchantOrderPaymentService;
@Autowired
private PriceComputePrepareProcessor priceComputePrepareProcessor;
public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException {
log.info("in computePublishPrd, req {}", req);
int uid = req.getUid();
if(uid <= 0){
log.warn("in computePublishPrd uid illegal , req {}", req);
throw new GatewayException(400, "用户ID错误");
}
//
Integer storageId = req.getStorageId();
if (storageId <=0 ){
log.warn("in computePublishPrd storageId illegal , req {}", req);
throw new GatewayException(400, "storageId 错误");
}
int num;
if ((num = req.getNum())<=0){
log.warn("in computePublishPrd num illegal , req {}", req);
throw new GatewayException(400, "非法数量值");
PriceComputePrepareProcessor.PriceComputeNode pcn = priceComputePrepareProcessor.checkBasePrice(req);
int uid = pcn.getUid();
Integer storageId = pcn.getStorageId();
int num = pcn.getNum();
BigDecimal prdPrice = pcn.getPrdPrice();
String tips = null;
try {
sellerOrderPrepareProcessor.checkPrice(storageId, prdPrice, false);
}catch (Exception ex){
if (ex instanceof UfoServiceException && ((UfoServiceException) ex).getCode() == SellerOrderPrepareProcessor.TIPS_ERROR_CODE){
tips = ((UfoServiceException) ex).getMessage();
}
}
/*商品鉴定费 ¥10.00
商品包装费 ¥10.00
平台服务费(5%,优惠期间0%) ¥0.00
*/
String price = req.getPrice();
if (StringUtils.isBlank(price)){
log.warn("in computePublishPrd price illegal , req {}", req);
throw new GatewayException(400, "没有价格");
}
/*
if(!price.endsWith("9")){
log.warn("in computePublishPrd price illegal , req {}", req);
throw new GatewayException(400, "价格须为以9结尾的正整数");
}*/
SoldPrdComputeBo spc = buildSoldPrdComputeBo(uid, num, prdPrice);
spc.setTips(tips);
return spc;
}
BigDecimal prdPrice = null;
try{
prdPrice = new BigDecimal(price);
}catch (Exception e){
log.warn("in computePublishPrd price convert BigDecimal fail, {}", req);
throw new GatewayException(400, "非法数字");
public SoldPrdComputeBo computeChangePrice(SellerOrderComputeReq req) throws GatewayException {
log.info("in computeChangePrice, req {}", req);
PriceComputePrepareProcessor.PriceComputeNode pcn = priceComputePrepareProcessor.checkBasePrice(req);
int uid = pcn.getUid();
Integer storageId = pcn.getStorageId();
int num = pcn.getNum();
BigDecimal prdPrice = pcn.getPrdPrice();
SellerOrderComputeResult computeResult = computeHandler.compute(prdPrice);
/**
* 验证是否是入驻商家
*/
if(sellerOrderPrepareProcessor.checkIsEntry(uid)){
sellerOrderPrepareProcessor.checkNGetMergeEarnestMoney(uid, computeResult.getEarnestMoney().getEarnestMoney(), num, prdPrice);
}
SoldPrdComputeBo spc = SellerOrderConvertor.computeResult2SoldPrdComputeBo(computeResult);
String tips = null;
try {
sellerOrderPrepareProcessor.checkPrice(storageId, prdPrice, false);
sellerOrderPrepareProcessor.checkPrice(storageId, prdPrice, true);
}catch (Exception ex){
if (ex instanceof UfoServiceException && ((UfoServiceException) ex).getCode() == SellerOrderPrepareProcessor.TIPS_ERROR_CODE){
tips = ((UfoServiceException) ex).getMessage();
}
}
SoldPrdComputeBo spc = buildSoldPrdComputeBo(uid, num, prdPrice);
spc.setTips(tips);
return spc;
}
... ... @@ -553,7 +552,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
@Autowired
private SellerFeeService sellerFeeService;
/**
* todo
* 批量调价
* @param req
* @return
*/
... ... @@ -615,7 +614,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
failCnt = skupMap.size();
}
BatchChangePriceResp resp = BatchChangePriceResp.builder().successCnt(successCnt).failCnt(failCnt)
.tips("变价成功").build();
.tips(cppDto.getTips()).build();
return resp;
}
... ...
... ... @@ -96,7 +96,21 @@ public class ChangePricePrepareProcessor {
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(sampleSkup);
BigDecimal sourceEM = sellerOrder.getEarnestMoney();
int storageId = sampleSog.getStorageId();
sellerOrderPrepareProcessor.checkPrice(storageId, salePrice, true);
String tips = null;
try {
sellerOrderPrepareProcessor.checkPrice(storageId, salePrice, true);
}catch (Exception ex){
if (ex instanceof UfoServiceException
&& ((UfoServiceException) ex).getCode() == SellerOrderPrepareProcessor.TIPS_ERROR_CODE){
tips = ((UfoServiceException) ex).getMessage();
}else{
throw ex;
}
}
// compute every fee from price
SellerOrderComputeResult computeResult = computeHandler.compute(salePrice);
int num = skupMap.size();
... ... @@ -115,6 +129,7 @@ public class ChangePricePrepareProcessor {
.computeResult(computeResult)
.preEarnestMoney(sourceEM)
.preSalePrice(sampleSog.getGoodsPrice())
.tips(tips)
.build();
}
... ...
package com.yohoufo.order.service.impl.processor;
import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
import com.yohoufo.common.exception.GatewayException;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
/**
* Created by chao.chen on 2018/11/28.
*/
@Service
public class PriceComputePrepareProcessor {
final Logger log = LoggerFactory.getLogger(getClass());
@Data
public static class PriceComputeNode{
int uid;
Integer storageId;
int num;
BigDecimal prdPrice;
public PriceComputeNode(int uid, Integer storageId, int num, BigDecimal prdPrice) {
this.uid = uid;
this.storageId = storageId;
this.num = num;
this.prdPrice = prdPrice;
}
}
public PriceComputeNode checkBasePrice(SellerOrderComputeReq req) throws GatewayException {
int uid = req.getUid();
if(uid <= 0){
log.warn("in computePublishPrd uid illegal , req {}", req);
throw new GatewayException(400, "用户ID错误");
}
//
Integer storageId = req.getStorageId();
if (storageId <=0 ){
log.warn("in computePublishPrd storageId illegal , req {}", req);
throw new GatewayException(400, "storageId 错误");
}
int num;
if ((num = req.getNum())<=0){
log.warn("in computePublishPrd num illegal , req {}", req);
throw new GatewayException(400, "非法数量值");
}
/*商品鉴定费 ¥10.00
商品包装费 ¥10.00
平台服务费(5%,优惠期间0%) ¥0.00
*/
String price = req.getPrice();
if (StringUtils.isBlank(price)){
log.warn("in computePublishPrd price illegal , req {}", req);
throw new GatewayException(400, "没有价格");
}
/*
if(!price.endsWith("9")){
log.warn("in computePublishPrd price illegal , req {}", req);
throw new GatewayException(400, "价格须为以9结尾的正整数");
}*/
BigDecimal prdPrice = null;
try{
prdPrice = new BigDecimal(price);
}catch (Exception e){
log.warn("in computePublishPrd price convert BigDecimal fail, {}", req);
throw new GatewayException(400, "非法数字");
}
return new PriceComputeNode(uid, storageId, num, prdPrice);
}
}
... ...