You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package moments_copy
import (
"github.com/gin-gonic/gin"
"recook/internal/api/manage/moments_copy/reasons"
"recook/internal/back"
"recook/internal/dbc"
"recook/internal/model/goods"
"recook/internal/model/live"
"recook/internal/model/manage"
"recook/tools"
"strings"
)
type reviewPassOrDenyParam struct {
MomentID int `json:"momentId" validate:"numeric,required"`
Review string `json:"review" validate:"oneof=pass deny"`
ReasonID int `json:"reasonId" validate:"numeric"`
Detail string `json:"detail" validate:"max=255"` // 存在详情理由, reasonid不传或者传0
}
func Review(c *gin.Context) {
var p reviewPassOrDenyParam
err := tools.Params(&p, c)
if err != nil {
back.Fail(c, "参数错误:"+err.Error())
return
}
var moment goods.MomentsCopy
moment.ID = uint(p.MomentID)
if err = dbc.DB.First(&moment).Error; err != nil {
back.Fail(c, "m无数据错误:"+err.Error())
return
}
var passOrDeny = reasons.PassOrDeny
r, ok := passOrDeny[strings.Trim(p.Review, " ")]
if !ok {
back.Fail(c, "错误的审核")
return
}
moment.Reviewing = uint(r)
var userId = c.MustGet("Manager_ID").(uint)
var user manage.UserInfo
user.ID = userId
if err = dbc.DB.Find(&user).Error; err != nil {
back.Fail(c, "u数据错误:"+err.Error())
return
}
// 拒绝时需要填写理由
if r == 2 {
// 不传理由id 则为自己输入的理由
if p.ReasonID > 0 {
var reason goods.MomentsReason
reason.ID = p.ReasonID
if err = dbc.DB.Find(&reason).Error; err != nil {
back.Fail(c, "r数据错误:"+err.Error())
return
}
moment.ReasonID = uint(p.ReasonID)
} else {
moment.ReasonID = 0
moment.ReasonNote = p.Detail
}
}
// 审核通过
if r == 1 {
p.ReasonID = 0
p.Detail = ""
}
// 审核通过r=0 userId>0时 处理 用户动态
if moment.UserID > 0 {
dbc.DB.Where("user_id = ? and trend_id = ? and trend_type = ?", moment.UserID, moment.ID, live.TREND_TYPE_message).
Update(&live.UserTrend{
IsShow: 1,
})
}
moment.Reviewing = uint(r)
moment.ReasonID = uint(p.ReasonID)
moment.ReasonNote = p.Detail
moment.ManagerID = int(userId)
if err = dbc.DB.Save(&moment).Error; err != nil {
back.Fail(c, "更新失败"+err.Error())
return
}
back.Suc(c, "操作成功", nil)
return
}