|
@@ -1,25 +1,322 @@
|
|
|
package models
|
|
|
|
|
|
+import (
|
|
|
+ "hongze/hongze_api/utils"
|
|
|
+ "rdluck_tools/orm"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
type BillDetailResp struct {
|
|
|
RealName string `description:"用户实际名称"`
|
|
|
- TogetherDay int `description:"相伴天数"`
|
|
|
+ TogetherDay string `description:"相伴天数"`
|
|
|
CreateDate string `description:"创建时间"`
|
|
|
FirstReadReportType string `description:"首次阅读报告类型"`
|
|
|
FirstReadReportTitle string `description:"首次阅读报告标题"`
|
|
|
ListenReportCount int `description:"收听报告次数"`
|
|
|
ListenReportDuration float64 `description:"收听报告时长"`
|
|
|
MaxReadReportDate string `description:"阅读报告最多的一天"`
|
|
|
- MaxReadReportCount int `description:"阅读报告最多的一天,报告数量"`
|
|
|
+ MaxReadReportCount int `description:"阅读报告最多的一天,报告数量"`
|
|
|
LatestReadReportDate string `description:"阅读报告时间最晚的一天"`
|
|
|
LatestReadReportTime string `description:"阅读报告时间最晚的一天,最晚的时间"`
|
|
|
LatestReadReportDateDuration string `description:"阅读报告时间最晚的一天,总共阅读报告的时长"`
|
|
|
MaxOpenReportClassify string `description:"打开次数最多报告的栏目"`
|
|
|
MaxOpenReportCount string `description:"打开次数最多报告的栏目下,用户阅读的报告数"`
|
|
|
- TotalReadDuration float64 `description:"总阅读时长"`
|
|
|
- TotalReportDayCount int `description:"总阅读晨报数"`
|
|
|
- TotalReportWeekCount int `description:"总阅读周报数"`
|
|
|
- TotalReportMonthCount int `description:"总阅读月报数"`
|
|
|
- TotalReportTwoWeekCount int `description:"总阅读双周报数"`
|
|
|
- TotalReportRddpCount int `description:"总阅读点评数"`
|
|
|
- LearnDay int `description:"连续学习天数"`
|
|
|
+ TotalReadDuration string `description:"总阅读时长"`
|
|
|
+ TotalReportDayCount string `description:"总阅读晨报数"`
|
|
|
+ TotalReportWeekCount string `description:"总阅读周报数"`
|
|
|
+ TotalReportMonthCount string `description:"总阅读月报数"`
|
|
|
+ TotalReportTwoWeekCount string `description:"总阅读双周报数"`
|
|
|
+ TotalReportRddpCount string `description:"总阅读点评数"`
|
|
|
+ LearnDay string `description:"连续学习天数"`
|
|
|
+}
|
|
|
+
|
|
|
+type ReadReportType struct {
|
|
|
+ ReportType string
|
|
|
+ CreateTime time.Time
|
|
|
+ Title string
|
|
|
+ Stage int
|
|
|
+}
|
|
|
+
|
|
|
+func GetRddpMinReportType(uid int) (item *ReadReportType, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ o.Using("rddp")
|
|
|
+ sql := `SELECT 'rddp' AS report_type,MIN(a.create_time) AS create_time,b.title,b.stage FROM report_view_record AS a
|
|
|
+ INNER JOIN report AS b ON a.report_id=b.id
|
|
|
+ WHERE a.user_id=? `
|
|
|
+ err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetWeekMinReportType(uid int) (item *ReadReportType, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := `SELECT b.type AS report_type,MIN(a.created_time) AS create_time,b.research_report_name AS title,b.periods AS stage FROM user_view_history AS a
|
|
|
+ INNER JOIN research_report AS b ON a.research_report_id=b.research_report_id
|
|
|
+ WHERE a.user_id=? `
|
|
|
+ err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
+ return
|
|
|
}
|
|
|
+
|
|
|
+func GetFirstReportInfo(uid int) (firstReadReportType, firstReadReportTitle string, err error) {
|
|
|
+ rddpFlag := true
|
|
|
+ weekFlag := true
|
|
|
+ rddpMinReportItem, err := GetRddpMinReportType(uid)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ rddpFlag = false
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if rddpMinReportItem == nil {
|
|
|
+ rddpFlag = false
|
|
|
+ }
|
|
|
+ weekMinReportItem, err := GetWeekMinReportType(uid)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ weekFlag = false
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if weekMinReportItem == nil {
|
|
|
+ weekFlag = false
|
|
|
+ }
|
|
|
+
|
|
|
+ if rddpFlag && weekFlag {
|
|
|
+ if rddpMinReportItem.CreateTime.After(weekMinReportItem.CreateTime) {
|
|
|
+ firstReadReportType = rddpMinReportItem.ReportType
|
|
|
+ firstReadReportTitle = rddpMinReportItem.Title
|
|
|
+ } else {
|
|
|
+ firstReadReportType = weekMinReportItem.ReportType
|
|
|
+ firstReadReportTitle = weekMinReportItem.Title
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if rddpFlag == false && weekFlag {
|
|
|
+ firstReadReportType = weekMinReportItem.ReportType
|
|
|
+ firstReadReportTitle = weekMinReportItem.Title
|
|
|
+ }
|
|
|
+ if rddpFlag && weekFlag == false {
|
|
|
+ firstReadReportType = rddpMinReportItem.ReportType
|
|
|
+ firstReadReportTitle = rddpMinReportItem.Title
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+type Listen struct {
|
|
|
+ Count int
|
|
|
+ VideoPlaySeconds float64
|
|
|
+}
|
|
|
+
|
|
|
+func GetRddpListen(uid int) (item *Listen, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ o.Using("rddp")
|
|
|
+ sql := ` SELECT COUNT(1),SUM(b.video_play_seconds) FROM report_audio_record AS a
|
|
|
+ INNER JOIN report AS b ON a.report_id=b.id
|
|
|
+ WHERE user_id=? LIMIT 1`
|
|
|
+ err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetWeekListen(uid int) (item *Listen, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := `SELECT COUNT(1) AS count,SUM(b.video_play_seconds) AS video_play_seconds FROM voice_record AS a
|
|
|
+ INNER JOIN teleconference AS b ON a.teleconference_id=b.teleconference_id
|
|
|
+ WHERE a.uid=? LIMIT 1`
|
|
|
+ err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetListenInfo(uid int) (count int, videoPlaySeconds float64, err error) {
|
|
|
+ rddpFlag := true
|
|
|
+ weekFlag := true
|
|
|
+ rddpListenItem, err := GetRddpListen(uid)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ rddpFlag = false
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if rddpListenItem == nil {
|
|
|
+ rddpFlag = false
|
|
|
+ }
|
|
|
+ weekListenItem, err := GetWeekListen(uid)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ weekFlag = false
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if weekListenItem == nil {
|
|
|
+ weekFlag = false
|
|
|
+ }
|
|
|
+
|
|
|
+ if rddpFlag && weekFlag {
|
|
|
+ count = rddpListenItem.Count + weekListenItem.Count
|
|
|
+ videoPlaySeconds = rddpListenItem.VideoPlaySeconds + weekListenItem.VideoPlaySeconds
|
|
|
+ } else {
|
|
|
+ if rddpFlag == false && weekFlag {
|
|
|
+ count = weekListenItem.Count
|
|
|
+ videoPlaySeconds = weekListenItem.VideoPlaySeconds
|
|
|
+ }
|
|
|
+ if rddpFlag && weekFlag == false {
|
|
|
+ count = rddpListenItem.Count
|
|
|
+ videoPlaySeconds = rddpListenItem.VideoPlaySeconds
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+type MaxReadReportCount struct {
|
|
|
+ Count int
|
|
|
+ CreateDate time.Time
|
|
|
+}
|
|
|
+
|
|
|
+func GetRddpMaxReadReportCount(uid int) (item *MaxReadReportCount, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ o.Using("rddp")
|
|
|
+ sql := ` SELECT DATE(create_time)AS create_date,COUNT(1) AS count FROM report_view_record AS a
|
|
|
+ WHERE a.user_id=?
|
|
|
+ GROUP BY DATE(create_time)
|
|
|
+ ORDER BY num DESC
|
|
|
+ LIMIT 1 `
|
|
|
+ err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetWeekMaxReadReportCount(uid int) (item *MaxReadReportCount, err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := ` SELECT DATE(a.created_time)AS create_date,COUNT(1) AS count FROM user_view_history AS a
|
|
|
+ WHERE a.user_id=?
|
|
|
+ GROUP BY DATE(created_time)
|
|
|
+ ORDER BY num DESC
|
|
|
+ LIMIT 1 `
|
|
|
+ err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetMaxReadReportInfo(uid int) (count int, createDate time.Time, err error) {
|
|
|
+ rddpFlag := true
|
|
|
+ weekFlag := true
|
|
|
+ rddpReadReportItem, err := GetRddpMaxReadReportCount(uid)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ rddpFlag = false
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if rddpReadReportItem == nil {
|
|
|
+ rddpFlag = false
|
|
|
+ }
|
|
|
+ weekReadReportItem, err := GetWeekMaxReadReportCount(uid)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ weekFlag = false
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if weekReadReportItem == nil {
|
|
|
+ weekFlag = false
|
|
|
+ }
|
|
|
+
|
|
|
+ if rddpFlag && weekFlag {
|
|
|
+ if rddpReadReportItem.Count>weekReadReportItem.Count {
|
|
|
+ count=rddpReadReportItem.Count
|
|
|
+ createDate=rddpReadReportItem.CreateDate
|
|
|
+ }else{
|
|
|
+ count=weekReadReportItem.Count
|
|
|
+ createDate=weekReadReportItem.CreateDate
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if rddpFlag == false && weekFlag {
|
|
|
+ count=weekReadReportItem.Count
|
|
|
+ createDate=weekReadReportItem.CreateDate
|
|
|
+ }
|
|
|
+ if rddpFlag && weekFlag == false {
|
|
|
+ count=rddpReadReportItem.Count
|
|
|
+ createDate=rddpReadReportItem.CreateDate
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+//
|
|
|
+//type MaxReadReportCount struct {
|
|
|
+// Count int
|
|
|
+// CreateDate time.Time
|
|
|
+//}
|
|
|
+//
|
|
|
+//func GetRddpMaxReadReportCount(uid int) (item *MaxReadReportCount, err error) {
|
|
|
+// o := orm.NewOrm()
|
|
|
+// o.Using("rddp")
|
|
|
+// sql := ` SELECT DATE(create_time)AS create_date,COUNT(1) AS count FROM report_view_record AS a
|
|
|
+// WHERE a.user_id=?
|
|
|
+// GROUP BY DATE(create_time)
|
|
|
+// ORDER BY num DESC
|
|
|
+// LIMIT 1 `
|
|
|
+// err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
+// return
|
|
|
+//}
|
|
|
+//
|
|
|
+//func GetWeekMaxReadReportCount(uid int) (item *MaxReadReportCount, err error) {
|
|
|
+// o := orm.NewOrm()
|
|
|
+// sql := ` SELECT DATE(a.created_time)AS create_date,COUNT(1) AS count FROM user_view_history AS a
|
|
|
+// WHERE a.user_id=?
|
|
|
+// GROUP BY DATE(created_time)
|
|
|
+// ORDER BY num DESC
|
|
|
+// LIMIT 1 `
|
|
|
+// err = o.Raw(sql, uid).QueryRow(&item)
|
|
|
+// return
|
|
|
+//}
|
|
|
+//
|
|
|
+//func GetMaxReadReportInfo(uid int) (count int, createDate time.Time, err error) {
|
|
|
+// rddpFlag := true
|
|
|
+// weekFlag := true
|
|
|
+// rddpReadReportItem, err := GetRddpMaxReadReportCount(uid)
|
|
|
+// if err != nil {
|
|
|
+// if err.Error() == utils.ErrNoRow() {
|
|
|
+// rddpFlag = false
|
|
|
+// } else {
|
|
|
+// return
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if rddpReadReportItem == nil {
|
|
|
+// rddpFlag = false
|
|
|
+// }
|
|
|
+// weekReadReportItem, err := GetWeekMaxReadReportCount(uid)
|
|
|
+// if err != nil {
|
|
|
+// if err.Error() == utils.ErrNoRow() {
|
|
|
+// weekFlag = false
|
|
|
+// } else {
|
|
|
+// return
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if weekReadReportItem == nil {
|
|
|
+// weekFlag = false
|
|
|
+// }
|
|
|
+//
|
|
|
+// if rddpFlag && weekFlag {
|
|
|
+// if rddpReadReportItem.Count>weekReadReportItem.Count {
|
|
|
+// count=rddpReadReportItem.Count
|
|
|
+// createDate=rddpReadReportItem.CreateDate
|
|
|
+// }else{
|
|
|
+// count=weekReadReportItem.Count
|
|
|
+// createDate=weekReadReportItem.CreateDate
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// if rddpFlag == false && weekFlag {
|
|
|
+// count=weekReadReportItem.Count
|
|
|
+// createDate=weekReadReportItem.CreateDate
|
|
|
+// }
|
|
|
+// if rddpFlag && weekFlag == false {
|
|
|
+// count=rddpReadReportItem.Count
|
|
|
+// createDate=rddpReadReportItem.CreateDate
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return
|
|
|
+//}
|