zhibo/主播中心粉丝数问题排查.md
2026-01-03 15:32:31 +08:00

170 lines
4.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 主播中心粉丝数问题排查指南
## 问题描述
主播中心页面显示粉丝数为 0即使有用户关注了该主播。
## 已修复的问题
### 1. 后端统计接口修复
**文件**: `Zhibo/zhibo-h/crmeb-front/src/main/java/com/zbkj/front/controller/StreamerController.java`
**修复内容**:
- 修正了粉丝数查询的 SQL 语句
- 原来使用了错误的字段名 `follow_user_id`
- 现在使用正确的字段 `followed_id`被关注者ID
- 添加了状态过滤条件:`follow_status IN ('1', '关注') AND is_deleted = 0`
- 同时添加了关注数统计(我关注了多少人)
**修复后的代码**:
```java
// 获取粉丝数(统计有多少人关注了我)
try {
String fansSql = "SELECT COUNT(*) FROM eb_follow_record WHERE followed_id = ? AND follow_status IN ('1', '关注') AND is_deleted = 0";
Integer fansCount = jdbcTemplate.queryForObject(fansSql, Integer.class, userId);
stats.put("fansCount", fansCount != null ? fansCount : 0);
} catch (Exception e) {
log.error("获取粉丝数失败", e);
stats.put("fansCount", 0);
}
// 获取关注数(统计我关注了多少人)
try {
String followingSql = "SELECT COUNT(*) FROM eb_follow_record WHERE follower_id = ? AND follow_status IN ('1', '关注') AND is_deleted = 0";
Integer followingCount = jdbcTemplate.queryForObject(followingSql, Integer.class, userId);
stats.put("followingCount", followingCount != null ? followingCount : 0);
} catch (Exception e) {
log.error("获取关注数失败", e);
stats.put("followingCount", 0);
}
```
## 验证步骤
### 1. 重新部署后端
```bash
# 已编译完成,需要重启服务
# 在服务器上执行:
cd /root/zhibo/Zhibo/zhibo-h/crmeb-front
./restart.sh
```
### 2. 使用 SQL 验证数据
运行 `test_streamer_stats.sql` 中的查询来验证数据:
```sql
-- 查看某个主播的粉丝数
SET @USER_ID = 1; -- 替换为实际的主播用户ID
SELECT
'粉丝数' as stat_type,
COUNT(*) as count
FROM eb_follow_record
WHERE followed_id = @USER_ID
AND follow_status IN ('1', '关注')
AND is_deleted = 0;
-- 查看谁关注了这个主播
SELECT
fr.follower_id,
u.nickname as follower_nickname,
fr.follow_status,
fr.create_time
FROM eb_follow_record fr
LEFT JOIN eb_user u ON fr.follower_id = u.uid
WHERE fr.followed_id = @USER_ID
AND fr.follow_status IN ('1', '关注')
AND fr.is_deleted = 0
ORDER BY fr.create_time DESC;
```
### 3. 测试 API 接口
使用 Postman 或 curl 测试接口:
```bash
# 获取主播统计数据
curl -X GET "http://your-server/api/front/streamer/stats" \
-H "Authorization: Bearer YOUR_TOKEN"
```
预期返回:
```json
{
"code": 200,
"message": "success",
"data": {
"nickname": "主播昵称",
"avatar": "头像URL",
"streamerLevel": 1,
"fansCount": 实际粉丝数,
"followingCount": 关注数,
"likesCount": 获赞数,
"giftsCount": 礼物数,
"totalIncome": 总收益,
"hasActiveRoom": true/false
}
}
```
### 4. Android 端测试
1. 重新启动 Android 应用
2. 登录主播账号
3. 进入主播中心
4. 查看粉丝数是否正确显示
## 可能的其他问题
### 1. 数据库中没有关注记录
检查 `eb_follow_record` 表是否有数据:
```sql
SELECT COUNT(*) FROM eb_follow_record;
```
如果没有数据,需要:
- 确认关注功能是否正常工作
- 检查关注接口是否正确插入数据
### 2. follow_status 字段值不一致
检查状态值:
```sql
SELECT DISTINCT follow_status, COUNT(*)
FROM eb_follow_record
GROUP BY follow_status;
```
如果发现状态值不一致,可以统一:
```sql
-- 将字符串状态统一为数字
UPDATE eb_follow_record SET follow_status = '1' WHERE follow_status = '关注';
UPDATE eb_follow_record SET follow_status = '0' WHERE follow_status = '取消关注';
```
### 3. Android 端缓存问题
- 清除应用数据
- 重新登录
- 或者在代码中添加强制刷新逻辑
### 4. Token 过期或权限问题
- 确认用户已登录
- 确认 Token 有效
- 确认用户是主播身份is_streamer = 1
## 相关文件
- 后端接口: `Zhibo/zhibo-h/crmeb-front/src/main/java/com/zbkj/front/controller/StreamerController.java`
- Android 页面: `android-app/app/src/main/java/com/example/livestreaming/StreamerCenterActivity.java`
- API 接口定义: `android-app/app/src/main/java/com/example/livestreaming/net/ApiService.java`
- 数据库表: `eb_follow_record`
- 测试 SQL: `test_streamer_stats.sql`
## 下一步
1. 重启后端服务
2. 运行 SQL 验证数据
3. 测试 API 接口
4. 在 Android 端验证显示
如果问题仍然存在,请检查:
- 后端日志中是否有错误信息
- Android 端网络请求是否成功
- 返回的数据格式是否正确