|
|
|
@ -9,13 +9,6 @@ import cn.iocoder.yudao.module.member.api.address.AddressApi;
|
|
|
|
|
import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO;
|
|
|
|
|
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
|
|
|
|
|
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
|
|
|
|
import cn.iocoder.yudao.module.product.api.express.ShippingTemplatesApi;
|
|
|
|
|
import cn.iocoder.yudao.module.product.api.express.ShippingTemplatesFreeApi;
|
|
|
|
|
import cn.iocoder.yudao.module.product.api.express.ShippingTemplatesRegionApi;
|
|
|
|
|
import cn.iocoder.yudao.module.product.api.express.dto.ShippingTemplatesDO;
|
|
|
|
|
import cn.iocoder.yudao.module.product.api.express.dto.ShippingTemplatesFreeDO;
|
|
|
|
|
import cn.iocoder.yudao.module.product.api.express.dto.ShippingTemplatesRegionDO;
|
|
|
|
|
import cn.iocoder.yudao.module.product.api.property.ProductPropertyValueApi;
|
|
|
|
|
import cn.iocoder.yudao.module.shop.constants.PayConstants;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.enums.Constants;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
|
@ -119,17 +112,15 @@ public class OrderServiceImpl implements OrderService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private AddressApi addressApi;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private GetProductReply getProductReply;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ShippingTemplatesApi shippingTemplatesApi;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ShippingTemplatesFreeApi shippingTemplatesFreeApi;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ShippingTemplatesRegionApi shippingTemplatesRegionApi;
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private ShippingTemplatesApi shippingTemplatesApi;
|
|
|
|
|
//
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private ShippingTemplatesFreeApi shippingTemplatesFreeApi;
|
|
|
|
|
//
|
|
|
|
|
// @Autowired
|
|
|
|
|
// private ShippingTemplatesRegionApi shippingTemplatesRegionApi;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private StoreProductService storeProductService;
|
|
|
|
@ -612,115 +603,115 @@ public class OrderServiceImpl implements OrderService {
|
|
|
|
|
* 计算订单运费
|
|
|
|
|
*/
|
|
|
|
|
private void getFreightFee(OrderInfoVo orderInfoVo, AddressRespDTO userAddress) {
|
|
|
|
|
// 判断是否满额包邮 type=1按件数 2按重量 3按体积
|
|
|
|
|
// 全场满额包邮开关
|
|
|
|
|
String postageSwitchString = apiConfigApi.getConfigKey(SysConfigConstants.STORE_FEE_POSTAGE_SWITCH).toString();
|
|
|
|
|
// 全场满额包邮金额
|
|
|
|
|
String storeFreePostageString = apiConfigApi.getConfigKey(SysConfigConstants.STORE_FEE_POSTAGE).toString();
|
|
|
|
|
BigDecimal storePostage = BigDecimal.ZERO;
|
|
|
|
|
if (postageSwitchString.equals("true") && (storeFreePostageString.equals("0") || orderInfoVo.getProTotalFee().compareTo(new BigDecimal(storeFreePostageString)) >= 0)) {
|
|
|
|
|
storePostage = BigDecimal.ZERO;
|
|
|
|
|
} else if (ObjectUtil.isNull(userAddress) || userAddress.getCityId() <= 0) {
|
|
|
|
|
// 用户地址不存在,默认运费为0元
|
|
|
|
|
storePostage = BigDecimal.ZERO;
|
|
|
|
|
} else {
|
|
|
|
|
// 有用户地址的情况下
|
|
|
|
|
// 运费根据商品计算
|
|
|
|
|
Map<Integer, MyRecord> proMap = new HashMap<>();
|
|
|
|
|
orderInfoVo.getOrderDetailList().forEach(e -> {
|
|
|
|
|
Integer proId = e.getProductId();
|
|
|
|
|
if (proMap.containsKey(proId)) {
|
|
|
|
|
MyRecord record = proMap.get(proId);
|
|
|
|
|
record.set("totalPrice", record.getBigDecimal("totalPrice").add(e.getPrice().multiply(BigDecimal.valueOf(e.getPayNum()))));
|
|
|
|
|
record.set("totalNum", record.getInt("totalNum") + e.getPayNum());
|
|
|
|
|
BigDecimal weight = e.getWeight().multiply(BigDecimal.valueOf(e.getPayNum()));
|
|
|
|
|
record.set("weight", record.getBigDecimal("weight").add(weight));
|
|
|
|
|
BigDecimal volume = e.getVolume().multiply(BigDecimal.valueOf(e.getPayNum()));
|
|
|
|
|
record.set("volume", record.getBigDecimal("volume").add(volume));
|
|
|
|
|
} else {
|
|
|
|
|
MyRecord record = new MyRecord();
|
|
|
|
|
record.set("totalPrice", e.getPrice().multiply(BigDecimal.valueOf(e.getPayNum())));
|
|
|
|
|
record.set("totalNum", e.getPayNum());
|
|
|
|
|
record.set("tempId", e.getTempId());
|
|
|
|
|
record.set("proId", proId);
|
|
|
|
|
BigDecimal weight = e.getWeight().multiply(BigDecimal.valueOf(e.getPayNum()));
|
|
|
|
|
record.set("weight", weight);
|
|
|
|
|
BigDecimal volume = e.getVolume().multiply(BigDecimal.valueOf(e.getPayNum()));
|
|
|
|
|
record.set("volume", volume);
|
|
|
|
|
|
|
|
|
|
proMap.put(proId, record);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 指定包邮(单品运费模板)> 指定区域配送(单品运费模板)
|
|
|
|
|
int cityId = userAddress.getCityId();
|
|
|
|
|
|
|
|
|
|
for (Map.Entry<Integer, MyRecord> m : proMap.entrySet()) {
|
|
|
|
|
MyRecord value = m.getValue();
|
|
|
|
|
Integer tempId = value.getInt("tempId");
|
|
|
|
|
ShippingTemplatesDO shippingTemplatesDO = shippingTemplatesApi.getById(tempId);
|
|
|
|
|
if (shippingTemplatesDO.getAppoint()) {// 指定包邮
|
|
|
|
|
// 判断是否在指定包邮区域内
|
|
|
|
|
// 必须满足件数 + 金额 才能包邮
|
|
|
|
|
ShippingTemplatesFreeDO shippingTemplatesFree = shippingTemplatesFreeApi.getByTempIdAndCityId(tempId, cityId);
|
|
|
|
|
if (ObjectUtil.isNotNull(shippingTemplatesFree)) { // 在包邮区域内
|
|
|
|
|
BigDecimal freeNum = shippingTemplatesFree.getNumber();
|
|
|
|
|
BigDecimal multiply = value.getBigDecimal("totalPrice");
|
|
|
|
|
if (new BigDecimal(value.getInt("totalNum")).compareTo(freeNum) >= 0 && multiply.compareTo(shippingTemplatesFree.getPrice()) >= 0) {
|
|
|
|
|
// 满足件数 + 金额 = 包邮
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 不满足指定包邮条件,走指定区域配送
|
|
|
|
|
ShippingTemplatesRegionDO shippingTemplatesRegion = shippingTemplatesRegionApi.getByTempIdAndCityId(tempId, cityId);
|
|
|
|
|
if (ObjectUtil.isNull(shippingTemplatesRegion)) {
|
|
|
|
|
throw new ServiceException("计算运费时,未找到全国运费配置");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 判断计费方式:件数、重量、体积
|
|
|
|
|
switch (shippingTemplatesDO.getType()) {
|
|
|
|
|
case 1: // 件数
|
|
|
|
|
// 判断件数是否超过首件
|
|
|
|
|
Integer num = value.getInt("totalNum");
|
|
|
|
|
if (num <= shippingTemplatesRegion.getFirst().intValue()) {
|
|
|
|
|
storePostage = storePostage.add(shippingTemplatesRegion.getFirstPrice());
|
|
|
|
|
} else {// 超过首件的需要计算续件
|
|
|
|
|
int renewalNum = num - shippingTemplatesRegion.getFirst().intValue();
|
|
|
|
|
// 剩余件数/续件 = 需要计算的续件费用的次数
|
|
|
|
|
BigDecimal divide = new BigDecimal(renewalNum).divide(shippingTemplatesRegion.getRenewal(), 0, BigDecimal.ROUND_UP);
|
|
|
|
|
BigDecimal renewalPrice = shippingTemplatesRegion.getRenewalPrice().multiply(divide);
|
|
|
|
|
storePostage = storePostage.add(shippingTemplatesRegion.getFirstPrice()).add(renewalPrice);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2: // 重量
|
|
|
|
|
BigDecimal weight = value.getBigDecimal("weight");
|
|
|
|
|
if (weight.compareTo(shippingTemplatesRegion.getFirst()) <= 0) {
|
|
|
|
|
storePostage = storePostage.add(shippingTemplatesRegion.getFirstPrice());
|
|
|
|
|
} else {// 超过首件的需要计算续件
|
|
|
|
|
BigDecimal renewalNum = weight.subtract(shippingTemplatesRegion.getFirst());
|
|
|
|
|
// 剩余件数/续件 = 需要计算的续件费用的次数
|
|
|
|
|
BigDecimal divide = renewalNum.divide(shippingTemplatesRegion.getRenewal(), 0, BigDecimal.ROUND_UP);
|
|
|
|
|
BigDecimal renewalPrice = shippingTemplatesRegion.getRenewalPrice().multiply(divide);
|
|
|
|
|
storePostage = storePostage.add(shippingTemplatesRegion.getFirstPrice()).add(renewalPrice);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3: // 体积
|
|
|
|
|
BigDecimal volume = value.getBigDecimal("volume");
|
|
|
|
|
if (volume.compareTo(shippingTemplatesRegion.getFirst()) <= 0) {
|
|
|
|
|
storePostage = storePostage.add(shippingTemplatesRegion.getFirstPrice());
|
|
|
|
|
} else {// 超过首件的需要计算续件
|
|
|
|
|
BigDecimal renewalNum = volume.subtract(shippingTemplatesRegion.getFirst());
|
|
|
|
|
// 剩余件数/续件 = 需要计算的续件费用的次数
|
|
|
|
|
BigDecimal divide = renewalNum.divide(shippingTemplatesRegion.getRenewal(), 0, BigDecimal.ROUND_UP);
|
|
|
|
|
BigDecimal renewalPrice = shippingTemplatesRegion.getRenewalPrice().multiply(divide);
|
|
|
|
|
storePostage = storePostage.add(shippingTemplatesRegion.getFirstPrice()).add(renewalPrice);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
orderInfoVo.setFreightFee(storePostage);
|
|
|
|
|
// // 判断是否满额包邮 type=1按件数 2按重量 3按体积
|
|
|
|
|
// // 全场满额包邮开关
|
|
|
|
|
// String postageSwitchString = apiConfigApi.getConfigKey(SysConfigConstants.STORE_FEE_POSTAGE_SWITCH).toString();
|
|
|
|
|
// // 全场满额包邮金额
|
|
|
|
|
// String storeFreePostageString = apiConfigApi.getConfigKey(SysConfigConstants.STORE_FEE_POSTAGE).toString();
|
|
|
|
|
// BigDecimal storePostage = BigDecimal.ZERO;
|
|
|
|
|
// if (postageSwitchString.equals("true") && (storeFreePostageString.equals("0") || orderInfoVo.getProTotalFee().compareTo(new BigDecimal(storeFreePostageString)) >= 0)) {
|
|
|
|
|
// storePostage = BigDecimal.ZERO;
|
|
|
|
|
// } else if (ObjectUtil.isNull(userAddress) || userAddress.getCityId() <= 0) {
|
|
|
|
|
// // 用户地址不存在,默认运费为0元
|
|
|
|
|
// storePostage = BigDecimal.ZERO;
|
|
|
|
|
// } else {
|
|
|
|
|
// // 有用户地址的情况下
|
|
|
|
|
// // 运费根据商品计算
|
|
|
|
|
// Map<Integer, MyRecord> proMap = new HashMap<>();
|
|
|
|
|
// orderInfoVo.getOrderDetailList().forEach(e -> {
|
|
|
|
|
// Integer proId = e.getProductId();
|
|
|
|
|
// if (proMap.containsKey(proId)) {
|
|
|
|
|
// MyRecord record = proMap.get(proId);
|
|
|
|
|
// record.set("totalPrice", record.getBigDecimal("totalPrice").add(e.getPrice().multiply(BigDecimal.valueOf(e.getPayNum()))));
|
|
|
|
|
// record.set("totalNum", record.getInt("totalNum") + e.getPayNum());
|
|
|
|
|
// BigDecimal weight = e.getWeight().multiply(BigDecimal.valueOf(e.getPayNum()));
|
|
|
|
|
// record.set("weight", record.getBigDecimal("weight").add(weight));
|
|
|
|
|
// BigDecimal volume = e.getVolume().multiply(BigDecimal.valueOf(e.getPayNum()));
|
|
|
|
|
// record.set("volume", record.getBigDecimal("volume").add(volume));
|
|
|
|
|
// } else {
|
|
|
|
|
// MyRecord record = new MyRecord();
|
|
|
|
|
// record.set("totalPrice", e.getPrice().multiply(BigDecimal.valueOf(e.getPayNum())));
|
|
|
|
|
// record.set("totalNum", e.getPayNum());
|
|
|
|
|
// record.set("tempId", e.getTempId());
|
|
|
|
|
// record.set("proId", proId);
|
|
|
|
|
// BigDecimal weight = e.getWeight().multiply(BigDecimal.valueOf(e.getPayNum()));
|
|
|
|
|
// record.set("weight", weight);
|
|
|
|
|
// BigDecimal volume = e.getVolume().multiply(BigDecimal.valueOf(e.getPayNum()));
|
|
|
|
|
// record.set("volume", volume);
|
|
|
|
|
//
|
|
|
|
|
// proMap.put(proId, record);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// // 指定包邮(单品运费模板)> 指定区域配送(单品运费模板)
|
|
|
|
|
// int cityId = userAddress.getCityId();
|
|
|
|
|
//
|
|
|
|
|
// for (Map.Entry<Integer, MyRecord> m : proMap.entrySet()) {
|
|
|
|
|
// MyRecord value = m.getValue();
|
|
|
|
|
// Integer tempId = value.getInt("tempId");
|
|
|
|
|
// ShippingTemplatesDO shippingTemplatesDO = shippingTemplatesApi.getById(tempId);
|
|
|
|
|
// if (shippingTemplatesDO.getAppoint()) {// 指定包邮
|
|
|
|
|
// // 判断是否在指定包邮区域内
|
|
|
|
|
// // 必须满足件数 + 金额 才能包邮
|
|
|
|
|
// ShippingTemplatesFreeDO shippingTemplatesFree = shippingTemplatesFreeApi.getByTempIdAndCityId(tempId, cityId);
|
|
|
|
|
// if (ObjectUtil.isNotNull(shippingTemplatesFree)) { // 在包邮区域内
|
|
|
|
|
// BigDecimal freeNum = shippingTemplatesFree.getNumber();
|
|
|
|
|
// BigDecimal multiply = value.getBigDecimal("totalPrice");
|
|
|
|
|
// if (new BigDecimal(value.getInt("totalNum")).compareTo(freeNum) >= 0 && multiply.compareTo(shippingTemplatesFree.getPrice()) >= 0) {
|
|
|
|
|
// // 满足件数 + 金额 = 包邮
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// // 不满足指定包邮条件,走指定区域配送
|
|
|
|
|
// ShippingTemplatesRegionDO shippingTemplatesRegion = shippingTemplatesRegionApi.getByTempIdAndCityId(tempId, cityId);
|
|
|
|
|
// if (ObjectUtil.isNull(shippingTemplatesRegion)) {
|
|
|
|
|
// throw new ServiceException("计算运费时,未找到全国运费配置");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // 判断计费方式:件数、重量、体积
|
|
|
|
|
// switch (shippingTemplatesDO.getType()) {
|
|
|
|
|
// case 1: // 件数
|
|
|
|
|
// // 判断件数是否超过首件
|
|
|
|
|
// Integer num = value.getInt("totalNum");
|
|
|
|
|
// if (num <= shippingTemplatesRegion.getFirst().intValue()) {
|
|
|
|
|
// storePostage = storePostage.add(shippingTemplatesRegion.getFirstPrice());
|
|
|
|
|
// } else {// 超过首件的需要计算续件
|
|
|
|
|
// int renewalNum = num - shippingTemplatesRegion.getFirst().intValue();
|
|
|
|
|
// // 剩余件数/续件 = 需要计算的续件费用的次数
|
|
|
|
|
// BigDecimal divide = new BigDecimal(renewalNum).divide(shippingTemplatesRegion.getRenewal(), 0, BigDecimal.ROUND_UP);
|
|
|
|
|
// BigDecimal renewalPrice = shippingTemplatesRegion.getRenewalPrice().multiply(divide);
|
|
|
|
|
// storePostage = storePostage.add(shippingTemplatesRegion.getFirstPrice()).add(renewalPrice);
|
|
|
|
|
// }
|
|
|
|
|
// break;
|
|
|
|
|
// case 2: // 重量
|
|
|
|
|
// BigDecimal weight = value.getBigDecimal("weight");
|
|
|
|
|
// if (weight.compareTo(shippingTemplatesRegion.getFirst()) <= 0) {
|
|
|
|
|
// storePostage = storePostage.add(shippingTemplatesRegion.getFirstPrice());
|
|
|
|
|
// } else {// 超过首件的需要计算续件
|
|
|
|
|
// BigDecimal renewalNum = weight.subtract(shippingTemplatesRegion.getFirst());
|
|
|
|
|
// // 剩余件数/续件 = 需要计算的续件费用的次数
|
|
|
|
|
// BigDecimal divide = renewalNum.divide(shippingTemplatesRegion.getRenewal(), 0, BigDecimal.ROUND_UP);
|
|
|
|
|
// BigDecimal renewalPrice = shippingTemplatesRegion.getRenewalPrice().multiply(divide);
|
|
|
|
|
// storePostage = storePostage.add(shippingTemplatesRegion.getFirstPrice()).add(renewalPrice);
|
|
|
|
|
// }
|
|
|
|
|
// break;
|
|
|
|
|
// case 3: // 体积
|
|
|
|
|
// BigDecimal volume = value.getBigDecimal("volume");
|
|
|
|
|
// if (volume.compareTo(shippingTemplatesRegion.getFirst()) <= 0) {
|
|
|
|
|
// storePostage = storePostage.add(shippingTemplatesRegion.getFirstPrice());
|
|
|
|
|
// } else {// 超过首件的需要计算续件
|
|
|
|
|
// BigDecimal renewalNum = volume.subtract(shippingTemplatesRegion.getFirst());
|
|
|
|
|
// // 剩余件数/续件 = 需要计算的续件费用的次数
|
|
|
|
|
// BigDecimal divide = renewalNum.divide(shippingTemplatesRegion.getRenewal(), 0, BigDecimal.ROUND_UP);
|
|
|
|
|
// BigDecimal renewalPrice = shippingTemplatesRegion.getRenewalPrice().multiply(divide);
|
|
|
|
|
// storePostage = storePostage.add(shippingTemplatesRegion.getFirstPrice()).add(renewalPrice);
|
|
|
|
|
// }
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// orderInfoVo.setFreightFee(storePostage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|