diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java index 7d28ee9..9556b2d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/OrderController.java @@ -4,8 +4,8 @@ import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletResponse; -import com.alibaba.fastjson.JSONObject; -import com.ruoyi.system.controllerUtil.orderUtil; +import com.ruoyi.system.controllerUtil.VerificationResult; +import com.ruoyi.system.controllerUtil.OrderUtil; import com.ruoyi.system.domain.*; import com.ruoyi.system.service.*; import org.springframework.security.access.prepost.PreAuthorize; @@ -116,6 +116,20 @@ public class OrderController extends BaseController { } + + /** + * 获取服务订单详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:Order:query')") + @GetMapping(value = "generateCode") + public AjaxResult generateCode() { + return success(OrderUtil.generateCode()); + } + + + + + /** * 新增服务订单 */ @@ -123,7 +137,7 @@ public class OrderController extends BaseController { @Log(title = "服务订单", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody Order order) { - orderUtil orderUtil = new orderUtil(); + OrderUtil orderUtil = new OrderUtil(); //1,根据用户手机号和地址判断用户的数据数据和地址数据 //如果用户数据不存在,则添加用户数据 //如果用户地址不存在,则添加用户地址数据 @@ -171,11 +185,6 @@ public class OrderController extends BaseController { }else{ return error(); } - - - - - } @@ -188,10 +197,25 @@ public class OrderController extends BaseController { @PutMapping public AjaxResult edit(@RequestBody Order order) { //插入订单日志记录 - orderUtil orderUtil = new orderUtil(); - orderUtil.SaveOrderLog(order); - return toAjax(orderService.updateOrder(order) - ); + OrderUtil orderUtil = new OrderUtil(); + Order oldorder=orderService.selectOrderById(order.getId()); + //验证订单状态 + VerificationResult verificationResult = orderUtil.validateOrderStatusChange(order, oldorder); + if (verificationResult.getCode().equals(VerificationResult.CODE_SUCCESS)){ + + //特殊情况,状态不变的情况下,不插入日志记录 + if (!verificationResult.getData().equals("NODATA")){ + //开始服务,需要给order做标记 + orderUtil.SaveOrderLog(order); + }else{ + if(!order.getStatus().equals(oldorder.getStatus())){ + orderUtil.SaveOrderLog(order); + } + } + return toAjax(orderService.updateOrder(order)); + }else{ + return error(verificationResult.getData()); + } } /** diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderStatusValidator.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderStatusValidator.java new file mode 100644 index 0000000..38ceff0 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderStatusValidator.java @@ -0,0 +1,179 @@ +package com.ruoyi.system.controllerUtil; + +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.system.domain.Order; + +/** + * 订单状态验证器 + * 专门处理订单状态变更的验证逻辑 + * + * @author ruoyi + */ +public class OrderStatusValidator { + + // 订单状态常量定义 + public static final int STATUS_ZERO = 0; // 派单 + public static final int STATUS_DISPATCH = 1; // 派单 + public static final int STATUS_ACCEPT = 2; // 接单 + public static final int STATUS_SET_FEE = 3; // 设置上门费 + public static final int STATUS_DEPART = 4; // 出发上门 + public static final int STATUS_ARRIVE = 5; // 到达上门 + public static final int STATUS_QUOTE = 6; // 项目报价 + public static final int STATUS_START_SERVICE = 7; // 开始服务 + public static final int STATUS_PAUSE_SERVICE = 8; // 暂停服务 + public static final int STATUS_COMPLETE = 9; // 服务完成 + + /** + * 验证派单状态 + * + * @param newOrder 新订单状态 + * @param oldStatus 旧订单状态 + * @return 验证结果 + */ + public VerificationResult validateDispatchStatus(Order newOrder, Integer oldStatus) { + if (oldStatus != STATUS_ZERO) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "此订单不允许派单"); + } + if (newOrder.getOrderLog() == null || newOrder.getOrderLog().getWorkerId() == null) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "派单师傅不能为空"); + } + return new VerificationResult(VerificationResult.CODE_SUCCESS, "验证通过"); + } + + /** + * 验证接单状态 + * + * @param oldStatus 旧订单状态 + * @return 验证结果 + */ + public VerificationResult validateAcceptStatus(Integer oldStatus) { + if (oldStatus != STATUS_DISPATCH) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "请先完成派单之后再进行操作"); + } + return new VerificationResult(VerificationResult.CODE_SUCCESS, "验证通过"); + } + + /** + * 验证设置上门费状态 + * + * @param newOrder 新订单状态 + * @param oldStatus 旧订单状态 + * @return 验证结果 + */ + public VerificationResult validateSetFeeStatus(Order newOrder, Integer oldStatus) { + if (oldStatus != STATUS_ACCEPT) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "请先完成接单之后再进行操作"); + } + if (newOrder.getOrderLog() == null || newOrder.getOrderLog().getPrice() == null) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "请设置上门费之后再进行操作"); + } + return new VerificationResult(VerificationResult.CODE_SUCCESS, "验证通过"); + } + + /** + * 验证出发上门状态 + * + * @param oldStatus 旧订单状态 + * @return 验证结果 + */ + public VerificationResult validateDepartStatus(Integer oldStatus) { + if (oldStatus != STATUS_SET_FEE) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "请先设置上门费后再进行操作"); + } + return new VerificationResult(VerificationResult.CODE_SUCCESS, "验证通过"); + } + + /** + * 验证到达上门状态 + * + * @param oldStatus 旧订单状态 + * @return 验证结果 + */ + public VerificationResult validateArriveStatus(Integer oldStatus) { + if (oldStatus != STATUS_DEPART) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "请先完成出发上门后再进行操作"); + } + return new VerificationResult(VerificationResult.CODE_SUCCESS, "验证通过"); + } + + /** + * 验证项目报价状态 + * + * @param newOrder 新订单状态 + * @param oldStatus 旧订单状态 + * @return 验证结果 + */ + public VerificationResult validateQuoteStatus(Order newOrder, Integer oldStatus) { + if (oldStatus != STATUS_ARRIVE) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "请先完成到达上门后再进行操作"); + } + if (isOrderLogContentEmpty(newOrder)) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "请填写项目报价"); + } + return new VerificationResult(VerificationResult.CODE_SUCCESS, "验证通过"); + } + + /** + * 验证开始服务状态 + * 只允许从项目报价(6)或暂停服务(8)状态转换到开始服务 + * + * @param newOrder 新订单状态 + * @param oldStatus 旧订单状态 + * @return 验证结果 + */ + public VerificationResult validateStartServiceStatus(Order newOrder, Integer oldStatus) { + // 只有状态为6(项目报价)或8(暂停服务)时才可以执行开始服务 + if (oldStatus != STATUS_QUOTE && oldStatus != STATUS_PAUSE_SERVICE) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "只能从项目报价或暂停服务状态转换到开始服务"); + } + if (isOrderLogContentEmpty(newOrder)) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "请上传服务图片"); + } + return new VerificationResult(VerificationResult.CODE_SUCCESS, "验证通过"); + } + + /** + * 验证暂停服务状态 + * + * @param newOrder 新订单状态 + * @param oldStatus 旧订单状态 + * @return 验证结果 + */ + public VerificationResult validatePauseServiceStatus(Order newOrder, Integer oldStatus) { + if (oldStatus != STATUS_START_SERVICE) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "请先开始服务再进行操作"); + } + if (isOrderLogContentEmpty(newOrder)) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "请填写暂停服务原因,下次服务时间,暂停图片等信息再进行操作"); + } + return new VerificationResult(VerificationResult.CODE_SUCCESS, "验证通过"); + } + + /** + * 验证服务完成状态 + * + * @param newOrder 新订单状态 + * @param oldStatus 旧订单状态 + * @return 验证结果 + */ + public VerificationResult validateCompleteStatus(Order newOrder, Integer oldStatus) { + if (oldStatus != STATUS_START_SERVICE) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "请先开始服务后再进行操作"); + } + if (isOrderLogContentEmpty(newOrder)) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "请上传服务完成图片"); + } + return new VerificationResult(VerificationResult.CODE_SUCCESS, "验证通过"); + } + + /** + * 检查订单日志内容是否为空 + * + * @param order 订单对象 + * @return true-内容为空,false-内容不为空 + */ + private boolean isOrderLogContentEmpty(Order order) { + return order.getOrderLog() == null || + StringUtils.isEmpty(order.getOrderLog().getContent()); + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderUtil.java new file mode 100644 index 0000000..a44289b --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderUtil.java @@ -0,0 +1,354 @@ +package com.ruoyi.system.controllerUtil; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.utils.AmapUtils; +import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.system.domain.Order; +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 final String PREFIX = "C"; + private static final int FIXED_LENGTH = 15; // 总长度为15 + + + /** + * 生成订单编码的工具 + */ + public static String generateCode() { + // 获取当前日期,格式化为yyyyMMdd + String currentDate = LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE); + + // 生成固定长度的随机数字字符串 + int randomLength = FIXED_LENGTH - 1 - currentDate.length(); // 计算需要生成的随机数位数 + StringBuilder randomBuilder = new StringBuilder(); + Random random = new Random(); + + for (int i = 0; i < randomLength; i++) { + randomBuilder.append(random.nextInt(10)); // 生成0-9之间的随机数字 + } + + // 拼接最终的编码 + return PREFIX + currentDate + randomBuilder.toString(); + } + + + /** + * 验证订单状态变更是否合法 + * + * @param newOrder 新订单状态 + * @param oldOrder 旧订单状态 + * @return 验证结果,包含状态码和消息 + */ + public VerificationResult validateOrderStatusChange(Order newOrder, Order oldOrder) { + // 基础参数验证 + if (oldOrder == null) { + return new VerificationResult(VerificationResult.CODE_FAILURE, "旧订单不能为空"); + } + + Integer newStatus = newOrder.getJsonStatus(); + Integer oldStatus = null; + if (oldOrder.getJsonStatus() != null) { + oldStatus = oldOrder.getJsonStatus(); + } else { + oldStatus = 0; + } + + + // 状态未发生变化,直接通过 + if (Objects.equals(newStatus, oldStatus)) { + return new VerificationResult(VerificationResult.CODE_SUCCESS, "NODATA"); + } + + // 创建验证器实例 + OrderStatusValidator validator = new OrderStatusValidator(); + + // 根据新状态进行相应验证 + 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 isUser(String phone, String adressName) { + AmapUtils amapUtils = new AmapUtils(); + Map map = new HashMap(); + 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 isAddAdressUser(Users users, String adressName) { + Map map = new HashMap(); + UserAddress selectuserAddress = new UserAddress(); + selectuserAddress.setUid(users.getId()); + selectuserAddress.setAddressName(adressName); + List 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; + } + } + } + + //新增订单后添加订单记录 + 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()); + } + } + + } + 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)); + } + } + 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); + } + + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/VerificationResult.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/VerificationResult.java new file mode 100644 index 0000000..2eb62a4 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/VerificationResult.java @@ -0,0 +1,24 @@ +package com.ruoyi.system.controllerUtil; + +public class VerificationResult { + + private String code; + private String data; + + public VerificationResult(String code, String data) { + this.code = code; + this.data = data; + } + + public String getCode() { + return code; + } + + public String getData() { + return data; + } + public static final String CODE_NODATA = "2"; + public static final String CODE_SUCCESS = "1"; + public static final String CODE_FAILURE = "0"; + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/orderUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/orderUtil.java deleted file mode 100644 index bd925fc..0000000 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/orderUtil.java +++ /dev/null @@ -1,223 +0,0 @@ -package com.ruoyi.system.controllerUtil; - -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.ruoyi.common.utils.AmapUtils; -import com.ruoyi.common.utils.spring.SpringUtils; -import com.ruoyi.system.domain.Order; -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.IUserAddressService; -import com.ruoyi.system.service.IUsersService; -import org.springframework.stereotype.Controller; - -import java.math.BigDecimal; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * 服务订单Controller工具类 - */ -@Controller -public class orderUtil { - private static IUsersService usersService = SpringUtils.getBean(IUsersService.class); - private static IOrderLogService orderLogService = SpringUtils.getBean(IOrderLogService.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_8 = "暂停服务"; - //暂停服务 - private static final String TITLE_9 = "服务完成"; - - - - //1,根据用户手机号判断用户不存在,4如果不存在就要新增一个用户数据 - public Map isUser(String phone, String adressName) { - AmapUtils amapUtils = new AmapUtils(); - Map map = new HashMap(); - 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 isAddAdressUser(Users users, String adressName) { - Map map = new HashMap(); - UserAddress selectuserAddress = new UserAddress(); - selectuserAddress.setUid(users.getId()); - selectuserAddress.setAddressName(adressName); - List 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; - } - } - } - - //新增订单后添加订单记录 - 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()); - } - } - - } - orderLog.setTitle(TITLE_2); - jsonObject.put("name",TITLE_2_CONTENT_TYPE2); - orderLog.setType(new BigDecimal(1.1)); - } - //师傅同意接单 - if (order.getJsonStatus()==2){ - 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.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); - jsonObject=JSONObject.parseObject(order.getOrderLog().getContent()); - orderLog.setType(new BigDecimal(5.0)); - } - } - if (Objects.equals(order.getStatus(), 3L)){ - //开始服务 - if(order.getJsonStatus()==7){ - orderLog.setTitle(TITLE_7); - jsonObject=JSONObject.parseObject(order.getOrderLog().getContent()); - orderLog.setType(new BigDecimal(6.0)); - - } - //暂停服务 - if(order.getJsonStatus()==8){ - 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)); - - } - - } - orderLog.setRemark(order.getRemark()); - orderLog.setOid(order.getId()); - orderLog.setOrderId(order.getOrderId()); - orderLog.setContent(jsonObject.toJSONString()); - return orderLogService.insertOrderLog(orderLog); - } - - -} diff --git a/ruoyi-ui/src/api/system/Order.js b/ruoyi-ui/src/api/system/Order.js index 5687272..dd90f46 100644 --- a/ruoyi-ui/src/api/system/Order.js +++ b/ruoyi-ui/src/api/system/Order.js @@ -73,6 +73,16 @@ export function getCallRecords(orderId) { }) } +// 获取通话记录列表 +export function generateCode() { + return request({ + url: '/system/Order/generateCode/', + method: 'get' + }) +} + + + // 获取通话记录列表 export function getCommentRecords(orderId) { return request({ diff --git a/ruoyi-ui/src/views/system/Order/components/ReceiveRecord.vue b/ruoyi-ui/src/views/system/Order/components/ReceiveRecord.vue index fd1c007..f61639e 100644 --- a/ruoyi-ui/src/views/system/Order/components/ReceiveRecord.vue +++ b/ruoyi-ui/src/views/system/Order/components/ReceiveRecord.vue @@ -42,6 +42,7 @@
项目费用: ¥{{ item.project.price }}
+
基础项: {{ item.basic.map(b => b.name).join('、') }}
所需服务: {{ item.craft.map(c => `${c.name} ¥${c.price}*${c.count}`).join('、') }}
所需物料: {{ item.material.map(m => `${m.name} ¥${m.price}*${m.count}`).join('、') }}
@@ -49,6 +50,8 @@
{{ item.name || item.text }}
+
暂停原因:{{ item.pauseReason || item.text }}
+
下次服务时间:{{ item.nextServiceTime || item.text }}
- - - - - - - - - - + + @@ -508,14 +490,10 @@ - - - - - + - + - + - + @@ -723,6 +699,7 @@ v-model="form.pauseReason" type="textarea" placeholder="请输入暂停原因" + @change="handlePauseServiceData" /> @@ -734,18 +711,11 @@ placeholder="选择下次服务时间" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%" + @change="handlePauseServiceData" /> - - - - - + @@ -766,7 +736,9 @@ - + + + - -import { listOrder, getOrder, delOrder, addOrder, updateOrder,getUserDataList,getGoodsDataList,selectQuoteCraftList,selectQuoteMaterialList,selectBaseProjectList} from "@/api/system/Order" +import { listOrder, getOrder, delOrder, addOrder, updateOrder,getUserDataList,getGoodsDataList,selectQuoteCraftList,generateCode,selectQuoteMaterialList,selectBaseProjectList} from "@/api/system/Order" import { getuserAddressList } from "@/api/system/UserAddress" import CallRecord from './components/CallRecord' import AudioRecord from './components/AudioRecord' @@ -951,8 +922,10 @@ export default { productId: null, type: 1, num: 1, - totalPrice: null, - payPrice: null, + servicePrice:0, + goodPrice:0, + totalPrice: 0, + payPrice: 0, deduction: null, payTime: null, status: 1, // 默认待支付 @@ -1167,12 +1140,17 @@ export default { }, /** 新增按钮操作 */ handleAdd() { + this.generateCode() this.reset() // 初始化必要的数组 this.form.serviceItems = [] this.form.materials = [] this.form.price = 0 + this.form.servicePrice = 0 + this.form.goodPrice = 0 this.form.baseProject = [] // 初始化为空数组 + this.form.pauseReason = null // 初始化暂停原因 + this.form.nextServiceTime = null // 初始化下次服务时间 this.form.orderLog = { workerId: 1, workerName: null, @@ -1231,6 +1209,17 @@ export default { this.baseProjectList = [] }) }, + + + //获取报价材料列表 + generateCode(){ + generateCode().then(response => { + this.form.orderId=response.msg; + }) + }, + + + /** 修改按钮操作 */ handleUpdate(row) { this.reset() @@ -1301,6 +1290,13 @@ export default { url: url, uid: Date.now() + index })) + // 解析暂停原因和下次服务时间 + if (content.pauseReason) { + this.form.pauseReason = content.pauseReason; + } + if (content.nextServiceTime) { + this.form.nextServiceTime = content.nextServiceTime; + } } // 解析完成服务状态的图片数据(jsonStatus === 9) @@ -1533,23 +1529,46 @@ export default { this.form.jsonStatus = null; }, handlejsonStatusChange(value) { - // 重置相关字段 + // 智能重置相关字段,只重置与当前状态无关的字段 + + // 重置通用字段 this.form.workerId = null; this.form.departureTime = null; this.form.arrivalTime = null; this.form.projectCost = null; - this.form.baseProject = null; - this.form.serviceItems = []; - this.form.materials = []; - this.form.paymentMethod = 2; - this.form.deposit = 0; - this.form.startTime = null; - this.form.pauseTime = null; - this.form.pauseReason = null; - this.form.completeTime = null; this.form.doorFee = null; - this.form.servicePhotos = []; - this.form.nextServiceTime = null; // 重置下次服务时间 + + // 根据新状态决定是否重置特定字段 + if (value !== 6) { + // 如果不是项目报价状态,重置报价相关字段 + this.form.baseProject = []; + this.form.serviceItems = []; + this.form.materials = []; + this.form.paymentMethod = 2; + this.form.deposit = 0; + } + + if (value !== 7) { + // 如果不是开始服务状态,重置开始服务相关字段 + this.form.startTime = null; + } + + if (value !== 8) { + // 如果不是暂停服务状态,重置暂停相关字段 + this.form.pauseTime = null; + this.form.pauseReason = null; + this.form.nextServiceTime = null; + } + + if (value !== 9) { + // 如果不是完成服务状态,重置完成相关字段 + this.form.completeTime = null; + } + + // 只有在状态不是7、8、9时才重置服务照片 + if (value !== 7 && value !== 8 && value !== 9) { + this.form.servicePhotos = []; + } }, addServiceItem() { this.form.serviceItems.push({ @@ -1620,6 +1639,24 @@ export default { // 总价 = 项目费用 + 服务项目总价 + 物料总价 const totalPrice = parseFloat(this.form.price || 0) + craftTotal + materialTotal; + // 将计算出的总价赋值给订单金额字段 + this.form.totalPrice = totalPrice; + + // 将服务项目合计金额赋值给servicePrice + this.form.servicePrice = craftTotal; + + // 将物料合计金额赋值给goodPrice + this.form.goodPrice = materialTotal; + + // 根据支付方式设置支付金额 + if (this.form.paymentMethod === 1) { + // 定金+尾款模式,支付金额为定金 + this.form.payPrice = this.form.orderLog.deposit || 0; + } else { + // 一次性付清模式,支付金额为总价 + this.form.payPrice = totalPrice; + } + // 构建基础项目数组 const basicItems = this.form.baseProject.map(item => ({ name: item })); @@ -1643,7 +1680,7 @@ export default { name: "项目费用", price: totalPrice, paymentMethod: this.form.paymentMethod === 1 ? "定金+尾款" : "一次性付清", - deposit: this.form.paymentMethod === 1 ? this.form.deposit : 0 + deposit: this.form.paymentMethod === 1 ? this.form.orderLog.deposit : 0 }, basic: basicItems, craft: craftItems, @@ -1659,23 +1696,19 @@ export default { handlePhotoChange(file, fileList) { this.form.servicePhotos = fileList; - // 提取图片地址数组 - const imageUrls = fileList.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格式 if (this.form.jsonStatus === 7) { // 开始服务状态 + const imageUrls = fileList.map(file => { + if (file.response && file.response.url) { + return file.response.url; + } + if (file.url) { + return file.url; + } + return ''; + }).filter(url => url); + const serviceImageJson = { name: "师傅开始服务", image: imageUrls @@ -1684,16 +1717,21 @@ export default { console.log('开始服务图片JSON:', this.form.orderLog.content); } else if (this.form.jsonStatus === 8) { - // 暂停状态 - const pauseImageJson = { - name: "服务暂停", - image: imageUrls - }; - this.form.orderLog.content = JSON.stringify(pauseImageJson); - console.log('暂停服务图片JSON:', this.form.orderLog.content); + // 暂停状态 - 调用专门的处理方法 + this.handlePauseServiceData(); } else if (this.form.jsonStatus === 9) { // 完成服务状态 + const imageUrls = fileList.map(file => { + if (file.response && file.response.url) { + return file.response.url; + } + if (file.url) { + return file.url; + } + return ''; + }).filter(url => url); + const completeImageJson = { name: "服务完成", image: imageUrls @@ -1705,12 +1743,48 @@ export default { handlePaymentMethodChange(value) { if (value === 2) { // 如果选择一次性付清 this.form.orderLog.deposit = 0; // 清空定金 + this.form.payPrice = this.form.totalPrice; // 支付金额等于总价 + } else if (value === 1) { // 如果选择定金+尾款 + // 如果有定金,支付金额为定金;否则支付金额为0 + this.form.payPrice = this.form.orderLog.deposit || 0; } this.updateQuoteContent(); }, handleDepositChange() { + // 如果是定金+尾款模式,更新支付金额为定金金额 + if (this.form.paymentMethod === 1) { + this.form.payPrice = this.form.orderLog.deposit || 0; + } this.updateQuoteContent(); }, + // 处理暂停服务数据封装 + 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); + } + }, } }