202506051732
This commit is contained in:
parent
13aebd4218
commit
eb0298bb00
|
|
@ -154,6 +154,7 @@ public class OrderController extends BaseController {
|
|||
}
|
||||
|
||||
}
|
||||
order.setUserPhone(order.getPhone());
|
||||
}
|
||||
//添加订单日志记录
|
||||
int flg= orderService.insertOrder(order);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,415 @@
|
|||
package com.ruoyi.system.controllerUtil;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.system.domain.Order;
|
||||
import com.ruoyi.system.domain.OrderLog;
|
||||
import com.ruoyi.system.domain.Users;
|
||||
import com.ruoyi.system.service.IOrderService;
|
||||
import com.ruoyi.system.service.IUsersService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 订单日志处理器
|
||||
* 专门处理订单状态变更时的日志生成逻辑
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class OrderLogHandler {
|
||||
|
||||
// 订单日志标题常量
|
||||
private static final String TITLE_1 = "订单生成";
|
||||
private static final String TITLE_1_CONTENT_TYPE1 = "管理人员生成订单";
|
||||
private static final String TITLE_1_CONTENT_TYPE2 = "预约成功,将尽快为主人派单";
|
||||
private static final String TITLE_2 = "平台派单";
|
||||
private static final String TITLE_2_CONTENT_TYPE2 = "师傅收到派单信息";
|
||||
private static final String TITLE_3 = "师傅接单";
|
||||
private static final String TITLE_3_CONTENT_TYPE3 = "同意系统配单";
|
||||
private static final String TITLE_4 = "出发上门";
|
||||
private static final String TITLE_4_CONTENT_TYPE4 = "师傅收到派单信息准备出发";
|
||||
private static final String TITLE_5 = "师傅到达";
|
||||
private static final String TITLE_5_CONTENT_TYPE5 = "师傅到达服务地点";
|
||||
private static final String TITLE_6 = "已检查评估报价";
|
||||
private static final String TITLE_7 = "进行服务";
|
||||
private static final String TITLE_7_1 = "继续服务";
|
||||
private static final String TITLE_8 = "暂停服务";
|
||||
private static final String TITLE_9 = "服务完成";
|
||||
private static final String TITLE_10 = "订单取消";
|
||||
private static final String TITLE_10_CONTENT_TYPE10 = "订单取消";
|
||||
|
||||
private final IUsersService usersService;
|
||||
private final IOrderService orderService;
|
||||
|
||||
public OrderLogHandler() {
|
||||
this.usersService = SpringUtils.getBean(IUsersService.class);
|
||||
this.orderService = SpringUtils.getBean(IOrderService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建基础订单日志对象
|
||||
*
|
||||
* @param order 订单对象
|
||||
* @return 基础订单日志对象
|
||||
*/
|
||||
public OrderLog createBaseOrderLog(Order order) {
|
||||
OrderLog orderLog = new OrderLog();
|
||||
orderLog.setOid(order.getId());
|
||||
orderLog.setOrderId(order.getOrderId());
|
||||
orderLog.setRemark(order.getRemark());
|
||||
return orderLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据订单状态处理相应的业务逻辑
|
||||
*
|
||||
* @param order 订单对象
|
||||
* @param orderLog 订单日志对象
|
||||
*/
|
||||
public void processOrderStatus(Order order, OrderLog orderLog) {
|
||||
Long orderStatus = order.getStatus();
|
||||
Integer jsonStatus = order.getJsonStatus();
|
||||
|
||||
if (orderStatus == null) {
|
||||
throw new IllegalArgumentException("订单状态不能为空");
|
||||
}
|
||||
|
||||
switch (orderStatus.intValue()) {
|
||||
case 1:
|
||||
handleNewOrderStatus(order, orderLog);
|
||||
break;
|
||||
case 2:
|
||||
handlePendingServiceStatus(order, orderLog, jsonStatus);
|
||||
break;
|
||||
case 3:
|
||||
handleInServiceStatus(order, orderLog, jsonStatus);
|
||||
break;
|
||||
case 5:
|
||||
handleCancelledOrderStatus(order, orderLog);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("不支持的订单状态: " + orderStatus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理新订单状态(status=1)
|
||||
*
|
||||
* @param order 订单对象
|
||||
* @param orderLog 订单日志对象
|
||||
*/
|
||||
private void handleNewOrderStatus(Order order, OrderLog orderLog) {
|
||||
|
||||
JSONObject content = new JSONObject();
|
||||
orderService.updateOrder(order);
|
||||
// 根据创建类型设置不同的内容
|
||||
if (order.getCreateType() == 2) {
|
||||
content.put("name", TITLE_1_CONTENT_TYPE1);
|
||||
} else {
|
||||
content.put("name", TITLE_1_CONTENT_TYPE2);
|
||||
}
|
||||
|
||||
orderLog.setTitle(TITLE_1);
|
||||
orderLog.setType(new BigDecimal("1.0"));
|
||||
orderLog.setContent(content.toJSONString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理待服务状态(status=2)
|
||||
*
|
||||
* @param order 订单对象
|
||||
* @param orderLog 订单日志对象
|
||||
* @param jsonStatus 服务进度状态
|
||||
*/
|
||||
private void handlePendingServiceStatus(Order order, OrderLog orderLog, Integer jsonStatus) {
|
||||
if (jsonStatus == null) {
|
||||
throw new IllegalArgumentException("待服务状态下,服务进度不能为空");
|
||||
}
|
||||
|
||||
switch (jsonStatus) {
|
||||
case 1:
|
||||
handleDispatchStatus(order, orderLog);
|
||||
break;
|
||||
case 2:
|
||||
handleAcceptStatus(order, orderLog);
|
||||
break;
|
||||
case 3:
|
||||
handleSetFeeStatus(order, orderLog);
|
||||
break;
|
||||
case 4:
|
||||
handleDepartureStatus(order,orderLog);
|
||||
break;
|
||||
case 5:
|
||||
handleArrivalStatus(order,orderLog);
|
||||
break;
|
||||
case 6:
|
||||
handleQuoteStatus(order, orderLog);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("不支持的服务进度状态: " + jsonStatus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理服务中状态(status=3)
|
||||
*
|
||||
* @param order 订单对象
|
||||
* @param orderLog 订单日志对象
|
||||
* @param jsonStatus 服务进度状态
|
||||
*/
|
||||
private void handleInServiceStatus(Order order, OrderLog orderLog, Integer jsonStatus) {
|
||||
if (jsonStatus == null) {
|
||||
throw new IllegalArgumentException("服务中状态下,服务进度不能为空");
|
||||
}
|
||||
|
||||
switch (jsonStatus) {
|
||||
case 7:
|
||||
handleStartServiceStatus(order, orderLog);
|
||||
break;
|
||||
case 8:
|
||||
handlePauseServiceStatus(order, orderLog);
|
||||
break;
|
||||
case 9:
|
||||
handleCompleteServiceStatus(order, orderLog);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("不支持的服务进度状态: " + jsonStatus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理派单状态(jsonStatus=1)
|
||||
*/
|
||||
private void handleDispatchStatus(Order order, OrderLog orderLog) {
|
||||
JSONObject content = new JSONObject();
|
||||
content.put("name", TITLE_2_CONTENT_TYPE2);
|
||||
|
||||
JSONObject typeJson = new JSONObject();
|
||||
typeJson.put("type", 9);
|
||||
order.setLogJson(typeJson.toJSONString());
|
||||
orderService.updateOrder(order);
|
||||
// 设置师傅信息
|
||||
if (order.getOrderLog() != null && order.getOrderLog().getWorkerId() != null) {
|
||||
Users worker = usersService.selectUsersById(order.getOrderLog().getWorkerId());
|
||||
if (worker != null) {
|
||||
orderLog.setWorkerName(worker.getName());
|
||||
}
|
||||
}
|
||||
|
||||
orderLog.setTitle(TITLE_2);
|
||||
orderLog.setType(new BigDecimal("1.1"));
|
||||
orderLog.setContent(content.toJSONString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理接单状态(jsonStatus=2)
|
||||
*/
|
||||
private void handleAcceptStatus(Order order, OrderLog orderLog) {
|
||||
JSONObject content = new JSONObject();
|
||||
Users worker = usersService.selectUsersById(order.getWorkerId());
|
||||
if(worker!=null){
|
||||
order.setWorkerPhone(worker.getPhone());
|
||||
}
|
||||
content.put("name", TITLE_3_CONTENT_TYPE3);
|
||||
order.setWorkerId(order.getWorkerId());
|
||||
JSONObject typeJson = new JSONObject();
|
||||
typeJson.put("type", 1);
|
||||
order.setLogJson(typeJson.toJSONString());
|
||||
//orderService.updateOrder(order);
|
||||
// 更新订单接单相关信息
|
||||
updateOrderAcceptInfo(order, orderLog);
|
||||
|
||||
orderLog.setFirstWorkerId(orderLog.getWorkerId());
|
||||
orderLog.setIsPause(1);
|
||||
orderLog.setTitle(TITLE_3);
|
||||
orderLog.setType(new BigDecimal("2.0"));
|
||||
orderLog.setContent(content.toJSONString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理设置上门费状态(jsonStatus=3)
|
||||
*/
|
||||
private void handleSetFeeStatus(Order order, OrderLog orderLog) {
|
||||
JSONObject content = new JSONObject();
|
||||
content.put("name", TITLE_4_CONTENT_TYPE4);
|
||||
|
||||
JSONObject typeJson = new JSONObject();
|
||||
typeJson.put("type", 2);
|
||||
order.setLogJson(typeJson.toJSONString());
|
||||
orderService.updateOrder(order);
|
||||
|
||||
if (order.getOrderLog() != null && order.getOrderLog().getPrice() != null) {
|
||||
orderLog.setPrice(order.getOrderLog().getPrice());
|
||||
orderLog.setPaid(1L);
|
||||
}
|
||||
|
||||
orderLog.setTitle(TITLE_4);
|
||||
orderLog.setType(new BigDecimal("3.0"));
|
||||
orderLog.setContent(content.toJSONString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理出发上门状态(jsonStatus=4)
|
||||
*/
|
||||
private void handleDepartureStatus(Order order, OrderLog orderLog) {
|
||||
JSONObject content = new JSONObject();
|
||||
content.put("name", TITLE_4_CONTENT_TYPE4);
|
||||
|
||||
JSONObject typeJson = new JSONObject();
|
||||
typeJson.put("type", 3);
|
||||
order.setLogJson(typeJson.toJSONString());
|
||||
orderService.updateOrder(order);
|
||||
|
||||
orderLog.setTitle(TITLE_4);
|
||||
orderLog.setType(new BigDecimal("3.0"));
|
||||
orderLog.setContent(content.toJSONString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理确认到达状态(jsonStatus=5)
|
||||
*/
|
||||
private void handleArrivalStatus(Order order, OrderLog orderLog) {
|
||||
JSONObject content = new JSONObject();
|
||||
content.put("name", TITLE_5_CONTENT_TYPE5);
|
||||
|
||||
JSONObject typeJson = new JSONObject();
|
||||
typeJson.put("type", 4);
|
||||
order.setLogJson(typeJson.toJSONString());
|
||||
orderService.updateOrder(order);
|
||||
|
||||
orderLog.setTitle(TITLE_5);
|
||||
orderLog.setType(new BigDecimal("4.0"));
|
||||
orderLog.setContent(content.toJSONString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理项目报价状态(jsonStatus=6)
|
||||
*/
|
||||
private void handleQuoteStatus(Order order, OrderLog orderLog) {
|
||||
if (order.getOrderLog() == null || order.getOrderLog().getContent() == null) {
|
||||
throw new IllegalArgumentException("项目报价状态下,报价内容不能为空");
|
||||
}
|
||||
|
||||
|
||||
JSONObject typeJson = new JSONObject();
|
||||
typeJson.put("type", 5);
|
||||
order.setLogJson(typeJson.toJSONString());
|
||||
orderService.updateOrder(order);
|
||||
|
||||
orderLog.setTitle(TITLE_6);
|
||||
orderLog.setType(new BigDecimal("5.0"));
|
||||
orderLog.setPaid(1L);
|
||||
|
||||
// 设置报价相关信息
|
||||
if (order.getOrderLog().getDeposit() != null) {
|
||||
orderLog.setDeposit(order.getOrderLog().getDeposit());
|
||||
if (order.getOrderLog().getDeposit().compareTo(BigDecimal.ZERO) > 0) {
|
||||
orderLog.setDepPaid(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (order.getTotalPrice() != null) {
|
||||
orderLog.setPrice(order.getTotalPrice());
|
||||
}
|
||||
|
||||
orderLog.setContent(order.getOrderLog().getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理开始服务状态(jsonStatus=7)
|
||||
*/
|
||||
private void handleStartServiceStatus(Order order, OrderLog orderLog) {
|
||||
if (order.getOrderLog() == null || order.getOrderLog().getContent() == null) {
|
||||
throw new IllegalArgumentException("开始服务状态下,服务内容不能为空");
|
||||
}
|
||||
|
||||
JSONObject typeJson = new JSONObject();
|
||||
typeJson.put("type", 6);
|
||||
order.setLogJson(typeJson.toJSONString());
|
||||
orderService.updateOrder(order);
|
||||
|
||||
// 判断是否为继续服务(从暂停状态恢复)
|
||||
if (order.getIsPause() != null && order.getIsPause() == 2) {
|
||||
order.setIsPause(1);
|
||||
orderService.updateOrder(order);
|
||||
orderLog.setIsPause(1);
|
||||
orderLog.setTitle(TITLE_7_1);
|
||||
} else {
|
||||
orderLog.setTitle(TITLE_7);
|
||||
}
|
||||
|
||||
orderLog.setType(new BigDecimal("6.0"));
|
||||
orderLog.setContent(order.getOrderLog().getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理暂停服务状态(jsonStatus=8)
|
||||
*/
|
||||
private void handlePauseServiceStatus(Order order, OrderLog orderLog) {
|
||||
if (order.getOrderLog() == null || order.getOrderLog().getContent() == null) {
|
||||
throw new IllegalArgumentException("暂停服务状态下,暂停内容不能为空");
|
||||
}
|
||||
JSONObject typeJson = new JSONObject();
|
||||
typeJson.put("type", 7);
|
||||
order.setLogJson(typeJson.toJSONString());
|
||||
// 更新订单暂停状态
|
||||
order.setIsPause(2);
|
||||
orderService.updateOrder(order);
|
||||
|
||||
orderLog.setIsPause(2);
|
||||
orderLog.setTitle(TITLE_8);
|
||||
orderLog.setType(new BigDecimal("7.0"));
|
||||
orderLog.setContent(order.getOrderLog().getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理完成服务状态(jsonStatus=9)
|
||||
*/
|
||||
private void handleCompleteServiceStatus(Order order, OrderLog orderLog) {
|
||||
if (order.getOrderLog() == null || order.getOrderLog().getContent() == null) {
|
||||
throw new IllegalArgumentException("完成服务状态下,完成内容不能为空");
|
||||
}
|
||||
JSONObject typeJson = new JSONObject();
|
||||
typeJson.put("type", 8);
|
||||
order.setLogJson(typeJson.toJSONString());
|
||||
orderService.updateOrder(order);
|
||||
orderLog.setTitle(TITLE_9);
|
||||
orderLog.setType(new BigDecimal("8.0"));
|
||||
orderLog.setContent(order.getOrderLog().getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理取消订单状态(status=5)
|
||||
*/
|
||||
private void handleCancelledOrderStatus(Order order, OrderLog orderLog) {
|
||||
JSONObject content = new JSONObject();
|
||||
content.put("name", TITLE_10_CONTENT_TYPE10);
|
||||
|
||||
// 更新订单暂停状态
|
||||
order.setIsPause(1);
|
||||
orderService.updateOrder(order);
|
||||
|
||||
orderLog.setIsPause(2);
|
||||
orderLog.setTitle(TITLE_10);
|
||||
orderLog.setType(new BigDecimal("9.0"));
|
||||
orderLog.setContent(content.toJSONString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单接单相关信息
|
||||
*
|
||||
* @param order 订单对象
|
||||
* @param orderLog 订单日志对象
|
||||
*/
|
||||
private void updateOrderAcceptInfo(Order order, OrderLog orderLog) {
|
||||
order.setIsPause(1);
|
||||
order.setReceiveType(3L);
|
||||
order.setReceiveTime(new Date());
|
||||
order.setIsAccept(1);
|
||||
order.setWorkerId(orderLog.getWorkerId());
|
||||
orderService.updateOrder(order);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,67 +9,32 @@ import com.ruoyi.system.domain.OrderLog;
|
|||
import com.ruoyi.system.domain.UserAddress;
|
||||
import com.ruoyi.system.domain.Users;
|
||||
import com.ruoyi.system.service.IOrderLogService;
|
||||
import com.ruoyi.system.service.IOrderService;
|
||||
import com.ruoyi.system.service.IUserAddressService;
|
||||
import com.ruoyi.system.service.IUsersService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 服务订单Controller工具类
|
||||
* 专注于订单编号生成、状态验证和用户地址处理等核心功能
|
||||
*/
|
||||
@Controller
|
||||
public class OrderUtil {
|
||||
private static IUsersService usersService = SpringUtils.getBean(IUsersService.class);
|
||||
private static IOrderLogService orderLogService = SpringUtils.getBean(IOrderLogService.class);
|
||||
private static IOrderService orderService = SpringUtils.getBean(IOrderService.class);
|
||||
|
||||
//新增订单状态
|
||||
private static final String TITLE_1 = "订单生成";
|
||||
private static final String TITLE_1_CONTENT_TYPE1 = "管理人员生成订单";
|
||||
private static final String TITLE_1_CONTENT_TYPE2 = "预约成功,将尽快为主人派单";
|
||||
//派单订单状态
|
||||
private static final String TITLE_2 = "平台派单";
|
||||
private static final String TITLE_2_1 = "系统派单";
|
||||
private static final String TITLE_2_CONTENT_TYPE2 = "师傅收到派单信息";
|
||||
//师傅接单
|
||||
private static final String TITLE_3 = "师傅接单";
|
||||
private static final String TITLE_3_CONTENT_TYPE3 = "同意系统配单";
|
||||
//设置上门费
|
||||
|
||||
//出发上门
|
||||
private static final String TITLE_4 = "出发上门";
|
||||
private static final String TITLE_4_CONTENT_TYPE4 = "师傅收到派单信息准备出发";
|
||||
|
||||
//设置上门费
|
||||
private static final String TITLE_5 = "师傅到达";
|
||||
private static final String TITLE_5_CONTENT_TYPE5 = "师傅到达服务地点";
|
||||
//项目报价
|
||||
private static final String TITLE_6 = "已检查评估报价";
|
||||
//开始服务
|
||||
private static final String TITLE_7 = "进行服务";
|
||||
|
||||
//开始服务
|
||||
private static final String TITLE_7_1 = "继续服务";
|
||||
//暂停服务
|
||||
private static final String TITLE_8 = "暂停服务";
|
||||
//服务完成
|
||||
private static final String TITLE_9 = "服务完成";
|
||||
//订单取消
|
||||
private static final String TITLE_10 = "订单取消";
|
||||
private static final String TITLE_10_CONTENT_TYPE10 = "订单取消";
|
||||
|
||||
private static OrderLogHandler orderLogHandler = SpringUtils.getBean(OrderLogHandler.class);
|
||||
|
||||
// 订单编号生成相关常量
|
||||
private static final String PREFIX = "C";
|
||||
private static final int FIXED_LENGTH = 15; // 总长度为15
|
||||
|
||||
|
||||
/**
|
||||
* 生成订单编码的工具
|
||||
*
|
||||
* @return 格式为 C + yyyyMMdd + 随机数字 的订单编号
|
||||
*/
|
||||
public static String generateCode() {
|
||||
// 获取当前日期,格式化为yyyyMMdd
|
||||
|
|
@ -88,7 +53,6 @@ public class OrderUtil {
|
|||
return PREFIX + currentDate + randomBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证订单状态变更是否合法
|
||||
*
|
||||
|
|
@ -103,252 +67,275 @@ public class OrderUtil {
|
|||
}
|
||||
|
||||
Integer newStatus = newOrder.getJsonStatus();
|
||||
Integer oldStatus = null;
|
||||
if (oldOrder.getJsonStatus() != null) {
|
||||
oldStatus = oldOrder.getJsonStatus();
|
||||
} else {
|
||||
oldStatus = 0;
|
||||
}
|
||||
|
||||
Integer oldStatus = oldOrder.getJsonStatus() != null ? oldOrder.getJsonStatus() : 0;
|
||||
|
||||
// 状态未发生变化,直接通过
|
||||
if (Objects.equals(newStatus, oldStatus)) {
|
||||
return new VerificationResult(VerificationResult.CODE_SUCCESS, "NODATA");
|
||||
}
|
||||
|
||||
// 创建验证器实例
|
||||
// 创建验证器实例并进行验证
|
||||
OrderStatusValidator validator = new OrderStatusValidator();
|
||||
return performStatusValidation(validator, newOrder, newStatus, oldStatus);
|
||||
}
|
||||
|
||||
// 根据新状态进行相应验证
|
||||
/**
|
||||
* 执行状态验证
|
||||
*
|
||||
* @param validator 状态验证器
|
||||
* @param newOrder 新订单
|
||||
* @param newStatus 新状态
|
||||
* @param oldStatus 旧状态
|
||||
* @return 验证结果
|
||||
*/
|
||||
private VerificationResult performStatusValidation(OrderStatusValidator validator, Order newOrder, Integer newStatus, Integer oldStatus) {
|
||||
switch (newStatus) {
|
||||
case OrderStatusValidator.STATUS_DISPATCH:
|
||||
return validator.validateDispatchStatus(newOrder, oldStatus);
|
||||
|
||||
case OrderStatusValidator.STATUS_ACCEPT:
|
||||
return validator.validateAcceptStatus(oldStatus);
|
||||
|
||||
case OrderStatusValidator.STATUS_SET_FEE:
|
||||
return validator.validateSetFeeStatus(newOrder, oldStatus);
|
||||
|
||||
case OrderStatusValidator.STATUS_DEPART:
|
||||
return validator.validateDepartStatus(oldStatus);
|
||||
|
||||
case OrderStatusValidator.STATUS_ARRIVE:
|
||||
return validator.validateArriveStatus(oldStatus);
|
||||
|
||||
case OrderStatusValidator.STATUS_QUOTE:
|
||||
return validator.validateQuoteStatus(newOrder, oldStatus);
|
||||
|
||||
case OrderStatusValidator.STATUS_START_SERVICE:
|
||||
return validator.validateStartServiceStatus(newOrder, oldStatus);
|
||||
|
||||
case OrderStatusValidator.STATUS_PAUSE_SERVICE:
|
||||
return validator.validatePauseServiceStatus(newOrder, oldStatus);
|
||||
|
||||
case OrderStatusValidator.STATUS_COMPLETE:
|
||||
return validator.validateCompleteStatus(newOrder, oldStatus);
|
||||
|
||||
default:
|
||||
return new VerificationResult(VerificationResult.CODE_FAILURE, "无效的订单状态");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//1,根据用户手机号判断用户不存在,4如果不存在就要新增一个用户数据
|
||||
public Map<String, Object> isUser(String phone, String adressName) {
|
||||
AmapUtils amapUtils = new AmapUtils();
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
if (SpringUtils.getBean(IUsersService.class).selectUsersByPhone(phone) == null) {
|
||||
//1,用户不存在添加用户
|
||||
Users users = new Users();
|
||||
users.setName("微信用户");
|
||||
users.setType("1");
|
||||
users.setStatus(1);
|
||||
users.setPhone(phone);
|
||||
if (SpringUtils.getBean(IUsersService.class).insertUsers(users) > 0) {
|
||||
//添加成功用户后添加用户地址
|
||||
return isAddAdressUser(users, adressName);
|
||||
} else {
|
||||
map.put("code", "0");
|
||||
return map;
|
||||
}
|
||||
} else {
|
||||
return isAddAdressUser(SpringUtils.getBean(IUsersService.class).selectUsersByPhone(phone), adressName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//2根据用户地址获取经纬度,然后存地址数据
|
||||
public Map<String, Object> isAddAdressUser(Users users, String adressName) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
UserAddress selectuserAddress = new UserAddress();
|
||||
selectuserAddress.setUid(users.getId());
|
||||
selectuserAddress.setAddressName(adressName);
|
||||
List<UserAddress> userAddresslist = SpringUtils.getBean(IUserAddressService.class).selectUserAddressList(selectuserAddress);
|
||||
//判断用户地址是否存在
|
||||
if (!userAddresslist.isEmpty()) {
|
||||
map.put("code", "1");
|
||||
map.put("users", users);
|
||||
map.put("UserAddress", userAddresslist.get(0));
|
||||
return map;
|
||||
} else {
|
||||
//如果用户地址不存在就添加地址
|
||||
AmapUtils amapUtils = new AmapUtils();
|
||||
JSONObject jsonObject = amapUtils.geocode(adressName);
|
||||
UserAddress userAddress = new UserAddress();
|
||||
userAddress.setUid(users.getId());
|
||||
userAddress.setName(users.getName());
|
||||
userAddress.setPhone(users.getPhone());
|
||||
userAddress.setAddressName(adressName);
|
||||
userAddress.setAddressInfo(adressName);
|
||||
userAddress.setInfo(adressName);
|
||||
if (jsonObject.get("info").equals("OK")) {
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("geocodes");
|
||||
if (!jsonArray.isEmpty()) {
|
||||
JSONObject jsonObject1 = (JSONObject) jsonArray.get(0);
|
||||
String itude = jsonObject1.get("location").toString();
|
||||
String[] latitude = itude.split(",");
|
||||
userAddress.setLatitude(latitude[1]);
|
||||
userAddress.setLongitude(latitude[0]);
|
||||
}
|
||||
}
|
||||
userAddress.setIsDefault(Long.valueOf(1));
|
||||
if (SpringUtils.getBean(IUserAddressService.class).insertUserAddress(userAddress) > 0) {
|
||||
map.put("code", "1");
|
||||
map.put("users", users);
|
||||
map.put("UserAddress", userAddress);
|
||||
return map;
|
||||
} else {
|
||||
map.put("code", "0");
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//新增订单后添加订单记录
|
||||
/**
|
||||
* 保存订单日志
|
||||
* 委托给OrderLogHandler处理具体的业务逻辑
|
||||
*
|
||||
* @param order 订单对象,包含状态和服务进度信息
|
||||
* @return 影响的行数,大于0表示保存成功
|
||||
* @throws IllegalArgumentException 当订单参数无效时
|
||||
*/
|
||||
public int SaveOrderLog(Order order) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
OrderLog orderLog = new OrderLog();
|
||||
if (Objects.equals(order.getStatus(), 1L)) {
|
||||
if (order.getCreateType() == 2) {
|
||||
jsonObject.put("name", TITLE_1_CONTENT_TYPE1);
|
||||
} else {
|
||||
jsonObject.put("name", TITLE_1_CONTENT_TYPE2);
|
||||
}
|
||||
orderLog.setTitle(TITLE_1);
|
||||
orderLog.setType(new BigDecimal(1.0));
|
||||
}
|
||||
if (Objects.equals(order.getStatus(), 2L)) {
|
||||
//分配师傅待接单
|
||||
if (order.getJsonStatus() == 1) {
|
||||
if (order.getOrderLog() != null) {
|
||||
if (order.getOrderLog().getWorkerId() != null) {
|
||||
Users users = usersService.selectUsersById(order.getOrderLog().getWorkerId());
|
||||
if (users != null) {
|
||||
orderLog.setWorkerName(users.getName());
|
||||
}
|
||||
}
|
||||
// 参数验证
|
||||
validateOrderForLog(order);
|
||||
|
||||
}
|
||||
orderLog.setTitle(TITLE_2);
|
||||
jsonObject.put("name", TITLE_2_CONTENT_TYPE2);
|
||||
orderLog.setType(new BigDecimal(1.1));
|
||||
}
|
||||
//师傅同意接单
|
||||
if (order.getJsonStatus() == 2) {
|
||||
order.setIsPause(1);
|
||||
order.setReceiveType(3l);
|
||||
order.setReceiveTime(new Date());
|
||||
order.setIsAccept(1);
|
||||
order.setWorkerId(orderLog.getWorkerId());
|
||||
orderService.updateOrder(order);
|
||||
orderLog.setFirstWorkerId(orderLog.getWorkerId());
|
||||
orderLog.setIsPause(1);
|
||||
orderLog.setTitle(TITLE_3);
|
||||
jsonObject.put("name", TITLE_3_CONTENT_TYPE3);
|
||||
orderLog.setType(new BigDecimal(2.0));
|
||||
}
|
||||
//设置上门费
|
||||
if (order.getJsonStatus() == 3) {
|
||||
orderLog.setPrice(order.getOrderLog().getPrice());
|
||||
orderLog.setPaid(1L);
|
||||
orderLog.setTitle(TITLE_4);
|
||||
jsonObject.put("name", TITLE_4_CONTENT_TYPE4);
|
||||
orderLog.setType(new BigDecimal(3.0));
|
||||
}
|
||||
//出发上门
|
||||
if (order.getJsonStatus() == 4) {
|
||||
orderLog.setTitle(TITLE_4);
|
||||
jsonObject.put("name", TITLE_4_CONTENT_TYPE4);
|
||||
orderLog.setType(new BigDecimal(3.0));
|
||||
}
|
||||
//确认到达
|
||||
if (order.getJsonStatus() == 5) {
|
||||
orderLog.setTitle(TITLE_5);
|
||||
jsonObject.put("name", TITLE_5_CONTENT_TYPE5);
|
||||
orderLog.setType(new BigDecimal(4.0));
|
||||
}
|
||||
//项目报价
|
||||
if (order.getJsonStatus() == 6) {
|
||||
orderLog.setTitle(TITLE_6);
|
||||
orderLog.setDeposit(order.getOrderLog().getDeposit());
|
||||
orderLog.setPrice(order.getTotalPrice());
|
||||
orderLog.setPaid(1L);
|
||||
if ((order.getOrderLog().getDeposit()).compareTo(BigDecimal.ZERO) > 0) {
|
||||
orderLog.setDepPaid(1);
|
||||
}
|
||||
jsonObject = JSONObject.parseObject(order.getOrderLog().getContent());
|
||||
orderLog.setType(new BigDecimal(5.0));
|
||||
}
|
||||
try {
|
||||
// 委托给OrderLogHandler处理
|
||||
OrderLog orderLog = orderLogHandler.createBaseOrderLog(order);
|
||||
orderLogHandler.processOrderStatus(order, orderLog);
|
||||
|
||||
// 保存订单日志
|
||||
return orderLogService.insertOrderLog(orderLog);
|
||||
|
||||
} catch (Exception e) {
|
||||
// 记录异常信息(这里可以添加日志记录)
|
||||
throw new RuntimeException("保存订单日志失败: " + e.getMessage(), e);
|
||||
}
|
||||
if (Objects.equals(order.getStatus(), 3L)) {
|
||||
//开始服务
|
||||
if (order.getJsonStatus() == 7) {
|
||||
if (order.getIsPause() == 2) {
|
||||
order.setIsPause(1);
|
||||
orderService.updateOrder(order);
|
||||
orderLog.setIsPause(1);
|
||||
orderLog.setTitle(TITLE_7_1);
|
||||
jsonObject = JSONObject.parseObject(order.getOrderLog().getContent());
|
||||
orderLog.setType(new BigDecimal(6.0));
|
||||
} else {
|
||||
orderLog.setTitle(TITLE_7);
|
||||
jsonObject = JSONObject.parseObject(order.getOrderLog().getContent());
|
||||
orderLog.setType(new BigDecimal(6.0));
|
||||
}
|
||||
}
|
||||
//暂停服务
|
||||
if (order.getJsonStatus() == 8) {
|
||||
order.setIsPause(2);
|
||||
orderService.updateOrder(order);
|
||||
orderLog.setIsPause(2);
|
||||
orderLog.setTitle(TITLE_8);
|
||||
jsonObject = JSONObject.parseObject(order.getOrderLog().getContent());
|
||||
orderLog.setType(new BigDecimal(7.0));
|
||||
}
|
||||
//完成服务
|
||||
if (order.getJsonStatus() == 9) {
|
||||
orderLog.setTitle(TITLE_9);
|
||||
jsonObject = JSONObject.parseObject(order.getOrderLog().getContent());
|
||||
orderLog.setType(new BigDecimal(8.0));
|
||||
}
|
||||
|
||||
}
|
||||
//取消订单
|
||||
if (Objects.equals(order.getStatus(), 5L)) {
|
||||
order.setIsPause(1);
|
||||
orderService.updateOrder(order);
|
||||
orderLog.setIsPause(2);
|
||||
orderLog.setTitle(TITLE_10);
|
||||
jsonObject.put("name", TITLE_10_CONTENT_TYPE10);
|
||||
orderLog.setType(new BigDecimal(9.0));
|
||||
}
|
||||
orderLog.setRemark(order.getRemark());
|
||||
orderLog.setOid(order.getId());
|
||||
orderLog.setOrderId(order.getOrderId());
|
||||
orderLog.setContent(jsonObject.toJSONString());
|
||||
return orderLogService.insertOrderLog(orderLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证订单日志参数
|
||||
*
|
||||
* @param order 订单对象
|
||||
*/
|
||||
private void validateOrderForLog(Order order) {
|
||||
if (order == null) {
|
||||
throw new IllegalArgumentException("订单对象不能为空");
|
||||
}
|
||||
if (order.getId() == null || order.getOrderId() == null) {
|
||||
throw new IllegalArgumentException("订单ID和订单编号不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户手机号判断用户是否存在,如果不存在则新增用户数据
|
||||
*
|
||||
* @param phone 用户手机号
|
||||
* @param addressName 地址名称
|
||||
* @return 包含用户和地址信息的Map
|
||||
*/
|
||||
public Map<String, Object> isUser(String phone, String addressName) {
|
||||
Users existingUser = usersService.selectUsersByPhone(phone);
|
||||
|
||||
if (existingUser == null) {
|
||||
// 用户不存在,创建新用户
|
||||
Users newUser = createNewUser(phone);
|
||||
if (usersService.insertUsers(newUser) > 0) {
|
||||
return isAddAddressUser(newUser, addressName);
|
||||
} else {
|
||||
return createFailureResult();
|
||||
}
|
||||
} else {
|
||||
return isAddAddressUser(existingUser, addressName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新用户对象
|
||||
*
|
||||
* @param phone 用户手机号
|
||||
* @return 新用户对象
|
||||
*/
|
||||
private Users createNewUser(String phone) {
|
||||
Users user = new Users();
|
||||
user.setName("微信用户");
|
||||
user.setType("1");
|
||||
user.setStatus(1);
|
||||
user.setPhone(phone);
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建失败结果
|
||||
*
|
||||
* @return 失败结果Map
|
||||
*/
|
||||
private Map<String, Object> createFailureResult() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("code", "0");
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户地址获取经纬度,然后存储地址数据
|
||||
*
|
||||
* @param user 用户对象
|
||||
* @param addressName 地址名称
|
||||
* @return 包含处理结果的Map
|
||||
*/
|
||||
public Map<String, Object> isAddAddressUser(Users user, String addressName) {
|
||||
// 查询用户是否已有该地址
|
||||
List<UserAddress> existingAddresses = findExistingAddress(user.getId(), addressName);
|
||||
|
||||
if (!existingAddresses.isEmpty()) {
|
||||
// 地址已存在
|
||||
return createSuccessResult(user, existingAddresses.get(0));
|
||||
} else {
|
||||
// 地址不存在,创建新地址
|
||||
return createNewUserAddress(user, addressName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找已存在的地址
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param addressName 地址名称
|
||||
* @return 地址列表
|
||||
*/
|
||||
private List<UserAddress> findExistingAddress(Long userId, String addressName) {
|
||||
UserAddress queryAddress = new UserAddress();
|
||||
queryAddress.setUid(userId);
|
||||
queryAddress.setAddressName(addressName);
|
||||
return SpringUtils.getBean(IUserAddressService.class).selectUserAddressList(queryAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建成功结果
|
||||
*
|
||||
* @param user 用户对象
|
||||
* @param address 地址对象
|
||||
* @return 成功结果Map
|
||||
*/
|
||||
private Map<String, Object> createSuccessResult(Users user, UserAddress address) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("code", "1");
|
||||
map.put("users", user);
|
||||
map.put("UserAddress", address);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新的用户地址
|
||||
*
|
||||
* @param user 用户对象
|
||||
* @param addressName 地址名称
|
||||
* @return 包含处理结果的Map
|
||||
*/
|
||||
private Map<String, Object> createNewUserAddress(Users user, String addressName) {
|
||||
try {
|
||||
UserAddress userAddress = buildUserAddress(user, addressName);
|
||||
|
||||
// 获取地址的经纬度信息
|
||||
setAddressCoordinates(userAddress, addressName);
|
||||
|
||||
// 保存地址
|
||||
if (SpringUtils.getBean(IUserAddressService.class).insertUserAddress(userAddress) > 0) {
|
||||
return createSuccessResult(user, userAddress);
|
||||
} else {
|
||||
return createFailureResult();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("code", "0");
|
||||
map.put("message", "创建地址失败: " + e.getMessage());
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建用户地址对象
|
||||
*
|
||||
* @param user 用户对象
|
||||
* @param addressName 地址名称
|
||||
* @return 用户地址对象
|
||||
*/
|
||||
private UserAddress buildUserAddress(Users user, String addressName) {
|
||||
UserAddress userAddress = new UserAddress();
|
||||
userAddress.setUid(user.getId());
|
||||
userAddress.setName(user.getName());
|
||||
userAddress.setPhone(user.getPhone());
|
||||
userAddress.setAddressName(addressName);
|
||||
userAddress.setAddressInfo(addressName);
|
||||
userAddress.setInfo(addressName);
|
||||
userAddress.setIsDefault(1L);
|
||||
return userAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置地址的经纬度坐标
|
||||
*
|
||||
* @param userAddress 用户地址对象
|
||||
* @param addressName 地址名称
|
||||
*/
|
||||
private void setAddressCoordinates(UserAddress userAddress, String addressName) {
|
||||
try {
|
||||
AmapUtils amapUtils = new AmapUtils();
|
||||
JSONObject geoResult = amapUtils.geocode(addressName);
|
||||
|
||||
if ("OK".equals(geoResult.get("info"))) {
|
||||
parseCoordinates(userAddress, geoResult);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 地理编码失败,不影响地址保存,只是没有经纬度信息
|
||||
System.err.println("获取地址坐标失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析坐标信息
|
||||
*
|
||||
* @param userAddress 用户地址对象
|
||||
* @param geoResult 地理编码结果
|
||||
*/
|
||||
private void parseCoordinates(UserAddress userAddress, JSONObject geoResult) {
|
||||
JSONArray geocodes = geoResult.getJSONArray("geocodes");
|
||||
if (geocodes != null && !geocodes.isEmpty()) {
|
||||
JSONObject firstGeocode = geocodes.getJSONObject(0);
|
||||
String location = firstGeocode.getString("location");
|
||||
|
||||
if (location != null && location.contains(",")) {
|
||||
String[] coordinates = location.split(",");
|
||||
userAddress.setLongitude(coordinates[0]); // 经度
|
||||
userAddress.setLatitude(coordinates[1]); // 纬度
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1003,6 +1003,62 @@ export default {
|
|||
],
|
||||
timeSlot: [
|
||||
{ required: true, message: "请选择时间段", trigger: "change" }
|
||||
],
|
||||
// 服务暂停状态下的必填字段验证
|
||||
servicePhotos: [
|
||||
{
|
||||
validator: (rule, value, callback) => {
|
||||
if (this.form.jsonStatus === 8) {
|
||||
if (!value || value.length === 0) {
|
||||
callback(new Error('服务暂停时必须上传服务照片'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
},
|
||||
trigger: 'change'
|
||||
}
|
||||
],
|
||||
pauseReason: [
|
||||
{
|
||||
validator: (rule, value, callback) => {
|
||||
if (this.form.jsonStatus === 8) {
|
||||
if (!value || value.trim() === '') {
|
||||
callback(new Error('服务暂停时必须填写暂停原因'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
},
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
nextServiceTime: [
|
||||
{
|
||||
validator: (rule, value, callback) => {
|
||||
if (this.form.jsonStatus === 8) {
|
||||
if (!value) {
|
||||
callback(new Error('服务暂停时必须选择下次服务时间'))
|
||||
} else {
|
||||
// 验证下次服务时间必须是未来时间
|
||||
const selectedTime = new Date(value)
|
||||
const currentTime = new Date()
|
||||
if (selectedTime <= currentTime) {
|
||||
callback(new Error('下次服务时间必须是未来时间'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
},
|
||||
trigger: 'change'
|
||||
}
|
||||
]
|
||||
},
|
||||
commentDialogVisible: false, // 评价详情对话框可见性
|
||||
|
|
@ -1228,6 +1284,11 @@ export default {
|
|||
getOrder(id).then(response => {
|
||||
this.form = response.data
|
||||
|
||||
// 时间戳转换为日期格式显示
|
||||
if (this.form.makeTime && typeof this.form.makeTime === 'number') {
|
||||
this.form.makeTime = this.timestampToDate(this.form.makeTime)
|
||||
}
|
||||
|
||||
// 确保必要的数组和对象被初始化
|
||||
if (!this.form.serviceItems) {
|
||||
this.$set(this.form, 'serviceItems', [])
|
||||
|
|
@ -1319,14 +1380,31 @@ export default {
|
|||
submitForm() {
|
||||
this.$refs["form"].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.form.id != null) {
|
||||
updateOrder(this.form).then(response => {
|
||||
// 服务暂停状态的额外验证
|
||||
if (this.form.jsonStatus === 8) {
|
||||
const pauseValidation = this.validatePauseServiceData()
|
||||
if (!pauseValidation.valid) {
|
||||
this.$modal.msgError(pauseValidation.message)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 创建提交数据的副本
|
||||
const submitData = { ...this.form }
|
||||
|
||||
// 将预约时间转换为时间戳
|
||||
if (submitData.makeTime) {
|
||||
submitData.makeTime = this.dateToTimestamp(submitData.makeTime)
|
||||
}
|
||||
|
||||
if (submitData.id != null) {
|
||||
updateOrder(submitData).then(response => {
|
||||
this.$modal.msgSuccess("修改成功")
|
||||
this.open = false
|
||||
this.getList()
|
||||
})
|
||||
} else {
|
||||
addOrder(this.form).then(response => {
|
||||
addOrder(submitData).then(response => {
|
||||
this.$modal.msgSuccess("新增成功")
|
||||
this.open = false
|
||||
this.getList()
|
||||
|
|
@ -1696,6 +1774,13 @@ export default {
|
|||
handlePhotoChange(file, fileList) {
|
||||
this.form.servicePhotos = fileList;
|
||||
|
||||
// 如果是暂停服务状态,触发表单验证
|
||||
if (this.form.jsonStatus === 8) {
|
||||
this.$nextTick(() => {
|
||||
this.$refs.form.validateField('servicePhotos')
|
||||
})
|
||||
}
|
||||
|
||||
// 根据不同的服务进度状态封装不同的JSON格式
|
||||
if (this.form.jsonStatus === 7) {
|
||||
// 开始服务状态
|
||||
|
|
@ -1785,6 +1870,131 @@ export default {
|
|||
console.log('暂停服务数据JSON:', this.form.orderLog.content);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 将日期转换为Unix时间戳(秒)
|
||||
* @param {string|Date} date - 日期字符串或Date对象
|
||||
* @returns {number} Unix时间戳
|
||||
*/
|
||||
dateToTimestamp(date) {
|
||||
if (!date) return null;
|
||||
|
||||
let dateObj;
|
||||
if (typeof date === 'string') {
|
||||
dateObj = new Date(date);
|
||||
} else if (date instanceof Date) {
|
||||
dateObj = date;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 检查日期是否有效
|
||||
if (isNaN(dateObj.getTime())) {
|
||||
console.error('无效的日期格式:', date);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 返回Unix时间戳(秒)
|
||||
return Math.floor(dateObj.getTime() / 1000);
|
||||
},
|
||||
|
||||
/**
|
||||
* 将Unix时间戳转换为日期字符串
|
||||
* @param {number} timestamp - Unix时间戳(秒)
|
||||
* @returns {string} 日期字符串 (YYYY-MM-DD格式)
|
||||
*/
|
||||
timestampToDate(timestamp) {
|
||||
if (!timestamp || typeof timestamp !== 'number') return null;
|
||||
|
||||
try {
|
||||
// 将秒级时间戳转换为毫秒级
|
||||
const date = new Date(timestamp * 1000);
|
||||
|
||||
// 检查日期是否有效
|
||||
if (isNaN(date.getTime())) {
|
||||
console.error('无效的时间戳:', timestamp);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 格式化为 YYYY-MM-DD
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
|
||||
return `${year}-${month}-${day}`;
|
||||
} catch (error) {
|
||||
console.error('时间戳转换失败:', error);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
// 处理暂停服务数据封装
|
||||
handlePauseServiceData() {
|
||||
if (this.form.jsonStatus === 8) {
|
||||
// 提取图片地址数组
|
||||
const imageUrls = this.form.servicePhotos.map(file => {
|
||||
// 如果是新上传的文件,使用response中的url
|
||||
if (file.response && file.response.url) {
|
||||
return file.response.url;
|
||||
}
|
||||
// 如果是已存在的文件,使用url属性
|
||||
if (file.url) {
|
||||
return file.url;
|
||||
}
|
||||
return '';
|
||||
}).filter(url => url); // 过滤掉空字符串
|
||||
|
||||
// 暂停服务JSON结构
|
||||
const pauseServiceJson = {
|
||||
name: "服务暂停",
|
||||
image: imageUrls,
|
||||
pauseReason: this.form.pauseReason || "",
|
||||
nextServiceTime: this.form.nextServiceTime || ""
|
||||
};
|
||||
|
||||
this.form.orderLog.content = JSON.stringify(pauseServiceJson);
|
||||
console.log('暂停服务数据JSON:', this.form.orderLog.content);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 验证服务暂停数据的完整性
|
||||
* @returns {Object} 验证结果对象
|
||||
*/
|
||||
validatePauseServiceData() {
|
||||
const result = { valid: true, message: '' }
|
||||
|
||||
// 验证服务照片
|
||||
if (!this.form.servicePhotos || this.form.servicePhotos.length === 0) {
|
||||
result.valid = false
|
||||
result.message = '服务暂停时必须上传服务照片'
|
||||
return result
|
||||
}
|
||||
|
||||
// 验证暂停原因
|
||||
if (!this.form.pauseReason || this.form.pauseReason.trim() === '') {
|
||||
result.valid = false
|
||||
result.message = '服务暂停时必须填写暂停原因'
|
||||
return result
|
||||
}
|
||||
|
||||
// 验证下次服务时间
|
||||
if (!this.form.nextServiceTime) {
|
||||
result.valid = false
|
||||
result.message = '服务暂停时必须选择下次服务时间'
|
||||
return result
|
||||
}
|
||||
|
||||
// 验证下次服务时间必须是未来时间
|
||||
const selectedTime = new Date(this.form.nextServiceTime)
|
||||
const currentTime = new Date()
|
||||
if (selectedTime <= currentTime) {
|
||||
result.valid = false
|
||||
result.message = '下次服务时间必须是未来时间'
|
||||
return result
|
||||
}
|
||||
|
||||
return result
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue