123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- package models
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_clpt/models/company"
- "hongze/hongze_clpt/utils"
- "strconv"
- "time"
- )
- type CygxArticleHistoryRecordNewpv struct {
- Id int `orm:"column(id);pk"`
- ArticleId int
- UserId int
- CreateTime time.Time
- 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:电脑端"`
- RegisterPlatform int `description:"来源 1小程序,2:网页"`
- }
- type CygxArticleHistoryRecord struct {
- Id int `orm:"column(id);pk"`
- ArticleId int
- UserId int
- CreateTime time.Time
- Mobile string `description:"手机号"`
- Email string `description:"邮箱"`
- CompanyId int `description:"公司id"`
- CompanyName string `description:"公司名称"`
- ModifyTime time.Time `description:"修改时间"`
- StopTime int `description:"停留时间"`
- OutType int `description:"退出方式,1正常退出,2强制关闭"`
- RegisterPlatform int `description:"来源 1小程序,2:网页"`
- }
- // 添加阅读记录信息
- func AddCygxArticleViewRecordNewpv(item *CygxArticleHistoryRecordNewpv) (lastId int64, err error) {
- o, err := orm.NewOrm().Begin()
- if err != nil {
- return
- }
- defer func() {
- fmt.Println(err)
- if err == nil {
- o.Commit()
- } else {
- o.Rollback()
- }
- }()
- userSeller, err := company.GetCompanyProductListByUserId(item.UserId)
- if err != nil {
- return
- }
- lastId, err = o.Insert(item)
- if err != nil {
- return
- }
- historyRecord := new(CygxArticleHistoryRecord)
- historyRecord.UserId = item.UserId
- historyRecord.ArticleId = item.ArticleId
- historyRecord.CreateTime = time.Now()
- historyRecord.Mobile = item.Mobile
- historyRecord.Email = item.Email
- historyRecord.CompanyId = item.CompanyId
- historyRecord.CompanyName = item.CompanyName
- lastId, err = o.Insert(historyRecord)
- if err != nil {
- return
- }
- //写入记录到总的统计表
- record := new(CygxArticleHistoryRecordAll)
- record.UserId = item.UserId
- record.ArticleId = item.ArticleId
- record.CreateTime = item.CreateTime.Format(utils.FormatDateTime)
- record.ModifyTime = item.ModifyTime
- record.Mobile = item.Mobile
- record.Email = item.Email
- record.CompanyId = item.CompanyId
- record.CompanyName = item.CompanyName
- record.StopTime = item.StopTime
- record.OutType = item.OutType
- record.Source = item.Source
- record.CompanyStatus = userSeller.Status
- record.SellerName = userSeller.SellerName
- record.RegisterPlatform = utils.REGISTER_PLATFORM
- record.Platfor = 1
- lastId, err = o.Insert(record)
- if err != nil {
- return
- }
- // 软删除当天策略平台的文章阅读记录
- if item.Mobile != "" {
- sql := `UPDATE cygx_article_history_record_all
- SET is_del = 1
- WHERE
- article_id = ?
- AND mobile = ?
- AND platfor = 2
- AND create_time >= date(NOW()) `
- _, err = o.Raw(sql, record.ArticleId, record.Mobile).Exec()
- }
- 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:"是否删除"`
- RegisterPlatform int `description:"来源 1小程序,2:网页"`
- CompanyStatus string `description:"公司状态"`
- SellerName string `description:"所属销售"`
- }
- type EsUserInteraction struct {
- Id int `description:"主键ID"`
- ArticleId int `description:"文章id"`
- ArticleType int `description:"文章类型 1:查研观向, 2:策略平台"`
- Title string `description:"标题"`
- PublishDate string `description:"发布时间"`
- CreateTime string `description:"创建时间"`
- StopTime string `description:"阅读停留时间"`
- RealName string `description:"姓名"`
- CompanyName string `description:"公司名称"`
- CompanyId int `description:"公司ID"`
- SellerName string `description:"所属销售"`
- SellerId int `description:"所属销售ID"`
- Mobile string `description:"手机号"`
- Email string `description:"邮箱"`
- UserId int `description:"用户ID"`
- UserArticleHistoryNum int `description:"用户阅读数量"`
- CompanyArticleHistoryNum int `description:"机构阅读数量"`
- }
- // GetArticleHistoryRecord 或用户阅读过的文章ID
- func GetArticleHistoryRecord(condition string, pars []interface{}) (item []*CygxArticleHistoryRecord, err error) {
- if condition == "" {
- return
- }
- o := orm.NewOrm()
- sql := `SELECT *
- FROM
- cygx_article_history_record
- WHERE 1 = 1 ` + condition + ` GROUP BY article_id`
- _, err = o.Raw(sql, pars).QueryRows(&item)
- return
- }
- // 把十分钟之内的阅读记录进行累加
- func UpdateCygxArticleViewRecordNewpv(itemRep *CygxArticleHistoryRecordNewpv, stopTime int) (err error) {
- o, err := orm.NewOrm().Begin()
- if err != nil {
- return
- }
- defer func() {
- fmt.Println(err)
- if err == nil {
- o.Commit()
- } else {
- o.Rollback()
- }
- }()
- sql := `UPDATE cygx_article_history_record_newpv
- SET modify_time = NOW(), stop_time = stop_time + ` + strconv.Itoa(stopTime) + `
- WHERE
- article_id = ?
- AND user_id = ?
- AND out_type = 2
- AND timestampdiff(MINUTE,modify_time,NOW()) < 10`
- _, err = o.Raw(sql, itemRep.ArticleId, itemRep.UserId).Exec()
- // 修改总表的停留时间
- sql = `UPDATE cygx_article_history_record_all
- SET modify_time = NOW(), stop_time = stop_time + ` + strconv.Itoa(stopTime) + `
- WHERE
- article_id = ?
- AND user_id = ?
- AND out_type = 2
- AND timestampdiff(MINUTE,modify_time,NOW()) < 10`
- _, err = o.Raw(sql, itemRep.ArticleId, itemRep.UserId).Exec()
- return
- }
- // 列表
- func GetCygxArticleHistoryRecordNewpvList(condition string, pars []interface{}) (items []*CygxArticleHistoryRecordNewpv, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM cygx_article_history_record_newpv as art WHERE 1= 1 `
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- type ListPvUvResp struct {
- ArticleId int `description:"文章ID"`
- Pv int `description:"pv"`
- Uv int `description:"pv"`
- }
- // 列表
- func GetCygxArticleHistoryRecordNewpvListPv(condition string, pars []interface{}) (items []*ListPvUvResp, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- COUNT( 1 ) AS pv,
- article_id
- FROM
- cygx_article_history_record_newpv WHERE 1 = 1 `
- if condition != "" {
- sql += condition
- }
- sql += ` GROUP BY article_id `
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- // 查研PV列表
- func GetCygxArticleHistoryRecordNewpvListPvCy(condition string, pars []interface{}) (items []*ListPvUvResp, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- COUNT( 1 ) AS pv,
- article_id
- FROM
- cygx_article_history_record_all WHERE 1 = 1 AND platfor = 1 `
- if condition != "" {
- sql += condition
- }
- sql += ` GROUP BY article_id `
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- // 策略PV列表
- func GetCygxArticleHistoryRecordNewpvListPvCl(condition string, pars []interface{}) (items []*ListPvUvResp, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- COUNT( 1 ) AS pv,
- article_id
- FROM
- cygx_article_history_record_all WHERE 1 = 1 AND platfor = 2 AND is_del = 0 `
- if condition != "" {
- sql += condition
- }
- sql += ` GROUP BY article_id `
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
|