Explorar el Código

专项调研活动列表介入

xingzai hace 2 años
padre
commit
699eefbd73

+ 11 - 1
controllers/activity.go

@@ -96,6 +96,15 @@ func (this *ActivityController) LabelTypeList() {
 		return
 	}
 	list, err = services.HandleActivityTypeHomeList(list, activityList, user)
+
+	speciaItem, err := services.GetActivityLabelSpecialList(user, chartPermissionIds)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	list = append(list, speciaItem)
+
 	resp := new(models.ActivityTypeListHomeResp)
 	resp.List = list
 	br.Ret = 200
@@ -278,7 +287,7 @@ func (this *ActivityController) ActivityListNew() {
 	resp := new(models.GetCygxActivityListRep)
 	var activityList []*models.ActivityListResp
 	resp.Label = label
-	if activityTypeId != "" {
+	if activityTypeId != "" && label == "" {
 		activityTypeIdint, err := strconv.Atoi(activityTypeId)
 		if err == nil {
 			detail, errDetail := models.GetActivityTypeDetailById(activityTypeIdint)
@@ -367,6 +376,7 @@ func (this *ActivityController) ActivityListNew() {
 	//if keyWord != "" {
 	//	go services.AddActivitykeyWordSearch(keyWord, user)
 	//}
+	fmt.Println(resp.Label)
 	//预处理返给前端的字段
 	resp.List = activityList
 	fmt.Println(len(resp.List))

+ 67 - 0
models/activity.go

@@ -298,3 +298,70 @@ func GetAddActivityInfoByIdShow(uid, ActivityId int) (item *ActivityDetail, err
 	err = o.Raw(sql, uid, uid, uid, ActivityId).QueryRow(&item)
 	return
 }
+
+//GetActivitySpecialSearcheList 活动与专项调研的搜索
+func GetActivitySpecialSearcheList(condition string, pars []interface{}, conditionSpecil string, parsSpecil []interface{}, startSize, pageSize int) (items []*ActivityDetail, total int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			art.activity_id,
+			art.activity_time_text,
+			art.activity_name,
+			art.chart_permission_id,
+			art.active_state,
+			t.activity_type,
+			art.chart_permission_name,
+			art.distinguished_guest,
+			art.expert,
+			art.speaker,
+			"" AS trip_img_link,
+			"" AS activity_time_end,
+			art.yidong_activity_id,
+			art.is_can_appointment_minutes,
+			art.activity_type_id,
+			art.limit_people_num,
+			1 AS source_type,
+			art.activity_time 
+		FROM
+			cygx_activity AS art
+			INNER JOIN cygx_activity_type AS t ON t.activity_type_id = art.activity_type_id
+		WHERE
+			1 = 1 `
+	if condition != `` {
+		sql += condition
+	}
+	sql += ` UNION ALL
+		SELECT
+			art.activity_id,
+			art.activity_time_text_by_day AS activity_time_text,
+			art.research_theme AS activity_name,
+			art.chart_permission_id,
+			"",
+			art.special_type AS activity_type,
+			art.chart_permission_name,
+			"",
+			"",
+			"",
+			art.trip_img_link_fix AS trip_img_link,
+			art.activity_time_end,
+			"",
+			"",
+			"",
+			"",
+			2 AS source_type,
+			art.activity_time 
+		FROM
+			cygx_activity_special AS art
+		WHERE
+			1 = 1 `
+	if conditionSpecil != "" {
+		sql += conditionSpecil
+	}
+	totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
+	err = o.Raw(totalSql, pars, parsSpecil).QueryRow(&total)
+	if err != nil {
+		return
+	}
+	sql += ` ORDER BY activity_time DESC   LIMIT ?,?`
+	_, err = o.Raw(sql, pars, parsSpecil, startSize, pageSize).QueryRows(&items)
+	return
+}

+ 237 - 0
models/activity_appointment.go

@@ -0,0 +1,237 @@
+package models
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxActivityAppointment struct {
+	Id          int       `orm:"column(id);pk"`
+	ActivityId  int       `description:"活动ID"`
+	UserId      int       `description:"用户ID"`
+	CreateTime  time.Time `description:"创建时间"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	RealName    string    `description:"用户实际名称"`
+	SellerName  string    `description:"所属销售"`
+}
+
+type AppointmentResp struct {
+	ActivityId    int    `description:"活动ID"`
+	HasPermission int    `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
+	PopupMsg      string `description:"权限弹窗信息"`
+	SellerMobile  string `description:"销售电话"`
+	SellerName    string `description:"销售姓名"`
+	GoFollow      bool   `description:"是否去关注"`
+}
+
+//添加
+func AddCygxActivityAppointment(item *CygxActivityAppointment) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+	var countMySchedule int
+	sql := `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
+	err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countMySchedule)
+	if err != nil {
+		return
+	}
+	if countMySchedule == 0 {
+		itemMy := new(CygxMySchedule)
+		itemMy.UserId = item.UserId
+		itemMy.ActivityId = item.ActivityId
+		itemMy.CreateTime = time.Now()
+		itemMy.Mobile = item.Mobile
+		itemMy.Email = item.Email
+		itemMy.CompanyId = item.CompanyId
+		itemMy.CompanyName = item.CompanyName
+		_, err = o.Insert(itemMy)
+		if err != nil {
+			return
+		}
+	}
+	_, err = o.Insert(item)
+	return
+}
+
+//获取某一用户的报名的数量
+func GetUserCygxActivityAppointmentCount(uid, activityId int) (count int, err error) {
+	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_appointment  WHERE  user_id=?  AND   activity_id =? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
+	return
+}
+
+//获取某一用户的报名的数量
+func GetUserCygxActivityAppointmentCountByUid(uid int) (count int, err error) {
+	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_appointment  WHERE  user_id=? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, uid).QueryRow(&count)
+	return
+}
+
+//删除
+func DeleteCygxActivityAppointment(uid, activityId int) (err error) {
+	o := orm.NewOrm()
+	sql := `DELETE  FROM cygx_activity_special_signup   WHERE   user_id=?   AND  activity_id=?    `
+	_, err = o.Raw(sql, uid, activityId).Exec()
+	return
+}
+
+//取消纪要预约
+func CancelcygxActivityAppointment(item *CygxActivityAppointment) (lastId int64, err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+	//判断是否删除我的日程
+	var countSingup int
+	var countReminder int
+	sql := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE  is_cancel = 0  AND user_id=? AND activity_id=? `
+	err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countSingup)
+	sql = `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE   user_id=? AND activity_id=? `
+	err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countReminder)
+	if err != nil {
+		return
+	}
+	if countSingup == 0 && countReminder == 0 {
+		sql = `DELETE  FROM cygx_my_schedule   WHERE user_id=?  AND activity_id=? `
+		_, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
+		if err != nil {
+			return
+		}
+	}
+	//删除预约的纪要
+	sql = `DELETE  FROM cygx_activity_appointment   WHERE user_id=?  AND activity_id=? `
+	_, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
+	if err != nil {
+		return
+	}
+	return
+}
+
+type CygxAppointmentAndActivity struct {
+	Mobile         string `description:"手机号"`
+	ActivityName   string `description:"所属销售"`
+	ActivityTypeId int    `description:"活动类型"`
+}
+
+//通过活动ID获取预约列表
+func GetAppointmentListByActivityId(activityIds, activityTypeIds string) (items []*CygxAppointmentAndActivity, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			m.*,a.activity_name,
+			a.activity_type_id
+		FROM
+			cygx_activity_appointment AS m
+			INNER JOIN cygx_activity AS a ON a.activity_id = m.activity_id 
+		WHERE
+			a.activity_id IN ( ` + activityIds + ` ) 
+			AND a.activity_type_id IN (` + activityTypeIds + `) 
+			AND DATE_SUB( CURDATE(), INTERVAL 14 DAY ) <= date( a.activity_time ) 
+			AND a.active_state = 3 	GROUP BY m.mobile`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//通过活动ID、手机号获取预约列表
+func GetAppointmentListByActivityIdAndMobile(activityIds, mobile string) (items []*CygxAppointmentAndActivity, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			m.*,a.activity_name
+		FROM
+			cygx_activity_appointment AS m
+			INNER JOIN cygx_activity AS a ON a.activity_id = m.activity_id 
+		WHERE
+			a.activity_id IN ( ` + activityIds + ` ) 
+			AND a.activity_type_id IN ( 1, 2, 5 ) 
+			AND DATE_SUB( CURDATE(), INTERVAL 14 DAY ) <= date( a.activity_time ) 
+			AND a.active_state = 3
+			AND  m.mobile= ?`
+	_, err = o.Raw(sql, mobile).QueryRows(&items)
+	return
+}
+
+//通过活动ID获取预约纪要的人数列表
+func GetCygxAppointmentSummaryListBySubjectId(subjectIds string) (item []*CygxAppointmentAndActivity, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			ap.mobile,
+			ap.activity_id,
+			a.activity_name 
+		FROM
+			cygx_activity_appointment AS ap
+			INNER JOIN cygx_activity AS a ON a.activity_id = ap.activity_id
+			INNER JOIN cygx_industrial_activity_group_subject AS sg ON sg.activity_id = a.activity_id 
+		WHERE
+			a.active_state = 3 
+			AND a.chart_permission_id = 31 
+			AND DATE_SUB( CURDATE(), INTERVAL 14 DAY ) <= date( a.activity_time ) 
+			AND a.activity_type_id = 1 
+			AND sg.industrial_subject_id IN (` + subjectIds + `) 
+		GROUP BY
+			ap.mobile,
+			ap.activity_id `
+	_, err = o.Raw(sql).QueryRows(&item)
+	return
+}
+
+type CygxAppointment struct {
+	Mobile         string `description:"手机号"`
+	UserId         int    `description:"userId"`
+	ActivityName   string `description:"所属销售"`
+	ActivityTypeId int    `description:"活动类型"`
+}
+
+//通过活动ID获取预约纪要的人数列表
+func GetCygxAppointmentSummaryBySubjectId(subjectIds string) (item []*CygxAppointment, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			ap.user_id,
+			ap.mobile,
+			ap.activity_id,
+			a.activity_name 
+		FROM
+			cygx_activity_appointment AS ap
+			INNER JOIN cygx_activity AS a ON a.activity_id = ap.activity_id
+			INNER JOIN cygx_industrial_activity_group_subject AS sg ON sg.activity_id = a.activity_id 
+		WHERE
+			a.active_state = 3
+			AND sg.industrial_subject_id IN (` + subjectIds + `) 
+		GROUP BY
+			ap.mobile,
+			ap.activity_id `
+	_, err = o.Raw(sql).QueryRows(&item)
+	return
+}
+
+//GetCygxAppointmentListByUser 获取预约纪要的人
+func GetCygxAppointmentListByUser(condition string, pars []interface{}) (item []*CygxActivityAppointment, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_activity_appointment  
+			WHERE 1 = 1 ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}

+ 167 - 0
models/activity_meeting_reminder.go

@@ -0,0 +1,167 @@
+package models
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxActivityMeetingReminder struct {
+	Id          int       `orm:"column(id);pk"`
+	ActivityId  int       `description:"活动ID"`
+	UserId      int       `description:"用户ID"`
+	CreateTime  time.Time `description:"创建时间"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+}
+
+//记录日志
+type CygxActivityMeetingReminderLog struct {
+	Id          int       `orm:"column(id);pk"`
+	ActivityId  int       `description:"活动ID"`
+	UserId      int       `description:"用户ID"`
+	CreateTime  time.Time `description:"创建时间"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	Type        int       `description:"操作方式,1报名,2取消报名"`
+}
+
+//添加会议提醒信息
+func AddActivityMeetingReminder(item *CygxActivityMeetingReminder) (lastId int64, err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+	var count int
+	var countMySchedule int
+	sql := `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
+	err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countMySchedule)
+	if err != nil {
+		return
+	}
+	if countMySchedule == 0 {
+		itemMy := new(CygxMySchedule)
+		itemMy.UserId = item.UserId
+		itemMy.ActivityId = item.ActivityId
+		itemMy.CreateTime = time.Now()
+		itemMy.Mobile = item.Mobile
+		itemMy.Email = item.Email
+		itemMy.CompanyId = item.CompanyId
+		itemMy.CompanyName = item.CompanyName
+		lastId, err = o.Insert(itemMy)
+		if err != nil {
+			return
+		}
+	}
+	sql = `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE user_id=? AND activity_id=? `
+	err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
+	if err != nil {
+		return
+	}
+	if count > 0 {
+		sql := `UPDATE cygx_activity_meeting_reminder SET is_cancel = 0  WHERE user_id=?  AND activity_id=? `
+		_, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
+	} else {
+		lastId, err = o.Insert(item)
+	}
+	itemLog := new(CygxActivityMeetingReminderLog)
+	itemLog.UserId = item.UserId
+	itemLog.ActivityId = item.ActivityId
+	itemLog.CreateTime = time.Now()
+	itemLog.Mobile = item.Mobile
+	itemLog.Email = item.Email
+	itemLog.CompanyId = item.CompanyId
+	itemLog.CompanyName = item.CompanyName
+	itemLog.Type = 1
+	lastId, err = o.Insert(itemLog)
+	return
+}
+
+//获取用户报名数量
+func GetActivityMeetingReminderCount(uid, activityId int) (count int, err error) {
+	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder WHERE is_cancel=0 AND user_id=? AND activity_id=? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
+	return
+}
+
+//取消会议提醒
+func CancelActivityMeetingReminder(item *CygxActivityMeetingReminder) (lastId int64, err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+	//判断是否删除我的日程
+	var countSignup int
+	var countAppointment int
+	sql := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE  is_cancel = 0  AND user_id=? AND activity_id=? `
+	err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countSignup)
+
+	sql = `SELECT COUNT(1) AS count FROM cygx_activity_appointment WHERE  user_id=? AND activity_id=? `
+	err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countAppointment)
+	if err != nil {
+		return
+	}
+	if countSignup == 0 && countAppointment == 0 {
+		sql = `DELETE  FROM cygx_my_schedule   WHERE user_id=?  AND activity_id=? `
+		_, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
+		if err != nil {
+			return
+		}
+	}
+	sql = `DELETE  FROM cygx_activity_meeting_reminder   WHERE user_id=?  AND activity_id=? `
+	_, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
+	if err != nil {
+		return
+	}
+	itemLog := new(CygxActivityMeetingReminderLog)
+	itemLog.UserId = item.UserId
+	itemLog.ActivityId = item.ActivityId
+	itemLog.CreateTime = time.Now()
+	itemLog.Mobile = item.Mobile
+	itemLog.Email = item.Email
+	itemLog.CompanyId = item.CompanyId
+	itemLog.CompanyName = item.CompanyName
+	itemLog.Type = 2
+	lastId, err = o.Insert(itemLog)
+	return
+}
+
+//获取某一用户的日程数量
+func GetUserActivityMeetingReminderCount(uid int) (count int, err error) {
+	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_meeting_reminder_log WHERE  user_id=? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, uid).QueryRow(&count)
+	return
+}
+
+//GetCygxReminderListByUser 获取设置会议提醒的人
+func GetCygxReminderListByUser(condition string, pars []interface{}) (item []*CygxActivityMeetingReminder, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_activity_meeting_reminder  
+			WHERE 1 = 1 ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}

+ 114 - 0
models/activity_special.go

@@ -0,0 +1,114 @@
+package models
+
+import (
+	//"fmt"
+	"github.com/beego/beego/v2/client/orm"
+)
+
+//专项调研活动列表
+type CygxActivitySpecialDetail struct {
+	ActivityId            int    `description:"活动ID "`
+	ActivityTypeName      string `description:"活动名称"`
+	SpecialType           int    `description:"调研形式、 1 线上 , 2 线下"`
+	City                  string `description:"调研城市"`
+	ChartPermissionName   string `description:"行业名称"`
+	ChartPermissionId     string `description:"行业Id"`
+	ResearchTheme         string `description:"调研主题"`
+	ActivityTimeText      string `description:"活动预期时间带文字"`
+	TripImgLink           string `description:"行程图片链接"`
+	IsSignup              int    `description:"是否感兴趣 1是 ,0 否"`
+	Label                 string `description:"主题标签"`
+	ImgUrl                string `description:"图片链接"`
+	ImgUrlText            string `description:"图片链接文字"`
+	IndustrialName        string `description:"产业名称"`
+	IndustrialSubjectName string `description:"标的名称(相关公司)"`
+	Scale                 string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
+	CustomerTypeIds       string `description:"活动可见的客户类型,多个ID用 , 隔开"`
+	IsTrip                int    `description:"是否报名 1是 ,0 否"`
+	TripNum               int    `description:"已报名人数"`
+	Days                  int    `description:"调研天数"`
+	Host                  string `description:"主持人"`
+	PersonInCharge        string `description:"纪要负责人"`
+	LimitPeopleNum        int    `description:"限制人数数量"`
+	TripImgLinkFix        string `description:"确定行程之后的图片链接"`
+	ActivityTimeTextByDay string `description:"活动预期时间带周日"`
+	ActivityTime          string `description:"活动预期时间"`
+	ActivityTimeEnd       string `description:"活动预期结束时间"`
+	ActiveState           int    `description:"活动进行状态 未开始:1、进行中2、已结束3"`
+	TripStatus            int    `description:"行程进行状态 1:预报名,2:确定行程"`
+	Explain               string `description:"说明"`
+	AdminId               int    `description:"管理员ID"`
+}
+
+//获取数量
+func GetActivitySpecialCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_activity_special as art WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+//主题列表
+func GetActivitySpecialListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivitySpecialDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT	*
+		FROM cygx_activity_special as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY art.last_updated_time DESC  LIMIT ?,? `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+//修改发布状态
+func UpdateActivitySpecialPublishStatus(publishStatus, activityId int) (err error) {
+	sql := ` UPDATE cygx_activity_special SET  publish_status= ?  WHERE activity_id = ?`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, publishStatus, activityId).Exec()
+	return
+}
+
+//主题列表
+func GetActivityLabelSpecialListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityLabelList, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT	label,activity_id,is_show_subject_name
+		FROM cygx_activity_special as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += `  LIMIT ?,? `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+//获取专项调研活动列表
+func GetCygxActivitySpecialDetailList(condition string, pars []interface{}, uid, startSize, pageSize int) (items []*CygxActivitySpecialDetail, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT
+	art.*,
+	c.image_url AS img_url,
+	(
+	SELECT
+		COUNT( 1 ) 
+	FROM
+		cygx_activity_special_signup AS s 
+	WHERE
+		s.activity_id = art.activity_id 
+		AND s.user_id = ?
+	) AS is_signup
+FROM
+	cygx_activity_special AS art
+	INNER JOIN chart_permission AS c ON c.chart_permission_id = art.chart_permission_id 
+WHERE
+	1 = 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += `  LIMIT ?,? `
+	_, err = o.Raw(sql, uid, pars, startSize, pageSize).QueryRows(&items)
+	return
+}

+ 158 - 0
models/activity_special_signup.go

@@ -0,0 +1,158 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxActivitySpecialSignup struct {
+	Id          int       `orm:"column(id);pk"`
+	ActivityId  int       `description:"活动ID"`
+	UserId      int       `description:"用户ID"`
+	CreateTime  time.Time `description:"创建时间"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	RealName    string    `description:"用户实际名称"`
+	SellerName  string    `description:"所属销售"`
+}
+
+type SignupSpecialStatus struct {
+	ActivityId    int    `description:"活动ID"`
+	HasPermission int    `description:"操作方式,1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
+	PopupMsg      string `description:"权限弹窗信息"`
+	PopupMsg2     string `description:"权限弹窗信息"`
+	Status        int    `description:"返回类型,1:添加,2:取消"`
+	SellerMobile  string `description:"销售电话"`
+	SellerName    string `description:"销售姓名"`
+	SignupStatus  int    `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
+}
+
+//添加
+func AddCygxActivitySpecialSignup(item *CygxActivitySpecialSignup) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+//获取某一用户的报名的数量
+func GetUserCygxActivitySpecialSignup(uid, activityId int) (count int, err error) {
+	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_signup  WHERE  user_id=?  AND   activity_id =? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
+	return
+}
+
+//删除
+func DeleteCygxActivitySpecialSignup(uid, activityId int) (err error) {
+	o := orm.NewOrm()
+	sql := `DELETE  FROM cygx_activity_special_signup   WHERE   user_id=?   AND  activity_id=?    `
+	_, err = o.Raw(sql, uid, activityId).Exec()
+	return
+}
+
+//列表
+func GetActivityListSpecialAll(activityId int) (items []*CygxActivitySpecialSignup, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT art.*  FROM cygx_activity_special_signup as art WHERE 1= 1 AND  activity_id = ?  GROUP BY company_id`
+	_, err = o.Raw(sql, activityId).QueryRows(&items)
+	return
+}
+
+//列表
+func GetActivityListSpecialByActivityId(activityId int) (items []*CygxActivitySpecialSignup, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT art.*  FROM cygx_activity_special_signup as art WHERE 1= 1 AND  activity_id = ? `
+	_, err = o.Raw(sql, activityId).QueryRows(&items)
+	return
+}
+
+type CygxActivitySpecialSignupResp struct {
+	Id          int       `orm:"column(id);pk"`
+	ActivityId  int       `description:"活动ID"`
+	UserId      int       `description:"用户ID"`
+	CreateTime  time.Time `description:"创建时间"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	RealName    string    `description:"用户实际名称"`
+	SellerName  string    `description:"所属销售"`
+	Count       string    `description:"所属销售"`
+}
+
+//列表
+func GetActivityListSpecialGroupByMobile(condition string, pars []interface{}) (items []*CygxActivitySpecialSignupResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT s.*,	COUNT( 1 ) AS count   FROM cygx_activity_special_signup as s INNER JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
+			INNER JOIN wx_user AS u ON u.user_id = s.user_id ` + condition + `  GROUP BY s.mobile`
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+//列表
+func GetActivityListSpecialGroupByCompanyId(condition string, pars []interface{}) (items []*CygxActivitySpecialSignupResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *,	COUNT( 1 ) AS count   FROM cygx_activity_special_signup   as s INNER JOIN cygx_activity_special AS a ON a.activity_id = s.activity_id
+			INNER JOIN wx_user AS u ON u.user_id = s.user_id ` + condition + `  GROUP BY s.company_id`
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+// UpdateActivitySpecialSignupNumMulti 批量修改专项调研感兴趣的人数排名
+func UpdateActivitySpecialSignupNumMulti(items []*CygxActivitySpecialSignupResp) (err error) {
+	o := orm.NewOrm()
+	p, err := o.Raw("UPDATE cygx_activity_special_signup SET user_num = ? WHERE mobile = ?").Prepare()
+	if err != nil {
+		return
+	}
+	defer func() {
+		_ = p.Close() // 别忘记关闭 statement
+	}()
+	for _, v := range items {
+		_, err = p.Exec(v.Count, v.Mobile)
+		if err != nil {
+			return
+		}
+	}
+	return
+}
+
+// UpdateActivitySpecialSignupCompanyIdMulti 批量修改专项调研感兴趣的用户的对应公司ID
+func UpdateActivitySpecialSignupCompanyIdMulti(items []*WxUser) (err error) {
+	o := orm.NewOrm()
+	p, err := o.Raw("UPDATE cygx_activity_special_signup SET company_id = ? WHERE mobile = ?").Prepare()
+	if err != nil {
+		return
+	}
+	defer func() {
+		_ = p.Close() // 别忘记关闭 statement
+	}()
+	for _, v := range items {
+		_, err = p.Exec(v.CompanyId, v.Mobile)
+		if err != nil {
+			return
+		}
+	}
+	return
+}
+
+// UpdateActivitySpecialSignupCompanyNumMulti 批量修改专项调研感兴趣的公司对应的数量
+func UpdateActivitySpecialSignupCompanyNumMulti(items []*CygxActivitySpecialSignupResp) (err error) {
+	o := orm.NewOrm()
+	p, err := o.Raw("UPDATE cygx_activity_special_signup SET company_num = ? WHERE company_id = ?").Prepare()
+	if err != nil {
+		return
+	}
+	defer func() {
+		_ = p.Close() // 别忘记关闭 statement
+	}()
+	for _, v := range items {
+		_, err = p.Exec(v.Count, v.CompanyId)
+		if err != nil {
+			return
+		}
+	}
+	return
+}

+ 116 - 0
models/activity_special_trip.go

@@ -0,0 +1,116 @@
+package models
+
+import (
+	//"hongze/hongze_admin/models"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxActivitySpecialTrip struct {
+	Id             int       `orm:"column(id);pk"`
+	UserId         int       `description:"用户id,多个用,隔开"`
+	ActivityId     int       `description:"活动ID"`
+	CreateTime     time.Time `description:"创建时间"`
+	Mobile         string    `description:"手机号"`
+	Email          string    `description:"邮箱号"`
+	CompanyId      int       `description:"公司ID"`
+	CompanyName    string    `description:"公司名称"`
+	RealName       string    `description:"用户实际名称"`
+	SellerName     string    `description:"所属销售"`
+	AdminId        int       `description:"销售/管理员ID"`
+	Source         int       `description:"来源,1小程序,2后台添加"`
+	OutboundMobile string    `description:"外呼手机号"`
+	CountryCode    string    `description:"手机国家区号"`
+	IsCancel       string    `description:"是否取消,1是,0否"`
+	IsValid        int       `description:"参会报名是否有效 1:是,0"`
+}
+
+type CygxActivitySpecialTripResp struct {
+	Id             int    `description:"ID"`
+	UserId         int    `description:"用户id"`
+	ActivityId     int    `description:"活动ID"`
+	CreateTime     string `description:"创建时间"`
+	Mobile         string `description:"手机号"`
+	Email          string `description:"邮箱号"`
+	CompanyId      int    `description:"公司ID"`
+	CompanyName    string `description:"公司名称"`
+	RealName       string `description:"用户实际名称"`
+	SellerName     string `description:"所属销售"`
+	OutboundMobile string `description:"外呼手机号"`
+	CountryCode    string `description:"手机国家区号"`
+}
+
+func GetCygxActivitySpecialTripList(condition string, pars []interface{}) (item []*CygxActivitySpecialTripResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_activity_special_trip  
+			WHERE 1 = 1 ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}
+
+//获取某一用户的报名的数量
+func GetUserActivitySpecialTripCount(uid, activityId int) (count int, err error) {
+	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip  WHERE  user_id=?  AND   activity_id =? `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, uid, activityId).QueryRow(&count)
+	return
+}
+
+//获取某一活动的报名的数量
+func GetActivitySpecialTripCountByActivityId(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip as t   INNER JOIN wx_user as  u on u.user_id = t.user_id WHERE    1 = 1 ` + condition
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+//获取某一活动的报名的数量 (同时关联活动类型进行获取)
+func GetActivitySpecialTripCountByActivitySpecial(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count
+		FROM
+			cygx_activity_special_trip AS t
+			INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id 
+		WHERE
+			 1= 1 ` + condition
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+//获取空降的公司报名的记录
+func GetActivitySpecialTripAirborneCountByActivitySpecial(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count
+		FROM
+			cygx_activity_special_meeting_detail AS t
+			INNER JOIN cygx_activity_special AS a ON a.activity_id = t.activity_id 
+		WHERE
+			 1= 1 ` + condition
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+//添加
+func AddCygxActivitySpecialTrip(item *CygxActivitySpecialTrip) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+//取消
+func CancelActivitySpecialTrip(uid int, item *CygxActivitySpecialDetail) (err error) {
+	o := orm.NewOrm()
+	sql := `DELETE  FROM cygx_activity_special_trip   WHERE user_id=?  AND activity_id=? `
+	_, err = o.Raw(sql, uid, item.ActivityId).Exec()
+	return
+}
+
+//CancelActivitySpecialTripIsValid  处理活动报名是否有效
+func CancelActivitySpecialTripIsValid(isValid, activityId, userId int) (err error) {
+	sql := ` UPDATE cygx_activity_special_trip SET  is_valid= ?,is_cancel = 1  WHERE activity_id = ? AND  user_id = ? `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, isValid, activityId, userId).Exec()
+	return
+}

+ 9 - 7
models/activity_type.go

@@ -46,13 +46,15 @@ type ActivityTypeHome struct {
 
 //活动详情
 type CygxActivityLabelList struct {
-	KeyWord          string `orm:"column(label)";description:"主题"`
-	ImgUrlBg         string `description:"背景图片"`
-	ActivityId       int    `description:"活动ID "`
-	Resource         int    `description:"来源 ,1:活动 ,2:专项产业调研"`
-	IsNew            bool   `description:"是否为新:活动存在关联的的产业所关联的报告均在3个月内/无报告则标记新"`
-	YidongActivityId int    `description:"易董活动ID"`
-	IsExternalLabel  bool   `description:"是否为外部资源"`
+	KeyWord           string `orm:"column(label)";description:"主题"`
+	ImgUrlBg          string `description:"背景图片"`
+	ActivityId        int    `description:"活动ID "`
+	Resource          int    `description:"来源 ,1:活动 ,2:专项产业调研"`
+	IsNew             bool   `description:"是否为新:活动存在关联的的产业所关联的报告均在3个月内/无报告则标记新"`
+	YidongActivityId  int    `description:"易董活动ID"`
+	IsExternalLabel   bool   `description:"是否为外部资源"`
+	IsShowSubjectName int    `description:"小程序内是否展示标的名称 1是 ,0否 默认0 "`
+	TemporaryLabel    string `description:"临时标签"`
 }
 
 //列表

+ 7 - 0
models/seller.go

@@ -69,3 +69,10 @@ func GetSelleridWhichGroup(companyId, productId int) (adminId string, err error)
 	err = o.Raw(sql, companyId, productId).QueryRow(&adminId)
 	return
 }
+
+func GetSellerByAdminId(adminId int) (item *AdminItem, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM admin WHERE admin_id=?  `
+	err = o.Raw(sql, adminId).QueryRow(&item)
+	return
+}

+ 12 - 0
models/user.go

@@ -263,3 +263,15 @@ func BindUserOutboundMobileByMobile(mobile, countryCode string, userId int) (err
 	_, err = o.Raw(sql, mobile, countryCode, userId).Exec()
 	return
 }
+
+// GetWxUserByMobiles 根据用户手机号获取用户详情
+func GetWxUserByMobiles(mobiles []string) (items []*WxUser, err error) {
+	lenmobiles := len(mobiles)
+	if lenmobiles == 0 {
+		return
+	}
+	sql := `SELECT* FROM wx_user  WHERE mobile in (` + utils.GetOrmInReplace(lenmobiles) + `)  `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, mobiles).QueryRows(&items)
+	return
+}

+ 11 - 0
services/activity.go

@@ -701,3 +701,14 @@ func CheckUserPowerByActivityChoose(user *models.WxUserItem, activityInfo *model
 	}
 	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
+}

+ 277 - 0
services/activity_button.go

@@ -0,0 +1,277 @@
+package services
+
+import (
+	"errors"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+	"strconv"
+	"strings"
+	"time"
+)
+
+//获取用户已经报名的活动
+func GetActivitySignUpUserMap(activityIds []int, user *models.WxUserItem) (mapUserId map[int]int, err error) {
+	userId := user.UserId
+	var condition string
+	var pars []interface{}
+	activityIdsLen := len(activityIds)
+	if activityIdsLen > 0 {
+		condition += ` AND activity_id IN (` + utils.GetOrmInReplace(activityIdsLen) + `)`
+		pars = append(pars, activityIds)
+	}
+	condition += ` AND user_id = ?  AND do_fail_type = 0 `
+	pars = append(pars, userId)
+	list, e := models.GetActivitySignuListByUser(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
+		return
+	}
+	mapUid := make(map[int]int)
+	for _, v := range list {
+		mapUid[v.ActivityId] = v.UserId
+	}
+	mapUserId = mapUid
+	return
+}
+
+//获取用户已经设置会议提醒的活动  cygx_activity_meeting_reminder
+func GetActivityReminderUserMasp(activityIds []int, user *models.WxUserItem) (mapUserId map[int]int, err error) {
+	userId := user.UserId
+	var condition string
+	var pars []interface{}
+	activityIdsLen := len(activityIds)
+	if activityIdsLen > 0 {
+		condition += ` AND activity_id IN (` + utils.GetOrmInReplace(activityIdsLen) + `)`
+		pars = append(pars, activityIds)
+	}
+	condition += ` AND user_id = ?  `
+	pars = append(pars, userId)
+	list, e := models.GetCygxReminderListByUser(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxReminderListByUser, Err: " + e.Error())
+		return
+	}
+	mapUid := make(map[int]int)
+	for _, v := range list {
+		mapUid[v.ActivityId] = v.UserId
+	}
+	mapUserId = mapUid
+	return
+}
+
+//获取用户已经预约纪要的活动
+func GetActivityAppointmentUserMap(activityIds []int, user *models.WxUserItem) (mapUserId map[int]int, err error) {
+	userId := user.UserId
+	var condition string
+	var pars []interface{}
+	activityIdsLen := len(activityIds)
+	if activityIdsLen > 0 {
+		condition += ` AND activity_id IN (` + utils.GetOrmInReplace(activityIdsLen) + `)`
+		pars = append(pars, activityIds)
+	}
+	condition += ` AND user_id = ?  `
+	pars = append(pars, userId)
+	list, e := models.GetCygxAppointmentListByUser(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
+		return
+	}
+	mapUid := make(map[int]int)
+	for _, v := range list {
+		mapUid[v.ActivityId] = v.UserId
+	}
+	mapUserId = mapUid
+	return
+}
+
+//活动列表的展示  HandleActivityListButton
+func HandleActivityListButton(list []*models.ActivityDetail, user *models.WxUserItem) (items []*models.ActivityDetail, err error) {
+	var activityIds []int
+	var activitySpecilalIds []int
+	for k, v := range list {
+		if v.SourceType == 2 {
+			activitySpecilalIds = append(activitySpecilalIds, v.ActivityId)
+			//把专项调研的线下改为活动的线下类型
+			if v.ActivityType == 2 {
+				list[k].ActivityType = 0
+			}
+			list[k].IsShowSignup = true
+		} else {
+			activityIds = append(activityIds, v.ActivityId)
+		}
+	}
+	//处理活动
+	if len(activityIds) > 0 {
+		//处理用户是否报名
+		mapSignUp, e := GetActivitySignUpUserMap(activityIds, user)
+		if e != nil {
+			err = errors.New("GetActivitySignUpUserMap, Err: " + e.Error())
+			return
+		}
+		for k, v := range list {
+			if v.SourceType != 2 {
+				if _, ok := mapSignUp[v.ActivityId]; ok {
+					list[k].IsSignup = 1
+				}
+			}
+		}
+		//处理用户是否预约纪要
+		mapAppointment, e := GetActivityAppointmentUserMap(activityIds, user)
+		if e != nil {
+			err = errors.New("GetActivityAppointmentUserMap, Err: " + e.Error())
+			return
+		}
+		for k, v := range list {
+			if v.SourceType != 2 {
+				if _, ok := mapAppointment[v.ActivityId]; ok {
+					list[k].IsAppointment = 1
+				}
+			}
+		}
+		//处理用户是否预约会议提醒
+		mapReminder, e := GetActivityReminderUserMasp(activityIds, user)
+		if e != nil {
+			err = errors.New("GetActivityReminderUserMasp, Err: " + e.Error())
+			return
+		}
+		for k, v := range list {
+			if v.SourceType != 2 {
+				if _, ok := mapReminder[v.ActivityId]; ok {
+					list[k].IsCancelMeetingReminder = 1
+				}
+			}
+		}
+	}
+
+	//处理专项产业调研
+	if len(activitySpecilalIds) > 0 {
+		//处理用户是否报名
+		UserMap, e := GetSpecialTripUserMap(activitySpecilalIds, user.UserId)
+		if e != nil {
+			err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
+			return
+		}
+		for k, v := range list {
+			if v.SourceType == 2 {
+				if _, ok := UserMap[v.ActivityId]; ok {
+					list[k].IsSignup = 1
+				}
+			}
+		}
+
+		for k, v := range list {
+			if v.SourceType == 2 {
+				resultTimeStart := utils.StrTimeToTime(v.ActivityTime)  //时间字符串格式转时间格式
+				resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
+				if resultTimeStart.After(time.Now()) {
+					list[k].ActiveState = strconv.Itoa(1)
+				} else if time.Now().After(resultTimeEnd) {
+					list[k].ActiveState = strconv.Itoa(3)
+				} else {
+					list[k].ActiveState = strconv.Itoa(2)
+				}
+			}
+		}
+	}
+
+	//var isShow bool
+	isShow, e := GetShowSustainableNew()
+	if e != nil {
+		err = errors.New("GetShowSustainableNew, Err: " + e.Error())
+		return
+	}
+	detail, e := models.GetConfigByCode("city_img_url")
+	if e != nil {
+		err = errors.New("GetConfigByCode, Err: " + e.Error())
+		return
+	}
+	detailChart, e := models.GetConfigByCode("chart_img_url")
+	if e != nil {
+		err = errors.New("GetConfigByCode, Err: " + e.Error())
+		return
+	}
+	addressList := strings.Split(detail.ConfigValue, "{|}")
+	mapAddress := make(map[string]string)
+	chartList := strings.Split(detailChart.ConfigValue, "{|}")
+	mapChart := make(map[string]string)
+	var cityName string
+	var chartName string
+	var imgUrl string
+	var imgUrlChart string
+	var mapActivityId []int
+	for _, v := range addressList {
+		vslice := strings.Split(v, "_")
+		cityName = vslice[0]
+		imgUrl = vslice[len(vslice)-1]
+		mapAddress[cityName] = imgUrl
+	}
+	for _, v := range chartList {
+		vslice := strings.Split(v, "_")
+		chartName = vslice[0]
+		imgUrlChart = vslice[len(vslice)-1]
+		mapChart[chartName] = imgUrlChart
+	}
+	for k, v := range list {
+		if strings.Contains(v.ActivityName, "【") {
+			list[k].IsBrackets = 1
+		}
+		if v.SignupNum > v.LimitPeopleNum {
+			list[k].SignupNum = v.LimitPeopleNum
+		}
+		if isShow && strings.Contains(v.ChartPermissionName, "研选") {
+			list[k].IsShowSustainable = true
+		}
+		if strings.Contains(v.ChartPermissionName, "研选") && v.ActivityTypeId == 1 {
+			list[k].ActivityTypeName = "买方研选电话会"
+			list[k].ImgUrlText = utils.YAN_XUAN_IMG
+		}
+		if v.ActivityType == 0 {
+			if mapAddress[v.City] != "" {
+				list[k].ImgUrl = mapAddress[v.City]
+			} else {
+				list[k].ImgUrl = mapAddress["其它"]
+			}
+		} else {
+			if mapChart[v.ChartPermissionName] != "" {
+				list[k].ImgUrl = mapChart[v.ChartPermissionName]
+			}
+		}
+		expertTxt, _ := GetReportContentTextSub(v.Expert)
+		list[k].Expert = expertTxt
+		if v.IsHideAppointment == 0 {
+			list[k].IsShowAppointment = IsShowAppointment(v.ActivityTypeId, v.ChartPermissionName)
+		}
+		if v.ActivityTypeId == utils.C_CLASS_ACTIVITY_TYPE_ID {
+			list[k].IsCClassMeeting = true
+		}
+		mapActivityId = append(mapActivityId, v.ActivityId)
+	}
+
+	//处理音频回放
+	mapActivityVoice, e := GetActivityVoiceResp(mapActivityId)
+	if e != nil {
+		err = errors.New("GetActivityVoiceResp, Err: " + e.Error())
+		return
+	}
+
+	//处理视频回放
+	mapActivityVideo, e := GetActivityVideoResp(mapActivityId)
+	if e != nil {
+		err = errors.New("GetActivityVoiceResp, Err: " + e.Error())
+		return
+	}
+	for k, v := range list {
+		if mapActivityVoice[v.ActivityId] != nil {
+			list[k].FileType = 1
+			list[k].AudioLink = true
+			list[k].VoiceList = mapActivityVoice[v.ActivityId]
+		}
+		if mapActivityVideo[v.ActivityId] != nil {
+			list[k].FileType = 2
+			list[k].AudioLink = true
+			list[k].VideoDetail = mapActivityVideo[v.ActivityId]
+		}
+		//items = append(items, ActivityButtonShow(v))
+	}
+	return
+}

+ 694 - 0
services/activity_special.go

@@ -0,0 +1,694 @@
+package services
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+	"strconv"
+	"strings"
+	"time"
+)
+
+//func init() {
+//	UpdateCygxActivitySpecialSignupNum()
+//}
+
+//处理专项调研的展示
+func GetActivityLabelSpecialList(user *models.WxUserItem, chartPermissionIds string) (item *models.ActivityTypeHome, err error) {
+	itemList := new(models.ActivityTypeHome)
+	if user.CompanyId <= 1 {
+		itemList.List = make([]*models.CygxActivityLabelList, 0)
+		item = itemList
+		return
+	}
+	userType, e := GetSpecialUserType(user)
+	if e != nil {
+		err = errors.New("GetSpecialUserType, Err: " + e.Error())
+		return
+	}
+	if userType == 0 {
+		itemList.List = make([]*models.CygxActivityLabelList, 0)
+		item = itemList
+		return
+	}
+	companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
+	if e != nil {
+		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.publish_status = 1  AND art.label != ''  AND art.is_offline = 0 `
+
+	////行业名称
+	//if isPower == 1 {
+	//	condition += ` AND art.chart_permission_name  IN (` + permissionNameStr + `) `
+	//}
+	if chartPermissionIds != "" {
+		condition += ` AND art.chart_permission_id  IN (` + chartPermissionIds + `) `
+	}
+	conditionTrip := condition
+	conditionTrip += ` AND art.days > 0  ORDER BY art.activity_time ASC `
+	specialList, err := models.GetActivityLabelSpecialListAll(conditionTrip, pars, 0, 8)
+	if err != nil {
+		return
+	}
+	if len(specialList) < 8 {
+		conditionTrip += ` AND art.days = 0  ORDER BY art.last_updated_time DESC`
+		specialListNotrip, e := models.GetActivityLabelSpecialListAll(condition, pars, 0, 8-len(specialList))
+		if e != nil {
+			err = e
+			return
+		}
+		for _, v := range specialListNotrip {
+			specialList = append(specialList, v)
+		}
+	}
+	for k2, v2 := range specialList {
+		v2.Resource = 2
+		specialList[k2].KeyWord = LabelStr(v2.KeyWord, v2.IsShowSubjectName, v2.TemporaryLabel)
+		specialList[k2].ImgUrlBg = "https://hzstatic.hzinsights.com/static/temp/20220426202204/20220426/XDLLsjC9XAAy8LIzQr7GsjrBbtX6.png"
+		specialList[k2].ImgUrlBg = utils.ACTIVITY_ZXDY_ImgUrl3
+	}
+	itemList.ActivityTypeName = "专项产业调研"
+	itemList.Resource = 2
+	itemList.List = specialList
+	itemList.ActivityTypeId = 7
+	itemList.OnlineIco = utils.ACTIVITY_ZXDY_ImgUrl1
+	itemList.ImgUrlBgPc = utils.ACTIVITY_ZXDY_ImgUrl2
+	item = itemList
+	return
+}
+
+//HandleActivityLabelSpecialPermission 处理专项产业调研的查询权限sql 永续
+func HandleActivityLabelSpecialPermission(user *models.WxUserItem) (condition string, err error) {
+	permissionStr, e := GetCompanyPermission(user.CompanyId)
+	if e != nil {
+		err = errors.New("GetCompanyPermission, Err: " + e.Error())
+		return
+	}
+	userType, e := GetSpecialUserType(user)
+	if e != nil {
+		err = errors.New("GetSpecialUserType, Err: " + e.Error())
+		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, ",")
+	condition = ` AND art.publish_status = 1  AND art.label != ''  AND art.is_offline = 0  `
+	if permissionSqlStr != "" {
+		condition += ` AND art.chart_permission_name  IN (` + permissionSqlStr + `) `
+	}
+	condition += ` AND  art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
+	return
+}
+
+//HandleActivityLabelSpecialPermisseion 处理专项产业调研的查询权限sql
+func HandleActivityLabelSpecialTripPermission(user *models.WxUserItem) (condition string, err error) {
+	permissionStr, e := GetCompanyPermission(user.CompanyId)
+	if e != nil {
+		err = errors.New("GetCompanyPermission, Err: " + e.Error())
+		return
+	}
+	userType, e := GetSpecialUserType(user)
+	if e != nil {
+		err = errors.New("GetSpecialUserType, Err: " + e.Error())
+		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, ",")
+	condition = ` AND art.publish_status = 1  AND art.label != ''  AND art.is_offline = 0  `
+	if permissionSqlStr != "" {
+		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) {
+	companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
+	if e != nil {
+		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 != "" {
+		keywords = "%" + keywords + "%"
+		condition += ` AND art.research_theme LIKE ? `
+		pars = append(pars, keywords)
+	}
+	totalPrepare, e = models.GetActivitySpecialCount(condition, pars)
+	if e != nil {
+		err = errors.New("GetActivitySpecialCount, Err: " + e.Error())
+		return
+	}
+	condition += `  ORDER BY art.last_updated_time DESC `
+	list, e = models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, startSize, pageSize)
+	if e != nil {
+		err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
+		return
+	}
+	return
+}
+
+/*
+确定行程的查询  GetActivityLabelSpecialConfirmList
+state 进行状态 1:未开始,2:进行中,3:已结束,4:未开始、进行中 不传默认查询全部items []*CygxActivitySpecialDetail
+*/
+func GetActivityLabelSpecialConfirmList(user *models.WxUserItem, startSize, pageSize, state int, keywords string) (list []*models.CygxActivitySpecialDetail, totalConfirm int, err error) {
+	//var condition string
+	companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
+	if e != nil {
+		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 state == 1 {
+		condition += ` AND art.activity_time > ? `
+		pars = append(pars, time.Now())
+	}
+	if state == 2 {
+		condition += ` AND art.activity_time < ? `
+		pars = append(pars, time.Now())
+		condition += ` AND art.activity_time_end > ? `
+		pars = append(pars, time.Now())
+	}
+	if state == 3 {
+		condition += ` AND art.activity_time_end < ? `
+		pars = append(pars, time.Now())
+	}
+	if state == 4 {
+		condition += ` AND art.activity_time_end > ? `
+		pars = append(pars, time.Now())
+	}
+	if keywords != "" {
+		keywords = "%" + keywords + "%"
+		condition += ` AND art.research_theme LIKE ? `
+		pars = append(pars, keywords)
+	}
+	totalConfirm, e = models.GetActivitySpecialCount(condition, pars)
+	if e != nil {
+		err = errors.New("GetActivitySpecialCount, Err: " + e.Error())
+		return
+	}
+	condition += `  ORDER BY art.activity_time ASC `
+	list, e = models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, startSize, pageSize)
+	if e != nil {
+		err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
+		return
+	}
+	var activityIds []int
+	for k, v := range list {
+		resultTimeStart := utils.StrTimeToTime(v.ActivityTime)  //时间字符串格式转时间格式
+		resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
+		if resultTimeStart.After(time.Now()) {
+			list[k].ActiveState = 1
+		} else if time.Now().After(resultTimeEnd) {
+			list[k].ActiveState = 3
+		} else {
+			list[k].ActiveState = 2
+		}
+		if list[k].Days == 0 {
+			list[k].TripStatus = 1
+		} else {
+			list[k].TripStatus = 2
+		}
+		activityIds = append(activityIds, v.ActivityId)
+	}
+
+	//处理用户已经报名了的行程
+	UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
+	if e != nil {
+		err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
+		return
+	}
+	for k, v := range list {
+		if _, ok := UserMap[v.ActivityId]; ok {
+			list[k].IsTrip = 1
+		}
+	}
+	return
+}
+
+//获取用户已经报名的活动
+func GetSpecialTripUserMap(activityIds []int, userId int) (mapUserId map[int]int, err error) {
+	var condition string
+	var pars []interface{}
+	activityIdsLen := len(activityIds)
+	if activityIdsLen > 0 {
+		condition += ` AND activity_id IN (` + utils.GetOrmInReplace(activityIdsLen) + `)`
+		pars = append(pars, activityIds)
+	}
+	condition += ` AND user_id = ?  AND is_cancel = 0 `
+	pars = append(pars, userId)
+	list, e := models.GetCygxActivitySpecialTripList(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
+		return
+	}
+	mapUid := make(map[int]int)
+	for _, v := range list {
+		mapUid[v.ActivityId] = v.UserId
+	}
+	mapUserId = mapUid
+	return
+}
+
+//获取用户已经报名的活动数量
+func GetSpecialTripUserSchedule(userId int) (total int, err error) {
+	var condition string
+	var pars []interface{}
+
+	condition += ` AND t.user_id = ? AND t.is_cancel = 0 `
+	pars = append(pars, userId)
+	condition += ` AND a.activity_time_end >= ? `
+	pars = append(pars, time.Now())
+	condition += ` AND is_valid = 1 `
+	total, err = models.GetActivitySpecialTripCountByActivitySpecial(condition, pars)
+	return
+}
+
+//GetActivitySpecialList 获取专项调研列表
+func GetActivitySpecialList(user *models.WxUserItem, currentIndex, pageSize int, keywords string) (list []*models.CygxActivitySpecialDetail, total int, err error) {
+	listConfirm, totalConfirm, e := GetActivityLabelSpecialConfirmList(user, (currentIndex-1)*pageSize, pageSize, 4, keywords)
+	if e != nil {
+		err = errors.New("GetActivityLabelSpecialConfirmList, Err: " + e.Error())
+		return
+	}
+	if currentIndex == 1 && len(listConfirm) > 0 {
+		listConfirm[0].Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
+	}
+	list = listConfirm
+	total = totalConfirm
+	var startSizePrepare, pageSizePrepare int
+	//全是确定行程的查询数据
+	if totalConfirm >= currentIndex*pageSize {
+		startSizePrepare = 0
+		pageSizePrepare = 0
+	} else if totalConfirm > (currentIndex-1)*pageSize && totalConfirm < currentIndex*pageSize {
+		//一半确认行程一半预报名
+		startSizePrepare = 0
+		pageSizePrepare = pageSize - len(listConfirm)
+	} else {
+		//全是预报名
+		startSizePrepare = (currentIndex-1)*pageSize - totalConfirm
+		pageSizePrepare = pageSize - len(listConfirm)
+	}
+	listPrepare, totalPrepare, e := GetActivitySpecialPrepareList(user, startSizePrepare, pageSizePrepare, keywords)
+	if e != nil {
+		err = errors.New("GetActivityLabelSpecialConfirmList, Err: " + e.Error())
+		return
+	}
+	if len(listPrepare) > 0 {
+		for _, v := range listPrepare {
+			list = append(list, v)
+		}
+		if startSizePrepare == 0 {
+			listPrepare[0].Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
+		}
+	}
+	total = totalConfirm + totalPrepare
+
+	//处理封面图片
+	detail, e := models.GetConfigByCode("city_img_url")
+	if e != nil {
+		err = errors.New("GetConfigByCode, Err: " + e.Error())
+		return
+	}
+	detailChart, e := models.GetConfigByCode("chart_img_url")
+	if e != nil {
+		err = errors.New("GetConfigByCode, Err: " + e.Error())
+		return
+	}
+	addressList := strings.Split(detail.ConfigValue, "{|}")
+	mapAddress := make(map[string]string)
+	chartList := strings.Split(detailChart.ConfigValue, "{|}")
+	mapChart := make(map[string]string)
+	var cityName string
+	var chartName string
+	var imgUrl string
+	var imgUrlChart string
+	for _, v := range addressList {
+		vslice := strings.Split(v, "_")
+		cityName = vslice[0]
+		imgUrl = vslice[len(vslice)-1]
+		mapAddress[cityName] = imgUrl
+	}
+	for _, v := range chartList {
+		vslice := strings.Split(v, "_")
+		chartName = vslice[0]
+		imgUrlChart = vslice[len(vslice)-1]
+		mapChart[chartName] = imgUrlChart
+	}
+	for k, v := range list {
+		//list[k].ImgUrlText = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211221/bIdfv8t86xrFRpDOeGGHXOmKEuKl.png"
+		if mapChart[v.ChartPermissionName] != "" {
+			list[k].ImgUrl = mapChart[v.ChartPermissionName]
+		}
+		list[k].ActivityTypeName = "专项调研"
+		if list[k].Days == 0 {
+			list[k].TripStatus = 1
+		} else {
+			list[k].TripStatus = 2
+			list[k].TripImgLink = list[k].TripImgLinkFix
+		}
+	}
+	return
+}
+
+//HandleActivitySpecialShow 处理活动的状态
+func HandleActivitySpecialShow(activityDetail *models.CygxActivitySpecialDetail, user *models.WxUserItem) (item *models.CygxActivitySpecialDetail, err error) {
+	var activityIds []int
+	resultTimeStart := utils.StrTimeToTime(activityDetail.ActivityTime)  //时间字符串格式转时间格式
+	resultTimeEnd := utils.StrTimeToTime(activityDetail.ActivityTimeEnd) //时间字符串格式转时间格式
+	if resultTimeStart.After(time.Now()) {
+		activityDetail.ActiveState = 1
+	} else if time.Now().After(resultTimeEnd) {
+		activityDetail.ActiveState = 3
+	} else {
+		activityDetail.ActiveState = 2
+	}
+	activityIds = append(activityIds, activityDetail.ActivityId)
+	//处理用户已经报名了的行程
+	UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
+	if e != nil {
+		err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
+		return
+	}
+	if activityDetail.Days == 0 {
+		activityDetail.TripStatus = 1
+		activityDetail.Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
+	} else {
+		activityDetail.TripStatus = 2
+		activityDetail.TripImgLink = activityDetail.TripImgLinkFix
+		activityDetail.Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
+	}
+	if _, ok := UserMap[activityDetail.ActivityId]; ok {
+		activityDetail.IsTrip = 1
+	}
+	item = activityDetail
+	return
+}
+
+//活动与专项调研搜索 GetActivitySpecialSearcheList
+func GetActivitySpecialSearcheList(user *models.WxUserItem, condition string, startSize, pageSize int, keywords string) (items []*models.ActivityDetail, total int, err error) {
+	var conditionSpecil string
+	var pars, parsSpecil []interface{}
+	if keywords != "" {
+		keywords = "%" + keywords + "%"
+		conditionSpecil += ` AND art.days > 0 AND (art.research_theme LIKE ? OR art.label LIKE ? OR art.industrial_name LIKE ? OR art.industrial_subject_name LIKE ? ) `
+		parsSpecil = append(parsSpecil, keywords, keywords, keywords, keywords)
+	}
+	list, totalSearche, e := models.GetActivitySpecialSearcheList(condition, pars, conditionSpecil, parsSpecil, startSize, pageSize)
+	if e != nil {
+		err = errors.New("GetActivitySpecialSearcheList, Err: " + e.Error())
+		return
+	}
+	items, e = HandleActivityListButton(list, user)
+	if e != nil {
+		err = errors.New("HandleActivityListButton, Err: " + e.Error())
+		return
+	}
+	total = totalSearche
+	return
+}
+
+//获取 专项调研客户类型   //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //8、行业升级套餐客户 //9、其余正式客户;5、试用客户
+func GetActivitySpecialUserType(companyId int) (userType int, permissionStrnew string, err error) {
+	var permissionStr string
+	if companyId <= 1 {
+		userType = 0
+	} else {
+		total, e := models.GetCountCompanyDetailByIdGroupTrip(companyId)
+		if e != nil {
+			err = errors.New("GetCountCompanyDetailByIdGroupTrip, Err: " + e.Error())
+			return
+		}
+		if total == 0 {
+			userType = 0
+		} else {
+			companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
+			if e != nil {
+				err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
+				return
+			}
+			permissionStr, e = models.GetCompanyPermissionByUserTrip(companyId)
+			if e != nil {
+				err = errors.New("GetCompanyPermissionByUserTrip, Err: " + e.Error())
+				return
+			}
+			//permissionZhengShiStr, e = models.GetCompanyPermissionByUserZhengShiTrip(companyId)
+			//if e != nil {
+			//	err = errors.New("GetCompanyPermissionByUserZhengShiTrip, Err: " + e.Error())
+			//	return
+			//}
+			//大套餐客户定义:医药、消费、科技、智造。4个行业中为升级,策略是正式,属于大套餐客户
+			if companyDetail.Status == "永续" {
+				userType = 1
+			} else if companyDetail.Status == "试用" {
+				userType = 5
+			} else if companyDetail.Status == "正式" {
+				if permissionStr == "专家" {
+					userType = 4
+				} else if strings.Count(permissionStr, "医药") == 2 && strings.Count(permissionStr, "消费") == 2 && strings.Count(permissionStr, "科技") == 2 && strings.Count(permissionStr, "智造") == 2 && strings.Count(permissionStr, "策略") == 1 {
+					userType = 2
+				} else {
+					userType = 3
+				}
+				if userType == 3 {
+					if !strings.Contains(permissionStr, "医药") && !strings.Contains(permissionStr, "消费") && !strings.Contains(permissionStr, "科技") && !strings.Contains(permissionStr, "智造") {
+						userType = 4
+					}
+				}
+			} else if companyDetail.Status == "冻结" {
+				userType = 6
+			} else if companyDetail.Status == "流失" {
+				userType = 7
+			}
+		}
+	}
+	permissionStrnew = permissionStr
+	return
+}
+
+//GetSpecialUserType 获取专项产业调研的用户身份类型
+//获取 专项调研客户类型   //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //8、行业升级套餐客户 //9、其余正式客户;5、试用客户
+func GetSpecialUserType(user *models.WxUserItem) (userType int, err error) {
+	companyId := user.CompanyId
+	companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
+	if e != nil {
+		err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
+		return
+	}
+	if companyId <= 1 {
+		userType = 0
+	} else {
+		if companyDetail.Status == "永续" {
+			userType = 1
+		} else {
+			if companyDetail.Status == "正式" {
+				list, e := models.GetCompanyReportPermissionUpgrade(companyId, 2)
+				if e != nil && e.Error() != utils.ErrNoRow() {
+					err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
+				}
+				if len(list) == 0 {
+					userType = 9
+				}
+				if len(list) == 4 {
+					totalName, e := models.GetCompanyPermissionNameCheck(companyId, 2, "策略")
+					if e != nil {
+						err = errors.New("获取品种信息失败, Err:" + e.Error())
+						return
+					}
+					if totalName > 0 {
+						userType = 2
+					} else {
+						userType = 8
+					}
+				} else {
+					userType = 8
+				}
+			} else if companyDetail.Status == "试用" {
+				userType = 5
+			}
+		}
+	}
+	return
+}
+
+//GetSpecialDetailUserPower 处理用户查看专项调研详情的权限
+func GetSpecialDetailUserPower(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (havePower bool, err error) {
+	permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
+	if e != nil {
+		err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
+		return
+	}
+	fmt.Println(permissionStr)
+	//如果没有对应的升级权限,则返回
+	if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
+		return
+	}
+	userType, e := GetSpecialUserType(user)
+	if e != nil {
+		err = errors.New("GetSpecialUserType, Err: " + e.Error())
+		return
+	}
+	if userType == 0 {
+		return
+	}
+	var pars []interface{}
+	var condition string
+	var userTypes string
+	condition += `  AND art.publish_status = 1 AND art.is_offline = 0   `
+	userTypes = "%" + strconv.Itoa(userType) + "%"
+	condition += ` AND art.customer_type_ids LIKE ? `
+	pars = append(pars, userTypes)
+
+	condition += ` AND art.activity_id = ? `
+	pars = append(pars, activityInfo.ActivityId)
+
+	total, e := models.GetActivitySpecialCount(condition, pars)
+	if e != nil {
+		err = errors.New("GetSpecialUserType, Err: " + e.Error())
+		return
+	}
+	if total == 1 {
+		havePower = true
+	}
+	return
+}
+
+//预报名活动,感兴趣人数满10人时,推送给活动负责人和王芳
+func SendWxMsgActivitySpecial10(activityInfo *models.CygxActivitySpecialDetail) (err error) {
+	activityId := activityInfo.ActivityId
+	var msg string
+	defer func() {
+		if err != nil {
+			go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
+			go utils.SendAlarmMsg(fmt.Sprint("预报名活动,感兴趣人数满10人时,推送给活动负责人和王芳消息发送失败", activityInfo.ResearchTheme, ", activityId"), 2)
+			utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
+		}
+	}()
+	var first string
+	var keyword1 string
+	var keyword2 string
+	var keyword3 string
+	var keyword4 string
+	var remark string
+
+	adminUser, e := models.GetSellerByAdminId(activityInfo.AdminId)
+	if e != nil {
+		err = errors.New("GetSellerByAdminId, Err: " + e.Error())
+		return
+	}
+	cnf, _ := models.GetConfigByCode("tpl_msg")
+	mobile := adminUser.Mobile + "," + cnf.ConfigValue
+
+	specialSignupList, e := models.GetActivityListSpecialByActivityId(activityId)
+	if e != nil {
+		err = errors.New("GetActivityListSpecialAll, Err: " + e.Error())
+		return
+	}
+	for _, v := range specialSignupList {
+		keyword1 += "【" + v.RealName + "--" + v.CompanyName + "】"
+	}
+	openIdList, e := models.GetWxOpenIdByMobileList(mobile)
+	if e != nil {
+		err = errors.New("GetSellerByAdminId, Err: " + e.Error())
+		return
+	}
+	first = "【" + activityInfo.ResearchTheme + "】已有10人预报名"
+	keyword3 = "-"
+	keyword2 = "-"
+	keyword4 = activityInfo.ResearchTheme
+	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.WxMsgTemplateIdAskMsgXzs
+	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
+}

+ 57 - 0
services/wechat_send_msg.go

@@ -3,11 +3,13 @@ package services
 import (
 	"bytes"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"hongze/hongze_clpt/models"
 	"hongze/hongze_clpt/utils"
 	"io/ioutil"
 	"net/http"
+	"strings"
 	"time"
 )
 
@@ -225,3 +227,58 @@ type SendTemplateResponse struct {
 	Errmsg  string `json:"errmsg"`
 	MsgID   int    `json:"msgid"`
 }
+
+type SendWxTemplate struct {
+	WxAppId        string   `description:"公众号appId"`
+	First          string   `description:"模板消息first字段"`
+	Keyword1       string   `description:"模板消息keyword1字段"`
+	Keyword2       string   `description:"模板消息keyword2字段"`
+	Keyword3       string   `description:"模板消息keyword3字段"`
+	Keyword4       string   `description:"模板消息keyword4字段"`
+	Remark         string   `description:"模板消息remark字段"`
+	TemplateId     string   `description:"模板id"`
+	RedirectUrl    string   `description:"跳转地址"`
+	RedirectTarget int      `description:"小程序跳转目标:1:弘则研报小程序,2:随手办公小程序"`
+	Resource       string   `description:"资源唯一标识"`
+	SendType       int      `description:"发送的消息类型:1:报告,2:指标更新提醒,3:审批通知,4:销售领取客户通知,5:活动取消通知,6活动更改时间通知,7:关注的作者发布报告通知,8:发送日报(周报、双周报、月报)模板消息,9:活动预约/报名时间通知"`
+	OpenIdArr      []string `description:"消息接收者openid"`
+}
+
+//推送模板消息
+func PublicSendTemplateMsg(sendInfo *SendWxTemplate) (err error) {
+	postData, err := json.Marshal(sendInfo)
+	if err != nil {
+		utils.SendAlarmMsg("SendTemplateMsg json.Marshal Err:"+err.Error(), 1)
+		return err
+	}
+	body := ioutil.NopCloser(strings.NewReader(string(postData)))
+	client := &http.Client{}
+	req, err := http.NewRequest("POST", utils.SendWxTemplateMsgUrl, body)
+	if err != nil {
+		utils.SendAlarmMsg("SendTemplateMsg http.NewRequest Err:"+err.Error(), 1)
+		return err
+	}
+	contentType := "application/json;charset=utf-8"
+	req.Header.Set("Content-Type", contentType)
+	req.Header.Set("Authorization", utils.SendTemplateMsgAuthorization)
+	resp, err := client.Do(req)
+	if err != nil {
+		fmt.Println("http client.Do Err:" + err.Error())
+		return err
+	}
+	defer resp.Body.Close()
+	b, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		return err
+	}
+	result := new(models.BaseResponse)
+	err = json.Unmarshal(b, &result)
+	if err != nil {
+		return err
+	}
+	if result.Ret != 200 {
+		err = errors.New(string(b))
+		return err
+	}
+	return
+}

+ 5 - 0
utils/config.go

@@ -43,6 +43,11 @@ var (
 	YiDonggetOriginalLink    string //易董 短连接转为长链接
 )
 
+//模板消息推送
+var (
+	SendWxTemplateMsgUrl string
+)
+
 func init() {
 	tmpRunMode, err := web.AppConfig.String("run_mode")
 	if err != nil {

+ 29 - 0
utils/constants.go

@@ -118,3 +118,32 @@ const (
 const (
 	YD_TOKEN = "yidong_token"
 )
+
+const (
+	//专项调研背景图片
+	//ACTIVITY_ZXDY_ImgUrl1 = "https://hzstatic.hzinsights.com/static/temp/20220427202204/20220427/b2Bj3fGakP16iJRFKisQohCWnCNl.png"
+	//ACTIVITY_ZXDY_ImgUrl2 = "https://hzstatic.hzinsights.com/static/temp/20220427202204/20220427/OkunjfKEgo5KRLifzwwLX8cDZnnN.png"
+	//ACTIVITY_ZXDY_ImgUrl3 = "https://hzstatic.hzinsights.com/static/temp/20220426202204/20220426/XDLLsjC9XAAy8LIzQr7GsjrBbtX6.png"
+
+	ACTIVITY_ZXDY_ImgUrl1 = "https://hzstatic.hzinsights.com/static/temp/20220707202207/20220707/0H4md6VgZMuIttggMUnJxgrlayxC.png"
+	ACTIVITY_ZXDY_ImgUrl2 = "https://hzstatic.hzinsights.com/static/temp/20220707202207/20220707/rFwAM1c4fIMJM0EGoUkUYl25XH9L.png"
+	ACTIVITY_ZXDY_ImgUrl3 = "https://hzstatic.hzinsights.com/cygx/special_list_bg.png"
+)
+
+//模板消息地址路由
+const (
+	ACtIVITY_SPECIAL_EXPLAIN      = "此类调研具体行程尚未确定,待预报名人数满10人后弘则会确定行程并推送给您活动日期,只有在确定行程中再次报名才完成占位。"                        //专项调研说明
+	ACtIVITY_SPECIAL_TRIP_EXPLAIN = "此类调研时间安排已经确定,点击报名后按人次扣除对应机构的服务点数。由于每场活动人数有限,如果不能参加请提前48小时取消,未及时取消导致影响其他客户报名将会维持扣点。" //专项调研说明
+
+)
+
+//模板消息地址路由
+const (
+	WX_MSG_PATH_ARTICLE_DETAIL          = "pageMy/reportDetail/reportDetail?id="          //文章详情模板消息地址
+	WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL = "activityPages/specialDetail/specialDetail?id=" //专项调研活动模板消息地址
+)
+
+//微信模板消息推送公共接口的秘钥
+const (
+	SendTemplateMsgAuthorization = "dc855fce962a639faa779cbdd4cd332f"
+)