package models import ( "github.com/rdlucklib/rdluck_tools/orm" "time" ) // UserViewStatistics 用户报告报告阅读数量统计表 type UserViewStatistics struct { Id int `orm:"column(id)" description:"自增Id"` Mobile string `description:"手机号"` Email string `description:"手机号"` RealName string `description:"联系人名称"` CompanyName string `description:"客户名称"` ViewNum int `description:"阅读总数"` Date time.Time `description:"阅读日期"` CreateTime time.Time `description:"添加时间"` } // AddMultiUserViewStatistics 添加用户报告报告阅读数量统计记录 func AddMultiUserViewStatistics(list []*UserViewStatistics) (err error) { if len(list) <= 0 { return } o := orm.NewOrm() _, err = o.InsertMulti(len(list), list) return } // GetUserViewStatisticsCount 获取某天的用户报告报告阅读数量统计记录数量 func GetUserViewStatisticsCount(dayStr string) (count int, err error) { o := orm.NewOrm() //产品权限 sql := `SELECT count(1) count FROM user_view_statistics WHERE date = ?` err = o.Raw(sql, dayStr).QueryRow(&count) return } // DeleteUserViewStatisticsCount 获取某天的用户报告报告阅读数量统计记录数量 func DeleteUserViewStatisticsCount(dayStr string) (err error) { o := orm.NewOrm() //产品权限 sql := `delete from user_view_statistics WHERE date = ?` _, err = o.Raw(sql, dayStr).Exec() return } // UserViewMobileTotalSlice 根据用户手机号字符串获取用户的浏览数 type UserViewMobileTotalSlice struct { Mobile string `description:"用户手机号"` CompanyName string `description:"客户名称"` RealName string `description:"用户名称"` Total int `description:"总阅读数"` } // UserViewEmailTotalSlice 根据用户邮箱字符串获取用户的浏览数 type UserViewEmailTotalSlice struct { Email string `description:"用户邮箱"` CompanyName string `description:"客户名称"` RealName string `description:"用户名称"` Total int `description:"总阅读数"` } func GetCountUserViewHistoryByMobiles(date string) (items []*UserViewMobileTotalSlice, err error) { o := orm.NewOrm() sql := `SELECT count(1) total,mobile,company_name,real_name FROM user_view_history WHERE created_time >= ? and created_time <= ? and mobile != "" group by mobile` _, err = o.Raw(sql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items) return } func GetCountUserViewHistoryByEmails(date string) (items []*UserViewEmailTotalSlice, err error) { o := orm.NewOrm() sql := `SELECT count(1) total,email,company_name,real_name FROM user_view_history WHERE created_time >= ? and created_time <= ? and email != "" group by email` _, err = o.Raw(sql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items) return //return items2,err } func GetReportViewMaxTimeByMobiles(date string) (items []*UserViewMobileTotalSlice, err error) { o := orm.NewOrm() o.Using("rddp") rddpSql := `SELECT mobile,company_name,real_name,COUNT(1) AS total FROM report_view_record WHERE create_time >= ? and create_time <= ? and mobile != "" group by mobile` _, err = o.Raw(rddpSql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items) return } func GetReportViewMaxTimeByEmails(date string) (items []*UserViewEmailTotalSlice, err error) { o := orm.NewOrm() o.Using("rddp") rddpSql := `SELECT mobile,company_name,real_name,COUNT(1) AS total FROM report_view_record WHERE create_time >= ? and create_time <= ? and email != "" group by email` _, err = o.Raw(rddpSql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items) return } // GetAdvisoryCountUserViewHistoryByMobiles 每日资讯 func GetAdvisoryCountUserViewHistoryByMobiles(date string) (items []*UserViewMobileTotalSlice, err error) { o := orm.NewOrm() sql := `SELECT count(1) total,mobile,company_name,real_name FROM advisory_user_chart_article_record WHERE create_time >= ? and create_time <= ? and mobile != "" group by mobile` _, err = o.Raw(sql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items) return } // GetAdvisoryCountUserViewHistoryByEmails 每日资讯 func GetAdvisoryCountUserViewHistoryByEmails(date string) (items []*UserViewEmailTotalSlice, err error) { o := orm.NewOrm() sql := `SELECT count(1) total,email,company_name,real_name as created_time FROM advisory_user_chart_article_record WHERE create_time >= ? and create_time <= ? and email != "" group by email` _, err = o.Raw(sql, date+" 00:00:00", date+" 23:59:59").QueryRows(&items) return //return items2,err }