feat: 赋能溢出截断 + 前端按已赋能量禁用按钮
- 单篇赋能上限由硬拒绝改为溢出截断,类似每日经验处理 - 前端弹窗时查询文章已赋能总量,>=10 禁用重赋,>=20 全部禁用 - GetEnergyInfo 支持 ?post_id= 返回 post_energize_total - 文案精简为'赋能成功!+N 经验'等短句
This commit is contained in:
@ -37,7 +37,7 @@ func (ec *EnergyController) Energize(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
expGained, err := ec.energySvc.Energize(uid, req.PostID, req.Amount)
|
||||
expGained, actualAmount, err := ec.energySvc.Energize(uid, req.PostID, req.Amount)
|
||||
if err != nil {
|
||||
switch err {
|
||||
case common.ErrPostNotFound:
|
||||
@ -56,21 +56,30 @@ func (ec *EnergyController) Energize(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
truncated := actualAmount != req.Amount
|
||||
common.Ok(c, gin.H{
|
||||
"exp_gained": expGained,
|
||||
"message": buildEnergizeMessage(expGained),
|
||||
"exp_gained": expGained,
|
||||
"actual_amount": actualAmount,
|
||||
"truncated": truncated,
|
||||
"message": buildEnergizeMessage(expGained, truncated),
|
||||
})
|
||||
}
|
||||
|
||||
// buildEnergizeMessage 根据获得的经验生成提示消息
|
||||
func buildEnergizeMessage(expGained int) string {
|
||||
if expGained > 0 {
|
||||
return "赋能成功!" + strconv.Itoa(expGained) + "经验已加入你的旅程。"
|
||||
func buildEnergizeMessage(expGained int, truncated bool) string {
|
||||
if truncated {
|
||||
if expGained > 0 {
|
||||
return "单篇额度已满,实际赋能部分额度,+" + strconv.Itoa(expGained) + " 经验"
|
||||
}
|
||||
return "单篇额度已满,实际赋能部分额度"
|
||||
}
|
||||
return "赋能成功!今日赋能经验奖励已达上限,对方仍会获得激励。"
|
||||
if expGained > 0 {
|
||||
return "赋能成功!+" + strconv.Itoa(expGained) + " 经验"
|
||||
}
|
||||
return "赋能成功!今日经验已满,对方仍获得激励"
|
||||
}
|
||||
|
||||
// GetEnergyInfo 获取域能余额和经验上限状态
|
||||
// GetEnergyInfo 获取域能余额和经验上限状态,支持 ?post_id= 查询文章赋能总量
|
||||
func (ec *EnergyController) GetEnergyInfo(c *gin.Context) {
|
||||
uid, _, ok := common.GetGinUser(c)
|
||||
if !ok {
|
||||
@ -78,7 +87,10 @@ func (ec *EnergyController) GetEnergyInfo(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
info, err := ec.energySvc.GetEnergyInfo(uid)
|
||||
postIDStr := c.DefaultQuery("post_id", "0")
|
||||
postID, _ := strconv.ParseUint(postIDStr, 10, 64)
|
||||
|
||||
info, err := ec.energySvc.GetEnergyInfo(uid, uint(postID))
|
||||
if err != nil {
|
||||
common.Error(c, http.StatusInternalServerError, "获取域能信息失败")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user