| | |
| | | private final IApiMallTeamLeaderService iApiMallTeamLeaderService; |
| | | private final IMallElectronicFenceService iMallElectronicFenceService; |
| | | private final MallElectronicFenceMapper mallElectronicFenceMapper; |
| | | private final MallMemberWalletMapper mallMemberWalletMapper; |
| | | private final MallRollPerkMapper mallRollPerkMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long createOrder(AddOrderDto addOrderDto) { |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | //验证用户的等级 |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | MallMember member = mallMemberMapper.selectById(memberId); |
| | | MallMemberWallet memberWallet = mallMemberWalletMapper.selectWalletByMemberId(memberId); |
| | | |
| | | //验证用户的等级 |
| | | // if(AgentLevelEnum.ZERO_LEVEL.name().equals(member.getLevel())){ |
| | | // throw new FebsException("请先申请成为代理人"); |
| | | // } |
| | | |
| | | //订单范围内才允许下单 |
| | | //验证收货地址 |
| | | MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId()); |
| | | if(ObjectUtil.isEmpty(address)){ |
| | | throw new FebsException("请重新选择收货地址信息"); |
| | |
| | | |
| | | BigDecimal total = BigDecimal.ZERO; |
| | | for (AddOrderItemDto item : addOrderDto.getItems()) { |
| | | MallOrderItem orderItem = new MallOrderItem(); |
| | | MallOrderItem orderItem = new MallOrderItem(); |
| | | MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId()); |
| | | if (ObjectUtil.isEmpty(sku)) { |
| | | throw new FebsException("购买商品或sku不存在"); |
| | | } |
| | | |
| | | // 积分商品提交订单 |
| | | 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() + "已下架"); |
| | | } |
| | | |
| | | 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不存在"); |
| | | } |
| | | |
| | | 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("样品只能购买一件"); |
| | | } |
| | | |
| | | } |
| | | |
| | | 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 (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("无法重复领取同一个商品"); |
| | | } |
| | | mallOrderItemMapper.insert(orderItem); |
| | | } |
| | | |
| | | 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())); |
| | | BigDecimal itemPrice = sku.getPresentPrice(); |
| | | orderItem.setAmount(amount); |
| | | orderItem.setCnt(item.getCnt()); |
| | | orderItem.setOrderId(orderInfo.getId()); |
| | | orderItem.setPrice(itemPrice); |
| | | 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()); |
| | | } |
| | | mallOrderItemMapper.insert(orderItem); |
| | | } |
| | | //运费 |
| | | BigDecimal delivaryAmount = addOrderDto.getDeliveryAmount() == null ? BigDecimal.ZERO : addOrderDto.getDeliveryAmount(); |
| | |
| | | orderInfo.setPhone(address.getPhone()); |
| | | orderInfo.setIsHome(addOrderDto.getIsHome()); |
| | | |
| | | if (StrUtil.isBlank(address.getLatitude())||StrUtil.isBlank(address.getLongitude())) { |
| | | throw new FebsException("请添加地址"); |
| | | } |
| | | // if (StrUtil.isBlank(address.getLatitude())||StrUtil.isBlank(address.getLongitude())) { |
| | | // throw new FebsException("请添加地址"); |
| | | // } |
| | | orderInfo.setAddress(address.getProvince()+address.getCity()+address.getArea() + address.getAddress()); |
| | | orderInfo.setLatitude(address.getLatitude()); |
| | | orderInfo.setLongitude(address.getLongitude()); |
| | | this.baseMapper.updateById(orderInfo); |
| | | |
| | | agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(), 15 * 60 * 1000L); |
| | | //过期时间修改成24小时 |
| | | agentProducer.sendOrderCancelDelayMsg(orderInfo.getId(), 24 * 60 * 60 * 1000L); |
| | | return orderInfo.getId(); |
| | | } |
| | | |
| | |
| | | |
| | | String payResultStr = ""; |
| | | String wxResultStr = ""; |
| | | String amountActualMsg = "0"; |
| | | switch (payOrderDto.getType()) { |
| | | case "1": |
| | | BrandWCPayRequestData brandWCPayRequestData = null; |
| | |
| | | wxResultStr = JSONUtil.toJsonStr(brandWCPayRequestData); |
| | | payResultStr = brandWCPayRequestData.getPrepay_id(); |
| | | orderInfo.setPayMethod("微信支付"); |
| | | amountActualMsg = orderInfo.getAmount().toString(); |
| | | break; |
| | | case "2": |
| | | if (StrUtil.isNotBlank(orderInfo.getPayOrderNo())) { |
| | | payResultStr = orderInfo.getPayOrderNo(); |
| | | } else { |
| | | payResultStr = payService.aliPay(orderInfo); |
| | | } |
| | | |
| | | orderInfo.setPayOrderNo(payResultStr); |
| | | orderInfo.setPayMethod("支付宝支付"); |
| | | agentProducer.sendOrderReturn(orderInfo.getId()); |
| | | break; |
| | | case "3": |
| | | payResultStr = balancePay(orderInfo, payOrderDto.getTradePwd(), "balance"); |
| | | |
| | | orderInfo.setPayOrderNo(orderInfo.getOrderNo()); |
| | |
| | | orderInfo.setPayResult("1"); |
| | | orderInfo.setDeliveryState(OrderDeliveryStateEnum.DELIVERY_WAIT.getValue()); |
| | | |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue()); |
| | | break; |
| | | case "4": |
| | | if (orderInfo.getOrderType() != 2) { |
| | | throw new FebsException("非积分订单,无法使用积分支付"); |
| | | } |
| | | payResultStr = balancePay(orderInfo, payOrderDto.getTradePwd(), "prizeScore"); |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), |
| | | orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue(),"余额支付",2); |
| | | |
| | | amountActualMsg = orderInfo.getAmount().toString(); |
| | | break; |
| | | case "3": |
| | | /** |
| | | * 获取用户的当前积分 |
| | | */ |
| | | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(member.getId()); |
| | | BigDecimal score = mallMemberWallet.getScore(); |
| | | BigDecimal amount = orderInfo.getAmount(); |
| | | //积分兑换比例 |
| | | DataDictionaryCustom scoreChangeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.SCORE_CHANGE.getType(), |
| | | DataDictionaryEnum.SCORE_CHANGE.getCode() |
| | | ); |
| | | BigDecimal scoreChange = StrUtil.isEmpty(scoreChangeDic.getValue()) ? new BigDecimal("1") : new BigDecimal(scoreChangeDic.getValue()); |
| | | BigDecimal amountToScore = amount.multiply(scoreChange).setScale(0, BigDecimal.ROUND_DOWN); |
| | | //实际支付积分 |
| | | BigDecimal scoreActual = BigDecimal.ZERO; |
| | | if(score.compareTo(amountToScore) >= 0){ |
| | | //拥有的积分大于此次订单的金额,则全额订单折扣 |
| | | int reduce = memberWalletService.reduce(amountToScore, member.getId(), "score"); |
| | | if (reduce == 2) { |
| | | throw new FebsException("积分余额不足"); |
| | | } |
| | | orderInfo.setPayMethod("积分支付"); |
| | | scoreActual = amountToScore; |
| | | }else{ |
| | | //拥有的积分大于此次订单的金额,则全额订单折扣 |
| | | int reduce = memberWalletService.reduce(score, member.getId(), "score"); |
| | | if (reduce == 2) { |
| | | throw new FebsException("积分余额不足"); |
| | | } |
| | | scoreActual = score; |
| | | } |
| | | |
| | | BigDecimal scoreToAmount = score.divide(scoreChange, 2, BigDecimal.ROUND_DOWN); |
| | | //实际支付余额 |
| | | BigDecimal amountActual = amount.subtract(scoreToAmount).setScale(2, BigDecimal.ROUND_DOWN); |
| | | int balance = memberWalletService.reduce(amountActual, member.getId(), "balance"); |
| | | if (balance == 2) { |
| | | throw new FebsException("余额不足"); |
| | | } |
| | | orderInfo.setPayOrderNo(orderInfo.getOrderNo()); |
| | | orderInfo.setPayMethod("积分支付"); |
| | | orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue()); |
| | | orderInfo.setPayTime(new Date()); |
| | | orderInfo.setPayResult("1"); |
| | | orderInfo.setDeliveryState(OrderDeliveryStateEnum.DELIVERY_WAIT.getValue()); |
| | | if(amountActual.compareTo(BigDecimal.ZERO) > 0){ |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), amountActual.negate(), MoneyFlowTypeEnum.PAY.getValue(), |
| | | orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue(),"余额支付",2); |
| | | amountActualMsg = amountActual.toString(); |
| | | } |
| | | if(scoreActual.compareTo(BigDecimal.ZERO) > 0){ |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), scoreActual.negate(), |
| | | MoneyFlowTypeEnum.SCORE_PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.SCORE.getValue(),"积分支付",2); |
| | | } |
| | | break; |
| | | case "4": |
| | | MallRollPerk mallRollPerk = mallRollPerkMapper.selectById(payOrderDto.getRollId()); |
| | | if(ObjectUtil.isEmpty(mallRollPerk)){ |
| | | throw new FebsException("兑换券不存在"); |
| | | } |
| | | int stateRoll = ObjectUtil.isEmpty(mallRollPerk.getState()) ? 2 : mallRollPerk.getState(); |
| | | if(stateRoll == 2){ |
| | | throw new FebsException("兑换券已使用"); |
| | | } |
| | | mallRollPerk.setState(2); |
| | | mallRollPerkMapper.updateById(mallRollPerk); |
| | | payResultStr = orderInfo.getOrderNo(); |
| | | |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.PRIZE_SCORE.getValue()); |
| | | orderInfo.setPayOrderNo(payOrderDto.getRollId().toString()); |
| | | orderInfo.setPayMethod("兑换券支付"); |
| | | orderInfo.setPayTime(new Date()); |
| | | orderInfo.setPayResult("1"); |
| | | |
| | | mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.ROLL_PAY.getValue(), |
| | | orderInfo.getOrderNo(), FlowTypeEnum.PRIZE_SCORE.getValue()); |
| | | break; |
| | | default: |
| | | |
| | | } |
| | | if(ObjectUtil.isNotEmpty(payOrderDto.getUseTime())){ |
| | | orderInfo.setUseTime(payOrderDto.getUseTime()); |
| | | } |
| | | |
| | | //订单支付成功产生一个提货码 |
| | | String takeCode = ShareCodeUtil.toSerialCode(orderInfo.getId()); |
| | | orderInfo.setTakeCode(takeCode); |
| | | |
| | | this.baseMapper.updateById(orderInfo); |
| | | |
| | | |
| | | StringBuffer stringBuffer = new StringBuffer(); |
| | | stringBuffer.append(orderInfo.getId().toString()); |
| | | stringBuffer.append("@"); |
| | | stringBuffer.append(amountActualMsg); |
| | | agentProducer.sendOrderGetMsg(stringBuffer.toString()); |
| | | if("4".equals(payOrderDto.getType())){ |
| | | agentProducer.sendRollSendMsg(orderInfo.getId()); |
| | | } |
| | | |
| | | // OrderStateDto orderStateDto = new OrderStateDto(); |
| | | // orderStateDto.setOrderNo(orderInfo.getOrderNo()); |
| | |
| | | |
| | | OrderDetailVo orderDetailVo = MallOrderInfoConversion.INSTANCE.entityToDetailVo(orderInfo); |
| | | |
| | | // if (orderInfo.getStatus() == OrderStatusEnum.WAIT_FINISH.getValue()) { |
| | | // MallExpressInfo expressInfo = expressInfoMapper.selectByOrderId(orderInfo.getId()); |
| | | // orderDetailVo.setExpressNo(expressInfo.getExpressNo()); |
| | | // orderDetailVo.setExpressCom(expressInfo.getExpressCom()); |
| | | // } |
| | | MallExpressInfo expressInfo = expressInfoMapper.selectByOrderId(orderInfo.getId()); |
| | | if(ObjectUtil.isNotEmpty(expressInfo)){ |
| | | orderDetailVo.setExpressNo(expressInfo.getExpressNo()); |
| | | orderDetailVo.setExpressCom(expressInfo.getExpressCom()); |
| | | } |
| | | |
| | | if (orderInfo.getStatus() == OrderStatusEnum.REFUNDING.getValue() || orderInfo.getStatus() == OrderStatusEnum.REFUNDED.getValue()) { |
| | | MallOrderRefund orderRefund = mallOrderRefundMapper.selectOrderRefundByOrderId(orderInfo.getId()); |
| | |
| | | } |
| | | |
| | | if (OrderStatusEnum.WAIT_PAY.getValue() == orderInfo.getStatus()) { |
| | | Date endTime = DateUtil.offsetMinute(orderInfo.getOrderTime(), 15); |
| | | Date endTime = DateUtil.offsetMinute(orderInfo.getOrderTime(), 1440); |
| | | |
| | | long remainTime = DateUtil.between(new Date(), endTime, DateUnit.SECOND, false); |
| | | orderDetailVo.setRemainTime(remainTime); |
| | |
| | | |
| | | @Override |
| | | public FebsResponse createOrderVerify(ApiCreateOrderVerifyDto apiCreateOrderVerifyDto) { |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | MallMember member = memberMapper.selectById(memberId); |
| | | List<AddOrderItemDto> items = apiCreateOrderVerifyDto.getItems(); |
| | | if(CollUtil.isEmpty(items)){ |
| | | return new FebsResponse().fail().message("请先挑选商品"); |
| | |
| | | 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("请先申请成为代理人"); |
| | | } |
| | | } |
| | | // 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("请先申请成为合伙人"); |
| | | // } |
| | | // } |
| | | |
| | | if (sku.getStock() < item.getCnt()) { |
| | | return new FebsResponse().fail().message(sku.getSkuName() + "库存不足"); |