diff --git a/package-lock.json b/package-lock.json index f139f89..b31d541 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "RuoYi-Vue-master", + "name": "202508091038", "lockfileVersion": 2, "requires": true, "packages": { 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 d0a9500..c7283cb 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 @@ -127,1687 +127,6 @@ public class AppletController extends BaseController { @Autowired private IUserDemandQuotationService userDemandQuotationService; - - -// -// /** -// * 获取服务分类列表 -// * 功能说明: -// * - 获取状态为启用的服务分类 -// * - 支持二级分类树形结构 -// * - 将二级分类组装在一级分类下的children字段 -// * - 只返回title和icon字段 -// * - 自动添加图片CDN前缀 -// * - 支持用户登录状态验证(可选) -// * -// * @param request HTTP请求对象 -// * @return 分类树形列表数据(只包含title和icon) -// */ -// @GetMapping(value = "/api/service/cate") -// public AjaxResult getServiceCategories(HttpServletRequest request) { -// try { -// // 验证用户登录状态(可选) -// AppletControllerUtil.getUserData(request.getHeader("token"), usersService); -// -// // 1. 查询所有启用状态的服务分类 -// ServiceCate serviceCateQuery = new ServiceCate(); -// serviceCateQuery.setStatus(1L); -// serviceCateQuery.setType(1L); -// List allCategoryList = serviceCateService.selectServiceCateList(serviceCateQuery); -// -// // 2. 分离一级分类和二级分类 -// List firstLevelCategories = new ArrayList<>(); -// Map> secondLevelMap = new HashMap<>(); -// -// for (ServiceCate category : allCategoryList) { -// if (category.getParentId() == null || category.getParentId() == 0L) { -// // 一级分类 -// firstLevelCategories.add(category); -// } else { -// // 二级分类,按父级ID分组 -// secondLevelMap.computeIfAbsent(category.getParentId(), k -> new ArrayList<>()).add(category); -// } -// } -// -// // 3. 构建简化的分类数据(只包含title和icon) -// List> resultList = new ArrayList<>(); -// -// for (ServiceCate firstLevel : firstLevelCategories) { -// Map firstLevelData = new HashMap<>(); -// firstLevelData.put("id", firstLevel.getId()); -// firstLevelData.put("title", firstLevel.getTitle()); -// firstLevelData.put("icon", AppletControllerUtil.buildImageUrl(firstLevel.getIcon())); -// -// // 4. 处理二级分类 -// List> childrenList = new ArrayList<>(); -// List children = secondLevelMap.get(firstLevel.getId()); -// if (children != null && !children.isEmpty()) { -// for (ServiceCate child : children) { -// Map childData = new HashMap<>(); -// childData.put("id", child.getId()); -// childData.put("title", child.getTitle()); -// childData.put("icon", AppletControllerUtil.buildImageUrl(child.getIcon())); -// childrenList.add(childData); -// } -// } -// firstLevelData.put("children", childrenList); -// -// resultList.add(firstLevelData); -// } -// -// return AppletControllerUtil.appletSuccess(resultList); -// } catch (Exception e) { -// return AppletControllerUtil.appletError("获取服务分类列表失败:" + e.getMessage()); -// } -// } -// /** -// * 获取系统配置信息 -// * 功能说明: -// * - 根据配置名称获取对应的配置值 -// * - 配置值以JSON格式返回 -// * - 支持动态配置管理 -// * -// * @param name 配置项名称 -// * @param request HTTP请求对象 -// * @return 配置信息数据 -// */ -// @GetMapping(value = "/api/public/config/{name}") -// public AjaxResult getConfig(@PathVariable("name") String name, HttpServletRequest request) { -// try { -// // 参数验证 -// if (StringUtils.isEmpty(name)) { -// return AppletControllerUtil.appletWarning("配置名称不能为空"); -// } -// // 查询配置信息 -// SiteConfig config = AppletControllerUtil.getSiteConfig(name, siteConfigService); -// if (config == null) { -// return AppletControllerUtil.appletWarning("未找到指定的配置项:" + name); -// } -// // 解析配置值为JSON对象 -// JSONObject configJson = AppletControllerUtil.parseConfigValue(config.getValue()); -// return AppletControllerUtil.appletSuccess(configJson); -// } catch (Exception e) { -// return AppletControllerUtil.appletError("获取配置信息失败:" + e.getMessage()); -// } -// } -// /** -// * 获取默认配置信息 -// * -// * @param request HTTP请求对象 -// * @return 返回config_one配置的JSON对象 -// *

-// * 功能说明: -// * - 获取名为"config_one"的系统配置 -// * - 将配置值解析为JSON对象并返回 -// * - 用于小程序获取基础配置信息 -// */ -// @GetMapping(value = "/api/public/get/config") -// public AjaxResult getconfig(HttpServletRequest request) { -// try { -// 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); -// } else { -// return AppletControllerUtil.appletWarning("未找到默认配置信息"); -// } -// } catch (Exception e) { -// return AppletControllerUtil.appletError("获取配置信息失败:" + e.getMessage()); -// } -// } -// /** -// * 查询用户收货地址列表 -// * -// * @param limit 每页显示数量 -// * @param page 页码 -// * @param request HTTP请求对象 -// * @return 分页地址列表 -// *

-// * 请求参数: -// * - limit: 每页显示数量,默认15 -// * - page: 页码,默认1 -// *

-// */ -// @GetMapping("/api/user/address/list") -// public AjaxResult getaddresslist( -// @RequestParam(value = "limit", defaultValue = "15") int limit, -// @RequestParam(value = "page", defaultValue = "1") int page, -// HttpServletRequest request) { -// try { -// // 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")) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// // 3. 获取用户信息 -// Users user = (Users) userValidation.get("user"); -// if (user == null) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// // 4. 设置分页参数 -// PageHelper.startPage(page, limit); -// // 5. 查询用户地址列表 -// UserAddress userAddressQuery = new UserAddress(); -// userAddressQuery.setUid(user.getId()); -// List addressList = userAddressService.selectUserAddressList(userAddressQuery); -// // 6. 获取分页信息并构建响应 -// TableDataInfo tableDataInfo = getDataTable(addressList); -// // 7. 构建符合要求的分页响应格式 -// Map pageData = PageUtil.buildPageResponse(tableDataInfo, page, limit); -// return AppletControllerUtil.appletSuccess(pageData); -// } catch (Exception e) { -// System.err.println("查询用户地址列表异常:" + e.getMessage()); -// return AppletControllerUtil.appletError("查询地址列表失败:" + e.getMessage()); -// } -// } -// /** -// * 根据地址ID查询用户收货地址详情 -// * -// * @param id 地址ID -// * @param request HTTP请求对象 -// * @return 地址详细信息 -// *

-// * 接口说明: -// * - 根据地址ID获取单个地址的详细信息 -// * - 验证用户登录状态和地址归属权 -// * - 返回AddressApple格式的地址数据,用于前端修改页面 -// *

-// */ -// @GetMapping("/api/user/address/info/{id}") -// public AjaxResult getAddressInfo(@PathVariable("id") Long id, HttpServletRequest request) { -// try { -// // 1. 参数验证 -// if (id == null || id <= 0) { -// return AppletControllerUtil.appletWarning("地址ID无效"); -// } -// // 2. 验证用户登录状态 -// String token = request.getHeader("token"); -// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); -// if (!(Boolean) userValidation.get("valid")) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// // 3. 获取用户信息 -// Users user = (Users) userValidation.get("user"); -// if (user == null) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// // 4. 查询地址信息 -// UserAddress userAddress = userAddressService.selectUserAddressById(id); -// if (userAddress == null) { -// return AppletControllerUtil.appletWarning("地址不存在"); -// } -// // 5. 验证地址归属权 -// if (!userAddress.getUid().equals(user.getId())) { -// return AppletControllerUtil.appletWarning("无权访问该地址信息"); -// } -// // 6. 转换为AddressApple格式并返回 -// AddressApple addressApple = AddressApple.fromUserAddress(userAddress); -// return AppletControllerUtil.appletSuccess(addressApple); -// } catch (Exception e) { -// System.err.println("查询用户地址详情异常:" + e.getMessage()); -// return AppletControllerUtil.appletError("查询地址详情失败:" + e.getMessage()); -// } -// } -// /** -// * 修改用户收货地址 -// * -// * @param params 地址修改参数 -// * @param request HTTP请求对象 -// * @return 修改结果 -// * 接口说明: -// * - 验证用户登录状态和地址归属权 -// * - 支持修改地址的所有字段 -// * - 自动处理默认地址逻辑(设为默认时会取消其他默认地址) -// * - 返回修改后的地址信息 -// */ -// @PostMapping("/api/user/address/edit") -// public AjaxResult editAddress(@RequestBody Map params, HttpServletRequest request) { -// try { -// // 1. 参数验证 -// if (params == null || params.get("id") == null) { -// return AppletControllerUtil.appletWarning("地址ID不能为空"); -// } -// Long addressId; -// try { -// addressId = Long.valueOf(params.get("id").toString()); -// if (addressId <= 0) { -// return AppletControllerUtil.appletWarning("地址ID无效"); -// } -// } catch (NumberFormatException e) { -// return AppletControllerUtil.appletWarning("地址ID格式错误"); -// } -// // 2. 验证用户登录状态 -// String token = request.getHeader("token"); -// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); -// if (!(Boolean) userValidation.get("valid")) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// // 3. 获取用户信息 -// Users user = (Users) userValidation.get("user"); -// if (user == null) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// // 4. 查询原地址信息并验证归属权 -// UserAddress existingAddress = userAddressService.selectUserAddressById(addressId); -// if (existingAddress == null) { -// return AppletControllerUtil.appletWarning("地址不存在"); -// } -// if (!existingAddress.getUid().equals(user.getId())) { -// return AppletControllerUtil.appletWarning("无权修改该地址"); -// } -// // 5. 构建更新的地址对象 -// UserAddress updateAddress = AppletControllerUtil.buildUpdateAddress(params, addressId, user.getId()); -// // 6. 验证必填字段 -// String validationResult = AppletControllerUtil.validateAddressParams(updateAddress); -// if (validationResult != null) { -// return AppletControllerUtil.appletWarning(validationResult); -// } -// // 7. 处理默认地址逻辑 -// if (updateAddress.getIsDefault() != null && updateAddress.getIsDefault() == 1L) { -// // 如果设置为默认地址,先将该用户的所有地址设为非默认 -// userAddressService.updateUserAddressDefault(user.getId()); -// } -// // 8. 执行地址更新 -// int updateResult = userAddressService.updateUserAddress(updateAddress); -// if (updateResult > 0) { -// return AppletControllerUtil.appletSuccess("地址修改成功"); -// } else { -// return AppletControllerUtil.appletWarning("地址修改失败"); -// } -// } catch (Exception e) { -// System.err.println("修改用户地址异常:" + e.getMessage()); -// return AppletControllerUtil.appletError("修改地址失败:" + e.getMessage()); -// } -// } -// /** -// * 新增用户收货地址 -// * -// * @param params 地址新增参数 -// * @param request HTTP请求对象 -// * @return 新增结果 -// * 接口说明: -// * - 验证用户登录状态 -// * - 支持新增地址的所有字段 -// * - 自动处理默认地址逻辑(设为默认时会取消其他默认地址) -// * - 返回新增后的地址信息 -// */ -// @PostMapping("/api/user/address/add") -// public AjaxResult addAddress(@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.appletdengluWarning("用户信息获取失败"); -// } -// // 2. 获取用户信息 -// Users user = (Users) userValidation.get("user"); -// if (user == null) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// // 3. 构建新增的地址对象 -// UserAddress newAddress = AppletControllerUtil.buildNewAddress(params, user.getId()); -// // 4. 验证必填字段 -// String validationResult = AppletControllerUtil.validateAddressParams(newAddress); -// if (validationResult != null) { -// return AppletControllerUtil.appletWarning(validationResult); -// } -// // 5. 处理默认地址逻辑 -// if (newAddress.getIsDefault() != null && newAddress.getIsDefault() == 1L) { -// // 如果设置为默认地址,先将该用户的所有地址设为非默认 -// userAddressService.updateUserAddressDefault(user.getId()); -// } -// // 6. 执行地址新增 -// int insertResult = userAddressService.insertUserAddress(newAddress); -// if (insertResult > 0) { -// return AppletControllerUtil.appletSuccess("地址新增成功"); -// } else { -// return AppletControllerUtil.appletWarning("地址新增失败"); -// } -// } catch (Exception e) { -// System.err.println("新增用户地址异常:" + e.getMessage()); -// return AppletControllerUtil.appletError("新增地址失败:" + e.getMessage()); -// } -// } -// /** -// * 售后返修申请接口 -// * -// * @param params 请求参数 包含order_id(订单ID)、phone(联系电话)、mark(返修原因备注) -// * @param request HTTP请求对象 -// * @return 返修申请结果 -// *

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

-// * 请求参数: -// * - order_id: 订单ID -// * - phone: 联系电话 -// * - mark: 返修原因备注 -// */ -// @PostMapping("/api/service/order/rework") -// public AjaxResult serviceOrderRework(@RequestBody Map params, HttpServletRequest request) { -// try { -// // 1. 参数验证 -// if (params == null) { -// return AppletControllerUtil.appletWarning("请求参数不能为空"); -// } -// String orderId = (String) params.get("order_id"); -// String phone = (String) params.get("phone"); -// String mark = (String) params.get("mark"); -// if (StringUtils.isEmpty(orderId)) { -// return AppletControllerUtil.appletWarning("订单ID不能为空"); -// } -// if (StringUtils.isEmpty(phone)) { -// return AppletControllerUtil.appletWarning("联系电话不能为空"); -// } -// // 验证手机号格式 -// if (!phone.matches("^1[3-9]\\d{9}$")) { -// return AppletControllerUtil.appletWarning("联系电话格式不正确"); -// } -// if (StringUtils.isEmpty(mark)) { -// return AppletControllerUtil.appletWarning("返修原因不能为空"); -// } -// // 2. 验证用户登录状态 -// String token = request.getHeader("token"); -// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); -// if (!(Boolean) userValidation.get("valid")) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// // 3. 获取用户信息 -// Users user = (Users) userValidation.get("user"); -// if (user == null) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// // 4. 查询订单信息并验证归属权 -// Order order = orderService.selectOrderByOrderId(orderId); -// if (order == null) { -// return AppletControllerUtil.appletWarning("订单不存在"); -// } -// if (!order.getUid().equals(user.getId())) { -// return AppletControllerUtil.appletWarning("无权操作此订单"); -// } -// // 5. 验证订单状态是否允许申请售后 -// if (!AppletControllerUtil.isOrderAllowRework(order.getStatus())) { -// return AppletControllerUtil.appletWarning("当前订单状态不允许申请售后"); -// } -// // 6. 处理售后返修申请 -// boolean reworkResult = AppletControllerUtil.processReworkApplication(order, phone, mark, user, orderReworkService, orderService); -// if (reworkResult) { -// return AppletControllerUtil.appletSuccess("售后返修申请已提交,我们会尽快联系您处理"); -// } else { -// return AppletControllerUtil.appletWarning("售后申请提交失败,请稍后重试"); -// } -// } catch (Exception e) { -// System.err.println("售后返修申请异常:" + e.getMessage()); -// return AppletControllerUtil.appletWarning("售后申请失败:" + e.getMessage()); -// } -// } -// /** -// * 获取用户服务订单列表 -// * -// * @param params 请求参数 包含page(页码)、limit(每页数量)、status(订单状态) -// * @param request HTTP请求对象 -// * @return 返回分页的服务订单列表 -// *

-// * 功能说明: -// * - 获取当前登录用户的服务类订单(type=1) -// * - 支持按订单状态筛选 -// * - 返回带分页信息的订单列表 -// * - 自动填充商品信息(标题、图标、价格等) -// */ -// @PostMapping("api/service/order/lst") -// public AjaxResult getserviceorderlst(@RequestBody Map params, -// HttpServletRequest request) { -// 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")) { -// return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); -// } -// // 2. 验证用户登录状态 -// String token = request.getHeader("token"); -// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); -// if (!(Boolean) userValidation.get("valid")) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// // 3. 获取用户信息 -// Users user = (Users) userValidation.get("user"); -// if (user == null) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// // 4. 设置分页参数 -// PageHelper.startPage(page, limit); -// // 5. 查询用户地址列表 -// OrderApple order = new OrderApple(); -// // order.setType(1); -// order.setUid(user.getId()); -// if (StringUtils.isNotNull(status) && !"".equals(status)) { -// order.setStatus(Long.valueOf(status)); -// } -// List orderList = orderService.selectOrderAppleList(order); -// for (OrderApple orderdata : orderList) { -// Map jsonObject = new HashMap<>(); -// if (orderdata.getProduct_id() != null) { -// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(orderdata.getProduct_id()); -// if (serviceGoods != null) { -// jsonObject.put("title", serviceGoods.getTitle()); -// jsonObject.put("icon", "https://img.huafurenjia.cn/" + serviceGoods.getIcon()); -// jsonObject.put("id", serviceGoods.getId()); -// jsonObject.put("price_zn", serviceGoods.getPriceZn()); -// jsonObject.put("sub_title", serviceGoods.getSubTitle()); -// orderdata.setProduct(jsonObject); -// } -// } -// } -// // 6. 获取分页信息并构建响应 -// TableDataInfo tableDataInfo = getDataTable(orderList); -// // 7. 构建符合要求的分页响应格式 -// Map pageData = PageUtil.buildPageResponse(tableDataInfo, page, limit); -// return AppletControllerUtil.appletSuccess(pageData); -// } -// /** -// * 获取用户商品订单列表 -// * -// * @param params 请求参数 包含page(页码)、limit(每页数量)、status(订单状态) -// * @param request HTTP请求对象 -// * @return 返回分页的商品订单列表 -// *

-// * 功能说明: -// * - 获取当前登录用户的商品类订单 -// * - 支持按订单状态筛选 -// * - 返回带分页信息的订单列表 -// * - 包含完整的商品信息和订单状态文本 -// */ -// @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"); -// // 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")) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// -// // 3. 获取用户信息 -// Users user = (Users) userValidation.get("user"); -// if (user == null) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// -// // 4. 设置分页参数 -// PageHelper.startPage(page, limit); -// -// // 5. 构建查询条件 -// GoodsOrder queryOrder = new GoodsOrder(); -// queryOrder.setUid(user.getId()); -// -// if (StringUtils.isNotNull(status) && !status.isEmpty()) { -// if ("7".equals(status)){ -// queryOrder.setReturnstatus(7L); -// }else{ -// queryOrder.setStatus(Long.valueOf(status)); -// } -// -// } -// -// // 6. 查询商品订单列表 -// List orderList = goodsOrderService.selectGoodsOrderList(queryOrder); -// -// // 7. 为每个订单填充商品信息 -// List> resultList = new ArrayList<>(); -// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); -// -// for (GoodsOrder order : orderList) { -// Map orderData = new HashMap<>(); -// -// // 订单基本信息 -// orderData.put("id", order.getId()); -// orderData.put("order_id", order.getOrderId()); -// orderData.put("order_no", order.getOrderId()); // 小程序常用字段 -// orderData.put("status", order.getStatus()); -// orderData.put("status_text", getOrderStatusText(order.getStatus())); // 状态文本 -// orderData.put("total_price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); -// orderData.put("num", order.getNum()); -// if (order.getSku() != null) { -// orderData.put("sku",AppletControllerUtil.parseSkuStringToObject(order.getSku())); -// } else { -// orderData.put("sku", null); -// } -// -// -// // 时间字段格式化 -// 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 { -// orderData.put("created_at", null); -// } -// -// // 查询并添加商品详细信息 -// if (order.getProductId() != null) { -// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); -// if (serviceGoods != null) { -// Map productInfo = new HashMap<>(); -// productInfo.put("id", serviceGoods.getId()); -// productInfo.put("title", serviceGoods.getTitle()); -// productInfo.put("sub_title", serviceGoods.getSubTitle()); -// 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); -// } -// } -// resultList.add(orderData); -// } -// // 8. 构建分页信息 -// PageInfo pageInfo = new PageInfo<>(orderList); -// // 9. 构建返回数据格式(简化版本,更适合小程序) -// Map responseData = new HashMap<>(); -// responseData.put("current_page", pageInfo.getPageNum()); -// responseData.put("data", resultList); -// responseData.put("total", pageInfo.getTotal()); -// responseData.put("per_page", pageInfo.getPageSize()); -// responseData.put("last_page", pageInfo.getPages()); -// -// return AppletControllerUtil.appletSuccess(responseData); -// -// } catch (Exception e) { -// System.err.println("查询商品订单列表异常:" + e.getMessage()); -// return AppletControllerUtil.appletError("查询商品订单列表失败:" + e.getMessage()); -// } -// } -// -// /** -// * 获取订单状态文本 -// * -// * @param status 订单状态 -// * @return 状态文本 -// */ -// private String getOrderStatusText(Long status) { -// if (status == null) { -// return "未知状态"; -// } -// switch (status.intValue()) { -// case 1: -// return "待付款"; -// case 2: -// return "待发货"; -// case 3: -// return "待收货"; -// case 4: -// return "待评价"; -// case 5: -// return "已完成"; -// case 6: -// return "已取消"; -// case 7: -// return "售后中"; -// case 8: -// return "已退款"; -// default: -// return "未知状态"; -// } -// } -// -// -// /** -// * 用户登录验证接口 -// * -// * @param request HTTP请求对象 -// * @return 返回用户信息或错误信息 -// *

-// * 功能说明: -// * - 通过请求头中的token验证用户身份 -// * - 查询用户基本信息并返回 -// * - 设置remember_token字段用于前端使用 -// */ -// @PostMapping(value = "/api/user/login") -// public AjaxResult getuserlogin(HttpServletRequest request) { -// String token = request.getHeader("token"); -// Users users = usersService.selectUsersByRememberToken(token); -// if (users != null) { -// users.setRemember_token(users.getRememberToken()); -// return AppletControllerUtil.appletSuccess(users); -// } else { -// return AppletControllerUtil.appletWarning("用户不存在"); -// } -// -// } -// /** -// * 获取服务商品列表 -// * 前端参数格式:{cate_id: 18} -// * 业务逻辑: -// * - 如果cate_id为空或null:返回所有分类的服务分组 -// * - 如果是一级分类:返回该一级分类下的服务分组 + 该一级分类下所有二级分类的服务分组 -// * - 如果是二级分类:返回该二级分类下的服务分组 -// * 返回格式:分类title + [服务列表] 的分组结构 -// */ -// @PostMapping(value = "/api/service/lst") -// public AjaxResult getServiceGoodsList(@RequestBody Map params, HttpServletRequest request) { -// try { -// // 1. 获取分类ID参数 -// Long cateId = null; -// if (params.get("cate_id") != null) { -// Object cateIdObj = params.get("cate_id"); -// try { -// if (cateIdObj instanceof Integer) { -// cateId = ((Integer) cateIdObj).longValue(); -// } else if (cateIdObj instanceof String) { -// String cateIdStr = cateIdObj.toString().trim(); -// if (!cateIdStr.isEmpty()) { -// cateId = Long.parseLong(cateIdStr); -// } -// } else { -// cateId = Long.parseLong(cateIdObj.toString()); -// } -// } catch (NumberFormatException e) { -// return AppletControllerUtil.appletkaifaWarning("分类ID格式错误"); -// } -// } -// -// // 2. 如果cate_id为空,查询默认的服务分类 -// if (cateId == null) { -// // 查询启用状态、类型为服务、排序第一的分类 -// ServiceCate defaultCateQuery = new ServiceCate(); -// defaultCateQuery.setStatus(1L); // 启用状态 -// defaultCateQuery.setType(1L); // 类型为服务(假设1为服务类型) -// List defaultCateList = serviceCateService.selectServiceCateList(defaultCateQuery); -// -// if (defaultCateList.isEmpty()) { -// return AppletControllerUtil.appletkaifaWarning("未找到默认服务分类"); -// } -// -// // 按排序字段升序排列,取第一个 -// defaultCateList.sort((a, b) -> { -// Long sortA = a.getSort() != null ? a.getSort() : Long.MAX_VALUE; -// Long sortB = b.getSort() != null ? b.getSort() : Long.MAX_VALUE; -// return sortA.compareTo(sortB); -// }); -// -// // 给cate_id赋值为排序第一的分类ID -// cateId = defaultCateList.get(0).getId(); -// } -// -// // 3. 构建返回数据 -// List> resultList = new ArrayList<>(); -// -// // 3. 查询分类信息,判断是一级还是二级分类 -// ServiceCate category = serviceCateService.selectServiceCateById(cateId); -// if (category == null) { -// return AppletControllerUtil.appletkaifaWarning("分类不存在"); -// } -// -// if (category.getParentId() == null || category.getParentId() == 0L) { -// // 一级分类:返回该一级分类的服务分组 + 所有二级分类的服务分组 -// -// // 先添加一级分类本身的服务 -// List> firstLevelServices = getServicesByCategory(cateId); -// if (!firstLevelServices.isEmpty()) { -// Map firstLevelGroup = new HashMap<>(); -// firstLevelGroup.put("id", category.getId()); -// firstLevelGroup.put("title", category.getTitle()); -// firstLevelGroup.put("services", firstLevelServices); -// resultList.add(firstLevelGroup); -// } -// -// // 再添加该一级分类下所有二级分类的服务分组 -// ServiceCate childQuery = new ServiceCate(); -// childQuery.setParentId(cateId); -// childQuery.setStatus(1L); -// List childCategories = serviceCateService.selectServiceCateList(childQuery); -// -// for (ServiceCate child : childCategories) { -// List> childServices = getServicesByCategory(child.getId()); -// if (!childServices.isEmpty()) { -// Map childGroup = new HashMap<>(); -// childGroup.put("id", category.getId()); -// childGroup.put("title", child.getTitle()); -// childGroup.put("services", childServices); -// resultList.add(childGroup); -// } -// } -// -// } else { -// // 二级分类:只返回该二级分类的服务分组 -// List> services = getServicesByCategory(cateId); -// if (!services.isEmpty()) { -// Map group = new HashMap<>(); -// group.put("id", category.getId()); -// group.put("title", category.getTitle()); -// group.put("services", services); -// resultList.add(group); -// } -// } -// -// return AppletControllerUtil.appletSuccess(resultList); -// } catch (Exception e) { -// return AppletControllerUtil.appletkaifaWarning("查询服务商品列表失败:" + e.getMessage()); -// } -// } -// -// -// /** -// * 根据分类ID查询该分类下的服务列表 -// * @param categoryId 分类ID -// * @return 服务列表(只包含id、title、icon) -// */ -// private List> getServicesByCategory(Long categoryId) { -// List> serviceList = new ArrayList<>(); -// -// ServiceGoods queryGoods = new ServiceGoods(); -// queryGoods.setCateId(categoryId); -// queryGoods.setStatus("1"); // 只查询启用状态的商品 -// -// List goodsList = serviceGoodsService.selectServiceGoodsList(queryGoods); -// -// for (ServiceGoods goods : goodsList) { -// Map serviceData = new HashMap<>(); -// serviceData.put("id", goods.getId()); -// serviceData.put("title", goods.getTitle()); -// serviceData.put("icon", AppletControllerUtil.buildImageUrl(goods.getIcon())); -// serviceList.add(serviceData); -// } -// -// return serviceList; -// } -// /** -// * 获取服务商品详细信息 -// * -// * @param id 商品ID -// * @param request HTTP请求对象 -// * @return 商品详细信息 -// *

-// * 接口说明: -// * - 根据商品ID获取详细信息 -// * - type=1时返回ServiceGoodsResponse格式 -// * - type=2时返回json.txt中的商品格式 -// * - 包含图片、基础信息等数组数据 -// */ -// @GetMapping(value = "/api/service/info/id/{id}") -// public AjaxResult serviceGoodsQuery(@PathVariable("id") long id, -// @RequestParam(value = "type", required = false) Integer type, -// HttpServletRequest request) { -// try { -// // 参数验证 -// if (id <= 0) { -// return AppletControllerUtil.appletError("商品ID无效"); -// } -// -// // 查询商品信息 -// ServiceGoods serviceGoodsData = serviceGoodsService.selectServiceGoodsById(id); -// if (serviceGoodsData == null) { -// return AppletControllerUtil.appletError("商品不存在或已下架"); -// } -// if (type != null && type == 1) { -// if (serviceGoodsData.getIsgroup()!=1){ -// return AppletControllerUtil.appletError("改服务不是拼团服务"); -// } -// } -// //次卡详情 -// if (type != null && type == 2) { -// UserSecondaryCard goods = userSecondaryCardService.selectUserSecondaryCardById(id); -// Map map = new HashMap<>(); -// map.put("isyikoujia", 1); -// map.put("id", goods.getId()); -// map.put("allsellnum", 10); -// map.put("orderid", goods.getOrderid()); -// map.put("title", goods.getTitle()); -// map.put("goodsids", goods.getGoodsids()); -// map.put("show_money", goods.getShowMoney()); -// map.put("real_money", goods.getRealMoney()); -// map.put("showimage", AppletControllerUtil.buildImageUrl(goods.getShowimage())); -// map.put("carouselImage", AppletControllerUtil.parseImagesStringToArray(goods.getCarouselImage())); -// map.put("status", goods.getStatus()); -// map.put("creattime", goods.getCreattime()); -// map.put("type", goods.getType()); -// map.put("num", goods.getNum()); -// map.put("allnum", goods.getAllnum()); -// map.put("introduction", goods.getIntroduction()); -// List idsList = JSONArray.parseArray(goods.getGoodsids(), String.class); -// List serviceGoodsList = serviceGoodsService.selectServiceGoodsfrocikaList(idsList); -// List> serviceDetail = new ArrayList<>(); -// if(serviceGoodsList != null && !serviceGoodsList.isEmpty()) { -// for(ServiceGoods serviceGoods : serviceGoodsList) { -// Map card = new HashMap<>(); -// card.put("icon", AppletControllerUtil.buildImageUrl(serviceGoods.getIcon())); -// card.put("title", serviceGoods.getTitle()); -// card.put("price", serviceGoods.getPrice()); -// card.put("id", serviceGoods.getId()); -// serviceDetail.add( card); -// } -// } -// map.put("serviceDetail", serviceDetail); -// // card.setServiceDetail(serviceGoodsService.selectServiceGoodsfrocikaList(idsList)); -// return AppletControllerUtil.appletSuccess(map); -// } -// //拼团详情 -// -// -// -// // 原有逻辑:普通服务详情 -// if (serviceGoodsData.getType() != null && serviceGoodsData.getType() == 2) { -// // type=2时返回json.txt格式 -// Map goodsData = AppletControllerUtil.buildType2ServiceGoodsResponse(serviceGoodsData); -// return AppletControllerUtil.appletSuccess(goodsData); -// } else { -// // type=1时返回ServiceGoodsResponse格式 -// Map goodsData = AppletControllerUtil.buildType2ServiceGoodsResponse(serviceGoodsData); -// //根据需求就要添加拼团相关数据 -// if (type != null) { -// //拼团独有数据 -// if (type == 1) { -// // 拼团服务详情 -// goodsData.put("isyikoujia", 1); -// goodsData.put("allsellnum", 10); -// goodsData.put("isgroup", serviceGoodsData.getIsgroup()); -// goodsData.put("groupnum", serviceGoodsData.getGroupnum()); -// goodsData.put("groupprice", serviceGoodsData.getGroupprice()); -// List> groupBuyingList = userGroupBuyingService.selectGroupBuyingGroupByProductAndOrder(Math.toIntExact(serviceGoodsData.getId())); -// for (Map groupBuying : groupBuyingList) { -// //还差几人成团 -// JSONArray groupBuyingArray = JSONArray.parseArray(groupBuying.get("name").toString()); -// // JSONArray groupBuyingArray =new JSONArray(); -// groupBuying.put("neednum", serviceGoodsData.getGroupnum() - groupBuyingArray.size()); -// groupBuying.put("image", AppletControllerUtil.parseImagesStringToArray(groupBuying.get("image").toString())); -// //parseImagesStringToArray(goods.getImgs()) -// //groupBuying.put("neednum", AppletControllerUtil.buildImageUrl(groupBuying.get("image").toString())); -// } -// goodsData.put("groupBuyData", groupBuyingList); -// } -// //秒杀独有数据 -// if (type == 3) { -// -// // 获取秒杀相关数据 -// long msdata = 0L; -// try { -// // 获取config_one配置中的秒杀结束时间 -// SiteConfig configQuery = new SiteConfig(); -// configQuery.setName("config_one"); -// List configList = siteConfigService.selectSiteConfigList(configQuery); -// -// if (configList != null && !configList.isEmpty()) { -// String configValue = configList.get(0).getValue(); -// if (configValue != null && !configValue.trim().isEmpty()) { -// JSONObject configJson = JSONObject.parseObject(configValue); -// String mstime = configJson.getString("mstime"); -// -// if (mstime != null && !mstime.trim().isEmpty()) { -// // 解析秒杀结束时间 -// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); -// Date endTime = sdf.parse(mstime); -// msdata = endTime.getTime(); // 返回结束时间的毫秒数 -// } -// } -// } -// } catch (Exception e) { -// // 解析异常时设置为0 -// msdata = 0L; -// } -// -// -// // 秒杀服务详情 -// goodsData.put("isyikoujia", 1); -// goodsData.put("msdata", msdata); -// goodsData.put("allsellnum", 10); -// goodsData.put("isfixed", serviceGoodsData.getIsfixed()); -// goodsData.put("fixedprice", serviceGoodsData.getFixedprice()); -// } -// //报价数据下师傅的报价详情 -// if (type == 4) { -// goodsData.put("isyikoujia", 2); -// // 秒杀服务详情 -//// List> quoteList = new List>() ; -//// -//// goodsData.put("isfixed", serviceGoodsData.getIsfixed()); -//// goodsData.put("fixedprice", serviceGoodsData.getFixedprice()); -// } -// }else{ -// goodsData.put("isyikoujia", 2); -// } -// return AppletControllerUtil.appletSuccess(goodsData); -// } -// } catch (Exception e) { -// return AppletControllerUtil.appletError("查询商品详情失败:" + e.getMessage()); -// } -// } -// /** -// * 获取广告图片列表 -// * -// * @param type 广告类型 -// * @param request HTTP请求对象 -// * @return 广告图片列表 -// *

-// * 接口说明: -// * - 根据广告类型获取对应的图片列表 -// * - 自动添加图片CDN前缀 -// * - 支持多种广告位配置 -// */ -// @GetMapping(value = "/api/public/adv/lst/{type}") -// public AjaxResult getAdvImgData(@PathVariable("type") long type, HttpServletRequest request) { -// try { -// // 参数验证 -// if (type < 0) { -// return AppletControllerUtil.appletWarning("广告类型无效"); -// } -// -// // 构建查询条件 -// AdvImg advImgQuery = new AdvImg(); -// advImgQuery.setType(type); -// advImgQuery.setStatus(1L); -// -// // 查询广告图片列表 -// List advImgList = advImgService.selectAdvImgList(advImgQuery); -// -// // 为每张图片添加CDN前缀 -// for (AdvImg advImg : advImgList) { -// advImg.setImage(AppletControllerUtil.buildImageUrl(advImg.getImage())); -// } -// -// return AppletControllerUtil.appletSuccess(advImgList); -// } catch (Exception e) { -// return AppletControllerUtil.appletWarning("获取广告图片失败:" + e.getMessage()); -// } -// } -// -// /** -// * 获取商城分类列表 -// * -// * @param request HTTP请求对象 -// * @return 商城分类列表 -// *

-// * 接口说明: -// * - 查询类型为商品且状态为启用的分类数据 -// * - 只返回title和icon字段 -// * - 自动添加图片CDN前缀 -// * - 保持原有排序不变 -// * - 无需用户登录验证 -// */ -// @GetMapping(value = "/api/mall/cate/lst/{type}") -// public AjaxResult getMallCategoryList(@PathVariable("type") int type, HttpServletRequest request) { -// try { -// // 构建查询条件 -// ServiceCate serviceCateQuery = new ServiceCate(); -// serviceCateQuery.setStatus(1L); // 状态为启用 -// serviceCateQuery.setType(2L); // 类型为商品(假设2为商品类型,请根据实际业务调整) -// -// // 查询商城分类列表 -// List categoryList = serviceCateService.selectServiceCateList(serviceCateQuery); -// -// // 构建返回数据(只包含title和icon) -// List> resultList = new ArrayList<>(); -// for (ServiceCate category : categoryList) { -// Map categoryData = new HashMap<>(); -// categoryData.put("id", category.getId()); -// categoryData.put("title", category.getTitle()); -// categoryData.put("icon", AppletControllerUtil.buildImageUrl(category.getIcon())); -// resultList.add(categoryData); -// } -// -// return AppletControllerUtil.appletSuccess(resultList); -// } catch (Exception e) { -// return AppletControllerUtil.appletError("获取商城分类列表失败:" + e.getMessage()); -// } -// } -// -// /** -// * 获取热门推荐商品 -// * -// * @param request HTTP请求对象 -// * @return 热门推荐商品列表(销量前6个) -// *

-// * 接口说明: -// * - 查询type=2的商品 -// * - 按销量降序排列,取前6个 -// * - 返回id、title、icon、price、sales字段 -// * - 自动添加图片CDN前缀 -// * - 无需用户登录验证 -// */ -// @GetMapping(value = "/api/hot/recommend") -// public AjaxResult getHotRecommendGoods(HttpServletRequest request) { -// try { -// // 构建查询条件 -// ServiceGoods queryGoods = new ServiceGoods(); -// queryGoods.setType(2); // 查询type=2的商品 -// queryGoods.setStatus("1"); // 只查询启用状态的商品 -// -// // 查询符合条件的商品列表 -// List goodsList = serviceGoodsService.selectServiceGoodsList(queryGoods); -// -// // 按销量降序排序 -// goodsList.sort((a, b) -> { -// Long salesA = a.getSales() != null ? a.getSales() : 0L; -// Long salesB = b.getSales() != null ? b.getSales() : 0L; -// return salesB.compareTo(salesA); -// }); -// -// // 取前6个 -// if (goodsList.size() > 6) { -// goodsList = goodsList.subList(0, 6); -// } -// -// // 构建返回数据 -// List> resultList = new ArrayList<>(); -// for (ServiceGoods goods : goodsList) { -// Map goodsData = new HashMap<>(); -// goodsData.put("id", goods.getId()); -// goodsData.put("title", goods.getTitle()); -// goodsData.put("icon", AppletControllerUtil.buildImageUrl(goods.getIcon())); -// goodsData.put("price", goods.getPrice() != null ? goods.getPrice().toString() : "0.00"); -// goodsData.put("sales", goods.getSales() != null ? goods.getSales() : 0L); -// resultList.add(goodsData); -// } -// -// return AppletControllerUtil.appletSuccess(resultList); -// } catch (Exception e) { -// return AppletControllerUtil.appletError("获取热门推荐商品失败:" + e.getMessage()); -// } -// } -// -// /** -// * 根据分类ID查询商品列表 -// * -// * @param request HTTP请求对象 -// * @return 该分类下的商品列表 -// *

-// * 接口说明: -// * - 根据分类ID查询商品 -// * - 只查询启用状态的商品 -// * - 返回id、title、icon、price、sales字段 -// * - 自动添加图片CDN前缀 -// * - 无需用户登录验证 -// */ -// @PostMapping(value = "/api/goods/cate") -// public AjaxResult getGoodsByCategory(@RequestBody Map params, HttpServletRequest request) { -// try { -// // 1. 获取分页参数 -// int page = params.get("page") != null ? (Integer) params.get("page") : 1; -// int limit = params.get("limit") != null ? (Integer) params.get("limit") : 15; -// String cateId = params.get("cateId").toString(); -// -// // 验证分页参数 -// if (page < 1) page = 1; -// if (limit < 1) limit = 15; -//// if (limit > 100) limit = 100; // 限制最大每页数量 -// -// // 2. 设置分页参数 -// PageHelper.startPage(page, limit); -// -// // 3. 构建查询条件 -// ServiceGoods queryGoods = new ServiceGoods(); -// queryGoods.setStatus("1"); // 只查询启用状态的商品 -// -// // 判断是否查询全部商品 -// boolean queryAll = "00".equals(cateId.trim()) || cateId.trim().isEmpty(); -// -// if (!queryAll) { -// // 验证分类ID格式 -// Long categoryId; -// try { -// categoryId = Long.parseLong(cateId); -// if (categoryId <= 0) { -// return AppletControllerUtil.appletWarning("分类ID无效"); -// } -// } catch (NumberFormatException e) { -// return AppletControllerUtil.appletWarning("分类ID格式错误"); -// } -// -// // 验证分类是否存在 -// ServiceCate category = serviceCateService.selectServiceCateById(categoryId); -// if (category == null) { -// return AppletControllerUtil.appletWarning("分类不存在"); -// } -// -// queryGoods.setCateId(categoryId); // 根据分类ID查询 -// } -// -// // 4. 查询商品列表 -// List goodsList = serviceGoodsService.selectServiceGoodsList(queryGoods); -// -// // 5. 构建返回数据 -// List> resultList = new ArrayList<>(); -// for (ServiceGoods goods : goodsList) { -// Map goodsData = new HashMap<>(); -// goodsData.put("id", goods.getId()); -// goodsData.put("title", goods.getTitle()); -// goodsData.put("icon", AppletControllerUtil.buildImageUrl(goods.getIcon())); -// goodsData.put("price", goods.getPrice() != null ? goods.getPrice().toString() : "0.00"); -// goodsData.put("sales", goods.getSales() != null ? goods.getSales() : 0L); -// goodsData.put("cate_id", goods.getCateId()); -// resultList.add(goodsData); -// } -// -// // 6. 构建分页信息 -// PageInfo pageInfo = new PageInfo<>(goodsList); -// -// // 7. 构建返回数据格式 -// Map responseData = new HashMap<>(); -// responseData.put("current_page", pageInfo.getPageNum()); -// responseData.put("data", resultList); -// responseData.put("from", pageInfo.getStartRow()); -// responseData.put("last_page", pageInfo.getPages()); -// responseData.put("per_page", pageInfo.getPageSize()); -// responseData.put("to", pageInfo.getEndRow()); -// responseData.put("total", pageInfo.getTotal()); -// -// // 构建分页链接信息 -// String baseUrl = "https://www.huafurenjia.cn/api/goods/cate/" + cateId; -// 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("path", baseUrl); -// -// return AppletControllerUtil.appletSuccess(responseData); -// } catch (Exception e) { -// return AppletControllerUtil.appletError("查询分类商品失败:" + e.getMessage()); -// } -// } -// -// /** -// * 获取一级城市列表 -// * -// * @param request HTTP请求对象 -// * @return 一级城市列表 -// *

-// * 接口说明: -// * - 查询parent_id=0的城市数据 -// * - 只返回id和title字段 -// * - 无需用户登录验证 -// */ -// @GetMapping(value = "/api/city/list") -// public AjaxResult getCityList(HttpServletRequest request) { -// try { -// // 构建查询条件 -// DiyCity queryCond = new DiyCity(); -// queryCond.setParentId(0L); // 查询parent_id=0的一级城市 -// -// // 查询一级城市列表 -// List cityList = diyCityService.selectDiyCityList(queryCond); -// -// // 构建返回数据(只包含id和title) -// List> resultList = new ArrayList<>(); -// for (DiyCity city : cityList) { -// Map cityData = new HashMap<>(); -// cityData.put("id", city.getId()); -// cityData.put("title", city.getTitle()); -// resultList.add(cityData); -// } -// -// return AppletControllerUtil.appletSuccess(resultList); -// } catch (Exception e) { -// return AppletControllerUtil.appletError("获取城市列表失败:" + e.getMessage()); -// } -// } -// -// /** -// * 根据经纬度获取城市信息 -// * -// * @param params 请求参数,包含latitude(纬度)、longitude(经度) -// * @param request HTTP请求对象 -// * @return 城市信息 -// *

-// * 接口说明: -// * - 接收前端传入的经纬度坐标 -// * - 调用高德地图逆地理编码API获取城市信息 -// * - 返回城市名称和详细地址信息 -// * - 无需用户登录验证 -// */ -// @PostMapping(value = "/api/location/city") -// public AjaxResult getCityByLocation(@RequestBody Map params, HttpServletRequest request) { -// try { -// // 1. 参数验证 -// if (params == null) { -// return AppletControllerUtil.appletWarning("请求参数不能为空"); -// } -// -// String latitude = params.get("latitude") != null ? params.get("latitude").toString() : ""; -// String longitude = params.get("longitude") != null ? params.get("longitude").toString() : ""; -// -// if (latitude.isEmpty() || longitude.isEmpty()) { -// return AppletControllerUtil.appletWarning("经纬度参数不能为空"); -// } -// -// // 验证经纬度格式并转换为double -// double lat, lng; -// try { -// lat = Double.parseDouble(latitude); -// lng = Double.parseDouble(longitude); -// -// // 验证经纬度范围 -// if (lat < -90 || lat > 90) { -// return AppletControllerUtil.appletWarning("纬度范围应在-90到90之间"); -// } -// if (lng < -180 || lng > 180) { -// return AppletControllerUtil.appletWarning("经度范围应在-180到180之间"); -// } -// } catch (NumberFormatException e) { -// return AppletControllerUtil.appletWarning("经纬度格式错误"); -// } -// -// // 2. 调用高德地图工具类获取位置信息 -// String city = GaoDeMapUtil.getCityByLocation(lng, lat); -// String address = GaoDeMapUtil.getAddressByLocation(lng, lat); -// -// // 3. 构建返回数据 -// Map locationInfo = new HashMap<>(); -// locationInfo.put("city", city != null ? city : ""); -// locationInfo.put("formatted_address", address != null ? address : ""); -// locationInfo.put("latitude", latitude); -// locationInfo.put("longitude", longitude); -// -// return AppletControllerUtil.appletSuccess(locationInfo); -// -// } catch (Exception e) { -// return AppletControllerUtil.appletError("获取位置信息失败:" + e.getMessage()); -// } -// } -// -// /** -// * 微信用户登录接口 -// * -// * @param params 请求参数 -// * @param request HTTP请求对象 -// * @return 登录结果 -// * 登录流程: -// * 1. 验证请求参数 -// * 2. 通过usercode获取微信openid -// * 3. 检查用户是否已存在(通过openid) -// * 4. 如果用户存在,直接返回用户信息 -// * 5. 如果用户不存在,获取手机号并创建/更新用户 -// */ -// @PostMapping(value = "/api/user/phone/login") -// public AjaxResult wechatLogin(@RequestBody Map params, HttpServletRequest request) { -// // 使用AppletLoginUtil执行完整的微信登录流程 -// return AppletLoginUtil.executeWechatLogin(params, usersService); -// } -// - - -// /** -// * 获取用户基本信息接口 -// * -// * @param request HTTP请求对象 -// * @return 用户基本信息 -// *

-// * 接口说明: -// * - 通过token获取当前登录用户的基本信息 -// * - 返回完整的用户数据 -// * - 需要用户登录验证 -// *

-// */ -// @GetMapping(value = "/api/user/info") -// public AjaxResult getUserInfo(HttpServletRequest request) { -// try { -// Map order_num = new HashMap<>(); -// Map goods_order_num = new HashMap<>(); -// // 1. 验证用户登录状态 -// String token = request.getHeader("token"); -// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); -// if (!(Boolean) userValidation.get("valid")) { -// return AppletControllerUtil.appletUnauthorized(); -// } -// -// // 2. 获取用户信息 -// Users user = (Users) userValidation.get("user"); -// if (user == null) { -// return AppletControllerUtil.appletWarning("用户信息获取失败"); -// } -// -// // 3. 构建精简用户信息响应数据 -// Map userInfo = new HashMap<>(); -// userInfo.put("nickname", user.getNickname()); -// userInfo.put("phone", user.getPhone()); -// userInfo.put("ismember", user.getIsmember()); -// userInfo.put("member_begin", user.getMemberBegin()); -// userInfo.put("member_end", user.getMemberEnd()); -// userInfo.put("balance", user.getBalance()); -// userInfo.put("integral", user.getIntegral()); -// userInfo.put("shop_money", user.getConsumption()); -// userInfo.put("service_money", user.getServicefee()); -// userInfo.put("birthday", user.getBirthday()); -// userInfo.put("remember_token", userInfo.get("rememberToken")); -// -// // 头像处理 -// String avatar = user.getAvatar(); -// if (avatar != null && !avatar.isEmpty()) { -// userInfo.put("avatar", AppletControllerUtil.buildImageUrl(avatar)); -// } else { -// userInfo.put("avatar", "https://img.huafurenjia.cn/default/user_avatar.jpeg"); -// } -// order_num.put("pending_accept", orderService.selectCountOrderByUid(user.getId(), 2L)); -// order_num.put("pending_service", orderService.selectCountOrderByUid(user.getId(), 3L)); -// order_num.put("in_service", orderService.selectCountOrderByUid(user.getId(), 4L)); -// order_num.put("other_status", orderService.selectAllCountOrderByUid(user.getId())); -// userInfo.put("order_num", order_num); -// -// -// goods_order_num.put("pending_accept", goodsOrderService.selectCountGoodsOrderByUid(user.getId(), 2L)); -// goods_order_num.put("pending_service", goodsOrderService.selectCountGoodsOrderByUid(user.getId(), 3L)); -// goods_order_num.put("in_service", goodsOrderService.selectCountGoodsOrderByUid(user.getId(), 5L)); -// goods_order_num.put("other_status", goodsOrderService.selectAllCountGoodsOrderByUid(user.getId())); -// userInfo.put("goods_order_num", goods_order_num); -// // 新增tx_time字段 -// List txTimeArr = new ArrayList<>(); -// try { -// SiteConfig configQuery = new SiteConfig(); -// configQuery.setName("config_four"); -// List configList = siteConfigService.selectSiteConfigList(configQuery); -// if (configList != null && !configList.isEmpty()) { -// String configValue = configList.get(0).getValue(); -// if (configValue != null && !configValue.trim().isEmpty()) { -// JSONObject json = JSONObject.parse(configValue); -// if (json.containsKey("time")) { -// Object timeObj = json.get("time"); -// if (timeObj instanceof List) { -// txTimeArr = (List) timeObj; -// } else if (timeObj instanceof JSONArray) { -// txTimeArr = ((JSONArray) timeObj).toJavaList(Object.class); -// } -// } -// } -// } -// } catch (Exception ignore) { -// } -// userInfo.put("tx_time", txTimeArr); -// return AppletControllerUtil.appletSuccess(userInfo); -// } catch (Exception e) { -// System.err.println("查询用户基本信息异常:" + e.getMessage()); -// return AppletControllerUtil.appletError("查询用户信息失败:" + e.getMessage()); -// } -// } - - - - -// /** -// * 获取用户基本信息接口 -// * -// * @param request HTTP请求对象 -// * @return 用户基本信息 -// *

-// * 接口说明: -// * - 通过token获取当前登录用户的基本信息 -// * - 返回完整的用户数据 -// * - 需要用户登录验证 -// *

-// */ -// @GetMapping(value = "/api/user/info") -// public AjaxResult apiuserinfo(HttpServletRequest request) { -// try { -// SimpleDateFormat sdfday = new SimpleDateFormat("yyyy-MM-dd"); -// Map order_num = new HashMap<>(); -// Map goods_order_num = new HashMap<>(); -// // 1. 验证用户登录状态 -// String token = request.getHeader("token"); -// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); -// if (!(Boolean) userValidation.get("valid")) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// -// // 2. 获取用户信息 -// Users user = (Users) userValidation.get("user"); -// if (user == null) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// -// // 3. 构建用户信息响应数据 -// Map userInfo = buildUserInfoResponse(user); -// -// userInfo.put("remember_token", userInfo.get("rememberToken")); -// -// // 新增:根据会员状态查询充值项目 -// Integer queryType = (user.getIsmember() != null && user.getIsmember() == 1) ? 2 : 1; -// UserMemberRechargeProgram query = new UserMemberRechargeProgram(); -// query.setType(queryType); -// query.setStatus(0); // 只查启用 -// java.util.List rechargePrograms = userMemberRechargeProgramService.selectUserMemberRechargeProgramList(query); -// userInfo.put("memberRechargePrograms", rechargePrograms.getFirst()); -// //List counts = orderService.selectOrderCountByBigtype(user.getId()); -// // OrderTypeCount -// order_num.put("yuyue",orderService.selectOrderCountByBigtype(user.getId(),1)); -// order_num.put("baojia",orderService.selectOrderCountByBigtype(user.getId(),2)); -// order_num.put("yikoujia",orderService.selectOrderCountByBigtype(user.getId(),3)); -// userInfo.put("order_num", order_num); -// -// goods_order_num.put("daifukuan",goodsOrderService.countGoodsOrderByUidAndStatus(user.getId(),1)); -// goods_order_num.put("daifahuo",goodsOrderService.countGoodsOrderByUidAndStatus(user.getId(),2)); -// goods_order_num.put("daishouhuo",goodsOrderService.countGoodsOrderByUidAndStatus(user.getId(),3)); -// goods_order_num.put("daipingjia",goodsOrderService.countGoodsOrderByUidAndStatus(user.getId(),4)); -// goods_order_num.put("shouhou",goodsOrderService.countGoodsOrderByUidAndStatus(user.getId(),20)); -// userInfo.put("goods_order_num", goods_order_num); -// -// // 新增tx_time字段 -// List txTimeArr = new ArrayList<>(); -// try { -// SiteConfig configQuery = new SiteConfig(); -// configQuery.setName("config_four"); -// List configList = siteConfigService.selectSiteConfigList(configQuery); -// if (configList != null && !configList.isEmpty()) { -// String configValue = configList.get(0).getValue(); -// if (configValue != null && !configValue.trim().isEmpty()) { -// JSONObject json = JSONObject.parse(configValue); -// if (json.containsKey("time")) { -// Object timeObj = json.get("time"); -// if (timeObj instanceof List) { -// txTimeArr = (List) timeObj; -// } else if (timeObj instanceof JSONArray) { -// txTimeArr = ((JSONArray) timeObj).toJavaList(Object.class); -// } -// } -// } -// } -// } catch (Exception ignore) { -// } -// userInfo.put("tx_time", txTimeArr); -// -// // 新增:查询该用户可用优惠券数量 -// int couponNum = 0; -// try { -// com.ruoyi.system.domain.CouponUser queryCoupon = new com.ruoyi.system.domain.CouponUser(); -// queryCoupon.setUid(user.getId()); -// queryCoupon.setStatus(0L); // 0=可用 -// java.util.List couponList = couponUserService.selectCouponUserList(queryCoupon); -// couponNum = couponList != null ? couponList.size() : 0; -// } catch (Exception e) { -// } -// userInfo.put("couponNum", couponNum); -// -// return AppletControllerUtil.appletSuccess(userInfo); -// -// } catch (Exception e) { -// System.err.println("查询用户基本信息异常:" + e.getMessage()); -// return AppletControllerUtil.appletError("查询用户信息失败:" + e.getMessage()); -// } -// } - - - -// /** -// * 构建用户信息响应数据 -// * -// * @param user 用户实体 -// * @return 格式化的用户信息 -// */ -// private Map buildUserInfoResponse(Users user) { -// Map userInfo = new HashMap<>(); -// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); -// SimpleDateFormat sdfday = new SimpleDateFormat("yyyy-MM-dd"); -// -// // 基本信息 -// userInfo.put("id", user.getId()); -// userInfo.put("name", user.getName()); -// userInfo.put("nickname", user.getNickname()); -// userInfo.put("phone", user.getPhone()); -// userInfo.put("password", null); // 密码不返回 -// // userInfo.put("ismember", user.getIsmember()); -//// if (user.getMemberBegin() != null) { -//// userInfo.put("member_begin", sdfday.format(user.getMemberBegin())); -//// } -//// if (user.getMemberEnd() != null){ -//// userInfo.put("member_end", sdfday.format(user.getMemberEnd())); -//// } -//// userInfo.put("member_begin", sdfday.format(user.getMemberBegin())); -//// userInfo.put("member_end", sdfday.format(user.getMemberEnd())); -//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.*; -//import com.ruoyi.system.domain.*; -//import com.ruoyi.system.domain.AppleDoMain.OrderApple; -//import com.ruoyi.system.domain.AppleDoMain.AddressApple; -//import com.ruoyi.system.service.*; -//import com.winnerlook.model.VoiceResponseResult; -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.web.bind.annotation.*; -//import org.springframework.web.multipart.MultipartFile; -//import javax.servlet.http.HttpServletRequest; -//import java.time.LocalDateTime; -//import java.time.ZoneId; -//import java.util.*; -//import java.text.SimpleDateFormat; -//import java.math.BigDecimal; -//import com.ruoyi.system.config.QiniuConfig; -//import com.ruoyi.system.utils.QiniuUploadUtil; -//import com.github.pagehelper.PageHelper; -//import com.github.pagehelper.PageInfo; -//import com.ruoyi.system.domain.WechatTransfer; -//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; -///** -// * 小程序控制器 -// * -// * -// * @author Mr. Zhang Pan -// * @version 2.0 -// */ -//@RestController -//public class AppletController extends BaseController { -// -// private static final Logger logger = LoggerFactory.getLogger(AppletController.class); -// -// @Autowired -// private IServiceCateService serviceCateService; -// @Autowired -// private IUsersService usersService; -// @Autowired -// private ISiteConfigService siteConfigService; -// @Autowired -// private IAdvImgService advImgService; -// @Autowired -// private IServiceGoodsService serviceGoodsService; -// @Autowired -// private IUserAddressService userAddressService; -// @Autowired -// private IOrderService orderService; -// @Autowired -// private IOrderReworkService orderReworkService; -// @Autowired -// private ICooperateService cooperateService; -// @Autowired -// private ICouponUserService couponUserService; -// @Autowired -// private IIntegralLogService integralLogService; -// @Autowired -// private IIntegralOrderService integralOrderService; -// @Autowired -// private IIntegralProductService integralProductService; -// @Autowired -// private IIntegralOrderLogService integralOrderLogService; -// @Autowired -// private IIntegralCateService integralCateService; -// @Autowired -// private IOrderLogService orderLogService; -// @Autowired -// private IDiyCityService diyCityService; -// @Autowired -// private ISiteSkillService siteSkillService; -// @Autowired -// private QiniuConfig qiniuConfig; -// @Autowired -// private IGoodsCartService goodsCartService; -// @Autowired -// private IGoodsOrderService goodsOrderService; -// @Autowired -// private ICouponsService couponsService; -// @Autowired -// private IWorkerSignService workerSignService; -// @Autowired -// private IWorkerLevelService workerLevelService; -// @Autowired -// private IOrderCommentService orderCommentService; -// @Autowired -// private IWorkerMarginLogService workerMarginLogService; -// @Autowired -// private IWorkerMoneyLogService workerMoneyLogService; -// @Autowired -// private IWechatTransferService wechatTransferService; -// @Autowired -// private IQuoteCraftService quoteCraftService; -// @Autowired -// private IQuoteTypeService quoteTypeService; -// @Autowired -// private IQuoteMaterialTypeService quoteMaterialTypeService; -// @Autowired -// private IQuoteMaterialService quoteMaterialService; -// @Autowired -// private IGoodsOrderCursorService goodsOrderCursorService; -// @Autowired -// private IWorkerApplyService workerApplyService; -// @Autowired -// private IUserMemberRechargeProgramService userMemberRechargeProgramService; -// -// @Autowired -// private IUserSecondaryCardService userSecondaryCardService; -// @Autowired -// private IUserGroupBuyingService userGroupBuyingService; -// @Autowired -// private IUsersPayBeforService usersPayBeforService; -// @Autowired -// private IUserDemandQuotationService userDemandQuotationService; - - - - /** * 获取服务分类列表 * 功能说明: @@ -1817,7 +136,7 @@ public class AppletController extends BaseController { * - 只返回title和icon字段 * - 自动添加图片CDN前缀 * - 支持用户登录状态验证(可选) - * + * * @param request HTTP请求对象 * @return 分类树形列表数据(只包含title和icon) */ @@ -1849,13 +168,13 @@ public class AppletController extends BaseController { // 3. 构建简化的分类数据(只包含title和icon) List> resultList = new ArrayList<>(); - + for (ServiceCate firstLevel : firstLevelCategories) { Map firstLevelData = new HashMap<>(); firstLevelData.put("id", firstLevel.getId()); firstLevelData.put("title", firstLevel.getTitle()); firstLevelData.put("icon", AppletControllerUtil.buildImageUrl(firstLevel.getIcon())); - + // 4. 处理二级分类 List> childrenList = new ArrayList<>(); List children = secondLevelMap.get(firstLevel.getId()); @@ -1869,7 +188,7 @@ public class AppletController extends BaseController { } } firstLevelData.put("children", childrenList); - + resultList.add(firstLevelData); } @@ -1884,7 +203,7 @@ public class AppletController extends BaseController { * - 根据配置名称获取对应的配置值 * - 配置值以JSON格式返回 * - 支持动态配置管理 - * + * * @param name 配置项名称 * @param request HTTP请求对象 * @return 配置信息数据 @@ -2524,18 +843,18 @@ public class AppletController extends BaseController { defaultCateQuery.setStatus(1L); // 启用状态 defaultCateQuery.setType(1L); // 类型为服务(假设1为服务类型) List defaultCateList = serviceCateService.selectServiceCateList(defaultCateQuery); - + if (defaultCateList.isEmpty()) { return AppletControllerUtil.appletkaifaWarning("未找到默认服务分类"); } - + // 按排序字段升序排列,取第一个 defaultCateList.sort((a, b) -> { Long sortA = a.getSort() != null ? a.getSort() : Long.MAX_VALUE; Long sortB = b.getSort() != null ? b.getSort() : Long.MAX_VALUE; return sortA.compareTo(sortB); }); - + // 给cate_id赋值为排序第一的分类ID cateId = defaultCateList.get(0).getId(); } @@ -2548,10 +867,10 @@ public class AppletController extends BaseController { if (category == null) { return AppletControllerUtil.appletkaifaWarning("分类不存在"); } - + if (category.getParentId() == null || category.getParentId() == 0L) { // 一级分类:返回该一级分类的服务分组 + 所有二级分类的服务分组 - + // 先添加一级分类本身的服务 List> firstLevelServices = getServicesByCategory(cateId); if (!firstLevelServices.isEmpty()) { @@ -2561,13 +880,13 @@ public class AppletController extends BaseController { firstLevelGroup.put("services", firstLevelServices); resultList.add(firstLevelGroup); } - + // 再添加该一级分类下所有二级分类的服务分组 ServiceCate childQuery = new ServiceCate(); childQuery.setParentId(cateId); childQuery.setStatus(1L); List childCategories = serviceCateService.selectServiceCateList(childQuery); - + for (ServiceCate child : childCategories) { List> childServices = getServicesByCategory(child.getId()); if (!childServices.isEmpty()) { @@ -2578,7 +897,7 @@ public class AppletController extends BaseController { resultList.add(childGroup); } } - + } else { // 二级分类:只返回该二级分类的服务分组 List> services = getServicesByCategory(cateId); @@ -2597,7 +916,7 @@ public class AppletController extends BaseController { } } - + /** * 根据分类ID查询该分类下的服务列表 * @param categoryId 分类ID @@ -2605,13 +924,13 @@ public class AppletController extends BaseController { */ private List> getServicesByCategory(Long categoryId) { List> serviceList = new ArrayList<>(); - + ServiceGoods queryGoods = new ServiceGoods(); queryGoods.setCateId(categoryId); queryGoods.setStatus("1"); // 只查询启用状态的商品 - + List goodsList = serviceGoodsService.selectServiceGoodsList(queryGoods); - + for (ServiceGoods goods : goodsList) { Map serviceData = new HashMap<>(); serviceData.put("id", goods.getId()); @@ -2619,7 +938,7 @@ public class AppletController extends BaseController { serviceData.put("icon", AppletControllerUtil.buildImageUrl(goods.getIcon())); serviceList.add(serviceData); } - + return serviceList; } /** @@ -2820,7 +1139,7 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletWarning("获取广告图片失败:" + e.getMessage()); } } - + /** * 获取商城分类列表 * @@ -2860,7 +1179,7 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletError("获取商城分类列表失败:" + e.getMessage()); } } - + /** * 获取热门推荐商品 * @@ -2884,14 +1203,14 @@ public class AppletController extends BaseController { // 查询符合条件的商品列表 List goodsList = serviceGoodsService.selectServiceGoodsList(queryGoods); - + // 按销量降序排序 goodsList.sort((a, b) -> { Long salesA = a.getSales() != null ? a.getSales() : 0L; Long salesB = b.getSales() != null ? b.getSales() : 0L; return salesB.compareTo(salesA); }); - + // 取前6个 if (goodsList.size() > 6) { goodsList = goodsList.subList(0, 6); @@ -2914,7 +1233,7 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletError("获取热门推荐商品失败:" + e.getMessage()); } } - + /** * 根据分类ID查询商品列表 * @@ -2950,7 +1269,7 @@ public class AppletController extends BaseController { // 判断是否查询全部商品 boolean queryAll = "00".equals(cateId.trim()) || cateId.trim().isEmpty(); - + if (!queryAll) { // 验证分类ID格式 Long categoryId; @@ -3016,7 +1335,7 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletError("查询分类商品失败:" + e.getMessage()); } } - + /** * 获取一级城市列表 * @@ -3052,7 +1371,7 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletError("获取城市列表失败:" + e.getMessage()); } } - + /** * 根据经纬度获取城市信息 * @@ -3073,20 +1392,20 @@ public class AppletController extends BaseController { if (params == null) { return AppletControllerUtil.appletWarning("请求参数不能为空"); } - + String latitude = params.get("latitude") != null ? params.get("latitude").toString() : ""; String longitude = params.get("longitude") != null ? params.get("longitude").toString() : ""; - + if (latitude.isEmpty() || longitude.isEmpty()) { return AppletControllerUtil.appletWarning("经纬度参数不能为空"); } - + // 验证经纬度格式并转换为double double lat, lng; try { lat = Double.parseDouble(latitude); lng = Double.parseDouble(longitude); - + // 验证经纬度范围 if (lat < -90 || lat > 90) { return AppletControllerUtil.appletWarning("纬度范围应在-90到90之间"); @@ -3097,20 +1416,20 @@ public class AppletController extends BaseController { } catch (NumberFormatException e) { return AppletControllerUtil.appletWarning("经纬度格式错误"); } - + // 2. 调用高德地图工具类获取位置信息 String city = GaoDeMapUtil.getCityByLocation(lng, lat); String address = GaoDeMapUtil.getAddressByLocation(lng, lat); - + // 3. 构建返回数据 Map locationInfo = new HashMap<>(); locationInfo.put("city", city != null ? city : ""); locationInfo.put("formatted_address", address != null ? address : ""); locationInfo.put("latitude", latitude); locationInfo.put("longitude", longitude); - + return AppletControllerUtil.appletSuccess(locationInfo); - + } catch (Exception e) { return AppletControllerUtil.appletError("获取位置信息失败:" + e.getMessage()); } @@ -3136,103 +1455,6 @@ public class AppletController extends BaseController { } - -// /** -// * 获取用户基本信息接口 -// * -// * @param request HTTP请求对象 -// * @return 用户基本信息 -// *

-// * 接口说明: -// * - 通过token获取当前登录用户的基本信息 -// * - 返回完整的用户数据 -// * - 需要用户登录验证 -// *

-// */ -// @GetMapping(value = "/api/user/info") -// public AjaxResult getUserInfo(HttpServletRequest request) { -// try { -// Map order_num = new HashMap<>(); -// Map goods_order_num = new HashMap<>(); -// // 1. 验证用户登录状态 -// String token = request.getHeader("token"); -// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); -// if (!(Boolean) userValidation.get("valid")) { -// return AppletControllerUtil.appletUnauthorized(); -// } -// -// // 2. 获取用户信息 -// Users user = (Users) userValidation.get("user"); -// if (user == null) { -// return AppletControllerUtil.appletWarning("用户信息获取失败"); -// } -// -// // 3. 构建精简用户信息响应数据 -// Map userInfo = new HashMap<>(); -// userInfo.put("nickname", user.getNickname()); -// userInfo.put("phone", user.getPhone()); -// userInfo.put("ismember", user.getIsmember()); -// userInfo.put("member_begin", user.getMemberBegin()); -// userInfo.put("member_end", user.getMemberEnd()); -// userInfo.put("balance", user.getBalance()); -// userInfo.put("integral", user.getIntegral()); -// userInfo.put("shop_money", user.getConsumption()); -// userInfo.put("service_money", user.getServicefee()); -// userInfo.put("birthday", user.getBirthday()); -// userInfo.put("remember_token", userInfo.get("rememberToken")); -// -// // 头像处理 -// String avatar = user.getAvatar(); -// if (avatar != null && !avatar.isEmpty()) { -// userInfo.put("avatar", AppletControllerUtil.buildImageUrl(avatar)); -// } else { -// userInfo.put("avatar", "https://img.huafurenjia.cn/default/user_avatar.jpeg"); -// } -// order_num.put("pending_accept", orderService.selectCountOrderByUid(user.getId(), 2L)); -// order_num.put("pending_service", orderService.selectCountOrderByUid(user.getId(), 3L)); -// order_num.put("in_service", orderService.selectCountOrderByUid(user.getId(), 4L)); -// order_num.put("other_status", orderService.selectAllCountOrderByUid(user.getId())); -// userInfo.put("order_num", order_num); -// -// -// goods_order_num.put("pending_accept", goodsOrderService.selectCountGoodsOrderByUid(user.getId(), 2L)); -// goods_order_num.put("pending_service", goodsOrderService.selectCountGoodsOrderByUid(user.getId(), 3L)); -// goods_order_num.put("in_service", goodsOrderService.selectCountGoodsOrderByUid(user.getId(), 5L)); -// goods_order_num.put("other_status", goodsOrderService.selectAllCountGoodsOrderByUid(user.getId())); -// userInfo.put("goods_order_num", goods_order_num); -// // 新增tx_time字段 -// List txTimeArr = new ArrayList<>(); -// try { -// SiteConfig configQuery = new SiteConfig(); -// configQuery.setName("config_four"); -// List configList = siteConfigService.selectSiteConfigList(configQuery); -// if (configList != null && !configList.isEmpty()) { -// String configValue = configList.get(0).getValue(); -// if (configValue != null && !configValue.trim().isEmpty()) { -// JSONObject json = JSONObject.parse(configValue); -// if (json.containsKey("time")) { -// Object timeObj = json.get("time"); -// if (timeObj instanceof List) { -// txTimeArr = (List) timeObj; -// } else if (timeObj instanceof JSONArray) { -// txTimeArr = ((JSONArray) timeObj).toJavaList(Object.class); -// } -// } -// } -// } -// } catch (Exception ignore) { -// } -// userInfo.put("tx_time", txTimeArr); -// return AppletControllerUtil.appletSuccess(userInfo); -// } catch (Exception e) { -// System.err.println("查询用户基本信息异常:" + e.getMessage()); -// return AppletControllerUtil.appletError("查询用户信息失败:" + e.getMessage()); -// } -// } - - - - /** * 获取用户基本信息接口 * @@ -3614,96 +1836,6 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletWarning("查询订单状态失败:" + e.getMessage()); } } -// /** -// * 查询用户售后返修列表 -// * -// * @param params 请求参数,包含page(页码)、limit(每页数量) -// * @param request HTTP请求对象 -// * @return 返回分页的售后返修列表 -// *

-// * 功能说明: -// * - 获取当前登录用户的售后返修记录 -// * - 支持分页查询 -// * - 按创建时间倒序排列 -// * - 返回符合前端要求的分页格式 -// */ -// @PostMapping("/api/service/order/rework/lst") -// public AjaxResult getReworkList(@RequestBody Map params, HttpServletRequest request) { -// try { -// // 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"); -// -// // 2. 验证分页参数 -// Map pageValidation = PageUtil.validatePageParams(page, limit); -// if (!(Boolean) pageValidation.get("valid")) { -// return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); -// } -// -// // 3. 验证用户登录状态 -// String token = request.getHeader("token"); -// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); -// if (!(Boolean) userValidation.get("valid")) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// -// // 4. 获取用户信息 -// Users user = (Users) userValidation.get("user"); -// if (user == null) { -// return AppletControllerUtil.appletdengluWarning("用户信息获取失败"); -// } -// -// // 5. 设置分页参数 -// PageHelper.startPage(page, limit); -// -// // 6. 构建查询条件 -// OrderRework queryCondition = new OrderRework(); -// queryCondition.setUid(user.getId()); // 只查询当前用户的售后记录 -// queryCondition.setStatus(status); -// // 7. 查询售后返修列表 -// List reworkList = orderReworkService.selectOrderReworkList(queryCondition); -// -// // 8. 构建分页数据 -// PageInfo pageInfo = new PageInfo<>(reworkList); -// -// // 9. 构建返回数据格式 -// Map responseData = new HashMap<>(); -// responseData.put("current_page", pageInfo.getPageNum()); -// responseData.put("data", reworkList); -// responseData.put("from", pageInfo.getStartRow()); -// responseData.put("last_page", pageInfo.getPages()); -// responseData.put("per_page", String.valueOf(pageInfo.getPageSize())); -// responseData.put("to", pageInfo.getEndRow()); -// responseData.put("total", pageInfo.getTotal()); -// -// // 构建分页链接信息 -// Map links = new HashMap<>(); -// Map prevLink = new HashMap<>(); -// prevLink.put("url", null); -// prevLink.put("label", "« Previous"); -// 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("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("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); -// -// return AppletControllerUtil.appletSuccess(responseData); -// -// } catch (Exception e) { -// System.err.println("查询售后返修列表异常:" + e.getMessage()); -// return AppletControllerUtil.appletWarning("查询售后返修列表失败:" + e.getMessage()); -// } -// } /** * 合作申请提交接口 @@ -5080,7 +3212,7 @@ public class AppletController extends BaseController { } else { sku = null; } - + // 5. 获取新增的三个参数:ordertype、fileData、remark Long ordertype = null; if (params.get("ordertype") != null) { @@ -5119,12 +3251,12 @@ public class AppletController extends BaseController { fileData = fileDataObj.toString(); } } - + String reamk = null; if (params.get("reamk") != null) { reamk = params.get("reamk").toString(); } - + // 6. 查询商品信息并验证 ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodId); if (serviceGoods == null) { @@ -6683,7 +4815,7 @@ public class AppletController extends BaseController { baojiadata.put("isbaojia", "2"); } data.put("baojia", baojiadata); - + // 添加上门标准数据 try { SiteConfig serviceStandardConfig = siteConfigService.selectSiteConfigByName("config_ten"); @@ -6706,7 +4838,7 @@ public class AppletController extends BaseController { logger.warn("获取上门标准配置失败: " + e.getMessage()); data.put("serviceStandard", ""); } - + return AjaxResult.success(data); } catch (Exception e) { return AppletControllerUtil.appletError("查询师傅订单详情失败:" + e.getMessage()); @@ -9496,10 +7628,10 @@ public class AppletController extends BaseController { } JSONArray noticeArray = (JSONArray) noticeObj; - + // 4. 过滤上线状态的公告并构建返回数据 List> resultList = new ArrayList<>(); - + for (int i = 0; i < noticeArray.size(); i++) { try { JSONObject noticeItem = noticeArray.getJSONObject(i); @@ -9566,7 +7698,7 @@ public class AppletController extends BaseController { // 1. 获取分页参数并进行安全的类型转换 int page = 1; int limit = 15; - + if (params.get("page") != null) { try { page = Integer.parseInt(params.get("page").toString()); @@ -9575,7 +7707,7 @@ public class AppletController extends BaseController { page = 1; } } - + if (params.get("limit") != null) { try { limit = Integer.parseInt(params.get("limit").toString()); @@ -9585,7 +7717,7 @@ public class AppletController extends BaseController { limit = 15; } } - + String keywords = params.get("keywords") != null ? params.get("keywords").toString().trim() : ""; // 2. 验证分页参数 @@ -9801,20 +7933,20 @@ public class AppletController extends BaseController { // 构建返回数据 List> resultList = new ArrayList<>(); - + for (ServiceGoods goods : goodsList) { Map goodsData = new HashMap<>(); - + // 基本信息 goodsData.put("id", goods.getId()); goodsData.put("groupnum", goods.getGroupnum()); goodsData.put("title", goods.getTitle()); goodsData.put("price", goods.getPrice() != null ? goods.getPrice().toString() : "0.00"); goodsData.put("groupprice", goods.getGroupprice() != null ? goods.getGroupprice().toString() : "0.00"); - + // 处理图片URL - 添加CDN前缀 goodsData.put("icon", AppletControllerUtil.buildImageUrl(goods.getIcon())); - + resultList.add(goodsData); } @@ -10027,7 +8159,7 @@ public class AppletController extends BaseController { TableDataInfo tableDataInfo = getDataTable(goodsList); tableDataInfo.setRows(resultList); // 只返回精简字段 Map pageData = PageUtil.buildPageResponse(tableDataInfo, page, limit); - + // 获取秒杀相关数据 long msdata = 0L; try { @@ -10035,13 +8167,13 @@ public class AppletController extends BaseController { SiteConfig configQuery = new SiteConfig(); configQuery.setName("config_one"); List configList = siteConfigService.selectSiteConfigList(configQuery); - + if (configList != null && !configList.isEmpty()) { String configValue = configList.get(0).getValue(); if (configValue != null && !configValue.trim().isEmpty()) { JSONObject configJson = JSONObject.parseObject(configValue); String mstime = configJson.getString("mstime"); - + if (mstime != null && !mstime.trim().isEmpty()) { // 解析秒杀结束时间 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -10054,7 +8186,7 @@ public class AppletController extends BaseController { // 解析异常时设置为0 msdata = 0L; } - + Map reData = new HashMap<>(); reData.put("listData", pageData); reData.put("msdata", msdata); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderUtil.java index 7b31127..2d28ada 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderUtil.java @@ -78,7 +78,7 @@ public class OrderUtil { /** * 生成订单编码的工具 - * + * * @return 格式为 C + yyyyMMdd + 随机数字 的订单编号 */ public static String generateCode() { @@ -126,7 +126,7 @@ public class OrderUtil { /** * 执行状态验证 - * + * * @param validator 状态验证器 * @param newOrder 新订单 * @param newStatus 新状态 @@ -161,7 +161,7 @@ public class OrderUtil { /** * 保存订单日志 * 委托给OrderLogHandler处理具体的业务逻辑 - * + * * @param order 订单对象,包含状态和服务进度信息 * @return 影响的行数,大于0表示保存成功 * @throws IllegalArgumentException 当订单参数无效时 @@ -174,10 +174,10 @@ public class OrderUtil { // 委托给OrderLogHandler处理 OrderLog orderLog = orderLogHandler.createBaseOrderLog(order); orderLogHandler.processOrderStatus(order, orderLog); - + // 保存订单日志 return orderLogService.insertOrderLog(orderLog); - + } catch (Exception e) { // 记录异常信息(这里可以添加日志记录) throw new RuntimeException("保存订单日志失败: " + e.getMessage(), e); @@ -186,7 +186,7 @@ public class OrderUtil { /** * 验证订单日志参数 - * + * * @param order 订单对象 */ private void validateOrderForLog(Order order) { @@ -200,14 +200,14 @@ public class OrderUtil { /** * 根据用户手机号判断用户是否存在,如果不存在则新增用户数据 - * + * * @param phone 用户手机号 * @param addressName 地址名称 * @return 包含用户和地址信息的Map */ public Map isUser(String phone, String addressName) { Users existingUser = usersService.selectUsersByPhone(phone); - + if (existingUser == null) { // 用户不存在,创建新用户 Users newUser = createNewUser(phone); @@ -223,7 +223,7 @@ public class OrderUtil { /** * 创建新用户对象 - * + * * @param phone 用户手机号 * @return 新用户对象 */ @@ -238,7 +238,7 @@ public class OrderUtil { /** * 创建失败结果 - * + * * @return 失败结果Map */ private Map createFailureResult() { @@ -249,7 +249,7 @@ public class OrderUtil { /** * 根据用户地址获取经纬度,然后存储地址数据 - * + * * @param user 用户对象 * @param addressName 地址名称 * @return 包含处理结果的Map @@ -257,7 +257,7 @@ public class OrderUtil { public Map isAddAddressUser(Users user, String addressName) { // 查询用户是否已有该地址 List existingAddresses = findExistingAddress(user.getId(), addressName); - + if (!existingAddresses.isEmpty()) { // 地址已存在 return createSuccessResult(user, existingAddresses.get(0)); @@ -269,7 +269,7 @@ public class OrderUtil { /** * 查找已存在的地址 - * + * * @param userId 用户ID * @param addressName 地址名称 * @return 地址列表 @@ -283,7 +283,7 @@ public class OrderUtil { /** * 创建成功结果 - * + * * @param user 用户对象 * @param address 地址对象 * @return 成功结果Map @@ -298,7 +298,7 @@ public class OrderUtil { /** * 创建新的用户地址 - * + * * @param user 用户对象 * @param addressName 地址名称 * @return 包含处理结果的Map @@ -306,17 +306,17 @@ public class OrderUtil { private Map createNewUserAddress(Users user, String addressName) { try { UserAddress userAddress = buildUserAddress(user, addressName); - + // 获取地址的经纬度信息 setAddressCoordinates(userAddress, addressName); - + // 保存地址 if (SpringUtils.getBean(IUserAddressService.class).insertUserAddress(userAddress) > 0) { return createSuccessResult(user, userAddress); } else { return createFailureResult(); } - + } catch (Exception e) { Map map = new HashMap<>(); map.put("code", "0"); @@ -327,7 +327,7 @@ public class OrderUtil { /** * 构建用户地址对象 - * + * * @param user 用户对象 * @param addressName 地址名称 * @return 用户地址对象 @@ -346,7 +346,7 @@ public class OrderUtil { /** * 设置地址的经纬度坐标 - * + * * @param userAddress 用户地址对象 * @param addressName 地址名称 */ @@ -354,7 +354,7 @@ public class OrderUtil { try { AmapUtils amapUtils = new AmapUtils(); JSONObject geoResult = amapUtils.geocode(addressName); - + if ("OK".equals(geoResult.get("info"))) { parseCoordinates(userAddress, geoResult); } @@ -366,7 +366,7 @@ public class OrderUtil { /** * 解析坐标信息 - * + * * @param userAddress 用户地址对象 * @param geoResult 地理编码结果 */ @@ -375,7 +375,7 @@ public class OrderUtil { if (geocodes != null && !geocodes.isEmpty()) { JSONObject firstGeocode = geocodes.getJSONObject(0); String location = firstGeocode.getString("location"); - + if (location != null && location.contains(",")) { String[] coordinates = location.split(","); userAddress.setLongitude(coordinates[0]); // 经度 @@ -471,23 +471,23 @@ public class OrderUtil { /** * 订单价格确认工具方法 * 根据服务ID、SKU、是否一口价和订单类型计算最终价格 - * + * * @param serviceId 服务ID * @param sku SKU信息,格式:{"精细擦玻璃":"20㎡全屋精细擦窗","pic":"","price":"236","groupprice":"100","seckillprice":"99","stock":"1000"} * @param type 订单类别 1=拼团 2=次卡 3=秒杀 * @return 计算后的价格,如果计算失败返回null - * + * * 使用示例: * // 一口价订单(单规格) * BigDecimal price1 = OrderUtil.confirmOrderPrice(1L, null, 1, 1); - * + * * // 一口价订单(多规格) * String sku = "{\"精细擦玻璃\":\"20㎡全屋精细擦窗\",\"pic\":\"\",\"price\":\"236\",\"groupprice\":\"100\",\"seckillprice\":\"99\",\"stock\":\"1000\"}"; * BigDecimal price2 = OrderUtil.confirmOrderPrice(1L, sku, 1, 1); - * + * * // 拼团订单(单规格) * BigDecimal price3 = OrderUtil.confirmOrderPrice(1L, null, 2, 1); - * + * * // 秒杀订单(多规格) * BigDecimal price4 = OrderUtil.confirmOrderPrice(1L, sku, 2, 3); */ @@ -501,7 +501,7 @@ public class OrderUtil { // 获取服务商品信息 IServiceGoodsService serviceGoodsService = SpringUtils.getBean(IServiceGoodsService.class); ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(serviceId); - + if (serviceGoods == null) { return null; } @@ -534,7 +534,7 @@ public class OrderUtil { } return null; - + } catch (Exception e) { // 记录异常信息(这里可以添加日志记录) System.err.println("订单价格确认失败: " + e.getMessage()); @@ -544,7 +544,7 @@ public class OrderUtil { /** * 处理单规格商品价格计算 - * + * * @param serviceGoods 服务商品对象 * @param type 订单类型 1=拼团 2=次卡 3=秒杀 * @return 计算后的价格 @@ -564,7 +564,7 @@ public class OrderUtil { /** * 处理多规格商品价格计算 - * + * * @param sku SKU信息JSON字符串 * @param type 订单类型 1=拼团 2=次卡 3=秒杀,null表示获取基础价格 * @return 计算后的价格 @@ -577,13 +577,13 @@ public class OrderUtil { // 解析SKU JSON JSONObject skuJson = JSONObject.parseObject(sku); - + // 如果type为null,获取基础价格 if (type == null) { String priceStr = skuJson.getString("price"); return parsePrice(priceStr); } - + switch (type) { case 1: // 拼团 String groupPriceStr = skuJson.getString("groupprice"); @@ -598,7 +598,7 @@ public class OrderUtil { String defaultPriceStr = skuJson.getString("price"); return parsePrice(defaultPriceStr); } - + } catch (Exception e) { System.err.println("解析多规格SKU价格失败: " + e.getMessage()); return null; @@ -607,7 +607,7 @@ public class OrderUtil { /** * 解析价格字符串为BigDecimal - * + * * @param priceStr 价格字符串 * @return BigDecimal价格,解析失败返回null */ @@ -643,7 +643,7 @@ public class OrderUtil { System.out.println("服务类型 - servicetype: " + payBefor.getServicetype()); IOrderService orderService = SpringUtils.getBean(IOrderService.class); - + // 单个商品支付 if (type == 5){ GoodsOrder gorder = new GoodsOrder(); @@ -668,7 +668,7 @@ public class OrderUtil { System.out.println("查询拼团商品订单 - orderid: " + payBefor.getOrderid()); List orderslist =goodsOrderService.selectGoodsOrderList(gorder); System.out.println("查询到的商品订单数量: " + (orderslist != null ? orderslist.size() : 0)); - + if (!orderslist.isEmpty()){ System.out.println("开始更新商品订单状态"); for (GoodsOrder goodsOrder : orderslist){ @@ -802,25 +802,25 @@ public class OrderUtil { // 查询订单 Order order = orderService.selectOrderByOrderId(payBefor.getOrderid()); System.out.println("查询到的订单: " + (order != null ? order.toString() : "null")); - + if (order != null) { UserDemandQuotation userDemandQuotation=userDemandQuotationService.selectUserDemandQuotationById(payBefor.getBaojiaid()); - + if (userDemandQuotation!=null) { System.out.println("找到报价记录,开始处理"); //UserDemandQuotation userDemandQuotation=userDemandQuotationList.getFirst(); System.out.println("报价记录详情: " + userDemandQuotation.toString()); - + System.out.println("更新报价状态为被选中"); userDemandQuotation.setStatus(2L);//被选中状态 int quotationUpdateResult = userDemandQuotationService.updateUserDemandQuotation(userDemandQuotation); System.out.println("报价状态更新结果: " + quotationUpdateResult); - + System.out.println("查询师傅信息 - workerId: " + userDemandQuotation.getWorkerid()); Users users = usersService.selectUsersById(userDemandQuotation.getWorkerid()); System.out.println("查询到的师傅信息: " + (users != null ? users.toString() : "null")); - + if (users != null){ order.setStatus(2L); @@ -833,7 +833,7 @@ public class OrderUtil { order.setWorkerId(users.getId()); int orderUpdateResult = orderService.updateOrder(order); System.out.println("订单更新结果: " + orderUpdateResult); - + // 添加订单日志 System.out.println("添加订单日志"); OrderLog orderLog = new OrderLog(); @@ -944,14 +944,14 @@ public class OrderUtil { Order order = new Order(); order.setOdertype(1); // 拼团 order.setStatus(9L); // 9=待成团 - order.setPayPrice(order.getPayPrice().add(payBefor.getAllmoney())); + order.setOrderId(ptorderid); order.setUid(payBefor.getUid()); order.setNum(payBefor.getNum()); // 默认1,可根据业务调整 //order.setProductId(payBefor.getSku() != null ? Long.valueOf(payBefor.getSku()) : null); // 假设sku字段存储商品ID order.setProductId(payBefor.getServiceid()); // 假设sku字段存储商品ID System.out.println("商品ID: " + payBefor.getServiceid()); - + IServiceGoodsService serviceGoodsService = SpringUtils.getBean(IServiceGoodsService.class); ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(payBefor.getServiceid()); System.out.println("查询到的商品信息: " + (serviceGoods != null ? serviceGoods.toString() : "null")); @@ -976,7 +976,8 @@ public class OrderUtil { order.setType(1); // 服务订单 order.setCreateType(1); // 用户自主下单 order.setUname(user.getName()); - System.out.println("订单基本信息设置完成"); + //20250809处理过的一个故障 + order.setPayPrice(payBefor.getAllmoney()); order.setReceiveType(Long.valueOf(dispatchtype)); // 自由抢单 // 预约时间 System.out.println("预约时间: " + payBefor.getMaketime()); @@ -1010,7 +1011,7 @@ public class OrderUtil { System.out.println("开始插入订单"); int orderInsertResult = orderService.insertOrder(order); System.out.println("订单插入结果: " + orderInsertResult + ", 订单ID: " + order.getId()); - + // 添加订单日志 System.out.println("添加订单日志"); IOrderLogService orderLogService = SpringUtils.getBean(IOrderLogService.class); @@ -1030,7 +1031,7 @@ public class OrderUtil { IUserGroupBuyingService userGroupBuyingService = SpringUtils.getBean(IUserGroupBuyingService.class); UserGroupBuying userGroupBuying = userGroupBuyingService.selectUserGroupBuyingByptorderid(ptorderid); System.out.println("查询到的拼团记录: " + (userGroupBuying != null ? userGroupBuying.toString() : "null")); - + if (userGroupBuying != null){ System.out.println("更新拼团状态"); userGroupBuying.setStatus(1L); @@ -1044,7 +1045,7 @@ public class OrderUtil { System.out.println("=== 第三步:核验团数据 ==="); System.out.println("团订单ID: " + payBefor.getGrouporderid()); System.out.println("商品拼团人数要求: " + (serviceGoods != null ? serviceGoods.getGroupnum() : "null")); - + UserGroupBuying userGroupBuyingData = new UserGroupBuying(); userGroupBuyingData.setOrderid(payBefor.getGrouporderid()); userGroupBuyingData.setPaystatus(1L); @@ -1088,7 +1089,7 @@ public class OrderUtil { IUserUseSecondaryCardService userUseSecondaryCardService = SpringUtils.getBean(IUserUseSecondaryCardService.class); UserUseSecondaryCard userUseSecondaryCard = userUseSecondaryCardService.selectUserUseSecondaryCardByorderId(payBefor.getOrderid()); System.out.println("查询到的次卡记录: " + (userUseSecondaryCard != null ? userUseSecondaryCard.toString() : "null")); - + if (userUseSecondaryCard != null){ System.out.println("更新次卡状态"); userUseSecondaryCard.setStatus(1L); @@ -1121,7 +1122,7 @@ public class OrderUtil { System.out.println("处理普通订单"); Order order = orderService.selectOrderByOrderId(payBefor.getOrderid()); System.out.println("查询到的订单: " + (order != null ? order.toString() : "null")); - + if (order != null) { System.out.println("添加订单日志"); OrderLog orderLog = new OrderLog(); @@ -1137,7 +1138,7 @@ public class OrderUtil { DispatchUtil.dispatchOrder(order.getId()); } System.out.println("订单日志插入结果: " + logInsertResult); - + System.out.println("更新订单状态为待派单"); order.setPayPrice(order.getPayPrice().add(payBefor.getAllmoney())); order.setStatus(1L); // 1=待预约 @@ -1216,7 +1217,7 @@ public class OrderUtil { * 用户付款后回调中修改订单状态的辅助方法 * 逻辑:如果用户付款的时候,查询paynum=0(没有可付款的数据), * 且订单最新状态大于等于6(师傅已完成),那么就修改订单为已完成状态 - * + * * @param orderid 订单ID * @return 剩余可付款数量 */ @@ -1251,13 +1252,13 @@ public class OrderUtil { // 5. 如果paynum=0且师傅已完成,则修改订单为已完成状态 if (paynum <= 0 && isWorkerCompleted) { System.out.println("订单 " + orderid + " 满足完成条件:无剩余付款且师傅已完成,开始修改订单状态"); - + // 修改订单状态为已完成 order.setStatus(4L); // 4:已完成 order.setReceiveType(3L); // 3:完成类型 order.setJsonStatus(9); // 9:已完成 order.setLogJson("{\"type\":8}"); // 8:完成状态 - + int updateResult = orderService.updateOrder(order); System.out.println("订单状态更新结果: " + updateResult); @@ -1298,7 +1299,7 @@ public class OrderUtil { // } return paynum; - + } catch (Exception e) { System.err.println("ISTOPAYSIZE方法执行异常,orderid: " + orderid + ", 错误: " + e.getMessage()); e.printStackTrace(); @@ -1375,22 +1376,22 @@ public class OrderUtil { return result; } } - + // 智能派单 - 调用DispatchUtil进行智能派单 try { System.out.println("【OrderUtil】开始智能派单,订单ID: " + order.getId()); DispatchUtil.DispatchResult dispatchResult = DispatchUtil.dispatchOrder(order.getId()); - + if (dispatchResult.isSuccess()) { Users selectedWorker = dispatchResult.getWorker(); System.out.println("【OrderUtil】智能派单成功,选中师傅: " + selectedWorker.getName()); - + // 更新订单状态和师傅信息 order.setStatus(1L); // 待服务 order.setWorkerId(selectedWorker.getId()); order.setWorkerPhone(selectedWorker.getPhone()); orderService.updateOrder(order); - + // 添加订单日志 OrderLog orderLog = new OrderLog(); orderLog.setOid(order.getId()); @@ -1401,26 +1402,26 @@ public class OrderUtil { jsonObject.put("name", "智能派单成功,师傅: " + selectedWorker.getName()); orderLog.setContent(jsonObject.toJSONString()); orderLogService.insertOrderLog(orderLog); - + result.put("success", true); result.put("msg", "智能派单成功,师傅: " + selectedWorker.getName()); result.put("workerId", selectedWorker.getId()); result.put("workerName", selectedWorker.getName()); result.put("workerPhone", selectedWorker.getPhone()); - + } else { System.out.println("【OrderUtil】智能派单失败: " + dispatchResult.getMessage()); result.put("success", false); result.put("msg", "智能派单失败: " + dispatchResult.getMessage()); } - + } catch (Exception e) { System.out.println("【OrderUtil】智能派单异常: " + e.getMessage()); e.printStackTrace(); result.put("success", false); result.put("msg", "智能派单异常: " + e.getMessage()); } - + return result; } @@ -1502,7 +1503,7 @@ public class OrderUtil { /** * 库存及销量变更 * 根据订单ID更新商品/服务的销量和库存 - * + * * @param orderid 订单ID * @param type 商品类型 1=服务类商品 2=商城类商品 * @return 处理结果,成功返回true,失败返回false @@ -1510,7 +1511,7 @@ public class OrderUtil { /** * 库存及销量变更方法 * 根据订单ID更新商品/服务的销量和库存 - * + * * @param orderid 订单ID * @param type 商品类型:1-服务类商品,2-商城类商品 * @return 处理结果,成功返回true,失败返回false @@ -1522,12 +1523,12 @@ public class OrderUtil { System.err.println("订单ID不能为空"); return false; } - + if (type == null || (type != 1 && type != 2)) { System.err.println("无效的商品类型,type: " + type + ", orderid: " + orderid); return false; } - + // 1. 根据type查询订单数据 Object order = null; if (type == 1) { @@ -1539,18 +1540,18 @@ public class OrderUtil { IGoodsOrderService goodsOrderService = SpringUtils.getBean(IGoodsOrderService.class); order = goodsOrderService.selectGoodsOrderByorderId(orderid); } - + if (order == null) { System.err.println("未找到订单数据,orderid: " + orderid + ", type: " + type); return false; } - + // 2. 提取订单信息 IServiceGoodsService serviceGoodsService = SpringUtils.getBean(IServiceGoodsService.class); Long productId = null; Long orderNum = null; String orderSku = null; - + if (type == 1) { // 服务类商品 Order serviceOrder = (Order) order; @@ -1564,65 +1565,65 @@ public class OrderUtil { orderNum = goodsOrder.getNum() != null ? goodsOrder.getNum() : 1L; orderSku = goodsOrder.getSku(); } - + // 验证商品ID if (productId == null) { System.err.println("订单商品ID为空,orderid: " + orderid + ", type: " + type); return false; } - + // 3. 查询商品/服务数据 ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); - + if (serviceGoods == null) { System.err.println("未找到商品/服务数据,productId: " + productId + ", type: " + type); return false; } - + // 4. 增加销量(无论是否有SKU都要增加销量) Long currentSales = serviceGoods.getSales() != null ? serviceGoods.getSales() : 0L; serviceGoods.setSales(currentSales + orderNum); - - System.out.println("销量更新:商品ID: " + serviceGoods.getId() + - ", 原销量: " + currentSales + ", 增加销量: " + orderNum + + + System.out.println("销量更新:商品ID: " + serviceGoods.getId() + + ", 原销量: " + currentSales + ", 增加销量: " + orderNum + ", 新销量: " + serviceGoods.getSales()); - + // 5. 更新库存 updateStock(serviceGoods, orderSku, orderNum, type); - + // 6. 保存更新后的商品/服务数据 int updateResult = serviceGoodsService.updateServiceGoods(serviceGoods); - + if (updateResult > 0) { - System.out.println("库存及销量更新成功,orderid: " + orderid + + System.out.println("库存及销量更新成功,orderid: " + orderid + ", type: " + type + ", 销量增加: " + orderNum + ", 商品ID: " + serviceGoods.getId()); return true; } else { System.err.println("库存及销量更新失败,orderid: " + orderid + ", type: " + type); return false; } - + } catch (Exception e) { System.err.println("库存及销量变更异常,orderid: " + orderid + ", type: " + type + ", 错误: " + e.getMessage()); e.printStackTrace(); return false; } } - + /** * 库存及销量变更(兼容旧版本) * 根据订单ID更新商品/服务的销量和库存,默认为服务类商品 - * + * * @param orderid 订单ID * @return 处理结果,成功返回true,失败返回false */ // public static boolean updateInventoryAndSales(String orderid) { //// return updateInventoryAndSales(orderid, 1); // 默认为服务类商品 // } - + /** * 更新库存逻辑 - * + * * @param serviceGoods 商品/服务对象 * @param orderSku 订单SKU * @param orderNum 订单数量 @@ -1635,20 +1636,20 @@ public class OrderUtil { System.err.println("商品对象为空,无法更新库存"); return; } - + if (orderNum == null || orderNum <= 0) { System.err.println("订单数量无效,orderNum: " + orderNum); return; } - + // 如果订单的sku为空或null,直接扣减ServiceGoods的库存 if (orderSku == null || orderSku.trim().isEmpty()) { Long currentStock = serviceGoods.getStock() != null ? serviceGoods.getStock() : 0L; Long newStock = Math.max(0, currentStock - orderNum); // 确保库存不为负数 serviceGoods.setStock(newStock); - - System.out.println("直接扣减库存,商品ID: " + serviceGoods.getId() + - ", 原库存: " + currentStock + ", 扣减数量: " + orderNum + + + System.out.println("直接扣减库存,商品ID: " + serviceGoods.getId() + + ", 原库存: " + currentStock + ", 扣减数量: " + orderNum + ", 剩余库存: " + newStock); } else { // 根据商品类型选择不同的SKU更新方法 @@ -1663,14 +1664,14 @@ public class OrderUtil { } } } catch (Exception e) { - System.err.println("更新库存异常,商品ID: " + (serviceGoods != null ? serviceGoods.getId() : "null") + + System.err.println("更新库存异常,商品ID: " + (serviceGoods != null ? serviceGoods.getId() : "null") + ", 错误: " + e.getMessage()); } } - + /** * 更新SKU库存 - * + * * @param serviceGoods 商品/服务对象 * @param orderSku 订单SKU(具体规格选择) * @param orderNum 订单数量 @@ -1682,18 +1683,18 @@ public class OrderUtil { System.err.println("商品对象为空,无法更新SKU库存"); return; } - + if (orderSku == null || orderSku.trim().isEmpty()) { System.err.println("订单SKU为空,无法更新SKU库存"); return; } - + String serviceSku = serviceGoods.getSku(); if (serviceSku == null || serviceSku.trim().isEmpty()) { System.err.println("商品SKU为空,无法更新SKU库存,商品ID: " + serviceGoods.getId()); return; } - + // 解析ServiceGoods的SKU JSON(复杂多规格格式) JSONObject skuJson; try { @@ -1702,20 +1703,20 @@ public class OrderUtil { System.err.println("商品SKU JSON格式错误,商品ID: " + serviceGoods.getId() + ", SKU: " + serviceSku); return; } - + // 检查是否是复杂多规格格式 if (!skuJson.containsKey("sku") || !skuJson.containsKey("type")) { System.err.println("商品SKU格式不是多规格格式,商品ID: " + serviceGoods.getId()); return; } - + // 获取sku数组 JSONArray skuArray = skuJson.getJSONArray("sku"); if (skuArray == null || skuArray.isEmpty()) { System.err.println("商品SKU数组为空,商品ID: " + serviceGoods.getId()); return; } - + // 解析订单SKU(具体规格选择) JSONObject orderSkuJson; try { @@ -1724,33 +1725,33 @@ public class OrderUtil { System.err.println("订单SKU JSON格式错误,订单SKU: " + orderSku); return; } - + // 在sku数组中查找匹配的规格 boolean found = false; for (int i = 0; i < skuArray.size(); i++) { JSONObject skuItem = skuArray.getJSONObject(i); - + // 检查是否匹配订单SKU的所有属性 if (isSkuMatch(skuItem, orderSkuJson)) { // 找到匹配的SKU,更新库存 String stockStr = skuItem.getString("stock"); - + if (stockStr != null && !stockStr.trim().isEmpty()) { try { Long currentStock = Long.parseLong(stockStr); Long newStock = Math.max(0, currentStock - orderNum); // 确保库存不为负数 skuItem.put("stock", newStock.toString()); - + // 更新ServiceGoods的sku字段 serviceGoods.setSku(skuJson.toJSONString()); - - System.out.println("SKU库存更新成功,商品ID: " + serviceGoods.getId() + - ", 订单SKU: " + orderSku + ", 原库存: " + currentStock + + + System.out.println("SKU库存更新成功,商品ID: " + serviceGoods.getId() + + ", 订单SKU: " + orderSku + ", 原库存: " + currentStock + ", 扣减数量: " + orderNum + ", 剩余库存: " + newStock); found = true; break; } catch (NumberFormatException e) { - System.err.println("SKU库存格式错误,商品ID: " + serviceGoods.getId() + + System.err.println("SKU库存格式错误,商品ID: " + serviceGoods.getId() + ", SKU: " + orderSku + ", 库存值: " + stockStr); } } else { @@ -1758,21 +1759,21 @@ public class OrderUtil { } } } - + if (!found) { - System.err.println("未找到匹配的SKU,商品ID: " + serviceGoods.getId() + + System.err.println("未找到匹配的SKU,商品ID: " + serviceGoods.getId() + ", 订单SKU: " + orderSku + ", 商品SKU数组大小: " + skuArray.size()); } - + } catch (Exception e) { - System.err.println("更新SKU库存异常,商品ID: " + (serviceGoods != null ? serviceGoods.getId() : "null") + + System.err.println("更新SKU库存异常,商品ID: " + (serviceGoods != null ? serviceGoods.getId() : "null") + ", 订单SKU: " + orderSku + ", 错误: " + e.getMessage()); } } - + /** * 更新商城商品SKU库存 - * + * * @param serviceGoods 商品/服务对象 * @param orderSku 订单SKU(具体规格选择) * @param orderNum 订单数量 @@ -1784,18 +1785,18 @@ public class OrderUtil { System.err.println("商品对象为空,无法更新SKU库存"); return; } - + if (orderSku == null || orderSku.trim().isEmpty()) { System.err.println("订单SKU为空,无法更新SKU库存"); return; } - + String serviceSku = serviceGoods.getSku(); if (serviceSku == null || serviceSku.trim().isEmpty()) { System.err.println("商品SKU为空,无法更新SKU库存,商品ID: " + serviceGoods.getId()); return; } - + // 解析ServiceGoods的SKU JSON(商城商品格式) JSONObject skuJson; try { @@ -1804,20 +1805,20 @@ public class OrderUtil { System.err.println("商品SKU JSON格式错误,商品ID: " + serviceGoods.getId() + ", SKU: " + serviceSku); return; } - + // 检查是否是商城商品格式 if (!skuJson.containsKey("sku") || !skuJson.containsKey("type")) { System.err.println("商品SKU格式不是商城商品格式,商品ID: " + serviceGoods.getId()); return; } - + // 获取sku数组 JSONArray skuArray = skuJson.getJSONArray("sku"); if (skuArray == null || skuArray.isEmpty()) { System.err.println("商品SKU数组为空,商品ID: " + serviceGoods.getId()); return; } - + // 解析订单SKU(具体规格选择) JSONObject orderSkuJson; try { @@ -1826,33 +1827,33 @@ public class OrderUtil { System.err.println("订单SKU JSON格式错误,订单SKU: " + orderSku); return; } - + // 在sku数组中查找匹配的规格 boolean found = false; for (int i = 0; i < skuArray.size(); i++) { JSONObject skuItem = skuArray.getJSONObject(i); - + // 检查是否匹配订单SKU的"价格"属性 if (isGoodsSkuMatch(skuItem, orderSkuJson)) { // 找到匹配的SKU,更新库存 String stockStr = skuItem.getString("stock"); - + if (stockStr != null && !stockStr.trim().isEmpty()) { try { Long currentStock = Long.parseLong(stockStr); Long newStock = Math.max(0, currentStock - orderNum); // 确保库存不为负数 skuItem.put("stock", newStock.toString()); - + // 更新ServiceGoods的sku字段 serviceGoods.setSku(skuJson.toJSONString()); - - System.out.println("商城商品SKU库存更新成功,商品ID: " + serviceGoods.getId() + - ", 订单SKU: " + orderSku + ", 原库存: " + currentStock + + + System.out.println("商城商品SKU库存更新成功,商品ID: " + serviceGoods.getId() + + ", 订单SKU: " + orderSku + ", 原库存: " + currentStock + ", 扣减数量: " + orderNum + ", 剩余库存: " + newStock); found = true; break; } catch (NumberFormatException e) { - System.err.println("SKU库存格式错误,商品ID: " + serviceGoods.getId() + + System.err.println("SKU库存格式错误,商品ID: " + serviceGoods.getId() + ", SKU: " + orderSku + ", 库存值: " + stockStr); } } else { @@ -1860,21 +1861,21 @@ public class OrderUtil { } } } - + if (!found) { - System.err.println("未找到匹配的SKU,商品ID: " + serviceGoods.getId() + + System.err.println("未找到匹配的SKU,商品ID: " + serviceGoods.getId() + ", 订单SKU: " + orderSku + ", 商品SKU数组大小: " + skuArray.size()); } - + } catch (Exception e) { - System.err.println("更新商城商品SKU库存异常,商品ID: " + (serviceGoods != null ? serviceGoods.getId() : "null") + + System.err.println("更新商城商品SKU库存异常,商品ID: " + (serviceGoods != null ? serviceGoods.getId() : "null") + ", 订单SKU: " + orderSku + ", 错误: " + e.getMessage()); } } - + /** * 检查商城商品SKU是否匹配 - * + * * @param skuItem 商品SKU项 * @param orderSkuJson 订单SKU JSON * @return 是否匹配 @@ -1886,31 +1887,31 @@ public class OrderUtil { System.err.println("商城商品SKU匹配检查参数为空"); return false; } - + // 商城商品主要根据"价格"属性进行匹配 String orderPrice = orderSkuJson.getString("价格"); String skuPrice = skuItem.getString("价格"); - + if (orderPrice == null || skuPrice == null) { System.err.println("商城商品SKU价格属性为空,订单价格: " + orderPrice + ", 商品价格: " + skuPrice); return false; } - + // 如果价格属性匹配,返回true if (orderPrice.equals(skuPrice)) { return true; } - + return false; } catch (Exception e) { System.err.println("商城商品SKU匹配检查异常: " + e.getMessage()); return false; } } - + /** * 检查SKU是否匹配 - * + * * @param skuItem 商品SKU项 * @param orderSkuJson 订单SKU JSON * @return 是否匹配 @@ -1922,36 +1923,36 @@ public class OrderUtil { System.err.println("SKU匹配检查参数为空"); return false; } - + // 定义需要跳过的非属性字段 Set skipFields = new HashSet<>(Arrays.asList( "price", "groupprice", "seckillprice", "stock", "pic", "image" )); - + // 遍历订单SKU的所有属性,检查是否与商品SKU项匹配 for (String key : orderSkuJson.keySet()) { // 跳过非属性字段 if (skipFields.contains(key)) { continue; } - + String orderValue = orderSkuJson.getString(key); String skuValue = skuItem.getString(key); - + // 如果订单SKU中的属性在商品SKU中不存在,返回false if (skuValue == null) { System.err.println("商品SKU中缺少属性: " + key + ", 订单SKU值: " + orderValue); return false; } - + // 如果属性值不匹配,返回false if (!orderValue.equals(skuValue)) { - System.err.println("SKU属性不匹配,属性: " + key + + System.err.println("SKU属性不匹配,属性: " + key + ", 订单值: " + orderValue + ", 商品值: " + skuValue); return false; } } - + return true; } catch (Exception e) { System.err.println("SKU匹配检查异常: " + e.getMessage()); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WechatPayUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WechatPayUtil.java index 92c2b67..3a12ba4 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WechatPayUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WechatPayUtil.java @@ -26,7 +26,7 @@ import java.util.*; /** * 微信支付工具类 - * + * * 提供微信支付相关的完整功能实现 * 主要功能: * 1. 统一下单支付 @@ -71,30 +71,30 @@ public class WechatPayUtil { private static WechatConfig wechatConfig() { return SpringUtils.getBean(WechatConfig.class); } - + /** * 微信支付API地址(仅保留小程序相关接口) */ private static final String WECHAT_PAY_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder"; // 统一下单 private static final String WECHAT_QUERY_URL = "https://api.mch.weixin.qq.com/pay/orderquery"; // 订单查询 - private static final String WECHAT_REFUND_URL = "https://api.mch.weixin.qq.com/secapi/pay/refund"; + private static final String WECHAT_REFUND_URL = "https://api.mch.weixin.qq.com/secapi/pay/refund"; private static final String WECHAT_TRANSFER_URL = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"; // 企业付款 - public static final String PAY_FH = "https://73bb8889.r3.cpolar.top/"; + public static final String PAY_FH = "https://api.huafurenjia.cn/"; /** * 其他配置常量 */ - private static final String TRADE_TYPE_JSAPI = "JSAPI"; + private static final String TRADE_TYPE_JSAPI = "JSAPI"; private static final String CURRENCY = "CNY"; // 货币类型 - private static final String SUCCESS_CODE = "SUCCESS"; - private static final String FAIL_CODE = "FAIL"; - + private static final String SUCCESS_CODE = "SUCCESS"; + private static final String FAIL_CODE = "FAIL"; + /** * RestTemplate实例(配置UTF-8编码) */ private static final RestTemplate restTemplate = createRestTemplate(); - + /** * 创建配置了UTF-8编码的RestTemplate实例 */ @@ -158,36 +158,36 @@ public class WechatPayUtil { if (attach != null && !attach.trim().isEmpty()) { params.put("attach", attach); } - + // 3. 生成签名 String sign = generateSign(params, wechatConfig().getApikey()); params.put("sign", sign); - + // 4. 发送请求 String xmlRequest = mapToXml(params); - + // 设置请求头,指定字符编码为UTF-8 HttpHeaders headers = new HttpHeaders(); headers.set("Content-Type", "application/xml;charset=UTF-8"); headers.set("Accept", "application/xml;charset=UTF-8"); headers.set("User-Agent", "Mozilla/5.0"); - + HttpEntity requestEntity = new HttpEntity<>(xmlRequest, headers); ResponseEntity response = restTemplate.exchange(WECHAT_PAY_URL, HttpMethod.POST, requestEntity, String.class); - + // 5. 解析响应 Map responseMap = xmlToMap(response.getBody()); - + // 6. 处理响应 String returnCode = responseMap.get("return_code"); String resultCode = responseMap.get("result_code"); - + if (SUCCESS_CODE.equals(returnCode) && SUCCESS_CODE.equals(resultCode)) { String prepayId = responseMap.get("prepay_id"); - + // 7. 构建小程序端调起支付参数 Map payParams = buildMiniProgramPayParams(prepayId); - + result.put("success", true); result.put("payParams", payParams); result.put("prepayId", prepayId); @@ -196,14 +196,14 @@ public class WechatPayUtil { String errorCode = responseMap.get("err_code"); String errorCodeDes = responseMap.get("err_code_des"); String returnMsg = responseMap.get("return_msg"); - + String errorMessage = "统一下单失败:" + (errorCodeDes != null ? errorCodeDes : returnMsg); result = failResult(errorMessage); } } catch (Exception e) { result = failResult("统一下单异常:" + e.getMessage()); } - + return result; } @@ -232,13 +232,13 @@ public class WechatPayUtil { String sign = generateSign(params, wechatConfig().getApikey()); params.put("sign", sign); String xmlRequest = mapToXml(params); - + // 设置请求头,指定字符编码为UTF-8解决中文乱码 HttpHeaders headers = new HttpHeaders(); headers.set("Content-Type", "application/xml;charset=UTF-8"); headers.set("Accept", "application/xml;charset=UTF-8"); headers.set("User-Agent", "Mozilla/5.0"); - + HttpEntity requestEntity = new HttpEntity<>(xmlRequest, headers); ResponseEntity response = restTemplate.exchange(WECHAT_QUERY_URL, HttpMethod.POST, requestEntity, String.class); Map responseMap = xmlToMap(response.getBody()); @@ -309,13 +309,13 @@ public class WechatPayUtil { /** * 申请退款 - * + * * @param refundInfo 退款信息 * @return 退款结果 */ public Map refund(Map refundInfo) { Map result = new HashMap<>(); - + try { // 1. 参数验证 String validationError = validateRefundParams(refundInfo); @@ -324,53 +324,53 @@ public class WechatPayUtil { result.put("message", validationError); return result; } - + // 2. 构建退款参数 Map params = buildRefundParams(refundInfo); - + // 3. 生成签名 String sign = generateSign(params, wechatConfig().getApikey()); params.put("sign", sign); - + // 4. 发送请求(需要证书) String xmlRequest = mapToXml(params); // 注意:退款接口需要使用客户端证书,这里简化处理 ResponseEntity response = restTemplate.postForEntity(WECHAT_REFUND_URL, xmlRequest, String.class); - + // 5. 解析响应 Map responseMap = xmlToMap(response.getBody()); - - if (SUCCESS_CODE.equals(responseMap.get("return_code")) && + + if (SUCCESS_CODE.equals(responseMap.get("return_code")) && SUCCESS_CODE.equals(responseMap.get("result_code"))) { - + Map refundResult = new HashMap<>(); refundResult.put("refundId", responseMap.get("refund_id")); refundResult.put("outRefundNo", responseMap.get("out_refund_no")); refundResult.put("refundFee", responseMap.get("refund_fee")); refundResult.put("settlementRefundFee", responseMap.get("settlement_refund_fee")); - + result.put("success", true); result.put("refundInfo", refundResult); result.put("message", "申请退款成功"); - + } else { result.put("success", false); - result.put("message", "申请退款失败:" + - (responseMap.get("err_code_des") != null ? responseMap.get("err_code_des") : + result.put("message", "申请退款失败:" + + (responseMap.get("err_code_des") != null ? responseMap.get("err_code_des") : responseMap.get("return_msg"))); } - + } catch (Exception e) { result.put("success", false); result.put("message", "申请退款异常:" + e.getMessage()); } - + return result; } /** * 企业付款到零钱(微信支付v3接口实现) - * + * * @param transferInfo 付款信息 * @return 付款结果 */ @@ -558,7 +558,7 @@ public class WechatPayUtil { String nonceStr = generateNonceStr(); String packageStr = "prepay_id=" + prepayId; String signType = "MD5"; - + // 构建签名参数 Map signParams = new HashMap<>(); signParams.put("appId", wechatConfig().getAppid()); @@ -566,15 +566,15 @@ public class WechatPayUtil { signParams.put("nonceStr", nonceStr); signParams.put("package", packageStr); signParams.put("signType", signType); - + String paySign = generateSign(signParams, wechatConfig().getApikey()); - + payParams.put("timeStamp", timeStamp); payParams.put("nonceStr", nonceStr); payParams.put("package", packageStr); payParams.put("signType", signType); payParams.put("paySign", paySign); - + return payParams; } @@ -594,7 +594,7 @@ public class WechatPayUtil { } } stringBuilder.append("key=").append(key); - + String signString = stringBuilder.toString(); MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] digest = md5.digest(signString.getBytes(StandardCharsets.UTF_8)); @@ -602,7 +602,7 @@ public class WechatPayUtil { for (byte b : digest) { result.append(String.format("%02X", b)); } - + return result.toString(); } catch (Exception e) { throw new RuntimeException("生成签名失败", e); @@ -656,28 +656,28 @@ public class WechatPayUtil { String processedXml = xml.replaceAll("<\\?xml[^>]*\\?>", "") .replaceAll("", "") .replaceAll("", ""); - + String[] elements = processedXml.split(""); - + for (String element : elements) { if (element.trim().isEmpty()) { continue; } - + int startTag = element.indexOf("<"); int endTag = element.indexOf(">"); if (startTag >= 0 && endTag > startTag) { String key = element.substring(startTag + 1, endTag); String value = element.substring(endTag + 1); - + if (value.startsWith("")) { value = value.substring(9, value.length() - 3); } - + map.put(key, value); } } - + } catch (Exception e) { throw new RuntimeException("XML解析失败", e); } @@ -825,14 +825,14 @@ public class WechatPayUtil { params.put("out_refund_no", refundInfo.get("refundNo").toString()); params.put("total_fee", refundInfo.get("totalFee").toString()); params.put("refund_fee", refundInfo.get("refundFee").toString()); - + if (refundInfo.get("refundDesc") != null) { params.put("refund_desc", refundInfo.get("refundDesc").toString()); } if (refundInfo.get("notifyUrl") != null) { params.put("notify_url", refundInfo.get("notifyUrl").toString()); } - + return params; } @@ -848,16 +848,16 @@ public class WechatPayUtil { params.put("nonce_str", generateNonceStr()); params.put("partner_trade_no", transferInfo.get("partnerTradeNo").toString()); params.put("openid", transferInfo.get("openid").toString()); - params.put("check_name", transferInfo.get("checkName") != null ? + params.put("check_name", transferInfo.get("checkName") != null ? transferInfo.get("checkName").toString() : "NO_CHECK"); params.put("amount", transferInfo.get("amount").toString()); params.put("desc", transferInfo.get("desc").toString()); params.put("spbill_create_ip", "127.0.0.1"); - + if (transferInfo.get("reUserName") != null) { params.put("re_user_name", transferInfo.get("reUserName").toString()); } - + return params; } @@ -1051,4 +1051,4 @@ public class WechatPayUtil { return transferToUserV3(transferInfo); } -} \ No newline at end of file +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WorkerCommissionUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WorkerCommissionUtil.java index c2da13f..94c3021 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WorkerCommissionUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WorkerCommissionUtil.java @@ -11,21 +11,23 @@ import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.math.RoundingMode; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.Date; import java.util.List; import com.alibaba.fastjson.JSONArray; /** * 师傅分佣处理工具类 - * + * * @author ruoyi * @date 2025-01-27 */ @Component public class WorkerCommissionUtil { - + private static final Logger logger = LoggerFactory.getLogger(WorkerCommissionUtil.class); - + // 注入相关服务 private static final IWorkerLevelService workerLevelService = SpringUtils.getBean(IWorkerLevelService.class); private static final IUsersService usersService = SpringUtils.getBean(IUsersService.class); @@ -42,64 +44,64 @@ public class WorkerCommissionUtil { /** * 获取订单总金额 * 计算订单的总金额:totalPrice + doorFee + deposit + finalPayment + priceDifference + discountAmount - * + * * @param order 订单对象 * @return 订单总金额 */ public static BigDecimal getOrderTotalAmount(Order order) { logger.info("=== 开始获取订单总金额 ==="); logger.info("订单ID: {}, 订单号: {}", order.getId(), order.getOrderId()); - + try { // 1. 订单总金额 (Order.total_price) BigDecimal totalPrice = order.getTotalPrice(); if (totalPrice == null) { totalPrice = BigDecimal.ZERO; } - + // 2. 上门费 (type=7) BigDecimal doorFee = getPaymentAmount(order.getOrderId(), 7L); - + // 3. 定金 (type=8) BigDecimal deposit = getPaymentAmount(order.getOrderId(), 8L); - + // 4. 尾款 (type=9) BigDecimal finalPayment = getPaymentAmount(order.getOrderId(), 9L); - + // 5. 差价 (type=10) BigDecimal priceDifference = getPaymentAmount(order.getOrderId(), 10L); - + // 6. 优惠金额 (从type=5的日志中解析) BigDecimal discountAmount = getDiscountAmount(order.getId()); - + // 7. 计算总金额 BigDecimal totalAmount = totalPrice.add(doorFee).add(deposit).add(finalPayment).add(priceDifference).subtract(discountAmount); - + logger.info("订单总金额计算完成: {}元", totalAmount); - logger.info("计算明细 - 订单总金额: {}, 上门费: {}, 定金: {}, 尾款: {}, 差价: {}, 优惠: {}", + logger.info("计算明细 - 订单总金额: {}, 上门费: {}, 定金: {}, 尾款: {}, 差价: {}, 优惠: {}", totalPrice, doorFee, deposit, finalPayment, priceDifference, discountAmount); - + return totalAmount; - + } catch (Exception e) { logger.error("获取订单总金额异常", e); return BigDecimal.ZERO; } } - + /** * 获取订单金额组成 * 详细分析订单总金额的各个组成部分 - * + * * @param order 订单对象 * @return 包含各项金额的JSONObject */ public static JSONObject getOrderAmountComposition(Order order) { JSONObject result = new JSONObject(); - + logger.info("=== 开始获取订单金额组成 ==="); logger.info("订单ID: {}, 订单号: {}", order.getId(), order.getOrderId()); - + try { // 1. 订单总金额 (Order.total_price) BigDecimal totalPrice = order.getTotalPrice(); @@ -108,32 +110,32 @@ public class WorkerCommissionUtil { } result.put("totalPrice", totalPrice); logger.info("1. 订单总金额: {}元", totalPrice); - + // 2. 上门费 (type=7) BigDecimal doorFee = getPaymentAmount(order.getOrderId(), 7L); result.put("doorFee", doorFee); logger.info("2. 上门费: {}元", doorFee); - + // 3. 定金 (type=8) BigDecimal deposit = getPaymentAmount(order.getOrderId(), 8L); result.put("deposit", deposit); logger.info("3. 定金: {}元", deposit); - + // 4. 尾款 (type=9) BigDecimal finalPayment = getPaymentAmount(order.getOrderId(), 9L); result.put("finalPayment", finalPayment); logger.info("4. 尾款: {}元", finalPayment); - + // 5. 差价 (type=10) BigDecimal priceDifference = getPaymentAmount(order.getOrderId(), 10L); result.put("priceDifference", priceDifference); logger.info("5. 差价: {}元", priceDifference); - + // 6. 优惠金额 (从type=5的日志中解析) BigDecimal discountAmount = getDiscountAmount(order.getId()); result.put("discountAmount", discountAmount); logger.info("6. 优惠金额: {}元", discountAmount); - + // 7. 材料费用 (Order.good_price) BigDecimal materialFee = order.getGoodPrice(); if (materialFee == null) { @@ -141,7 +143,7 @@ public class WorkerCommissionUtil { } result.put("materialFee", materialFee); logger.info("7. 材料费用: {}元", materialFee); - + // 8. 服务费用 (Order.service_price) BigDecimal serviceFee = order.getServicePrice(); if (serviceFee == null) { @@ -149,35 +151,35 @@ public class WorkerCommissionUtil { } result.put("serviceFee", serviceFee); logger.info("8. 服务费用: {}元", serviceFee); - + // 计算各项统计 BigDecimal totalPaymentAmount = doorFee.add(deposit).add(finalPayment).add(priceDifference); result.put("totalPaymentAmount", totalPaymentAmount); logger.info("支付金额总计: {}元", totalPaymentAmount); - + BigDecimal totalFees = materialFee.add(serviceFee); result.put("totalFees", totalFees); logger.info("费用总计: {}元", totalFees); - + BigDecimal netAmount = totalPrice.subtract(discountAmount); result.put("netAmount", netAmount); logger.info("净金额(总金额-优惠): {}元", netAmount); - + logger.info("=== 订单金额组成获取完成 ==="); - logger.info("订单金额组成详情 - 总金额: {}, 上门费: {}, 定金: {}, 尾款: {}, 差价: {}, 优惠: {}, 材料费: {}, 服务费: {}", + logger.info("订单金额组成详情 - 总金额: {}, 上门费: {}, 定金: {}, 尾款: {}, 差价: {}, 优惠: {}, 材料费: {}, 服务费: {}", totalPrice, doorFee, deposit, finalPayment, priceDifference, discountAmount, materialFee, serviceFee); - + } catch (Exception e) { logger.error("获取订单金额组成异常", e); result.put("error", "获取订单金额组成失败: " + e.getMessage()); } - + return result; } - + /** * 获取指定类型的支付金额 - * + * * @param orderId 订单号 * @param type 支付类型 * @return 支付金额 @@ -188,9 +190,9 @@ public class WorkerCommissionUtil { queryParam.setLastorderid(orderId); queryParam.setType(type); queryParam.setStatus(2L); // 已支付状态 - + List payBeforList = usersPayBeforService.selectUsersPayBeforList(queryParam); - + BigDecimal totalAmount = BigDecimal.ZERO; if (payBeforList != null && !payBeforList.isEmpty()) { for (UsersPayBefor payBefor : payBeforList) { @@ -199,19 +201,19 @@ public class WorkerCommissionUtil { } } } - + logger.debug("订单 {} 类型 {} 支付金额: {}元", orderId, type, totalAmount); return totalAmount; - + } catch (Exception e) { logger.error("获取支付金额异常,订单号: {}, 类型: {}", orderId, type, e); return BigDecimal.ZERO; } } - + /** * 从订单日志中获取优惠金额 - * + * * @param orderId 订单ID * @return 优惠金额 */ @@ -221,11 +223,11 @@ public class WorkerCommissionUtil { OrderLog queryLog = new OrderLog(); queryLog.setOid(orderId); queryLog.setType(new BigDecimal("5")); // type=5 - + List logList = orderLogService.selectOrderLogList(queryLog); - + BigDecimal totalDiscount = BigDecimal.ZERO; - + if (logList != null && !logList.isEmpty()) { if (logList.getFirst().getReductionPrice()!=null){ totalDiscount=logList.getFirst().getReductionPrice(); @@ -270,10 +272,10 @@ public class WorkerCommissionUtil { // } // } } - + logger.debug("订单 {} 总优惠金额: {}元", orderId, totalDiscount); return totalDiscount; - + } catch (Exception e) { logger.error("获取优惠金额异常,订单ID: {}", orderId, e); return BigDecimal.ZERO; @@ -283,14 +285,14 @@ public class WorkerCommissionUtil { /** * 获取分佣基数 * 根据订单ID获取分佣基数,根据商品的分佣模式计算 - * + * * @param orderId 订单ID * @return 分佣基数(百分比形式,如:0.15表示15%) */ public static BigDecimal getCommissionBase(Long orderId) { logger.info("=== 开始获取分佣基数 ==="); logger.info("订单ID: {}", orderId); - + try { // 1. 查询订单信息 Order order = orderService.selectOrderById(orderId); @@ -298,23 +300,23 @@ public class WorkerCommissionUtil { logger.error("订单不存在,订单ID: {}", orderId); return BigDecimal.ZERO; } - - logger.info("订单信息 - 订单号: {}, 商品ID: {}, 师傅ID: {}", + + logger.info("订单信息 - 订单号: {}, 商品ID: {}, 师傅ID: {}", order.getOrderId(), order.getProductId(), order.getWorkerId()); - + // 2. 根据订单中的product_id获取商品数据 ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); if (serviceGoods == null) { logger.error("商品不存在,商品ID: {}", order.getProductId()); return BigDecimal.ZERO; } - - logger.info("商品信息 - 商品名称: {}, 分佣模式: {}, 分佣比例: {}", + + logger.info("商品信息 - 商品名称: {}, 分佣模式: {}, 分佣比例: {}", serviceGoods.getTitle(), serviceGoods.getCommissiontype(), serviceGoods.getCommission()); - + // 3. 获取商品数据中的commissiontype Integer commissionType = serviceGoods.getCommissiontype(); - + // 4. 判断分佣模式 if (commissionType == null || commissionType == 1) { // 系统默认分佣 或 commissiontype为空/null @@ -333,22 +335,22 @@ public class WorkerCommissionUtil { logger.warn("未知分佣模式: {},默认使用系统分佣", commissionType); return getSystemCommissionBase(order); } - + } catch (Exception e) { logger.error("获取分佣基数异常,订单ID: {}", orderId, e); return BigDecimal.ZERO; } } - + /** * 获取质保金扣除比例 * 通过调用ISiteConfigService查询config_one配置,获取margin字段并转化为百分比 - * + * * @return 质保金扣除比例(百分比形式) */ public static BigDecimal getWarrantyRatio() { logger.info("=== 开始获取质保金扣除比例 ==="); - + try { // 1. 查询config_one配置 SiteConfig configOne = siteConfigService.selectSiteConfigByName("config_one"); @@ -356,23 +358,23 @@ public class WorkerCommissionUtil { logger.error("config_one配置不存在或为空"); return new BigDecimal("0.10"); // 默认10% } - + logger.info("config_one配置值: {}", configOne.getValue()); - + // 2. 解析JSON配置 JSONObject configJson = JSONObject.parseObject(configOne.getValue()); if (configJson == null) { logger.error("config_one配置JSON解析失败"); return new BigDecimal("0.10"); // 默认10% } - + // 3. 获取margin字段 Object marginObj = configJson.get("margin"); if (marginObj == null) { logger.warn("margin字段不存在,使用默认值10%"); return new BigDecimal("0.10"); // 默认10% } - + BigDecimal margin; if (marginObj instanceof Integer) { margin = new BigDecimal((Integer) marginObj); @@ -386,34 +388,34 @@ public class WorkerCommissionUtil { logger.warn("margin字段类型不支持: {}", marginObj.getClass().getName()); return new BigDecimal("0.10"); // 默认10% } - + // 4. 验证质保金扣除比例 if (margin.compareTo(BigDecimal.ZERO) <= 0) { logger.warn("质保金扣除比例为0或无效: {},使用默认值10%", margin); return new BigDecimal("0.10"); // 默认10% } - + // 5. 转换为百分比 BigDecimal warrantyRatio = margin.divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP); - + logger.info("质保金扣除比例计算完成: {}%", warrantyRatio.multiply(new BigDecimal("100"))); return warrantyRatio; - + } catch (Exception e) { logger.error("获取质保金扣除比例异常", e); return new BigDecimal("0.10"); // 默认10% } } - + /** * 获取材料分佣基数 * 通过调用ISiteConfigService查询config_one配置,获取material_commissions字段并转化为百分比 - * + * * @return 材料分佣基数(百分比形式) */ public static BigDecimal getMaterialCommissionBase() { logger.info("=== 开始获取材料分佣基数 ==="); - + try { // 1. 查询config_one配置 SiteConfig configOne = siteConfigService.selectSiteConfigByName("config_one"); @@ -421,23 +423,23 @@ public class WorkerCommissionUtil { logger.error("config_one配置不存在或为空"); return BigDecimal.ZERO; } - + logger.info("config_one配置值: {}", configOne.getValue()); - + // 2. 解析JSON配置 JSONObject configJson = JSONObject.parseObject(configOne.getValue()); if (configJson == null) { logger.error("config_one配置JSON解析失败"); return BigDecimal.ZERO; } - + // 3. 获取material_commissions字段 Object materialCommissionsObj = configJson.get("material_commissions"); if (materialCommissionsObj == null) { logger.warn("material_commissions字段不存在,使用默认值0"); return BigDecimal.ZERO; } - + BigDecimal materialCommissions; if (materialCommissionsObj instanceof Integer) { materialCommissions = new BigDecimal((Integer) materialCommissionsObj); @@ -451,29 +453,29 @@ public class WorkerCommissionUtil { logger.warn("material_commissions字段类型不支持: {}", materialCommissionsObj.getClass().getName()); return BigDecimal.ZERO; } - + // 4. 验证材料分佣比例 if (materialCommissions.compareTo(BigDecimal.ZERO) <= 0) { logger.warn("材料分佣比例为0或无效: {}", materialCommissions); return BigDecimal.ZERO; } - + // 5. 转换为百分比 BigDecimal materialCommissionBase = materialCommissions.divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP); - + logger.info("材料分佣基数计算完成: {}%", materialCommissionBase.multiply(new BigDecimal("100"))); return materialCommissionBase; - + } catch (Exception e) { logger.error("获取材料分佣基数异常", e); return BigDecimal.ZERO; } } - + /** * 获取系统默认分佣基数 * 根据师傅等级获取分佣比例 - * + * * @param order 订单对象 * @return 分佣基数(百分比形式) */ @@ -485,43 +487,43 @@ public class WorkerCommissionUtil { logger.error("师傅不存在,师傅ID: {}", order.getWorkerId()); return BigDecimal.ZERO; } - - logger.info("师傅信息 - 师傅ID: {}, 师傅姓名: {}, 师傅等级: {}", + + logger.info("师傅信息 - 师傅ID: {}, 师傅姓名: {}, 师傅等级: {}", worker.getId(), worker.getName(), worker.getLevel()); - + // 2. 根据师傅的等级调用IWorkerLevelService查询师傅对应等级 WorkerLevel workerLevel = workerLevelService.selectWorkerLevelById(worker.getLevel().longValue()); if (workerLevel == null) { logger.error("师傅等级配置不存在,等级ID: {}", worker.getLevel()); return BigDecimal.ZERO; } - - logger.info("师傅等级信息 - 等级名称: {}, 等级: {}, 佣金比例: {}", + + logger.info("师傅等级信息 - 等级名称: {}, 等级: {}, 佣金比例: {}", workerLevel.getTitle(), workerLevel.getLevel(), workerLevel.getCr()); - + // 3. 获取等级中的cr然后转化为百分比 Long cr = workerLevel.getCr(); if (cr == null || cr <= 0) { logger.warn("师傅等级佣金比例为0或无效,等级ID: {}, cr: {}", worker.getLevel(), cr); return BigDecimal.ZERO; } - + // 将cr转换为百分比(假设cr存储的是整数,如15表示15%) BigDecimal commissionBase = new BigDecimal(cr).divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP); - + logger.info("系统默认分佣基数计算完成: {}%", commissionBase.multiply(new BigDecimal("100"))); return commissionBase; - + } catch (Exception e) { logger.error("获取系统默认分佣基数异常", e); return BigDecimal.ZERO; } } - + /** * 获取独立分佣基数 * 直接使用商品信息中的commission作为分佣比例 - * + * * @param serviceGoods 商品对象 * @return 分佣基数(百分比形式) */ @@ -529,17 +531,17 @@ public class WorkerCommissionUtil { try { BigDecimal commission = serviceGoods.getCommission(); if (commission == null || commission.compareTo(BigDecimal.ZERO) <= 0) { - logger.warn("商品独立分佣比例为0或无效,商品ID: {}, commission: {}", + logger.warn("商品独立分佣比例为0或无效,商品ID: {}, commission: {}", serviceGoods.getId(), commission); return BigDecimal.ZERO; } - + // 将commission转换为百分比(假设commission存储的是整数,如15表示15%) BigDecimal commissionBase = commission.divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP); - + logger.info("独立分佣基数计算完成: {}%", commissionBase.multiply(new BigDecimal("100"))); return commissionBase; - + } catch (Exception e) { logger.error("获取独立分佣基数异常", e); return BigDecimal.ZERO; @@ -552,55 +554,55 @@ public class WorkerCommissionUtil { - + /** * 师傅分佣处理(原有方法,暂时保留) - * + * * @param order 订单对象 * @param users 师傅用户对象 * @return 处理结果 */ public static JSONObject processWorkerCommission(Order order, Users users) { JSONObject result = new JSONObject(); - + logger.info("=== 开始师傅分佣处理(原有方法) ==="); - logger.info("订单ID: {}, 订单号: {}, 师傅ID: {}, 师傅姓名: {}", + logger.info("订单ID: {}, 订单号: {}, 师傅ID: {}, 师傅姓名: {}", order.getId(), order.getOrderId(), users.getId(), users.getName()); - + try { // 获取订单金额组成 JSONObject amountComposition = getOrderAmountComposition(order); logger.info("订单金额组成: {}", amountComposition.toJSONString()); - + // 这里可以添加新的分佣逻辑 // TODO: 根据新的业务需求实现分佣逻辑 - + result.put("success", true); result.put("message", "师傅分佣处理成功(原有方法)"); result.put("amountComposition", amountComposition); - + } catch (Exception e) { logger.error("师傅分佣处理异常", e); result.put("success", false); result.put("message", "处理过程中发生异常:" + e.getMessage()); } - + return result; } - + /** * 计算师傅完整分佣 * 根据订单ID计算师傅的完整分佣,包括服务分佣、材料分佣、质保金和最终分佣 - * + * * @param orderId 订单ID * @return 分佣计算结果 */ public static JSONObject calculateCompleteWorkerCommission(Long orderId) { JSONObject result = new JSONObject(); - + logger.info("=== 开始计算师傅完整分佣 ==="); logger.info("订单ID: {}", orderId); - + try { // 1. 查询订单信息 Order order = orderService.selectOrderById(orderId); @@ -610,14 +612,14 @@ public class WorkerCommissionUtil { result.put("message", "订单不存在"); return result; } - - logger.info("订单信息 - 订单号: {}, 商品ID: {}, 师傅ID: {}", + + logger.info("订单信息 - 订单号: {}, 商品ID: {}, 师傅ID: {}", order.getOrderId(), order.getProductId(), order.getWorkerId()); - + // 2. 获取订单金额组成 JSONObject amountComposition = getOrderAmountComposition(order); logger.info("订单金额组成: {}", amountComposition.toJSONString()); - + // 3. 获取各项金额 BigDecimal totalPrice = (BigDecimal) amountComposition.get("totalPrice"); // BigDecimal deposit = (BigDecimal) amountComposition.get("deposit"); @@ -628,63 +630,63 @@ public class WorkerCommissionUtil { BigDecimal serviceFee = (BigDecimal) amountComposition.get("serviceFee"); BigDecimal materialFee = (BigDecimal) amountComposition.get("materialFee"); - + // 获取用户支付总金额 (allmoney) BigDecimal allmoney = (BigDecimal) amountComposition.get("totalPaymentAmount"); if (allmoney == null) { allmoney = BigDecimal.ZERO; } logger.info("用户支付总金额 (allmoney): {}元", allmoney); - + // 4. 获取分佣基数 BigDecimal serviceCommissionBase = getCommissionBase(orderId); BigDecimal materialCommissionBase = getMaterialCommissionBase(); - + logger.info("=== 分佣基数信息 ==="); logger.info("服务分佣基数: {}%", serviceCommissionBase.multiply(new BigDecimal("100"))); logger.info("材料分佣基数: {}%", materialCommissionBase.multiply(new BigDecimal("100"))); - + // 5. 计算师傅服务初次分佣 // 公式:((订单总金额+服务费用+差价)-优惠金额)*服务分佣基数 BigDecimal serviceCommissionAmount = calculateServiceCommission( totalPrice, serviceFee, priceDifference, discountAmount, serviceCommissionBase); - + // 6. 计算师傅材料初次分佣 // 公式:材料费用*材料分佣基数 BigDecimal materialCommissionAmount = calculateMaterialCommissionNew(orderId); - + // 7. 计算师傅质保金 // 公式:(师傅材料初次分佣+师傅服务初次分佣)*质保金扣除比例 BigDecimal totalInitialCommission = serviceCommissionAmount.add(materialCommissionAmount); BigDecimal warrantyAmount = calculateWarrantyAmount(order, totalInitialCommission); - + // 8. 计算本次订单师傅最终分佣 // 公式:(师傅材料初次分佣+师傅服务初次分佣)-师傅质保金 BigDecimal finalCommissionAmount = totalInitialCommission.subtract(warrantyAmount); - + // 9. 加上上门费(师傅全额应得) BigDecimal finalCommissionWithDoorFee = finalCommissionAmount.add(doorFee); - + // // 10. 打印详细的分佣公式和计算结果 // printDetailedCommissionFormula(totalPrice, deposit, finalPayment, priceDifference, // discountAmount, doorFee, materialFee, serviceCommissionBase, materialCommissionBase, // serviceCommissionAmount, materialCommissionAmount, totalInitialCommission, // warrantyAmount, finalCommissionAmount, finalCommissionWithDoorFee); - + // // 11. 生成分佣简要公式(用于客户展示) // JSONObject commissionFormula = generateCommissionFormulaForCustomer( // totalPrice, deposit, finalPayment, priceDifference, discountAmount, doorFee, materialFee, // serviceCommissionBase, materialCommissionBase, serviceCommissionAmount, // materialCommissionAmount, totalInitialCommission, warrantyAmount, finalCommissionAmount, finalCommissionWithDoorFee); - + // 12. 生成分佣总结(用于数据库存储) String commissionSummary = generateSimpleCommissionSummary( totalPrice, serviceFee, priceDifference, discountAmount, doorFee, materialFee, - serviceCommissionBase, materialCommissionBase, serviceCommissionAmount, + serviceCommissionBase, materialCommissionBase, serviceCommissionAmount, materialCommissionAmount, totalInitialCommission, warrantyAmount, finalCommissionAmount, finalCommissionWithDoorFee); result.put("commissionSummary", commissionSummary); - + // 13. 构建结果 result.put("success", true); result.put("message", "师傅分佣计算成功"); @@ -712,13 +714,13 @@ public class WorkerCommissionUtil { .fluentPut("finalCommissionAmount", finalCommissionAmount) .fluentPut("finalCommissionWithDoorFee", finalCommissionWithDoorFee)); - + // 14. 分佣完成后的业务处理 handleCommissionCompletion(order, finalCommissionWithDoorFee, warrantyAmount, commissionSummary,serviceCommissionBase); - + // 15. 计算并更新订单总金额(用于开票) updateOrderTotalPriceForInvoice(order, amountComposition); - + //次卡下的服务不用给客户添加购物金 if (StringUtils.isBlank(order.getCartid())){ //增加购物金 @@ -746,26 +748,26 @@ public class WorkerCommissionUtil { logger.info("师傅ID: {}", order.getWorkerId()); logger.info("最终分佣金额: {}元", finalCommissionAmount); logger.info("最终应得金额(含上门费): {}元", finalCommissionWithDoorFee); - + } catch (Exception e) { logger.error("计算师傅完整分佣异常", e); result.put("success", false); result.put("message", "计算过程中发生异常:" + e.getMessage()); } - + return result; } - + /** * 处理分佣完成后的业务逻辑 * 包括更新师傅质保金、累计佣金和添加流水记录 - * + * * @param order 订单对象 * @param finalCommissionWithDoorFee 最终应得金额(含上门费) * @param warrantyAmount 质保金 * @param commissionSummary 分佣总结 */ - private static void handleCommissionCompletion(Order order, BigDecimal finalCommissionWithDoorFee, + private static void handleCommissionCompletion(Order order, BigDecimal finalCommissionWithDoorFee, BigDecimal warrantyAmount, String commissionSummary,BigDecimal serviceCommissionBase) { try { JSONObject amountComposition = getOrderAmountComposition(order); @@ -781,41 +783,41 @@ public class WorkerCommissionUtil { BigDecimal materialFee = (BigDecimal) amountComposition.get("materialFee"); logger.info("=== 开始处理分佣完成后的业务逻辑 ==="); - logger.info("订单ID: {}, 师傅ID: {}, 最终应得金额: {}元", + logger.info("订单ID: {}, 师傅ID: {}, 最终应得金额: {}元", order.getId(), order.getWorkerId(), finalCommissionWithDoorFee); - + // 1. 查询师傅信息 Users worker = usersService.selectUsersById(order.getWorkerId()); if (worker == null) { logger.error("师傅不存在,师傅ID: {}", order.getWorkerId()); return; } - - logger.info("师傅信息 - 姓名: {}, 当前质保金: {}, 当前累计佣金: {}", + + logger.info("师傅信息 - 姓名: {}, 当前质保金: {}, 当前累计佣金: {}", worker.getName(), worker.getMargin(), worker.getCommission()); - + // 2. 检查是否已经处理过该订单的分佣,避免重复更新师傅信息 // 通过查询流水记录来判断是否已处理 WorkerMarginLog checkMarginLog = new WorkerMarginLog(); checkMarginLog.setUid(order.getWorkerId()); checkMarginLog.setOid(order.getId()); checkMarginLog.setOrderId(order.getOrderId()); - + List existingMarginCheck = workerMarginLogService.selectWorkerMarginLogList(checkMarginLog); - + WorkerMoneyLog checkMoneyLog = new WorkerMoneyLog(); checkMoneyLog.setWorkerId(order.getWorkerId()); checkMoneyLog.setOid(order.getId()); checkMoneyLog.setOrderId(order.getOrderId()); - + List existingMoneyCheck = workerMoneyLogService.selectWorkerMoneyLogList(checkMoneyLog); - - if ((existingMarginCheck != null && !existingMarginCheck.isEmpty()) || + + if ((existingMarginCheck != null && !existingMarginCheck.isEmpty()) || (existingMoneyCheck != null && !existingMoneyCheck.isEmpty())) { logger.warn("订单 {} 的师傅 {} 分佣已处理过,跳过师傅信息更新", order.getOrderId(), order.getWorkerId()); return; } - + // 3. 更新师傅质保金 BigDecimal currentMargin = worker.getMargin(); if (currentMargin == null) { @@ -823,7 +825,7 @@ public class WorkerCommissionUtil { } BigDecimal newMargin = currentMargin.add(warrantyAmount); worker.setMargin(newMargin); - + // 4. 更新师傅累计佣金 BigDecimal currentCommission = worker.getCommission(); if (currentCommission == null) { @@ -831,7 +833,7 @@ public class WorkerCommissionUtil { } BigDecimal newCommission = currentCommission.add(finalCommissionWithDoorFee); worker.setCommission(newCommission); - + // 5. 更新师傅信息 int updateResult = usersService.updateUsers(worker); if (updateResult > 0) { @@ -858,7 +860,7 @@ public class WorkerCommissionUtil { // marginLog.setReamk(commissionSummary); marginLog.setCreatedAt(new Date()); marginLog.setUpdatedAt(new Date()); - + int marginLogResult = workerMarginLogService.insertWorkerMarginLog(marginLog); if (marginLogResult > 0) { logger.info("师傅质保金流水记录添加成功 - 质保金: {}元", warrantyAmount); @@ -889,9 +891,17 @@ public class WorkerCommissionUtil { moneyLog.setPrice(finalCommissionWithDoorFee); moneyLog.setType(1); // 1:收入 moneyLog.setGongshi(commissionSummary); - moneyLog.setCreatedAt(new Date()); - moneyLog.setUpdatedAt(new Date()); - + + //系统要求给师傅的分佣有七天的锁定期,锁定期内不允许师傅体现的操作 + moneyLog.setStatus(1);//锁单 + moneyLog.setStatusType(0);//后台锁定 + moneyLog.setBeginlook(new Date()); + //7天锁单 + LocalDateTime ldt = LocalDateTime.now().plusDays(7); + Date end = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()); + moneyLog.setEndlook(end); + moneyLog.setLookday(7); + moneyLog.setLookMoney(moneyLog.getPrice()); int moneyLogResult = workerMoneyLogService.insertWorkerMoneyLog(moneyLog); if (moneyLogResult > 0) { logger.info("师傅佣金流水记录添加成功 - 佣金: {}元", finalCommissionWithDoorFee); @@ -899,7 +909,7 @@ public class WorkerCommissionUtil { logger.error("师傅佣金流水记录添加失败"); } } - + logger.info("=== 分佣完成后的业务处理完成 ==="); logger.info("师傅: {}", worker.getName()); logger.info("订单号: {}", order.getOrderId()); @@ -907,16 +917,16 @@ public class WorkerCommissionUtil { logger.info("佣金收入: {}元", finalCommissionWithDoorFee); logger.info("新质保金余额: {}元", newMargin); logger.info("新累计佣金: {}元", newCommission); - + } catch (Exception e) { logger.error("处理分佣完成后的业务逻辑异常", e); } } - + /** * 计算师傅服务初次分佣 * 公式:((订单总金额+服务费用+差价)-优惠金额)*服务分佣基数 - * + * * @param totalPrice 订单总金额 * @param serviceFee 服务费用 * @param priceDifference 差价 @@ -926,11 +936,11 @@ public class WorkerCommissionUtil { */ private static BigDecimal calculateServiceCommission(BigDecimal totalPrice,BigDecimal serviceFee,BigDecimal priceDifference, BigDecimal discountAmount, BigDecimal serviceCommissionBase) { - + logger.info("=== 计算师傅服务初次分佣 ==="); logger.info("公式: ((订单总金额 + 服务费用 + 差价) - 优惠金额) × 服务分佣基数"); logger.info(""); - + // 1. 计算基础金额:订单总金额+服务费用+差价 BigDecimal baseAmount = totalPrice.add(serviceFee).add(priceDifference); logger.info("步骤1 - 基础金额计算:"); @@ -939,7 +949,7 @@ public class WorkerCommissionUtil { logger.info(" 差价: {}元", priceDifference); logger.info(" 基础金额 = {} + {} + {} = {}元", totalPrice, serviceFee, priceDifference, baseAmount); logger.info(""); - + // 2. 减去优惠金额 BigDecimal netAmount = baseAmount; if (discountAmount != null && discountAmount.compareTo(BigDecimal.ZERO) > 0) { @@ -952,7 +962,7 @@ public class WorkerCommissionUtil { logger.info(" 净金额: {}元", netAmount); } logger.info(""); - + // 3. 乘以服务分佣基数 BigDecimal serviceCommissionAmount = netAmount.multiply(serviceCommissionBase) .setScale(2, RoundingMode.HALF_UP); @@ -960,39 +970,39 @@ public class WorkerCommissionUtil { logger.info(" 服务分佣基数: {}%", serviceCommissionBase.multiply(new BigDecimal("100"))); logger.info(" 服务初次分佣 = {} × {} = {}元", netAmount, serviceCommissionBase, serviceCommissionAmount); logger.info(""); - + logger.info("师傅服务初次分佣计算完成: {}元", serviceCommissionAmount); logger.info("=== 服务初次分佣计算结束 ==="); logger.info(""); return serviceCommissionAmount; } - + /** * 计算师傅材料初次分佣 * 公式:材料费用*材料分佣基数 - * + * * @param materialFee 材料费用 * @param materialCommissionBase 材料分佣基数 * @return 材料初次分佣金额 */ private static BigDecimal calculateMaterialCommission(BigDecimal materialFee, BigDecimal materialCommissionBase) { - + logger.info("=== 计算师傅材料初次分佣 ==="); logger.info("公式: 材料费用 × 材料分佣基数"); logger.info(""); - + BigDecimal materialCommissionAmount = BigDecimal.ZERO; - - if (materialFee != null && materialFee.compareTo(BigDecimal.ZERO) > 0 && + + if (materialFee != null && materialFee.compareTo(BigDecimal.ZERO) > 0 && materialCommissionBase != null && materialCommissionBase.compareTo(BigDecimal.ZERO) > 0) { - + materialCommissionAmount = materialFee.multiply(materialCommissionBase) .setScale(2, RoundingMode.HALF_UP); - + logger.info("计算过程:"); logger.info(" 材料费用: {}元", materialFee); logger.info(" 材料分佣基数: {}%", materialCommissionBase.multiply(new BigDecimal("100"))); - logger.info(" 材料初次分佣 = {} × {} = {}元", + logger.info(" 材料初次分佣 = {} × {} = {}元", materialFee, materialCommissionBase, materialCommissionAmount); } else { logger.info("计算过程:"); @@ -1001,102 +1011,102 @@ public class WorkerCommissionUtil { logger.info(" 材料费用或材料分佣基数为0,材料初次分佣: 0元"); } logger.info(""); - + logger.info("师傅材料初次分佣计算完成: {}元", materialCommissionAmount); logger.info("=== 材料初次分佣计算结束 ==="); logger.info(""); return materialCommissionAmount; } - + /** * 计算师傅材料初次分佣(新逻辑) * 从订单日志中获取材料明细,根据报价材料配置计算分佣 - * + * * @param orderId 订单ID * @return 材料初次分佣金额 */ private static BigDecimal calculateMaterialCommissionNew(Long orderId) { logger.info("=== 计算师傅材料初次分佣(新逻辑) ==="); logger.info("订单ID: {}", orderId); - + BigDecimal totalMaterialCommission = BigDecimal.ZERO; - + try { // 1. 查询订单日志中type=5的数据 OrderLog queryLog = new OrderLog(); queryLog.setOid(orderId); queryLog.setType(new BigDecimal("5")); // type=5 - + List logList = orderLogService.selectOrderLogList(queryLog); - + if (logList == null || logList.isEmpty()) { logger.info("未找到type=5的订单日志,材料分佣为0"); return BigDecimal.ZERO; } - + // 2. 获取系统材料分佣基数 BigDecimal systemMaterialCommissionBase = getMaterialCommissionBase(); logger.info("系统材料分佣基数: {}%", systemMaterialCommissionBase.multiply(new BigDecimal("100"))); - + // 3. 遍历订单日志 for (OrderLog orderLog : logList) { String content = orderLog.getContent(); if (content == null || content.trim().isEmpty()) { continue; } - + try { // 4. 解析content获取material JSONObject contentJson = JSONObject.parseObject(content); JSONArray materialArray = contentJson.getJSONArray("material"); - + if (materialArray == null || materialArray.isEmpty()) { logger.info("订单日志 {} 中没有material数据", orderLog.getId()); continue; } - + // 5. 遍历材料明细 for (int i = 0; i < materialArray.size(); i++) { JSONObject materialItem = materialArray.getJSONObject(i); Long materialId = materialItem.getLong("id"); BigDecimal quantity = materialItem.getBigDecimal("quantity"); - + if (materialId == null || quantity == null || quantity.compareTo(BigDecimal.ZERO) <= 0) { continue; } - + logger.info("处理材料 - ID: {}, 数量: {}", materialId, quantity); - + // 6. 查询报价材料信息 BigDecimal materialCommission = calculateSingleMaterialCommission( materialId, quantity, systemMaterialCommissionBase); - + totalMaterialCommission = totalMaterialCommission.add(materialCommission); } - + } catch (Exception e) { logger.error("解析订单日志 {} 的material数据失败", orderLog.getId(), e); } } - + logger.info("材料分佣计算完成: {}元", totalMaterialCommission); return totalMaterialCommission; - + } catch (Exception e) { logger.error("计算材料分佣异常", e); return BigDecimal.ZERO; } } - + /** * 计算单个材料的分佣 - * + * * @param materialId 材料ID * @param quantity 使用数量 * @param systemMaterialCommissionBase 系统材料分佣基数 * @return 单个材料分佣金额 */ - private static BigDecimal calculateSingleMaterialCommission(Long materialId, BigDecimal quantity, + private static BigDecimal calculateSingleMaterialCommission(Long materialId, BigDecimal quantity, BigDecimal systemMaterialCommissionBase) { try { // 1. 查询报价材料信息 @@ -1105,21 +1115,21 @@ public class WorkerCommissionUtil { logger.warn("未找到材料ID: {} 的报价材料信息", materialId); return BigDecimal.ZERO; } - + // 2. 获取材料净利润 BigDecimal profit = quoteMaterial.getProfit(); if (profit == null || profit.compareTo(BigDecimal.ZERO) <= 0) { logger.info("材料ID: {} 净利润为0或无效", materialId); return BigDecimal.ZERO; } - + // 3. 判断是否有分佣 Integer isCommissions = quoteMaterial.getIscommissions(); if (isCommissions == null || isCommissions != 1) { logger.info("材料ID: {} 不参与分佣 (iscommissions: {})", materialId, isCommissions); return BigDecimal.ZERO; } - + // 4. 确定分佣基数 BigDecimal commissionBase = systemMaterialCommissionBase; BigDecimal materialCommissions = quoteMaterial.getCommissions(); @@ -1130,26 +1140,26 @@ public class WorkerCommissionUtil { } else { logger.info("材料ID: {} 使用系统分佣比例: {}%", materialId, commissionBase.multiply(new BigDecimal("100"))); } - + // 5. 计算材料分佣:材料净利润 × 材料分佣基数 × 使用材料数量 BigDecimal materialCommission = profit.multiply(commissionBase).multiply(quantity) .setScale(2, RoundingMode.HALF_UP); - - logger.info("材料分佣计算 - 材料ID: {}, 净利润: {}, 分佣基数: {}, 数量: {}, 分佣金额: {}", + + logger.info("材料分佣计算 - 材料ID: {}, 净利润: {}, 分佣基数: {}, 数量: {}, 分佣金额: {}", materialId, profit, commissionBase, quantity, materialCommission); - + return materialCommission; - + } catch (Exception e) { logger.error("计算单个材料分佣异常,材料ID: {}", materialId, e); return BigDecimal.ZERO; } } - + /** * 计算师傅质保金 * 根据订单和总初次分佣金额计算质保金 - * + * * @param order 订单对象 * @param totalInitialCommission 总初次分佣金额 * @return 质保金金额 @@ -1157,7 +1167,7 @@ public class WorkerCommissionUtil { private static BigDecimal calculateWarrantyAmount(Order order, BigDecimal totalInitialCommission) { logger.info("=== 计算师傅质保金 ==="); logger.info("订单ID: {}, 总初次分佣: {}", order.getId(), totalInitialCommission); - + try { // 1. 获取产品保证金 BigDecimal productMargin = BigDecimal.ZERO; @@ -1166,7 +1176,7 @@ public class WorkerCommissionUtil { productMargin = serviceGoods.getMargin(); } logger.info("产品保证金: {}元", productMargin); - + // 2. 获取师傅质保金 BigDecimal workerMargin = BigDecimal.ZERO; Users worker = usersService.selectUsersById(order.getWorkerId()); @@ -1174,11 +1184,11 @@ public class WorkerCommissionUtil { workerMargin = worker.getMargin(); } logger.info("师傅质保金: {}元", workerMargin); - + // 3. 获取质保金扣除比例 BigDecimal warrantyRatio = getWarrantyRatio(); logger.info("质保金扣除比例: {}%", warrantyRatio.multiply(new BigDecimal("100"))); - + // 4. 比较师傅质保金和产品保证金 if (workerMargin.compareTo(productMargin) >= 0) { // 师傅质保金大于等于产品保证金,不扣除质保金 @@ -1196,10 +1206,10 @@ public class WorkerCommissionUtil { return BigDecimal.ZERO; } } - + /** * 打印详细的分佣公式和计算结果 - * + * * @param totalPrice 订单总金额 * @param deposit 定金 * @param finalPayment 尾款 @@ -1222,10 +1232,10 @@ public class WorkerCommissionUtil { BigDecimal materialCommissionBase, BigDecimal serviceCommissionAmount, BigDecimal materialCommissionAmount, BigDecimal totalInitialCommission, BigDecimal warrantyAmount, BigDecimal finalCommissionAmount, BigDecimal finalCommissionWithDoorFee) { - + logger.info("=== 详细分佣公式和计算结果 ==="); logger.info(""); - + // 1. 基础金额信息 logger.info("【基础金额信息】"); logger.info("订单总金额: {}元", totalPrice); @@ -1236,33 +1246,33 @@ public class WorkerCommissionUtil { logger.info("上门费: {}元", doorFee); logger.info("材料费用: {}元", materialFee); logger.info(""); - + // 2. 分佣基数信息 logger.info("【分佣基数信息】"); logger.info("服务分佣基数: {}%", serviceCommissionBase.multiply(new BigDecimal("100"))); logger.info("材料分佣基数: {}%", materialCommissionBase.multiply(new BigDecimal("100"))); logger.info(""); - + // 3. 师傅服务初次分佣公式 logger.info("【师傅服务初次分佣】"); logger.info("公式: ((订单总金额 + 定金 + 尾款 + 差价) - 优惠金额) × 服务分佣基数"); logger.info("计算过程:"); - logger.info(" 基础金额 = {} + {} + {} + {} = {}元", - totalPrice, deposit, finalPayment, priceDifference, + logger.info(" 基础金额 = {} + {} + {} + {} = {}元", + totalPrice, deposit, finalPayment, priceDifference, totalPrice.add(deposit).add(finalPayment).add(priceDifference)); - + BigDecimal baseAmount = totalPrice.add(deposit).add(finalPayment).add(priceDifference); BigDecimal netAmount = baseAmount.subtract(discountAmount); logger.info(" 净金额 = {} - {} = {}元", baseAmount, discountAmount, netAmount); - + BigDecimal commissionAmount = netAmount.multiply(serviceCommissionBase); logger.info(" 分佣金额 = {} × {} = {}元", netAmount, serviceCommissionBase, commissionAmount); - + BigDecimal finalServiceCommission = commissionAmount; logger.info(" 服务初次分佣 = {}元", finalServiceCommission); logger.info(" 结果: {}元", serviceCommissionAmount); logger.info(""); - + // 4. 师傅材料初次分佣公式 logger.info("【师傅材料初次分佣】"); logger.info("公式: 材料费用 × 材料分佣基数"); @@ -1270,7 +1280,7 @@ public class WorkerCommissionUtil { logger.info(" 材料初次分佣 = {} × {} = {}元", materialFee, materialCommissionBase, materialCommissionAmount); logger.info(" 结果: {}元", materialCommissionAmount); logger.info(""); - + // 5. 师傅质保金公式 logger.info("【师傅质保金】"); logger.info("公式: (师傅材料初次分佣 + 师傅服务初次分佣) × 10%"); @@ -1279,7 +1289,7 @@ public class WorkerCommissionUtil { logger.info(" 质保金 = {} × 10% = {}元", totalInitialCommission, warrantyAmount); logger.info(" 结果: {}元", warrantyAmount); logger.info(""); - + // 6. 本次订单师傅最终分佣公式 logger.info("【本次订单师傅最终分佣】"); logger.info("公式: (师傅材料初次分佣 + 师傅服务初次分佣) - 师傅质保金"); @@ -1287,7 +1297,7 @@ public class WorkerCommissionUtil { logger.info(" 最终分佣 = {} - {} = {}元", totalInitialCommission, warrantyAmount, finalCommissionAmount); logger.info(" 结果: {}元", finalCommissionAmount); logger.info(""); - + // 7. 最终分佣(含上门费) logger.info("【最终分佣(含上门费)】"); logger.info("公式: 最终分佣 + 上门费"); @@ -1295,7 +1305,7 @@ public class WorkerCommissionUtil { logger.info(" 最终分佣(含上门费) = {} + {} = {}元", finalCommissionAmount, doorFee, finalCommissionWithDoorFee); logger.info(" 结果: {}元", finalCommissionWithDoorFee); logger.info(""); - + // 8. 总结 logger.info("【分佣计算总结】"); logger.info("服务初次分佣: {}元", serviceCommissionAmount); @@ -1307,10 +1317,10 @@ public class WorkerCommissionUtil { logger.info("=== 分佣公式计算完成 ==="); logger.info(""); } - + /** * 生成分佣简要公式(用于客户展示) - * + * * @param totalPrice 订单总金额 * @param deposit 定金 * @param finalPayment 尾款 @@ -1334,9 +1344,9 @@ public class WorkerCommissionUtil { BigDecimal materialCommissionBase, BigDecimal serviceCommissionAmount, BigDecimal materialCommissionAmount, BigDecimal totalInitialCommission, BigDecimal warrantyAmount, BigDecimal finalCommissionAmount, BigDecimal finalCommissionWithDoorFee) { - + JSONObject formula = new JSONObject(); - + // 基础数据 formula.put("totalPrice", totalPrice); formula.put("deposit", deposit); @@ -1345,13 +1355,13 @@ public class WorkerCommissionUtil { formula.put("discountAmount", discountAmount); formula.put("doorFee", doorFee); formula.put("materialFee", materialFee); - + // 分佣基数 formula.put("serviceCommissionBase", serviceCommissionBase); formula.put("serviceCommissionBasePercent", serviceCommissionBase.multiply(new BigDecimal("100"))); formula.put("materialCommissionBase", materialCommissionBase); formula.put("materialCommissionBasePercent", materialCommissionBase.multiply(new BigDecimal("100"))); - + // 计算结果 formula.put("serviceCommissionAmount", serviceCommissionAmount); formula.put("materialCommissionAmount", materialCommissionAmount); @@ -1359,12 +1369,12 @@ public class WorkerCommissionUtil { formula.put("warrantyAmount", warrantyAmount); formula.put("finalCommissionAmount", finalCommissionAmount); formula.put("finalCommissionWithDoorFee", finalCommissionWithDoorFee); - + // 1. 服务分佣公式 BigDecimal baseAmount = totalPrice.add(deposit).add(finalPayment).add(priceDifference); BigDecimal netAmount = baseAmount.subtract(discountAmount); BigDecimal commissionAmount = netAmount.multiply(serviceCommissionBase); - + formula.put("serviceCommissionFormula", "服务分佣 = (订单总金额 + 定金 + 尾款 + 差价 - 优惠金额) × 服务分佣基数"); formula.put("serviceCommissionFormulaDetail", String.format( "服务分佣 = (%s + %s + %s + %s - %s) × %s%%", @@ -1374,7 +1384,7 @@ public class WorkerCommissionUtil { "服务分佣 = (%s + %s + %s + %s - %s) × %s = %s × %s = %s元", totalPrice, deposit, finalPayment, priceDifference, discountAmount, serviceCommissionBase, netAmount, serviceCommissionBase, commissionAmount)); - + // 2. 材料分佣公式 formula.put("materialCommissionFormula", "材料分佣 = 材料费用 × 材料分佣基数"); formula.put("materialCommissionFormulaDetail", String.format( @@ -1383,7 +1393,7 @@ public class WorkerCommissionUtil { formula.put("materialCommissionCalculation", String.format( "材料分佣 = %s × %s = %s元", materialFee, materialCommissionBase, materialCommissionAmount)); - + // 3. 质保金公式 formula.put("warrantyFormula", "质保金 = (服务分佣 + 材料分佣) × 10%"); formula.put("warrantyFormulaDetail", String.format( @@ -1392,7 +1402,7 @@ public class WorkerCommissionUtil { formula.put("warrantyCalculation", String.format( "质保金 = (%s + %s) × 0.10 = %s × 0.10 = %s元", serviceCommissionAmount, materialCommissionAmount, totalInitialCommission, warrantyAmount)); - + // 4. 最终分佣公式 formula.put("finalCommissionFormula", "最终分佣 = 总初次分佣 - 质保金"); formula.put("finalCommissionFormulaDetail", String.format( @@ -1401,7 +1411,7 @@ public class WorkerCommissionUtil { formula.put("finalCommissionCalculation", String.format( "最终分佣 = %s - %s = %s元", totalInitialCommission, warrantyAmount, finalCommissionAmount)); - + // 5. 最终分佣(含上门费) formula.put("finalCommissionWithDoorFee", "最终分佣(含上门费) = 最终分佣 + 上门费"); formula.put("finalCommissionWithDoorFeeDetail", String.format( @@ -1410,25 +1420,25 @@ public class WorkerCommissionUtil { formula.put("finalCommissionWithDoorFeeCalculation", String.format( "最终分佣(含上门费) = %s + %s = %s元", finalCommissionAmount, doorFee, finalCommissionWithDoorFee)); - + // 6. 分佣总结 formula.put("commissionSummary", String.format( "分佣总结:服务分佣%s元 + 材料分佣%s元 = 总初次分佣%s元,扣除质保金%s元,师傅最终分佣%s元", serviceCommissionAmount, materialCommissionAmount, totalInitialCommission, warrantyAmount, finalCommissionAmount)); - + // 7. 分佣比例说明 formula.put("commissionRatioExplanation", String.format( "分佣比例说明:服务分佣按%s%%计算,材料分佣按%s%%计算,质保金按10%%扣除", serviceCommissionBase.multiply(new BigDecimal("100")), materialCommissionBase.multiply(new BigDecimal("100")))); - + return formula; } - + /** * 生成简洁分佣总结(括号加中文名格式) - * + * * @param totalPrice 订单总金额 * @param priceDifference 差价 * @param discountAmount 优惠金额 @@ -1450,7 +1460,7 @@ public class WorkerCommissionUtil { BigDecimal materialCommissionBase, BigDecimal serviceCommissionAmount, BigDecimal materialCommissionAmount, BigDecimal totalInitialCommission, BigDecimal warrantyAmount, BigDecimal finalCommissionAmount, BigDecimal finalCommissionWithDoorFee) { - + StringBuilder summary = new StringBuilder(); BigDecimal baseAmount = totalPrice.add(serviceFee).add(priceDifference).subtract(discountAmount); // // 计算基础金额 @@ -1490,27 +1500,27 @@ public class WorkerCommissionUtil { return fwyj; } - + /** * 测试获取分佣基数方法 * 用于验证分佣基数计算功能 - * + * * @param orderId 订单ID * @return 测试结果 */ public static JSONObject testGetCommissionBase(Long orderId) { JSONObject result = new JSONObject(); - + logger.info("=== 开始测试获取分佣基数 ==="); logger.info("测试订单ID: {}", orderId); - + try { // 调用获取分佣基数方法 BigDecimal commissionBase = getCommissionBase(orderId); - + // 获取材料分佣基数 BigDecimal materialCommissionBase = getMaterialCommissionBase(); - + result.put("success", true); result.put("message", "获取分佣基数测试成功"); result.put("orderId", orderId); @@ -1518,63 +1528,63 @@ public class WorkerCommissionUtil { result.put("commissionBasePercent", commissionBase.multiply(new BigDecimal("100"))); result.put("materialCommissionBase", materialCommissionBase); result.put("materialCommissionBasePercent", materialCommissionBase.multiply(new BigDecimal("100"))); - - logger.info("分佣基数测试完成 - 订单ID: {}, 分佣基数: {}, 分佣比例: {}%, 材料分佣基数: {}, 材料分佣比例: {}%", - orderId, commissionBase, commissionBase.multiply(new BigDecimal("100")), + + logger.info("分佣基数测试完成 - 订单ID: {}, 分佣基数: {}, 分佣比例: {}%, 材料分佣基数: {}, 材料分佣比例: {}%", + orderId, commissionBase, commissionBase.multiply(new BigDecimal("100")), materialCommissionBase, materialCommissionBase.multiply(new BigDecimal("100"))); - + } catch (Exception e) { logger.error("获取分佣基数测试异常", e); result.put("success", false); result.put("message", "测试过程中发生异常:" + e.getMessage()); } - + return result; } - + /** * 测试获取材料分佣基数方法 * 用于验证材料分佣基数计算功能 - * + * * @return 测试结果 */ public static JSONObject testGetMaterialCommissionBase() { JSONObject result = new JSONObject(); - + logger.info("=== 开始测试获取材料分佣基数 ==="); - + try { // 调用获取材料分佣基数方法 BigDecimal materialCommissionBase = getMaterialCommissionBase(); - + result.put("success", true); result.put("message", "获取材料分佣基数测试成功"); result.put("materialCommissionBase", materialCommissionBase); result.put("materialCommissionBasePercent", materialCommissionBase.multiply(new BigDecimal("100"))); - - logger.info("材料分佣基数测试完成 - 材料分佣基数: {}, 材料分佣比例: {}%", + + logger.info("材料分佣基数测试完成 - 材料分佣基数: {}, 材料分佣比例: {}%", materialCommissionBase, materialCommissionBase.multiply(new BigDecimal("100"))); - + } catch (Exception e) { logger.error("获取材料分佣基数测试异常", e); result.put("success", false); result.put("message", "测试过程中发生异常:" + e.getMessage()); } - + return result; } - + /** * 计算并更新订单总金额(用于开票) * 公式:上门费 + 服务费用 + 材料费用 + 尾款 + 差价 + 定金 - 优惠费用 - * + * * @param order 订单对象 * @param amountComposition 订单金额组成 */ private static void updateOrderTotalPriceForInvoice(Order order, JSONObject amountComposition) { logger.info("=== 开始计算并更新订单总金额(用于开票) ==="); logger.info("订单ID: {}, 订单号: {}", order.getId(), order.getOrderId()); - + try { // 1. 获取各项金额 BigDecimal doorFee = (BigDecimal) amountComposition.get("doorFee"); @@ -1586,7 +1596,7 @@ public class WorkerCommissionUtil { BigDecimal priceDifference = (BigDecimal) amountComposition.get("priceDifference"); BigDecimal deposit = (BigDecimal) amountComposition.get("deposit"); BigDecimal discountAmount = (BigDecimal) amountComposition.get("discountAmount"); - + // 2. 确保金额不为null if (totalPrice == null) totalPrice = BigDecimal.ZERO; if (doorFee == null) doorFee = BigDecimal.ZERO; @@ -1596,12 +1606,12 @@ public class WorkerCommissionUtil { if (priceDifference == null) priceDifference = BigDecimal.ZERO; if (deposit == null) deposit = BigDecimal.ZERO; if (discountAmount == null) discountAmount = BigDecimal.ZERO; - + // 3. 计算订单总金额(用于开票) // 公式:上门费 + 服务费用 + 材料费用 + 尾款 + 差价 + 定金 - 优惠费用 BigDecimal invoiceTotalPrice = doorFee.add(serviceFee).add(materialFee).add(totalPrice) .add(finalPayment).add(priceDifference).add(deposit).subtract(discountAmount); - + logger.info("=== 订单总金额计算明细(用于开票) ==="); logger.info("上门费: {}元", doorFee); logger.info("服务费用: {}元", serviceFee); @@ -1610,12 +1620,12 @@ public class WorkerCommissionUtil { logger.info("差价: {}元", priceDifference); logger.info("定金: {}元", deposit); logger.info("优惠费用: {}元", discountAmount); - logger.info("计算公式: {} + {} + {} + {} + {} + {} - {} = {}元", + logger.info("计算公式: {} + {} + {} + {} + {} + {} - {} = {}元", doorFee, serviceFee, materialFee, finalPayment, priceDifference, deposit, discountAmount, invoiceTotalPrice); - + // 4. 更新订单的total_price字段 order.setTotalPrice(invoiceTotalPrice); - + // 5. 保存更新后的订单信息 int updateResult = orderService.updateOrder(order); if (updateResult > 0) { @@ -1623,44 +1633,44 @@ public class WorkerCommissionUtil { } else { logger.error("订单总金额更新失败 - 订单ID: {}", order.getId()); } - + logger.info("=== 订单总金额更新完成(用于开票) ==="); logger.info("订单号: {}", order.getOrderId()); logger.info("更新后总金额: {}元", invoiceTotalPrice); - + } catch (Exception e) { logger.error("计算并更新订单总金额异常,订单ID: {}", order.getId(), e); } } - + /** * 测试完整分佣计算方法 * 用于验证完整的分佣计算功能,包含详细的步骤打印 - * + * * @param orderId 订单ID * @return 测试结果 */ public static JSONObject testCompleteWorkerCommission(Long orderId) { JSONObject result = new JSONObject(); - + logger.info("=== 开始测试完整分佣计算 ==="); logger.info("测试订单ID: {}", orderId); - + try { // 调用完整分佣计算方法 JSONObject commissionResult = calculateCompleteWorkerCommission(orderId); - + if (Boolean.TRUE.equals(commissionResult.get("success"))) { result.put("success", true); result.put("message", "完整分佣计算测试成功"); result.put("orderId", orderId); result.put("commissionResult", commissionResult); - + // 提取关键信息用于日志 JSONObject orderInfo = (JSONObject) commissionResult.get("orderInfo"); JSONObject commissionBases = (JSONObject) commissionResult.get("commissionBases"); JSONObject commissionAmounts = (JSONObject) commissionResult.get("commissionAmounts"); - + logger.info("=== 完整分佣计算测试完成 ==="); logger.info("订单号: {}", orderInfo.getString("orderId")); logger.info("师傅ID: {}", orderInfo.getLong("workerId")); @@ -1672,19 +1682,19 @@ public class WorkerCommissionUtil { logger.info("质保金: {}元", commissionAmounts.getBigDecimal("warrantyAmount")); logger.info("最终分佣: {}元", commissionAmounts.getBigDecimal("finalCommissionAmount")); logger.info("最终分佣(含上门费): {}元", commissionAmounts.getBigDecimal("finalCommissionWithDoorFee")); - + } else { result.put("success", false); result.put("message", "完整分佣计算失败:" + commissionResult.getString("message")); logger.error("完整分佣计算测试失败: {}", commissionResult.getString("message")); } - + } catch (Exception e) { logger.error("完整分佣计算测试异常", e); result.put("success", false); result.put("message", "测试过程中发生异常:" + e.getMessage()); } - + return result; } -} \ No newline at end of file +}