소스 검색

年度数据

rdluck 4 년 전
부모
커밋
957a31c37c
3개의 변경된 파일293개의 추가작업 그리고 55개의 파일을 삭제
  1. 276 55
      controllers/bill.go
  2. 7 0
      models/bill.go
  3. 10 0
      models/wx_user.go

+ 276 - 55
controllers/bill.go

@@ -311,62 +311,283 @@ func (this *BillController) Detail() {
 	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")
-		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")
-}
-*/
-
-//func init() {
-//	fmt.Println("start")
 //
-//	startDate:="2020-01-01 00:00:00"
-//	latestTime, latestCreateTime, err := models.GetLatestReadReportInfo(34167, startDate)
-//	if err != nil && err.Error() != utils.ErrNoRow() {
+//func init123() {
+//	fmt.Println("start")
+//	msg := ""
+//	defer func() {
+//		if msg != "" {
+//			fmt.Println("err:" + msg)
+//		}
+//	}()
+//	list, err := models.GetWxUserAll()
+//	if err != nil {
+//		msg = "GetWxUserAll Err:" + err.Error()
 //		return
 //	}
-//	fmt.Println(latestTime,latestCreateTime)
+//	for _, user := range list {
+//		uid := user.UserId
+//		existCount, err := models.GetAnnualReportCount(uid)
+//		if err != nil {
+//			msg = "GetAnnualReportCount Err:" + err.Error()
+//			return
+//		}
+//		if existCount > 0 {
+//			continue
+//		}
+//		userInfo, err := models.GetWxUserItemByUserId(uid)
+//		if err != nil {
+//			msg = "GetWxUserItemByUserId Err:" + err.Error()
+//			return
+//		}
+//		permission, err := services.CheckUserPermission(uid)
+//		if err != nil {
+//			msg = "GetWxUserItemByUserId Err:" + err.Error()
+//			return
+//		}
+//		if permission != 0 {
+//			msg = "判断用户是否有权限失败"
+//			return
+//		}
+//		startDate := "2020-01-01 00:00:00"
+//		endDate := time.Now().Format(utils.FormatDate)
+//		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 = 1
+//			}
+//			expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
+//			togetherDay = expireDay
+//			createDate = user.CreatedTime.Format("2006年01月02日")
+//		} else {
+//			sub := time.Now().Sub(user.LastUpdatedTime)
+//			if sub <= 0 {
+//				sub = 1
+//			}
+//			expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
+//			togetherDay = expireDay
+//			createDate = user.LastUpdatedTime.Format("2006年01月02日")
+//		}
+//		if togetherDay == "0" {
+//			togetherDay = "1"
+//		}
+//		//uid = 41555
+//
+//		firstReadReportType, firstReadReportTitle, err := models.GetFirstReportInfo(uid, startDate)
+//		if err != nil && err.Error() != utils.ErrNoRow() {
+//			msg = "获取数据失败GetFirstReportInfo,Err:" + err.Error()
+//			return
+//		}
+//		listenCount, listenVideoPlaySeconds, err := models.GetListenInfo(uid, startDate)
+//		if err != nil && err.Error() != utils.ErrNoRow() {
+//			msg = "获取数据失败GetListenInfo,Err:" + err.Error()
+//			return
+//		}
+//		maxReadReportCount, maxReadReportDate, err := models.GetMaxReadReportInfo(uid, startDate)
+//		if err != nil && err.Error() != utils.ErrNoRow() {
+//			msg = "获取数据失败GetMaxReadReportInfo,Err:" + err.Error()
+//			return
+//		}
+//
+//		latestTime, latestCreateTime, err := models.GetLatestReadReportInfo(uid, startDate)
+//		if err != nil && err.Error() != utils.ErrNoRow() {
+//			msg = "获取数据失败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)
+//			if err != nil && err.Error() != utils.ErrNoRow() {
+//				msg = "获取数据失败GetRddpReadReportCountByDate,Err:" + err.Error()
+//				return
+//			}
+//			weekReadCount, err := models.GetWeekReadReportCountByDate(uid, lastestCreateDate)
+//			if err != nil && err.Error() != utils.ErrNoRow() {
+//				msg = "获取数据失败GetWeekReadReportCountByDate,Err:" + err.Error()
+//				return
+//			}
+//			var weekVideoPlaySeconds float64
+//			if rddpReadCount <= 0 {
+//				weekVideoPlaySeconds = float64(utils.GetRandInt(3, 300)) / float64(10.00)
+//			} else {
+//				weekVideoPlaySeconds = float64(weekReadCount) * (rddpVideoPlaySeconds / float64(rddpReadCount))
+//			}
+//			VideoPlaySeconds = utils.FixFloat(rddpVideoPlaySeconds+weekVideoPlaySeconds, 2)
+//		}
+//
+//		maxOpenReportClassify, maxOpenReportCount, err := models.GetOpenReadReportInfo(uid, startDate)
+//		if err != nil && err.Error() != utils.ErrNoRow() {
+//			msg = "获取数据失败GetOpenReadReportInfo,Err:" + err.Error()
+//			return
+//		}
+//
+//		rddpTotalPlaySeconds, rddpTotal, err := models.GetRddpTotalReadDuration(uid, startDate)
+//		if err != nil && err.Error() != utils.ErrNoRow() {
+//			msg = "获取数据失败GetRddpTotalReadDuration,Err:" + err.Error()
+//			return
+//		}
+//
+//		weekTotal, err := models.GetWeekTotalRead(uid, startDate)
+//		if err != nil && err.Error() != utils.ErrNoRow() {
+//			msg = "获取数据失败GetRddpTotalReadDuration,Err:" + err.Error()
+//			return
+//		}
+//		totalReadDuration := 0.00
+//		if rddpTotal <= 0 {
+//			totalReadDuration = rddpTotalPlaySeconds + float64(weekTotal)*float64(120.00) //(float64(utils.GetRandInt(150, 155))/float64(10.00))
+//		} else {
+//			totalReadDuration = rddpTotalPlaySeconds + float64(weekTotal)*float64(120.00) //(rddpTotalPlaySeconds/float64(rddpTotal))*float64(weekTotal)
+//		}
+//		fmt.Println(uid, rddpTotalPlaySeconds, weekTotal, totalReadDuration)
+//		dayType := `day`
+//		dayTotal, err := models.GetWeekTotalReadByType(uid, dayType, startDate)
+//		if err != nil && err.Error() != utils.ErrNoRow() {
+//			msg = "获取数据失败GetWeekTotalReadByType,Err:" + err.Error()
+//			return
+//		}
+//		weekType := `week`
+//		weekReportReadTotal, err := models.GetWeekTotalReadByType(uid, weekType, startDate)
+//		if err != nil && err.Error() != utils.ErrNoRow() {
+//			msg = "获取数据失败GetWeekTotalReadByType,Err:" + err.Error()
+//			return
+//		}
+//		twoWeekType := `two_week`
+//		twoWeekTotal, err := models.GetWeekTotalReadByType(uid, twoWeekType, startDate)
+//		if err != nil && err.Error() != utils.ErrNoRow() {
+//			msg = "获取数据失败GetWeekTotalReadByType,Err:" + err.Error()
+//			return
+//		}
+//		monthType := `month`
+//		monthTotal, err := models.GetWeekTotalReadByType(uid, dayType, startDate)
+//		if err != nil && err.Error() != utils.ErrNoRow() {
+//			msg = "获取数据失败GetWeekTotalReadByType,Err:" + err.Error()
+//			return
+//		}
+//
+//		rddpReadTotal, err := models.GetRddpTotalReadByType(uid, startDate)
+//		if err != nil && err.Error() != utils.ErrNoRow() {
+//			msg = "获取数据失败GetRddpTotalReadByType,Err:" + err.Error()
+//			return
+//		}
+//
+//		var learnDay int
+//		rddpLearnDay, err := models.GetRddpLearnDay(uid, startDate, endDate)
+//		if err != nil && err.Error() != utils.ErrNoRow() {
+//			msg = "获取数据失败GetRddpLearnDay,Err:" + err.Error()
+//			return
+//		}
+//
+//		weekLearnDay, err := models.GetWeekpLearnDay(uid, startDate)
+//		if err != nil && err.Error() != utils.ErrNoRow() {
+//			msg = "获取数据失败GetWeekpLearnDay,Err:" + err.Error() + ";report_type:" + monthType
+//			return
+//		}
+//		if rddpLearnDay >= weekLearnDay {
+//			learnDay = rddpLearnDay
+//		} else {
+//			learnDay = weekLearnDay
+//		}
+//		if learnDay <= 0 {
+//			learnDay = 1
+//		}
+//		resp.RealName = realName
+//		resp.TogetherDay = togetherDay
+//		resp.CreateDate = createDate
+//		if firstReadReportType == "rddp" {
+//			resp.FirstReadReportType = "日度点评"
+//		} else if firstReadReportType == "day" {
+//			resp.FirstReadReportType = "晨报"
+//		} else if firstReadReportType == "week" {
+//			resp.FirstReadReportType = "周报"
+//		} else if firstReadReportType == "two_week" {
+//			resp.FirstReadReportType = "双周报"
+//		} else if firstReadReportType == "month" {
+//			resp.FirstReadReportType = "月报"
+//		} else {
+//			resp.FirstReadReportType = "其他"
+//		}
+//		resp.FirstReadReportTitle = firstReadReportTitle
+//		resp.ListenReportCount = listenCount
+//		resp.ListenReportDuration = utils.FixFloat((listenVideoPlaySeconds / 60.00), 2)
+//		resp.MaxReadReportCount = maxReadReportCount
+//		resp.MaxReadReportDate = maxReadReportDate.Format("2006年01月02日")
+//		if lastestCreateDate == "" {
+//			resp.LatestReadReportDate = ""
+//		} else {
+//			lastestDate, _ := time.Parse("2006-01-02", lastestCreateDate)
+//			resp.LatestReadReportDate = lastestDate.Format("2006年01月02日")
+//		}
+//		resp.LatestReadReportTime = latestTime
+//		resp.LatestReadReportDateDuration = VideoPlaySeconds
+//		resp.MaxOpenReportClassify = maxOpenReportClassify
+//		resp.MaxOpenReportCount = maxOpenReportCount
+//		resp.TotalReadDuration = totalReadDuration
+//		resp.TotalReportDayCount = dayTotal
+//		resp.TotalReportWeekCount = weekReportReadTotal
+//		resp.TotalReportTwoWeekCount = twoWeekTotal
+//		resp.TotalReportMonthCount = monthTotal
+//		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()
+//			models.AddAnnualReport(annualReport)
+//		}
+//	}
+//	return
 //	fmt.Println("end")
-//}
+//}

+ 7 - 0
models/bill.go

@@ -529,3 +529,10 @@ func GetRddpTotalReadByType(uid int, startDate string) (report_count int, err er
 	err = o.Raw(sql, uid, startDate).QueryRow(&report_count)
 	return
 }
+
+func GetAnnualReportCount(userId int)(count int,err error)  {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS count FROM annual_report WHERE user_id=? `
+	err = o.Raw(sql, userId).QueryRow(&count)
+	return
+}

+ 10 - 0
models/wx_user.go

@@ -440,3 +440,13 @@ func ModifyWxUserUnionId(unionId string, userId int) (err error) {
 	_, err = o.Raw(sql, unionId, unionId, userId).Exec()
 	return
 }
+
+func GetWxUserAll()(items []*WxUserItem, err error) {
+	sql := ` SELECT a.* FROM wx_user AS a 
+			INNER JOIN company_product AS b ON a.company_id=b.company_id
+			WHERE b.status IN('正式','试用')
+			AND b.product_id=1 `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}