修改菜单点赞相关代码
main
zxf 24 hours ago
parent 175974b438
commit 981497099a

@ -0,0 +1,13 @@
import request from '@/utils/request'
/**
* 发送一次性订阅消息
* @param params
*/
export function sendSubscribeMessageApi(params) {
return request({
url: `admin/wechat/subscribe/message/send`,
method: 'POST',
params
})
}

@ -191,6 +191,7 @@
import * as api from '@/api/pmcomplaintsuggestion.js' import * as api from '@/api/pmcomplaintsuggestion.js'
import * as ownerApi from '@/api/pmowner.js' import * as ownerApi from '@/api/pmowner.js'
import * as houseApi from '@/api/pmhouse.js' import * as houseApi from '@/api/pmhouse.js'
import * as wechatApi from '@/api/wechat.js'
import DictTag from '@/components/DictTag' import DictTag from '@/components/DictTag'
export default { export default {
dicts: ['owner_type', 'cs_type', 'submit_channel', 'suggestion_status'], dicts: ['owner_type', 'cs_type', 'submit_channel', 'suggestion_status'],
@ -367,7 +368,7 @@
}, },
// /3 // /3
handleComplaint (id) { handleComplaint (id) {
this.$confirm('确定要将该投诉/建议标记为已处理吗?', '提示', { this.$confirm('确定要将该投诉/建议标记为已处理吗', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
@ -384,6 +385,34 @@
}) })
}).catch(() => {}) }).catch(() => {})
}, },
//
testWechatMessage () {
this.$confirm('确定要发送测试微信消息吗固定测试用户obahy2fytF_nhWznyc4ihUzQtPZ0', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// API
const params = {
unionId: 'obahy2fytF_nhWznyc4ihUzQtPZ0',
templateId: 'TEMPLATE_ID', // ID
scene: '1000',
title: '测试通知',
content: '这是一条测试消息,请忽略。'
}
// 使 API
wechatApi.sendSubscribeMessageApi(params).then(res => {
if (res.code === 200) {
this.$message.success('发送成功,请查看微信!')
} else {
this.$message.error(res.message || '发送失败')
}
}).catch(err => {
this.$message.error('发送失败:' + (err.message || '未知错误'))
})
}).catch(() => {})
},
} }
} }
</script> </script>

@ -1,10 +1,20 @@
/*
* @Author: zxf 1532322479@qq.com
* @Date: 2025-06-21 12:18:44
* @LastEditors: zxf 1532322479@qq.com
* @LastEditTime: 2026-05-20 14:48:26
* @FilePath: \crmebTwo\crmeb\crmeb-admin\src\main\java\com\zbkj\admin\controller\WeChatAdminController.java
* @Description: ,`customMade`, koroFileHeader : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
package com.zbkj.admin.controller; package com.zbkj.admin.controller;
import com.zbkj.common.response.CommonResult; import com.zbkj.common.response.CommonResult;
import com.zbkj.common.response.WeChatJsSdkConfigResponse; import com.zbkj.common.response.WeChatJsSdkConfigResponse;
import com.zbkj.service.service.WechatFansService;
import com.zbkj.service.service.WechatNewService; import com.zbkj.service.service.WechatNewService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -14,6 +24,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.security.PermitAll;
/** /**
* -- admin * -- admin
* +---------------------------------------------------------------------- * +----------------------------------------------------------------------
@ -35,6 +47,9 @@ public class WeChatAdminController {
@Autowired @Autowired
private WechatNewService wechatNewService; private WechatNewService wechatNewService;
@Autowired
private WechatFansService wechatFansService;
/** /**
* js * js
*/ */
@ -45,4 +60,40 @@ public class WeChatAdminController {
public CommonResult<WeChatJsSdkConfigResponse> configJs(@RequestParam(value = "url") String url) { public CommonResult<WeChatJsSdkConfigResponse> configJs(@RequestParam(value = "url") String url) {
return CommonResult.success(wechatNewService.getJsSdkConfig(url)); return CommonResult.success(wechatNewService.getJsSdkConfig(url));
} }
/**
*
* unionIdopenId
*/
@ApiOperation(value = "发送一次性订阅消息")
@RequestMapping(value = "/subscribe/message/send", method = RequestMethod.POST)
@PermitAll
@ApiImplicitParams({
@ApiImplicitParam(name = "unionId", value = "用户unionId", dataType = "String", required = true),
@ApiImplicitParam(name = "templateId", value = "订阅消息模板ID", dataType = "String", required = true),
@ApiImplicitParam(name = "scene", value = "订阅场景值", dataType = "String", required = true),
@ApiImplicitParam(name = "title", value = "消息标题(15字以内)", dataType = "String", required = true),
@ApiImplicitParam(name = "content", value = "消息内容(200字以内)", dataType = "String", required = true),
@ApiImplicitParam(name = "url", value = "跳转链接(需ICP备案)", dataType = "String")
})
public CommonResult<Boolean> sendSubscribeMessage(@RequestParam(value = "unionId") String unionId,
@RequestParam(value = "templateId") String templateId,
@RequestParam(value = "scene") String scene,
@RequestParam(value = "title") String title,
@RequestParam(value = "content") String content,
@RequestParam(value = "url", required = false) String url){
// 通过unionId获取公众号openId
String openId = wechatFansService.getOpenIdByUnionId(unionId);
if (openId == null) {
return CommonResult.failed("未找到该用户的公众号openId");
}
// 发送订阅消息
boolean success = wechatFansService.sendSubscribeMessage(openId, templateId, scene, title, content, url);
if (success) {
return CommonResult.success(true, "发送成功");
} else {
return CommonResult.failed("发送失败");
}
}
} }

@ -229,7 +229,7 @@ public class PmDailyMenuDtlLikeController {
return CommonResult.failed("菜单明细不存在"); return CommonResult.failed("菜单明细不存在");
} }
// 通过PmDailyMenu 获取菜单日期 // 通过PmDailyMenu 获取菜单日期和餐别
PmDailyMenu menu = pmDailyMenuService.getById(menuDtl.getMenuId()); PmDailyMenu menu = pmDailyMenuService.getById(menuDtl.getMenuId());
if (menu == null) { if (menu == null) {
return CommonResult.failed("菜单不存在"); return CommonResult.failed("菜单不存在");
@ -240,6 +240,11 @@ public class PmDailyMenuDtlLikeController {
return CommonResult.failed("菜单日期不存在"); return CommonResult.failed("菜单日期不存在");
} }
String mealType = menu.getMealType();
if (StrUtil.isBlank(mealType)) {
return CommonResult.failed("餐别不存在");
}
// 检查是否已经对该菜单明细进行过评价 // 检查是否已经对该菜单明细进行过评价
LambdaQueryWrapper<PmDailyMenuDtlLike> existQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<PmDailyMenuDtlLike> existQueryWrapper = new LambdaQueryWrapper<>();
existQueryWrapper.eq(PmDailyMenuDtlLike::getUserId, userId); existQueryWrapper.eq(PmDailyMenuDtlLike::getUserId, userId);
@ -252,16 +257,17 @@ public class PmDailyMenuDtlLikeController {
return CommonResult.failed("已经对该菜品进行过" + ("1".equals(likeType) ? "点赞" : "点踩")); return CommonResult.failed("已经对该菜品进行过" + ("1".equals(likeType) ? "点赞" : "点踩"));
} }
// 检查用户在该日期的评价次数 // 检查用户在该日期、该餐别的评价次数
LambdaQueryWrapper<PmDailyMenuDtlLike> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<PmDailyMenuDtlLike> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PmDailyMenuDtlLike::getUserId, userId); queryWrapper.eq(PmDailyMenuDtlLike::getUserId, userId);
queryWrapper.eq(PmDailyMenuDtlLike::getMenuDate, menuDate); queryWrapper.eq(PmDailyMenuDtlLike::getMenuDate, menuDate);
queryWrapper.eq(PmDailyMenuDtlLike::getMealType, mealType);
queryWrapper.eq(PmDailyMenuDtlLike::getLikeType, likeType); queryWrapper.eq(PmDailyMenuDtlLike::getLikeType, likeType);
queryWrapper.eq(PmDailyMenuDtlLike::getDelFlag, "0"); queryWrapper.eq(PmDailyMenuDtlLike::getDelFlag, "0");
int count = pmDailyMenuDtlLikeService.count(queryWrapper); int count = pmDailyMenuDtlLikeService.count(queryWrapper);
if (count >= 3) { if (count >= 3) {
return CommonResult.failed("同一日期内" + ("1".equals(likeType) ? "点赞" : "点踩") + "次数已达上限3次"); return CommonResult.failed("同一日期同一餐别内" + ("1".equals(likeType) ? "点赞" : "点踩") + "次数已达上限3次");
} }
// 保存点赞/点踩记录 // 保存点赞/点踩记录
@ -269,6 +275,7 @@ public class PmDailyMenuDtlLikeController {
like.setMenuDtlId(menuDtlId); like.setMenuDtlId(menuDtlId);
like.setUserId(userId); like.setUserId(userId);
like.setMenuDate(menuDate); like.setMenuDate(menuDate);
like.setMealType(mealType);
like.setLikeType(likeType); like.setLikeType(likeType);
like.setRemark(remark); like.setRemark(remark);
like.setDelFlag("0"); like.setDelFlag("0");
@ -454,33 +461,32 @@ public class PmDailyMenuDtlLikeController {
}); });
} }
// 计算总记录数 // 分页处理
int total = rankingList.size(); int total = rankingList.size();
int fromIndex = (page - 1) * limit;
// 实现真正的分页 int toIndex = Math.min(fromIndex + limit, total);
int startIndex = (page - 1) * limit;
int endIndex = Math.min(startIndex + limit, total); if (fromIndex >= total) {
List<PmDailyMenuDtlLike> pageList; // 如果起始索引超出范围,返回空列表
if (startIndex >= total) { CommonPage<PmDailyMenuDtlLike> emptyPage = new CommonPage<>();
pageList = new ArrayList<>(); emptyPage.setList(new ArrayList<>());
} else { emptyPage.setTotal((long) total);
pageList = rankingList.subList(startIndex, endIndex); emptyPage.setPage(page);
} emptyPage.setLimit(limit);
return CommonResult.success(emptyPage);
// 构建分页对象 }
CommonPage<PmDailyMenuDtlLike> pageResult = new CommonPage<>();
pageResult.setList(pageList); List<PmDailyMenuDtlLike> pageList = rankingList.subList(fromIndex, toIndex);
pageResult.setTotal((long) total); CommonPage<PmDailyMenuDtlLike> resultPage = new CommonPage<>();
pageResult.setPage(page); resultPage.setList(pageList);
pageResult.setLimit(limit); resultPage.setTotal((long) total);
resultPage.setPage(page);
return CommonResult.success(pageResult); resultPage.setLimit(limit);
return CommonResult.success(resultPage);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return CommonResult.failed("查询失败:" + e.getMessage()); return CommonResult.failed("查询失败:" + e.getMessage());
} }
} }
} }

@ -120,11 +120,16 @@ public class PmDailyMenuDtlLike implements Serializable {
@ApiModelProperty(value = "备注") @ApiModelProperty(value = "备注")
private String remark; private String remark;
/**
* 便
*/
@ApiModelProperty(value = "餐别")
private String mealType;
/** /**
* *
*/ */
@ApiModelProperty(value = "用户名称") @ApiModelProperty(value = "用户名称")
@TableField(exist = false) @TableField(exist = false)
private String userName; private String userName;
} }

@ -16,11 +16,13 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.security.PermitAll;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -148,6 +150,7 @@ public class WeChatController {
*/ */
@ApiOperation(value = "发送一次性订阅消息") @ApiOperation(value = "发送一次性订阅消息")
@RequestMapping(value = "/subscribe/message/send", method = RequestMethod.POST) @RequestMapping(value = "/subscribe/message/send", method = RequestMethod.POST)
@PermitAll
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "unionId", value = "用户unionId", dataType = "String", required = true), @ApiImplicitParam(name = "unionId", value = "用户unionId", dataType = "String", required = true),
@ApiImplicitParam(name = "templateId", value = "订阅消息模板ID", dataType = "String", required = true), @ApiImplicitParam(name = "templateId", value = "订阅消息模板ID", dataType = "String", required = true),

Loading…
Cancel
Save