package services import ( "errors" "fmt" "hongze/hongze_clpt/models" "hongze/hongze_clpt/utils" "strconv" "strings" "time" "unicode/utf8" ) // 获取活动列表查询权限的SQL // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开" // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开" // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3" // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开" // @Param WhichTime query string false "已结束的时间筛选项 本周:1、上周:2 、本月:3、上月:4" // @Param Label query string false "搜索主题 多个用 , 隔开" // @Param PlayBack query int false "是否仅展示回放 1:是、0:否 默认0" // @Param KeyWord query string false "搜索关键词" // @Param ikType query int false "联想词类型 , 1不做联想,2,做除初始词的联想,3所有联想" func GetActivityonditionList(user *models.WxUserItem, activityTypeId, chartPermissionIds, whichDay, activeState, label string, isPower, source int, keyWord string, playBack, ikType int) (conditionActivity string, err error) { keyWordNoIk := keyWord adminIds, err := models.GetSelleridWhichGroup(user.CompanyId, 2) if err != nil { return } userType, permissionStr, permissionStrZhengShi, err := GetUserTypeZhengShi(user.CompanyId) if err != nil { return } //判断客户规模是否属于可见范围的活动 companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2) if err != nil && err.Error() != utils.ErrNoRow() { return } isMaker := user.IsMaker slicePer := strings.Split(permissionStr, ",") var permissionSqlStr string var permissionNameStr string for _, v := range slicePer { if userType == 1 { //研选权限处理 if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) { permissionNameStr += "'" + v + "'," } } else { permissionNameStr += "'" + v + "'," } } permissionNameStr = strings.Replace(permissionNameStr, "(主观)", "", -1) permissionNameStr = strings.Replace(permissionNameStr, "(客观)", "", -1) permissionNameStr = strings.TrimRight(permissionNameStr, ",") slicePerZhengShi := strings.Split(permissionStrZhengShi, ",") var permissionNameStrZhengShi string for _, v := range slicePerZhengShi { if userType == 1 { //研选权限处理 if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) { permissionNameStrZhengShi += "'" + v + "'," } } else { permissionNameStrZhengShi += "'" + v + "'," } } permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(主观)", "", -1) permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(客观)", "", -1) permissionNameStrZhengShi = strings.TrimRight(permissionNameStrZhengShi, ",") mapUserType, e := GetActivityCcustomerTypeList() if e != nil { err = e return } var userTypeStr string userTypeStr = mapUserType[userType] // 查研观向7.4-始终查询宏观的权限(无论是否有权限) if permissionNameStr == `` { permissionNameStr = `'宏观'` } else { permissionNameStr += `, '宏观'` } var condition string var conditionAdmin string var conditionHz string // 弘则权限处理 var sqlExport string // 专家权限处理 //permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionNameStr + `)` sqlExport = ` AND (art.customer_type_ids LIKE '%` + userTypeStr + `%' ` //if userType == 2 { // sqlExport += ` OR art.customer_type_ids LIKE '%3%' ` //} if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") { sqlExport += ` OR art.customer_type_ids LIKE '%4%' ` } sqlExport += `) ` // 如果是C类电话会就不展示内容,且合并到分析师电话会 if activityTypeId != "" { if activityTypeId == strconv.Itoa(utils.ANALYST_TELL_ACTIVITY_TYPE_ID) { condition = ` AND art.publish_status = 1 AND art.label != '' AND art.activity_type_id IN (` + activityTypeId + "," + strconv.Itoa(utils.C_CLASS_ACTIVITY_TYPE_ID) + `)` } else { condition = ` AND art.publish_status = 1 AND art.label != '' AND art.activity_type_id IN (` + activityTypeId + `)` } } //主题 if label != "" { condition = ` AND art.label LIKE "%` + label + `%" ` } if isPower == 1 { condition += permissionSqlStr } //行业名称 if len(chartPermissionIds) > 0 { condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)` } //如果是PC的,则不看易董的 if source == 1 { condition += ` AND art.yidong_activity_id = '' ` } var conditionOr string if whichDay != "" { var startDate string var endDate string if whichDay == "1" { startDate = time.Now().Format(utils.FormatDate) endDate = startDate } else if whichDay == "2" { startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate) endDate = startDate } else if whichDay == "3" { startDate = utils.GetNowWeekMonday().Format(utils.FormatDate) endDate = utils.GetNowWeekSunday().Format(utils.FormatDate) } else if whichDay == "4" { startDate = utils.GetLastWeekMonday().Format(utils.FormatDate) endDate = utils.GetLastWeekSunday().Format(utils.FormatDate) } else if whichDay == "5" { startDate = utils.GetNowMonthFirstDay().Format(utils.FormatDate) endDate = utils.GetNowMonthLastDay().Format(utils.FormatDate) } else if whichDay == "6" { startDate = utils.GetLastMonthFirstDay().Format(utils.FormatDate) endDate = utils.GetLastMonthLastDay().Format(utils.FormatDate) } else if whichDay == "1,2" { startDate = time.Now().Format(utils.FormatDate) endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate) } else if whichDay == "3,4" { startDate = utils.GetLastWeekMonday().Format(utils.FormatDate) endDate = utils.GetNowWeekSunday().Format(utils.FormatDate) } else if whichDay == "5,6" { startDate = utils.GetLastMonthFirstDay().Format(utils.FormatDate) endDate = utils.GetNowMonthLastDay().Format(utils.FormatDate) } else { startDate = time.Now().Format(utils.FormatDate) endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate) } condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'" condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'" } //有搜索条件传过来时,不判进行状态条件 if keyWord != "" { if ikType == 2 || ikType == 3 { keyWordArr, e := GetIndustryMapNameSliceV3(keyWord) if e != nil { err = errors.New("获取分词失败,GetIndustryMapNameSliceV3, Err: " + keyWord + e.Error()) return } keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr) //var keywords string if len(keyWordArr) > 1 { if ikType == 2 { keyWord = KeyWordArrSqlRegexp(keyWordArr) condition += ` AND (art.label NOT LIKE '%` + keyWordNoIk + `%' AND art.activity_name NOT LIKE '%` + keyWordNoIk + `%' ) ` } else if ikType == 3 { keyWord = KeyWordArrSqlRegexpAll(keyWordArr) } } } condition += ` AND (art.label REGEXP '` + keyWord + `' OR art.activity_name REGEXP '` + keyWord + `' ) ` } else { if activeState != "" { // 默认查看未开始跟进行中 if activeState == "1" { condition += ` AND art.active_state IN (1,2)` } else { condition += ` AND art.active_state IN (` + activeState + `)` } } else { condition += ` AND art.active_state IN (1,2)` } } if playBack == 1 { var pars []interface{} ativityVIdArry := make([]string, 0) voiceList, e := models.GetActivityVoiceListAll("", pars, 0, 1000) if e != nil && e.Error() != utils.ErrNoRow() { err = e return } for _, v := range voiceList { ativityVIdArry = append(ativityVIdArry, strconv.Itoa(v.ActivityId)) } videoList, e := models.GetActivityVideoListAll("", pars, 0, 1000) if e != nil && e.Error() != utils.ErrNoRow() { err = e return } for _, v := range videoList { ativityVIdArry = append(ativityVIdArry, strconv.Itoa(v.ActivityId)) } //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间 //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05") //condition += ` AND art.activity_time > '` + endTime + `' ` if len(ativityVIdArry) > 0 { ativityVIdstr := strings.Join(ativityVIdArry, ",") condition += ` AND art.activity_id IN (` + ativityVIdstr + `) ` } else { condition += ` AND art.activity_id = 0 ` } } //查询全部可见的数据(是否全部客户可见) //condition += ` AND art.visible_range != 1 AND art.publish_status = 1 ` condition += ` AND art.publish_status = 1 ` //if adminIds == "" { // //condition += ` AND art.visible_range != 1 ` //} else { // condition += ` AND ( art.visible_range != 1 OR ( art.admin_id IN ( ` + adminIds + ` ) AND art.visible_range = 1 )) ` //} if adminIds != "" { condition += ` AND ( art.visible_range != 1 OR ( art.admin_id IN ( ` + adminIds + ` ) AND art.visible_range = 1 )) ` } conditionHz = condition //活动仅决策人可见 if isMaker == 0 { condition += ` AND art.is_maker_show = 0 ` } conditionAdmin = condition + ` AND art.visible_range = 1 ` //condition += ` AND art.visible_range != 1 ` if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") { conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) ` } if (userType == 5) && strings.Contains(permissionStr, "专家") { conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) ` } if userType == 1 { conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) ` } else { conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) ` } if userType == 6 || userType == 7 { conditionOr += ` OR ( art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' ` + condition + `) ` } if companyProduct != nil { if companyProduct.Scale != "" { conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) ` } } if adminIds != "" { if userType == 3 { conditionAdmin += ` AND art.chart_permission_name IN (` + permissionNameStrZhengShi + `) ` } conditionOr += ` OR ( art.customer_type_ids LIKE '%` + userTypeStr + `%' ` + ` AND art.admin_id IN (` + adminIds + `) ` + conditionAdmin + `) ` if companyProduct != nil { if companyProduct.Scale != "" { conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%'` + ` AND art.admin_id IN (` + adminIds + `) ` + conditionAdmin + `) ` } } } conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user) if e != nil { err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error()) return } if conditionShengji != "" { conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionShengji + condition + ` ) ` } if conditionZhengshi != "" { conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionZhengshi + condition + ` ) ` } if conditionHangYe != "" { conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionHangYe + condition + ` ) ` } //弘则研究下的客户不做权限,限制,C类电话会,仅本组销售、部门管理员、admin、权益研究员账号能看到 if user.CompanyId == utils.HZ_COMPANY_ID { mapMobile, e := GetAdminMobileMap() if e != nil { err = e return } if _, ok := mapMobile[user.Mobile]; ok { conditionOr += ` OR ( art.publish_status = 1 ` + conditionHz + `) ` } } if userType == 3 { condition += ` AND art.chart_permission_name IN (` + permissionNameStrZhengShi + `) ` } conditionActivity = condition + permissionSqlStr + sqlExport + conditionOr return } // 根据用户身份处理活动可见 func ActivityConditioninitSql(user *models.WxUserItem, condition string, isPower int) (conditionActivity string, err error) { // cygx_10.9 未绑定联系方式的客户可以看到部分活动 if user.UserId == 0 || user.CompanyId == 1 { conditionActivity = ` AND art.publish_status = 1 AND art.visible_range != 1 AND (art.is_limit_people = 0 OR (art.is_limit_people=1 AND art.is_all_customer_type=1)) ` + condition return } condition += ` AND art.publish_status = 1 ` conditionActivity = condition //弘则可以查看所有活动 if GetBelongingRaiIt(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID { return } //adminIds, err := models.GetSelleridWhichGroup(user.CompanyId, 2) //if err != nil { // return //} adminIds := GetSelleridWhichGroup(user.CompanyId, 2, user.Mobile) userType, permissionStr, permissionStrZhengShi, err := GetUserTypeZhengShi(user.CompanyId) if err != nil { return } //判断客户规模是否属于可见范围的活动 companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2) if err != nil && err.Error() != utils.ErrNoRow() { return } isMaker := user.IsMaker slicePer := strings.Split(permissionStr, ",") var permissionSqlStr string var permissionNameStr string for _, v := range slicePer { if userType == 1 { //研选权限处理 if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) { permissionNameStr += "'" + v + "'," } } else { permissionNameStr += "'" + v + "'," } } permissionNameStr = strings.Replace(permissionNameStr, "(主观)", "", -1) permissionNameStr = strings.Replace(permissionNameStr, "(客观)", "", -1) permissionNameStr = strings.TrimRight(permissionNameStr, ",") slicePerZhengShi := strings.Split(permissionStrZhengShi, ",") var permissionNameStrZhengShi string for _, v := range slicePerZhengShi { if userType == 1 { //研选权限处理 if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) { permissionNameStrZhengShi += "'" + v + "'," } } else { permissionNameStrZhengShi += "'" + v + "'," } } permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(主观)", "", -1) permissionNameStrZhengShi = strings.Replace(permissionNameStrZhengShi, "(客观)", "", -1) permissionNameStrZhengShi = strings.TrimRight(permissionNameStrZhengShi, ",") mapUserType, e := GetActivityCcustomerTypeList() if e != nil { err = e return } var userTypeStr string userTypeStr = mapUserType[userType] fmt.Println("userTypeStr", userTypeStr) // 查研观向7.4-始终查询宏观的权限(无论是否有权限) if permissionNameStr == `` { permissionNameStr = `'宏观'` } else { permissionNameStr += `, '宏观'` } var sqlExport string // 专家权限处理 sqlExport = ` AND (art.customer_type_ids LIKE '%` + userTypeStr + `%' ` if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") { sqlExport += ` OR art.customer_type_ids LIKE '%4%' ` } sqlExport += `) ` if isPower == 1 { permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionNameStr + `)` condition += permissionSqlStr } var conditionOr string //查询全部可见的数据(是否全部客户可见) if adminIds != "" { condition += ` AND ( art.visible_range != 1 OR ( art.admin_id IN ( ` + adminIds + ` ) AND art.visible_range = 1 )) ` } //活动仅决策人可见 if isMaker == 0 { condition += ` AND art.is_maker_show = 0 ` } //condition += ` AND art.visible_range != 1 ` if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") { conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) ` } if (userType == 5) && strings.Contains(permissionStr, "专家") { conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) ` } if userType == 1 { conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) ` } else { conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) ` } if userType == 6 || userType == 7 { conditionOr += ` OR ( art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' ` + condition + `) ` } if companyProduct != nil { if companyProduct.Scale != "" { conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) ` } } conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user) if e != nil { err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error()) return } // 升级客户可查看范围 if conditionShengji != "" { conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionShengji + condition + ` ) ` } // 正式客户可查看范围 if conditionZhengshi != "" { conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionZhengshi + condition + ` ) ` } // 行业客户可查看范围 if conditionHangYe != "" { conditionOr += ` OR ( art.is_limit_people = 1 AND ` + conditionHangYe + condition + ` ) ` } if userType == 3 { condition += ` AND art.chart_permission_name IN (` + permissionNameStrZhengShi + `) ` } condition += ` AND art.is_limit_people = 1 ` conditionActivity = condition + permissionSqlStr + sqlExport + conditionOr return } // 获取可见的活动 func HandleActivityPowerList(listActivity []*models.CygxActivity, user *models.WxUserItem) (items []*models.CygxActivity, err error) { return } // 5.3版本活动标签字符串处理 func LabelStr(label string, isShowSubjectName int, temporaryLabel string) (labelNew string) { slicebr := strings.Split(label, "-") if len(slicebr) > 1 { if isShowSubjectName == 1 { labelNew = slicebr[1] } else { labelNew = slicebr[0] } } else { labelNew = label } if temporaryLabel != "" { labelNew = temporaryLabel } return labelNew } // 列表 func HandleActivityTypeHomeList(listType []*models.ActivityTypeHome, listActivity []*models.CygxActivity, user *models.WxUserItem) (items []*models.ActivityTypeHome, err error) { mapActivity := make(map[int][]*models.CygxActivityLabelList) activityIds := make([]int, 0) // 用于查询活动【新】标签Map for _, v := range listActivity { // 如果是C类电话会就不展示内容,且合并到分析师电话会 if v.ActivityTypeId == 7 { v.ActivityTypeId = 2 } // 如果是买方线下交流的活动,合并到专家线下交流 if v.ActivityTypeId == 8 { v.ActivityTypeId = 5 } //if v.ActivityTypeId == 1 { activityIds = append(activityIds, v.ActivityId) //} } // 活动【新】标签Map newLabelMap, _, e := GetActivityNewLabelMap(activityIds) if e != nil { err = errors.New("获取产业新标签Map失败,GetActivityNewLabelMap Err: " + e.Error()) return } activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动 mapkeyWord := make(map[string]string) for _, v := range listActivity { if v.Label == "" { continue } // 如果是C类电话会就不展示内容,且合并到分析师电话会 if v.ActivityTypeId == 7 { v.ActivityTypeId = 2 } item := new(models.CygxActivityLabelList) item.IsResearchPoints = activityPointsByUserAllMap[v.ActivityId] item.KeyWord = LabelStr(v.Label, v.IsShowSubjectName, v.TemporaryLabel) if _, ok := mapkeyWord[fmt.Sprint(v.ActivityTypeId, "-", item.KeyWord)]; ok { continue } item.Resource = 1 item.ActivityId = v.ActivityId if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN { item.IsResearch = true } //易董同步过来的活动只展示外部资源标签 if v.YidongActivityId != "" { item.IsResearchPoints = false item.IsResearch = false } if v.IsExternalLabel > 0 { item.IsExternalLabel = true } //if v.IsResearchPoints > 0 { item.IsResearchPoints = activityPointsByUserAllMap[v.ActivityId] //} item.City = v.City if utf8.RuneCountInString(v.City) != 2 { item.City = "" } item.IsNew = newLabelMap[v.ActivityId] mapActivity[v.ActivityTypeId] = append(mapActivity[v.ActivityTypeId], item) mapkeyWord[fmt.Sprint(v.ActivityTypeId, "-", item.KeyWord)] = item.KeyWord } for _, v := range listType { v.Resource = 1 if len(mapActivity[v.ActivityTypeId]) > 0 { v.List = mapActivity[v.ActivityTypeId] } else { v.List = make([]*models.CygxActivityLabelList, 0) } } items = listType return } // GetActivityVoiceResp 处理活动音频回放 func GetActivityVoiceResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVoiceReq, err error) { activityVoiceList, err := models.GetCygxActivityVoiceReqList(mapActivityId) if err != nil && err.Error() != utils.ErrNoRow() { return } mapActivityVoice := make(map[int]*models.CygxActivityVoiceReq) if len(activityVoiceList) > 0 { for _, v := range activityVoiceList { v.Type = 1 //活动音频为1 mapActivityVoice[v.ActivityId] = v } } mapItem = mapActivityVoice return } // GetActivityVideoResp 处理活动视频频回放 func GetActivityVideoResp(mapActivityId []int) (mapItem map[int]*models.CygxActivityVideoListResp, err error) { var condition string var ativityVIdstr string for _, v := range mapActivityId { ativityVIdstr += strconv.Itoa(v) + "," } if ativityVIdstr == "" { return } ativityVIdstr = strings.TrimRight(ativityVIdstr, ",") condition += ` AND art.activity_id IN (` + ativityVIdstr + `) ` var pars []interface{} //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05") //condition += ` AND art.activity_time > ? ` //pars = append(pars, endTime) videoList, e := models.GetActivityVideoListAll(condition, pars, 0, 1000) if e != nil && e.Error() != utils.ErrNoRow() { err = e return } mapActivityVideo := make(map[int]*models.CygxActivityVideoListResp) if len(videoList) > 0 { for _, v := range videoList { v.Type = 2 // 活动视频为 2 mapActivityVideo[v.ActivityId] = v } } mapItem = mapActivityVideo return } func ActivityButtonShow(item *models.ActivityDetail, user *models.WxUserItem, permissionArr []string) (itemActivity *models.ActivityListResp) { activityDetail := item //IsShowAppointment bool `description:"是否展示预约纪要"` //IsShowOutboundCall bool `description:"是否展示预约外呼"` //IsShowMeetingReminder bool `description:"是否展示会议提醒"` //IsShowHelpSsk bool `description:"是否展示帮我带问"` //IsShowSignup bool `description:"是否展示我要报名"` activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动 if strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) { activityDetail.IsResearch = true } //勾选【研选扣点】且扣点对象为参会人的活动,需要有买方研选的正式权限 if strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityDetail.ActivityId] { activityDetail.IsResearchSpecial = true } if activityDetail.SiginupDeadline == utils.FormatDateTimeInit { //报名截止时间处理 activityDetail.SiginupDeadline = "" } //如果报名截止时间不规范,或者是非研选扣点活动就把截止时间设置为空 if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints { activityDetail.CancelDeadline = "" } activityTimeText := activityDetail.ActivityTimeText activityTimeText = strings.Replace(activityTimeText, "(", "(", -1) activityTimeText = strings.Replace(activityTimeText, ")", ")", -1) activityDetail.ActivityTimeText = activityTimeText var yidongActivityUrl string activityDetail.IsShowAppointment = false //易董的操作按钮都隐藏 if activityDetail.YidongActivityId != "" { activityDetail.IsShowSignup = false activityDetail.IsShowDetails = true if activityDetail.YidongActivityId != "" { ydTgc, _ := GetYiDongCreateUserInfo(user) yidongLongLink, _ := GetYiDongOriginalLink(activityDetail) if yidongLongLink != "" { yidongActivityUrl = yidongLongLink + "%26source=11%26fromHz=true%26tgc=" + ydTgc } } } else { //专家电话会 1 if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") { activityDetail.IsShowHelpSsk = true } if activityDetail.ActiveState == "1" { //新的是否展示规则 if activityDetail.IsCanAppointmentMinutes == 1 { activityDetail.IsShowAppointment = true } //专家电话会 1 if activityDetail.ActivityTypeId == 1 { if activityDetail.LimitPeopleNum == 0 { activityDetail.IsShowOutboundCall = true } else { activityDetail.IsShowSignup = true } activityDetail.IsShowMeetingReminder = true activityDetail.IsShowHelpSsk = true } //分析师电话会 2 if activityDetail.ActivityTypeId == 2 { if activityDetail.LimitPeopleNum == 0 { activityDetail.IsShowOutboundCall = true } else { activityDetail.IsShowSignup = true } activityDetail.IsShowMeetingReminder = true } if activityDetail.ActivityTypeId == 3 { //司调研电话会(3)、扣点的研选活动只展示我要报名 if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 { activityDetail.IsShowSignup = true } else { activityDetail.IsShowMeetingReminder = true activityDetail.IsShowOutboundCall = true } } //公司线下调研 4 if activityDetail.ActivityTypeId == 4 { activityDetail.IsShowSignup = true } //专家线下沙龙 5 if activityDetail.ActivityTypeId == 5 { activityDetail.IsShowSignup = true } //分析师线下沙龙 6 if activityDetail.ActivityTypeId == 6 { activityDetail.IsShowSignup = true } //分析师电话会(C类) 7 if activityDetail.ActivityTypeId == 7 { activityDetail.IsShowSignup = true activityDetail.IsShowMeetingReminder = true } //买方线下交流 8 // 查研观向 11.0 if activityDetail.ActivityTypeId == 8 { activityDetail.IsShowSignup = true } //如果是易董创建的活动,展示我要报名,不展示预约外呼 if activityDetail.IsYidongConduct { activityDetail.IsShowSignup = true activityDetail.IsShowOutboundCall = false } } } activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId] authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId) if e != nil { e = errors.New("获取用户权限失败, Err: " + e.Error()) return } if utils.InArrayByStr(permissionArr, utils.YAN_XUAN_KOU_DIAN_BAO_NAME) { permissionArr = append(permissionArr, utils.CHART_PERMISSION_NAME_MF_YANXUAN) } //如果是易董同步过来的,只展示外部资源标签 if activityDetail.YidongActivityId != "" { activityDetail.IsExternalLabel = true activityDetail.IsResearch = false activityDetail.IsResearchSpecial = false } v := activityDetail itemActivity = &models.ActivityListResp{ ActivityId: v.ActivityId, ActivityTypeId: v.ActivityTypeId, ActivityTypeName: v.ActivityTypeName, ChartPermissionId: v.ChartPermissionId, ChartPermissionName: v.ChartPermissionName, IsLimitPeople: v.IsLimitPeople, LimitPeopleNum: v.LimitPeopleNum, LastUpdatedTime: v.LastUpdatedTime, ActivityTime: v.ActivityTime, ActivityTimeText: v.ActivityTimeText, DistinguishedGuest: v.DistinguishedGuest, Host: v.Host, Speaker: v.Speaker, MainlandTell: v.MainlandTell, HongKongTell: v.HongKongTell, TaiwanTell: v.TaiwanTell, AmericaTell: v.AmericaTell, ParticipationCode: v.ParticipationCode, Theme: v.Theme, Expert: v.Expert, ActivityName: v.ActivityName, OnlineParticipation: v.OnlineParticipation, ReportLink: v.ReportLink, AppAttendance: v.AppAttendance, ConferencePassword: v.ConferencePassword, City: v.City, Address: v.Address, Highlights: v.Highlights, Remarks: v.Remarks, IsSignup: v.IsSignup, IsCancelMeetingReminder: v.IsCancelMeetingReminder, IsAppointment: v.IsAppointment, ActiveState: v.ActiveState, IsShowSustainable: v.IsShowSustainable, Description: v.Description, IsResearch: v.IsResearch, IsHideAppointment: v.IsHideAppointment, IsCClassMeeting: v.IsCClassMeeting, Label: v.Label, ImgUrl: v.ImgUrl, ImgUrlText: v.ImgUrlText, ActivityType: v.ActivityType, IsShowOutboundCall: v.IsShowOutboundCall, IsShowMeetingReminder: v.IsShowMeetingReminder, IsShowHelpSsk: v.IsShowHelpSsk, IsShowSignup: v.IsShowSignup, IsShowAppointment: v.IsShowAppointment, IsShowDetails: v.IsShowDetails, AudioLink: v.AudioLink, VoiceDetail: v.VoiceList, VideoDetail: v.VideoDetail, FileType: v.FileType, SourceType: v.SourceType, SignupNum: v.SignupNum, YidongActivityUrl: yidongActivityUrl, Explain: utils.ACtIVITY_SPECIAL_EXPLAIN, TripImgLink: v.TripImgLink, Days: v.Days, SignupType: v.SignupType, IsYidongConduct: v.IsYidongConduct, IsCanOutboundCall: v.IsCanOutboundCall, TencentConferenceNumber: v.TencentConferenceNumber, IsResearchSpecial: v.IsResearchSpecial, LinkParticipants: v.LinkParticipants, IsResearchPoints: v.IsResearchPoints, IsExternalLabel: v.IsExternalLabel, SiginupDeadline: v.SiginupDeadline, CancelDeadline: v.CancelDeadline, } au := new(models.UserPermissionAuthInfo) au.SellerName = authInfo.SellerName au.SellerMobile = authInfo.SellerMobile au.HasPermission = authInfo.HasPermission au.OperationMode = authInfo.OperationMode if au.HasPermission == 1 { // 非宏观权限进一步判断是否有权限 if v.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, v.ChartPermissionName) { au.HasPermission = 2 } //如果是易董的活动,主、副权限有一个满足即可 查研观向 11.0 if v.YidongActivityId != "" { if utils.InArrayByStr(permissionArr, v.ChartPermissionName) || utils.InArrayByStr(permissionArr, v.ChartPermissionNameDeputy) { au.HasPermission = 1 } } } // 无权限的弹框提示 if au.HasPermission != 1 { if au.OperationMode == UserPermissionOperationModeCall { if v.FileType == 1 { au.PopupMsg = UserPermissionPopupMsgCallMicroVoice } else { au.PopupMsg = UserPermissionPopupMsgCallMicroVideo } } else { if v.FileType == 1 { au.PopupMsg = UserPermissionPopupMsgApplyMicroVoice } else { au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo } } } itemActivity.AuthInfo = au //处理用户已经报名了的行程 var activityIds []int activityIds = append(activityIds, v.ActivityId) UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId) if e != nil { e = errors.New("GetSpecialTripUserMap, Err: " + e.Error()) return } if _, ok := UserMap[v.ActivityId]; ok { itemActivity.IsTrip = 1 } if itemActivity.Days == 0 { itemActivity.TripStatus = 1 //activityDetail.Explain = utils.ACtIVITY_SPECIAL_EXPLAIN } else { itemActivity.TripStatus = 2 //itemActivity.TripImgLink = itemActivity.TripImgLinkFix //activityDetail.Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN } return } func ActivityArrButtonShow(items []*models.ActivityDetail, user *models.WxUserItem, permissionArr []string) (itemsActivity []*models.ActivityListResp) { var activityIds []int authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId) if e != nil { e = errors.New("获取用户权限失败, Err: " + e.Error()) return } activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动 for _, activityDetail := range items { //IsShowAppointment bool `description:"是否展示预约纪要"` //IsShowOutboundCall bool `description:"是否展示预约外呼"` //IsShowMeetingReminder bool `description:"是否展示会议提醒"` //IsShowHelpSsk bool `description:"是否展示帮我带问"` //IsShowSignup bool `description:"是否展示我要报名"` if strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) { activityDetail.IsResearch = true } //如果是 公司调研电话会:3,或 专家线下沙龙:5 而且 除易董同步过来的以外的研选类型活动 //if (activityDetail.ActivityTypeId == 3 || activityDetail.ActivityTypeId == 5) && activityDetail.YidongActivityId == "" && strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) { // activityDetail.IsResearchSpecial = true //} //勾选【研选扣点】且扣点对象为参会人的活动,需要有买方研选的正式权限 if strings.Contains(activityDetail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityDetail.ActivityId] { activityDetail.IsResearchSpecial = true } if activityDetail.SiginupDeadline == utils.FormatDateTimeInit { //报名截止时间处理 activityDetail.SiginupDeadline = "" } //如果报名截止时间不规范,或者是非研选扣点活动就把截止时间设置为空 if activityDetail.CancelDeadline == utils.FormatDateTimeInit || !activityDetail.IsResearchPoints { activityDetail.CancelDeadline = "" } activityTimeText := activityDetail.ActivityTimeText activityTimeText = strings.Replace(activityTimeText, "(", "(", -1) activityTimeText = strings.Replace(activityTimeText, ")", ")", -1) activityDetail.ActivityTimeText = activityTimeText var yidongActivityUrl string activityDetail.IsShowAppointment = false //易董的操作按钮都隐藏 if activityDetail.YidongActivityId != "" { activityDetail.IsShowSignup = false activityDetail.IsShowDetails = true activityDetail.IsYidongActivity = true //if activityDetail.YidongActivityId != "" { // ydTgc, _ := GetYiDongCreateUserInfo(user) // yidongLongLink, _ := GetYiDongOriginalLink(activityDetail) // if yidongLongLink != "" { // yidongActivityUrl = yidongLongLink + "%26source=11%26fromHz=true%26tgc=" + ydTgc // } //} } else { //专家电话会 1 if activityDetail.ActivityTypeId == 1 && activityDetail.IsLimitPeople == 0 && (activityDetail.ActiveState == "1" || activityDetail.ActiveState == "2") { activityDetail.IsShowHelpSsk = true } if activityDetail.ActiveState == "1" { //新的是否展示规则 if activityDetail.IsCanAppointmentMinutes == 1 { activityDetail.IsShowAppointment = true } //专家电话会 1 if activityDetail.ActivityTypeId == 1 { if activityDetail.LimitPeopleNum == 0 { activityDetail.IsShowOutboundCall = true } else { activityDetail.IsShowSignup = true } activityDetail.IsShowMeetingReminder = true activityDetail.IsShowHelpSsk = true } //分析师电话会 2 if activityDetail.ActivityTypeId == 2 { if activityDetail.LimitPeopleNum == 0 { activityDetail.IsShowOutboundCall = true } else { activityDetail.IsShowSignup = true } activityDetail.IsShowMeetingReminder = true } if activityDetail.ActivityTypeId == 3 { //司调研电话会(3)、扣点的研选活动只展示我要报名 if activityDetail.IsResearchPoints || activityDetail.LimitPeopleNum > 0 { activityDetail.IsShowSignup = true } else { activityDetail.IsShowMeetingReminder = true activityDetail.IsShowOutboundCall = true } } //公司线下调研 4 if activityDetail.ActivityTypeId == 4 { activityDetail.IsShowSignup = true } //专家线下沙龙 5 if activityDetail.ActivityTypeId == 5 { activityDetail.IsShowSignup = true } //分析师线下沙龙 6 if activityDetail.ActivityTypeId == 6 { activityDetail.IsShowSignup = true } //分析师电话会(C类) 7 if activityDetail.ActivityTypeId == 7 { activityDetail.IsShowSignup = true activityDetail.IsShowMeetingReminder = true } //买方线下交流 8 // 查研观向 11.0 if activityDetail.ActivityTypeId == 8 { activityDetail.IsShowSignup = true } //如果是易董创建的活动,展示我要报名,不展示预约外呼 if activityDetail.IsYidongConduct { activityDetail.IsShowSignup = true activityDetail.IsShowOutboundCall = false } } } activityDetail.IsResearchPoints = activityPointsByUserAllMap[activityDetail.ActivityId] v := activityDetail itemActivity := &models.ActivityListResp{ ActivityId: v.ActivityId, ActivityTypeId: v.ActivityTypeId, ActivityTypeName: v.ActivityTypeName, ChartPermissionId: v.ChartPermissionId, ChartPermissionName: v.ChartPermissionName, IsLimitPeople: v.IsLimitPeople, LimitPeopleNum: v.LimitPeopleNum, LastUpdatedTime: v.LastUpdatedTime, ActivityTime: v.ActivityTime, ActivityTimeText: v.ActivityTimeText, DistinguishedGuest: v.DistinguishedGuest, Host: v.Host, Speaker: v.Speaker, MainlandTell: v.MainlandTell, HongKongTell: v.HongKongTell, TaiwanTell: v.TaiwanTell, AmericaTell: v.AmericaTell, ParticipationCode: v.ParticipationCode, Theme: v.Theme, Expert: v.Expert, ActivityName: v.ActivityName, OnlineParticipation: v.OnlineParticipation, ReportLink: v.ReportLink, AppAttendance: v.AppAttendance, ConferencePassword: v.ConferencePassword, City: v.City, Address: v.Address, Highlights: v.Highlights, Remarks: v.Remarks, IsSignup: v.IsSignup, IsCancelMeetingReminder: v.IsCancelMeetingReminder, IsAppointment: v.IsAppointment, ActiveState: v.ActiveState, IsShowSustainable: v.IsShowSustainable, Description: v.Description, IsResearch: v.IsResearch, IsHideAppointment: v.IsHideAppointment, IsCClassMeeting: v.IsCClassMeeting, Label: v.Label, ImgUrl: v.ImgUrl, ImgUrlText: v.ImgUrlText, ActivityType: v.ActivityType, IsShowOutboundCall: v.IsShowOutboundCall, IsShowMeetingReminder: v.IsShowMeetingReminder, IsShowHelpSsk: v.IsShowHelpSsk, IsShowSignup: v.IsShowSignup, IsShowAppointment: v.IsShowAppointment, IsShowDetails: v.IsShowDetails, AudioLink: v.AudioLink, VoiceDetail: v.VoiceList, VideoDetail: v.VideoDetail, FileType: v.FileType, SourceType: v.SourceType, SignupNum: v.SignupNum, YidongActivityUrl: yidongActivityUrl, Explain: utils.ACtIVITY_SPECIAL_EXPLAIN, TripImgLink: v.TripImgLink, Days: v.Days, SignupType: v.SignupType, IsYidongConduct: v.IsYidongConduct, IsCanOutboundCall: v.IsCanOutboundCall, TencentConferenceNumber: v.TencentConferenceNumber, IsResearchSpecial: v.IsResearchSpecial, LinkParticipants: v.LinkParticipants, IsResearchPoints: v.IsResearchPoints, IsExternalLabel: v.IsExternalLabel, SiginupDeadline: v.SiginupDeadline, CancelDeadline: v.CancelDeadline, IsYidongActivity: v.IsYidongActivity, TopTime: v.TopTime, } au := new(models.UserPermissionAuthInfo) au.SellerName = authInfo.SellerName au.SellerMobile = authInfo.SellerMobile au.HasPermission = authInfo.HasPermission au.OperationMode = authInfo.OperationMode if au.HasPermission == 1 { // 非宏观权限进一步判断是否有权限 if v.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, v.ChartPermissionName) { au.HasPermission = 2 } //如果是易董的活动,主、副权限有一个满足即可 查研观向 11.0 if v.YidongActivityId != "" { if utils.InArrayByStr(permissionArr, v.ChartPermissionName) || utils.InArrayByStr(permissionArr, v.ChartPermissionNameDeputy) { au.HasPermission = 1 } } } // 无权限的弹框提示 if au.HasPermission != 1 { if au.OperationMode == UserPermissionOperationModeCall { if v.FileType == 1 { au.PopupMsg = UserPermissionPopupMsgCallMicroVoice } else { au.PopupMsg = UserPermissionPopupMsgCallMicroVideo } } else { if v.FileType == 1 { au.PopupMsg = UserPermissionPopupMsgApplyMicroVoice } else { au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo } } } //如果是易董同步过来的,只展示外部资源标签 if activityDetail.YidongActivityId != "" { itemActivity.IsExternalLabel = true itemActivity.IsResearch = false itemActivity.IsResearchSpecial = false } itemActivity.AuthInfo = au //处理用户已经报名了的行程 activityIds = append(activityIds, v.ActivityId) itemsActivity = append(itemsActivity, itemActivity) } //处理专项调研 UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId) if e != nil { e = errors.New("GetSpecialTripUserMap, Err: " + e.Error()) return } for _, v := range itemsActivity { if _, ok := UserMap[v.ActivityId]; ok { v.IsTrip = 1 } if v.Days == 0 { v.TripStatus = 1 } else { v.TripStatus = 2 } } return } func ActivityDetaailShow(activityInfo *models.ActivityListResp) (itemActivity *models.ActivityListResp, err error) { itemActivity = activityInfo if GetShowSustainable() && strings.Contains(itemActivity.ChartPermissionName, "研选") { itemActivity.IsShowSustainable = true } if activityInfo.SignupNum > activityInfo.LimitPeopleNum { activityInfo.SignupNum = activityInfo.LimitPeopleNum } if activityInfo.ReportLink != "" { artList, e := GetActivityReportLinkToArticleList(activityInfo) if e != nil && e.Error() != utils.ErrNoRow() { err = e return } if len(artList) == 0 { activityInfo.ArticleList = make([]*models.ActivityArticleResp, 0) } else { activityInfo.ArticleList = artList } } else { activityInfo.ArticleList = make([]*models.ActivityArticleResp, 0) } activityInfo.ActivityTypeName = strings.Replace(activityInfo.ActivityTypeName, "(C类)", "", -1) return } // GetActivityNewLabelMap 获取活动【新】标签Map func GetActivityNewLabelMap(activityIds []int) (labelMap map[int]bool, industryNewMap map[int]bool, err error) { labelMap = make(map[int]bool, 0) industryNewMap = make(map[int]bool, 0) if len(activityIds) == 0 { return } // 获取活动关联的产业 var groupCond string var groupPars []interface{} groupCond += ` AND a.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) AND b.source = 1 ` groupPars = append(groupPars, activityIds) groups, e := models.GetActivityIndustryRelationList(groupCond, groupPars) if e != nil { err = errors.New("获取活动产业关联列表失败, Err: " + e.Error()) return } activityIndustryMap := make(map[int][]int, 0) industryIds := make([]int, 0) for i := range groups { industryIds = append(industryIds, groups[i].IndustrialManagementId) activityIndustryMap[groups[i].ActivityId] = append(activityIndustryMap[groups[i].ActivityId], groups[i].IndustrialManagementId) } // 获取新产业Map industryLabelMap, e := GetIndustryNewLabelMap(industryIds) if e != nil { err = errors.New("获取产业新标签Map失败, Err: " + e.Error()) return } // 判断活动是否为新 for k := range industryLabelMap { for k2, v2 := range activityIndustryMap { if labelMap[k2] { continue } // 活动的产业ID中存在一个新产业即为新活动 if utils.InArrayByInt(v2, k) { labelMap[k2] = true } } } // //////产业关联的弘则报告发布日期在三个月以内的活动、产业显示 NEW标签 //articNewLabel, e := GetArticNewLabelWhithActivity3Month() //if e != nil { // err = errors.New("获取产业新标签Map失败, Err: " + e.Error()) // return //} //for k := range articNewLabel { // labelMap[k] = true //} return } // GetIndustryNewLabelMap 获取产业【新】标签Map func GetIndustryNewLabelMap(industryIds []int) (labelMap map[int]bool, err error) { labelMap = make(map[int]bool, 0) industryIdLen := len(industryIds) if industryIdLen == 0 { return } // 获取产业关联的报告最早发布时间及最近的发布时间 var timeCond string var timePars []interface{} timeCond += ` AND b.publish_status = 1` if industryIdLen > 0 { timeCond += ` AND a.industrial_management_id IN (` + utils.GetOrmInReplace(industryIdLen) + `)` timePars = append(timePars, industryIds) } //只要弘则报告,不要研选报告 timeCond += ` AND b.article_id < ? ` timePars = append(timePars, utils.SummaryArticleId) industryTimeList, e := models.GetIndustryArticleMinMaxPublishTime(timeCond, timePars) if e != nil { err = errors.New("获取产业文章最大最小发布时间失败, Err: " + e.Error()) return } // 判断产业是否为新 nowTime := time.Now().Local() threeMonthBefore := nowTime.AddDate(0, -3, 0) nullTime, _ := time.ParseInLocation(utils.FormatDateTime, "0001-01-01 00:00:00", time.Local) industryMap := make(map[int]*models.IndustryArticleMinMaxPublishTime, 0) for i := range industryTimeList { industryMap[industryTimeList[i].IndustrialManagementId] = industryTimeList[i] } for i := range industryIds { iid := industryIds[i] item := industryMap[iid] if item != nil { // 最早发布时间为空 / 最早发布时间在三个月前之后 if item.MinPublishTime.Equal(nullTime) || (item.MinPublishTime.After(threeMonthBefore)) { labelMap[iid] = true } } else { // 产业无报告, 则为新产业 labelMap[iid] = true } } return } // GetSpecialDetailUserPower 处理用户查看详情的权限 func GetActivityDetailUserPower(user *models.WxUserItem, activityInfo *models.ActivityDetail) (havePower, isResearchSpecial bool, err error) { var companyDetailStatus string var userTypeStr string userId := user.UserId activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动 //勾选【研选扣点】且扣点对象为参会人的活动,需要有买方研选的正式权限 if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityInfo.ActivityId] { isResearchSpecial = true } //如果是弘则的用户或者宏观的权限不做校验 //if (GetBelongingRai(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID) || activityInfo.ChartPermissionName == utils.HONG_GUAN_NAME { if GetBelongingRai(user.Mobile) && user.CompanyId == utils.HZ_COMPANY_ID { havePower = true return } userType, permissionStr, permissionStrZhengShi, e := GetUserTypeZhengShi(user.CompanyId) if e != nil { err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error()) return } //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称 mfyxUserPermissionTotal := GetMfyxUserPermissionTotal(userId) if mfyxUserPermissionTotal == 1 { permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN } //如果正式权限有开通 研选扣点包 ,那么就拼接一个 研选订阅的权限 if strings.Contains(permissionStrZhengShi, utils.YAN_XUAN_KOU_DIAN_BAO_NAME) { permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN permissionStrZhengShi += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN } //如果测试权限有开通 研选扣点包 ,那么就拼接一个 研选订阅的权限 if strings.Contains(permissionStr, utils.YAN_XUAN_KOU_DIAN_BAO_NAME) { permissionStr += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN } //如果一个权限都没有就返回无权限 if permissionStr == "" { return } //永续客户,无法查看研选权限,但是下面的联系人,单独开通研选后,也可以查看研选内容 if userType == 1 && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && mfyxUserPermissionTotal == 0 { havePower = false return } permissionStr += "," + utils.HONG_GUAN_NAME // 添加一个宏观权限 if permissionStrZhengShi == "" { permissionStrZhengShi = utils.HONG_GUAN_NAME // 添加一个宏观权限 } else { permissionStrZhengShi += "," + utils.HONG_GUAN_NAME // 添加一个宏观权限 } //如果是易董的活动,主、副权限有一个满足即可 if activityInfo.YidongActivityId != "" { if strings.Contains(permissionStr, activityInfo.ChartPermissionName) || strings.Contains(permissionStr, activityInfo.ChartPermissionNameDeputy) { havePower = true return } } //如果权限不包含那么直接返回 if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) { return } else { havePower = true } //如果是 对用户的研选扣点的必须要有研选的正式权限 if activityInfo.IsResearchPoints { //获取活动对用户要扣的点 userPointsNum, e := models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId) if e != nil { err = errors.New("GetActivitySignupSuccessByUserCountNoHz, Err: " + e.Error()) return } if userPointsNum > 0 { //if !strings.Contains(permissionStr, utils.CHART_PERMISSION_NAME_YANXUAN) { // //如果连试用权限都没有,那么久按照普通的研选样式展示 // isResearchSpecial = false //} if !strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) { havePower = false return } } } //处理决策人可见权限 if user.IsMaker == 0 && activityInfo.IsMakerShow == 1 { havePower = false return } // 处理本组可见权限 if activityInfo.VisibleRange == 1 { adminIds, e := models.GetSelleridWhichGroup(user.CompanyId, 2) if e != nil { err = errors.New("GetSelleridWhichGroup, Err: " + e.Error()) return } haveVisibleRange := false adminIdSlice := strings.Split(adminIds, ",") for _, v := range adminIdSlice { if v == strconv.Itoa(activityInfo.AdminId) { haveVisibleRange = true } } if activityInfo.AdminId > 0 { adminGroup := GetAdminActivityPermission(activityInfo.AdminId) for _, v := range adminGroup { if v == activityInfo.AdminId { haveVisibleRange = true } } } if !haveVisibleRange { havePower = false return } } if permissionStr == "" { return } //如果是易董的活动且属于研选类型,只要开通任何权限就可以查看详情 if activityInfo.YidongActivityId != "" && permissionStr != "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) { havePower = true return } //医药消费,科技,智造四大行业,验证主客观。如果主客观校验不通过,那么直接返回 if strings.Contains(utils.YI_YAO_NAME+utils.XIAO_FEI_NAME+utils.KE_JI_NAME+utils.ZHI_ZAO_NAME, activityInfo.ChartPermissionName) { if activityInfo.ActivityTypeId == 2 || activityInfo.ActivityTypeId == 6 || activityInfo.ActivityTypeId == 7 { if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(主观)") { havePower = true } else { havePower = false } } else { if strings.Contains(permissionStr, activityInfo.ChartPermissionName+"(客观)") { havePower = true } else { havePower = false } } //如果主客观校验不通过,那么直接返回 if !havePower { return } } if activityInfo.LimitPeopleNum > 0 { mapUserType, e := GetActivityCcustomerTypeList() if e != nil { err = e return } userTypeStr = mapUserType[userType] // 永续客户、大套餐客户、30W套餐客户可以查看行业升级套餐客户 权限 if userTypeStr == "1" || userTypeStr == "2" || userTypeStr == "AA" { if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && strings.Contains(activityInfo.CustomerTypeIds, "8") { havePower = true //return } } } else { if strings.Contains(permissionStr, activityInfo.ChartPermissionName) { havePower = true return } } //判断管理规模是否满足 companyProduct, e := models.GetCompanyProductDetail(user.CompanyId, 2) if e != nil { err = e return } if companyProduct != nil && activityInfo.Scale != "" { if strings.Contains(activityInfo.Scale, companyProduct.Scale) { havePower = true } } if user.CompanyId <= 1 { return } else { if permissionStr == "" { return } else { companyDetail, e := models.GetCompanyDetailById(user.CompanyId) if e != nil { err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error()) return } if companyDetail == nil { err = errors.New("客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)) return } companyDetailStatus = companyDetail.Status } } //宏观满足用户可见身份验证权限既满足 2023-9-18 if activityInfo.ChartPermissionId == 1 { if activityInfo.LimitPeopleNum > 0 { if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) { havePower = true return } } else { havePower = true return } } if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3) && strings.Contains(permissionStr, "专家") && activityInfo.LimitPeopleNum == 0 { havePower = true } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "正式" && strings.Contains(activityInfo.CustomerTypeIds, "4") { havePower = true } else if activityInfo.ActivityTypeId == 3 && strings.Contains(permissionStr, "专家") && companyDetailStatus == "试用" && strings.Contains(activityInfo.CustomerTypeIds, "5") { havePower = true } else if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 4 || activityInfo.ActivityTypeId == 5) && strings.Contains(permissionStr, "专家") { havePower = true } fmt.Println(permissionStrZhengShi) //if (strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略") && strings.Contains(permissionStr, activityInfo.ChartPermissionName) { // havePower = true // return //} if strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略" { if strings.Contains(activityInfo.CustomerTypeIds, "5") { if strings.Contains(permissionStr, activityInfo.ChartPermissionName) { havePower = true return } } else { if strings.Contains(permissionStrZhengShi, activityInfo.ChartPermissionName) { havePower = true return } } } permissionShengji, errs := models.GetCompanyPermissionByUserTrip(user.CompanyId) if errs != nil { err = errs return } //fmt.Println("主客观2", havePower) //if strings.Contains(permissionStr, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) { // havePower = true //} //fmt.Println("主客观3", havePower) //处理升级权限以及用户身份的 双重判断 if activityInfo.CustomerTypeIds != "" { if !strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) && userTypeStr != "8" { havePower = false if strings.Contains(permissionShengji, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") { havePower = true } } } if havePower && activityInfo.LimitPeopleNum > 0 { //对于一些特殊的活动,即使权限满足也不给查看 noPower, e := GetShareNoPowe(activityInfo, permissionStr, userType, user) if e != nil { err = errors.New("GetShareNoPowe, Err: " + e.Error()) return } if noPower { havePower = false } } return } // 校验被分享的用户是否有查看详情的权限 func GetShareNoPowe(activityInfo *models.ActivityDetail, permissionStr string, userType int, user *models.WxUserItem) (noPower bool, err error) { //如果是弘则的就不进行可见权限校验 if user.CompanyId == utils.HZ_COMPANY_ID { return } //var noPower bool //if !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(userType)) { // noPower = true //} //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户 //if userType == 2 && strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(2)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(4)) { // noPower = true //} //if userType == 2 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(2)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) { // noPower = true //} //if userType == 3 && strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(4)) { // noPower = true //} //if userType == 3 && !strings.Contains(permissionStr, "专家") && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(3)) { // noPower = true //} if userType == 8 { permissionShengji, errs := models.GetCompanyPermissionByUserZhengShiTrip(user.CompanyId) if errs != nil { err = errs return } if !strings.Contains(permissionShengji, activityInfo.ChartPermissionName) { noPower = true return } } if !noPower { noPower, err = CheckUserPowerByActivityChoose(user, activityInfo) } return } // 处理活动本组们是否决策人权限 func CheckUserPowerByActivityChoose(user *models.WxUserItem, activityInfo *models.ActivityDetail) (noPower bool, err error) { //处理 见范围 1,仅本组可见 、2,全部客户可见 if activityInfo.VisibleRange == 1 { adminIds, errAdmin := models.GetSelleridWhichGroup(user.CompanyId, 2) if errAdmin != nil { err = errAdmin return } sliceAdminIds := strings.Split(adminIds, ",") var haveAdminId bool for _, v := range sliceAdminIds { if v == strconv.Itoa(activityInfo.AdminId) { haveAdminId = true } } if !haveAdminId { noPower = true } } //处理 是否仅决策人可见 0,否 、1,是 if activityInfo.IsMakerShow == 1 { if user.IsMaker == 0 { noPower = true } } return } // 判断预约纪要按钮是否显示 func IsShowAppointment(activityTypeId int, chartPermissionName string) (isShowAppointment bool) { if activityTypeId == 1 || activityTypeId == 2 || activityTypeId == 3 || activityTypeId == 4 { isShowAppointment = true } if activityTypeId == 5 && chartPermissionName == "医药" { isShowAppointment = true } return } // GetindustryVideoDetailById 通过视频ID获取视频详情 func GetActivityVideoDetailById(user *models.WxUserItem, videoId int) (industryVideo *models.CygxActivityVideoDetailResp, AuthInfo *models.UserPermissionAuthInfo, err error) { total, e := models.GetActivityVideoByVideoIdCount(videoId) if e != nil { err = errors.New("获取活动的视频失败,GetActivityVideoByVideoIdCount " + e.Error()) return } if total == 0 { err = errors.New("视频不存在,或已取消发布") return } // 用户权限 authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId) if e != nil { err = errors.New("获取用户权限失败,GetUserRaiPermissionInfo " + e.Error()) return } videoSimple := new(models.CygxActivityVideoDetailResp) // 权限 var au *models.UserPermissionAuthInfo videoSimple, e = models.GetCygxActivityVideoById(videoId) if e != nil { err = errors.New("获取产业关联的视频失败,GetMicroRoadshowVideoByIndustryId " + e.Error()) return } else { //videoSimple.Id = video.Id //videoSimple.Title = video.Title //videoSimple.ResourceUrl = video.ResourceUrl //videoSimple.PlaySeconds = video.PlaySeconds //videoSimple.ActivityId = video.ActivityId //videoSimple.ChartPermissionId = video.ChartPermissionId if videoSimple.BackgroundImg == "" { // 获取默认图配置 _, videoMap, _, _, e := GetMicroRoadShowDefaultImgConfig() if e != nil { err = errors.New("获取视频默认配置图失败,GetMicroRoadshowVideoByIndustryId " + e.Error()) return } videoSimple.BackgroundImg = videoMap[videoSimple.ChartPermissionId] } au = new(models.UserPermissionAuthInfo) au.SellerName = authInfo.SellerName au.SellerMobile = authInfo.SellerMobile au.HasPermission = authInfo.HasPermission au.OperationMode = authInfo.OperationMode if au.HasPermission == 1 { // 非宏观权限进一步判断是否有权限 if videoSimple.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, videoSimple.ChartPermissionName) { au.HasPermission = 2 } } // 无权限的弹框提示 if au.HasPermission != 1 { if au.OperationMode == UserPermissionOperationModeCall { au.PopupMsg = UserPermissionPopupMsgCallMicroVideo } else { au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo } videoSimple.ResourceUrl = "" } } videoSimple.Type = 2 industryVideo = videoSimple AuthInfo = au return } // 用户活动操作行为,模板消息推送 func ActivityUserRemind(user *models.WxUserItem, activityDetail *models.ActivityDetail, source int) (err error) { defer func() { if err != nil { go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "ActivityUserRemind ErrMsg:"+err.Error(), utils.EmailSendToUsers) } }() //获取销售手机号 countUser, e := models.GetUserRemind(user.UserId) if e != nil { err = errors.New("GetUserRemind, Err: " + e.Error()) return } //获取销售手机号 sellerItemQy, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error()) return } if sellerItemQy == nil { err = nil return } //某销售下的所有客户活动报名/预约外呼时,模板消息提醒该销售(可设置销售范围,随时增减销售) conf, e := models.GetConfigByCode("tpl_msg_seller_mobile") if e != nil { err = errors.New("GetConfigByCode, Err: " + e.Error()) return } //如果用户没有设置消息提醒,而且销售的手机号也没有添加到配置中,那么就不推送模版消息 if countUser == 0 && !strings.Contains(conf.ConfigValue, sellerItemQy.Mobile) { err = nil return } var sourceMsg string sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号 if e != nil { err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error()) return } sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",") if source == 1 { sourceMsg = "预约外呼" } else if source == 2 { sourceMsg = "设置会议提醒" } else if source == 3 { sourceMsg = "预约纪要" } else if source == 4 { sourceMsg = "活动报名" } openIdList, e := models.GetWxOpenIdByMobileList(sllerAndShareMobiles) if e != nil { err = errors.New("GetWxOpenIdByMobileList, Err: " + e.Error()) return err } var keyword1 string var keyword2 string keyword1 = activityDetail.ActivityName keyword2 = fmt.Sprint("互动:", sourceMsg, ",", user.RealName, "--", user.CompanyName) SendWxMsgWithActivityUserRemind(keyword1, keyword2, openIdList, activityDetail.ActivityId) // 类目模版买方研选 if activityDetail.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN { openIdListMfyx, e := models.GetMfyxWxOpenIdByMobileList(sllerAndShareMobiles) if e != nil { err = errors.New("GetMfyxWxOpenIdByMobileList, Err: " + e.Error()) return err } var redirectUrl string keyword1 = utils.TruncateActivityNameString(user.RealName + "-" + user.CompanyName) keyword2 = fmt.Sprint("互动提醒:", sourceMsg) keyword3 := utils.TruncateActivityNameString(activityDetail.ActivityName) keyword4 := time.Now().Format(utils.FormatDateTimeMinute2) redirectUrl = utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(activityDetail.ActivityId) SendWxCategoryMsgWithActivityUserRemind(keyword1, keyword2, keyword3, keyword4, redirectUrl, openIdListMfyx, activityDetail.ActivityId) } return } // 用户音视频回放操作操作行为,模板消息推送 func ActivityVideoUserRmind(user *models.WxUserItem, activityId, fileType int) (err error) { defer func() { if err != nil { go utils.SendAlarmMsg("用户音视频回放操作操作行为,模板消息推送失败"+err.Error(), 2) } }() countUser, err := models.GetUserRemind(user.UserId) if err != nil { return err } if countUser == 0 { return err } var first string var keyword1 string var keyword2 string var keyword3 string var keyword4 string var remark string //获取销售手机号 sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2) if err != nil && err.Error() != utils.ErrNoRow() { return err } if sellerItemQy != nil { sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号 if e != nil { err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error()) return } sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",") openIdList, e := models.GetWxOpenIdByMobileList(sllerAndShareMobiles) if e != nil { err = errors.New("GetSellerByAdminId, Err: " + e.Error()) return } //TripStatus int `description:"行程进行状态 1:预报名,2:确定行程"` if fileType == 1 { activityInfo, e := models.GetCygxActivityVideoByActivityId(activityId) if e != nil { err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error()) return } if activityInfo == nil { return } keyword1 = activityInfo.VideoName keyword2 = fmt.Sprint("互动:播放视频,", user.RealName, "--", user.CompanyName) first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放视频") } else { activityInfo, e := models.GetCygxActivityVoiceByActivityId(activityId) if e != nil { err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error()) return } if activityInfo == nil { return } keyword1 = activityInfo.VoiceName keyword2 = fmt.Sprint("互动:播放音频,", user.RealName, "--", user.CompanyName) first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:播放音频") } //keyword2 = "__" //remark = "点击查看活动详情" openIdArr := make([]string, 0) for _, v := range openIdList { openIdArr = append(openIdArr, v.OpenId) } redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId) sendInfo := new(SendWxTemplate) sendInfo.First = first sendInfo.Keyword1 = keyword1 sendInfo.Keyword2 = keyword2 sendInfo.Keyword3 = keyword3 sendInfo.Keyword4 = keyword4 sendInfo.Remark = remark sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind sendInfo.RedirectUrl = redirectUrl sendInfo.RedirectTarget = 3 sendInfo.Resource = strconv.Itoa(activityId) sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD sendInfo.OpenIdArr = openIdArr err = PublicSendTemplateMsg(sendInfo) if err != nil { return } } return } // 获取活动分享封面图片 func GetActivityShareImg(activityDetail *models.ActivityDetail) (shareImg string) { var err error defer func() { if err != nil { go utils.SendAlarmMsg(fmt.Sprint("获取活动分享封面图片失败Err:", err.Error(), "活动ID:", activityDetail.ActivityId), 2) } }() activityTypeId := activityDetail.ActivityTypeId chartPermissionId := activityDetail.ChartPermissionId city := activityDetail.City //分析师C类电话会,等于分析师电话会 if activityTypeId == 7 { activityTypeId = 2 } defaultCity := []string{"北京", "广州", "杭州", "南京", "上海", "深圳", "苏州"} //几个默认城市 if city != "" { if !utils.InArrayByStr(defaultCity, city) { city = "其他" } } imgDetail, e := models.CygxActivityShareImgDetail(activityTypeId, chartPermissionId, city) if e != nil { err = errors.New("CygxActivityShareImgDetail, Err: " + e.Error()) return } shareImg = imgDetail.Img return }