rdluck 4 anos atrás
pai
commit
9260369a73

+ 66 - 0
controllers/bill.go

@@ -0,0 +1,66 @@
+package controllers
+
+import (
+	"hongze/hongze_api/models"
+)
+
+//年度账单
+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
+	}
+	var realName string
+
+	resp := new(models.BillDetailResp)
+	if user.RealName == "" {
+		realName = user.NickName
+	} else {
+		realName = user.RealName
+	}
+	
+	/*
+	   RealName                     string  `description:"用户实际名称"`
+	   TogetherDay                  int     `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 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
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 29 - 2
controllers/report.go

@@ -301,11 +301,31 @@ func (this *ReportController) ListReport() {
 		hasPermission = true
 	}
 
+	reportType := "rddp"
+	reportPermissionList, err := models.GetReportVarietyListByUserIdExt(user.UserId, reportType) //获取客户拥有权限的报告id
+	if err != nil {
+		if err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取报告详情失败"
+			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+			return
+		} else {
+			hasPermission = false
+		}
+	}
+	if len(reportPermissionList) == 0 {
+		hasPermission = false
+	}
+	permissionMap := make(map[int]int)
+	for _, v := range reportPermissionList {
+		if _, ok := permissionMap[v.ReportChapterTypeId]; !ok {
+			permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId
+		}
+	}
+
 	listLen := len(list)
 	for i := 0; i < listLen; i++ {
 		item := list[i]
-		//list[i].Content = html.UnescapeString(item.Content)
-		//list[i].ContentSub = html.UnescapeString(item.ContentSub)
+
 		count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond)
 		if err != nil {
 			br.Msg = "获取失败"
@@ -322,6 +342,13 @@ func (this *ReportController) ListReport() {
 			list[i].TitleType = "FICC"
 		}
 
+		if _, ok := permissionMap[item.Id]; !ok {
+			list[i].VideoUrl = ""
+			list[i].VideoName = ""
+			list[i].VideoName = ""
+			list[i].VideoPlaySeconds = ""
+		}
+
 		if hasPermission == false {
 			list[i].VideoUrl = ""
 			list[i].VideoName = ""

+ 10 - 3
controllers/user_pc.go

@@ -265,7 +265,7 @@ func (this *UserCommonController) PcLogin() {
 		user.RegisterTime = time.Now()
 		user.LoginTime = time.Now()
 		user.IsFreeLogin = req.IsFreeLogin
-		user.RegisterPlatform=2
+		user.RegisterPlatform = 2
 		lastId, err := models.AddWxUser(user)
 		if err != nil {
 			br.Msg = "登录失败"
@@ -358,13 +358,20 @@ func (this *UserCommonController) PcLogin() {
 	var companyName, status, endDate, productName string
 	for _, v := range cp {
 		companyName = v.CompanyName
+		if v.EndDate=="0000-00-00" {
+			v.EndDate=""
+		}
 		if status != "" {
 			status = status + "/" + v.Status
-			endDate = endDate + "/" + v.EndDate
+			if v.EndDate != "" {
+				endDate = endDate + "/" + v.Status + ":" + v.EndDate
+			}
 			productName = productName + "/" + v.ProductName
 		} else {
 			status = v.Status
-			endDate = v.EndDate
+			if v.EndDate != "" {
+				endDate = v.Status + ":" + v.EndDate
+			}
 			productName = v.ProductName
 		}
 	}

+ 72 - 45
controllers/wechat.go

@@ -1,6 +1,7 @@
 package controllers
 
 import (
+	"encoding/json"
 	"fmt"
 	"hongze/hongze_api/models"
 	"hongze/hongze_api/services"
@@ -42,73 +43,66 @@ func (this *WechatCommonController) WechatLogin() {
 		return
 	}
 	openId := item.Openid
+	accessToken, err := services.WxGetAccessToken()
+	if err != nil {
+		br.Msg = "获取用户信息失败"
+		br.ErrMsg = "获取access_token失败,err:" + err.Error()
+		return
+	}
+	//获取用户信息
+	wxUserInfo, err := services.WxGetUserInfo(openId, accessToken)
+	if err != nil {
+		br.Msg = "获取用户信息失败"
+		br.ErrMsg = "获取微信用户信息失败,Err:" + err.Error()
+		return
+	}
+	if wxUserInfo.Errcode != 0 {
+		userInfoJson, _ := json.Marshal(wxUserInfo)
+		br.Msg = "登录失败"
+		br.ErrMsg = "获取用户信息失败,err:" + string(userInfoJson)
+		return
+	}
+
 	unionid := item.Unionid
+	if unionid == "" {
+		unionid = wxUserInfo.Unionid
+	}
 	firstLogin := 1
 	userId := 0
+	utils.FileLog.Info("openId:%s", openId)
+	utils.FileLog.Info("unionid:%s", unionid)
 	//获取成功
-	if openId != "" {
-		wxUser, err := models.GetWxUserItemByOpenId(openId)
+	if unionid != "" {
+		wxUser, err := models.GetWxUserItemByUnionid(unionid)
 		if err != nil && err.Error() != utils.ErrNoRow() {
 			br.Msg = "获取用户信息失败"
 			br.ErrMsg = "根据openid获取用户信息失败,Eerr:" + err.Error()
 			return
 		}
 		if wxUser == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
-			accessToken, err := services.WxGetAccessToken()
-			if err != nil {
-				br.Msg = "获取用户信息失败"
-				br.ErrMsg = "获取access_token失败,err:" + err.Error()
-				return
-			}
-			//获取用户信息
-			wxUserInfo, err := services.WxGetUserInfo(openId, accessToken)
-			if err != nil {
-				br.Msg = "获取用户信息失败"
-				br.ErrMsg = "获取微信用户信息失败,Err:" + err.Error()
-				return
-			}
-			/*if wxUserInfo.Errcode != 0 {
-				br.Msg = "获取用户信息失败"
-				br.ErrMsg = "获取用户信息失败 errcode:" + item.Errcode + " ;errmsg:" + item.Errmsg
-				return
-			}*/
-			if unionid == "" {
-				unionid = wxUserInfo.Unionid
-			}
 			user := new(models.WxUser)
 			user.OpenId = openId
 			user.CompanyId = 1
 			user.CreatedTime = time.Now()
 			user.UnionId = unionid
 			user.Unionid = unionid
-			user.Subscribe = wxUserInfo.SubscribeScene
-			user.SubscribeTime = wxUserInfo.SubscribeTime
 			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.Remark = wxUserInfo.Remark
 			user.FirstLogin = 1
 			user.Enabled = 1
 			user.RegisterPlatform=1
 			user.RegisterTime = time.Now()
 			_, err = models.AddWxUser(user)
-			if wxUserInfo.Unionid != "" {
-				wxUser, err = models.GetWxUserItemByUnionid(wxUserInfo.Unionid)
-				if err != nil {
-					br.Msg = "获取用户信息失败"
-					br.ErrMsg = "获取微信用户信息失败,Err:" + err.Error()
-					return
-				}
-			} else {
-				wxUser, err = models.GetWxUserItemByOpenId(openId)
-				if err != nil {
-					br.Msg = "获取用户信息失败"
-					br.ErrMsg = "获取微信用户信息失败,Err:" + err.Error()
-					return
-				}
+
+			wxUser, err = models.GetWxUserItemByUnionid(unionid)
+			if err != nil{
+				br.Msg = "获取用户信息失败"
+				br.ErrMsg = "unionid登录,获取微信用户信息失败,Err:" + err.Error()
+				return
 			}
 			userId = wxUser.UserId
 		} else {
@@ -116,6 +110,43 @@ func (this *WechatCommonController) WechatLogin() {
 			userId = wxUser.UserId
 		}
 	} else {
+		if openId!="" {
+			wxUser, err := models.GetWxUserItemByOpenId(openId)
+			if err != nil {
+				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
@@ -214,8 +245,4 @@ func (this *WechatController) GetWxSign() {
 	br.Success = true
 	br.Msg = "获取签名成功"
 	br.Data = resp
-}
-
-/*
-$app->bag('api/wechat/check', "WechatController@check");
-*/
+}

+ 50 - 39
controllers/wechat_pc.go

@@ -97,42 +97,13 @@ func (this *WechatCommonController) PcWechatLogin() {
 			user.RegisterTime = time.Now()
 			user.RegisterPlatform = 2
 			_, err = models.AddWxUser(user)
-			if unionid != "" {
-				wxUser, err = models.GetWxUserItemByUnionid(wxUserInfo.Unionid)
-				if err != nil {
-					br.Msg = "获取用户信息失败"
-					br.ErrMsg = "获取微信用户信息失败,Err:" + err.Error()
-					return
-				}
-			} else {
-				wxUser, err = models.GetWxUserItemByOpenId(openId)
-				if err != nil {
-					br.Msg = "获取用户信息失败"
-					br.ErrMsg = "获取微信用户信息失败,Err:" + err.Error()
-					return
-				}
+			wxUser, err = models.GetWxUserItemByUnionid(wxUserInfo.Unionid)
+			if err != nil {
+				br.Msg = "获取用户信息失败"
+				br.ErrMsg = "获取微信用户信息失败,Err:" + err.Error()
+				return
 			}
 			userId = wxUser.UserId
-			utils.FileLog.Info("注册后获取的用户id:%d", userId)
-			timeUnix := time.Now().Unix()
-			timeUnixStr := strconv.FormatInt(timeUnix, 10)
-			token := utils.MD5(strconv.Itoa(userId)) + utils.MD5(timeUnixStr)
-			//新增session
-			{
-				session := new(models.Session)
-				session.OpenId = openId
-				session.UserId = userId
-				session.CreatedTime = time.Now()
-				session.LastUpdatedTime = time.Now()
-				session.ExpireTime = time.Now().AddDate(0, 1, 0)
-				session.AccessToken = token
-				err = models.AddSession(session)
-				if err != nil {
-					br.Msg = "登录失败"
-					br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
-					return
-				}
-			}
 		} else {
 			utils.FileLog.Info("用户已经存在")
 			firstLogin = wxUser.FirstLogin
@@ -140,9 +111,42 @@ func (this *WechatCommonController) PcWechatLogin() {
 			utils.FileLog.Info("用户已经存在,用户id:%d", userId)
 		}
 	} else {
-		br.Msg = "获取用户信息失败"
-		br.ErrMsg = "获取openid失败,openid:" + item.Openid
-		return
+		if openId!="" {
+			wxUser, err := models.GetWxUserItemByOpenId(openId)
+			if err != nil {
+				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
+			}
+		}
 	}
 
 	permission, err := services.CheckUserPermission(userId)
@@ -193,13 +197,20 @@ func (this *WechatCommonController) PcWechatLogin() {
 	var companyName, status, endDate, productName string
 	for _, v := range cp {
 		companyName = v.CompanyName
+		if v.EndDate == "0000-00-00" {
+			v.EndDate = ""
+		}
 		if status != "" {
 			status = status + "/" + v.Status
-			endDate = endDate + "/" + v.EndDate
+			if v.EndDate != "" {
+				endDate = endDate + "/" + v.Status + ":" + v.EndDate
+			}
 			productName = productName + "/" + v.ProductName
 		} else {
 			status = v.Status
-			endDate = v.EndDate
+			if v.EndDate != "" {
+				endDate = v.Status + ":" + v.EndDate
+			}
 			productName = v.ProductName
 		}
 	}

+ 25 - 0
models/bill.go

@@ -0,0 +1,25 @@
+package models
+
+type BillDetailResp struct {
+	RealName                     string  `description:"用户实际名称"`
+	TogetherDay                  int     `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 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:"连续学习天数"`
+}

+ 3 - 2
models/classify.go

@@ -31,7 +31,7 @@ func GetClassifyById(classifyId int) (item *Classify, err error) {
 }
 
 func GetClassifyList() (item []*Classify, err error) {
-	sql := ` SELECT * FROM classify WHERE parent_id = 0  `
+	sql := ` SELECT * FROM classify WHERE parent_id = 0 AND classify_name<>'权益研报' `
 	o := orm.NewOrm()
 	o.Using("rddp")
 	_, err = o.Raw(sql).QueryRows(&item)
@@ -43,7 +43,8 @@ func GetClassifySecondList(classifyId int) (item []*ClassifyDetail, err error) {
             FROM classify AS a 
 			LEFT JOIN report AS b ON a.id=b.classify_id_second 
 			WHERE a.parent_id = ?
-			GROUP BY a.id  `
+			GROUP BY a.id 
+            ORDER BY create_time ASC `
 	o := orm.NewOrm()
 	o.Using("rddp")
 	_, err = o.Raw(sql, classifyId).QueryRows(&item)

+ 10 - 4
models/wx_user.go

@@ -302,6 +302,12 @@ 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 = ? `
@@ -311,22 +317,22 @@ func PcBindMobile(unionId, mobile string, userId, loginType int) (wxUserId int,
 			}
 			msql := ``
 			if loginType == 1 {
-				msql = ` UPDATE wx_user SET mobile=?,bind_account = ?,created_time=NOW(),register_time=?`
+				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=? `
+				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, user.CompanyId, unionId).Exec()
+				_, err = o.Raw(msql, mobile, mobile, maxRegisterTime,realName, user.CompanyId, unionId).Exec()
 			} else {
-				_, err = o.Raw(msql, mobile, mobile, maxRegisterTime, unionId).Exec()
+				_, err = o.Raw(msql, mobile, mobile, maxRegisterTime,realName, unionId).Exec()
 			}
 			wxUserId = userInfo.UserId
 		} else {

+ 5 - 0
routers/router.go

@@ -71,6 +71,11 @@ func init() {
 				&controllers.VideoController{},
 			),
 		),
+		beego.NSNamespace("/bill",
+			beego.NSInclude(
+				&controllers.BillController{},
+			),
+		),
 	)
 	beego.AddNamespace(ns)
 }