Browse Source

Merge branch 'cygx_12.8' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 1 year ago
parent
commit
36d35045d2

+ 2 - 2
controllers/activity.go

@@ -1592,7 +1592,7 @@ func (this *ActivityCoAntroller) AskAdd() {
 			openIpItem, _ := models.GetUserRecordByMobile(4, sendMobile)
 			if openIpItem != nil && openIpItem.OpenId != "" {
 				if sellerItem != nil {
-					services.SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "留言:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), req.Content, activityInfo.ActivityName, openIpItem, activityInfo, int(msgId))
+					services.SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "提问:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), req.Content, activityInfo.ActivityName, openIpItem, activityInfo, int(msgId))
 				}
 			}
 		}
@@ -1600,7 +1600,7 @@ func (this *ActivityCoAntroller) AskAdd() {
 		if sellerItem != nil {
 			openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
 			if openIpItem != nil && openIpItem.OpenId != "" {
-				services.SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "留言:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), req.Content, activityInfo.ActivityName, openIpItem, activityInfo, int(msgId))
+				services.SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "提问:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), req.Content, activityInfo.ActivityName, openIpItem, activityInfo, int(msgId))
 			}
 		}
 	}

+ 33 - 0
models/article_and_yanxuan_record.go

@@ -0,0 +1,33 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxArticleAndYanxuanRecord struct {
+	Id               int       `orm:"column(id);pk"`
+	SourceId         int       `description:"资源ID"`
+	Source           string    `description:"资源I类型  文章、研选专栏"`
+	UserId           int       `description:"用户ID"`
+	CreateTime       string    `description:"创建时间"`
+	Mobile           string    `description:"手机号"`
+	Email            string    `description:"邮箱"`
+	CompanyId        int       `description:"公司id"`
+	CompanyName      string    `description:"公司名称"`
+	ModifyTime       time.Time `description:"修改时间"`
+	RealName         string    `description:"用户实际名称"`
+	SellerName       string    `description:"所属销售"`
+	StopTime         int       `description:"停留时间"`
+	RegisterPlatform int       `description:"来源 1小程序,2:网页"`
+}
+
+// 批量添加
+func AddCygxArticleAndYanxuanRecordMulti(items []*CygxArticleAndYanxuanRecord) (err error) {
+	o := orm.NewOrm()
+	if len(items) > 0 {
+		//批量添加
+		_, err = o.InsertMulti(len(items), items)
+	}
+	return
+}

+ 49 - 0
models/article_history_record_all.go

@@ -0,0 +1,49 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxArticleHistoryRecordAll struct {
+	Id             int `orm:"column(id);pk"`
+	ArticleId      int
+	UserId         int
+	CreateTime     string
+	ModifyTime     time.Time
+	Mobile         string    `description:"手机号"`
+	Email          string    `description:"邮箱"`
+	CompanyId      int       `description:"公司id"`
+	CompanyName    string    `description:"公司名称"`
+	StopTime       int       `description:"停留时间"`
+	OutType        int       `description:"退出方式,1正常退出,2强制关闭"`
+	Source         string    `description:"来源,MOBILE:手机端,PC:电脑端"`
+	RealName       string    `description:"用户实际名称"`
+	CreateDateApi  time.Time `description:"同步创建时间"`
+	CelueHistoryId int       `description:"策略平台记录的ID"`
+	Platfor        int       `description:"PV阅读记录来源,1:查研观向,2:策略平台"`
+	IsDel          int       `description:"是否删除"`
+}
+
+// 获取数量
+func GetCygxArticleHistoryRecordAllCountBycondition(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_article_history_record_all as art WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+// 列表
+func GetCygxArticleHistoryRecordAllList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxArticleHistoryRecordAll, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article_history_record_all as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}

+ 0 - 20
models/article_history_record_newpv.go

@@ -128,26 +128,6 @@ func UpdateCygxArticleViewRecordNewpvList(itemRep *CygxArticleHistoryRecordNewpv
 	return
 }
 
-type CygxArticleHistoryRecordAll struct {
-	Id             int `orm:"column(id);pk"`
-	ArticleId      int
-	UserId         int
-	CreateTime     string
-	ModifyTime     time.Time
-	Mobile         string    `description:"手机号"`
-	Email          string    `description:"邮箱"`
-	CompanyId      int       `description:"公司id"`
-	CompanyName    string    `description:"公司名称"`
-	StopTime       int       `description:"停留时间"`
-	OutType        int       `description:"退出方式,1正常退出,2强制关闭"`
-	Source         string    `description:"来源,MOBILE:手机端,PC:电脑端"`
-	RealName       string    `description:"用户实际名称"`
-	CreateDateApi  time.Time `description:"同步创建时间"`
-	CelueHistoryId int       `description:"策略平台记录的ID"`
-	Platfor        int       `description:"PV阅读记录来源,1:查研观向,2:策略平台"`
-	IsDel          int       `description:"是否删除"`
-}
-
 // 获取当天总表的阅读记录
 func GetArticleHistoryRecordAllList() (items []*CygxArticleHistoryRecordNewpv, err error) {
 	o := orm.NewOrm()

+ 29 - 1
models/cygx_yanxuan_special_record.go

@@ -21,6 +21,22 @@ type CygxYanxuanSpecialRecord struct {
 	StopTime                   int       // 停留时间
 }
 
+type CygxYanxuanSpecialRecordResp struct {
+	CygxYanxuanSpecialRecordId int       `orm:"column(cygx_yanxuan_special_record_id);pk"`
+	UserId                     int       // 用户ID
+	Mobile                     string    // 手机号
+	Email                      string    // 邮箱
+	CompanyId                  int       // 公司ID
+	CompanyName                string    // 公司名称
+	RealName                   string    // 用户实际名称
+	SellerName                 string    // 所属销售
+	CreateTime                 string    // 创建时间
+	ModifyTime                 time.Time // 修改时间
+	RegisterPlatform           int       // 来源 1小程序,2:网页
+	YanxuanSpecialId           int       // cygx_yanxuan_special 表主键ID
+	StopTime                   int       // 停留时间
+}
+
 func AddCygxYanxuanSpecialRecord(item *CygxYanxuanSpecialRecord) (lastId int64, err error) {
 	o := orm.NewOrm()
 	lastId, err = o.Insert(item)
@@ -34,7 +50,7 @@ type AddCygxYanxuanSpecialRecordReq struct {
 
 // 获取数量
 func GetCygxYanxuanSpecialRecordCount(condition string, pars []interface{}) (count int, err error) {
-	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_record as a  WHERE 1= 1  `
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_record as art  WHERE 1= 1  `
 	if condition != "" {
 		sqlCount += condition
 	}
@@ -73,3 +89,15 @@ func AddCygxYanxuanSpecialRecordLog(item *CygxYanxuanSpecialRecordLog) (lastId i
 	lastId, err = o.Insert(item)
 	return
 }
+
+// 列表
+func GetCygxYanxuanSpecialRecordRespList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialRecordResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_yanxuan_special_record as art WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}

+ 1 - 0
models/db.go

@@ -186,6 +186,7 @@ func init() {
 		new(CygxAskserieVideoCollection),
 		new(CygxAskserieVideoCollect),
 		new(CygxVoiceAndVideoHistory),
+		new(CygxArticleAndYanxuanRecord),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 4 - 4
services/activity.go

@@ -1418,14 +1418,14 @@ func SendEmailFileForAskMsgResearch(cont context.Context) (err error) {
 			if sellerItem != nil {
 				openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
 				if openIpItem != nil && openIpItem.OpenId != "" {
-					SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "留言:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo, v2.AskId)
+					SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "提问:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo, v2.AskId)
 				}
 			}
 			//给所属销售推送消息
 			if sellerItem != nil {
 				openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
 				if openIpItem != nil && openIpItem.OpenId != "" {
-					SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "留言:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo, v2.AskId)
+					SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "提问:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo, v2.AskId)
 				}
 			}
 		}
@@ -1508,7 +1508,7 @@ func SendEmailFileForAskMsg(cont context.Context) (err error) {
 				if openIpItem != nil && openIpItem.OpenId != "" {
 					//SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RealName+")", v2.CreateTime, v2.Content, activityInfo.ActivityName, activityInfo.ActivityId, openIpItem)
 					//SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName, "所属销售:"+sellerItem.RealName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo)
-					SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "留言:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo, v2.AskId)
+					SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "提问:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo, v2.AskId)
 				}
 			}
 			//给销售推送模板消息
@@ -1517,7 +1517,7 @@ func SendEmailFileForAskMsg(cont context.Context) (err error) {
 				if openIpItem != nil && openIpItem.OpenId != "" {
 					//SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RealName+")", v2.CreateTime, v2.Content, activityInfo.ActivityName, activityInfo.ActivityId, openIpItem)
 					//SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName, "所属销售:"+sellerItem.RealName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo)
-					SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "留言:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo, v2.AskId)
+					SendActivityAskApplyTemplateMsgV2(user.RealName+"——"+user.CompanyName+"("+sellerItem.RealName+")", "提问:"+activityInfo.ActivityName, time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem, activityInfo, v2.AskId)
 				}
 			}
 		}

+ 125 - 0
services/article_history.go

@@ -1,6 +1,7 @@
 package services
 
 import (
+	"context"
 	"errors"
 	"fmt"
 	"hongze/hongze_cygx/models"
@@ -148,3 +149,127 @@ func ArticleHistoryStopTime(articleId, stopTime, outType int, user *models.WxUse
 	go ArticleHistoryUserLabelLogAdd(articleId, uid)
 	return
 }
+
+//func init() {
+//	AddAllArticleAndYanxuanHistory()
+//}
+
+// 定时任务更新文章和研选专栏记录
+func AddAllArticleAndYanxuanHistory(cont context.Context) (err error) {
+	//func AddAllArticleAndYanxuanHistory() (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("同步阅读记录到es失败;AddAllArticleHistory Err:"+err.Error(), 2)
+		}
+	}()
+
+	var pars []interface{}
+	var condition string
+
+	var companyIds []int
+	condition = " AND  product_id = 2  AND STATUS IN ( '正式', '试用', '冻结' ) "
+	list, e := models.GetCompanyProductList(condition, pars)
+	if e != nil {
+		err = errors.New("GetCompanyProductList, Err: " + e.Error())
+		return
+	}
+
+	for _, v := range list {
+		companyIds = append(companyIds, v.CompanyId)
+	}
+
+	//添加文章记录
+	{
+		condition = ""
+		pars = make([]interface{}, 0)
+		condition = " AND art.company_id IN (" + utils.GetOrmInReplace(len(companyIds)) + ") AND   art.is_del = 0  AND art.create_time >= ?   AND art.create_time <= ?  "
+		pars = append(pars, companyIds, time.Now().AddDate(0, 0, -1).Format(utils.FormatDate), time.Now().Format(utils.FormatDate))
+		total, e := models.GetCygxArticleHistoryRecordAllCountBycondition(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxArticleHistoryRecordAllCount, Err: " + e.Error())
+			return
+		}
+		for i := 0; i <= total/2000; i++ {
+			allList, e := models.GetCygxArticleHistoryRecordAllList(condition, pars, 2000*i, 2000)
+			if e != nil {
+				err = errors.New("GetCygxArticleHistoryRecordAllList, Err: " + e.Error())
+				return
+			}
+			var items []*models.CygxArticleAndYanxuanRecord
+			for _, v := range allList {
+				item := new(models.CygxArticleAndYanxuanRecord)
+				item.SourceId = v.ArticleId
+				item.Source = utils.CYGX_OBJ_ARTICLE
+				item.UserId = v.UserId
+				item.RealName = v.RealName
+				item.Mobile = v.Mobile
+				item.Email = v.Email
+				item.CompanyId = v.CompanyId
+				item.CompanyName = v.CompanyName
+				item.CompanyId = v.CompanyId
+				item.CreateTime = v.CreateTime
+				item.ModifyTime = v.ModifyTime
+				item.StopTime = v.StopTime
+				if v.Source == "CELUE" {
+					item.RegisterPlatform = 3
+				} else if v.Source == "WEB" {
+					item.RegisterPlatform = 2
+				} else {
+					item.RegisterPlatform = 1
+				}
+				items = append(items, item)
+			}
+			e = models.AddCygxArticleAndYanxuanRecordMulti(items)
+			if e != nil {
+				err = errors.New("AddCygxArticleAndYanxuanRecordMulti, Err: " + e.Error())
+				return
+			}
+		}
+	}
+
+	//添加研选专栏记录
+	{
+		condition = ""
+		pars = make([]interface{}, 0)
+		condition = " AND   art.create_time >= ?   AND art.create_time <= ?   AND  user_id > 0 "
+		pars = append(pars, time.Now().AddDate(0, 0, -1).Format(utils.FormatDate), time.Now().Format(utils.FormatDate))
+		totalYanxuanSpecial, e := models.GetCygxYanxuanSpecialRecordCount(condition, pars)
+		if e != nil {
+			err = errors.New("GetCygxYanxuanSpecialRecordCount, Err: " + e.Error())
+			return
+		}
+		for i := 0; i <= totalYanxuanSpecial/2000; i++ {
+			listYanxuanSpecialRecord, e := models.GetCygxYanxuanSpecialRecordRespList(condition, pars, 2000*i, 2000)
+			if e != nil {
+				err = errors.New("GetCygxYanxuanSpecialRecordRespList, Err: " + e.Error())
+				return
+			}
+			var items []*models.CygxArticleAndYanxuanRecord
+			for _, v := range listYanxuanSpecialRecord {
+				item := new(models.CygxArticleAndYanxuanRecord)
+				item.SourceId = v.YanxuanSpecialId
+				item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
+				item.UserId = v.UserId
+				item.RealName = v.RealName
+				item.Mobile = v.Mobile
+				item.Email = v.Email
+				item.CompanyId = v.CompanyId
+				item.CompanyName = v.CompanyName
+				item.CompanyId = v.CompanyId
+				item.CreateTime = v.CreateTime
+				item.ModifyTime = v.ModifyTime
+				item.StopTime = v.StopTime
+				item.RegisterPlatform = v.RegisterPlatform
+				items = append(items, item)
+			}
+			e = models.AddCygxArticleAndYanxuanRecordMulti(items)
+			if e != nil {
+				err = errors.New("AddCygxArticleAndYanxuanRecordMulti, Err: " + e.Error())
+				return
+			}
+		}
+	}
+
+	return
+}

+ 89 - 0
services/init12.8.go

@@ -3,6 +3,7 @@ package services
 import (
 	"fmt"
 	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
 )
 
 func init11() {
@@ -18,3 +19,91 @@ func init11() {
 		UdpateYanxuanSpecialauthorArticleNum(v.UserId)
 	}
 }
+
+func init77() {
+	var condition string
+	var pars []interface{}
+
+	//condition = " AND  is_del = 0 AND company_id > 1 AND article_id IN (SELECT  article_id FROM cygx_article) "
+	//total, err := models.GetCygxArticleHistoryRecordAllCountBycondition(condition, pars)
+	//
+	//if err != nil {
+	//	fmt.Println(err)
+	//	return
+	//}
+	//for i := 0; i <= total/2000; i++ {
+	//	allList, err := models.GetCygxArticleHistoryRecordAllList(condition, pars, 2000*i, 2000)
+	//	if err != nil {
+	//		fmt.Println("GetCygxArticleHistoryRecordByCompanyListNew Err:", err.Error())
+	//
+	//	}
+	//	var items []*models.CygxArticleAndYanxuanRecord
+	//	fmt.Println(len(allList))
+	//	for _, v := range allList {
+	//		item := new(models.CygxArticleAndYanxuanRecord)
+	//		item.SourceId = v.ArticleId
+	//		item.Source = utils.CYGX_OBJ_ARTICLE
+	//		item.UserId = v.UserId
+	//		item.RealName = v.RealName
+	//		item.Mobile = v.Mobile
+	//		item.Email = v.Email
+	//		item.CompanyId = v.CompanyId
+	//		item.CompanyName = v.CompanyName
+	//		item.CompanyId = v.CompanyId
+	//		item.CreateTime = v.CreateTime
+	//		item.ModifyTime = v.ModifyTime
+	//		item.StopTime = v.StopTime
+	//
+	//		if v.Source == "CELUE" {
+	//			item.RegisterPlatform = 3
+	//		} else if v.Source == "WEB" {
+	//			item.RegisterPlatform = 2
+	//		} else {
+	//			item.RegisterPlatform = 1
+	//		}
+	//
+	//		items = append(items, item)
+	//	}
+	//
+	//	err = models.AddCygxArticleAndYanxuanRecordMulti(items)
+	//	if err != nil {
+	//		fmt.Println(err)
+	//	}
+	//
+	//}
+	condition = " AND yanxuan_special_id IN (SELECT  id FROM cygx_yanxuan_special ) "
+	list, err := models.GetCygxYanxuanSpecialRecordRespList(condition, pars, 0, 99999)
+	if err != nil {
+		fmt.Println("GetCygxArticleHistoryRecordByCompanyListNew Err:", err.Error())
+
+	}
+	var items []*models.CygxArticleAndYanxuanRecord
+	fmt.Println(len(list))
+	for _, v := range list {
+		item := new(models.CygxArticleAndYanxuanRecord)
+		item.SourceId = v.YanxuanSpecialId
+		item.Source = utils.CYGX_OBJ_YANXUANSPECIAL
+		item.UserId = v.UserId
+		item.RealName = v.RealName
+		item.Mobile = v.Mobile
+		item.Email = v.Email
+		item.CompanyId = v.CompanyId
+		item.CompanyName = v.CompanyName
+		item.CompanyId = v.CompanyId
+		item.CreateTime = v.CreateTime
+		item.ModifyTime = v.ModifyTime
+		item.StopTime = v.StopTime
+
+		item.RegisterPlatform = v.RegisterPlatform
+
+		items = append(items, item)
+	}
+	fmt.Println(len(items))
+
+	//return
+	err = models.AddCygxArticleAndYanxuanRecordMulti(items)
+	if err != nil {
+		fmt.Println(err)
+	}
+
+}

+ 1 - 1
services/task.go

@@ -84,7 +84,7 @@ func Task() {
 		updateWxUserLabel := task.NewTask("updateWxUserLabel", "0 01 0 * * *", UpdateWxUserLabel) //更新用户的标签
 		task.AddTask("updateWxUserLabel", updateWxUserLabel)
 
-		addAllArticleHistory := task.NewTask("addAllArticleHistory", "0 30 2 * * *", AddAllArticleHistory) //把前一天的用户阅读记录同步到ES
+		addAllArticleHistory := task.NewTask("addAllArticleHistory", "0 30 2 * * *", AddAllArticleAndYanxuanHistory) //把前一天的用户阅读记录同步到ES
 		task.AddTask("addAllArticleHistory", addAllArticleHistory)
 
 		getCeLueArticlePv := task.NewTask("getCeLueArticlePv", "0 */10 * * * *", GetCeLueArticlePv) //通过三方接口获取策略平台上的阅读记录