Files
mce/internal/service/repository.go
Victor_Jay e1d7c318ab feat: 实现域能系统
- 新增域能完整分层:EnergyLog/PostEnergizeLog/DailyExpSummary 模型、EnergyRepo、EnergyService、EnergyController/AdminEnergyController
- 支持签到获取域能(+1)、帖子赋能(-1/-2)/被赋能(+1/+2)、改名扣能(-6)/退款(+6)、删帖扣能(-2)
- 赋能单人单帖上限20域能,每日赋能获得经验上限50
- 管理员支持批量调整域能(owner)和查询域能日志(admin)
- LV0用户(exp<1)禁止签到和发帖,余额为负可签到/被赋能/删帖但不能赋能/改名
- 首次改名免费(通过HasCompletedTask判重),改名扣能在提交审核时执行
- 移除导航栏手动签到按钮,签到融入域能系统(自动签到)
- 新增个人中心域能TAB展示余额和流水日志(近7天)
- 新增帖子详情页赋能按钮(轻赋/重赋)
- 管理后台新增域能管理和域能日志页面
2026-06-01 03:32:50 +08:00

111 lines
4.0 KiB
Go
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.

package service
import (
"time"
"metazone.cc/metalab/internal/model"
)
// userAuthStore AuthService 所需的最小仓储接口ISP7 个方法)
type userAuthStore interface {
ExistsByEmail(email string) (bool, error)
Create(user *model.User) error
FindByEmail(email string) (*model.User, error)
FindByID(id uint) (*model.User, error)
Update(user *model.User) error
ExistsByUsername(username string) (bool, error)
}
// userAdminStore AdminService 所需的最小仓储接口ISP7 个方法)
type userAdminStore interface {
CountSearchUsers(keyword, role, status string) (int64, error)
SearchUsers(keyword, role, status string, offset, limit int) ([]model.User, error)
FindByIDUnscoped(userID uint) (*model.User, error)
UpdateStatus(uid uint, status string) error
SoftDelete(uid uint) error
Restore(uid uint) error
ExistsByEmailExclude(email string, excludeUID uint) (bool, error)
}
// postStore PostService 所需的最小仓储接口
type postStore interface {
Create(post *model.Post) error
FindByID(id uint) (*model.Post, error)
FindByIDWithAuthor(id uint) (*model.Post, error)
FindPageable(keyword string, offset, limit int) ([]model.Post, int64, error)
FindAdminPageable(keyword, status string, offset, limit int) ([]model.Post, int64, error)
FindByUserIDAndStatus(userID uint, status string, offset, limit int) ([]model.Post, int64, error)
FindPendingRevisions(keyword string, offset, limit int) ([]model.Post, int64, error)
Update(post *model.Post) error
SoftDelete(id uint) error
Restore(id uint) error
}
// spaceUserStore SpaceService 所需的最小用户仓储接口
type spaceUserStore interface {
FindByID(id uint) (*model.User, error)
}
// spacePostStore SpaceService 所需的最小帖子仓储接口
type spacePostStore interface {
FindByUserID(userID uint, offset, limit int) ([]model.Post, int64, error)
}
// postAdminStatStore AdminService 所需的帖子统计接口ISP2 个方法)
type postAdminStatStore interface {
CountPostsByStatus(status string) (int64, error)
CountPending() (int64, error)
}
// postNotifier PostService 所需的通知服务接口
type postNotifier interface {
NotifyPostApproved(userID uint, postTitle string, postID uint)
NotifyPostRejected(userID uint, postTitle, reason string, postID uint)
}
// userLevelStore LevelService 所需的用户仓储接口
type userLevelStore interface {
FindByID(id uint) (*model.User, error)
AddExp(userID uint, delta int) error
}
// checkInStore 签到记录仓储接口
type checkInStore interface {
FindCheckIn(userID uint, date time.Time) (*model.UserCheckIn, error)
CreateCheckIn(ci *model.UserCheckIn) error
}
// taskStore 任务完成记录仓储接口
type taskStore interface {
FindTask(userID uint, taskType string) (*model.UserTask, error)
CreateTask(task *model.UserTask) error
HasTask(userID uint, taskType string) (bool, error)
}
// levelNotifier 等级升级通知接口
type levelNotifier interface {
Create(userID uint, notifyType, title, content string, relatedID *uint) error
}
// energyStore EnergyService 所需的完整仓储接口
type energyStore interface {
FindUserByID(userID uint) (*model.User, error)
FindPostByID(postID uint) (*model.Post, error)
AddEnergy(userID uint, amount int) error
IncrPostEnergy(postID uint, amount int) error
CreateEnergyLog(log *model.EnergyLog) error
SumUserPostEnergy(userID, postID uint) (int, error)
CreateEnergizeLog(log *model.PostEnergizeLog) error
GetDailyEnergizeExp(userID uint, date time.Time) (*model.DailyExpSummary, error)
UpsertDailyExp(summary *model.DailyExpSummary) error
AddDailyExp(userID uint, date time.Time, delta int) error
ListEnergyLogsByUser(userID uint, days int, offset, limit int) ([]model.EnergyLog, error)
CountEnergyLogsByUser(userID uint, days int) (int64, error)
ListAllEnergyLogs(energyType string, offset, limit int) ([]model.EnergyLog, int64, error)
}
// energyNotifier EnergyService 所需的通知接口ISP
type energyNotifier interface {
Create(userID uint, notifyType, title, content string, relatedID *uint) error
}