feat: 赋能溢出截断 + 前端按已赋能量禁用按钮

- 单篇赋能上限由硬拒绝改为溢出截断,类似每日经验处理
- 前端弹窗时查询文章已赋能总量,>=10 禁用重赋,>=20 全部禁用
- GetEnergyInfo 支持 ?post_id= 返回 post_energize_total
- 文案精简为'赋能成功!+N 经验'等短句
This commit is contained in:
2026-06-03 00:13:03 +08:00
parent 4442da31c3
commit 1af9fba291
6 changed files with 90 additions and 30 deletions

View File

@ -8,7 +8,8 @@ import (
)
// GetEnergyInfo 获取用户域能余额和每日赋能经验状态
func (s *EnergyService) GetEnergyInfo(userID uint) (*EnergyInfo, error) {
// postID 为 0 时不查文章赋能总量
func (s *EnergyService) GetEnergyInfo(userID uint, postID uint) (*EnergyInfo, error) {
user, err := s.repo.FindUserByID(userID)
if err != nil {
return nil, err
@ -24,12 +25,21 @@ func (s *EnergyService) GetEnergyInfo(userID uint) (*EnergyInfo, error) {
dailyExp = summary.ExpEarned
}
return &EnergyInfo{
info := &EnergyInfo{
Energy: user.Energy,
DailyEnergizeExp: dailyExp,
DailyExpCap: DailyEnergizeExpCap,
DailyExpCapReached: dailyExp >= DailyEnergizeExpCap,
}, nil
}
if postID != 0 {
total, err := s.repo.SumUserPostEnergy(userID, postID)
if err == nil {
info.PostEnergizeTotal = total
}
}
return info, nil
}
// GetEnergyLogs 分页查询用户域能流水(近 N 天)