需求与确认(用户逐项确认): - 老数据「按次 / 通行证 / 深渊」统一迁移成按日,代码里彻底删除三种模式 - 打手归属一并移除(只剩一个人,颜色与指派没有区分意义) - 盲水印做成完全不可见:只存在于 DOM / 源码,肉眼与截图都看不到 - 拼写采用更正后的 Powered by Baka春秋 - 版本号与品牌全站统一带 -L - screen_public / portal_public 保留解析但不起作用,保证旧 ini 能直接启动 - README 同步更新 品牌与版本(全站统一): - const version = "1.11.5-L":<title>、启动横幅、日志前缀 [代打台-L]、 设置页版本号、页脚版本号全部带 -L - 左上角导航品牌 代打台 → 代打台-L(登录页、初始化页同步) - 页脚新增可见署名 Powered by Baka春秋 盲水印: - _layout.html 在 <body> 起始处注入 .wm-blind 容器(含注释与 data-wm 双标记), 覆盖包括登录/初始化在内的所有页面 - app.css 用零尺寸 + 透明 + opacity:0 + clip-path:inset(50%) 四重隐藏, 同时留同名注释;不占位、不上色、不进无障碍树、不影响打印 功能移除: - 大屏:删除 handlers_screen.go、pages/screen.html、_screen_layout.html、 static/screen.css、static/screen.js、store.Stats/ScreenStats; 导航「大屏 ↗」、页脚「大屏」、设置页「大屏刷新/大屏」行、启动横幅大屏行一并删除 - 客户自查:删除 handlers_portal.go、pages/portal.html 与 .portal-*/.pcal-* 样式, 设置页「客户自助」行删除 - 多管理员:删除 handleUserCreate/Toggle/Color/UserEditPage/UserEditSave、 pages/user_form.html、store 侧 ActiveUsers/SetUserColor/SetUserActive/ UpdateUserByAdmin/NormalizeColor/AssigneePalette;设置页「管理员」整块移除, 只保留首次启动创建的那一个账户与「修改我的密码」 - 打手归属:删除 customers.assignee_id 相关读写与 UI(客户详情指派下拉、 客户表单「归属打手」、日历格左侧打手色竖条、任务卡打手标签、套餐详情客户列) - 登录页与初始化页的说明文案同步改为单账户口径(「只有一个管理员账户」 「创建后不能再添加其他管理员」),字数与 main 对齐,卡片不换行、高度不变 - 触摸小键盘:删除 3×4 键盘、⌨/触控开关、localStorage 记忆、.keypad* 样式 - 套餐计费方式:只保留按日。删除按次/通行证/深渊的 Package 与 Subscription 字段、 domain 里的 UnitCount/StateUsedUp/CycleIndex、package_form 计费方式单选与 通行证/深渊/有效期字段、日历整段色块(has-block/cell-block/season-band)、 追加次数分支、SeasonComplete/AddCount、CountActiveSubs 的次数条件 数据库迁移(幂等,Migrate 内自动执行): - normalizeLegacyData:套餐一律 unit='day' 并清 season/abyss/cycle_days/ default_validity_days/season_*;订阅清 season/abyss/cycle_days/season_done - 通行证、深渊当年就是 unit='day' 且起止日完整,仅清标记,服务区间原样保留 - 按次按「1 次 = 1 天」折算:结束日 = 开始日 + 总次数 − 1;仍缺结束日退回开始日 - 只动数据,不删表不删列:老库的 season/abyss/cycle_days/total_count/used_count 保留但不再使用,升级可逆、不会因为 DDL 失败卡住 - 新库 schema 干净:不再创建上述列,users.color / customers.assignee_id 也不创建 - 老库 ensureColumn 保留 calendar_separate / tag / archived 三项(真增量列) 兼容: - config 仍解析 screen_public / portal_public(结构体字段注明已废弃), 默认 ini 模板里改为「已废弃,写了不报错、不生效」 测试: - go vet ./... 通过;go test ./... 全部通过 (新增 TestNormalizeLegacyTypeData 验证三模式折算成按日; TestSingleUserAccount / TestSessionLifecycle 覆盖单用户与会话; 删除按次、深渊、打手颜色、多用户等已不存在的能力的用例) - 新增 scripts/smoke-lite.ps1:起隔离实例,19 个页面级请求全部 200, 已移除的 /screen、/customer、/api/screen/day 均 404, 水印/品牌/v1.11.5-L/无残留词 12 项断言通过, 真实数据下日历出现待打任务、「剩 30 天」、今天到期徽标 4 项断言通过, 本次 0 失败 README:改为 lite 版说明,删除大屏/客户自查/通行证/深渊/按次/小键盘/多用户章节, 新增「盲水印」与「与 main 分支的差异」两节(含老数据折算规则与列保留说明)。
132 lines
3.6 KiB
Go
132 lines
3.6 KiB
Go
package domain
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func d(y int, m time.Month, day int) time.Time {
|
|
return time.Date(y, m, day, 0, 0, 0, 0, time.Local)
|
|
}
|
|
|
|
func TestDayDiff(t *testing.T) {
|
|
cases := []struct {
|
|
a, b time.Time
|
|
want int
|
|
}{
|
|
{d(2026, 1, 1), d(2026, 1, 1), 0},
|
|
{d(2026, 1, 1), d(2026, 1, 31), 30},
|
|
{d(2026, 2, 28), d(2026, 3, 1), 1},
|
|
{d(2024, 2, 28), d(2024, 3, 1), 2}, // 闰年
|
|
{d(2026, 12, 31), d(2027, 1, 1), 1},
|
|
{d(2026, 1, 10), d(2026, 1, 1), -9},
|
|
}
|
|
for _, c := range cases {
|
|
if got := DayDiff(c.a, c.b); got != c.want {
|
|
t.Errorf("DayDiff(%s,%s)=%d want %d", Date(c.a), Date(c.b), got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestEvalDay(t *testing.T) {
|
|
today := d(2026, 10, 18)
|
|
cases := []struct {
|
|
name string
|
|
status string
|
|
end string
|
|
wantState string
|
|
wantLevel string
|
|
wantDays int
|
|
}{
|
|
{"进行中", "active", "2026-11-16", StateActive, LevelOK, 30},
|
|
{"今天到期", "active", "2026-10-18", StateActive, LevelToday, 1},
|
|
{"3天内", "active", "2026-10-20", StateActive, LevelWarn, 3},
|
|
{"已到期", "active", "2026-10-17", StateExpired, LevelExpired, 0},
|
|
{"暂停中", "paused", "2026-11-16", StatePaused, LevelNone, 30},
|
|
{"已结束", "closed", "2026-11-16", StateClosed, LevelNone, 30},
|
|
}
|
|
for _, c := range cases {
|
|
e := EvalSub(c.status, "2026-10-01", c.end, today, 3)
|
|
if e.State != c.wantState {
|
|
t.Errorf("%s: state=%s want %s", c.name, e.State, c.wantState)
|
|
}
|
|
if e.Level != c.wantLevel {
|
|
t.Errorf("%s: level=%s want %s", c.name, e.Level, c.wantLevel)
|
|
}
|
|
if e.RemainingDays != c.wantDays {
|
|
t.Errorf("%s: remaining=%d want %d", c.name, e.RemainingDays, c.wantDays)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestEvalDayNotStarted(t *testing.T) {
|
|
today := d(2026, 10, 18)
|
|
e := EvalSub("active", "2026-10-20", "2026-11-18", today, 3)
|
|
if e.State != StatePending {
|
|
t.Fatalf("state=%s want pending", e.State)
|
|
}
|
|
if e.RemainingDays != 32 {
|
|
t.Fatalf("remaining=%d want 32", e.RemainingDays)
|
|
}
|
|
}
|
|
|
|
// TestEvalNoEndDate 覆盖历史数据里结束日为空的兜底分支(lite 版没有按次计费)。
|
|
func TestEvalNoEndDate(t *testing.T) {
|
|
today := d(2026, 10, 18)
|
|
|
|
e := EvalSub("active", "2026-10-01", "", today, 3)
|
|
if e.Level != LevelNone || e.DaysLeft != -1 || e.RemainingDays != 0 {
|
|
t.Fatalf("level=%s daysLeft=%d remain=%d", e.Level, e.DaysLeft, e.RemainingDays)
|
|
}
|
|
if e.State != StateActive {
|
|
t.Fatalf("state=%s want active", e.State)
|
|
}
|
|
}
|
|
|
|
func TestPlanExtend(t *testing.T) {
|
|
today := d(2026, 10, 18)
|
|
|
|
// 未到期:从原结束日次日顺延,追加天数 = 新旧结束日之差
|
|
oldEnd := d(2026, 11, 16)
|
|
newEnd := d(2026, 12, 2)
|
|
p := PlanExtend(oldEnd, newEnd, today)
|
|
if Date(p.Base) != "2026-11-17" {
|
|
t.Fatalf("base=%s", Date(p.Base))
|
|
}
|
|
if p.Days != 16 {
|
|
t.Fatalf("days=%d want 16", p.Days)
|
|
}
|
|
|
|
// 已到期:从今天起算
|
|
oldEnd = d(2026, 10, 5)
|
|
newEnd = d(2026, 11, 3)
|
|
p = PlanExtend(oldEnd, newEnd, today)
|
|
if Date(p.Base) != "2026-10-18" {
|
|
t.Fatalf("base=%s", Date(p.Base))
|
|
}
|
|
if p.Days != 17 {
|
|
t.Fatalf("days=%d want 17", p.Days)
|
|
}
|
|
|
|
// 选的日期早于计算起点 → 无效
|
|
p = PlanExtend(d(2026, 11, 16), d(2026, 11, 10), today)
|
|
if !p.Backwards || p.Days != 0 {
|
|
t.Fatalf("backwards=%v days=%d", p.Backwards, p.Days)
|
|
}
|
|
}
|
|
|
|
func TestMonthHelpers(t *testing.T) {
|
|
if got := Date(MonthEnd(2026, time.February)); got != "2026-02-28" {
|
|
t.Fatalf("MonthEnd=%s", got)
|
|
}
|
|
if got := Date(MonthEnd(2024, time.February)); got != "2024-02-29" {
|
|
t.Fatalf("MonthEnd=%s", got)
|
|
}
|
|
if got := WeekdayIndex(d(2026, 10, 18)); got != 6 { // 周日
|
|
t.Fatalf("WeekdayIndex=%d want 6", got)
|
|
}
|
|
if got := WeekdayIndex(d(2026, 10, 19)); got != 0 { // 周一
|
|
t.Fatalf("WeekdayIndex=%d want 0", got)
|
|
}
|
|
}
|