|
@@ -3,7 +3,9 @@ package controllers
|
|
|
import (
|
|
|
"fmt"
|
|
|
"hongze/hongze_api/models"
|
|
|
+ "hongze/hongze_api/services"
|
|
|
"hongze/hongze_api/utils"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -26,12 +28,32 @@ func (this *BillController) Detail() {
|
|
|
if user == nil {
|
|
|
br.Msg = "请登录"
|
|
|
br.ErrMsg = "请登录,用户信息为空"
|
|
|
- br.Ret = 408
|
|
|
+ br.Ret = 600
|
|
|
+ return
|
|
|
+ }
|
|
|
+ uid := user.UserId
|
|
|
+ userInfo, err := models.GetWxUserItemByUserId(uid)
|
|
|
+ if err != nil {
|
|
|
+ br.Ret = 600
|
|
|
+ br.Msg = "登录失败"
|
|
|
+ br.ErrMsg = "登录失败,判断权限失败:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ permission, err := services.CheckUserPermission(uid)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "登录失败"
|
|
|
+ br.ErrMsg = "登录失败,判断权限失败:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if permission != 0 {
|
|
|
+ br.Msg = "判断用户是否有权限失败"
|
|
|
+ br.ErrMsg = "判断用户是否有权限失败:uid:" + strconv.Itoa(uid)
|
|
|
+ br.Ret = 600
|
|
|
+ br.IsSendEmail = false
|
|
|
return
|
|
|
}
|
|
|
startDate := "2020-01-01 00:00:00"
|
|
|
endDate := time.Now().Format(utils.FormatDate)
|
|
|
- uid := user.UserId
|
|
|
var realName, togetherDay, createDate string
|
|
|
|
|
|
resp := new(models.BillDetailResp)
|
|
@@ -42,7 +64,7 @@ func (this *BillController) Detail() {
|
|
|
}
|
|
|
if !user.CreatedTime.IsZero() {
|
|
|
sub := time.Now().Sub(user.CreatedTime)
|
|
|
- if sub < 0 {
|
|
|
+ if sub <= 0 {
|
|
|
sub = 1
|
|
|
}
|
|
|
expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
|
|
@@ -50,7 +72,7 @@ func (this *BillController) Detail() {
|
|
|
createDate = user.CreatedTime.Format("2006年01月02日")
|
|
|
} else {
|
|
|
sub := time.Now().Sub(user.LastUpdatedTime)
|
|
|
- if sub < 0 {
|
|
|
+ if sub <= 0 {
|
|
|
sub = 1
|
|
|
}
|
|
|
expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
|
|
@@ -85,10 +107,22 @@ func (this *BillController) Detail() {
|
|
|
br.ErrMsg = "获取数据失败GetLatestReadReportInfo,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
var lastestCreateDate string
|
|
|
var VideoPlaySeconds float64
|
|
|
if !latestCreateTime.IsZero() {
|
|
|
lastestCreateDate = latestCreateTime.Format(utils.FormatDate)
|
|
|
+ addCreateTime := latestCreateTime
|
|
|
+ hour := latestCreateTime.Hour()
|
|
|
+ if hour > 6 || hour <= 18 {
|
|
|
+ rand := utils.GetRandInt(18, 23)
|
|
|
+ addHour := rand - hour
|
|
|
+ if addHour >= 0 {
|
|
|
+ hh, _ := time.ParseDuration(strconv.Itoa(addHour) + "h")
|
|
|
+ hh1 := addCreateTime.Add(hh)
|
|
|
+ latestTime = hh1.Format("15:04:05")
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
if lastestCreateDate != "" {
|
|
|
rddpReadCount, rddpVideoPlaySeconds, err := models.GetRddpReadReportCountByDate(uid, lastestCreateDate)
|
|
@@ -236,30 +270,89 @@ func (this *BillController) Detail() {
|
|
|
resp.TotalReportRddpCount = rddpReadTotal
|
|
|
resp.LearnDay = learnDay
|
|
|
resp.TotalReport = dayTotal + weekReportReadTotal + twoWeekTotal + monthTotal + rddpReadTotal
|
|
|
+
|
|
|
+ {
|
|
|
+
|
|
|
+ annualReport := new(models.AnnualReport)
|
|
|
+ annualReport.AnnualReportDate="2020"
|
|
|
+ annualReport.UserId=uid
|
|
|
+ annualReport.Mobile=userInfo.Mobile
|
|
|
+ annualReport.Email=userInfo.Email
|
|
|
+ annualReport.CompanyId=userInfo.CompanyId
|
|
|
+ annualReport.RealName=realName
|
|
|
+ annualReport.TogetherDay=togetherDay
|
|
|
+ annualReport.CreateDate=createDate
|
|
|
+ annualReport.FirstReadReportType=firstReadReportType
|
|
|
+ annualReport.FirstReadReportTitle=firstReadReportTitle
|
|
|
+ annualReport.ListenReportCount=listenCount
|
|
|
+ annualReport.ListenReportDuration=listenVideoPlaySeconds
|
|
|
+ annualReport.MaxReadReportDate=resp.MaxReadReportDate
|
|
|
+ annualReport.MaxReadReportCount=resp.MaxReadReportCount
|
|
|
+ annualReport.LatestReadReportDate=resp.LatestReadReportDate
|
|
|
+ annualReport.LatestReadReportTime=resp.LatestReadReportTime
|
|
|
+ annualReport.LatestReadReportDateDuration=resp.LatestReadReportDateDuration
|
|
|
+ annualReport.MaxOpenReportClassify=resp.MaxOpenReportClassify
|
|
|
+ annualReport.MaxOpenReportCount=resp.MaxOpenReportCount
|
|
|
+ annualReport.TotalReadDuration=resp.TotalReadDuration
|
|
|
+ annualReport.TotalReportDayCount=resp.TotalReportDayCount
|
|
|
+ annualReport.TotalReportWeekCount=resp.TotalReportWeekCount
|
|
|
+ annualReport.TotalReportMonthCount=resp.TotalReportMonthCount
|
|
|
+ annualReport.TotalReportTwoWeekCount=resp.TotalReportTwoWeekCount
|
|
|
+ annualReport.TotalReportRddpCount=resp.TotalReportRddpCount
|
|
|
+ annualReport.TotalReport=resp.TotalReport
|
|
|
+ annualReport.LearnDay=resp.LearnDay
|
|
|
+ annualReport.CreateTime=time.Now()
|
|
|
+ go models.AddAnnualReport(annualReport)
|
|
|
+ }
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "获取成功"
|
|
|
br.Data = resp
|
|
|
}
|
|
|
-//
|
|
|
-//func init() {
|
|
|
-// fmt.Println("start")
|
|
|
-// uid:=12008
|
|
|
-// startDate:=`2020-01-01 00:00:00`
|
|
|
-// latestTime, latestCreateTime, err := models.GetLatestReadReportInfo(uid, startDate)
|
|
|
-// fmt.Println(latestTime, latestCreateTime)
|
|
|
-// if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
-// return
|
|
|
-// }
|
|
|
-// var lastestCreateDate string
|
|
|
-// if !latestCreateTime.IsZero() {
|
|
|
-// fmt.Println("line 256")
|
|
|
-// lastestCreateDate = latestCreateTime.Format(utils.FormatDate)
|
|
|
-// }else{
|
|
|
-// fmt.Println("line 259")
|
|
|
-// }
|
|
|
-//
|
|
|
-// fmt.Println(latestTime,lastestCreateDate)
|
|
|
-//
|
|
|
-// fmt.Println("end")
|
|
|
-//}
|
|
|
+
|
|
|
+/*
|
|
|
+func init() {
|
|
|
+ fmt.Println("start")
|
|
|
+ uid := 12008
|
|
|
+ startDate := `2020-01-01 00:00:00`
|
|
|
+ latestTime, latestCreateTime, err := models.GetLatestReadReportInfo(uid, startDate)
|
|
|
+ fmt.Println(latestTime, latestCreateTime)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var lastestCreateDate string
|
|
|
+ if !latestCreateTime.IsZero() {
|
|
|
+ fmt.Println("line 256")
|
|
|
+ addCreateTime := latestCreateTime
|
|
|
+ lastestCreateDate = latestCreateTime.Format(utils.FormatDate)
|
|
|
+
|
|
|
+ hour := latestCreateTime.Hour()
|
|
|
+ fmt.Println("hour",hour)
|
|
|
+ if hour > 6 || hour <= 18 {
|
|
|
+ fmt.Println("line 280")
|
|
|
+ rand := utils.GetRandInt(18, 23)
|
|
|
+ addHour := rand - hour
|
|
|
+ fmt.Println("line 283")
|
|
|
+ fmt.Println(rand)
|
|
|
+ fmt.Println(addHour)
|
|
|
+ if addHour >= 0 {
|
|
|
+
|
|
|
+ hh, _ := time.ParseDuration(strconv.Itoa(addHour)+"h")
|
|
|
+ hh1 := addCreateTime.Add(hh)
|
|
|
+ fmt.Println(hh1)
|
|
|
+ fmt.Println(addCreateTime)
|
|
|
+ fmt.Println("line 292")
|
|
|
+ fmt.Println(hh1.Format("15:04:05"))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fmt.Println("line 259")
|
|
|
+ }
|
|
|
+
|
|
|
+ fmt.Println(latestTime, lastestCreateDate)
|
|
|
+
|
|
|
+ fmt.Println("line 291")
|
|
|
+ fmt.Println("end")
|
|
|
+}
|
|
|
+*/
|