| | |
| | | noticeService.create(notice); |
| | | } |
| | | |
| | | /** |
| | | * 发送司机站内信通知 |
| | | */ |
| | | private void sendDriverNotice(Integer driverId, Constants.DriverOrderNotify notify, Integer orderId, String... params) { |
| | | DriverInfo driver = driverInfoMapper.selectById(driverId); |
| | | if (driver == null || driver.getMemberId() == null) { |
| | | return; |
| | | } |
| | | Notice notice = new Notice(); |
| | | notice.setUserType(1); // 1=司机 |
| | | notice.setUserId(driver.getMemberId()); |
| | | notice.setTitle(notify.getTitle()); |
| | | notice.setContent(notify.format(params)); |
| | | notice.setObjId(orderId); |
| | | notice.setObjType(0); // 0=订单 |
| | | notice.setStatus(0); // 0=未读 |
| | | notice.setIsdeleted(Constants.ZERO); |
| | | notice.setCreateDate(new Date()); |
| | | noticeService.create(notice); |
| | | } |
| | | |
| | | @Override |
| | | public Integer create(DriverInfo driverInfo) { |
| | | driverInfoMapper.insert(driverInfo); |
| | |
| | | // 通知会员:司机变更 |
| | | sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.DRIVER_CHANGED, orderId, |
| | | "orderNo", order.getCode()); |
| | | |
| | | // 通知司机:取消成功 |
| | | int remainLimit = limit - (todayCancelCount != null ? todayCancelCount.intValue() + 1 : 1); |
| | | sendDriverNotice(driverId, Constants.DriverOrderNotify.CANCELLED, orderId, |
| | | "orderNo", order.getCode(), |
| | | "cancelLimit", String.valueOf(Math.max(remainLimit, 0))); |
| | | } |
| | | |
| | | @Override |
| | |
| | | sendShopNotice(order.getDepositShopId(), Constants.ShopOrderNotify.WAIT_PICKUP, orderId, |
| | | "orderNo", order.getCode()); |
| | | } |
| | | |
| | | // 通知司机:抢单成功 |
| | | String shopName = order.getDepositShopName() != null ? order.getDepositShopName() : order.getDepositLocation(); |
| | | sendDriverNotice(driverId, Constants.DriverOrderNotify.WAIT_DELIVER, orderId, |
| | | "orderNo", order.getCode(), |
| | | "shopName", shopName != null ? shopName : ""); |
| | | } |
| | | |
| | | @Override |
| | |
| | | "orderNo", order.getCode(), |
| | | "driverName", driver.getName()); |
| | | } |
| | | |
| | | // 通知司机:已取件配送中 |
| | | sendDriverNotice(driverId, Constants.DriverOrderNotify.DELIVERING, orderId, |
| | | "orderNo", order.getCode()); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void confirmDeliver(Integer driverId, DriverDeliverDTO dto) { |
| | | Integer orderId = dto.getOrderId(); |
| | | |
| | | // 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 (order.getTakeShopId() != null) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "有取件门店的订单请送达至门店核销"); |
| | | } |
| | | if (!Constants.equalsInteger(order.getStatus(), Constants.OrderStatus.delivering.getStatus())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "当前订单状态不允许确认送达"); |
| | | } |
| | | if (!driverId.equals(order.getAcceptDriver())) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "无权操作该订单"); |
| | | } |
| | | |
| | | // 3. 保存送达图片 |
| | | Date now = new Date(); |
| | | if (dto.getImages() != null && !dto.getImages().isEmpty()) { |
| | | int sortNum = 0; |
| | | for (String url : dto.getImages()) { |
| | | Multifile multifile = new Multifile(); |
| | | multifile.setObjId(orderId); |
| | | multifile.setObjType(Constants.FileType.DRIVER_DONE.getKey()); |
| | | multifile.setType(Constants.ZERO); |
| | | multifile.setFileurl(url); |
| | | multifile.setIsdeleted(Constants.ZERO); |
| | | multifile.setCreateDate(now); |
| | | multifile.setSortnum(sortNum++); |
| | | multifileMapper.insert(multifile); |
| | | } |
| | | } |
| | | |
| | | // 4. 更新订单状态为已送达(5) |
| | | ordersMapper.update(new UpdateWrapper<Orders>().lambda() |
| | | .set(Orders::getStatus, Constants.OrderStatus.arrived.getStatus()) |
| | | .set(Orders::getArriveTime, now) |
| | | .set(Orders::getUpdateTime, now) |
| | | .eq(Orders::getId, orderId)); |
| | | |
| | | // 5. 写入操作日志 |
| | | OrderLog log = new OrderLog(); |
| | | log.setOrderId(orderId); |
| | | log.setTitle("司机确认送达"); |
| | | log.setLogInfo(StringUtils.isNotBlank(dto.getRemark()) ? dto.getRemark() : "司机【" + driver.getName() + "】已送达"); |
| | | log.setObjType(Constants.ORDER_LOG_DRIVER_DELIVER); |
| | | log.setOptUserId(driver.getMemberId()); |
| | | log.setOptUserType(Constants.ONE); |
| | | log.setOrderStatus(Constants.OrderStatus.arrived.getStatus()); |
| | | log.setCreateTime(now); |
| | | log.setDeleted(Constants.ZERO); |
| | | orderLogMapper.insert(log); |
| | | |
| | | // 6. 通知会员:订单已送达(无取件门店) |
| | | String destination = StringUtils.isNotBlank(order.getTakeShopAddress()) ? order.getTakeShopAddress() : "目的地"; |
| | | sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.ARRIVED_NO_SHOP, orderId, |
| | | "orderNo", order.getCode(), |
| | | "destination", destination); |
| | | |
| | | // 通知司机:已送达 |
| | | sendDriverNotice(driverId, Constants.DriverOrderNotify.ARRIVED, orderId, |
| | | "orderNo", order.getCode(), |
| | | "destination", destination); |
| | | } |
| | | |
| | | private List<String> getFileUrls(Integer orderId, int objType, String prefix) { |