package controllers import ( "fmt" "hongze/hongze_api/models" "hongze/hongze_api/utils" "time" ) //年度账单 type BillController struct { BaseAuthController } // @Title 年度账单接口 // @Description 年度账单接口 // @Success 200 {object} models.WxLoginResp // @router /detail [get] func (this *WechatCommonController) Detail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } uid := user.UserId var realName, togetherDay, createDate string resp := new(models.BillDetailResp) if user.RealName == "" { realName = user.NickName } else { realName = user.RealName } if !user.CreatedTime.IsZero() { sub := time.Now().Sub(user.CreatedTime) if sub < 0 { sub = 0 } expireDay := fmt.Sprintf("%v", int(sub.Hours()/24)) togetherDay = expireDay createDate = user.CreatedTime.Format(utils.FormatDate) } else { sub := time.Now().Sub(user.LastUpdatedTime) if sub < 0 { sub = 0 } expireDay := fmt.Sprintf("%v", int(sub.Hours()/24)) togetherDay = expireDay createDate = user.LastUpdatedTime.Format(utils.FormatDate) } uid = 41555 firstReadReportType, firstReadReportTitle, err := models.GetFirstReportInfo(uid) if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败GetFirstReportInfo,Err:" + err.Error() return } listenCount, listenVideoPlaySeconds, err := models.GetListenInfo(uid) if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败GetListenInfo,Err:" + err.Error() return } maxReadReportCount, maxReadReportDate, err := models.GetMaxReadReportInfo(uid) if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败GetListenInfo,Err:" + err.Error() return } /* 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:"连续学习天数"` */ resp.RealName = realName resp.TogetherDay = togetherDay resp.CreateDate = createDate resp.FirstReadReportType = firstReadReportType resp.FirstReadReportTitle = firstReadReportTitle resp.ListenReportCount = listenCount resp.ListenReportDuration = utils.FixFloat((listenVideoPlaySeconds / 60.00), 2) resp.MaxReadReportCount = maxReadReportCount resp.MaxReadReportDate = maxReadReportDate.Format(utils.FormatDate) br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp }