use of cn.lili.modules.store.entity.dos.FreightTemplateChild in project lilishop by lilishop.
the class FreightTemplateServiceImpl method editFreightTemplate.
@Override
@Transactional(rollbackFor = Exception.class)
public FreightTemplateVO editFreightTemplate(FreightTemplateVO freightTemplateVO) {
// 获取当前登录商家账号
AuthUser tokenUser = UserContext.getCurrentUser();
if (freightTemplateVO.getId().equals(tokenUser.getStoreId())) {
throw new ServiceException(ResultCode.USER_AUTHORITY_ERROR);
}
FreightTemplate freightTemplate = new FreightTemplate();
// 复制属性
BeanUtils.copyProperties(freightTemplateVO, freightTemplate);
// 修改运费模板
this.updateById(freightTemplate);
// 删除模板子内容
freightTemplateChildService.removeFreightTemplate(freightTemplateVO.getId());
// 给子模板赋父模板的id
List<FreightTemplateChild> list = new ArrayList<>();
for (FreightTemplateChild freightTemplateChild : freightTemplateVO.getFreightTemplateChildList()) {
freightTemplateChild.setFreightTemplateId(freightTemplate.getId());
list.add(freightTemplateChild);
}
// 添加模板子内容
freightTemplateChildService.addFreightTemplateChild(list);
// 更新缓存
cache.remove(CachePrefix.SHIP_TEMPLATE.getPrefix() + tokenUser.getStoreId());
return null;
}
use of cn.lili.modules.store.entity.dos.FreightTemplateChild in project lilishop by lilishop.
the class FreightTemplateServiceImpl method addFreightTemplate.
@Override
public FreightTemplateVO addFreightTemplate(FreightTemplateVO freightTemplateVO) {
// 获取当前登录商家账号
AuthUser tokenUser = UserContext.getCurrentUser();
FreightTemplate freightTemplate = new FreightTemplate();
// 设置店铺ID
freightTemplateVO.setStoreId(tokenUser.getStoreId());
// 复制属性
BeanUtils.copyProperties(freightTemplateVO, freightTemplate);
// 添加运费模板
this.save(freightTemplate);
// 给子模板赋父模板的id
List<FreightTemplateChild> list = new ArrayList<>();
// 如果子运费模板不为空则进行新增
if (freightTemplateVO.getFreightTemplateChildList() != null) {
for (FreightTemplateChild freightTemplateChild : freightTemplateVO.getFreightTemplateChildList()) {
freightTemplateChild.setFreightTemplateId(freightTemplate.getId());
list.add(freightTemplateChild);
}
// 添加运费模板子内容
freightTemplateChildService.addFreightTemplateChild(list);
}
// 更新缓存
cache.remove(CachePrefix.SHIP_TEMPLATE.getPrefix() + tokenUser.getStoreId());
return freightTemplateVO;
}
use of cn.lili.modules.store.entity.dos.FreightTemplateChild in project lilishop by lilishop.
the class FreightTemplateServiceImpl method getFreightTemplateList.
@Override
public List<FreightTemplateVO> getFreightTemplateList(String storeId) {
// 先从缓存中获取运费模板,如果有则直接返回,如果没有则查询数据后再返回
List<FreightTemplateVO> list = (List<FreightTemplateVO>) cache.get(CachePrefix.SHIP_TEMPLATE.getPrefix() + storeId);
if (list != null) {
return list;
}
list = new ArrayList<>();
// 查询运费模板
LambdaQueryWrapper<FreightTemplate> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(FreightTemplate::getStoreId, storeId);
List<FreightTemplate> freightTemplates = this.baseMapper.selectList(lambdaQueryWrapper);
if (!freightTemplates.isEmpty()) {
// 如果模板不为空则查询子模板信息
for (FreightTemplate freightTemplate : freightTemplates) {
FreightTemplateVO freightTemplateVO = new FreightTemplateVO();
BeanUtil.copyProperties(freightTemplate, freightTemplateVO);
List<FreightTemplateChild> freightTemplateChildren = freightTemplateChildService.getFreightTemplateChild(freightTemplate.getId());
if (!freightTemplateChildren.isEmpty()) {
freightTemplateVO.setFreightTemplateChildList(freightTemplateChildren);
}
list.add(freightTemplateVO);
}
}
cache.put(CachePrefix.SHIP_TEMPLATE.getPrefix() + storeId, list);
return list;
}
use of cn.lili.modules.store.entity.dos.FreightTemplateChild in project lilishop by lilishop.
the class FreightTemplateServiceImpl method getFreightTemplate.
@Override
public FreightTemplateVO getFreightTemplate(String id) {
FreightTemplateVO freightTemplateVO = new FreightTemplateVO();
// 获取运费模板
FreightTemplate freightTemplate = this.getById(id);
if (freightTemplate != null) {
// 复制属性
BeanUtils.copyProperties(freightTemplate, freightTemplateVO);
// 填写运费模板子内容
List<FreightTemplateChild> freightTemplateChildList = freightTemplateChildService.getFreightTemplateChild(id);
freightTemplateVO.setFreightTemplateChildList(freightTemplateChildList);
}
return freightTemplateVO;
}
use of cn.lili.modules.store.entity.dos.FreightTemplateChild in project lilishop by lilishop.
the class SkuFreightRender method render.
@Override
public void render(TradeDTO tradeDTO) {
List<CartSkuVO> cartSkuVOS = tradeDTO.getCheckedSkuList();
// 会员收货地址问题处理
MemberAddress memberAddress = tradeDTO.getMemberAddress();
// 如果收货地址为空,则抛出异常
if (memberAddress == null) {
return;
}
// 循环渲染购物车商品运费价格
forSku: for (CartSkuVO cartSkuVO : cartSkuVOS) {
// 获取sku运费模版
String freightTemplateId = cartSkuVO.getGoodsSku().getFreightTemplateId();
// 免运费则跳出运费计算
if (Boolean.TRUE.equals(cartSkuVO.getIsFreeFreight()) || freightTemplateId == null) {
continue;
}
// 寻找对应对商品运费计算模版
FreightTemplateVO freightTemplate = freightTemplateService.getFreightTemplate(freightTemplateId);
if (freightTemplate != null && freightTemplate.getFreightTemplateChildList() != null && !freightTemplate.getFreightTemplateChildList().isEmpty()) {
// 店铺支付运费则跳过
if (freightTemplate.getPricingMethod().equals(FreightTemplateEnum.FREE.name())) {
break;
}
FreightTemplateChild freightTemplateChild = null;
// 获取市级别id
String addressId = memberAddress.getConsigneeAddressIdPath().split(",")[1];
// 获取匹配的收货地址
for (FreightTemplateChild templateChild : freightTemplate.getFreightTemplateChildList()) {
// 如果当前模版包含,则返回
if (templateChild.getAreaId().contains(addressId)) {
freightTemplateChild = templateChild;
break;
}
}
// 如果没有匹配到物流规则,则说明不支持配送
if (freightTemplateChild == null) {
if (tradeDTO.getNotSupportFreight() == null) {
tradeDTO.setNotSupportFreight(new ArrayList<>());
}
tradeDTO.getNotSupportFreight().add(cartSkuVO);
continue forSku;
}
// 物流规则模型创立
FreightTemplateChildDTO freightTemplateChildDTO = new FreightTemplateChildDTO(freightTemplateChild);
freightTemplateChildDTO.setPricingMethod(freightTemplate.getPricingMethod());
// 要计算的基数 数量/重量
Double count = (freightTemplateChildDTO.getPricingMethod().equals(FreightTemplateEnum.NUM.name())) ? cartSkuVO.getNum() : cartSkuVO.getGoodsSku().getWeight() * cartSkuVO.getNum();
// 计算运费
Double countFreight = countFreight(count, freightTemplateChildDTO);
// 写入SKU运费
cartSkuVO.getPriceDetailDTO().setFreightPrice(countFreight);
}
}
}
Aggregations