Browse Source

no message

xingzai 2 years ago
parent
commit
bbc2217164
3 changed files with 160 additions and 76 deletions
  1. 56 58
      controllers/activity_special.go
  2. 88 10
      services/activity_special.go
  3. 16 8
      services/activity_special_trip.go

+ 56 - 58
controllers/activity_special.go

@@ -529,66 +529,64 @@ func (this *ActivitySpecialCoAntroller) SpecialTripAdd() {
 		resp.PopupMsg = popupMsg
 		resp.PopupMsg2 = popupMsg2
 		resp.SignupStatus = signupStatus
-		//判断是删除还是添加
-		if total == 0 {
-			//获取销售信息
-			sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
-			if err != nil {
-				br.Msg = "操作失败"
-				br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
-				return
-			}
-			item := new(models.CygxActivitySpecialTrip)
-			item.UserId = uid
-			item.RealName = user.RealName
-			item.ActivityId = activityId
-			item.CreateTime = time.Now()
-			item.Mobile = user.Mobile
-			item.Email = user.Email
-			item.CompanyId = user.CompanyId
-			item.CompanyName = user.CompanyName
-			if sellerItem != nil {
-				item.SellerName = sellerItem.RealName
-			}
-			err = models.AddCygxActivitySpecialTrip(item)
-			if err != nil {
-				br.Msg = "操作失败"
-				br.ErrMsg = "操作失败,Err:" + err.Error()
-				return
-			}
-			//SignupStatus  int    `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
-			resp.Status = 1
-			resp.SignupStatus = 1
-			resp.PopupMsg = "感谢参与,本次报名会扣除一次贵司在弘则的调研点数。"
-			resp.PopupMsg2 = "由于每场活动人数有限,如果不能参加请提前48小时取消,未及时取消导致影响其他客户报名将会维持扣点。"
+		if signupStatus == 1 {
+			//判断是删除还是添加
+			if total == 0 {
+				//获取销售信息
+				sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
+				if err != nil {
+					br.Msg = "操作失败"
+					br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
+					return
+				}
+				item := new(models.CygxActivitySpecialTrip)
+				item.UserId = uid
+				item.RealName = user.RealName
+				item.ActivityId = activityId
+				item.CreateTime = time.Now()
+				item.Mobile = user.Mobile
+				item.Email = user.Email
+				item.CompanyId = user.CompanyId
+				item.CompanyName = user.CompanyName
+				if sellerItem != nil {
+					item.SellerName = sellerItem.RealName
+				}
+				err = models.AddCygxActivitySpecialTrip(item)
+				if err != nil {
+					br.Msg = "操作失败"
+					br.ErrMsg = "操作失败,Err:" + err.Error()
+					return
+				}
+				//SignupStatus  int    `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
 
-			////给所属销售发送消息
-			//if sellerItem.Mobile != "" {
-			//	openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
-			//	if openIpItem != nil && openIpItem.OpenId != "" {
-			//		if sellerItem != nil {
-			//			go services.SendSpecialTemplateMsg(user.RealName+"【"+user.CompanyName+"】", time.Now().Format(utils.FormatDateTime), user.Mobile, activityInfo.ResearchTheme, "sale", openIpItem)
-			//		}
-			//	}
-			//}
+				////给所属销售发送消息
+				//if sellerItem.Mobile != "" {
+				//	openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
+				//	if openIpItem != nil && openIpItem.OpenId != "" {
+				//		if sellerItem != nil {
+				//			go services.SendSpecialTemplateMsg(user.RealName+"【"+user.CompanyName+"】", time.Now().Format(utils.FormatDateTime), user.Mobile, activityInfo.ResearchTheme, "sale", openIpItem)
+				//		}
+				//	}
+				//}
 
-			// 给芳姐发消息
-			//cnf, _ := models.GetConfigByCode("tpl_msg")
-			//if cnf != nil {
-			//	openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
-			//	if openIpItem != nil && openIpItem.OpenId != "" {
-			//		actList, _ := models.GetActivityListSpecialAll(activityId)
-			//		if len(actList) == 5 {
-			//			var companyName string
-			//			for _, v := range actList {
-			//				companyName += "【" + v.CompanyName + "】"
-			//			}
-			//			go services.SendSpecialTemplateMsg(companyName, "", "", activityInfo.ResearchTheme, "", openIpItem)
-			//		}
-			//	}
-			//}
-			////用户专项调研操作行为,模板消息推送
-			//go services.SpecialActivityUserRemind(user, activityInfo, 1)
+				// 给芳姐发消息
+				//cnf, _ := models.GetConfigByCode("tpl_msg")
+				//if cnf != nil {
+				//	openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
+				//	if openIpItem != nil && openIpItem.OpenId != "" {
+				//		actList, _ := models.GetActivityListSpecialAll(activityId)
+				//		if len(actList) == 5 {
+				//			var companyName string
+				//			for _, v := range actList {
+				//				companyName += "【" + v.CompanyName + "】"
+				//			}
+				//			go services.SendSpecialTemplateMsg(companyName, "", "", activityInfo.ResearchTheme, "", openIpItem)
+				//		}
+				//	}
+				//}
+				////用户专项调研操作行为,模板消息推送
+				//go services.SpecialActivityUserRemind(user, activityInfo, 1)
+			}
 		}
 	}
 	br.Ret = 200

+ 88 - 10
services/activity_special.go

@@ -109,7 +109,7 @@ func GetActivityLabelSpecialList(userType, isPower int, chartPermissionIds, scal
 	return
 }
 
-//HandleActivityLabelSpecialPermission 处理专项产业调研的查询权限sql
+//HandleActivityLabelSpecialPermission 处理专项产业调研的查询权限sql 永续
 func HandleActivityLabelSpecialPermission(user *models.WxUserItem) (condition string, err error) {
 	userType, permissionStr, err := GetUserType(user.CompanyId)
 	if err != nil {
@@ -135,13 +135,54 @@ func HandleActivityLabelSpecialPermission(user *models.WxUserItem) (condition st
 	return
 }
 
+//HandleActivityLabelSpecialPermission 处理专项产业调研的查询权限sql 升级
+func HandleActivityLabelSpecialTripPermission(user *models.WxUserItem) (condition string, err error) {
+	userType, permissionStr, err := GetActivitySpecialUserType(user.CompanyId)
+	if err != nil {
+		return
+	}
+	slicePer := strings.Split(permissionStr, ",")
+	var permissionSqlStr string
+	for _, v := range slicePer {
+		if userType == 1 {
+			if !strings.Contains(v, "研选") {
+				permissionSqlStr += "'" + v + "',"
+			}
+		} else {
+			permissionSqlStr += "'" + v + "',"
+		}
+	}
+	permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
+	permissionSqlStr = strings.Replace(permissionSqlStr, "(主观)", "", -1)
+	permissionSqlStr = strings.Replace(permissionSqlStr, "(客观)", "", -1)
+	condition = ` AND art.publish_status = 1  AND art.label != ''  AND art.is_offline = 0  `
+	condition += ` AND art.chart_permission_name  IN (` + permissionSqlStr + `) `
+	condition += ` AND  art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
+	return
+}
+
 //获取预报名列表
 func GetActivitySpecialPrepareList(user *models.WxUserItem, startSize, pageSize int, keywords string) (list []*models.CygxActivitySpecialDetail, totalPrepare int, err error) {
-	condition, e := HandleActivityLabelSpecialPermission(user)
+	companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
 	if e != nil {
-		err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
+		err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
 		return
 	}
+	//如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
+	var condition string
+	if companyDetail.Status == "永续" {
+		condition, e = HandleActivityLabelSpecialPermission(user)
+		if e != nil {
+			err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
+			return
+		}
+	} else {
+		condition, e = HandleActivityLabelSpecialTripPermission(user)
+		if e != nil {
+			err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
+			return
+		}
+	}
 	var pars []interface{}
 	condition += ` AND art.days = 0  AND art.publish_status = 1 AND art.is_offline = 0   `
 	if keywords != "" {
@@ -169,11 +210,27 @@ state 进行状态 1:未开始,2:进行中,3:已结束 不传默认查
 */
 func GetActivityLabelSpecialConfirmList(user *models.WxUserItem, startSize, pageSize, state int, keywords string) (list []*models.CygxActivitySpecialDetail, totalConfirm int, err error) {
 	//var condition string
-	condition, e := HandleActivityLabelSpecialPermission(user)
+	companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
 	if e != nil {
-		err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
+		err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
 		return
 	}
+	//如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
+	var condition string
+	if companyDetail.Status == "永续" {
+		condition, e = HandleActivityLabelSpecialPermission(user)
+		if e != nil {
+			err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
+			return
+		}
+	} else {
+		condition, e = HandleActivityLabelSpecialTripPermission(user)
+		if e != nil {
+			err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
+			return
+		}
+	}
+
 	var pars []interface{}
 	condition += ` AND art.days >0  `
 	if state == 1 {
@@ -403,11 +460,6 @@ func GetActivitySpecialSearcheList(user *models.WxUserItem, condition string, st
 	return
 }
 
-//func init() {
-//	_, _, err := GetActivitySpecialUserType(235)
-//	fmt.Println(err)
-//}
-
 //获取 专项调研客户类型   //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户;6、冻结客户;7、流失客户 8:行业升级套餐客户
 func GetActivitySpecialUserType(companyId int) (userType int, permissionStrnew string, err error) {
 	var permissionStr, permissionZhengShiStr string
@@ -465,3 +517,29 @@ func GetActivitySpecialUserType(companyId int) (userType int, permissionStrnew s
 	permissionStrnew = permissionStr
 	return
 }
+
+//GetSpeciUserhasPermissionType 获取专项产业调研的用户身份类型
+func GetSpeciUserhasPermissionType(user *models.WxUserItem, activityDetail *models.CygxActivitySpecialDetail) (hasPermissionType int, err error) {
+	//var condition string
+	//HasPermission     int    `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请,5:有IFCC、无权益"`
+	companyId := user.CompanyId
+	companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
+	if e != nil {
+		err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
+		return
+	}
+	if companyId <= 1 {
+		hasPermissionType = 0
+	} else {
+		if companyDetail.Status == "永续" {
+			hasPermissionType = 1
+		} else {
+			//total, e := models.GetCountCompanyDetailByIdGroup(companyId)
+			//if e != nil {
+			//	err = errors.New("GetCountCompanyDetailByIdGroup, Err: " + e.Error())
+			//	return
+			//}
+		}
+	}
+	return
+}

+ 16 - 8
services/activity_special_trip.go

@@ -2,7 +2,6 @@ package services
 
 import (
 	"errors"
-	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
 	"time"
@@ -17,6 +16,17 @@ func SpecialTripPopupMsg(activityInfo *models.CygxActivitySpecialDetail, user *m
 		popupMsg = "活动开始前1小时内无法报名,请联系对口销售处理"
 		return
 	}
+
+	errMsg, _, e := GetTripRemainingtimesBycompany(user, activityInfo)
+	if e != nil {
+		err = errors.New("获取客户剩余报名次数失败 GetActivitySpecialUserType, Err: " + e.Error())
+		return
+	}
+	if errMsg != "" {
+		popupMsg = errMsg
+		signupStatus = 3
+		return
+	}
 	var condition string
 	var pars []interface{}
 
@@ -40,12 +50,12 @@ func SpecialTripPopupMsg(activityInfo *models.CygxActivitySpecialDetail, user *m
 }
 
 //获取用户剩余报名次数
-func GetTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (errMsg string, err error) {
+func GetTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (errMsg string, tripRemaining int, err error) {
 
 	//获取 专项调研客户类型   //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户;6、冻结客户;7、流失客户 8:行业升级套餐客户
 	msgTemplate := "您的专项调研次数已用完,如仍想参加,请与您的对口销售商议"
 	var tripTota int
-	userType, permissionStrnew, e := GetActivitySpecialUserType(user.CompanyId)
+	userType, _, e := GetActivitySpecialUserType(user.CompanyId)
 	if e != nil {
 		err = errors.New("获取客户身份信息失败 GetActivitySpecialUserType, Err: " + e.Error())
 		return
@@ -54,6 +64,7 @@ func GetTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *model
 		errMsg = msgTemplate
 		return
 	} else if userType == 1 {
+		tripRemaining = 999
 		return
 	} else if userType == 2 {
 		var condition string
@@ -73,6 +84,7 @@ func GetTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *model
 			errMsg = msgTemplate
 			return
 		}
+		tripRemaining = 12 - tripTota
 	} else {
 		var condition string
 		var pars []interface{}
@@ -94,11 +106,7 @@ func GetTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *model
 			errMsg = msgTemplate
 			return
 		}
+		tripRemaining = 6 - tripTota
 	}
-
-	fmt.Println(permissionStrnew)
-	fmt.Println(permissionStrnew)
-	fmt.Println(userType)
-	fmt.Println(tripTota)
 	return
 }