| | |
| | | import com.doumee.dao.business.OrdersDetailMapper; |
| | | import com.doumee.dao.business.RevenueMapper; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.biz.system.OperationConfigBiz; |
| | | import com.doumee.dao.business.OrderLogMapper; |
| | | import com.doumee.dao.business.model.Category; |
| | | import com.doumee.dao.business.model.DriverInfo; |
| | | import com.doumee.dao.business.model.OrderLog; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.business.model.Multifile; |
| | | import com.doumee.dao.business.model.Smsrecord; |
| | |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | @Autowired |
| | | private OrderLogMapper orderLogMapper; |
| | | |
| | | @Autowired |
| | | private OperationConfigBiz operationConfigBiz; |
| | | |
| | | @Override |
| | | public Integer create(DriverInfo driverInfo) { |
| | |
| | | if (driver == null) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "司机信息不存在"); |
| | | } |
| | | if (!Constants.THREE.equals(driver.getAuditStatus())) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "请先完成押金支付"); |
| | | } |
| | | driverInfoMapper.update(new UpdateWrapper<DriverInfo>().lambda() |
| | | .set(DriverInfo::getAcceptingStatus, status) |
| | | .eq(DriverInfo::getId, driver.getId())); |
| | |
| | | if (driver == null || driver.getLatitude() == null || driver.getLongitude() == null) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "司机位置信息缺失,请先开启定位"); |
| | | } |
| | | // 校验司机已支付押金 |
| | | if (!Constants.THREE.equals(driver.getAuditStatus())) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "请先完成押金支付"); |
| | | } |
| | | double driverLat = driver.getLatitude(); |
| | | double driverLng = driver.getLongitude(); |
| | | |
| | |
| | | wrapper.eq(Orders::getType, Constants.ONE) |
| | | .eq(Orders::getStatus, Constants.TWO) |
| | | .eq(Orders::getDeleted, Constants.ZERO); |
| | | |
| | | // 司机级别 >= 订单物品级别 |
| | | if (driver.getDriverLevel() != null) { |
| | | wrapper.apply("t.GOOD_LEVEL <= {0}", driver.getDriverLevel()); |
| | | } |
| | | |
| | | // 加急 OR 在配送范围内 |
| | | wrapper.and(w -> w |
| | |
| | | return vo; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void cancelOrder(Integer driverId, Integer orderId, String reason) { |
| | | // 1. 查询司机信息 |
| | | DriverInfo driver = driverInfoMapper.selectById(driverId); |
| | | if (driver == null) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "司机信息不存在"); |
| | | } |
| | | |
| | | // 2. 校验订单 |
| | | Orders order = ordersMapper.selectById(orderId); |
| | | if (order == null || Constants.ONE.equals(order.getDeleted())) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "订单不存在"); |
| | | } |
| | | if (!Constants.ONE.equals(order.getType())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "仅异地寄存订单可取消"); |
| | | } |
| | | if (!Constants.TWO.equals(order.getStatus())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "当前订单状态不允许取消"); |
| | | } |
| | | if (!driverId.equals(order.getAcceptDriver())) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "无权操作该订单"); |
| | | } |
| | | |
| | | // 3. 每日取消次数限制 |
| | | String limitStr = operationConfigBiz.getConfig().getDriverDailyCancelLimit(); |
| | | int limit = 3; |
| | | if (StringUtils.isNotBlank(limitStr)) { |
| | | try { limit = Integer.parseInt(limitStr); } catch (NumberFormatException ignored) {} |
| | | } |
| | | Calendar cal = Calendar.getInstance(); |
| | | cal.set(Calendar.HOUR_OF_DAY, 0); |
| | | cal.set(Calendar.MINUTE, 0); |
| | | cal.set(Calendar.SECOND, 0); |
| | | cal.set(Calendar.MILLISECOND, 0); |
| | | Date todayStart = cal.getTime(); |
| | | Long todayCancelCount = orderLogMapper.selectCount(new QueryWrapper<OrderLog>().lambda() |
| | | .eq(OrderLog::getOptUserId, driver.getMemberId()) |
| | | .eq(OrderLog::getObjType, Constants.ORDER_LOG_CANCEL) |
| | | .eq(OrderLog::getOptUserType, Constants.ONE) |
| | | .ge(OrderLog::getCreateTime, todayStart)); |
| | | if (todayCancelCount != null && todayCancelCount >= limit) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "今日取消次数已达上限"); |
| | | } |
| | | |
| | | // 4. 重置订单司机字段(保持status=2,释放回抢单大厅) |
| | | ordersMapper.update(new UpdateWrapper<Orders>().lambda() |
| | | .set(Orders::getAcceptDriver, null) |
| | | .set(Orders::getAcceptTime, null) |
| | | .set(Orders::getAcceptType, null) |
| | | .eq(Orders::getId, orderId)); |
| | | |
| | | // 5. 写入取消日志 |
| | | OrderLog log = new OrderLog(); |
| | | log.setOrderId(orderId); |
| | | log.setTitle("司机取消订单"); |
| | | log.setLogInfo(StringUtils.isNotBlank(reason) ? reason : "司机取消接单"); |
| | | log.setObjType(Constants.ORDER_LOG_CANCEL); |
| | | log.setOptUserId(driver.getMemberId()); |
| | | log.setOptUserType(Constants.ONE); |
| | | log.setOrderStatus(order.getStatus()); |
| | | log.setCreateTime(new Date()); |
| | | log.setDeleted(Constants.ZERO); |
| | | orderLogMapper.insert(log); |
| | | } |
| | | |
| | | private List<String> getFileUrls(Integer orderId, int objType, String prefix) { |
| | | List<Multifile> files = multifileMapper.selectList( |
| | | new QueryWrapper<Multifile>().lambda() |