计算运费
This commit is contained in:
@@ -389,27 +389,62 @@ public class BuyOrderController {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping(path = "/calculateTransportPrice", method = RequestMethod.POST)
|
@RequestMapping(path = "/calculateTransportPrice", method = RequestMethod.POST)
|
||||||
public R getTransportPrice(@RequestBody ProductTransportVo vo) {
|
public R getTransportPrice(@RequestBody ProductTransportVo vo) {
|
||||||
|
//商品列表和收货区域编码
|
||||||
String regionCode = vo.getRegionCode();
|
String regionCode = vo.getRegionCode();
|
||||||
List<ProductRequestVo> products = vo.getProducts();
|
List<ProductRequestVo> products = vo.getProducts();
|
||||||
BigDecimal totalWeight = new BigDecimal(0);
|
//查询默认快递公司代码 defaultExpress.getParamValue()
|
||||||
for (ProductRequestVo product : products) {
|
|
||||||
ShopProduct shopProduct = shopProductService.getById(product.getProductId());
|
|
||||||
if(shopProduct.getIsFreeMail()==0){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
BigDecimal weight = BigDecimal.valueOf(Double.valueOf(shopProduct.getWeight()) / 1000.0);
|
|
||||||
totalWeight = totalWeight.add(weight.multiply(new BigDecimal(product.getQuantity())));
|
|
||||||
}
|
|
||||||
BigDecimal expressFee = new BigDecimal(0);
|
|
||||||
if(totalWeight.compareTo(BigDecimal.ZERO)!=0){
|
|
||||||
totalWeight = totalWeight.setScale(0, RoundingMode.UP);
|
|
||||||
QueryWrapper<SysConfigEntity> configQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<SysConfigEntity> configQueryWrapper = new QueryWrapper<>();
|
||||||
configQueryWrapper.eq("param_key", "DEFAULT_EXPRESS");
|
configQueryWrapper.eq("param_key", "DEFAULT_EXPRESS");
|
||||||
SysConfigEntity config = sysConfigService.getOne(configQueryWrapper);
|
SysConfigEntity defaultExpress = sysConfigService.getOne(configQueryWrapper);
|
||||||
expressFee = expressFeeService.calculateExpressFee(config.getParamValue(), totalWeight, regionCode);
|
if (defaultExpress == null) {
|
||||||
|
return R.error("未设置默认快递");
|
||||||
}
|
}
|
||||||
|
//总运费
|
||||||
return R.ok().put("result", expressFee);
|
BigDecimal totalExpressFee = new BigDecimal(0);
|
||||||
|
BigDecimal totalWeight01 = new BigDecimal(0);
|
||||||
|
BigDecimal totalWeight02 = new BigDecimal(0);
|
||||||
|
BigDecimal totalWeight04 = new BigDecimal(0);
|
||||||
|
for (ProductRequestVo product : products) {
|
||||||
|
ShopProduct p = shopProductService.getById(product.getProductId());
|
||||||
|
if (p != null) {
|
||||||
|
//包邮
|
||||||
|
if(p.getIsFreeMail()==0){
|
||||||
|
continue;
|
||||||
|
}else {
|
||||||
|
BigDecimal weight = BigDecimal.valueOf(Double.valueOf(p.getWeight()) / 1000.0);
|
||||||
|
BigDecimal totalWeight = weight.multiply(new BigDecimal(product.getQuantity()));
|
||||||
|
if ("01".equals(p.getGoodsType())){
|
||||||
|
totalWeight01 = totalWeight01.add(totalWeight);
|
||||||
|
}
|
||||||
|
if ("02".equals(p.getGoodsType())){
|
||||||
|
totalWeight02 = totalWeight02.add(totalWeight);
|
||||||
|
}
|
||||||
|
//预售书单独计算
|
||||||
|
if ("03".equals(p.getGoodsType())){
|
||||||
|
totalExpressFee = totalExpressFee.add(
|
||||||
|
expressFeeService.calculateExpressFee(defaultExpress.getParamValue(), totalWeight.setScale(0, RoundingMode.UP), regionCode));
|
||||||
|
}
|
||||||
|
if ("04".equals(p.getGoodsType())){
|
||||||
|
totalWeight04 = totalWeight04.add(totalWeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
return R.error("未查询到商品");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(totalWeight01.compareTo(BigDecimal.ZERO)!=0){
|
||||||
|
totalExpressFee = totalExpressFee.add(
|
||||||
|
expressFeeService.calculateExpressFee(defaultExpress.getParamValue(), totalWeight01.setScale(0, RoundingMode.UP), regionCode));
|
||||||
|
}
|
||||||
|
if(totalWeight02.compareTo(BigDecimal.ZERO)!=0){
|
||||||
|
totalExpressFee = totalExpressFee.add(
|
||||||
|
expressFeeService.calculateExpressFee(defaultExpress.getParamValue(), totalWeight02.setScale(0, RoundingMode.UP), regionCode));
|
||||||
|
}
|
||||||
|
if(totalWeight04.compareTo(BigDecimal.ZERO)!=0){
|
||||||
|
totalExpressFee = totalExpressFee.add(
|
||||||
|
expressFeeService.calculateExpressFee(defaultExpress.getParamValue(), totalWeight04.setScale(0, RoundingMode.UP), regionCode));
|
||||||
|
}
|
||||||
|
return R.ok().put("result", totalExpressFee);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ public class ShopProduct implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Integer sumSales;
|
private Integer sumSales;
|
||||||
/**
|
/**
|
||||||
* 商品类型 1: 画册 2:书 3:仪器,4:预售书
|
* 商品类型 01: 画册 02:书 04:仪器,03:预售书
|
||||||
*/
|
*/
|
||||||
private String goodsType;
|
private String goodsType;
|
||||||
private String goodsTypeCode;
|
private String goodsTypeCode;
|
||||||
|
|||||||
Reference in New Issue
Block a user