From 74257caefe700dd0aef1e87622a54ac2c087dbc8 Mon Sep 17 00:00:00 2001 From: "925116093-qq.com" <925116093@qq.com> Date: Tue, 24 Jun 2025 17:15:20 +0800 Subject: [PATCH] 202506241715 --- .../src/main/resources/application.yml | 9 +- .../com/ruoyi/system/config/WechatConfig.java | 46 + .../system/controller/AppletController.java | 978 +++++++++++------- .../controller/WorkerApplyController.java | 70 +- .../system/controllerUtil/CouponUtil.java | 76 ++ .../system/controllerUtil/WechatPayUtil.java | 114 +- .../controllerUtil/WorkerApplyUtil.java | 88 ++ .../com/ruoyi/system/domain/GoodsOrder.java | 10 + .../ruoyi/system/mapper/CouponUserMapper.java | 7 + .../ruoyi/system/mapper/GoodsOrderMapper.java | 7 + .../com/ruoyi/system/mapper/OrderMapper.java | 3 + .../com/ruoyi/system/mapper/UsersMapper.java | 3 + .../system/service/ICouponUserService.java | 3 + .../system/service/IGoodsOrderService.java | 7 + .../ruoyi/system/service/IOrderService.java | 5 + .../ruoyi/system/service/IUsersService.java | 3 + .../service/impl/CouponUserServiceImpl.java | 5 + .../service/impl/GoodsOrderServiceImpl.java | 10 + .../system/service/impl/OrderServiceImpl.java | 8 + .../system/service/impl/UsersServiceImpl.java | 3 + .../mapper/system/CouponUserMapper.xml | 6 + .../resources/mapper/system/CouponsMapper.xml | 5 + .../mapper/system/GoodsOrderMapper.xml | 15 + .../resources/mapper/system/OrderMapper.xml | 9 + .../resources/mapper/system/UsersMapper.xml | 7 + 25 files changed, 1100 insertions(+), 397 deletions(-) create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/config/WechatConfig.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/CouponUtil.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WorkerApplyUtil.java diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 5d8be1d..7296036 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -13,11 +13,10 @@ ruoyi: # 验证码类型 math 数字计算 char 字符验证 captchaType: math wechat: - pay: - app-id: wx73d0202b3c8a6d68 - mch-id: 1672571923 - api-key: sssssssssssssssssssssssssssssssS - cert-path: wechat/apiclient_cert.p12 + appid: wx73d0202b3c8a6d68 + mchid: 1672571923 + apikey: sssssssssssssssssssssssssssssssS + certpath: wechat/apiclient_cert.p12 # 七牛云配置 qiniu: # 是否启用七牛云上传 true-启用七牛云 false-使用本地上传 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/config/WechatConfig.java b/ruoyi-system/src/main/java/com/ruoyi/system/config/WechatConfig.java new file mode 100644 index 0000000..4514a52 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/config/WechatConfig.java @@ -0,0 +1,46 @@ +package com.ruoyi.system.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "wechat") +public class WechatConfig { + + private String appid; + private String mchid; + private String apikey; + private String certpath; + + public String getAppid() { + return appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getMchid() { + return mchid; + } + + public void setMchid(String mchid) { + this.mchid = mchid; + } + + public String getApikey() { + return apikey; + } + + public void setApikey(String apikey) { + this.apikey = apikey; + } + + public String getCertpath() { + return certpath; + } + + public void setCertpath(String certpath) { + this.certpath = certpath; + } +} 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 c4f6561..8651626 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 @@ -134,112 +134,11 @@ public class AppletController extends BaseController { private WechatPayUtil wechatPayUtil; @Autowired private IGoodsOrderCursorService goodsOrderCursorService; + @Autowired + private IWorkerApplyService workerApplyService; + -// /** -// * 创建服务订单 -// * -// * @param params 请求参数,包含商品信息、地址信息和预约时间 -// * @param request HTTP请求对象 -// * @return 返回创建结果 -// */ -// @PostMapping("/api/service/create/order") -// public AjaxResult createServiceNewOrder(@RequestBody Map params, HttpServletRequest request) { -// try { -// // 1. 验证用户登录状态 -// String token = request.getHeader("token"); -// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); -// if (!(Boolean) userValidation.get("valid")) { -// return error("用户未登录或token无效"); -// } -// -// // 2. 获取用户信息 -// Users user = (Users) userValidation.get("user"); -// if (user == null) { -// return error("用户信息获取失败"); -// } -// -// // 3. 解析订单参数 -// if (params == null || params.get("0") == null) { -// return error("订单参数不能为空"); -// } -// Map orderParams = (Map) params.get("0"); -// -// // 4. 验证必要参数 -// Long productId = Long.valueOf(orderParams.get("product_id").toString()); -// Long addressId = Long.valueOf(orderParams.get("address_id").toString()); -// String makeTime = orderParams.get("make_time").toString(); -// String sku = orderParams.get("sku") != null ? orderParams.get("sku").toString() : ""; -// -// // 5. 查询商品信息 -// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); -// if (serviceGoods == null) { -// return error("商品不存在"); -// } -// -// // 6. 查询地址信息 -// UserAddress userAddress = userAddressService.selectUserAddressById(addressId); -// if (userAddress == null) { -// return error("地址不存在"); -// } -// -// // 7. 创建订单对象 -// Order order = new Order(); -// order.setType(1); // 1:服务项目 -// order.setCreateType(1); // 1:用户自主下单 -// order.setUid(user.getId()); -// order.setUname(user.getName()); -// order.setProductId(productId); -// order.setProductName(serviceGoods.getTitle()); -// order.setName(userAddress.getName()); -// order.setPhone(userAddress.getPhone()); -// order.setAddress(userAddress.getAddressInfo()); -// order.setAddressId(addressId); -// order.setSku(sku); -// -// // 解析预约时间 -// String[] makeTimeArr = makeTime.split(" "); -// if (makeTimeArr.length != 2) { -// return error("预约时间格式错误"); -// } -// // 将日期字符串转换为时间戳 -// try { -// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); -// Date date = sdf.parse(makeTimeArr[0]); -// order.setMakeTime(date.getTime() / 1000); // 转换为秒级时间戳 -// order.setMakeHour(makeTimeArr[1]); // 设置预约时间段 -// } catch (Exception e) { -// return error("预约时间格式错误"); -// } -// -// order.setNum(1L); // 默认数量为1 -// order.setTotalPrice(serviceGoods.getPrice()); // 总价等于商品价格 -// order.setGoodPrice(serviceGoods.getPrice()); // 商品金额 -// order.setServicePrice(BigDecimal.ZERO); // 服务金额默认为0 -// order.setPayPrice(serviceGoods.getPrice()); // 支付金额等于总价 -// order.setStatus(1L); // 1:待接单 -// order.setReceiveType(1L); // 1:自由抢单 -// order.setIsAccept(0); // 0:未接单 -// order.setIsComment(0); // 0:未评价 -// order.setIsPause(0); // 0:未暂停 -// -// // 8. 生成订单号 -// String orderId = generateOrderId(); -// order.setOrderId(orderId); -// order.setMainOrderId(orderId); -// -// // 9. 保存订单 -// int result = orderService.insertOrder(order); -// if (result > 0) { -// return success("预约成功"); -// } else { -// return error("预约失败,请稍后重试"); -// } -// -// } catch (Exception e) { -// return error("预约失败:" + e.getMessage()); -// } -// } /** * 生成订单号 @@ -288,6 +187,49 @@ public class AppletController extends BaseController { } } + +// /** +// * 获取服务分类列表 +// * +// * @param request HTTP请求对象 +// * @return 分类列表数据 +// *

+// * 接口说明: +// * - 获取状态为启用的服务分类 +// * - 自动添加图片CDN前缀 +// * - 支持用户登录状态验证 +// */ +// @GetMapping(value = "/api/form/apply/worker") +// public AjaxResult applyworker(@RequestBody Map params, HttpServletRequest request) { +// try { +// +// // 2. 验证用户登录状态 +// String token = request.getHeader("token"); +// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); +// if (!(Boolean) userValidation.get("valid")) { +// return AppletControllerUtil.appletUnauthorized(); +// } +// +// // 3. 获取用户信息 +// Users user = (Users) userValidation.get("user"); +// if (user == null) { +// return AppletControllerUtil.appletWarning("用户信息获取失败"); +// } +// +// +// +// return AppletControllerUtil.appletSuccess(""); +// } catch (Exception e) { +// return AppletControllerUtil.appletError("获取服务分类列表失败:" + e.getMessage()); +// } +// } + + + + + + + /** * 获取系统配置信息 * @@ -722,7 +664,7 @@ public class AppletController extends BaseController { try { // 1. 参数验证 if (params == null) { - return error("请求参数不能为空"); + return AppletControllerUtil.appletWarning("请求参数不能为空"); } String orderId = (String) params.get("order_id"); @@ -730,62 +672,62 @@ public class AppletController extends BaseController { String mark = (String) params.get("mark"); if (StringUtils.isEmpty(orderId)) { - return error("订单ID不能为空"); + return AppletControllerUtil.appletWarning("订单ID不能为空"); } if (StringUtils.isEmpty(phone)) { - return error("联系电话不能为空"); + return AppletControllerUtil.appletWarning("联系电话不能为空"); } // 验证手机号格式 if (!phone.matches("^1[3-9]\\d{9}$")) { - return error("联系电话格式不正确"); + return AppletControllerUtil.appletWarning("联系电话格式不正确"); } if (StringUtils.isEmpty(mark)) { - return error("返修原因不能为空"); + return AppletControllerUtil.appletWarning("返修原因不能为空"); } // 2. 验证用户登录状态 String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 3. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 4. 查询订单信息并验证归属权 Order order = orderService.selectOrderByOrderId(orderId); if (order == null) { - return error("订单不存在"); + return AppletControllerUtil.appletWarning("订单不存在"); } if (!order.getUid().equals(user.getId())) { - return error("无权操作此订单"); + return AppletControllerUtil.appletWarning("无权操作此订单"); } // 5. 验证订单状态是否允许申请售后 if (!AppletControllerUtil.isOrderAllowRework(order.getStatus())) { - return error("当前订单状态不允许申请售后"); + return AppletControllerUtil.appletWarning("当前订单状态不允许申请售后"); } // 6. 处理售后返修申请 boolean reworkResult = AppletControllerUtil.processReworkApplication(order, phone, mark, user, orderReworkService, orderService); if (reworkResult) { - return success("售后返修申请已提交,我们会尽快联系您处理"); + return AppletControllerUtil.appletSuccess("售后返修申请已提交,我们会尽快联系您处理"); } else { - return error("售后申请提交失败,请稍后重试"); + return AppletControllerUtil.appletWarning("售后申请提交失败,请稍后重试"); } } catch (Exception e) { System.err.println("售后返修申请异常:" + e.getMessage()); - return error("售后申请失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("售后申请失败:" + e.getMessage()); } } @@ -814,20 +756,20 @@ public class AppletController extends BaseController { // 1. 验证分页参数 Map pageValidation = PageUtil.validatePageParams(page, limit); if (!(Boolean) pageValidation.get("valid")) { - return error((String) pageValidation.get("message")); + 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 error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 3. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 4. 设置分页参数 @@ -865,7 +807,7 @@ public class AppletController extends BaseController { // 7. 构建符合要求的分页响应格式 Map pageData = PageUtil.buildPageResponse(tableDataInfo, page, limit); - return success(pageData); + return AppletControllerUtil.appletSuccess(pageData); } /** @@ -1087,9 +1029,9 @@ public class AppletController extends BaseController { Users users = usersService.selectUsersByRememberToken(token); if (users != null) { users.setRemember_token(users.getRememberToken()); - return success(users); + return AppletControllerUtil.appletSuccess(users); } else { - return error("用户不存在"); + return AppletControllerUtil.appletWarning("用户不存在"); } } @@ -1115,7 +1057,7 @@ public class AppletController extends BaseController { try { cateId = Long.parseLong((String) cateIdObj); } catch (NumberFormatException e) { - return error("分类ID格式错误"); + return AppletControllerUtil.appletWarning("分类ID格式错误"); } } } @@ -1155,9 +1097,9 @@ public class AppletController extends BaseController { } } - return success(resultList); + return AppletControllerUtil.appletSuccess(resultList); } catch (Exception e) { - return error("查询服务商品列表失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询服务商品列表失败:" + e.getMessage()); } } @@ -1178,7 +1120,7 @@ public class AppletController extends BaseController { // try { // // 参数验证 // if (id <= 0) { -// return error("商品ID无效"); +// return AppletControllerUtil.appletWarning("商品ID无效"); // } // // // 查询商品信息 @@ -1186,12 +1128,12 @@ public class AppletController extends BaseController { // if (serviceGoodsData != null) { // // 使用工具类转换数据格式 // AppletControllerUtil.ServiceGoodsResponse response = new AppletControllerUtil.ServiceGoodsResponse(serviceGoodsData); -// return success(response); +// return AppletControllerUtil.appletSuccess(response); // } else { -// return error("商品不存在或已下架"); +// return AppletControllerUtil.appletWarning("商品不存在或已下架"); // } // } catch (Exception e) { -// return error("查询商品详情失败:" + e.getMessage()); +// return AppletControllerUtil.appletWarning("查询商品详情失败:" + e.getMessage()); // } // } @@ -1237,6 +1179,12 @@ public class AppletController extends BaseController { } } + + + + + + /** * 获取广告图片列表 * @@ -1254,7 +1202,7 @@ public class AppletController extends BaseController { try { // 参数验证 if (type < 0) { - return error("广告类型无效"); + return AppletControllerUtil.appletWarning("广告类型无效"); } // 构建查询条件 @@ -1269,9 +1217,9 @@ public class AppletController extends BaseController { advImg.setImage(AppletControllerUtil.buildImageUrl(advImg.getImage())); } - return success(advImgList); + return AppletControllerUtil.appletSuccess(advImgList); } catch (Exception e) { - return error("获取广告图片失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("获取广告图片失败:" + e.getMessage()); } } @@ -1387,16 +1335,21 @@ public class AppletController extends BaseController { Map userInfo = buildUserInfoResponse(user); userInfo.put("remember_token", userInfo.get("rememberToken")); - order_num.put("pending_accept", 2); - order_num.put("pending_service", 0); - order_num.put("in_service", 0); - order_num.put("other_status", 0); + + + 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", 0); - goods_order_num.put("pending_service", 3); - goods_order_num.put("in_service", 0); - goods_order_num.put("other_status", 0); + + + 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 { @@ -1856,7 +1809,7 @@ public class AppletController extends BaseController { ); if (token == null) { - return error("未提供token,请先登录"); + return AppletControllerUtil.appletWarning("未提供token,请先登录"); } // 2. 验证token @@ -1865,13 +1818,13 @@ public class AppletController extends BaseController { // 3. 返回验证结果 boolean valid = (Boolean) validateResult.get("valid"); if (valid) { - return success(validateResult); + return AppletControllerUtil.appletSuccess(validateResult); } else { - return error((String) validateResult.get("message")); + return AppletControllerUtil.appletWarning((String) validateResult.get("message")); } } catch (Exception e) { - return error("验证token失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("验证token失败:" + e.getMessage()); } } @@ -1911,7 +1864,7 @@ public class AppletController extends BaseController { // if (usercode == null) { // // } -// return success(); +// return AppletControllerUtil.appletSuccess(); // // } @@ -1956,7 +1909,7 @@ public class AppletController extends BaseController { String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } WechatPayUtil wechatPayUtil = new WechatPayUtil(); // 2. 调用微信支付统一下单 @@ -1965,13 +1918,13 @@ public class AppletController extends BaseController { // 3. 返回结果 boolean success = (Boolean) payResult.get("success"); if (success) { - return success(payResult); + return AppletControllerUtil.appletSuccess(payResult); } else { - return error((String) payResult.get("message")); + return AppletControllerUtil.appletWarning((String) payResult.get("message")); } } catch (Exception e) { - return error("创建支付订单失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("创建支付订单失败:" + e.getMessage()); } } @@ -1989,7 +1942,7 @@ public class AppletController extends BaseController { String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } WechatPayUtil wechatPayUtil = new WechatPayUtil(); // 2. 查询订单状态 @@ -1998,13 +1951,13 @@ public class AppletController extends BaseController { // 3. 返回结果 boolean success = (Boolean) queryResult.get("success"); if (success) { - return success(queryResult); + return AppletControllerUtil.appletSuccess(queryResult); } else { - return error((String) queryResult.get("message")); + return AppletControllerUtil.appletWarning((String) queryResult.get("message")); } } catch (Exception e) { - return error("查询订单状态失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询订单状态失败:" + e.getMessage()); } } @@ -2033,7 +1986,7 @@ public class AppletController extends BaseController { String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } WechatPayUtil wechatPayUtil = new WechatPayUtil(); // 2. 创建代付订单 @@ -2042,13 +1995,13 @@ public class AppletController extends BaseController { // 3. 返回结果 boolean success = (Boolean) payForResult.get("success"); if (success) { - return success(payForResult); + return AppletControllerUtil.appletSuccess(payForResult); } else { - return error((String) payForResult.get("message")); + return AppletControllerUtil.appletWarning((String) payForResult.get("message")); } } catch (Exception e) { - return error("创建代付订单失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("创建代付订单失败:" + e.getMessage()); } } @@ -2114,7 +2067,7 @@ public class AppletController extends BaseController { String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } WechatPayUtil wechatPayUtil = new WechatPayUtil(); // 2. 申请退款 @@ -2123,13 +2076,13 @@ public class AppletController extends BaseController { // 3. 返回结果 boolean success = (Boolean) refundResult.get("success"); if (success) { - return success(refundResult); + return AppletControllerUtil.appletSuccess(refundResult); } else { - return error((String) refundResult.get("message")); + return AppletControllerUtil.appletWarning((String) refundResult.get("message")); } } catch (Exception e) { - return error("申请退款失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("申请退款失败:" + e.getMessage()); } } @@ -2155,7 +2108,7 @@ public class AppletController extends BaseController { String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } WechatPayUtil wechatPayUtil = new WechatPayUtil(); // 2. 企业付款 @@ -2164,13 +2117,13 @@ public class AppletController extends BaseController { // 3. 返回结果 boolean success = (Boolean) transferResult.get("success"); if (success) { - return success(transferResult); + return AppletControllerUtil.appletSuccess(transferResult); } else { - return error((String) transferResult.get("message")); + return AppletControllerUtil.appletWarning((String) transferResult.get("message")); } } catch (Exception e) { - return error("企业付款失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("企业付款失败:" + e.getMessage()); } } @@ -2199,20 +2152,20 @@ public class AppletController extends BaseController { // 2. 验证分页参数 Map pageValidation = PageUtil.validatePageParams(page, limit); if (!(Boolean) pageValidation.get("valid")) { - return error((String) pageValidation.get("message")); + 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 error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 4. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 5. 设置分页参数 @@ -2258,11 +2211,11 @@ public class AppletController extends BaseController { responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/service/order/rework/lst?page=" + pageInfo.getPrePage() : null); - return success(responseData); + return AppletControllerUtil.appletSuccess(responseData); } catch (Exception e) { System.err.println("查询售后返修列表异常:" + e.getMessage()); - return error("查询售后返修列表失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询售后返修列表失败:" + e.getMessage()); } } @@ -2301,7 +2254,7 @@ public class AppletController extends BaseController { try { // 1. 参数验证 if (params == null) { - return error("请求参数不能为空"); + return AppletControllerUtil.appletWarning("请求参数不能为空"); } String company = (String) params.get("company"); @@ -2312,28 +2265,28 @@ public class AppletController extends BaseController { // 2. 验证必填字段 if (StringUtils.isEmpty(company)) { - return error("公司名称不能为空"); + return AppletControllerUtil.appletWarning("公司名称不能为空"); } if (StringUtils.isEmpty(name)) { - return error("联系人姓名不能为空"); + return AppletControllerUtil.appletWarning("联系人姓名不能为空"); } if (StringUtils.isEmpty(phone)) { - return error("联系电话不能为空"); + return AppletControllerUtil.appletWarning("联系电话不能为空"); } // 验证手机号格式 if (!phone.matches("^1[3-9]\\d{9}$")) { - return error("联系电话格式不正确"); + return AppletControllerUtil.appletWarning("联系电话格式不正确"); } if (StringUtils.isEmpty(address)) { - return error("联系地址不能为空"); + return AppletControllerUtil.appletWarning("联系地址不能为空"); } if (StringUtils.isEmpty(info)) { - return error("合作意向不能为空"); + return AppletControllerUtil.appletWarning("合作意向不能为空"); } // 3. 获取用户信息(可选,不强制要求登录) @@ -2358,21 +2311,21 @@ public class AppletController extends BaseController { // 5. 验证合作申请参数 String validationResult = AppletControllerUtil.validateCooperateParams(cooperate); if (validationResult != null) { - return error(validationResult); + return AppletControllerUtil.appletWarning(validationResult); } // 6. 保存合作申请记录 int insertResult = cooperateService.insertCooperate(cooperate); if (insertResult > 0) { - return success("合作申请提交成功,我们会尽快联系您"); + return AppletControllerUtil.appletSuccess("合作申请提交成功,我们会尽快联系您"); } else { - return error("合作申请提交失败,请稍后重试"); + return AppletControllerUtil.appletWarning("合作申请提交失败,请稍后重试"); } } catch (Exception e) { System.err.println("合作申请提交异常:" + e.getMessage()); - return error("合作申请提交失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("合作申请提交失败:" + e.getMessage()); } } @@ -2391,13 +2344,13 @@ public class AppletController extends BaseController { String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 4. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } Long userId = user.getId(); // 获取当前用户id @@ -2416,9 +2369,9 @@ public class AppletController extends BaseController { //安状态进行赋值 //待领取优惠券 if (status==4){ - Coupons coupons = new Coupons(); - coupons.setSearchValue("12"); - List couponsList = couponsService.selectCouponsList(coupons); +// Coupons coupons = new Coupons(); +// coupons.setSearchValue("12"); + List couponsList =CouponUtil.iscoupon(userId,couponsService,couponUserService); if (!couponsList.isEmpty()){ return AppletControllerUtil.appletSuccess(AppletControllerUtil.buildCouponDataList(couponsList,serviceCateService,serviceGoodsService)); } @@ -2426,15 +2379,7 @@ public class AppletController extends BaseController { CouponUser couponUserData = new CouponUser(); couponUserData.setStatus(Long.valueOf(status)); couponUserData.setUid(user.getId()); -// if (productIdStr!=null){ -// couponUserData.setProductId(productIdStr); -// } -// if (totalPrice!=null){ -// couponUserData.setMinPrice(totalPrice); -// } -// List couponUserList, -// IServiceCateService serviceCateService, IServiceGoodsService serviceGoodsService,Long productId,Long totalPrice List couponUserDataList = couponUserService.selectCouponUserList(couponUserData); if (couponUserDataList!=null){ @@ -2450,6 +2395,122 @@ public class AppletController extends BaseController { + /** + * 积分订单收货确认接口 + * @param request + * @return AjaxResult + * 订单状态 1:待支付 2:已支付,待发货3:待收货 4:待评价 5:已收货 6:取消 20:申请退款 21:同意退款 22:驳回退款 + */ + + @GetMapping("/api/integral/user/order/confirm/{id}") + public AjaxResult confirmOrder(@PathVariable("id") String id,HttpServletRequest request) { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + IntegralOrder integralOrder = integralOrderService.selectIntegralOrderById(Long.valueOf(id)); + if (integralOrder==null){ + return AppletControllerUtil.appletWarning("订单不存在"); + } + if(!user.getId().equals(integralOrder.getUid())){ + return AppletControllerUtil.appletWarning("确认收货失败,收货人和操作人应为同一人,请确认后再进行操作"); + } + if (!integralOrder.getStatus().equals("2")){ + return AppletControllerUtil.appletWarning("订单状态错误"); + } + integralOrder.setStatus("3"); + integralOrderService.updateIntegralOrder(integralOrder); + IntegralOrderLog integralOrderLog = new IntegralOrderLog(); + integralOrderLog.setOrderId(integralOrder.getOrderId()); + integralOrderLog.setOid(integralOrder.getId()); + integralOrderLog.setType(3L); + integralOrderLog.setTitle("确认收货"); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name","用户确认收货"); + integralOrderLog.setContent(jsonObject.toJSONString()); + int flg=integralOrderLogService.insertIntegralOrderLog(integralOrderLog); + if (flg>0){ + return AppletControllerUtil.appletSuccess("确认收货成功"); + }else{ + return AppletControllerUtil.appletWarning("确认收货失败"); + } + + } + + + + /** + * 商品订单评价接口 + * @param param {order_id, content, num, images} + * @param request + * @return AjaxResult + * 订单状态 1:待支付 2:已支付,待发货3:待收货 4:待评价 5:已收货 6:取消 20:申请退款 21:同意退款 22:驳回退款 + */ + @PostMapping("/api/goods/order/comment") + public AjaxResult commentGoodsOrder(@RequestBody Map param, HttpServletRequest request) { + // 参数校验 + String orderId = (String) param.get("order_id"); + String content = (String) param.get("content"); + Integer num = param.get("num") != null ? Integer.parseInt(param.get("num").toString()) : null; + Object imagesObj = param.get("images"); + if (orderId == null || orderId.isEmpty()) { + return AjaxResult.error("请选择评价的订单"); + } + if (content == null || content.isEmpty()) { + return AjaxResult.error("请输入评价内容"); + } + if (num == null) { + return AjaxResult.error("请打分"); + } + // 获取当前登录用户(假设有token或session,示例用1L) + Long uid = 1L; + // 判断是否已评价 + GoodsOrder goodsOrder = null; + { + GoodsOrder query = new GoodsOrder(); + query.setOrderId(orderId); + List orderList = goodsOrderService.selectGoodsOrderList(query); + if (orderList == null || orderList.isEmpty()) { + return AjaxResult.error("订单不存在"); + } + goodsOrder = orderList.get(0); + } + int count = orderCommentService.selectCountOrderCommentByOid(goodsOrder.getId()); + if (count > 0) { + return AjaxResult.error("请勿重复提交"); + } + // 评分类型 + long numType = num == 1 ? 3 : ((num == 2 || num == 3) ? 2 : 1); + // 组装评价对象 + OrderComment comment = new OrderComment(); + comment.setOid(goodsOrder.getId()); + comment.setOrderId(orderId); + comment.setProductId(goodsOrder.getProductId()); + comment.setContent(content); + comment.setNum((long) num); + comment.setUid(goodsOrder.getUid()); // 或uid + comment.setImages(imagesObj != null ? com.alibaba.fastjson2.JSON.toJSONString(imagesObj) : null); + comment.setNumType(numType); + comment.setCreatedAt(new java.util.Date()); + comment.setUpdatedAt(new java.util.Date()); + comment.setStatus(1); // 显示 + int result = orderCommentService.insertOrderComment(comment); + if (result > 0) { + goodsOrder.setStatus(5L); // 订单状态改为已收货 + goodsOrderService.updateGoodsOrder(goodsOrder); + return AjaxResult.success(); + } else { + return AjaxResult.error("操作失败"); + } + } // ... existing code ... // /** @@ -2466,13 +2527,13 @@ public class AppletController extends BaseController { // String token = request.getHeader("token"); // Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); // if (!(Boolean) userValidation.get("valid")) { -// return error("用户未登录或token无效"); +// return AppletControllerUtil.appletWarning("用户未登录或token无效"); // } // // 2. 获取用户信息 // Users user = (Users) userValidation.get("user"); // if (user == null) { -// return error("用户信息获取失败"); +// return AppletControllerUtil.appletWarning("用户信息获取失败"); // } // // 3. 解析查询参数 @@ -2565,11 +2626,11 @@ public class AppletController extends BaseController { // List> resultList = AppletControllerUtil.buildCouponUserList( // priceFilteredList, serviceCateService); -// return success(resultList); +// return AppletControllerUtil.appletSuccess(resultList); // } catch (Exception e) { // System.err.println("查询用户优惠券列表异常:" + e.getMessage()); -// return error("查询优惠券列表失败:" + e.getMessage()); +// return AppletControllerUtil.appletWarning("查询优惠券列表失败:" + e.getMessage()); // } // } @@ -2626,20 +2687,20 @@ public AjaxResult getUserIntegralLogList(@RequestBody Map params // 2. 验证分页参数 Map pageValidation = PageUtil.validatePageParams(page, limit); if (!(Boolean) pageValidation.get("valid")) { - return error((String) pageValidation.get("message")); + 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 error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 4. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 5. 设置分页参数 @@ -2665,11 +2726,11 @@ public AjaxResult getUserIntegralLogList(@RequestBody Map params responseData.put("user", userData); responseData.put("msg", "OK"); - return success(responseData); + return AppletControllerUtil.appletSuccess(responseData); } catch (Exception e) { System.err.println("查询用户积分日志列表异常:" + e.getMessage()); - return error("查询积分日志列表失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询积分日志列表失败:" + e.getMessage()); } } @@ -2691,20 +2752,20 @@ public AjaxResult getUserIntegralOrderList(@RequestBody Map para // 2. 验证分页参数 Map pageValidation = PageUtil.validatePageParams(page, limit); if (!(Boolean) pageValidation.get("valid")) { - return error((String) pageValidation.get("message")); + 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 error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 4. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 5. 设置分页参数 @@ -2727,11 +2788,11 @@ public AjaxResult getUserIntegralOrderList(@RequestBody Map para Map responseData = AppletControllerUtil.buildPaginationResponse( pageInfo, formattedOrderList, "https://www.huafurenjia.cn/api/integral/user/order"); - return success(responseData); + return AppletControllerUtil.appletSuccess(responseData); } catch (Exception e) { System.err.println("查询用户积分商城订单列表异常:" + e.getMessage()); - return error("查询积分商城订单列表失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询积分商城订单列表失败:" + e.getMessage()); } } @@ -2747,42 +2808,42 @@ public AjaxResult getIntegralOrderInfo(@PathVariable("id") Long id, HttpServletR try { // 1. 参数验证 if (id == null || id <= 0) { - return error("订单ID无效"); + return AppletControllerUtil.appletWarning("订单ID无效"); } // 2. 验证用户登录状态 String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 3. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 4. 查询积分订单信息 IntegralOrder integralOrder = integralOrderService.selectIntegralOrderById(id); if (integralOrder == null) { - return error("订单不存在"); + return AppletControllerUtil.appletWarning("订单不存在"); } // 5. 验证订单归属权 if (!integralOrder.getUid().equals(user.getId())) { - return error("无权访问该订单信息"); + return AppletControllerUtil.appletWarning("无权访问该订单信息"); } // 6. 使用工具类构建订单详情数据 Map orderData = AppletControllerUtil.buildIntegralOrderDetail( integralOrder, integralProductService, integralOrderLogService); - return success(orderData); + return AppletControllerUtil.appletSuccess(orderData); } catch (Exception e) { System.err.println("查询积分订单详情异常:" + e.getMessage()); - return error("查询订单详情失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询订单详情失败:" + e.getMessage()); } } @@ -2828,11 +2889,11 @@ public AjaxResult getIntegralProductCateList(HttpServletRequest request) { resultList.add(cateData); } - return success(resultList); + return AppletControllerUtil.appletSuccess(resultList); } catch (Exception e) { System.err.println("查询积分商品分类列表异常:" + e.getMessage()); - return error("查询分类列表失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询分类列表失败:" + e.getMessage()); } } @@ -2892,7 +2953,7 @@ public AjaxResult getIntegralProductList(@RequestBody Map params // 2. 验证分页参数 Map pageValidation = PageUtil.validatePageParams(page, limit); if (!(Boolean) pageValidation.get("valid")) { - return error((String) pageValidation.get("message")); + return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); } // 3. 设置分页参数 @@ -2908,7 +2969,7 @@ public AjaxResult getIntegralProductList(@RequestBody Map params Long cateId = Long.parseLong(type.trim()); integralProductQuery.setCateId(cateId); } catch (NumberFormatException e) { - return error("分类参数格式错误"); + return AppletControllerUtil.appletWarning("分类参数格式错误"); } } @@ -2923,11 +2984,11 @@ public AjaxResult getIntegralProductList(@RequestBody Map params Map responseData = AppletControllerUtil.buildPaginationResponse( pageInfo, formattedProductList, "https://www.huafurenjia.cn/api/integral/product/lst"); - return success(responseData); + return AppletControllerUtil.appletSuccess(responseData); } catch (Exception e) { System.err.println("查询积分商品列表异常:" + e.getMessage()); - return error("查询积分商品列表失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询积分商品列表失败:" + e.getMessage()); } } @@ -2974,28 +3035,28 @@ public AjaxResult getIntegralProductInfo(@PathVariable("id") Long id, HttpServle try { // 1. 参数验证 if (id == null || id <= 0) { - return error("商品ID无效"); + return AppletControllerUtil.appletWarning("商品ID无效"); } // 2. 查询积分商品信息 IntegralProduct integralProduct = integralProductService.selectIntegralProductById(id); if (integralProduct == null) { - return error("商品不存在"); + return AppletControllerUtil.appletWarning("商品不存在"); } // 3. 验证商品状态(只返回启用状态的商品) if (integralProduct.getStatus() == null || integralProduct.getStatus() != 1) { - return error("商品已下架或不可用"); + return AppletControllerUtil.appletWarning("商品已下架或不可用"); } // 4. 使用工具类构建商品详情数据 Map productDetail = AppletControllerUtil.buildIntegralProductDetail(integralProduct); - return success(productDetail); + return AppletControllerUtil.appletSuccess(productDetail); } catch (Exception e) { System.err.println("查询积分商品详情异常:" + e.getMessage()); - return error("查询商品详情失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询商品详情失败:" + e.getMessage()); } } @@ -3038,13 +3099,13 @@ public AjaxResult getUserDefaultAddress(HttpServletRequest request) { String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 2. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 3. 首先查询用户的默认地址 @@ -3067,18 +3128,18 @@ public AjaxResult getUserDefaultAddress(HttpServletRequest request) { if (!allAddressList.isEmpty()) { targetAddress = allAddressList.get(0); } else { - return error("用户暂无收货地址"); + return AppletControllerUtil.appletWarning("用户暂无收货地址"); } } // 4. 转换为AddressApple格式并返回 AddressApple addressApple = AddressApple.fromUserAddress(targetAddress); - return success(addressApple); + return AppletControllerUtil.appletSuccess(addressApple); } catch (Exception e) { System.err.println("查询用户默认地址异常:" + e.getMessage()); - return error("查询默认地址失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询默认地址失败:" + e.getMessage()); } } @@ -3121,23 +3182,23 @@ public AjaxResult getUserNotificationStatus(HttpServletRequest request) { String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 2. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 3. 直接返回固定的消息模板配置数据 Map notificationStatus = AppletControllerUtil.buildMiniProgramNotificationStatus(user); - return success(notificationStatus); + return AppletControllerUtil.appletSuccess(notificationStatus); } catch (Exception e) { System.err.println("查询用户通知订阅状态异常:" + e.getMessage()); - return error("查询通知订阅状态失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询通知订阅状态失败:" + e.getMessage()); } } @@ -3165,19 +3226,19 @@ public AjaxResult subscribeNotification(@RequestBody Map params, String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 2. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 3. 获取模板ID列表 List tmplIds = (List) params.get("tmplIds"); if (tmplIds == null || tmplIds.isEmpty()) { - return error("模板ID列表不能为空"); + return AppletControllerUtil.appletWarning("模板ID列表不能为空"); } // 4. 验证模板ID的有效性 @@ -3188,7 +3249,7 @@ public AjaxResult subscribeNotification(@RequestBody Map params, for (String tmplId : tmplIds) { if (!validTemplateIds.contains(tmplId)) { - return error("无效的模板ID:" + tmplId); + return AppletControllerUtil.appletWarning("无效的模板ID:" + tmplId); } } @@ -3202,11 +3263,11 @@ public AjaxResult subscribeNotification(@RequestBody Map params, // 6. 这里可以将订阅状态保存到数据库 // 例如:userNotificationService.saveSubscribeStatus(user.getId(), tmplIds); - return success(subscribeResult); + return AppletControllerUtil.appletSuccess(subscribeResult); } catch (Exception e) { System.err.println("用户订阅消息异常:" + e.getMessage()); - return error("订阅消息失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("订阅消息失败:" + e.getMessage()); } } @@ -3279,47 +3340,47 @@ public AjaxResult exchangeIntegralProduct(@RequestBody Map param String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 2. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 3. 验证请求参数 String validationResult = AppletControllerUtil.validateIntegralExchangeParams(params); if (validationResult != null) { - return error(validationResult); + return AppletControllerUtil.appletWarning(validationResult); } // 4. 获取并验证积分商品信息 Long productId = Long.valueOf(params.get("id").toString()); IntegralProduct product = integralProductService.selectIntegralProductById(productId); if (product == null) { - return error("积分商品不存在"); + return AppletControllerUtil.appletWarning("积分商品不存在"); } if (product.getStatus() == null || product.getStatus() != 1) { - return error("积分商品已下架或不可用"); + return AppletControllerUtil.appletWarning("积分商品已下架或不可用"); } // 5. 获取并验证收货地址信息 Long addressId = Long.valueOf(params.get("address_id").toString()); UserAddress address = userAddressService.selectUserAddressById(addressId); if (address == null) { - return error("收货地址不存在"); + return AppletControllerUtil.appletWarning("收货地址不存在"); } if (!address.getUid().equals(user.getId())) { - return error("无权使用该收货地址"); + return AppletControllerUtil.appletWarning("无权使用该收货地址"); } // 6. 计算所需积分并验证库存 Integer num = Integer.valueOf(params.get("num").toString()); if (product.getStock() != null && product.getStock() < num) { - return error("商品库存不足"); + return AppletControllerUtil.appletWarning("商品库存不足"); } Long totalIntegral = product.getNum() * num; @@ -3335,7 +3396,7 @@ public AjaxResult exchangeIntegralProduct(@RequestBody Map param int orderResult = integralOrderService.insertIntegralOrder(order); if (orderResult <= 0) { - return error("订单创建失败"); + return AppletControllerUtil.appletWarning("订单创建失败"); } // 9. 扣除用户积分 @@ -3345,7 +3406,7 @@ public AjaxResult exchangeIntegralProduct(@RequestBody Map param int updateResult = usersService.updateUsers(updateUser); if (updateResult <= 0) { - return error("扣除积分失败"); + return AppletControllerUtil.appletWarning("扣除积分失败"); } // 10. 记录积分变动日志 @@ -4316,51 +4377,51 @@ public AjaxResult getMyCouponCount(HttpServletRequest request) { return AppletControllerUtil.appletWarning("用户信息获取失败"); } - // 3. 查询用户的所有优惠券 - CouponUser couponUserQuery = new CouponUser(); - couponUserQuery.setUid(user.getId()); - List userCouponList = couponUserService.selectCouponUserList(couponUserQuery); - - // 4. 统计各种状态的优惠券数量 - int unusedCount = 0; // 未使用数量 (one) - int usedCount = 0; // 已使用数量 (two) - int expiredCount = 0; // 已过期数量 (three) - - long currentTime = System.currentTimeMillis() / 1000; // 当前时间戳(秒) - - for (CouponUser couponUser : userCouponList) { - // 检查是否已使用 - if (couponUser.getStatus() != null && couponUser.getStatus() == 2L) { - usedCount++; - } else { - // 检查是否已过期 - if (isExpired(couponUser, currentTime)) { - expiredCount++; - } else { - // 未使用且未过期 - unusedCount++; - } - } - } - - // 5. 查询可领取的优惠券数量 - Coupons couponsQuery = new Coupons(); - couponsQuery.setStatus(1L); // 启用状态 - List availableCoupons = couponsService.selectCouponsList(couponsQuery); - - int availableToReceiveCount = 0; // 待领取数量 (four) - for (Coupons coupon : availableCoupons) { - if (isCouponAvailableToReceive(coupon, user.getId(), currentTime)) { - availableToReceiveCount++; - } - } +// // 3. 查询用户的所有优惠券 +// CouponUser couponUserQuery = new CouponUser(); +// couponUserQuery.setUid(user.getId()); +// List userCouponList = couponUserService.selectCouponUserList(couponUserQuery); +// +// // 4. 统计各种状态的优惠券数量 +// int unusedCount = 0; // 未使用数量 (one) +// int usedCount = 0; // 已使用数量 (two) +// int expiredCount = 0; // 已过期数量 (three) +// +// long currentTime = System.currentTimeMillis() / 1000; // 当前时间戳(秒) +// +// for (CouponUser couponUser : userCouponList) { +// // 检查是否已使用 +// if (couponUser.getStatus() != null && couponUser.getStatus() == 2L) { +// usedCount++; +// } else { +// // 检查是否已过期 +// if (isExpired(couponUser, currentTime)) { +// expiredCount++; +// } else { +// // 未使用且未过期 +// unusedCount++; +// } +// } +// } +// +// // 5. 查询可领取的优惠券数量 +// Coupons couponsQuery = new Coupons(); +// couponsQuery.setStatus(1L); // 启用状态 +// List availableCoupons = couponsService.selectCouponsList(couponsQuery); +// +// int availableToReceiveCount = 0; // 待领取数量 (four) +// for (Coupons coupon : availableCoupons) { +// if (isCouponAvailableToReceive(coupon, user.getId(), currentTime)) { +// availableToReceiveCount++; +// } +// } // 6. 构建返回数据 Map countData = new HashMap<>(); - countData.put("one", unusedCount); // 未使用数量 - countData.put("two", usedCount); // 已使用数量 - countData.put("three", expiredCount); // 已过期数量 - countData.put("four", availableToReceiveCount); // 待领取数量 + countData.put("one", couponUserService.selectCountCouponsByUid(user.getId(), 1L)); // 未使用数量 + countData.put("two",couponUserService.selectCountCouponsByUid(user.getId(), 3L)); // 已使用数量 + countData.put("three",couponUserService.selectCountCouponsByUid(user.getId(), 2L)); // 已过期数量 + countData.put("four", CouponUtil.iscoupon(user.getId(), couponsService, couponUserService).size()); // 待领取数量 return AppletControllerUtil.appletSuccess(countData); @@ -4524,18 +4585,18 @@ public AjaxResult createServiceOrder(@RequestBody Map params, Ht String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 2. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 3. 验证订单参数 if (params == null || params.isEmpty()) { - return error("订单参数不能为空"); + return AppletControllerUtil.appletWarning("订单参数不能为空"); } // 4. 生成主订单号 @@ -4556,7 +4617,7 @@ public AjaxResult createServiceOrder(@RequestBody Map params, Ht // 验证必要参数 if (orderParams.get("product_id") == null || orderParams.get("address_id") == null) { - return error("商品ID或地址ID不能为空"); + return AppletControllerUtil.appletWarning("商品ID或地址ID不能为空"); } Long productId = Long.valueOf(orderParams.get("product_id").toString()); @@ -4569,13 +4630,13 @@ public AjaxResult createServiceOrder(@RequestBody Map params, Ht // 查询商品信息 ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); if (serviceGoods == null) { - return error("商品ID " + productId + " 不存在"); + return AppletControllerUtil.appletWarning("商品ID " + productId + " 不存在"); } // 查询地址信息(只需要查询一次,假设所有订单使用相同地址) UserAddress userAddress = userAddressService.selectUserAddressById(addressId); if (userAddress == null) { - return error("地址不存在"); + return AppletControllerUtil.appletWarning("地址不存在"); } // 计算单个订单金额 @@ -4617,6 +4678,7 @@ public AjaxResult createServiceOrder(@RequestBody Map params, Ht goodsOrder.setGoodPrice(serviceGoods.getPrice()); goodsOrder.setPayPrice(itemPrice); goodsOrder.setDeduction(DeductionPrice); + goodsOrder.setCouponId(Long.valueOf(coupon_id)); goodsOrder.setStatus(1L); // 待支付状态 goodsOrder.setAddressId(addressId); goodsOrder.setSku(sku); @@ -4624,7 +4686,7 @@ public AjaxResult createServiceOrder(@RequestBody Map params, Ht // 保存商品订单 int insertResult = goodsOrderService.insertGoodsOrder(goodsOrder); if (insertResult <= 0) { - return error("商品订单创建失败,请稍后重试"); + return AppletControllerUtil.appletWarning("商品订单创建失败,请稍后重试"); } // 添加到订单列表 @@ -4685,7 +4747,7 @@ public AjaxResult createServiceOrder(@RequestBody Map params, Ht // 保存服务订单 int result = orderService.insertOrder(order); if (result <= 0) { - return error("服务订单创建失败,请稍后重试"); + return AppletControllerUtil.appletWarning("服务订单创建失败,请稍后重试"); } // 添加订单日志 @@ -4751,7 +4813,7 @@ public AjaxResult createServiceOrder(@RequestBody Map params, Ht if (hasGoodsOrder && totalAmount.compareTo(BigDecimal.ZERO) > 0) { // 使用工具类简化微信支付参数组装 - Map payResult = wechatPayUtil.createBatchOrderAndPay(user.getOpenid(), mainOrderId, new BigDecimal(0.01), orderList.size(), "https://2d684c7a.r5.cpolar.xyz/api/goods/pay/notify"); + Map payResult = wechatPayUtil.createBatchOrderAndPay(user.getOpenid(), mainOrderId, new BigDecimal(0.01), orderList.size(), "https://7ce20b15.r5.cpolar.xyz/api/goods/pay/notify"); //Map payResult = wechatPayUtil.createBatchOrderAndPay(user.getOpenid(), mainOrderId, totalAmount, orderList.size()); if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { Map responseData = new HashMap<>(); @@ -4764,7 +4826,7 @@ public AjaxResult createServiceOrder(@RequestBody Map params, Ht return AppletControllerUtil.appletSuccess(responseData); } else { String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; - return error("支付下单失败:" + errorMsg); + return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); } } else { // 没有商品订单,只有服务订单,直接返回成功 @@ -4777,7 +4839,7 @@ public AjaxResult createServiceOrder(@RequestBody Map params, Ht } catch (Exception e) { logger.error("创建订单异常:", e); - return error("创建订单失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("创建订单失败:" + e.getMessage()); } } @@ -4790,18 +4852,18 @@ public AjaxResult apiServiceOrderPayTotalPprice(@RequestBody Map String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 2. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 3. 验证必要参数 if (params == null || params.get("order_id") == null || params.get("worker_id") == null) { - return error("参数不能为空"); + return AppletControllerUtil.appletWarning("参数不能为空"); } Long worker_id = Long.valueOf(params.get("worker_id").toString()); String order_id = params.get("order_id").toString(); @@ -4819,15 +4881,40 @@ public AjaxResult apiServiceOrderPayTotalPprice(@RequestBody Map log = logList.get(0); } if (log == null) { - return error("未找到订单日志"); + return AppletControllerUtil.appletWarning("未找到订单日志"); } +if (params.get("coupon_id")!= null) { + String coupon_id = params.get("coupon_id").toString(); + if (coupon_id != null && !coupon_id.isEmpty()) { + CouponUser couponUser = couponUserService.selectCouponUserById(Long.valueOf(coupon_id)); + if (couponUser == null && couponUser.getStatus() != 1) { + return AppletControllerUtil.appletWarning("优惠券已被使用,或优惠券不存在"); + } + OrderLog orderLogQery = new OrderLog(); + orderLogQery.setOrderId(order.getOrderId()); + orderLogQery.setType(new BigDecimal(5)); + orderLogQery.setWorkerId(worker_id); + OrderLog orderLognew = orderLogService.selectOneByOidTypeWorkerIdPaid(orderLogQery); + if (orderLognew != null) { + orderLognew.setCouponId(couponUser.getCouponId()); + orderLognew.setDeduction(new BigDecimal(couponUser.getCouponPrice())); + orderLogService.updateOrderLog(orderLognew); + order.setCouponId(couponUser.getCouponId()); + order.setDeduction(new BigDecimal(couponUser.getCouponPrice())); + orderService.updateOrder(order); + } + + + } +} + Map payResult = wechatPayUtil.createBatchOrderAndPay( user.getOpenid(), String.valueOf(order_id), new BigDecimal(0.01), 1, - "https://2d684c7a.r5.cpolar.xyz/api/order/amount/pay/notify"); + "https://7ce20b15.r5.cpolar.xyz/api/order/amount/pay/notify"); if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { Map responseData = new HashMap<>(); responseData.put("mainOrderId", order_id); @@ -4839,7 +4926,7 @@ public AjaxResult apiServiceOrderPayTotalPprice(@RequestBody Map return AppletControllerUtil.appletSuccess(responseData); } else { String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; - return error("支付下单失败:" + errorMsg); + return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); } @@ -4855,18 +4942,18 @@ public AjaxResult apiServiceOrderPayFee(@RequestBody Map params, String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 2. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 3. 验证必要参数 if (params == null || params.get("id") == null) { - return error("参数不能为空"); + return AppletControllerUtil.appletWarning("参数不能为空"); } Long orderId = Long.valueOf(params.get("id").toString()); OrderLog orderLog = orderLogService.selectOrderLogById(orderId); @@ -4877,7 +4964,7 @@ public AjaxResult apiServiceOrderPayFee(@RequestBody Map params, String.valueOf(orderLog.getId()), new BigDecimal(0.01), 1, - "https://2d684c7a.r5.cpolar.xyz/api/door/fee/pay/notify"); + "https://7ce20b15.r5.cpolar.xyz/api/door/fee/pay/notify"); if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { Map responseData = new HashMap<>(); responseData.put("mainOrderId", String.valueOf(orderLog.getId())); @@ -4889,13 +4976,13 @@ public AjaxResult apiServiceOrderPayFee(@RequestBody Map params, return AppletControllerUtil.appletSuccess(responseData); } else { String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; - return error("支付下单失败:" + errorMsg); + return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); } } - return error("支付失败"); + return AppletControllerUtil.appletWarning("支付失败"); } @@ -4909,18 +4996,18 @@ public AjaxResult apiServiceOrderPaydeposit(@RequestBody Map par String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 2. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 3. 验证必要参数 if (params == null || params.get("id") == null) { - return error("参数不能为空"); + return AppletControllerUtil.appletWarning("参数不能为空"); } Long orderId = Long.valueOf(params.get("id").toString()); OrderLog orderLog = orderLogService.selectOrderLogById(orderId); @@ -4931,7 +5018,7 @@ public AjaxResult apiServiceOrderPaydeposit(@RequestBody Map par String.valueOf(orderLog.getId()), new BigDecimal(0.01), 1, - "https://2d684c7a.r5.cpolar.xyz/api/deposit/pay/notify"); + "https://7ce20b15.r5.cpolar.xyz/api/deposit/pay/notify"); if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { Map responseData = new HashMap<>(); responseData.put("mainOrderId", String.valueOf(orderLog.getId())); @@ -4943,13 +5030,13 @@ public AjaxResult apiServiceOrderPaydeposit(@RequestBody Map par return AppletControllerUtil.appletSuccess(responseData); } else { String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; - return error("支付下单失败:" + errorMsg); + return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); } } - return error("支付失败"); + return AppletControllerUtil.appletWarning("支付失败"); } @@ -4962,18 +5049,18 @@ public AjaxResult apiGoodsOrderOncePay(@RequestBody Map params, String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 2. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 3. 验证必要参数 if (params == null || params.get("id") == null) { - return error("参数不能为空"); + return AppletControllerUtil.appletWarning("参数不能为空"); } Long orderId = Long.valueOf(params.get("id").toString()); GoodsOrder goodsOrder = goodsOrderService.selectGoodsOrderById(orderId); @@ -4985,7 +5072,7 @@ public AjaxResult apiGoodsOrderOncePay(@RequestBody Map params, //修改成功就开始走支付功能 if (flg > 0) { goodsOrder.setMainOrderId(goodsOrder.getMainOrderId()); - Map payResult = wechatPayUtil.createBatchOrderAndPay(user.getOpenid(), goodsOrder.getMainOrderId(), new BigDecimal(0.01), 1, "https://2d684c7a.r5.cpolar.xyz/api/goods/pay/notify"); + Map payResult = wechatPayUtil.createBatchOrderAndPay(user.getOpenid(), goodsOrder.getMainOrderId(), new BigDecimal(0.01), 1, "https://7ce20b15.r5.cpolar.xyz/api/goods/pay/notify"); if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { Map responseData = new HashMap<>(); responseData.put("mainOrderId", goodsOrder.getMainOrderId()); @@ -4997,14 +5084,14 @@ public AjaxResult apiGoodsOrderOncePay(@RequestBody Map params, return AppletControllerUtil.appletSuccess(responseData); } else { String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; - return error("支付下单失败:" + errorMsg); + return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); } } } - return error("支付失败"); + return AppletControllerUtil.appletWarning("支付失败"); } /** @@ -5032,18 +5119,18 @@ public AjaxResult cancelServiceOrder(@RequestBody Map params, Ht String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return error("用户未登录或token无效"); + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } // 2. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { - return error("用户信息获取失败"); + return AppletControllerUtil.appletWarning("用户信息获取失败"); } // 3. 验证必要参数 if (params == null || params.get("id") == null || params.get("content") == null) { - return error("参数不能为空"); + return AppletControllerUtil.appletWarning("参数不能为空"); } Long orderId = Long.valueOf(params.get("id").toString()); String cancelReason = params.get("content").toString(); @@ -5055,13 +5142,13 @@ public AjaxResult cancelServiceOrder(@RequestBody Map params, Ht List orders = orderService.selectOrderList(orderQuery); if (orders == null || orders.isEmpty()) { - return error("订单不存在"); + return AppletControllerUtil.appletWarning("订单不存在"); } Order order = orders.get(0); // 5. 验证订单状态是否可以取消 if (order.getStatus() != 1L) { - return error("当前订单状态不可取消"); + return AppletControllerUtil.appletWarning("当前订单状态不可取消"); } // 6. 更新订单状态为已取消(5) @@ -5082,13 +5169,13 @@ public AjaxResult cancelServiceOrder(@RequestBody Map params, Ht orderLog.setContent(jsonObject.toString()); orderLogService.insertOrderLog(orderLog); - return success("取消成功"); + return AppletControllerUtil.appletSuccess("取消成功"); } else { - return error("取消失败,请稍后重试"); + return AppletControllerUtil.appletWarning("取消失败,请稍后重试"); } } catch (Exception e) { - return error("取消失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("取消失败:" + e.getMessage()); } } @@ -5532,13 +5619,13 @@ public AjaxResult getOrderPayLastInfo(@RequestBody Map params) { try { String orderId = (String) params.get("order_id"); if (StringUtils.isEmpty(orderId)) { - return error("订单号不能为空"); + return AppletControllerUtil.appletWarning("订单号不能为空"); } // 1. 查询订单 Order order = orderService.selectOrderByOrderId(orderId); if (order == null) { - return error("订单不存在"); + return AppletControllerUtil.appletWarning("订单不存在"); } // 2. 查询订单日志(取type=5评估报价,或最新一条) @@ -5554,7 +5641,7 @@ public AjaxResult getOrderPayLastInfo(@RequestBody Map params) { log = logList.get(0); } if (log == null) { - return error("未找到订单日志"); + return AppletControllerUtil.appletWarning("未找到订单日志"); } // 3. 组装content字段 @@ -5595,9 +5682,9 @@ public AjaxResult getOrderPayLastInfo(@RequestBody Map params) { data.put("updated_at", log.getUpdatedAt() != null ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(log.getUpdatedAt()) : null); data.put("deleted_at", log.getDeletedAt()); - return success(data); + return AppletControllerUtil.appletSuccess(data); } catch (Exception e) { - return error("查询失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询失败:" + e.getMessage()); } } @@ -5713,6 +5800,71 @@ public AjaxResult getWorkerUserList(@RequestBody Map params) { } } +/** + * 用户申请师傅接口 + */ +@PostMapping("/api/form/apply/worker") +public AjaxResult applyWorker(@RequestBody Map params, HttpServletRequest request) { + try { + // 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 构建WorkerApply对象 + WorkerApply apply = new WorkerApply(); + apply.setUid(user.getId()); + apply.setName((String) params.getOrDefault("name", "")); + apply.setPhone((String) params.getOrDefault("phone", "")); + apply.setAddress((String) params.getOrDefault("address", "")); + apply.setCardNo((String) params.getOrDefault("card_no", "")); + // city_pid + Object cityPidObj = params.get("city_pid"); + if (cityPidObj != null) { + try { + apply.setCityPid(Long.valueOf(cityPidObj.toString())); + } catch (Exception ignore) {} + } + // city_ids + Object cityIdsObj = params.get("city_ids"); + if (cityIdsObj instanceof List) { + List cityIdsList = (List) cityIdsObj; + apply.setCityIds(cityIdsList.toString().replace(" ","")); // 存字符串如[5,7,10,11] + } else if (cityIdsObj != null) { + apply.setCityIds(cityIdsObj.toString()); + } + // skill_id + Object skillIdObj = params.get("skill_id"); + if (skillIdObj instanceof List) { + List skillIdList = (List) skillIdObj; + apply.setSkillId(skillIdList.toString().replace(" ","")); + } else if (skillIdObj != null) { + apply.setSkillId(skillIdObj.toString()); + } + // 图片相关 + apply.setSkill((String) params.getOrDefault("skill", "")); + apply.setCriminal((String) params.getOrDefault("criminal", "")); + apply.setDrive((String) params.getOrDefault("drive", "")); + apply.setEducation((String) params.getOrDefault("education", "")); + apply.setHealth((String) params.getOrDefault("health", "")); + apply.setImage((String) params.getOrDefault("image", "")); + // 其他字段可按需补充 + int result = workerApplyService.insertWorkerApply(apply); + if (result > 0) { + return AppletControllerUtil.appletSuccess("申请已提交"); + } else { + return AppletControllerUtil.appletWarning("申请提交失败,请稍后重试"); + } + } catch (Exception e) { + return AppletControllerUtil.appletError("申请失败:" + e.getMessage()); + } +} + /** * 师傅转单接口 * @@ -6401,10 +6553,10 @@ public AjaxResult workerStartDoor(@PathVariable("id") Long id, HttpServletReques return AppletControllerUtil.appletWarning("您不是该订单的师傅"); } // if (order.getStatus() == null || order.getStatus() != 2L) { -// return error("订单状态不正确"); +// return AppletControllerUtil.appletWarning("订单状态不正确"); // } // if (order.getJsonStatus() == null || order.getJsonStatus() != 3) { -// return error("订单进度不正确"); +// return AppletControllerUtil.appletWarning("订单进度不正确"); // } order.setJsonStatus(4); // 出发上门 @@ -6715,6 +6867,20 @@ public AjaxResult workerEstimate(@RequestBody Map params, HttpSe } } } + BigDecimal reductionPrice = BigDecimal.ZERO; + String reduction = params.get("reduction").toString(); + if (reduction != null && !reduction.trim().isEmpty()) { + reductionPrice = new BigDecimal(reduction); + totalPrice = totalPrice.subtract(reductionPrice); + } + +// BigDecimal depositMoney = BigDecimal.ZERO; +// String deposit = params.get("price").toString(); +// if (deposit != null && !deposit.trim().isEmpty()) { +// depositMoney= new BigDecimal(deposit); +// } + + // 2. 组装新json Map resultJson = new LinkedHashMap<>(); // project @@ -6722,8 +6888,22 @@ public AjaxResult workerEstimate(@RequestBody Map params, HttpSe project.put("name", "项目费用"); project.put("price", totalPrice); resultJson.put("project", project); + Map reductionproject = new LinkedHashMap<>(); + reductionproject.put("name", "优惠金额"); + reductionproject.put("price", params.get("reduction")); + resultJson.put("reduction", reductionproject); + Map depositproject = new LinkedHashMap<>(); + depositproject.put("name", "定金"); + depositproject.put("price", params.get("price")); + resultJson.put("deposit", depositproject); +// // project +// Map project = new LinkedHashMap<>(); +// project.put("name", "项目费用"); +// project.put("price", totalPrice); +// resultJson.put("project", project); // basic resultJson.put("basic", params.get("basic")); + // craft List> craftListNew = new ArrayList<>(); if (craftList != null) { @@ -6785,15 +6965,18 @@ public AjaxResult workerEstimate(@RequestBody Map params, HttpSe log.setDeposit(new BigDecimal(params.get("price").toString())); log.setDepPaid(1); log.setDepLogId(GenerateCustomCode.generCreateOrder("RED")); + }else { + log.setDeposit(BigDecimal.ZERO); } - log.setPrice(totalPrice); + log.setPrice(totalPrice.add(reductionPrice)); log.setPaid(1l); if (params.get("reduction") != null) { log.setReductionPrice(new BigDecimal(params.get("reduction").toString())); } else { log.setReductionPrice(BigDecimal.ZERO); } - log.setWorkerCost(ServiceAllPrice); + log.setWorkerCost(ServiceAllPrice.subtract(reductionPrice)); + //log.set log.setLogId(GenerateCustomCode.generCreateOrder("EST")); log.setWorkerLogId(order.getWorkerId()); log.setWorkerId(order.getWorkerId()); @@ -7382,16 +7565,16 @@ public AjaxResult serviceCursor(@RequestBody Map params, HttpSer try { // 1. 参数验证 if (params == null) { - return error("请求参数不能为空"); + return AppletControllerUtil.appletWarning("请求参数不能为空"); } // 验证必要参数 if (params.get("product_id") == null) { - return error("商品ID不能为空"); + return AppletControllerUtil.appletWarning("商品ID不能为空"); } if (params.get("num") == null) { - return error("商品数量不能为空"); + return AppletControllerUtil.appletWarning("商品数量不能为空"); } // 2. 解析参数 @@ -7403,32 +7586,32 @@ public AjaxResult serviceCursor(@RequestBody Map params, HttpSer productId = Long.valueOf(params.get("product_id").toString()); num = Integer.valueOf(params.get("num").toString()); } catch (NumberFormatException e) { - return error("参数格式错误"); + return AppletControllerUtil.appletWarning("参数格式错误"); } // 3. 验证参数有效性 if (productId <= 0) { - return error("商品ID无效"); + return AppletControllerUtil.appletWarning("商品ID无效"); } if (num <= 0) { - return error("商品数量必须大于0"); + return AppletControllerUtil.appletWarning("商品数量必须大于0"); } // 4. 验证商品是否存在 ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); if (serviceGoods == null) { - return error("商品不存在"); + return AppletControllerUtil.appletWarning("商品不存在"); } // 5. 验证商品状态 if (serviceGoods.getStatus() == null || !"1".equals(serviceGoods.getStatus())) { - return error("商品已下架或不可购买"); + return AppletControllerUtil.appletWarning("商品已下架或不可购买"); } // 6. 验证库存(如果有库存管理) if (serviceGoods.getStock() != null && serviceGoods.getStock() < num) { - return error("商品库存不足"); + return AppletControllerUtil.appletWarning("商品库存不足"); } // 7. 解析并验证SKU信息(如果有的话) @@ -7442,7 +7625,7 @@ public AjaxResult serviceCursor(@RequestBody Map params, HttpSer try { int skuStock = Integer.parseInt(stockStr); if (skuStock < num) { - return error("SKU库存不足"); + return AppletControllerUtil.appletWarning("SKU库存不足"); } } catch (NumberFormatException e) { // SKU库存格式错误,忽略验证 @@ -7493,18 +7676,95 @@ public AjaxResult serviceCursor(@RequestBody Map params, HttpSer if (result > 0) { // 10. 返回商品ID - return success(goodsOrderCursor.getId()); + return AppletControllerUtil.appletSuccess(goodsOrderCursor.getId()); } else { - return error("数据保存失败"); + return AppletControllerUtil.appletWarning("数据保存失败"); } } catch (Exception e) { System.err.println("商品订单游标接口异常:" + e.getMessage()); - return error("操作失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("操作失败:" + e.getMessage()); } } + + +/** + * 云信交互式小号呼叫结果推送结果推送回调接口 + * 用于接收云信平台推送的交互式语音通知呼叫结果。 + * + * @return 必须返回{"resultCode":"200"},否则云信认为推送失败 + */ + @PostMapping("api/worker/withdraw") + public Map withdraw(@RequestBody Map params, HttpServletRequest request) { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + String orderId =GenerateCustomCode.generCreateOrder("TX"); + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + String money = params.get("money").toString(); + + if (money == null || money.trim().isEmpty()) { + return AppletControllerUtil.appletWarning("提现金额不能为空"); + } + BigDecimal moneyBigDecimal = new BigDecimal(money); + if (moneyBigDecimal.compareTo(BigDecimal.ZERO) <= 0) { + return AppletControllerUtil.appletWarning("提现金额必须大于0"); + } + if (moneyBigDecimal.compareTo(user.getCommission()) > 0) { + return AppletControllerUtil.appletWarning("提现金额不能大于账户余额"); + } + if (moneyBigDecimal.compareTo(new BigDecimal("2000")) > 0) { + return AppletControllerUtil.appletWarning("提现金额不能大于2000"); + } + //--------------------------预留提现的接口实现核心逻辑开始-------------------------------- + //------------------------------------结束-------------------------------- + WechatTransfer wechatTransfer = new WechatTransfer(); + wechatTransfer.setUid(user.getId()); + wechatTransfer.setMoney(moneyBigDecimal); + wechatTransfer.setUname(user.getName()); + wechatTransfer.setOrderId(orderId); + wechatTransfer.setStatus(1L); + wechatTransfer.setPaid(0L); + wechatTransfer.setOpenid(user.getOpenid()); + int flg= wechatTransferService.insertWechatTransfer(wechatTransfer); + if(flg>0){ + //减少师傅提现的余额 + user.setCommission(user.getCommission().subtract(moneyBigDecimal)); + //增加师傅的累计提现金额 + user.setPropose(user.getPropose().add(moneyBigDecimal)); + usersService.updateUsers(user); + } + + + + +// Map paramsMoney = new HashMap<>(); +// +// paramsMoney.put("nonce_str", GenerateCustomCode.generCreateOrder("VX")); +// paramsMoney.put("partner_trade_no", "T" + System.currentTimeMillis()); +// paramsMoney.put("partnerTradeNo", "T" + System.currentTimeMillis()); +// paramsMoney.put("openid", "oHTYB7ctO6k4ICmy73HnU0aNRZIo"); +// paramsMoney.put("check_name", "张潘"); +// paramsMoney.put("amount", "1"); +// paramsMoney.put("desc", "提现到零钱"); +// +// WechatPayUtil wechatApiUtil = new WechatPayUtil(); +// wechatApiUtil.transferToUser(paramsMoney); + + Map resp = new java.util.HashMap<>(); + resp.put("resultCode", "200"); + return resp; + } + /** * 获取商品订单临时信息 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/WorkerApplyController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/WorkerApplyController.java index 223ba45..6720b2c 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/WorkerApplyController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/WorkerApplyController.java @@ -1,10 +1,15 @@ package com.ruoyi.system.controller; +import java.math.BigDecimal; import java.util.List; +import java.util.Map; import javax.servlet.http.HttpServletResponse; +import com.ruoyi.system.ControllerUtil.WorkerApplyUtil; import com.ruoyi.system.domain.Users; +import com.ruoyi.system.domain.WorkerLevel; import com.ruoyi.system.service.IUsersService; +import com.ruoyi.system.service.IWorkerLevelService; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -38,6 +43,9 @@ public class WorkerApplyController extends BaseController private IWorkerApplyService workerApplyService; @Autowired private IUsersService usersService; + + @Autowired + private IWorkerLevelService workerLevelService; /** * 查询师傅申请记录列表 */ @@ -97,8 +105,66 @@ for(WorkerApply data:list){ @PreAuthorize("@ss.hasPermi('system:WorkerApply:edit')") @Log(title = "师傅申请记录", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody WorkerApply workerApply) - { + public AjaxResult edit(@RequestBody WorkerApply workerApply) throws Exception { + WorkerApply oldworkerApply=workerApplyService.selectWorkerApplyById(workerApply.getId()); + + if (oldworkerApply.getStatus()==1){ + return error("该条数据已被处理为师傅,不允许重复提交"); + } + if (workerApply.getImage()==null){ + return error("请上传电子照片"); + } + if (workerApply.getCardNo()==null){ + return error("身份证号不能为空"); + } + if (workerApply.getName()==null){ + return error("真是姓名不能为空"); + } + if (workerApply.getPhone()==null){ + return error("手机号码不能为空"); + } + + //同意师傅申请 + if (workerApply.getStatus()==1){ + Users users = usersService.selectUsersById(workerApply.getUid()); + //查询最低的师傅级别进行赋值 + WorkerLevel workerLevel = workerLevelService.selectWorkerLevelByLevel(1L); + //工号 + int jobnumber=0; + Users usersMax =usersService.selectUsersIsMaxNumber() ; + if (usersMax!=null){ + jobnumber=usersMax.getJobNumber()+1; + } + //已经是师傅了,就不用处理 + if(!users.getType().equals("2")){ + users.setType("2"); + users.setCommission(new BigDecimal("0.00")); + users.setTotalComm(new BigDecimal("0.00")); + users.setMargin(new BigDecimal("0.00")); + users.setProhibitTimeNum(0); + users.setIsWork(1); + users.setLevel(Math.toIntExact(workerLevel.getLevel())); + users.setJobNumber(jobnumber); + users.setServiceCityIds(workerApply.getCityIds()); + users.setSkillIds(workerApply.getSkillId()); + users.setServiceCityPid(workerApply.getCityPid()); + usersService.updateUsers(users); + Map verifyResult =WorkerApplyUtil.virtualVerify(workerApply.getImage(), + workerApply.getPhone(), + workerApply.getCardNo(), + workerApply.getName(), + "",//回调地址,暂时不用写,等需要的时候再去写吧 + "https://img.huafurenjia.cn/",//七牛云的地址 + "https://101.37.133.245:11008/voice/1.0.0/");//"实名API地址" + System.out.println("34344334电子照片" + verifyResult.get("message")); + System.out.println("34344334电子照片" + verifyResult.get("result")); + if (!"000000".equals(verifyResult.get("result"))) { + System.out.println("电子照片" + verifyResult.get("message")); + } + } + + + } return toAjax(workerApplyService.updateWorkerApply(workerApply)); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/CouponUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/CouponUtil.java new file mode 100644 index 0000000..bb3ef31 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/CouponUtil.java @@ -0,0 +1,76 @@ +package com.ruoyi.system.ControllerUtil; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.ruoyi.system.service.ICouponUserService; +import com.ruoyi.system.service.ICouponsService; +import com.ruoyi.system.domain.Coupons; +import com.ruoyi.system.domain.CouponUser; + +public class CouponUtil { + public static List iscoupon(Long uid, ICouponsService couponsService, ICouponUserService couponUserService){ + Map map=new HashMap<>(); + List canReceiveList = new java.util.ArrayList<>(); + long now = System.currentTimeMillis() / 1000; // 当前时间戳(秒) + // 1. 查询所有可领取的手动领取优惠券(type=2,status=1) + Coupons couponsQuery = new Coupons(); + couponsQuery.setStatus(1L); // 启用 + couponsQuery.setType(2L); // 手动领取 + List allCanReceive = couponsService.selectCouponsList(couponsQuery); + // 2. 查询用户已领取的优惠券 + CouponUser userQuery = new CouponUser(); + userQuery.setUid(uid); + List userCouponList = couponUserService.selectCouponUserList(userQuery); + java.util.Set receivedCouponIds = new java.util.HashSet<>(); + for (CouponUser cu : userCouponList) { + if (cu.getCouponId() != null) { + receivedCouponIds.add(cu.getCouponId()); + } + } + // 3. 过滤掉已领取的和已过期的 + for (Coupons coupon : allCanReceive) { + // 计算过期时间 + long expireTime = (coupon.getEndTime() != null ? coupon.getEndTime() : 0L) + (coupon.getCouponTime() != null ? coupon.getCouponTime() * 24 * 60 * 60 : 0L); + if (expireTime > 0 && expireTime < now) { + // 已过期,设置为关闭 + coupon.setStatus(0L); + couponsService.updateCoupons(coupon); + continue; + } + if (coupon.getCount() != null && coupon.getCount() > 0 && !receivedCouponIds.contains(coupon.getId())) { + canReceiveList.add(coupon); + } + } + // 4. 判断是否已领取过新人券(假设新人券type=3或有特殊标记) + Coupons newUserCouponQuery = new Coupons(); + newUserCouponQuery.setStatus(1L); + newUserCouponQuery.setType(3L); // 新人券类型 + List newUserCoupons = couponsService.selectCouponsList(newUserCouponQuery); + boolean hasNewUserCoupon = false; + for (CouponUser cu : userCouponList) { + for (Coupons nc : newUserCoupons) { + if (cu.getCouponId() != null && cu.getCouponId().equals(nc.getId())) { + hasNewUserCoupon = true; + break; + } + } + if (hasNewUserCoupon) break; + } + // 5. 如果没领过新人券,把新人券加进来(也要判断新人券是否过期) + for (Coupons nc : newUserCoupons) { + long expireTime = (nc.getEndTime() != null ? nc.getEndTime() : 0L) + (nc.getCouponTime() != null ? nc.getCouponTime() * 24 * 60 * 60 : 0L); + if (expireTime > 0 && expireTime < now) { + nc.setStatus(0L); + couponsService.updateCoupons(nc); + continue; + } + if (!hasNewUserCoupon) { + canReceiveList.add(nc); + } + } + return canReceiveList; + + } +} 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 12b1751..07e8e30 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 @@ -1,6 +1,9 @@ package com.ruoyi.system.ControllerUtil; import com.alibaba.fastjson2.JSONObject; +import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.system.config.QiniuConfig; +import com.ruoyi.system.config.WechatConfig; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -12,11 +15,11 @@ import org.springframework.stereotype.Component; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import javax.servlet.http.HttpServletRequest; -import java.io.BufferedReader; -import java.io.InputStreamReader; +import java.io.*; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; +import java.security.cert.*; import java.text.SimpleDateFormat; import java.util.*; @@ -49,17 +52,24 @@ public class WechatPayUtil { * wechat.pay.api-key=xxx * wechat.pay.cert-path=xxx */ - @Value("${wechat.pay.app-id}") - private String wechatAppId; +// @Value("${wechat.pay.app-id}") +// private String wechatAppId; +// +// @Value("${wechat.pay.mch-id}") +// private String wechatMchId; +// +// @Value("${wechat.pay.api-key}") +// private String wechatApiKey; +// +// @Value("/wechat/apiclient_cert.p12") +// private String wechatCertPath; - @Value("${wechat.pay.mch-id}") - private String wechatMchId; - - @Value("${wechat.pay.api-key}") - private String wechatApiKey; - - @Value("${wechat.pay.cert-path}") - private String wechatCertPath; + /** + * 获取七牛云配置 + */ + private static WechatConfig wechatConfig() { + return SpringUtils.getBean(WechatConfig.class); + } /** * 微信支付API地址(仅保留小程序相关接口) @@ -131,8 +141,8 @@ public class WechatPayUtil { // 2. 构建参数 Map params = new HashMap<>(); - params.put("appid", wechatAppId); - params.put("mch_id", wechatMchId); + params.put("appid", wechatConfig().getAppid()); + params.put("mch_id", wechatConfig().getMchid()); String nonceStr = generateNonceStr(); params.put("nonce_str", nonceStr); params.put("body", body); @@ -147,7 +157,7 @@ public class WechatPayUtil { } // 3. 生成签名 - String sign = generateSign(params, wechatApiKey); + String sign = generateSign(params, wechatConfig().getApikey()); params.put("sign", sign); // 4. 发送请求 @@ -207,8 +217,8 @@ public class WechatPayUtil { return failResult("订单号和微信订单号不能同时为空"); } Map params = new HashMap<>(); - params.put("appid", wechatAppId); - params.put("mch_id", wechatMchId); + params.put("appid", wechatConfig().getAppid()); + params.put("mch_id", wechatConfig().getMchid()); params.put("nonce_str", generateNonceStr()); if (orderNo != null && !orderNo.trim().isEmpty()) { params.put("out_trade_no", orderNo.trim()); @@ -216,7 +226,7 @@ public class WechatPayUtil { if (transactionId != null && !transactionId.trim().isEmpty()) { params.put("transaction_id", transactionId.trim()); } - String sign = generateSign(params, wechatApiKey); + String sign = generateSign(params, wechatConfig().getApikey()); params.put("sign", sign); String xmlRequest = mapToXml(params); @@ -269,7 +279,7 @@ public class WechatPayUtil { // 2. 解析XML数据 Map notifyData = xmlToMap(xmlData.toString()); // 3. 验证签名 - if (!verifySign(notifyData, wechatApiKey)) { + if (!verifySign(notifyData, wechatConfig().getApikey())) { return failResult("签名验证失败"); } // 4. 检查支付结果 @@ -316,7 +326,7 @@ public class WechatPayUtil { Map params = buildRefundParams(refundInfo); // 3. 生成签名 - String sign = generateSign(params, wechatApiKey); + String sign = generateSign(params, wechatConfig().getApikey()); params.put("sign", sign); // 4. 发送请求(需要证书) @@ -361,7 +371,7 @@ public class WechatPayUtil { * @param transferInfo 付款信息 * @return 付款结果 */ - public Map transferToUser(Map transferInfo) { + public Map transferToUser(Map transferInfo) { Map result = new HashMap<>(); try { @@ -377,17 +387,24 @@ public class WechatPayUtil { Map params = buildTransferParams(transferInfo); // 3. 生成签名 - String sign = generateSign(params, wechatApiKey); + String sign = generateSign(params, wechatConfig().getApikey()); params.put("sign", sign); - + + // 设置请求头,指定字符编码为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"); + // 4. 发送请求(需要证书) String xmlRequest = mapToXml(params); + // HttpEntity requestEntity = new HttpEntity<>(xmlRequest, headers); // 注意:企业付款接口需要使用客户端证书,这里简化处理 - ResponseEntity response = restTemplate.postForEntity(WECHAT_TRANSFER_URL, xmlRequest, String.class); + String resourcePath = getClass().getClassLoader().getResource(wechatConfig().getCertpath()).getPath(); + ResponseEntity response = restTemplate.postForEntity(WECHAT_TRANSFER_URL, xmlRequest,String.class, resourcePath); // 5. 解析响应 Map responseMap = xmlToMap(response.getBody()); - if (SUCCESS_CODE.equals(responseMap.get("return_code")) && SUCCESS_CODE.equals(responseMap.get("result_code"))) { @@ -414,6 +431,35 @@ public class WechatPayUtil { return result; } + /** + * 获取证书。 + * + * @param filename 证书文件路径 (required) + * @return X509证书 + */ + public static X509Certificate getCertificate(String filename) throws IOException { + InputStream fis = new FileInputStream(filename); + BufferedInputStream bis = new BufferedInputStream(fis); + try { + CertificateFactory cf = CertificateFactory.getInstance("X509"); + X509Certificate cert = (X509Certificate) cf.generateCertificate(bis); + cert.checkValidity(); + return cert; + } catch (CertificateExpiredException e) { + throw new RuntimeException("证书已过期", e); + } catch (CertificateNotYetValidException e) { + throw new RuntimeException("证书尚未生效", e); + } catch (CertificateException e) { + throw new RuntimeException("无效的证书文件", e); + } finally { + bis.close(); + } + } + + public static void main(String[] args) throws IOException { + getCertificate("D:/javacode/RuoYi-Vue-master/ruoyi-admin/target/classes/wechat/apiclient_cert.p12"); + } + /** * 批量订单统一下单并返回前端支付参数(用于多商品批量下单场景) @@ -483,13 +529,13 @@ public class WechatPayUtil { // 构建签名参数 Map signParams = new HashMap<>(); - signParams.put("appId", wechatAppId); + signParams.put("appId", wechatConfig().getAppid()); signParams.put("timeStamp", timeStamp); signParams.put("nonceStr", nonceStr); signParams.put("package", packageStr); signParams.put("signType", signType); - String paySign = generateSign(signParams, wechatApiKey); + String paySign = generateSign(signParams, wechatConfig().getApikey()); payParams.put("timeStamp", timeStamp); payParams.put("nonceStr", nonceStr); @@ -738,8 +784,10 @@ public class WechatPayUtil { */ private Map buildRefundParams(Map refundInfo) { Map params = new HashMap<>(); - params.put("appid", wechatAppId); - params.put("mch_id", wechatMchId); +// params.put("appid", wechatAppId); +// params.put("mch_id", wechatMchId); + params.put("appid","wx73d0202b3c8a6d68"); + params.put("mch_id","1672571923"); params.put("nonce_str", generateNonceStr()); params.put("out_trade_no", refundInfo.get("orderNo").toString()); params.put("out_refund_no", refundInfo.get("refundNo").toString()); @@ -761,8 +809,10 @@ public class WechatPayUtil { */ private Map buildTransferParams(Map transferInfo) { Map params = new HashMap<>(); - params.put("mch_appid", wechatAppId); - params.put("mchid", wechatMchId); +// params.put("mch_appid", wechatAppId); +// params.put("mchid", wechatMchId); + params.put("mch_appid","wx73d0202b3c8a6d68"); + params.put("mchid","1672571923"); params.put("nonce_str", generateNonceStr()); params.put("partner_trade_no", transferInfo.get("partnerTradeNo").toString()); params.put("openid", transferInfo.get("openid").toString()); @@ -778,4 +828,6 @@ public class WechatPayUtil { return params; } + + } \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WorkerApplyUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WorkerApplyUtil.java new file mode 100644 index 0000000..9829154 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WorkerApplyUtil.java @@ -0,0 +1,88 @@ +package com.ruoyi.system.ControllerUtil; +import javax.crypto.Cipher; +import javax.crypto.spec.SecretKeySpec; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +import javax.net.ssl.*; +import java.security.cert.X509Certificate; +import org.springframework.http.*; +import org.springframework.web.client.RestTemplate; +public class WorkerApplyUtil { + + + public static String aesEncrypt(String data, String key) throws Exception { + Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); + SecretKeySpec secretKey = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); + cipher.init(Cipher.ENCRYPT_MODE, secretKey); + byte[] encrypted = cipher.doFinal(data.getBytes("UTF-8")); + return Base64.getEncoder().encodeToString(encrypted); + } + + public static String getImageBase64(String imageUrl) throws Exception { + java.net.URL url = new java.net.URL(imageUrl); + java.io.InputStream in = url.openStream(); + byte[] bytes = in.readAllBytes(); + in.close(); + return Base64.getEncoder().encodeToString(bytes); + } + //自定义 RestTemplate 禁用 SSL 验证 + + public static RestTemplate getUnsafeRestTemplate() throws Exception { + TrustManager[] trustAllCerts = new TrustManager[]{ + new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } + public void checkClientTrusted(X509Certificate[] certs, String authType) {} + public void checkServerTrusted(X509Certificate[] certs, String authType) {} + } + }; + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory()); + HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true); + + SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); + return new RestTemplate(requestFactory); + } + + + public static Map virtualVerify(String image, String phone, String cardNo, String name, String callbackUrl, String qiniuPrefix, String apiUrl) throws Exception { + long time = System.currentTimeMillis(); + String key = "ecf5ae04c52b4d85"; + // 1. 处理图片URL + String imageUrl = image.startsWith(qiniuPrefix) ? image : (qiniuPrefix + image); + String base64Image = getImageBase64(imageUrl); + String encryptedImage = aesEncrypt(base64Image, key); + + // 2. 加密其他字段 + String encryptedPhone = aesEncrypt(phone, key); + String encryptedName = aesEncrypt(name, key); + String encryptedCardNo = aesEncrypt(cardNo, key); + + // 3. 组装header和body + String sign = org.apache.commons.codec.digest.DigestUtils.md5Hex("256339ecf5ae04c52b4d85a0e4255d7d0ebb71" + time); + String authorization = Base64.getEncoder().encodeToString(("256339:" + time).getBytes("UTF-8")); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("Authorization", authorization); + + Map body = new HashMap<>(); + body.put("phoneNo", encryptedPhone); + body.put("name", encryptedName); + body.put("identifyCardNO", encryptedCardNo); + body.put("photo", encryptedImage); + body.put("callbackUrl", callbackUrl); + + HttpEntity> entity = new HttpEntity<>(body, headers); + RestTemplate restTemplate = getUnsafeRestTemplate(); + // RestTemplate restTemplate = new getUnsafeRestTemplate(); + String url = apiUrl + "/realNameAuth/256339/" + sign; + ResponseEntity response = restTemplate.postForEntity(url, entity, Map.class); + + return response.getBody(); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/GoodsOrder.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/GoodsOrder.java index 5231e9d..7f48397 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/GoodsOrder.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/GoodsOrder.java @@ -85,6 +85,10 @@ public class GoodsOrder extends BaseEntity @Excel(name = "支付金额") private BigDecimal payPrice; + /** 支付金额 */ + @Excel(name = "优惠券id") + private Long couponId; + /** 抵扣金额 */ @Excel(name = "抵扣金额") private BigDecimal deduction; @@ -494,7 +498,13 @@ public class GoodsOrder extends BaseEntity this.payPriceMin = payPriceMin; } + public Long getCouponId() { + return couponId; + } + public void setCouponId(Long couponId) { + this.couponId = couponId; + } @Override public String toString() { diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/CouponUserMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/CouponUserMapper.java index 96d4cb7..2544ee7 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/CouponUserMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/CouponUserMapper.java @@ -2,6 +2,7 @@ package com.ruoyi.system.mapper; import java.util.List; import com.ruoyi.system.domain.CouponUser; +import org.apache.ibatis.annotations.Param; /** * 优惠券领取记录Mapper接口 @@ -23,6 +24,12 @@ public interface CouponUserMapper public int selectCountCouponUserbycouponId(Long couponId); + + public int selectCountCouponsByUid(@Param("uid") Long uid, @Param("status") Long status); + + + + /** * 查询优惠券领取记录列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/GoodsOrderMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/GoodsOrderMapper.java index 1607eac..e8b986d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/GoodsOrderMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/GoodsOrderMapper.java @@ -2,6 +2,7 @@ package com.ruoyi.system.mapper; import java.util.List; import com.ruoyi.system.domain.GoodsOrder; +import org.apache.ibatis.annotations.Param; /** * 商品订单Mapper接口 @@ -19,6 +20,12 @@ public interface GoodsOrderMapper */ public GoodsOrder selectGoodsOrderById(Long id); + + public int selectCountGoodsOrderByUid(@Param("uid") Long uid, @Param("status") Long status); + + public int selectAllCountGoodsOrderByUid(Long uid); + + /** * 查询商品订单列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/OrderMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/OrderMapper.java index c54c920..949755d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/OrderMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/OrderMapper.java @@ -4,6 +4,7 @@ import java.util.List; import com.ruoyi.system.domain.AppleDoMain.OrderApple; import com.ruoyi.system.domain.Order; +import org.apache.ibatis.annotations.Param; /** * 服务订单Mapper接口 @@ -22,8 +23,10 @@ public interface OrderMapper public Order selectOrderById(Long id); + public int selectCountOrderByUid(@Param("uid") Long uid,@Param("status") Long status); + public int selectAllCountOrderByUid(Long uid); /** * 小程序查询服务订单列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UsersMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UsersMapper.java index a10ffbd..25b093b 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UsersMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UsersMapper.java @@ -19,6 +19,9 @@ public interface UsersMapper */ public Users selectUsersById(Long id); + + public Users selectUsersIsMaxNumber(); + /** * 查询【请填写功能名称】 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ICouponUserService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ICouponUserService.java index 94cb941..76a78db 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ICouponUserService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ICouponUserService.java @@ -2,6 +2,7 @@ package com.ruoyi.system.service; import java.util.List; import com.ruoyi.system.domain.CouponUser; +import org.apache.ibatis.annotations.Param; /** * 优惠券领取记录Service接口 @@ -28,6 +29,8 @@ public interface ICouponUserService public int deleteCouponUserBycouponId (Long couponId); public int selectCountCouponUserbycouponId(Long couponId); + + public int selectCountCouponsByUid(Long uid,Long status); /** * 查询优惠券领取记录列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IGoodsOrderService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IGoodsOrderService.java index c99c1c0..7883549 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IGoodsOrderService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IGoodsOrderService.java @@ -27,6 +27,13 @@ public interface IGoodsOrderService */ public List selectGoodsOrderList(GoodsOrder goodsOrder); + + + public int selectCountGoodsOrderByUid(Long uid,Long status); + + public int selectAllCountGoodsOrderByUid(Long uid); + + /** * 新增商品订单 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IOrderService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IOrderService.java index 4087ca5..c13ce50 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IOrderService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IOrderService.java @@ -38,6 +38,11 @@ public interface IOrderService */ public List selectOrderList(Order order); + + public int selectCountOrderByUid(Long uid,Long status); + + + public int selectAllCountOrderByUid(Long uid); /** * 新增服务订单 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IUsersService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IUsersService.java index 7a4f54f..77c67d7 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IUsersService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IUsersService.java @@ -27,6 +27,9 @@ public interface IUsersService public Users selectUsersByRememberToken(String rememberToken); + public Users selectUsersIsMaxNumber(); + + /** * 查询【请填写功能名称】 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CouponUserServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CouponUserServiceImpl.java index 9764172..4ea2b09 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CouponUserServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CouponUserServiceImpl.java @@ -31,6 +31,11 @@ public class CouponUserServiceImpl implements ICouponUserService return couponUserMapper.selectCouponUserById(id); } + + public int selectCountCouponsByUid(Long uid,Long status){ + return couponUserMapper.selectCountCouponsByUid(uid,status); + } + /** * 批量删除优惠券领取记录 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/GoodsOrderServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/GoodsOrderServiceImpl.java index 685d862..ea69d97 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/GoodsOrderServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/GoodsOrderServiceImpl.java @@ -31,6 +31,16 @@ public class GoodsOrderServiceImpl implements IGoodsOrderService return goodsOrderMapper.selectGoodsOrderById(id); } + + public int selectCountGoodsOrderByUid(Long uid,Long status) { + return goodsOrderMapper.selectCountGoodsOrderByUid(uid,status); + + } + + public int selectAllCountGoodsOrderByUid(Long uid) { + return goodsOrderMapper.selectAllCountGoodsOrderByUid(uid); + } + /** * 查询商品订单列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OrderServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OrderServiceImpl.java index 7220208..e64e3b0 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OrderServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OrderServiceImpl.java @@ -35,6 +35,14 @@ public class OrderServiceImpl implements IOrderService + public int selectCountOrderByUid(Long uid,Long status) { + return orderMapper.selectCountOrderByUid(uid,status); + } + + + public int selectAllCountOrderByUid(Long uid) { + return orderMapper.selectAllCountOrderByUid(uid); + } /** * 小程序查询服务订单列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsersServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsersServiceImpl.java index 6d804ee..00f40ac 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsersServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsersServiceImpl.java @@ -44,7 +44,10 @@ public class UsersServiceImpl implements IUsersService } + public Users selectUsersIsMaxNumber() { + return usersMapper.selectUsersIsMaxNumber(); + } /** * 查询【请填写功能名称】 * diff --git a/ruoyi-system/src/main/resources/mapper/system/CouponUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/CouponUserMapper.xml index 6436ecd..64a3b64 100644 --- a/ruoyi-system/src/main/resources/mapper/system/CouponUserMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/CouponUserMapper.xml @@ -30,6 +30,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select count(0) from coupon_user where coupon_id=#{couponId} + + + + + + + + + + + insert into goods_order @@ -74,6 +86,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order_id, transaction_id, uid, + coupon_id, product_id, name, phone, @@ -103,6 +116,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{orderId}, #{transactionId}, #{uid}, + #{couponId}, #{productId}, #{name}, #{phone}, @@ -138,6 +152,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" transaction_id = #{transactionId}, uid = #{uid}, product_id = #{productId}, + coupon_id = #{couponId}, name = #{name}, phone = #{phone}, address = #{address}, diff --git a/ruoyi-system/src/main/resources/mapper/system/OrderMapper.xml b/ruoyi-system/src/main/resources/mapper/system/OrderMapper.xml index f85dd49..4d1460c 100644 --- a/ruoyi-system/src/main/resources/mapper/system/OrderMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/OrderMapper.xml @@ -192,6 +192,15 @@ + + + + + + +