package com.ruoyi.system.controller; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.ControllerUtil.*; import com.ruoyi.system.domain.*; import com.ruoyi.system.service.*; import com.winnerlook.model.VoiceResponseResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.service.IServiceGoodsService; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.system.domain.ServiceGoods; /** * 服务订单Controller * * @author ruoyi * @date 2025-05-13 */ @Api(tags = "订单管理接口") @RestController @RequestMapping("/system/Order") public class OrderController extends BaseController { @Autowired private IOrderService orderService; @Autowired private IServiceGoodsService serviceGoodsService; @Autowired private IUsersPayBeforService usersPayBeforService; @Autowired private IQuoteTypeService quoteTypeService; @Autowired private IQuoteCraftService quoteCraftService; @Autowired private IQuoteMaterialTypeService quoteMaterialTypeService; @Autowired private IQuoteMaterialService quoteMaterialService; @Autowired IUsersService usersService; @Autowired IOrderCallService orderCallService; @Autowired IOrderCommentService orderCommentService; @Autowired IOrderSoundLogService orderSoundLogService; @Autowired IOrderSoundService orderSoundService; @Autowired IUserAddressService userAddressService; @Autowired IOrderLogService orderLogService; @Autowired INotifyOrderService notifyOrderService; @Autowired private ISysUserService sysUserService; /** * 查询服务订单列表 */ @PreAuthorize("@ss.hasPermi('system:Order:list')") @GetMapping("/list") public TableDataInfo list(Order order) { startPage(); List list = orderService.selectOrderList(order); for (Order orderdata : list) { ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(orderdata.getProductId()); if (serviceGoods != null) { orderdata.setProductName(serviceGoods.getTitle()); } Users users = usersService.selectUsersById(orderdata.getUid()); if (users != null) { orderdata.setUname(users.getName()); } orderdata.setThjl(orderCallService.selectCountOrderCallByOid(orderdata.getId())); orderdata.setFwpj(orderCommentService.selectCountOrderCommentByOid(orderdata.getOrderId())); orderdata.setLywj(orderSoundService.selectCountOrderSoundByOid(orderdata.getId())); orderdata.setJdjl(orderLogService.selectCountOrderLogByOrderId(orderdata.getOrderId())); orderdata.setTzjl(notifyOrderService.selectNotifyOrderCountByOid(orderdata.getId())); } return getDataTable(list); } /** * 导出服务订单列表 */ @PreAuthorize("@ss.hasPermi('system:Order:export')") @Log(title = "服务订单", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, Order order) { // 使用导出专用的关联查询,一次性获取所有数据包括关联信息 List list = orderService.selectOrderListForExport(order); ExcelUtil util = new ExcelUtil(Order.class); util.exportExcel(response, list, "服务订单数据"); } /** * 获取服务订单详细信息 */ @PreAuthorize("@ss.hasPermi('system:Order:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { Order order = orderService.selectOrderById(id); if (order != null){ if(StringUtils.isBlank(order.getAdressjson())){ UserAddress userAddress=userAddressService.selectUserAddressById(order.getAddressId()); if (userAddress != null) { try { order.setAdressjson(JSON.toJSONString(userAddress)); orderService.updateOrder(order); } catch (Exception e) { order.setAdressjson(null); } } // Users users=usersService.selectUsersById(order.getUid()); // if() } order.setOrderLog(new OrderLog()); } return success(order); } /** * 师傅完成订单接口 * POST /api/worker/finish/service * 参数:{"id":订单id,"image":[图片url数组]} */ @PostMapping("/complete-service") public AjaxResult workerFinishService(@RequestBody Map params, HttpServletRequest request) throws Exception { if (params == null || params.get("orderId") == null) { return AppletControllerUtil.appletError("参数错误"); } String orderid; try { orderid = params.get("orderId").toString(); } catch (Exception e) { return AppletControllerUtil.appletError("订单ID格式错误"); } Order order = orderService.selectOrderByOrderId(orderid); if (order == null) { return AppletControllerUtil.appletError("订单不存在"); } String reamk = ""; String latitude = ""; String longitude = ""; String addressName = ""; PayBeforeUtil payBeforeUtil = new PayBeforeUtil(); String priceDifferenceprice= "0"; // int paynum=usersPayBeforService.countByLastOrderIdAndStatus(order.getOrderId()); // //如果订单没有支付 // if (paynum<=0){ // // 1. 修改订单状态 // order.setStatus(6L); // 完成 // order.setReceiveType(3L); // 完成类型 // order.setJsonStatus(9); // 完成 // order.setLogJson("{\"type\":8}"); // int update = orderService.updateOrder(order); // } // 2. 组装日志内容 Map logContent = new LinkedHashMap<>(); if (StringUtils.isNotBlank(reamk)) { logContent.put("name","师傅服务完成--"+ reamk); }else{ logContent.put("name", "师傅服务完成"); } logContent.put("image", params.get("image")); String contentStr = com.alibaba.fastjson2.JSONObject.toJSONString(logContent); // 3. 写入订单日志 OrderLog log = new OrderLog(); log.setOid(order.getId()); log.setOrderId(order.getOrderId()); log.setLogOrderId(GenerateCustomCode.generCreateOrder("DSB")); log.setTitle("服务完成"); log.setLatitude(latitude); log.setLongitude(longitude); log.setAddressName(addressName); log.setType(new java.math.BigDecimal(7)); log.setContent(contentStr); log.setWorkerId(order.getWorkerId()); log.setCreatedAt(new Date()); if (StringUtils.isNotBlank(priceDifferenceprice)) { log.setCjMoney(new BigDecimal(priceDifferenceprice)); log.setCjPaid(1L); } orderLogService.insertOrderLog(log); //如果有补差价,就要插入日志中进行处理 if (StringUtils.isNotBlank(priceDifferenceprice)) { log.setCjMoney(new BigDecimal(priceDifferenceprice)); log.setCjPaid(1L); Users userinfo = usersService.selectUsersById(order.getUid()); payBeforeUtil.createPayBefore(userinfo, log.getCjMoney(), log.getLogOrderId(), log.getId(), null, 10L, null, null, null, null, null,1L,null,order.getOrderId(), null); } //判断这个订单还有没有未支付的数据,如果有就停留在服务中如果没有就直接去到状态为4的已完成状态 int paynum=usersPayBeforService.countByLastOrderIdAndStatus(order.getOrderId()); //如果订单没有支付,订单完成,分佣,推送 if (paynum<=0){ //师傅完成时,确认没有可支付的信息,就可以分佣,让这个订单结束 OrderUtil.ISTOPAYSIZE(order.getOrderId()); order.setStatus(4L); // 完成 order.setReceiveType(3L); // 完成类型 order.setJsonStatus(9); // 完成 order.setLogJson("{\"type\":8}"); int update = orderService.updateOrder(order); Users wusers = usersService.selectUsersById(order.getWorkerId()); WorkerCommissionUtil.processWorkerCommission(order,wusers); Users users = usersService.selectUsersById(order.getUid()); ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); WXsendMsgUtil.sendWorkerFinishOrder(users.getOpenid(), order, serviceGoods); }else{ order.setStatus(6L); // 完成 order.setJsonStatus(9); // 完成 int update = orderService.updateOrder(order); } return AppletControllerUtil.appletSuccess("服务已完成"); } // /** // * 完成服务接口 // */ // @PreAuthorize("@ss.hasPermi('system:Order:edit')") // @Log(title = "完成服务", businessType = BusinessType.UPDATE) // @PostMapping("/complete-service") // public AjaxResult completeService(@RequestBody Map params) { // try { // // 参数验证 // if (params == null || params.isEmpty()) { // return error("请求参数不能为空"); // } // // String orderId = params.get("orderId") != null ? params.get("orderId").toString() : null; // if (orderId == null || orderId.trim().isEmpty()) { // return error("订单号不能为空"); // } // // // 查询订单信息 // Order order = orderService.selectOrderByOrderId(orderId); // if (order == null) { // return error("订单不存在"); // } // // // 验证订单状态(只有服务中状态的订单才能完成服务) // if (order.getStatus() == null || order.getStatus() != 3L) { // return error("当前订单状态不可完成服务,只有服务中状态的订单才能完成服务"); // } // // // 验证是否已分配师傅 // if (order.getWorkerId() == null) { // return error("订单未分配师傅,无法完成服务"); // } // // // 验证师傅是否已接单 // if (order.getIsAccept() == null || order.getIsAccept() != 1) { // return error("师傅未接单,无法完成服务"); // } // // // 验证订单进度状态(应该是服务中状态) // if (order.getJsonStatus() == null || order.getJsonStatus() != 7) { // return error("订单进度状态不正确,只有服务中状态的订单才能完成服务"); // } // // // TODO: 在这里添加您的具体业务逻辑 // // 例如: // // 1. 更新订单状态为已完成 // // 2. 记录完成时间 // // 3. 计算服务费用 // // 4. 生成支付订单 // // 5. 发送通知等 // // return success("完成服务成功"); // } catch (Exception e) { // return error("完成服务失败:" + e.getMessage()); // } // } // ... existing code ... /** * 获取服务订单最新的日志状态用来判断页面的操作 */ @PreAuthorize("@ss.hasPermi('system:Order:query')") @GetMapping(value = "/orderlog/{id}") public AjaxResult getorderlogInfo(@PathVariable("id") Long id) { Order order = orderService.selectOrderById(id); if (order != null){ order.setOrderLog(new OrderLog()); } OrderLog orderLog = orderLogService.selectDataTheFirstNew(id); return success(orderLog.getType()); } /** * 获取服务订单详细信息 */ @PreAuthorize("@ss.hasPermi('system:Order:query')") @GetMapping(value = "generateCode") public AjaxResult generateCode() { return success(OrderUtil.generateCode()); } /** * 新增服务订单 */ @PreAuthorize("@ss.hasPermi('system:Order:add')") @Log(title = "服务订单", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody Order order) { Order orderdata=new Order(); Users users = usersService.selectUsersById(order.getUid()); if (users == null){ return error("用户不能为空"); } UserAddress userAddress = userAddressService.selectUserAddressById(order.getAddressId()); if (userAddress == null){ return error("地址不能为空"); } ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); if (serviceGoods == null){ return error("服务不能为空"); } orderdata.setType(1); orderdata.setMainOrderId(GenerateCustomCode.generCreateOrder("HT")); orderdata.setOrderId(GenerateCustomCode.generCreateOrder("SE")); orderdata.setCreateType(1); orderdata.setCreatePhone(users.getPhone()); orderdata.setUid(users.getId()); orderdata.setProductId(serviceGoods.getId()); orderdata.setName(userAddress.getName()); orderdata.setPhone(userAddress.getPhone()); orderdata.setAddress(userAddress.getAddressName()); orderdata.setMakeTime(order.getMakeTime()); orderdata.setMakeHour(order.getMakeHour()); orderdata.setNum(order.getNum()); orderdata.setTotalPrice(new BigDecimal(0)); orderdata.setGoodPrice(new BigDecimal(0)); orderdata.setPayPrice(new BigDecimal(0)); orderdata.setDeduction(new BigDecimal(0)); orderdata.setStatus(1L); orderdata.setIsPause(1); orderdata.setMark(order.getMark()); orderdata.setAddressId(userAddress.getId()); orderdata.setSku(order.getSku()); //orderdata.setReceiveTime(); orderdata.setIsComment(0); orderdata.setReceiveType(3L); orderdata.setIsAccept(0); orderdata.setUidAdmin(String.valueOf(users.getId())); orderdata.setAddressAdmin(String.valueOf(userAddress.getId())); orderdata.setLogStatus(9); JSONObject logJson=new JSONObject(); logJson.put("type",9); orderdata.setLogJson(logJson.toJSONString()); orderdata.setJsonStatus(0); if(StringUtils.isNotBlank(order.getFileData())){ orderdata.setFileData(AppletControllerUtil.convertToJSONArray(order.getFileData()).toJSONString()); } //orderdata.setFileData(order.getFileData()); orderdata.setOdertype(0); orderdata.setReamk(order.getReamk()); orderdata.setBigtype(1); orderdata.setAddressEn(userAddress.getAddressName()); if (userAddress != null) { try { order.setAdressjson(JSON.toJSONString(userAddress)); } catch (Exception e) { order.setAdressjson(null); } } //添加订单日志记录 int flg= orderService.insertOrder(orderdata); if (flg>0){ // 添加订单日志 OrderLog orderLog = new OrderLog(); orderLog.setOid(orderdata.getId()); orderLog.setOrderId(orderdata.getOrderId()); orderLog.setTitle("订单生成"); orderLog.setType(BigDecimal.valueOf(1.0)); com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject(); jsonObject.put("name", "后台订单创建成功"); orderLog.setContent(jsonObject.toJSONString()); orderLogService.insertOrderLog(orderLog); } return success("操作成功"); } /** * 获取服务订单详细信息 */ @PreAuthorize("@ss.hasPermi('system:Order:query')") @GetMapping(value = "/selectBaseProjectList/{id}") public AjaxResult selectBaseProjectList(@PathVariable("id") Long id) { Order order = orderService.selectOrderById(id); if (order != null){ ServiceGoods serviceGoods=serviceGoodsService.selectServiceGoodsById(order.getProductId()); if(serviceGoods!=null){ return success(serviceGoods); }else{ return error(); } }else{ return error(); } } /** * 修改服务订单 */ @PreAuthorize("@ss.hasPermi('system:Order:edit')") @Log(title = "服务订单", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody Order 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()); } } /** * 删除服务订单 */ @PreAuthorize("@ss.hasPermi('system:Order:remove')") @Log(title = "服务订单", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(orderService.deleteOrderByIds(ids)); } /** * 获取订单接单记录 */ @PreAuthorize("@ss.hasPermi('system:Order:query')") @GetMapping("/receive-records/{orderId}") public AjaxResult getReceiveRecords(@PathVariable("orderId") String orderId) { System.out.println("=== 获取接单记录 ==="); System.out.println("订单ID: " + orderId); List list = orderLogService.selectOrderLogByOrderIdASC(orderId); System.out.println("查询到的日志记录数量: " + (list != null ? list.size() : "null")); if (list != null && !list.isEmpty()) { System.out.println("第一条记录: " + list.get(0)); for (OrderLog orderLogdata : list) { System.out.println("处理日志记录: ID=" + orderLogdata.getId() + ", 标题=" + orderLogdata.getTitle()); if (orderLogdata.getWorkerId() != null) { Users users = usersService.selectUsersById(orderLogdata.getWorkerId()); if (users != null) { orderLogdata.setWorkerName(users.getName()); System.out.println("设置师傅姓名: " + users.getName()); } else { System.out.println("未找到师傅信息,workerId: " + orderLogdata.getWorkerId()); } } else { System.out.println("日志记录没有师傅ID"); } } } else { System.out.println("没有找到订单日志记录"); } return success(list); } // /** // * 获取订单通话记录 // */ @PreAuthorize("@ss.hasPermi('system:Order:query')") @GetMapping("/call-records/{orderId}") public AjaxResult getCallRecords(@PathVariable("orderId") String orderId) { Order data = orderService.selectOrderByOrderId(orderId); ; if (data != null) { return success(orderCallService.selectOrderCallByOid(data.getId())); } else { return AjaxResult.error("订单不存在"); } } /** * 获取订单录音文件 */ @PreAuthorize("@ss.hasPermi('system:Order:query')") @GetMapping("/audio-records/{orderId}") public AjaxResult getAudioRecords(@PathVariable("orderId") String orderId) { Order data = orderService.selectOrderByOrderId(orderId); ; if (data != null) { List list = orderSoundService.selectOrderSoundByOid(data.getId()); for (OrderSound orderSounddata : list) { orderSounddata.setFile("https://img.huafurenjia.cn/" + orderSounddata.getFile()); // https://img.huafurenjia.cn/ Users users = usersService.selectUsersById(orderSounddata.getWorkerUid()); Order order = orderService.selectOrderById(orderSounddata.getOid()); if (users != null) { orderSounddata.setWorkerName(users.getName()); } if (order != null) { orderSounddata.setOcode(order.getOrderId()); } } return success(list); } else { return AjaxResult.error("订单不存在"); } } /** * 获取订单通知记录 */ @PreAuthorize("@ss.hasPermi('system:Order:query')") @GetMapping("/notify-records/{orderId}") public AjaxResult getNotifyRecords(@PathVariable("orderId") String orderId) { Order data = orderService.selectOrderByOrderId(orderId); ; if (data != null) { return success(notifyOrderService.selectNotifyOrderByOid(data.getId())); } else { return AjaxResult.error("订单不存在"); } } /** * 获取订单通知记录 */ @PreAuthorize("@ss.hasPermi('system:Order:query')") @GetMapping("/comment-records/{orderId}") public AjaxResult getCommentRecords(@PathVariable("orderId") String orderId) { Order data = orderService.selectOrderByOrderId(orderId); ; if (data != null) { List list = orderCommentService.selectOrderCommentByOid(data.getOrderId()); for (OrderComment orderCommentdata : list) { Users users = usersService.selectUsersById(orderCommentdata.getUid()); if (users != null) { orderCommentdata.setUname(users.getName()); } } return success(list); } else { return AjaxResult.error("订单不存在"); } } /** * 获取用户下拉列表 */ @GetMapping("/userOptions") public AjaxResult getUserOptions() { List users = sysUserService.selectUserList(new SysUser()); return AjaxResult.success(users); } /** * 获取商品下拉列表 */ @GetMapping("/serviceGoodsOptions") public AjaxResult getServiceGoodsOptions() { List goods = serviceGoodsService.selectServiceGoodsList(new ServiceGoods()); return AjaxResult.success(goods); } /** * 派单接口 */ @PreAuthorize("@ss.hasPermi('system:Order:edit')") @Log(title = "订单派单", businessType = BusinessType.UPDATE) @PostMapping("/dispatch") public AjaxResult dispatch(@RequestBody Map params) { try { Long orderId = Long.valueOf(params.get("orderId").toString()); Integer receiveType = Integer.valueOf(params.get("receiveType").toString()); Long workerId = null; if (params.get("workerId") != null) { workerId = Long.valueOf(params.get("workerId").toString()); } // 查询师傅 Users users = usersService.selectUsersById(workerId); if (users == null) { return error("工人不存在"); } // 查询订单 Order order = orderService.selectOrderById(orderId); if (order == null) { return error("订单不存在"); } // // 验证订单状态 // if (order.getStatus() != 1) { // return error("只有待接单状态的订单才能派单"); // } if (order.getWorkerId()!=null){ //给师傅派单的时候的推送 ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); WXsendMsgUtil.sendMsgForWorkerInfo(users.getOpenid(), order, serviceGoods); DispatchUtil.creatWorkerForOrder(order,users); }else{ changeWorkerOrder(order.getId(), workerId); } // // // 更新订单的派单类型 // order.setReceiveType(receiveType.longValue()); // // // 如果是指定工人,需要验证工人信息 // if (receiveType == 3 && workerId != null) { // // 这里可以添加工人验证逻辑 // // 暂时跳过工人验证 // } // // // 更新订单状态为待服务 // order.setStatus(2L); return toAjax(1); } catch (Exception e) { return error("派单失败:" + e.getMessage()); } } public AjaxResult changeWorkerOrder(Long orderId,Long newWorkerId) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 1. 查询订单 Order order = orderService.selectOrderById(orderId); if (order == null) { return AjaxResult.error("订单不存在"); } // 2. 查询新师傅信息 Users newWorker = usersService.selectUsersById(newWorkerId); if (newWorker == null) { return AjaxResult.error("新师傅不存在"); } // 3. 查询原师傅信息 Users oldWorker = null; if (order.getWorkerId() != null) { oldWorker = usersService.selectUsersById(order.getWorkerId()); } // 4. 修改订单的师傅id order.setWorkerId(newWorkerId); order.setStatus(1L); order.setIsAccept(0); int updateOrder = orderService.updateOrder(order); if (updateOrder <= 0) { return AjaxResult.error("订单更新失败"); } //查询最新的订单日志 OrderLog log = orderLogService.selectDataTheFirstNew(order.getId()); OrderLog log1 = new OrderLog(); log1.setOid(order.getId()); //原订单日志下所有师傅id需更换为新的师傅id List logList = orderLogService.selectOrderLogList(log1); if (!logList.isEmpty()) { for (OrderLog l : logList) { if (l.getWorkerId() != null) { l.setWorkerId(newWorkerId); orderLogService.updateOrderLog(l); } } } //如果订单状态为6就继续做 if (log.getType().compareTo(new BigDecimal("6.0")) == 0) { // 2. 组装日志内容为数组格式 Map logItem = new LinkedHashMap<>(); JSONArray jsonArray = JSONArray.parseArray(log.getContent()); logItem.put("name", "师傅" + newWorker.getName() + "将继续为您服务 不需要预约时间"); logItem.put("name", "暂停服务"); logItem.put("image", ""); logItem.put("reson", "由于订单师傅更换,自动暂停服务"); logItem.put("next_time", ""); logItem.put("type", 2); logItem.put("date", sdf.format(new Date())); jsonArray.add(logItem); if (log != null) { log.setIsPause(2); log.setContent(jsonArray.toJSONString()); orderLogService.updateOrderLog(log); order.setIsPause(2); order.setWorkerId(newWorkerId); orderService.updateOrder(order); } } else { // 5. 插入转单日志 OrderLog newlog = new OrderLog(); if (log.getType().compareTo(new BigDecimal("5.0")) == 0) { newlog.setType(new BigDecimal(6.0)); } else { newlog.setType(new BigDecimal(1.1)); } com.alibaba.fastjson2.JSONObject jsonObjectnew = new com.alibaba.fastjson2.JSONObject(); jsonObjectnew.put("name", "师傅" + newWorker.getName() + "将继续为您服务 不需要预约时间"); jsonObjectnew.put("convert", oldWorker.getName() + "将订单转给" + newWorker.getName()); newlog.setContent(jsonObjectnew.toJSONString()); newlog.setOid(order.getId()); newlog.setOrderId(order.getOrderId()); newlog.setWorkerId(newWorkerId); newlog.setWorkerLogId(newWorkerId); newlog.setTitle("转单"); newlog.setIsPause(2); orderLogService.insertOrderLog(newlog); //需要解绑原订单上原师傅和客户的虚拟号 VoiceResponseResult resultObj = YunXinPhoneUtilAPI.httpsPrivacyUnbind(order.getWorkerPhone(), order.getUserPhone(), order.getMiddlePhone(), order.getId()); if (resultObj.getResult().equals("000000")) { orderService.updateOrderPhone(order.getId()); // orderService.updateOrder(order); } //绑定新师傅的虚拟号 //给新师傅进行电话通知 YunXinPhoneUtilAPI.httpsAxbTransfer(newWorker.getPhone(), order.getId()); } return AjaxResult.success("转单成功"); } catch (Exception e) { return AjaxResult.error("转单失败:" + e.getMessage()); } } /** * 获取可派单工人列表 */ @PreAuthorize("@ss.hasPermi('system:Order:query')") @GetMapping("/getCanDoWorkerList") public TableDataInfo getCanDoWorkerList(Users users) { startPage(); List list = usersService.selectUsersList(users); return getDataTable(list); } /** * 获取所有工人列表(用于订单处理) */ @PreAuthorize("@ss.hasPermi('system:Order:edit')") @GetMapping("/getWorkerList") public AjaxResult getWorkerList() { Users users = new Users(); users.setType("2"); // 工人类型 List list = usersService.selectUsersList(users); return AjaxResult.success(list); } /** * 更换师傅接口 */ @PreAuthorize("@ss.hasPermi('system:Order:edit')") @Log(title = "更换师傅", businessType = BusinessType.UPDATE) @PostMapping("/change-worker") public AjaxResult changeWorker(@RequestBody Map params) { try { String orderId = params.get("orderId").toString(); // 这里调用具体的业务逻辑,您来实现 // 例如:调用DispatchUtil进行重新派单 return success("更换师傅成功"); } catch (Exception e) { return error("更换师傅失败:" + e.getMessage()); } } /** * 接单接口 */ @PreAuthorize("@ss.hasPermi('system:Order:edit')") @Log(title = "订单接单", businessType = BusinessType.UPDATE) @PostMapping("/accept-order") public AjaxResult acceptOrder(@RequestBody Map params) { try { String orderId = params.get("orderId").toString(); // Long workerId = null; // if (params.get("workerId") != null) { // workerId = Long.valueOf(params.get("workerId").toString()); // } // 2. 查询订单 Order order = orderService.selectOrderByOrderId(orderId); if (order == null) { return error("订单不存在"); } Long workerId =order.getWorkerId(); // 如果没有传递workerId,使用订单中的workerId // if (workerId == null) { // workerId = order.getWorkerId(); // } if (workerId == null) { return error("订单未分配师傅,无法接单"); } Users worker = usersService.selectUsersById(workerId); if (worker == null) { return error("工人不存在"); } // 3. 验证订单状态(允许状态1和2的订单接单) if (order.getStatus() == null || (order.getStatus() != 1L && order.getStatus() != 2L)) { return error("当前订单状态不可接单,只有待支付或待服务状态的订单才能接单"); } // 4. 设置接单相关字段 order.setWorkerId(worker.getId()); order.setWorkerPhone(worker.getPhone()); order.setIsPause(1); // 1:未暂停 order.setReceiveType(3L); // 3:平台派单 order.setReceiveTime(new Date()); order.setIsAccept(1); // 1:已接单 order.setJsonStatus(2); // 服务进度:2=接单 order.setStatus(2L); // 设置为待服务状态 order.setLogStatus(9); com.alibaba.fastjson2.JSONObject json = new com.alibaba.fastjson2.JSONObject(); json.put("type", 1); order.setLogJson(json.toJSONString()); // 更新订单 int updateResult = orderService.updateOrder(order); if (updateResult <= 0) { return error("更新订单失败"); } // 5. 写入日志 OrderLog orderLog = new OrderLog(); orderLog.setOid(order.getId()); orderLog.setOrderId(order.getOrderId()); orderLog.setTitle("师傅接单"); orderLog.setType(new BigDecimal(2.0)); orderLog.setCreatedAt(new Date()); com.alibaba.fastjson2.JSONObject logContent = new com.alibaba.fastjson2.JSONObject(); logContent.put("name", "同意系统配单"); orderLog.setContent(logContent.toJSONString()); orderLog.setWorkerId(order.getWorkerId()); orderLog.setWorkerLogId(order.getWorkerId()); int logResult = orderLogService.insertOrderLog(orderLog); if (logResult <= 0) { return error("记录接单日志失败"); } // 6. 绑定号码(如果有相关工具类) try { Map bindmap = OrderBindWorkerUtil.getOrderBindWorker(order.getId()); // 这里可以处理绑定结果 } catch (Exception e) { // 绑定失败不影响接单流程 System.out.println("绑定号码失败:" + e.getMessage()); } return success("接单成功"); } catch (Exception e) { return error("接单失败:" + e.getMessage()); } } /** * 出发上门接口 */ @PreAuthorize("@ss.hasPermi('system:Order:edit')") @Log(title = "出发上门", businessType = BusinessType.UPDATE) @PostMapping("/departure") public AjaxResult departure(@RequestBody Map params) { try { // 参数验证 if (params == null || params.isEmpty()) { return error("请求参数不能为空"); } String orderId = params.get("orderId") != null ? params.get("orderId").toString() : null; if (orderId == null || orderId.trim().isEmpty()) { return error("订单号不能为空"); } // 查询订单信息 Order order = orderService.selectOrderByOrderId(orderId); if (order == null) { return error("订单不存在"); } // 验证订单状态(只有已接单状态的订单才能出发上门) if (order.getStatus() == null || order.getStatus() != 2L) { return error("当前订单状态不可出发上门,只有已接单状态的订单才能出发上门"); } // 验证是否已分配师傅 if (order.getWorkerId() == null) { return error("订单未分配师傅,无法出发上门"); } // 验证师傅是否已接单 if (order.getIsAccept() == null || order.getIsAccept() != 1) { return error("师傅未接单,无法出发上门"); } // if (order.getStatus() == null || order.getStatus() != 2L) { // return AppletControllerUtil.appletWarning("订单状态不正确"); // } // if (order.getJsonStatus() == null || order.getJsonStatus() != 3) { // return AppletControllerUtil.appletWarning("订单进度不正确"); // } order.setJsonStatus(4); // 出发上门 com.alibaba.fastjson2.JSONObject typeJson = new com.alibaba.fastjson2.JSONObject(); typeJson.put("type", 3); order.setLogJson(typeJson.toJSONString()); // 5. 保存 orderService.updateOrder(order); // 4. 写订单日志 OrderLog orderLog = new OrderLog(); orderLog.setOid(order.getId()); orderLog.setOrderId(order.getOrderId()); orderLog.setWorkerId(order.getWorkerId()); orderLog.setWorkerLogId(order.getWorkerId()); orderLog.setTitle("出发上门"); com.alibaba.fastjson2.JSONObject typeJson1 = new com.alibaba.fastjson2.JSONObject(); typeJson1.put("name", "师傅收到派单信息准备出发"); orderLog.setType(new BigDecimal("3.0")); orderLog.setContent(typeJson1.toJSONString()); orderLogService.insertOrderLog(orderLog); ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); Users user=usersService.selectUsersById(order.getUid()); //小程序推送给用户师傅已经出发 WXsendMsgUtil.sendStartDoorMoney(user.getOpenid(), order, serviceGoods); return success("出发上门成功"); } catch (Exception e) { return error("出发上门失败:" + e.getMessage()); } } /** * 确认到达接口 */ @PreAuthorize("@ss.hasPermi('system:Order:edit')") @Log(title = "确认到达", businessType = BusinessType.UPDATE) @PostMapping("/confirm-arrival") public AjaxResult confirmArrival(@RequestBody Map params) { try { // 参数验证 if (params == null || params.isEmpty()) { return error("请求参数不能为空"); } String orderId = params.get("orderId") != null ? params.get("orderId").toString() : null; if (orderId == null || orderId.trim().isEmpty()) { return error("订单号不能为空"); } // 查询订单信息 Order order = orderService.selectOrderByOrderId(orderId); if (order == null) { return error("订单不存在"); } // 验证订单状态(只有已出发上门状态的订单才能确认到达) if (order.getStatus() == null || order.getStatus() != 2L) { return error("当前订单状态不可确认到达,只有已出发上门状态的订单才能确认到达"); } // 验证是否已分配师傅 if (order.getWorkerId() == null) { return error("订单未分配师傅,无法确认到达"); } // 验证师傅是否已接单 if (order.getIsAccept() == null || order.getIsAccept() != 1) { return error("师傅未接单,无法确认到达"); } // 验证订单进度状态(应该是出发上门状态) if (order.getJsonStatus() == null || order.getJsonStatus() != 4) { return error("订单进度状态不正确,只有出发上门状态的订单才能确认到达"); } order.setJsonStatus(5); // 确认到达 com.alibaba.fastjson2.JSONObject typeJson = new com.alibaba.fastjson2.JSONObject(); typeJson.put("type", 4); order.setLogJson(typeJson.toJSONString()); // 6. 保存 orderService.updateOrder(order); // 5. 写订单日志 //一口价直接开始服务,没有报价的环节 // if (order.getOdertype()!= 0){ // OrderLog orderLog = new OrderLog(); // orderLog.setOid(order.getId()); // orderLog.setOrderId(order.getOrderId()); // orderLog.setWorkerId(workerId); // orderLog.setLatitude(latitude); // orderLog.setLongitude(longitude); // orderLog.setAddressName(addressName); // orderLog.setWorkerLogId(workerId); // orderLog.setTitle("师傅到达"); // orderLog.setType(new BigDecimal("5.0")); // com.alibaba.fastjson2.JSONObject content = new com.alibaba.fastjson2.JSONObject(); // content.put("name", "师傅到达服务地点,开始服务工作"); // orderLog.setContent(content.toJSONString()); // // 6. 保存 // orderLogService.insertOrderLog(orderLog); // ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); // // WXsendMsgUtil.sendMsgForWorkerInfo(user.getOpenid(), order, serviceGoods); // return AppletControllerUtil.appletSuccess("师傅已经上门"); // } OrderLog orderLog = new OrderLog(); orderLog.setOid(order.getId()); orderLog.setOrderId(order.getOrderId()); orderLog.setWorkerId(order.getWorkerId()); orderLog.setWorkerLogId(order.getWorkerId()); orderLog.setTitle("师傅到达"); orderLog.setType(new BigDecimal("4.0")); com.alibaba.fastjson2.JSONObject content = new com.alibaba.fastjson2.JSONObject(); content.put("name", "师傅到达服务地点"); orderLog.setContent(content.toJSONString()); // 6. 保存 orderLogService.insertOrderLog(orderLog); //解绑订单虚拟号 //需要解绑原订单上原师傅和客户的虚拟号 VoiceResponseResult resultObj = YunXinPhoneUtilAPI.httpsPrivacyUnbind(order.getWorkerPhone(), order.getUserPhone(), order.getMiddlePhone(), order.getId()); if (resultObj.getResult().equals("000000")) { // order.setWorkerPhone(null); // order.setUserPhone(null); // order.setMiddlePhone(null); // orderService.updateOrder(order); orderService.updateOrderPhone(order.getId()); } // 4. 更新订单状 //解绑号码 // YunXinPhoneUtilAPI.httpsPrivacyUnbind(order.getWorkerPhone(), order.getUserPhone(), order.getMiddlePhone()); // 小程序推送给用户师傅已经到达 ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); //师傅到达的时候给客户的微信推送 Users user = usersService.selectUsersById(order.getUid()); WXsendMsgUtil.sendWorkerIsComing(user.getOpenid(), order, serviceGoods); return success("确认到达成功"); } catch (Exception e) { return error("确认到达失败:" + e.getMessage()); } } /** * 结束订单接口 */ @PreAuthorize("@ss.hasPermi('system:Order:edit')") @Log(title = "结束订单", businessType = BusinessType.UPDATE) @PostMapping("/end-order") public AjaxResult endOrder(@RequestBody Map params) { try { // 参数校验 if (params == null || params.isEmpty()) { return error("请求参数不能为空"); } String orderId = params.get("orderId") != null ? params.get("orderId").toString() : null; if (orderId == null || orderId.trim().isEmpty()) { return error("订单号不能为空"); } String doorFee=params.get("doorFee") != null ? params.get("doorFee").toString() : null; // 查询订单 Order order = orderService.selectOrderByOrderId(orderId); if (order == null) { return error("订单不存在"); } RefundUtil refundUtil = new RefundUtil(); // 3.1 更新订单状态为7(已结束) Order updateOrder = new Order(); updateOrder.setId(order.getId()); updateOrder.setStatus(7L); updateOrder.setServicePrice(new BigDecimal(0)); updateOrder.setGoodPrice(new BigDecimal(0)); updateOrder.setTotalPrice(new BigDecimal(0)); orderService.updateOrder(updateOrder); String logOrderId = GenerateCustomCode.generCreateOrder("DSB"); // 3.2 插入订单日志 OrderLog log = new OrderLog(); com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject(); //1.1结束订单就要删除客户未支付的付款数据 UsersPayBefor payBefor = new UsersPayBefor(); payBefor.setLastorderid(order.getOrderId()); payBefor.setStatus(1L); List payBeforList = usersPayBeforService.selectUsersPayBeforList(payBefor); for (UsersPayBefor payBeforInfo : payBeforList) { usersPayBeforService.deleteUsersPayBeforById(payBeforInfo.getId()); } //1.2如果这个订单有支付数据,还要给客户退回去 UsersPayBefor userpayBefor = usersPayBeforService.selectUsersPayBeforByOrderId(order.getOrderId()); if (userpayBefor != null) { Users user = usersService.selectUsersById(order.getUid()); //退回其他对应支付时产生的金额和积分 BenefitPointsUtil.refundServiceAndConsumption(order.getId(), user, userpayBefor.getServicemoney(),userpayBefor.getShopmoney()); System.out.println("=== 开始退款处理,2222222222订单号: " + userpayBefor.getStatus() + " ==="); // if (usersPayBefor.getStatus() == 2){ System.out.println("=== 开始退款处理,2222222222订单号: " + order.getOrderId() + " ==="); refundUtil.refundOrder(order.getOrderId()); // } } //1.3找到订单日志的报价数据将报价的支付数据给抹除 OrderLog orderLog = new OrderLog(); orderLog.setOrderId(order.getOrderId()); orderLog.setType(new BigDecimal(5)); List orderLogList = orderLogService.selectOrderLogList(orderLog); if (!orderLogList.isEmpty()) { orderLogService.updateOrderLogEnd(orderLogList.getFirst().getId()); } if (StringUtils.isNotBlank(doorFee)&&!doorFee.equals("0")){ log.setPaid(1L); log.setPrice(new BigDecimal(doorFee)); jsonObject.put("name","师傅提前结束订单,上门费"+doorFee+"元"); }else{ jsonObject.put("name","师傅提前结束订单,无其他费用"); } log.setLogOrderId(logOrderId); log.setOid(order.getId()); log.setOrderId(order.getOrderId()); log.setTitle("结束订单"); log.setType(BigDecimal.valueOf(10)); log.setContent(jsonObject.toJSONString()); //Long workerId = getCurrentWorkerId(request); // 需实现 log.setWorkerId(order.getWorkerId()); log.setCreatedAt(new Date()); log.setUpdatedAt(new Date()); orderLogService.insertOrderLog(log); if (StringUtils.isNotBlank(doorFee)){ BigDecimal totalAmount=log.getPrice(); Users userinfo = usersService.selectUsersById(order.getUid()); PayBeforeUtil payBeforeUtil = new PayBeforeUtil(); payBeforeUtil.createPayBefore(userinfo, totalAmount, logOrderId, log.getId(), null, 7L, null, null, null, null, null,1L,null,order.getOrderId(), null); ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); //微信推送师傅设置上门费 WXsendMsgUtil.sendMsgForUserDoorMoney(userinfo.getOpenid(), order, serviceGoods); } // 3.4 解绑虚拟号 if (order.getMiddlePhone() != null) { VoiceResponseResult unbind = YunXinPhoneUtilAPI.httpsPrivacyUnbind(order.getWorkerPhone(), order.getUserPhone(), order.getMiddlePhone(), order.getId()); if (unbind.getResult().equals("000000")) { orderService.updateOrderPhone(order.getId()); } } // return AjaxResult.success("订单结束成功"); return success("订单已结束"); } catch (Exception e) { return error("结束订单失败:" + e.getMessage()); } } // /** // * 开始服务接口 // */ // @PreAuthorize("@ss.hasPermi('system:Order:edit')") // @Log(title = "开始服务", businessType = BusinessType.UPDATE) // @PostMapping("/start-service") // public AjaxResult startService(@RequestBody Map params) { // try { // String orderId = params.get("orderId").toString(); // String image = params.get("image").toString(); // if (StringUtils.isBlank(image)) { // return error("需上传图片"); // } // Order order = orderService.selectOrderByOrderId(orderId); // if (order == null) { // return error("订单不存在"); // } // // OrderLog newlogdata =new OrderLog(); // newlogdata.setType(new BigDecimal("6.0")); // newlogdata.setOid(order.getId()); // //如果没有进行服务的记录就是开启服务 // List logList = orderLogService.selectOrderLogList(newlogdata); // if (logList.isEmpty()){ // // 2. 组装日志内容为数组格式 // Map logItem = new LinkedHashMap<>(); // logItem.put("name", "师傅开始服务"); // logItem.put("image", params.get("image")); // logItem.put("type", 1); // List logArr = new ArrayList<>(); // logArr.add(logItem); // String contentStr = com.alibaba.fastjson2.JSONObject.toJSONString(logArr); // // 3. 写入订单日志 // OrderLog log = new OrderLog(); // log.setOid(order.getId()); // log.setOrderId(order.getOrderId()); // log.setTitle("开始服务"); // log.setType(new BigDecimal(6.0)); // log.setContent(contentStr); // log.setWorkerId(order.getWorkerId()); // log.setWorkerLogId(order.getWorkerId()); // log.setIsPause(1); // log.setCreatedAt(new Date()); // orderLogService.insertOrderLog(log); // //开始服务 // // 1. 修改订单状态 // order.setStatus(3L); // 服务中 // order.setJsonStatus(7); // 服务中 // order.setLogJson("{\"type\":6}"); // order.setIsPause(1); // 服务中 // order.setUpdatedAt(new Date()); // int update = orderService.updateOrder(order); // return AppletControllerUtil.appletSuccess("服务已开始"); // }else{ // // if (order.getJsonStatus() == 7) { // com.alibaba.fastjson2.JSONObject logItem = new com.alibaba.fastjson2.JSONObject(); // logItem.put("name", "暂停服务"); // logItem.put("image", params.get("image")); // logItem.put("reson", params.get("reson")); // logItem.put("next_time", params.get("next_time")); // logItem.put("time", new Date()); // logItem.put("type", 2); // // // OrderLog newlogdata1 =new OrderLog(); // newlogdata1.setOid(order.getId()); // newlogdata1.setOrderId(order.getOrderId()); // newlogdata1.setTitle("暂停服务"); // newlogdata1.setIsPause(2); // newlogdata1.setContent(logItem.toJSONString()); // newlogdata1.setType(new BigDecimal(6.0)); // newlogdata1.setWorkerId(order.getWorkerId()); // newlogdata1.setWorkerLogId(order.getWorkerId()); // // // orderLogService.insertOrderLog(newlogdata1); // if (order != null) { // // 1. 修改订单状态 // order.setStatus(3L); // 服务中 // order.setJsonStatus(8); // 服务中 // order.setLogJson("{\"type\":6}"); // order.setIsPause(2); // 服务中 // order.setUpdatedAt(new Date()); // orderService.updateOrder(order); // } // return AppletControllerUtil.appletSuccess("操作成功"); // } // if (order.getJsonStatus() == 8) { // com.alibaba.fastjson2.JSONObject logItem = new com.alibaba.fastjson2.JSONObject(); // logItem.put("name", "继续服务"); // logItem.put("image", params.get("image")); // logItem.put("time", new Date()); // logItem.put("type", 1); // // OrderLog newlogdata2 =new OrderLog(); // newlogdata2.setOid(order.getId()); // newlogdata2.setOrderId(order.getOrderId()); // newlogdata2.setTitle("继续服务"); // newlogdata2.setIsPause(1); // newlogdata2.setType(new BigDecimal(6.0)); // newlogdata2.setWorkerId(order.getWorkerId()); // newlogdata2.setWorkerLogId(order.getWorkerId()); // newlogdata2.setContent(logItem.toJSONString()); // orderLogService.insertOrderLog(newlogdata2); // if (order != null) { // //继续服务 // order.setStatus(3L); // 服务中 // order.setJsonStatus(7); // 服务中 // order.setLogJson("{\"type\":6}"); // order.setIsPause(1); // 服务中 // order.setUpdatedAt(new Date()); // orderService.updateOrder(order); // } // return AppletControllerUtil.appletSuccess("操作成功"); // } // } // // // // // 这里调用具体的业务逻辑,您来实现 // // 例如:更新订单状态为服务中,记录开始时间等 // // return success("开始服务成功"); // } catch (Exception e) { // return error("开始服务失败:" + e.getMessage()); // } // } /** * 项目报价接口 */ @PreAuthorize("@ss.hasPermi('system:Order:edit')") @Log(title = "项目报价", businessType = BusinessType.UPDATE) @PostMapping("/project-quote") public AjaxResult projectQuote(@RequestBody Map params) { try { String orderId = params.get("orderId").toString(); // 这里调用具体的业务逻辑,您来实现 // 例如:创建项目报价,更新订单状态等 return success("项目报价成功"); } catch (Exception e) { return error("项目报价失败:" + e.getMessage()); } } //---------------------------------------------------------------报价相关----------------------------------------------------- // ... existing code ... /** * 获取基检项目和订单报价信息 * GET /api/worker/basic/project?id=订单id&goodid=服务id */ @GetMapping("/basic-project/{id}") public AjaxResult getWorkerBasicProject(@PathVariable("id") Long id ) { List basicList = new ArrayList<>(); Map data = new HashMap<>(); Long goodid = null; Object quoteJson = null; // 1. 如果订单id不为空,查订单和报价日志 if (id != null) { Order order = orderService.selectOrderById(id); if (order != null) { // 查 type=5.0 的订单日志 OrderLog logQuery = new OrderLog(); logQuery.setOid(order.getId()); logQuery.setType(new BigDecimal("5.0")); List logs = orderLogService.selectOrderLogList(logQuery); if (logs != null && !logs.isEmpty()) { String content = logs.getFirst().getContent(); try { quoteJson = JSON.parse(content); } catch (Exception e) { quoteJson = content; } } // 取服务id if (order.getProductId() != null) { goodid = order.getProductId(); } } } // 2. 查服务信息 if (goodid != null) { ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodid); if (serviceGoods != null) { String basic = serviceGoods.getBasic(); if (basic != null && !basic.trim().isEmpty()) { try { JSONArray jsonArray = JSONArray.parse(basic); for (int i = 0; i < jsonArray.size(); i++) { String item = jsonArray.getString(i); if (item != null && !item.trim().isEmpty()) { basicList.add(item.trim()); } } } catch (Exception e) { String[] arr = basic.split("[\n,,]"); for (String s : arr) { if (!s.trim().isEmpty()) basicList.add(s.trim()); } } } } } //查询报价的支付信息 if (id != null) { Order order = orderService.selectOrderById(id); if (order != null) { // 查 type=5.0 的订单日志 OrderLog logQuery = new OrderLog(); logQuery.setOid(order.getId()); logQuery.setType(new BigDecimal("5.0")); List logs = orderLogService.selectOrderLogList(logQuery); if (logs != null && !logs.isEmpty()) { OrderLog logdata = logs.getFirst(); if (logdata != null) { Map paydata = new HashMap<>(); paydata.put("weikuan", logdata.getPaid()); paydata.put("dingjin", logdata.getDepPaid()); data.put("payStatusdata", paydata); } } } }else{ Map paydata = new HashMap<>(); paydata.put("weikuan", "1"); paydata.put("dingjin", "1"); data.put("payStatusdata", paydata); } data.put("basic", basicList); if (quoteJson != null) { data.put("quote", quoteJson); } return AjaxResult.success(data); } // /** // * 获取基检项目 // */ // @ApiOperation("获取基检项目") // @GetMapping("/basic/project/{id}") // public AjaxResult getWorkerBasicProject(@PathVariable("id") Long id) { // Order order = orderService.selectOrderById(id); // if (order == null) { // return AjaxResult.error("订单不存在"); // } // ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); // if (serviceGoods == null) { // return AjaxResult.error("商品不存在"); // } // // String basic = serviceGoods.getBasic(); // List basicList = new ArrayList<>(); // if (basic != null && !basic.trim().isEmpty()) { // try { // JSONArray jsonArray = JSONArray.parseArray(basic); // for (int i = 0; i < jsonArray.size(); i++) { // String item = jsonArray.getString(i); // if (item != null && !item.trim().isEmpty()) { // basicList.add(item.trim()); // } // } // } catch (Exception e) { // String[] arr = basic.split("[\n,,]"); // for (String s : arr) { // if (!s.trim().isEmpty()) basicList.add(s.trim()); // } // } // } // Map data = new HashMap<>(); // data.put("basic", basicList); // return AjaxResult.success(data); // } /** * 报价获取服务项目 */ @ApiOperation("获取取服务项目") @GetMapping("/quote-craft/{goodsId}") public AjaxResult getWorkerQuoteCraft(@PathVariable("goodsId") Long goodsId) { // 1. 查询商品基本信息 ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodsId); if (serviceGoods == null) { return AjaxResult.error("商品不存在"); } // 2. 查询服务分类(IQuoteTypeService) QuoteType typeQuery = new QuoteType(); typeQuery.setGoodId("\"" + goodsId + "\""); List typeList = quoteTypeService.selectQuoteTypeList(typeQuery); List dataArr = new ArrayList<>(); for (QuoteType type : typeList) { Map typeMap = new HashMap<>(); typeMap.put("id", type.getId()); typeMap.put("title", type.getTitle()); // 3. 查询工艺(IQuoteCraftService) QuoteCraft craftQuery = new QuoteCraft(); craftQuery.setTypeId("[\"" + type.getId() + "\"]"); List craftList = quoteCraftService.selectQuoteCraftList(craftQuery); List> craftArr = new ArrayList<>(); for (QuoteCraft craft : craftList) { Map craftMap = new HashMap<>(); craftMap.put("id", craft.getId()); craftMap.put("title", craft.getTitle()); craftMap.put("price", craft.getPrice() != null ? craft.getPrice().toString() : "0.00"); craftMap.put("unit", craft.getUnit()); // type_id为数组,需解析 List typeIdList = new ArrayList<>(); String typeIdStr = craft.getTypeId(); if (typeIdStr != null && typeIdStr.trim().startsWith("[") && typeIdStr.trim().endsWith("]")) { try { typeIdList = JSON.parseArray(typeIdStr, String.class); } catch (Exception e) { typeIdList.add(typeIdStr); } } else if (typeIdStr != null) { typeIdList.add(typeIdStr); } craftMap.put("type_id", typeIdList); craftArr.add(craftMap); } typeMap.put("craft", craftArr); dataArr.add(typeMap); } return AjaxResult.success(dataArr); } /** * 报价所需物料查询 * GET /api/worker/quote/material/{goodsId} */ @ApiOperation("获取所需物料") @GetMapping("/quote-material/{goodsId}") public AjaxResult getWorkerQuoteMaterial(@PathVariable("goodsId") Long goodsId) { // 1. 查询商品基本信息 ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodsId); if (serviceGoods == null) { return AjaxResult.error("商品不存在"); } // 2. 查询物料分类(IQuoteMaterialTypeService) QuoteMaterialType typeQuery = new QuoteMaterialType(); typeQuery.setGoodId("\"" + goodsId + "\""); List typeList = quoteMaterialTypeService.selectQuoteMaterialTypeList(typeQuery); List dataArr = new ArrayList<>(); for (QuoteMaterialType type : typeList) { Map typeMap = new HashMap<>(); typeMap.put("id", type.getId()); typeMap.put("title", type.getTitle()); // 3. 查询物料信息(IQuoteMaterialService) QuoteMaterial materialQuery = new QuoteMaterial(); materialQuery.setTypeId("\"" + type.getId() + "\""); List materialList = quoteMaterialService.selectQuoteMaterialList(materialQuery); List> materialArr = new ArrayList<>(); for (QuoteMaterial material : materialList) { Map materialMap = new HashMap<>(); materialMap.put("id", material.getId()); materialMap.put("title", material.getTitle()); materialMap.put("image",AppletControllerUtil.buildImageUrl(material.getImage())); materialMap.put("price", material.getPrice() != null ? material.getPrice().toString() : "0.00"); materialMap.put("unit", material.getUnit()); // 格式化manyimages为数组 if (material.getManyimages() != null && !material.getManyimages().trim().isEmpty()) { materialMap.put("manyimages", JSONArray.parseArray(material.getManyimages())); } else { materialMap.put("manyimages", new JSONArray()); } if (org.apache.commons.lang3.StringUtils.isNotBlank(material.getContent())&& org.apache.commons.lang3.StringUtils.isNotBlank(material.getManyimages())){ materialMap.put("showtype", 1); }else{ materialMap.put("showtype", 2); } materialMap.put("content", material.getContent()); // type_id为数组,需解析 List typeIdList = new ArrayList<>(); String typeIdStr = material.getTypeId(); if (typeIdStr != null && typeIdStr.trim().startsWith("[") && typeIdStr.trim().endsWith("]")) { try { typeIdList = JSON.parseArray(typeIdStr, String.class); } catch (Exception e) { typeIdList.add(typeIdStr); } } else if (typeIdStr != null) { typeIdList.add(typeIdStr); } materialMap.put("type_id", typeIdList); materialArr.add(materialMap); } typeMap.put("material", materialArr); dataArr.add(typeMap); } return AjaxResult.success(dataArr); } /** * 师傅报价接口 * POST /api/worker/estimate */ @ApiOperation(value = "测试") @PostMapping("/worker-estimate") public AjaxResult workerEstimate(@RequestBody Map params, HttpServletRequest request) throws Exception { if (params == null) { return AjaxResult.error("参数错误"); } PayBeforeUtil payBeforeUtil = new PayBeforeUtil(); // 1. 计算金额 BigDecimal GoodsAllPrice = BigDecimal.ZERO; BigDecimal ServiceAllPrice = BigDecimal.ZERO; BigDecimal totalPrice = BigDecimal.ZERO; List> craftList = (List>) params.get("craft"); if (craftList != null) { for (Map craft : craftList) { Long craftId = null; try { craftId = Long.valueOf(craft.get("id").toString()); } catch (Exception ignore) { } if (craftId != null) { QuoteCraft quoteCraft = quoteCraftService.selectQuoteCraftById(craftId); if (quoteCraft != null) { BigDecimal price = new BigDecimal(craft.get("price").toString()); Integer count = craft.get("count") == null ? 1 : Integer.parseInt(craft.get("count").toString()); totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(count))); ServiceAllPrice = ServiceAllPrice.add(price.multiply(BigDecimal.valueOf(count))); } } } } List> materialList = (List>) params.get("material"); if (materialList != null) { for (Map material : materialList) { Long materialId = null; try { materialId = Long.valueOf(material.get("id").toString()); } catch (Exception ignore) { } if (materialId != null) { QuoteMaterial quoteMaterial = quoteMaterialService.selectQuoteMaterialById(materialId); if (quoteMaterial != null) { BigDecimal price = new BigDecimal(material.get("price").toString()); Integer count = material.get("count") == null ? 1 : Integer.parseInt(material.get("count").toString()); totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(count))); GoodsAllPrice = GoodsAllPrice.add(price.multiply(BigDecimal.valueOf(count))); } } } } BigDecimal reductionPrice = BigDecimal.ZERO; String reduction = params.get("reduction").toString(); String reamk = null; if (params.get("reamk") != null){ reamk =params.get("reamk").toString(); } if (reduction != null && !reduction.trim().isEmpty()) { reductionPrice = new BigDecimal(reduction); // totalPrice = totalPrice.subtract(reductionPrice); totalPrice = totalPrice; } // 2. 组装新json Map resultJson = new LinkedHashMap<>(); // project Map project = new LinkedHashMap<>(); project.put("name", "项目费用"); project.put("price", totalPrice); resultJson.put("project", project); Map reductionproject = new LinkedHashMap<>(); reductionproject.put("name", "优惠金额"); reductionproject.put("price", params.get("reduction")); resultJson.put("reduction", reductionproject); Map depositproject = new LinkedHashMap<>(); depositproject.put("name", "定金"); depositproject.put("price", params.get("price")); resultJson.put("deposit", depositproject); // basic resultJson.put("basic", params.get("basic")); if (StringUtils.isNotBlank(reamk)){ resultJson.put("reamk", reamk); } // craft List> craftListNew = new ArrayList<>(); if (craftList != null) { for (Map craft : craftList) { Map item = new LinkedHashMap<>(); item.put("name", craft.get("title") != null ? craft.get("title") : craft.get("name")); item.put("price", craft.get("price")); item.put("pid", craft.get("pid")); item.put("id", craft.get("id")); item.put("count", craft.get("count")); craftListNew.add(item); } } resultJson.put("craft", craftListNew); // material List> materialListNew = new ArrayList<>(); if (materialList != null) { for (Map material : materialList) { Map item = new LinkedHashMap<>(); item.put("name", material.get("title") != null ? material.get("title") : material.get("name")); item.put("price", material.get("price")); item.put("id", material.get("id")); item.put("pid", material.get("pid")); item.put("count", material.get("count")); materialListNew.add(item); } } resultJson.put("material", materialListNew); // 3. 转为字符串 String contentStr = com.alibaba.fastjson2.JSONObject.toJSONString(resultJson); // 4. 订单相关处理 Long orderId = null; if (params.get("id") != null) { try { orderId = Long.valueOf(params.get("id").toString()); } catch (Exception ignore) { } } if (orderId == null) { return AppletControllerUtil.appletError("订单ID格式错误"); } Order order = orderService.selectOrderById(orderId); if (order == null) { return AppletControllerUtil.appletError("订单不存在"); } // 查询最新订单日志 OrderLog neworderLogdata =new OrderLog(); neworderLogdata.setType(new BigDecimal(5.0)); neworderLogdata.setOid(order.getId()); List orderLogslist = orderLogService.selectOrderLogList(neworderLogdata); if(!orderLogslist.isEmpty()){ OrderLog neworderLog=orderLogslist.getFirst(); neworderLog.setContent(contentStr); if (params.get("price") != null) { //String DepLogId = GenerateCustomCode.generCreateOrder("LOG"); neworderLog.setDeposit(new BigDecimal(params.get("price").toString())); neworderLog.setDepPaid(1); // neworderLog.setDepLogId(DepLogId); //给尾款添加预支 // BigDecimal totalAmount=neworderLog.getDeposit(); // PayBeforeUtil payBeforeUtil = new PayBeforeUtil(); // payBeforeUtil.createPayBefore(userinfo, totalAmount, DepLogId, neworderLog.getId(), // null, 7L, null, null, // null, null, null,1L,null); //// payBeforeUtil.createPayBefore(user, totalPrice.add(reductionPrice), order.getOrderId(), order.getId(),); }else { neworderLog.setDeposit(BigDecimal.ZERO); } // neworderLog.setPrice(totalPrice.add(reductionPrice)); neworderLog.setPaid(1L); if (params.get("reduction") != null) { neworderLog.setReductionPrice(new BigDecimal(params.get("reduction").toString())); } else { neworderLog.setReductionPrice(BigDecimal.ZERO); } System.out.println("neworderLog.getPrice():totalPrice"+totalPrice); System.out.println("neworderLog.getPrice():reductionPrice"+reductionPrice); System.out.println("neworderLog.getPrice():neworderLog.getDeposit()"+neworderLog.getDeposit()); BigDecimal WK=totalPrice.subtract(reductionPrice).subtract(neworderLog.getDeposit()); System.out.println("neworderLog.getPrice():neworderLog.getDeposit()WKWKWK"+WK); if(WK.compareTo(BigDecimal.ZERO)>0){ System.out.println("111neworderLog.getPrice():neworderLog.getDeposit()WKWKWK"+WK); neworderLog.setPrice(WK); }else{ neworderLog.setPrice(BigDecimal.ZERO); } // if (params.get("reduction") != null) { // neworderLog.setReductionPrice(new BigDecimal(params.get("reduction").toString())); // } else { // neworderLog.setReductionPrice(BigDecimal.ZERO); // } neworderLog.setWorkerCost(BigDecimal.ZERO); //log.set neworderLog.setLogId(GenerateCustomCode.generCreateOrder("EST")); //删除之前的预支付信息 UsersPayBefor payBefore = new UsersPayBefor(); payBefore.setOrderid(neworderLog.getDepLogId()); List payBeforeList = usersPayBeforService.selectUsersPayBeforList(payBefore); if(!payBeforeList.isEmpty()){ for (UsersPayBefor payBefore1 : payBeforeList) { usersPayBeforService.deleteUsersPayBeforById(payBefore1.getId()); } } //删除之前的预支付信息 UsersPayBefor payBefore3 = new UsersPayBefor(); payBefore3.setOrderid(neworderLog.getLogOrderId()); payBefore3.setType(9L); List payBeforeList3 = usersPayBeforService.selectUsersPayBeforList(payBefore3); if(!payBeforeList3.isEmpty()){ for (UsersPayBefor payBefore4 : payBeforeList3) { usersPayBeforService.deleteUsersPayBeforById(payBefore4.getId()); } } Users userinfo = usersService.selectUsersById(order.getUid()); payBeforeUtil.handleQuotationPayBefore(userinfo, neworderLog, contentStr, order.getOrderId()); int flg= orderLogService.updateOrderLog(neworderLog); if (flg > 0) { order.setGoodPrice(GoodsAllPrice); order.setServicePrice(ServiceAllPrice); orderService.updateOrder(order); } //小程序推送报价成功 Users user = usersService.selectUsersById(order.getUid()); ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); WXsendMsgUtil.sendWorkerADDmoney(user.getOpenid(), order, serviceGoods); return AjaxResult.success("报价成功"); }else{ order.setJsonStatus(6); com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject(); jsonObject.put("type", 5); order.setLogJson(jsonObject.toJSONString()); // order.setTotalPrice(totalPrice); // order.setUpdatedAt(new Date()); order.setGoodPrice(GoodsAllPrice); order.setServicePrice(ServiceAllPrice); int update = orderService.updateOrder(order); if (update > 0) { OrderLog log = new OrderLog(); log.setOid(order.getId()); log.setLogOrderId(GenerateCustomCode.generCreateOrder("DSB") ); log.setOrderId(order.getOrderId()); log.setType(new BigDecimal(5)); log.setContent(contentStr); log.setTitle("已检查评估报价"); if (params.get("price") != null) { log.setDeposit(new BigDecimal(params.get("price").toString())); log.setDepPaid(1); log.setDepLogId(GenerateCustomCode.generCreateOrder("RED")); }else { log.setDeposit(BigDecimal.ZERO); } BigDecimal WK=totalPrice.subtract(reductionPrice).subtract(log.getDeposit()); if(WK.compareTo(BigDecimal.ZERO)>0){ log.setPrice(WK); }else{ log.setPrice(BigDecimal.ZERO); } // log.setPrice(totalPrice.add(reductionPrice)); log.setPaid(1L); if (params.get("reduction") != null) { log.setReductionPrice(new BigDecimal(params.get("reduction").toString())); } else { log.setReductionPrice(BigDecimal.ZERO); } //log.setPrice(ServiceAllPrice.subtract(reductionPrice)); //log.set log.setLogId(GenerateCustomCode.generCreateOrder("EST")); log.setWorkerLogId(order.getWorkerId()); log.setWorkerId(order.getWorkerId()); int flg=orderLogService.insertOrderLog(log); if (flg > 0) { order.setGoodPrice(GoodsAllPrice); order.setServicePrice(ServiceAllPrice); orderService.updateOrder(order); } Users user = usersService.selectUsersById(order.getUid()); ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); //小程序推送用户报价成功 WXsendMsgUtil.sendWorkerADDmoney(user.getOpenid(), order, serviceGoods); Users userinfo = usersService.selectUsersById(order.getUid()); payBeforeUtil.handleQuotationPayBefore(userinfo, log, contentStr, order.getOrderId()); return AjaxResult.success("报价成功"); } else { return AjaxResult.success("报价失败"); } } } /** * 师傅开始服务接口 * POST /api/worker/do/service * 参数:{"oid":订单id,"image":[图片url数组]} */ @PostMapping("/start-service") public AjaxResult workerDostartserviceService(@RequestBody Map params, HttpServletRequest request) { System.out.println("jsonArray.size():"+params.toString()); String orderid = ""; if (params.get("orderId") != null) { try { orderid = params.get("orderId").toString(); } catch (Exception e) { return AppletControllerUtil.appletError("订单ID格式错误"); } } Order order = orderService.selectOrderByOrderId(orderid); if (order == null) { return AppletControllerUtil.appletError("订单不存在"); } String image = ""; if (params.get("image") != null) { try { image = params.get("image").toString(); // JSONArray jsonArray = JSON.parseArray(image); // if (jsonArray.size() > 1) { // System.out.println("jsonArray.size():"+jsonArray.size()); // System.out.println("jsonArray.size():"+jsonArray.getFirst().toString()); // } } catch (Exception e) { return AppletControllerUtil.appletError("图片格式错误"); } } OrderLog newlogdata =new OrderLog(); newlogdata.setType(new BigDecimal("6.0")); newlogdata.setOid(order.getId()); //如果没有进行服务的记录就是开启服务 List logList = orderLogService.selectOrderLogList(newlogdata); if (logList.isEmpty()){ // 2. 组装日志内容为数组格式 Map logItem = new LinkedHashMap<>(); logItem.put("name", "师傅开始服务"); logItem.put("image", params.get("image")); logItem.put("type", 1); List logArr = new ArrayList<>(); logArr.add(logItem); String contentStr = com.alibaba.fastjson2.JSONObject.toJSONString(logArr); // 3. 写入订单日志 OrderLog log = new OrderLog(); log.setOid(order.getId()); log.setOrderId(order.getOrderId()); log.setTitle("开始服务"); log.setType(new BigDecimal(6.0)); log.setContent(contentStr); log.setWorkerId(order.getWorkerId()); log.setWorkerLogId(order.getWorkerId()); log.setIsPause(1); log.setCreatedAt(new Date()); orderLogService.insertOrderLog(log); //开始服务 // 1. 修改订单状态 order.setStatus(3L); // 服务中 order.setJsonStatus(7); // 服务中 order.setLogJson("{\"type\":6}"); order.setIsPause(1); // 服务中 order.setUpdatedAt(new Date()); int update = orderService.updateOrder(order); return AppletControllerUtil.appletSuccess("服务已开始"); }else{ if (order.getJsonStatus() == 7) { com.alibaba.fastjson2.JSONObject logItem = new com.alibaba.fastjson2.JSONObject(); logItem.put("name", "暂停服务"); logItem.put("image", params.get("image")); logItem.put("reson", params.get("reson")); logItem.put("next_time", params.get("next_time")); logItem.put("time", new Date()); logItem.put("type", 2); OrderLog newlogdata1 =new OrderLog(); newlogdata1.setOid(order.getId()); newlogdata1.setOrderId(order.getOrderId()); newlogdata1.setTitle("暂停服务"); newlogdata1.setIsPause(2); newlogdata1.setContent(logItem.toJSONString()); newlogdata1.setType(new BigDecimal(6.0)); newlogdata1.setWorkerId(order.getWorkerId()); newlogdata1.setWorkerLogId(order.getWorkerId()); orderLogService.insertOrderLog(newlogdata1); if (order != null) { // 1. 修改订单状态 order.setStatus(3L); // 服务中 order.setJsonStatus(8); // 服务中 order.setLogJson("{\"type\":6}"); order.setIsPause(2); // 服务中 order.setUpdatedAt(new Date()); orderService.updateOrder(order); } return AppletControllerUtil.appletSuccess("操作成功"); } if (order.getJsonStatus() == 8) { com.alibaba.fastjson2.JSONObject logItem = new com.alibaba.fastjson2.JSONObject(); logItem.put("name", "继续服务"); logItem.put("image", params.get("image")); logItem.put("time", new Date()); logItem.put("type", 1); OrderLog newlogdata2 =new OrderLog(); newlogdata2.setOid(order.getId()); newlogdata2.setOrderId(order.getOrderId()); newlogdata2.setTitle("继续服务"); newlogdata2.setIsPause(1); newlogdata2.setType(new BigDecimal(6.0)); newlogdata2.setWorkerId(order.getWorkerId()); newlogdata2.setWorkerLogId(order.getWorkerId()); newlogdata2.setContent(logItem.toJSONString()); orderLogService.insertOrderLog(newlogdata2); if (order != null) { //继续服务 order.setStatus(3L); // 服务中 order.setJsonStatus(7); // 服务中 order.setLogJson("{\"type\":6}"); order.setIsPause(1); // 服务中 order.setUpdatedAt(new Date()); orderService.updateOrder(order); } return AppletControllerUtil.appletSuccess("操作成功"); } } return AppletControllerUtil.appletSuccess("操作成功"); } }