| | |
| | | private final IApiMallTeamLeaderService iApiMallTeamLeaderService; |
| | | private final IMallElectronicFenceService iMallElectronicFenceService; |
| | | private final MallElectronicFenceMapper mallElectronicFenceMapper; |
| | | private final MallMemberWalletMapper mallMemberWalletMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | |
| | | //订单范围内才允许下单 |
| | | MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId()); |
| | | if(ObjectUtil.isEmpty(address)){ |
| | | throw new FebsException("请重新选择提货人信息"); |
| | | } |
| | | // MallElectronicFence mallElectronicFence = mallElectronicFenceMapper.selectByTeamLeaderCode(mallTeamLeader.getUniqueCode()); |
| | | // if(ObjectUtil.isNotEmpty(mallElectronicFence)){ |
| | | // String inStr = iMallElectronicFenceService.fenceToLocation(mallElectronicFence.getGKey(), |
| | |
| | | orderInfo.setCarriage(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(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()); |
| | | } |
| | | // } |
| | | 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() + "库存不足"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | throw new FebsException("订单状态不能支付"); |
| | | } |
| | | |
| | | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(member.getId()); |
| | | if (ObjectUtil.isEmpty(mallMemberWallet)) { |
| | | throw new FebsException("用户钱包不存在。"); |
| | | } |
| | | |
| | | String payResultStr = ""; |
| | | String wxResultStr = ""; |
| | | switch (payOrderDto.getType()) { |
| | |
| | | agentProducer.sendOrderReturn(orderInfo.getId()); |
| | | break; |
| | | case "3": |
| | | payResultStr = balancePay(orderInfo, payOrderDto.getTradePwd(), "balance"); |
| | | BigDecimal score = mallMemberWallet.getScore();//积分 |
| | | BigDecimal balance = mallMemberWallet.getBalance();//余额 |
| | | |
| | | //这里将运费定义成折扣总金额 |
| | | /** |
| | | * 积分 + 余额 1:1来折扣支付金额 |
| | | */ |
| | | BigDecimal total = orderInfo.getAmount(); |
| | | BigDecimal totalCarriage = BigDecimal.ZERO;//总折扣金额 |
| | | BigDecimal memberAmount = score.add(balance);//用户积分加余额总数 |
| | | if(memberAmount.compareTo(BigDecimal.ZERO) > 0){ |
| | | //折扣金额 |
| | | if(total.compareTo(memberAmount) >= 0){ |
| | | totalCarriage = memberAmount; |
| | | }else{ |
| | | totalCarriage = total; |
| | | } |
| | | //减少用户积分和余额 |
| | | |
| | | BigDecimal avaAmount = totalCarriage;//剩余需要折扣的金额 |
| | | if(avaAmount.compareTo(memberAmount) >= 0){ |
| | | //清零用户的积分和余额 |
| | | mallMemberWallet.setBalance(BigDecimal.ZERO); |
| | | mallMemberWallet.setScore(BigDecimal.ZERO); |
| | | mallMemberWalletMapper.updateBalanceScoreWithId(mallMemberWallet); |
| | | }else{ |
| | | /** |
| | | * 先扣积分,再扣余额 |
| | | */ |
| | | if(avaAmount.compareTo(score) >= 0){ |
| | | mallMemberWallet.setScore(BigDecimal.ZERO); |
| | | avaAmount = avaAmount.subtract(score); |
| | | }else{ |
| | | mallMemberWallet.setScore(score.subtract(avaAmount)); |
| | | avaAmount = BigDecimal.ZERO; |
| | | } |
| | | //积分不够 |
| | | if(avaAmount.compareTo(BigDecimal.ZERO) > 0){ |
| | | mallMemberWallet.setBalance(balance.subtract(avaAmount)); |
| | | }else{ |
| | | mallMemberWallet.setBalance(balance); |
| | | } |
| | | mallMemberWalletMapper.updateBalanceScoreWithId(mallMemberWallet); |
| | | } |
| | | } |
| | | orderInfo.setCarriage(totalCarriage); |
| | | payResultStr = "支付成功"; |
| | | // payResultStr = balancePay(orderInfo, payOrderDto.getTradePwd(), "balance"); |
| | | |
| | | orderInfo.setPayOrderNo(orderInfo.getOrderNo()); |
| | | orderInfo.setPayMethod("余额支付"); |
| | | orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue()); |
| | | orderInfo.setStatus(OrderStatusEnum.FINISH.getValue()); |
| | | // orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue()); |
| | | orderInfo.setPayTime(new Date()); |
| | | orderInfo.setPayResult("1"); |
| | | orderInfo.setDeliveryState(OrderDeliveryStateEnum.DELIVERY_WAIT.getValue()); |
| | | orderInfo.setPayResult(1); |
| | | orderInfo.setDeliveryState(OrderDeliveryStateEnum.DELIVERY_FINISH.getValue()); |
| | | // orderInfo.setDeliveryState(OrderDeliveryStateEnum.DELIVERY_WAIT.getValue()); |
| | | |
| | | // boolean hasTc = false; |
| | | // // 静态倍数 |
| | |
| | | orderInfo.setPayMethod("积分支付"); |
| | | orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue()); |
| | | orderInfo.setPayTime(new Date()); |
| | | orderInfo.setPayResult("1"); |
| | | orderInfo.setPayResult(1); |
| | | |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.PRIZE_SCORE.getValue()); |
| | | break; |
| | |
| | | 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()); |
| | | } |
| | | |
| | |
| | | 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() + "库存不足"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |