| | |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final MallLeaderAchieveMapper mallLeaderAchieveMapper; |
| | | private final IApiMallTeamLeaderService iApiMallTeamLeaderService; |
| | | private final IMallElectronicFenceService iMallElectronicFenceService; |
| | | private final MallElectronicFenceMapper mallElectronicFenceMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createOrder(AddOrderDto addOrderDto) { |
| | | synchronized(this){ |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | String takeUniqueCode = addOrderDto.getTakeUniqueCode(); |
| | | if(StrUtil.isEmpty(takeUniqueCode)){ |
| | |
| | | MallTeamLeader mallTeamLeader = mallTeamLeaderMapper.selectLeaderByUniqueCode(takeUniqueCode); |
| | | if(ObjectUtil.isEmpty(mallTeamLeader)){ |
| | | throw new FebsException("请重新选择团长"); |
| | | } |
| | | |
| | | //订单范围内才允许下单 |
| | | MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId()); |
| | | MallElectronicFence mallElectronicFence = mallElectronicFenceMapper.selectByTeamLeaderCode(mallTeamLeader.getUniqueCode()); |
| | | if(ObjectUtil.isNotEmpty(mallElectronicFence)){ |
| | | String inStr = iMallElectronicFenceService.fenceToLocation(mallElectronicFence.getGKey(), |
| | | mallElectronicFence.getServiceId(), address.getLongitude() + "," + address.getLatitude(), mallElectronicFence.getGid()); |
| | | if("1".equals(inStr)){ |
| | | throw new FebsException("不在当前团长的配送范围内"); |
| | | } |
| | | } |
| | | |
| | | String orderNo = MallUtils.getOrderNum(); |
| | |
| | | BigDecimal total = BigDecimal.ZERO; |
| | | BigDecimal carriage = BigDecimal.ZERO; |
| | | for (AddOrderItemDto item : addOrderDto.getItems()) { |
| | | synchronized(this){ |
| | | MallOrderItem orderItem = new MallOrderItem(); |
| | | |
| | | // 积分商品提交订单 |
| | |
| | | throw new FebsException(mallGoods.getGoodsName() + "已下架"); |
| | | } |
| | | |
| | | mallGoods.setStock(mallGoods.getStock() - item.getCnt()); |
| | | mallGoods.setVolume(mallGoods.getVolume() + item.getCnt()); |
| | | mallGoodsMapper.updateById(mallGoods); |
| | | // mallGoods.setStock(mallGoods.getStock() - item.getCnt()); |
| | | // mallGoods.setVolume(mallGoods.getVolume() + item.getCnt()); |
| | | Integer goodsResult = mallGoodsMapper.upDateStockAndVolumeByGoodsId(mallGoods.getId(), item.getCnt()); |
| | | if(1 != goodsResult){ |
| | | throw new FebsException(mallGoods.getGoodsName() + "库存不足"); |
| | | } |
| | | |
| | | BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt())); |
| | | orderItem.setAmount(amount); |
| | |
| | | total = total.add(amount); |
| | | carriage = carriage.add(mallGoods.getCarriage()); |
| | | |
| | | sku.setStock(sku.getStock() - item.getCnt()); |
| | | sku.setSkuVolume(sku.getSkuVolume() + item.getCnt()); |
| | | mallGoodsSkuMapper.updateById(sku); |
| | | |
| | | // sku.setStock(sku.getStock() - item.getCnt()); |
| | | // sku.setSkuVolume(sku.getSkuVolume() + item.getCnt()); |
| | | // mallGoodsSkuMapper.updateById(sku); |
| | | Integer skuResult = mallGoodsSkuMapper.upDateStockAndVolumeBySkuId(sku.getId(),item.getCnt()); |
| | | if(1 != skuResult){ |
| | | throw new FebsException(sku.getSkuName() + "库存不足"); |
| | | } |
| | | if (addOrderDto.getType() == 1) { |
| | | mallShoppingCartMapper.delBySkuId(sku.getId(), member.getId()); |
| | | } |
| | | } |
| | | mallOrderItemMapper.insert(orderItem); |
| | | } |
| | | } |
| | | //配送费 |
| | | BigDecimal delivaryAmount = addOrderDto.getDeliveryAmount() == null ? BigDecimal.ZERO : addOrderDto.getDeliveryAmount(); |
| | |
| | | } |
| | | orderInfo.setAmount(total); |
| | | |
| | | MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId()); |
| | | orderInfo.setName(address.getName()); |
| | | orderInfo.setPhone(address.getPhone()); |
| | | orderInfo.setIsHome(addOrderDto.getIsHome()); |
| | |
| | | |
| | | agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(), 15 * 60 * 1000L); |
| | | return orderInfo.getId(); |
| | | } |
| | | } |
| | | |
| | | |