920 lines
40 KiB
Java
920 lines
40 KiB
Java
package com.ruoyi.system.controller;
|
||
|
||
import com.alibaba.fastjson2.JSON;
|
||
import com.alibaba.fastjson2.JSONObject;
|
||
import com.github.pagehelper.PageHelper;
|
||
import com.ruoyi.common.core.controller.BaseController;
|
||
import com.ruoyi.common.core.domain.AjaxResult;
|
||
import com.ruoyi.common.core.page.TableDataInfo;
|
||
import com.ruoyi.system.ControllerUtil.*;
|
||
import com.ruoyi.system.domain.*;
|
||
import com.ruoyi.system.service.*;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
import javax.servlet.http.HttpServletRequest;
|
||
import java.math.BigDecimal;
|
||
import java.math.RoundingMode;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.Date;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
/**
|
||
* 会员管理控制器
|
||
*
|
||
* 提供会员相关的API接口,包括:
|
||
* 1. 会员充值功能
|
||
* 2. 充值记录管理
|
||
* 3. 消费记录管理
|
||
* 4. 会员权益管理
|
||
* 5. 订单评价功能
|
||
* 6. 师傅报价功能
|
||
* 7. 拼团支付功能
|
||
* 8. 次卡管理功能
|
||
* 9. 余额支付功能
|
||
*
|
||
* @author Mr. Zhang Pan
|
||
* @version 1.0
|
||
* @date 2025-01-26
|
||
*/
|
||
@RestController
|
||
@RequestMapping("/api")
|
||
public class AppleMemberController extends BaseController {
|
||
|
||
// ==================== 依赖注入 ====================
|
||
|
||
@Autowired
|
||
private IUsersService usersService;
|
||
|
||
@Autowired
|
||
private IUserMemberRechargeLogService userMemberRechargeLogService;
|
||
|
||
@Autowired
|
||
private IUserMemberRechargeProgramService userMemberRechargeProgramService;
|
||
|
||
@Autowired
|
||
private ISiteConfigService siteConfigService;
|
||
|
||
@Autowired
|
||
private IUserMemnerConsumptionLogService userMemnerConsumptionLogService;
|
||
|
||
@Autowired
|
||
private IOrderService orderService;
|
||
|
||
@Autowired
|
||
private IOrderCommentService orderCommentService;
|
||
|
||
@Autowired
|
||
private IOrderLogService orderLogService;
|
||
|
||
@Autowired
|
||
private IServiceCateService serviceCateService;
|
||
|
||
@Autowired
|
||
private IUserSecondaryCardService userSecondaryCardService;
|
||
|
||
@Autowired
|
||
private IServiceGoodsService serviceGoodsService;
|
||
|
||
@Autowired
|
||
private IUserDemandQuotationService userDemandQuotationService;
|
||
|
||
@Autowired
|
||
private IUserGroupBuyingService userGroupBuyingService;
|
||
|
||
@Autowired
|
||
private IUserBenefitPointsService userBenefitPointsService;
|
||
|
||
@Autowired
|
||
private WechatPayUtil wechatPayUtil;
|
||
|
||
// ==================== 会员充值相关接口 ====================
|
||
|
||
/**
|
||
* 会员充值支付接口
|
||
*
|
||
* 支持两种充值方式:
|
||
* 1. 通过充值套餐ID充值(优先级更高)
|
||
* 2. 通过自定义金额充值
|
||
*
|
||
* 业务逻辑:
|
||
* - 如果id和money都有值,优先使用id充值套餐
|
||
* - 如果只有money有值,使用自定义金额充值
|
||
* - 支持充值优惠配置(从系统配置中读取)
|
||
* - 生成充值记录并调用微信支付
|
||
*
|
||
* @param request HTTP请求对象(需要包含token)
|
||
* @return 支付结果,包含prepayId等微信支付参数
|
||
*/
|
||
@PostMapping("/member/recharge/pay")
|
||
public AjaxResult memberRechargePay(@RequestBody Map<String, Object> params,HttpServletRequest request) {
|
||
try {
|
||
// 1. 验证用户登录状态
|
||
//Map<String, Object> params = new HashMap<>();
|
||
//params.put("money", 300); // 测试用固定金额,实际应从请求参数获取
|
||
|
||
String token = request.getHeader("token");
|
||
Map<String, Object> 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("用户信息获取失败");
|
||
}
|
||
|
||
// 3. 参数验证逻辑:id和money必须有一个有值,如果都有值则优先使用id
|
||
Object idObj = params.get("id");
|
||
Object moneyObj = params.get("money");
|
||
boolean idEmpty = (idObj == null || idObj.toString().trim().isEmpty());
|
||
boolean moneyEmpty = (moneyObj == null || moneyObj.toString().trim().isEmpty());
|
||
|
||
if (idEmpty && moneyEmpty) {
|
||
return AppletControllerUtil.appletWarning("参数不能为空,类目和金额必须有一个有值");
|
||
}
|
||
|
||
// 如果id和money都有值,优先走id逻辑,money置空
|
||
if (!idEmpty && !moneyEmpty) {
|
||
moneyObj = null;
|
||
}
|
||
|
||
// 4. 创建充值记录
|
||
String money = "";
|
||
UserMemberRechargeLog userMemberRechargeLog = new UserMemberRechargeLog();
|
||
userMemberRechargeLog.setUid(Math.toIntExact(user.getId()));
|
||
userMemberRechargeLog.setOrderid(GenerateCustomCode.generCreateOrder("DYZ"));
|
||
userMemberRechargeLog.setPaytype(0); // 0=微信支付
|
||
userMemberRechargeLog.setPaytime(new Date());
|
||
|
||
if (!idEmpty) {
|
||
// 5a. 通过充值套餐ID充值
|
||
UserMemberRechargeProgram userMemberRechargeProgram = userMemberRechargeProgramService
|
||
.selectUserMemberRechargeProgramById(Integer.valueOf(idObj.toString()));
|
||
|
||
if (userMemberRechargeProgram != null) {
|
||
userMemberRechargeLog.setInmoney(userMemberRechargeProgram.getMoney()); // 应付金额
|
||
userMemberRechargeLog.setComemoney(userMemberRechargeProgram.getDiscount()); // 实际到账金额
|
||
userMemberRechargeLog.setReamk("购买" + userMemberRechargeProgram.getRechargename()
|
||
+ "应付" + userMemberRechargeProgram.getMoney() + "元,应到"
|
||
+ userMemberRechargeProgram.getDiscount() + "元");
|
||
userMemberRechargeLog.setProid(userMemberRechargeProgram.getId());
|
||
money = userMemberRechargeProgram.getMoney().toString();
|
||
|
||
// type大于0表示会员包年充值,需要特殊处理
|
||
if (userMemberRechargeProgram.getType() > 0) {
|
||
userMemberRechargeLog.setIsmember(1); // 会员充值
|
||
} else {
|
||
userMemberRechargeLog.setIsmember(2); // 普通充值
|
||
}
|
||
}
|
||
} else if (!moneyEmpty) {
|
||
// 5b. 通过自定义金额充值
|
||
money = moneyObj.toString();
|
||
BigDecimal rechargeAmount = new BigDecimal(money);
|
||
BigDecimal actualAmount = rechargeAmount; // 默认实际到账金额等于充值金额
|
||
|
||
try {
|
||
// 查询充值优惠配置
|
||
SiteConfig siteConfig = siteConfigService.selectSiteConfigByName("config_one");
|
||
if (siteConfig != null && siteConfig.getValue() != null) {
|
||
JSONObject configJson = JSONObject.parseObject(siteConfig.getValue());
|
||
if (configJson.containsKey("recharge_discount")) {
|
||
// 获取充值优惠率(百分比)
|
||
BigDecimal discountRate = configJson.getBigDecimal("recharge_discount");
|
||
if (discountRate != null && discountRate.compareTo(BigDecimal.ZERO) > 0) {
|
||
// 计算实际到账金额:充值金额 * (1 + 优惠率/100)
|
||
BigDecimal discountMultiplier = BigDecimal.ONE.add(
|
||
discountRate.divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP));
|
||
actualAmount = rechargeAmount.multiply(discountMultiplier)
|
||
.setScale(2, RoundingMode.HALF_UP);
|
||
}
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
System.err.println("获取充值优惠配置失败:" + e.getMessage());
|
||
// 配置获取失败时,使用原金额,不影响充值流程
|
||
}
|
||
|
||
userMemberRechargeLog.setInmoney(rechargeAmount); // 应付金额
|
||
userMemberRechargeLog.setComemoney(actualAmount); // 实际到账金额
|
||
userMemberRechargeLog.setIsmember(2); // 普通充值
|
||
|
||
// 更新备注信息,显示优惠详情
|
||
if (actualAmount.compareTo(rechargeAmount) > 0) {
|
||
BigDecimal bonusAmount = actualAmount.subtract(rechargeAmount);
|
||
userMemberRechargeLog.setReamk("会员现金充值" + money + "元,实际到账" + actualAmount
|
||
+ "元(含优惠" + bonusAmount + "元)");
|
||
} else {
|
||
userMemberRechargeLog.setReamk("会员现金充值" + money + "元");
|
||
}
|
||
}
|
||
|
||
// 6. 保存充值记录并调用微信支付
|
||
if (userMemberRechargeLogService.insertUserMemberRechargeLog(userMemberRechargeLog) > 0) {
|
||
// 调用微信支付(测试环境使用0.01元)
|
||
Map<String, Object> payResult = wechatPayUtil.createBatchOrderAndPay(
|
||
user.getOpenid(),
|
||
userMemberRechargeLog.getId().toString(),
|
||
new BigDecimal("0.01"), // 测试金额
|
||
1,
|
||
wechatPayUtil.PAY_FH + "api/recharge/pay/notify");
|
||
|
||
if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) {
|
||
// 构建支付响应数据
|
||
Map<String, Object> responseData = new HashMap<>();
|
||
responseData.put("mainOrderId", userMemberRechargeLog.getId().toString());
|
||
responseData.put("totalAmount", money);
|
||
responseData.put("prepayId", payResult.get("prepayId"));
|
||
// 合并所有支付参数
|
||
responseData.putAll(payResult);
|
||
return AppletControllerUtil.appletSuccess(responseData);
|
||
} else {
|
||
String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败";
|
||
return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg);
|
||
}
|
||
}
|
||
|
||
return AppletControllerUtil.appletWarning("支付失败");
|
||
|
||
} catch (Exception e) {
|
||
System.err.println("会员充值支付异常:" + e.getMessage());
|
||
return AppletControllerUtil.appletError("充值支付失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取充值类目列表
|
||
*
|
||
* 查询状态为0(启用)且类型为0(普通充值)的充值套餐
|
||
* 用于用户选择充值项目
|
||
*
|
||
* @return 充值类目列表
|
||
*/
|
||
@GetMapping("/member/recharge/catalogue")
|
||
public AjaxResult getRechargeCatalogue(HttpServletRequest request) {
|
||
try {
|
||
|
||
SimpleDateFormat sdfday = new SimpleDateFormat("yyyy-MM-dd");
|
||
HomeUtril homeUtril = new HomeUtril();
|
||
Map<String, Object> params = new HashMap<>();
|
||
String token = request.getHeader("token");
|
||
Map<String, Object> 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("用户信息获取失败");
|
||
}
|
||
UserMemberRechargeProgram query = new UserMemberRechargeProgram();
|
||
query.setStatus(0); // 0=启用状态
|
||
query.setType(0); // 0=普通充值类型
|
||
|
||
List<UserMemberRechargeProgram> list = userMemberRechargeProgramService
|
||
.selectUserMemberRechargeProgramList(query);
|
||
params.put("balance", user.getBalance());
|
||
params.put("ismember", user.getIsmember());
|
||
params.put("member_begin",user.getMemberBegin() != null ? sdfday.format(user.getMemberBegin()) : null );
|
||
params.put("member_end",user.getMemberEnd() != null ? sdfday.format(user.getMemberEnd()) : null );
|
||
|
||
// params.put("member_begin", user.getIsmember());
|
||
// params.put("member_end", user.getIsmember());
|
||
|
||
int nu= homeUtril.getMemberType(user);
|
||
if (nu==0){//新会员
|
||
// 新增:根据会员状态查询充值项目
|
||
Integer queryType = 1;
|
||
UserMemberRechargeProgram query2 = new UserMemberRechargeProgram();
|
||
query2.setType(queryType);
|
||
query2.setStatus(0); // 只查启用
|
||
java.util.List<UserMemberRechargeProgram> rechargePrograms = userMemberRechargeProgramService.selectUserMemberRechargeProgramList(query2);
|
||
params.put("memberpay", rechargePrograms.getFirst());
|
||
}
|
||
if (nu==2){//续费会员
|
||
// 新增:根据会员状态查询充值项目
|
||
Integer queryType =2;
|
||
UserMemberRechargeProgram query2 = new UserMemberRechargeProgram();
|
||
query2.setType(queryType);
|
||
query2.setStatus(0); // 只查启用
|
||
java.util.List<UserMemberRechargeProgram> rechargePrograms = userMemberRechargeProgramService.selectUserMemberRechargeProgramList(query2);
|
||
params.put("memberpay", rechargePrograms.getFirst());
|
||
}
|
||
if (nu==1){//已经是会员
|
||
// 新增:根据会员状态查询充值项目
|
||
Integer queryType =2;
|
||
UserMemberRechargeProgram query2 = new UserMemberRechargeProgram();
|
||
query2.setType(queryType);
|
||
query2.setStatus(0); // 只查启用
|
||
java.util.List<UserMemberRechargeProgram> rechargePrograms = userMemberRechargeProgramService.selectUserMemberRechargeProgramList(query2);
|
||
params.put("memberpay", rechargePrograms.getFirst());
|
||
}
|
||
params.put("list", list);
|
||
Map<String, Object> homeNoticeList = homeUtril.getConfigData("config_one");
|
||
JSONObject js= JSONObject.parseObject(homeNoticeList.get("data").toString());
|
||
params.put("notice", js.get("notice"));
|
||
//公司简介
|
||
params.put("member", homeUtril.getConfigData("config_five").get("data"));
|
||
|
||
|
||
|
||
return AppletControllerUtil.appletSuccess(params);
|
||
} catch (Exception e) {
|
||
return AppletControllerUtil.appletError("获取充值类目失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取包年充值项目列表
|
||
*
|
||
* 根据类型ID查询对应的包年充值项目
|
||
* 用于会员包年充值功能
|
||
*
|
||
* @param id 充值类型ID
|
||
* @return 包年充值项目列表
|
||
*/
|
||
@GetMapping("/member/recharge/catal/{id}")
|
||
public AjaxResult getRechargeCatalyear(@PathVariable("id") int id) {
|
||
try {
|
||
UserMemberRechargeProgram query = new UserMemberRechargeProgram();
|
||
query.setStatus(0); // 0=启用状态
|
||
query.setType(id); // 指定类型
|
||
|
||
List<UserMemberRechargeProgram> list = userMemberRechargeProgramService
|
||
.selectUserMemberRechargeProgramList(query);
|
||
|
||
if (!list.isEmpty()) {
|
||
return AppletControllerUtil.appletSuccess(list);
|
||
} else {
|
||
return AppletControllerUtil.appletWarning("暂无数据");
|
||
}
|
||
} catch (Exception e) {
|
||
return AppletControllerUtil.appletError("获取充值类目失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
// ==================== 余额支付相关接口 ====================
|
||
|
||
// /**
|
||
// * 余额支付测试接口
|
||
// *
|
||
// * 测试用户余额支付功能
|
||
// * 模拟购买99.99元商品的余额支付流程
|
||
// *
|
||
// * @param request HTTP请求对象(需要包含token)
|
||
// * @return 支付结果
|
||
// */
|
||
// @GetMapping("/balance/payment")
|
||
// public AjaxResult apibalancepayment(HttpServletRequest request) {
|
||
// try {
|
||
// // 1. 验证用户登录状态
|
||
// String token = request.getHeader("token");
|
||
// Map<String, Object> 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("用户信息获取失败");
|
||
// }
|
||
//
|
||
//// // 3. 调用余额支付工具类
|
||
//// Map<String, Object> rmap = BalancePayUtil.processBalancePayment(
|
||
//// user.getId(),
|
||
//// new BigDecimal("99.99"),
|
||
//// "购买一般商品单价99.99");
|
||
//// return AppletControllerUtil.appletSuccess(rmap.get("message"));
|
||
//
|
||
// } catch (Exception e) {
|
||
// System.err.println("余额支付异常:" + e.getMessage());
|
||
// return AppletControllerUtil.appletError("余额支付失败:" + e.getMessage());
|
||
// }
|
||
// }
|
||
|
||
// ==================== 记录查询相关接口 ====================
|
||
|
||
/**
|
||
* 获取用户充值记录列表
|
||
*
|
||
* 查询当前用户的所有充值记录
|
||
* 按时间倒序排列
|
||
*
|
||
* @param request HTTP请求对象(需要包含token)
|
||
* @return 用户充值记录列表
|
||
*/
|
||
@GetMapping("/member/recharge/log")
|
||
public AjaxResult getRechargelog(HttpServletRequest request) {
|
||
try {
|
||
// 1. 验证用户登录状态
|
||
String token = request.getHeader("token");
|
||
Map<String, Object> 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("用户信息获取失败");
|
||
}
|
||
|
||
// 3. 查询充值记录
|
||
UserMemberRechargeLog query = new UserMemberRechargeLog();
|
||
query.setUid(Math.toIntExact(user.getId()));
|
||
|
||
List<UserMemberRechargeLog> list = userMemberRechargeLogService
|
||
.selectUserMemberRechargeLogList(query);
|
||
|
||
if (!list.isEmpty()) {
|
||
return AppletControllerUtil.appletSuccess(list);
|
||
} else {
|
||
return AppletControllerUtil.appletWarning("暂无数据");
|
||
}
|
||
|
||
} catch (Exception e) {
|
||
return AppletControllerUtil.appletError("获取数据失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取用户消费记录
|
||
*
|
||
* 查询当前用户的消费记录
|
||
* 注意:这里只返回第一条记录(可能是设计问题,建议返回完整列表)
|
||
*
|
||
* @param request HTTP请求对象(需要包含token)
|
||
* @return 用户消费记录
|
||
*/
|
||
@GetMapping("/member/consumption/log")
|
||
public AjaxResult getconsumptionlog(HttpServletRequest request) {
|
||
try {
|
||
// 1. 验证用户登录状态
|
||
String token = request.getHeader("token");
|
||
Map<String, Object> 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("用户信息获取失败");
|
||
}
|
||
|
||
// 3. 查询消费记录
|
||
UserMemnerConsumptionLog query = new UserMemnerConsumptionLog();
|
||
query.setUid(Math.toIntExact(user.getId()));
|
||
|
||
List<UserMemnerConsumptionLog> list = userMemnerConsumptionLogService
|
||
.selectUserMemnerConsumptionLogList(query);
|
||
|
||
if (!list.isEmpty()) {
|
||
// 注意:这里只返回第一条记录,可能需要根据业务需求调整
|
||
return AppletControllerUtil.appletSuccess(list.getFirst());
|
||
} else {
|
||
return AppletControllerUtil.appletWarning("暂无数据");
|
||
}
|
||
|
||
} catch (Exception e) {
|
||
return AppletControllerUtil.appletError("获取消费记录失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 查询用户充值记录(只返回订单号和金额,带分页)
|
||
* @param request HTTP请求对象(需要包含token)
|
||
* @param page 页码(默认1)
|
||
* @param limit 每页条数(默认10)
|
||
* @return 订单号和金额列表
|
||
*/
|
||
@GetMapping("/member/recharge/simplelog")
|
||
public AjaxResult getRechargeSimpleLog(HttpServletRequest request,
|
||
@RequestParam(value = "page", defaultValue = "1") int page,
|
||
@RequestParam(value = "limit", defaultValue = "10") int limit) {
|
||
try {
|
||
// 1. 验证分页参数
|
||
Map<String, Object> pageValidation = PageUtil.validatePageParams(page, limit);
|
||
if (!(Boolean) pageValidation.get("valid")) {
|
||
return AppletControllerUtil.appletWarning((String) pageValidation.get("message"));
|
||
}
|
||
// 2. 验证用户登录状态
|
||
String token = request.getHeader("token");
|
||
Map<String, Object> userValidation = AppletLoginUtil.validateUserToken(token, usersService);
|
||
if (!(Boolean) userValidation.get("valid")) {
|
||
return AppletControllerUtil.appletWarning("用户未登录或token无效");
|
||
}
|
||
// 3. 获取用户信息
|
||
Users user = (Users) userValidation.get("user");
|
||
if (user == null) {
|
||
return AppletControllerUtil.appletWarning("用户信息获取失败");
|
||
}
|
||
// 4. 设置分页参数
|
||
com.github.pagehelper.PageHelper.startPage(page, limit);
|
||
// 5. 查询充值记录
|
||
UserMemberRechargeLog query = new UserMemberRechargeLog();
|
||
query.setUid(Math.toIntExact(user.getId()));
|
||
List<UserMemberRechargeLog> list = userMemberRechargeLogService.selectUserMemberRechargeLogList(query);
|
||
// 6. 只返回订单号和金额
|
||
// List<Map<String, Object>> result = new java.util.ArrayList<>();
|
||
// for (UserMemberRechargeLog log : list) {
|
||
// Map<String, Object> map = new java.util.HashMap<>();
|
||
// map.put("orderid", log.getOrderid());
|
||
// map.put("inmoney", log.getInmoney());
|
||
// result.add(map);
|
||
// }
|
||
// 7. 构建分页响应
|
||
TableDataInfo tableDataInfo = getDataTable(list);
|
||
Map<String, Object> pageData = PageUtil.buildPageResponse(tableDataInfo, page, limit);
|
||
//pageData.put("rows", result); // 用精简后的数据覆盖rows
|
||
return AppletControllerUtil.appletSuccess(pageData);
|
||
} catch (Exception e) {
|
||
return AppletControllerUtil.appletError("获取充值记录失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
// ==================== 订单评价相关接口 ====================
|
||
|
||
/**
|
||
* 服务订单评价接口
|
||
*
|
||
* 用户对已完成的服务订单进行评价
|
||
* 包括评分、评价内容、图片、标签等
|
||
*
|
||
* 业务逻辑:
|
||
* 1. 验证用户登录状态
|
||
* 2. 检查订单是否存在且属于当前用户
|
||
* 3. 检查是否已经评价过(防止重复评价)
|
||
* 4. 保存评价信息
|
||
* 5. 添加订单日志
|
||
* 6. 更新订单状态为已完成
|
||
*
|
||
* @param params 评价参数(order_id, content, num, images, labels)
|
||
* @param request HTTP请求对象(需要包含token)
|
||
* @return 评价结果
|
||
*/
|
||
@PostMapping("/service/order/comment")
|
||
public AjaxResult serviceOrderComment(@RequestBody Map<String, Object> params, HttpServletRequest request) {
|
||
try {
|
||
// 1. 验证用户登录状态
|
||
String token = request.getHeader("token");
|
||
Map<String, Object> 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("用户信息获取失败");
|
||
}
|
||
|
||
// 3. 参数验证
|
||
if (!params.containsKey("order_id") || !params.containsKey("content") || !params.containsKey("num")) {
|
||
return AppletControllerUtil.appletWarning("参数错误");
|
||
}
|
||
|
||
String orderId = params.get("order_id").toString();
|
||
String content = params.get("content").toString();
|
||
Integer num = Integer.parseInt(params.get("num").toString());
|
||
|
||
// 4. 获取订单信息并验证
|
||
Order order = orderService.selectOrderByOrderId(orderId);
|
||
if (order == null) {
|
||
return AppletControllerUtil.appletWarning("订单不存在");
|
||
}
|
||
|
||
// 5. 检查是否已经评价过
|
||
int count = orderCommentService.selectCountOrderCommentByOid(order.getId());
|
||
if (count > 0) {
|
||
return AppletControllerUtil.appletWarning("请勿重复提交");
|
||
}
|
||
|
||
// 6. 计算评分类型
|
||
Integer numType;
|
||
if (num == 1) {
|
||
numType = 3; // 差评
|
||
} else if (num == 2 || num == 3) {
|
||
numType = 2; // 中评
|
||
} else {
|
||
numType = 1; // 好评
|
||
}
|
||
|
||
// 7. 构建评价数据
|
||
OrderComment comment = new OrderComment();
|
||
comment.setOid(order.getId());
|
||
comment.setOrderId(orderId);
|
||
comment.setProductId(order.getProductId());
|
||
comment.setContent(content);
|
||
comment.setNum(Long.valueOf(num));
|
||
comment.setNumType(Long.valueOf(numType));
|
||
comment.setUid(user.getId());
|
||
comment.setWorkerId(order.getWorkerId());
|
||
|
||
// 8. 处理图片附件
|
||
if (params.containsKey("images") && params.get("images") != null) {
|
||
String images = JSON.toJSONString(params.get("images"));
|
||
comment.setImages(images);
|
||
}
|
||
|
||
// 9. 处理评价标签
|
||
if (params.containsKey("labels") && params.get("labels") != null) {
|
||
String labels = JSON.toJSONString(params.get("labels"));
|
||
comment.setLabels(labels);
|
||
}
|
||
|
||
// 10. 保存评价并更新订单状态
|
||
// 保存评价
|
||
orderCommentService.insertOrderComment(comment);
|
||
|
||
// 添加订单日志
|
||
OrderLog orderLog = new OrderLog();
|
||
orderLog.setOid(order.getId());
|
||
orderLog.setOrderId(orderId);
|
||
orderLog.setTitle("订单评价");
|
||
orderLog.setType(BigDecimal.valueOf(8)); // 8=评价类型
|
||
|
||
Map<String, Object> logContent = new HashMap<>();
|
||
logContent.put("text", content);
|
||
logContent.put("image", params.get("images"));
|
||
logContent.put("num", num);
|
||
orderLog.setContent(JSON.toJSONString(logContent));
|
||
|
||
orderLogService.insertOrderLog(orderLog);
|
||
|
||
// 更新订单状态
|
||
order.setStatus(4L); // 4=完成状态
|
||
order.setIsComment(1); // 1=已评价
|
||
orderService.updateOrder(order);
|
||
|
||
return AjaxResult.success("评价提交成功");
|
||
|
||
} catch (Exception e) {
|
||
System.err.println("服务订单评价异常:" + e.getMessage());
|
||
return AjaxResult.error("评价提交失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
// ==================== 用户验证相关接口 ====================
|
||
|
||
/**
|
||
* 检查用户是否使用默认头像和昵称
|
||
*
|
||
* 验证用户是否还在使用系统默认的头像和昵称
|
||
* 如果是默认的,提示用户修改
|
||
*
|
||
* @param request HTTP请求对象(需要包含token)
|
||
* @return 验证结果
|
||
*/
|
||
@GetMapping("/user/check/default")
|
||
public AjaxResult checkUserDefault(HttpServletRequest request) {
|
||
try {
|
||
// 1. 验证用户登录状态
|
||
String token = request.getHeader("token");
|
||
Map<String, Object> userValidation = AppletLoginUtil.validateUserToken(token, usersService);
|
||
if (!(Boolean) userValidation.get("valid")) {
|
||
return AppletControllerUtil.appletUnauthorized();
|
||
}
|
||
|
||
// 2. 获取用户信息
|
||
Users user = (Users) userValidation.get("user");
|
||
if (user == null) {
|
||
return AppletControllerUtil.appletWarning("用户信息获取失败");
|
||
}
|
||
|
||
// 3. 验证图像和昵称是否为系统默认
|
||
String defaultAvatar = "https://img.huafurenjia.cn/default/user_avatar.jpeg";
|
||
String defaultName = "微信用户";
|
||
|
||
if (defaultAvatar.equals(user.getAvatar()) && defaultName.equals(user.getName())) {
|
||
return AppletControllerUtil.appletWarning("请修改您的图像和昵称");
|
||
}
|
||
|
||
return AppletControllerUtil.appletSuccess("校验通过");
|
||
|
||
} catch (Exception e) {
|
||
System.err.println("验证用户图像和昵称异常:" + e.getMessage());
|
||
return AppletControllerUtil.appletError("验证失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
// ==================== 分类和次卡相关接口 ====================
|
||
|
||
/**
|
||
* 获取二级分类列表
|
||
*
|
||
* 查询所有的服务分类信息
|
||
* 用于前端分类展示
|
||
*
|
||
* @param request HTTP请求对象
|
||
* @return 分类列表
|
||
*/
|
||
@GetMapping("/secondary/classification")
|
||
public AjaxResult classification(HttpServletRequest request) {
|
||
try {
|
||
List<ServiceCate> list = serviceCateService.selectServiceCateCiKaList();
|
||
return AppletControllerUtil.appletSuccess(list);
|
||
} catch (Exception e) {
|
||
System.err.println("获取二级分类异常:" + e.getMessage());
|
||
return AppletControllerUtil.appletError("获取分类失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
|
||
|
||
// ==================== 师傅报价相关接口 ====================
|
||
|
||
/**
|
||
* 师傅报价接口
|
||
*
|
||
* 师傅对用户发布的需求订单进行报价
|
||
* 支持新增报价和更新已有报价
|
||
*
|
||
* 业务逻辑:
|
||
* 1. 验证师傅登录状态
|
||
* 2. 验证订单是否存在
|
||
* 3. 检查是否已经报过价
|
||
* 4. 如果已报价则更新,否则新增报价记录
|
||
*
|
||
* @param params 报价参数(orderid, money)
|
||
* @param request HTTP请求对象(需要包含token)
|
||
* @return 报价结果
|
||
*/
|
||
@PostMapping("/worker/quote/price")
|
||
public AjaxResult workerQuotePrice(@RequestBody Map<String, Object> params, HttpServletRequest request) {
|
||
try {
|
||
// 1. 验证用户登录状态
|
||
String token = request.getHeader("token");
|
||
Map<String, Object> 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("用户信息获取失败");
|
||
}
|
||
|
||
// 3. 验证必要参数
|
||
if (params == null || params.get("orderid") == null || params.get("money") == null) {
|
||
return AppletControllerUtil.appletWarning("订单ID和报价金额不能为空");
|
||
}
|
||
|
||
// 4. 获取参数
|
||
String orderId = params.get("orderid").toString();
|
||
BigDecimal quoteMoney = new BigDecimal(params.get("money").toString());
|
||
|
||
// 5. 查询订单是否存在
|
||
Order order = orderService.selectOrderByOrderId(orderId);
|
||
if (order == null) {
|
||
return AppletControllerUtil.appletWarning("订单不存在");
|
||
}
|
||
|
||
// 6. 查询用户是否已对该订单报过价
|
||
UserDemandQuotation queryParams = new UserDemandQuotation();
|
||
queryParams.setWorkerid(user.getId());
|
||
queryParams.setOrderid(orderId);
|
||
List<UserDemandQuotation> existingQuotes = userDemandQuotationService
|
||
.selectUserDemandQuotationList(queryParams);
|
||
|
||
// 7. 处理报价
|
||
UserDemandQuotation quoteRecord;
|
||
boolean isFirstQuote = false;
|
||
if (existingQuotes != null && !existingQuotes.isEmpty()) {
|
||
// 已有报价,更新
|
||
quoteRecord = existingQuotes.getFirst();
|
||
quoteRecord.setMoney(quoteMoney);
|
||
quoteRecord.setQuotationTime(new Date());
|
||
quoteRecord.setUpdateTime(new Date());
|
||
userDemandQuotationService.updateUserDemandQuotation(quoteRecord);
|
||
} else {
|
||
// 新增报价
|
||
quoteRecord = new UserDemandQuotation();
|
||
quoteRecord.setWorkerid(user.getId());
|
||
quoteRecord.setOrderid(orderId);
|
||
quoteRecord.setMoney(quoteMoney);
|
||
quoteRecord.setQuotationTime(new Date());
|
||
quoteRecord.setStatus(1L); // 设置状态为有效
|
||
quoteRecord.setWorkername(user.getName());
|
||
quoteRecord.setWorkerimage(user.getAvatar());
|
||
quoteRecord.setCreateTime(new Date());
|
||
userDemandQuotationService.insertUserDemandQuotation(quoteRecord);
|
||
isFirstQuote = true;
|
||
}
|
||
|
||
// 8. 如果是第一次报价,更新订单状态为待选择(12)
|
||
if (isFirstQuote) {
|
||
order.setStatus(12L);
|
||
orderService.updateOrder(order);
|
||
}
|
||
|
||
return AppletControllerUtil.appletSuccess("报价成功");
|
||
|
||
} catch (Exception e) {
|
||
System.err.println("师傅报价异常:" + e.getMessage());
|
||
return AppletControllerUtil.appletError("报价失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
// ==================== 拼团支付相关接口 ====================
|
||
|
||
|
||
|
||
// ==================== 用户权益相关接口 ====================
|
||
|
||
/**
|
||
* 查询用户服务金/消费金日志(支持分页)
|
||
*
|
||
* 查询用户的服务金或消费金变动日志
|
||
* 支持分页查询,按时间倒序排列
|
||
*
|
||
* @param type 日志类型(1=服务金,2=消费金)
|
||
* @param limit 每页条数(默认10)
|
||
* @param page 页码(默认1)
|
||
* @param request HTTP请求对象(需要包含token)
|
||
* @return 权益日志列表(分页格式)
|
||
*/
|
||
@GetMapping("/user/benefit/log")
|
||
public AjaxResult getUserBenefitLog(
|
||
@RequestParam(value = "type") Integer type,
|
||
@RequestParam(value = "limit", defaultValue = "10") int limit,
|
||
@RequestParam(value = "page", defaultValue = "1") int page,
|
||
HttpServletRequest request) {
|
||
try {
|
||
// 1. 验证分页参数
|
||
Map<String, Object> pageValidation = PageUtil.validatePageParams(page, limit);
|
||
if (!(Boolean) pageValidation.get("valid")) {
|
||
return AppletControllerUtil.appletWarning((String) pageValidation.get("message"));
|
||
}
|
||
|
||
// 2. 验证用户登录状态
|
||
String token = request.getHeader("token");
|
||
Map<String, Object> 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("用户信息获取失败");
|
||
}
|
||
|
||
// 4. 设置分页参数
|
||
PageHelper.startPage(page, limit);
|
||
|
||
// 5. 查询服务金/消费金日志
|
||
UserBenefitPoints query = new UserBenefitPoints();
|
||
query.setUid(user.getId());
|
||
query.setType(Long.valueOf(type));
|
||
List<UserBenefitPoints> logList = userBenefitPointsService.selectUserBenefitPointsList(query);
|
||
|
||
// 6. 获取分页信息并构建响应
|
||
TableDataInfo tableDataInfo = getDataTable(logList);
|
||
Map<String, Object> pageData = PageUtil.buildPageResponse(tableDataInfo, page, limit);
|
||
|
||
return AppletControllerUtil.appletSuccess(pageData);
|
||
|
||
} catch (Exception e) {
|
||
System.err.println("查询用户服务金/消费金日志异常:" + e.getMessage());
|
||
return AppletControllerUtil.appletError("查询服务金/消费金日志失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 小程序用户余额日志查询接口(带分页)
|
||
* 查询用户的余额变动日志
|
||
* 调用工具类方法统一处理
|
||
* @param request HTTP请求对象(需要包含token)
|
||
* @param params 查询参数,需包含 page/limit
|
||
* @return 余额日志列表
|
||
*/
|
||
@PostMapping("/user/balance/logs")
|
||
public AjaxResult getBalanceLogList(HttpServletRequest request, @RequestBody Map<String, Object> params) {
|
||
try {
|
||
// 从请求体获取分页参数
|
||
int page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1;
|
||
int limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 10;
|
||
// 验证分页参数
|
||
Map<String, Object> pageValidation = PageUtil.validatePageParams(page, limit);
|
||
if (!(Boolean) pageValidation.get("valid")) {
|
||
return AppletControllerUtil.appletWarning((String) pageValidation.get("message"));
|
||
}
|
||
// 从请求头获取token
|
||
String token = request.getHeader("token");
|
||
// 调用工具类方法统一处理(保持原有4参调用)
|
||
return AppletControllerUtil.getUserBalanceLogList(params, token, usersService, userMemnerConsumptionLogService);
|
||
} catch (Exception e) {
|
||
System.err.println("查询用户余额日志异常:" + e.getMessage());
|
||
return AppletControllerUtil.appletError("查询余额日志失败:" + e.getMessage());
|
||
}
|
||
}
|
||
}
|