计算运费

This commit is contained in:
wuchunlei
2023-12-05 16:28:51 +08:00
parent 97b7031d72
commit b3cc17a8b0
2 changed files with 51 additions and 16 deletions

View File

@@ -389,27 +389,62 @@ public class BuyOrderController {
*/
@RequestMapping(path = "/calculateTransportPrice", method = RequestMethod.POST)
public R getTransportPrice(@RequestBody ProductTransportVo vo) {
//商品列表和收货区域编码
String regionCode = vo.getRegionCode();
List<ProductRequestVo> products = vo.getProducts();
BigDecimal totalWeight = new BigDecimal(0);
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);
//查询默认快递公司代码 defaultExpress.getParamValue()
QueryWrapper<SysConfigEntity> configQueryWrapper = new QueryWrapper<>();
configQueryWrapper.eq("param_key", "DEFAULT_EXPRESS");
SysConfigEntity config = sysConfigService.getOne(configQueryWrapper);
expressFee = expressFeeService.calculateExpressFee(config.getParamValue(), totalWeight, regionCode);
SysConfigEntity defaultExpress = sysConfigService.getOne(configQueryWrapper);
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);
}
/**

View File

@@ -129,7 +129,7 @@ public class ShopProduct implements Serializable {
*/
private Integer sumSales;
/**
* 商品类型 1: 画册 23:仪器,4:预售书
* 商品类型 01: 画册 0204:仪器,03:预售书
*/
private String goodsType;
private String goodsTypeCode;