Browse Source

Merge branch 'master' of http://8.136.199.33:3000/cxzhang/hongze_clpt into cygx_9.8

xingzai 2 years ago
parent
commit
7cd416a82c

+ 18 - 12
controllers/activity.go

@@ -69,6 +69,7 @@ func (this *ActivityController) LabelTypeList() {
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
 		return
 	}
+	//return
 
 	list, err := models.GetActivityTypeHomeList()
 	if err != nil {
@@ -78,8 +79,11 @@ func (this *ActivityController) LabelTypeList() {
 	}
 	list, err = services.HandleActivityTypeHomeList(list, activityList, user)
 
+	//专项产业调研未开始状态不查询
+	if activeState == "1" {
+		activeState = ""
+	}
 	conditionActivitySpecial := services.ActivityLabelSpecialSql(chartPermissionIds, whichDay, activeState)
-
 	speciaItem, err := services.GetActivityLabelSpecialList(user, conditionActivitySpecial)
 	if err != nil {
 		br.Msg = "获取失败"
@@ -176,7 +180,6 @@ func (this *ActivityController) ActivityListNew() {
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
-
 	var conditionOrder string
 	if activeState == "2" || activeState == "3" {
 		conditionOrder = ` ORDER BY art.activity_time DESC  `
@@ -705,16 +708,19 @@ func (this *ActivityController) SignupAdd() {
 				resp.PopupMsg = "由于爽约次数过多,您暂时被限制报名资格"
 				item.FailType = 3
 			}
-			totalSignupCompany, err := models.GetActivitySignupCompanyCount(activityId, user.CompanyId)
-			if err != nil {
-				br.Msg = "获取信息失败"
-				br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
-				return
-			}
-			if totalSignupCompany >= 2 {
-				signupStatus = "TwoPeople"
-				resp.PopupMsg = "单机构最多2人报名同一活动,您所在机构报名人数已满"
-				item.FailType = 2
+			//弘则下面的用户不做单机构两人限制
+			if user.CompanyId != utils.HZ_COMPANY_ID {
+				totalSignupCompany, err := models.GetActivitySignupCompanyCount(activityId, user.CompanyId)
+				if err != nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+					return
+				}
+				if totalSignupCompany >= 2 {
+					signupStatus = "TwoPeople"
+					resp.PopupMsg = "单机构最多2人报名同一活动,您所在机构报名人数已满"
+					item.FailType = 2
+				}
 			}
 			totaSignupPeopleNum, err := models.GetActivitySignupSuccessCount(activityId)
 			if err != nil {

+ 45 - 3
controllers/activity_special.go

@@ -10,7 +10,7 @@ import (
 	"time"
 )
 
-//专项调研活动
+// 专项调研活动
 type ActivitySpecialController struct {
 	BaseAuthController
 }
@@ -47,7 +47,9 @@ func (this *ActivitySpecialController) SpecialList() {
 	if currentIndex <= 0 {
 		currentIndex = 1
 	}
-
+	if activeState == "1" {
+		activeState = ""
+	}
 	conditionActivity := services.ActivityLabelSpecialSql(chartPermissionIds, whichDay, activeState)
 
 	list, total, errList := services.GetActivitySpecialList(user, currentIndex, pageSize, "", conditionActivity, activeState)
@@ -243,6 +245,23 @@ func (this *ActivitySpecialController) SpecialTripAdd() {
 				br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
 				return
 			}
+			//流水记录表
+			itemBill := new(models.CygxActivitySpecialTripBill)
+			itemBill.UserId = user.UserId
+			itemBill.ActivityId = activityInfo.ActivityId
+			itemBill.CreateTime = time.Now()
+			itemBill.Mobile = user.Mobile
+			itemBill.Email = user.Email
+			itemBill.CompanyId = user.CompanyId
+			itemBill.CompanyName = user.CompanyName
+			itemBill.RealName = user.RealName
+			itemBill.Source = 1
+			itemBill.DoType = 1
+			itemBill.BillDetailed = -1 // 流水减一
+			itemBill.RegisterPlatform = 1
+			itemBill.ChartPermissionId = activityInfo.ChartPermissionId
+
+			go services.ActivitySpecialUserRmind(user, activityId, 2)
 			//判断是删除还是添加
 			if total == 0 {
 				//获取销售信息
@@ -253,7 +272,6 @@ func (this *ActivitySpecialController) SpecialTripAdd() {
 					return
 				}
 				item := new(models.CygxActivitySpecialTrip)
-				item.RegisterPlatform = utils.REGISTER_PLATFORM
 				item.UserId = uid
 				item.RealName = user.RealName
 				item.ActivityId = activityId
@@ -285,7 +303,13 @@ func (this *ActivitySpecialController) SpecialTripAdd() {
 					br.ErrMsg = "二次报名,更改报名是否有效状态失败,Err:" + err.Error()
 					return
 				}
+				resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
+				//48小时之内的取消也扣除一次参会记录
+				if time.Now().Add(+time.Hour * 48).After(resultTime) {
+					itemBill.BillDetailed = 0 //48小时之内,取消报名之后二次报名,不扣除流水记录
+				}
 			}
+			go models.AddCygxActivitySpecialTripBill(itemBill)
 		}
 	} else {
 		hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermission(user)
@@ -344,11 +368,27 @@ func (this *ActivitySpecialController) Tripcancel() {
 		br.ErrMsg = "操作失败,Err:" + errInfo.Error()
 		return
 	}
+	//流水记录表
+	itemBill := new(models.CygxActivitySpecialTripBill)
+	itemBill.UserId = user.UserId
+	itemBill.ActivityId = activityInfo.ActivityId
+	itemBill.CreateTime = time.Now()
+	itemBill.Mobile = user.Mobile
+	itemBill.Email = user.Email
+	itemBill.CompanyId = user.CompanyId
+	itemBill.CompanyName = user.CompanyName
+	itemBill.RealName = user.RealName
+	itemBill.Source = 1
+	itemBill.DoType = 2
+	itemBill.BillDetailed = 1 // 流水加一
+	itemBill.RegisterPlatform = 1
+	itemBill.ChartPermissionId = activityInfo.ChartPermissionId
 	resultTime := utils.StrTimeToTime(activityInfo.ActivityTime)
 	//48小时之内的取消也扣除一次参会记录
 	var isValid int
 	if time.Now().Add(+time.Hour * 48).After(resultTime) {
 		isValid = 1
+		itemBill.BillDetailed = 0 //48小时之内取消的活动扣点不返回
 	}
 	err = models.CancelActivitySpecialTripIsValid(isValid, activityInfo.ActivityId, uid)
 	if err != nil {
@@ -356,6 +396,8 @@ func (this *ActivitySpecialController) Tripcancel() {
 		br.ErrMsg = "CancelActivitySpecialTrip,Err:" + err.Error()
 		return
 	}
+	go models.AddCygxActivitySpecialTripBill(itemBill)
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "已取消"

+ 5 - 1
controllers/chart_permission.go

@@ -6,7 +6,7 @@ import (
 	"strconv"
 )
 
-//品种
+// 品种
 type ChartPermissionController struct {
 	BaseCommonController
 }
@@ -67,6 +67,10 @@ func (this *ChartPermissionController) ListByReport() {
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
 		return
 	}
+	item := new(models.ChartPermissionResp)
+	item.PermissionName = utils.GU_SHOU_NAME
+	item.ChartPermissionId = utils.GU_SHOU_ID
+	list = append(list, item)
 	resp := new(models.ChartPermissionListResp)
 	resp.List = list
 	br.Ret = 200

+ 38 - 30
controllers/report.go

@@ -51,8 +51,8 @@ func (this *MobileReportController) TradeList() {
 	var list []*models.TradeReportMapping
 	var err error
 	mapCategory := make(map[int]int)
-	if ChartPermissionId == utils.CE_LUE_ID {
-		listTrade, errTrade := models.GetReportMappingStrategyHomeAll(user.UserId)
+	if ChartPermissionId == utils.CE_LUE_ID || ChartPermissionId == utils.GU_SHOU_ID {
+		listTrade, errTrade := models.GetReportMappingStrategyHomeAll(user.UserId, ChartPermissionId)
 		list = listTrade
 		err = errTrade
 
@@ -120,7 +120,7 @@ func (this *MobileReportController) TradeList() {
 			condition = ` AND a.category_id IN(` + strconv.Itoa(v.CategoryId) + `)`
 		}
 
-		if ChartPermissionId != utils.CE_LUE_ID {
+		if ChartPermissionId != utils.CE_LUE_ID && ChartPermissionId != utils.GU_SHOU_ID {
 			var pageSize int
 			//if ChartPermissionId == utils.KE_JI_ID {
 			//	pageSize = 12
@@ -508,7 +508,7 @@ func (this *MobileReportController) List() {
 	var total int
 	resp := new(models.TacticsListResp)
 	page := paging.GetPaging(currentIndex, pageSize, total)
-	list := make([]*models.HomeArticle, 0)
+	list := make([]*models.ArticleListResp, 0)
 
 	if categoryId == utils.TIME_CATEGORYID {
 		var err error
@@ -567,17 +567,6 @@ func (this *MobileReportController) List() {
 			imgUrlChart = vslice[len(vslice)-1]
 			mapCategoryUrl[categoryIdStr] = imgUrlChart
 		}
-
-		//condition += ` AND category_id_two=? `
-		//pars = append(pars, categoryId)
-
-		//categoryIdSet, errCategory := models.GetdetailByCategoryIdSet(categoryId)
-		//if errCategory != nil {
-		//	br.Msg = "获取信息失败"
-		//	br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
-		//	return
-		//}
-		//fmt.Println(detail.PolymerizationId)
 		if detail.CeLueFieldId != "" {
 			condition = ` AND ce_lue_field_id IN(` + detail.CeLueFieldId + `)`
 		} else if detail.PolymerizationId != "" {
@@ -618,7 +607,7 @@ func (this *MobileReportController) List() {
 			return
 		}
 
-		list, err = models.GetHomeList(condition, pars, startSize, pageSize)
+		list, err = models.GetHomeListNew(condition, pars, startSize, pageSize)
 		if err != nil {
 			br.Msg = "获取信息失败"
 			br.Msg = "获取帖子数据失败,Err:" + err.Error()
@@ -647,23 +636,42 @@ func (this *MobileReportController) List() {
 		}
 		resp.CategoryImgUrlPc = mapChartPermission[detail.ChartPermissionName]
 	}
-	lenList := len(list)
-	for i := 0; i < lenList; i++ {
-		item := list[i]
-		list[i].Body = ""
-		list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
-		list[i].Annotation, _ = services.GetReportContentTextSub(item.Annotation)
-		list[i].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
-		//行业比较研究、资金流向,显示报告的摘要
-		if resp.MatchTypeName == "行业比较研究" || resp.MatchTypeName == "资金流向" {
-			list[i].Annotation = list[i].Abstract
-		}
+
+	listPublic, err := services.HandleArticleCategoryImg(list, user)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取报告封面图片失败, Err:" + err.Error()
+		return
 	}
-	if len(list) == 0 {
-		list = make([]*models.HomeArticle, 0)
+	listResp := make([]*models.HomeArticle, 0)
+	//listResp :=
+	for _, v := range listPublic {
+		listResp = append(listResp, &models.HomeArticle{
+			ArticleId:   v.ArticleId,
+			Title:       v.Title,
+			Annotation:  "核心观点:" + v.Annotation,
+			Abstract:    v.Abstract,
+			ImgUrlPc:    v.ImgUrlPc,
+			PublishDate: v.PublishDate,
+		})
+	}
+	//lenList := len(list)
+	//for i := 0; i < lenList; i++ {
+	//	item := list[i]
+	//	list[i].Body = ""
+	//	list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
+	//	list[i].Annotation, _ = services.GetReportContentTextSub(item.Annotation)
+	//	list[i].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
+	//	//行业比较研究、资金流向,显示报告的摘要
+	//	if resp.MatchTypeName == "行业比较研究" || resp.MatchTypeName == "资金流向" {
+	//		list[i].Annotation = list[i].Abstract
+	//	}
+	//}
+	if len(listResp) == 0 {
+		listResp = make([]*models.HomeArticle, 0)
 	}
 	page = paging.GetPaging(currentIndex, pageSize, total)
-	resp.List = list
+	resp.List = listResp
 	resp.Paging = page
 	br.Ret = 200
 	br.Success = true

+ 22 - 5
controllers/search.go

@@ -181,23 +181,40 @@ func (this *MobileSearchController) ListHomeArtAndChart() {
 			br.ErrMsg = "检索失败,Err:" + err.Error()
 			return
 		}
-		tmpResult, tmpTotalResult, err := services.EsArticleSearch(keyWord, startSize, pageSize, orderColumn, 1)
+		tmpResult, tmpTotalResult, err := services.EsArticleSearchBody(keyWord, startSize, pageSize, orderColumn, 1)
 		if err != nil {
 			br.Msg = "检索失败"
 			br.ErrMsg = "检索失败,Err:" + err.Error()
 			return
 		}
 		result = tmpResult
+		fmt.Println(tmpTotalResult)
+		if int(tmpTotalResult) < currentIndex*pageSize {
+			startSizeBody := startSize - int(tmpTotalResult)
+			if startSizeBody < 0 {
+				startSizeBody = 0
+			}
+			var pageSizeBody int
+			pageSizeBody = pageSize - len(tmpResult)
+			tmpResultBody, tmpTotalBody, err := services.EsArticleSearchBody(keyWord, startSizeBody, pageSizeBody, orderColumn, 2)
+			if err != nil {
+				br.Msg = "检索失败"
+				br.ErrMsg = "检索失败,Err:" + err.Error()
+				return
+			}
+			for _, v := range tmpResultBody {
+				result = append(result, v)
+			}
+			tmpTotalResult += tmpTotalBody
+		}
+
 		if int(tmpTotalResult) < currentIndex*pageSize {
-			fmt.Println(currentIndex * pageSize)
-			fmt.Println(startSize)
-			fmt.Println(tmpTotalResult)
 			startSizeIk := startSize - int(tmpTotalResult)
 			if startSizeIk < 0 {
 				startSizeIk = 0
 			}
 			var pageSizeIk int
-			pageSizeIk = pageSize - len(tmpResult)
+			pageSizeIk = pageSize - len(result)
 			tmpResultIk, _, err := services.EsArticleSearch(keyWord, startSizeIk, pageSizeIk, orderColumn, 2)
 			if err != nil {
 				br.Msg = "检索失败"

+ 2 - 0
models/activity.go

@@ -392,6 +392,7 @@ func GetActivitySpecialSearcheList(condition string, pars []interface{}, conditi
             t.img_url_text,
             art.is_yidong_conduct,
             art.is_can_outbound_call,
+            art.city,
 			art.activity_time 
 		FROM
 			cygx_activity AS art
@@ -424,6 +425,7 @@ func GetActivitySpecialSearcheList(condition string, pars []interface{}, conditi
 			"",
 			"",
 			"",
+			"",
 			art.activity_time 
 		FROM
 			cygx_activity_special AS art

+ 1 - 1
models/activity_special.go

@@ -13,7 +13,7 @@ type CygxActivitySpecialDetail struct {
 	SpecialType           int    `description:"调研形式、 1 线上 , 2 线下"`
 	City                  string `description:"调研城市"`
 	ChartPermissionName   string `description:"行业名称"`
-	ChartPermissionId     string `description:"行业Id"`
+	ChartPermissionId     int    `description:"行业Id"`
 	ResearchTheme         string `description:"调研主题"`
 	ActivityTimeText      string `description:"活动预期时间带文字"`
 	TripImgLink           string `description:"行程图片链接"`

+ 44 - 0
models/activity_special_trip_bill.go

@@ -0,0 +1,44 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxActivitySpecialTripBill 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:"用户实际名称"`
+	AdminId           int       `description:"销售/管理员ID"`
+	Source            int       `description:"来源,1小程序,2后台添加, 3开发人员手动添加"`
+	BillDetailed      int       `description:"流水明细,判断是进账还是出账"`
+	DoType            int       `description:"操作方式,1报名,2取消报名"`
+	RegisterPlatform  int       `description:"来源 1小程序,2:网页"`
+	ChartPermissionId int       `description:"行业id"`
+}
+
+// 添加
+func AddCygxActivitySpecialTripBill(item *CygxActivitySpecialTripBill) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	if err != nil {
+		return
+	}
+	return
+}
+
+func GetCygxActivitySpecialTripBill(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBill, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_activity_special_trip_bill  
+			WHERE 1 = 1 ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}

+ 14 - 0
models/activity_type.go

@@ -67,3 +67,17 @@ func GetActivityTypeHomeList() (items []*ActivityTypeHome, err error) {
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+type ActivityCcustomerType struct {
+	CustomerTypeId  int    `description:"活动类型id"`
+	CustomerName    string `description:"活动名称"`
+	PermissionValue string `description:"用户权限对应的值"`
+}
+
+// 列表
+func GetActivityCcustomerTypeList() (items []*ActivityCcustomerType, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_customer_type ORDER BY sort DESC`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 1 - 2
models/article.go

@@ -59,10 +59,9 @@ func GetArticleDetailById(articleId int) (item *ArticleDetail, err error) {
 func GetArticlePermission(companyId int) (item *ChartPermission, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
-			b.* 
+			a.chart_permission_name as  permission_name
 			FROM
 			cygx_report_mapping AS a
-			INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id 
 			WHERE
 			a.category_id = ?`
 	err = o.Raw(sql, companyId).QueryRow(&item)

+ 5 - 6
models/company_activity_trip.go

@@ -60,23 +60,22 @@ func GetCompanyPermissionByUserTrip(companyId int) (permission string, err error
 	return
 }
 
-//获取正式权限
+// 获取正式权限
 func GetCompanyPermissionByUserZhengShiTrip(companyId int) (permission string, err error) {
-	sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark  ORDER BY b.sort ASC  SEPARATOR ',') AS permission
+	sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name  ORDER BY b.sort ASC  SEPARATOR ',') AS permission
 			FROM company_report_permission AS a
 			INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
 			INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
 			WHERE  a.company_id=?
 			AND c.is_suspend=0
             AND b.cygx_auth=1
-			AND a.is_upgrade = 1 
-			AND c.status IN('正式')  `
+			AND ( a.is_upgrade = 1 AND c.STATUS = '正式' OR c.STATUS = '永续' ) `
 	o := orm.NewOrm()
 	err = o.Raw(sql, companyId).QueryRow(&permission)
 	return
 }
 
-//GetCompanyReportPermissionUpgrade 获取升级的权限类型
+// GetCompanyReportPermissionUpgrade 获取升级的权限类型
 func GetCompanyReportPermissionUpgrade(companyId, productId int) (items []*CompanyReportPermission, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
@@ -109,7 +108,7 @@ func GetChartPermissionByIds(permissionIds []string) (list []*ChartPermission, e
 	return
 }
 
-//GetCompanyPermissionNameCheck 通过名称判断客户是否开了某一类型的权限
+// GetCompanyPermissionNameCheck 通过名称判断客户是否开了某一类型的权限
 func GetCompanyPermissionNameCheck(companyId, productId int, permissionName string) (count int, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT

+ 22 - 0
models/company_user_type.go

@@ -0,0 +1,22 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxCompanyUserType struct {
+	Id             int `orm:"column(id);pk" description:"分析师id"`
+	CompanyId      int
+	CustomerTypeId int       `description:"用户身份ID"`
+	CreateTime     time.Time `description:"创建时间"`
+	ModifyTime     time.Time `description:"创建时间"`
+}
+
+// 通过活动ID获取详情
+func GetCygxCompanyUserType(companyId int) (item *CygxCompanyUserType, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *  FROM cygx_company_user_type AS a WHERE a.company_id=?  `
+	err = o.Raw(sql, companyId).QueryRow(&item)
+	return
+}

+ 1 - 0
models/db.go

@@ -60,6 +60,7 @@ func init() {
 		new(CygxArticleHistoryRecordNewpv),
 		new(CygxArticleHistoryRecord),
 		new(CygxArticleHistoryRecordAll),
+		new(CygxActivitySpecialTripBill),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 14 - 0
models/home.go

@@ -69,6 +69,7 @@ type ArticleListResp struct {
 	DepartmentId        int    `description:"作者Id"`
 	NickName            string `description:"作者昵称"`
 	IsCollect           bool   `description:"本人是否收藏"`
+	IsRed               bool   `description:"是否标红"`
 	CollectNum          int    `description:"收藏人数"`
 	List                []*IndustrialManagementIdInt
 }
@@ -122,6 +123,19 @@ func GetHomeList(condition string, pars []interface{}, startSize, pageSize int)
 	return
 }
 
+func GetHomeListNew(condition string, pars []interface{}, startSize, pageSize int) (items []*ArticleListResp, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * ,(SELECT count(1) FROM cygx_article_history_record_newpv as h WHERE h.article_id = a.article_id ) as pv
+                 FROM cygx_article AS a
+                WHERE a.publish_status=1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY publish_date DESC,article_id DESC LIMIT ?,? `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
 // 获取产业报告列表
 func GetReportIndustrialList(condition string, pars []interface{}, categoryId, industrialManagementId, userId, startSize, pageSize int) (items []*HomeArticle, err error) {
 	o := orm.NewOrm()

+ 1 - 1
models/report.go

@@ -390,7 +390,7 @@ func GetReportCollectionBillboardListYx(limit int, pars []interface{}, condition
 }
 
 // 获取产业报告+晨会点评列表
-func GetTimeLineReportIndustrialList(industrialManagementId, startSize, pageSize int) (items []*HomeArticle, total int, err error) {
+func GetTimeLineReportIndustrialList(industrialManagementId, startSize, pageSize int) (items []*ArticleListResp, total int, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
 			a.id,

+ 3 - 3
models/report_mapping.go

@@ -58,7 +58,7 @@ func GetReportMappingStrategyAll() (items []*ReportMapping, err error) {
 }
 
 // 获取策略下面的所有分类
-func GetReportMappingStrategyHomeAll(userId int) (items []*TradeReportMapping, err error) {
+func GetReportMappingStrategyHomeAll(userId, ChartPermissionId int) (items []*TradeReportMapping, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
 			MAX( art.publish_date ) AS update_time,
@@ -69,12 +69,12 @@ func GetReportMappingStrategyHomeAll(userId int) (items []*TradeReportMapping, e
 				INNER JOIN cygx_article AS art ON art.category_id = re.category_id 
 			WHERE
 				re.report_type = 1 
-				AND re.chart_permission_id = 23 
+				AND re.chart_permission_id = ? 
 			GROUP  BY
 				re.match_type_name
 			ORDER BY
 				sort DESC , art.publish_date DESC`
-	_, err = o.Raw(sql).QueryRows(&items)
+	_, err = o.Raw(sql, ChartPermissionId).QueryRows(&items)
 	return
 }
 

+ 28 - 14
models/user.go

@@ -137,14 +137,14 @@ type LoginResp struct {
 }
 
 type UserDetailResp struct {
-	UserId              int    `description:"用户id"`
-	UserName            string `description:"用户名称"`
-	Headimgurl          string `description:"用户头像"`
-	Mobile              string `description:"手机号"`
-	Email               string `description:"邮箱"`
-	CompanyName         string `description:"客户名称"`
-	OutboundMobile      string `description:"外呼手机号"`
-	OutboundCountryCode string `description:"外呼手机号区号"`
+	UserId              int      `description:"用户id"`
+	UserName            string   `description:"用户名称"`
+	Headimgurl          string   `description:"用户头像"`
+	Mobile              string   `description:"手机号"`
+	Email               string   `description:"邮箱"`
+	CompanyName         string   `description:"客户名称"`
+	OutboundMobile      string   `description:"外呼手机号"`
+	OutboundCountryCode string   `description:"外呼手机号区号"`
 	PermissionName      []string `description:"拥有权限分类"`
 }
 
@@ -175,7 +175,7 @@ type CountryCodeItem struct {
 	CountryCode string `description:"区号"`
 }
 
-//修改外呼手机号
+// 修改外呼手机号
 type OutboundMobileItem struct {
 	OutboundMobile      string `description:"外呼手机号"`
 	OutboundCountryCode string `description:"外呼手机号区号"`
@@ -207,6 +207,21 @@ type UserDetailByUserLogin struct {
 }
 
 func GetCompanyPermission(companyId int) (permission string, err error) {
+	sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark  ORDER BY b.sort ASC SEPARATOR ',') AS permission
+			FROM company_report_permission AS a
+			INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
+			INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
+			WHERE  a.company_id=?
+			AND c.is_suspend=0
+            AND b.cygx_auth=1
+			AND c.status IN('正式','试用','永续')
+			AND a.status IN('正式','试用','永续') `
+	o := orm.NewOrm()
+	err = o.Raw(sql, companyId).QueryRow(&permission)
+	return
+}
+
+func GetCompanyPermissionName(companyId int) (permission string, err error) {
 	sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name  ORDER BY b.sort ASC SEPARATOR ',') AS permission
 			FROM company_report_permission AS a
 			INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
@@ -236,7 +251,7 @@ func GetCompanyPermissionId(companyId int) (permissionId string, err error) {
 	return
 }
 
-//用户绑定手机号时同时绑定外呼手机号
+// 用户绑定手机号时同时绑定外呼手机号
 func BindUserOutboundMobile(mobile, countryCode string, userId int) (err error) {
 	o := orm.NewOrm()
 	sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ?, country_code= ? WHERE user_id=? `
@@ -252,7 +267,7 @@ type UserPermissionAuthInfo struct {
 	PopupMsg      string `description:"权限弹窗信息"`
 }
 
-//修改用户是否绑定外呼手机号弹窗
+// 修改用户是否绑定外呼手机号弹窗
 func ModifyWxUserIsMsgOutboundMobile(userId int) (err error) {
 	o := orm.NewOrm()
 	sql := `UPDATE wx_user SET is_msg_outbound_mobile=1 WHERE user_id=? `
@@ -260,7 +275,7 @@ func ModifyWxUserIsMsgOutboundMobile(userId int) (err error) {
 	return
 }
 
-//已经绑定手机号,没有绑定外呼手机号的的用户,预约外呼的时候,将外呼手机号同步成手机号
+// 已经绑定手机号,没有绑定外呼手机号的的用户,预约外呼的时候,将外呼手机号同步成手机号
 func BindUserOutboundMobileByMobile(mobile, countryCode string, userId int) (err error) {
 	o := orm.NewOrm()
 	sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ? WHERE user_id=? `
@@ -329,7 +344,7 @@ type Headimgurl struct {
 	Headimgurl string `description:"用户头像"`
 }
 
-//更改用户头像
+// 更改用户头像
 func UpdateUserHeadimgurl(headimgurl string, userId int) (err error) {
 	o := orm.NewOrm()
 	sql := `UPDATE wx_user SET headimgurl = ? WHERE user_id=? `
@@ -375,4 +390,3 @@ func GetUserMicroRoadshowCollectList(userId int) (items []*CygxArticleCollect, e
 	_, err = orm.NewOrm().Raw(sql, userId).QueryRows(&items)
 	return
 }
-

+ 12 - 5
models/wx_user.go

@@ -126,7 +126,7 @@ func GetWxUserItemByUserUnionId(unionId string) (item *WxUserItem, err error) {
 	return
 }
 
-//根据用户UnionId取相关信息
+// 根据用户UnionId取相关信息
 func GetWxUserAouthByUnionId(UnionId string) (item *WxUserItem, err error) {
 	sql := `SELECT
 			a.*,
@@ -146,7 +146,7 @@ func GetWxUserAouthByUnionId(UnionId string) (item *WxUserItem, err error) {
 	return
 }
 
-//根据用户手机号获取相关信息
+// 根据用户手机号获取相关信息
 func GetWxUserItemByUserMobile(mobile string) (item *WxUserItem, err error) {
 	sql := `SELECT
 			a.user_id,
@@ -171,7 +171,7 @@ func GetWxUserItemByUserMobile(mobile string) (item *WxUserItem, err error) {
 	return
 }
 
-//GetUserCountByMobile 获取数量
+// GetUserCountByMobile 获取数量
 func GetUserCountByMobile(mobile string) (count int, err error) {
 	o := orm.NewOrm()
 	sqlCount := ` SELECT COUNT(1) AS count  FROM wx_user WHERE mobile = ? `
@@ -179,17 +179,24 @@ func GetUserCountByMobile(mobile string) (count int, err error) {
 	return
 }
 
-//添加用户信息
+// 添加用户信息
 func AddWxUser(item *WxUser) (lastId int64, err error) {
 	o := orm.NewOrm()
 	lastId, err = o.Insert(item)
 	return
 }
 
-//变更联系人是否已注册状态
+// 变更联系人是否已注册状态
 func ModifyWxUserRegisterStatus(userId int) (err error) {
 	o := orm.NewOrm()
 	sql := `UPDATE wx_user SET is_register=?,source=3,register_time=NOW() WHERE user_id = ? `
 	_, err = o.Raw(sql, 1, userId).Exec()
 	return
 }
+
+// 判断这个用户是否被设置消息提醒
+func GetUserRemind(uid int) (count int, err error) {
+	sql := `SELECT  COUNT(1) AS count FROM cygx_user_remind WHERE user_id = ? `
+	err = orm.NewOrm().Raw(sql, uid).QueryRow(&count)
+	return
+}

+ 139 - 27
services/activity.go

@@ -54,6 +54,14 @@ func GetActivityonditionList(user *models.WxUserItem, activityTypeId, chartPermi
 	permissionNameStr = strings.Replace(permissionNameStr, "(客观)", "", -1)
 	permissionNameStr = strings.TrimRight(permissionNameStr, ",")
 
+	mapUserType, e := GetActivityCcustomerTypeList()
+	if e != nil {
+		err = e
+		return
+	}
+	var userTypeStr string
+	userTypeStr = mapUserType[userType]
+
 	// 查研观向7.4-始终查询宏观的权限(无论是否有权限)
 	if permissionNameStr == `` {
 		permissionNameStr = `'宏观'`
@@ -65,11 +73,11 @@ func GetActivityonditionList(user *models.WxUserItem, activityTypeId, chartPermi
 	var conditionAdmin string
 	var conditionHz string // 弘则权限处理
 	var sqlExport string   // 专家权限处理
-	permissionSqlStr = `  AND art.chart_permission_name  IN (` + permissionNameStr + `)`
-	sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
-	if userType == 2 {
-		sqlExport += ` OR  art.customer_type_ids LIKE '%3%' `
-	}
+	//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%' `
 	}
@@ -200,20 +208,27 @@ func GetActivityonditionList(user *models.WxUserItem, activityTypeId, chartPermi
 		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 ))  `
+	//}
+	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 `
+	//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 + `) `
 	}
@@ -235,7 +250,10 @@ func GetActivityonditionList(user *models.WxUserItem, activityTypeId, chartPermi
 	}
 
 	if adminIds != "" {
-		conditionOr += ` OR (  art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' ` + ` AND  art.admin_id IN (` + adminIds + `) ` + conditionAdmin + `) `
+		if userType == 3 {
+			conditionAdmin += `  AND art.chart_permission_name  IN (` + permissionNameStr + `) `
+		}
+		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 + `) `
@@ -243,8 +261,23 @@ func GetActivityonditionList(user *models.WxUserItem, activityTypeId, chartPermi
 		}
 	}
 
+	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 == 16 {
+	if user.CompanyId == utils.HZ_COMPANY_ID {
 		mapMobile, e := GetAdminMobileMap()
 		if e != nil {
 			err = e
@@ -254,7 +287,9 @@ func GetActivityonditionList(user *models.WxUserItem, activityTypeId, chartPermi
 			conditionOr += ` OR (  art.publish_status = 1 ` + conditionHz + `) `
 		}
 	}
-
+	if userType == 3 {
+		condition += `  AND art.chart_permission_name  IN (` + permissionNameStr + `) `
+	}
 	conditionActivity = condition + permissionSqlStr + sqlExport + conditionOr
 	return
 }
@@ -758,14 +793,46 @@ func GetIndustryNewLabelMap(industryIds []int) (labelMap map[int]bool, err error
 	return
 }
 
-// GetSpecialDetailUserPower 处理用户查看专项调研详情的权限
+// GetSpecialDetailUserPower 处理用户查看详情的权限
 func GetActivityDetailUserPower(user *models.WxUserItem, activityInfo *models.ActivityDetail) (havePower bool, err error) {
 	var companyDetailStatus string
+	var userTypeStr string
+	if user.CompanyId == utils.HZ_COMPANY_ID || activityInfo.ChartPermissionName == utils.HONG_GUAN_NAME {
+		havePower = true
+		return
+	}
 	userType, permissionStr, e := GetUserType(user.CompanyId)
 	if e != nil {
 		err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
 		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
+			}
+		}
+	}
+	//判断管理规模是否满足
+	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 {
@@ -797,22 +864,55 @@ func GetActivityDetailUserPower(user *models.WxUserItem, activityInfo *models.Ac
 	} else if (activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 4 || activityInfo.ActivityTypeId == 5) && strings.Contains(permissionStr, "专家") {
 		havePower = true
 	}
+	if (strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略") && strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
+		havePower = true
+		return
+	}
 	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 (strings.Contains(activityInfo.ChartPermissionName, "研选") || activityInfo.ChartPermissionName == "策略") && strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
-		havePower = true
+	//如果主客观校验不通过,那么直接返回
+	if !havePower {
+		return
 	}
+
 	//如果是易董的活动且属于研选类型,只要开通任何权限就可以查看详情
 	if activityInfo.YidongActivityId != "" && permissionStr != "" && strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
 		havePower = true
 	}
+
+	permissionShengji, errs := models.GetCompanyPermissionByUserTrip(user.CompanyId)
+	if errs != nil {
+		err = errs
+		return
+	}
+	//if strings.Contains(permissionShengji, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
+	//	havePower = true
+	//}
+	//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)
@@ -833,21 +933,33 @@ func GetShareNoPowe(activityInfo *models.ActivityDetail, permissionStr string, u
 	if user.CompanyId == utils.HZ_COMPANY_ID {
 		return
 	}
-	if (userType == 1 || userType == 4 || userType == 5) && !strings.Contains(activityInfo.CustomerTypeIds, strconv.Itoa(userType)) {
-		noPower = true
-	}
+	//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 == 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)

+ 11 - 4
services/activity_button.go

@@ -225,17 +225,24 @@ func HandleActivityListButton(list []*models.ActivityDetail, user *models.WxUser
 			list[k].ActivityTypeName = "买方研选电话会"
 			list[k].ImgUrlText = utils.YAN_XUAN_IMG
 		}
-		if v.ActivityType == 0 {
-			if mapAddress[v.City] != "" {
-				list[k].ImgUrl = mapAddress[v.City]
+		if v.SourceType == 1 {
+			if v.ActivityType == 0 {
+				if mapAddress[v.City] != "" {
+					list[k].ImgUrl = mapAddress[v.City]
+				} else {
+					list[k].ImgUrl = mapAddress["其它"]
+				}
 			} else {
-				list[k].ImgUrl = mapAddress["其它"]
+				if mapChart[v.ChartPermissionName] != "" {
+					list[k].ImgUrl = mapChart[v.ChartPermissionName]
+				}
 			}
 		} else {
 			if mapChart[v.ChartPermissionName] != "" {
 				list[k].ImgUrl = mapChart[v.ChartPermissionName]
 			}
 		}
+
 		expertTxt, _ := GetReportContentTextSub(v.Expert)
 		list[k].Expert = expertTxt
 		if v.IsHideAppointment == 0 {

+ 283 - 75
services/activity_special.go

@@ -67,6 +67,10 @@ func ActivityLabelSpecialSql(chartPermissionIds, whichDay, activeState string) (
 		condition += ` AND art.days > 0  AND art.activity_time_end <= ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
 	}
 
+	//if activeState != "3" {
+	//	condition += `  AND art.activity_time_end  > ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
+	//}
+
 	//if activeState == "" && whichDay == "" {
 	//	condition += ` AND art.activity_time_end > ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
 	//}
@@ -77,34 +81,76 @@ func ActivityLabelSpecialSql(chartPermissionIds, whichDay, activeState string) (
 	condition += `  AND art.label != ''  AND art.is_offline = 0   `
 
 	if activeState == "1" {
-		//conditionor := " OR  ( art.days = 0 " + condition + " )  "
-		conditionor := ""
-		condition = condition + ` AND ( art.days > 0    AND art.activity_time_end > ` + "'" + time.Now().Format(utils.FormatDateTime) + " ' OR  ( art.days = 0 ) )" + conditionor
+		condition = condition + ` AND art.days > 0    AND art.activity_time_end > ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
 	}
 
 	return
 }
 
-// 处理专项调研的展示
-func GetActivityLabelSpecialList(user *models.WxUserItem, conditionActivitySpecial string) (item *models.ActivityTypeHome, err error) {
-	itemList := new(models.ActivityTypeHome)
-	if user.CompanyId <= 1 {
-		itemList.List = make([]*models.CygxActivityLabelList, 0)
-		item = itemList
+// ActivityLabelSpecialUserSql 专项产业调研用户权限查询数据预处理
+func ActivityLabelSpecialUserSql(user *models.WxUserItem) (conditionShengji, conditionZhengshi, conditionHangYe string, err error) {
+	_, userType, e := HandleActivityLabelSpecialTripPermission(user)
+	if e != nil {
+		err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
 		return
 	}
-	userType, e := GetSpecialUserType(user)
-	if e != nil {
-		err = errors.New("GetSpecialUserType, Err: " + e.Error())
+	// 8: 行业升级套餐客户:该活动对应行业为升级权限的客户
+	permissionShengji, errs := models.GetCompanyPermissionByUserZhengShiTrip(user.CompanyId)
+	if errs != nil {
+		err = errs
 		return
 	}
-	if userType == 0 {
+	if permissionShengji != "" {
+		slicePerShengji := strings.Split(permissionShengji, ",")
+		permissionShengji = ""
+		for _, v := range slicePerShengji {
+			permissionShengji += "'" + v + "',"
+		}
+		permissionShengji = strings.TrimRight(permissionShengji, ",")
+		conditionShengji = ` art.customer_type_ids LIKE '%8%' AND art.chart_permission_name  IN (` + permissionShengji + `)`
+	}
+	//9:其他行业正式客户:前述所有正式客户以外的正式客户 查询处理
+	permissionZhengShiStr, errs := models.GetCompanyPermissionByUserZhengShi(user.CompanyId)
+	if errs != nil {
+		err = errs
+		return
+	}
+	if permissionZhengShiStr != "" {
+		slicePerZhengshi := strings.Split(permissionZhengShiStr, ",")
+		permissionZhengShiStr = ""
+		for _, v := range slicePerZhengshi {
+			if userType == 1 {
+				//研选权限处理(永续客户无法查看研选)
+				if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
+					permissionZhengShiStr += "'" + v + "',"
+				}
+			} else {
+				permissionZhengShiStr += "'" + v + "',"
+			}
+		}
+		permissionZhengShiStr = strings.Replace(permissionZhengShiStr, "(主观)", "", -1)
+		permissionZhengShiStr = strings.Replace(permissionZhengShiStr, "(客观)", "", -1)
+		permissionZhengShiStr = strings.TrimRight(permissionZhengShiStr, ",")
+		permissionZhengShiStr += `, '宏观'`
+		if userType != 1 && userType != 2 && userType != 10 {
+			conditionHangYe = `  art.customer_type_ids LIKE '%3%'	   AND art.chart_permission_name    IN (` + permissionZhengShiStr + `)`
+		}
+		if userType == 3 {
+			conditionZhengshi = `  art.customer_type_ids LIKE '%9%'	   AND art.chart_permission_name  NOT  IN (` + permissionZhengShiStr + `)`
+		}
+	}
+	return
+}
+
+// 处理专项调研的展示
+func GetActivityLabelSpecialList(user *models.WxUserItem, conditionActivitySpecial string) (item *models.ActivityTypeHome, err error) {
+	itemList := new(models.ActivityTypeHome)
+	if user.CompanyId <= 1 {
 		itemList.List = make([]*models.CygxActivityLabelList, 0)
 		item = itemList
 		return
 	}
 	companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
-	fmt.Println(e)
 	if e != nil && e.Error() != utils.ErrNoRow() {
 		err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
 		return
@@ -114,14 +160,16 @@ func GetActivityLabelSpecialList(user *models.WxUserItem, conditionActivitySpeci
 	}
 	//如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
 	var condition string
+	var conditionUser string
+	//var userType int
 	if companyDetail.Status == "永续" {
-		condition, e = HandleActivityLabelSpecialPermission(user)
+		conditionUser, e = HandleActivityLabelSpecialPermission(user)
 		if e != nil {
 			err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
 			return
 		}
 	} else {
-		condition, e = HandleActivityLabelSpecialTripPermission(user)
+		conditionUser, _, e = HandleActivityLabelSpecialTripPermission(user)
 		if e != nil {
 			err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
 			return
@@ -129,31 +177,82 @@ func GetActivityLabelSpecialList(user *models.WxUserItem, conditionActivitySpeci
 	}
 	var pars []interface{}
 	condition += ` AND art.publish_status = 1  AND art.label != ''  AND art.is_offline = 0 ` + conditionActivitySpecial
-
-	////行业名称
-	//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)
+	conditionTripSql := condition
+	conditionNoTrip := condition
+	conditionNoTripSql := condition
+	//condition += conditionUser
+	conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
+	if e != nil {
+		err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
+		return
+	}
+	conditionTrip += ` AND art.days > 0   AND art.activity_time_end  > '` + time.Now().Format(utils.FormatDateTime) + ` '`
+
+	var conditionZhengshiTrip string
+	var conditionShengjiTrip string
+	var conditionHangYeTrip string
+
+	//处理专项调研确认行程的其它正式客户权限查询
+	if conditionZhengshi != "" {
+		conditionZhengshiTrip = ` OR ( ` + conditionZhengshi + conditionTrip + ` )`
+	}
+	//处理升级权限查询
+	if conditionShengji != "" {
+		conditionShengjiTrip = ` OR ( ` + conditionShengji + conditionTrip + ` )`
+	}
+	//处理行业套餐客户权限查询
+	if conditionHangYe != "" {
+		conditionHangYeTrip = ` OR ( ` + conditionHangYe + conditionTrip + ` )`
+	}
+	if conditionZhengshi != "" {
+		conditionTrip += conditionZhengshiTrip
+	}
+	if conditionShengjiTrip != "" {
+		conditionTrip += conditionShengjiTrip
+	}
+	if conditionHangYeTrip != "" {
+		conditionTrip += conditionHangYeTrip
+	}
+
+	conditionTripSql += conditionUser + conditionTrip + `  ORDER BY art.activity_time ASC `
+	specialList, err := models.GetActivityLabelSpecialListAll(conditionTripSql, pars, 0, 80)
 	if err != nil {
 		return
 	}
-	if len(specialList) < 8 {
-		condition += ` AND art.days = 0  ORDER BY art.last_updated_time DESC`
-		specialListNotrip, e := models.GetActivityLabelSpecialListAll(condition, pars, 0, 20)
-		if e != nil {
-			err = e
-			return
-		}
-		for _, v := range specialListNotrip {
-			specialList = append(specialList, v)
-		}
+	//if len(specialList) < 80 {
+	conditionNoTrip += ` AND art.days = 0  `
+	var conditionShengjiNoTrip string
+	var conditionZhengshiNoTrip string
+	var conditionHangYeNoTrip string
+	if conditionShengji != "" {
+		conditionShengjiNoTrip = ` OR ( ` + conditionShengji + conditionNoTrip + ` )`
+	}
+	if conditionZhengshi != "" {
+		conditionZhengshiNoTrip = ` OR ( ` + conditionZhengshi + conditionNoTrip + ` )`
+	}
+	if conditionHangYe != "" {
+		conditionHangYeNoTrip = ` OR ( ` + conditionHangYe + conditionNoTrip + ` )`
+	}
+	if conditionShengji != "" {
+		conditionNoTrip += conditionShengjiNoTrip
 	}
+	if conditionZhengshi != "" {
+		conditionNoTrip += conditionZhengshiNoTrip
+	}
+	if conditionHangYe != "" {
+		conditionNoTrip += conditionHangYeNoTrip
+	}
+	conditionNoTripSql += conditionUser + conditionNoTrip + ` ORDER BY art.last_updated_time DESC`
+	specialListNotrip, e := models.GetActivityLabelSpecialListAll(conditionNoTripSql, pars, 0, 200)
+	if e != nil {
+		err = e
+		return
+	}
+	for _, v := range specialListNotrip {
+		specialList = append(specialList, v)
+	}
+	//}
 	for k2, v2 := range specialList {
 		v2.Resource = 2
 		if v2.Days == 0 {
@@ -200,25 +299,35 @@ func HandleActivityLabelSpecialPermission(user *models.WxUserItem) (condition st
 	}
 	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 + `) `
-	}
+	//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) {
+// HandleActivityLabelSpecialPermisseion 处理专项产业调研的查询权限sql
+func HandleActivityLabelSpecialTripPermission(user *models.WxUserItem) (condition string, userType int, err error) {
 	permissionStr, e := GetCompanyPermission(user.CompanyId)
 	if e != nil {
 		err = errors.New("GetCompanyPermission, Err: " + e.Error())
 		return
 	}
-	userType, e := GetSpecialUserType(user)
+	userType, _, e = GetUserType(user.CompanyId)
+	//userType, e := GetSpecialUserType(user)
 	if e != nil {
 		err = errors.New("GetSpecialUserType, Err: " + e.Error())
 		return
 	}
+	mapUserType, e := GetActivityCcustomerTypeList()
+	if e != nil {
+		err = e
+		return
+	}
+	var userTypeStr string
+	userTypeStr = mapUserType[userType]
+	//fmt.Println(userType)
 	slicePer := strings.Split(permissionStr, ",")
 	var permissionSqlStr string
 	for _, v := range slicePer {
@@ -232,10 +341,13 @@ func HandleActivityLabelSpecialTripPermission(user *models.WxUserItem) (conditio
 	}
 	permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
 	condition = ` AND art.publish_status = 1  AND art.label != ''  AND art.is_offline = 0  `
-	if permissionSqlStr != "" {
+	if permissionSqlStr != "" && userType == 3 {
 		condition += ` AND art.chart_permission_name  IN (` + permissionSqlStr + `) `
 	}
-	condition += ` AND  art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
+	condition += ` AND  art.customer_type_ids LIKE '%` + userTypeStr + `%' `
+
+	//if userType != 2 {
+
 	return
 }
 
@@ -251,14 +363,15 @@ func GetActivitySpecialPrepareList(user *models.WxUserItem, startSize, pageSize
 	}
 	//如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
 	var condition string
+	var conditionUser string
 	if companyDetail.Status == "永续" {
-		condition, e = HandleActivityLabelSpecialPermission(user)
+		conditionUser, e = HandleActivityLabelSpecialPermission(user)
 		if e != nil {
 			err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
 			return
 		}
 	} else {
-		condition, e = HandleActivityLabelSpecialTripPermission(user)
+		conditionUser, _, e = HandleActivityLabelSpecialTripPermission(user)
 		if e != nil {
 			err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
 			return
@@ -268,16 +381,45 @@ func GetActivitySpecialPrepareList(user *models.WxUserItem, startSize, pageSize
 	condition += ` AND art.days = 0  AND art.publish_status = 1 AND art.is_offline = 0   ` + conditionActivity
 	if keywords != "" {
 		keywords = "%" + keywords + "%"
-		condition += ` AND art.research_theme LIKE ? `
-		pars = append(pars, keywords)
+		condition += ` AND art.research_theme LIKE  ` + keywords
 	}
-	totalPrepare, e = models.GetActivitySpecialCount(condition, pars)
+	conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
+	if e != nil {
+		err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
+		return
+	}
+	conditionNoTrip := condition
+	var conditionShengjiNoTrip string
+	var conditionZhengshiNoTrip string
+	var conditionHangYeNoTrip string
+	if conditionShengji != "" {
+		conditionShengjiNoTrip = ` OR ( ` + conditionShengji + conditionNoTrip + ` )`
+	}
+	if conditionZhengshi != "" {
+		conditionZhengshiNoTrip = ` OR ( ` + conditionZhengshi + conditionNoTrip + ` )`
+	}
+	//处理行业套餐权限查询
+	if conditionHangYe != "" {
+		conditionHangYeNoTrip = ` OR ( ` + conditionHangYe + conditionNoTrip + ` )`
+	}
+
+	if conditionShengji != "" {
+		conditionNoTrip += conditionShengjiNoTrip
+	}
+	if conditionZhengshi != "" {
+		conditionNoTrip += conditionZhengshiNoTrip
+	}
+	if conditionHangYe != "" {
+		conditionNoTrip += conditionHangYeNoTrip
+	}
+	conditionNoTripSql := conditionUser + conditionNoTrip
+	totalPrepare, e = models.GetActivitySpecialCount(conditionNoTripSql, 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)
+	conditionNoTripSql += `  ORDER BY art.last_updated_time DESC `
+	list, e = models.GetCygxActivitySpecialDetailList(conditionNoTripSql, pars, user.UserId, startSize, pageSize)
 	if e != nil {
 		err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
 		return
@@ -302,14 +444,16 @@ func GetActivityLabelSpecialConfirmList(user *models.WxUserItem, startSize, page
 
 	//如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
 	var condition string
+	var conditionUser string
+	//var userType int
 	if companyDetail.Status == "永续" {
-		condition, e = HandleActivityLabelSpecialPermission(user)
+		conditionUser, e = HandleActivityLabelSpecialPermission(user)
 		if e != nil {
 			err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
 			return
 		}
 	} else {
-		condition, e = HandleActivityLabelSpecialTripPermission(user)
+		conditionUser, _, e = HandleActivityLabelSpecialTripPermission(user)
 		if e != nil {
 			err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
 			return
@@ -318,35 +462,70 @@ func GetActivityLabelSpecialConfirmList(user *models.WxUserItem, startSize, page
 	var pars []interface{}
 	condition += ` AND art.days >0  AND art.publish_status =1   AND art.is_offline = 0  ` + conditionActivity
 	if state == 1 {
-		condition += ` AND art.activity_time > ? `
-		pars = append(pars, time.Now())
+		condition += ` AND art.activity_time >  '` + time.Now().Format(utils.FormatDateTime) + `'`
 	}
 	if state == 2 {
-		condition += ` AND art.activity_time < ? `
-		pars = append(pars, time.Now())
-		condition += ` AND art.activity_time_end > ? `
-		pars = append(pars, time.Now())
+		condition += ` AND art.activity_time < '` + time.Now().Format(utils.FormatDateTime) + `'`
+		condition += ` AND art.activity_time_end > '` + time.Now().Format(utils.FormatDateTime) + `'`
 	}
 	if state == 3 {
-		condition += ` AND art.activity_time_end < ? `
-		pars = append(pars, time.Now())
+		condition += ` AND art.activity_time_end < '` + time.Now().Format(utils.FormatDateTime) + `'`
 	}
 	if state == 4 {
-		condition += ` AND art.activity_time_end > ? `
-		pars = append(pars, time.Now())
+		condition += ` AND art.activity_time_end > '` + time.Now().Format(utils.FormatDateTime) + `'`
 	}
 	if keywords != "" {
 		keywords = "%" + keywords + "%"
-		condition += ` AND art.research_theme LIKE ? `
-		pars = append(pars, keywords)
+		condition += ` AND art.research_theme LIKE  ` + keywords
+	}
+	//condition += ` AND art.publish_status = 1  AND art.label != ''  AND art.is_offline = 0 ` + conditionActivitySpecial
+	conditionTrip := condition
+	conditionTripSql := condition
+
+	//condition += conditionUser
+	conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
+	if e != nil {
+		err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
+		return
+	}
+	conditionTrip += ` AND art.days > 0   AND art.activity_time_end  > '` + time.Now().Format(utils.FormatDateTime) + ` '`
+
+	var conditionZhengshiTrip string
+	var conditionShengjiTrip string
+	var conditionHangYeTrip string
+
+	//处理专项调研确认行程的其它正式客户权限查询
+	if conditionZhengshi != "" {
+		conditionZhengshiTrip = ` OR ( ` + conditionZhengshi + conditionTrip + ` )`
+	}
+	//处理专项调研确认行程的升级权限查询
+	if conditionShengji != "" {
+		conditionShengjiTrip = ` OR ( ` + conditionShengji + conditionTrip + ` )`
+	}
+	//处理行业套餐客户权限查询
+	if conditionHangYe != "" {
+		conditionHangYeTrip = ` OR ( ` + conditionHangYe + conditionTrip + ` )`
+	}
+
+	if conditionZhengshi != "" {
+		conditionTrip += conditionZhengshiTrip
+	}
+	if conditionShengjiTrip != "" {
+		conditionTrip += conditionShengjiTrip
+	}
+	if conditionHangYeTrip != "" {
+		conditionTrip += conditionHangYeTrip
 	}
-	totalConfirm, e = models.GetActivitySpecialCount(condition, pars)
+	conditionTripSql += conditionUser + conditionTrip + `  ORDER BY art.activity_time ASC `
+
+	//condition += conditionUser + conditionOr
+	totalConfirm, e = models.GetActivitySpecialCount(conditionTripSql, 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)
+	list, e = models.GetCygxActivitySpecialDetailList(conditionTripSql, pars, user.UserId, startSize, pageSize)
 	if e != nil {
 		err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
 		return
@@ -735,29 +914,49 @@ func GetSpecialUserType(user *models.WxUserItem) (userType int, err error) {
 
 // GetSpecialDetailUserPower 处理用户查看专项调研详情的权限
 func GetSpecialDetailUserPower(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (havePower bool, err error) {
-	permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
+	if user.CompanyId == utils.HZ_COMPANY_ID {
+		havePower = true
+		return
+	}
+	userType, _, e := GetUserType(user.CompanyId)
 	if e != nil {
-		err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
+		err = errors.New("GetSpecialUserType, Err: " + e.Error())
 		return
 	}
-	fmt.Println(permissionStr)
-	//如果没有对应的升级权限,则返回
-	if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
+	if userType == 0 {
 		return
 	}
-	userType, e := GetSpecialUserType(user)
+	mapUserType, e := GetActivityCcustomerTypeList()
 	if e != nil {
-		err = errors.New("GetSpecialUserType, Err: " + e.Error())
+		err = e
 		return
 	}
-	if userType == 0 {
+	var userTypeStr string
+	userTypeStr = mapUserType[userType]
+	// 永续客户、大套餐客户可以查看行业升级套餐客户 权限
+	if userTypeStr == "1" || userTypeStr == "2" {
+		if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) || strings.Contains(activityInfo.CustomerTypeIds, "8") {
+			havePower = true
+			return
+		}
+	}
+
+	permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
+	if e != nil {
+		err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
 		return
 	}
+	//如果没有对应的升级权限,则返回
+	if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
+		return
+	}
+	//userType, e := GetSpecialUserType(user)
+
 	var pars []interface{}
 	var condition string
 	var userTypes string
 	condition += `  AND art.publish_status = 1 AND art.is_offline = 0   `
-	userTypes = "%" + strconv.Itoa(userType) + "%"
+	userTypes = "%" + userTypeStr + "%"
 	condition += ` AND art.customer_type_ids LIKE ? `
 	pars = append(pars, userTypes)
 
@@ -771,6 +970,15 @@ func GetSpecialDetailUserPower(user *models.WxUserItem, activityInfo *models.Cyg
 	}
 	if total == 1 {
 		havePower = true
+		return
+	}
+	fmt.Println(userType)
+	fmt.Println(permissionStr)
+	fmt.Println(activityInfo.ChartPermissionName)
+	fmt.Println(activityInfo.CustomerTypeIds)
+	if strings.Contains(permissionStr, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
+		havePower = true
+		return
 	}
 	return
 }

+ 104 - 17
services/activity_special_trip.go

@@ -2,8 +2,10 @@ package services
 
 import (
 	"errors"
+	"fmt"
 	"hongze/hongze_clpt/models"
 	"hongze/hongze_clpt/utils"
+	"strconv"
 	"time"
 )
 
@@ -49,14 +51,17 @@ func SpecialTripPopupMsg(activityInfo *models.CygxActivitySpecialDetail, user *m
 	return
 }
 
-//获取用户剩余报名次数
+// 获取用户剩余报名次数
+
+// 获取用户剩余报名次数
 func GetTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (errMsg string, tripRemaining int, err error) {
 
 	//获取 专项调研客户类型   //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户;6、冻结客户;7、流失客户 8:行业升级套餐客户
 	msgTemplate := "您的专项调研次数已用完,如仍想参加,请与您的对口销售商议"
-	var tripTota int
+	//var tripTota int
 	var airborneTota int
-	userType, _, e := GetActivitySpecialUserType(user.CompanyId)
+	//userType, _, e := GetActivitySpecialUserType(user.CompanyId)
+	userType, _, e := GetUserType(user.CompanyId)
 	if e != nil {
 		err = errors.New("获取客户身份信息失败 GetActivitySpecialUserType, Err: " + e.Error())
 		return
@@ -79,20 +84,25 @@ func GetTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *model
 			err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
 			return
 		}
-
-		condition += ` AND is_valid = 1 `
-
-		tripTota, e = models.GetActivitySpecialTripCountByActivitySpecial(condition, pars)
+		//condition += ` AND is_valid = 1 `
+		//查询当年的数据
+		condition += ` AND create_time >= ?  `
+		pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
+		listTripBill, e := models.GetCygxActivitySpecialTripBill(condition, pars)
 		if e != nil {
 			err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
 			return
 		}
-		tripTota += airborneTota
-		if tripTota >= 12 {
+		var TripBillNum int
+		for _, v := range listTripBill {
+			TripBillNum += v.BillDetailed
+		}
+		tripRemaining = 10 - airborneTota + TripBillNum
+		if tripRemaining <= 0 {
 			errMsg = msgTemplate
 			return
 		}
-		tripRemaining = 12 - tripTota
+		//tripRemaining = 12 - tripTota
 	} else {
 		var condition string
 		var pars []interface{}
@@ -108,20 +118,97 @@ func GetTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *model
 			err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
 			return
 		}
-
-		condition += ` AND is_valid = 1 `
-
-		tripTota, e = models.GetActivitySpecialTripCountByActivitySpecial(condition, pars)
+		//查询当年的数据
+		condition += ` AND create_time >= ?  `
+		pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
+		listTripBill, e := models.GetCygxActivitySpecialTripBill(condition, pars)
 		if e != nil {
 			err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
 			return
 		}
-		tripTota += airborneTota
-		if tripTota >= 6 {
+		var TripBillNum int
+		for _, v := range listTripBill {
+			TripBillNum += v.BillDetailed
+		}
+		tripRemaining = 5 - airborneTota + TripBillNum
+		if tripRemaining <= 0 {
 			errMsg = msgTemplate
 			return
 		}
-		tripRemaining = 6 - tripTota
+	}
+	return
+}
+
+// 用户搜专项调研操作操作行为,模板消息推送
+func ActivitySpecialUserRmind(user *models.WxUserItem, activityId, TripStatus 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 {
+		openIdList, e := models.GetWxOpenIdByMobileList(sellerItemQy.Mobile)
+		if e != nil {
+			err = errors.New("GetSellerByAdminId, Err: " + e.Error())
+			return
+		}
+		activityInfo, e := models.GetCygxActivitySpecialDetailById(user.UserId, activityId)
+		if e != nil {
+			err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
+			return
+		}
+		if activityInfo == nil {
+			return
+		}
+		//TripStatus            int    `description:"行程进行状态 1:预报名,2:确定行程"`
+		if TripStatus == 1 {
+			first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:专项调研预报名")
+		} else {
+			first = fmt.Sprint(user.RealName, "--", user.CompanyName, ",有新的互动:活动报名")
+		}
+		keyword1 = activityInfo.ResearchTheme
+		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
 }

+ 15 - 0
services/admin.go

@@ -15,3 +15,18 @@ func GetAdminMobileMap() (mapItem map[string]string, err error) {
 	mapItem = mapMobile
 	return
 }
+
+func GetActivityCcustomerTypeList() (mapItem map[int]string, err error) {
+	list, e := models.GetActivityCcustomerTypeList()
+	if e != nil {
+		err = e
+		return
+	}
+	mapUserType := make(map[int]string)
+	for _, v := range list {
+		mapUserType[v.CustomerTypeId] = v.PermissionValue
+	}
+	mapUserType[0] = "0"
+	mapItem = mapUserType
+	return
+}

+ 16 - 6
services/article.go

@@ -346,6 +346,7 @@ func ArticleAnnotation(item *models.ArticleListResp) (annotation string) {
 		doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
 		docText := doc.Text()
 		mapDoc := make(map[int]string)
+		mapSortRepeat := make(map[string]string)
 		var mapSort []int
 		p := doc.Find("p")
 		p.Each(func(tk int, pd *goquery.Selection) {
@@ -353,8 +354,11 @@ func ArticleAnnotation(item *models.ArticleListResp) (annotation string) {
 			pdText = strings.Replace(pdText, " ", "", -1)
 			if pdText != "" {
 				textLen := strings.Index(docText, pdText)
-				mapDoc[(strings.Index(docText, pdText))] = pdText
-				mapSort = append(mapSort, textLen)
+				if mapSortRepeat[strconv.Itoa(textLen)] == "" {
+					mapDoc[(strings.Index(docText, pdText))] = pdText
+					mapSort = append(mapSort, textLen)
+					mapSortRepeat[strconv.Itoa(textLen)] = strconv.Itoa(textLen)
+				}
 			}
 		})
 		li := doc.Find("li")
@@ -363,8 +367,11 @@ func ArticleAnnotation(item *models.ArticleListResp) (annotation string) {
 			liText = strings.Replace(liText, " ", "", -1)
 			if liText != "" {
 				textLen := strings.Index(docText, liText)
-				mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
-				mapSort = append(mapSort, textLen)
+				if mapSortRepeat[strconv.Itoa(textLen)] == "" {
+					mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
+					mapSort = append(mapSort, textLen)
+					mapSortRepeat[strconv.Itoa(textLen)] = strconv.Itoa(textLen)
+				}
 			}
 		})
 
@@ -374,8 +381,11 @@ func ArticleAnnotation(item *models.ArticleListResp) (annotation string) {
 			ulText = strings.Replace(ulText, " ", "", -1)
 			if ulText != "" {
 				textLen := strings.Index(docText, ulText)
-				mapDoc[(strings.Index(docText, ulText))] = ulText
-				mapSort = append(mapSort, textLen)
+				if mapSortRepeat[strconv.Itoa(textLen)] == "" {
+					mapDoc[(strings.Index(docText, ulText))] = ulText
+					mapSort = append(mapSort, textLen)
+					mapSortRepeat[strconv.Itoa(textLen)] = strconv.Itoa(textLen)
+				}
 			}
 		})
 		if len(mapSort) == 0 {

+ 294 - 1
services/elastic.go

@@ -250,6 +250,10 @@ func EsArticleSearch(keyWord string, startSize, pageSize int, orderColumn string
 		keyWordArr = append(keyWordArr, keyWord)
 		keyWordLen = len(keyWordArr)
 	}
+	//如果没有联想词,而且查询的还是联想词就返回
+	if ikType == 2 && keyWordLen == 1 {
+		return
+	}
 	//Es 的高级查询有 自定义排序 文档一时半会儿撸不懂,先做多次查询手动过滤 2023.2.2
 	//ikType 查询方式 ,0:查所有 、 1:查询键入词 、 2:查询除了查询键入词之外的联想词
 	mustMap := make([]interface{}, 0)
@@ -464,9 +468,286 @@ func EsArticleSearch(keyWord string, startSize, pageSize int, orderColumn string
 				}
 				searchItem := new(models.SearchItem)
 				searchItem.ArticleId, _ = strconv.Atoi(v.Id)
+				if len(v.Highlight["Annotation"]) > 0 {
+					for _, vText := range v.Highlight["Annotation"] {
+						searchItem.Body = append(searchItem.Body, vText)
+					}
+				}
+				if len(v.Highlight["Abstract"]) > 0 {
+					for _, vText := range v.Highlight["Abstract"] {
+						searchItem.Body = append(searchItem.Body, vText)
+					}
+				}
 				if len(v.Highlight["BodyText"]) > 0 {
-					searchItem.Body = v.Highlight["BodyText"]
+					for _, vText := range v.Highlight["BodyText"] {
+						searchItem.Body = append(searchItem.Body, vText)
+					}
+				}
+
+				if len(searchItem.Body) == 0 {
+					bodyRune := []rune(article.BodyText)
+					bodyRuneLen := len(bodyRune)
+					if bodyRuneLen > 100 {
+						bodyRuneLen = 100
+					}
+					body := string(bodyRune[:bodyRuneLen])
+					searchItem.Body = []string{body}
+				}
+
+				//if len(v.Highlight["BodyText"]) > 0 {
+				//	searchItem.Body = v.Highlight["BodyText"]
+				//} else {
+				//	bodyRune := []rune(article.BodyText)
+				//	bodyRuneLen := len(bodyRune)
+				//	if bodyRuneLen > 100 {
+				//		bodyRuneLen = 100
+				//	}
+				//	body := string(bodyRune[:bodyRuneLen])
+				//	searchItem.Body = []string{body}
+				//}
+				var title string
+				if len(v.Highlight["Title"]) > 0 {
+					title = v.Highlight["Title"][0]
 				} else {
+					title = article.Title
+				}
+				searchItem.Title = title
+				searchItem.PublishDate = article.PublishDate
+				searchItem.ExpertBackground = article.ExpertBackground
+				searchItem.CategoryId = article.CategoryId
+				for _, v_result := range result {
+					if v_result.ArticleId == searchItem.ArticleId {
+						isAppend = true
+					}
+				}
+				if !isAppend {
+					result = append(result, searchItem)
+				}
+			}
+		}
+		total = searchByMatch.Hits.TotalHits.Value
+	}
+	return
+}
+
+func EsArticleSearchBody(keyWord string, startSize, pageSize int, orderColumn string, searchType int) (result []*models.SearchItem, total int64, err error) {
+	if keyWord == "" {
+		return
+	}
+	indexName := utils.IndexName
+	client := utils.Client
+
+	//Es 的高级查询有 自定义排序 文档一时半会儿撸不懂,先做多次查询手动过滤 2023.2.2
+	//ikType 查询方式 ,0:查所有 、 1:查询键入词 、 2:查询除了查询键入词之外的联想词
+	mustMap := make([]interface{}, 0)
+	shouldMap := make(map[string]interface{}, 0)
+	shouldMapquery := make([]interface{}, 0)
+
+	mustNotMap := make([]interface{}, 0)
+	shouldNotMap := make(map[string]interface{}, 0)
+	shouldNotMapquery := make([]interface{}, 0)
+	// @Param   OrderColumn   query   int  true       "排序字段 ,Comprehensive综合 ,Matching匹配度 ,PublishDate 发布时间 "
+	//keyWordWeight := GetWeight(keyWordLen)
+	var boost int
+
+	//如果是 2:查询标题,摘要,核心观点的词
+	if searchType == 1 {
+		shouldMapquery = append(shouldMapquery, map[string]interface{}{
+			"function_score": map[string]interface{}{
+				"query": map[string]interface{}{
+					"multi_match": map[string]interface{}{
+						"boost":  boost, //给查询的值赋予权重
+						"fields": []interface{}{"Title"},
+						"query":  keyWord,
+					},
+				},
+			},
+		})
+		shouldMapquery = append(shouldMapquery, map[string]interface{}{
+			"function_score": map[string]interface{}{
+				"query": map[string]interface{}{
+					"multi_match": map[string]interface{}{
+						"boost":  boost, //给查询的值赋予权重
+						"fields": []interface{}{"Abstract"},
+						"query":  keyWord,
+					},
+				},
+			},
+		})
+		shouldMapquery = append(shouldMapquery, map[string]interface{}{
+			"function_score": map[string]interface{}{
+				"query": map[string]interface{}{
+					"multi_match": map[string]interface{}{
+						"boost":  boost, //给查询的值赋予权重
+						"fields": []interface{}{"Annotation"},
+						"query":  keyWord,
+					},
+				},
+			},
+		})
+	}
+
+	//如果是 2:查询body的相关词
+	if searchType == 2 {
+
+		shouldNotMapquery = append(shouldNotMapquery, map[string]interface{}{
+			"function_score": map[string]interface{}{
+				"query": map[string]interface{}{
+					"multi_match": map[string]interface{}{
+						"boost":  boost, //给查询的值赋予权重
+						"fields": []interface{}{"Title"},
+						"query":  keyWord,
+					},
+				},
+			},
+		})
+		shouldNotMapquery = append(shouldNotMapquery, map[string]interface{}{
+			"function_score": map[string]interface{}{
+				"query": map[string]interface{}{
+					"multi_match": map[string]interface{}{
+						"boost":  boost, //给查询的值赋予权重
+						"fields": []interface{}{"Abstract"},
+						"query":  keyWord,
+					},
+				},
+			},
+		})
+		shouldNotMapquery = append(shouldNotMapquery, map[string]interface{}{
+			"function_score": map[string]interface{}{
+				"query": map[string]interface{}{
+					"multi_match": map[string]interface{}{
+						"boost":  boost, //给查询的值赋予权重
+						"fields": []interface{}{"Annotation"},
+						"query":  keyWord,
+					},
+				},
+			},
+		})
+
+		//shouldNotMapquery = append(shouldNotMapquery, map[string]interface{}{
+		//	"function_score": map[string]interface{}{
+		//		"query": map[string]interface{}{
+		//			"multi_match": map[string]interface{}{
+		//				//"boost":  (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
+		//				"boost":  boost, //给查询的值赋予权重
+		//				"fields": []interface{}{"BodyText"},
+		//				"query":  keyWord,
+		//			},
+		//		},
+		//	},
+		//})
+		shouldMapquery = append(shouldMapquery, map[string]interface{}{
+			"function_score": map[string]interface{}{
+				"query": map[string]interface{}{
+					"multi_match": map[string]interface{}{
+						//"boost":  (lenkeyWordArr-k)*boost - 1, //给查询的值赋予权重
+						"boost":  boost, //给查询的值赋予权重
+						"fields": []interface{}{"BodyText"},
+						"query":  keyWord,
+					},
+				},
+			},
+		})
+	}
+
+	shouldMap = map[string]interface{}{
+		"should": shouldMapquery,
+	}
+
+	shouldNotMap = map[string]interface{}{
+		"should": shouldNotMapquery,
+	}
+	//排序
+	sortMap := make([]interface{}, 0)
+
+	//时间
+	sortMap = append(sortMap, map[string]interface{}{
+		"PublishDate": map[string]interface{}{
+			"order": "desc",
+		},
+	})
+	//高亮
+	highlightMap := make(map[string]interface{}, 0)
+	highlightMap = map[string]interface{}{
+		"fields": map[string]interface{}{
+			"BodyText":   map[string]interface{}{},
+			"Title":      map[string]interface{}{},
+			"Abstract":   map[string]interface{}{},
+			"Annotation": map[string]interface{}{},
+		},
+		//样式 红色
+		"post_tags": []interface{}{"</font>"},
+		"pre_tags":  []interface{}{"<font color='red'>"},
+	}
+
+	mustMap = append(mustMap, map[string]interface{}{
+		"bool": shouldMap,
+	})
+	mustNotMap = append(mustNotMap, map[string]interface{}{
+		"bool": shouldNotMap,
+	})
+
+	queryMap := map[string]interface{}{
+		"query": map[string]interface{}{
+			"bool": map[string]interface{}{
+				"must": mustMap,
+			},
+		},
+	}
+	//把第一次的筛选条件过滤掉
+	if searchType == 2 {
+		queryMap = map[string]interface{}{
+			"query": map[string]interface{}{
+				"bool": map[string]interface{}{
+					"must":     mustMap,
+					"must_not": mustNotMap,
+				},
+			},
+		}
+	}
+	if orderColumn == "Matching" {
+		queryMap["sort"] = sortMap
+	}
+	queryMap["from"] = startSize
+	queryMap["size"] = pageSize
+	queryMap["highlight"] = highlightMap
+	jsonBytes, _ := json.Marshal(queryMap)
+	fmt.Println(string(jsonBytes))
+	//utils.FileLog.Info(string(jsonBytes))
+	request := client.Search(indexName).Source(queryMap) // sets the JSON request
+	searchByMatch, err := request.Do(context.Background())
+	if searchByMatch != nil {
+		if searchByMatch.Hits != nil {
+			for _, v := range searchByMatch.Hits.Hits {
+				var isAppend bool
+				articleJson, err := v.Source.MarshalJSON()
+				if err != nil {
+					return nil, 0, err
+				}
+				article := new(models.CygxArticleEs)
+				err = json.Unmarshal(articleJson, &article)
+				if err != nil {
+					return nil, 0, err
+				}
+				searchItem := new(models.SearchItem)
+				searchItem.ArticleId, _ = strconv.Atoi(v.Id)
+				if len(v.Highlight["Annotation"]) > 0 {
+					for _, vText := range v.Highlight["Annotation"] {
+						searchItem.Body = append(searchItem.Body, vText)
+					}
+				}
+				if len(v.Highlight["Abstract"]) > 0 {
+					for _, vText := range v.Highlight["Abstract"] {
+						searchItem.Body = append(searchItem.Body, vText)
+					}
+				}
+				if len(v.Highlight["BodyText"]) > 0 {
+					for _, vText := range v.Highlight["BodyText"] {
+						searchItem.Body = append(searchItem.Body, vText)
+					}
+				}
+
+				if len(searchItem.Body) == 0 {
 					bodyRune := []rune(article.BodyText)
 					bodyRuneLen := len(bodyRune)
 					if bodyRuneLen > 100 {
@@ -475,6 +756,18 @@ func EsArticleSearch(keyWord string, startSize, pageSize int, orderColumn string
 					body := string(bodyRune[:bodyRuneLen])
 					searchItem.Body = []string{body}
 				}
+
+				//if len(v.Highlight["BodyText"]) > 0 {
+				//	searchItem.Body = v.Highlight["BodyText"]
+				//} else {
+				//	bodyRune := []rune(article.BodyText)
+				//	bodyRuneLen := len(bodyRune)
+				//	if bodyRuneLen > 100 {
+				//		bodyRuneLen = 100
+				//	}
+				//	body := string(bodyRune[:bodyRuneLen])
+				//	searchItem.Body = []string{body}
+				//}
 				var title string
 				if len(v.Highlight["Title"]) > 0 {
 					title = v.Highlight["Title"][0]

+ 55 - 25
services/user.go

@@ -11,7 +11,7 @@ import (
 var ERR_NO_USER_RECORD = errors.New("用户关系没有入库")
 var ERR_USER_NOT_BIND = errors.New("用户没有绑定")
 
-//通过用户 关系表记录  和  用户记录  格式化返回 用户数据
+// 通过用户 关系表记录  和  用户记录  格式化返回 用户数据
 func formatWxUserAndUserRecord(wxUser *models.WxUserItem, userRecord *models.UserRecord) {
 	wxUser.OpenId = userRecord.OpenId
 	wxUser.UnionId = userRecord.UnionId
@@ -47,10 +47,9 @@ func GetWxUserItemByOpenId(unionId string) (item *models.WxUserItem, err error)
 	return
 }
 
-//获取 用户类型   //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户;6、冻结客户;7、流失客户
+// 获取 用户类型   //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户;6、冻结客户;7、流失客户
 func GetUserType(companyId int) (userType int, permissionStrnew string, err error) {
-
-	var permissionStr, permissionZhegnshiStr string
+	var permissionStr, permissionZhengShiStr string
 	if companyId <= 1 {
 		userType = 0
 	} else {
@@ -67,47 +66,78 @@ func GetUserType(companyId int) (userType int, permissionStrnew string, err erro
 				err = errs
 				return
 			}
-			permissionStr, errs = models.GetCompanyPermissionByUserNoStatus(companyId)
+			permissionStr, errs = models.GetCompanyPermission(companyId)
 			if errs != nil {
 				err = errs
 				return
 			}
-			permissionZhegnshiStr, errs = models.GetCompanyPermissionByUserZhengShi(companyId)
+			permissionStrnew = permissionStr
+			//大套餐客户,数据库添加标识,
+			companyUserTypeDetail, errs := models.GetCygxCompanyUserType(companyId)
+			if errs != nil && errs.Error() != utils.ErrNoRow() {
+				err = errs
+				return
+			}
+			if companyUserTypeDetail != nil {
+				if companyUserTypeDetail.CustomerTypeId != 0 {
+					userType = companyUserTypeDetail.CustomerTypeId
+					return
+				}
+			}
+			permissionZhengShiStr, errs = models.GetCompanyPermissionByUserZhengShi(companyId)
 			if errs != nil {
 				err = errs
 				return
 			}
-
-			//1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户
+			//1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户、 10: 30W套餐客户
+			//大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
 			if companyDetail.Status == "永续" {
 				userType = 1
 			} else if companyDetail.Status == "试用" {
 				userType = 5
-			} else if companyDetail.Status == "正式" {
-				if permissionStr == "专家" {
-					userType = 4
-				} else if strings.Count(permissionZhegnshiStr, "医药") == 2 && strings.Count(permissionZhegnshiStr, "消费") == 2 && strings.Count(permissionZhegnshiStr, "科技") == 2 && strings.Count(permissionZhegnshiStr, "智造") == 2 {
-					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
 			}
+			//大套餐客户定义:医药、消费、科技、智造、策略。5个行业中任意4个及以上是正式权限的,属于大套餐客户(医药、消费、科技、智造需要主客观都开)
+			if userType == 0 && companyDetail.Status == "正式" {
+				var permissionZhegnshiNum int
+				if strings.Count(permissionZhengShiStr, "医药") == 2 {
+					permissionZhegnshiNum++
+				}
+				if strings.Count(permissionZhengShiStr, "消费") == 2 {
+					permissionZhegnshiNum++
+				}
+				if strings.Count(permissionZhengShiStr, "科技") == 2 {
+					permissionZhegnshiNum++
+				}
+				if strings.Count(permissionZhengShiStr, "智造") == 2 {
+					permissionZhegnshiNum++
+				}
+				if strings.Count(permissionZhengShiStr, "策略") == 1 {
+					permissionZhegnshiNum++
+				}
+				if strings.Count(permissionZhengShiStr, "路演服务") == 1 {
+					permissionZhegnshiNum++
+				}
+				//if permissionZhegnshiNum == 6 {
+				//	userType = 2
+				//} else
+				//大套餐客户,数据库添加标识,条件大于等于四的都是 30W套餐客户
+				if permissionZhegnshiNum >= 4 {
+					userType = 10
+				} else {
+					userType = 3
+				}
+			}
 		}
 	}
 	permissionStrnew = permissionStr
 	return
 }
 
-//用户绑定
+// 用户绑定
 func BindWxUser(mobile, countryCode string) (wxUser *models.WxUserItem, err error) {
 	if mobile == "" {
 		err = errors.New("手机号或邮箱必填一个")
@@ -161,7 +191,7 @@ func BindWxUser(mobile, countryCode string) (wxUser *models.WxUserItem, err erro
 	return
 }
 
-//用户绑定用户手机号以及openid
+// 用户绑定用户手机号以及openid
 func BindWxUserMobileAndOpenid(mobile, openid, countryCode string) (wxUser *models.WxUserItem, err error) {
 	if mobile == "" {
 		err = errors.New("手机号或邮箱必填一个")
@@ -249,7 +279,7 @@ func BindWxUserMobileAndOpenid(mobile, openid, countryCode string) (wxUser *mode
 	return
 }
 
-//添加第三方用户(微信)记录
+// 添加第三方用户(微信)记录
 func AddUserRecord(openId, unionId, nickName, realName, province, city, country, headimgurl, sessionKey string, platform, sex, subscribe int) (userRecord *models.UserRecord, err error) {
 	find, err := models.GetUserRecordByOpenId(openId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
@@ -282,7 +312,7 @@ func AddUserRecord(openId, unionId, nickName, realName, province, city, country,
 	return
 }
 
-//用户绑定
+// 用户绑定
 func BindSession(mobile, countryCode string) (wxUser *models.WxUserItem, err error) {
 	if mobile == "" {
 		err = errors.New("手机号或邮箱必填一个")

+ 1 - 1
services/user_permission.go

@@ -63,7 +63,7 @@ func GetUserRaiPermissionInfo(userId, companyId int) (authInfo models.UserPermis
 	}
 
 	// permissions示例: 医药,消费,科技,智造,策略,专家,买方研选
-	permissions, e := models.GetCompanyPermission(companyId)
+	permissions, e := models.GetCompanyPermissionName(companyId)
 	if e != nil {
 		err = errors.New("获取客户权限失败, Err: " + e.Error())
 		return

+ 3 - 0
utils/config.go

@@ -36,6 +36,7 @@ var (
 	WxMsgTemplateIdAskMsgXzs          string //手机号用户【XXX】发送模板消息模板ID(小助手)
 	IndexName                         string
 	WxMsgTemplateIdAskMsgMobilePublic string //手机号用户【XXX】发送模板消rm --
+	WxMsgTemplateIdArticleUserRemind  string //用户阅读报告通知-模板ID
 
 	ActSendMsgMobile string //活动带问发送模板消息接收者的手机号
 
@@ -100,6 +101,7 @@ func init() {
 		WxMsgTemplateIdApply = "PaoDanHGlt1kFw5q-4_ipJSwO3FyZpxSSNg4rwB7YCk"
 		WxMsgTemplateIdAskMsgMobile = "15557270714,17634786714,18767183922,17516315016"
 		WxMsgTemplateIdAskMsgXzs = "IpS-yuNNQc8osCoy20jPHNkvBUyKRL1NGn7c0G9xmQA" //手机号用户【XXX】发送模板消息模板ID(小助手)
+		WxMsgTemplateIdArticleUserRemind = "7qe3i4MrGxAIPhJeMgoqqw6j0A_foUB65DLSmxKe05s"
 
 		WxOpenAppId = "wx26ccbe242908ed73"                   //公众平台AppId
 		WxOpenAppSecret = "0851cc85027c6eb74a400016648ecda8" //公众平台AppSecret
@@ -114,6 +116,7 @@ func init() {
 		WxMsgTemplateIdApply = "qfNuops-sKrfIkbA7U97A7gSrX03mUpoEpJksRUdloo"
 		WxMsgTemplateIdAskMsgMobile = "15557270714,17634786714,18767183922,17516315016"
 		WxMsgTemplateIdAskMsgXzs = "qfNuops-sKrfIkbA7U97A7gSrX03mUpoEpJksRUdloo" //手机号用户【XXX】发送模板消息模板ID(小助手)
+		WxMsgTemplateIdArticleUserRemind = "CB7bOl7f3viMG4s1uhRo7WM0Jbx3WvodKuIZ8A_z8fM"
 
 		WxOpenAppId = "wx294d2825f451f851"                   //公众平台AppId
 		WxOpenAppSecret = "7bf62d2d037280f8b635c6eca2f31db9" //公众平台AppSecret

+ 4 - 0
utils/constants.go

@@ -12,6 +12,7 @@ const (
 	HlbFormatDateTime      = "2006-01-02_15:04:05.999" //完整时间格式
 	FormatDateTimeNoSecond = "2006-01-02 15:04"        //完整时间格式
 	FormatDateTimeUnSpace  = "20060102150405"          //完整时间格式
+	FormatYearDate         = "2006"                    //日期格式
 	PageSize15             = 15                        //列表页每页数据量
 	PageSize5              = 5
 	PageSize10             = 10
@@ -93,6 +94,9 @@ const (
 	YAN_XUAN_ARTICLE_TYPE_IDS        string = "1,2,12" // 属于研选的报告类型ID
 	REOURCE_YX                       string = "Yx"
 	REOURCE_HZ                       string = "Hz"
+	GU_SHOU_NAME                     string = "固收"
+	HONG_GUAN_NAME                   string = "宏观"
+	GU_SHOU_ID                       int    = 100000 // 自定义权限类型ID ,十万起步
 )
 
 // 模板消息推送类型