Browse Source

权限校验

xingzai 3 years ago
parent
commit
7bc11fd569
3 changed files with 230 additions and 88 deletions
  1. 212 84
      controllers/activity.go
  2. 9 0
      models/activity.go
  3. 9 4
      models/activity_signup.go

+ 212 - 84
controllers/activity.go

@@ -224,7 +224,7 @@ func (this *ActivityCoAntroller) ScheduleList() {
 // @Title  活动详情
 // @Description 获取活动详情接口
 // @Param   ActivityId   query   int  true       "活动ID"
-// @Success Ret=200 {object} models.ActivityDetail
+// @Success Ret=200 {object} models.CygxActivityResp
 // @router /detail [get]
 func (this *ActivityCoAntroller) Detail() {
 	br := new(models.BaseResponse).Init()
@@ -267,10 +267,63 @@ func (this *ActivityCoAntroller) Detail() {
 		activityInfo.SignupType = detail.SignupType
 	}
 	activityInfo.ShowType = detail.ShowType
+	resp := new(models.CygxActivityResp)
+	hasPermission := 0
+	//判断是否已经申请过
+	applyCount, err := models.GetApplyRecordCount(uid)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+		return
+	}
+	if user.CompanyId > 1 {
+		permissionStr, err := models.GetCompanyPermission(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+			return
+		}
+		companyItem, err := models.GetCompanyDetailAllById(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+			return
+		}
+		//1专家电话会、2分析师电话会、3公司调研电话会、4公司线下调研、5专家线下沙龙、6分析师线下沙龙
+		//OperationMode     string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
+		if activityInfo.ActivityTypeId != 1 && activityInfo.ActivityTypeId != 4 && permissionStr == "专家" {
+			resp.PopupMsg = "您暂无权限参加" + activityInfo.ActivityName + "类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
+			resp.SellerMobile = companyItem.Mobile
+			resp.OperationMode = "Call"
+			hasPermission = 2
+		} else {
+			if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
+				hasPermission = 1
+				resp.HaqveJurisdiction = true
+			} else {
+				resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
+				resp.SellerMobile = companyItem.Mobile
+				resp.OperationMode = "Call"
+				resp.HasPermission = 2
+			}
+		}
+	} else { //潜在客户
+		if applyCount > 0 {
+			hasPermission = 4
+		} else {
+			hasPermission = 3
+		}
+		resp.OperationMode = "Apply"
+		resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
+	}
+	if hasPermission == 1 {
+		resp.Detail = activityInfo
+	}
+	resp.HasPermission = hasPermission
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
-	br.Data = activityInfo
+	br.Data = resp
 }
 
 // @Title 活动报名
@@ -308,22 +361,18 @@ func (this *ActivityCoAntroller) SignupAdd() {
 	//	return
 	//}
 	//SignupStatus string `description:"报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
+	//HasPermission int    `description:"1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
 	item := new(models.CygxActivitySignup)
-	//if activityId%5 == 1 {
-	//	signupStatus = "FullStarffed"
-	//	item.FailType = 1
-	//} else if activityId%5 == 2 {
-	//	signupStatus = "TwoPeople"
-	//	item.FailType = 2
-	//} else if activityId%5 == 3 {
-	//	signupStatus = "BreakPromise"
-	//	item.FailType = 3
-	//} else if activityId%5 == 4 {
-	//	signupStatus = "Overtime"
-	//} else if activityId%5 == 5 {
-	//	signupStatus = "Success"
-	//}
-	signupStatus = "Success"
+	resp := new(models.SignupStatus)
+	hasPermission := 0
+
+	//判断是否已经申请过
+	applyCount, err := models.GetApplyRecordCount(uid)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+		return
+	}
 	activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
 	if activityInfo == nil {
 		br.Msg = "操作失败"
@@ -335,40 +384,82 @@ func (this *ActivityCoAntroller) SignupAdd() {
 		br.ErrMsg = "操作失败,Err:" + errInfo.Error()
 		return
 	}
-	resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
-	if time.Now().After(resultTime.Add(-time.Minute * 60)) {
-		signupStatus = "Overtime"
-	}
-	total, errtotal := models.GetActivitySignupCount(uid, activityId)
-	if errtotal != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取失败,Err:" + errtotal.Error()
-		return
-	}
-	if total > 0 {
-		br.Msg = "您已报名这个活动"
-		return
-	}
-
-	if signupStatus == "Success" {
-		item.UserId = uid
-		item.ActivityId = activityId
-		item.CreateTime = time.Now()
-		item.Mobile = user.Mobile
-		item.Email = user.Email
-		item.CompanyId = user.CompanyId
-		item.CompanyName = user.CompanyName
-		item.SignupType = signupType
-		_, errSignup := models.AddActivitySignup(item)
-		if errSignup != nil {
-			br.Msg = "操作失败"
-			br.ErrMsg = "操作失败,Err:" + errSignup.Error()
+	if user.CompanyId > 1 {
+		permissionStr, err := models.GetCompanyPermission(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
 			return
 		}
+		companyItem, err := models.GetCompanyDetailAllById(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+			return
+		}
+		//1专家电话会、2分析师电话会、3公司调研电话会、4公司线下调研、5专家线下沙龙、6分析师线下沙龙
+		//OperationMode     string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
+		if activityInfo.ActivityTypeId != 1 && activityInfo.ActivityTypeId != 4 && permissionStr == "专家" {
+			resp.PopupMsg = "您暂无权限参加" + activityInfo.ActivityName + "类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
+			resp.SellerMobile = companyItem.Mobile
+			resp.OperationMode = "Call"
+			hasPermission = 2
+		} else {
+			fmt.Println(activityInfo.ChartPermissionName)
+			fmt.Println(permissionStr)
+			if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
+				hasPermission = 1
+				signupStatus = "Success"
+				resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
+				if time.Now().After(resultTime.Add(-time.Minute * 60)) {
+					signupStatus = "Overtime"
+				}
+				total, errtotal := models.GetActivitySignupCount(uid, activityId)
+				if errtotal != nil {
+					br.Msg = "获取失败"
+					br.ErrMsg = "获取失败,Err:" + errtotal.Error()
+					return
+				}
+				if total > 0 {
+					br.Msg = "您已报名这个活动"
+					return
+				}
+				if signupStatus == "Success" {
+					item.UserId = uid
+					item.ActivityId = activityId
+					item.CreateTime = time.Now()
+					item.Mobile = user.Mobile
+					item.Email = user.Email
+					item.CompanyId = user.CompanyId
+					item.CompanyName = user.CompanyName
+					item.SignupType = signupType
+					_, errSignup := models.AddActivitySignup(item)
+					if errSignup != nil {
+						br.Msg = "操作失败"
+						br.ErrMsg = "操作失败,Err:" + errSignup.Error()
+						return
+					}
+				}
+				resp.HaqveJurisdiction = true
+			} else {
+				resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
+				resp.SellerMobile = companyItem.Mobile
+				resp.OperationMode = "Call"
+				resp.HasPermission = 2
+			}
+		}
+	} else { //潜在客户
+		if applyCount > 0 {
+			hasPermission = 4
+		} else {
+			hasPermission = 3
+		}
+		resp.OperationMode = "Apply"
+		resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
 	}
-	resp := new(models.SignupStatus)
 	resp.SignupType = signupType
 	resp.SignupStatus = signupStatus
+	resp.HasPermission = hasPermission
 	if signupStatus == "Success" {
 		resp.ActivityId = activityId
 	}
@@ -617,6 +708,16 @@ func (this *ActivityCoAntroller) MeetingReminderAdd() {
 	activityId := req.ActivityId
 	//SignupStatus string `description:"报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
 	item := new(models.CygxActivityMeetingReminder)
+	resp := new(models.SignupStatus)
+	hasPermission := 0
+
+	//判断是否已经申请过
+	applyCount, err := models.GetApplyRecordCount(uid)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+		return
+	}
 	activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
 	if activityInfo == nil {
 		br.Msg = "操作失败"
@@ -633,44 +734,69 @@ func (this *ActivityCoAntroller) MeetingReminderAdd() {
 		br.Msg = "活动开始前15分钟无法设置会议提醒"
 		return
 	}
-	//if signupStatus == "Success" {
-	//total, err := models.GetActivitySignupCount(uid, activityId)
-	//if err != nil {
-	//	br.Msg = "获取失败"
-	//	br.ErrMsg = "获取失败,Err:" + err.Error()
-	//	return
-	//}
-	//if total == 0 {
-	//	br.Msg = "您暂未预约外呼这个活动"
-	//	return
-	//}
-
-	totalMeeting, errMeeting := models.GetActivityMeetingReminderCount(uid, activityId)
-	if errMeeting != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取失败,Err:" + errMeeting.Error()
-		return
-	}
-	if totalMeeting > 0 {
-		br.Msg = "您已预约,请勿重复预约"
-		return
-	}
-
-	item.UserId = uid
-	item.ActivityId = activityId
-	item.CreateTime = time.Now()
-	item.Mobile = user.Mobile
-	item.Email = user.Email
-	item.CompanyId = user.CompanyId
-	item.CompanyName = user.CompanyName
-	_, errSignup := models.AddActivityMeetingReminder(item)
-	if errSignup != nil {
-		br.Msg = "操作失败"
-		br.ErrMsg = "操作失败,Err:" + errSignup.Error()
-		return
+	if user.CompanyId > 1 {
+		permissionStr, err := models.GetCompanyPermission(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+			return
+		}
+		companyItem, err := models.GetCompanyDetailAllById(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+			return
+		}
+		if activityInfo.ActivityTypeId != 1 && activityInfo.ActivityTypeId != 4 && permissionStr == "专家" {
+			resp.PopupMsg = "您暂无权限参加" + activityInfo.ActivityName + "类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
+			resp.SellerMobile = companyItem.Mobile
+			resp.OperationMode = "Call"
+			hasPermission = 2
+		} else {
+			if strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
+				hasPermission = 1
+				signupStatus = "Success"
+				totalMeeting, errMeeting := models.GetActivityMeetingReminderCount(uid, activityId)
+				if errMeeting != nil {
+					br.Msg = "获取失败"
+					br.ErrMsg = "获取失败,Err:" + errMeeting.Error()
+					return
+				}
+				if totalMeeting > 0 {
+					br.Msg = "您已预约,请勿重复预约"
+					return
+				}
+				item.UserId = uid
+				item.ActivityId = activityId
+				item.CreateTime = time.Now()
+				item.Mobile = user.Mobile
+				item.Email = user.Email
+				item.CompanyId = user.CompanyId
+				item.CompanyName = user.CompanyName
+				_, errSignup := models.AddActivityMeetingReminder(item)
+				if errSignup != nil {
+					br.Msg = "操作失败"
+					br.ErrMsg = "操作失败,Err:" + errSignup.Error()
+					return
+				}
+				resp.HaqveJurisdiction = true
+			} else {
+				resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
+				resp.SellerMobile = companyItem.Mobile
+				resp.OperationMode = "Call"
+				resp.HasPermission = 2
+			}
+		}
+	} else { //潜在客户
+		if applyCount > 0 {
+			hasPermission = 4
+		} else {
+			hasPermission = 3
+		}
+		resp.OperationMode = "Apply"
+		resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
 	}
-	//}
-	resp := new(models.SignupStatus)
+	resp.HasPermission = hasPermission
 	resp.SignupStatus = signupStatus
 	resp.ActivityId = activityId
 	if activityId%2 == 1 {
@@ -678,7 +804,9 @@ func (this *ActivityCoAntroller) MeetingReminderAdd() {
 	}
 	br.Ret = 200
 	br.Success = true
-	br.Msg = "设置成功,会前15分钟会为您推送微信消息提醒"
+	if hasPermission == 1 {
+		br.Msg = "设置成功,会前15分钟会为您推送微信消息提醒"
+	}
 	br.Data = resp
 }
 

+ 9 - 0
models/activity.go

@@ -89,6 +89,15 @@ type ActivityDetail struct {
 	IsCancelMeetingReminder int    `description:"是否取消会议提醒 1展示取消会议提醒 ,0展示会议提醒"`
 }
 
+type CygxActivityResp struct {
+	HaqveJurisdiction bool   `description:"是否有权限"`
+	OperationMode     string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
+	HasPermission     int    `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
+	PopupMsg          string `description:"权限弹窗信息"`
+	SellerMobile      string `description:"销售电话"`
+	Detail            *ActivityDetail
+}
+
 //通过纪要ID获取活动详情
 func GetAddActivityInfoById(ActivityId int) (item *ActivityDetail, err error) {
 	o := orm.NewOrm()

+ 9 - 4
models/activity_signup.go

@@ -20,10 +20,15 @@ type CygxActivitySignup struct {
 }
 
 type SignupStatus struct {
-	SignupStatus string `description:"返回状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
-	GoFollow     bool   `description:"是否去关注"`
-	SignupType   int    `description:"报名方式,1预约外呼,2我要报名"`
-	ActivityId   int    `description:"活动ID"`
+	SignupStatus      string `description:"返回状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
+	GoFollow          bool   `description:"是否去关注"`
+	SignupType        int    `description:"报名方式,1预约外呼,2我要报名"`
+	ActivityId        int    `description:"活动ID"`
+	HaqveJurisdiction bool   `description:"是否有权限"`
+	OperationMode     string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
+	HasPermission     int    `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
+	PopupMsg          string `description:"权限弹窗信息"`
+	SellerMobile      string `description:"销售电话"`
 }
 
 //报名记录日志