...
|
...
|
@@ -7,13 +7,18 @@ import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo; |
|
|
import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
|
|
|
import com.yohoufo.common.exception.GatewayException;
|
|
|
import com.yohoufo.common.http.URLHolder;
|
|
|
import com.yohoufo.common.utils.BigDecimalHelper;
|
|
|
import com.yohoufo.common.utils.PriceFormater;
|
|
|
import com.yohoufo.dal.order.SellerOrderMapper;
|
|
|
import com.yohoufo.order.model.dto.PlatformFeeDto;
|
|
|
import com.yohoufo.product.response.StorageLeastPriceResp;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* Created by chenchao on 2018/9/13.
|
...
|
...
|
@@ -31,17 +36,23 @@ public class SellerOrderService { |
|
|
@Autowired
|
|
|
private URLHolder urlHolder;
|
|
|
|
|
|
private static final BigDecimal[] EARNESTMONEYRANGE = {new BigDecimal(28), new BigDecimal(200)};
|
|
|
|
|
|
public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException {
|
|
|
log.info("in computePublishPrd, req {}", req);
|
|
|
SoldPrdComputeBo computeBo = null;
|
|
|
|
|
|
//TODO
|
|
|
String baseUrl = urlHolder.getUrl();
|
|
|
String apiParam = "?method=ufo.product.storage.leastprice";
|
|
|
String fullUrl = baseUrl + apiParam;
|
|
|
Object params = new Object();
|
|
|
AsyncFuture<Object> future = serviceCaller.post("product.getFloorPrice", fullUrl, params, Object.class, new Object());
|
|
|
Object resp = future.get();
|
|
|
|
|
|
AsyncFuture<StorageLeastPriceResp.StorageLeastPrice> future = serviceCaller.post("product.getFloorPrice", fullUrl, params,
|
|
|
StorageLeastPriceResp.StorageLeastPrice.class, null);
|
|
|
StorageLeastPriceResp.StorageLeastPrice resp = future.get();
|
|
|
BigDecimal leastPrice;
|
|
|
if (Objects.isNull(resp) || Objects.isNull(leastPrice = resp.getLeastPrice()) || leastPrice.doubleValue() == 0D){
|
|
|
throw new GatewayException(501, "暂无商品");
|
|
|
}
|
|
|
/*商品鉴定费 ¥10.00
|
|
|
商品包装费 ¥10.00
|
|
|
平台服务费(5%,优惠期间0%) ¥0.00
|
...
|
...
|
@@ -52,19 +63,93 @@ public class SellerOrderService { |
|
|
throw new GatewayException(400, "没有价格");
|
|
|
}
|
|
|
|
|
|
try{
|
|
|
BigDecimal prdPrice = new BigDecimal(price);
|
|
|
String earnestMoneyStr;
|
|
|
PlatformFee platformFee;
|
|
|
String incomeStr;
|
|
|
|
|
|
//保证金(28-200(按照卖家发布商品的货款金额5%计算,最低28,封顶200));
|
|
|
|
|
|
|
|
|
BigDecimal prdPrice = null;
|
|
|
try{
|
|
|
prdPrice = new BigDecimal(price);
|
|
|
}catch (Exception e){
|
|
|
log.warn("in computePublishPrd price convert BigDecimal fail, {}", req);
|
|
|
return null;
|
|
|
}
|
|
|
if (prdPrice.subtract(leastPrice).doubleValue() < 0D){
|
|
|
log.warn("in computePublishPrd,leastPrice {}, req {}", leastPrice, req);
|
|
|
throw new GatewayException(501, "设定的价格低于商品最低价");
|
|
|
}
|
|
|
|
|
|
return buildSoldPrdComputeBo(prdPrice);
|
|
|
}
|
|
|
|
|
|
public SoldPrdComputeBo buildSoldPrdComputeBo(BigDecimal prdPrice){
|
|
|
//保证金(28-200(按照卖家发布商品的货款金额5%计算,最低28,封顶200))
|
|
|
BigDecimal earnestMoney = calEarnestMoney(prdPrice);
|
|
|
//银行转账费(0.65%+¥1.00)
|
|
|
BigDecimal bankTransferfee = calBankTransferFee(prdPrice);
|
|
|
PlatformFeeDto platformFeeDto = calPlatformFee();
|
|
|
BigDecimal income = calIncome(prdPrice, platformFeeDto.getTotal(), bankTransferfee);
|
|
|
|
|
|
//
|
|
|
PlatformFee platformFeeWrapper = PlatformFee.builder()
|
|
|
.appraiseFee(formatFee(platformFeeDto.getAppraiseFee()))
|
|
|
.packageFee(formatFee(platformFeeDto.getPackageFee()))
|
|
|
.serviceFee(formatFee(platformFeeDto.getServiceFee())).build();
|
|
|
//
|
|
|
String incomeStr = formatFee(income);
|
|
|
String earnestMoneyStr = formatFee(earnestMoney);
|
|
|
String bankTransferFeeStr = formatFee(bankTransferfee);
|
|
|
SoldPrdComputeBo computeBo = SoldPrdComputeBo.builder()
|
|
|
.earnestMoney(earnestMoneyStr)
|
|
|
.bankTransferFee(bankTransferFeeStr)
|
|
|
.platformFee(platformFeeWrapper)
|
|
|
.income(incomeStr)
|
|
|
.build();
|
|
|
return computeBo;
|
|
|
}
|
|
|
|
|
|
|
|
|
private BigDecimal calBankTransferFee(BigDecimal prdPrice){
|
|
|
//银行转账费(0.65%+¥1.00)
|
|
|
return prdPrice.multiply(new BigDecimal(0.0065)).add(new BigDecimal(1));
|
|
|
}
|
|
|
|
|
|
private BigDecimal calIncome(BigDecimal prdPrice,BigDecimal platformFee,BigDecimal bankTransferfee){
|
|
|
return prdPrice.subtract(platformFee).subtract(bankTransferfee);
|
|
|
}
|
|
|
|
|
|
private PlatformFeeDto calPlatformFee(){
|
|
|
|
|
|
BigDecimal appraiseFee = new BigDecimal(10);;
|
|
|
BigDecimal packageFee = new BigDecimal(10);
|
|
|
BigDecimal serviceFee = new BigDecimal(0);
|
|
|
|
|
|
BigDecimal total = appraiseFee.add(packageFee).add(serviceFee);
|
|
|
PlatformFeeDto platformFee = new PlatformFeeDto();
|
|
|
platformFee.setTotal(total);
|
|
|
platformFee.setAppraiseFee(appraiseFee);
|
|
|
platformFee.setPackageFee(packageFee);
|
|
|
platformFee.setServiceFee(serviceFee);
|
|
|
return platformFee;
|
|
|
}
|
|
|
|
|
|
|
|
|
private String formatFee(BigDecimal fee){
|
|
|
return PriceFormater.addCnCurrencySymbol(BigDecimalHelper.formatNumber(fee, BigDecimalHelper.FORMAT_TWOBITAFTERPOINT));
|
|
|
}
|
|
|
|
|
|
private BigDecimal calEarnestMoney(BigDecimal prdPrice){
|
|
|
BigDecimal real = prdPrice.multiply(new BigDecimal(0.05));
|
|
|
final BigDecimal min = EARNESTMONEYRANGE[0];
|
|
|
final BigDecimal max = EARNESTMONEYRANGE[1];
|
|
|
if(real.subtract(min).doubleValue() < 0D){
|
|
|
return min;
|
|
|
}
|
|
|
|
|
|
if (real.subtract(max).doubleValue() > 0D){
|
|
|
return max;
|
|
|
}
|
|
|
|
|
|
return real;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|