| | |
| | | import cn.lili.trigger.util.DelayQueueTools; |
| | | import cn.lili.utils.COSUtil; |
| | | import cn.lili.utils.CommonUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | private RedisTemplate<Object,Object> redisTemplate; |
| | | |
| | | private final static String LOCK_ORDER_NO_MQ="lock_order_no_mq:"; |
| | | private final static String LOCK_EDIT_ORDER_ADDRESS="lock_edit_order_address:"; |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void intoDB(TradeDTO tradeDTO) { |
| | |
| | | //查询订单和自订单,然后写入vo返回 |
| | | return new OrderDetailVO(order, orderItems, orderLogs, receipt); |
| | | } |
| | | @Override |
| | | public OrderDetailVO queryEditAddressDetail(String orderSn) { |
| | | Order order = this.getBySn(orderSn); |
| | | if (order == null) { |
| | | throw new ServiceException(ResultCode.ORDER_NOT_EXIST); |
| | | } |
| | | //查询订单项信息 |
| | | List<OrderItem> orderItems = orderItemService.getByOrderSn(orderSn); |
| | | |
| | | //查询订单和自订单,然后写入vo返回 |
| | | return new OrderDetailVO(order, orderItems, null, null); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | |
| | | return order; |
| | | } |
| | | @Override |
| | | @SystemLogPoint(description = "修改订单", customerLog = "'订单[' + #orderSn + ']收货信息修改,修改为'+#memberAddressDTO.consigneeDetail") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Order updateAddressConsignee(String orderSn, MemberAddressDTO memberAddressDTO) { |
| | | Order order = this.getBySn(orderSn); |
| | | if (order == null) { |
| | | throw new ServiceException(ResultCode.ORDER_NOT_EXIST); |
| | | } |
| | | //限制30秒只能请求一次避免出现重新提交问题 |
| | | Boolean b = redisTemplate.opsForValue().setIfAbsent(LOCK_EDIT_ORDER_ADDRESS + orderSn, orderSn,30, TimeUnit.SECONDS); |
| | | if ( Boolean.FALSE.equals(b)){ |
| | | throw new ServiceException("请在30秒后重试"); |
| | | } |
| | | String modifyAddressFlag = order.getModifyAddressFlag(); |
| | | if (StringUtils.isNotBlank(modifyAddressFlag)) { |
| | | throw new ServiceException("当前订单已经被领取"); |
| | | } |
| | | QueryWrapper<Order> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("id", order.getId()); |
| | | // 使用 last 方法拼接 FOR UPDATE 语句 |
| | | wrapper.last("FOR UPDATE"); |
| | | baseMapper.selectOne(wrapper); |
| | | //要记录之前的收货地址,所以需要以代码方式进行调用 不采用注解 |
| | | String message = "订单[" + orderSn + "]收货信息修改,由[" +order.getConsigneeAddressPath()+ order.getConsigneeDetail() + "]修改为[" + memberAddressDTO.getConsigneeAddressPath()+ memberAddressDTO.getConsigneeDetail() + "]"; |
| | | //记录订单操作日志 |
| | | BeanUtil.copyProperties(memberAddressDTO, order); |
| | | order.setModifyAddressFlag(ModifyAddressEnums.USED.name()); |
| | | this.updateById(order); |
| | | OrderLog orderLog = new OrderLog(orderSn, UserContext.getCurrentUser().getId(), UserContext.getCurrentUser().getRole().getRole(), |
| | | UserContext.getCurrentUser().getUsername(), message); |
| | | orderLogService.save(orderLog); |
| | | |
| | | return order; |
| | | } |
| | | @Override |
| | | @OrderLogPoint(description = "'订单['+#orderSn+']发货,发货单号['+#logisticsNo+']'", orderSn = "#orderSn") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Order delivery(String orderSn, String logisticsNo, String logisticsId) { |
| | | Order order = OperationalJudgment.judgment(this.getBySn(orderSn)); |
| | | //如果订单未发货,并且订单状态值等于待发货 |
| | | log.info("获取到的订单信息为{}", JSON.toJSONString(order)); |
| | | if (order.getDeliverStatus().equals(DeliverStatusEnum.UNDELIVERED.name()) && order.getOrderStatus().equals(OrderStatusEnum.UNDELIVERED.name())) { |
| | | //获取对应物流 |
| | | Logistics logistics = logisticsService.getById(logisticsId); |
| | | log.info("获取到的物流信息id为{}", logisticsId); |
| | | log.info("获取到的物流信息为{}", JSON.toJSONString(logistics)); |
| | | if (logistics == null) { |
| | | throw new ServiceException(ResultCode.ORDER_LOGISTICS_ERROR); |
| | | } |
| | |
| | | this.update(new LambdaUpdateWrapper<Order>() |
| | | .eq(Order::getSn, orderSn) |
| | | .set(Order::getOrderStatus, orderStatusEnum.name())); |
| | | //修改订单商品 todo 所有的订单需要审核后才能退款 |
| | | orderItemService.update(new LambdaUpdateWrapper<OrderItem>() |
| | | .eq(OrderItem::getOrderSn,orderSn) |
| | | .set(OrderItem::getAfterSaleStatus, OrderItemAfterSaleStatusEnum.NOT_APPLIED.name()) |
| | | .set(OrderItem::getCommentStatus,CommentStatusEnum.UNFINISHED.name()) |
| | | .set(OrderItem::getComplainStatus, OrderComplaintStatusEnum.NO_APPLY.name())); |
| | | //修改订单 |
| | | OrderMessage orderMessage = new OrderMessage(); |
| | | orderMessage.setNewStatus(orderStatusEnum); |