| | |
| | | import cc.mrbird.febs.mall.conversion.MallGoodsCommentConversion; |
| | | import cc.mrbird.febs.mall.conversion.MallOrderInfoConversion; |
| | | import cc.mrbird.febs.mall.conversion.MallOrderRefundConversion; |
| | | import cc.mrbird.febs.mall.conversion.MallTeamLeaderConversion; |
| | | import cc.mrbird.febs.mall.dto.*; |
| | | import cc.mrbird.febs.mall.entity.*; |
| | | import cc.mrbird.febs.mall.mapper.*; |
| | | import cc.mrbird.febs.mall.service.*; |
| | | import cc.mrbird.febs.mall.vo.ApiLeaderListVo; |
| | | import cc.mrbird.febs.mall.vo.OrderDetailVo; |
| | | import cc.mrbird.febs.mall.vo.OrderListVo; |
| | | import cc.mrbird.febs.mall.vo.OrderRefundVo; |
| | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | 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) { |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | String takeUniqueCode = addOrderDto.getTakeUniqueCode(); |
| | | if(StrUtil.isEmpty(takeUniqueCode)){ |
| | | throw new FebsException("请选择自提点"); |
| | | } |
| | | //验证用户的等级 |
| | | // if(AgentLevelEnum.ZERO_LEVEL.name().equals(member.getLevel())){ |
| | | // throw new FebsException("请先申请成为代理人"); |
| | | // } |
| | | |
| | | MallTeamLeader mallTeamLeader = mallTeamLeaderMapper.selectLeaderByUniqueCode(takeUniqueCode); |
| | | if(ObjectUtil.isEmpty(mallTeamLeader)){ |
| | | throw new FebsException("请重新选择团长"); |
| | | //订单范围内才允许下单 |
| | | MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId()); |
| | | if(ObjectUtil.isEmpty(address)){ |
| | | throw new FebsException("请重新选择收货地址信息"); |
| | | } |
| | | |
| | | String orderNo = MallUtils.getOrderNum(); |
| | |
| | | orderInfo.setStatus(OrderStatusEnum.WAIT_PAY.getValue()); |
| | | orderInfo.setRemark(addOrderDto.getRemark()); |
| | | orderInfo.setOrderType(addOrderDto.getOrderType()); |
| | | |
| | | orderInfo.setTakeUniqueCode(addOrderDto.getTakeUniqueCode()); |
| | | orderInfo.setDeliveryType(1); |
| | | |
| | | orderInfo.setDeliveryType(2); |
| | | if (CollUtil.isEmpty(addOrderDto.getItems())) { |
| | | throw new FebsException("参数错误"); |
| | | } |
| | | |
| | | this.baseMapper.insert(orderInfo); |
| | | |
| | | BigDecimal total = BigDecimal.ZERO; |
| | | BigDecimal carriage = BigDecimal.ZERO; |
| | | for (AddOrderItemDto item : addOrderDto.getItems()) { |
| | | MallOrderItem orderItem = new MallOrderItem(); |
| | | MallOrderItem orderItem = new MallOrderItem(); |
| | | |
| | | // 积分商品提交订单 |
| | | if (addOrderDto.getOrderType() == 2) { |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(item.getSkuId()); |
| | | if (mallGoods.getStock() < item.getCnt()) { |
| | | throw new FebsException(mallGoods.getGoodsName() + "库存不足"); |
| | | } |
| | | // 积分商品提交订单 |
| | | if (addOrderDto.getOrderType() == 2) { |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(item.getSkuId()); |
| | | if (mallGoods.getStock() < item.getCnt()) { |
| | | throw new FebsException(mallGoods.getGoodsName() + "库存不足"); |
| | | } |
| | | |
| | | if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) { |
| | | throw new FebsException(mallGoods.getGoodsName() + "已下架"); |
| | | } |
| | | if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) { |
| | | throw new FebsException(mallGoods.getGoodsName() + "已下架"); |
| | | } |
| | | |
| | | BigDecimal amount = mallGoods.getScore().multiply(BigDecimal.valueOf(item.getCnt())); |
| | | orderItem.setAmount(amount); |
| | | orderItem.setCnt(item.getCnt()); |
| | | orderItem.setOrderId(orderInfo.getId()); |
| | | orderItem.setPrice(mallGoods.getScore()); |
| | | orderItem.setGoodsId(mallGoods.getId()); |
| | | orderItem.setGoodsName(mallGoods.getGoodsName()); |
| | | orderItem.setStyleName(mallGoods.getGoodsName()); |
| | | orderItem.setSkuName(mallGoods.getGoodsName()); |
| | | orderItem.setSkuImage(mallGoods.getThumb()); |
| | | orderItem.setState(1); |
| | | BigDecimal amount = mallGoods.getScore().multiply(BigDecimal.valueOf(item.getCnt())); |
| | | orderItem.setAmount(amount); |
| | | orderItem.setCnt(item.getCnt()); |
| | | orderItem.setOrderId(orderInfo.getId()); |
| | | orderItem.setPrice(mallGoods.getScore()); |
| | | orderItem.setGoodsId(mallGoods.getId()); |
| | | orderItem.setGoodsName(mallGoods.getGoodsName()); |
| | | orderItem.setStyleName(mallGoods.getGoodsName()); |
| | | orderItem.setSkuName(mallGoods.getGoodsName()); |
| | | orderItem.setSkuImage(mallGoods.getThumb()); |
| | | orderItem.setState(1); |
| | | |
| | | total = total.add(amount); |
| | | } else { |
| | | MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId()); |
| | | if (sku == null) { |
| | | throw new FebsException("购买商品或sku不存在"); |
| | | } |
| | | total = total.add(amount); |
| | | } else { |
| | | MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId()); |
| | | if (sku == null) { |
| | | throw new FebsException("购买商品或sku不存在"); |
| | | } |
| | | |
| | | if (sku.getStock() < item.getCnt()) { |
| | | throw new FebsException(sku.getSkuName() + "库存不足"); |
| | | } |
| | | if("样品".equals(sku.getSample())){ |
| | | List<MallOrderItem> items = mallOrderItemMapper.selectItemBySkuIdUnCancel(sku.getId(), member.getId()); |
| | | if (CollUtil.isNotEmpty(items)) { |
| | | throw new FebsException("样品一个用户只能购买一次"); |
| | | } |
| | | Integer cnt = item.getCnt(); |
| | | if(1 < cnt){ |
| | | throw new FebsException("样品只能购买一件"); |
| | | } |
| | | |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId()); |
| | | } |
| | | |
| | | // 零撸专区购买 |
| | | if (new BigDecimal(mallGoods.getPresentPrice()).compareTo(BigDecimal.ZERO) == 0) { |
| | | List<MallOrderItem> items = mallOrderItemMapper.selectItemByGoodsIdUnCancel(mallGoods.getId(), member.getId()); |
| | | if (CollUtil.isNotEmpty(items)) { |
| | | throw new FebsException("无法重复领取同一个商品"); |
| | | if (sku.getStock() < item.getCnt()) { |
| | | throw new FebsException(sku.getSkuName() + "库存不足"); |
| | | } |
| | | |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId()); |
| | | // 零撸专区购买 |
| | | if (new BigDecimal(mallGoods.getPresentPrice()).compareTo(BigDecimal.ZERO) == 0) { |
| | | List<MallOrderItem> items = mallOrderItemMapper.selectItemByGoodsIdUnCancel(mallGoods.getId(), member.getId()); |
| | | if (CollUtil.isNotEmpty(items)) { |
| | | throw new FebsException("无法重复领取同一个商品"); |
| | | } |
| | | } |
| | | |
| | | if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) { |
| | | throw new FebsException(mallGoods.getGoodsName() + "已下架"); |
| | | } |
| | | //商品库存销量计算 |
| | | 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); |
| | | orderItem.setCnt(item.getCnt()); |
| | | orderItem.setOrderId(orderInfo.getId()); |
| | | orderItem.setPrice(sku.getPresentPrice()); |
| | | orderItem.setGoodsId(sku.getGoodsId()); |
| | | orderItem.setGoodsName(sku.getGoodsName()); |
| | | orderItem.setSkuId(sku.getId()); |
| | | orderItem.setState(1); |
| | | orderItem.setStyleName(sku.getStyleName()); |
| | | orderItem.setSkuName(sku.getSkuName()); |
| | | orderItem.setSkuImage(sku.getSkuImage()); |
| | | orderItem.setIsNormal(mallGoods.getIsNormal()); |
| | | orderItem.setCostPrice(sku.getCostPrice()); |
| | | |
| | | total = total.add(amount); |
| | | //规格的库存销量 |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | | if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) { |
| | | throw new FebsException(mallGoods.getGoodsName() + "已下架"); |
| | | } |
| | | |
| | | BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt())); |
| | | orderItem.setAmount(amount); |
| | | orderItem.setCnt(item.getCnt()); |
| | | orderItem.setOrderId(orderInfo.getId()); |
| | | orderItem.setPrice(sku.getPresentPrice()); |
| | | orderItem.setGoodsId(sku.getGoodsId()); |
| | | orderItem.setGoodsName(sku.getGoodsName()); |
| | | orderItem.setSkuId(sku.getId()); |
| | | orderItem.setState(1); |
| | | orderItem.setStyleName(sku.getStyleName()); |
| | | orderItem.setSkuName(sku.getSkuName()); |
| | | orderItem.setSkuImage(sku.getSkuImage()); |
| | | orderItem.setIsNormal(mallGoods.getIsNormal()); |
| | | orderItem.setCostPrice(sku.getCostPrice()); |
| | | |
| | | total = total.add(amount); |
| | | carriage = carriage.add(mallGoods.getCarriage()); |
| | | |
| | | sku.setStock(sku.getStock() - item.getCnt()); |
| | | sku.setSkuVolume(sku.getSkuVolume() + item.getCnt()); |
| | | mallGoodsSkuMapper.updateById(sku); |
| | | |
| | | if (addOrderDto.getType() == 1) { |
| | | mallShoppingCartMapper.delBySkuId(sku.getId(), member.getId()); |
| | | } |
| | | } |
| | | mallOrderItemMapper.insert(orderItem); |
| | | mallOrderItemMapper.insert(orderItem); |
| | | } |
| | | //配送费 |
| | | //运费 |
| | | BigDecimal delivaryAmount = addOrderDto.getDeliveryAmount() == null ? BigDecimal.ZERO : addOrderDto.getDeliveryAmount(); |
| | | if(BigDecimal.ZERO.compareTo(delivaryAmount) < 0 && 1 == addOrderDto.getIsHome()){ |
| | | total = total.add(delivaryAmount); |
| | | orderInfo.setCarriage(delivaryAmount); |
| | | } |
| | | orderInfo.setAmount(total); |
| | | orderInfo.setCarriage(delivaryAmount); |
| | | |
| | | MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId()); |
| | | total = total.add(delivaryAmount); |
| | | orderInfo.setAmount(total); |
| | | orderInfo.setAddressId(address.getId()); |
| | | orderInfo.setName(address.getName()); |
| | | orderInfo.setPhone(address.getPhone()); |
| | | orderInfo.setIsHome(addOrderDto.getIsHome()); |
| | | //订单金额大于50,且选择送货上门,订单需要选择地址信息 |
| | | if(1 == addOrderDto.getIsHome()){ |
| | | if (StrUtil.isBlank(address.getLatitude())||StrUtil.isBlank(address.getLongitude())) { |
| | | throw new FebsException("请添加地址"); |
| | | } |
| | | orderInfo.setAddress(address.getArea() + address.getAddress()); |
| | | orderInfo.setLatitude(address.getLatitude()); |
| | | orderInfo.setLongitude(address.getLongitude()); |
| | | |
| | | if (StrUtil.isBlank(address.getLatitude())||StrUtil.isBlank(address.getLongitude())) { |
| | | throw new FebsException("请添加地址"); |
| | | } |
| | | orderInfo.setAddress(address.getArea() + address.getAddress()); |
| | | orderInfo.setLatitude(address.getLatitude()); |
| | | orderInfo.setLongitude(address.getLongitude()); |
| | | this.baseMapper.updateById(orderInfo); |
| | | |
| | | agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(), 15 * 60 * 1000L); |
| | |
| | | orderInfo.setStatus(OrderStatusEnum.CANCEL.getValue()); |
| | | orderInfo.setCancelType(MallOrderInfo.CANCEL_BY_SELF); |
| | | this.baseMapper.updateById(orderInfo); |
| | | List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(id); |
| | | |
| | | |
| | | |
| | | List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfo.getId()); |
| | | if(CollUtil.isNotEmpty(mallOrderItemList)){ |
| | | for(MallOrderItem mallOrderItem : mallOrderItemList){ |
| | | Long goodsId = mallOrderItem.getGoodsId(); |
| | | Long skuId = mallOrderItem.getSkuId(); |
| | | Integer cnt = mallOrderItem.getCnt(); |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(goodsId); |
| | | mallGoods.setVolume(mallGoods.getVolume() - cnt); |
| | | mallGoods.setStock(mallGoods.getStock() + cnt); |
| | | mallGoodsMapper.updateById(mallGoods); |
| | | MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(mallOrderItem.getSkuId()); |
| | | if (sku == null) { |
| | | throw new FebsException("购买商品或sku不存在"); |
| | | } |
| | | |
| | | MallGoodsSku mallGoodsSku = mallGoodsSkuMapper.selectById(skuId); |
| | | mallGoodsSku.setSkuVolume(mallGoodsSku.getSkuVolume() - cnt); |
| | | mallGoodsSku.setStock(mallGoodsSku.getStock() + cnt); |
| | | mallGoodsSkuMapper.updateById(mallGoodsSku); |
| | | if (sku.getStock() < mallOrderItem.getCnt()) { |
| | | throw new FebsException(sku.getSkuName() + "库存不足"); |
| | | } |
| | | |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId()); |
| | | Integer goodsResult = mallGoodsMapper.updateStockAndVolumeByGoodsId(mallGoods.getId(), mallOrderItem.getCnt()); |
| | | if(1 != goodsResult){ |
| | | throw new FebsException(mallGoods.getGoodsName() + "库存不足"); |
| | | } |
| | | |
| | | Integer skuResult = mallGoodsSkuMapper.updateStockAndVolumeBySkuId(sku.getId(),mallOrderItem.getCnt()); |
| | | if(1 != skuResult){ |
| | | throw new FebsException(sku.getSkuName() + "库存不足"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | String wxResultStr = ""; |
| | | switch (payOrderDto.getType()) { |
| | | case "1": |
| | | // orderInfo.setPayOrderNo(payOrderDto.getPayOrderNo()); |
| | | // orderInfo.setPayImage(payOrderDto.getPayImage()); |
| | | BrandWCPayRequestData brandWCPayRequestData = null; |
| | | try { |
| | | brandWCPayRequestData = iXcxPayService.startPayment(orderInfo); |
| | |
| | | wxResultStr = JSONUtil.toJsonStr(brandWCPayRequestData); |
| | | payResultStr = brandWCPayRequestData.getPrepay_id(); |
| | | orderInfo.setPayMethod("微信支付"); |
| | | // agentProducer.sendOrderReturn(orderInfo.getId()); |
| | | break; |
| | | case "2": |
| | | if (StrUtil.isNotBlank(orderInfo.getPayOrderNo())) { |
| | |
| | | orderInfo.setPayResult("1"); |
| | | orderInfo.setDeliveryState(OrderDeliveryStateEnum.DELIVERY_WAIT.getValue()); |
| | | |
| | | // boolean hasTc = false; |
| | | // // 静态倍数 |
| | | // List<MallOrderItem> orderItems = this.baseMapper.getMallOrderItemByOrderId(orderInfo.getId()); |
| | | // if (CollUtil.isNotEmpty(orderItems)) { |
| | | // for (MallOrderItem orderItem : orderItems) { |
| | | // MallGoods mallGoods = mallGoodsMapper.selectById(orderItem.getGoodsId()); |
| | | // BigDecimal score = BigDecimal.ZERO; |
| | | // MallGoodsSku sku = mallGoodsSkuMapper.selectById(orderItem.getSkuId()); |
| | | // if (mallGoods.getIsNormal() == 2) { |
| | | // hasTc = true; |
| | | // score = sku.getPresentPrice().multiply(mallGoods.getStaticMulti()).multiply(new BigDecimal(orderItem.getCnt())); |
| | | //// BigDecimal staticMulti = mallGoods.getStaticMulti() == null ? BigDecimal.ZERO : mallGoods.getStaticMulti(); |
| | | //// score = sku.getPresentPrice().multiply(staticMulti); |
| | | // } |
| | | // |
| | | // if (score.compareTo(BigDecimal.ZERO) > 0) { |
| | | // memberWalletService.add(score, member.getId(), "score"); |
| | | // mallMoneyFlowService.addMoneyFlow(member.getId(), score, MoneyFlowTypeEnum.STATIC_BONUS.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue()); |
| | | // |
| | | // // 添加业绩 |
| | | // mallAchieveService.add(orderItem.getId()); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | // 购买套餐后,升级为普通会员 |
| | | // if (hasTc) { |
| | | // MallMember mallMember = memberMapper.selectById(member.getId()); |
| | | // if (AgentLevelEnum.ZERO_LEVEL.name().equals(mallMember.getLevel())) { |
| | | // mallMember.setLevel(AgentLevelEnum.FIRST_LEVEL.name()); |
| | | // memberMapper.updateById(mallMember); |
| | | // } |
| | | // } |
| | | |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue()); |
| | | // agentProducer.sendAutoLevelUpMsg(member.getId()); |
| | | // agentProducer.sendOrderReturn(orderInfo.getId()); |
| | | break; |
| | | case "4": |
| | | if (orderInfo.getOrderType() != 2) { |
| | |
| | | |
| | | @Override |
| | | public List<OrderListVo> findOrderList(OrderListDto orderListDto) { |
| | | log.info("订单查询"); |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | IPage<MallOrderInfo> page = new Page<>(orderListDto.getPageNum(), orderListDto.getPageSize()); |
| | | |
| | | orderListDto.setMemberId(member.getId()); |
| | | IPage<MallOrderInfo> mallOrderInfos = this.baseMapper.selectApiOrderListInPage(page, orderListDto); |
| | | // IPage<MallOrderInfo> mallOrderInfos = this.baseMapper.selectApiOrderListInPage(page, orderListDto); |
| | | IPage<MallOrderInfo> mallOrderInfos = this.baseMapper.selectNewApiOrderListInPage(page, orderListDto); |
| | | if (CollUtil.isNotEmpty(mallOrderInfos.getRecords())) { |
| | | mallOrderInfos.getRecords().forEach(item -> { |
| | | item.setItems(mallOrderItemMapper.selectListByOrderId(item.getId())); |
| | | }); |
| | | } |
| | | return MallOrderInfoConversion.INSTANCE.entitysToVos(mallOrderInfos.getRecords()); |
| | | } |
| | | |
| | |
| | | throw new FebsException("该状态不能确认收货"); |
| | | } |
| | | |
| | | if (orderInfo.getDeliveryState() != OrderDeliveryStateEnum.DELIVERY_FINISH.getValue()) { |
| | | throw new FebsException("还未送至自提点"); |
| | | } |
| | | // if (orderInfo.getDeliveryState() != OrderDeliveryStateEnum.DELIVERY_FINISH.getValue()) { |
| | | // throw new FebsException("还未送至自提点"); |
| | | // } |
| | | |
| | | List<MallRefundEntity> mallRefundEntities = mallRefundMapper.selectByItemIdAndOrderIdAndState(null, orderInfo.getId(), 3); |
| | | if(CollUtil.isNotEmpty(mallRefundEntities)){ |
| | |
| | | this.baseMapper.updateById(orderInfo); |
| | | |
| | | //生成一条团长提成记录 |
| | | Long orderInfoId = orderInfo.getId(); |
| | | List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfoId); |
| | | if(CollUtil.isNotEmpty(mallOrderItemList)){ |
| | | |
| | | MallTeamLeader mallTeamLeader = mallTeamLeaderMapper.selectLeaderByUniqueCode(orderInfo.getTakeUniqueCode()); |
| | | BigDecimal bonusPercent =new BigDecimal(mallTeamLeader.getBonusPercent()==null?"0":mallTeamLeader.getBonusPercent()); |
| | | // DataDictionaryCustom dicBonusPercent = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.BONUS_PERCENT.getType(), DataDictionaryEnum.BONUS_PERCENT.getCode()); |
| | | // BigDecimal bonusPercent = new BigDecimal(dicBonusPercent.getValue()).setScale(2,BigDecimal.ROUND_DOWN); |
| | | for(MallOrderItem mallOrderItem : mallOrderItemList){ |
| | | Integer state = mallOrderItem.getState() == null ? 1 : mallOrderItem.getState(); |
| | | if(1 == state){ |
| | | MallLeaderAchieve mallLeaderAchieve = new MallLeaderAchieve(); |
| | | mallLeaderAchieve.setMemberId(orderInfo.getMemberId()); |
| | | mallLeaderAchieve.setOrderNo(orderInfo.getOrderNo()); |
| | | mallLeaderAchieve.setOrderItemId(mallOrderItem.getId()); |
| | | BigDecimal itemAmount = mallOrderItem.getAmount(); |
| | | mallLeaderAchieve.setAmount(itemAmount); |
| | | BigDecimal bigDecimal = bonusPercent.multiply(itemAmount).setScale(2, BigDecimal.ROUND_DOWN); |
| | | mallLeaderAchieve.setProfitAmount(bigDecimal); |
| | | mallLeaderAchieve.setUniqueCode(orderInfo.getTakeUniqueCode()); |
| | | mallLeaderAchieve.setState(MallLeaderAchieve.STATE_ONE); |
| | | mallLeaderAchieveMapper.insert(mallLeaderAchieve); |
| | | } |
| | | } |
| | | } |
| | | // Long orderInfoId = orderInfo.getId(); |
| | | // List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfoId); |
| | | // if(CollUtil.isNotEmpty(mallOrderItemList)){ |
| | | // |
| | | // MallTeamLeader mallTeamLeader = mallTeamLeaderMapper.selectLeaderByUniqueCode(orderInfo.getTakeUniqueCode()); |
| | | // Integer profitSwitch = mallTeamLeader.getProfitSwitch()==null?2:mallTeamLeader.getProfitSwitch(); |
| | | // BigDecimal bonusPercent =new BigDecimal(mallTeamLeader.getBonusPercent()==null?"0":mallTeamLeader.getBonusPercent()); |
| | | // |
| | | // if(1 == profitSwitch){ |
| | | // for(MallOrderItem mallOrderItem : mallOrderItemList){ |
| | | // Integer state = mallOrderItem.getState() == null ? 1 : mallOrderItem.getState(); |
| | | // if(1 == state){ |
| | | // MallLeaderAchieve mallLeaderAchieve = new MallLeaderAchieve(); |
| | | // mallLeaderAchieve.setMemberId(orderInfo.getMemberId()); |
| | | // mallLeaderAchieve.setOrderNo(orderInfo.getOrderNo()); |
| | | // mallLeaderAchieve.setOrderItemId(mallOrderItem.getId()); |
| | | // BigDecimal itemAmount = mallOrderItem.getAmount(); |
| | | // mallLeaderAchieve.setAmount(itemAmount); |
| | | // BigDecimal bigDecimal = bonusPercent.multiply(itemAmount).setScale(2, BigDecimal.ROUND_DOWN); |
| | | // mallLeaderAchieve.setProfitAmount(bigDecimal); |
| | | // mallLeaderAchieve.setUniqueCode(orderInfo.getTakeUniqueCode()); |
| | | // mallLeaderAchieve.setState(MallLeaderAchieve.STATE_ONE); |
| | | // mallLeaderAchieveMapper.insert(mallLeaderAchieve); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | @Override |
| | |
| | | orderInfo.setStatus(OrderStatusEnum.CANCEL.getValue()); |
| | | orderInfo.setCancelType(MallOrderInfo.CANCEL_OVERTIME_NO_PAY); |
| | | this.baseMapper.updateById(orderInfo); |
| | | |
| | | List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfo.getId()); |
| | | if(CollUtil.isNotEmpty(mallOrderItemList)){ |
| | | for(MallOrderItem mallOrderItem : mallOrderItemList){ |
| | | MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(mallOrderItem.getSkuId()); |
| | | if (sku == null) { |
| | | throw new FebsException("购买商品或sku不存在"); |
| | | } |
| | | |
| | | // if (sku.getStock() < mallOrderItem.getCnt()) { |
| | | // throw new FebsException(sku.getSkuName() + "库存不足"); |
| | | // } |
| | | |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId()); |
| | | Integer goodsResult = mallGoodsMapper.updateStockAndVolumeByGoodsId(mallGoods.getId(), mallOrderItem.getCnt()); |
| | | if(1 != goodsResult){ |
| | | throw new FebsException(mallGoods.getGoodsName() + "库存不足"); |
| | | } |
| | | |
| | | Integer skuResult = mallGoodsSkuMapper.updateStockAndVolumeBySkuId(sku.getId(),mallOrderItem.getCnt()); |
| | | if(1 != skuResult){ |
| | | throw new FebsException(sku.getSkuName() + "库存不足"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | return new FebsResponse().success().message("已取消"); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse createOrderVerify(ApiCreateOrderVerifyDto apiCreateOrderVerifyDto) { |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | List<AddOrderItemDto> items = apiCreateOrderVerifyDto.getItems(); |
| | | if(CollUtil.isEmpty(items)){ |
| | | return new FebsResponse().fail().message("请先挑选商品"); |
| | | } |
| | | for (AddOrderItemDto item : apiCreateOrderVerifyDto.getItems()) { |
| | | MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId()); |
| | | if (sku == null) { |
| | | return new FebsResponse().fail().message("购买商品或sku不存在"); |
| | | } |
| | | if("样品".equals(sku.getSample())){ |
| | | List<MallOrderItem> mallOrderItems = mallOrderItemMapper.selectItemBySkuIdUnCancel(sku.getId(), member.getId()); |
| | | if (CollUtil.isNotEmpty(mallOrderItems)) { |
| | | return new FebsResponse().fail().message("样品只能购买一次"); |
| | | } |
| | | Integer cnt = item.getCnt(); |
| | | if(1 < cnt){ |
| | | return new FebsResponse().fail().message("样品只能购买一件"); |
| | | } |
| | | }else{ |
| | | //验证用户的等级 |
| | | if(AgentLevelEnum.ZERO_LEVEL.name().equals(member.getLevel())){ |
| | | return new FebsResponse().fail().message(sku.getSkuName() + "请先申请成为代理人"); |
| | | } |
| | | } |
| | | |
| | | if (sku.getStock() < item.getCnt()) { |
| | | return new FebsResponse().fail().message(sku.getSkuName() + "库存不足"); |
| | | } |
| | | |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId()); |
| | | if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) { |
| | | return new FebsResponse().fail().message(mallGoods.getGoodsName() + "已下架"); |
| | | } |
| | | } |
| | | |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | } |