| | |
| | | import com.doumee.dao.business.DriverInfoMapper; |
| | | import com.doumee.dao.business.MemberMapper; |
| | | import com.doumee.dao.business.MultifileMapper; |
| | | import com.doumee.dao.business.OrderCommentMapper; |
| | | import com.doumee.dao.business.SmsrecordMapper; |
| | | import com.doumee.dao.business.CategoryMapper; |
| | | import com.doumee.dao.business.OrdersMapper; |
| | | import com.doumee.dao.business.ShopInfoMapper; |
| | | import com.doumee.dao.business.OrdersDetailMapper; |
| | | import com.doumee.dao.business.RevenueMapper; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | |
| | | 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.OrderComment; |
| | | import com.doumee.dao.business.model.ShopInfo; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.business.model.Multifile; |
| | | import com.doumee.dao.business.model.Smsrecord; |
| | | import com.doumee.dao.business.model.Orders; |
| | | import com.doumee.dao.business.model.OrdersDetail; |
| | | import com.doumee.dao.business.model.Revenue; |
| | | import com.doumee.dao.dto.*; |
| | | import com.doumee.dao.vo.AccountResponse; |
| | | import com.doumee.dao.vo.DriverCenterVO; |
| | | import com.doumee.dao.vo.DriverGrabOrderVO; |
| | | import com.doumee.dao.vo.DriverOrderDetailVO; |
| | | import com.doumee.dao.dto.AuditDTO; |
| | | import com.doumee.dao.dto.ChangeStatusDTO; |
| | | import com.doumee.dao.dto.DriverLoginRequest; |
| | | import com.doumee.dao.dto.DriverRegisterRequest; |
| | | import com.doumee.dao.dto.DriverVerifyRequest; |
| | | import com.doumee.dao.dto.DriverActiveOrderDTO; |
| | | import com.doumee.dao.dto.DriverGrabOrderDTO; |
| | | import com.doumee.core.utils.aliyun.AliSmsService; |
| | | import com.doumee.dao.business.model.Notice; |
| | | import com.doumee.service.business.DriverInfoService; |
| | | import com.doumee.service.business.NoticeService; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.RandomStringUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | * @author rk |
| | | * @date 2026/04/08 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class DriverInfoServiceImpl implements DriverInfoService { |
| | | |
| | |
| | | private OrdersMapper ordersMapper; |
| | | |
| | | @Autowired |
| | | private ShopInfoMapper shopInfoMapper; |
| | | |
| | | @Autowired |
| | | private OrderCommentMapper orderCommentMapper; |
| | | |
| | | @Autowired |
| | | private RevenueMapper revenueMapper; |
| | | |
| | | @Autowired |
| | |
| | | |
| | | @Autowired |
| | | private OperationConfigBiz operationConfigBiz; |
| | | |
| | | @Autowired |
| | | private NoticeService noticeService; |
| | | |
| | | /** |
| | | * 发送订单站内信通知 |
| | | */ |
| | | private void sendOrderNotice(Integer memberId, Constants.MemberOrderNotify notify, Integer orderId, String... params) { |
| | | Notice notice = new Notice(); |
| | | notice.setUserType(0); // 0=会员 |
| | | notice.setUserId(memberId); |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 发送门店站内信通知 |
| | | */ |
| | | private void sendShopNotice(Integer shopId, Constants.ShopOrderNotify notify, Integer orderId, String... params) { |
| | | Notice notice = new Notice(); |
| | | notice.setUserType(2); // 2=门店 |
| | | notice.setUserId(shopId); |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 发送司机站内信通知 |
| | | */ |
| | | 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) { |
| | |
| | | .set(DriverInfo::getCardEndDate, request.getCardEndDate()) |
| | | .set(DriverInfo::getIdcardImg, request.getIdcardImg()) |
| | | .set(DriverInfo::getIdcardImgBack, request.getIdcardImgBack()) |
| | | .set(DriverInfo::getAuditStatus, Constants.ZERO) |
| | | .set(DriverInfo::getAliAccount, request.getAliAccount()) |
| | | .set(DriverInfo::getAliName, request.getAliName()) |
| | | .set(DriverInfo::getUpdateTime, now) |
| | | .set(DriverInfo::getAuditRemark, null) |
| | | .set(DriverInfo::getAuditTime, null) |
| | |
| | | .set(Member::getBusinessStatus, driverStatus) |
| | | .set(Member::getUpdateTime, now) |
| | | .eq(Member::getId, driverInfo.getMemberId())); |
| | | |
| | | // 短信通知 |
| | | if (Constants.equalsInteger(newAuditStatus, Constants.ONE)) { |
| | | // 审批通过 |
| | | sendSmsNotify(driverInfo.getTelephone(), |
| | | Constants.SmsNotify.DRIVER_AUTH_APPROVED, |
| | | "driver", driverInfo.getName()); |
| | | } else if (Constants.equalsInteger(newAuditStatus, Constants.TWO)) { |
| | | // 审批驳回 |
| | | sendSmsNotify(driverInfo.getTelephone(), |
| | | Constants.SmsNotify.DRIVER_AUTH_REJECTED, |
| | | "driver", driverInfo.getName(), |
| | | "reason", auditDTO.getAuditRemark() != null ? auditDTO.getAuditRemark() : ""); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | } |
| | | |
| | | // 异地寄存实时经纬度(按状态返回) |
| | | if (Constants.ONE.equals(order.getType())) { |
| | | // 司机自身经纬度 |
| | | vo.setDriverLng(driverLng); |
| | | vo.setDriverLat(driverLat); |
| | | |
| | | // status=3(已接单):返回存件门店经纬度 |
| | | if (Constants.equalsInteger(order.getStatus(), Constants.OrderStatus.accepted.getStatus())) { |
| | | if (order.getDepositShopId() != null) { |
| | | ShopInfo depositShop = shopInfoMapper.selectById(order.getDepositShopId()); |
| | | if (depositShop != null) { |
| | | vo.setDepositShopLng(depositShop.getLongitude()); |
| | | vo.setDepositShopLat(depositShop.getLatitude()); |
| | | } |
| | | } |
| | | } |
| | | // status=4(配送中):返回取件点经纬度 |
| | | if (Constants.equalsInteger(order.getStatus(), Constants.OrderStatus.delivering.getStatus())) { |
| | | if (order.getTakeShopId() != null) { |
| | | ShopInfo takeShop = shopInfoMapper.selectById(order.getTakeShopId()); |
| | | if (takeShop != null) { |
| | | vo.setTakeLng(takeShop.getLongitude()); |
| | | vo.setTakeLat(takeShop.getLatitude()); |
| | | } |
| | | } else if (order.getTakeLgt() != null && order.getTakeLat() != null) { |
| | | vo.setTakeLng(order.getTakeLgt().doubleValue()); |
| | | vo.setTakeLat(order.getTakeLat().doubleValue()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 下单附件图片 |
| | | String imgPrefix = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() |
| | | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.MEMBER_FILES).getCode(); |
| | | vo.setOrderImages(getFileUrls(orderId, Constants.FileType.ORDER_FILE.getKey(), imgPrefix)); |
| | | |
| | | // 评价信息 |
| | | vo.setCommentStatus(order.getCommentStatus()); |
| | | if (Constants.equalsInteger(order.getCommentStatus(), Constants.ONE)) { |
| | | vo.setCommentTime(order.getCommentTime()); |
| | | // 查询司机评价记录 |
| | | OrderComment driverComment = orderCommentMapper.selectOne(new QueryWrapper<OrderComment>().lambda() |
| | | .eq(OrderComment::getOrderId, orderId) |
| | | .eq(OrderComment::getTargetType, Constants.THREE) |
| | | .eq(OrderComment::getDeleted, Constants.ZERO) |
| | | .last("limit 1")); |
| | | if (driverComment != null) { |
| | | vo.setDriverScore(driverComment.getScore()); |
| | | vo.setCommentContent(driverComment.getContent()); |
| | | } |
| | | // 评价附件图片 |
| | | vo.setCommentImages(getFileUrls(orderId, Constants.FileType.COMMENT_ATTACH.getKey(), imgPrefix)); |
| | | } |
| | | |
| | | return vo; |
| | | } |
| | |
| | | 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::getObjType, Constants.OrderLogType.driverCancel.getStatus()) |
| | | .eq(OrderLog::getOptUserType, Constants.ONE) |
| | | .ge(OrderLog::getCreateTime, todayStart)); |
| | | if (todayCancelCount != null && todayCancelCount >= limit) { |
| | |
| | | // 5. 写入取消日志 |
| | | OrderLog log = new OrderLog(); |
| | | log.setOrderId(orderId); |
| | | log.setTitle("司机取消订单"); |
| | | log.setLogInfo(StringUtils.isNotBlank(reason) ? reason : "司机取消接单"); |
| | | log.setObjType(Constants.ORDER_LOG_CANCEL); |
| | | log.setTitle(Constants.OrderLogType.driverCancel.getTitle()); |
| | | log.setLogInfo(Constants.OrderLogType.driverCancel.format(StringUtils.isNotBlank(reason) ? reason : "司机取消接单")); |
| | | log.setObjType(Constants.OrderLogType.driverCancel.getStatus()); |
| | | log.setOptUserId(driver.getMemberId()); |
| | | log.setOptUserType(Constants.ONE); |
| | | log.setOrderStatus(order.getStatus()); |
| | | log.setCreateTime(new Date()); |
| | | log.setDeleted(Constants.ZERO); |
| | | orderLogMapper.insert(log); |
| | | |
| | | // 通知会员:司机变更 |
| | | 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 |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void grabOrder(Integer driverId, Integer orderId) { |
| | | // 1. 校验司机 |
| | | DriverInfo driver = driverInfoMapper.selectById(driverId); |
| | | if (driver == null) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "司机信息不存在"); |
| | | } |
| | | // 2. 校验司机接单状态 |
| | | if (!Constants.ONE.equals(driver.getAcceptingStatus())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "请先开启接单状态"); |
| | | } |
| | | if (!Integer.valueOf(3).equals(driver.getAuditStatus())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "司机审核未通过或未缴纳押金"); |
| | | } |
| | | if (driver.getDriverLevel() == null) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "司机等级未设置"); |
| | | } |
| | | |
| | | // 3. 校验订单 |
| | | 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(), "当前订单状态不允许抢单"); |
| | | } |
| | | |
| | | // 4. 校验司机等级 ≥ 订单等级 |
| | | if (order.getGoodLevel() != null && driver.getDriverLevel() < order.getGoodLevel()) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "司机等级不足,无法抢该订单"); |
| | | } |
| | | |
| | | // 5. 原子更新:带 status=2 条件防止并发重复抢单 |
| | | Date now = new Date(); |
| | | int rows = ordersMapper.update(new UpdateWrapper<Orders>().lambda() |
| | | .set(Orders::getAcceptDriver, driverId) |
| | | .set(Orders::getAcceptTime, now) |
| | | .set(Orders::getAcceptType, 0) // 0=手动抢单 |
| | | .set(Orders::getStatus, Constants.OrderStatus.accepted.getStatus()) |
| | | .set(Orders::getUpdateTime, now) |
| | | .eq(Orders::getId, orderId) |
| | | .eq(Orders::getStatus, Constants.TWO)); |
| | | if (rows == 0) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "抢单失败,订单已被抢或状态已变更"); |
| | | } |
| | | |
| | | // 6. 写入操作日志 |
| | | OrderLog log = new OrderLog(); |
| | | log.setOrderId(orderId); |
| | | log.setTitle(Constants.OrderLogType.driverGrab.getTitle()); |
| | | log.setLogInfo(Constants.OrderLogType.driverGrab.format(driver.getName())); |
| | | log.setObjType(Constants.OrderLogType.driverGrab.getStatus()); |
| | | log.setOptUserId(driver.getMemberId()); |
| | | log.setOptUserType(Constants.ONE); |
| | | log.setOrderStatus(Constants.OrderStatus.accepted.getStatus()); |
| | | log.setCreateTime(now); |
| | | log.setDeleted(Constants.ZERO); |
| | | orderLogMapper.insert(log); |
| | | |
| | | // 7. 通知会员:司机已抢单 |
| | | sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.WAIT_PICKUP_GRABBED, orderId, |
| | | "driverName", driver.getName()); |
| | | |
| | | // 通知存件门店:订单已抢单待取件 |
| | | if (order.getDepositShopId() != null) { |
| | | 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 : ""); |
| | | |
| | | // 短信通知司机:抢单成功,待取件 |
| | | String pickupAddress = order.getDepositShopAddress() != null ? order.getDepositShopAddress() : order.getDepositLocation(); |
| | | sendSmsNotify(driver.getTelephone(), Constants.SmsNotify.DRIVER_WAIT_PICKUP, |
| | | "orderNo", order.getCode(), |
| | | "address", pickupAddress != null ? pickupAddress : ""); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void confirmPickup(Integer driverId, DriverPickupDTO 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 (!Constants.equalsInteger(order.getStatus(), Constants.OrderStatus.accepted.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_TAKE.getKey()); |
| | | multifile.setType(Constants.ZERO); |
| | | multifile.setFileurl(url); |
| | | multifile.setIsdeleted(Constants.ZERO); |
| | | multifile.setCreateDate(now); |
| | | multifile.setSortnum(sortNum++); |
| | | multifileMapper.insert(multifile); |
| | | } |
| | | } |
| | | |
| | | // 4. 更新订单状态为派送中(4) |
| | | ordersMapper.update(new UpdateWrapper<Orders>().lambda() |
| | | .set(Orders::getStatus, Constants.OrderStatus.delivering.getStatus()) |
| | | .set(Orders::getUpdateTime, now) |
| | | .eq(Orders::getId, orderId)); |
| | | |
| | | // 5. 写入操作日志 |
| | | OrderLog log = new OrderLog(); |
| | | log.setOrderId(orderId); |
| | | log.setTitle(Constants.OrderLogType.driverPickup.getTitle()); |
| | | log.setLogInfo(Constants.OrderLogType.driverPickup.format(driver.getName())); |
| | | log.setObjType(Constants.OrderLogType.driverPickup.getStatus()); |
| | | log.setOptUserId(driver.getMemberId()); |
| | | log.setOptUserType(Constants.ONE); |
| | | log.setOrderStatus(Constants.OrderStatus.delivering.getStatus()); |
| | | log.setCreateTime(now); |
| | | log.setDeleted(Constants.ZERO); |
| | | orderLogMapper.insert(log); |
| | | |
| | | // 通知会员:订单配送中 |
| | | sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.DELIVERING, orderId, |
| | | "orderNo", order.getCode(), |
| | | "driverName", driver.getName()); |
| | | |
| | | // 通知取件门店:订单配送中 |
| | | if (order.getTakeShopId() != null) { |
| | | sendShopNotice(order.getTakeShopId(), Constants.ShopOrderNotify.DELIVERING, orderId, |
| | | "orderNo", order.getCode(), |
| | | "driverName", driver.getName()); |
| | | } |
| | | |
| | | // 通知司机:已取件配送中 |
| | | sendDriverNotice(driverId, Constants.DriverOrderNotify.DELIVERING, orderId, |
| | | "orderNo", order.getCode()); |
| | | |
| | | // 短信通知会员:司机已取件,配送中 |
| | | Member deliveringMember = memberMapper.selectById(order.getMemberId()); |
| | | if (deliveringMember != null) { |
| | | sendSmsNotify(deliveringMember.getTelephone(), Constants.SmsNotify.MEMBER_DELIVERING, |
| | | "orderNo", order.getCode(), |
| | | "name", driver.getName()); |
| | | } |
| | | } |
| | | |
| | | @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(Constants.OrderLogType.driverDeliver.getTitle()); |
| | | log.setLogInfo(Constants.OrderLogType.driverDeliver.format( |
| | | StringUtils.isNotBlank(dto.getRemark()) ? dto.getRemark() : "司机【" + driver.getName() + "】已送达")); |
| | | log.setObjType(Constants.OrderLogType.driverDeliver.getStatus()); |
| | | 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) { |
| | |
| | | return vo; |
| | | } |
| | | |
| | | /** |
| | | * 发送短信通知(失败不影响主业务) |
| | | */ |
| | | private void sendSmsNotify(String phone, Constants.SmsNotify smsNotify, String... paramPairs) { |
| | | if (StringUtils.isBlank(phone)) { |
| | | return; |
| | | } |
| | | String content = smsNotify.format(paramPairs); |
| | | try { |
| | | JSONObject templateParam = new JSONObject(); |
| | | for (int i = 0; i < paramPairs.length - 1; i += 2) { |
| | | templateParam.put(paramPairs[i], paramPairs[i + 1]); |
| | | } |
| | | boolean result = AliSmsService.sendSms(phone, smsNotify.getTemplateCode(), |
| | | templateParam.toJSONString()); |
| | | if (result) { |
| | | log.info("短信发送成功: phone={}, template={}", phone, smsNotify.name()); |
| | | } else { |
| | | log.warn("短信发送失败: phone={}, template={}", phone, smsNotify.name()); |
| | | } |
| | | // 存储短信记录 |
| | | Smsrecord record = new Smsrecord(); |
| | | record.setPhone(phone); |
| | | record.setContent(content); |
| | | record.setType(Constants.ONE); // 1=订单通知 |
| | | record.setStatus(result ? Constants.ONE : Constants.ZERO); |
| | | record.setCreateTime(new Date()); |
| | | record.setDeleted(Constants.ZERO); |
| | | smsrecordMapper.insert(record); |
| | | } catch (Exception e) { |
| | | log.error("短信发送异常: phone={}, template={}, error={}", phone, smsNotify.name(), e.getMessage()); |
| | | try { |
| | | Smsrecord record = new Smsrecord(); |
| | | record.setPhone(phone); |
| | | record.setContent(content); |
| | | record.setType(Constants.ONE); |
| | | record.setStatus(Constants.ZERO); |
| | | record.setCreateTime(new Date()); |
| | | record.setDeleted(Constants.ZERO); |
| | | smsrecordMapper.insert(record); |
| | | } catch (Exception ignored) {} |
| | | } |
| | | } |
| | | |
| | | } |