diff --git a/api/consts/option.go b/api/consts/option.go index 106c1f3e..ba31b497 100644 --- a/api/consts/option.go +++ b/api/consts/option.go @@ -9,3 +9,7 @@ const ( TextAuditTaskUpdate_Pass = 0 TextAuditTaskUpdate_Rollback = 1 ) + +const ( + AccountPunishment_BlockFromCreatingMoment = 0 // 禁止发贴 +) diff --git a/api/consts/role.go b/api/consts/role.go index 6786a55f..dbe17db3 100644 --- a/api/consts/role.go +++ b/api/consts/role.go @@ -13,3 +13,7 @@ const ( Supportor = 2 //运营 Streamer = 3 //主播 ) + +var AccountPunishmentRoleMap = map[int64][]int64{ + AccountPunishment_BlockFromCreatingMoment: {Streamer}, +} diff --git a/api/consts/status.go b/api/consts/status.go index 2fb13e0e..7e73c599 100644 --- a/api/consts/status.go +++ b/api/consts/status.go @@ -117,3 +117,10 @@ const ( TextAuditIsAligned_No = 0 //否 TextAuditIsAligned_Yes = 1 //是 ) + +// 账号处罚状态 +const ( + AccountPunishment_Punishing = 0 //处罚中 + AccountPunishment_Finished = 1 //正常结束 + AccountPunishment_Interrupted = 2 //提前中止 +) diff --git a/api/errcode/errcode.go b/api/errcode/errcode.go index 9bf99398..f3222664 100644 --- a/api/errcode/errcode.go +++ b/api/errcode/errcode.go @@ -63,8 +63,10 @@ var ErrCodeMsgMap = map[ErrCode]string{ ErrCodeVasAlipayUniTransferFail: "支付宝提现失败", ErrCodeVasOverTodayWithdrawCnt: "今日提现次数到达上限", - ErrCodeMomentSrvFail: "动态服务错误", - ErrCodeMomentNotExist: "动态不存在", + ErrCodeMomentSrvFail: "动态服务错误", + ErrCodeMomentNotExist: "动态不存在", + ErrCodMomentBlockedFromCreatingMoment: "功能封禁中,截止时间:%s", + ErrCodMomentBlockedFromCreatingMomentPermanently: "该功能已被永久封禁", ErrCodeFootPrintSrvFail: "足迹服务错误", ErrCodeFootPrintNotExist: "足迹不存在", @@ -150,6 +152,13 @@ var ErrCodeMsgMap = map[ErrCode]string{ ErrCodeMomentAuditTaskSrvFail: "动态审核任务表服务错误", ErrCodeMomentAuditTaskNotExist: "动态审核任务表不存在", + + ErrCodeAccountPunishmentSrvFail: "账号处罚服务错误", + ErrCodeAccountPunishmentNotExist: "账号处罚不存在", + ErrCodeAccountPunishmentDuplicateKey: "该账号已有该类型处罚,若要更改处罚时长,请先中止当前处罚!", + ErrCodeAccountPunishmentHasFinished: "账号处罚已正常结束,无法执行该操作!", + ErrCodeAccountPunishmentHasBeenInterrupted: "账号处罚已提前中止,无法执行该操作!", + ErrCodeAccountPunishmentStreamerOnly: "该账号处罚行为仅能对主播进行!", } const ( @@ -204,8 +213,8 @@ const ( ErrCodeAccountSrvOk ErrCode = ErrCodeOk ErrCodeAccountSrvFail ErrCode = -6001 //账户服务错误 ErrCodeAccountNotExist ErrCode = -6002 //账户信息不存在 - ErrCodeAccountInviterNotExist ErrCode = -6003 //邀请人不存在, - ErrCodeAccountInviterIsNotAStreamer ErrCode = -6004 //邀请人非主播, + ErrCodeAccountInviterNotExist ErrCode = -6003 //邀请人不存在 + ErrCodeAccountInviterIsNotAStreamer ErrCode = -6004 //邀请人非主播 // Vas: 7xxx ErrCodeVasSrvOk ErrCode = ErrCodeOk @@ -233,9 +242,11 @@ const ( ErrCodeVasOverTodayWithdrawCnt ErrCode = -7022 // 今天提现次数到达上限 // Moment: 8xxx - ErrCodeMomentSrvOk ErrCode = ErrCodeOk - ErrCodeMomentSrvFail ErrCode = -8001 // 动态服务错误 - ErrCodeMomentNotExist ErrCode = -8002 // 动态不存在 + ErrCodeMomentSrvOk ErrCode = ErrCodeOk + ErrCodeMomentSrvFail ErrCode = -8001 // 动态服务错误 + ErrCodeMomentNotExist ErrCode = -8002 // 动态不存在 + ErrCodMomentBlockedFromCreatingMoment ErrCode = -8003 // 动态创建已被封禁 + ErrCodMomentBlockedFromCreatingMomentPermanently ErrCode = -8004 // 动态创建已被永久封禁 // FootPrint: 9xxx ErrCodeFootPrintSrvOk ErrCode = ErrCodeOk @@ -358,6 +369,16 @@ const ( ErrCodeMomentAuditTaskSrvFail ErrCode = -29001 // 动态审核任务表服务错误 ErrCodeMomentAuditTaskNotExist ErrCode = -29002 // 动态审核任务表不存在 + // AccountPunishment: 32xxx + ErrCodeAccountPunishmentSrvOk ErrCode = ErrCodeOk + ErrCodeAccountPunishmentSrvFail ErrCode = -32001 // 账号处罚服务错误 + ErrCodeAccountPunishmentNotExist ErrCode = -32002 // 账号处罚不存在 + ErrCodeAccountPunishmentExist ErrCode = -32003 // 账号处罚存在 + ErrCodeAccountPunishmentDuplicateKey ErrCode = -32004 // 账号处罚重复创建 + ErrCodeAccountPunishmentHasFinished ErrCode = -32005 // 账号处罚已正常结束 + ErrCodeAccountPunishmentHasBeenInterrupted ErrCode = -32006 // 账号处罚已提前中止 + ErrCodeAccountPunishmentStreamerOnly ErrCode = -32007 // 该账号处罚仅能对主播进行 + // Media: 60xxx ErrCodeMediaSrvOk ErrCode = ErrCodeOk ErrCodeMediaSrvFail ErrCode = -60001 // 媒体服务错误 diff --git a/api/proto/accountpunishment/proto/accountpunishment_op.go b/api/proto/accountpunishment/proto/accountpunishment_op.go new file mode 100644 index 00000000..2fd83a0c --- /dev/null +++ b/api/proto/accountpunishment/proto/accountpunishment_op.go @@ -0,0 +1,98 @@ +package proto + +import ( + "service/api/base" + "service/dbstruct" +) + +// op 创建 +type OpCreateReq struct { + base.BaseRequest + *dbstruct.AccountPunishment +} + +type OpCreateData struct { +} + +type OpCreateResp struct { + base.BaseResponse + Data *OpCreateData `json:"data"` +} + +// op 删除 +type OpDeleteReq struct { + base.BaseRequest + Id int64 `json:"id"` +} + +type OpDeleteData struct { +} + +type OpDeleteResp struct { + base.BaseResponse + Data *OpDeleteData `json:"data"` +} + +// op 更新 +type OpUpdateReq struct { + base.BaseRequest + *dbstruct.AccountPunishment +} + +type OpUpdateData struct { +} + +type OpUpdateResp struct { + base.BaseResponse + Data *OpUpdateData `json:"data"` +} + +// op 列表 +type OpListReq struct { + base.BaseRequest + Offset int `json:"offset"` + Limit int `json:"limit"` +} + +type OpListData struct { + List []*OpAccountPunishmentVO `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` +} + +type OpListResp struct { + base.BaseResponse + Data *OpListData `json:"data"` +} + +// op 解封 +type OpUnblockReq struct { + base.BaseRequest + Id *int64 `json:"id"` +} + +type OpUnblockData struct { +} + +type OpUnblockResp struct { + base.BaseResponse + Data *OpUnblockData `json:"data"` +} + +// op 查询已结束的封禁 +type OpListTerminatedReq struct { + base.BaseRequest + Offset int `json:"offset"` + Limit int `json:"limit"` +} + +type OpListTerminatedData struct { + List []*OpAccountPunishmentVO `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` +} + +type OpListTerminatedResp struct { + base.BaseResponse + Data *OpListTerminatedData `json:"data"` +} diff --git a/api/proto/accountpunishment/proto/accountpunishment_vo_op.go b/api/proto/accountpunishment/proto/accountpunishment_vo_op.go new file mode 100644 index 00000000..8f3980a1 --- /dev/null +++ b/api/proto/accountpunishment/proto/accountpunishment_vo_op.go @@ -0,0 +1,11 @@ +package proto + +import ( + accountproto "service/api/proto/account/proto" + "service/dbstruct" +) + +type OpAccountPunishmentVO struct { + Account *accountproto.OpListVO `json:"account"` + List []*dbstruct.AccountPunishment `json:"account_punishments"` +} diff --git a/api/proto/accountpunishment/proto/not_null_def_op.go b/api/proto/accountpunishment/proto/not_null_def_op.go new file mode 100644 index 00000000..e7cbdda0 --- /dev/null +++ b/api/proto/accountpunishment/proto/not_null_def_op.go @@ -0,0 +1,20 @@ +package proto + +import ( + "service/library/validator" +) + +// op 创建 +func (p *OpCreateReq) ProvideNotNullValue() (params []*validator.JsonParam) { + params = make([]*validator.JsonParam, 0) + params = append(params, validator.NewInt64PtrParam("请填写欲进行处罚的账号mid", p.AccountPunishment.Mid)) + params = append(params, validator.NewInt64PtrParam("请填写欲进行的处罚类型", p.AccountPunishment.Type)) + params = append(params, validator.NewInt64PtrParam("请填写处罚时长", p.AccountPunishment.Duration)) + return params +} + +func (p *OpUnblockReq) ProvideNotNullValue() (params []*validator.JsonParam) { + params = make([]*validator.JsonParam, 0) + params = append(params, validator.NewInt64PtrParam("请填写欲进行解封的账号处罚表id", p.Id)) + return params +} diff --git a/app/mix/controller/accountpunishment_op.go b/app/mix/controller/accountpunishment_op.go new file mode 100644 index 00000000..b8ceccb1 --- /dev/null +++ b/app/mix/controller/accountpunishment_op.go @@ -0,0 +1,95 @@ +package controller + +import ( + "service/api/consts" + "service/api/errcode" + accountpunishmentproto "service/api/proto/accountpunishment/proto" + "service/app/mix/service" + "service/bizcommon/util" + "service/library/logger" + "service/library/mediafiller" + + "github.com/gin-gonic/gin" +) + +func OpCreateAccountPunishment(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*accountpunishmentproto.OpCreateReq) + ec := service.DefaultService.OpCreateAccountPunishment(ctx, req) + if ec != errcode.ErrCodeAccountPunishmentSrvOk { + logger.Error("OpCreateAccountPunishment fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + ReplyOk(ctx, nil) +} + +func OpGetAccountPunishmentList(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*accountpunishmentproto.OpListReq) + + //设置默认页长 + if req.Limit == 0 { + req.Limit = consts.DefaultPageSize + } + + list, ec := service.DefaultService.OpGetAccountPunishmentList(ctx, req) + if ec != errcode.ErrCodeAccountPunishmentSrvOk { + logger.Error("OpGetAccountPunishmentList fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + //填充媒体切片 + objectMediaNum := 1 // 单个账号封禁服务总共1个媒体类 + mediafillables := make([]mediafiller.MediaFillable, len(list)*objectMediaNum) + for i, vo := range list { + mediafillables[objectMediaNum*i+0] = vo.Account.Avatar + } + mediafiller.FillList(ctx, mediafillables) + + data := &accountpunishmentproto.OpListData{ + List: list, + } + ReplyOk(ctx, data) +} + +func OpUnblockAccountPunishment(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*accountpunishmentproto.OpUnblockReq) + ec := service.DefaultService.OpUnblockAccountPunishment(ctx, req) + if ec != errcode.ErrCodeAccountPunishmentSrvOk { + logger.Error("OpUnblockAccountPunishment fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + ReplyOk(ctx, nil) +} + +func OpGetTerminatedAccountPunishmentList(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*accountpunishmentproto.OpListTerminatedReq) + + //设置默认页长 + if req.Limit == 0 { + req.Limit = consts.DefaultPageSize + } + + list, ec := service.DefaultService.OpGetTerminatedAccountPunishmentList(ctx, req) + if ec != errcode.ErrCodeAccountPunishmentSrvOk { + logger.Error("OpGetTerminatedAccountPunishmentList fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + //填充媒体切片 + objectMediaNum := 1 // 单个账号封禁服务总共1个媒体类 + mediafillables := make([]mediafiller.MediaFillable, len(list)*objectMediaNum) + for i, vo := range list { + mediafillables[objectMediaNum*i+0] = vo.Account.Avatar + } + mediafiller.FillList(ctx, mediafillables) + + data := &accountpunishmentproto.OpListData{ + List: list, + } + ReplyOk(ctx, data) +} diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index d6633c5d..12e0b4ac 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -19,6 +19,7 @@ import ( "service/api/consts" "service/api/errcode" accountproto "service/api/proto/account/proto" + accountpunishmentproto "service/api/proto/accountpunishment/proto" accountrelationproto "service/api/proto/accountrelation/proto" appconfigproto "service/api/proto/app_config/proto" callhistoryproto "service/api/proto/callhistory/proto" @@ -408,6 +409,13 @@ func Init(r *gin.Engine) { opAppConfigGroup.POST("update", middleware.JSONParamValidator(appconfigproto.OpUpdateReq{}), middleware.JwtAuthenticator(), OpUpdateAppConfig) opAppConfigGroup.POST("list_by_key", middleware.JSONParamValidator(appconfigproto.OpListByKeyReq{}), middleware.JwtAuthenticator(), OpGetAppConfigListByKey) + // 账号处罚 + opAccountPunishmentGroup := r.Group("/op/account_punishment", PrepareOp()) + opAccountPunishmentGroup.POST("create", middleware.JSONParamValidator(accountpunishmentproto.OpCreateReq{}), middleware.JwtAuthenticator(), OpCreateAccountPunishment) + opAccountPunishmentGroup.POST("list", middleware.JSONParamValidator(accountpunishmentproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetAccountPunishmentList) + opAccountPunishmentGroup.POST("unblock", middleware.JSONParamValidator(accountpunishmentproto.OpUnblockReq{}), middleware.JwtAuthenticator(), OpUnblockAccountPunishment) + opAccountPunishmentGroup.POST("list_terminated", middleware.JSONParamValidator(accountpunishmentproto.OpListTerminatedReq{}), middleware.JwtAuthenticator(), OpGetTerminatedAccountPunishmentList) + // 账号相关 //accountGroup := r.Group("/account") @@ -443,6 +451,14 @@ func ReplyErrCodeMsg(ctx *gin.Context, ec errcode.ErrCode) { }) } +func ReplyErrCodeMsgAndDetail(ctx *gin.Context, ec errcode.ErrCode, params ...any) { + ctx.AbortWithStatusJSON(http.StatusOK, base.BaseResponse{ + Ret: consts.RetCodeFail, + ErrCode: ec, + Msg: fmt.Sprintf(errcode.ErrCodeMsgMap[ec], params...), + }) +} + func ReplyJsonError(ctx *gin.Context, code int, msg string) { ctx.AbortWithStatusJSON(code, base.BaseResponse{ Ret: consts.RetCodeFail, diff --git a/app/mix/controller/moment_api.go b/app/mix/controller/moment_api.go index 00314360..fca17ce3 100644 --- a/app/mix/controller/moment_api.go +++ b/app/mix/controller/moment_api.go @@ -14,7 +14,12 @@ import ( func ApiCreateMoment(ctx *gin.Context) { req := ctx.MustGet("client_req").(*momentproto.ApiCreateReq) - ec := service.DefaultService.ApiCreateMoment(ctx, req) + ec, acctPunEndTime := service.DefaultService.ApiCreateMoment(ctx, req) + if ec == errcode.ErrCodMomentBlockedFromCreatingMoment { + logger.Error("ApiCreateMoment fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsgAndDetail(ctx, ec, acctPunEndTime) + return + } if ec != errcode.ErrCodeMomentSrvOk { logger.Error("ApiCreateMoment fail, req: %v, ec: %v", util.ToJson(req), ec) ReplyErrCodeMsg(ctx, ec) diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index 7ff1516f..346a42fc 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -15,6 +15,7 @@ import ( "go.mongodb.org/mongo-driver/bson" accountproto "service/api/proto/account/proto" + accountpunishmentproto "service/api/proto/accountpunishment/proto" accountrelationproto "service/api/proto/accountrelation/proto" appconfigproto "service/api/proto/app_config/proto" callhistoryproto "service/api/proto/callhistory/proto" @@ -154,6 +155,9 @@ const ( DBMomentAuditTask = "moment_audit_task" COLMomentAuditTask = "moment_audit_task" + + DBAccountPunishment = "account_punishment" + COLAccountPunishment = "account_punishment" ) // 商品表 @@ -360,6 +364,11 @@ func (m *Mongo) getColMomentAuditTask() *qmgo.Collection { return m.clientMix.Database(DBMomentAuditTask).Collection(COLMomentAuditTask) } +// 账号处罚表 +func (m *Mongo) getColAccountPunishment() *qmgo.Collection { + return m.clientMix.Database(DBAccountPunishment).Collection(COLAccountPunishment) +} + // 商品相关 func (m *Mongo) CreateProduct(ctx *gin.Context, product *dbstruct.Product) error { col := m.getColProduct() @@ -3297,3 +3306,113 @@ func (m *Mongo) GetAppConfigListByKey(ctx *gin.Context, req *appconfigproto.OpLi } return appconfig, err } + +// 账号处罚相关 +func (m *Mongo) CreateAccountPunishment(ctx *gin.Context, accountpunishment *dbstruct.AccountPunishment) error { + col := m.getColAccountPunishment() + _, err := col.InsertOne(ctx, accountpunishment) + return err +} + +func (m *Mongo) UpdateAccountPunishment(ctx *gin.Context, accountpunishment *dbstruct.AccountPunishment) error { + col := m.getColAccountPunishment() + set := util.EntityToM(accountpunishment) + set["ut"] = time.Now().Unix() + up := qmgo.M{ + "$set": set, + } + err := col.UpdateId(ctx, accountpunishment.Id, up) + return err +} + +func (m *Mongo) DeleteAccountPunishment(ctx *gin.Context, id int64) error { + col := m.getColAccountPunishment() + update := qmgo.M{ + "$set": qmgo.M{ + "del_flag": 1, + }, + } + err := col.UpdateId(ctx, id, update) + return err +} + +func (m *Mongo) GetAccountPunishmentList(ctx *gin.Context, req *accountpunishmentproto.OpListReq) ([]*dbstruct.AccountPunishment, error) { + list := make([]*dbstruct.AccountPunishment, 0) + col := m.getColAccountPunishment() + query := qmgo.M{ + "status": qmgo.M{ + "$ne": consts.AccountPunishment_Interrupted, + }, + "end_time": qmgo.M{ + "$gt": time.Now().Unix(), + }, + "del_flag": 0, + } + err := col.Find(ctx, query).Sort("-ct").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) + if err == qmgo.ErrNoSuchDocuments { + err = nil + return list, err + } + return list, err +} + +func (m *Mongo) GetAccountPunishmentListById(ctx *gin.Context, id int64) (*dbstruct.AccountPunishment, error) { + accountpunishment := &dbstruct.AccountPunishment{} + col := m.getColAccountPunishment() + query := qmgo.M{ + "_id": id, + "del_flag": 0, + } + err := col.Find(ctx, query).One(&accountpunishment) + if err == qmgo.ErrNoSuchDocuments { + err = nil + return nil, err + } + return accountpunishment, err +} + +func (m *Mongo) GetAccountPunishmentListByMidAndType(ctx *gin.Context, mid int64, typ int64) (*dbstruct.AccountPunishment, error) { + accountpunishment := &dbstruct.AccountPunishment{} + col := m.getColAccountPunishment() + query := qmgo.M{ + "mid": mid, + "type": typ, + "status": qmgo.M{ + "$ne": consts.AccountPunishment_Interrupted, + }, + "end_time": qmgo.M{ + "$gt": time.Now().Unix(), + }, + "del_flag": 0, + } + err := col.Find(ctx, query).One(&accountpunishment) + if err == qmgo.ErrNoSuchDocuments { + err = nil + return nil, err + } + return accountpunishment, err +} + +func (m *Mongo) GetTerminatedAccountPunishmentList(ctx *gin.Context, req *accountpunishmentproto.OpListTerminatedReq) ([]*dbstruct.AccountPunishment, error) { + list := make([]*dbstruct.AccountPunishment, 0) + col := m.getColAccountPunishment() + query := qmgo.M{ + "$or": []qmgo.M{ + { + "status": consts.AccountPunishment_Interrupted, + }, + { + "end_time": qmgo.M{ + "$lte": time.Now().Unix(), + }, + }, + }, + "del_flag": 0, + } + err := col.Find(ctx, query).Sort("-ct").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) + if err == qmgo.ErrNoSuchDocuments { + err = nil + return list, err + } + return list, err +} diff --git a/app/mix/dao/mongo_idseq.go b/app/mix/dao/mongo_idseq.go index 372f962f..2919d232 100644 --- a/app/mix/dao/mongo_idseq.go +++ b/app/mix/dao/mongo_idseq.go @@ -45,6 +45,9 @@ const ( DBFeedbackIdSeq = "feedback_id_seq" COLFeedbackIdSeq = "feedback_id_seq" + + DBAccountPunishmentIdSeq = "account_punishment_id_seq" + COLAccountPunishmentIdSeq = "account_punishment_id_seq" ) // UserIdSeq序列表 @@ -107,6 +110,11 @@ func (m *Mongo) getColFeedbackIdSeq() *qmgo.Collection { return m.clientMix.Database(DBFeedbackIdSeq).Collection(COLFeedbackIdSeq) } +// AccountPunishmentIdSeq序列表 +func (m *Mongo) getColAccountPunishmentIdSeq() *qmgo.Collection { + return m.clientMix.Database(DBAccountPunishmentIdSeq).Collection(COLAccountPunishmentIdSeq) +} + // account_id发号器 func (m *Mongo) GetAndUpdateAccountIdSeq(ctx *gin.Context) (accountIdSeq *dbstruct.AccountIdSeq, err error) { col := m.getColAccountIdSeq() @@ -345,3 +353,22 @@ func (m *Mongo) GetAndUpdateMediaSeq(ctx *gin.Context) (mediaIdSeq *dbstruct.Med return &mediaIdSeqInstance, err } + +// accountpunishment_id发号器 +func (m *Mongo) GetAndUpdateAccountPunishmentIdSeq(ctx *gin.Context) (accountpunishmentIdSeq *dbstruct.AccountPunishmentIdSeq, err error) { + col := m.getColAccountPunishmentIdSeq() + + change := qmgo.Change{ + Update: qmgo.M{"$inc": qmgo.M{"seq": 1}}, + Upsert: true, + ReturnNew: false, + } + + accountpunishmentIdSeqInstance := dbstruct.AccountPunishmentIdSeq{} + if err = col.Find(ctx, qmgo.M{"_id": "account_punishment_id_seq_id"}).Apply(change, &accountpunishmentIdSeqInstance); err != nil { + logger.Error("change error : %v", err) + return + } + + return &accountpunishmentIdSeqInstance, err +} diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index cfafedb5..01e88544 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -1574,12 +1574,23 @@ func (s *Service) ApiGetContactCustomerServiceSessionListByMid(ctx *gin.Context, } // Moment -func (s *Service) ApiCreateMoment(ctx *gin.Context, req *momentproto.ApiCreateReq) (ec errcode.ErrCode) { +func (s *Service) ApiCreateMoment(ctx *gin.Context, req *momentproto.ApiCreateReq) (ec errcode.ErrCode, acctPunEndTime string) { ec = errcode.ErrCodeMomentSrvOk req.Moment.Mid = goproto.Int64(req.BaseRequest.Mid) + var accountpunishment *dbstruct.AccountPunishment + if ec, accountpunishment = s.ApiCreateMomentBusinessValidate(ctx, req); ec != errcode.ErrCodeMomentSrvOk { + if ec == errcode.ErrCodeAccountPunishmentExist { + if accountpunishment.IsPermanent() { + ec = errcode.ErrCodMomentBlockedFromCreatingMomentPermanently + return + } else { + ec = errcode.ErrCodMomentBlockedFromCreatingMoment + acctPunEndTime = accountpunishment.GetEndTimeFormatString() + return + } - if ec = s.ApiCreateMomentBusinessValidate(ctx, req); ec != errcode.ErrCodeMomentSrvOk { + } return } diff --git a/app/mix/service/apiservice_business_validation.go b/app/mix/service/apiservice_business_validation.go index a4a698a0..c7419c52 100644 --- a/app/mix/service/apiservice_business_validation.go +++ b/app/mix/service/apiservice_business_validation.go @@ -524,16 +524,18 @@ func (s *Service) ApiGetStreamerWxIdBusinessValidate(ctx *gin.Context, req *stre return } -func (s *Service) ApiCreateMomentBusinessValidate(ctx *gin.Context, req *momentproto.ApiCreateReq) (ec errcode.ErrCode) { +func (s *Service) ApiCreateMomentBusinessValidate(ctx *gin.Context, req *momentproto.ApiCreateReq) (ec errcode.ErrCode, accountpunishment *dbstruct.AccountPunishment) { ec = errcode.ErrCodeMomentSrvOk resultList := businessvalidator.NewAuthBusinessValidator(ctx, req). + EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, consts.AccountPunishment_BlockFromCreatingMoment, _DefaultAccountPunishment.OpListByMidAndType). QueryMomentCreateTimes(_DefaultMomentCreateTimes.OpGetAndUpdate, req.GetBaseRequest().Mid). EnsureMomentCreateTimesNotReachedDailyUpperbound(). Validate(). Collect() ec, _ = resultList[0].(errcode.ErrCode) - if ec != errcode.ErrCodeLoginSrvOk { + accountpunishment, _ = resultList[3].(*dbstruct.AccountPunishment) + if ec != errcode.ErrCodeOk { logger.Error("ApiCreateMomentBusinessValidate business validation failed!") return } diff --git a/app/mix/service/business_validator/auth.go b/app/mix/service/business_validator/auth.go index 194d5364..ad49d5a5 100644 --- a/app/mix/service/business_validator/auth.go +++ b/app/mix/service/business_validator/auth.go @@ -10,6 +10,7 @@ import ( "service/dbstruct" "service/library/apollo" "service/library/logger" + "time" "github.com/gin-gonic/gin" goproto "google.golang.org/protobuf/proto" @@ -25,6 +26,7 @@ type AuthBusinessValidator struct { account *dbstruct.Account accountrelation *dbstruct.AccountRelation momentCreateTimes *dbstruct.MomentCreateTimes + accountpunishment *dbstruct.AccountPunishment } func NewAuthBusinessValidator(ctx *gin.Context, req any) *AuthBusinessValidator { @@ -297,6 +299,86 @@ func (l *AuthBusinessValidator) EnsureMomentCreateTimesNotReachedDailyUpperbound return l } +func (l *AuthBusinessValidator) EnsureAccountPunishmentHasNotTerminated(id int64, QueryFunc func(ctx *gin.Context, id int64) (*dbstruct.AccountPunishment, error)) *AuthBusinessValidator { + l.oplist = append(l.oplist, func() { + accountpunishment, err := QueryFunc(l.ctx, id) + if err != nil { + logger.Error("Query account punishment failed, err: %v", err) + l.ec = errcode.ErrCodeAccountPunishmentSrvFail + return + } + if accountpunishment == nil { + logger.Error("No account punishment was found") + l.ec = errcode.ErrCodeAccountPunishmentNotExist + return + } + if util.DerefInt64(accountpunishment.Status) == consts.AccountPunishment_Interrupted { + l.ec = errcode.ErrCodeAccountPunishmentHasBeenInterrupted + return + } + if util.DerefInt64(accountpunishment.EndTime) <= time.Now().Unix() { + l.ec = errcode.ErrCodeAccountPunishmentHasFinished + return + } + }) + return l +} + +func (l *AuthBusinessValidator) EnsureAccountPunishmentMatchesRoleOfTarget(uid int64, typ int64, QueryFunc func(ctx *gin.Context, req *accountproto.OpListByMidReq) (*dbstruct.Account, error)) *AuthBusinessValidator { + l.oplist = append(l.oplist, func() { + acct, err := QueryFunc(l.ctx, &accountproto.OpListByMidReq{ + Mid: goproto.Int64(uid), + }) + if err != nil { + logger.Error("Query account failed, err: %v", err) + l.ec = errcode.ErrCodeAccountSrvFail + return + } + if acct == nil { + logger.Error("No account entity was found") + l.ec = errcode.ErrCodeAccountNotExist + return + } + acctRole := util.DerefInt64(acct.Role) + pass := false + for _, role := range consts.AccountPunishmentRoleMap[typ] { + if acctRole == role { + pass = true + break + } + } + if !pass { + switch typ { + case consts.AccountPunishment_BlockFromCreatingMoment: + l.ec = errcode.ErrCodeAccountPunishmentStreamerOnly + default: + l.ec = errcode.ErrCodeAccountPunishmentSrvFail + } + } + + }) + return l +} + +func (l *AuthBusinessValidator) EnsureSuchAccountPunishmentNotExist(uid int64, typ int64, QueryFunc func(ctx *gin.Context, mid int64, typ int64) (*dbstruct.AccountPunishment, error)) *AuthBusinessValidator { + l.oplist = append(l.oplist, func() { + accountpunishment, err := QueryFunc(l.ctx, uid, typ) + if err != nil { + logger.Error("Query account punishment failed, err: %v", err) + l.ec = errcode.ErrCodeAccountPunishmentSrvFail + return + } + + if accountpunishment != nil { + l.ec = errcode.ErrCodeAccountPunishmentExist + l.accountpunishment = accountpunishment + return + } + + }) + return l +} + // 执行校验 func (a *AuthBusinessValidator) Validate() *AuthBusinessValidator { a.BusinessValidateStream.Validate() @@ -308,5 +390,6 @@ func (a *AuthBusinessValidator) Collect() []any { resultList[0] = a.ec resultList[1] = a.account resultList[2] = a.accountrelation + resultList[3] = a.accountpunishment return resultList } diff --git a/app/mix/service/logic/accountpunishment.go b/app/mix/service/logic/accountpunishment.go new file mode 100644 index 00000000..45403e9f --- /dev/null +++ b/app/mix/service/logic/accountpunishment.go @@ -0,0 +1,103 @@ +package logic + +import ( + "service/api/consts" + accountpunishmentproto "service/api/proto/accountpunishment/proto" + "service/app/mix/dao" + "service/bizcommon/util" + "service/dbstruct" + "service/library/logger" + "time" + + "github.com/gin-gonic/gin" + goproto "google.golang.org/protobuf/proto" +) + +type AccountPunishment struct { + store *dao.Store +} + +func NewAccountPunishment(store *dao.Store) (a *AccountPunishment) { + a = &AccountPunishment{ + store: store, + } + return +} + +func (p *AccountPunishment) OpCreate(ctx *gin.Context, req *accountpunishmentproto.OpCreateReq) error { + + //产生id + accountpunishmentIdSeq, err := p.store.GetAndUpdateAccountPunishmentIdSeq(ctx) + if err != nil { + logger.Error("GetAndUpdateAccountPunishmentIdSeq failed : %v", err) + return err + } + + nowTime := time.Now().Unix() + req.AccountPunishment.Id = goproto.Int64(accountpunishmentIdSeq.Seq) + req.AccountPunishment.Status = goproto.Int64(consts.AccountPunishment_Punishing) + req.AccountPunishment.EndTime = goproto.Int64(nowTime + util.DerefInt64(req.Duration)) + req.AccountPunishment.Ct = goproto.Int64(nowTime) + req.AccountPunishment.Ut = goproto.Int64(nowTime) + req.AccountPunishment.DelFlag = goproto.Int64(consts.Exist) + err = p.store.CreateAccountPunishment(ctx, req.AccountPunishment) + if err != nil { + logger.Error("CreateAccountPunishment fail, err: %v", err) + return err + } + return nil +} + +func (p *AccountPunishment) OpUpdate(ctx *gin.Context, req *accountpunishmentproto.OpUpdateReq) error { + err := p.store.UpdateAccountPunishment(ctx, req.AccountPunishment) + if err != nil { + logger.Error("UpdateAccountPunishment fail, err: %v", err) + return err + } + return nil +} + +func (p *AccountPunishment) OpDelete(ctx *gin.Context, id int64) error { + err := p.store.DeleteAccountPunishment(ctx, id) + if err != nil { + logger.Error("DeleteAccountPunishment fail, err: %v", err) + return err + } + return nil +} + +func (p *AccountPunishment) OpList(ctx *gin.Context, req *accountpunishmentproto.OpListReq) ([]*dbstruct.AccountPunishment, error) { + list, err := p.store.GetAccountPunishmentList(ctx, req) + if err != nil { + logger.Error("GetAccountPunishmentList fail, err: %v", err) + return make([]*dbstruct.AccountPunishment, 0), err + } + return list, nil +} + +func (p *AccountPunishment) OpListTerminated(ctx *gin.Context, req *accountpunishmentproto.OpListTerminatedReq) ([]*dbstruct.AccountPunishment, error) { + list, err := p.store.GetTerminatedAccountPunishmentList(ctx, req) + if err != nil { + logger.Error("GetTerminatedAccountPunishmentList fail, err: %v", err) + return make([]*dbstruct.AccountPunishment, 0), err + } + return list, nil +} + +func (p *AccountPunishment) OpListById(ctx *gin.Context, id int64) (*dbstruct.AccountPunishment, error) { + accountpunishment, err := p.store.GetAccountPunishmentListById(ctx, id) + if err != nil { + logger.Error("GetAccountPunishmentListById fail, err: %v", err) + return nil, err + } + return accountpunishment, nil +} + +func (p *AccountPunishment) OpListByMidAndType(ctx *gin.Context, mid int64, typ int64) (*dbstruct.AccountPunishment, error) { + accountpunishment, err := p.store.GetAccountPunishmentListByMidAndType(ctx, mid, typ) + if err != nil { + logger.Error("GetAccountPunishmentListByMid fail, err: %v", err) + return nil, err + } + return accountpunishment, nil +} diff --git a/app/mix/service/opservice_business_validation.go b/app/mix/service/opservice_business_validation.go index 2b15ca81..670abb84 100644 --- a/app/mix/service/opservice_business_validation.go +++ b/app/mix/service/opservice_business_validation.go @@ -3,6 +3,7 @@ package service import ( "service/api/errcode" accountproto "service/api/proto/account/proto" + accountpunishmentproto "service/api/proto/accountpunishment/proto" accountrelationproto "service/api/proto/accountrelation/proto" appconfigproto "service/api/proto/app_config/proto" callhistoryproto "service/api/proto/callhistory/proto" @@ -22,6 +23,7 @@ import ( userwxaddcheckproto "service/api/proto/userwxaddcheck/proto" vericodeproto "service/api/proto/vericode/proto" businessvalidator "service/app/mix/service/business_validator" + "service/bizcommon/util" "service/dbstruct" "service/library/logger" "service/library/mycrypto" @@ -1334,3 +1336,77 @@ func (s *Service) OpGetAppConfigListByKeyBusinessValidate(ctx *gin.Context, req } return } + +func (s *Service) OpCreateAccountPunishmentBusinessValidate(ctx *gin.Context, req *accountpunishmentproto.OpCreateReq) (ec errcode.ErrCode) { + ec = errcode.ErrCodeAccountPunishmentSrvOk + + uid := util.DerefInt64(req.AccountPunishment.Mid) + typ := util.DerefInt64(req.AccountPunishment.Type) + + // 1.业务校验 + result := businessvalidator.NewAuthBusinessValidator(ctx, req). + QueryAccount(_DefaultAccount.OpListByMid). + EnsureAccountExist(). + EnsureIsOpRole(). + EnsureAccountPunishmentMatchesRoleOfTarget(uid, typ, _DefaultAccount.OpListByMid). + EnsureSuchAccountPunishmentNotExist(uid, typ, _DefaultAccountPunishment.OpListByMidAndType). + Validate(). + Collect() + if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk { + logger.Error("OpCreateAccountPunishment business validation failed") + return + } + return +} + +func (s *Service) OpUnblockAccountPunishmentBusinessValidate(ctx *gin.Context, req *accountpunishmentproto.OpUnblockReq) (ec errcode.ErrCode) { + ec = errcode.ErrCodeAccountPunishmentSrvOk + + // 1.业务校验 + result := businessvalidator.NewAuthBusinessValidator(ctx, req). + QueryAccount(_DefaultAccount.OpListByMid). + EnsureAccountExist(). + EnsureIsOpRole(). + EnsureAccountPunishmentHasNotTerminated(util.DerefInt64(req.Id), _DefaultAccountPunishment.OpListById). + Validate(). + Collect() + if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk { + logger.Error("OpUnblockAccountPunishment business validation failed") + return + } + return +} + +func (s *Service) OpGetAccountPunishmentListBusinessValidate(ctx *gin.Context, req *accountpunishmentproto.OpListReq) (ec errcode.ErrCode) { + ec = errcode.ErrCodeAccountPunishmentSrvOk + + // 1.业务校验 + result := businessvalidator.NewAuthBusinessValidator(ctx, req). + QueryAccount(_DefaultAccount.OpListByMid). + EnsureAccountExist(). + EnsureIsOpRole(). + Validate(). + Collect() + if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk { + logger.Error("OpGetAccountPunishmentList business validation failed") + return + } + return +} + +func (s *Service) OpGetTerminatedAccountPunishmentListBusinessValidate(ctx *gin.Context, req *accountpunishmentproto.OpListTerminatedReq) (ec errcode.ErrCode) { + ec = errcode.ErrCodeAccountPunishmentSrvOk + + // 1.业务校验 + result := businessvalidator.NewAuthBusinessValidator(ctx, req). + QueryAccount(_DefaultAccount.OpListByMid). + EnsureAccountExist(). + EnsureIsOpRole(). + Validate(). + Collect() + if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk { + logger.Error("OpGetAccountPunishmentList business validation failed") + return + } + return +} diff --git a/app/mix/service/service.go b/app/mix/service/service.go index be24447f..96039331 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -52,6 +52,8 @@ import ( "service/library/payclients/wxpaycli" "service/library/redis" + accountpunishmentproto "service/api/proto/accountpunishment/proto" + "go.mongodb.org/mongo-driver/mongo" goproto "google.golang.org/protobuf/proto" @@ -100,6 +102,7 @@ var ( _DefaultXxlJob *logic.XxlJob _DefaultAppConfig *logic.AppConfig _DefaultMomentAuditTask *logic.MomentAuditTask + _DefaultAccountPunishment *logic.AccountPunishment ) type Service struct { @@ -176,6 +179,7 @@ func (s *Service) Init(c any) (err error) { _DefaultXxlJob = logic.NewXxlJob(store, cfg.XxlJob) _DefaultAppConfig = logic.NewAppConfig(store) _DefaultMomentAuditTask = logic.NewMomentAuditTask(store) + _DefaultAccountPunishment = logic.NewAccountPunishment(store) return } @@ -2883,3 +2887,170 @@ func (s *Service) OpGetAppConfigListByKey(ctx *gin.Context, req *appconfigproto. } return } + +// AccountPunishment +func (s *Service) OpCreateAccountPunishment(ctx *gin.Context, req *accountpunishmentproto.OpCreateReq) (ec errcode.ErrCode) { + ec = errcode.ErrCodeAccountPunishmentSrvOk + + if ec = s.OpCreateAccountPunishmentBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountPunishmentSrvOk { + if ec == errcode.ErrCodeAccountPunishmentExist { + ec = errcode.ErrCodeAccountPunishmentDuplicateKey + return + } + return + } + + err := _DefaultAccountPunishment.OpCreate(ctx, req) + if err != nil { + logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeAccountPunishmentSrvFail + return + } + return +} + +func (s *Service) OpUnblockAccountPunishment(ctx *gin.Context, req *accountpunishmentproto.OpUnblockReq) (ec errcode.ErrCode) { + ec = errcode.ErrCodeAccountPunishmentSrvOk + + if ec = s.OpUnblockAccountPunishmentBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountPunishmentSrvOk { + return + } + + err := _DefaultAccountPunishment.OpUpdate(ctx, &accountpunishmentproto.OpUpdateReq{ + AccountPunishment: &dbstruct.AccountPunishment{ + Id: req.Id, + Status: goproto.Int64(consts.AccountPunishment_Interrupted), + }, + }) + if err == qmgo.ErrNoSuchDocuments { + ec = errcode.ErrCodeAccountPunishmentNotExist + err = nil + return + } + if err != nil { + logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeAccountPunishmentSrvFail + return + } + return +} + +func (s *Service) OpGetAccountPunishmentList(ctx *gin.Context, req *accountpunishmentproto.OpListReq) (volist []*accountpunishmentproto.OpAccountPunishmentVO, ec errcode.ErrCode) { + ec = errcode.ErrCodeAccountPunishmentSrvOk + + if ec = s.OpGetAccountPunishmentListBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountPunishmentSrvOk { + return + } + + list, err := _DefaultAccountPunishment.OpList(ctx, req) + if err != nil { + logger.Error("OpGetAccountPunishmentList fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeAccountPunishmentSrvFail + return + } + + // 获取mid的set + midMap := make(map[int64]*dbstruct.Account) + midSet := make([]int64, 0) + for _, v := range list { + mid := util.DerefInt64(v.Mid) + if midMap[mid] != nil { + continue + } else { + midSet = append(midSet, mid) + midMap[mid] = &dbstruct.Account{} + } + } + + // 查询mid的map + acctMap, err := _DefaultAccount.GetAccountMapByMids(ctx, midSet) + if err != nil { + logger.Error("GetAccountMapByMids fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeAccountSrvFail + return + } + + // 组装vo + volist = make([]*accountpunishmentproto.OpAccountPunishmentVO, 0) + voMap := make(map[int64]*accountpunishmentproto.OpAccountPunishmentVO) + for _, accountpunishment := range list { + mid := util.DerefInt64(accountpunishment.Mid) + if voMap[mid] != nil { + voMap[mid].List = append(voMap[mid].List, accountpunishment) + } else { + vo := &accountpunishmentproto.OpAccountPunishmentVO{ + Account: &accountproto.OpListVO{}, + List: make([]*dbstruct.AccountPunishment, 0), + } + vo.Account.CopyAccount(acctMap[mid]) + vo.List = append(vo.List, accountpunishment) + volist = append(volist, vo) + voMap[mid] = vo + } + } + + return +} + +func (s *Service) OpGetTerminatedAccountPunishmentList(ctx *gin.Context, req *accountpunishmentproto.OpListTerminatedReq) (volist []*accountpunishmentproto.OpAccountPunishmentVO, ec errcode.ErrCode) { + ec = errcode.ErrCodeAccountPunishmentSrvOk + + if ec = s.OpGetTerminatedAccountPunishmentListBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountPunishmentSrvOk { + return + } + + list, err := _DefaultAccountPunishment.OpListTerminated(ctx, req) + if err != nil { + logger.Error("OpGetAccountPunishmentList fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeAccountPunishmentSrvFail + return + } + + // 获取mid的set + midMap := make(map[int64]*dbstruct.Account) + midSet := make([]int64, 0) + for _, v := range list { + mid := util.DerefInt64(v.Mid) + if midMap[mid] != nil { + continue + } else { + midSet = append(midSet, mid) + midMap[mid] = &dbstruct.Account{} + } + } + + // 查询mid的map + acctMap, err := _DefaultAccount.GetAccountMapByMids(ctx, midSet) + if err != nil { + logger.Error("GetAccountMapByMids fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeAccountSrvFail + return + } + + // 组装vo + volist = make([]*accountpunishmentproto.OpAccountPunishmentVO, 0) + voMap := make(map[int64]*accountpunishmentproto.OpAccountPunishmentVO) + for _, accountpunishment := range list { + mid := util.DerefInt64(accountpunishment.Mid) + + // 填充状态,不为提前中止,则为正常结束 + if util.DerefInt64(accountpunishment.Status) != consts.AccountPunishment_Interrupted { + accountpunishment.Status = goproto.Int64(consts.AccountPunishment_Finished) + } + + if voMap[mid] != nil { + voMap[mid].List = append(voMap[mid].List, accountpunishment) + } else { + vo := &accountpunishmentproto.OpAccountPunishmentVO{ + Account: &accountproto.OpListVO{}, + List: make([]*dbstruct.AccountPunishment, 0), + } + vo.Account.CopyAccount(acctMap[mid]) + vo.List = append(vo.List, accountpunishment) + volist = append(volist, vo) + voMap[mid] = vo + } + } + + return +} diff --git a/codecreate/codecreate.go b/codecreate/codecreate.go index 9967cceb..52c5b8bc 100644 --- a/codecreate/codecreate.go +++ b/codecreate/codecreate.go @@ -9,10 +9,10 @@ import ( func main() { genSource := &generator.GenSource{ - EntityName: "MomentAuditTask", - ModuleName: "moment_audit_task", - EntityCNName: "动态审核任务表", - ErrCodeSeq: "28", + EntityName: "AccountPunishment", + ModuleName: "accountpunishment", + EntityCNName: "账号处罚", + ErrCodeSeq: "32", } generator.CreateFileDirectory(genSource) diff --git a/codecreate/consts/consts.go b/codecreate/consts/consts.go index 39e71ce4..77b1ceaf 100644 --- a/codecreate/consts/consts.go +++ b/codecreate/consts/consts.go @@ -1,7 +1,7 @@ package consts // root -const RootPath = "/Users/PC/Desktop/wishpal_ironfan_service/service/" +const RootPath = "/Users/PC/Desktop/service/" const ExcelPath = "codecreate/resource/EntityDefine.xlsx" diff --git a/codecreate/resource/EntityDefine.xlsx b/codecreate/resource/EntityDefine.xlsx index 8161387d..2f919032 100644 Binary files a/codecreate/resource/EntityDefine.xlsx and b/codecreate/resource/EntityDefine.xlsx differ diff --git a/codecreate/template/mongo.txt b/codecreate/template/mongo.txt index 3401bf68..1969c3d9 100644 --- a/codecreate/template/mongo.txt +++ b/codecreate/template/mongo.txt @@ -49,20 +49,3 @@ func (m *Mongo) Get#{EntityName}List(ctx *gin.Context, req *#{moduleName}proto.O } return list, err } - -func (m *Mongo) Get#{EntityName}ListByIds(ctx *gin.Context, ids []int64) ([]*dbstruct.#{EntityName}, error) { - list := make([]*dbstruct.#{EntityName}, 0) - col := m.getCol#{EntityName}() - query := qmgo.M{ - "_id": bson.M{ - "$in": ids, - }, - "del_flag": 0, - } - err := col.Find(ctx, query).All(&list) - if err == qmgo.ErrNoSuchDocuments { - err = nil - return list, err - } - return list, err -} \ No newline at end of file diff --git a/dbstruct/accountpunishment.go b/dbstruct/accountpunishment.go new file mode 100644 index 00000000..9588743a --- /dev/null +++ b/dbstruct/accountpunishment.go @@ -0,0 +1,34 @@ +package dbstruct + +import ( + "service/bizcommon/util" + "time" +) + +const PermanentDuration int64 = 3155760000 + +type AccountPunishment struct { + Id *int64 `json:"id" bson:"_id"` // 账号处罚表id + Mid *int64 `json:"mid" bson:"mid"` // 用户表id + Type *int64 `json:"type" bson:"type"` // 处罚类型 + Duration *int64 `json:"duration" bson:"duration"` // 处罚时长 + EndTime *int64 `json:"end_time" bson:"end_time"` // 处罚结束时间 + Status *int64 `json:"status" bson:"status"` // 处罚结果 + Ct *int64 `json:"ct" bson:"ct"` // 创建时间 + Ut *int64 `json:"ut" bson:"ut"` // 更新时间 + DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记 +} + +func (p *AccountPunishment) GetEndTimeFormatString() string { + if p == nil || p.EndTime == nil { + return "" + } + return time.Unix(util.DerefInt64(p.EndTime), 0).Local().Format("1/2 15:04") +} + +func (p *AccountPunishment) IsPermanent() bool { + if p == nil || p.Duration == nil { + return false + } + return util.DerefInt64(p.Duration) == PermanentDuration +} diff --git a/dbstruct/idSeq.go b/dbstruct/idSeq.go index 07a0ab78..fa3cf2c8 100644 --- a/dbstruct/idSeq.go +++ b/dbstruct/idSeq.go @@ -52,3 +52,7 @@ type FeedbackIdSeq struct { type MediaIdSeq struct { Seq int64 `json:"seq" bson:"seq"` } + +type AccountPunishmentIdSeq struct { + Seq int64 //用户Id序列号 +} diff --git a/etc/mix/mix-test.yaml b/etc/mix/mix-test.yaml index 5efaa1bb..cd30bb7f 100644 --- a/etc/mix/mix-test.yaml +++ b/etc/mix/mix-test.yaml @@ -22,7 +22,7 @@ mix_mongo: mix_mysql: uri: "127.0.0.1:3306" username: "root" - password: "Xbz@114514" + password: "Wishpal@2023" timeout: 3 read_timeout_s: 5 write_timeout_s: 3