diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleMemberController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleMemberController.java index 1fc5757..5a72ff5 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleMemberController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleMemberController.java @@ -1,6 +1,7 @@ package com.ruoyi.system.controller; import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.github.pagehelper.PageHelper; import com.ruoyi.common.core.controller.BaseController; @@ -86,6 +87,12 @@ public class AppleMemberController extends BaseController { @Autowired private IUserBenefitPointsService userBenefitPointsService; + + @Autowired + private IGoodsOrderService goodsOrderService; + + + @Autowired private WechatPayUtil wechatPayUtil; @@ -581,11 +588,12 @@ public class AppleMemberController extends BaseController { } String orderId = params.get("order_id").toString(); + String type = params.get("type").toString(); String content = params.get("content").toString(); Integer num = Integer.parseInt(params.get("num").toString()); // 4. 获取订单信息并验证 - Order order = orderService.selectOrderByOrderId(orderId); + Order order = orderService.selectOrderById(Long.valueOf(orderId)); if (order == null) { return AppletControllerUtil.appletWarning("订单不存在"); } @@ -609,7 +617,7 @@ public class AppleMemberController extends BaseController { // 7. 构建评价数据 OrderComment comment = new OrderComment(); comment.setOid(order.getId()); - comment.setOrderId(orderId); + comment.setOrderId(order.getOrderId()); comment.setProductId(order.getProductId()); comment.setContent(content); comment.setNum(Long.valueOf(num)); @@ -617,41 +625,54 @@ public class AppleMemberController extends BaseController { comment.setUid(user.getId()); comment.setWorkerId(order.getWorkerId()); + //JSONArray jsonArrayimg=new JSONArray(); // 8. 处理图片附件 if (params.containsKey("images") && params.get("images") != null) { String images = JSON.toJSONString(params.get("images")); comment.setImages(images); + //jsonArrayimg + } - + JSONArray jsonArray=new JSONArray(); // 9. 处理评价标签 if (params.containsKey("labels") && params.get("labels") != null) { String labels = JSON.toJSONString(params.get("labels")); comment.setLabels(labels); + // jsonArray = JSON.parseArray(labels); } // 10. 保存评价并更新订单状态 // 保存评价 orderCommentService.insertOrderComment(comment); + if (type.equals("service")){ + // 添加订单日志 + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(orderId); + orderLog.setTitle("订单评价"); + orderLog.setType(BigDecimal.valueOf(8)); // 8=评价类型 - // 添加订单日志 - OrderLog orderLog = new OrderLog(); - orderLog.setOid(order.getId()); - orderLog.setOrderId(orderId); - orderLog.setTitle("订单评价"); - orderLog.setType(BigDecimal.valueOf(8)); // 8=评价类型 + Map logContent = new HashMap<>(); + logContent.put("text", content); + logContent.put("image", params.get("images")); + logContent.put("labels", params.get("labels")); + logContent.put("num", num); + orderLog.setContent(JSON.toJSONString(logContent)); - Map logContent = new HashMap<>(); - logContent.put("text", content); - logContent.put("image", params.get("images")); - logContent.put("num", num); - orderLog.setContent(JSON.toJSONString(logContent)); + orderLogService.insertOrderLog(orderLog); - orderLogService.insertOrderLog(orderLog); - - // 更新订单状态 - order.setStatus(4L); // 4=完成状态 - order.setIsComment(1); // 1=已评价 - orderService.updateOrder(order); + // 更新订单状态 + order.setStatus(4L); // 4=完成状态 + order.setIsComment(1); // 1=已评价 + orderService.updateOrder(order); + } + if (type.equals("goods")){{ + GoodsOrder goodsOrder = goodsOrderService.selectGoodsOrderByorderId(orderId); + if (goodsOrder != null){ + // goodsOrder.setis + } + } + } return AjaxResult.success("评价提交成功"); @@ -786,7 +807,7 @@ public class AppleMemberController extends BaseController { // 7. 处理报价 UserDemandQuotation quoteRecord; - boolean isFirstQuote = false; + //boolean isFirstQuote = false; if (existingQuotes != null && !existingQuotes.isEmpty()) { // 已有报价,更新 quoteRecord = existingQuotes.getFirst(); @@ -799,6 +820,7 @@ public class AppleMemberController extends BaseController { quoteRecord = new UserDemandQuotation(); quoteRecord.setWorkerid(user.getId()); quoteRecord.setOrderid(orderId); + quoteRecord.setOid(order.getId()); quoteRecord.setMoney(quoteMoney); quoteRecord.setQuotationTime(new Date()); quoteRecord.setStatus(1L); // 设置状态为有效 @@ -806,14 +828,14 @@ public class AppleMemberController extends BaseController { quoteRecord.setWorkerimage(user.getAvatar()); quoteRecord.setCreateTime(new Date()); userDemandQuotationService.insertUserDemandQuotation(quoteRecord); - isFirstQuote = true; + // isFirstQuote = true; } - // 8. 如果是第一次报价,更新订单状态为待选择(12) - if (isFirstQuote) { - order.setStatus(12L); - orderService.updateOrder(order); - } +// // 8. 如果是第一次报价,更新订单状态为待选择(12) +// if (isFirstQuote) { +// order.setStatus(12L); +// orderService.updateOrder(order); +// } return AppletControllerUtil.appletSuccess("报价成功"); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleOrderController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleOrderController.java index 2ad3e05..8fae935 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleOrderController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleOrderController.java @@ -57,6 +57,9 @@ public class AppleOrderController extends BaseController { @Autowired private IUserUseSecondaryCardService userUseSecondaryCardService; + @Autowired + private IContentService contentService; + @Autowired @@ -100,6 +103,14 @@ public class AppleOrderController extends BaseController { @Autowired private IOrderCommentService orderCommentService; + @Autowired + private IWorkerLevelService workerLevelService; + +// @Autowired +// private IUserGroupBuyingService userGroupBuyingService; + + + /** * 查询用户优惠券列表 * @@ -1059,7 +1070,7 @@ public class AppleOrderController extends BaseController { // 3. 解析服务ID列表 List goodsIds = new ArrayList<>(); try { - List goodsIdStrs = com.alibaba.fastjson2.JSONArray.parseArray(card.getGoodsids(), String.class); + List goodsIdStrs = JSONArray.parseArray(card.getGoodsids(), String.class); for (String gid : goodsIdStrs) { goodsIds.add(Long.valueOf(gid)); } @@ -1208,13 +1219,13 @@ public class AppleOrderController extends BaseController { case 0: // 普通预约 return createNormalOrder(user, productId, userAddress, sku, num, makeTime,fileData,reamk); case 1: // 拼团 - return createGroupBuyingOrder(user, productId,fileData,grouporderid,ptcode); + return createGroupBuyingOrder(user, productId,fileData,grouporderid,ptcode,reamk); case 2: // 一口价 - return createCardOrder(user, productId, userAddress, sku, num, makeTime, fileData,cikaid,totalAmount); + return createCardOrder(user, productId, userAddress, sku, num, makeTime, fileData,cikaid,totalAmount,reamk); case 3: // 秒杀 - return createSeckillOrder(user, productId, userAddress, sku, num, makeTime,fileData,totalAmount); + return createSeckillOrder(user, productId, userAddress, sku, num, makeTime,fileData,totalAmount,reamk); case 4: // 报价 - return createQuoteOrder(user, productId, userAddress, sku, num, makeTime,fileData); + return createQuoteOrder(user, productId, userAddress, sku, num, makeTime,fileData,reamk); default: result.put("success", false); result.put("message", "不支持的订单类型"); @@ -1248,17 +1259,20 @@ public class AppleOrderController extends BaseController { BigDecimal itemPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); // 生成订单号 - String orderId = GenerateCustomCode.generCreateOrder("N"); + String orderId = GenerateCustomCode.generCreateOrder("YY"); + String mainorderId = GenerateCustomCode.generCreateOrder("MYY"); // 创建普通预约订单(统一使用服务订单表) Order order = new Order(); order.setNum(Long.valueOf(num)); order.setType(1); // 普通预约订单 + order.setMainOrderId(mainorderId); order.setCreateType(1); // 用户自主下单 order.setOrderId(orderId); order.setUid(user.getId()); order.setUname(user.getName()); order.setProductId(serviceGoods.getId()); + order.setBigtype(serviceGoods.getServicetype()); order.setProductName(serviceGoods.getTitle()); order.setReamk(reamk); order.setSku(sku); @@ -1293,6 +1307,7 @@ public class AppleOrderController extends BaseController { order.setIsAccept(0); order.setIsComment(0); order.setIsPause(1); + order.setJsonStatus(0); order.setOdertype(0); order.setDeduction(new BigDecimal(0)); order.setFileData(attachments); // 设置附件数据 @@ -1333,7 +1348,7 @@ public class AppleOrderController extends BaseController { * 创建拼团订单user, productId,fileData,grouporderid */ private Map createGroupBuyingOrder(Users user, Long productId,String fileData, - String grouporderid,String ptcode) { + String grouporderid,String ptcode,String reamk) { Map result = new HashMap<>(); ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); @@ -1399,7 +1414,7 @@ public class AppleOrderController extends BaseController { */ private Map createCardOrder(Users user, Long productId, UserAddress userAddress, String sku, Integer num, String makeTime, - String attachments,String cikaid,BigDecimal totalAmount) { + String attachments,String cikaid,BigDecimal totalAmount,String reamk) { Map result = new HashMap<>(); try { @@ -1421,6 +1436,7 @@ public class AppleOrderController extends BaseController { order.setCreateType(1); // 用户自主下单 order.setOrderId(orderId); order.setUid(user.getId()); + order.setReamk(reamk); order.setUname(user.getName()); order.setProductId(serviceGoods.getId()); order.setProductName(serviceGoods.getTitle()); @@ -1466,6 +1482,7 @@ public class AppleOrderController extends BaseController { order.setIsComment(0); order.setIsPause(1); order.setOdertype(2); + order.setJsonStatus(0); order.setDeduction(new BigDecimal(0)); order.setFileData(attachments); // 设置附件数据 order.setType(1); @@ -1569,7 +1586,7 @@ public class AppleOrderController extends BaseController { */ private Map createSeckillOrder(Users user, Long productId, UserAddress userAddress, String sku, Integer num, String makeTime, - String attachments,BigDecimal totalAmount) { + String attachments,BigDecimal totalAmount,String reamk) { Map result = new HashMap<>(); ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); @@ -1597,6 +1614,7 @@ public class AppleOrderController extends BaseController { order.setType(3); // 秒杀类型 order.setCreateType(1); // 用户自主下单 order.setOrderId(orderId); + order.setReamk(reamk); order.setUid(user.getId()); order.setUname(user.getName()); order.setProductId(serviceGoods.getId()); @@ -1636,6 +1654,7 @@ public class AppleOrderController extends BaseController { order.setIsComment(0); order.setOdertype(3); order.setIsPause(1); + order.setJsonStatus(0); order.setDeduction(new BigDecimal(0)); order.setFileData(attachments); // 设置附件数据 order.setTotalPrice(totalAmount); @@ -1676,7 +1695,7 @@ public class AppleOrderController extends BaseController { */ private Map createQuoteOrder(Users user, Long productId, UserAddress userAddress, String sku, Integer num, String makeTime, - String attachments) { + String attachments,String reamk) { Map result = new HashMap<>(); ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); @@ -1692,17 +1711,21 @@ public class AppleOrderController extends BaseController { // 生成订单号 String orderId = GenerateCustomCode.generCreateOrder("Q"); + String mainorderId = GenerateCustomCode.generCreateOrder("XQ"); // 创建报价订单(使用服务订单表) Order order = new Order(); - order.setType(4); // 报价订单 + order.setCreateType(1); // 用户自主下单 order.setOrderId(orderId); order.setUid(user.getId()); order.setUname(user.getName()); + order.setMainOrderId(mainorderId); order.setProductId(serviceGoods.getId()); + order.setReamk(reamk); order.setProductName(serviceGoods.getTitle()); order.setSku(sku); + order.setJsonStatus(0); order.setType(1); order.setNum(Long.valueOf(num)); if (userAddress != null) { @@ -1739,6 +1762,7 @@ public class AppleOrderController extends BaseController { order.setIsComment(0); order.setIsPause(1); order.setOdertype(4); + order.setType(4); // 报价订单 order.setDeduction(new BigDecimal(0)); order.setFileData(attachments); // 设置附件数据 @@ -1760,6 +1784,18 @@ public class AppleOrderController extends BaseController { orderLog.setContent(jsonObject.toJSONString()); orderLogService.insertOrderLog(orderLog); + +// // 添加订单日志 +// OrderLog orderLog1 = new OrderLog(); +// orderLog1.setOid(order.getId()); +// orderLog1.setOrderId(order.getOrderId()); +// orderLog1.setType(BigDecimal.valueOf(1)); +// orderLog1.setTitle("师傅报价"); +// JSONObject jsonObject1 = new JSONObject(); +// jsonObject1.put("name", "等待师傅报价中"); +// orderLog.setContent(jsonObject1.toJSONString()); +// +// orderLogService.insertOrderLog(orderLog1); result.put("success", true); result.put("orderId", orderId); @@ -1841,7 +1877,7 @@ public class AppleOrderController extends BaseController { totalAmount = totalAmount.add(new BigDecimal(orderResult.get("allprice").toString())); //一口价 if (cart.getGoodstype()==1&&cart.getOrdertype()==2){ - String payBeforeId = payBeforeUtil.createPayBefore(user, totalAmount, maincorid, null, cart.getGoodId(), 6L, cart.getSku(), null, null, null, null,1L); + String payBeforeId = payBeforeUtil.createPayBefore(user, totalAmount, maincorid, null, cart.getGoodId(), 6L, cart.getSku(), null, null, null, null,1L, null, null); Map result1 = new HashMap<>(); result1.put("type", "2"); result1.put("orderid", maincorid); @@ -1851,7 +1887,7 @@ public class AppleOrderController extends BaseController { if (totalAmount.compareTo(BigDecimal.ZERO) > 0) { //插入预支付订单,随后进行支付 - String payBeforeId = payBeforeUtil.createPayBefore(user, totalAmount, maincorid, null, null, 5L, null, null, null, null, null,2L); + String payBeforeId = payBeforeUtil.createPayBefore(user, totalAmount, maincorid, null, null, 5L, null, null, null, null, null,2L,null,null); Map result1 = new HashMap<>(); result1.put("type", "2"); result1.put("orderid", maincorid); @@ -1923,7 +1959,26 @@ public class AppleOrderController extends BaseController { // 根据status筛选订单状态 if (status != null) { - queryOrder.setStatus(Long.valueOf(status)); + + if (status == 12){ + queryOrder.setBaojiayh(user.getId()); + }else{ + if (status == 4){ + List idslist=new ArrayList<>(); + idslist.add("4"); + idslist.add("7"); + queryOrder.setIds(idslist); + + }else if (status == 13){ + queryOrder.setStatus(6L); + queryOrder.setIsComment(0); + }else { + queryOrder.setStatus(Long.valueOf(status)); + } + + + // queryOrder.setStatus(Long.valueOf(status)); + } } // 3. 查询订单列表 @@ -1941,15 +1996,31 @@ public class AppleOrderController extends BaseController { for (Order order : pageOrderList) { Map orderMap = new HashMap<>(); - + + UsersPayBefor payBefore = new UsersPayBefor(); + payBefore.setLastorderid(order.getOrderId()); + payBefore.setStatus(1L); + List payBeforeList = usersPayBeforService.selectUsersPayBeforList(payBefore); + if (!payBeforeList.isEmpty()) { + orderMap.put("istopay", 1); + }else{ + orderMap.put("istopay", 2); + } + UserGroupBuying groupBuying =userGroupBuyingService.selectUserGroupBuyingByptorderid(order.getOrderId()); + if (groupBuying != null){ + orderMap.put("groupid", groupBuying.getOrderid()); + } // 基本信息 + orderMap.put("goodsid", order.getProductId()); orderMap.put("id", order.getId()); orderMap.put("orderId", order.getOrderId()); orderMap.put("odertype", order.getOdertype()); // 添加odertype字段 orderMap.put("totalPrice", order.getTotalPrice()); orderMap.put("status", order.getStatus()); + orderMap.put("orcerCrateTime", sdf.format(order.getCreatedAt())); orderMap.put("num", order.getNum()); + orderMap.put("jsonStatus", order.getJsonStatus()); orderMap.put("statusText", getOrderStatusText(order.getStatus())); // orderMap.put("createTime", sdf.format(order.getCreateTime())); @@ -1986,7 +2057,7 @@ public class AppleOrderController extends BaseController { // 报价相关信息(仅报价订单) if (order.getBigtype() == 2) { // 当订单状态为8(待报价)或12(待选择)时,返回截止时间毫秒数 - if ((order.getStatus() == 8 || order.getStatus() == 12) && order.getCreatedAt() != null) { + if (order.getStatus() == 8 && order.getCreatedAt() != null) { // 计算报价截止时间(创建时间+3天)的毫秒数 Calendar calendar = Calendar.getInstance(); calendar.setTime(order.getCreatedAt()); @@ -2288,7 +2359,7 @@ public class AppleOrderController extends BaseController { } // 7. 验证订单状态是否为待选择(12) - if (order.getStatus() != 12) { + if (order.getStatus() != 8) { return AppletControllerUtil.appletWarning("订单状态不正确,无法确认报价"); } @@ -2298,22 +2369,44 @@ public class AppleOrderController extends BaseController { } // 9. 更新报价状态为被选中(2) - quotation.setStatus(2L); - int updateResult = userDemandQuotationService.updateUserDemandQuotation(quotation); - if (updateResult <= 0) { - return AppletControllerUtil.appletWarning("更新报价状态失败"); - } - +// quotation.setStatus(2L); +// int updateResult = userDemandQuotationService.updateUserDemandQuotation(quotation); +// if (updateResult <= 0) { +// return AppletControllerUtil.appletWarning("更新报价状态失败"); +// } + if (order.getOdertype()==4&&order.getStatus()==8){ + UsersPayBefor payBefore = new UsersPayBefor(); + payBefore.setOrderid(order.getOrderId()); + payBefore.setStatus(1L); + List payBeforeList = usersPayBeforService.selectUsersPayBeforList(payBefore); + if (!payBeforeList.isEmpty()) { + for (UsersPayBefor payBefore1 : payBeforeList) { + usersPayBeforService.deleteUsersPayBeforById(payBefore1.getId()); + } + } +// UserDemandQuotation quotation1=new UserDemandQuotation(); +// quotation1.setOrderid(order.getOrderId()); +// quotation1.setStatus(1L); +// List quotationList = userDemandQuotationService.selectUserDemandQuotationList(quotation1); +// if (!quotationList.isEmpty()) { +// for (UserDemandQuotation quotation2 : quotationList) { +// userDemandQuotationService.deleteUserDemandQuotationById(quotation2.getId()); +// } +// } + } + + // 10. 更新订单状态为待支付(11) //为了防止出现支付多条订单为同一个订单号的情况,就需要重新生成订单号 - orderId=GenerateCustomCode.generCreateOrder("XQ"); - order.setStatus(11L); - order.setOrderId(orderId); - order.setWorkerId(quotation.getWorkerid()); - int orderUpdateResult = orderService.updateOrder(order); - if (orderUpdateResult <= 0) { - return AppletControllerUtil.appletWarning("更新订单状态失败"); - } + // orderId=GenerateCustomCode.generCreateOrder("XQ"); +// orderId=order.getOrderId(); +// order.setStatus(11L); +// order.setOrderId(orderId); +// // order.setWorkerId(quotation.getWorkerid()); +// int orderUpdateResult = orderService.updateOrder(order); +// if (orderUpdateResult <= 0) { +// return AppletControllerUtil.appletWarning("更新订单状态失败"); +// } // 11. 创建预支付记录 PayBeforeUtil payBeforeUtil = new PayBeforeUtil(); String payOrderId = payBeforeUtil.createPayBefore( @@ -2328,7 +2421,8 @@ public class AppleOrderController extends BaseController { order.getAddressId(), order.getMakeTime() != null ? order.getMakeTime().toString() : "", order.getFileData() != null ? order.getFileData() : "", - 2L // servicetype=2表示服务类型 + 1L, // servicetype=2表示服务类型 + quotation.getId(), order.getOrderId() ); if (payOrderId == null) { @@ -2338,7 +2432,7 @@ public class AppleOrderController extends BaseController { // 12. 返回预支付信息 Map result = new HashMap<>(); result.put("orderid", payOrderId); - result.put("type", "1"); // 1表示需要调起支付 + result.put("type", "2"); // 1表示需要调起支付 result.put("totalAmount", quotation.getMoney()); result.put("workerName", quotation.getWorkername()); result.put("quotationId", baojiaId); @@ -2365,6 +2459,8 @@ public class AppleOrderController extends BaseController { @RequestParam(value = "status", required = false) Integer status, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, + @RequestParam(value = "dayDate", required = false) String dayDate, + @RequestParam(value = "day", required = false) String day, HttpServletRequest request) { try { // 1. 验证用户登录状态 @@ -2377,41 +2473,91 @@ public class AppleOrderController extends BaseController { if (user == null) { return AppletControllerUtil.appletWarning("用户信息获取失败"); } - List orderList; - // 2. 查询逻辑 - if (status != null && status == 8) { - // 查询所有status=8的订单 - Order queryOrder = new Order(); - queryOrder.setStatus(8L); - orderList = orderService.selectOrderList(queryOrder); - } else if (status != null && status == 10) { - // 查询当前师傅报过价且status=1的报价,查其orderid对应订单 - UserDemandQuotation query = new UserDemandQuotation(); - query.setWorkerid(user.getId()); - query.setStatus(1L); // 1=已报价 - List quoteList = userDemandQuotationService.selectUserDemandQuotationList(query); - List orderIds = new ArrayList<>(); - for (UserDemandQuotation q : quoteList) { - if (q.getOrderid() != null) { - orderIds.add(q.getOrderid()); - } + List orderList = new ArrayList<>(); + Order queryOrder = new Order(); + // 直接用dayDate字符串查 + if (org.apache.commons.lang3.StringUtils.isNotBlank(dayDate)) { + queryOrder.setDayDate(dayDate); + } else if (org.apache.commons.lang3.StringUtils.isNotBlank(day)) { + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + long todayStart = cal.getTimeInMillis() / 1000; + long tomorrowStart = todayStart + 24 * 60 * 60; + if ("today".equals(day)) { + queryOrder.setMakeTimeStart(todayStart); + queryOrder.setMakeTimeEnd(tomorrowStart); + } else if ("tomorrow".equals(day)) { + queryOrder.setMakeTimeStart(tomorrowStart); + queryOrder.setMakeTimeEnd(tomorrowStart + 24 * 60 * 60); } - orderList = new ArrayList<>(); - if (!orderIds.isEmpty()) { - for (String oid : orderIds) { - Order o = orderService.selectOrderByOrderId(oid); - if (o != null) orderList.add(o); - } + } + // ... existing code ... + if (status != null && (status == 8 || status == 12)) { + if (status == 8){ + //queryOrder.setWorkerId(user.getId()); + queryOrder.setStatus(8L); + orderList = orderService.selectOrderList(queryOrder); } - } else { - // 普通师傅订单查询 - Order queryOrder = new Order(); + if (status == 12){{ + //queryOrder.setWorkerId(user.getId()); + queryOrder.setBaojiasf(user.getId()); + orderList = orderService.selectOrderList(queryOrder); + + } + } + + }else{ queryOrder.setWorkerId(user.getId()); if (status != null) { - queryOrder.setStatus(Long.valueOf(status)); + if (status == 4){ + List idslist=new ArrayList<>(); + idslist.add("4"); + idslist.add("7"); + queryOrder.setIds(idslist); + }else{ + queryOrder.setStatus(Long.valueOf(status)); + } } orderList = orderService.selectOrderList(queryOrder); } + +// // 2. 查询逻辑 +// if (status != null && status == 8) { +// // 查询所有status=8的订单 +// Order queryOrder = new Order(); +// queryOrder.setStatus(8L); +// orderList = orderService.selectOrderList(queryOrder); +// } else if (status != null && status == 12) { +// // 查询当前师傅报过价且status=1的报价,查其orderid对应订单 +// UserDemandQuotation query = new UserDemandQuotation(); +// query.setWorkerid(user.getId()); +// query.setStatus(1L); // 1=已报价 +// List quoteList = userDemandQuotationService.selectUserDemandQuotationList(query); +// List orderIds = new ArrayList<>(); +// for (UserDemandQuotation q : quoteList) { +// if (q.getOrderid() != null) { +// orderIds.add(q.getOrderid()); +// } +// } +// orderList = new ArrayList<>(); +// if (!orderIds.isEmpty()) { +// for (String oid : orderIds) { +// Order o = orderService.selectOrderByOrderId(oid); +// if (o != null) orderList.add(o); +// } +// } +// } else { +// // 普通师傅订单查询 +// Order queryOrder = new Order(); +// queryOrder.setWorkerId(user.getId()); +// if (status != null) { +// queryOrder.setStatus(Long.valueOf(status)); +// } +// orderList = orderService.selectOrderList(queryOrder); +// } // 3. 分页处理 int total = orderList.size(); int fromIndex = Math.max(0, (pageNum - 1) * pageSize); @@ -2532,7 +2678,19 @@ public class AppleOrderController extends BaseController { result.put("name", worker.getName()); result.put("avatar", AppletControllerUtil.buildImageUrl(worker.getAvatar())); result.put("jobNo", worker.getJobNumber()); + result.put("level", worker.getLevel()); result.put("phone", worker.getPhone()); + //IWorkerLevelService workerLevelService; + if ( worker.getLevel()!=null){ + WorkerLevel workerLevel = workerLevelService.selectWorkerLevelByLevel(Long.valueOf(worker.getLevel())); + if (workerLevel != null){ + result.put("levelName", workerLevel.getTitle()); + result.put("levelImage",AppletControllerUtil.buildImageUrl(workerLevel.getImage())); + }else{ + result.put("levelName", ""); + result.put("levelImage",""); + } + } // 2. 服务区域 List> cityList = new ArrayList<>(); try { @@ -2540,7 +2698,7 @@ public class AppleOrderController extends BaseController { List cityIds; String cityIdsStr = worker.getServiceCityIds().trim(); if (cityIdsStr.startsWith("[") && cityIdsStr.endsWith("]")) { - cityIds = com.alibaba.fastjson2.JSON.parseArray(cityIdsStr, String.class); + cityIds = JSON.parseArray(cityIdsStr, String.class); } else { cityIds = Arrays.asList(cityIdsStr.split(",")); } @@ -2567,7 +2725,7 @@ public class AppleOrderController extends BaseController { List skillIds; String skillIdsStr = worker.getSkillIds().trim(); if (skillIdsStr.startsWith("[") && skillIdsStr.endsWith("]")) { - skillIds = com.alibaba.fastjson2.JSON.parseArray(skillIdsStr, String.class); + skillIds = JSON.parseArray(skillIdsStr, String.class); } else { skillIds = Arrays.asList(skillIdsStr.split(",")); } @@ -2659,11 +2817,11 @@ public class AppleOrderController extends BaseController { */ @GetMapping("/api/comment/list") public AjaxResult getCommentList( - @RequestParam(value = "order_id", required = false) String orderId, - @RequestParam(value = "product_id", required = false) Long productId, + @RequestParam(value = "orderid", required = false) String orderId, + @RequestParam(value = "productid", required = false) Long productId, @RequestParam(value = "uid", required = false) Long uid, - @RequestParam(value = "worker_id", required = false) Long workerId, - @RequestParam(value = "num_type", required = false) Integer numType, + @RequestParam(value = "workerid", required = false) Long workerId, + @RequestParam(value = "numtype", required = false) Long numType, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize ) { @@ -2673,7 +2831,7 @@ public class AppleOrderController extends BaseController { if (productId != null) query.setProductId(productId); if (uid != null) query.setUid(uid); if (workerId != null) query.setWorkerId(workerId); - if (numType != null) query.setNumType(Long.valueOf(numType)); + if (numType != null) query.setNumType(numType); List allList = orderCommentService.selectOrderCommentList(query); int total = allList.size(); int fromIndex = Math.max(0, (pageNum - 1) * pageSize); @@ -2687,7 +2845,8 @@ public class AppleOrderController extends BaseController { cMap.put("userName", usersdata != null ? usersdata.getName() : ""); cMap.put("userAvatar", usersdata != null ? AppletControllerUtil.buildImageUrl(usersdata.getAvatar()) : ""); cMap.put("score", c.getNum()); - cMap.put("labels", c.getLabels() != null ? JSON.toJSONString(c.getLabels()) : null); + cMap.put("labels", c.getLabels() != null ? JSONArray.parseArray(c.getLabels()) : null); + cMap.put("images",c.getImages() != null ? JSONArray.parseArray(c.getImages()): null ); cMap.put("numType", c.getNumType()); cMap.put("content", c.getContent()); cMap.put("date", c.getCreatedAt() != null ? sdf.format(c.getCreatedAt()) : ""); @@ -2705,4 +2864,999 @@ public class AppleOrderController extends BaseController { } } + /** + * 报价查看接口 + * 查询指定订单下的所有报价,支持价格和时间共存排序 + * @param oid 订单ID + * @param priceSort 价格排序:1-升序,2-降序,0-不排序 + * @param timeSort 时间排序:1-升序,2-降序,0-不排序 + * @param groupBy 分组方式:1-按师傅等级分组,2-按价格区间分组,3-按评价等级分组,0-不分组 + * @param pageNum 页码 + * @param pageSize 每页数量 + * @param request HTTP请求对象 + * @return 报价列表 + */ + @GetMapping("/api/quotation/list") + public AjaxResult getQuotationList( + @RequestParam("oid") Long oid, + @RequestParam(value = "priceSort", defaultValue = "0") Integer priceSort, + @RequestParam(value = "timeSort", defaultValue = "0") Integer timeSort, + @RequestParam(value = "groupBy", defaultValue = "0") Integer groupBy, + @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, + @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, + HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 2. 查询订单信息,验证订单是否存在 + Order order = orderService.selectOrderById(oid); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + + // 3. 查询该订单下的所有报价 + UserDemandQuotation query = new UserDemandQuotation(); + query.setOid(oid); + List allQuotations = userDemandQuotationService.selectUserDemandQuotationList(query); + + // 4. 根据排序参数进行排序(价格和时间共存排序) + if ((priceSort != null && priceSort > 0) || (timeSort != null && timeSort > 0)) { + allQuotations.sort((q1, q2) -> { + int result = 0; + + // 价格排序(优先级高) + if (priceSort != null && priceSort > 0) { + BigDecimal price1 = q1.getMoney() != null ? q1.getMoney() : BigDecimal.ZERO; + BigDecimal price2 = q2.getMoney() != null ? q2.getMoney() : BigDecimal.ZERO; + result = price1.compareTo(price2); + + // 如果价格排序是降序,则反转结果 + if (priceSort == 2) { + result = -result; + } + } + + // 如果价格相同或没有价格排序,则按时间排序 + if (result == 0 && timeSort != null && timeSort > 0) { + Date time1 = q1.getQuotationTime() != null ? q1.getQuotationTime() : new Date(0); + Date time2 = q2.getQuotationTime() != null ? q2.getQuotationTime() : new Date(0); + result = time1.compareTo(time2); + + // 如果时间排序是降序,则反转结果 + if (timeSort == 2) { + result = -result; + } + } + + return result; + }); + } + + // 5. 根据分组参数进行分组 + Map> groupedQuotations = new HashMap<>(); + boolean hasGrouping = false; + if (groupBy != null && groupBy > 0) { + hasGrouping = true; + if (groupBy == 1) { + // 按师傅等级分组 + for (UserDemandQuotation quotation : allQuotations) { + Users worker = usersService.selectUsersById(quotation.getWorkerid()); + String groupKey = "等级" + (worker != null && worker.getLevel() != null ? worker.getLevel() : "未知"); + groupedQuotations.computeIfAbsent(groupKey, k -> new ArrayList<>()).add(quotation); + } + } else if (groupBy == 2) { + // 按价格区间分组 + for (UserDemandQuotation quotation : allQuotations) { + BigDecimal price = quotation.getMoney() != null ? quotation.getMoney() : BigDecimal.ZERO; + String groupKey = getPriceRangeGroup(price); + groupedQuotations.computeIfAbsent(groupKey, k -> new ArrayList<>()).add(quotation); + } + } else if (groupBy == 3) { + // 按评价等级分组 + for (UserDemandQuotation quotation : allQuotations) { + double goodRate = getWorkerGoodRate(quotation.getWorkerid()); + String groupKey = getRatingGroup(goodRate); + groupedQuotations.computeIfAbsent(groupKey, k -> new ArrayList<>()).add(quotation); + } + } + + // 对分组后的数据进行排序 + List sortedGroupedQuotations = new ArrayList<>(); + List sortedGroupKeys = new ArrayList<>(groupedQuotations.keySet()); + + // 根据分组类型对分组键进行排序(默认按升序) + if (groupBy == 1) { + // 按等级数字排序 + sortedGroupKeys.sort((k1, k2) -> { + try { + int level1 = Integer.parseInt(k1.replace("等级", "")); + int level2 = Integer.parseInt(k2.replace("等级", "")); + return level1 - level2; // 默认升序 + } catch (NumberFormatException e) { + return k1.compareTo(k2); + } + }); + } else if (groupBy == 2) { + // 按价格区间排序 + sortedGroupKeys.sort((k1, k2) -> { + BigDecimal min1 = getPriceRangeMin(k1); + BigDecimal min2 = getPriceRangeMin(k2); + return min1.compareTo(min2); // 默认升序 + }); + } else if (groupBy == 3) { + // 按评价等级排序 + sortedGroupKeys.sort((k1, k2) -> { + double rate1 = getRatingGroupRate(k1); + double rate2 = getRatingGroupRate(k2); + return Double.compare(rate1, rate2); // 默认升序 + }); + } + + // 按排序后的分组键重新组装数据 + for (String groupKey : sortedGroupKeys) { + sortedGroupedQuotations.addAll(groupedQuotations.get(groupKey)); + } + allQuotations = sortedGroupedQuotations; + } + + // 6. 分页处理 + int total = allQuotations.size(); + int fromIndex = Math.max(0, (pageNum - 1) * pageSize); + int toIndex = Math.min(fromIndex + pageSize, total); + List pageQuotations = fromIndex < toIndex ? + allQuotations.subList(fromIndex, toIndex) : new ArrayList<>(); + + // 6. 构建返回数据 + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd"); + + for (UserDemandQuotation quotation : pageQuotations) { + Map quoteMap = new HashMap<>(); + + // 基本信息 + quoteMap.put("id", quotation.getId()); + quoteMap.put("orderId", quotation.getOrderid()); + quoteMap.put("money", quotation.getMoney()); + quoteMap.put("status", quotation.getStatus()); + quoteMap.put("statusText", getQuotationStatusText(quotation.getStatus())); + + // 时间信息 +// quoteMap.put("createTime", quotation.getCreatedAt() != null ? sdf.format(quotation.getCreatedAt()) : ""); +// quoteMap.put("createDate", quotation.getCreatedAt() != null ? sdfDate.format(quotation.getCreatedAt()) : ""); + quoteMap.put("quotationTime", quotation.getQuotationTime() != null ? sdf.format(quotation.getQuotationTime()) : ""); + + // 师傅信息 + if (quotation.getWorkerid() != null) { + Users worker = usersService.selectUsersById(quotation.getWorkerid()); + if (worker != null) { + quoteMap.put("workerId", worker.getId()); + quoteMap.put("workerName", worker.getName()); + quoteMap.put("workerAvatar", AppletControllerUtil.buildImageUrl(worker.getAvatar())); + quoteMap.put("workerPhone", worker.getPhone()); + quoteMap.put("workerJobNo", worker.getJobNumber()); + + // 师傅服务区域 +// List> cityList = new ArrayList<>(); +// try { +// if (worker.getServiceCityIds() != null && !worker.getServiceCityIds().trim().isEmpty()) { +// List cityIds; +// String cityIdsStr = worker.getServiceCityIds().trim(); +// if (cityIdsStr.startsWith("[") && cityIdsStr.endsWith("]")) { +// cityIds = com.alibaba.fastjson2.JSON.parseArray(cityIdsStr, String.class); +// } else { +// cityIds = Arrays.asList(cityIdsStr.split(",")); +// } +// for (String cityId : cityIds) { +// if (cityId != null && !cityId.trim().isEmpty()) { +// DiyCity city = diyCityService.selectDiyCityById(Math.toIntExact(Long.parseLong(cityId.replaceAll("\"", "").trim()))); +// if (city != null) { +// Map cityMap = new HashMap<>(); +// cityMap.put("id", city.getId()); +// cityMap.put("name", city.getTitle()); +// cityList.add(cityMap); +// } +// } +// } +// } +// } catch (Exception e) { +// logger.warn("解析师傅服务区域失败:" + e.getMessage()); +// } +// quoteMap.put("workerServiceCities", cityList); + +// // 师傅技能 +// List> skillList = new ArrayList<>(); +// try { +// if (worker.getSkillIds() != null && !worker.getSkillIds().trim().isEmpty()) { +// List skillIds; +// String skillIdsStr = worker.getSkillIds().trim(); +// if (skillIdsStr.startsWith("[") && skillIdsStr.endsWith("]")) { +// skillIds = com.alibaba.fastjson2.JSON.parseArray(skillIdsStr, String.class); +// } else { +// skillIds = Arrays.asList(skillIdsStr.split(",")); +// } +// for (String skillId : skillIds) { +// if (skillId != null && !skillId.trim().isEmpty()) { +// SiteSkill skill = siteSkillService.selectSiteSkillById(Long.parseLong(skillId.replaceAll("\"", "").trim())); +// if (skill != null) { +// Map skillMap = new HashMap<>(); +// skillMap.put("id", skill.getId()); +// skillMap.put("name", skill.getTitle()); +// skillList.add(skillMap); +// } +// } +// } +// } +// } catch (Exception e) { +// logger.warn("解析师傅技能失败:" + e.getMessage()); +// } +// quoteMap.put("workerSkills", skillList); + + // 师傅评价统计 +// OrderComment commentQuery = new OrderComment(); +// commentQuery.setWorkerId(worker.getId()); +// List workerComments = orderCommentService.selectOrderCommentList(commentQuery); +// int goodNum = 0, midNum = 0, badNum = 0, totalNum = 0; +// for (OrderComment c : workerComments) { +// if (c.getNumType() != null) { +// if (c.getNumType() == 1) goodNum++; +// else if (c.getNumType() == 2) midNum++; +// else if (c.getNumType() == 3) badNum++; +// } +// } +// totalNum = workerComments.size(); +// +// Map commentStat = new HashMap<>(); +// commentStat.put("total", totalNum); +// commentStat.put("good", goodNum); +// commentStat.put("mid", midNum); +// commentStat.put("bad", badNum); +// quoteMap.put("workerCommentStat", commentStat); + } + } + + resultList.add(quoteMap); + } + + // 7. 构建分页结果 + Map pageResult = new HashMap<>(); + pageResult.put("total", total); + pageResult.put("pageNum", pageNum); + pageResult.put("pageSize", pageSize); + pageResult.put("data", resultList); + +// // 8. 添加排序信息 +// Map sortInfo = new HashMap<>(); +// sortInfo.put("priceSort", priceSort); +// sortInfo.put("timeSort", timeSort); +// sortInfo.put("priceSortText", getSortText(priceSort, "价格")); +// sortInfo.put("timeSortText", getSortText(timeSort, "时间")); +// pageResult.put("sortInfo", sortInfo); + +// // 9. 添加分组信息 +// if (hasGrouping) { +// Map groupInfo = new HashMap<>(); +// groupInfo.put("groupBy", groupBy); +// groupInfo.put("groupByText", getGroupByText(groupBy)); +// groupInfo.put("groupCount", groupedQuotations.size()); +// groupInfo.put("groupDetails", buildGroupDetails(groupedQuotations, groupBy)); +// pageResult.put("groupInfo", groupInfo); +// } + + // 10. 添加订单基本信息 + Map orderInfo = new HashMap<>(); + orderInfo.put("orderId", order.getOrderId()); + orderInfo.put("orderStatus", order.getStatus()); + orderInfo.put("orderStatusText", getOrderStatusText(order.getStatus())); + orderInfo.put("productName", order.getProductName()); + orderInfo.put("totalQuotations", total); + pageResult.put("orderInfo", orderInfo); + + return AppletControllerUtil.appletSuccess(pageResult); + + } catch (Exception e) { + logger.error("查询报价列表失败:", e); + return AppletControllerUtil.appletError("查询报价列表失败:" + e.getMessage()); + } + } + + /** + * 获取报价状态文本 + * @param status 报价状态 + * @return 状态文本 + */ + private String getQuotationStatusText(Long status) { + if (status == null) return "未知"; + switch (status.intValue()) { + case 1: return "已报价"; + case 2: return "已选中"; + default: return "未知"; + } + } + + /** + * 获取师傅好评率 + * @param workerId 师傅ID + * @return 好评率(0-1之间的小数) + */ + private double getWorkerGoodRate(Long workerId) { + try { + OrderComment commentQuery = new OrderComment(); + commentQuery.setWorkerId(workerId); + List workerComments = orderCommentService.selectOrderCommentList(commentQuery); + + if (workerComments.isEmpty()) { + return 0.0; + } + + int goodNum = 0; + for (OrderComment c : workerComments) { + if (c.getNumType() != null && c.getNumType() == 1) { + goodNum++; + } + } + + return (double) goodNum / workerComments.size(); + } catch (Exception e) { + logger.warn("计算师傅好评率失败,师傅ID: " + workerId + ", 错误: " + e.getMessage()); + return 0.0; + } + } + + /** + * 获取师傅综合评分 + * @param quotation 报价信息 + * @return 综合评分 + */ + private double getWorkerComprehensiveScore(UserDemandQuotation quotation) { + try { + double score = 0.0; + + // 1. 价格评分(价格越低分数越高,满分30分) + BigDecimal price = quotation.getMoney() != null ? quotation.getMoney() : BigDecimal.ZERO; + if (price.compareTo(BigDecimal.ZERO) > 0) { + // 假设价格在100-1000之间,价格越低分数越高 + double priceScore = Math.max(0, 30 - (price.doubleValue() - 100) / 30); + score += priceScore; + } + + // 2. 等级评分(等级越高分数越高,满分30分) + Users worker = usersService.selectUsersById(quotation.getWorkerid()); + if (worker != null && worker.getLevel() != null) { + double levelScore = Math.min(30, worker.getLevel() * 10); // 假设等级1-3,每级10分 + score += levelScore; + } + + // 3. 评价评分(好评率越高分数越高,满分40分) + double goodRate = getWorkerGoodRate(quotation.getWorkerid()); + double ratingScore = goodRate * 40; + score += ratingScore; + + return score; + } catch (Exception e) { + logger.warn("计算师傅综合评分失败,报价ID: " + quotation.getId() + ", 错误: " + e.getMessage()); + return 0.0; + } + } + + /** + * 获取价格区间分组 + * @param price 价格 + * @return 价格区间分组名称 + */ + private String getPriceRangeGroup(BigDecimal price) { + if (price == null || price.compareTo(BigDecimal.ZERO) <= 0) { + return "价格未知"; + } + + double priceValue = price.doubleValue(); + if (priceValue < 100) { + return "100元以下"; + } else if (priceValue < 200) { + return "100-200元"; + } else if (priceValue < 300) { + return "200-300元"; + } else if (priceValue < 500) { + return "300-500元"; + } else if (priceValue < 1000) { + return "500-1000元"; + } else { + return "1000元以上"; + } + } + + /** + * 获取价格区间的最小值 + * @param groupKey 分组键 + * @return 最小值 + */ + private BigDecimal getPriceRangeMin(String groupKey) { + switch (groupKey) { + case "100元以下": return new BigDecimal("0"); + case "100-200元": return new BigDecimal("100"); + case "200-300元": return new BigDecimal("200"); + case "300-500元": return new BigDecimal("300"); + case "500-1000元": return new BigDecimal("500"); + case "1000元以上": return new BigDecimal("1000"); + default: return BigDecimal.ZERO; + } + } + + /** + * 获取评价等级分组 + * @param goodRate 好评率 + * @return 评价等级分组名称 + */ + private String getRatingGroup(double goodRate) { + if (goodRate >= 0.9) { + return "优秀评价(90%+)"; + } else if (goodRate >= 0.8) { + return "良好评价(80-90%)"; + } else if (goodRate >= 0.7) { + return "一般评价(70-80%)"; + } else if (goodRate >= 0.6) { + return "较差评价(60-70%)"; + } else { + return "差评(60%以下)"; + } + } + + /** + * 获取评价等级分组的基准评分 + * @param groupKey 分组键 + * @return 基准评分 + */ + private double getRatingGroupRate(String groupKey) { + switch (groupKey) { + case "优秀评价(90%+)": return 0.95; + case "良好评价(80-90%)": return 0.85; + case "一般评价(70-80%)": return 0.75; + case "较差评价(60-70%)": return 0.65; + case "差评(60%以下)": return 0.3; + default: return 0.0; + } + } + + /** + * 获取排序方式文本 + * @param sortType 排序类型 + * @param fieldName 字段名称 + * @return 排序方式文本 + */ + private String getSortText(Integer sortType, String fieldName) { + if (sortType == null || sortType == 0) return fieldName + "不排序"; + switch (sortType) { + case 1: return fieldName + "升序"; + case 2: return fieldName + "降序"; + default: return fieldName + "不排序"; + } + } + + /** + * 获取分组方式文本 + * @param groupBy 分组方式 + * @return 分组方式文本 + */ + private String getGroupByText(Integer groupBy) { + if (groupBy == null) return "不分组"; + switch (groupBy) { + case 1: return "按师傅等级分组"; + case 2: return "按价格区间分组"; + case 3: return "按评价等级分组"; + default: return "不分组"; + } + } + + /** + * 构建分组详情 + * @param groupedQuotations 分组后的报价数据 + * @param groupBy 分组方式 + * @return 分组详情 + */ + private List> buildGroupDetails(Map> groupedQuotations, Integer groupBy) { + List> groupDetails = new ArrayList<>(); + + for (Map.Entry> entry : groupedQuotations.entrySet()) { + Map groupDetail = new HashMap<>(); + groupDetail.put("groupName", entry.getKey()); + groupDetail.put("count", entry.getValue().size()); + + // 计算该分组的平均价格 + BigDecimal totalPrice = BigDecimal.ZERO; + int validPriceCount = 0; + for (UserDemandQuotation quotation : entry.getValue()) { + if (quotation.getMoney() != null) { + totalPrice = totalPrice.add(quotation.getMoney()); + validPriceCount++; + } + } + + if (validPriceCount > 0) { + BigDecimal avgPrice = totalPrice.divide(BigDecimal.valueOf(validPriceCount), 2, BigDecimal.ROUND_HALF_UP); + groupDetail.put("avgPrice", avgPrice); + } else { + groupDetail.put("avgPrice", BigDecimal.ZERO); + } + + // 根据分组类型添加特定信息 + if (groupBy == 1) { + // 师傅等级分组 + groupDetail.put("groupType", "level"); + } else if (groupBy == 2) { + // 价格区间分组 + groupDetail.put("groupType", "price"); + } else if (groupBy == 3) { + // 评价等级分组 + groupDetail.put("groupType", "rating"); + } + + groupDetails.add(groupDetail); + } + + return groupDetails; + } + /** + * 修改预约时间接口 + * @param params {"id":"订单id","make_time":"预约时间"} + * @return 操作结果 + */ + @PostMapping("/api/service/update/make/time/") + public AjaxResult updateMakeTime(@RequestBody Map params) { + try { + // 1. 校验参数 + if (params == null || params.get("id") == null || params.get("make_time") == null) { + return AjaxResult.error("参数id和make_time不能为空"); + } + Long id; + try { + id = Long.valueOf(params.get("id").toString()); + } catch (Exception e) { + return AjaxResult.error("id格式错误"); + } + String makeTime = params.get("make_time").toString(); + // 2. 查询订单 + Order order = orderService.selectOrderById(id); + if (order == null) { + return AjaxResult.error("订单不存在"); + } + // 3. 解析预约时间 + // 预约时间格式:2025-07-21 8:00-10:00 + String[] arr = makeTime.split(" "); + if (arr.length != 2) { + return AjaxResult.error("make_time格式错误,需为'yyyy-MM-dd HH:mm-HH:mm'"); + } + String dateStr = arr[0]; + String hourStr = arr[1]; + Long makeTimeStamp = null; + try { + java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd"); + java.util.Date date = sdf.parse(dateStr); + makeTimeStamp = date.getTime() / 1000; + } catch (Exception e) { + return AjaxResult.error("日期格式错误"); + } + // 4. 更新订单 + order.setMakeTime(makeTimeStamp); + order.setMakeHour(hourStr); + int result = orderService.updateOrder(order); + if (result <= 0) { + return AjaxResult.error("预约时间修改失败"); + } + return AjaxResult.success("预约时间修改成功"); + } catch (Exception e) { + logger.error("修改预约时间失败:", e); + return AjaxResult.error("修改预约时间失败:" + e.getMessage()); + } + } + /** + * 跟单功能接口 + * @param params {"oid":订单ID, "content":跟单内容} + * @param request HTTP请求对象 + * @return 操作结果 + */ + @PostMapping("/api/order/follow") + public AjaxResult followOrder(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 校验参数 + if (params == null || params.get("oid") == null || params.get("content") == null) { + return AppletControllerUtil.appletWarning("参数oid和content不能为空"); + } + Long oid; + try { + oid = Long.valueOf(params.get("oid").toString()); + } catch (Exception e) { + return AppletControllerUtil.appletWarning("oid格式错误"); + } + String content = params.get("content").toString(); + // 2. 校验订单是否存在 + Order order = orderService.selectOrderById(oid); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + // 3. 查询最新一条日志,获取type + java.math.BigDecimal logType = null; + try { + OrderLog latestLog = orderLogService.selectDataTheFirstNew(oid); + if (latestLog != null && latestLog.getType() != null) { + logType = latestLog.getType(); + } + } catch (Exception e) { + // 查询异常,logType保持null + } + // 4. 构造订单日志对象 + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setWorkerId(order.getWorkerId()); + orderLog.setWorkerLogId(order.getWorkerId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("师傅跟单"); + orderLog.setType(logType); // 跟单type与最新日志一致 + // content格式为{"name":内容} + com.alibaba.fastjson2.JSONObject json = new com.alibaba.fastjson2.JSONObject(); + json.put("name", content); + orderLog.setContent(json.toJSONString()); + // 5. 插入日志 + int result = orderLogService.insertOrderLog(orderLog); + if (result <= 0) { + return AppletControllerUtil.appletWarning("跟单日志插入失败"); + } + return AppletControllerUtil.appletSuccess("跟单成功"); + } catch (Exception e) { + logger.error("跟单失败:", e); + return AppletControllerUtil.appletError("跟单失败:" + e.getMessage()); + } + } + + /** + * 区域列表接口 + * @param pageNum 页码 + * @param pageSize 每页数量 + * @return 区域分页列表 + */ + @GetMapping("/api/area/list") + public AjaxResult getAreaList(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum, + @RequestParam(value = "pageSize", defaultValue = "120") int pageSize) { + try { + List allList = diyCityService.selectDiyCityList(new DiyCity()); + int total = allList.size(); + int fromIndex = Math.max(0, (pageNum - 1) * pageSize); + int toIndex = Math.min(fromIndex + pageSize, total); + List pageList = fromIndex < toIndex ? allList.subList(fromIndex, toIndex) : new java.util.ArrayList<>(); + // 只返回title和id + List> simpleList = new java.util.ArrayList<>(); + for (DiyCity city : pageList) { + Map map = new HashMap<>(); + map.put("id", city.getId()); + map.put("title", city.getTitle()); + simpleList.add(map); + } + Map result = new HashMap<>(); + result.put("total", total); + result.put("pageNum", pageNum); + result.put("pageSize", pageSize); + result.put("data", simpleList); + return AjaxResult.success(result); + } catch (Exception e) { + logger.error("查询区域列表失败:", e); + return AjaxResult.error("查询区域列表失败:" + e.getMessage()); + } + } + + /** + * 技能列表接口 + * @param pageNum 页码 + * @param pageSize 每页数量 + * @return 技能分页列表 + */ + @GetMapping("/api/skill/list") + public AjaxResult getSkillList(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum, + @RequestParam(value = "pageSize", defaultValue = "100") int pageSize) { + try { + List allList = siteSkillService.selectSiteSkillList(new SiteSkill()); + int total = allList.size(); + int fromIndex = Math.max(0, (pageNum - 1) * pageSize); + int toIndex = Math.min(fromIndex + pageSize, total); + List pageList = fromIndex < toIndex ? allList.subList(fromIndex, toIndex) : new java.util.ArrayList<>(); + // 只返回title和id + List> simpleList = new java.util.ArrayList<>(); + for (SiteSkill skill : pageList) { + Map map = new HashMap<>(); + map.put("id", skill.getId()); + map.put("title", skill.getTitle()); + simpleList.add(map); + } + Map result = new HashMap<>(); + result.put("total", total); + result.put("pageNum", pageNum); + result.put("pageSize", pageSize); + result.put("data", simpleList); + return AjaxResult.success(result); + } catch (Exception e) { + logger.error("查询技能列表失败:", e); + return AjaxResult.error("查询技能列表失败:" + e.getMessage()); + } + } + + /** + * 评论删除接口 + * @param id 评论ID + * @return 操作结果 + */ + @PostMapping("/api/goods/order/del/comment/{id}") + public AjaxResult deleteOrderComment(@PathVariable("id") Long id) { + try { + // 1. 查询评论 + OrderComment comment = new OrderComment(); + comment.setOid(id); + List comments = orderCommentService.selectOrderCommentList(comment); + if (!comments.isEmpty()){ + for (OrderComment c : comments){ + c.setStatus(0); + orderCommentService.updateOrderComment(c); + } + return AppletControllerUtil.appletSuccess("评论删除成功"); + } + + + + } catch (Exception e) { + logger.error("评论删除失败:", e); + return AppletControllerUtil.appletError("评论删除失败:" + e.getMessage()); + } + return AppletControllerUtil.appletSuccess("评论删除成功"); + } + + /** + * 拼团预约接口 + * @param params {id, address_id, make_time} + * @return 操作结果 + */ + @PostMapping("/api/group/order/appoint") + public AjaxResult groupOrderAppoint(@RequestBody Map params) { + try { + // 1. 校验参数 + if (params == null || params.get("id") == null || params.get("address_id") == null || params.get("make_time") == null) { + return AppletControllerUtil.appletWarning("参数id、address_id、make_time不能为空"); + } + Long id = Long.valueOf(params.get("id").toString()); + Long addressId = Long.valueOf(params.get("address_id").toString()); + String makeTimeStr = params.get("make_time").toString(); + String type = params.get("type").toString();; + + // 2. 查询订单 + Order order = orderService.selectOrderById(id); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + + // 3. 查询地址 + UserAddress userAddress = userAddressService.selectUserAddressById(addressId); + if (userAddress == null) { + return AppletControllerUtil.appletWarning("地址不存在"); + } + + // 4. 解析预约时间 + Long makeTime = null; + String makeHour = ""; + if (makeTimeStr != null && !makeTimeStr.isEmpty()) { + String[] arr = makeTimeStr.split(" "); + if (arr.length == 2) { + try { + java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd"); + java.util.Date date = sdf.parse(arr[0]); + makeTime = date.getTime() / 1000; + makeHour = arr[1]; + } catch (Exception e) { + return AppletControllerUtil.appletWarning("make_time格式错误,需为'yyyy-MM-dd HH:mm'"); + } + } else { + return AppletControllerUtil.appletWarning("make_time格式错误,需为'yyyy-MM-dd HH:mm'"); + } + } + + // 5. 更新订单信息 + order.setAddressId(userAddress.getId()); + order.setName(userAddress.getName()); + order.setPhone(userAddress.getPhone()); + order.setAddress(userAddress.getAddressInfo()); + order.setMakeTime(makeTime); + order.setMakeHour(makeHour); + order.setStatus(1L); // 待接单 + order.setJsonStatus(0); // 预约状态 + int updateResult = orderService.updateOrder(order); + if (updateResult <= 0) { + return AppletControllerUtil.appletWarning("预约失败,订单更新异常"); + } + + // 6. 添加订单日志 + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("拼团预约"); + orderLog.setType(java.math.BigDecimal.valueOf(1.0)); + com.alibaba.fastjson2.JSONObject json = new com.alibaba.fastjson2.JSONObject(); + json.put("name", "拼团预约成功,待接单"); + orderLog.setContent(json.toJSONString()); + orderLogService.insertOrderLog(orderLog); + if (type.equals("2")){ + UserGroupBuying userGroupBuying = userGroupBuyingService.selectUserGroupBuyingByptorderid(order.getOrderId()); + if (userGroupBuying != null){ + userGroupBuyingService.deleteUserGroupBuyingById(userGroupBuying.getId()); + } + UsersPayBefor payBefor = usersPayBeforService.selectUsersPayBeforByOrderId(order.getOrderId()); + if (payBefor != null){ + payBefor.setGrouporderid(order.getOrderId()); + usersPayBeforService.updateUsersPayBefor(payBefor); + } + } + return AppletControllerUtil.appletSuccess("拼团预约成功"); + } catch (Exception e) { + logger.error("拼团预约失败:", e); + return AppletControllerUtil.appletError("拼团预约失败:" + e.getMessage()); + } + } + + /** + * 好友支付预览接口 + * @param orderid 预支付订单号 + * @return 预览信息 + */ + @GetMapping("/api/friend/pay/preview") + public AjaxResult friendPayPreview(@RequestParam("orderid") String orderid) { + try { + // 1. 查询预支付信息 + UsersPayBefor payBefor = usersPayBeforService.selectUsersPayBeforByOrderId(orderid); + if (payBefor == null) { + return AppletControllerUtil.appletWarning("预支付订单不存在"); + } + Users user = usersService.selectUsersById(payBefor.getUid()); + Map result = new HashMap<>(); + result.put("needPay", payBefor.getAllmoney()); + result.put("paystatus", payBefor.getStatus()); + result.put("friendname", user.getName()); + // 剩余支付时间(如有createTime字段,保留一分钟倒计时演示) + long leftSeconds = 60; + try { + if (payBefor.getCreateTime() != null) { + long now = System.currentTimeMillis(); + long create = payBefor.getCreateTime().getTime(); + leftSeconds = Math.max(0, 60 - (now - create) / 1000); + } + } catch (Exception e) { + // 没有createTime字段则忽略 + } + result.put("leftSeconds", leftSeconds); + + List> goodsList = new ArrayList<>(); + // 2. 判断服务类型 + if (payBefor.getServicetype() != null && payBefor.getServicetype() == 1L) { + // 服务类 + Order order = orderService.selectOrderByOrderId(orderid); +// if (order == null) { +// return AppletControllerUtil.appletWarning("服务订单不存在"); +// } + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(payBefor.getServiceid()); + if (serviceGoods == null) { + return AppletControllerUtil.appletWarning("服务商品不存在"); + } + + Map item = new HashMap<>(); + item.put("shopName", "服务预约"); + item.put("title", serviceGoods.getTitle()); + item.put("sku",AppletControllerUtil.parseSkuStringToObject(payBefor.getSku())); + item.put("img", AppletControllerUtil.buildImageUrl(serviceGoods.getIcon())); // 假设fileData为图片 + item.put("price", payBefor.getAllmoney()); + if (order != null){ + item.put("num",order.getNum()); + }else{ + item.put("num",1); + } + + goodsList.add(item); + } else if (payBefor.getServicetype() != null && payBefor.getServicetype() == 2L) { + // 商品类 + GoodsOrder goodsOrderQuery = new GoodsOrder(); + goodsOrderQuery.setMainOrderId(orderid); + List goodsOrders = goodsOrderService.selectGoodsOrderList(goodsOrderQuery); + for (GoodsOrder goodsOrder : goodsOrders) { + Map item = new HashMap<>(); + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodsOrder.getProductId()); + if (serviceGoods != null){ + // 兼容无getShopName方法 + item.put("shopName", "商城订单"); + item.put("title", serviceGoods.getTitle()); + // 兼容无getProductIcon方法 + item.put("img",AppletControllerUtil.buildImageUrl(serviceGoods.getIcon())); + item.put("price", goodsOrder.getPayPrice()); + item.put("num", goodsOrder.getNum()); + goodsList.add(item); + } + + } + } else { + return AppletControllerUtil.appletWarning("未知订单类型"); + } + result.put("goodsList", goodsList); + // 3. 代付说明 + // result.put("payDesc", "1. 代付前请先与好友确认无误,避免误支付。\n2. 付款成功后,订单将自动进入处理流程。"); + + return AppletControllerUtil.appletSuccess(result); + } catch (Exception e) { + logger.error("好友支付预览失败:", e); + return AppletControllerUtil.appletError("好友支付预览失败:" + e.getMessage()); + } + } + + /** + * 协议类型接口,返回写死的数据 + */ + @GetMapping("/api/public/content/type") + public AjaxResult getContentType() { + List> data = new ArrayList<>(); + Map item1 = new HashMap<>(); + item1.put("id", 1); + item1.put("text", "用户协议"); + item1.put("is_single", true); + data.add(item1); + Map item2 = new HashMap<>(); + item2.put("id", 2); + item2.put("text", "隐私协议"); + item2.put("is_single", true); + data.add(item2); + return AjaxResult.success(data); + } + + /** + * 查询内容详情接口 + * @param id 内容ID + * @return 内容详情 + */ + @GetMapping("/api/public/content/info/{id}") + public AjaxResult getContentInfo(@PathVariable("id") Long id) { + try { + Content content = contentService.selectContentById(id); + if (content == null) { + return AppletControllerUtil.appletWarning("内容不存在"); + } + return AjaxResult.success(content); + } catch (Exception e) { + logger.error("查询内容详情失败:", e); + return AppletControllerUtil.appletError("查询内容详情失败:" + e.getMessage()); + } + } + + /** + * 统计bigtype为1、2、3且status!=4的订单数量(针对当前用户) + * @return 统计结果 + */ + @GetMapping("/api/order/bigtype/count") + public AjaxResult getOrderCountByBigtype(HttpServletRequest request) { + try { + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + List counts = orderService.selectOrderCountByBigtype(user.getId()); + return AjaxResult.success(counts); + } catch (Exception e) { + logger.error("统计订单数量失败:", e); + return AjaxResult.error("统计订单数量失败:" + e.getMessage()); + } + } + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/ApplePayController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/ApplePayController.java index b13ce5d..d88f11e 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/ApplePayController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/ApplePayController.java @@ -1077,12 +1077,7 @@ public class ApplePayController extends BaseController { }else{ } - } - - - - // 4. 获取订单日志信息 Long orderId = Long.valueOf(params.get("id").toString()); OrderLog orderLog = orderLogService.selectOrderLogById(orderId); @@ -1122,7 +1117,6 @@ public class ApplePayController extends BaseController { return AppletControllerUtil.appletError("支付失败:" + e.getMessage()); } } - /** * 订单支付接口 * 根据订单号查询预支付信息,并根据预支付信息中的支付方式和金额进行支付 @@ -1174,7 +1168,13 @@ public class ApplePayController extends BaseController { if (paytype == 1) { // 微信支付 if (wxMoney.compareTo(BigDecimal.ZERO) <= 0) { - return AppletControllerUtil.appletWarning("微信支付金额不能为0"); + // 金额为0,直接走后续逻辑 + payBefor.setStatus(2L); // 已支付 + payBefor.setPaytime(new Date()); + usersPayBeforService.updateUsersPayBefor(payBefor); + OrderUtil.prepayCallback(payBefor, user); + payResult.put("istowx", 1); + return AppletControllerUtil.appletSuccess("支付成功"); } payResult = wechatPayUtil.createBatchOrderAndPay( user.getOpenid(), @@ -1193,7 +1193,13 @@ public class ApplePayController extends BaseController { } else if (paytype == 2) { // 余额支付 if (yeMoney.compareTo(BigDecimal.ZERO) <= 0) { - return AppletControllerUtil.appletWarning("余额支付金额不能为0"); + // 金额为0,直接走后续逻辑 + payBefor.setStatus(2L); // 已支付 + payBefor.setPaytime(new Date()); + usersPayBeforService.updateUsersPayBefor(payBefor); + OrderUtil.prepayCallback(payBefor, user); + payResult.put("istowx", 2); + return AppletControllerUtil.appletSuccess("支付成功"); } Map balanceResult = BalancePayUtil.processBalancePayment( user.getId(), @@ -1215,6 +1221,15 @@ public class ApplePayController extends BaseController { } } else if (paytype == 3) { // 组合支付 + if (wxMoney.compareTo(BigDecimal.ZERO) <= 0 && yeMoney.compareTo(BigDecimal.ZERO) <= 0) { + // 两项都为0,直接走后续逻辑 + payBefor.setStatus(2L); // 已支付 + payBefor.setPaytime(new Date()); + usersPayBeforService.updateUsersPayBefor(payBefor); + OrderUtil.prepayCallback(payBefor, user); + payResult.put("istowx", 1); + return AppletControllerUtil.appletSuccess("支付成功"); + } if (wxMoney.compareTo(BigDecimal.ZERO) > 0 && yeMoney.compareTo(BigDecimal.ZERO) > 0) { // // 先扣余额 // Map balanceResult = BalancePayUtil.processBalancePayment( @@ -1366,4 +1381,82 @@ public class ApplePayController extends BaseController { } } + /** + * 好友代付接口 + * @param params {orderid, code} + * @param request + * @return 支付参数 + */ + @PostMapping("/friend/pay") + public AjaxResult friendPay(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 校验参数 + if (params == null || params.get("orderid") == null || params.get("code") == null) { + return AppletControllerUtil.appletWarning("参数orderid和code不能为空"); + } + String orderid = params.get("orderid").toString(); + String code = params.get("code").toString(); + + + + Map openidResult = WechatApiUtil.getWechatUserOpenidInfo(code); + + if (!(Boolean) openidResult.get("success")) { + System.err.println("获取openid失败:" + openidResult.get("errorMsg")); + return null; + } + + String openid = (String) openidResult.get("openid"); + if (openid == null || openid.trim().isEmpty()) { + System.err.println("微信API返回的openid为空"); + return null; + } + + +// // 2. 用code获取openid +// String openid = WechatApiUtil.getWechatUserOpenidInfo(code); +// if (openid == null || openid.isEmpty()) { +// return AppletControllerUtil.appletWarning("获取openid失败"); +// } + + // 3. 查询预支付数据 + UsersPayBefor payBefor = usersPayBeforService.selectUsersPayBeforByOrderId(orderid); + if (payBefor == null) { + return AppletControllerUtil.appletWarning("预支付订单不存在"); + } + if (payBefor.getAllmoney() == null || payBefor.getAllmoney().compareTo(BigDecimal.ZERO) <= 0) { + return AppletControllerUtil.appletWarning("支付金额无效"); + } + + // 4. 调用微信支付接口 + Map payResult = wechatPayUtil.createBatchOrderAndPay( + openid, + payBefor.getOrderid(), + new BigDecimal("0.01"), + 1, + WechatPayUtil.PAY_FH + "api/order/friend/paydata/notify" + ); + if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { + Map responseData = new HashMap<>(); + responseData.put("orderid", orderid); + responseData.put("totalAmount", payBefor.getAllmoney()); + responseData.put("prepayId", payResult.get("prepayId")); + responseData.putAll(payResult); + return AppletControllerUtil.appletSuccess(responseData); + } else { + String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; + return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); + } +// if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { +// payResult.put("istowx", 1); +// return AppletControllerUtil.appletSuccess(payResult); +// } else { +// String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; +// return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); +// } + } catch (Exception e) { + logger.error("好友代付异常:", e); + return AppletControllerUtil.appletError("好友代付失败:" + e.getMessage()); + } + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppletController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppletController.java index e5acb46..8d3f105 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppletController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppletController.java @@ -121,6 +121,8 @@ public class AppletController extends BaseController { private IUserGroupBuyingService userGroupBuyingService; @Autowired private IUsersPayBeforService usersPayBeforService; + @Autowired + private IUserDemandQuotationService userDemandQuotationService; @@ -1682,14 +1684,13 @@ public class AppletController extends BaseController { } // 其他业务字段 - //userInfo.put("commission","0.00"); if (user.getType().equals("2")) { - userInfo.put("commission", user.getCommission().toString() != null ? user.getCommission().toString() : "0.00"); - userInfo.put("total_comm", user.getTotalComm().toString() != null ? user.getTotalComm().toString() : "0.00"); - userInfo.put("propose", user.getPropose().toString() != null ? user.getPropose().toString() : "0.00"); + userInfo.put("commission", user.getCommission() != null ? user.getCommission().toString() : "0.00"); + userInfo.put("total_comm", user.getTotalComm() != null ? user.getTotalComm().toString() : "0.00"); + userInfo.put("propose", user.getPropose() != null ? user.getPropose().toString() : "0.00"); } if (user.getType().equals("1")) { - userInfo.put("balance", user.getBalance().toString() != null ? user.getBalance().toString() : "0.00"); + userInfo.put("balance", user.getBalance() != null ? user.getBalance().toString() : "0.00"); userInfo.put("ismember", user.getIsmember()); userInfo.put("member_begin",user.getMemberBegin() != null ? sdfday.format(user.getMemberBegin()) : null ); userInfo.put("member_end",user.getMemberEnd() != null ? sdfday.format(user.getMemberEnd()) : null ); @@ -1709,7 +1710,6 @@ public class AppletController extends BaseController { userInfo.put("remember_token", user.getRememberToken()); userInfo.put("status", user.getStatus() != null ? user.getStatus() : 1); userInfo.put("tpd", 0); // 默认值 - // userInfo.put("total_comm","0.00"); userInfo.put("total_integral", user.getTotalIntegral() != null ? user.getTotalIntegral() : 100); userInfo.put("type", user.getType() != null ? user.getType().toString() : "1"); userInfo.put("worker_time", user.getWorkerTime()); @@ -4072,10 +4072,10 @@ public class AppletController extends BaseController { } Order order = orders.get(0); - // 5. 验证订单状态是否可以取消 - if (order.getStatus() != 1L) { - return AppletControllerUtil.appletWarning("当前订单状态不可取消"); - } +// // 5. 验证订单状态是否可以取消 +// if (order.getStatus() != 1L) { +// return AppletControllerUtil.appletWarning("当前订单状态不可取消"); +// } // 6. 更新订单状态为已取消(5) Order updateOrder = new Order(); @@ -4119,10 +4119,10 @@ public class AppletController extends BaseController { if (order == null) { return AppletControllerUtil.appletWarning("订单不存在"); } - // 3. 仅允许待服务状态接单 - if (order.getStatus() == null || order.getStatus() != 2L) { - return AppletControllerUtil.appletWarning("当前订单状态不可接单"); - } +// // 3. 仅允许待服务状态接单 +// if (order.getStatus() == null || order.getStatus() != 2L) { +// return AppletControllerUtil.appletWarning("当前订单状态不可接单"); +// } // 4. 设置接单相关字段 order.setWorkerId(worker.getId()); order.setWorkerPhone(worker.getPhone()); @@ -4131,7 +4131,7 @@ public class AppletController extends BaseController { order.setReceiveTime(new Date()); order.setIsAccept(1); // 1:已接单 order.setJsonStatus(2); // 服务进度:2=接单 - order.setStatus(2l); + order.setStatus(2L); order.setLogStatus(9); JSONObject json = new JSONObject(); json.put("type", 1); @@ -4376,6 +4376,535 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletError("获取师傅统计数据失败:" + e.getMessage()); } } + +// /** +// * 师傅端订单详情接口 +// * 返回结构见json.txt +// */ +// @GetMapping("/api/worker/order/info/{id}") +// public AjaxResult getWorkerOrderInfo(@PathVariable("id") Long id, HttpServletRequest request) { +// Map data = new HashMap<>(); +// +// // 4. 处理时间字段 +// java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); +// // DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); +// // 1. 校验token并获取师傅信息 +// String token = request.getHeader("token"); +// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); +// if (!(Boolean) userValidation.get("valid")) { +// return AppletControllerUtil.appletUnauthorized(); +// } +// Users worker = (Users) userValidation.get("user"); +// if (worker == null) { +// return AppletControllerUtil.appletWarning("用户信息获取失败"); +// } +// // 2. 查询订单 +// Order order = orderService.selectOrderById(id); +// if (order == null) { +// return AppletControllerUtil.appletWarning("订单不存在"); +// } +// // 3. 查询用户信息 +// Users user = usersService.selectUsersById(order.getUid()); +// // 4. 查询地址信息 +// UserAddress address = null; +// if (order.getAddressId() != null) { +// address = userAddressService.selectUserAddressById(order.getAddressId()); +// } +// // 5. 查询商品信息 +// ServiceGoods product = null; +// if (order.getProductId() != null) { +// product = serviceGoodsService.selectServiceGoodsById(order.getProductId()); +// } +// // 6. 查询订单日志 +// OrderLog logQuery = new OrderLog(); +// logQuery.setOid(order.getId()); +// List logList = orderLogService.selectOrderLogList(logQuery); +// List> logArr = new ArrayList<>(); +// for (OrderLog log : logList) { +// Map logMap = new HashMap<>(); +// logMap.put("id", log.getId()); +// logMap.put("oid", log.getOid()); +// logMap.put("order_id", log.getOrderId()); +// logMap.put("log_order_id", log.getLogOrderId()); +// logMap.put("title", log.getTitle()); +// logMap.put("type", log.getType()); +// // content字段为json字符串,需转为对象 +// Object contentObj = null; +// try { +// if (log.getContent() != null) { +// contentObj = JSONObject.parse(log.getContent()); +// } +// } catch (Exception e) { +// +// if (AppletControllerUtil.canParseToJSONArray(log.getContent())) { +// contentObj = JSONArray.parseArray(log.getContent()); +// } else { +// contentObj = log.getContent(); +// } +// +// } +// logMap.put("content", contentObj); +// logMap.put("deposit", log.getDeposit()); +// logMap.put("dep_paid", log.getDepPaid()); +// logMap.put("dep_pay_time", log.getDepPayTime()); +// logMap.put("dep_log_id", log.getDepLogId()); +// logMap.put("price", log.getPrice()); +// logMap.put("paid", log.getPaid()); +// logMap.put("pay_time", log.getPayTime()); +// logMap.put("log_id", log.getLogId()); +// logMap.put("worker_id", log.getWorkerId()); +// logMap.put("first_worker_id", log.getFirstWorkerId()); +// logMap.put("give_up", log.getGiveUp()); +// logMap.put("worker_cost", log.getWorkerCost()); +// logMap.put("reduction_price", log.getReductionPrice()); +// logMap.put("is_pause", log.getIsPause()); +// logMap.put("coupon_id", log.getCouponId()); +// logMap.put("deduction", log.getDeduction()); +// logMap.put("worker_log_id", log.getWorkerLogId()); +// logMap.put("created_at", log.getCreatedAt() != null ? dateFormat.format(log.getCreatedAt()) : null); +// logArr.add(logMap); +// } +// +// +// return AjaxResult.success(data); +// } + + + + /** + * 师傅端订单详情接口 + * 返回结构见json.txt + */ + @GetMapping("/api/users/order/info/{id}") + public AjaxResult getusersOrderInfo(@PathVariable("id") Long id, HttpServletRequest request) { + try { + // 4. 处理时间字段 + java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + // DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + // 1. 校验token并获取师傅信息 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users worker = (Users) userValidation.get("user"); + if (worker == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 2. 查询订单 + Order order = orderService.selectOrderById(id); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + // 3. 查询用户信息 + Users user = usersService.selectUsersById(order.getUid()); + // 4. 查询地址信息 + UserAddress address = null; + if (order.getAddressId() != null) { + address = userAddressService.selectUserAddressById(order.getAddressId()); + } + // 5. 查询商品信息 + ServiceGoods product = null; + if (order.getProductId() != null) { + product = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + } + // 6. 查询订单日志 + OrderLog logQuery = new OrderLog(); + logQuery.setOid(order.getId()); + List logList = orderLogService.selectOrderLogList(logQuery); + List> logArr = new ArrayList<>(); + for (OrderLog log : logList) { + Map logMap = new HashMap<>(); + logMap.put("id", log.getId()); + logMap.put("oid", log.getOid()); + logMap.put("order_id", log.getOrderId()); + logMap.put("log_order_id", log.getLogOrderId()); + logMap.put("title", log.getTitle()); + logMap.put("type", log.getType()); + Object contentObj = null; + // content字段为json字符串,需转为对象 + if (log.getTitle().equals("订单评价")) { + OrderComment comment = new OrderComment(); + comment.setOid(log.getOid()); + List commentList = orderCommentService.selectOrderCommentList(comment); + if(!commentList.isEmpty()){ + OrderComment commentDATA = commentList.getFirst(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("num",commentDATA.getNum()); + jsonObject.put("status",commentDATA.getStatus()); + jsonObject.put("text",commentDATA.getContent()); + if (commentDATA.getImages()!=null){ + jsonObject.put("image",JSONArray.parseArray(commentDATA.getImages())); + } + if (commentDATA.getLabels()!=null){ + jsonObject.put("labels",JSONArray.parseArray(commentDATA.getLabels())); + } + + contentObj=jsonObject; + }else{ + JSONObject jsonObject = new JSONObject(); + + jsonObject.put("status",0); + contentObj=jsonObject; + } + + + }else{ + try { + if (log.getContent() != null) { + contentObj = JSONObject.parse(log.getContent()); + } + } catch (Exception e) { + + if (AppletControllerUtil.canParseToJSONArray(log.getContent())) { + contentObj = JSONArray.parseArray(log.getContent()); + } else { + contentObj = log.getContent(); + } + + } + } + + + logMap.put("content", contentObj); + + logMap.put("deposit", log.getDeposit()); + logMap.put("dep_paid", log.getDepPaid()); + logMap.put("dep_pay_time", log.getDepPayTime()); + logMap.put("dep_log_id", log.getDepLogId()); + logMap.put("cj_money", log.getCjMoney()); + logMap.put("cj_paid", log.getCjPaid()); + logMap.put("price", log.getPrice()); + logMap.put("paid", log.getPaid()); + logMap.put("pay_time", log.getPayTime()); + logMap.put("log_id", log.getLogId()); + logMap.put("worker_id", log.getWorkerId()); + + logMap.put("first_worker_id", log.getFirstWorkerId()); + logMap.put("give_up", log.getGiveUp()); + logMap.put("worker_cost", log.getWorkerCost()); + logMap.put("reduction_price", log.getReductionPrice()); + logMap.put("is_pause", log.getIsPause()); + logMap.put("coupon_id", log.getCouponId()); + logMap.put("deduction", log.getDeduction()); + logMap.put("worker_log_id", log.getWorkerLogId()); + logMap.put("created_at", log.getCreatedAt() != null ? dateFormat.format(log.getCreatedAt()) : null); + logMap.put("updated_at", log.getUpdatedAt() != null ? dateFormat.format(log.getUpdatedAt()) : null); + logMap.put("deleted_at", log.getDeletedAt()); + //报价倒计时 + logMap.put("orderstatus", order.getStatus()); + logMap.put("ordertype", order.getType()); + if (!log.getTitle().equals("师傅跟单")) { + logArr.add(logMap); + } + + } + // 7. 构建返回数据 + Map data = new HashMap<>(); + Map orderdata = new HashMap<>(); + Map yuyuedata = new HashMap<>(); + Map baojiadata = new HashMap<>(); + + if (product != null) { + yuyuedata.put("fuwumingcheng", product.getTitle()); + yuyuedata.put("fuwutupian", AppletControllerUtil.buildImageUrl(product.getIcon())); + + } + yuyuedata.put("service", order.getProductId()); + yuyuedata.put("shuliang", order.getNum()); + yuyuedata.put("sku",AppletControllerUtil.parseSkuStringToObject(order.getSku())); + if (order.getFileData() != null){ + yuyuedata.put("file_data", JSON.parseArray(order.getFileData())); + }else{ + yuyuedata.put("file_data",JSONArray.parseArray("[]")); + } + yuyuedata.put("beizhu", order.getReamk()); + + orderdata.put("yuyueshijian", AppletControllerUtil.timeStamp2Date(order)); + orderdata.put("id", order.getId()); + orderdata.put("shifupingjia", order.getIsComment()); + orderdata.put("shifuzanting", order.getIsPause()); + orderdata.put("status", order.getStatus()); + orderdata.put("ordertype", order.getOdertype()); + if (order.getWorkerId()!=null) { + if (Objects.equals(order.getWorkerId(), worker.getId())){ + orderdata.put("shifushifubenren","1"); + }else{ + orderdata.put("shifushifubenren","2"); + } + }else{ + orderdata.put("shifushifubenren","2"); + } + + if (order.getStatus() == 8 && order.getCreatedAt() != null) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(order.getCreatedAt()); + calendar.add(Calendar.DAY_OF_MONTH, 3); + long deadlineTime = calendar.getTimeInMillis(); + orderdata.put("daojishi", deadlineTime); + }else{ + orderdata.put("daojishi", 0L); + } + orderdata.put("fuwudizhi", address); + orderdata.put("orderStatus", order.getJsonStatus()); + orderdata.put("userPhone",order.getUserPhone()); + orderdata.put("middlePhone",order.getMiddlePhone()); + orderdata.put("zongjia",order.getTotalPrice()); + orderdata.put("dingdanbianhao", order.getOrderId()); + UserGroupBuying groupBuying =userGroupBuyingService.selectUserGroupBuyingByptorderid(order.getOrderId()); + if (groupBuying != null){ + orderdata.put("groupid", groupBuying.getOrderid()); + } + orderdata.put("goodsid", order.getProductId()); + orderdata.put("xiadanshijian",order.getCreatedAt() != null ? dateFormat.format(order.getCreatedAt()) : null); + Map shifuMap = new HashMap<>(); + if (order.getWorkerId() != null){ + Users workerInfo = usersService.selectUsersById(order.getWorkerId()); + shifuMap.put("worker_image", AppletControllerUtil.buildImageUrl(workerInfo.getAvatar())); + shifuMap.put("worker_name", workerInfo.getName()); + shifuMap.put("worker_id", workerInfo.getId()); + shifuMap.put("worker_phone", workerInfo.getPhone()); + shifuMap.put("isworker", 1); + }else{ + shifuMap.put("isworker", 2); + } + data.put("shifuMap", shifuMap); + data.put("yuyue", yuyuedata); + data.put("dingdan", orderdata); + data.put("log", logArr); +// Map baojiadingdan = new HashMap<>(); +// if (order.getStatus() == 8) { +// UserDemandQuotation demandQuotation = new UserDemandQuotation(); +// demandQuotation.setOid(order.getId()); +// List demandQuotationList = userDemandQuotationService.selectUserDemandQuotationList(demandQuotation); +// baojiadingdan.put("baojiashuliang", demandQuotationList.size()); +// baojiadingdan.put("zhaungtai", 1); +// }else{ +// baojiadingdan.put("zhaungtai", 2); +// } + // data.put("shifubaojia", baojiadingdan); + // IUserDemandQuotationService +// UserDemandQuotation demandQuotation =new UserDemandQuotation(); +// demandQuotation.setWorkerid(order.getWorkerId()); +// demandQuotation.setOrderid(order.getOrderId()); +// List demandQuotationList = userDemandQuotationService.selectUserDemandQuotationList(demandQuotation); + if (order.getOdertype()==4) { + baojiadata.put("isbaojia", "1"); + //UserDemandQuotation demandQuotationdata=demandQuotationList.getFirst(); + // demandQuotationdata.setWorkerimage(AppletControllerUtil.buildImageUrl(demandQuotationdata.getWorkerimage())); + // baojiadata.put("baojia", demandQuotationdata); + if (order.getStatus() == 8) { + UserDemandQuotation demandQuotation3 = new UserDemandQuotation(); + demandQuotation3.setOid(order.getId()); + List demandQuotationList3 = userDemandQuotationService.selectUserDemandQuotationList(demandQuotation3); + baojiadata.put("baojiashuliang", demandQuotationList3.size()); + + baojiadata.put("zhaungtai", 1); + }else{ + baojiadata.put("zhaungtai", 2); + } + }else{ + baojiadata.put("isbaojia", "2"); + } + data.put("baojia", baojiadata); + + + + return AjaxResult.success(data); + } catch (Exception e) { + return AppletControllerUtil.appletError("查询师傅订单详情失败:" + e.getMessage()); + } + } + + +// /** +// * 师傅端订单详情接口 +// * 返回结构见json.txt +// */ +// @GetMapping("/api/users/order/info/{id}") +// public AjaxResult getusersOrderInfo(@PathVariable("id") Long id, HttpServletRequest request) { +// try { +// // 4. 处理时间字段 +// java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); +// // DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); +// // 1. 校验token并获取师傅信息 +// String token = request.getHeader("token"); +// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); +// if (!(Boolean) userValidation.get("valid")) { +// return AppletControllerUtil.appletUnauthorized(); +// } +// Users worker = (Users) userValidation.get("user"); +// if (worker == null) { +// return AppletControllerUtil.appletWarning("用户信息获取失败"); +// } +// // 2. 查询订单 +// Order order = orderService.selectOrderById(id); +// if (order == null) { +// return AppletControllerUtil.appletWarning("订单不存在"); +// } +// // 3. 查询用户信息 +// Users user = usersService.selectUsersById(order.getUid()); +// // 4. 查询地址信息 +// UserAddress address = null; +// if (order.getAddressId() != null) { +// address = userAddressService.selectUserAddressById(order.getAddressId()); +// } +// // 5. 查询商品信息 +// ServiceGoods product = null; +// if (order.getProductId() != null) { +// product = serviceGoodsService.selectServiceGoodsById(order.getProductId()); +// } +// // 6. 查询订单日志 +// OrderLog logQuery = new OrderLog(); +// logQuery.setOid(order.getId()); +// List logList = orderLogService.selectOrderLogList(logQuery); +// List> logArr = new ArrayList<>(); +// for (OrderLog log : logList) { +// Map logMap = new HashMap<>(); +// logMap.put("id", log.getId()); +// logMap.put("oid", log.getOid()); +// logMap.put("order_id", log.getOrderId()); +// logMap.put("log_order_id", log.getLogOrderId()); +// logMap.put("title", log.getTitle()); +// logMap.put("type", log.getType()); +// +// // content字段为json字符串,需转为对象 +// Object contentObj = null; +// try { +// if (log.getContent() != null) { +// contentObj = JSONObject.parse(log.getContent()); +// } +// } catch (Exception e) { +// +// if (AppletControllerUtil.canParseToJSONArray(log.getContent())) { +// contentObj = JSONArray.parseArray(log.getContent()); +// } else { +// contentObj = log.getContent(); +// } +// +// } +// logMap.put("content", contentObj); +// logMap.put("deposit", log.getDeposit()); +// logMap.put("dep_paid", log.getDepPaid()); +// logMap.put("dep_pay_time", log.getDepPayTime()); +// logMap.put("dep_log_id", log.getDepLogId()); +// logMap.put("cj_money", log.getCjMoney()); +// logMap.put("cj_paid", log.getCjPaid()); +// logMap.put("price", log.getPrice()); +// logMap.put("paid", log.getPaid()); +// logMap.put("pay_time", log.getPayTime()); +// logMap.put("log_id", log.getLogId()); +// logMap.put("worker_id", log.getWorkerId()); +// logMap.put("first_worker_id", log.getFirstWorkerId()); +// logMap.put("give_up", log.getGiveUp()); +// logMap.put("worker_cost", log.getWorkerCost()); +// logMap.put("reduction_price", log.getReductionPrice()); +// logMap.put("is_pause", log.getIsPause()); +// logMap.put("coupon_id", log.getCouponId()); +// logMap.put("deduction", log.getDeduction()); +// logMap.put("worker_log_id", log.getWorkerLogId()); +// logMap.put("created_at", log.getCreatedAt() != null ? dateFormat.format(log.getCreatedAt()) : null); +// logMap.put("updated_at", log.getUpdatedAt() != null ? dateFormat.format(log.getUpdatedAt()) : null); +// logMap.put("deleted_at", log.getDeletedAt()); +// //报价倒计时 +// logMap.put("orderstatus", order.getStatus()); +// logMap.put("ordertype", order.getType()); +// if (!log.getTitle().equals("师傅跟单")) { +// logArr.add(logMap); +// } +// +// } +// // 7. 构建返回数据 +// Map data = new HashMap<>(); +// Map orderdata = new HashMap<>(); +// Map yuyuedata = new HashMap<>(); +// Map baojiadata = new HashMap<>(); +// +// if (product != null) { +// yuyuedata.put("fuwumingcheng", product.getTitle()); +// yuyuedata.put("fuwutupian", AppletControllerUtil.buildImageUrl(product.getIcon())); +// +// } +// yuyuedata.put("service", order.getProductId()); +// yuyuedata.put("shuliang", order.getNum()); +// yuyuedata.put("sku",AppletControllerUtil.parseSkuStringToObject(order.getSku())); +// if (order.getFileData() != null){ +// yuyuedata.put("file_data", JSON.parseArray(order.getFileData())); +// }else{ +// yuyuedata.put("file_data",JSONArray.parseArray("[]")); +// } +// yuyuedata.put("beizhu", order.getReamk()); +// +// orderdata.put("yuyueshijian", AppletControllerUtil.timeStamp2Date(order)); +// orderdata.put("id", order.getId()); +// orderdata.put("shifuzanting", order.getIsPause()); +// orderdata.put("status", order.getStatus()); +// orderdata.put("ordertype", order.getOdertype()); +// if (order.getWorkerId()!=null) { +// if (Objects.equals(order.getWorkerId(), worker.getId())){ +// orderdata.put("shifushifubenren","1"); +// }else{ +// orderdata.put("shifushifubenren","2"); +// } +// }else{ +// orderdata.put("shifushifubenren","2"); +// } +// +// if (order.getStatus() == 8 && order.getCreatedAt() != null) { +// Calendar calendar = Calendar.getInstance(); +// calendar.setTime(order.getCreatedAt()); +// calendar.add(Calendar.DAY_OF_MONTH, 3); +// long deadlineTime = calendar.getTimeInMillis(); +// orderdata.put("daojishi", deadlineTime); +// }else{ +// orderdata.put("daojishi", 0L); +// } +// orderdata.put("fuwudizhi", address); +// orderdata.put("orderStatus", order.getJsonStatus()); +// orderdata.put("userPhone",order.getUserPhone()); +// orderdata.put("middlePhone",order.getMiddlePhone()); +// orderdata.put("zongjia",order.getTotalPrice()); +// orderdata.put("dingdanbianhao", order.getOrderId()); +// orderdata.put("xiadanshijian",order.getCreatedAt() != null ? dateFormat.format(order.getCreatedAt()) : null); +// data.put("yuyue", yuyuedata); +// data.put("dingdan", orderdata); +// data.put("log", logArr); +// Map baojiadingdan = new HashMap<>(); +// if (order.getStatus() == 8) { +// UserDemandQuotation demandQuotation = new UserDemandQuotation(); +// demandQuotation.setOid(order.getId()); +// List demandQuotationList = userDemandQuotationService.selectUserDemandQuotationList(demandQuotation); +// baojiadingdan.put("baojiashuliang", demandQuotationList.size()); +// baojiadingdan.put("zhaungtai", 1); +// }else{ +// baojiadingdan.put("zhaungtai", 2); +// } +// data.put("shifubaojia", baojiadingdan); +// // IUserDemandQuotationService +// UserDemandQuotation demandQuotation =new UserDemandQuotation(); +// demandQuotation.setWorkerid(order.getWorkerId()); +// demandQuotation.setOrderid(order.getOrderId()); +// List demandQuotationList = userDemandQuotationService.selectUserDemandQuotationList(demandQuotation); +// if (demandQuotationList != null && !demandQuotationList.isEmpty() &&order.getOdertype()==4) { +// baojiadata.put("isbaojia", "1"); +// UserDemandQuotation demandQuotationdata=demandQuotationList.getFirst(); +// demandQuotationdata.setWorkerimage(AppletControllerUtil.buildImageUrl(demandQuotationdata.getWorkerimage())); +// baojiadata.put("baojia", demandQuotationdata); +// }else{ +// baojiadata.put("isbaojia", "2"); +// } +// data.put("baojia", baojiadata); +// +// +// +// return AjaxResult.success(data); +// } catch (Exception e) { +// return AppletControllerUtil.appletError("查询师傅订单详情失败:" + e.getMessage()); +// } +// } + + + /** * 师傅端订单详情接口 * 返回结构见json.txt @@ -4427,25 +4956,73 @@ public class AppletController extends BaseController { logMap.put("title", log.getTitle()); logMap.put("type", log.getType()); // content字段为json字符串,需转为对象 +// Object contentObj = null; +// try { +// if (log.getContent() != null) { +// contentObj = JSONObject.parse(log.getContent()); +// } +// } catch (Exception e) { +// +// if (AppletControllerUtil.canParseToJSONArray(log.getContent())) { +// contentObj = JSONArray.parseArray(log.getContent()); +// } else { +// contentObj = log.getContent(); +// } +// +// } +// logMap.put("content", contentObj); Object contentObj = null; - try { - if (log.getContent() != null) { - contentObj = JSONObject.parse(log.getContent()); - } - } catch (Exception e) { + // content字段为json字符串,需转为对象 + if (log.getTitle().equals("订单评价")) { + OrderComment comment = new OrderComment(); + comment.setOid(log.getOid()); + List commentList = orderCommentService.selectOrderCommentList(comment); + if(!commentList.isEmpty()){ + OrderComment commentDATA = commentList.getFirst(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("num",commentDATA.getNum()); + jsonObject.put("status",commentDATA.getStatus()); + jsonObject.put("text",commentDATA.getContent()); + if (commentDATA.getImages()!=null){ + jsonObject.put("image",JSONArray.parseArray(commentDATA.getImages())); + } + if (commentDATA.getLabels()!=null){ + jsonObject.put("labels",JSONArray.parseArray(commentDATA.getLabels())); + } - if (AppletControllerUtil.canParseToJSONArray(log.getContent())) { - contentObj = JSONArray.parseArray(log.getContent()); - } else { - contentObj = log.getContent(); + contentObj=jsonObject; + }else{ + JSONObject jsonObject = new JSONObject(); + + jsonObject.put("status",0); + contentObj=jsonObject; } + + }else{ + try { + if (log.getContent() != null) { + contentObj = JSONObject.parse(log.getContent()); + } + } catch (Exception e) { + + if (AppletControllerUtil.canParseToJSONArray(log.getContent())) { + contentObj = JSONArray.parseArray(log.getContent()); + } else { + contentObj = log.getContent(); + } + + } } + + logMap.put("content", contentObj); logMap.put("deposit", log.getDeposit()); logMap.put("dep_paid", log.getDepPaid()); logMap.put("dep_pay_time", log.getDepPayTime()); logMap.put("dep_log_id", log.getDepLogId()); + logMap.put("cj_money", log.getCjMoney()); + logMap.put("cj_paid", log.getCjPaid()); logMap.put("price", log.getPrice()); logMap.put("paid", log.getPaid()); logMap.put("pay_time", log.getPayTime()); @@ -4462,65 +5039,107 @@ public class AppletController extends BaseController { logMap.put("created_at", log.getCreatedAt() != null ? dateFormat.format(log.getCreatedAt()) : null); logMap.put("updated_at", log.getUpdatedAt() != null ? dateFormat.format(log.getUpdatedAt()) : null); logMap.put("deleted_at", log.getDeletedAt()); + //报价倒计时 + logMap.put("orderstatus", order.getStatus()); + logMap.put("ordertype", order.getType()); + logArr.add(logMap); } // 7. 构建返回数据 Map data = new HashMap<>(); - data.put("id", order.getId()); - data.put("type", order.getType()); - data.put("main_order_id", order.getMainOrderId()); - data.put("order_id", order.getOrderId()); - data.put("transaction_id", order.getTransactionId()); - data.put("create_type", order.getCreateType()); - data.put("create_phone", order.getCreatePhone()); - data.put("uid", order.getUid()); - data.put("product_id", order.getProductId()); - data.put("name", order.getName()); - data.put("phone", order.getPhone()); - data.put("address", address); - data.put("make_time", AppletControllerUtil.timeStamp2Date(order)); - data.put("make_hour", order.getMakeHour()); - data.put("num", order.getNum()); - data.put("total_price", order.getTotalPrice()); - data.put("good_price", order.getGoodPrice()); - data.put("service_price", order.getServicePrice()); - data.put("pay_price", order.getPayPrice()); - data.put("coupon_id", order.getCouponId()); - data.put("deduction", order.getDeduction()); - data.put("pay_time", order.getPayTime()); - data.put("status", order.getStatus()); - data.put("is_pause", order.getIsPause()); - data.put("mark", order.getMark()); - data.put("address_id", order.getAddressId()); - data.put("sku", order.getSku()); - data.put("worker_id", order.getWorkerId()); - data.put("first_worker_id", order.getFirstWorkerId()); - data.put("receive_time", order.getReceiveTime() != null ? dateFormat.format(order.getReceiveTime()) : null); - data.put("is_comment", order.getIsComment()); - data.put("receive_type", order.getReceiveType()); - data.put("is_accept", order.getIsAccept()); - data.put("middle_phone", order.getMiddlePhone()); - data.put("user_phone", order.getUserPhone()); - data.put("worker_phone", order.getWorkerPhone()); - data.put("address_en", order.getAddressEn()); - data.put("uid_admin", order.getUidAdmin()); - data.put("address_admin", order.getAddressAdmin()); - data.put("log_status", order.getLogStatus()); - data.put("log_json", order.getLogJson()); - data.put("json_status", order.getJsonStatus()); - data.put("log_images", order.getLogImages()); - data.put("created_at", order.getCreatedAt() != null ? dateFormat.format(order.getCreatedAt()) : null); - data.put("updated_at", order.getUpdatedAt() != null ? dateFormat.format(order.getUpdatedAt()) : null); - data.put("deleted_at", order.getDeletedAt() != null ? dateFormat.format(order.getDeletedAt()) : null); - data.put("phone_xx", order.getPhone()); // 可脱敏处理 - data.put("user", user); - data.put("product", product); - if (order.getFileData() != null){ - data.put("file_data", JSON.parseArray(order.getFileData())); - }else{ - data.put("file_data", null); + Map orderdata = new HashMap<>(); + Map yuyuedata = new HashMap<>(); + Map baojiadata = new HashMap<>(); + + if (product != null) { + yuyuedata.put("fuwumingcheng", product.getTitle()); + yuyuedata.put("fuwutupian", AppletControllerUtil.buildImageUrl(product.getIcon())); + } + yuyuedata.put("service", order.getProductId()); + yuyuedata.put("shuliang", order.getNum()); + yuyuedata.put("sku",AppletControllerUtil.parseSkuStringToObject(order.getSku())); + if (order.getFileData() != null){ + yuyuedata.put("file_data", JSON.parseArray(order.getFileData())); + }else{ + yuyuedata.put("file_data",JSONArray.parseArray("[]")); + } + yuyuedata.put("beizhu", order.getReamk()); + + orderdata.put("yuyueshijian", AppletControllerUtil.timeStamp2Date(order)); + orderdata.put("id", order.getId()); + orderdata.put("shifuzanting", order.getIsPause()); + orderdata.put("status", order.getStatus()); + orderdata.put("ordertype", order.getOdertype()); + if (order.getWorkerId()!=null) { + System.out.println("订单中的用户id"+order.getWorkerId()); + System.out.println("当前登录用户用户id"+user.getId()); + if (Objects.equals(order.getWorkerId(), worker.getId())){ + orderdata.put("shifushifubenren","1"); + }else{ + orderdata.put("shifushifubenren","2"); + } + }else{ + orderdata.put("shifushifubenren","2"); + } + + if (order.getStatus() == 8 && order.getCreatedAt() != null) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(order.getCreatedAt()); + calendar.add(Calendar.DAY_OF_MONTH, 3); + long deadlineTime = calendar.getTimeInMillis(); + orderdata.put("daojishi", deadlineTime); + }else{ + orderdata.put("daojishi", 0L); + } + orderdata.put("fuwudizhi", address); + orderdata.put("orderStatus", order.getJsonStatus()); + orderdata.put("userPhone",order.getUserPhone()); + orderdata.put("middlePhone",order.getMiddlePhone()); + orderdata.put("zongjia",order.getTotalPrice()); + orderdata.put("dingdanbianhao", order.getOrderId()); + orderdata.put("xiadanshijian",order.getCreatedAt() != null ? dateFormat.format(order.getCreatedAt()) : null); + data.put("yuyue", yuyuedata); + data.put("dingdan", orderdata); data.put("log", logArr); + // IUserDemandQuotationService + UserDemandQuotation demandQuotation =new UserDemandQuotation(); + demandQuotation.setWorkerid(order.getWorkerId()); + demandQuotation.setOrderid(order.getOrderId()); + List demandQuotationList = userDemandQuotationService.selectUserDemandQuotationList(demandQuotation); + if (demandQuotationList != null && !demandQuotationList.isEmpty() &&order.getOdertype()==4) { + baojiadata.put("isbaojia", "1"); + UserDemandQuotation demandQuotationdata=demandQuotationList.getFirst(); + demandQuotationdata.setWorkerimage(AppletControllerUtil.buildImageUrl(demandQuotationdata.getWorkerimage())); + baojiadata.put("baojia", demandQuotationdata); + }else{ + baojiadata.put("isbaojia", "2"); + } + data.put("baojia", baojiadata); + + // 添加上门标准数据 + try { + SiteConfig serviceStandardConfig = siteConfigService.selectSiteConfigByName("config_ten"); + if (serviceStandardConfig != null && serviceStandardConfig.getValue() != null) { + try { + JSONObject configJson = JSONObject.parseObject(serviceStandardConfig.getValue()); + if (configJson.containsKey("serviceStandard")) { + data.put("serviceStandard", configJson.getString("serviceStandard")); + } else { + data.put("serviceStandard", ""); + } + } catch (Exception e) { + logger.warn("解析上门标准配置失败: " + e.getMessage()); + data.put("serviceStandard", ""); + } + } else { + data.put("serviceStandard", ""); + } + } catch (Exception e) { + logger.warn("获取上门标准配置失败: " + e.getMessage()); + data.put("serviceStandard", ""); + } + return AjaxResult.success(data); } catch (Exception e) { return AppletControllerUtil.appletError("查询师傅订单详情失败:" + e.getMessage()); @@ -4608,6 +5227,21 @@ public class AppletController extends BaseController { String keywords = params.get("keywords") != null ? params.get("keywords").toString().trim() : null; // 查询type=2的师傅 Users query = new Users(); + // 解析 area + if (params.containsKey("area")) { + Object areaObj = params.get("area"); + if (areaObj instanceof List) { + query.setAreaList((List) areaObj); + } else if (areaObj instanceof String) { + query.setAreaList(JSON.parseArray(areaObj.toString(), String.class)); + } + } + // 解析 skill + if (params.containsKey("skill")) { + query.setSkill(params.get("skill").toString()); + } + + query.setType("2"); if (keywords != null && !keywords.isEmpty()) { query.setName(keywords); @@ -4855,6 +5489,7 @@ public class AppletController extends BaseController { newlog.setOrderId(order.getOrderId()); newlog.setWorkerId(newWorkerId); newlog.setWorkerLogId(newWorkerId); + newlog.setTitle("转单"); newlog.setIsPause(2); orderLogService.insertOrderLog(newlog); //需要解绑原订单上原师傅和客户的虚拟号 @@ -5359,6 +5994,65 @@ public class AppletController extends BaseController { } } +// /** +// * 师傅设置上门费接口 +// * 参数:{"id":订单id,"price":金额} +// * 逻辑:查找订单最新日志,设置workerCost和price,并设置paid=1 +// */ +// @PostMapping("/api/worker/set/price") +// public AjaxResult setWorkerPrice(@RequestBody Map params, HttpServletRequest request) { +// try { +// // 1. 校验token并获取用户 +// String token = request.getHeader("token"); +// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); +// if (!(Boolean) userValidation.get("valid")) { +// return AppletControllerUtil.appletUnauthorized(); +// } +// Users user = (Users) userValidation.get("user"); +// if (user == null) { +// return AppletControllerUtil.appletWarning("用户信息获取失败"); +// } +// +// Long orderId = params.get("id") != null ? Long.parseLong(params.get("id").toString()) : null; +// String priceStr = params.get("price") != null ? params.get("price").toString() : null; +// if (orderId == null || StringUtils.isEmpty(priceStr)) { +// return AppletControllerUtil.appletWarning("参数错误"); +// } +// BigDecimal price = new BigDecimal(priceStr); +// // 查询订单 +// Order order = orderService.selectOrderById(orderId); +// if (order == null) { +// return AppletControllerUtil.appletWarning("订单不存在"); +// } +// +// OrderLog neworderLog =new OrderLog(); +// neworderLog.seto +// +//// // 查询最新订单日志 +//// OrderLog neworderLog = orderLogService.selectDataTheFirstNew(order.getId()); +//// if (neworderLog != null) { +//// //修改订单日志添加费用 +//// neworderLog.setPrice(price); +//// neworderLog.setPaid(1L); +//// neworderLog.setWorkerCost(price); +//// neworderLog.setLogId(GenerateCustomCode.generCreateOrder("FEE")); +//// //修改订单状态 +//// order.setJsonStatus(3); +//// JSONObject jsonObject3 = new JSONObject(); +//// jsonObject3.put("type", 2); +//// order.setLogJson(jsonObject3.toJSONString()); +//// orderLogService.updateOrderLog(neworderLog); +//// orderService.updateOrder(order); +//// Users userinfo = usersService.selectUsersById(order.getUid()); +//// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); +//// //给用户发送微信推送消息 +//// WXsendMsgUtil.sendMsgForUserDoorMoney(userinfo.getOpenid(), order, serviceGoods); +//// } +// return AjaxResult.success("设置上门费成功"); +// } catch (Exception e) { +// return AppletControllerUtil.appletError("设置上门费失败:" + e.getMessage()); +// } +// } /** * 师傅设置上门费接口 * 参数:{"id":订单id,"price":金额} @@ -5390,24 +6084,128 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletWarning("订单不存在"); } // 查询最新订单日志 - OrderLog neworderLog = orderLogService.selectDataTheFirstNew(order.getId()); - if (neworderLog != null) { - //修改订单日志添加费用 - neworderLog.setPrice(price); + OrderLog neworderLogdata =orderLogService.selectDataTheFirstNew(order.getId()); +// neworderLogdata.setType(new BigDecimal(2.0)); +// neworderLogdata.setOid(order.getId()); +// List orderLogslist = orderLogService.selectOrderLogList(neworderLogdata); +// OrderLog neworderLog = orderLogslist.getFirst(); + if (neworderLogdata != null) { + + String logOrderId = GenerateCustomCode.generCreateOrder("DSB"); + OrderLog neworderLog =new OrderLog(); + neworderLog.setOid(order.getId()); + neworderLog.setOrderId(order.getOrderId()); + neworderLog.setLogOrderId(logOrderId); + neworderLog.setTitle("上门费"); + neworderLog.setType(neworderLogdata.getType()); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "师傅"+user.getName()+"设置上门费"+ price+"元"); + neworderLog.setContent(jsonObject.toJSONString()); neworderLog.setPaid(1L); - neworderLog.setWorkerCost(price); + neworderLog.setPrice( price); neworderLog.setLogId(GenerateCustomCode.generCreateOrder("FEE")); - //修改订单状态 - order.setJsonStatus(3); - JSONObject jsonObject3 = new JSONObject(); - jsonObject3.put("type", 2); - order.setLogJson(jsonObject3.toJSONString()); - orderLogService.updateOrderLog(neworderLog); - orderService.updateOrder(order); - Users userinfo = usersService.selectUsersById(order.getUid()); - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); - //给用户发送微信推送消息 - WXsendMsgUtil.sendMsgForUserDoorMoney(userinfo.getOpenid(), order, serviceGoods); + neworderLog.setWorkerId(user.getId()); + neworderLog.setWorkerCost( price); + neworderLog.setWorkerLogId(user.getId()); + int insert =orderLogService.insertOrderLog(neworderLog); + if (insert > 0) { + //上门费创建支付单 + BigDecimal totalAmount=neworderLog.getPrice(); + Users userinfo = usersService.selectUsersById(order.getUid()); + PayBeforeUtil payBeforeUtil = new PayBeforeUtil(); + payBeforeUtil.createPayBefore(userinfo, totalAmount, logOrderId, neworderLog.getId(), + null, 7L, null, null, + null, null, null,1L,null,null); + +// // 9. 计算会员优惠和服务金抵扣 +// BigDecimal memberMoney = BigDecimal.ZERO; +// BigDecimal serviceMoney = BigDecimal.ZERO; +// +// try { +// // 查询config_one配置 +// SiteConfig configQuery = new SiteConfig(); +// configQuery.setName("config_one"); +// List configList = siteConfigService.selectSiteConfigList(configQuery); +// +// if (configList != null && !configList.isEmpty()) { +// String configValue = configList.get(0).getValue(); +// if (configValue != null && !configValue.trim().isEmpty()) { +// JSONObject configJson = JSONObject.parseObject(configValue); +// +// // 计算会员优惠金额 +// if (user.getIsmember() != null && user.getIsmember() == 1) { +// // 用户是包年会员,计算会员优惠 +// Integer memberDiscount = configJson.getInteger("member_discount"); +// if (memberDiscount != null && memberDiscount > 0) { +// // 会员优惠金额 = 订单金额 * (100 - 会员折扣) / 100 +// BigDecimal discountRate = BigDecimal.valueOf(memberDiscount).divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_HALF_UP); +// if (totalAmount != null) { +// memberMoney = totalAmount.multiply(discountRate); +// } +// } +// } +// +// // 计算服务金抵扣金额 +// Integer serviceFee = configJson.getInteger("servicefee"); +// if (serviceFee != null && serviceFee > 0) { +// // 查询数据库最新用户数据 +// Users userDb = usersService.selectUsersById(user.getId()); +// if (userDb != null && userDb.getServicefee() != null && userDb.getServicefee().compareTo(BigDecimal.ZERO) > 0) { +// // 服务金抵扣金额 = 用户服务金 * 服务金比例 / 100 +// BigDecimal serviceRate = BigDecimal.valueOf(serviceFee).divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_HALF_UP); +// serviceMoney = userDb.getServicefee().multiply(serviceRate); +// } +// } +// } +// } +// } catch (Exception e) { +// logger.warn("计算会员优惠和服务金抵扣失败: " + e.getMessage()); +// memberMoney = BigDecimal.ZERO; +// serviceMoney = BigDecimal.ZERO; +// } +// +// // 10. 创建预支付记录 +// UsersPayBefor usersPayBefor = new UsersPayBefor(); +// usersPayBefor.setUid(userinfo.getId()); +// usersPayBefor.setOrderid(logOrderId); +// usersPayBefor.setOid(neworderLog.getId()); +// usersPayBefor.setPaycode(GenerateCustomCode.generCreateOrder("PAY")); +// usersPayBefor.setAllmoney(totalAmount); +// usersPayBefor.setWxmoney(totalAmount); +// usersPayBefor.setShopmoney(BigDecimal.ZERO); +// usersPayBefor.setServicemoney(serviceMoney); +// usersPayBefor.setMtmoney(BigDecimal.ZERO); +// usersPayBefor.setYemoney(BigDecimal.ZERO); +// usersPayBefor.setCouponmoney(BigDecimal.ZERO); +// usersPayBefor.setServicetype(1L); +// usersPayBefor.setMembermoney(memberMoney); +// usersPayBefor.setType(7L); +// usersPayBefor.setSku(""); +// usersPayBefor.setStatus(1L); // 1=待支付 +// usersPayBefor.setPaytype(1L); // 默认微信支付 +// +// int payBeforResult = usersPayBeforService.insertUsersPayBefor(usersPayBefor); +// if (payBeforResult <= 0) { +// return AppletControllerUtil.appletWarning("预支付记录创建失败"); +// } + } + +// //修改订单日志添加费用 +// neworderLog.setPrice(price); +// neworderLog.setPaid(1L); +// neworderLog.setWorkerCost(price); +// neworderLog.setLogId(GenerateCustomCode.generCreateOrder("FEE")); +// //修改订单状态 +// order.setJsonStatus(3); +// JSONObject jsonObject3 = new JSONObject(); +// jsonObject3.put("type", 2); +// order.setLogJson(jsonObject3.toJSONString()); +// orderLogService.updateOrderLog(neworderLog); +// orderService.updateOrder(order); +// Users userinfo = usersService.selectUsersById(order.getUid()); +// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); +// //给用户发送微信推送消息 +// WXsendMsgUtil.sendMsgForUserDoorMoney(userinfo.getOpenid(), order, serviceGoods); } return AjaxResult.success("设置上门费成功"); } catch (Exception e) { @@ -5496,15 +6294,15 @@ public class AppletController extends BaseController { } // 2. 获取当前登录师傅ID(token在header) - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { return AppletControllerUtil.appletWarning("未登录或token无效"); - } - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } Long workerId = user.getId(); // 3. 获取订单 @@ -5534,6 +6332,24 @@ public class AppletController extends BaseController { // 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.setWorkerLogId(workerId); + orderLog.setTitle("师傅到达"); + orderLog.setType(new BigDecimal("5.0")); + JSONObject content = new 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()); @@ -5552,38 +6368,111 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletSuccess("师傅已经上门"); } + + + // ... existing code ... /** - * 获取基检项目 - * GET /api/worker/basic/project/{id} + * 获取基检项目和订单报价信息 + * GET /api/worker/basic/project?id=订单id&goodid=服务id */ - @GetMapping("/api/worker/basic/project/{id}") - public AjaxResult getWorkerBasicProject(@PathVariable("id") Long id) { - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(id); - if (serviceGoods == null) { - return AppletControllerUtil.appletError("商品不存在"); - } - String basic = serviceGoods.getBasic(); + @GetMapping("/api/worker/basic/project") + public AjaxResult getWorkerBasicProject(@RequestParam(value = "id", required = false) Long id, + @RequestParam(value = "goodid", required = false) Long goodid) { 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()); + 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; } } - } catch (Exception e) { - String[] arr = basic.split("[\n,,]"); - for (String s : arr) { - if (!s.trim().isEmpty()) basicList.add(s.trim()); + // 取服务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()); + } + } } } } Map data = new HashMap<>(); data.put("basic", basicList); + if (quoteJson != null) { + data.put("quote", quoteJson); + } return AjaxResult.success(data); } +// ... existing code ... + + + +// /** +// * 获取基检项目 +// * GET /api/worker/basic/project/{id} +// */ +// @GetMapping("/api/worker/basic/project/{id}") +// public AjaxResult getWorkerBasicProject(@PathVariable("id") Long id) { +// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(id); +// if (serviceGoods == null) { +// return AppletControllerUtil.appletError("商品不存在"); +// } +// Order order = orderService.selectOrderById(id); +// if (order != null) { +// return AppletControllerUtil.appletError("订单不存在"); +// } +// 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); +// } /** * 报价获取服务项目 @@ -5670,6 +6559,7 @@ public class AppletController extends BaseController { 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()); // type_id为数组,需解析 @@ -5706,6 +6596,7 @@ public class AppletController extends BaseController { if (params == null) { return AppletControllerUtil.appletError("参数错误"); } + PayBeforeUtil payBeforeUtil = new PayBeforeUtil(); // 1. 计算金额 BigDecimal GoodsAllPrice = BigDecimal.ZERO; BigDecimal ServiceAllPrice = BigDecimal.ZERO; @@ -5779,6 +6670,9 @@ public class AppletController extends BaseController { 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); } @@ -5791,6 +6685,8 @@ public class AppletController extends BaseController { 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); } @@ -5798,6 +6694,7 @@ public class AppletController extends BaseController { resultJson.put("material", materialListNew); // 3. 转为字符串 String contentStr = JSONObject.toJSONString(resultJson); + // 4. 订单相关处理 Long orderId = null; if (params.get("id") != null) { @@ -5809,56 +6706,127 @@ public class AppletController extends BaseController { if (orderId == null) { return AppletControllerUtil.appletError("订单ID格式错误"); } - Order order = orderService.selectOrderById(orderId); - if (order == null) { + Order order = orderService.selectOrderById(orderId); + if (order == null) { return AppletControllerUtil.appletError("订单不存在"); - } - order.setJsonStatus(6); - JSONObject jsonObject = new 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.setOrderId(order.getOrderId()); - log.setType(new BigDecimal(5)); - log.setContent(contentStr); - log.setTitle("已检查评估报价"); + } + // 查询最新订单日志 + 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) { - log.setDeposit(new BigDecimal(params.get("price").toString())); - log.setDepPaid(1); - log.setDepLogId(GenerateCustomCode.generCreateOrder("RED")); + //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 { - log.setDeposit(BigDecimal.ZERO); + neworderLog.setDeposit(BigDecimal.ZERO); } - log.setPrice(totalPrice.add(reductionPrice)); - log.setPaid(1l); + neworderLog.setPrice(totalPrice.add(reductionPrice)); + neworderLog.setPaid(1l); if (params.get("reduction") != null) { - log.setReductionPrice(new BigDecimal(params.get("reduction").toString())); + neworderLog.setReductionPrice(new BigDecimal(params.get("reduction").toString())); } else { - log.setReductionPrice(BigDecimal.ZERO); + neworderLog.setReductionPrice(BigDecimal.ZERO); } - log.setWorkerCost(ServiceAllPrice.subtract(reductionPrice)); + neworderLog.setWorkerCost(ServiceAllPrice.subtract(reductionPrice)); //log.set - log.setLogId(GenerateCustomCode.generCreateOrder("EST")); - log.setWorkerLogId(order.getWorkerId()); - log.setWorkerId(order.getWorkerId()); - orderLogService.insertOrderLog(log); - Users user = usersService.selectUsersById(order.getUid()); - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); - //小程序推送用户报价成功 - WXsendMsgUtil.sendWorkerADDmoney(user.getOpenid(), order, serviceGoods); + 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); + orderLogService.updateOrderLog(neworderLog); return AppletControllerUtil.appletSuccess("报价成功"); - } else { - return AppletControllerUtil.appletError("报价失败"); + }else{ + order.setJsonStatus(6); + JSONObject jsonObject = new 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(order.getOrderId()); + log.setOrderId(GenerateCustomCode.generCreateOrder("DSB")); + 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); + } + 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.setWorkerCost(ServiceAllPrice.subtract(reductionPrice)); + //log.set + log.setLogId(GenerateCustomCode.generCreateOrder("EST")); + log.setWorkerLogId(order.getWorkerId()); + log.setWorkerId(order.getWorkerId()); + orderLogService.insertOrderLog(log); + 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); + return AppletControllerUtil.appletSuccess("报价成功"); + } else { + return AppletControllerUtil.appletError("报价失败"); + } } } - /** * 师傅开始服务接口 * POST /api/worker/do/service @@ -5867,111 +6835,241 @@ public class AppletController extends BaseController { @PostMapping("/api/worker/do/service") public AjaxResult workerDoService(@RequestBody Map params, HttpServletRequest request) { Long oid = 0L; - if (params.get("oid") != null) { + if (params.get("id") != null) { try { - oid = Long.valueOf(params.get("oid").toString()); + oid = Long.valueOf(params.get("id").toString()); } catch (Exception e) { return AppletControllerUtil.appletError("订单ID格式错误"); } } Order order = orderService.selectOrderById(oid); - // 获取当前师傅id - if (order != null) { - Long workerId = order.getWorkerId(); - if (order.getJsonStatus() == 6) { - //开始服务 - // 1. 修改订单状态 - order.setStatus(3L); // 服务中 - order.setJsonStatus(7); // 服务中 - order.setLogJson("{\"type\":6}"); - order.setIsPause(1); // 服务中 - order.setUpdatedAt(new Date()); - int update = orderService.updateOrder(order); - if (update > 0) { - // 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 = 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(workerId); - log.setWorkerLogId(workerId); - log.setIsPause(1); - log.setCreatedAt(new Date()); - orderLogService.insertOrderLog(log); - return AppletControllerUtil.appletSuccess("服务已开始"); - } else { - return AppletControllerUtil.appletError("操作失败"); - } - } - } else { - OrderLog newlog = orderLogService.selectOrderLogById(Long.valueOf(params.get("id").toString())); - Order storder = orderService.selectOrderById(newlog.getOid()); - if (storder.getJsonStatus() == 7) { - if (newlog != null) { - newlog.setIsPause(2); - JSONArray jsonArray = JSONArray.parseArray(newlog.getContent()); - // 2. 组装日志内容为数组格式 - Map logItem = new LinkedHashMap<>(); - 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); - jsonArray.add(logItem); - newlog.setContent(jsonArray.toJSONString()); - orderLogService.updateOrderLog(newlog); + if (order == null) { + return AppletControllerUtil.appletError("订单不存在"); + } - if (storder != null) { - // 1. 修改订单状态 - storder.setStatus(3L); // 服务中 - storder.setJsonStatus(8); // 服务中 - storder.setLogJson("{\"type\":6}"); - storder.setIsPause(2); // 服务中 - storder.setUpdatedAt(new Date()); - orderService.updateOrder(storder); - } + 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 = 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) { + JSONObject logItem = new 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 (storder.getJsonStatus() == 8) { + if (order.getJsonStatus() == 8) { + JSONObject logItem = new JSONObject(); + logItem.put("name", "继续服务"); + logItem.put("image", params.get("image")); + logItem.put("time", new Date()); + logItem.put("type", 1); - if (newlog != null) { - newlog.setIsPause(1); - JSONArray jsonArray = JSONArray.parseArray(newlog.getContent()); - Map logItem = new LinkedHashMap<>(); - logItem.put("name", "继续服务"); - logItem.put("image", ""); - logItem.put("time", new Date()); - logItem.put("type", 1); - jsonArray.add(logItem); - newlog.setContent(jsonArray.toJSONString()); - orderLogService.updateOrderLog(newlog); - if (storder != null) { - //继续服务 - storder.setStatus(3L); // 服务中 - storder.setJsonStatus(7); // 服务中 - storder.setLogJson("{\"type\":6}"); - storder.setIsPause(1); // 服务中 - storder.setUpdatedAt(new Date()); - orderService.updateOrder(storder); - } + 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("操作成功"); } +// /** +// * 师傅开始服务接口 +// * POST /api/worker/do/service +// * 参数:{"oid":订单id,"image":[图片url数组]} +// */ +// @PostMapping("/api/worker/do/servicedel") +// public AjaxResult workerDoServicedel(@RequestBody Map params, HttpServletRequest request) { +// Long oid = 0L; +// if (params.get("id") != null) { +// try { +// oid = Long.valueOf(params.get("id").toString()); +// } catch (Exception e) { +// return AppletControllerUtil.appletError("订单ID格式错误"); +// } +// } +// Order order = orderService.selectOrderById(oid); +// if (order == null) { +// return AppletControllerUtil.appletError("订单不存在"); +// } +//// if (order.getStatus() != 3) { +//// return AppletControllerUtil.appletError("订单状态只能是服务中的数据才能暂停服务"); +//// } +// // 获取当前师傅id +// if (order != null) { +// Long workerId = order.getWorkerId(); +// if (order.getJsonStatus() == 6||order.getJsonStatus() == 4) { +// //开始服务 +// // 1. 修改订单状态 +// order.setStatus(3L); // 服务中 +// order.setJsonStatus(7); // 服务中 +// order.setLogJson("{\"type\":6}"); +// order.setIsPause(1); // 服务中 +// order.setUpdatedAt(new Date()); +// int update = orderService.updateOrder(order); +// if (update > 0) { +// // 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 = 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(workerId); +// log.setWorkerLogId(workerId); +// log.setIsPause(1); +// log.setCreatedAt(new Date()); +// orderLogService.insertOrderLog(log); +// return AppletControllerUtil.appletSuccess("服务已开始"); +// } else { +// return AppletControllerUtil.appletError("操作失败"); +// } +// } +// OrderLog newlog =new OrderLog(); +// OrderLog newlogdata =new OrderLog(); +// newlogdata.setType(new BigDecimal(6.0)); +// newlogdata.setOid(order.getId()); +// List logList = orderLogService.selectOrderLogList(newlogdata); +// if (!logList.isEmpty()) { +// newlog = logList.getFirst(); +// } +// Order storder = orderService.selectOrderById(newlog.getOid()); +// if (storder.getJsonStatus() == 7) { +// newlog.setIsPause(2); +// JSONArray jsonArray = JSONArray.parseArray(newlog.getContent()); +// // 2. 组装日志内容为数组格式 +// Map logItem = new LinkedHashMap<>(); +// 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); +// jsonArray.add(logItem); +// newlog.setContent(jsonArray.toJSONString()); +// orderLogService.updateOrderLog(newlog); +// +// if (storder != null) { +// // 1. 修改订单状态 +// storder.setStatus(3L); // 服务中 +// storder.setJsonStatus(8); // 服务中 +// storder.setLogJson("{\"type\":6}"); +// storder.setIsPause(2); // 服务中 +// storder.setUpdatedAt(new Date()); +// orderService.updateOrder(storder); +// } +// return AppletControllerUtil.appletSuccess("操作成功"); +// } +// if (storder.getJsonStatus() == 8) { +// newlog.setIsPause(1); +// JSONArray jsonArray = JSONArray.parseArray(newlog.getContent()); +// Map logItem = new LinkedHashMap<>(); +// logItem.put("name", "继续服务"); +// logItem.put("image", params.get("image")); +// logItem.put("time", new Date()); +// logItem.put("type", 1); +// jsonArray.add(logItem); +// newlog.setContent(jsonArray.toJSONString()); +// orderLogService.updateOrderLog(newlog); +// if (storder != null) { +// //继续服务 +// storder.setStatus(3L); // 服务中 +// storder.setJsonStatus(7); // 服务中 +// storder.setLogJson("{\"type\":6}"); +// storder.setIsPause(1); // 服务中 +// storder.setUpdatedAt(new Date()); +// orderService.updateOrder(storder); +// } +// return AppletControllerUtil.appletSuccess("操作成功"); +// } +// } +// return AppletControllerUtil.appletSuccess("操作成功"); +// } /** * 师傅完成订单接口 * POST /api/worker/finish/service @@ -5992,6 +7090,9 @@ public class AppletController extends BaseController { if (order == null) { return AppletControllerUtil.appletError("订单不存在"); } + + String priceDifferenceprice= params.get("priceDifferenceprice").toString(); + // 1. 修改订单状态 order.setStatus(6L); // 完成 order.setReceiveType(3L); // 完成类型 @@ -6013,6 +7114,11 @@ public class AppletController extends BaseController { 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); Users users = usersService.selectUsersById(order.getUid()); ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); @@ -6761,7 +7867,7 @@ public class AppletController extends BaseController { notice.put("sort", noticeItem.getInteger("sort")); notice.put("status", status); resultList.add(notice); - } catch (Exception e) { + } catch (Exception e) { // 单个公告解析失败时跳过,继续处理其他公告 System.err.println("解析单个公告数据失败:" + e.getMessage()); continue; @@ -7477,6 +8583,8 @@ public class AppletController extends BaseController { result.put("allmoney", originalAmount); // 原始总金额(固定不变,这是您最初存储的金额) result.put("finalAmount", actualAmount); // 实际应付金额(基于allmoney计算得出) result.put("wxmoney", wxMoney); // 微信支付金额 + result.put("status", payBefor.getStatus()); + result.put("oid", payBefor.getOid()); result.put("yemoney", yeMoney); // 余额支付金额 result.put("membermoney", memberMoney); // 会员优惠金额(固定不变) result.put("shopmoney", shopMoney); // 购物金抵扣金额(固定不变) @@ -7568,6 +8676,8 @@ public class AppletController extends BaseController { result.put("allmoney", originalAmount); // 原始总金额(固定不变,这是您最初存储的金额) result.put("finalAmount", actualAmount); // 实际应付金额(基于allmoney计算得出) result.put("wxmoney", wxMoney); // 微信支付金额 + result.put("status", payBefor.getStatus()); + result.put("oid", payBefor.getOid()); result.put("yemoney", yeMoney); // 余额支付金额 result.put("membermoney", memberMoney); // 会员优惠金额(固定不变) result.put("shopmoney", shopMoney); // 购物金抵扣金额(固定不变) @@ -7600,59 +8710,4 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletError("查询预支付记录失败:" + e.getMessage()); } } -// /** -// * 获取次卡列表(支持分页) -// * -// * 查询用户次卡列表,支持按类型筛选和分页 -// * 每个次卡会包含对应的服务商品详情 -// * -// * @param params 查询参数(page, limit, type) -// * @param request HTTP请求对象 -// * @return 次卡列表(分页格式) -// */ -// @PostMapping("/secondary/card/list") -// public AjaxResult getSecondaryCardList(@RequestBody Map params, HttpServletRequest request) { -// try { -// // 1. 获取并验证分页参数 -// int page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1; -// int limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 15; -// -// Map pageValidation = PageUtil.validatePageParams(page, limit); -// if (!(Boolean) pageValidation.get("valid")) { -// return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); -// } -// -// // 2. 获取type参数 -// Long type = params.get("type") != null ? Long.parseLong(params.get("type").toString()) : null; -// -// // 3. 创建查询对象 -// UserSecondaryCard queryParams = new UserSecondaryCard(); -// queryParams.setStatus(1L); // 只查询状态为1的数据 -// if (type != null) { -// queryParams.setType(type); -// } -// -// // 4. 设置分页参数 -// PageHelper.startPage(page, limit); -// -// // 5. 执行查询 -// List list = userSecondaryCardService.selectUserSecondaryCardList(queryParams); -// -// // 6. 为每个次卡填充服务商品详情 -// for (UserSecondaryCard card : list) { -// List idsList = com.alibaba.fastjson2.JSONArray.parseArray(card.getGoodsids(), String.class); -// card.setServiceDetail(serviceGoodsService.selectServiceGoodsfrocikaList(idsList)); -// } -// -// // 7. 获取分页信息并构建响应 -// TableDataInfo tableDataInfo = getDataTable(list); -// Map pageData = PageUtil.buildPageResponse(tableDataInfo, page, limit); -// -// return AppletControllerUtil.appletSuccess(pageData); -// -// } catch (Exception e) { -// System.err.println("查询次卡列表异常:" + e.getMessage()); -// return AppletControllerUtil.appletError("获取次卡列表失败:" + e.getMessage()); -// } -// } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/PayNotifyController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/PayNotifyController.java index a101d87..14a89a0 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/PayNotifyController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/PayNotifyController.java @@ -340,7 +340,79 @@ public class PayNotifyController extends BaseController { } } + /** + * 拼团支付的回调接口 + * + * @param request HTTP请求对象 + * @return XML格式响应给微信服务器 + *IUserGroupBuyingService userGroupBuyingService; + * 处理商品订单的支付成功回调: + * 1. 验证支付签名 + * 2. 更新商品订单支付状态 + * 3. 更新订单支付时间和交易号 + * 4. 处理库存扣减等业务逻辑 + */ + @PostMapping(value = "/api/order/friend/paydata/notify") + public String apiorderfriendpaydatanotify(HttpServletRequest request) { + try { + logger.info("收到商品支付回调通知,开始处理..."); + // 1. 使用WechatPayUtil处理支付回调 + Map notifyResult = wechatPayUtil.handlePayNotify(request); + + // 2. 检查处理结果 + boolean success = (Boolean) notifyResult.get("success"); + String message = (String) notifyResult.get("message"); + + if (!success) { + logger.error("商品支付回调处理失败:{}", message); + return buildFailResponse("商品支付回调处理失败"); + } + + // 3. 获取支付信息 + Map paymentInfo = (Map) notifyResult.get("paymentInfo"); + String outTradeNo = (String) paymentInfo.get("outTradeNo"); + String transactionId = (String) paymentInfo.get("transactionId"); + String totalFee = (String) paymentInfo.get("totalFee"); + UsersPayBefor usersPayBefor = usersPayBeforService.selectUsersPayBeforByOrderId(outTradeNo); + + if (usersPayBefor!=null){ + usersPayBefor.setStatus(2L); + usersPayBefor.setPaytype(4L); + usersPayBefor.setPaytime(new Date()); + usersPayBefor.setPaycode(transactionId); + usersPayBeforService.updateUsersPayBefor(usersPayBefor); + } + Users users = null; + if (usersPayBefor != null) { + users = usersService.selectUsersById(usersPayBefor.getUid()); + } + //订单回调处理,拼团创建订单,其他订单修改状态 + OrderUtil.prepayCallback(usersPayBefor, users); + +// //最后无论如何平台流水需要添加,让平台看到流水和账目 + PayMoneyLog payMoneyLog = new PayMoneyLog(); + if (usersPayBefor != null) { + payMoneyLog.setOid(usersPayBefor.getId()); + } + payMoneyLog.setOrderId(usersPayBefor.getOrderid()); + payMoneyLog.setUid(usersPayBefor.getUid()); + if (users != null) { + payMoneyLog.setUname(users.getName()); + } + payMoneyLog.setPrice(usersPayBefor.getWxmoney()); + payMoneyLog.setMark("订单支付"); + payMoneyLog.setPayTime(new Date()); + payMoneyLogService.insertPayMoneyLog(payMoneyLog); + //sendWechatMessage(users,outTradeNo); + logger.info("商品支付回调处理成功,订单号:{}", outTradeNo); + return buildSuccessResponse(); + + } catch (Exception e) { + logger.error("商品支付回调处理异常:", e); + return buildFailResponse("商品支付回调处理异常"); + } + } /** diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/QuoteMaterialController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/QuoteMaterialController.java index cdea516..2ea11c4 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/QuoteMaterialController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/QuoteMaterialController.java @@ -6,6 +6,7 @@ import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; import com.alibaba.fastjson2.JSON; +import com.ruoyi.system.ControllerUtil.AppletControllerUtil; import com.ruoyi.system.domain.QuoteCraft; import com.ruoyi.system.domain.QuoteType; import com.ruoyi.system.service.IQuoteMaterialTypeService; @@ -59,6 +60,7 @@ public class QuoteMaterialController extends BaseController } List list = quoteMaterialService.selectQuoteMaterialList(quoteMaterial); for(QuoteMaterial QuoteMaterialData:list){ + QuoteMaterialData.setImage(AppletControllerUtil.buildImageUrl(QuoteMaterialData.getImage())); List idslist = Arrays.asList( QuoteMaterialData.getGoodId().replaceAll("[\\[\\]\"]", "").split(", ")); QuoteMaterialData.setServiceName(serviceGoodsService.selectTitlesByIds(idslist)); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/UserSecondaryCardController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/UserSecondaryCardController.java index 731f2b8..4725e20 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/UserSecondaryCardController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/UserSecondaryCardController.java @@ -49,7 +49,47 @@ public class UserSecondaryCardController extends BaseController @Autowired private IServiceCateService serviceCateService; + /** + * 数字转中文工具方法 + */ + private String numberToChinese(Long num) { + if (num == null || num <= 0) { + return "零"; + } + + String[] chineseNumbers = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}; + + if (num <= 10) { + return chineseNumbers[num.intValue()]; + } else if (num < 20) { + return "十" + (num > 10 ? chineseNumbers[Math.toIntExact((num - 10))] : ""); + } else if (num < 100) { + long tens = num / 10; + long ones = num % 10; + String result = chineseNumbers[(int)tens] + "十"; + if (ones > 0) { + result += chineseNumbers[(int)ones]; + } + return result; + } else { + // 对于大于100的数字,直接返回阿拉伯数字 + return num.toString(); + } + } + /** + * 生成introduction字段 + */ + private String generateIntroduction(Long allnum, Long num) { + if (allnum == null || num == null) { + return ""; + } + + String allnumChinese = numberToChinese(allnum); + String numChinese = numberToChinese(num); + + return allnumChinese + "选" + numChinese; + } /** * 查询次卡管理列表 @@ -107,6 +147,11 @@ public class UserSecondaryCardController extends BaseController { userSecondaryCard.setOrderid(GenerateCustomCode.generCreateOrder("CIKA")); userSecondaryCard.setCreattime(new Date()); + + // 自动生成introduction字段 + String introduction = generateIntroduction(userSecondaryCard.getAllnum(), userSecondaryCard.getNum()); + userSecondaryCard.setIntroduction(introduction); + return toAjax(userSecondaryCardService.insertUserSecondaryCard(userSecondaryCard)); } @@ -118,6 +163,10 @@ public class UserSecondaryCardController extends BaseController @PutMapping public AjaxResult edit(@RequestBody UserSecondaryCard userSecondaryCard) { + // 自动生成introduction字段 + String introduction = generateIntroduction(userSecondaryCard.getAllnum(), userSecondaryCard.getNum()); + userSecondaryCard.setIntroduction(introduction); + return toAjax(userSecondaryCardService.updateUserSecondaryCard(userSecondaryCard)); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/AppletControllerUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/AppletControllerUtil.java index 5b6d580..5ec7139 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/AppletControllerUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/AppletControllerUtil.java @@ -4894,4 +4894,225 @@ public class AppletControllerUtil { * - data字段可能为null或空数组 * - 金额字段可能为null,需要默认值处理 */ + + /** + * 将字符串格式化为JSON,支持数组类型字符串的处理 + *

+ * 该方法可以将各种格式的字符串转换为标准JSON格式: + * 1. 普通字符串 -> JSON字符串 + * 2. 数组字符串(如"1,2,3") -> JSON数组字符串 + * 3. 对象字符串 -> JSON对象字符串 + * 4. 已经是JSON格式的字符串 -> 格式化后的JSON字符串 + * + * @param inputString 输入字符串 + * @return 格式化后的JSON字符串,如果输入为空或处理失败返回null + */ + public static String formatStringToJson(String inputString) { + if (inputString == null || inputString.trim().isEmpty()) { + return null; + } + + String trimmedString = inputString.trim(); + + try { + // 如果已经是有效的JSON格式,直接格式化返回 + if (isValidJson(trimmedString)) { + return formatJsonString(trimmedString); + } + + // 检查是否是数组格式的字符串(用逗号分隔) + if (isArrayFormatString(trimmedString)) { + return formatArrayStringToJson(trimmedString); + } + + // 检查是否是对象格式的字符串(key=value格式) + if (isObjectFormatString(trimmedString)) { + return formatObjectStringToJson(trimmedString); + } + + // 普通字符串,包装为JSON字符串 + return JSON.toJSONString(trimmedString); + + } catch (Exception e) { + System.err.println("字符串格式化JSON失败,原始字符串: [" + inputString + "], 错误: " + e.getMessage()); + return null; + } + } + + /** + * 检查字符串是否是有效的JSON格式 + * + * @param jsonString JSON字符串 + * @return 是否是有效JSON + */ + private static boolean isValidJson(String jsonString) { + try { + // 尝试解析为JSON对象或数组 + if (jsonString.startsWith("{") && jsonString.endsWith("}")) { + JSONObject.parseObject(jsonString); + return true; + } else if (jsonString.startsWith("[") && jsonString.endsWith("]")) { + JSONArray.parseArray(jsonString); + return true; + } + return false; + } catch (Exception e) { + return false; + } + } + + /** + * 格式化JSON字符串,使其更易读 + * + * @param jsonString JSON字符串 + * @return 格式化后的JSON字符串 + */ + private static String formatJsonString(String jsonString) { + try { + if (jsonString.startsWith("{")) { + JSONObject jsonObject = JSONObject.parseObject(jsonString); + return JSON.toJSONString(jsonObject, String.valueOf(true)); // true表示格式化输出 + } else if (jsonString.startsWith("[")) { + JSONArray jsonArray = JSONArray.parseArray(jsonString); + return JSON.toJSONString(jsonArray, String.valueOf(true)); // true表示格式化输出 + } + return jsonString; + } catch (Exception e) { + return jsonString; + } + } + + /** + * 检查字符串是否是数组格式(用逗号分隔) + * + * @param inputString 输入字符串 + * @return 是否是数组格式 + */ + private static boolean isArrayFormatString(String inputString) { + // 检查是否包含逗号分隔符,且不是JSON对象格式 + return inputString.contains(",") && !inputString.startsWith("{") && !inputString.startsWith("["); + } + + /** + * 将数组格式的字符串转换为JSON数组字符串 + * + * @param arrayString 数组格式字符串(如"1,2,3"或"a,b,c") + * @return JSON数组字符串 + */ + private static String formatArrayStringToJson(String arrayString) { + String[] items = arrayString.split(","); + List result = new ArrayList<>(); + + for (String item : items) { + String trimmedItem = item.trim(); + if (trimmedItem.isEmpty()) { + continue; + } + + // 尝试转换为数字 + if (isNumeric(trimmedItem)) { + if (trimmedItem.contains(".")) { + result.add(Double.parseDouble(trimmedItem)); + } else { + result.add(Long.parseLong(trimmedItem)); + } + } else { + // 字符串类型 + result.add(trimmedItem); + } + } + + return JSON.toJSONString(result, String.valueOf(true)); + } + + /** + * 检查字符串是否是对象格式(key=value格式) + * + * @param inputString 输入字符串 + * @return 是否是对象格式 + */ + private static boolean isObjectFormatString(String inputString) { + // 检查是否包含等号分隔符,且不是JSON格式 + return inputString.contains("=") && !inputString.startsWith("{") && !inputString.startsWith("["); + } + + /** + * 将对象格式的字符串转换为JSON对象字符串 + * + * @param objectString 对象格式字符串(如"key1=value1,key2=value2") + * @return JSON对象字符串 + */ + private static String formatObjectStringToJson(String objectString) { + Map result = new HashMap<>(); + + // 先按逗号分割,再按等号分割 + String[] pairs = objectString.split(","); + for (String pair : pairs) { + String trimmedPair = pair.trim(); + if (trimmedPair.isEmpty()) { + continue; + } + + String[] keyValue = trimmedPair.split("=", 2); // 最多分割2次,避免值中包含等号 + if (keyValue.length == 2) { + String key = keyValue[0].trim(); + String value = keyValue[1].trim(); + + if (!key.isEmpty()) { + // 尝试转换值的类型 + if (isNumeric(value)) { + if (value.contains(".")) { + result.put(key, Double.parseDouble(value)); + } else { + result.put(key, Long.parseLong(value)); + } + } else if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) { + result.put(key, Boolean.parseBoolean(value)); + } else { + result.put(key, value); + } + } + } + } + + return JSON.toJSONString(result, String.valueOf(true)); + } + + /** + * 检查字符串是否是数字 + * + * @param str 字符串 + * @return 是否是数字 + */ + private static boolean isNumeric(String str) { + if (str == null || str.trim().isEmpty()) { + return false; + } + + try { + Double.parseDouble(str.trim()); + return true; + } catch (NumberFormatException e) { + return false; + } + } + + /** + * 将字符串格式化为JSON(带默认值) + *

+ * 如果格式化失败,返回提供的默认值 + * + * @param inputString 输入字符串 + * @param defaultValue 格式化失败时的默认值 + * @return 格式化后的JSON字符串,失败返回默认值 + */ + public static String formatStringToJson(String inputString, String defaultValue) { + String result = formatStringToJson(inputString); + return result != null ? result : defaultValue; + } + + + public static void main(String[] args) { + System.out.println(formatStringToJson("{\"image\":\"['https:img.huafurenjia.cn/images/2024-10-13/dKriAtS3HHsM0JAm6DdQEPQvAFnnuPcnOxau6SSy.jpg']\",\"num\":1,\"text\":\"你很好我爱你\" ,\"labels\":[\"技术专业\",\"作业规范\",\"价格合理\"] }")); + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/MeituanUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/MeituanUtil.java new file mode 100644 index 0000000..bd8e56d --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/MeituanUtil.java @@ -0,0 +1,165 @@ +package com.ruoyi.system.ControllerUtil; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.security.PrivateKey; +import java.security.Signature; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; + +/** + * 美团工具类 + * 主要用于美团码的核销、抵扣等相关操作 + * + * @author ruoyi + */ +public class MeituanUtil { + + // ====== 美团API配置(请补充实际值) ====== + public static String appId = "你的美团appId"; + public static String appKey = "你的美团appKey"; + public static String meituanApiUrl = "https://api-open-cater.meituan.com"; // 示例 + public static String privateKeyPem = "-----BEGIN PRIVATE KEY-----\n你的私钥内容\n-----END PRIVATE KEY-----"; + public static String publicKeyPem = "-----BEGIN PUBLIC KEY-----\n你的公钥内容\n-----END PUBLIC KEY-----"; + + // ========== 通用签名生成 ============= + /** + * 生成签名(示例,具体算法请参考美团开放平台文档) + * @param data 待签名数据 + * @param privateKey 私钥对象 + * @return 签名字符串 + */ + public static String sign(String data, PrivateKey privateKey) throws Exception { + Signature signature = Signature.getInstance("SHA256withRSA"); + signature.initSign(privateKey); + signature.update(data.getBytes(StandardCharsets.UTF_8)); + byte[] signBytes = signature.sign(); + return Base64.getEncoder().encodeToString(signBytes); + } + + // ========== HTTP请求工具 ============= + /** + * 发送POST请求 + * @param apiUrl 接口地址 + * @param jsonBody 请求体 + * @return 响应字符串 + */ + public static String doPost(String apiUrl, String jsonBody) throws Exception { + URL url = new URL(apiUrl); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); + conn.setDoOutput(true); + try (OutputStream os = conn.getOutputStream()) { + os.write(jsonBody.getBytes(StandardCharsets.UTF_8)); + } + StringBuilder response = new StringBuilder(); + try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) { + String line; + while ((line = br.readLine()) != null) { + response.append(line); + } + } + return response.toString(); + } + + // ========== 美团业务API实现 ============= + + /** + * 美团码核销 + * @param code 美团券码 + * @param orderId 订单号 + * @return 核销结果 + */ + public static Map verifyMeituanCode(String code, String orderId) { + Map result = new HashMap<>(); + try { + // 1. 构造请求参数 + Map param = new HashMap<>(); + param.put("app_id", appId); + param.put("order_id", orderId); + param.put("code", code); + // TODO: 其他必需参数 + // 2. 生成签名(具体字段顺序和内容请参考美团文档) + // String sign = sign(待签名字符串, 私钥对象); + // param.put("sign", sign); + // 3. 转为JSON + String jsonBody = com.alibaba.fastjson2.JSON.toJSONString(param); + // 4. 发送请求 + String apiUrl = meituanApiUrl + "/your/verify/api/path"; // TODO: 替换为实际核销接口路径 + String response = doPost(apiUrl, jsonBody); + // 5. 解析响应 + // TODO: 按美团返回格式解析 + result.put("success", true); + result.put("msg", "核销成功"); + result.put("response", response); + } catch (Exception e) { + result.put("success", false); + result.put("msg", "核销失败: " + e.getMessage()); + } + return result; + } + + /** + * 美团码抵扣 + * @param code 美团券码 + * @param amount 抵扣金额 + * @return 抵扣结果 + */ + public static Map deductMeituanCode(String code, double amount) { + Map result = new HashMap<>(); + try { + Map param = new HashMap<>(); + param.put("app_id", appId); + param.put("code", code); + param.put("amount", amount); + // TODO: 其他必需参数和签名 + String jsonBody = com.alibaba.fastjson2.JSON.toJSONString(param); + String apiUrl = meituanApiUrl + "/your/deduct/api/path"; // TODO: 替换为实际抵扣接口路径 + String response = doPost(apiUrl, jsonBody); + result.put("success", true); + result.put("msg", "抵扣成功"); + result.put("response", response); + } catch (Exception e) { + result.put("success", false); + result.put("msg", "抵扣失败: " + e.getMessage()); + } + return result; + } + + /** + * 查询美团码状态 + * @param code 美团券码 + * @return 状态结果 + */ + public static Map queryMeituanCodeStatus(String code) { + Map result = new HashMap<>(); + try { + Map param = new HashMap<>(); + param.put("app_id", appId); + param.put("code", code); + // TODO: 其他必需参数和签名 + String jsonBody = com.alibaba.fastjson2.JSON.toJSONString(param); + String apiUrl = meituanApiUrl + "/your/query/api/path"; // TODO: 替换为实际查询接口路径 + String response = doPost(apiUrl, jsonBody); + result.put("success", true); + result.put("msg", "查询成功"); + result.put("response", response); + } catch (Exception e) { + result.put("success", false); + result.put("msg", "查询失败: " + e.getMessage()); + } + return result; + } + + // ========== 私钥、公钥加载工具(可选) ============= + // 可根据需要实现PEM字符串转PrivateKey/公钥对象的方法 + // ... + + // 可根据实际美团API文档,继续扩展更多方法 +} \ 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 index 74dba4a..e901033 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderUtil.java @@ -24,6 +24,7 @@ public class OrderUtil { private static IUsersService usersService = SpringUtils.getBean(IUsersService.class); private static IOrderLogService orderLogService = SpringUtils.getBean(IOrderLogService.class); private static IGoodsOrderService goodsOrderService = SpringUtils.getBean(IGoodsOrderService.class); + private static IUserDemandQuotationService userDemandQuotationService = SpringUtils.getBean(IUserDemandQuotationService.class); private static OrderLogHandler orderLogHandler = SpringUtils.getBean(OrderLogHandler.class); @@ -585,50 +586,192 @@ public class OrderUtil { * @return 新建的订单对象(仅拼团),或处理结果Map */ public static Object prepayCallback(UsersPayBefor payBefor, Users user) { + System.out.println("=== prepayCallback 方法开始 ==="); + System.out.println("输入参数 - payBefor: " + (payBefor != null ? payBefor.toString() : "null")); + System.out.println("输入参数 - user: " + (user != null ? user.toString() : "null")); + if (payBefor == null || user == null) { + System.out.println("参数验证失败 - payBefor或user为空"); return null; } int type = payBefor.getType() != null ? payBefor.getType().intValue() : 0; + System.out.println("支付类型 - type: " + type); + System.out.println("服务类型 - servicetype: " + payBefor.getServicetype()); + IOrderService orderService = SpringUtils.getBean(IOrderService.class); + // 拼团 if (payBefor.getServicetype()==2){ + System.out.println("=== 处理拼团商品订单 ==="); GoodsOrder gorder = new GoodsOrder(); gorder.setMainOrderId(payBefor.getOrderid()); + System.out.println("查询拼团商品订单 - orderid: " + payBefor.getOrderid()); List orderslist =goodsOrderService.selectGoodsOrderList(gorder); + System.out.println("查询到的商品订单数量: " + (orderslist != null ? orderslist.size() : 0)); + if (!orderslist.isEmpty()){ - for (GoodsOrder goodsOrder : orderslist){ - goodsOrder.setStatus(2L); - goodsOrder.setTransactionId(payBefor.getPaycode()); - goodsOrderService.updateGoodsOrder(goodsOrder); - } + System.out.println("开始更新商品订单状态"); + for (GoodsOrder goodsOrder : orderslist){ + System.out.println("更新商品订单 - ID: " + goodsOrder.getId() + ", 原状态: " + goodsOrder.getStatus()); + goodsOrder.setStatus(2L); + goodsOrder.setTransactionId(payBefor.getPaycode()); + int updateResult = goodsOrderService.updateGoodsOrder(goodsOrder); + System.out.println("商品订单更新结果: " + updateResult); + } + } else { + System.out.println("未找到相关商品订单"); } + System.out.println("拼团商品订单处理完成,返回orderid: " + payBefor.getOrderid()); + return payBefor.getOrderid(); } + // 7上门费 8定金 9尾款 10差价 + if (type == 7) { + // 4. 查询对应的订单日志(上门费记录) + OrderLog orderLog = orderLogService.selectOrderLogById(payBefor.getOid()); + if (orderLog != null) { + // 6. 更新上门费支付状态 + orderLog.setPaid(2L); // 1:已支付 + //orderLog.setWorkerCost(new BigDecimal(totalFee)); + orderLog.setPayTime(System.currentTimeMillis()/1000); + //orderLog.setUpdateTime(new Date()); + int updateResult = orderLogService.updateOrderLog(orderLog); + if (updateResult > 0){ + ISTOPAYSIZE(payBefor.getLastorderid()); + } + +// Order order = orderService.selectOrderByOrderId(payBefor.getLastorderid()); +// if (order != null) { +// if (order.getStatus() == 6){ +// +// } +// } + } + return 1; + } + if (type == 8) { + // 4. 查询对应的订单日志(定金记录) + OrderLog orderLog = orderLogService.selectOrderLogById(payBefor.getOid()); + if (orderLog != null) { + // 6. 更新定金支付状态 + orderLog.setDepPaid(2); // 1:已支付 + orderLog.setDepPayTime(System.currentTimeMillis()/1000); + int updateResult = orderLogService.updateOrderLog(orderLog); + if (updateResult > 0){ + ISTOPAYSIZE(payBefor.getLastorderid()); + } + } + return 1; + } + if (type == 9) { + // 4. 查询对应的服务订单 + Order order = orderService.selectOrderByOrderId(payBefor.getOrderid()); + + if (order != null) { + //更新最新的一条日志信息 + OrderLog orderLog = orderLogService.selectDataTheFirstNew(order.getId()); + orderLog.setPayTime(System.currentTimeMillis()/1000); + orderLog.setPaid(2L); + orderLogService.updateOrderLog(orderLog); + OrderLog orderLog1 = orderLogService.selectOrderLogById(payBefor.getOid()); + // 6. 更新订单支付状态 + order.setStatus(4L); // 2:已支付 + // order.setTransactionId(transactionId); + order.setPayTime(new Date()); + //order.setUpdateTime(new Date()); + // 计算实际支付金额(分转换为元) + BigDecimal paidAmount = orderLog1.getPrice(); + order.setPayPrice(paidAmount); + int updateResult = orderService.updateOrder(order); + if (updateResult > 0){ + ISTOPAYSIZE(payBefor.getLastorderid()); + } + } + return 1; + } + if (type == 10) { + OrderLog orderLog = orderLogService.selectOrderLogById(payBefor.getOid()); + if (orderLog != null) { + // 6. 更新定金支付状态 + orderLog.setCjPaid(2L); + orderLog.setDepPayTime(System.currentTimeMillis()/1000); + int updateResult = orderLogService.updateOrderLog(orderLog); + if (updateResult > 0){ + ISTOPAYSIZE(payBefor.getLastorderid()); + } + } + return 1; + } + //需求报价 if (type == 4) { + System.out.println("=== 处理需求报价订单 ==="); + System.out.println("查询订单 - orderid: " + payBefor.getOrderid()); // 查询订单 Order order = orderService.selectOrderByOrderId(payBefor.getOrderid()); + System.out.println("查询到的订单: " + (order != null ? order.toString() : "null")); + if (order != null) { - // 更新订单状态为待服务(2) - order.setStatus(2L); - orderService.updateOrder(order); - // 添加订单日志 - OrderLog orderLog = new OrderLog(); - orderLog.setOid(order.getId()); - orderLog.setOrderId(order.getOrderId()); - orderLog.setTitle("报价订单支付成功"); - orderLog.setType(new BigDecimal("1.1")); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("name", "报价订单支付成功,待服务"); - orderLog.setContent(jsonObject.toJSONString()); - orderLogService.insertOrderLog(orderLog); + + UserDemandQuotation userDemandQuotation=userDemandQuotationService.selectUserDemandQuotationById(payBefor.getBaojiaid()); + if (userDemandQuotation!=null) { + System.out.println("找到报价记录,开始处理"); + //UserDemandQuotation userDemandQuotation=userDemandQuotationList.getFirst(); + System.out.println("报价记录详情: " + userDemandQuotation.toString()); + + System.out.println("更新报价状态为被选中"); + userDemandQuotation.setStatus(2L);//被选中状态 + int quotationUpdateResult = userDemandQuotationService.updateUserDemandQuotation(userDemandQuotation); + System.out.println("报价状态更新结果: " + quotationUpdateResult); + + System.out.println("查询师傅信息 - workerId: " + userDemandQuotation.getWorkerid()); + Users users = usersService.selectUsersById(userDemandQuotation.getWorkerid()); + System.out.println("查询到的师傅信息: " + (users != null ? users.toString() : "null")); + + if (users != null){ + + order.setStatus(2L); + order.setJsonStatus(2); + order.setFirstWorkerId(users.getId()); + order.setIsAccept(1); + order.setWorkerPhone(users.getPhone()); + order.setWorkerId(users.getId()); + int orderUpdateResult = orderService.updateOrder(order); + System.out.println("订单更新结果: " + orderUpdateResult); + + // 添加订单日志 + System.out.println("添加订单日志"); + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("报价订单支付成功"); + orderLog.setType(new BigDecimal("2.0")); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "报价订单支付成功,待服务,师傅"+users.getName()); + orderLog.setContent(jsonObject.toJSONString()); + int logInsertResult = orderLogService.insertOrderLog(orderLog); + System.out.println("订单日志插入结果: " + logInsertResult); + System.out.println("需求报价订单处理完成"); + } else { + System.out.println("未找到师傅信息,处理失败"); + } + } else { + System.out.println("未找到报价记录,处理失败"); + } + System.out.println("需求报价订单处理完成,返回order: " + (order != null ? order.getOrderId() : "null")); + //dispatchOrderCheck(order); return order; + } else { + System.out.println("未找到订单,处理失败"); } + System.out.println("需求报价订单处理失败,返回null"); return null; } if (type == 1) { + System.out.println("=== 处理拼团订单 ==="); String ptorderid= payBefor.getOrderid(); + System.out.println("拼团订单ID: " + ptorderid); //第一步创建订单状态为待成团 Order order = new Order(); order.setOdertype(1); // 拼团 @@ -638,23 +781,32 @@ public class OrderUtil { order.setNum(1L); // 默认1,可根据业务调整 //order.setProductId(payBefor.getSku() != null ? Long.valueOf(payBefor.getSku()) : null); // 假设sku字段存储商品ID order.setProductId(payBefor.getServiceid()); // 假设sku字段存储商品ID + System.out.println("商品ID: " + payBefor.getServiceid()); + IServiceGoodsService serviceGoodsService = SpringUtils.getBean(IServiceGoodsService.class); ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(payBefor.getServiceid()); + System.out.println("查询到的商品信息: " + (serviceGoods != null ? serviceGoods.toString() : "null")); + // 商品名、图片、类型、价格等 String productName = ""; if (serviceGoods != null) { productName = serviceGoods.getTitle(); + System.out.println("商品名称: " + productName); } order.setProductName(productName); order.setSku(payBefor.getSku()); order.setTotalPrice(payBefor.getAllmoney()); + order.setBigtype(3); order.setPayPrice(payBefor.getWxmoney()); order.setCreateTime(new Date()); order.setType(1); // 服务订单 order.setCreateType(1); // 用户自主下单 order.setUname(user.getName()); + System.out.println("订单基本信息设置完成"); + // 预约时间 + System.out.println("预约时间: " + payBefor.getMaketime()); if (payBefor.getMaketime() != null && !payBefor.getMaketime().isEmpty()) { String[] makeTimeArr = payBefor.getMaketime().split(" "); if (makeTimeArr.length == 2) { @@ -668,19 +820,26 @@ public class OrderUtil { } } } + System.out.println("地址ID: " + payBefor.getAddressid()); if (payBefor.getAddressid() != null) { IUserAddressService userAddressService = SpringUtils.getBean(IUserAddressService.class); UserAddress userAddress = userAddressService.selectUserAddressById(payBefor.getAddressid()); + System.out.println("查询到的地址信息: " + (userAddress != null ? userAddress.toString() : "null")); if (userAddress != null) { order.setAddressId(userAddress.getId()); order.setName(userAddress.getName()); order.setPhone(userAddress.getPhone()); order.setAddress(userAddress.getAddressInfo()); + System.out.println("地址信息设置完成"); } } // 可补充其它字段,如拼团价、优惠券、备注等 - orderService.insertOrder(order); + System.out.println("开始插入订单"); + int orderInsertResult = orderService.insertOrder(order); + System.out.println("订单插入结果: " + orderInsertResult + ", 订单ID: " + order.getId()); + // 添加订单日志 + System.out.println("添加订单日志"); IOrderLogService orderLogService = SpringUtils.getBean(IOrderLogService.class); //IOrderService orderService = SpringUtils.getBean(IOrderService.class); OrderLog orderLog = new OrderLog(); @@ -691,49 +850,102 @@ public class OrderUtil { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", "订单创建成功,待成团"); orderLog.setContent(jsonObject.toJSONString()); - orderLogService.insertOrderLog(orderLog); + int logInsertResult = orderLogService.insertOrderLog(orderLog); + System.out.println("订单日志插入结果: " + logInsertResult); //第二步修改拼团时候的状态 + System.out.println("=== 第二步:修改拼团状态 ==="); IUserGroupBuyingService userGroupBuyingService = SpringUtils.getBean(IUserGroupBuyingService.class); UserGroupBuying userGroupBuying = userGroupBuyingService.selectUserGroupBuyingByptorderid(ptorderid); + System.out.println("查询到的拼团记录: " + (userGroupBuying != null ? userGroupBuying.toString() : "null")); + if (userGroupBuying != null){ + System.out.println("更新拼团状态"); userGroupBuying.setStatus(1L); userGroupBuying.setPaystatus(1L); - userGroupBuyingService.updateUserGroupBuying(userGroupBuying); + int groupUpdateResult = userGroupBuyingService.updateUserGroupBuying(userGroupBuying); + System.out.println("拼团状态更新结果: " + groupUpdateResult); + } else { + System.out.println("未找到拼团记录"); } //第三步核验团数据,如果满足条件都修改为待预约 + System.out.println("=== 第三步:核验团数据 ==="); + System.out.println("团订单ID: " + payBefor.getGrouporderid()); + System.out.println("商品拼团人数要求: " + (serviceGoods != null ? serviceGoods.getGroupnum() : "null")); + UserGroupBuying userGroupBuyingData = new UserGroupBuying(); userGroupBuyingData.setOrderid(payBefor.getGrouporderid()); userGroupBuyingData.setPaystatus(1L); + userGroupBuyingData.setStatus(2L); List userGroupBuyingList = userGroupBuyingService.selectUserGroupBuyingList(userGroupBuyingData); + System.out.println("已支付的拼团人数: " + (userGroupBuyingList != null ? userGroupBuyingList.size() : 0)); + if (userGroupBuyingList.size() >= serviceGoods.getGroupnum()) { + System.out.println("拼团人数已满足要求,开始更新所有拼团订单状态"); for (UserGroupBuying groupBuying1 : userGroupBuyingList){ - groupBuying1.setStatus(1L); + System.out.println("更新拼团记录 - ID: " + groupBuying1.getId() + ", 订单ID: " + groupBuying1.getPtorderid()); + groupBuying1.setStatus(2L); groupBuying1.setPaystatus(1L); - userGroupBuyingService.updateUserGroupBuying(groupBuying1); + int groupUpdateResult = userGroupBuyingService.updateUserGroupBuying(groupBuying1); + System.out.println("拼团记录更新结果: " + groupUpdateResult); + Order orderdata = orderService.selectOrderByOrderId(groupBuying1.getPtorderid()); + System.out.println("查询到的订单: " + (orderdata != null ? orderdata.getOrderId() : "null")); if (orderdata != null){ + System.out.println("更新订单状态为已成团待预约"); orderdata.setStatus(10L);//已成团待预约 - orderService.updateOrder(orderdata); + int orderUpdateResult = orderService.updateOrder(orderdata); + System.out.println("订单状态更新结果: " + orderUpdateResult); } - } - + System.out.println("拼团成功,所有订单状态已更新"); + } else { + System.out.println("拼团人数未满足要求,继续等待"); } + System.out.println("拼团订单处理完成,返回order: " + order.getOrderId()); + dispatchOrderCheck(order); return order; } else { // 其他类型 + System.out.println("=== 处理其他类型订单 ==="); + System.out.println("订单ID: " + payBefor.getOrderid()); // 只更新订单状态为待预约(假设为1) if (payBefor.getOrderid() != null) { if (type == 2){ + System.out.println("处理次卡订单"); IUserUseSecondaryCardService userUseSecondaryCardService = SpringUtils.getBean(IUserUseSecondaryCardService.class); UserUseSecondaryCard userUseSecondaryCard = userUseSecondaryCardService.selectUserUseSecondaryCardByorderId(payBefor.getOrderid()); + System.out.println("查询到的次卡记录: " + (userUseSecondaryCard != null ? userUseSecondaryCard.toString() : "null")); + if (userUseSecondaryCard != null){ + System.out.println("更新次卡状态"); userUseSecondaryCard.setStatus(1L); - userUseSecondaryCardService.updateUserUseSecondaryCard(userUseSecondaryCard); + int cardUpdateResult = userUseSecondaryCardService.updateUserUseSecondaryCard(userUseSecondaryCard); + System.out.println("次卡状态更新结果: " + cardUpdateResult); + } else { + Order order = orderService.selectOrderByOrderId(payBefor.getOrderid()); + System.out.println("添加订单日志"); + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("订单支付"); + orderLog.setType(new BigDecimal("1.1")); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "一口价订单支付成功,待派单"); + orderLog.setContent(jsonObject.toJSONString()); + int logInsertResult = orderLogService.insertOrderLog(orderLog); + order.setStatus(1L); // 1=待预约 + int orderUpdateResult = orderService.updateOrder(order); + dispatchOrderCheck(order); + return order; } + System.out.println("次卡订单处理完成,返回: " + (userUseSecondaryCard != null ? userUseSecondaryCard.getId() : "null")); return userUseSecondaryCard; }else{ + System.out.println("处理普通订单"); Order order = orderService.selectOrderByOrderId(payBefor.getOrderid()); + System.out.println("查询到的订单: " + (order != null ? order.toString() : "null")); + if (order != null) { + System.out.println("添加订单日志"); OrderLog orderLog = new OrderLog(); orderLog.setOid(order.getId()); orderLog.setOrderId(order.getOrderId()); @@ -742,14 +954,24 @@ public class OrderUtil { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", "订单支付成功,待派单"); orderLog.setContent(jsonObject.toJSONString()); - orderLogService.insertOrderLog(orderLog); + int logInsertResult = orderLogService.insertOrderLog(orderLog); + System.out.println("订单日志插入结果: " + logInsertResult); + + System.out.println("更新订单状态为待派单"); order.setStatus(1L); // 1=待预约 - orderService.updateOrder(order); + int orderUpdateResult = orderService.updateOrder(order); + System.out.println("订单状态更新结果: " + orderUpdateResult); + System.out.println("普通订单处理完成,返回order: " + order.getOrderId()); + dispatchOrderCheck(order); return order; + } else { + System.out.println("未找到订单"); } - } + } else { + System.out.println("订单ID为空,无法处理"); } + System.out.println("其他类型订单处理失败,返回null"); return null; } } @@ -807,4 +1029,88 @@ public class OrderUtil { } return false; } + + public static int ISTOPAYSIZE(String orderid) { + IUsersPayBeforService usersPayBeforService = SpringUtils.getBean(IUsersPayBeforService.class); + IOrderService orderService = SpringUtils.getBean(IOrderService.class); + UsersPayBefor payBefore = new UsersPayBefor(); + payBefore.setLastorderid(orderid); + payBefore.setStatus(1L); + List payBeforeList = usersPayBeforService.selectUsersPayBeforList(payBefore); + Order order = orderService.selectOrderByOrderId(orderid); + if (order != null) { + if (order.getStatus() == 6){ + if (payBeforeList.isEmpty()){ + order.setStatus(4L); + orderService.updateOrder(order); + } + + } + } + return payBeforeList.size(); + } + + + + /** + * 派单效验方法 + * @param order 订单对象,需包含 productId + * @return 处理结果Map,包含派单方式、绑定工人等信息 + */ + public static Map dispatchOrderCheck(Order order) { + IOrderService orderService = SpringUtils.getBean(IOrderService.class); + Map result = new HashMap<>(); + if (order == null || order.getProductId() == null) { + result.put("success", false); + result.put("msg", "订单或商品ID为空"); + return result; + } + IServiceGoodsService serviceGoodsService = SpringUtils.getBean(IServiceGoodsService.class); + IOrderLogService orderLogService = SpringUtils.getBean(IOrderLogService.class); + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + if (serviceGoods == null) { + result.put("success", false); + result.put("msg", "未找到对应服务商品"); + return result; + } + if(order.getOdertype()==4){ + return result; + } + Integer dispatchType = serviceGoods.getDispatchtype(); + result.put("dispatchtype", dispatchType); + if (dispatchType != null && dispatchType == 3) { + // 指定工人派单 + String workerIdsStr = serviceGoods.getWorkerids(); + result.put("workerids", workerIdsStr); + if (workerIdsStr != null) { + Users users = usersService.selectUsersById(Long.valueOf(workerIdsStr)); + + order.setStatus(1L); + order.setFirstWorkerId(users.getId()); + order.setIsAccept(1); + order.setWorkerPhone(users.getPhone()); + order.setWorkerId(users.getId()); + int orderUpdateResult = orderService.updateOrder(order); + // 添加订单日志 + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("订单支付成功"); + orderLog.setType(new BigDecimal("1.0")); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "一口价订单支付成功,待服务,师傅"+users.getName()); + orderLog.setContent(jsonObject.toJSONString()); + int logInsertResult = orderLogService.insertOrderLog(orderLog); + return result; + } else { + result.put("success", false); + result.put("msg", "服务未配置指定工人"); + return result; + } + } + // 其他派单类型可扩展 + result.put("success", true); + result.put("msg", "无需指定工人派单"); + return result; + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/PayBeforeUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/PayBeforeUtil.java index 036b94f..5859a35 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/PayBeforeUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/PayBeforeUtil.java @@ -1,5 +1,6 @@ package com.ruoyi.system.ControllerUtil; +import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.system.domain.SiteConfig; import com.ruoyi.system.domain.Users; @@ -13,6 +14,7 @@ import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.util.Date; import java.util.List; +import com.ruoyi.system.domain.OrderLog; /** * 预支付工具类 @@ -48,7 +50,7 @@ public class PayBeforeUtil { */ public String createPayBefore(Users user, BigDecimal amount, String orderId, Long oid, Long serviceId, Long orderType, String sku, String grouporderid, - Long addressid, String maketime, String attachments,Long servicetype) { + Long addressid, String maketime, String attachments,Long servicetype,Long baojiaid,String lastorderid) { try { // 计算会员优惠和服务金抵扣 BigDecimal memberMoney = BigDecimal.ZERO; @@ -83,7 +85,6 @@ public class PayBeforeUtil { } // 购物金抵扣(当servicetype=2时) if (servicetype != null && servicetype == 2) { - orderType= 5L; Integer consumption = configJson.getInteger("consumption"); if (consumption != null && consumption > 0) { Users userDb = usersService.selectUsersById(user.getId()); @@ -123,8 +124,10 @@ public class PayBeforeUtil { payBefore.setAddressid(addressid); payBefore.setMaketime(maketime != null ? maketime : ""); payBefore.setAttachments(attachments != null ? attachments : ""); + payBefore.setBaojiaid(baojiaid); payBefore.setStatus(1L); // 1待支付 payBefore.setPaytype(1L); // 默认微信支付 + payBefore.setLastorderid(lastorderid != null ? lastorderid : ""); int result = usersPayBeforService.insertUsersPayBefor(payBefore); if (result > 0) { return payBefore.getOrderid(); @@ -236,7 +239,7 @@ public class PayBeforeUtil { * @return 预支付记录ID,失败返回null */ public String createPayBefore(Users user, BigDecimal amount) { - return createPayBefore(user, amount, null, null, 0L, 0L, null, null, null, null, null,null); + return createPayBefore(user, amount, null, null, 0L, 0L, null, null, null, null, null,null, null,null); } /** @@ -252,7 +255,7 @@ public class PayBeforeUtil { */ public String createPayBefore(Users user, BigDecimal amount, String orderId, Long oid, Long serviceId, Long orderType) { - return createPayBefore(user, amount, orderId, oid, serviceId, orderType, null, null, null, null, null,null); + return createPayBefore(user, amount, orderId, oid, serviceId, orderType, null, null, null, null, null,null, null, null); } /** @@ -335,4 +338,78 @@ public class PayBeforeUtil { return false; } } + + /** + * 报价预支付数据处理 + * @param user 用户实体 + * @param orderLog 订单日志实体 + * @param baojiajson 报价json字符串 + */ + public void handleQuotationPayBefore(Users user, OrderLog orderLog, String baojiajson) { + if (user == null || orderLog == null || baojiajson == null || baojiajson.trim().isEmpty()) { + return; + } + try { + com.alibaba.fastjson2.JSONObject json = com.alibaba.fastjson2.JSONObject.parseObject(baojiajson); + // 处理定金 + JSONObject deposit = json.getJSONObject("deposit"); + if (deposit != null) { + String depositPriceStr = deposit.getString("price"); + BigDecimal depositPrice = null; + try { + depositPrice = new BigDecimal(depositPriceStr); + } catch (Exception ignore) {} + if (depositPrice != null && depositPrice.compareTo(BigDecimal.ZERO) > 0) { + // 添加定金预支付信息 + this.createPayBefore( + user, + depositPrice, + orderLog.getDepLogId(), // orderid + orderLog.getId(), // oid + null, // serviceId + 8L, // type=8 定金 + null, null, null, null, null, 1L, null, orderLog.getOrderId() + ); + } + } + // 处理尾款 + JSONObject project = json.getJSONObject("project"); + if (project != null) { + String projectPriceStr = project.getString("price"); + BigDecimal projectPrice = null; + try { + projectPrice = new BigDecimal(projectPriceStr); + } catch (Exception ignore) {} + if (projectPrice != null && projectPrice.compareTo(BigDecimal.ZERO) > 0) { + // 判断优惠金额 + JSONObject reduction = json.getJSONObject("reduction"); + BigDecimal reductionPrice = BigDecimal.ZERO; + if (reduction != null) { + String reductionPriceStr = reduction.getString("price"); + try { + reductionPrice = new BigDecimal(reductionPriceStr); + } catch (Exception ignore) {} + } + BigDecimal finalTail = projectPrice; + if (reductionPrice != null && reductionPrice.compareTo(BigDecimal.ZERO) > 0) { + finalTail = projectPrice.subtract(reductionPrice); + } + if (finalTail.compareTo(BigDecimal.ZERO) > 0) { + // 添加尾款预支付信息 + this.createPayBefore( + user, + finalTail, + orderLog.getLogOrderId(), // orderid + orderLog.getId(), // oid + null, // serviceId + 9L, // type=9 尾款 + null, null, null, null, null, 1L, null, orderLog.getOrderId() + ); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } } \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/Order.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/Order.java index 5125fb0..9f83083 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/Order.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/Order.java @@ -2,6 +2,8 @@ package com.ruoyi.system.domain; import java.math.BigDecimal; import java.util.Date; +import java.util.List; + import com.fasterxml.jackson.annotation.JsonFormat; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -200,6 +202,13 @@ public class Order extends BaseEntity /** 订单附件 */ @Excel(name = "订单附件") private String fileData; + + + private Long baojiasf; + + private Long baojiayh; + + private List ids; /** 录音文件 */ @Excel(name = "订单类别 1预约 2报价 3一口价 4拼团 5普通订单") private int odertype; @@ -255,6 +264,18 @@ public class Order extends BaseEntity @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") private Date deletedAt; + private Long makeTimeStart; + private Long makeTimeEnd; + + public Long getMakeTimeStart() { return makeTimeStart; } + public void setMakeTimeStart(Long makeTimeStart) { this.makeTimeStart = makeTimeStart; } + public Long getMakeTimeEnd() { return makeTimeEnd; } + public void setMakeTimeEnd(Long makeTimeEnd) { this.makeTimeEnd = makeTimeEnd; } + + private String dayDate; + public String getDayDate() { return dayDate; } + public void setDayDate(String dayDate) { this.dayDate = dayDate; } + public void setId(Long id) { this.id = id; @@ -887,6 +908,45 @@ public class Order extends BaseEntity this.bigtype = bigtype; } + + public Long getBaojiasf() { + return baojiasf; + } + + public void setBaojiasf(Long baojiasf) { + this.baojiasf = baojiasf; + } + + public Long getBaojiayh() { + return baojiayh; + } + + public void setBaojiayh(Long baojiayh) { + this.baojiayh = baojiayh; + } + + + public List getIds() { + return ids; + } + + public void setIds(List ids) { + this.ids = ids; + } + + public static class OrderTypeCount { + private int bigtype; + private int count; + public OrderTypeCount(int bigtype, int count) { + this.bigtype = bigtype; + this.count = count; + } + public int getBigtype() { return bigtype; } + public void setBigtype(int bigtype) { this.bigtype = bigtype; } + public int getCount() { return count; } + public void setCount(int count) { this.count = count; } + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/OrderLog.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/OrderLog.java index 2ef8072..1712ad7 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/OrderLog.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/OrderLog.java @@ -81,6 +81,14 @@ public class OrderLog extends BaseEntity @Excel(name = "工人id") private Long workerId; + /** 工人id */ + @Excel(name = "补差价金额") + private BigDecimal cjMoney; + + /** 工人id */ + @Excel(name = "补差价状态") + private Long cjPaid; + /** 工人id */ @Excel(name = "工人id") @@ -408,6 +416,23 @@ public class OrderLog extends BaseEntity this.workerName = workerName; } + + public BigDecimal getCjMoney() { + return cjMoney; + } + + public void setCjMoney(BigDecimal cjMoney) { + this.cjMoney = cjMoney; + } + + public Long getCjPaid() { + return cjPaid; + } + + public void setCjPaid(Long cjPaid) { + this.cjPaid = cjPaid; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/UserDemandQuotation.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/UserDemandQuotation.java index ed65510..d4dca48 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/UserDemandQuotation.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/UserDemandQuotation.java @@ -40,6 +40,10 @@ public class UserDemandQuotation extends BaseEntity /** 状态 1报价 2被选中 */ private Long status; + /** 状态 1报价 2被选中 */ + private Long oid; + + /** 师傅图像 */ @Excel(name = "师傅图像") private String workerimage; @@ -155,6 +159,15 @@ public class UserDemandQuotation extends BaseEntity return updatedAt; } + + public Long getOid() { + return oid; + } + + public void setOid(Long oid) { + this.oid = oid; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/Users.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/Users.java index 31f39c7..ec2f025 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/Users.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/Users.java @@ -3,6 +3,7 @@ package com.ruoyi.system.domain; import java.math.BigDecimal; import java.util.Date; import java.util.Map; +import java.util.List; import com.fasterxml.jackson.annotation.JsonFormat; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -186,6 +187,8 @@ public class Users extends BaseEntity private Map order_num; private Map goods_order_num; + private List areaList; + private String skill; public void setId(Long id) @@ -625,6 +628,11 @@ public class Users extends BaseEntity this.birthday = birthday; } + public List getAreaList() { return areaList; } + public void setAreaList(List areaList) { this.areaList = areaList; } + public String getSkill() { return skill; } + public void setSkill(String skill) { this.skill = skill; } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/UsersPayBefor.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/UsersPayBefor.java index c174c43..6c4ef51 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/UsersPayBefor.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/UsersPayBefor.java @@ -66,6 +66,13 @@ public class UsersPayBefor extends BaseEntity @Excel(name = "美团号") private String mtcode; + + /** 美团号 */ + @Excel(name = "号") + private String lastorderid; + + + /** 美团抵扣金额 */ @Excel(name = "美团抵扣金额") private BigDecimal mtmoney; @@ -98,6 +105,8 @@ public class UsersPayBefor extends BaseEntity private Long servicetype; + private Long baojiaid; + private String sku; private Long addressid; private String maketime; @@ -355,6 +364,23 @@ public class UsersPayBefor extends BaseEntity this.servicetype = servicetype; } + + public Long getBaojiaid() { + return baojiaid; + } + + public void setBaojiaid(Long baojiaid) { + this.baojiaid = baojiaid; + } + + public String getLastorderid() { + return lastorderid; + } + + public void setLastorderid(String lastorderid) { + this.lastorderid = lastorderid; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/OrderMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/OrderMapper.java index 949755d..b598fed 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/OrderMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/OrderMapper.java @@ -76,4 +76,11 @@ public interface OrderMapper * @return 结果 */ public int deleteOrderByIds(Long[] ids); + + /** + * 统计bigtype为1、2、3且status!=4的订单数量,按bigtype分组,指定用户 + * @param uid 用户id + * @return 统计结果 + */ + List selectOrderCountByBigtype(Long uid); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IOrderService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IOrderService.java index c13ce50..184fbef 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IOrderService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IOrderService.java @@ -74,4 +74,11 @@ public interface IOrderService * @return 结果 */ public int deleteOrderById(Long id); + + /** + * 统计bigtype为1、2、3且status!=4的订单数量,按bigtype分组,指定用户 + * @param uid 用户id + * @return 统计结果 + */ + List selectOrderCountByBigtype(Long uid); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OrderLogServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OrderLogServiceImpl.java index 3b325fb..c393bff 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OrderLogServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OrderLogServiceImpl.java @@ -1,6 +1,8 @@ package com.ruoyi.system.service.impl; import java.util.List; + +import com.ruoyi.system.ControllerUtil.GenerateCustomCode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.system.mapper.OrderLogMapper; @@ -89,6 +91,7 @@ public class OrderLogServiceImpl implements IOrderLogService @Override public int insertOrderLog(OrderLog orderLog) { + return orderLogMapper.insertOrderLog(orderLog); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OrderServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OrderServiceImpl.java index e64e3b0..c81abb2 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OrderServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OrderServiceImpl.java @@ -69,6 +69,10 @@ public class OrderServiceImpl implements IOrderService return orderMapper.selectOrderList(order); } + @Override + public List selectOrderCountByBigtype(Long uid) { + return orderMapper.selectOrderCountByBigtype(uid); + } /** * 新增服务订单 * diff --git a/ruoyi-system/src/main/resources/mapper/system/OrderLogMapper.xml b/ruoyi-system/src/main/resources/mapper/system/OrderLogMapper.xml index 72c860a..5a91e81 100644 --- a/ruoyi-system/src/main/resources/mapper/system/OrderLogMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/OrderLogMapper.xml @@ -17,6 +17,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + @@ -35,7 +39,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, oid, order_id, log_order_id, title, type, content, deposit, dep_paid, dep_pay_time, dep_log_id, price, paid, pay_time, log_id, worker_id, first_worker_id, give_up, worker_cost, reduction_price, is_pause, coupon_id, deduction, worker_log_id, created_at, updated_at, deleted_at from order_log + select id, oid, order_id, log_order_id,cj_money,cj_paid, title, type, content, deposit, dep_paid, dep_pay_time, dep_log_id, price, paid, pay_time, log_id, worker_id, first_worker_id, give_up, worker_cost, reduction_price, is_pause, coupon_id, deduction, worker_log_id, created_at, updated_at, deleted_at from order_log - select count(1) from order_data where uid = #{uid} and status=#{status} + select count(1) from order_data where uid = #{uid} and status !=4 + + insert into order_data diff --git a/ruoyi-system/src/main/resources/mapper/system/UserDemandQuotationMapper.xml b/ruoyi-system/src/main/resources/mapper/system/UserDemandQuotationMapper.xml index ee26aff..8bec94d 100644 --- a/ruoyi-system/src/main/resources/mapper/system/UserDemandQuotationMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/UserDemandQuotationMapper.xml @@ -11,6 +11,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + @@ -23,11 +26,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - where ptorderid = #{ptorderid} + where ptorderid = #{ptorderid} limit 1 diff --git a/ruoyi-system/src/main/resources/mapper/system/UsersMapper.xml b/ruoyi-system/src/main/resources/mapper/system/UsersMapper.xml index df4eace..15de8be 100644 --- a/ruoyi-system/src/main/resources/mapper/system/UsersMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/UsersMapper.xml @@ -191,6 +191,16 @@ and updated_at = #{updatedAt} + + and ( + + service_city_ids like concat('%"', #{area}, '"%') + + ) + + + and skill_ids like concat('%"', #{skill}, '"%') + order by id desc diff --git a/ruoyi-system/src/main/resources/mapper/system/UsersPayBeforMapper.xml b/ruoyi-system/src/main/resources/mapper/system/UsersPayBeforMapper.xml index 0be7e06..460e765 100644 --- a/ruoyi-system/src/main/resources/mapper/system/UsersPayBeforMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/UsersPayBeforMapper.xml @@ -19,6 +19,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + @@ -37,7 +39,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, uid, paytype,grouporderid, wxmoney,serviceid,servicetype,sku,addressid,maketime,attachments, yemoney, allmoney,membermoney, shopmoney, servicemoney, couponid, couponmoney, mtcode, mtmoney, type, orderid, oid, status, paytime, paycode from users_pay_befor + select id, uid, paytype,grouporderid,baojiaid, lastorderid,wxmoney,serviceid,servicetype,sku,addressid,maketime,attachments, yemoney, allmoney,membermoney, shopmoney, servicemoney, couponid, couponmoney, mtcode, mtmoney, type, orderid, oid, status, paytime, paycode from users_pay_befor