From 4d768ea54e6d7eaa2fe8e8ec505d025a19596266 Mon Sep 17 00:00:00 2001 From: "925116093-qq.com" <925116093@qq.com> Date: Mon, 16 Jun 2025 16:50:00 +0800 Subject: [PATCH] 202506161649 --- pom.xml | 7 + ruoyi-common/pom.xml | 8 +- .../system/controller/AppletController.java | 2447 +++++++++++------ .../controllerUtil/AppletControllerUtil.java | 65 +- .../system/controllerUtil/HttpsService.java | 75 + .../controllerUtil/OrderLogHandler.java | 1 + .../controllerUtil/PublicSendApiUtil.java | 131 + .../system/controllerUtil/WXsendMsgUtil.java | 100 + .../controllerUtil/YunXinPhoneUtilAPI.java | 187 ++ .../mapper/system/OrderLogMapper.xml | 2 +- .../mapper/system/QuoteMaterialMapper.xml | 2 +- 11 files changed, 2147 insertions(+), 878 deletions(-) create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/HttpsService.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/PublicSendApiUtil.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WXsendMsgUtil.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/YunXinPhoneUtilAPI.java diff --git a/pom.xml b/pom.xml index 70b8af9..d1bcd4f 100644 --- a/pom.xml +++ b/pom.xml @@ -163,6 +163,13 @@ ${velocity.version} + + + com.winnerlook + voice-sdk + 1.1.2 + + com.alibaba.fastjson2 diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index 3c2ca26..2cbe71f 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -58,7 +58,13 @@ com.fasterxml.jackson.core jackson-databind - + + + com.winnerlook + voice-sdk + 1.1.2 + + com.alibaba.fastjson2 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 d61fd08..35e7b4f 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 @@ -1,11 +1,12 @@ package com.ruoyi.system.controller; +import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.system.ControllerUtil.WechatApiUtil; +import com.ruoyi.system.ControllerUtil.*; import com.ruoyi.system.domain.*; import com.ruoyi.system.domain.AppleDoMain.OrderApple; import com.ruoyi.system.domain.AppleDoMain.AddressApple; @@ -20,19 +21,12 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.ArrayList; -import java.util.Date; +import java.util.*; import java.text.SimpleDateFormat; import java.util.stream.Collectors; import java.math.BigDecimal; import org.springframework.web.bind.annotation.RequestBody; -import com.ruoyi.system.ControllerUtil.AppletControllerUtil; -import com.ruoyi.system.ControllerUtil.AppletLoginUtil; -import com.ruoyi.system.ControllerUtil.PageUtil; import com.ruoyi.system.config.QiniuConfig; import com.ruoyi.system.utils.QiniuUploadUtil; @@ -43,6 +37,12 @@ import static com.ruoyi.common.utils.PageUtils.startPage; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.ruoyi.system.domain.WechatTransfer; +import com.ruoyi.common.utils.SecurityUtils; +import com.alibaba.fastjson2.JSONArray; +import com.ruoyi.system.domain.QuoteCraft; +import com.ruoyi.system.domain.QuoteType; +import com.ruoyi.system.domain.QuoteMaterialType; +import com.ruoyi.system.domain.QuoteMaterial; /** * 小程序控制器 @@ -86,7 +86,7 @@ public class AppletController extends BaseController { private IIntegralLogService integralLogService; @Autowired private IIntegralOrderService integralOrderService; - @Autowired + @Autowired private IIntegralProductService integralProductService; @Autowired private IIntegralOrderLogService integralOrderLogService; @@ -118,6 +118,14 @@ public class AppletController extends BaseController { private IWorkerMoneyLogService workerMoneyLogService; @Autowired private IWechatTransferService wechatTransferService; + @Autowired + private IQuoteCraftService quoteCraftService; + @Autowired + private IQuoteTypeService quoteTypeService; + @Autowired + private IQuoteMaterialTypeService quoteMaterialTypeService; + @Autowired + private IQuoteMaterialService quoteMaterialService; // /** @@ -319,10 +327,10 @@ public class AppletController extends BaseController { /** * 获取默认配置信息 - * + * * @param request HTTP请求对象 * @return 返回config_one配置的JSON对象 - * + *

* 功能说明: * - 获取名为"config_one"的系统配置 * - 将配置值解析为JSON对象并返回 @@ -334,7 +342,7 @@ public class AppletController extends BaseController { SiteConfig configQuery = new SiteConfig(); configQuery.setName("config_one"); List list = siteConfigService.selectSiteConfigList(configQuery); - + if (list != null && !list.isEmpty()) { JSONObject jsonObject = JSONObject.parseObject(list.get(0).getValue()); return AppletControllerUtil.appletSuccess(jsonObject); @@ -489,7 +497,7 @@ public class AppletController extends BaseController { // 6. 转换为AddressApple格式并返回 AddressApple addressApple = AddressApple.fromUserAddress(userAddress); - + return AppletControllerUtil.appletSuccess(addressApple); } catch (Exception e) { @@ -589,7 +597,7 @@ public class AppletController extends BaseController { // 8. 执行地址更新 int updateResult = userAddressService.updateUserAddress(updateAddress); - + if (updateResult > 0) { return AppletControllerUtil.appletSuccess("地址修改成功"); } else { @@ -603,7 +611,6 @@ public class AppletController extends BaseController { } - /** * 新增用户收货地址 * @@ -669,7 +676,7 @@ public class AppletController extends BaseController { // 6. 执行地址新增 int insertResult = userAddressService.insertUserAddress(newAddress); - + if (insertResult > 0) { return AppletControllerUtil.appletSuccess("地址新增成功"); } else { @@ -683,21 +690,20 @@ public class AppletController extends BaseController { } - /** * 售后返修申请接口 - * - * @param params 请求参数 包含order_id(订单ID)、phone(联系电话)、mark(返修原因备注) + * + * @param params 请求参数 包含order_id(订单ID)、phone(联系电话)、mark(返修原因备注) * @param request HTTP请求对象 * @return 返修申请结果 - * + *

* 功能说明: * - 验证用户登录状态和订单归属权 * - 检查订单状态是否允许申请售后 * - 处理售后返修申请逻辑 * - 更新订单状态为售后处理中 * - 记录返修申请信息和联系方式 - * + *

* 请求参数: * - order_id: 订单ID * - phone: 联系电话 @@ -776,15 +782,13 @@ public class AppletController extends BaseController { } - - /** * 获取用户服务订单列表 - * - * @param params 请求参数 包含page(页码)、limit(每页数量)、status(订单状态) + * + * @param params 请求参数 包含page(页码)、limit(每页数量)、status(订单状态) * @param request HTTP请求对象 * @return 返回分页的服务订单列表 - * + *

* 功能说明: * - 获取当前登录用户的服务类订单(type=1) * - 支持按订单状态筛选 @@ -823,7 +827,7 @@ public class AppletController extends BaseController { // 5. 查询用户地址列表 OrderApple order = new OrderApple(); - // order.setType(1); + // order.setType(1); order.setUid(user.getId()); if (StringUtils.isNotNull(status) && !"".equals(status)) { @@ -858,93 +862,93 @@ public class AppletController extends BaseController { /** * 获取用户商品订单列表 - * - * @param params 请求参数 包含page(页码)、limit(每页数量)、status(订单状态) + * + * @param params 请求参数 包含page(页码)、limit(每页数量)、status(订单状态) * @param request HTTP请求对象 * @return 返回分页的商品订单列表 - * + *

* 功能说明: * - 获取当前登录用户的商品类订单 * - 支持按订单状态筛选 * - 返回带分页信息的订单列表 * - 包含完整的商品信息和订单状态文本 - * + *

* 请求参数格式: * { - * "limit": 15, - * "page": 1, - * "status": "2" + * "limit": 15, + * "page": 1, + * "status": "2" * } - * + *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": { - * "current_page": 1, - * "data": [ - * { - * "id": 1, - * "order_id": "C307236827627129", - * "order_no": "C307236827627129", - * "status": 2, - * "status_text": "待发货", - * "total_price": "4.90", - * "num": 1, - * "pay_time": "2024-08-31 12:02:07", - * "created_at": "2024-08-31 12:02:07", - * "product": { - * "id": 86, - * "title": "长青泉·饮用天然泉水", - * "sub_title": "长青泉 1.5L*1瓶 4.9元", - * "icon": "https://img.huafurenjia.cn/images/...", - * "price": "4.90", - * "num": 1 - * } - * } - * ], - * "total": 3, - * "per_page": 15, - * "current_page": 1, - * "last_page": 1 - * } + * "code": 200, + * "msg": "OK", + * "data": { + * "current_page": 1, + * "data": [ + * { + * "id": 1, + * "order_id": "C307236827627129", + * "order_no": "C307236827627129", + * "status": 2, + * "status_text": "待发货", + * "total_price": "4.90", + * "num": 1, + * "pay_time": "2024-08-31 12:02:07", + * "created_at": "2024-08-31 12:02:07", + * "product": { + * "id": 86, + * "title": "长青泉·饮用天然泉水", + * "sub_title": "长青泉 1.5L*1瓶 4.9元", + * "icon": "https://img.huafurenjia.cn/images/...", + * "price": "4.90", + * "num": 1 + * } + * } + * ], + * "total": 3, + * "per_page": 15, + * "current_page": 1, + * "last_page": 1 + * } * } */ @PostMapping("/api/goods/order/lst") public AjaxResult getgoodsorderlst(@RequestBody Map params, HttpServletRequest request) { try { - int page = (int) params.get("page"); - int limit = (int) params.get("limit"); - String status = (String) params.get("status"); + int page = (int) params.get("page"); + int limit = (int) params.get("limit"); + String status = (String) params.get("status"); - // 1. 验证分页参数 - Map pageValidation = PageUtil.validatePageParams(page, limit); - if (!(Boolean) pageValidation.get("valid")) { + // 1. 验证分页参数 + Map pageValidation = PageUtil.validatePageParams(page, limit); + if (!(Boolean) pageValidation.get("valid")) { return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); - } + } - // 2. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { + // 2. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { return AppletControllerUtil.appletUnauthorized(); - } + } - // 3. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { + // 3. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { return AppletControllerUtil.appletWarning("用户信息获取失败"); - } + } - // 4. 设置分页参数 - PageHelper.startPage(page, limit); + // 4. 设置分页参数 + PageHelper.startPage(page, limit); // 5. 构建查询条件 GoodsOrder queryOrder = new GoodsOrder(); queryOrder.setUid(user.getId()); - if (StringUtils.isNotNull(status) && !"".equals(status)) { + if (StringUtils.isNotNull(status) && !"".equals(status)) { queryOrder.setStatus(Long.valueOf(status)); } @@ -957,7 +961,7 @@ public class AppletController extends BaseController { for (GoodsOrder order : orderList) { Map orderData = new HashMap<>(); - + // 订单基本信息 orderData.put("id", order.getId()); orderData.put("order_id", order.getOrderId()); @@ -967,14 +971,14 @@ public class AppletController extends BaseController { orderData.put("total_price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); orderData.put("num", order.getNum()); orderData.put("sku", order.getSku()); - + // 时间字段格式化 if (order.getPayTime() != null) { orderData.put("pay_time", sdf.format(order.getPayTime())); } else { orderData.put("pay_time", null); } - + if (order.getCreatedAt() != null) { orderData.put("created_at", sdf.format(order.getCreatedAt())); } else { @@ -992,7 +996,7 @@ public class AppletController extends BaseController { productInfo.put("icon", AppletControllerUtil.buildImageUrl(serviceGoods.getIcon())); productInfo.put("price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); productInfo.put("num", order.getNum()); - + orderData.put("product", productInfo); } } @@ -1021,7 +1025,7 @@ public class AppletController extends BaseController { /** * 获取订单状态文本 - * + * * @param status 订单状态 * @return 状态文本 */ @@ -1029,7 +1033,7 @@ public class AppletController extends BaseController { if (status == null) { return "未知状态"; } - + switch (status.intValue()) { case 1: return "待付款"; @@ -1055,10 +1059,10 @@ public class AppletController extends BaseController { /** * 用户登录验证接口 - * + * * @param request HTTP请求对象 * @return 返回用户信息或错误信息 - * + *

* 功能说明: * - 通过请求头中的token验证用户身份 * - 查询用户基本信息并返回 @@ -1112,7 +1116,7 @@ public class AppletController extends BaseController { } // 构建返回数据结构 - List> resultList = new java.util.ArrayList<>(); + List> resultList = new ArrayList<>(); if (cateId != null) { // 查询指定分类 @@ -1262,10 +1266,10 @@ public class AppletController extends BaseController { /** * 获取用户详细信息接口 - * + * * @param request HTTP请求对象 * @return 返回用户详细信息包含订单统计 - * + * * 功能说明: * - 通过token获取用户基本信息 * - 返回用户的服务订单和商品订单统计数据 @@ -1285,32 +1289,32 @@ public class AppletController extends BaseController { *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": { - * "id": 302, - * "name": "微信用户", - * "nickname": null, - * "phone": "18709185987", - * "avatar": "https://img.huafurenjia.cn/default/user_avatar.jpeg", - * "commission": 0, - * "created_at": "2024-08-31 12:02:07", - * "integral": 0, - * "openid": "oHIYB7DYezs7Myzn-yaF0amC3Bpc", - * "remember_token": "G88BSThmFCprrT0uTZ9ghDzW7QHj19CrwSwdq3e", - * "service_city_ids": ["2", "5", "7", "10", "11", "12", "13", "14", "15", "16", "17"], - * "skill_ids": ["19", "21", "25", "28", "35"], - * "status": 1, - * "total_integral": 100, - * "updated_at": "2025-06-11 10:35:44" - * } + * "code": 200, + * "msg": "OK", + * "data": { + * "id": 302, + * "name": "微信用户", + * "nickname": null, + * "phone": "18709185987", + * "avatar": "https://img.huafurenjia.cn/default/user_avatar.jpeg", + * "commission": 0, + * "created_at": "2024-08-31 12:02:07", + * "integral": 0, + * "openid": "oHIYB7DYezs7Myzn-yaF0amC3Bpc", + * "remember_token": "G88BSThmFCprrT0uTZ9ghDzW7QHj19CrwSwdq3e", + * "service_city_ids": ["2", "5", "7", "10", "11", "12", "13", "14", "15", "16", "17"], + * "skill_ids": ["19", "21", "25", "28", "35"], + * "status": 1, + * "total_integral": 100, + * "updated_at": "2025-06-11 10:35:44" + * } * } */ @GetMapping(value = "/api/user/info") public AjaxResult getUserInfo(HttpServletRequest request) { try { - Map order_num = new HashMap<>(); - Map goods_order_num = new HashMap<>(); + Map order_num = new HashMap<>(); + Map goods_order_num = new HashMap<>(); // 1. 验证用户登录状态 String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); @@ -1332,33 +1336,34 @@ public class AppletController extends BaseController { order_num.put("pending_service", 0); order_num.put("in_service", 0); order_num.put("other_status", 0); - userInfo.put("order_num",order_num); + userInfo.put("order_num", order_num); goods_order_num.put("pending_accept", 0); goods_order_num.put("pending_service", 3); goods_order_num.put("in_service", 0); goods_order_num.put("other_status", 0); - userInfo.put("goods_order_num",goods_order_num); + userInfo.put("goods_order_num", goods_order_num); // 新增tx_time字段 - java.util.List txTimeArr = new java.util.ArrayList<>(); + List txTimeArr = new ArrayList<>(); try { - com.ruoyi.system.domain.SiteConfig configQuery = new com.ruoyi.system.domain.SiteConfig(); + SiteConfig configQuery = new SiteConfig(); configQuery.setName("config_four"); - java.util.List configList = siteConfigService.selectSiteConfigList(configQuery); + List configList = siteConfigService.selectSiteConfigList(configQuery); if (configList != null && !configList.isEmpty()) { String configValue = configList.get(0).getValue(); if (configValue != null && !configValue.trim().isEmpty()) { - com.alibaba.fastjson2.JSONObject json = com.alibaba.fastjson2.JSONObject.parse(configValue); + JSONObject json = JSONObject.parse(configValue); if (json.containsKey("time")) { Object timeObj = json.get("time"); - if (timeObj instanceof java.util.List) { - txTimeArr = (java.util.List) timeObj; - } else if (timeObj instanceof com.alibaba.fastjson2.JSONArray) { - txTimeArr = ((com.alibaba.fastjson2.JSONArray) timeObj).toJavaList(Object.class); + if (timeObj instanceof List) { + txTimeArr = (List) timeObj; + } else if (timeObj instanceof JSONArray) { + txTimeArr = ((JSONArray) timeObj).toJavaList(Object.class); } } } } - } catch (Exception ignore) {} + } catch (Exception ignore) { + } userInfo.put("tx_time", txTimeArr); return AppletControllerUtil.appletSuccess(userInfo); @@ -1396,7 +1401,7 @@ public class AppletController extends BaseController { /** * 构建用户信息响应数据 - * + * * @param user 用户实体 * @return 格式化的用户信息 */ @@ -1410,7 +1415,7 @@ public class AppletController extends BaseController { userInfo.put("nickname", user.getNickname()); userInfo.put("phone", user.getPhone()); userInfo.put("password", null); // 密码不返回 - + // 头像处理 String avatar = user.getAvatar(); if (avatar != null && !avatar.isEmpty()) { @@ -1420,7 +1425,7 @@ public class AppletController extends BaseController { } // 其他业务字段 - userInfo.put("commission", user.getCommission().toString() != null ? user.getCommission().toString() : "0.00" ); + userInfo.put("commission", user.getCommission().toString() != null ? user.getCommission().toString() : "0.00"); userInfo.put("integral", user.getIntegral() != null ? user.getIntegral() : 0); userInfo.put("is_stop", user.getIsStop() != null ? user.getIsStop() : 1); userInfo.put("job_number", user.getJobNumber()); @@ -1473,7 +1478,7 @@ public class AppletController extends BaseController { /** * 修改用户基本信息接口 * - * @param params 请求参数,包含用户信息字段 + * @param params 请求参数,包含用户信息字段 * @param request HTTP请求对象 * @return 修改结果 *

@@ -1485,36 +1490,36 @@ public class AppletController extends BaseController { *

* 请求参数格式: * { - * "id": 302, - * "name": "微信用户P44455", - * "nickname": null, - * "phone": "18709185987", - * "avatar": "https://img.huafurenjia.cn/default/user_avatar.jpeg", - * "commission": 0, - * "integral": 0, - * "is_stop": 1, - * "job_number": null, - * "level": null, - * "login_status": 2, - * "margin": 0, - * "middle_auth": null, - * "openid": "oHIYB7DYezs7Myzn-yaF0amC3Bpc", - * "prohibit_time": null, - * "propose": "0.00", - * "service_city_ids": ["2", "5", "7", "10", "11", "12", "13", "14", "15", "16", "17"], - * "skill_ids": ["19", "21", "25", "20", "35"], - * "status": 1, - * "total_comm": 0, - * "total_integral": 100, - * "type": "1", - * "worker_time": null + * "id": 302, + * "name": "微信用户P44455", + * "nickname": null, + * "phone": "18709185987", + * "avatar": "https://img.huafurenjia.cn/default/user_avatar.jpeg", + * "commission": 0, + * "integral": 0, + * "is_stop": 1, + * "job_number": null, + * "level": null, + * "login_status": 2, + * "margin": 0, + * "middle_auth": null, + * "openid": "oHIYB7DYezs7Myzn-yaF0amC3Bpc", + * "prohibit_time": null, + * "propose": "0.00", + * "service_city_ids": ["2", "5", "7", "10", "11", "12", "13", "14", "15", "16", "17"], + * "skill_ids": ["19", "21", "25", "20", "35"], + * "status": 1, + * "total_comm": 0, + * "total_integral": 100, + * "type": "1", + * "worker_time": null * } *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": [] + * "code": 200, + * "msg": "OK", + * "data": [] * } */ @PostMapping(value = "/api/user/edit/info") @@ -1558,7 +1563,7 @@ public class AppletController extends BaseController { // 7. 执行用户信息更新 int updateResult = usersService.updateUsers(updateUser); - + if (updateResult > 0) { // 8. 返回成功响应(按照图片中的格式返回空数组) return AppletControllerUtil.appletSuccess(new ArrayList<>()); @@ -1574,7 +1579,7 @@ public class AppletController extends BaseController { /** * 从请求参数构建更新用户对象 - * + * * @param params 请求参数 * @param userId 用户ID * @return 用户更新对象 @@ -1587,11 +1592,11 @@ public class AppletController extends BaseController { if (params.get("name") != null) { updateUser.setName(params.get("name").toString().trim()); } - + if (params.get("nickname") != null && !params.get("nickname").toString().trim().isEmpty()) { updateUser.setNickname(params.get("nickname").toString().trim()); } - + if (params.get("phone") != null) { updateUser.setPhone(params.get("phone").toString().trim()); } @@ -1609,22 +1614,22 @@ public class AppletController extends BaseController { if (params.get("integral") != null) { updateUser.setIntegral(parseToLongForEdit(params.get("integral"))); } - + if (params.get("is_stop") != null) { Integer isStop = parseToIntegerForEdit(params.get("is_stop")); updateUser.setIsStop(isStop); } - + if (params.get("login_status") != null) { Integer loginStatus = parseToIntegerForEdit(params.get("login_status")); updateUser.setLoginStatus(loginStatus); } - + if (params.get("status") != null) { Integer status = parseToIntegerForEdit(params.get("status")); updateUser.setStatus(status); } - + if (params.get("total_integral") != null) { updateUser.setTotalIntegral(parseToLongForEdit(params.get("total_integral"))); } @@ -1634,28 +1639,28 @@ public class AppletController extends BaseController { Integer jobNumber = parseToIntegerForEdit(params.get("job_number")); updateUser.setJobNumber(jobNumber); } - + if (params.get("level") != null && !params.get("level").toString().trim().isEmpty()) { Integer level = parseToIntegerForEdit(params.get("level")); updateUser.setLevel(level); } - + if (params.get("middle_auth") != null && !params.get("middle_auth").toString().trim().isEmpty()) { Integer middleAuth = parseToIntegerForEdit(params.get("middle_auth")); updateUser.setMiddleAuth(middleAuth); } - + if (params.get("propose") != null) { // propose字段是BigDecimal类型,需要转换 String proposeStr = params.get("propose").toString().trim(); try { - java.math.BigDecimal propose = new java.math.BigDecimal(proposeStr); + BigDecimal propose = new BigDecimal(proposeStr); updateUser.setPropose(propose); } catch (NumberFormatException e) { // 忽略格式错误,保持原值 } } - + if (params.get("type") != null) { // type字段是String类型 updateUser.setType(params.get("type").toString().trim()); @@ -1688,7 +1693,7 @@ public class AppletController extends BaseController { */ private Long parseToLongForEdit(Object value) { if (value == null) return null; - + if (value instanceof Integer) { return ((Integer) value).longValue(); } else if (value instanceof Long) { @@ -1708,7 +1713,7 @@ public class AppletController extends BaseController { */ private Integer parseToIntegerForEdit(Object value) { if (value == null) return null; - + if (value instanceof Integer) { return (Integer) value; } else if (value instanceof Long) { @@ -1725,7 +1730,7 @@ public class AppletController extends BaseController { /** * 验证用户编辑参数 - * + * * @param user 用户对象 * @return 验证结果,null表示验证通过 */ @@ -1822,30 +1827,30 @@ public class AppletController extends BaseController { */ /** * 手机号登录接口(未完整实现) - * + * * @param params 包含code和phone参数 * @param request HTTP请求对象 * @return 登录结果 - * + * * 功能说明: * - 预留的手机号登录接口 * - 当前实现不完整,需要补充验证逻辑 * - 用于处理手机号码验证登录 */ - @GetMapping(value = "/user/phone/login") - public AjaxResult getUserByPhone(@RequestBody Map params, HttpServletRequest request) { - String code = (String) params.get("code"); - String usercode = (String) params.get("phone"); - - if (code == null) { - - } - if (usercode == null) { - - } - return success(); - - } +// @GetMapping(value = "/user/phone/login") +// public AjaxResult getUserByPhone(@RequestBody Map params, HttpServletRequest request) { +// String code = (String) params.get("code"); +// String usercode = (String) params.get("phone"); +// +// if (code == null) { +// +// } +// if (usercode == null) { +// +// } +// return success(); +// +// } /** @@ -1892,7 +1897,7 @@ public class AppletController extends BaseController { } // 2. 调用微信支付统一下单 - Map payResult = com.ruoyi.system.ControllerUtil.WechatPayUtil.unifiedOrder(params); + Map payResult = WechatPayUtil.unifiedOrder(params); // 3. 返回结果 boolean success = (Boolean) payResult.get("success"); @@ -1925,7 +1930,7 @@ public class AppletController extends BaseController { } // 2. 查询订单状态 - Map queryResult = com.ruoyi.system.ControllerUtil.WechatPayUtil.queryOrder(orderNo, null); + Map queryResult = WechatPayUtil.queryOrder(orderNo, null); // 3. 返回结果 boolean success = (Boolean) queryResult.get("success"); @@ -1969,7 +1974,7 @@ public class AppletController extends BaseController { } // 2. 创建代付订单 - Map payForResult = com.ruoyi.system.ControllerUtil.WechatPayUtil.createPayForOrder(params); + Map payForResult = WechatPayUtil.createPayForOrder(params); // 3. 返回结果 boolean success = (Boolean) payForResult.get("success"); @@ -1997,7 +2002,7 @@ public class AppletController extends BaseController { public String handlePayNotify(HttpServletRequest request) { try { // 1. 处理支付回调 - Map notifyResult = com.ruoyi.system.ControllerUtil.WechatPayUtil.handlePayNotify(request); + Map notifyResult = WechatPayUtil.handlePayNotify(request); // 2. 获取支付信息 boolean success = (Boolean) notifyResult.get("success"); @@ -2049,7 +2054,7 @@ public class AppletController extends BaseController { } // 2. 申请退款 - Map refundResult = com.ruoyi.system.ControllerUtil.WechatPayUtil.refund(params); + Map refundResult = WechatPayUtil.refund(params); // 3. 返回结果 boolean success = (Boolean) refundResult.get("success"); @@ -2090,7 +2095,7 @@ public class AppletController extends BaseController { } // 2. 企业付款 - Map transferResult = com.ruoyi.system.ControllerUtil.WechatPayUtil.transferToUser(params); + Map transferResult = WechatPayUtil.transferToUser(params); // 3. 返回结果 boolean success = (Boolean) transferResult.get("success"); @@ -2106,14 +2111,13 @@ public class AppletController extends BaseController { } - /** * 查询用户售后返修列表 - * - * @param params 请求参数,包含page(页码)、limit(每页数量) + * + * @param params 请求参数,包含page(页码)、limit(每页数量) * @param request HTTP请求对象 * @return 返回分页的售后返修列表 - * + *

* 功能说明: * - 获取当前登录用户的售后返修记录 * - 支持分页查询 @@ -2126,7 +2130,7 @@ public class AppletController extends BaseController { // 1. 获取分页参数 int page = params.get("page") != null ? (Integer) params.get("page") : 1; int limit = params.get("limit") != null ? (Integer) params.get("limit") : 15; - int status =(Integer) params.get("status"); + int status = (Integer) params.get("status"); // 2. 验证分页参数 Map pageValidation = PageUtil.validatePageParams(page, limit); @@ -2178,17 +2182,17 @@ public class AppletController extends BaseController { prevLink.put("active", false); Map nextLink = new HashMap<>(); - nextLink.put("url", pageInfo.isHasNextPage() ? - "https://www.huafurenjia.cn/api/service/order/rework/lst?page=" + pageInfo.getNextPage() : null); + nextLink.put("url", pageInfo.isHasNextPage() ? + "https://www.huafurenjia.cn/api/service/order/rework/lst?page=" + pageInfo.getNextPage() : null); nextLink.put("label", "Next »"); nextLink.put("active", false); responseData.put("links", new Object[]{prevLink, nextLink}); - responseData.put("next_page_url", pageInfo.isHasNextPage() ? - "https://www.huafurenjia.cn/api/service/order/rework/lst?page=" + pageInfo.getNextPage() : null); + responseData.put("next_page_url", pageInfo.isHasNextPage() ? + "https://www.huafurenjia.cn/api/service/order/rework/lst?page=" + pageInfo.getNextPage() : null); responseData.put("path", "https://www.huafurenjia.cn/api/service/order/rework/lst"); - responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? - "https://www.huafurenjia.cn/api/service/order/rework/lst?page=" + pageInfo.getPrePage() : null); + responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? + "https://www.huafurenjia.cn/api/service/order/rework/lst?page=" + pageInfo.getPrePage() : null); return success(responseData); @@ -2200,32 +2204,32 @@ public class AppletController extends BaseController { /** * 合作申请提交接口 - * - * @param params 请求参数,包含company(公司名称)、name(姓名)、phone(电话)、address(地址)、info(合作意向) + * + * @param params 请求参数,包含company(公司名称)、name(姓名)、phone(电话)、address(地址)、info(合作意向) * @param request HTTP请求对象 * @return 申请提交结果 - * + *

* 功能说明: * - 验证用户登录状态(可选) * - 接收合作申请表单数据 * - 验证必填字段 * - 保存合作申请记录 * - 设置默认状态为待处理 - * + *

* 请求参数格式: * { - * "company": "河南公司", - * "name": "王令兵", - * "phone": "15002954234", - * "address": "来宾", - * "info": "情感咨询" + * "company": "河南公司", + * "name": "王令兵", + * "phone": "15002954234", + * "address": "来宾", + * "info": "情感咨询" * } - * + *

* 返回格式: * { - * "code": 200, - * "msg": "操作成功", - * "data": "合作申请提交成功,我们会尽快联系您" + * "code": 200, + * "msg": "操作成功", + * "data": "合作申请提交成功,我们会尽快联系您" * } */ @PostMapping("/api/form/cooperate") @@ -2271,7 +2275,7 @@ public class AppletController extends BaseController { // 3. 获取用户信息(可选,不强制要求登录) Long uid = null; String uname = null; - + String token = request.getHeader("token"); if (StringUtils.isNotEmpty(token)) { Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); @@ -2295,7 +2299,7 @@ public class AppletController extends BaseController { // 6. 保存合作申请记录 int insertResult = cooperateService.insertCooperate(cooperate); - + if (insertResult > 0) { return success("合作申请提交成功,我们会尽快联系您"); } else { @@ -2310,8 +2314,8 @@ public class AppletController extends BaseController { /** * 查询用户优惠券列表 - * - * @param params 请求参数,包含status(优惠券状态)、product_id(指定商品ID)、price(最低价格) + * + * @param params 请求参数,包含status(优惠券状态)、product_id(指定商品ID)、price(最低价格) * @param request HTTP请求对象 * @return 返回用户优惠券列表 */ @@ -2375,11 +2379,11 @@ public class AppletController extends BaseController { couponsQuery.setStatus(1L); // 启用状态 couponsQuery.setType(2L); // 手动领取类型 List availableCoupons = couponsService.selectCouponsList(couponsQuery); - + for (Coupons coupon : availableCoupons) { // 检查剩余数量大于0且用户可领取 - if (coupon.getCount() != null && coupon.getCount() > 0 && - isCouponAvailableToReceive(coupon, user.getId(), currentTime)) { + if (coupon.getCount() != null && coupon.getCount() > 0 && + isCouponAvailableToReceive(coupon, user.getId(), currentTime)) { // 创建一个临时的CouponUser对象,包含完整的优惠券信息 CouponUser tempCouponUser = new CouponUser(); tempCouponUser.setCouponId(coupon.getId()); @@ -2391,7 +2395,7 @@ public class AppletController extends BaseController { tempCouponUser.setCateId(coupon.getCateId()); tempCouponUser.setProductId(coupon.getProductId()); tempCouponUser.setReceiveType(coupon.getReceiveType() != null ? coupon.getReceiveType().toString() : "1"); - + // 设置有效期 if (coupon.getCouponTime() != null) { // 如果有固定的有效期天数,计算失效时间 @@ -2401,7 +2405,7 @@ public class AppletController extends BaseController { // 如果有结束时间,使用结束时间作为失效时间 tempCouponUser.setLoseTime(String.valueOf(coupon.getEndTime())); } - + filteredList.add(tempCouponUser); } } @@ -2410,8 +2414,8 @@ public class AppletController extends BaseController { // 6. 商品ID筛选 if (productId != null) { filteredList = filteredList.stream() - .filter(coupon -> productId.equals(coupon.getProductId())) - .collect(Collectors.toList()); + .filter(coupon -> productId.equals(coupon.getProductId())) + .collect(Collectors.toList()); } // 7. 价格筛选 @@ -2419,7 +2423,7 @@ public class AppletController extends BaseController { // 8. 使用工具类处理数据格式化 List> resultList = AppletControllerUtil.buildCouponUserList( - priceFilteredList, serviceCateService); + priceFilteredList, serviceCateService); return success(resultList); @@ -2434,7 +2438,7 @@ public class AppletController extends BaseController { */ private Long parseParamToLong(Object param, String errorMsg) { if (param == null) return null; - + if (param instanceof Integer) { return ((Integer) param).longValue(); } else if (param instanceof String && !((String) param).trim().isEmpty()) { @@ -2452,7 +2456,7 @@ public class AppletController extends BaseController { */ private Integer parseParamToInteger(Object param, String errorMsg) { if (param == null) return null; - + if (param instanceof Integer) { return (Integer) param; } else if (param instanceof String && !((String) param).trim().isEmpty()) { @@ -2467,8 +2471,8 @@ public class AppletController extends BaseController { /** * 查询用户积分日志列表 - * - * @param params 请求参数,包含limit(每页数量)、page(页码) + * + * @param params 请求参数,包含limit(每页数量)、page(页码) * @param request HTTP请求对象 * @return 返回分页的积分日志列表 */ @@ -2512,7 +2516,7 @@ public class AppletController extends BaseController { // 8. 使用工具类处理数据格式化 List> formattedLogList = AppletControllerUtil.buildIntegralLogList(integralLogList); Map paginationData = AppletControllerUtil.buildPaginationResponse( - pageInfo, formattedLogList, "https://www.huafurenjia.cn/api/integral/user/log/lst"); + pageInfo, formattedLogList, "https://www.huafurenjia.cn/api/integral/user/log/lst"); Map userData = AppletControllerUtil.buildUserDataInfo(user); // 9. 构建最终返回数据结构 @@ -2531,8 +2535,8 @@ public class AppletController extends BaseController { /** * 查询用户积分商城订单列表 - * - * @param params 请求参数,包含limit(每页数量)、page(页码)、status(订单状态) + * + * @param params 请求参数,包含limit(每页数量)、page(页码)、status(订单状态) * @param request HTTP请求对象 * @return 返回分页的积分商城订单列表 */ @@ -2579,9 +2583,9 @@ public class AppletController extends BaseController { // 8. 使用工具类处理数据格式化 List> formattedOrderList = AppletControllerUtil.buildIntegralOrderList( - integralOrderList, integralProductService); + integralOrderList, integralProductService); Map responseData = AppletControllerUtil.buildPaginationResponse( - pageInfo, formattedOrderList, "https://www.huafurenjia.cn/api/integral/user/order"); + pageInfo, formattedOrderList, "https://www.huafurenjia.cn/api/integral/user/order"); return success(responseData); @@ -2593,8 +2597,8 @@ public class AppletController extends BaseController { /** * 查询积分订单详情 - * - * @param id 订单ID + * + * @param id 订单ID * @param request HTTP请求对象 * @return 返回积分订单详细信息 */ @@ -2632,7 +2636,7 @@ public class AppletController extends BaseController { // 6. 使用工具类构建订单详情数据 Map orderData = AppletControllerUtil.buildIntegralOrderDetail( - integralOrder, integralProductService, integralOrderLogService); + integralOrder, integralProductService, integralOrderLogService); return success(orderData); @@ -2644,25 +2648,25 @@ public class AppletController extends BaseController { /** * 查询积分商品分类列表 - * + * * @param request HTTP请求对象 * @return 返回积分商品分类列表 - * + *

* 功能说明: * - 获取所有启用状态的积分商品分类 * - 返回分类的ID和名称 * - 用于积分商城分类展示 - * + *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": [ - * { - * "id": 4, - * "title": "家清商品" - * } - * ] + * "code": 200, + * "msg": "OK", + * "data": [ + * { + * "id": 4, + * "title": "家清商品" + * } + * ] * } */ @GetMapping("/api/integral/product/cate") @@ -2694,47 +2698,47 @@ public class AppletController extends BaseController { /** * 查询积分商品列表 - * - * @param params 请求参数,包含limit(每页数量)、page(页码)、type(分类ID) + * + * @param params 请求参数,包含limit(每页数量)、page(页码)、type(分类ID) * @param request HTTP请求对象 * @return 返回分页的积分商品列表 - * + *

* 功能说明: * - 获取积分商品列表,支持分页 * - 支持按分类筛选 * - 返回商品详细信息和分页信息 * - 按创建时间倒序排列 - * + *

* 请求参数格式: * { - * "limit": 15, // 每页显示数量 - * "page": 1, // 页码 - * "type": "1" // 分类ID(可选) + * "limit": 15, // 每页显示数量 + * "page": 1, // 页码 + * "type": "1" // 分类ID(可选) * } - * + *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": { - * "current_page": 1, - * "data": [ - * { - * "id": 7, - * "title": "全无码食品火锅", - * "image": "https://img.huafurenjia.cn/images/cb03ed40d32282bb47235568219ca26.png", - * "num": 11, - * "price": "53.90", - * "sales": 568, - * "tags": [] - * } - * ], - * "from": 1, - * "last_page": 1, - * "per_page": 15, - * "to": 2, - * "total": 2 - * } + * "code": 200, + * "msg": "OK", + * "data": { + * "current_page": 1, + * "data": [ + * { + * "id": 7, + * "title": "全无码食品火锅", + * "image": "https://img.huafurenjia.cn/images/cb03ed40d32282bb47235568219ca26.png", + * "num": 11, + * "price": "53.90", + * "sales": 568, + * "tags": [] + * } + * ], + * "from": 1, + * "last_page": 1, + * "per_page": 15, + * "to": 2, + * "total": 2 + * } * } */ @PostMapping("/api/integral/product/lst") @@ -2757,7 +2761,7 @@ public class AppletController extends BaseController { // 4. 构建查询条件 IntegralProduct integralProductQuery = new IntegralProduct(); integralProductQuery.setStatus(1L); // 只查询启用状态的商品 - + // 如果有分类参数,添加分类筛选 if (type != null && !type.trim().isEmpty()) { try { @@ -2777,7 +2781,7 @@ public class AppletController extends BaseController { // 7. 使用工具类处理数据格式化 List> formattedProductList = AppletControllerUtil.buildIntegralProductList(integralProductList); Map responseData = AppletControllerUtil.buildPaginationResponse( - pageInfo, formattedProductList, "https://www.huafurenjia.cn/api/integral/product/lst"); + pageInfo, formattedProductList, "https://www.huafurenjia.cn/api/integral/product/lst"); return success(responseData); @@ -2789,40 +2793,40 @@ public class AppletController extends BaseController { /** * 查询积分商品详情 - * - * @param id 商品ID + * + * @param id 商品ID * @param request HTTP请求对象 * @return 返回积分商品详细信息 - * + *

* 功能说明: * - 根据商品ID获取积分商品详细信息 * - 返回完整的商品数据包括图片、规格、库存等 * - 自动处理图片URL添加CDN前缀 * - 格式化轮播图和标签为数组格式 - * + *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": { - * "id": 7, - * "title": "全无码食品火锅", - * "cate_id": 4, - * "contetnt": "

", - * "created_at": "2024-07-17 14:59:44", - * "image": "https://img.huafurenjia.cn/images/cb03ed40d32282bb47235568219ca26.png", - * "images": ["https://img.huafurenjia.cn/images/..."], - * "num": 11, - * "price": "53.90", - * "sales": 568, - * "sku": {"type": "single"}, - * "sku_type": 1, - * "sort": 1, - * "status": 1, - * "stock": 120, - * "tags": [], - * "updated_at": "2024-08-16 15:03:33" - * } + * "code": 200, + * "msg": "OK", + * "data": { + * "id": 7, + * "title": "全无码食品火锅", + * "cate_id": 4, + * "contetnt": "

", + * "created_at": "2024-07-17 14:59:44", + * "image": "https://img.huafurenjia.cn/images/cb03ed40d32282bb47235568219ca26.png", + * "images": ["https://img.huafurenjia.cn/images/..."], + * "num": 11, + * "price": "53.90", + * "sales": 568, + * "sku": {"type": "single"}, + * "sku_type": 1, + * "sort": 1, + * "status": 1, + * "stock": 120, + * "tags": [], + * "updated_at": "2024-08-16 15:03:33" + * } * } */ @GetMapping("/api/integral/product/info/{id}") @@ -2929,7 +2933,7 @@ public class AppletController extends BaseController { // 4. 转换为AddressApple格式并返回 AddressApple addressApple = AddressApple.fromUserAddress(targetAddress); - + return success(addressApple); } catch (Exception e) { @@ -2952,7 +2956,7 @@ public class AppletController extends BaseController { *

* 消息模板说明: * - pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M: 积分相关通知模板 - * - YKnuTCAD-oEEhNGoI3LUVkAqNsykOMTcyrf71S9vev8: 操作成功通知模板 + * - YKnuTCAD-oEEhNGoI3LUVkAqNsykOMTcyrf71S9vev8: 操作成功通知模板 * - 5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU: 工作人员通知模板 *

* 返回格式: @@ -3000,7 +3004,7 @@ public class AppletController extends BaseController { /** * 用户订阅消息授权接口 * - * @param params 请求参数,包含tmplIds(模板ID数组) + * @param params 请求参数,包含tmplIds(模板ID数组) * @param request HTTP请求对象 * @return 授权结果 *

@@ -3069,7 +3073,7 @@ public class AppletController extends BaseController { /** * 积分商品兑换接口 * - * @param params 请求参数,包含id(积分商品ID)、address_id(收货地址ID)、num(购买数量)、sku(规格)、mark(备注) + * @param params 请求参数,包含id(积分商品ID)、address_id(收货地址ID)、num(购买数量)、sku(规格)、mark(备注) * @param request HTTP请求对象 * @return 兑换结果 *

@@ -3149,7 +3153,7 @@ public class AppletController extends BaseController { } Long totalIntegral = product.getNum() * num; - + // 7. 验证用户积分是否足够 if (!AppletControllerUtil.checkUserIntegralSufficient(user, totalIntegral)) { // 积分不足,返回422状态码 @@ -3159,7 +3163,7 @@ public class AppletController extends BaseController { // 8. 创建积分订单 IntegralOrder order = AppletControllerUtil.buildIntegralOrder(params, user, product, address); int orderResult = integralOrderService.insertIntegralOrder(order); - + if (orderResult <= 0) { return error("订单创建失败"); } @@ -3169,14 +3173,14 @@ public class AppletController extends BaseController { updateUser.setId(user.getId()); updateUser.setIntegral(user.getIntegral() - totalIntegral); int updateResult = usersService.updateUsers(updateUser); - + if (updateResult <= 0) { return error("扣除积分失败"); } // 10. 记录积分变动日志 IntegralLog integralLog = AppletControllerUtil.buildIntegralLog( - user, -totalIntegral, order.getOrderId(), product.getTitle()); + user, -totalIntegral, order.getOrderId(), product.getTitle()); integralLogService.insertIntegralLog(integralLog); // 11. 更新商品库存(如果有库存管理) @@ -3198,7 +3202,7 @@ public class AppletController extends BaseController { /** * 获取服务订单详情 * - * @param id 订单ID + * @param id 订单ID * @param request HTTP请求对象 * @return 服务订单详细信息 *

@@ -3210,20 +3214,20 @@ public class AppletController extends BaseController { *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": { - * // 订单基本信息 - * "id": 260, - * "order_id": "B831770908583777", - * // ... 其他订单字段 - * "log": [ - * // 订单日志数组 - * ], - * "product": { - * // 商品信息 - * } - * } + * "code": 200, + * "msg": "OK", + * "data": { + * // 订单基本信息 + * "id": 260, + * "order_id": "B831770908583777", + * // ... 其他订单字段 + * "log": [ + * // 订单日志数组 + * ], + * "product": { + * // 商品信息 + * } + * } * } */ @GetMapping("/api/service/order/info/{id}") @@ -3260,7 +3264,7 @@ public class AppletController extends BaseController { // 6. 使用工具类构建订单详情数据 Map orderDetail = AppletControllerUtil.buildServiceOrderDetail( - order, orderLogService, serviceGoodsService); + order, orderLogService, serviceGoodsService); return AppletControllerUtil.appletSuccess(orderDetail); @@ -3284,15 +3288,15 @@ public class AppletController extends BaseController { *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": [ - * { - * "id": 1, - * "title": "西安市", - * "pid": 0 - * } - * ] + * "code": 200, + * "msg": "OK", + * "data": [ + * { + * "id": 1, + * "title": "西安市", + * "pid": 0 + * } + * ] * } */ @GetMapping(value = "/api/public/diy/city") @@ -3300,7 +3304,7 @@ public class AppletController extends BaseController { try { // 查询所有城市列表 List cityList = diyCityService.selectDiyCityList(null); - + // 构建树状结构数据 List> resultList = AppletControllerUtil.buildCityTree(cityList); @@ -3325,18 +3329,18 @@ public class AppletController extends BaseController { *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": [ - * { - * "id": 47, - * "title": "燃气灶维修", - * "sort": 43, - * "status": 1, - * "created_at": "2025-04-10 09:36:35", - * "updated_at": "2025-04-10 09:36:35" - * } - * ] + * "code": 200, + * "msg": "OK", + * "data": [ + * { + * "id": 47, + * "title": "燃气灶维修", + * "sort": 43, + * "status": 1, + * "created_at": "2025-04-10 09:36:35", + * "updated_at": "2025-04-10 09:36:35" + * } + * ] * } */ @GetMapping(value = "/api/form/skill/lst") @@ -3344,31 +3348,31 @@ public class AppletController extends BaseController { try { // 查询技能列表 List skillList = siteSkillService.selectSiteSkillList(null); - + // 构建返回数据格式 List> resultList = new ArrayList<>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - + for (SiteSkill skill : skillList) { Map skillData = new HashMap<>(); skillData.put("id", skill.getId()); skillData.put("title", skill.getTitle()); skillData.put("sort", skill.getSort()); skillData.put("status", skill.getStatus()); - + // 格式化时间字段 if (skill.getCreatedAt() != null) { skillData.put("created_at", sdf.format(skill.getCreatedAt())); } else { skillData.put("created_at", null); } - + if (skill.getUpdatedAt() != null) { skillData.put("updated_at", sdf.format(skill.getUpdatedAt())); } else { skillData.put("updated_at", null); } - + resultList.add(skillData); } @@ -3382,7 +3386,7 @@ public class AppletController extends BaseController { /** * 文件上传接口 * - * @param file 上传的文件 + * @param file 上传的文件 * @param request HTTP请求对象 * @return 上传结果 *

@@ -3398,12 +3402,12 @@ public class AppletController extends BaseController { *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": { - * "path": "images/2025-06-11/zvsZHNoFYlFkMCePQs1624hKwBSCozL9XM7pEUmo.jpg", - * "full_path": "http://img.huafurenjia.cn/images/2025-06-11/zvsZHNoFYlFkMCePQs1624hKwBSCozL9XM7pEUmo.jpg" - * } + * "code": 200, + * "msg": "OK", + * "data": { + * "path": "images/2025-06-11/zvsZHNoFYlFkMCePQs1624hKwBSCozL9XM7pEUmo.jpg", + * "full_path": "http://img.huafurenjia.cn/images/2025-06-11/zvsZHNoFYlFkMCePQs1624hKwBSCozL9XM7pEUmo.jpg" + * } * } */ @PostMapping(value = "/api/public/upload/file") @@ -3416,12 +3420,12 @@ public class AppletController extends BaseController { // 2. 验证文件格式 String[] allowedTypes = { - // 图片格式 - "jpg", "jpeg", "png", "gif", "bmp", "webp", "svg", - // 文档格式 - "doc", "docx", "xls", "xlsx", "ppt", "pptx", "txt", "pdf" + // 图片格式 + "jpg", "jpeg", "png", "gif", "bmp", "webp", "svg", + // 文档格式 + "doc", "docx", "xls", "xlsx", "ppt", "pptx", "txt", "pdf" }; - + if (!QiniuUploadUtil.isValidFileType(file.getOriginalFilename(), allowedTypes)) { return AppletControllerUtil.appletWarning("不支持的文件格式"); } @@ -3460,11 +3464,10 @@ public class AppletController extends BaseController { } - /** * 获取服务预约时间段接口 * - * @param params 请求参数,包含day(预约日期) + * @param params 请求参数,包含day(预约日期) * @param request HTTP请求对象 * @return 时间段列表数据 *

@@ -3476,21 +3479,21 @@ public class AppletController extends BaseController { *

* 请求参数格式: * { - * "day": "2025-06-11" + * "day": "2025-06-11" * } *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": [ - * { - * "click": true, - * "value": "8:00-10:00", - * "prove": "可预约", - * "residue_num": 99 - * } - * ] + * "code": 200, + * "msg": "OK", + * "data": [ + * { + * "click": true, + * "value": "8:00-10:00", + * "prove": "可预约", + * "residue_num": 99 + * } + * ] * } */ @PostMapping(value = "/api/service/make/time") @@ -3528,21 +3531,10 @@ public class AppletController extends BaseController { } - - - - - - - - - - - /** * 添加商品到购物车接口 * - * @param params 请求参数,包含good_id(商品ID)、sku(商品规格) + * @param params 请求参数,包含good_id(商品ID)、sku(商品规格) * @param request HTTP请求对象 * @return 添加结果 *

@@ -3554,15 +3546,15 @@ public class AppletController extends BaseController { *

* 请求参数格式: * { - * "good_id": 86, - * "sku": "" + * "good_id": 86, + * "sku": "" * } *

* 返回格式: * { - * "code": 200, - * "msg": "操作成功", - * "data": "商品已添加到购物车" + * "code": 200, + * "msg": "操作成功", + * "data": "商品已添加到购物车" * } */ @PostMapping(value = "/api/cart/add") @@ -3610,14 +3602,14 @@ public class AppletController extends BaseController { // return AppletControllerUtil.appletWarning("商品已下架或不可用"); // } - // 7. 检查商品库存(如果有库存管理) + // 7. 检查商品库存(如果有库存管理) // if (serviceGoods.getStock() != null && serviceGoods.getStock() <= 0L) { // return AppletControllerUtil.appletWarning("商品库存不足"); // } // 8. 检查购物车中是否已存在该商品 GoodsCart existingCartItem = AppletControllerUtil.findExistingCartItem(user.getId(), goodId, sku, goodsCartService); - + if (existingCartItem != null) { // 如果已存在,更新数量 return AppletControllerUtil.updateCartItemQuantity(existingCartItem, serviceGoods, goodsCartService); @@ -3633,15 +3625,10 @@ public class AppletController extends BaseController { } - - - - - /** * 查询购物车列表接口 * - * @param params 请求参数,包含limit(每页数量)、page(页码) + * @param params 请求参数,包含limit(每页数量)、page(页码) * @param request HTTP请求对象 * @return 购物车列表数据 *

@@ -3653,41 +3640,41 @@ public class AppletController extends BaseController { *

* 请求参数格式: * { - * "limit": 15, - * "page": 1 + * "limit": 15, + * "page": 1 * } *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": { - * "current_page": 1, - * "data": [ - * { - * "id": 248, - * "uid": 302, - * "good_id": 86, - * "good_num": 1, - * "sku": null, - * "created_at": "2025-06-11 10:05:37", - * "updated_at": "2025-06-11 10:05:37", - * "good": { - * "id": 86, - * "title": "马桶漏水", - * "price": "0.00", - * "icon": "https://img.huafurenjia.cn/images/...", - * "stock": 232, - * "type": 1 - * } - * } - * ], - * "from": 1, - * "last_page": 1, - * "per_page": 15, - * "to": 1, - * "total": 1 - * } + * "code": 200, + * "msg": "OK", + * "data": { + * "current_page": 1, + * "data": [ + * { + * "id": 248, + * "uid": 302, + * "good_id": 86, + * "good_num": 1, + * "sku": null, + * "created_at": "2025-06-11 10:05:37", + * "updated_at": "2025-06-11 10:05:37", + * "good": { + * "id": 86, + * "title": "马桶漏水", + * "price": "0.00", + * "icon": "https://img.huafurenjia.cn/images/...", + * "stock": 232, + * "type": 1 + * } + * } + * ], + * "from": 1, + * "last_page": 1, + * "per_page": 15, + * "to": 1, + * "total": 1 + * } * } */ @PostMapping(value = "/api/cart/lst") @@ -3732,19 +3719,19 @@ public class AppletController extends BaseController { for (GoodsCart cart : cartList) { Map cartData = new HashMap<>(); - + // 基本购物车信息 cartData.put("id", cart.getId()); cartData.put("uid", cart.getUid()); cartData.put("good_id", cart.getGoodId()); cartData.put("good_num", cart.getGoodNum()); cartData.put("sku", cart.getSku()); - + // 格式化时间字段 - cartData.put("created_at", cart.getCreatedAt() != null ? - sdf.format(cart.getCreatedAt()) : null); - cartData.put("updated_at", cart.getUpdatedAt() != null ? - sdf.format(cart.getUpdatedAt()) : null); + cartData.put("created_at", cart.getCreatedAt() != null ? + sdf.format(cart.getCreatedAt()) : null); + cartData.put("updated_at", cart.getUpdatedAt() != null ? + sdf.format(cart.getUpdatedAt()) : null); // 查询并添加商品详细信息 Map goodInfo = AppletControllerUtil.getGoodDetailForCart(cart.getGoodId(), serviceGoodsService); @@ -3770,24 +3757,24 @@ public class AppletController extends BaseController { String baseUrl = "https://www.huafurenjia.cn/api/cart/lst"; responseData.put("first_page_url", baseUrl + "?page=1"); responseData.put("last_page_url", baseUrl + "?page=" + pageInfo.getPages()); - responseData.put("next_page_url", pageInfo.isHasNextPage() ? - baseUrl + "?page=" + pageInfo.getNextPage() : null); - responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? - baseUrl + "?page=" + pageInfo.getPrePage() : null); + responseData.put("next_page_url", pageInfo.isHasNextPage() ? + baseUrl + "?page=" + pageInfo.getNextPage() : null); + responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? + baseUrl + "?page=" + pageInfo.getPrePage() : null); responseData.put("path", baseUrl); // 构建links数组 List> links = new ArrayList<>(); Map prevLink = new HashMap<>(); - prevLink.put("url", pageInfo.isHasPreviousPage() ? - baseUrl + "?page=" + pageInfo.getPrePage() : null); + prevLink.put("url", pageInfo.isHasPreviousPage() ? + baseUrl + "?page=" + pageInfo.getPrePage() : null); prevLink.put("label", "« Previous"); prevLink.put("active", false); links.add(prevLink); Map nextLink = new HashMap<>(); - nextLink.put("url", pageInfo.isHasNextPage() ? - baseUrl + "?page=" + pageInfo.getNextPage() : null); + nextLink.put("url", pageInfo.isHasNextPage() ? + baseUrl + "?page=" + pageInfo.getNextPage() : null); nextLink.put("label", "Next »"); nextLink.put("active", false); links.add(nextLink); @@ -3803,11 +3790,10 @@ public class AppletController extends BaseController { } - /** * 服务/商品搜索接口 * - * @param params 请求参数,包含limit(每页数量)、page(页码)、keywords(搜索关键词) + * @param params 请求参数,包含limit(每页数量)、page(页码)、keywords(搜索关键词) * @param request HTTP请求对象 * @return 搜索结果列表 *

@@ -3819,38 +3805,38 @@ public class AppletController extends BaseController { *

* 请求参数格式: * { - * "limit": 15, - * "page": 1, - * "keywords": "3" + * "limit": 15, + * "page": 1, + * "keywords": "3" * } *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": { - * "current_page": 1, - * "data": [ - * { - * "id": 161, - * "title": "238元套餐", - * "icon": "https://img.huafurenjia.cn/images/238元套餐.png", - * "cate_id": 8, - * "price": "238.00", - * "price_zn": "元起", - * "sales": 66, - * "stock": 942, - * "sub_title": "咖啡机(咖啡)冷台·洗衣机(空调)烘", - * "title": "238元套餐", - * "type": 1 - * } - * ], - * "from": 1, - * "last_page": 1, - * "per_page": 15, - * "to": 2, - * "total": 2 - * } + * "code": 200, + * "msg": "OK", + * "data": { + * "current_page": 1, + * "data": [ + * { + * "id": 161, + * "title": "238元套餐", + * "icon": "https://img.huafurenjia.cn/images/238元套餐.png", + * "cate_id": 8, + * "price": "238.00", + * "price_zn": "元起", + * "sales": 66, + * "stock": 942, + * "sub_title": "咖啡机(咖啡)冷台·洗衣机(空调)烘", + * "title": "238元套餐", + * "type": 1 + * } + * ], + * "from": 1, + * "last_page": 1, + * "per_page": 15, + * "to": 2, + * "total": 2 + * } * } */ @PostMapping(value = "/api/service/search") @@ -3872,7 +3858,7 @@ public class AppletController extends BaseController { // 4. 构建查询条件 ServiceGoods queryGoods = new ServiceGoods(); - + // 如果有关键词,设置标题模糊查询 if (!keywords.isEmpty()) { queryGoods.setTitle(keywords); // 这里依赖mapper中的like查询实现 @@ -3905,24 +3891,24 @@ public class AppletController extends BaseController { String baseUrl = "https://www.huafurenjia.cn/api/service/search"; responseData.put("first_page_url", baseUrl + "?page=1"); responseData.put("last_page_url", baseUrl + "?page=" + pageInfo.getPages()); - responseData.put("next_page_url", pageInfo.isHasNextPage() ? - baseUrl + "?page=" + pageInfo.getNextPage() : null); - responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? - baseUrl + "?page=" + pageInfo.getPrePage() : null); + responseData.put("next_page_url", pageInfo.isHasNextPage() ? + baseUrl + "?page=" + pageInfo.getNextPage() : null); + responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? + baseUrl + "?page=" + pageInfo.getPrePage() : null); responseData.put("path", baseUrl); // 构建links数组 List> links = new ArrayList<>(); Map prevLink = new HashMap<>(); - prevLink.put("url", pageInfo.isHasPreviousPage() ? - baseUrl + "?page=" + pageInfo.getPrePage() : null); + prevLink.put("url", pageInfo.isHasPreviousPage() ? + baseUrl + "?page=" + pageInfo.getPrePage() : null); prevLink.put("label", "« Previous"); prevLink.put("active", false); links.add(prevLink); Map nextLink = new HashMap<>(); - nextLink.put("url", pageInfo.isHasNextPage() ? - baseUrl + "?page=" + pageInfo.getNextPage() : null); + nextLink.put("url", pageInfo.isHasNextPage() ? + baseUrl + "?page=" + pageInfo.getNextPage() : null); nextLink.put("label", "Next »"); nextLink.put("active", false); links.add(nextLink); @@ -3940,7 +3926,7 @@ public class AppletController extends BaseController { /** * 获取商品订单详情接口 * - * @param id 订单ID + * @param id 订单ID * @param request HTTP请求对象 * @return 订单详细信息 *

@@ -3952,23 +3938,23 @@ public class AppletController extends BaseController { *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": { - * "id": 2, - * "type": 2, - * "main_order_id": "WXBB08452049418556", - * "order_id": "BB08452049567554", - * // ... 其他订单字段 - * "address": { - * // 地址信息 - * }, - * "product": { - * // 商品信息 - * }, - * "comment": [], - * "delivery": [] - * } + * "code": 200, + * "msg": "OK", + * "data": { + * "id": 2, + * "type": 2, + * "main_order_id": "WXBB08452049418556", + * "order_id": "BB08452049567554", + * // ... 其他订单字段 + * "address": { + * // 地址信息 + * }, + * "product": { + * // 商品信息 + * }, + * "comment": [], + * "delivery": [] + * } * } */ @GetMapping("/api/goods/order/info/{id}") @@ -4016,7 +4002,7 @@ public class AppletController extends BaseController { /** * 构建商品订单详情数据 - * + * * @param order 订单信息 * @return 格式化的订单详情 */ @@ -4049,7 +4035,7 @@ public class AppletController extends BaseController { orderDetail.put("mark", order.getMark()); orderDetail.put("address_id", order.getAddressId()); orderDetail.put("sku", order.getSku()); - + // 时间字段格式化 orderDetail.put("created_at", order.getCreatedAt() != null ? sdf.format(order.getCreatedAt()) : null); orderDetail.put("updated_at", order.getUpdatedAt() != null ? sdf.format(order.getUpdatedAt()) : null); @@ -4073,7 +4059,7 @@ public class AppletController extends BaseController { addressInfo.put("created_at", address.getCreatedAt() != null ? sdf.format(address.getCreatedAt()) : null); addressInfo.put("updated_at", address.getUpdatedAt() != null ? sdf.format(address.getUpdatedAt()) : null); addressInfo.put("deleted_at", null); // UserAddress可能没有deletedAt字段 - + orderDetail.put("address", addressInfo); } } @@ -4087,7 +4073,7 @@ public class AppletController extends BaseController { productInfo.put("title", product.getTitle()); productInfo.put("sub_title", product.getSubTitle()); productInfo.put("icon", AppletControllerUtil.buildImageUrl(product.getIcon())); - + orderDetail.put("product", productInfo); } } @@ -4112,14 +4098,14 @@ public class AppletController extends BaseController { *

* 返回格式: * { - * "code": 200, - * "msg": "OK", - * "data": { - * "one": 1, // 未使用数量 - * "two": 0, // 已使用数量 - * "three": 0, // 已过期数量 - * "four": 13 // 待领取数量 - * } + * "code": 200, + * "msg": "OK", + * "data": { + * "one": 1, // 未使用数量 + * "two": 0, // 已使用数量 + * "three": 0, // 已过期数量 + * "four": 13 // 待领取数量 + * } * } */ @GetMapping("/api/coupon/my/count") @@ -4169,7 +4155,7 @@ public class AppletController extends BaseController { Coupons couponsQuery = new Coupons(); couponsQuery.setStatus(1L); // 启用状态 List availableCoupons = couponsService.selectCouponsList(couponsQuery); - + int availableToReceiveCount = 0; // 待领取数量 (four) for (Coupons coupon : availableCoupons) { if (isCouponAvailableToReceive(coupon, user.getId(), currentTime)) { @@ -4194,8 +4180,8 @@ public class AppletController extends BaseController { /** * 判断优惠券是否已过期 - * - * @param couponUser 用户优惠券 + * + * @param couponUser 用户优惠券 * @param currentTime 当前时间戳(秒) * @return 是否过期 */ @@ -4210,21 +4196,21 @@ public class AppletController extends BaseController { System.err.println("解析失效时间失败:" + couponUser.getLoseTime()); } } - + // 如果状态为3,表示已失效 if (couponUser.getStatus() != null && couponUser.getStatus() == 3L) { return true; } - + // 如果都没有设置,认为未过期 return false; } /** * 判断优惠券是否可以领取 - * - * @param coupon 优惠券 - * @param userId 用户ID + * + * @param coupon 优惠券 + * @param userId 用户ID * @param currentTime 当前时间戳(秒) * @return 是否可以领取 */ @@ -4233,33 +4219,112 @@ public class AppletController extends BaseController { if (coupon.getStatus() == null || coupon.getStatus() != 1L) { return false; } - + // 检查领取时间范围 if (coupon.getStartTime() != null && currentTime < coupon.getStartTime()) { return false; // 还未到领取时间 } - + if (coupon.getEndTime() != null && currentTime > coupon.getEndTime()) { return false; // 已过领取时间 } - + // 检查数量限制(如果不是无限领取) if (coupon.getIsPermanent() == null || coupon.getIsPermanent() != 1L) { if (coupon.getCount() != null && coupon.getCount() <= 0) { return false; // 数量已用完 } } - + // 检查用户是否已经领取过此优惠券(如果有限制的话) // 这里可以根据业务规则进一步完善 - + return true; } + + +// /** +// * 商品下单接口 +// * POST /api/service/create/order +// * 参数:{"0":{"product_id":2,"num":1,"sku":{...},"address_id":26,"deduction":"","mark":""}} +// */ +// @PostMapping("/api/service/create/order") +// public AjaxResult createGoodsOrder(@RequestBody Map params, HttpServletRequest request) { +// try { +// // 1. 校验用户登录 +// String token = request.getHeader("token"); +// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); +// if (!(Boolean) userValidation.get("valid")) { +// return AppletControllerUtil.appletError("用户未登录或token无效"); +// } +// Users user = (Users) userValidation.get("user"); +// if (user == null) { +// return AppletControllerUtil.appletError("用户信息获取失败"); +// } +// // 2. 解析参数 +// Map orderParams = (Map) params.get("0"); +// if (orderParams == null) { +// return AppletControllerUtil.appletError("参数错误"); +// } +// Long productId = Long.valueOf(orderParams.get("product_id").toString()); +// Integer num = Integer.valueOf(orderParams.get("num").toString()); +// Map sku = (Map) orderParams.get("sku"); +// Long addressId = Long.valueOf(orderParams.get("address_id").toString()); +// String deduction = orderParams.get("deduction") != null ? orderParams.get("deduction").toString() : ""; +// String mark = orderParams.get("mark") != null ? orderParams.get("mark").toString() : ""; +// // 3. 查询商品信息 +// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); +// if (serviceGoods == null) { +// return AppletControllerUtil.appletError("商品不存在"); +// } +// // 4. 查询地址信息 +// UserAddress userAddress = userAddressService.selectUserAddressById(addressId); +// if (userAddress == null) { +// return AppletControllerUtil.appletError("地址不存在"); +// } +// // 5. 计算金额 +// BigDecimal price = new BigDecimal(sku.get("price").toString()); +// BigDecimal totalPrice = price.multiply(BigDecimal.valueOf(num)); +// // 6. 组装订单 +// GoodsOrder order = new GoodsOrder(); +// order.setType(2); // 商品订单 +// order.setMainOrderId("WX" + System.currentTimeMillis()); +// order.setOrderId("B" + System.currentTimeMillis()); +// order.setUid(user.getId()); +// order.setProductId(productId); +// order.setNum(Long.valueOf(num)); +// order.setSku(com.alibaba.fastjson2.JSONObject.toJSONString(sku)); +// order.setAddressId(addressId); +// order.setName(userAddress.getName()); +// order.setPhone(userAddress.getPhone()); +// order.setAddress(userAddress.getAddressName()); +// order.setStatus(1L); +// order.setGoodPrice(price); +// order.setTotalPrice(totalPrice); +// order.setDeduction(deduction.isEmpty() ? BigDecimal.ZERO : new BigDecimal(deduction)); +// order.setMark(mark); +// order.setCreatedAt(new Date()); +// order.setUpdatedAt(new Date()); +// // 7. 插入订单 +// int result = goodsOrderService.insertGoodsOrder(order); +// if (result > 0) { +// return AppletControllerUtil.appletSuccess("下单成功"); +// } else { +// return AppletControllerUtil.appletError("下单失败"); +// } +// } catch (Exception e) { +// return AppletControllerUtil.appletError("下单异常: " + e.getMessage()); +// } +// } + + + + /** * 创建服务订单 * - * @param params 请求参数,包含商品信息、地址信息和预约时间 + * @param params 请求参数,包含商品信息、地址信息和预约时间 * @param request HTTP请求对象 * @return 返回创建结果 */ @@ -4284,11 +4349,12 @@ public class AppletController extends BaseController { return error("订单参数不能为空"); } Map orderParams = (Map) params.get("0"); - + // 4. 验证必要参数 Long productId = Long.valueOf(orderParams.get("product_id").toString()); Long addressId = Long.valueOf(orderParams.get("address_id").toString()); String makeTime = orderParams.get("make_time").toString(); + Long num = Long.valueOf(orderParams.get("num").toString()); String sku = orderParams.get("sku") != null ? orderParams.get("sku").toString() : ""; // 5. 查询商品信息 @@ -4302,68 +4368,91 @@ public class AppletController extends BaseController { if (userAddress == null) { return error("地址不存在"); } - - // 7. 创建订单对象 - Order order = new Order(); - order.setType(1); // 1:服务项目 - order.setCreateType(1); // 1:用户自主下单 - order.setUid(user.getId()); - order.setUname(user.getName()); - order.setProductId(productId); - order.setProductName(serviceGoods.getTitle()); - order.setName(userAddress.getName()); - order.setPhone(userAddress.getPhone()); - order.setAddress(userAddress.getAddressInfo()); - order.setAddressId(addressId); - order.setSku(sku); - - // 解析预约时间 - String[] makeTimeArr = makeTime.split(" "); - if (makeTimeArr.length != 2) { - return error("预约时间格式错误"); - } - // 将日期字符串转换为时间戳 - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Date date = sdf.parse(makeTimeArr[0]); - order.setMakeTime(date.getTime() / 1000); // 转换为秒级时间戳 - order.setMakeHour(makeTimeArr[1]); // 设置预约时间段 - } catch (Exception e) { - return error("预约时间格式错误"); - } - - order.setNum(1L); // 默认数量为1 - order.setTotalPrice(serviceGoods.getPrice()); // 总价等于商品价格 - order.setGoodPrice(serviceGoods.getPrice()); // 商品金额 - order.setServicePrice(BigDecimal.ZERO); // 服务金额默认为0 - order.setPayPrice(serviceGoods.getPrice()); // 支付金额等于总价 - order.setStatus(1L); // 1:待接单 - order.setReceiveType(1L); // 1:自由抢单 - order.setIsAccept(0); // 0:未接单 - order.setIsComment(0); // 0:未评价 - order.setIsPause(0); // 0:未暂停 - // 8. 生成订单号 - String orderId = generateOrderId(); - order.setOrderId(orderId); - order.setMainOrderId(orderId); - // 9. 保存订单 - int result = orderService.insertOrder(order); - if (result > 0) { - //10预约后添加到订单记录中 - OrderLog orderLog = new OrderLog(); - orderLog.setOid(order.getId()); - orderLog.setOrderId(order.getOrderId()); - orderLog.setTitle("订单生成"); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("name", "预约成功,将尽快为主人派单"); - orderLog.setType(new BigDecimal(1.0)); - orderLog.setContent(jsonObject.toString()); - orderLogService.insertOrderLog(orderLog); + if(serviceGoods.getType()==2){ + GoodsOrder goodsOrder = new GoodsOrder(); + goodsOrder.setType(2); + goodsOrder.setMainOrderId("WX" + System.currentTimeMillis()); + goodsOrder.setOrderId("B" + System.currentTimeMillis()); + goodsOrder.setUid(user.getId()); + goodsOrder.setProductId(productId); + goodsOrder.setName(userAddress.getName()); + goodsOrder.setPhone(userAddress.getPhone()); + goodsOrder.setAddress(userAddress.getAddressName()); + goodsOrder.setNum(num); + goodsOrder.setTotalPrice(serviceGoods.getPrice().multiply(BigDecimal.valueOf(num))); + goodsOrder.setGoodPrice(serviceGoods.getPrice()); + goodsOrder.setPayPrice(new BigDecimal(0)); + goodsOrder.setDeduction(new BigDecimal(0)); + goodsOrder.setStatus(1L); + goodsOrder.setAddressId(addressId); + goodsOrder.setSku(sku); + goodsOrderService.insertGoodsOrder(goodsOrder); return success("预约成功"); - } else { - return error("预约失败,请稍后重试"); + }else{ + // 7. 创建订单对象 + Order order = new Order(); + order.setType(1); // 1:服务项目 + order.setCreateType(1); // 1:用户自主下单 + order.setUid(user.getId()); + order.setUname(user.getName()); + order.setProductId(productId); + order.setProductName(serviceGoods.getTitle()); + order.setName(userAddress.getName()); + order.setPhone(userAddress.getPhone()); + order.setAddress(userAddress.getAddressInfo()); + order.setAddressId(addressId); + order.setSku(sku); + + // 解析预约时间 + String[] makeTimeArr = makeTime.split(" "); + if (makeTimeArr.length != 2) { + return error("预约时间格式错误"); + } + // 将日期字符串转换为时间戳 + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Date date = sdf.parse(makeTimeArr[0]); + order.setMakeTime(date.getTime() / 1000); // 转换为秒级时间戳 + order.setMakeHour(makeTimeArr[1]); // 设置预约时间段 + } catch (Exception e) { + return error("预约时间格式错误"); + } + + order.setNum(num); // 默认数量为1 + order.setTotalPrice(serviceGoods.getPrice()); // 总价等于商品价格 + order.setGoodPrice(serviceGoods.getPrice()); // 商品金额 + order.setServicePrice(BigDecimal.ZERO); // 服务金额默认为0 + order.setPayPrice(serviceGoods.getPrice()); // 支付金额等于总价 + order.setStatus(1L); // 1:待接单 + order.setReceiveType(1L); // 1:自由抢单 + order.setIsAccept(0); // 0:未接单 + order.setIsComment(0); // 0:未评价 + order.setIsPause(1); // 0:未暂停 + // 8. 生成订单号 + String orderId = generateOrderId(); + order.setOrderId(orderId); + order.setMainOrderId(orderId); + // 9. 保存订单 + int result = orderService.insertOrder(order); + if (result > 0) { + //10预约后添加到订单记录中 + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("订单生成"); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "预约成功,将尽快为主人派单"); + orderLog.setType(new BigDecimal(1.0)); + orderLog.setContent(jsonObject.toString()); + orderLogService.insertOrderLog(orderLog); + return success("预约成功"); + } else { + return error("预约失败,请稍后重试"); + } } + + } catch (Exception e) { return error("预约失败:" + e.getMessage()); } @@ -4383,7 +4472,7 @@ public class AppletController extends BaseController { /** * 取消服务订单 * - * @param params 请求参数,包含订单ID和取消原因 + * @param params 请求参数,包含订单ID和取消原因 * @param request HTTP请求对象 * @return 返回取消结果 */ @@ -4415,7 +4504,7 @@ public class AppletController extends BaseController { orderQuery.setId(orderId); orderQuery.setUid(user.getId()); // 确保是用户自己的订单 List orders = orderService.selectOrderList(orderQuery); - + if (orders == null || orders.isEmpty()) { return error("订单不存在"); } @@ -4455,220 +4544,204 @@ public class AppletController extends BaseController { } /** - * 师傅接单 - * - * @param id 订单ID - * @param request HTTP请求对象 - * @return 返回接单结果 + * 师傅接单接口 + * 参考OrderController+OrderUtil+OrderLogHandler的json_status=2分支 */ @GetMapping("/api/worker/accept/order/{id}") - public AjaxResult acceptServiceOrder(@PathVariable("id") Long id, HttpServletRequest request) { + public AjaxResult workerAcceptOrder(@PathVariable("id") Long id, HttpServletRequest request) { try { - // 1. 验证用户登录状态 + // 1. 校验token并获取师傅信息 String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletUnauthorized(); } - - // 2. 获取师傅信息 Users worker = (Users) userValidation.get("user"); if (worker == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } - - // 3. 查询订单信息 + // 2. 查询订单 Order order = orderService.selectOrderById(id); if (order == null) { - return error("订单不存在"); + return AppletControllerUtil.appletWarning("订单不存在"); } - - // 4. 验证订单状态是否可以接单 - if (order.getStatus() != 1L) { - return error("当前订单状态不可接单"); + // 3. 仅允许待服务状态接单 + if (order.getStatus() == null || order.getStatus() != 2L) { + return AppletControllerUtil.appletWarning("当前订单状态不可接单"); } - - // 5. 更新订单信息 - order.setStatus(2L); // 更新状态为待服务 - order.setJsonStatus(2); // 更新为接单状态 - order.setWorkerId(worker.getId()); // 设置接单师傅ID - order.setWorkerPhone(worker.getPhone()); // 设置师傅电话 - order.setIsPause(1); // 设置暂停状态为1 - order.setReceiveType(3L); // 设置接单类型为3 - order.setReceiveTime(new Date()); // 设置接单时间 - order.setIsAccept(1); // 设置已接单 - - // 6. 添加订单日志 - OrderLog orderLog = new OrderLog(); - orderLog.setOid(order.getId()); - orderLog.setOrderId(order.getOrderId()); - orderLog.setTitle("师傅接单"); - orderLog.setWorkerId(worker.getId()); - orderLog.setFirstWorkerId(worker.getId()); - orderLog.setIsPause(1); - orderLog.setType(new BigDecimal("2.0")); - - JSONObject content = new JSONObject(); - content.put("name", "师傅已接单,请等待上门服务"); - orderLog.setContent(content.toString()); - - // 7. 保存订单和日志 - int result = orderService.updateOrder(order); - if (result > 0) { - orderLogService.insertOrderLog(orderLog); - return success("接单成功"); - } else { - return error("接单失败,请稍后重试"); - } - + // 4. 设置接单相关字段 + order.setWorkerId(worker.getId()); + order.setWorkerPhone(worker.getPhone()); + order.setIsPause(1); // 1:未暂停 + order.setReceiveType(3L); // 3:平台派单 + order.setReceiveTime(new Date()); + order.setIsAccept(1); // 1:已接单 + order.setJsonStatus(2); // 服务进度:2=接单 + // 5. 写入日志 + OrderUtil orderUtil = new OrderUtil(); + orderUtil.SaveOrderLog(order); + // 6. 返回成功 + return AjaxResult.success("接单成功"); } catch (Exception e) { - return error("接单失败:" + e.getMessage()); + return AppletControllerUtil.appletError("师傅接单失败:" + e.getMessage()); } } + /** + * 师傅端订单列表接口 + * 查询worker_id为当前师傅的订单,支持状态和预约日期筛选 + * + * @param params {"limit":10,"page":1,"status":0,"day":""} + * @param request HttpServletRequest + * @return AjaxResult 带分页的订单列表,结构与json.txt一致 + */ @PostMapping("/api/worker/order/lst") public AjaxResult getWorkerOrderList(@RequestBody Map params, HttpServletRequest request) { try { - // 获取当前用户token + // 1. 校验token并获取师傅信息 String token = request.getHeader("token"); - Map userData = AppletControllerUtil.getUserData(token, usersService); - if ((int) userData.get("code") != 200) { - return AjaxResult.error("用户未登录"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); } - Users user = (Users) userData.get("user"); - Long userId = user.getId(); + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 2. 解析分页和筛选参数 + 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()) : 10; + int status = params.get("status") != null ? Integer.parseInt(params.get("status").toString()) : 0; + String day = params.get("day") != null ? params.get("day").toString() : ""; - // 获取分页参数 - int page = params.containsKey("page") ? Integer.parseInt(params.get("page").toString()) : 1; - int limit = params.containsKey("limit") ? Integer.parseInt(params.get("limit").toString()) : 15; - int status = params.containsKey("status") ? Integer.parseInt(params.get("status").toString()) : 0; - String day = params.containsKey("day") ? params.get("day").toString() : ""; + // 3. 构建查询条件 + Order query = new Order(); + query.setWorkerId(user.getId()); + // 状态筛选 + if (status == 2) { + query.setStatus(2L); // 待服务 + } else if (status == 3) { + query.setStatus(3L); // 服务中 + } else if (status == 4) { + query.setStatus(5L); // 已结束 + } else if (status == 5) { + query.setStatus(6L); // 已取消 + } // status=0查全部 - // 查询工人的订单日志 - OrderLog queryLog = new OrderLog(); - queryLog.setWorkerId(userId); - queryLog.setType(new BigDecimal("1.1")); // type=2 的数据 - - // 执行分页查询 PageHelper.startPage(page, limit); - List orderLogs = orderLogService.selectOrderLogList(queryLog); - PageInfo pageInfo = new PageInfo<>(orderLogs); - - // 构建返回数据 + List orderList = orderService.selectOrderList(query); List> resultList = new ArrayList<>(); - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd"); - for (OrderLog log : orderLogs) { - // 获取订单信息 - Order order = orderService.selectOrderById(log.getOid()); - if (order != null) { - // 状态筛选 - boolean statusMatch = false; - if (status == 0) { - statusMatch = true; - } else if (status == 2 && order.getStatus() != null && order.getStatus() == 2L) { - statusMatch = true; - } else if (status == 3 && order.getStatus() != null && order.getStatus() == 3L) { - statusMatch = true; - } else if (status == 4 && order.getStatus() != null && order.getStatus() == 5L) { - statusMatch = true; - } else if (status == 5 && order.getStatus() != null && order.getStatus() == 6L) { - statusMatch = true; - } - // 日期筛选 - boolean dayMatch = true; - if (day != null && !day.trim().isEmpty() && order.getCreatedAt() != null) { - String orderDay = sdf.format(order.getCreatedAt()); - dayMatch = day.equals(orderDay); - } - if (statusMatch && dayMatch) { - Map orderMap = new HashMap<>(); - // 填充订单基本信息 - orderMap.put("id", order.getId()); - orderMap.put("type", order.getType()); - orderMap.put("main_order_id", order.getMainOrderId()); - orderMap.put("order_id", order.getOrderId()); - orderMap.put("transaction_id", order.getTransactionId()); - orderMap.put("create_type", order.getCreateType()); - orderMap.put("create_phone", order.getCreatePhone()); - orderMap.put("uid", order.getUid()); - orderMap.put("product_id", order.getProductId()); - orderMap.put("name", order.getName()); - orderMap.put("phone", order.getPhone()); - orderMap.put("make_time", order.getMakeTime()); - orderMap.put("make_hour", order.getMakeHour()); - orderMap.put("num", order.getNum()); - orderMap.put("total_price", order.getTotalPrice()); - orderMap.put("good_price", order.getGoodPrice()); - orderMap.put("service_price", order.getServicePrice()); - orderMap.put("pay_price", order.getPayPrice()); - orderMap.put("coupon_id", order.getCouponId()); - orderMap.put("deduction", order.getDeduction()); - orderMap.put("pay_time", order.getPayTime()); - orderMap.put("status", order.getStatus()); - orderMap.put("is_pause", order.getIsPause()); - orderMap.put("mark", order.getMark()); - orderMap.put("address_id", order.getAddressId()); - orderMap.put("sku", order.getSku()); - orderMap.put("worker_id", order.getWorkerId()); - orderMap.put("first_worker_id", order.getFirstWorkerId()); - orderMap.put("receive_time", order.getReceiveTime()); - orderMap.put("is_comment", order.getIsComment()); - orderMap.put("receive_type", order.getReceiveType()); - orderMap.put("is_accept", order.getIsAccept()); - orderMap.put("created_at", order.getCreatedAt()); - orderMap.put("updated_at", order.getUpdatedAt()); - orderMap.put("deleted_at", order.getDeletedAt()); - orderMap.put("log_type", log.getType()); - - // 获取地址信息 - if (order.getAddressId() != null) { - UserAddress address = userAddressService.selectUserAddressById(order.getAddressId()); - if (address != null) { - Map addressMap = new HashMap<>(); - addressMap.put("id", address.getId()); - addressMap.put("uid", address.getUid()); - addressMap.put("name", address.getName()); - addressMap.put("phone", address.getPhone()); - addressMap.put("latitude", address.getLatitude()); - addressMap.put("longitude", address.getLongitude()); - addressMap.put("address_name", address.getAddressName()); - addressMap.put("address_info", address.getAddressInfo()); - addressMap.put("info", address.getInfo()); - addressMap.put("is_default", address.getIsDefault()); - addressMap.put("created_at", address.getCreatedAt()); - addressMap.put("updated_at", address.getUpdatedAt()); - addressMap.put("deleted_at", address.getDeletedAt()); - orderMap.put("address", addressMap); - orderMap.put("address_has", addressMap); - } - } - // 获取商品信息 - if (order.getProductId() != null) { - ServiceGoods product = serviceGoodsService.selectServiceGoodsById(order.getProductId()); - if (product != null) { - Map productMap = new HashMap<>(); - productMap.put("id", product.getId()); - productMap.put("icon", "https://img.huafurenjia.cn/"+product.getIcon()); - productMap.put("title", product.getTitle()); - productMap.put("price", product.getPrice()); - productMap.put("sku_type", product.getSkuType()); - productMap.put("price_zn", product.getPriceZn()); - orderMap.put("product", productMap); - } - } - resultList.add(orderMap); - } + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + SimpleDateFormat sdfFull = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date today = new Date(); + Date tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000); + int todayCount = 0; + int tomorrowCount = 0; + for (Order order : orderList) { + // day筛选逻辑 + if (status == 2 && day != null && !day.isEmpty()) { + String orderDay = order.getMakeTime() != null ? sdf.format(new Date(order.getMakeTime() * 1000)) : ""; + if ("today".equals(day) && !orderDay.equals(sdf.format(today))) continue; + if ("tomorrow".equals(day) && !orderDay.equals(sdf.format(tomorrow))) continue; } + // 统计今日/明日待服务订单数 + if (order.getStatus() != null && order.getStatus() == 2L && order.getMakeTime() != null) { + String orderDay = sdf.format(new Date(order.getMakeTime() * 1000)); + if (orderDay.equals(sdf.format(today))) todayCount++; + if (orderDay.equals(sdf.format(tomorrow))) tomorrowCount++; + } + Map map = new HashMap<>(); + map.put("id", order.getId()); + map.put("type", order.getType()); + map.put("main_order_id", order.getMainOrderId()); + map.put("order_id", order.getOrderId()); + map.put("transaction_id", order.getTransactionId()); + map.put("create_type", order.getCreateType()); + map.put("create_phone", order.getCreatePhone()); + map.put("uid", order.getUid()); + map.put("product_id", order.getProductId()); + map.put("name", order.getName()); + map.put("phone", order.getPhone()); + // make_time格式化 + if (order.getMakeTime() != null && order.getMakeHour() != null) { + map.put("make_time", sdf.format(new Date(order.getMakeTime() * 1000)) + " " + order.getMakeHour()); + } else { + map.put("make_time", null); + } + map.put("make_hour", order.getMakeHour()); + map.put("num", order.getNum()); + map.put("total_price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); + map.put("good_price", order.getGoodPrice() != null ? order.getGoodPrice().toString() : "0.00"); + map.put("service_price", order.getServicePrice()); + map.put("pay_price", order.getPayPrice() != null ? order.getPayPrice().toString() : "0.00"); + map.put("coupon_id", order.getCouponId()); + map.put("deduction", order.getDeduction() != null ? order.getDeduction().toString() : "0.00"); + map.put("pay_time", order.getPayTime()); + map.put("status", order.getStatus()); + map.put("is_pause", order.getIsPause()); + map.put("mark", order.getMark()); + map.put("address_id", order.getAddressId()); + map.put("sku", order.getSku()); + map.put("worker_id", order.getWorkerId()); + map.put("first_worker_id", order.getFirstWorkerId()); + map.put("receive_time", order.getReceiveTime()); + map.put("is_comment", order.getIsComment()); + map.put("receive_type", order.getReceiveType()); + map.put("is_accept", order.getIsAccept()); + map.put("middle_phone", order.getMiddlePhone()); + map.put("user_phone", order.getUserPhone()); + map.put("worker_phone", order.getWorkerPhone()); + map.put("address_en", order.getAddressEn()); + map.put("uid_admin", order.getUidAdmin()); + map.put("address_admin", order.getAddressAdmin()); + map.put("log_status", order.getLogStatus()); + map.put("log_json", order.getLogJson()); + map.put("json_status", order.getJsonStatus()); + map.put("log_images", order.getLogImages()); + map.put("created_at", order.getCreatedAt() != null ? sdfFull.format(order.getCreatedAt()) : null); + map.put("updated_at", order.getUpdatedAt() != null ? sdfFull.format(order.getUpdatedAt()) : null); + map.put("deleted_at", order.getDeletedAt()); + //map.put("log_type", 1.1); + // 兼容log_type + + // address/address_has + UserAddress address = null; + if (order.getAddressId() != null) { + address = userAddressService.selectUserAddressById(order.getAddressId()); + } + map.put("address", address); + map.put("address_has", address); + // product + ServiceGoods product = null; + if (order.getProductId() != null) { + product = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + } + if (product != null) { + Map productMap = new HashMap<>(); + productMap.put("id", product.getId()); + productMap.put("icon", AppletControllerUtil.buildImageUrl(product.getIcon())); + productMap.put("title", product.getTitle()); + productMap.put("price", product.getPrice() != null ? product.getPrice().toString() : "0.00"); + productMap.put("sku_type", product.getSkuType()); + productMap.put("price_zn", product.getPriceZn()); + map.put("product", productMap); + } else { + map.put("product", null); + } + resultList.add(map); } - // 构建分页数据 - Map data = new HashMap<>(); - data.put("current_page", pageInfo.getPageNum()); - data.put("data", resultList); - Map result = new HashMap<>(); - result.put("data", data); - return AjaxResult.success(result); + PageInfo pageInfo = new PageInfo<>(orderList); + Map dataPage = AppletControllerUtil.buildPageResult(pageInfo, resultList, "/api/worker/order/lst"); + // 外层data结构 + Map outerData = new HashMap<>(); + outerData.put("data", dataPage); + Map totalMap = new HashMap<>(); + totalMap.put("today", todayCount); + totalMap.put("tomorrow", tomorrowCount); + outerData.put("total", totalMap); + return AjaxResult.success(outerData); } catch (Exception e) { - return AjaxResult.error("获取工人订单列表失败:" + e.getMessage()); + return AppletControllerUtil.appletError("查询师傅订单列表失败:" + e.getMessage()); } } @@ -4697,31 +4770,31 @@ public class AppletController extends BaseController { if (configList != null && !configList.isEmpty()) { String configValue = configList.get(0).getValue(); if (configValue != null && !configValue.trim().isEmpty()) { - configObj = com.alibaba.fastjson2.JSONObject.parse(configValue); + configObj = JSONObject.parse(configValue); } } // 3. 判断今日是否签到 - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd"); - String todayStr = sdf.format(new java.util.Date()); - com.ruoyi.system.domain.WorkerSign signQuery = new com.ruoyi.system.domain.WorkerSign(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String todayStr = sdf.format(new Date()); + WorkerSign signQuery = new WorkerSign(); signQuery.setUid(String.valueOf(user.getId())); signQuery.setTime(sdf.parse(todayStr)); boolean signed = false; - java.util.List signList = workerSignService.selectWorkerSignList(signQuery); + List signList = workerSignService.selectWorkerSignList(signQuery); if (signList != null && !signList.isEmpty()) { signed = true; } // 4. 构建user数据 Map userMap = buildUserInfoResponse(user); // 5. 构建返回结构 - java.util.Map data = new java.util.HashMap<>(); + Map data = new HashMap<>(); data.put("day_count", 0); data.put("mouth_count", 0); data.put("income", 0); data.put("user", userMap); data.put("sign", signed); data.put("config", configObj); - java.util.Map result = new java.util.HashMap<>(); + Map result = new HashMap<>(); result.put("code", 200); result.put("msg", "OK"); result.put("data", data); @@ -4782,10 +4855,16 @@ public class AppletController extends BaseController { Object contentObj = null; try { if (log.getContent() != null) { - contentObj = com.alibaba.fastjson2.JSONObject.parse(log.getContent()); + contentObj = JSONObject.parse(log.getContent()); } } catch (Exception e) { - contentObj = log.getContent(); + + if (AppletControllerUtil.canParseToJSONArray(log.getContent())) { + contentObj = JSONArray.parseArray(log.getContent()); + } else { + contentObj = log.getContent(); + } + } logMap.put("content", contentObj); logMap.put("deposit", log.getDeposit()); @@ -4907,32 +4986,34 @@ public class AppletController extends BaseController { map.put("skill_ids", user.getSkillIds()); // city名称数组 List cityNames = new ArrayList<>(); - List cityIds = com.ruoyi.system.ControllerUtil.AppletControllerUtil.parseStringToList(user.getServiceCityIds()); + List cityIds = AppletControllerUtil.parseStringToList(user.getServiceCityIds()); for (String cityIdStr : cityIds) { try { if (cityIdStr != null && !cityIdStr.trim().isEmpty()) { Integer cityId = Integer.valueOf(cityIdStr); - com.ruoyi.system.domain.DiyCity city = diyCityService.selectDiyCityById(cityId); + DiyCity city = diyCityService.selectDiyCityById(cityId); if (city != null && city.getTitle() != null) { cityNames.add(city.getTitle()); } } - } catch (Exception ignore) {} + } catch (Exception ignore) { + } } map.put("city", cityNames); // skill名称数组 List skillNames = new ArrayList<>(); - List skillIds = com.ruoyi.system.ControllerUtil.AppletControllerUtil.parseStringToList(user.getSkillIds()); + List skillIds = AppletControllerUtil.parseStringToList(user.getSkillIds()); for (String skillIdStr : skillIds) { try { if (skillIdStr != null && !skillIdStr.trim().isEmpty()) { Long skillId = Long.valueOf(skillIdStr); - com.ruoyi.system.domain.SiteSkill skill = siteSkillService.selectSiteSkillById(skillId); + SiteSkill skill = siteSkillService.selectSiteSkillById(skillId); if (skill != null && skill.getTitle() != null) { skillNames.add(skill.getTitle()); } } - } catch (Exception ignore) {} + } catch (Exception ignore) { + } } map.put("skill", skillNames); resultList.add(map); @@ -4979,7 +5060,8 @@ public class AppletController extends BaseController { /** * 师傅转单接口 - * @param orderId 订单ID + * + * @param orderId 订单ID * @param newWorkerId 新师傅ID * @return 操作结果 */ @@ -5012,21 +5094,21 @@ public class AppletController extends BaseController { log.setOid(order.getId()); log.setOrderId(order.getOrderId()); log.setTitle("转单"); - log.setType(new BigDecimal(1.1)); + log.setType(new BigDecimal(1.1)); log.setWorkerId(newWorkerId); log.setIsPause(2); // 转单 // 构造content - com.alibaba.fastjson2.JSONObject content = new com.alibaba.fastjson2.JSONObject(); + JSONObject content = new JSONObject(); content.put("name", "师傅" + newWorker.getName() + "将继续为您服务 不需要预约时间"); String oldName = oldWorker != null ? oldWorker.getName() : ""; - content.put("convert", oldName + "将订单转给" + newWorker.getName() ); + content.put("convert", oldName + "将订单转给" + newWorker.getName()); log.setContent(content.toString()); - log.setCreatedAt(new java.util.Date()); + log.setCreatedAt(new Date()); orderLogService.insertOrderLog(log); // 6. 查询所有日志并批量更新worker_id OrderLog queryLog = new OrderLog(); queryLog.setOid(order.getId()); - java.util.List logList = orderLogService.selectOrderLogList(queryLog); + List logList = orderLogService.selectOrderLogList(queryLog); for (OrderLog l : logList) { l.setWorkerId(newWorkerId); orderLogService.updateOrderLog(l); @@ -5042,7 +5124,7 @@ public class AppletController extends BaseController { * 返回结构见json.txt */ @PostMapping("/api/worker/index") - public AjaxResult getWorkerIndex(@RequestBody(required = false) Map params, HttpServletRequest request) { + public AjaxResult getWorkerIndex(@RequestBody Map params, HttpServletRequest request) { try { // 1. 校验token并获取师傅信息 String token = request.getHeader("token"); @@ -5058,7 +5140,7 @@ public class AppletController extends BaseController { Object levelInfo = null; String levelImg = null; if (user.getLevel() != null) { - com.ruoyi.system.domain.WorkerLevel level = workerLevelService.selectWorkerLevelById(Long.valueOf(user.getLevel())); + WorkerLevel level = workerLevelService.selectWorkerLevelById(Long.valueOf(user.getLevel())); if (level != null) { Map levelMap = new HashMap<>(); levelMap.put("id", level.getId()); @@ -5075,7 +5157,7 @@ public class AppletController extends BaseController { try { if (skillIdStr != null && !skillIdStr.trim().isEmpty()) { Long skillId = Long.valueOf(skillIdStr); - com.ruoyi.system.domain.SiteSkill skill = siteSkillService.selectSiteSkillById(skillId); + SiteSkill skill = siteSkillService.selectSiteSkillById(skillId); if (skill != null) { Map skillMap = new HashMap<>(); skillMap.put("id", skill.getId()); @@ -5083,7 +5165,8 @@ public class AppletController extends BaseController { skillArr.add(skillMap); } } - } catch (Exception ignore) {} + } catch (Exception ignore) { + } } // 4. 查询服务城市数组 List> cityArr = new ArrayList<>(); @@ -5092,7 +5175,7 @@ public class AppletController extends BaseController { try { if (cityIdStr != null && !cityIdStr.trim().isEmpty()) { Integer cityId = Integer.valueOf(cityIdStr); - com.ruoyi.system.domain.DiyCity city = diyCityService.selectDiyCityById(cityId); + DiyCity city = diyCityService.selectDiyCityById(cityId); if (city != null) { Map cityMap = new HashMap<>(); cityMap.put("id", city.getId()); @@ -5100,14 +5183,15 @@ public class AppletController extends BaseController { cityArr.add(cityMap); } } - } catch (Exception ignore) {} + } catch (Exception ignore) { + } } // 5. 统计评价 - com.ruoyi.system.domain.OrderComment commentQuery = new com.ruoyi.system.domain.OrderComment(); + OrderComment commentQuery = new OrderComment(); commentQuery.setWorkerId(user.getId()); - List commentList = orderCommentService.selectOrderCommentList(commentQuery); + List commentList = orderCommentService.selectOrderCommentList(commentQuery); int one = 0, two = 0, three = 0; - for (com.ruoyi.system.domain.OrderComment c : commentList) { + for (OrderComment c : commentList) { if (c.getNumType() != null) { if (c.getNumType() == 1L) one++; else if (c.getNumType() == 2L) two++; @@ -5127,27 +5211,34 @@ public class AppletController extends BaseController { userMap.put("service_city_arr", cityArr); userMap.put("level_img", levelImg); // 7. 处理分页和type筛选,默认参数 - if (params == null) params = new HashMap<>(); - 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; - int type = params.get("type") != null ? Integer.parseInt(params.get("type").toString()) : 0; - // 过滤type - List filteredList = new ArrayList<>(); - for (com.ruoyi.system.domain.OrderComment c : commentList) { - if (type == 0 || (type == 1 && c.getNumType() != null && c.getNumType() == 1L) - || (type == 2 && c.getNumType() != null && c.getNumType() == 2L) - || (type == 3 && c.getNumType() != null && c.getNumType() == 3L)) { - filteredList.add(c); + int page = 1; + int limit = 15; + int type = 0; + List filteredList = new ArrayList<>(); + if (params != null) { + params = new HashMap<>(); + page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1; + limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 15; + type = params.get("type") != null ? Integer.parseInt(params.get("type").toString()) : 0; + // 过滤type + for (OrderComment c : commentList) { + if (type == 0 || (type == 1 && c.getNumType() != null && c.getNumType() == 1L) + || (type == 2 && c.getNumType() != null && c.getNumType() == 2L) + || (type == 3 && c.getNumType() != null && c.getNumType() == 3L)) { + filteredList.add(c); + } } + }else{ + filteredList.addAll(commentList); } int totalCount = filteredList.size(); int from = (page - 1) * limit; int to = Math.min(from + limit, totalCount); List> commentArr = new ArrayList<>(); - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - java.text.SimpleDateFormat sdf2 = new java.text.SimpleDateFormat("yyyy年MM月dd日"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日"); for (int i = from; i < to; i++) { - com.ruoyi.system.domain.OrderComment c = filteredList.get(i); + OrderComment c = filteredList.get(i); Map cMap = new HashMap<>(); cMap.put("id", c.getId()); cMap.put("uid", c.getUid()); @@ -5223,7 +5314,8 @@ public class AppletController extends BaseController { /** * 师傅签到日志接口 - * @param params {year: "2025", month: "06"} + * + * @param params {year: "2025", month: "06"} * @param request * @return 签到日志列表 */ @@ -5247,22 +5339,22 @@ public class AppletController extends BaseController { String month = params.get("month").toString(); // 构造当月起止日期 String startDate = year + "-" + month + "-01"; - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd"); - java.util.Date start = sdf.parse(startDate); - java.util.Calendar cal = java.util.Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Date start = sdf.parse(startDate); + Calendar cal = Calendar.getInstance(); cal.setTime(start); - cal.set(java.util.Calendar.DAY_OF_MONTH, 1); - int maxDay = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH); - cal.set(java.util.Calendar.DAY_OF_MONTH, maxDay); - java.util.Date end = cal.getTime(); + cal.set(Calendar.DAY_OF_MONTH, 1); + int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); + cal.set(Calendar.DAY_OF_MONTH, maxDay); + Date end = cal.getTime(); // 查询签到记录 - com.ruoyi.system.domain.WorkerSign query = new com.ruoyi.system.domain.WorkerSign(); + WorkerSign query = new WorkerSign(); query.setUid(String.valueOf(user.getId())); - java.util.List allList = workerSignService.selectWorkerSignList(query); - java.util.List> result = new java.util.ArrayList<>(); - for (com.ruoyi.system.domain.WorkerSign sign : allList) { + List allList = workerSignService.selectWorkerSignList(query); + List> result = new ArrayList<>(); + for (WorkerSign sign : allList) { if (sign.getTime() != null && !sign.getTime().before(start) && !sign.getTime().after(end)) { - Map map = new java.util.HashMap<>(); + Map map = new HashMap<>(); map.put("id", sign.getId()); map.put("date", sdf.format(sign.getTime())); map.put("info", sign.getUname()); @@ -5277,7 +5369,8 @@ public class AppletController extends BaseController { /** * 师傅质保金日志接口 - * @param params {"limit":15,"page":1} + * + * @param params {"limit":15,"page":1} * @param request * @return 质保金日志分页数据和师傅信息 */ @@ -5297,15 +5390,15 @@ public class AppletController extends BaseController { 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; // 查询质保金日志 - com.ruoyi.system.domain.WorkerMarginLog query = new com.ruoyi.system.domain.WorkerMarginLog(); + WorkerMarginLog query = new WorkerMarginLog(); query.setUid(user.getId()); - com.github.pagehelper.PageHelper.startPage(page, limit); - java.util.List logList = workerMarginLogService.selectWorkerMarginLogList(query); - com.github.pagehelper.PageInfo pageInfo = new com.github.pagehelper.PageInfo<>(logList); - java.util.List> resultList = new java.util.ArrayList<>(); - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - for (com.ruoyi.system.domain.WorkerMarginLog log : logList) { - java.util.Map map = new java.util.HashMap<>(); + PageHelper.startPage(page, limit); + List logList = workerMarginLogService.selectWorkerMarginLogList(query); + PageInfo pageInfo = new PageInfo<>(logList); + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + for (WorkerMarginLog log : logList) { + Map map = new HashMap<>(); map.put("id", log.getId()); map.put("uid", log.getUid()); map.put("oid", log.getOid()); @@ -5316,7 +5409,7 @@ public class AppletController extends BaseController { resultList.add(map); } // 构建分页结构 - java.util.Map dataPage = new java.util.HashMap<>(); + Map dataPage = new HashMap<>(); dataPage.put("current_page", pageInfo.getPageNum()); dataPage.put("data", resultList); dataPage.put("first_page_url", "https://www.huafurenjia.cn/api/worker/mergin/log?page=1"); @@ -5324,20 +5417,20 @@ public class AppletController extends BaseController { dataPage.put("last_page", pageInfo.getPages()); dataPage.put("last_page_url", "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + pageInfo.getPages()); // links - java.util.List> links = new java.util.ArrayList<>(); - java.util.Map prevLink = new java.util.HashMap<>(); + List> links = new ArrayList<>(); + Map prevLink = new HashMap<>(); prevLink.put("url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + pageInfo.getPrePage() : null); prevLink.put("label", "« Previous"); prevLink.put("active", false); links.add(prevLink); for (int i = 1; i <= pageInfo.getPages(); i++) { - java.util.Map link = new java.util.HashMap<>(); + Map link = new HashMap<>(); link.put("url", "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + i); link.put("label", String.valueOf(i)); link.put("active", i == pageInfo.getPageNum()); links.add(link); } - java.util.Map nextLink = new java.util.HashMap<>(); + Map nextLink = new HashMap<>(); nextLink.put("url", pageInfo.isHasNextPage() ? "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + pageInfo.getNextPage() : null); nextLink.put("label", "Next »"); nextLink.put("active", false); @@ -5350,9 +5443,9 @@ public class AppletController extends BaseController { dataPage.put("to", pageInfo.getEndRow()); dataPage.put("total", pageInfo.getTotal()); // 构建user信息 - java.util.Map userMap = buildUserInfoResponse(user); + Map userMap = buildUserInfoResponse(user); // 最终返回结构 - java.util.Map data = new java.util.HashMap<>(); + Map data = new HashMap<>(); data.put("data", dataPage); data.put("user", userMap); return AjaxResult.success(data); @@ -5363,7 +5456,8 @@ public class AppletController extends BaseController { /** * 师傅收益明细接口 - * @param params {"limit":15,"page":1,"type":"1"} + * + * @param params {"limit":15,"page":1,"type":"1"} * @param request * @return 收益明细分页数据 */ @@ -5384,18 +5478,18 @@ public class AppletController extends BaseController { int limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 15; String type = params.get("type") != null ? params.get("type").toString() : null; // 查询收益明细 - com.ruoyi.system.domain.WorkerMoneyLog query = new com.ruoyi.system.domain.WorkerMoneyLog(); + WorkerMoneyLog query = new WorkerMoneyLog(); query.setWorkerId(user.getId()); if (type != null && !type.isEmpty()) { query.setType(Integer.valueOf(type)); } - com.github.pagehelper.PageHelper.startPage(page, limit); - java.util.List logList = workerMoneyLogService.selectWorkerMoneyLogList(query); - com.github.pagehelper.PageInfo pageInfo = new com.github.pagehelper.PageInfo<>(logList); - java.util.List> resultList = new java.util.ArrayList<>(); - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - for (com.ruoyi.system.domain.WorkerMoneyLog log : logList) { - java.util.Map map = new java.util.HashMap<>(); + PageHelper.startPage(page, limit); + List logList = workerMoneyLogService.selectWorkerMoneyLogList(query); + PageInfo pageInfo = new PageInfo<>(logList); + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + for (WorkerMoneyLog log : logList) { + Map map = new HashMap<>(); map.put("id", log.getId()); map.put("worker_id", log.getWorkerId()); map.put("oid", log.getOid()); @@ -5412,7 +5506,7 @@ public class AppletController extends BaseController { resultList.add(map); } // 构建分页结构 - java.util.Map dataPage = new java.util.HashMap<>(); + Map dataPage = new HashMap<>(); dataPage.put("current_page", pageInfo.getPageNum()); dataPage.put("data", resultList); dataPage.put("first_page_url", "https://www.huafurenjia.cn/api/worker/money/log?page=1"); @@ -5420,20 +5514,20 @@ public class AppletController extends BaseController { dataPage.put("last_page", pageInfo.getPages()); dataPage.put("last_page_url", "https://www.huafurenjia.cn/api/worker/money/log?page=" + pageInfo.getPages()); // links - java.util.List> links = new java.util.ArrayList<>(); - java.util.Map prevLink = new java.util.HashMap<>(); + List> links = new ArrayList<>(); + Map prevLink = new HashMap<>(); prevLink.put("url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/worker/money/log?page=" + pageInfo.getPrePage() : null); prevLink.put("label", "« Previous"); prevLink.put("active", false); links.add(prevLink); for (int i = 1; i <= pageInfo.getPages(); i++) { - java.util.Map link = new java.util.HashMap<>(); + Map link = new HashMap<>(); link.put("url", "https://www.huafurenjia.cn/api/worker/money/log?page=" + i); link.put("label", String.valueOf(i)); link.put("active", i == pageInfo.getPageNum()); links.add(link); } - java.util.Map nextLink = new java.util.HashMap<>(); + Map nextLink = new HashMap<>(); nextLink.put("url", pageInfo.isHasNextPage() ? "https://www.huafurenjia.cn/api/worker/money/log?page=" + pageInfo.getNextPage() : null); nextLink.put("label", "Next »"); nextLink.put("active", false); @@ -5454,7 +5548,8 @@ public class AppletController extends BaseController { /** * 师傅提现记录接口 * 查询当前师傅的提现记录,支持分页和类型筛选 - * @param params {"limit":15,"page":1,"type":2} + * + * @param params {"limit":15,"page":1,"type":2} * @param request HttpServletRequest * @return AjaxResult 分页提现记录 */ @@ -5513,4 +5608,608 @@ public class AppletController extends BaseController { } } + /** + * 师傅设置上门费接口 + * 参数:{"id":订单id,"price":金额} + * 逻辑:查找订单最新日志,设置workerCost和price,并设置paid=1 + */ + @PostMapping("/api/worker/set/price") + public AjaxResult setWorkerPrice(@RequestBody Map params) { + try { + 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("订单不存在"); + } + // 查询最新订单日志 + List logList = orderLogService.selectOrderLogByOrderId(order.getOrderId()); + if (logList == null || logList.isEmpty()) { + return AppletControllerUtil.appletWarning("订单日志不存在"); + } + OrderLog latestLog = logList.get(0); + latestLog.setWorkerCost(price); + latestLog.setPrice(price); + latestLog.setPaid(1L); + orderLogService.updateOrderLog(latestLog); + return AjaxResult.success("设置上门费成功"); + } catch (Exception e) { + return AppletControllerUtil.appletError("设置上门费失败:" + e.getMessage()); + } + } + + /** + * 师傅设置出发上门 + * GET /api/worker/start/door/{id} + * 逻辑参考OrderController的edit接口中jsonStatus=4的流程 + */ + @GetMapping("/api/worker/start/door/{id}") + public AjaxResult workerStartDoor(@PathVariable("id") Long id, HttpServletRequest request) { + // 1. 获取当前登录师傅ID(token在header) + 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("用户信息获取失败"); + } + Long workerId = user.getId(); + + // 2. 获取订单 + Order order = orderService.selectOrderById(id); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + if (!workerId.equals(order.getWorkerId())) { + return AppletControllerUtil.appletWarning("您不是该订单的师傅"); + } +// if (order.getStatus() == null || order.getStatus() != 2L) { +// return error("订单状态不正确"); +// } +// if (order.getJsonStatus() == null || order.getJsonStatus() != 3) { +// return error("订单进度不正确"); +// } + + // 3. 更新订单状态 + order.setJsonStatus(4); // 出发上门 + JSONObject typeJson = new JSONObject(); + typeJson.put("type", 3); + order.setLogJson(typeJson.toJSONString()); + + // 4. 写订单日志 + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setWorkerId(workerId); + orderLog.setTitle("师傅已出发"); + orderLog.setType(new BigDecimal("3.0")); + JSONObject content = new JSONObject(); + content.put("name", "师傅已出发"); + orderLog.setContent(content.toJSONString()); + + // 5. 保存 + orderService.updateOrder(order); + orderLogService.insertOrderLog(orderLog); + return AppletControllerUtil.appletSuccess("出发上门成功"); + } + + /** + * 师傅确认到达(新版,校验手机号后两位) + * POST /api/worker/confirm/door + * 参数:{id: 订单id, phone_two: 用户手机号后两位} + */ + @PostMapping("/api/worker/confirm/door") + public AjaxResult workerConfirmDoor(@RequestBody Map params, HttpServletRequest request) { + // 1. 获取参数 + if (params == null || !params.containsKey("id") || !params.containsKey("phone_two")) { + return AppletControllerUtil.appletWarning("参数不完整"); + } + Long id; + try { + id = Long.valueOf(params.get("id").toString()); + } catch (Exception e) { + return AppletControllerUtil.appletWarning("订单ID格式错误"); + } + String phoneTwo = params.get("phone_two").toString(); + if (phoneTwo.length() != 2) { + return AppletControllerUtil.appletWarning("请输入手机号后两位"); + } + + // 2. 获取当前登录师傅ID(token在header) + 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("用户信息获取失败"); + } + Long workerId = user.getId(); + + // 3. 获取订单 + Order order = orderService.selectOrderById(id); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + if (!workerId.equals(order.getWorkerId())) { + return AppletControllerUtil.appletWarning("您不是该订单的师傅"); + } + // 校验用户手机号后两位 + String userPhone = order.getPhone(); + if (userPhone == null || userPhone.length() < 2) { + return AppletControllerUtil.appletWarning("用户手机号无效"); + } + String lastTwo = userPhone.substring(userPhone.length() - 2); + if (!phoneTwo.equals(lastTwo)) { + return AppletControllerUtil.appletWarning("手机号后两位不正确"); + } + + // 4. 更新订单状态 + order.setJsonStatus(5); // 确认到达 + JSONObject typeJson = new JSONObject(); + typeJson.put("type", 4); + order.setLogJson(typeJson.toJSONString()); + + // 5. 写订单日志 + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setWorkerId(workerId); + orderLog.setTitle("师傅已到达"); + orderLog.setType(new BigDecimal("4.0")); + JSONObject content = new JSONObject(); + content.put("name", "师傅已到达"); + orderLog.setContent(content.toJSONString()); + + // 6. 保存 + orderService.updateOrder(order); + orderLogService.insertOrderLog(orderLog); + return AppletControllerUtil.appletSuccess("确认到达成功"); + } + + /** + * 获取基检项目 + * 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("商品不存在"); + } + 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); + } + + /** + * 报价获取服务项目 + * GET /api/worker/quote/craft/{goodsId} + * 返回格式参考json.txt + */ + @GetMapping("/api/worker/quote/craft/{goodsId}") + public Object getWorkerQuoteCraft(@PathVariable("goodsId") Long goodsId) { + // 1. 查询商品基本信息 + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodsId); + if (serviceGoods == null) { + return AppletControllerUtil.appletError("商品不存在"); + } + // 2. 查询服务分类(IQuoteTypeService) + QuoteType typeQuery = new QuoteType(); + typeQuery.setGoodId("\"" + goodsId + "\""); + List typeList = quoteTypeService.selectQuoteTypeList(typeQuery); + List dataArr = new ArrayList<>(); + for (QuoteType type : typeList) { + Map typeMap = new HashMap<>(); + typeMap.put("id", type.getId()); + typeMap.put("title", type.getTitle()); + // 3. 查询工艺(IQuoteCraftService) + QuoteCraft craftQuery = new QuoteCraft(); + craftQuery.setTypeId("[\"" + type.getId() + "\"]"); + List craftList = quoteCraftService.selectQuoteCraftList(craftQuery); + List> craftArr = new ArrayList<>(); + for (QuoteCraft craft : craftList) { + Map craftMap = new HashMap<>(); + craftMap.put("id", craft.getId()); + craftMap.put("title", craft.getTitle()); + craftMap.put("price", craft.getPrice() != null ? craft.getPrice().toString() : "0.00"); + craftMap.put("unit", craft.getUnit()); + // type_id为数组,需解析 + List typeIdList = new ArrayList<>(); + String typeIdStr = craft.getTypeId(); + if (typeIdStr != null && typeIdStr.trim().startsWith("[") && typeIdStr.trim().endsWith("]")) { + try { + typeIdList = JSON.parseArray(typeIdStr, String.class); + } catch (Exception e) { + typeIdList.add(typeIdStr); + } + } else if (typeIdStr != null) { + typeIdList.add(typeIdStr); + } + craftMap.put("type_id", typeIdList); + craftArr.add(craftMap); + } + typeMap.put("craft", craftArr); + dataArr.add(typeMap); + } + Map result = new HashMap<>(); + result.put("data", dataArr); + result.put("code", 200); + result.put("msg", "OK"); + return result; + } + + /** + * 报价所需物料查询 + * GET /api/worker/quote/material/{goodsId} + * 返回格式参考json.txt + */ + @GetMapping("/api/worker/quote/material/{goodsId}") + public Object getWorkerQuoteMaterial(@PathVariable("goodsId") Long goodsId) { + // 1. 查询商品基本信息 + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodsId); + if (serviceGoods == null) { + return AppletControllerUtil.appletError("商品不存在"); + } + // 2. 查询物料分类(IQuoteMaterialTypeService) + QuoteMaterialType typeQuery = new QuoteMaterialType(); + typeQuery.setGoodId("\"" + goodsId + "\""); + List typeList = quoteMaterialTypeService.selectQuoteMaterialTypeList(typeQuery); + List dataArr = new ArrayList<>(); + for (QuoteMaterialType type : typeList) { + Map typeMap = new HashMap<>(); + typeMap.put("id", type.getId()); + typeMap.put("title", type.getTitle()); + // 3. 查询物料信息(IQuoteMaterialService) + QuoteMaterial materialQuery = new QuoteMaterial(); + materialQuery.setTypeId("\"" + type.getId() + "\""); + List materialList = quoteMaterialService.selectQuoteMaterialList(materialQuery); + List> materialArr = new ArrayList<>(); + for (QuoteMaterial material : materialList) { + Map materialMap = new HashMap<>(); + materialMap.put("id", material.getId()); + materialMap.put("title", material.getTitle()); + materialMap.put("price", material.getPrice() != null ? material.getPrice().toString() : "0.00"); + materialMap.put("unit", material.getUnit()); + // type_id为数组,需解析 + List typeIdList = new ArrayList<>(); + String typeIdStr = material.getTypeId(); + if (typeIdStr != null && typeIdStr.trim().startsWith("[") && typeIdStr.trim().endsWith("]")) { + try { + typeIdList = JSON.parseArray(typeIdStr, String.class); + } catch (Exception e) { + typeIdList.add(typeIdStr); + } + } else if (typeIdStr != null) { + typeIdList.add(typeIdStr); + } + materialMap.put("type_id", typeIdList); + materialArr.add(materialMap); + } + typeMap.put("material", materialArr); + dataArr.add(typeMap); + } + Map result = new HashMap<>(); + result.put("data", dataArr); + result.put("code", 200); + result.put("msg", "OK"); + return result; + } + + /** + * 师傅报价接口 + * POST /api/worker/estimate + * 参数格式参考json.txt + */ + @PostMapping("/api/worker/estimate") + public AjaxResult workerEstimate(@RequestBody Map params, HttpServletRequest request) { + if (params == null) { + return AppletControllerUtil.appletError("参数错误"); + } + // 1. 计算金额 + BigDecimal totalPrice = BigDecimal.ZERO; + List> craftList = (List>) params.get("craft"); + if (craftList != null) { + for (Map craft : craftList) { + Long craftId = null; + try { + craftId = Long.valueOf(craft.get("id").toString()); + } catch (Exception ignore) { + } + if (craftId != null) { + QuoteCraft quoteCraft = quoteCraftService.selectQuoteCraftById(craftId); + if (quoteCraft != null) { + BigDecimal price = new BigDecimal(craft.get("price").toString()); + Integer count = craft.get("count") == null ? 1 : Integer.parseInt(craft.get("count").toString()); + totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(count))); + } + } + } + } + List> materialList = (List>) params.get("material"); + if (materialList != null) { + for (Map material : materialList) { + Long materialId = null; + try { + materialId = Long.valueOf(material.get("id").toString()); + } catch (Exception ignore) { + } + if (materialId != null) { + QuoteMaterial quoteMaterial = quoteMaterialService.selectQuoteMaterialById(materialId); + if (quoteMaterial != null) { + BigDecimal price = new BigDecimal(material.get("price").toString()); + Integer count = material.get("count") == null ? 1 : Integer.parseInt(material.get("count").toString()); + totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(count))); + } + } + } + } + // 2. 组装新json + Map resultJson = new LinkedHashMap<>(); + // project + Map project = new LinkedHashMap<>(); + project.put("name", "项目费用"); + project.put("price", totalPrice); + resultJson.put("project", project); + // basic + resultJson.put("basic", params.get("basic")); + // craft + List> craftListNew = new ArrayList<>(); + if (craftList != null) { + for (Map craft : craftList) { + Map item = new LinkedHashMap<>(); + item.put("name", craft.get("title") != null ? craft.get("title") : craft.get("name")); + item.put("price", craft.get("price")); + item.put("count", craft.get("count")); + craftListNew.add(item); + } + } + resultJson.put("craft", craftListNew); + // material + List> materialListNew = new ArrayList<>(); + if (materialList != null) { + for (Map material : materialList) { + Map item = new LinkedHashMap<>(); + item.put("name", material.get("title") != null ? material.get("title") : material.get("name")); + item.put("price", material.get("price")); + item.put("count", material.get("count")); + materialListNew.add(item); + } + } + resultJson.put("material", materialListNew); + // 3. 转为字符串 + String contentStr = JSONObject.toJSONString(resultJson); + // 4. 订单相关处理 + Long orderId = null; + if (params.get("id") != null) { + try { + orderId = Long.valueOf(params.get("id").toString()); + } catch (Exception ignore) { + } + } + if (orderId == null) { + return AppletControllerUtil.appletError("订单ID格式错误"); + } + Order order = orderService.selectOrderById(orderId); + if (order == null) { + return AppletControllerUtil.appletError("订单不存在"); + } + order.setJsonStatus(6); + order.setLogJson(contentStr); + order.setTotalPrice(totalPrice); + order.setUpdatedAt(new Date()); + int update = orderService.updateOrder(order); + if (update > 0) { + OrderLog log = new OrderLog(); + log.setOid(order.getId()); + log.setTitle("已检查评估报价"); + log.setPrice(totalPrice); + log.setPaid(1l); + log.setWorkerCost(totalPrice); + log.setReductionPrice(BigDecimal.ZERO); + log.setWorkerLogId(order.getWorkerId()); + log.setWorkerId(order.getWorkerId()); + log.setOrderId(order.getOrderId()); + log.setType(new BigDecimal(5)); + log.setContent(contentStr); + log.setCreatedAt(new Date()); + orderLogService.insertOrderLog(log); + return AppletControllerUtil.appletSuccess("报价成功"); + } else { + return AppletControllerUtil.appletError("报价失败"); + } + } + + /** + * 师傅开始服务接口 + * POST /api/worker/do/service + * 参数:{"oid":订单id,"image":[图片url数组]} + */ + @PostMapping("/api/worker/do/service") + public AjaxResult workerDoService(@RequestBody Map params, HttpServletRequest request) { + Long oid = 0L; + if (params.get("oid") != null) { + try { + oid = Long.valueOf(params.get("oid").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 (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) { + + 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); + } + + } + return AppletControllerUtil.appletSuccess("操作成功"); + } + } + return AppletControllerUtil.appletSuccess("操作成功"); + } + + /** + * 师傅完成订单接口 + * POST /api/worker/finish/service + * 参数:{"id":订单id,"image":[图片url数组]} + */ + @PostMapping("/api/worker/finish/service") + public AjaxResult workerFinishService(@RequestBody Map params, HttpServletRequest request) { + if (params == null || params.get("id") == null) { + return AppletControllerUtil.appletError("参数错误"); + } + Long id; + try { + id = Long.valueOf(params.get("id").toString()); + } catch (Exception e) { + return AppletControllerUtil.appletError("订单ID格式错误"); + } + Order order = orderService.selectOrderById(id); + if (order == null) { + return AppletControllerUtil.appletError("订单不存在"); + } + // 1. 修改订单状态 + order.setStatus(6L); // 完成 + order.setReceiveType(3L); // 完成类型 + order.setJsonStatus(9); // 完成 + order.setLogJson("{\"type\":8}"); + order.setUpdatedAt(new Date()); + int update = orderService.updateOrder(order); + if (update > 0) { + // 2. 组装日志内容 + Map logContent = new LinkedHashMap<>(); + logContent.put("name", "师傅服务完成"); + logContent.put("image", params.get("image")); + String contentStr = com.alibaba.fastjson2.JSONObject.toJSONString(logContent); + // 3. 写入订单日志 + OrderLog log = new OrderLog(); + log.setOid(order.getId()); + log.setOrderId(order.getOrderId()); + log.setTitle("服务完成"); + log.setType(new java.math.BigDecimal(7)); + log.setContent(contentStr); + log.setWorkerId(order.getWorkerId()); + log.setCreatedAt(new Date()); + orderLogService.insertOrderLog(log); + return AppletControllerUtil.appletSuccess("服务已完成"); + } else { + return AppletControllerUtil.appletError("操作失败"); + } + } } 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 12585b7..d7f472c 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 @@ -1,11 +1,13 @@ package com.ruoyi.system.ControllerUtil; +import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.ruoyi.system.domain.ServiceCate; import com.ruoyi.system.domain.ServiceGoods; import com.ruoyi.system.domain.Users; import com.ruoyi.system.service.IServiceGoodsService; import com.ruoyi.system.service.IUsersService; +import com.github.pagehelper.PageInfo; import java.util.ArrayList; import java.util.HashMap; @@ -129,7 +131,24 @@ public class AppletControllerUtil { result.put("data", new java.util.ArrayList<>()); return result; } - + /** + * 判断字符串是否能转换为 JSONArray + * + * @param str 需要判断的字符串 + * @return 如果是合法的JSON数组字符串,返回 true;否则返回 false + */ + public static boolean canParseToJSONArray(String str) { + if (str == null || str.trim().isEmpty()) { + return false; + } + try { + Object obj = JSON.parse(str); + return obj instanceof JSONArray; + } catch (Exception e) { + // 解析失败,不是合法的JSON数组 + return false; + } + } /** * 服务商品详情响应实体类 * @@ -2633,4 +2652,48 @@ public class AppletControllerUtil { return goodsData; } + + /** + * 构建分页响应结构,适用于小程序worker相关接口 + * @param pageInfo PageInfo对象 + * @param dataList 数据列表 + * @param baseUrl 分页url前缀 + * @return Map分页结构 + */ + public static Map buildPageResult(PageInfo pageInfo, List dataList, String baseUrl) { + Map dataPage = new HashMap<>(); + dataPage.put("current_page", pageInfo.getPageNum()); + dataPage.put("data", dataList); + dataPage.put("first_page_url", baseUrl + "?page=1"); + dataPage.put("from", pageInfo.getStartRow()); + dataPage.put("last_page", pageInfo.getPages()); + dataPage.put("last_page_url", baseUrl + "?page=" + pageInfo.getPages()); + // links + List> links = new ArrayList<>(); + Map prevLink = new HashMap<>(); + prevLink.put("url", pageInfo.isHasPreviousPage() ? baseUrl + "?page=" + pageInfo.getPrePage() : null); + prevLink.put("label", "« Previous"); + prevLink.put("active", false); + links.add(prevLink); + for (int i = 1; i <= pageInfo.getPages(); i++) { + Map link = new HashMap<>(); + link.put("url", baseUrl + "?page=" + i); + link.put("label", String.valueOf(i)); + link.put("active", i == pageInfo.getPageNum()); + links.add(link); + } + Map nextLink = new HashMap<>(); + nextLink.put("url", pageInfo.isHasNextPage() ? baseUrl + "?page=" + pageInfo.getNextPage() : null); + nextLink.put("label", "Next »"); + nextLink.put("active", false); + links.add(nextLink); + dataPage.put("links", links); + dataPage.put("next_page_url", pageInfo.isHasNextPage() ? baseUrl + "?page=" + pageInfo.getNextPage() : null); + dataPage.put("path", baseUrl); + dataPage.put("per_page", pageInfo.getPageSize()); + dataPage.put("prev_page_url", pageInfo.isHasPreviousPage() ? baseUrl + "?page=" + pageInfo.getPrePage() : null); + dataPage.put("to", pageInfo.getEndRow()); + dataPage.put("total", pageInfo.getTotal()); + return dataPage; + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/HttpsService.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/HttpsService.java new file mode 100644 index 0000000..665a397 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/HttpsService.java @@ -0,0 +1,75 @@ +package com.ruoyi.system.ControllerUtil; + +import com.winnerlook.service.https.MyVerifyHostname; +import com.winnerlook.service.https.MyX509TrustManager; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.BufferedHttpEntity; +import org.apache.http.entity.StringEntity; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.entity.mime.content.FileBody; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import java.io.File; +import java.net.URI; + + +public class HttpsService { + + private SSLContext sslContext; + private X509TrustManager tm; + private CloseableHttpClient httpClient; + + public HttpsService() + throws Exception { + sslContext = SSLContext.getInstance("TLS"); + tm = new MyX509TrustManager(); + sslContext.init(null, new TrustManager[]{tm}, + new java.security.SecureRandom()); + httpClient = HttpClients.custom() + .setSSLHostnameVerifier(new MyVerifyHostname()) + .setSSLContext(sslContext).build(); + } + + + + public String doPost(String path, String headerStr, + String requestBody, String encoding) throws Exception { + String resultString = ""; + CloseableHttpResponse response = null; + HttpPost httpPost = null; + try { + URI uri = new URI(path); + httpPost = new HttpPost(uri); + httpPost.setHeader("Content-type", "application/json; charset=utf-8"); + + /** 报文头中设置Authorization参数*/ + httpPost.setHeader("Authorization", headerStr); + + /** 设置请求报文体*/ + httpPost.setEntity(new StringEntity(requestBody, encoding)); + + response = httpClient.execute(httpPost); + HttpEntity httpEntity = response.getEntity(); + httpEntity = new BufferedHttpEntity(httpEntity); + resultString = EntityUtils.toString(httpEntity); + } catch (Exception e) { + throw e; + } finally { //释放连接 + + if (null != response) + response.close(); + if (httpPost != null) + httpPost.releaseConnection(); + + } + return resultString; + } + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderLogHandler.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderLogHandler.java index 20195c9..adc7684 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderLogHandler.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderLogHandler.java @@ -223,6 +223,7 @@ public class OrderLogHandler { updateOrderAcceptInfo(order, orderLog); orderLog.setFirstWorkerId(orderLog.getWorkerId()); + //orderLog.setWorkerId(order.getOrderLog().getWorkerId()); orderLog.setIsPause(1); orderLog.setTitle(TITLE_3); orderLog.setType(new BigDecimal("2.0")); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/PublicSendApiUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/PublicSendApiUtil.java new file mode 100644 index 0000000..286023b --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/PublicSendApiUtil.java @@ -0,0 +1,131 @@ +package com.ruoyi.system.ControllerUtil; + +import com.alibaba.fastjson2.JSONObject; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; +import java.util.StringJoiner; + +/** + * 通用第三方接口请求工具类 + * 支持GET和POST请求,支持自定义Header、请求体、URL参数等 + * 可扩展、可复用,适用于各种第三方接口调用场景 + */ +public class PublicSendApiUtil { + + /** + * 发送GET请求 + * @param urlStr 请求地址 + * @param headers 请求头参数(可为null) + * @param params URL参数(可为null) + * @return 响应内容 + * @throws Exception 异常 + */ + public static String sendGet(String urlStr, Map headers, Map params) throws Exception { + // 拼接URL参数 + if (params != null && !params.isEmpty()) { + StringJoiner sj = new StringJoiner("&"); + for (Map.Entry entry : params.entrySet()) { + sj.add(URLEncoder.encode(entry.getKey(), "UTF-8") + "=" + URLEncoder.encode(entry.getValue(), "UTF-8")); + } + urlStr += urlStr.contains("?") ? "&" + sj.toString() : "?" + sj.toString(); + } + URL url = new URL(urlStr); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + // 设置请求头 + if (headers != null) { + for (Map.Entry entry : headers.entrySet()) { + conn.setRequestProperty(entry.getKey(), entry.getValue()); + } + } + conn.setDoInput(true); + // 读取响应 + int code = conn.getResponseCode(); + InputStream is = (code == 200) ? conn.getInputStream() : conn.getErrorStream(); + StringBuilder sb = new StringBuilder(); + byte[] buf = new byte[1024]; + int len; + while ((len = is.read(buf)) != -1) { + sb.append(new String(buf, 0, len, StandardCharsets.UTF_8)); + } + is.close(); + return sb.toString(); + } + + /** + * 发送POST请求 + * @param urlStr 请求地址 + * @param headers 请求头参数(可为null) + * @param params URL参数(可为null) + * @param body 请求体内容(可为null,通常为JSON字符串或表单数据) + * @return 响应内容 + * @throws Exception 异常 + */ + public static String sendPost(String urlStr, Map headers, Map params, String body) throws Exception { + // 拼接URL参数 + if (params != null && !params.isEmpty()) { + StringJoiner sj = new StringJoiner("&"); + for (Map.Entry entry : params.entrySet()) { + sj.add(URLEncoder.encode(entry.getKey(), "UTF-8") + "=" + URLEncoder.encode(entry.getValue(), "UTF-8")); + } + urlStr += urlStr.contains("?") ? "&" + sj.toString() : "?" + sj.toString(); + } + URL url = new URL(urlStr); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("POST"); + // 设置请求头 + if (headers != null) { + for (Map.Entry entry : headers.entrySet()) { + conn.setRequestProperty(entry.getKey(), entry.getValue()); + } + } + conn.setDoOutput(true); + conn.setDoInput(true); + // 写入请求体 + if (body != null) { + try (OutputStream os = conn.getOutputStream()) { + os.write(body.getBytes(StandardCharsets.UTF_8)); + } + } + + System.out.println(conn); + + // 读取响应 + int code = conn.getResponseCode(); + InputStream is = (code == 000000) ? conn.getInputStream() : conn.getErrorStream(); + StringBuilder sb = new StringBuilder(); + byte[] buf = new byte[1024]; + int len; + while ((len = is.read(buf)) != -1) { + sb.append(new String(buf, 0, len, StandardCharsets.UTF_8)); + } + is.close(); + return sb.toString(); + } + + /** + * 示例:如何使用该工具类发送GET和POST请求 + */ + public static void main(String[] args) throws Exception { + // GET请求示例 + Map headers = new HashMap<>(); + headers.put("Accept", "application/json"); + Map params = new HashMap<>(); + params.put("q", "test"); + String getResult = sendGet("https://httpbin.org/get", headers, params); + System.out.println("GET结果:" + getResult); + + // POST请求示例 + headers.put("Content-Type", "application/json"); + String postBody = "{\"name\":\"张三\"}"; + String postResult = sendPost("https://httpbin.org/post", headers, null, postBody); + System.out.println("POST结果:" + postResult); + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WXsendMsgUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WXsendMsgUtil.java new file mode 100644 index 0000000..1fdfe4d --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WXsendMsgUtil.java @@ -0,0 +1,100 @@ +package com.ruoyi.system.ControllerUtil; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; + +/** + * 微信小程序通知消息推送工具类 + * 支持获取access_token、发送订阅消息等功能 + * 适用于Controller、Service等各层直接调用 + */ +public class WXsendMsgUtil { + + // 微信小程序的AppID和AppSecret(请替换为你自己的) + private static final String APPID = "YOUR_APPID"; + private static final String APPSECRET = "YOUR_APPSECRET"; + + /** + * 获取微信小程序全局唯一后台接口调用凭据 access_token + * @return access_token字符串 + * @throws Exception 异常 + */ + public static String getAccessToken() throws Exception { + String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + APPID + "&secret=" + APPSECRET; + HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); + conn.setRequestMethod("GET"); + conn.setDoInput(true); + InputStream is = conn.getInputStream(); + StringBuilder sb = new StringBuilder(); + byte[] buf = new byte[1024]; + int len; + while ((len = is.read(buf)) != -1) { + sb.append(new String(buf, 0, len, StandardCharsets.UTF_8)); + } + is.close(); + JSONObject json = JSONObject.parseObject(sb.toString()); + return json.getString("access_token"); + } + + /** + * 发送微信小程序订阅消息 + * @param accessToken access_token + * @param touser 接收者openid + * @param templateId 模板ID + * @param page 跳转页面(可选) + * @param data 模板内容(Map,如{"thing1":{"value":"内容"}}) + * @return 微信接口响应 + * @throws Exception 异常 + */ + public static String sendSubscribeMsg(String accessToken, String touser, String templateId, String page, Map data) throws Exception { + String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + accessToken; + Map param = new HashMap<>(); + param.put("touser", touser); + param.put("template_id", templateId); + if (page != null && !page.isEmpty()) { + param.put("page", page); + } + param.put("data", data); + String body = JSON.toJSONString(param); + HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); + conn.setDoOutput(true); + try (OutputStream os = conn.getOutputStream()) { + os.write(body.getBytes(StandardCharsets.UTF_8)); + } + InputStream is = conn.getInputStream(); + StringBuilder sb = new StringBuilder(); + byte[] buf = new byte[1024]; + int len; + while ((len = is.read(buf)) != -1) { + sb.append(new String(buf, 0, len, StandardCharsets.UTF_8)); + } + is.close(); + return sb.toString(); + } + + /** + * 示例:如何推送微信小程序订阅消息 + */ + public static void main(String[] args) throws Exception { + // 1. 获取access_token + String accessToken = getAccessToken(); + // 2. 组装消息内容 + Map data = new HashMap<>(); + Map thing1 = new HashMap<>(); + thing1.put("value", "测试内容"); + data.put("thing1", thing1); + // 3. 发送消息 + String result = sendSubscribeMsg(accessToken, "OPENID", "TEMPLATE_ID", "pages/index/index", data); + System.out.println("推送结果:" + result); + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/YunXinPhoneUtilAPI.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/YunXinPhoneUtilAPI.java new file mode 100644 index 0000000..b43e435 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/YunXinPhoneUtilAPI.java @@ -0,0 +1,187 @@ +package com.ruoyi.system.ControllerUtil; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.winnerlook.model.*; +import com.winnerlook.util.Base64; +import com.winnerlook.util.MD5Util; + +import java.util.LinkedHashMap; + +/** + * 云信小号相关API工具类 + *

+ * 封装了云信小号的AX、AXB绑定、解绑、语音通知等接口的调用方法。 + * 统一了签名、鉴权、请求体组装等流程,便于业务系统直接调用。 + *

+ *

+ * 依赖: + * - fastjson2 用于JSON序列化/反序列化 + * - com.winnerlook.model.* 需包含请求/响应体相关POJO + * - com.winnerlook.util.Base64、MD5Util 用于加密 + *

+ *

+ * 使用前请确保相关依赖和配置已正确引入。 + *

+ */ +public class YunXinPhoneUtilAPI { + + private static final String APP_ID = "256339"; + private static final String TOKEN = "ecf5ae04c52b4d85a0e4255d7d0ebb71"; + + // 云信接口地址常量 + private static final String UNBIND_URL = "https://101.37.133.245:11008/voice/1.0.0/middleNumberUnbind"; + private static final String NOTIFY_URL = "https://101.37.133.245:11008/voice/1.0.0/notify"; + private static final String AXB_URL = "https://101.37.133.245:11008/voice/1.0.0/middleNumberAXB"; + + // 回调地址常量(可通过set方法动态设置) + private static String AXB_CALLBACK_URL = ""; + private static String NOTIFY_CALLBACK_URL = ""; + + /** + * 设置AXB绑定的回调URL + */ + public static void setAxbCallbackUrl(String callbackUrl) { + AXB_CALLBACK_URL = callbackUrl; + } + + /** + * 设置语音通知的回调URL + */ + public static void setNotifyCallbackUrl(String callbackUrl) { + NOTIFY_CALLBACK_URL = callbackUrl; + } + + /** + * 语音通知接口调用 + * @param phone 通知目标手机号 + * @param templateID 语音通知模板ID + * @return VoiceResponseResult 结果对象 + * @throws Exception 异常 + *

回调地址使用 NOTIFY_CALLBACK_URL 常量,如需动态设置请调用 setNotifyCallbackUrl 方法

+ */ + public static VoiceResponseResult httpsAxbTransfer(String phone, String templateID) throws Exception { + VoiceResponseResult resultObj = new VoiceResponseResult(); + String url = NOTIFY_URL; + try { + // 组装请求体 + VoiceNotifyBody transfer = new VoiceNotifyBody(); + transfer.setCalleeNumber(phone); + transfer.setTemplateId(templateID); + transfer.setTemplateArgs(new LinkedHashMap()); // 可根据需要传递参数 + transfer.setCallbackUrl(NOTIFY_CALLBACK_URL); + + // 获取当前时间戳 + long timestamp = System.currentTimeMillis(); + // 生成鉴权参数 + String authorization = Base64.encodeBase64(APP_ID + ":" + timestamp); + String sig = MD5Util.getMD5(APP_ID + TOKEN + timestamp); + // 拼接最终URL + url = url + "/" + APP_ID + "/" + sig; + String body = JSON.toJSONString(transfer); + + // 调用HTTPS服务 + HttpsService httpsService = new HttpsService(); + String result = httpsService.doPost(url, authorization, body, "UTF-8"); + JSONObject rjson = JSONObject.parseObject(result); + resultObj.setCallId(rjson.getString("callId")); + resultObj.setResult(rjson.getString("result")); + resultObj.setMessage(rjson.getString("message")); + } catch (Exception e) { + System.out.println("[YunXinPhoneUtilAPI] 语音通知异常: " + e.getMessage()); + throw e; + } + return resultObj; + } + + /** + * AXB绑定接口调用 + * 提前绑定小号号码、号码A、号码B的关系,A、B呼叫小号即可互相通话。 + * @param minphone 隐私小号(X号) + * @param phoneA 号码A + * @param phoneB 号码B + * @return VoiceResponseResult 结果对象 + * @throws Exception 异常 + *

回调地址使用 AXB_CALLBACK_URL 常量,如需动态设置请调用 setAxbCallbackUrl 方法

+ */ + public static VoiceResponseResult httpsPrivacyBindAxb(String minphone, String phoneA, String phoneB) throws Exception { + String url = AXB_URL; + VoiceResponseResult resultObj = new VoiceResponseResult(); + try { + PrivacyBindBodyAxb bindBodyAxb = new PrivacyBindBodyAxb(); + // 组装请求体 + bindBodyAxb.setMiddleNumber(minphone); + bindBodyAxb.setBindNumberA(phoneA); + bindBodyAxb.setBindNumberB(phoneB); + bindBodyAxb.setCallRec(0); // 1:开启录音,0:关闭 + bindBodyAxb.setMaxBindingTime(3600); // 有效时长(秒),为空表示永久 + bindBodyAxb.setPassthroughCallerToA(0); // 0:不透传; 1:透传 + bindBodyAxb.setPassthroughCallerToB(0); // 0:不透传; 1:透传 + bindBodyAxb.setCallbackUrl(AXB_CALLBACK_URL); + + long timestamp = System.currentTimeMillis(); + String authorization = Base64.encodeBase64(APP_ID + ":" + timestamp); + String sig = MD5Util.getMD5(APP_ID + TOKEN + timestamp); + url = url + "/" + APP_ID + "/" + sig; + String body = JSON.toJSONString(bindBodyAxb); + + HttpsService httpsService = new HttpsService(); + String result = httpsService.doPost(url, authorization, body, "UTF-8"); + JSONObject rjson = JSONObject.parseObject(result); + resultObj.setCallId(rjson.getString("callId")); + resultObj.setResult(rjson.getString("result")); + resultObj.setMessage(rjson.getString("message")); + System.out.println(result); + } catch (Exception e) { + System.out.println("[YunXinPhoneUtilAPI] AXB绑定异常: " + e.getMessage()); + throw e; + } + return resultObj; + } + + /** + * 解绑接口调用 + * 解绑指定小号与A、B号码的绑定关系 + * @param phoneA 号码A + * @param phoneB 号码B + * @param phone 隐私小号(X号) + * @return VoiceResponseResult 结果对象 + * @throws Exception 异常 + */ + public static VoiceResponseResult httpsPrivacyUnbind(String phoneA, String phoneB, String phone) throws Exception { + VoiceResponseResult resultObj = new VoiceResponseResult(); + String url = UNBIND_URL; + try { + PrivacyUnbindBody unbindBody = new PrivacyUnbindBody(); + long timestamp = System.currentTimeMillis(); + unbindBody.setMiddleNumber(phone); + unbindBody.setBindNumberA(phoneA); + unbindBody.setBindNumberB(phoneB); + String authorization = Base64.encodeBase64(APP_ID + ":" + timestamp); + String sig = MD5Util.getMD5(APP_ID + TOKEN + timestamp); + url = url + "/" + APP_ID + "/" + sig; + String body = JSON.toJSONString(unbindBody); + HttpsService httpsService = new HttpsService(); + String result = httpsService.doPost(url, authorization, body, "UTF-8"); + JSONObject rjson = JSONObject.parseObject(result); + resultObj.setResult(rjson.getString("result")); + resultObj.setMessage(rjson.getString("message")); + } catch (Exception e) { + System.out.println("[YunXinPhoneUtilAPI] 解绑异常: " + e.getMessage()); + throw e; + } + return resultObj; + } + + /** + * main方法示例:解绑操作 + */ + public static void main(String[] args) throws Exception { + // 设置回调地址(如有需要) + setAxbCallbackUrl("http://your-callback-url.com/axb"); + setNotifyCallbackUrl("http://your-callback-url.com/notify"); + // 示例:解绑操作 + VoiceResponseResult res = httpsPrivacyUnbind("18339212639", "15270824290", "15695650664"); + System.out.println("解绑结果:" + JSON.toJSONString(res)); + } +} diff --git a/ruoyi-system/src/main/resources/mapper/system/OrderLogMapper.xml b/ruoyi-system/src/main/resources/mapper/system/OrderLogMapper.xml index 98bb002..1e2ec46 100644 --- a/ruoyi-system/src/main/resources/mapper/system/OrderLogMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/OrderLogMapper.xml @@ -84,7 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" diff --git a/ruoyi-system/src/main/resources/mapper/system/QuoteMaterialMapper.xml b/ruoyi-system/src/main/resources/mapper/system/QuoteMaterialMapper.xml index af2f4ec..bec52f9 100644 --- a/ruoyi-system/src/main/resources/mapper/system/QuoteMaterialMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/QuoteMaterialMapper.xml @@ -25,7 +25,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and good_id like concat('%', #{goodId}, '%') - and type_id in (select b.id from quote_material_type b where b.title like concat('%', #{typeId}, '%') ) + and type_id like concat('%', #{typeId}, '%') and title like concat('%', #{title}, '%')