17 KiB
17 KiB
阶段3:用户管理系统
阶段概述
时间: 2.5周
目标: 实现完整的用户管理功能,包括用户资产管理、VIP等级、积分系统、优惠券管理、福利屋系统等
优先级: P1 (高优先级)
详细任务清单
3.1 用户资产管理 (4天)
任务描述
实现用户多种资产的管理,包括余额、积分、吧唧币等
具体工作
- 设计用户资产数据模型
- 实现资产变更记录系统
- 实现资产查询接口
- 实现资产明细查询接口
- 添加资产安全控制
核心接口实现
用户资产概览接口
GET /api/v1/user/assets
Authorization: Bearer {token}
Response:
{
"status": 1,
"msg": "请求成功",
"data": {
"money": "100.50", // 余额
"money2": "50.00", // 积分
"integral": "200.00", // 吧唧币
"score": "300.00", // 欧气值
"frozen_money": "10.00" // 冻结金额
}
}
余额明细接口
GET /api/v1/user/money-records
Authorization: Bearer {token}
Query Parameters:
- type: 0=全部, 1=收入, 2=支出, 3=提现
- page: 页码
- limit: 每页数量
Response:
{
"status": 1,
"msg": "请求成功",
"data": {
"data": [
{
"change_money": "+10.00",
"content": "充值",
"addtime": "2024-01-01 12:00:00"
}
],
"last_page": 5
}
}
积分明细接口
GET /api/v1/user/integral-records
Authorization: Bearer {token}
Query Parameters:
- type: 0=全部, 1=收入, 2=支出
- page: 页码
- limit: 每页数量
Response:
{
"status": 1,
"msg": "请求成功",
"data": {
"data": [
{
"change_money": "+50.00",
"content": "签到奖励",
"addtime": "2024-01-01 12:00:00"
}
],
"last_page": 3
}
}
技术实现要点
// 资产变更服务
public interface IUserAssetService
{
Task<bool> ChangeMoney(int userId, decimal amount, int type, string content, int relatedId = 0);
Task<bool> ChangeIntegral(int userId, decimal amount, int type, string content, int relatedId = 0);
Task<bool> ChangeScore(int userId, decimal amount, int type, string content, int relatedId = 0);
Task<UserAssetDto> GetUserAssets(int userId);
}
// 资产变更记录
public class ProfitMoney
{
public int Id { get; set; }
public int UserId { get; set; }
public decimal ChangeMoney { get; set; }
public decimal BeforeMoney { get; set; }
public decimal AfterMoney { get; set; }
public int Type { get; set; }
public string Content { get; set; }
public int RelatedId { get; set; }
public DateTime AddTime { get; set; }
}
3.2 VIP等级系统 (3天)
任务描述
实现用户VIP等级管理,包括等级计算、升级逻辑、特权管理
具体工作
- 设计VIP等级数据模型
- 实现VIP等级计算逻辑
- 实现VIP升级检查
- 实现VIP信息查询接口
- 添加VIP特权验证
核心接口实现
VIP信息查询接口
GET /api/v1/user/vip
Authorization: Bearer {token}
Response:
{
"status": 1,
"msg": "请求成功",
"data": {
"userinfo": {
"nickname": "用户昵称",
"headimg": "https://example.com/avatar.jpg",
"vip": 2,
"upgrade_money": "500.00",
"last_vip": 3,
"jin_du": 60,
"notice": "VIP2特权说明"
},
"data": [
{
"id": 1,
"title": "VIP1",
"condition": "100.00",
"imgurl": "https://example.com/vip1.png",
"notice": "VIP1特权"
}
]
}
}
技术实现要点
// VIP等级服务
public interface IVipService
{
Task<int> CalculateVipLevel(int userId);
Task<VipInfoDto> GetVipInfo(int userId);
Task<bool> CheckVipUpgrade(int userId);
}
// VIP等级配置
public class UserVip
{
public int Id { get; set; }
public string Title { get; set; }
public decimal Condition { get; set; }
public string ImgUrl { get; set; }
public string Notice { get; set; }
public string Privileges { get; set; }
}
3.3 优惠券系统 (4天)
任务描述
实现用户优惠券管理,包括优惠券获取、使用、分享等功能
具体工作
- 设计优惠券数据模型
- 实现优惠券列表查询
- 实现优惠券详情查询
- 实现优惠券分享功能
- 实现优惠券领取功能
- 实现优惠券合成功能
核心接口实现
优惠券列表接口
GET /api/v1/user/coupons
Authorization: Bearer {token}
Query Parameters:
- type: 1=未使用, 2=已使用
- page: 页码
- limit: 每页数量
Response:
{
"status": 1,
"msg": "请求成功",
"data": {
"data": [
{
"id": 123,
"status": 1,
"level": 1,
"level_text": "特级赏券",
"level_img": "https://example.com/coupon_a.png",
"title": "特级赏券",
"num": "100.00",
"kl_num": 5,
"kl_num2": 10,
"yi_ling": 5
}
],
"y_count": 3,
"z_count": 50,
"user_integral": "200.00",
"ke_hc_count": 20,
"sun_hao": "10%"
}
}
优惠券详情接口
GET /api/v1/user/coupon/{id}
Authorization: Bearer {token}
Response:
{
"status": 1,
"msg": "请求成功",
"data": {
"id": 123,
"level": 1,
"level_text": "特级赏券",
"level_img": "https://example.com/coupon_a.png",
"share_time": "2024-01-01 12:00:00",
"num": "100.00",
"own2": "50.00",
"yl_count": 3,
"yl_integral_count": "30.00",
"share_user_nickname": "分享者",
"share_user_headimg": "https://example.com/avatar.jpg",
"yl_list": [
{
"user_id": 456,
"nickname": "领取者",
"headimg": "https://example.com/avatar2.jpg",
"l_num": "10.00",
"addtime": "2024-01-01 12:30:00",
"lucky_king": 1
}
]
}
}
优惠券分享接口
POST /api/v1/user/coupon/{id}/share
Authorization: Bearer {token}
Response:
{
"status": 1,
"msg": "分享成功"
}
优惠券领取接口
POST /api/v1/user/coupon/{id}/claim
Authorization: Bearer {token}
Response:
{
"status": 1,
"msg": "领取成功"
}
优惠券合成计算接口
POST /api/v1/user/coupon/synthesis/calculate
Authorization: Bearer {token}
Content-Type: application/json
Request:
{
"coupon_ids": "123,124,125"
}
Response:
{
"status": 1,
"msg": "请求成功",
"data": {
"coupon": {
"title": "高级赏券",
"level": 3
},
"sum_num": "1500.00",
"sh_num": "1350.00"
}
}
优惠券合成接口
POST /api/v1/user/coupon/synthesis
Authorization: Bearer {token}
Content-Type: application/json
Request:
{
"coupon_ids": "123,124,125"
}
Response:
{
"status": 1,
"msg": "合成成功"
}
3.4 任务系统 (2天)
任务描述
实现用户任务系统,包括每日任务、每周任务等
具体工作
- 设计任务数据模型
- 实现任务进度计算
- 实现任务完成检查
- 实现任务奖励发放
- 实现任务列表查询
核心接口实现
任务列表接口
GET /api/v1/user/tasks
Authorization: Bearer {token}
Response:
{
"status": 1,
"msg": "请求成功",
"data": {
"task_list": [
{
"id": 1,
"type": 1,
"cate": 1,
"title": "邀请好友注册",
"number": 5,
"z_number": 1,
"is_complete": 0,
"percentage": 60,
"ywc_count": 3
}
]
}
}
任务领取奖励接口
POST /api/v1/user/task/{id}/claim
Authorization: Bearer {token}
Response:
{
"status": 1,
"msg": "领取成功"
}
3.5 签到系统 (1天)
任务描述
实现用户每日签到功能
具体工作
- 设计签到数据模型
- 实现签到状态检查
- 实现签到奖励发放
- 实现连续签到统计
核心接口实现
签到状态查询接口
GET /api/v1/user/checkin/status
Authorization: Bearer {token}
Response:
{
"status": 1,
"msg": "请求成功",
"data": {
"is_checkin": false,
"continuous_days": 3,
"total_days": 15,
"today_reward": {
"type": "integral",
"amount": "10.00"
}
}
}
每日签到接口
POST /api/v1/user/checkin
Authorization: Bearer {token}
Response:
{
"status": 1,
"msg": "签到成功",
"data": {
"reward": {
"type": "integral",
"amount": "10.00"
},
"continuous_days": 4
}
}
3.6 推荐关系管理 (1天)
任务描述
实现用户推荐关系管理和奖励发放
具体工作
- 实现推荐关系查询
- 实现推荐奖励计算
- 实现推荐统计功能
- 实现绑定邀请码功能
核心接口实现
推荐信息查询接口
POST /api/v1/user/invitation
Authorization: Bearer {token}
Request:
{
"page": 1
}
Response:
{
"status": 1,
"msg": "请求成功",
"data": {
"referral_code": "ABC123",
"total_referrals": 10,
"total_rewards": "100.00",
"recent_referrals": [
{
"nickname": "新用户",
"headimg": "https://example.com/avatar.jpg",
"register_time": "2024-01-01 12:00:00",
"reward": "10.00"
}
]
}
}
绑定邀请码接口
POST /api/v1/user/bind-invite-code
Authorization: Bearer {token}
Request:
{
"invite_code": "ABC123"
}
Response:
{
"status": 1,
"msg": "绑定成功"
}
3.7 排行榜系统 (1天)
任务描述
实现用户排行榜功能
具体工作
- 实现邀请排行榜
- 实现消费排行榜
- 实现排行榜缓存
核心接口实现
获取排行榜接口
GET /api/v1/rank/list
Authorization: Bearer {token}
Query Parameters:
- type: 排行榜类型 (invite=邀请榜, consume=消费榜)
Response:
{
"status": 1,
"msg": "请求成功",
"data": [
{
"rank": 1,
"user_id": 123,
"nickname": "用户昵称",
"headimg": "https://example.com/avatar.jpg",
"value": "1000.00"
}
]
}
3.8 兑换码系统 (0.5天)
任务描述
实现兑换码使用功能
具体工作
- 实现兑换码验证
- 实现兑换码使用接口
- 实现兑换奖励发放
核心接口实现
使用兑换码接口
POST /api/v1/user/redeem
Authorization: Bearer {token}
Request:
{
"code": "EXCHANGE123"
}
Response:
{
"status": 1,
"msg": "兑换成功",
"data": {
"reward_type": "integral",
"reward_amount": "100.00"
}
}
3.9 福利屋系统 (2天)
任务描述
实现福利屋功能,包括福利活动展示、参与和中奖
具体工作
- 实现福利屋列表接口
- 实现福利屋详情接口
- 实现福利屋参与者查询
- 实现福利屋记录查询
- 实现用户参与记录查询
- 实现用户中奖记录查询
核心接口实现
福利屋列表接口
POST /api/v1/welfare/list
Authorization: Bearer {token}
Response:
{
"status": 1,
"msg": "请求成功",
"data": [
{
"id": 1001,
"title": "每日福利",
"imgurl": "https://example.com/welfare.jpg",
"status": 1
}
]
}
福利屋详情接口
POST /api/v1/welfare/detail
Authorization: Bearer {token}
Request:
{
"goods_id": 1001
}
Response:
{
"status": 1,
"msg": "请求成功",
"data": {
"id": 1001,
"title": "每日福利",
"imgurl": "https://example.com/welfare.jpg",
"prize_list": [],
"rules": "活动规则说明"
}
}
福利屋参与者接口
POST /api/v1/welfare/participants
Authorization: Bearer {token}
Request:
{
"goods_id": 1001,
"page": 1
}
Response:
{
"status": 1,
"msg": "请求成功",
"data": {
"data": [
{
"user_id": 123,
"nickname": "用户昵称",
"headimg": "https://example.com/avatar.jpg",
"join_time": "2024-01-01 12:00:00"
}
],
"last_page": 5
}
}
福利屋记录接口
POST /api/v1/welfare/records
Authorization: Bearer {token}
Request:
{
"goods_id": 1001,
"page": 1
}
Response:
{
"status": 1,
"msg": "请求成功",
"data": {
"data": [
{
"user_id": 123,
"nickname": "用户昵称",
"prize_title": "奖品名称",
"win_time": "2024-01-01 12:00:00"
}
],
"last_page": 3
}
}
用户福利屋参与记录接口
GET /api/v1/welfare/user/records
Authorization: Bearer {token}
Response:
{
"status": 1,
"msg": "请求成功",
"data": []
}
用户福利屋中奖记录接口
GET /api/v1/welfare/user/winning-records
Authorization: Bearer {token}
Response:
{
"status": 1,
"msg": "请求成功",
"data": []
}
数据模型设计
用户资产变更记录表
public class ProfitMoney
{
public int Id { get; set; }
public int UserId { get; set; }
public decimal ChangeMoney { get; set; }
public decimal BeforeMoney { get; set; }
public decimal AfterMoney { get; set; }
public int Type { get; set; }
public string Content { get; set; }
public int RelatedId { get; set; }
public DateTime AddTime { get; set; }
}
public class ProfitIntegral
{
public int Id { get; set; }
public int UserId { get; set; }
public decimal ChangeMoney { get; set; }
public decimal BeforeMoney { get; set; }
public decimal AfterMoney { get; set; }
public int Type { get; set; }
public string Content { get; set; }
public int RelatedId { get; set; }
public DateTime AddTime { get; set; }
}
优惠券表
public class UserCoupon
{
public int Id { get; set; }
public int UserId { get; set; }
public string Title { get; set; }
public decimal Num { get; set; }
public decimal LNum { get; set; }
public int Status { get; set; }
public int Type { get; set; }
public int Level { get; set; }
public int FromId { get; set; }
public int KlNum { get; set; }
public int KlNum2 { get; set; }
public decimal Own { get; set; }
public decimal Own2 { get; set; }
public decimal Other { get; set; }
public DateTime? ShareTime { get; set; }
public DateTime AddTime { get; set; }
public DateTime UpdateTime { get; set; }
}
任务表
public class TaskList
{
public int Id { get; set; }
public int Type { get; set; }
public int Cate { get; set; }
public string Title { get; set; }
public int Number { get; set; }
public int ZNumber { get; set; }
public int IsImportant { get; set; }
public int Sort { get; set; }
public int Status { get; set; }
}
public class UserTaskList
{
public int Id { get; set; }
public int UserId { get; set; }
public int TaskListId { get; set; }
public DateTime AddTime { get; set; }
public DateTime? DelTime { get; set; }
}
验收标准
功能验收
- 用户资产查询和变更记录正常
- VIP等级计算和升级逻辑正确
- 优惠券分享、领取、合成功能正常
- 任务系统进度计算和奖励发放正确
- 签到功能和连续签到统计正常
- 推荐关系管理功能正常
- 绑定邀请码功能正常
- 排行榜系统功能正常
- 兑换码使用功能正常
- 福利屋系统功能正常
性能验收
- 资产查询接口响应时间 < 200ms
- 优惠券列表查询响应时间 < 300ms
- 任务进度计算响应时间 < 100ms
- 支持并发操作 > 50 QPS
数据一致性验收
- 资产变更事务一致性保证
- 优惠券状态变更原子性
- 任务完成状态准确性
- VIP等级计算准确性
风险点和注意事项
技术风险
- 并发控制: 资产变更的并发安全
- 数据一致性: 多表关联操作的事务处理
- 性能优化: 大量历史记录的查询优化
- 业务逻辑: 复杂的等级和奖励计算逻辑
解决方案
- 分布式锁: 关键资产操作使用Redis锁
- 事务管理: 使用数据库事务确保一致性
- 缓存策略: 热点数据使用Redis缓存
- 单元测试: 重要业务逻辑编写完整测试
下一阶段准备
为阶段4准备的内容
- 商品分类和标签系统基础
- 库存管理系统基础
- 商品搜索和筛选基础
- 商品收藏功能基础
交接文档
- 用户资产管理系统说明
- VIP等级计算规则文档
- 优惠券系统业务流程
- 任务系统配置指南
阶段3完成标志: 用户管理系统功能完整,包括资产管理、VIP等级、优惠券、任务、签到等功能正常运行,数据一致性和安全性得到保障。