by Robin at 20241105

This commit is contained in:
Leufolium 2024-11-05 11:44:33 +08:00
parent 1d5f40b802
commit 7a4199503d
6 changed files with 60 additions and 5 deletions

View File

@ -317,7 +317,7 @@ func (s *Service) ApiUpdatePassword(ctx *gin.Context, req *loginproto.ApiUpdateP
// 3.更新密码
if err := _DefaultLogin.OpUpdate(ctx, &loginproto.OpUpdateReq{
Login: &dbstruct.Login{
Id: goproto.Int64(util.DerefInt64(login.Id)),
Id: goproto.Int64(login.GetId()),
Password: goproto.String(req.NewPassword),
WrongPswdTimes: goproto.Int64(0),
},
@ -327,6 +327,9 @@ func (s *Service) ApiUpdatePassword(ctx *gin.Context, req *loginproto.ApiUpdateP
return
}
// 4.发送通知
s.utilWriteNotifInfo(ctx, consts.SysNotifTemp_PswdChanged, login.GetMid())
return
}
@ -600,19 +603,19 @@ func (s *Service) ApiCancelAccount(ctx *gin.Context, req *accountproto.ApiCancel
return
}
if util.DerefInt64(account.Role) == consts.Streamer {
if account.GetRole() == consts.Streamer {
logger.Error("Cancellation of streamer requires manual operation")
ec = errcode.ErrCodeAccountStreamerRoleCancellation
return
}
if util.DerefInt64(account.Role) != consts.User {
if account.GetRole() != consts.User {
logger.Error("Cancellation of non-user account requires manual operation")
ec = errcode.ErrCodeAccountNonUserRoleCancellation
return
}
if util.DerefInt64(account.Status) != consts.AccountStatus_Normal {
if account.GetStatus() != consts.AccountStatus_Normal {
logger.Error("Only account in normal status is allowed to cancel")
ec = errcode.ErrCodeAccountNotInNormalStatus
return
@ -645,6 +648,9 @@ func (s *Service) ApiCancelAccount(ctx *gin.Context, req *accountproto.ApiCancel
return
}
// 发送通知
s.utilWriteNotifInfo(ctx, consts.SysNotifTemp_AcctCancellationApplied, account.GetMid())
return
}

View File

@ -3754,9 +3754,13 @@ func (s *Service) OpCreateAccountPunishment(ctx *gin.Context, req *accountpunish
return
}
// 封禁消息
// 封禁通知
s.utilWriteNotifInfo(ctx, consts.SysNotifTemp_StreamerPunished, req.AccountPunishment.GetMid(),
consts.AccountPunishmentMap[req.AccountPunishment.GetType()], req.AccountPunishment.GetEndTimeFormatAsChinese())
// 解禁通知
if !req.AccountPunishment.IsPermanent() {
s.utilWriteCrontabNotifInfo(ctx, consts.SysNotifTemp_StreamerPunishmentEnds, req.AccountPunishment.GetMid(), req.AccountPunishment.GetEndTime())
}
return
}

View File

@ -2131,3 +2131,20 @@ func (s *Service) utilWriteNotifInfo(ctx *gin.Context, notifTempId int64, objMid
})
ctx.Set("notif_builders", notifBuilders)
}
func (s *Service) utilWriteCrontabNotifInfo(ctx *gin.Context, notifTempId int64, objMid int64, pushTime int64, notifTempParams ...any) {
// 获取通知builder
notifBuilders := make([]*dbstruct.NotifBuilder, 0)
notifBuildersObj, ok := ctx.Get("notif_builders")
if ok {
notifBuilders = notifBuildersObj.([]*dbstruct.NotifBuilder)
}
notifBuilders = append(notifBuilders, &dbstruct.NotifBuilder{
TemplateId: notifTempId,
ObjMids: []int64{objMid},
PushTime: pushTime,
TemplateParams: notifTempParams,
})
ctx.Set("notif_builders", notifBuilders)
}

View File

@ -88,6 +88,13 @@ func (p *Account) GetRole() int64 {
return *p.Role
}
func (p *Account) GetStatus() int64 {
if p == nil || p.Status == nil {
return 0
}
return *p.Status
}
// StreamerAcct 用户结构
type StreamerAcct struct {
Mid *int64 `json:"mid" bson:"_id"` // 用户表Id

View File

@ -26,6 +26,13 @@ func (p *AccountPunishment) GetMid() int64 {
return *p.Mid
}
func (p *AccountPunishment) GetEndTime() int64 {
if p == nil || p.EndTime == nil {
return 0
}
return *p.EndTime
}
func (p *AccountPunishment) GetEndTimeFormatString() string {
if p == nil || p.EndTime == nil {
return ""

View File

@ -16,3 +16,17 @@ type Login struct {
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记0-否1-是
}
func (p *Login) GetId() int64 {
if p == nil || p.Id == nil {
return 0
}
return *p.Id
}
func (p *Login) GetMid() int64 {
if p == nil || p.Mid == nil {
return -1
}
return *p.Mid
}