| | |
| | | import com.oying.exception.BadRequestException; |
| | | import com.oying.modules.pc.store.domain.Store; |
| | | 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.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.utils.Constants; |
| | | import com.oying.modules.sh.domain.Order; |
| | | import com.oying.modules.sh.domain.vo.OrderResponse; |
| | | import com.oying.modules.sh.service.OrderService; |
| | | import com.oying.utils.*; |
| | | import com.oying.utils.enums.OrderStatusEnum; |
| | | import lombok.RequiredArgsConstructor; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | private final OrderService orderService; |
| | | private final RiderInfoService riderInfoService; |
| | | private final StoreService storeService; |
| | | private final RiderWalletInfoService riderWalletInfoService; |
| | | private final RiderIncomeDetailService riderIncomeDetailService; |
| | | |
| | | @Override |
| | | public PageResult<RiderOrderRecord> queryAll(RiderOrderRecordQueryCriteria criteria, Page<Object> page) { |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R riderGrabOrder(String orderNum) { |
| | | Long riderId = SecurityUtils.getCurrentUserId(); |
| | | // 查询骑手信息 |
| | | RiderInfo riderInfo = riderInfoService.getRiderSourceInfo(riderId); |
| | | if (riderInfo == null || riderInfo.getEnabled().equals(Constants.SOURCE_ENABLED_DFF)) { |
| | | return R.fail(400, "骑手信息不存在或已过期"); |
| | | } |
| | | // 唯一标识当前线程/客户端 |
| | | String clientId = UUID.randomUUID().toString(); |
| | | // Redis 锁 key |
| | |
| | | return R.fail(400, "订单已经被其他骑手接单或顾客取消,请稍后重试"); |
| | | } |
| | | // 订单没有被接单或取消的情况下,进行接单操作 |
| | | // 查询骑手信息 |
| | | Long riderId = SecurityUtils.getCurrentUserId(); |
| | | RiderInfo riderInfo = riderInfoService.getRiderSourceInfo(riderId); |
| | | // 查询商家信息 |
| | | Store store = storeService.getById(orderResponse.getOrder().getStoreId()); |
| | | // 1.新增骑手接单记录 |
| | | addRiderOrderRecord(riderInfo, orderResponse, store); |
| | | // 2.新增订单接单流程信息 |
| | | // 2.新增订单接单流程信息 骑手接单流程新增 |
| | | orderService.operationLog(orderResponse, OrderStatusEnum.THREE); |
| | | // 返回成功信息 |
| | | return R.success(orderResponse, "接单成功"); |
| | | } catch (Exception e) { |
| | |
| | | create(riderOrderRecord); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public R riderCancelOrder(String orderNum) { |
| | | // 查询当前订单信息 |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R riderOperationOrder(OrderRiderOperationVo orderRiderOperationVo){ |
| | | // 判断骑手操作类型 |
| | | // 添加订单操作记录 |
| | | public R riderOperationOrder(OrderRiderOperationVo orderRiderOperationVo) { |
| | | OrderResponse orderResponse = orderService.getByOrderNum(orderRiderOperationVo.getOrderNum()); |
| | | // 判断骑手操作类型 上报到店操作 OperationType=1 |
| | | if (orderRiderOperationVo.getOperationType().equals(Constants.ORDER_OPERATION_TYPE_STORE)) { |
| | | // 添加订单操作记录 上报到店操作1 |
| | | orderService.operationLog(orderResponse, OrderStatusEnum.FIVE); |
| | | updateRiderOrderStatus(orderRiderOperationVo.getOrderNum(), Constants.ORDER_STATUS_StORE); |
| | | orderResponse.getOrder().setOrderStatus(OrderStatusEnum.FIVE.getKey()); |
| | | } else { |
| | | // 添加订单操作记录 取货配送 OperationType=2 |
| | | orderService.operationLog(orderResponse, OrderStatusEnum.SIX); |
| | | updateRiderOrderStatus(orderRiderOperationVo.getOrderNum(), Constants.ORDER_STATUS_DELIVERY); |
| | | orderResponse.getOrder().setOrderStatus(OrderStatusEnum.SIX.getKey()); |
| | | } |
| | | // 修改骑手端的订单状态 |
| | | updateRiderOrderStatus(orderRiderOperationVo.getOrderNum(), Constants.ORDER_STATUS_StORE); |
| | | return R.success(); |
| | | return R.success(orderResponse); |
| | | } |
| | | |
| | | @Override |
| | | public R riderCompleteOrder(String orderNum) { |
| | | // 当前订单信息 |
| | | OrderResponse orderResponse = orderService.getByOrderNum(orderNum); |
| | | Order order = orderResponse.getOrder(); |
| | | // 添加订单操作记录 订单完成 |
| | | orderService.operationLog(orderResponse, OrderStatusEnum.SEVEN); |
| | | // 修改骑手端的订单状态 |
| | | updateRiderOrderStatus(orderNum, Constants.ORDER_STATUS_FINISH); |
| | | // 返回参数 |
| | | orderResponse.getOrder().setOrderStatus(OrderStatusEnum.SEVEN.getKey()); |
| | | // 查询骑手钱包信息 |
| | | RiderWalletInfo riderWalletInfo = riderWalletInfoService.getRiderWalletInfo(String.valueOf(order.getRiderId())); |
| | | // 修改骑手钱包信息 // 骑手总金额添加配送费 |
| | | riderWalletInfo.setAmount(riderWalletInfo.getAmount().add(order.getSendPrice())); |
| | | // 骑手可用余额添加配送费 |
| | | riderWalletInfo.setAvailableBalance(riderWalletInfo.getAvailableBalance().add(order.getSendPrice())); |
| | | // 添加累计收入添加配送费 |
| | | riderWalletInfo.setIncomeTotal(riderWalletInfo.getIncomeTotal().add(order.getSendPrice())); |
| | | // 完成总单数添加1 |
| | | riderWalletInfo.setRunTotal(riderWalletInfo.getRunTotal() + 1); |
| | | riderWalletInfoService.updateById(riderWalletInfo); |
| | | // 添加骑手收入明细 |
| | | RiderIncomeDetail riderIncomeDetail = new RiderIncomeDetail(); |
| | | riderIncomeDetail.setRiderId(order.getRiderId()); |
| | | riderIncomeDetail.setRiderName(order.getRiderName()); |
| | | riderIncomeDetail.setRiderPhone(order.getRiderPhone()); |
| | | riderIncomeDetail.setOrderId(order.getOrderId()); |
| | | riderIncomeDetail.setOrderNum(order.getOrderNum()); |
| | | riderIncomeDetail.setIncomeAmount(order.getSendPrice()); |
| | | riderIncomeDetail.setIncomeType(Constants.INCOME_TYPE_DELIVERY); |
| | | riderIncomeDetail.setIncomeDate(DateUtil.getNowTimeTypeYYYYMMDD()); |
| | | riderIncomeDetail.setIncomeMonth(DateUtil.getNowTimeTypeYYYYMM()); |
| | | riderIncomeDetail.setDeliveryTime(new Timestamp(System.currentTimeMillis())); |
| | | riderIncomeDetail.setOrderStatus(Constants.ORDER_STATUS_FINISH); |
| | | riderIncomeDetail.setStartAddress("待完善"); |
| | | riderIncomeDetail.setEndAddress("待完善"); |
| | | riderIncomeDetailService.save(riderIncomeDetail); |
| | | return R.success(orderResponse); |
| | | } |
| | | |
| | | |
| | | |
| | | } |