Files
GC/GC-UI/frontend/lib/models/user.dart
T
Morris ecb71ad347
PR 审核 / 后端编译 (pull_request) Waiting to run
PR 审核 / 前端检查(Flutter) (pull_request) Waiting to run
PR 审核 / 安全扫描 (pull_request) Waiting to run
feat(user): 用户系统重做——人机验证、30 天签到、主题色购买与退款、人品值
存储
- 目录改为 .GC/user/<用户名>/pw.yaml(用户名、积分、sha512 口令 + 盐)
- .GC/user/user.yaml 记住当前登录(用户名 + session token),启动自动登录
- 自动迁移旧的 .GC/user/<用户名>.yaml

注册 / 登录
- 新增算术人机验证:GET /api/user/captcha(5 分钟有效、一次性、用后即焚)
- 用户名不可重复、不能含空格、1–20 字符
- 口令只存 sha512(密码 + ":" + 随机盐),不存明文
- 新增 /api/user/logout

签到
- 30 天一循环:1–6 天 +10,第 7 天 +30,8–13 +15,第 14 天 +40,
  15–20 +20,第 21 天 +50,22–27 +25,第 28 天 +60,29 天 +40,第 30 天 +100
- 断签重置连续天数;接口返回 cycle_day / next_reward / today_signed

主题色
- 默认蓝免费,预置色 50,自定义色 150(服务端算价,不信客户端)
- 购买后 1 小时内换色退 80%,record 里存 theme_paid / theme_paid_at
- 禁止充值:积分只能签到获得

前端用户页
- 账号卡片:积分、连续天数、周期进度条、一键签到、退出登录
- 注册表单内嵌验证码(换一题、失败自动刷新)
- 人品值:0–100 随机 + 评语,每天不限次数
- 二选一:两个输入框随机选一个
- 主题色:8 个预置色 + 自定义色取色(十六进制 + 预览),积分不足上锁
- 应用主题色时同步覆盖全局强调色
2026-11-21 20:26:02 +08:00

155 lines
4.6 KiB
Dart
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.
/// 用户记录(对应后端 UserPayload)
class UserRecord {
const UserRecord({
required this.username,
required this.points,
required this.consecutiveDays,
required this.cycleDay,
required this.cycleDays,
required this.todaySigned,
required this.nextReward,
this.lastSignIn,
this.themeColor,
this.themePaid = 0,
this.refundSeconds = 0,
});
final String username;
final int points;
/// 连续签到天数(断签会重置)
final int consecutiveDays;
/// 当前处在 30 天周期的第几天(1–30)
final int cycleDay;
/// 周期长度,固定 30
final int cycleDays;
/// 今天是否已签到
final bool todaySigned;
/// 下一次签到能拿多少分
final int nextReward;
final String? lastSignIn;
/// 形如 `4A90D9`(不带 #)
final String? themeColor;
/// 当前这个颜色实际花了多少分
final int themePaid;
/// 退款窗口剩余秒数(0 表示没有可退的)
final int refundSeconds;
factory UserRecord.fromJson(Map<String, dynamic> json) {
return UserRecord(
username: json['username'] as String? ?? '',
points: (json['points'] as num?)?.toInt() ?? 0,
consecutiveDays: (json['consecutive_days'] as num?)?.toInt() ?? 0,
cycleDay: (json['cycle_day'] as num?)?.toInt() ?? 1,
cycleDays: (json['cycle_days'] as num?)?.toInt() ?? 30,
todaySigned: json['today_signed'] as bool? ?? false,
nextReward: (json['next_reward'] as num?)?.toInt() ?? 10,
lastSignIn: json['last_sign_in'] as String?,
themeColor: json['theme_color'] as String?,
themePaid: (json['theme_paid'] as num?)?.toInt() ?? 0,
refundSeconds: (json['refund_seconds'] as num?)?.toInt() ?? 0,
);
}
}
/// 签到奖励:30 天一循环,第 7/14/21/28 天给周奖励,第 30 天给满月奖励。
/// 与后端 `UserService.GetSignInReward` 保持一致。
class SignInRewards {
static const int cycleDays = 30;
static int getReward(int day) {
var d = day;
if (d < 1) d = 1;
if (d > cycleDays) d = ((d - 1) % cycleDays) + 1;
switch (d) {
case 7:
return 30;
case 14:
return 40;
case 21:
return 50;
case 28:
return 60;
case 30:
return 100;
}
if (d <= 6) return 10;
if (d <= 13) return 15;
if (d <= 20) return 20;
if (d <= 27) return 25;
return 40;
}
}
/// 主题颜色:预置色 50 分一个,自定义色 150 分一个,默认蓝免费。
class ThemeColor {
const ThemeColor({required this.name, required this.hex, required this.cost});
final String name;
final String hex;
final int cost;
/// 默认色(免费)
static const String defaultHex = '4A90D9';
/// 预置色单价
static const int presetCost = 50;
/// 自定义色单价
static const int customCost = 150;
/// 购买后 1 小时内换色可退 80%
static const Duration refundWindow = Duration(hours: 1);
static const double refundRate = 0.8;
static const List<ThemeColor> predefined = <ThemeColor>[
ThemeColor(name: '蓝色', hex: defaultHex, cost: 0),
ThemeColor(name: '红色', hex: 'E74C3C', cost: presetCost),
ThemeColor(name: '绿色', hex: '27AE60', cost: presetCost),
ThemeColor(name: '紫色', hex: '9B59B6', cost: presetCost),
ThemeColor(name: '橙色', hex: 'F39C12', cost: presetCost),
ThemeColor(name: '青色', hex: '1ABC9C', cost: presetCost),
ThemeColor(name: '粉色', hex: 'E91E63', cost: presetCost),
ThemeColor(name: '深蓝', hex: '2C3E50', cost: presetCost),
];
/// 某个十六进制颜色的价格;默认蓝 0,预置色 50,其它 150。
static int costOf(String hex) {
final h = hex.replaceAll('#', '').toUpperCase();
if (h == defaultHex) return 0;
for (final c in predefined) {
if (c.hex.toUpperCase() == h) return presetCost;
}
return customCost;
}
}
/// 人品值结果
class FortuneResult {
const FortuneResult(this.value, this.comment);
final int value;
final String comment;
/// 0–100,越高越「人品爆发」
static String commentFor(int value) {
if (value >= 96) return '欧皇附体,今天买彩票吧';
if (value >= 90) return '运气爆棚,适合干大事';
if (value >= 80) return '手气不错,稳';
if (value >= 65) return '中上水平,稍微努一下';
if (value >= 50) return '普普通通,够用';
if (value >= 35) return '有点背,低调点';
if (value >= 20) return '今天别赌任何东西';
if (value >= 8) return '极差,建议躺平';
return '非酋之王,明天再来';
}
}