From ddef0d558fba58fcf9d1f1b9a69992f576e6b93c Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Wed, 28 Jun 2023 17:38:04 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=80=E8=AF=B7=E6=B4=BE=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/invite_m/invite_apply.go | 4 +-- domain/model/promotion_m/promotion_info.go | 37 ++++++++++++++++++++++ route/invite_r/party_invite.go | 22 ++++++++++--- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/domain/model/invite_m/invite_apply.go b/domain/model/invite_m/invite_apply.go index aa44edf..4b97bba 100644 --- a/domain/model/invite_m/invite_apply.go +++ b/domain/model/invite_m/invite_apply.go @@ -28,8 +28,8 @@ func CreateInviteApply(model *domain.Model, userId, newUserId uint64, platform, return nil } -func GetApplyList(model *domain.Model, userId uint64, pageIndex, pageSize, gType int, beginTime, endTime time.Time) ([]*InviteApply, int64, error) { - db := model.DB().Model(InviteApply{}).Where("user_id = ?", userId).Where("created_time >= ? and created_time <= ?", beginTime, endTime) +func GetApplyList(model *domain.Model, userIds []uint64, pageIndex, pageSize, gType int, beginTime, endTime time.Time) ([]*InviteApply, int64, error) { + db := model.DB().Model(InviteApply{}).Where("user_id in (?)", userIds).Where("created_time >= ? and created_time <= ?", beginTime, endTime) switch gType { // 1.已申请2.待审核3.已通过4.已拒绝 case 2: db = db.Where("`status` = ?", 0) diff --git a/domain/model/promotion_m/promotion_info.go b/domain/model/promotion_m/promotion_info.go index a91bc30..d82ac4d 100644 --- a/domain/model/promotion_m/promotion_info.go +++ b/domain/model/promotion_m/promotion_info.go @@ -37,6 +37,43 @@ func IsPromotionInvitee(model *domain.Model, userId mysql.ID) (bool, error) { return true, nil } +// 检查是否推广经理 +func IsPromotionManager(model *domain.Model, userId mysql.ID) bool { + var promotionAgent PromotionAgent + if err := model.Db.Model(PromotionAgent{}).Where("manager_id = ?", userId).First(&promotionAgent).Error; err != nil { + if err != gorm.ErrRecordNotFound { + model.Log.Errorf("IsPromotionManager fail:%v", err) + } + } else if promotionAgent.ID > 0 { + return true + } + return false +} + +// 检查是否我的推广经理 +func IsMyPromotionManager(model *domain.Model, userId, myUserId mysql.ID) bool { + var promotionAgent PromotionAgent + if err := model.Db.Model(PromotionAgent{}).Where("manager_id = ? and agent_id = ?", userId, myUserId).First(&promotionAgent).Error; err != nil { + if err != gorm.ErrRecordNotFound { + model.Log.Errorf("IsMyPromotionManager fail:%v", err) + } + } else if promotionAgent.ID > 0 { + return true + } + return false +} + +// 获取推广经理拥有的所有推广员,包含自己 +func GetPromotionManagerAgentList(model *domain.Model, userId mysql.ID) ([]uint64, error) { + uids := make([]uint64, 0) + if err := model.Db.Model(PromotionAgent{}).Where("manager_id = ?", userId).Select("agent_id"). + Pluck("agent_id", &uids).Error; err != nil { + model.Log.Errorf("IsPromotionManager fail:%v", err) + return nil, err + } + return uids, nil +} + // 添加推广邀请关系 func AddPromotionInvite(model *domain.Model, managerId, agentId, invitee mysql.ID, platform, platformId, reason, inviteDate string) error { if err := model.Db.Create(&PromotionInvite{ diff --git a/route/invite_r/party_invite.go b/route/invite_r/party_invite.go index 2bd8e77..ad3c2eb 100644 --- a/route/invite_r/party_invite.go +++ b/route/invite_r/party_invite.go @@ -37,10 +37,10 @@ func InviteApply(c *gin.Context) (*mycontext.MyContext, error) { VideoUrl string `form:"videoUrl" binding:"required"` } - //myUserId, err := req.GetUserId(c) - //if err != nil { - // return myCtx, err - //} + myUserId, err := req.GetUserId(c) + if err != nil { + return myCtx, err + } var param paramStr if err := c.ShouldBind(¶m); err != nil { @@ -74,6 +74,10 @@ func InviteApply(c *gin.Context) (*mycontext.MyContext, error) { model.Log.Errorf("InviteApply param:%v", param) return myCtx, bizerr.InvalidParameter } + if user.ID != myUserId && !promotion_m.IsMyPromotionManager(model, user.ID, myUserId) { + model.Log.Errorf("InviteApply 没有邀请资格 param:%v", param) + return myCtx, bizerr.InviteApplyNoPermission + } // 邀请人是否有资格邀请 if !promotion_m.IsPromotionAgent(model, user.ID) { model.Log.Errorf("InviteApply 没有邀请资格 param:%v", param) @@ -144,7 +148,15 @@ func InviteApplyList(c *gin.Context) (*mycontext.MyContext, error) { var model = domain.CreateModelContext(myCtx) - list, total, err := invite_m.GetApplyList(model, userId, param.PageIndex, param.PageSize, param.Type, beginTime, endTime) + agentIds := []uint64{userId} + if promotion_m.IsPromotionManager(model, userId) { + agentIds, err = promotion_m.GetPromotionManagerAgentList(model, userId) + if err != nil { + return myCtx, err + } + } + + list, total, err := invite_m.GetApplyList(model, agentIds, param.PageIndex, param.PageSize, param.Type, beginTime, endTime) if err != nil { model.Log.Errorf("GetApplyList param:%v, err:%v", param, err) return myCtx, err -- 2.22.0