package sysin import ( "context" "hotgo/internal/consts" "hotgo/internal/library/dict" "hotgo/internal/model/input/form" "strings" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/os/gtime" ) type ImAbuseReasonListInp struct { form.PageReq TenantId int64 `json:"tenantId" dc:"租户ID"` TargetType string `json:"targetType" dc:"对象类型"` ReasonCode string `json:"reasonCode" dc:"原因编码"` Enabled *int `json:"enabled" dc:"启用状态"` } func (in *ImAbuseReasonListInp) Filter(ctx context.Context) (err error) { in.TargetType = strings.TrimSpace(in.TargetType) in.ReasonCode = strings.TrimSpace(in.ReasonCode) if in.TargetType != "" && !dict.HasOptionKey(consts.ImAbuseTargetTypeOptions, in.TargetType) { return gerror.New("举报对象类型不合法") } if in.Enabled != nil && !dict.HasOptionKey(consts.ImAbuseReasonEnabledOptions, *in.Enabled) { return gerror.New("启用状态不合法") } return nil } type ImAbuseReasonModel struct { TenantId int64 `json:"tenantId" dc:"租户ID"` TenantName string `json:"tenantName" dc:"租户名称"` Id int64 `json:"id" dc:"ID"` TargetType string `json:"targetType" dc:"对象类型"` ReasonCode string `json:"reasonCode" dc:"原因编码"` Label string `json:"label" dc:"展示文案"` RequiresDescription int `json:"requiresDescription" dc:"要求描述"` AllowsEvidence int `json:"allowsEvidence" dc:"允许证据"` SortOrder int `json:"sortOrder" dc:"排序"` Enabled int `json:"enabled" dc:"启用状态"` CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"` UpdatedAt *gtime.Time `json:"updatedAt" dc:"更新时间"` } type ImAbuseReasonEditInp struct { TenantId int64 `json:"tenantId" dc:"租户ID"` Id int64 `json:"id" dc:"ID"` TargetType string `json:"targetType" v:"required#对象类型不能为空" dc:"对象类型"` ReasonCode string `json:"reasonCode" v:"required#原因编码不能为空" dc:"原因编码"` Label string `json:"label" v:"required#展示文案不能为空" dc:"展示文案"` RequiresDescription int `json:"requiresDescription" dc:"要求描述"` AllowsEvidence int `json:"allowsEvidence" dc:"允许证据"` SortOrder int `json:"sortOrder" dc:"排序"` Enabled int `json:"enabled" dc:"启用状态"` } func (in *ImAbuseReasonEditInp) Filter(ctx context.Context) (err error) { in.TargetType = strings.TrimSpace(in.TargetType) in.ReasonCode = strings.TrimSpace(in.ReasonCode) in.Label = strings.TrimSpace(in.Label) if !dict.HasOptionKey(consts.ImAbuseTargetTypeOptions, in.TargetType) { return gerror.New("举报对象类型不合法") } if in.ReasonCode == "" || strings.ContainsAny(in.ReasonCode, " \t\r\n/") || len([]rune(in.ReasonCode)) > 64 { return gerror.New("原因编码不能为空,且不能包含空格或斜杠") } if in.Label == "" || len([]rune(in.Label)) > 128 { return gerror.New("展示文案不能为空且不能超过128个字符") } if !dict.HasOptionKey(consts.ImAbuseReasonEnabledOptions, in.RequiresDescription) { return gerror.New("要求描述开关不合法") } if !dict.HasOptionKey(consts.ImAbuseReasonEnabledOptions, in.AllowsEvidence) { return gerror.New("允许证据开关不合法") } if !dict.HasOptionKey(consts.ImAbuseReasonEnabledOptions, in.Enabled) { return gerror.New("启用状态不合法") } return nil } type ImAbuseReasonDeleteInp struct { TenantId int64 `json:"tenantId" dc:"租户ID"` Id int64 `json:"id" v:"required|min:1#请选择要禁用的举报原因|请选择要禁用的举报原因" dc:"ID"` } func (in *ImAbuseReasonDeleteInp) Filter(ctx context.Context) (err error) { if in.Id <= 0 { return gerror.New("请选择要禁用的举报原因") } return nil }