package models import ( "github.com/beego/beego/v2/client/orm" "time" ) // CompanyViewStatistics 客户报告报告阅读数量统计表 type CompanyViewStatistics struct { Id int `orm:"column(id)" description:"自增Id"` CompanyId int `description:"客户id"` ViewNum int `description:"阅读总数"` Date time.Time `description:"阅读日期"` CreateTime time.Time `description:"添加时间"` } // AddMultiCompanyViewStatistics 添加客户报告报告阅读数量统计记录 func AddMultiCompanyViewStatistics(list []*CompanyViewStatistics) (err error) { if len(list) <= 0 { return } o := orm.NewOrm() _, err = o.InsertMulti(len(list), list) return } // AddCompanyViewStatistics 添加客户报告报告阅读数量统计记录 func AddCompanyViewStatistics(item *CompanyViewStatistics) (err error) { o := orm.NewOrm() _, err = o.Insert(item) return } // Update 更新客户报告报告阅读数量统计表 func (companyViewStatistics *CompanyViewStatistics) Update(cols []string) (err error) { o := orm.NewOrm() _, err = o.Update(companyViewStatistics, cols...) return } // GetCompanyViewStatisticsCount 获取某天的客户报告报告阅读数量统计记录数量 func GetCompanyViewStatisticsCount(dayStr string) (count int, err error) { o := orm.NewOrm() sql := `SELECT count(1) count FROM company_view_statistics WHERE date = ?` err = o.Raw(sql, dayStr).QueryRow(&count) return } // GetCompanyViewStatisticsByCompanyId 根据客户id、日期获取数据 func GetCompanyViewStatisticsByCompanyId(companyId int, date string) (item *CompanyViewStatistics, err error) { o := orm.NewOrm() sql := `SELECT * from company_view_statistics WHERE company_id=? and date = ?` err = o.Raw(sql, companyId, date).QueryRow(&item) return } // CompanyViewTotalSlice 根据用户手机号字符串获取客户的浏览数 type CompanyViewTotalSlice struct { CompanyId int `description:"用户手机号"` Total int `description:"总阅读数"` Date string `description:"统计的日期"` } // GetCompanyViewMobileTotalList 根据用户手机号字符串获取客户的浏览数 func GetCompanyViewMobileTotalList(date string) (items []*CompanyViewTotalSlice, err error) { o := orm.NewOrm() sql := `SELECT sum(a.view_num) total,a.date,b.company_id FROM user_view_statistics a join wx_user b on a.mobile=b.mobile WHERE a.mobile != "" and b.mobile != "" and a.date = ? group by company_id` _, err = o.Raw(sql, date).QueryRows(&items) return } // GetCompanyViewEmailTotalList 根据用户邮箱字符串获取客户的浏览数 func GetCompanyViewEmailTotalList(date string) (items []*CompanyViewTotalSlice, err error) { o := orm.NewOrm() sql := `SELECT sum(a.view_num) total,a.date,b.company_id FROM user_view_statistics a join wx_user b on a.email=b.email WHERE a.email != "" and b.email != "" and a.date = ? group by company_id` _, err = o.Raw(sql, date).QueryRows(&items) return }