商品管理

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

View File

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