Browse Source

Merge branch 'crm/crm_16.9_v1' of http://8.136.199.33:3000/hongze/hongze_cygx

zhangchuanxing 4 tuần trước cách đây
mục cha
commit
02685f9602

+ 40 - 0
models/activity_video_history.go

@@ -79,3 +79,43 @@ func GetActivityVideoHistoryByMobileListCRM_16_5Init(condition string) (items []
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+type CygxActivityVideoHistoryResp struct {
+	RecordId         int    `description:"日志ID"`
+	VideoId          int    `description:"微路演音频id"`
+	VideoName        string `description:"文件名称"`
+	UserId           int    `description:"用户ID"`
+	Mobile           string `description:"手机号"`
+	Email            string `description:"邮箱"`
+	CompanyId        int    `description:"公司id"`
+	CompanyName      string `description:"公司名称"`
+	RealName         string `description:"用户实际名称"`
+	CreateTime       string `description:"创建时间"`
+	RegisterPlatform int    `description:"来源 1小程序,2:网页"`
+	ActivityId       int    `description:"活动ID"`
+}
+
+// 列表
+func GetCygxActivityVideoHistoryListNoLimit(condition string, pars []interface{}) (items []*CygxActivityVideoHistoryResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			a.video_name,
+			a.video_id,
+			a.activity_id,
+			b.user_id,
+			b.id as record_id,
+			b.real_name,
+			b.mobile,
+			b.email,
+			b.company_id,
+			b.company_name,
+			b.create_time 
+		FROM
+			cygx_activity_video AS a
+			INNER JOIN cygx_activity_video_history AS b ON a.video_id = b.video_id   WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 40 - 0
models/activity_voice_history.go

@@ -71,3 +71,43 @@ func GetActivityVoiceHistoryByMobileListCRM_16_5Init(condition string) (items []
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+type CygxActivityVoiceHistoryResp struct {
+	ActivityVoiceId  int    `orm:"column(activity_voice_id);pk" description:"活动音频ID"`
+	VoiceName        string `description:"音频名称"`
+	UserId           int    `description:"用户ID"`
+	Mobile           string `description:"手机号"`
+	Email            string `description:"邮箱"`
+	CompanyId        int    `description:"公司id"`
+	CompanyName      string `description:"公司名称"`
+	RealName         string `description:"用户实际名称"`
+	CreateTime       string `description:"创建时间"`
+	ActivityId       int    `description:"活动ID"`
+	RegisterPlatform int    `description:"来源 1小程序,2:网页"`
+	RecordId         int    `description:"日志ID"`
+}
+
+// 列表
+func GetCygxActivityVoiceHistoryListNoLimit(condition string, pars []interface{}) (items []*CygxActivityVoiceHistoryResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			a.voice_name,
+			a.activity_voice_id,
+			a.activity_id,
+			b.user_id,
+			b.id as record_id,
+			b.real_name,
+			b.mobile,
+			b.email,
+			b.company_id,
+			b.company_name,
+			b.create_time 
+		FROM
+			cygx_activity_voice AS a
+			INNER JOIN cygx_activity_voice_history AS b ON a.activity_voice_id = b.activity_voice_id    WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 38 - 0
models/chart_record.go

@@ -24,3 +24,41 @@ func AddCygxChartRecord(item *CygxChartRecord) (lastId int64, err error) {
 	lastId, err = o.Insert(item)
 	return
 }
+
+type CygxChartRecordResp struct {
+	ChartId          int    `description:"图表ID"`
+	Title            string `description:"标题"`
+	UserId           int    `description:"用户ID"`
+	Mobile           string `description:"手机号"`
+	Email            string `description:"邮箱"`
+	CompanyId        int    `description:"公司id"`
+	CompanyName      string `description:"公司名称"`
+	RealName         string `description:"用户实际名称"`
+	CreateTime       string `description:"创建时间"`
+	RegisterPlatform int    `description:"来源 1小程序,2:网页"`
+	RecordId         int    `description:"来源 1小程序,2:网页"`
+}
+
+// 列表
+func GetCygxChartRecordListNoLimit(condition string, pars []interface{}) (items []*CygxChartRecordResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			a.title,
+			a.chart_id,
+			b.record_id,
+			b.user_id,
+			b.real_name,
+			b.mobile,
+			b.email,
+			b.company_id,
+			b.company_name,
+			b.create_time 
+		FROM
+			cygx_chart AS a
+			INNER JOIN cygx_chart_record AS b ON a.chart_id = b.chart_id    WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 38 - 0
models/product_interior_history.go

@@ -65,3 +65,41 @@ func GetCygxProductInteriorHistoryListPv(condition string, pars []interface{}) (
 	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }
+
+type ListProductInteriorResp struct {
+	ProductInteriorId int    `description:"文章ID"`
+	Title             string `description:"标题"`
+	UserId            int    `description:"用户ID"`
+	Mobile            string `description:"手机号"`
+	Email             string `description:"邮箱"`
+	CompanyId         int    `description:"公司id"`
+	CompanyName       string `description:"公司名称"`
+	RealName          string `description:"用户实际名称"`
+	CreateTime        string `description:"创建时间"`
+	RegisterPlatform  int    `description:"来源 1小程序,2:网页"`
+	RecordId          int    `description:"日志ID"`
+}
+
+// 列表
+func GetCygxProductInteriorHistoryListData(condition string, pars []interface{}) (items []*ListProductInteriorResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			a.product_interior_id,
+			a.title,
+			b.user_id,
+			b.id as record_id,
+			b.real_name,
+			b.mobile,
+			b.email,
+			b.company_id,
+			b.company_name,
+			b.create_time 
+		FROM
+			cygx_product_interior AS a
+			INNER JOIN cygx_product_interior_history AS b ON a.product_interior_id = b.product_interior_id   WHERE 1= 1   `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 29 - 0
models/rai_serve/rai_company_user_bill.go

@@ -24,10 +24,14 @@ type CygxRaiCompanyUserBill struct {
 	Source              string    `comment:"来源 "`
 	WeekStartDate       string    `comment:"周一开始日期"`
 	WeekEndDate         string    `comment:"周日结束日期"`
+	MonthStartDate      string    `comment:"月份开始日期"`
+	MonthEndDate        string    `comment:"月份结束日期"`
 	ChartPermissionId   int       `description:"行业id"`
 	ChartPermissionName string    `description:"行业名称"`
 	CreateTime          time.Time `comment:"创建时间"`
 	ViewTime            string    `comment:"浏览时间"`
+	ActivityId          int       `description:"活动ID"`
+	RecordId            int       `description:"日志ID"`
 }
 
 // 列表
@@ -66,3 +70,28 @@ func AddCygxRaiCompanyUserBilllMulti(items []*CygxRaiCompanyUserBill) (err error
 	}
 	return
 }
+
+// UpdateActivitySignupDetailMulti 批量修改
+func UpdateCygxRaiCompanyUserBillMulti(items []*CygxRaiCompanyUserBill) (err error) {
+	o := orm.NewOrm()
+	p, err := o.Raw(` UPDATE cygx_rai_company_user_bill SET 
+							month_start_date = ?,
+							month_end_date = ?
+							WHERE bill_id = ? `).Prepare()
+	if err != nil {
+		return
+	}
+	defer func() {
+		_ = p.Close() // 别忘记关闭 statement
+	}()
+	for _, v := range items {
+		_, err = p.Exec(
+			v.MonthStartDate,
+			v.MonthEndDate,
+			v.BillId)
+		if err != nil {
+			return
+		}
+	}
+	return
+}

+ 29 - 0
models/rai_serve/rai_serve_bill.go

@@ -25,10 +25,14 @@ type CygxRaiServeBill struct {
 	Source              string    `comment:"来源 "`
 	WeekStartDate       string    `comment:"周一开始日期"`
 	WeekEndDate         string    `comment:"周日结束日期"`
+	MonthStartDate      string    `comment:"月份开始日期"`
+	MonthEndDate        string    `comment:"月份结束日期"`
 	ChartPermissionId   int       `description:"行业id"`
 	ChartPermissionName string    `description:"行业名称"`
 	CreateTime          time.Time `comment:"创建时间"`
 	ViewTime            string    `comment:"浏览时间"`
+	ActivityId          int       `description:"活动ID"`
+	RecordId            int       `description:"日志ID"`
 }
 
 // Redis对列消息中的结构体
@@ -105,3 +109,28 @@ func DelCygxRaiServeCompanyMulti(delBillIds []int) (err error) {
 
 	return
 }
+
+// UpdateActivitySignupDetailMulti 批量修改
+func UpdateCygxRaiServeBillMulti(items []*CygxRaiServeBill) (err error) {
+	o := orm.NewOrm()
+	p, err := o.Raw(` UPDATE cygx_rai_serve_bill SET 
+							month_start_date = ?,
+							month_end_date = ?
+							WHERE bill_id = ? `).Prepare()
+	if err != nil {
+		return
+	}
+	defer func() {
+		_ = p.Close() // 别忘记关闭 statement
+	}()
+	for _, v := range items {
+		_, err = p.Exec(
+			v.MonthStartDate,
+			v.MonthEndDate,
+			v.BillId)
+		if err != nil {
+			return
+		}
+	}
+	return
+}

+ 2 - 0
models/rai_serve/rai_serve_week_bill.go

@@ -14,6 +14,8 @@ type CygxRaiServeWeekBill struct {
 	CoverageRate    float64   `comment:"覆盖率"`
 	WeekStartDate   string    `comment:"周一开始日期"`
 	WeekEndDate     string    `comment:"周日结束日期"`
+	MonthStartDate  string    `comment:"月份开始日期"`
+	MonthEndDate    string    `comment:"月份结束日期"`
 	CreateTime      time.Time `comment:"创建时间"`
 	ModifyTime      time.Time `comment:"修改时间"`
 }

+ 36 - 0
models/report_history_record.go

@@ -84,3 +84,39 @@ func GetWxUserRaiCygxReportHistoryRecordCrm16_5() (items []*CygxReportHistoryRec
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+type CygxReportSelectionHistoryRecordResp struct {
+	ArticleId        int    `description:"文章ID"`
+	UserId           int    `description:"用户ID"`
+	Mobile           string `description:"手机号"`
+	Email            string `description:"邮箱"`
+	CompanyId        int    `description:"公司id"`
+	CompanyName      string `description:"公司名称"`
+	RealName         string `description:"用户实际名称"`
+	CreateTime       string `description:"创建时间"`
+	RegisterPlatform int    `description:"来源 1小程序,2:网页"`
+	RecordId         int    `description:"日志ID"`
+}
+
+// 列表
+func GetCygxReportSelectionHistoryRecordRespLimit(condition string, pars []interface{}) (items []*CygxReportSelectionHistoryRecordResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			a.article_id,
+			b.user_id,
+			b.id as record_id,
+			b.real_name,
+			b.mobile,
+			b.email,
+			b.company_id,
+			b.company_name,
+			b.create_time 
+		FROM
+			cygx_report_selection AS a
+			INNER JOIN cygx_report_history_record AS b ON a.article_id = b.article_id   WHERE 1= 1  AND report_type = 'bgjx'  `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 339 - 0
services/rai_company_user_bill.go

@@ -153,6 +153,7 @@ func UpdateCygxRaiCompanyUserBill() (err error) {
 			item.CreateTime = time.Now()
 			item.ViewTime = v.CreateTime
 			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
 			items = append(items, item)
 		}
 	}
@@ -222,6 +223,7 @@ func UpdateCygxRaiCompanyUserBill() (err error) {
 			item.CreateTime = time.Now()
 			item.ViewTime = v.CreateTime
 			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
 
 			if strings.Contains(v.CategoryName, "固收") {
 				item.ChartPermissionName = utils.GU_SHOU_NAME
@@ -312,6 +314,7 @@ func UpdateCygxRaiCompanyUserBill() (err error) {
 			item.ChartPermissionName = v.ChartPermissionName
 			item.ChartPermissionId = v.ChartPermissionId
 			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
 			items = append(items, item)
 		}
 	}
@@ -379,6 +382,7 @@ func UpdateCygxRaiCompanyUserBill() (err error) {
 			item.ChartPermissionName = v.ChartPermissionName
 			item.ChartPermissionId = v.ChartPermissionId
 			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
 			items = append(items, item)
 		}
 	}
@@ -477,6 +481,7 @@ func UpdateCygxRaiCompanyUserBill() (err error) {
 			item.CreateTime = time.Now()
 			item.ViewTime = v.StartDate + " " + v.StartTime
 			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
 
 			if utils.InArrayByStr(guShouResearcherName, item.Content) {
 				item.ChartPermissionName = utils.GU_SHOU_NAME
@@ -550,10 +555,294 @@ func UpdateCygxRaiCompanyUserBill() (err error) {
 			item.CreateTime = time.Now()
 			item.ViewTime = v.CreateTime
 			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
 			items = append(items, item)
 		}
 	}
 	//交流反馈 end
+
+	//图表浏览记录
+	{
+		condition = " AND  b.company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND b.create_time > ?  GROUP BY  b.record_id   "
+		userChartRecordList, e := models.GetCygxChartRecordListNoLimit(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxChartRecordListNoLimit, Err: " + e.Error())
+			return
+		}
+
+		//图表浏览记录明细
+		var conditionBill string
+		var parsBill []interface{}
+		conditionBill = " AND source = 'newchart' AND   company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND view_time > ?  "
+		parsBill = append(parsBill, companyIds, startWeekDate)
+		listBillByChart, e := rai_serve.GetCygxRaiCompanyUserBillListAll(conditionBill, parsBill)
+		if e != nil {
+			err = errors.New("GetCygxRaiServeBillListAll, Err: " + e.Error())
+			return
+		}
+
+		mapChartBill := make(map[string]bool)
+		for _, v := range listBillByChart {
+			mapChartBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] = true
+		}
+
+		for _, v := range userChartRecordList {
+			if mapChartBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] { // 如果内容存在就不插入
+				continue
+			}
+			item := new(rai_serve.CygxRaiCompanyUserBill)
+			item.Content = v.Title
+			item.ServeTypeId = 7
+			item.ServeTypeName = "图表阅读uv"
+			item.UserId = v.UserId
+			item.Mobile = v.Mobile
+			item.Email = v.Email
+			item.CompanyId = v.CompanyId
+			item.CompanyName = v.CompanyName
+			item.RealName = v.RealName
+			item.ServeCount = 0.5
+			if mapUserMaker[v.UserId] {
+				item.IsKp = 1
+				item.ServeCount = item.ServeCount * 3
+			}
+			item.SourceId = v.ChartId
+			item.RecordId = v.RecordId
+			item.Source = utils.CYGX_OBJ_NEWCHART
+			item.CreateTime = time.Now()
+			item.ViewTime = v.CreateTime
+			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
+			items = append(items, item)
+		}
+	}
+	//图表浏览记录 end
+
+	//活动音频记录
+	{
+		condition = " AND  b.company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND b.create_time > ?  GROUP BY  b.id   "
+		userActivityVoiceList, e := models.GetCygxActivityVoiceHistoryListNoLimit(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxActivityVoiceHistoryListNoLimit, Err: " + e.Error())
+			return
+		}
+
+		//活动音频记录 明细
+		var conditionBill string
+		var parsBill []interface{}
+		conditionBill = " AND source = 'activityvoice' AND   company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND view_time > ?  "
+		parsBill = append(parsBill, companyIds, startWeekDate)
+		listBillActivityVoice, e := rai_serve.GetCygxRaiCompanyUserBillListAll(conditionBill, parsBill)
+		if e != nil {
+			err = errors.New("GetCygxRaiServeBillListAll, Err: " + e.Error())
+			return
+		}
+
+		mapActivityVoiceBill := make(map[string]bool)
+		for _, v := range listBillActivityVoice {
+			mapActivityVoiceBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] = true
+		}
+
+		for _, v := range userActivityVoiceList {
+			if mapActivityVoiceBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] { // 如果内容存在就不插入
+				continue
+			}
+			item := new(rai_serve.CygxRaiCompanyUserBill)
+			item.Content = v.VoiceName
+			item.ServeTypeId = 8
+			item.ServeTypeName = "路演回放"
+			item.UserId = v.UserId
+			item.Mobile = v.Mobile
+			item.Email = v.Email
+			item.CompanyId = v.CompanyId
+			item.CompanyName = v.CompanyName
+			item.RealName = v.RealName
+			item.ServeCount = 0.5
+			if mapUserMaker[v.UserId] {
+				item.IsKp = 1
+				item.ServeCount = item.ServeCount * 3
+			}
+			item.SourceId = v.ActivityVoiceId
+			item.RecordId = v.RecordId
+			item.ActivityId = v.ActivityId
+			item.Source = utils.CYGX_OBJ_ACTIVITYVOICE
+			item.CreateTime = time.Now()
+			item.ViewTime = v.CreateTime
+			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
+			items = append(items, item)
+		}
+	}
+	//活动音频记录 end
+
+	//活动视频记录
+	{
+		condition = " AND  b.company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND b.create_time > ?  GROUP BY  b.id   "
+		userActivityVideoList, e := models.GetCygxActivityVideoHistoryListNoLimit(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxChartRecordListNoLimit, Err: " + e.Error())
+			return
+		}
+
+		//活动视频记录 明细
+		var conditionBill string
+		var parsBill []interface{}
+		conditionBill = " AND source = 'activityvideo' AND   company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND view_time > ?  "
+		parsBill = append(parsBill, companyIds, startWeekDate)
+		listBillActivityVideo, e := rai_serve.GetCygxRaiCompanyUserBillListAll(conditionBill, parsBill)
+		if e != nil {
+			err = errors.New("GetCygxRaiServeBillListAll, Err: " + e.Error())
+			return
+		}
+
+		mapActivityVideoBill := make(map[string]bool)
+		for _, v := range listBillActivityVideo {
+			mapActivityVideoBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] = true
+		}
+
+		for _, v := range userActivityVideoList {
+			if mapActivityVideoBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] { // 如果内容存在就不插入
+				continue
+			}
+			item := new(rai_serve.CygxRaiCompanyUserBill)
+			item.Content = v.VideoName
+			item.ServeTypeId = 8
+			item.ServeTypeName = "路演回放"
+			item.UserId = v.UserId
+			item.Mobile = v.Mobile
+			item.Email = v.Email
+			item.CompanyId = v.CompanyId
+			item.CompanyName = v.CompanyName
+			item.RealName = v.RealName
+			item.ServeCount = 0.5
+			if mapUserMaker[v.UserId] {
+				item.IsKp = 1
+				item.ServeCount = item.ServeCount * 3
+			}
+			item.SourceId = v.VideoId
+			item.RecordId = v.RecordId
+			item.ActivityId = v.ActivityId
+			item.Source = utils.CYGX_OBJ_ACTIVITYVIDEO
+			item.CreateTime = time.Now()
+			item.ViewTime = v.CreateTime
+			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
+			items = append(items, item)
+		}
+	}
+	//活动视频记录 end
+
+	//报告精选阅读记录
+	{
+		condition = " AND  b.company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND b.create_time > ?  GROUP BY  b.id   "
+		userReportSelectionList, e := models.GetCygxReportSelectionHistoryRecordRespLimit(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxChartRecordListNoLimit, Err: " + e.Error())
+			return
+		}
+
+		//报告精选阅读记录 明细
+		var conditionBill string
+		var parsBill []interface{}
+		conditionBill = " AND source = 'reportselection' AND   company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND view_time > ?  "
+		parsBill = append(parsBill, companyIds, startWeekDate)
+		listBillReportSelection, e := rai_serve.GetCygxRaiCompanyUserBillListAll(conditionBill, parsBill)
+		if e != nil {
+			err = errors.New("GetCygxRaiServeBillListAll, Err: " + e.Error())
+			return
+		}
+
+		mapReportSelectionBill := make(map[string]bool)
+		for _, v := range listBillReportSelection {
+			mapReportSelectionBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] = true
+		}
+
+		for _, v := range userReportSelectionList {
+			if mapReportSelectionBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] { // 如果内容存在就不插入
+				continue
+			}
+			item := new(rai_serve.CygxRaiCompanyUserBill)
+			item.Content = "重点公司"
+			item.ServeTypeId = 5
+			item.ServeTypeName = "阅读uv"
+			item.UserId = v.UserId
+			item.Mobile = v.Mobile
+			item.Email = v.Email
+			item.CompanyId = v.CompanyId
+			item.CompanyName = v.CompanyName
+			item.RealName = v.RealName
+			item.ServeCount = 0.5
+			if mapUserMaker[v.UserId] {
+				item.IsKp = 1
+				item.ServeCount = item.ServeCount * 3
+			}
+			item.SourceId = v.ArticleId
+			item.RecordId = v.RecordId
+			item.Source = utils.CYGX_OBJ_REPORTSELECTION
+			item.CreateTime = time.Now()
+			item.ViewTime = v.CreateTime
+			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
+			items = append(items, item)
+		}
+	}
+	//报告精选阅读记录 end
+
+	//产品内测阅读记录
+	{
+		condition = " AND  b.company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND b.create_time > ?  GROUP BY  b.id   "
+		userProductInteriorList, e := models.GetCygxProductInteriorHistoryListData(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxChartRecordListNoLimit, Err: " + e.Error())
+			return
+		}
+
+		//产品内测阅读记录 明细
+		var conditionBill string
+		var parsBill []interface{}
+		conditionBill = " AND source = 'productinterior' AND   company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND view_time > ?  "
+		parsBill = append(parsBill, companyIds, startWeekDate)
+		listBillProductInterior, e := rai_serve.GetCygxRaiCompanyUserBillListAll(conditionBill, parsBill)
+		if e != nil {
+			err = errors.New("GetCygxRaiServeBillListAll, Err: " + e.Error())
+			return
+		}
+
+		mapProductInteriorBill := make(map[string]bool)
+		for _, v := range listBillProductInterior {
+			mapProductInteriorBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] = true
+		}
+
+		for _, v := range userProductInteriorList {
+			if mapProductInteriorBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] { // 如果内容存在就不插入
+				continue
+			}
+			item := new(rai_serve.CygxRaiCompanyUserBill)
+			item.Content = v.Title
+			item.ServeTypeId = 5
+			item.ServeTypeName = "阅读uv"
+			item.UserId = v.UserId
+			item.Mobile = v.Mobile
+			item.Email = v.Email
+			item.CompanyId = v.CompanyId
+			item.CompanyName = v.CompanyName
+			item.RealName = v.RealName
+			item.ServeCount = 0.5
+			if mapUserMaker[v.UserId] {
+				item.IsKp = 1
+				item.ServeCount = item.ServeCount * 3
+			}
+			item.SourceId = v.ProductInteriorId
+			item.RecordId = v.RecordId
+			item.Source = utils.CYGX_OBJ_PRODUCTINTERIOR
+			item.CreateTime = time.Now()
+			item.ViewTime = v.CreateTime
+			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
+			items = append(items, item)
+		}
+	}
+	//产品内测阅读记录 end
+
 	//fmt.Println("items", len(items))
 	//return
 	if len(items) > 0 {
@@ -628,3 +917,53 @@ func UpdateCompanyProductIsUserMaker() (err error) {
 	fmt.Println(" UpdateCompanyProductIsUserMaker  end")
 	return
 }
+
+//func init() {
+//	initCRm_16_9_v2()
+//}
+
+func initCRm_16_9() {
+
+	var conditionBill string
+	var parsBill []interface{}
+	conditionBill = " AND  month_start_date = '' LIMIT 10000  "
+	listBillByYanxuanspecial, e := rai_serve.GetCygxRaiCompanyUserBillListAll(conditionBill, parsBill)
+	if e != nil {
+		fmt.Println(e)
+		return
+	}
+
+	for _, v := range listBillByYanxuanspecial {
+		v.MonthStartDate, v.MonthEndDate = utils.GetFirstAndLastDayOfMonth(v.ViewTime)
+	}
+
+	e = rai_serve.UpdateCygxRaiCompanyUserBillMulti(listBillByYanxuanspecial)
+	if e != nil {
+		fmt.Println(e)
+		return
+	}
+	fmt.Println("end")
+}
+
+func initCRm_16_9_v2() {
+
+	var conditionBill string
+	var parsBill []interface{}
+	conditionBill = " AND  month_start_date = '' LIMIT 10000  "
+	listBillByYanxuanspecial, e := rai_serve.GetCygxRaiServeBillListAll(conditionBill, parsBill)
+	if e != nil {
+		fmt.Println(e)
+		return
+	}
+
+	for _, v := range listBillByYanxuanspecial {
+		v.MonthStartDate, v.MonthEndDate = utils.GetFirstAndLastDayOfMonth(v.ViewTime)
+	}
+
+	e = rai_serve.UpdateCygxRaiServeBillMulti(listBillByYanxuanspecial)
+	if e != nil {
+		fmt.Println(e)
+		return
+	}
+	fmt.Println("end")
+}

+ 292 - 2
services/rai_serve_count.go

@@ -424,6 +424,10 @@ type RaiServeBillRedis struct {
 	ViewTime         time.Time `comment:"浏览时间"`
 }
 
+//func init() {
+//	UpdateCygxRaiServeBillByCompanyIds()
+//}
+
 // 批量更新企业服务明细记录
 func UpdateCygxRaiServeBillByCompanyIds() (err error) {
 	defer func() {
@@ -536,6 +540,7 @@ func UpdateCygxRaiServeBillByCompanyIds() (err error) {
 			item.CreateTime = time.Now()
 			item.ViewTime = v.CreateTime
 			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
 			items = append(items, item)
 		}
 	}
@@ -605,7 +610,7 @@ func UpdateCygxRaiServeBillByCompanyIds() (err error) {
 			item.CreateTime = time.Now()
 			item.ViewTime = v.CreateTime
 			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
-
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
 			if strings.Contains(v.CategoryName, "固收") {
 				item.ChartPermissionName = utils.GU_SHOU_NAME
 				item.ChartPermissionId = utils.GU_SHOU_ID_CHART
@@ -696,6 +701,7 @@ func UpdateCygxRaiServeBillByCompanyIds() (err error) {
 			item.ChartPermissionName = v.ChartPermissionName
 			item.ChartPermissionId = v.ChartPermissionId
 			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
 			items = append(items, item)
 		}
 	}
@@ -763,6 +769,7 @@ func UpdateCygxRaiServeBillByCompanyIds() (err error) {
 			item.ChartPermissionName = v.ChartPermissionName
 			item.ChartPermissionId = v.ChartPermissionId
 			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
 			items = append(items, item)
 		}
 	}
@@ -861,7 +868,7 @@ func UpdateCygxRaiServeBillByCompanyIds() (err error) {
 			item.CreateTime = time.Now()
 			item.ViewTime = v.StartDate + " " + v.StartTime
 			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
-
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
 			if utils.InArrayByStr(guShouResearcherName, item.Content) {
 				item.ChartPermissionName = utils.GU_SHOU_NAME
 				item.ChartPermissionId = utils.GU_SHOU_ID_CHART
@@ -934,11 +941,294 @@ func UpdateCygxRaiServeBillByCompanyIds() (err error) {
 			item.CreateTime = time.Now()
 			item.ViewTime = v.CreateTime
 			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
 			items = append(items, item)
 		}
 	}
 	//交流反馈 end
 
+	//图表浏览记录
+	{
+		condition = " AND  b.company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND b.create_time > ?  GROUP BY  b.record_id   "
+		userChartRecordList, e := models.GetCygxChartRecordListNoLimit(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxChartRecordListNoLimit, Err: " + e.Error())
+			return
+		}
+
+		//图表浏览记录明细
+		var conditionBill string
+		var parsBill []interface{}
+		conditionBill = " AND source = 'newchart' AND   company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND view_time > ?  "
+		parsBill = append(parsBill, companyIds, startWeekDate)
+		listBillByChart, e := rai_serve.GetCygxRaiServeBillListAll(conditionBill, parsBill)
+		if e != nil {
+			err = errors.New("GetCygxRaiServeBillListAll, Err: " + e.Error())
+			return
+		}
+
+		mapRscalendarBill := make(map[string]bool)
+		for _, v := range listBillByChart {
+			mapRscalendarBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] = true
+		}
+
+		for _, v := range userChartRecordList {
+			if mapRscalendarBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] { // 如果内容存在就不插入
+				continue
+			}
+			item := new(rai_serve.CygxRaiServeBill)
+			item.Content = v.Title
+			item.ServeTypeId = 7
+			item.ServeTypeName = "图表阅读uv"
+			item.UserId = v.UserId
+			item.Mobile = v.Mobile
+			item.Email = v.Email
+			item.CompanyId = v.CompanyId
+			item.CompanyName = v.CompanyName
+			item.RealName = v.RealName
+			item.ServeCount = 0.5
+			if mapUserMaker[v.UserId] {
+				item.IsKp = 1
+				item.ServeCount = item.ServeCount * 3
+			}
+			item.SourceId = v.ChartId
+			item.RecordId = v.RecordId
+			item.Source = utils.CYGX_OBJ_NEWCHART
+			item.CreateTime = time.Now()
+			item.ViewTime = v.CreateTime
+			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
+			items = append(items, item)
+		}
+	}
+	//图表浏览记录 end
+
+	//活动音频记录
+	{
+		condition = " AND  b.company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND b.create_time > ?  GROUP BY  b.id   "
+		userActivityVoiceList, e := models.GetCygxActivityVoiceHistoryListNoLimit(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxActivityVoiceHistoryListNoLimit, Err: " + e.Error())
+			return
+		}
+
+		//活动音频记录 明细
+		var conditionBill string
+		var parsBill []interface{}
+		conditionBill = " AND source = 'activityvoice' AND   company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND view_time > ?  "
+		parsBill = append(parsBill, companyIds, startWeekDate)
+		listBillActivityVoice, e := rai_serve.GetCygxRaiServeBillListAll(conditionBill, parsBill)
+		if e != nil {
+			err = errors.New("GetCygxRaiServeBillListAll, Err: " + e.Error())
+			return
+		}
+
+		mapActivityVoiceBill := make(map[string]bool)
+		for _, v := range listBillActivityVoice {
+			mapActivityVoiceBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] = true
+		}
+
+		for _, v := range userActivityVoiceList {
+			if mapActivityVoiceBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] { // 如果内容存在就不插入
+				continue
+			}
+			item := new(rai_serve.CygxRaiServeBill)
+			item.Content = v.VoiceName
+			item.ServeTypeId = 8
+			item.ServeTypeName = "路演回放"
+			item.UserId = v.UserId
+			item.Mobile = v.Mobile
+			item.Email = v.Email
+			item.CompanyId = v.CompanyId
+			item.CompanyName = v.CompanyName
+			item.RealName = v.RealName
+			item.ServeCount = 0.5
+			if mapUserMaker[v.UserId] {
+				item.IsKp = 1
+				item.ServeCount = item.ServeCount * 3
+			}
+			item.SourceId = v.ActivityVoiceId
+			item.ActivityId = v.ActivityId
+			item.RecordId = v.RecordId
+			item.Source = utils.CYGX_OBJ_ACTIVITYVOICE
+			item.CreateTime = time.Now()
+			item.ViewTime = v.CreateTime
+			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
+			items = append(items, item)
+		}
+	}
+	//活动音频记录 end
+
+	//活动视频记录
+	{
+		condition = " AND  b.company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND b.create_time > ?  GROUP BY  b.id   "
+		userActivityVideoList, e := models.GetCygxActivityVideoHistoryListNoLimit(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxChartRecordListNoLimit, Err: " + e.Error())
+			return
+		}
+
+		//图表浏览记录明细
+		var conditionBill string
+		var parsBill []interface{}
+		conditionBill = " AND source = 'activityvideo' AND   company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND view_time > ?  "
+		parsBill = append(parsBill, companyIds, startWeekDate)
+		listBillActivityVideo, e := rai_serve.GetCygxRaiServeBillListAll(conditionBill, parsBill)
+		if e != nil {
+			err = errors.New("GetCygxRaiServeBillListAll, Err: " + e.Error())
+			return
+		}
+
+		mapActivityVideoBill := make(map[string]bool)
+		for _, v := range listBillActivityVideo {
+			mapActivityVideoBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] = true
+		}
+
+		for _, v := range userActivityVideoList {
+			if mapActivityVideoBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] { // 如果内容存在就不插入
+				continue
+			}
+			item := new(rai_serve.CygxRaiServeBill)
+			item.Content = v.VideoName
+			item.ServeTypeId = 8
+			item.ServeTypeName = "路演回放"
+			item.UserId = v.UserId
+			item.Mobile = v.Mobile
+			item.Email = v.Email
+			item.CompanyId = v.CompanyId
+			item.CompanyName = v.CompanyName
+			item.RealName = v.RealName
+			item.ServeCount = 0.5
+			if mapUserMaker[v.UserId] {
+				item.IsKp = 1
+				item.ServeCount = item.ServeCount * 3
+			}
+			item.SourceId = v.VideoId
+			item.RecordId = v.RecordId
+			item.ActivityId = v.ActivityId
+			item.Source = utils.CYGX_OBJ_ACTIVITYVIDEO
+			item.CreateTime = time.Now()
+			item.ViewTime = v.CreateTime
+			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
+			items = append(items, item)
+		}
+	}
+	//活动视频记录 end
+
+	//报告精选阅读记录
+	{
+		condition = " AND  b.company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND b.create_time > ?  GROUP BY  b.id   "
+		userReportSelectionList, e := models.GetCygxReportSelectionHistoryRecordRespLimit(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxChartRecordListNoLimit, Err: " + e.Error())
+			return
+		}
+
+		//报告精选阅读记录 明细
+		var conditionBill string
+		var parsBill []interface{}
+		conditionBill = " AND source = 'reportselection' AND   company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND view_time > ?  "
+		parsBill = append(parsBill, companyIds, startWeekDate)
+		listBillReportSelection, e := rai_serve.GetCygxRaiServeBillListAll(conditionBill, parsBill)
+		if e != nil {
+			err = errors.New("GetCygxRaiServeBillListAll, Err: " + e.Error())
+			return
+		}
+
+		mapReportSelectionBill := make(map[string]bool)
+		for _, v := range listBillReportSelection {
+			mapReportSelectionBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] = true
+		}
+
+		for _, v := range userReportSelectionList {
+			if mapReportSelectionBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] { // 如果内容存在就不插入
+				continue
+			}
+			item := new(rai_serve.CygxRaiServeBill)
+			item.Content = "重点公司"
+			item.ServeTypeId = 5
+			item.ServeTypeName = "阅读uv"
+			item.UserId = v.UserId
+			item.Mobile = v.Mobile
+			item.Email = v.Email
+			item.CompanyId = v.CompanyId
+			item.CompanyName = v.CompanyName
+			item.RealName = v.RealName
+			item.ServeCount = 0.5
+			if mapUserMaker[v.UserId] {
+				item.IsKp = 1
+				item.ServeCount = item.ServeCount * 3
+			}
+			item.SourceId = v.ArticleId
+			item.RecordId = v.RecordId
+			item.Source = utils.CYGX_OBJ_REPORTSELECTION
+			item.CreateTime = time.Now()
+			item.ViewTime = v.CreateTime
+			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
+			items = append(items, item)
+		}
+	}
+	//报告精选阅读记录 end
+
+	//产品内测阅读记录
+	{
+		condition = " AND  b.company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND b.create_time > ?  GROUP BY  b.id   "
+		userProductInteriorList, e := models.GetCygxProductInteriorHistoryListData(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxChartRecordListNoLimit, Err: " + e.Error())
+			return
+		}
+
+		//产品内测阅读记录 明细
+		var conditionBill string
+		var parsBill []interface{}
+		conditionBill = " AND source = 'productinterior' AND   company_id IN  (" + utils.GetOrmInReplace(lencompanyId) + ")  AND view_time > ?  "
+		parsBill = append(parsBill, companyIds, startWeekDate)
+		listBillProductInterior, e := rai_serve.GetCygxRaiServeBillListAll(conditionBill, parsBill)
+		if e != nil {
+			err = errors.New("GetCygxRaiServeBillListAll, Err: " + e.Error())
+			return
+		}
+
+		mapProductInteriorBill := make(map[string]bool)
+		for _, v := range listBillProductInterior {
+			mapProductInteriorBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] = true
+		}
+
+		for _, v := range userProductInteriorList {
+			if mapProductInteriorBill[fmt.Sprint("UID_", v.UserId, "SID_", v.RecordId)] { // 如果内容存在就不插入
+				continue
+			}
+			item := new(rai_serve.CygxRaiServeBill)
+			item.Content = v.Title
+			item.ServeTypeId = 5
+			item.ServeTypeName = "阅读uv"
+			item.UserId = v.UserId
+			item.Mobile = v.Mobile
+			item.Email = v.Email
+			item.CompanyId = v.CompanyId
+			item.CompanyName = v.CompanyName
+			item.RealName = v.RealName
+			item.ServeCount = 0.5
+			if mapUserMaker[v.UserId] {
+				item.IsKp = 1
+				item.ServeCount = item.ServeCount * 3
+			}
+			item.SourceId = v.ProductInteriorId
+			item.RecordId = v.RecordId
+			item.Source = utils.CYGX_OBJ_PRODUCTINTERIOR
+			item.CreateTime = time.Now()
+			item.ViewTime = v.CreateTime
+			item.WeekStartDate, item.WeekEndDate = utils.GetMondayAndSundayByTimeString(item.ViewTime)
+			item.MonthStartDate, item.MonthEndDate = utils.GetFirstAndLastDayOfMonth(item.ViewTime)
+			items = append(items, item)
+		}
+	}
+	//产品内测阅读记录 end
+
 	if len(items) > 0 {
 		var itemsAdd []*rai_serve.CygxRaiServeBill
 		for k, v := range items {

+ 12 - 0
utils/common.go

@@ -1037,6 +1037,18 @@ func GetMondayAndSundayByTimeString(timeString string) (monday, sunday string) {
 	return
 }
 
+// 获取当前时间所属月份的第一天,与最后一天
+func GetFirstAndLastDayOfMonth(timeString string) (startDate, endDate string) {
+	t := StrTimeToTime(timeString)
+	// 获取当前月份的第一天
+	firstDay := time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location())
+	// 获取当前月份的最后一天
+	lastDay := firstDay.AddDate(0, 1, -1)
+	startDate = firstDay.Format(FormatDate)
+	endDate = lastDay.Format(FormatDate)
+	return
+}
+
 // HmacSha256 计算HmacSha256
 // key 是加密所使用的key
 // data 是加密的内容