| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.oying.exception.BadRequestException; |
| | | import com.oying.modules.pc.store.service.StoreService; |
| | | import com.oying.modules.rider.domain.RiderIncomeDetail; |
| | | import com.oying.modules.rider.domain.RiderInfo; |
| | | import com.oying.modules.rider.domain.RiderOrderRecord; |
| | | import com.oying.modules.rider.domain.RiderWalletInfo; |
| | | import com.oying.modules.rider.domain.*; |
| | | import com.oying.modules.rider.domain.vo.OrderRiderOperationVo; |
| | | import com.oying.modules.rider.service.RiderIncomeDetailService; |
| | | import com.oying.modules.rider.service.RiderInfoService; |
| | | import com.oying.modules.rider.service.RiderWalletInfoService; |
| | | import com.oying.modules.rider.service.*; |
| | | import com.oying.modules.rider.utils.Constants; |
| | | import com.oying.modules.sh.domain.Order; |
| | | import com.oying.modules.sh.domain.vo.OrderResponse; |
| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.oying.modules.rider.service.RiderOrderRecordService; |
| | | import com.oying.modules.rider.domain.dto.RiderOrderRecordQueryCriteria; |
| | | import com.oying.modules.rider.mapper.RiderOrderRecordMapper; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private final RedisUtils redisUtils; |
| | | private final OrderService orderService; |
| | | private final RiderInfoService riderInfoService; |
| | | private final StoreService storeService; |
| | | private final RiderWalletInfoService riderWalletInfoService; |
| | | private final RiderIncomeDetailService riderIncomeDetailService; |
| | | private final RiderDeliveryPhotosService riderDeliveryPhotosService; |
| | | |
| | | @Override |
| | | public PageResult<RiderOrderRecord> queryAll(RiderOrderRecordQueryCriteria criteria, Page<Object> page) { |
| | |
| | | LocalDateTime orderLocalTime = LocalDateTime.parse(riderOrderRecord.getOrderTime(), formatter); |
| | | Timestamp orderTime = Timestamp.valueOf(orderLocalTime); |
| | | // 判断是否超时 |
| | | String isOvertime = Constants.IS_OVERTIME_YES; |
| | | String isOvertime = Constants.IS_OVERTIME_NO; |
| | | if (now.after(orderTime)) { |
| | | isOvertime = Constants.IS_OVERTIME_YES; |
| | | } |
| | |
| | | // 查询骑手信息 |
| | | RiderInfo riderInfo = riderInfoService.getRiderSourceInfo(riderId); |
| | | if (riderInfo == null || riderInfo.getEnabled().equals(Constants.SOURCE_ENABLED_DFF)) { |
| | | return R.fail(400, "骑手信息不存在或已过期"); |
| | | throw new BadRequestException("骑手信息不存在或已过期"); |
| | | } |
| | | // 唯一标识当前线程/客户端 |
| | | String clientId = UUID.randomUUID().toString(); |
| | |
| | | // 获取分布式锁,设置超时时间10秒 |
| | | boolean isLocked = redisUtils.setIfAbsent(lockKey, clientId, 10); |
| | | if (!isLocked) { |
| | | return R.fail(400, "订单已经被其他骑手接单,请稍后重试"); |
| | | throw new BadRequestException("订单已经被其他骑手接单,请稍后重试"); |
| | | } |
| | | // 查询当前订单 检查订单是否已经被其他骑手抢到或取消 直接返回 |
| | | OrderResponse orderResponse = orderService.getByOrderNum(orderNum); |
| | | if (orderResponse == null || orderResponse.getOrder() == null) { |
| | | return R.fail(400, "订单信息不存在,请稍后重试"); |
| | | throw new BadRequestException("订单信息不存在,请稍后重试"); |
| | | } |
| | | int orderStatus = orderResponse.getOrder().getOrderStatus(); |
| | | // 2商家已接单 4商家已备货 这两个状态可以接单 |
| | | if (orderStatus != 2 && orderStatus != 4) { |
| | | return R.fail(400, "订单已经被其他骑手接单或取消,请稍后重试"); |
| | | // 2商家已接单 3商家已备货 这两个状态可以接单 |
| | | if (orderStatus != 2 && orderStatus != 3) { |
| | | throw new BadRequestException("订单已经被其他骑手接单或取消,请稍后重试"); |
| | | } |
| | | // 商家备货状态 查看是否存在骑手信息 |
| | | if (orderStatus == 4 && orderResponse.getOrder().getRiderId() != null) { |
| | | return R.fail(400, "订单已经被其他骑手接单,请稍后重试"); |
| | | throw new BadRequestException("订单已经被其他骑手接单,请稍后重试"); |
| | | } |
| | | // 订单没有被接单或取消的情况下,进行接单操作 |
| | | // 1.新增骑手接单记录 |
| | | addRiderOrderRecord(riderInfo, orderResponse); |
| | | // 2.新增订单接单流程信息 骑手接单流程新增 |
| | | orderService.operationLog(orderResponse, OrderStatusEnum.THREE, riderInfo.getCardName()); |
| | | orderService.operationLog(orderResponse, OrderStatusEnum.FOUR, riderInfo.getCardName()); |
| | | // 返回成功信息 |
| | | return R.success(orderResponse, "接单成功"); |
| | | } catch (Exception e) { |
| | |
| | | // riderOrderRecord.setDeliveryFeeId(orderResponse.getOrder().getDeliveryFeeId()); |
| | | riderOrderRecord.setOrderIncome(orderResponse.getOrder().getSendPrice()); |
| | | riderOrderRecord.setOrderTime(orderResponse.getOrder().getOrderTime()); |
| | | riderOrderRecord.setUserName(orderResponse.getOrder().getUsername()); |
| | | create(riderOrderRecord); |
| | | } |
| | | |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R riderCompleteOrder(String orderNum) { |
| | | // 是否上传送达照片 |
| | | RiderDeliveryPhotos riderDeliveryPhotos = riderDeliveryPhotosService.getOne( |
| | | new QueryWrapper<RiderDeliveryPhotos>().eq(RiderDeliveryPhotos.COL_ORDER_NUM, orderNum)); |
| | | if (riderDeliveryPhotos == null) { |
| | | // 送达照片数据为空,抛出异常 |
| | | throw new BadRequestException("请上传送达照片"); |
| | | } |
| | | // 当前订单信息 |
| | | OrderResponse orderResponse = orderService.getByOrderNum(orderNum); |
| | | Order order = orderResponse.getOrder(); |
| | |
| | | // 返回参数 |
| | | orderResponse.getOrder().setOrderStatus(OrderStatusEnum.SEVEN.getKey()); |
| | | // 查询骑手钱包信息 |
| | | RiderWalletInfo riderWalletInfo = riderWalletInfoService.getRiderWalletInfo(String.valueOf(order.getRiderId())); |
| | | RiderWalletInfo riderWalletInfo = riderWalletInfoService.getRiderWalletInfo(order.getRiderId()); |
| | | // 修改骑手钱包信息 // 骑手总金额添加配送费 |
| | | riderWalletInfo.setAmount(riderWalletInfo.getAmount().add(order.getSendPrice())); |
| | | // 骑手可用余额添加配送费 |