商品管理

pull/2/head
perry 2023-05-15 09:56:07 +08:00
parent 69da62ea38
commit 4e350e2767
5 changed files with 122 additions and 140 deletions

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.shop.service.order;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.shop.controller.admin.order.vo.StoreOrderPageQueryReqVo;
import cn.iocoder.yudao.module.shop.dal.dataobject.order.StoreOrder;
import cn.iocoder.yudao.module.shop.request.order.*;
import cn.iocoder.yudao.module.shop.request.product.StoreProductReplyAddRequest;

View File

@ -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,18 +112,16 @@ 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);
}
/**

View File

@ -29,8 +29,6 @@ public class AddressApiImpl implements AddressApi {
@Resource
private AddressMapper addressMapper;
@Autowired
private AddressConvert addressConvert;
@Override
public AddressRespDTO getAddress(Long id, Long userId) {
@ -41,8 +39,7 @@ public class AddressApiImpl implements AddressApi {
public AddressRespDTO getById(Integer addressId) {
LambdaQueryWrapper<AddressDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(AddressDO::getId, addressId);
lambdaQueryWrapper.eq(AddressDO::getIsDel, false);
return addressConvert.convert02(addressMapper.selectOne(lambdaQueryWrapper));
return AddressConvert.INSTANCE.convert02(addressMapper.selectOne(lambdaQueryWrapper));
}
/**
@ -54,7 +51,7 @@ public class AddressApiImpl implements AddressApi {
LambdaQueryWrapper<AddressDO> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(AddressDO::getDefaulted, true);
lambdaQueryWrapper.eq(AddressDO::getId, uid);
return addressConvert.convert02(addressMapper.selectOne(lambdaQueryWrapper));
return AddressConvert.INSTANCE.convert02(addressMapper.selectOne(lambdaQueryWrapper));
}

View File

@ -89,7 +89,7 @@ public class MemberUserApiImpl implements MemberUserApi {
if (getUserId() == 0L) {
return null;
}
return UserConvert.INSTANCE.convert2(userService.getById(getUserId()));
return UserConvert.INSTANCE.convert2(userService.getUser(getUserId()));
}
/**

View File

@ -56,10 +56,5 @@ public class AddressDO extends BaseDO {
*/
private Boolean defaulted;
/**
*
*/
@TableLogic
private Boolean isDel;
}