rdluck 4 years ago
parent
commit
7ccd0d4e4b
7 changed files with 112 additions and 137 deletions
  1. 32 5
      controllers/bill.go
  2. 5 2
      controllers/user.go
  3. 13 41
      controllers/wechat.go
  4. 30 2
      models/annual_report.go
  5. 7 4
      models/bill.go
  6. 24 82
      models/wx_user.go
  7. 1 1
      services/annual_report.go

+ 32 - 5
controllers/bill.go

@@ -43,7 +43,7 @@ func (this *BillController) Detail() {
 	if !user.CreatedTime.IsZero() {
 		sub := time.Now().Sub(user.CreatedTime)
 		if sub < 0 {
-			sub = 0
+			sub = 1
 		}
 		expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
 		togetherDay = expireDay
@@ -51,7 +51,7 @@ func (this *BillController) Detail() {
 	} else {
 		sub := time.Now().Sub(user.LastUpdatedTime)
 		if sub < 0 {
-			sub = 0
+			sub = 1
 		}
 		expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
 		togetherDay = expireDay
@@ -217,9 +217,14 @@ func (this *BillController) Detail() {
 	resp.ListenReportCount = listenCount
 	resp.ListenReportDuration = utils.FixFloat((listenVideoPlaySeconds / 60.00), 2)
 	resp.MaxReadReportCount = maxReadReportCount
-	resp.MaxReadReportDate = maxReadReportDate.Format(utils.FormatDate)
-	resp.LatestReadReportDate = lastestCreateDate
-	resp.LatestReadReportTime = latestTime.Format("15:04:05")
+	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
@@ -236,3 +241,25 @@ 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")
+//		lastestCreateDate = latestCreateTime.Format(utils.FormatDate)
+//	}else{
+//		fmt.Println("line 259")
+//	}
+//
+//	fmt.Println(latestTime,lastestCreateDate)
+//
+//	fmt.Println("end")
+//}

+ 5 - 2
controllers/user.go

@@ -49,6 +49,9 @@ func (this *UserController) Detail() {
 		br.ErrMsg = "判断用户权限信息失败,Err:" + err.Error()
 		return
 	}
+	if item.Mobile == "" && item.Email == "" {
+		item.FirstLogin = 1
+	}
 	item.UserPermission = userPermission
 	br.Ret = 200
 	br.Success = true
@@ -290,7 +293,7 @@ func (this *UserController) Login() {
 	newUserId := 0
 	if req.LoginType == 1 {
 		//BindMobile(openId, mobile string, userId, loginType int) (err error) {
-		req.Mobile=strings.Trim(req.Mobile," ")
+		req.Mobile = strings.Trim(req.Mobile, " ")
 		newUserId, err = models.BindMobile(openId, req.Mobile, userId, req.LoginType)
 	} else if req.LoginType == 2 {
 		if req.Email == "" {
@@ -455,4 +458,4 @@ func (this *UserController) SmallLimit() {
 	br.Ret = 200
 	br.Success = true
 	br.Data = resp
-}
+}

+ 13 - 41
controllers/wechat.go

@@ -72,8 +72,8 @@ func (this *WechatCommonController) WechatLogin() {
 	utils.FileLog.Info("openId:%s", openId)
 	utils.FileLog.Info("unionid:%s", unionid)
 	//获取成功
-	if unionid != "" {
-		wxUser, err := models.GetWxUserItemByUnionid(unionid)
+	if openId != "" {
+		wxUser, err := models.GetWxUserItemByOpenId(openId)
 		if err != nil && err.Error() != utils.ErrNoRow() {
 			br.Msg = "获取用户信息失败"
 			br.ErrMsg = "根据openid获取用户信息失败,Eerr:" + err.Error()
@@ -97,7 +97,7 @@ func (this *WechatCommonController) WechatLogin() {
 			user.RegisterPlatform = 1
 			user.RegisterTime = time.Now()
 			_, err = models.AddWxUser(user)
-			wxUser, err = models.GetWxUserItemByUnionid(unionid)
+			wxUser, err = models.GetWxUserItemByOpenId(openId)
 			if err != nil {
 				br.Msg = "获取用户信息失败"
 				br.ErrMsg = "unionid登录,获取微信用户信息失败,Err:" + err.Error()
@@ -109,43 +109,9 @@ func (this *WechatCommonController) WechatLogin() {
 			userId = wxUser.UserId
 		}
 	} else {
-		if openId != "" {
-			wxUser, err := models.GetWxUserItemByOpenId(openId)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				br.Msg = "获取用户信息失败"
-				br.ErrMsg = "获取微信用户信息失败,Err:" + err.Error()
-				return
-			}
-			if wxUser == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
-				user := new(models.WxUser)
-				user.OpenId = openId
-				user.CompanyId = 1
-				user.CreatedTime = time.Now()
-				user.UnionId = unionid
-				user.Unionid = unionid
-				user.NickName = wxUserInfo.Nickname
-				user.Sex = wxUserInfo.Sex
-				user.City = wxUserInfo.City
-				user.Province = wxUserInfo.Province
-				user.Country = wxUserInfo.Country
-				user.Headimgurl = wxUserInfo.Headimgurl
-				user.FirstLogin = 1
-				user.Enabled = 1
-				user.RegisterPlatform = 1
-				user.RegisterTime = time.Now()
-				_, err = models.AddWxUser(user)
-
-				wxUser, err = models.GetWxUserItemByOpenId(openId)
-				if err != nil {
-					br.Msg = "获取用户信息失败"
-					br.ErrMsg = "unionid登录,获取微信用户信息失败,Err:" + err.Error()
-					return
-				}
-				userId = wxUser.UserId
-			} else {
-				userId = wxUser.UserId
-			}
-		}
+		br.Msg = "获取用户信息失败"
+		br.ErrMsg = "获取openid失败,openid:" + item.Openid
+		return
 	}
 	permission, err := services.CheckUserPermission(userId)
 	if err != nil {
@@ -188,7 +154,13 @@ func (this *WechatCommonController) WechatLogin() {
 	if wxUserInfo != nil {
 		go models.ModifyWxUserInfo(wxUserInfo.Nickname, wxUserInfo.Headimgurl, wxUserInfo.City, wxUserInfo.Province, wxUserInfo.Country, wxUserInfo.Sex, userId)
 	}
-
+	//firstLogin==1,强制绑定手机号或者邮箱
+	{
+		newItem, _ := models.GetWxUserItemByUserId(userId)
+		if newItem.Mobile == "" && newItem.Email == "" {
+			firstLogin = 1
+		}
+	}
 	resp := new(models.WxLoginResp)
 	resp.UserId = userId
 	resp.Code = 0

+ 30 - 2
models/annual_report.go

@@ -1,6 +1,34 @@
 package models
 
+import "time"
+
 type AnnualReport struct {
-	CreateDate string
-	UserId     int
+	AnnualReportDate             string    `description:"报告年度"`
+	UserId                       int       `description:"用户id"`
+	Mobile                       string    `description:"手机号"`
+	Email                        string    `description:"邮箱"`
+	CompanyId                    int       `description:"公司id"`
+	RealName                     string    `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:"阅读报告最多的一天,报告数量"`
+	LatestReadReportDate         string    `description:"阅读报告时间最晚的一天"`
+	LatestReadReportTime         string    `description:"阅读报告时间最晚的一天,最晚的时间"`
+	LatestReadReportDateDuration float64   `description:"阅读报告时间最晚的一天,总共阅读报告的时长"`
+	MaxOpenReportClassify        string    `description:"打开次数最多报告的栏目"`
+	MaxOpenReportCount           int       `description:"打开次数最多报告的栏目下,用户阅读的报告数"`
+	TotalReadDuration            float64   `description:"总阅读时长"`
+	TotalReportDayCount          int       `description:"总阅读晨报数"`
+	TotalReportWeekCount         int       `description:"总阅读周报数"`
+	TotalReportMonthCount        int       `description:"总阅读月报数"`
+	TotalReportTwoWeekCount      int       `description:"总阅读双周报数"`
+	TotalReportRddpCount         int       `description:"总阅读点评数"`
+	TotalReport                  int       `description:"总阅读报告数"`
+	LearnDay                     int       `description:"连续学习天数"`
+	CreateTime                   time.Time `description:"创建时间"`
 }

+ 7 - 4
models/bill.go

@@ -1,6 +1,7 @@
 package models
 
 import (
+	"fmt"
 	"hongze/hongze_api/utils"
 	"rdluck_tools/orm"
 	"time"
@@ -171,7 +172,7 @@ func GetListenInfo(uid int, startDate string) (count int, videoPlaySeconds float
 }
 
 type LatestReadReport struct {
-	LatestTime time.Time
+	LatestTime string
 	CreateTime time.Time
 }
 
@@ -196,7 +197,7 @@ func GetWeekLatestReadReportCount(uid int, startDate string) (item *LatestReadRe
 	return
 }
 
-func GetLatestReadReportInfo(uid int, startDate string) (latestTime, latestCreateTime time.Time, err error) {
+func GetLatestReadReportInfo(uid int, startDate string) (latestTime string, latestCreateTime time.Time, err error) {
 	rddpFlag := true
 	weekFlag := true
 	rddpReadReportItem, err := GetRddpLatestReadReport(uid, startDate)
@@ -240,6 +241,8 @@ func GetLatestReadReportInfo(uid int, startDate string) (latestTime, latestCreat
 			latestCreateTime = rddpReadReportItem.CreateTime
 		}
 	}
+	fmt.Println("line 244")
+	fmt.Println(latestTime, latestCreateTime)
 	return
 }
 
@@ -346,7 +349,7 @@ type MaxOpenReport struct {
 func GetRddpOpenReadReport(uid int, startDate string) (item *MaxOpenReport, err error) {
 	o := orm.NewOrm()
 	o.Using("rddp")
-	sql := ` SELECT COUNT(b.classify_id_second) AS report_count,b.classify_name_second AS classify_name 
+	sql := ` SELECT COUNT(b.classify_id_second) AS open_report_count,b.classify_name_second AS classify_name 
             FROM report_view_record AS a
 			INNER JOIN report AS b ON a.report_id=b.id
 			WHERE a.user_id=? AND a.create_time>=?
@@ -359,7 +362,7 @@ func GetRddpOpenReadReport(uid int, startDate string) (item *MaxOpenReport, err
 
 func GetWeekOpenReadReportCount(uid int, startDate string) (item *MaxOpenReport, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT COUNT(b.research_report_name) AS report_count,b.research_report_name AS classify_name 
+	sql := ` SELECT COUNT(b.research_report_name) AS open_report_count,b.research_report_name AS classify_name 
             FROM user_view_history AS a 
 			LEFT JOIN research_report AS b ON a.research_report_id=b.research_report_id
 			WHERE user_id=? AND a.created_time=?

+ 24 - 82
models/wx_user.go

@@ -203,7 +203,7 @@ type LoginResp struct {
 }
 
 func BindMobile(openId, mobile string, userId, loginType int) (wxUserId int, err error) {
-	mobile=strings.Trim(mobile," ")
+	mobile = strings.Trim(mobile, " ")
 	//loginType  登录方式:1:手机,2:邮箱
 	sql := ``
 	if loginType == 1 {
@@ -233,7 +233,7 @@ func BindMobile(openId, mobile string, userId, loginType int) (wxUserId int, err
 		wxUserId = userId
 	} else {
 		fmt.Println("line  223")
-		if user.OpenId == "" {
+		if openId != "" {
 			wxUserId = user.UserId
 			dsql := ` DELETE FROM wx_user WHERE open_id = ? `
 			_, err = o.Raw(dsql, openId).Exec()
@@ -306,98 +306,40 @@ func PcBindMobile(unionId, mobile string, userId, loginType int) (wxUserId int,
 				maxRegisterTime = userInfo.RegisterTime
 				utils.FileLog.Info("not after")
 			}
-			var realName string
-			if user.RealName != "" {
-				realName = user.RealName
-			} else {
-				realName = userInfo.RealName
-			}
 			utils.FileLog.Info("maxRegisterTime %s", maxRegisterTime.Format(utils.FormatDateTime))
 			wxUserId = user.UserId
-			dsql := ` DELETE FROM wx_user WHERE user_id = ? `
-			_, err = o.Raw(dsql, wxUserId).Exec()
+			dsql := ` DELETE FROM wx_user WHERE union_id = ? `
+			_, err = o.Raw(dsql, unionId).Exec()
 			if err != nil {
 				return wxUserId, err
 			}
-			msql := ``
-			if loginType == 1 {
-				msql = ` UPDATE wx_user SET mobile=?,bind_account = ?,created_time=NOW(),register_time=?,real_name=? `
-				if user.CompanyId > 0 {
-					msql += ` ,company_id = ? `
-				}
-				msql += ` WHERE union_id = ? `
-			} else {
-				msql = ` UPDATE wx_user SET email=?,bind_account = ?,created_time=NOW(),register_time=?,real_name=? `
-				if user.CompanyId > 0 {
-					msql += ` ,company_id = ? `
-				}
-				msql += `  WHERE union_id = ? `
-			}
-			if user.CompanyId > 0 {
-				_, err = o.Raw(msql, mobile, mobile, maxRegisterTime, realName, user.CompanyId, unionId).Exec()
-			} else {
-				_, err = o.Raw(msql, mobile, mobile, maxRegisterTime, realName, unionId).Exec()
-			}
-			wxUserId = userInfo.UserId
+			msql := ` UPDATE wx_user SET union_id=?,register_time=?,province=?,city=?,country=?,headimgurl=?,unionid=?,sex=?  WHERE user_id = ?  `
+			_, err = o.Raw(msql, unionId, maxRegisterTime, userInfo.Province, userInfo.City, userInfo.Country, userInfo.Headimgurl, unionId, userInfo.Sex, user.UserId).Exec()
+			wxUserId = user.UserId
 		} else {
-			sql = `SELECT * FROM wx_user WHERE union_id = ? `
+			sql = `SELECT * FROM wx_user WHERE user_id = ? `
 			userInfo := new(WxUser)
 			o := orm.NewOrm()
-			err = o.Raw(sql, unionId).QueryRow(&userInfo)
+			err = o.Raw(sql, userId).QueryRow(&userInfo)
 			if err != nil && err.Error() != utils.ErrNoRow() {
 				return
 			}
-			if userInfo.UserId != user.UserId {
-				isDelete := 0
-				if userInfo.CompanyId <= 1 {
-					dsql := ` DELETE FROM wx_user WHERE user_id = ? `
-					_, err = o.Raw(dsql, userInfo.UserId).Exec()
-					if err != nil {
-						return userInfo.UserId, err
-					}
-					isDelete = 1
-				}
-
-				if user.CompanyId <= 1 {
-					dsql := ` DELETE FROM wx_user WHERE user_id = ? `
-					_, err = o.Raw(dsql, user.UserId).Exec()
-					if err != nil {
-						return userInfo.UserId, err
-					}
-					isDelete = 2
-				}
-
-				if userInfo.CompanyId > 1 && user.CompanyId > 1 {
-					dsql := ` DELETE FROM wx_user WHERE user_id = ? `
-					_, err = o.Raw(dsql, user.UserId).Exec()
-					if err != nil {
-						return userInfo.UserId, err
-					}
-					isDelete = 2
-				}
-				if isDelete == 1 {
-					msql := ` UPDATE wx_user SET union_id = ?,unionid=?,bind_account = ?,created_time=NOW(),register_time=NOW()  `
-					if loginType == 1 {
-						msql += ` ,mobile = ? `
-					} else {
-						msql += ` ,email = ? `
-					}
-					msql += ` WHERE user_id = ? `
-					_, err = o.Raw(msql, user.Unionid, user.Unionid, mobile, mobile, user.UserId).Exec()
-					wxUserId = user.UserId
-				} else {
-					msql := ` UPDATE wx_user SET union_id = ?,unionid=?,bind_account = ?,created_time=NOW(),register_time=NOW()  `
-					if loginType == 1 {
-						msql += ` ,mobile = ? `
-					} else {
-						msql += ` ,email = ? `
-					}
-					msql += ` WHERE user_id = ? `
-					_, err = o.Raw(msql, unionId, unionId, mobile, mobile, userInfo.UserId).Exec()
-					wxUserId = userInfo.UserId
-				}
+			dsql := ` DELETE FROM wx_user WHERE user_id = ? `
+			_, err = o.Raw(dsql, userId).Exec()
+			if err != nil {
+				return user.UserId, err
+			}
+			if user.Mobile == "" && loginType == 1 {
+				msql := ` UPDATE wx_user SET mobile = ?,bind_account = ?  WHERE user_id = ?`
+				_, err = o.Raw(msql, mobile, mobile, user.UserId).Exec()
+				wxUserId = user.UserId
+			}
+			if user.Email == "" && loginType == 2 {
+				msql := ` UPDATE wx_user SET email = ?,bind_account = ?  WHERE user_id = ?`
+				_, err = o.Raw(msql, mobile, mobile, user.UserId).Exec()
+				wxUserId = user.UserId
 			}
-			utils.FileLog.Info("用户存在,bind:%s,%d", unionId, wxUserId)
+			utils.FileLog.Info("用户存在,bind:%s,%d,%s", unionId, wxUserId)
 			wxUserId = userId
 		}
 	}

+ 1 - 1
services/annual_report.go

@@ -194,7 +194,7 @@ func CreateAnnualReport() {
 	resp.MaxReadReportCount = maxReadReportCount
 	resp.MaxReadReportDate = maxReadReportDate.Format(utils.FormatDate)
 	resp.LatestReadReportDate = lastestCreateDate
-	resp.LatestReadReportTime = latestTime.Format("15:04:05")
+	resp.LatestReadReportTime = latestTime
 	resp.LatestReadReportDateDuration = VideoPlaySeconds
 	resp.MaxOpenReportClassify = maxOpenReportClassify
 	resp.MaxOpenReportCount = maxOpenReportCount