diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index ad543060..bb6e3d83 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -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 } diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 6b4a9ef0..14eed503 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -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 } diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index 506a10ee..1459d672 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -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) +} diff --git a/dbstruct/account.go b/dbstruct/account.go index 198c621c..8365b830 100644 --- a/dbstruct/account.go +++ b/dbstruct/account.go @@ -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 diff --git a/dbstruct/accountpunishment.go b/dbstruct/accountpunishment.go index 89a366b5..f3a8b8ff 100644 --- a/dbstruct/accountpunishment.go +++ b/dbstruct/accountpunishment.go @@ -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 "" diff --git a/dbstruct/login.go b/dbstruct/login.go index f66915be..a6b9eaf8 100644 --- a/dbstruct/login.go +++ b/dbstruct/login.go @@ -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 +}