Commit ddef0d55 authored by chenweijian's avatar chenweijian

邀请派对

parent a3ae4ca1
......@@ -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)
......
......@@ -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{
......
......@@ -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(&param); 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment