浏览代码

Merge branch 'wx_login' into chart2.0

Roc 3 年之前
父节点
当前提交
a7748f3978

+ 38 - 0
controller/report/research_report.go

@@ -45,3 +45,41 @@ func GetResearchReportInfo(c *gin.Context) {
 	}
 	}
 	response.OkData("获取成功", reportInfo, c)
 	response.OkData("获取成功", reportInfo, c)
 }
 }
+
+// GetResearchReportChapter
+// @Tags 报告接口
+// @Summary  获取报告章节详情
+// @Description 获取报告章节详情
+// @Security ApiKeyAuth
+// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
+// @Accept  json
+// @Product json
+// @Param research_report_type_id query int true "章节ID"
+// @Success 200 {object} yb_activity.ActivityDetail
+// @failure 400 {string} string "获取失败"
+// @Router /report/research_report_chapter [get]
+func GetResearchReportChapter(c *gin.Context) {
+	userInfo := user.GetInfoByClaims(c)
+
+	researchReportTypeIdStr := c.DefaultQuery("research_report_type_id", "")
+	if researchReportTypeIdStr == "" {
+		response.Fail("请传入报告章节id", c)
+		return
+	}
+	researchReportId, tmpErr := strconv.Atoi(researchReportTypeIdStr)
+	if tmpErr != nil {
+		response.Fail("报告章节id异常", c)
+		return
+	}
+
+	reportInfo, hasPermission, err := report.GetResearchReportTypeContentInfo(uint64(researchReportId), userInfo.UserID)
+	if err != nil {
+		response.Fail("获取报告章节失败", c)
+		return
+	}
+	if !hasPermission {
+		response.Fail("无权限", c)
+		return
+	}
+	response.OkData("获取成功", reportInfo, c)
+}

+ 79 - 6
logic/report/research_report.go

@@ -3,9 +3,18 @@ package report
 import (
 import (
 	"hongze/hongze_yb/models/tables/company_report_permission"
 	"hongze/hongze_yb/models/tables/company_report_permission"
 	"hongze/hongze_yb/models/tables/research_report"
 	"hongze/hongze_yb/models/tables/research_report"
+	"hongze/hongze_yb/models/tables/research_report_type"
 	"hongze/hongze_yb/utils"
 	"hongze/hongze_yb/utils"
 )
 )
 
 
+type ResearchReportInfo struct {
+	ResearchReportInfo            *research_report.ResearchReport                     `json:"research_report_info"`
+	ResearchReportTypeList        []*company_report_permission.ResearchReportTypeList `json:"research_report_type_list"`
+	HasMenu                       int                                                 `json:"has_menu"`
+	ResearchReportTypeContentList []*research_report.ResearchReportTypeContent        `description:"报告详情"`
+}
+
+// GetResearchReportInfo 获取报告详情
 func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchReportInfo, hasPermission bool, err error) {
 func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchReportInfo, hasPermission bool, err error) {
 	//获取报告详情
 	//获取报告详情
 	reportInfo, err := research_report.GetByResearchReportId(researchReportId)
 	reportInfo, err := research_report.GetByResearchReportId(researchReportId)
@@ -61,7 +70,7 @@ func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchRepo
 	} else if len(researchReportTypeList) == 1 {
 	} else if len(researchReportTypeList) == 1 {
 		//只有一个章节,即没有目录的时候,需要直接返回章节详情
 		//只有一个章节,即没有目录的时候,需要直接返回章节详情
 		result.HasMenu = 0
 		result.HasMenu = 0
-		researchReportTypeContent, tmpErr := research_report.GetResearchReportTypeContent(researchReportTypeList[0].ResearchReportTypeId)
+		researchReportTypeContent, tmpErr := research_report.GetResearchReportTypeContentList(researchReportTypeList[0].ResearchReportTypeId)
 		if tmpErr != nil {
 		if tmpErr != nil {
 			return
 			return
 		}
 		}
@@ -70,9 +79,73 @@ func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchRepo
 	return
 	return
 }
 }
 
 
-type ResearchReportInfo struct {
-	ResearchReportInfo            *research_report.ResearchReport                     `json:"research_report_info"`
-	ResearchReportTypeList        []*company_report_permission.ResearchReportTypeList `json:"research_report_type_list"`
-	HasMenu                       int                                                 `json:"has_menu"`
-	ResearchReportTypeContentList []*research_report.ResearchReportTypeContent        `description:"报告详情"`
+type ResearchReportTypeContentInfo struct {
+	ResearchReportTypeInfo        *research_report_type.ResearchReportTypeInfo `json:"research_report_type_info"`
+	Add                           int                                          `json:"add"`
+	ResearchReportTypeContentList []*research_report.ResearchReportTypeContent `description:"报告详情" json:"research_report_type_content_list"`
+}
+
+// GetResearchReportTypeContentInfo 获取报告章节详情
+func GetResearchReportTypeContentInfo(researchReportTypeId, userId uint64) (result ResearchReportTypeContentInfo, hasPermission bool, err error) {
+	//获取章节详情
+	researchReportTypeContentList, err := research_report.GetResearchReportTypeContentList(researchReportTypeId)
+	if err != nil {
+		return
+	}
+	researchReportTypeInfo, err := research_report_type.GetResearchReportTypeInfo(researchReportTypeId)
+	//获取报告详情
+	reportInfo, err := research_report.GetByResearchReportId(researchReportTypeInfo.ResearchReportID)
+	if err != nil {
+		return
+	}
+	reportType := reportInfo.Type
+
+	//这些个报告需要做权限校验
+	if utils.InArray(reportInfo.Type, []string{"week", "month", "two_week", "other"}) {
+		list, tmpErr := company_report_permission.GetReportVarietyList(userId, reportType)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+
+		if reportInfo.Type == "week" {
+			//周报校验章节是否在权限内
+			for _, v := range list {
+				if researchReportTypeInfo.ReportChapterTypeId == v.ReportChapterTypeId {
+					hasPermission = true
+					break
+				}
+			}
+		} else {
+			//双周报和月报校验 类型是否在权限内
+			for _, v := range list {
+				if reportInfo.ResearchReportID == v.ReportChapterTypeId {
+					hasPermission = true
+					break
+				}
+			}
+		}
+
+		if !hasPermission {
+			//permissionName, tmpErr := company_report_permission.GetPermissionNameByReportId(reportInfo.ResearchReportID, reportType)
+			//if tmpErr != nil {
+			//	err = tmpErr
+			//	return
+			//}
+			return
+		}
+	} else {
+		hasPermission = true
+	}
+	add := 1
+	if len(researchReportTypeContentList) > 0 {
+		add = 0
+	}
+
+	result = ResearchReportTypeContentInfo{
+		ResearchReportTypeContentList: researchReportTypeContentList,
+		ResearchReportTypeInfo:        researchReportTypeInfo,
+		Add:                           add,
+	}
+	return
 }
 }

+ 2 - 2
models/tables/research_report/custom_query.go

@@ -17,8 +17,8 @@ type ResearchReportTypeContent struct {
 	LastUpdatedTime             time.Time `json:"last_updated_time" description:"最近一次更新时间"`
 	LastUpdatedTime             time.Time `json:"last_updated_time" description:"最近一次更新时间"`
 }
 }
 
 
-// GetResearchReportTypeContent 获取研究报告章节详情
-func GetResearchReportTypeContent(researchReportTypeId uint64) (items []*ResearchReportTypeContent, err error) {
+// GetResearchReportTypeContentList 获取研究报告章节详情
+func GetResearchReportTypeContentList(researchReportTypeId uint64) (items []*ResearchReportTypeContent, err error) {
 	sql := `select rrt.research_report_type_title,rrtc.*,rrt.research_report_type_id
 	sql := `select rrt.research_report_type_title,rrtc.*,rrt.research_report_type_id
 from research_report_type rrt
 from research_report_type rrt
 inner join research_report_type_content rrtc on rrtc.research_report_type_id = rrt.research_report_type_id
 inner join research_report_type_content rrtc on rrtc.research_report_type_id = rrt.research_report_type_id

+ 26 - 0
models/tables/research_report_type/custom_query.go

@@ -0,0 +1,26 @@
+package research_report_type
+
+import (
+	"hongze/hongze_yb/global"
+)
+
+type ResearchReportTypeInfo struct {
+	ResearchReportTypeTitle string `json:"research_report_type_title" description:"研究报告标题"`
+	BannerUrl               string `json:"banner_url" description:"banner url"`
+	ReportChapterTypeName   string `json:"report_chapter_type_name" description:"章节名称"`
+	ResearchReportID        uint64 `json:"research_report_id" description:"报告id"`
+	ResearchReportTypeID    uint64 `json:"research_report_type_id" description:"研究报告id"`
+	TypeID                  int    `json:"type_id" description:"分类id"`
+	ReportChapterTypeId     uint64 `json:"report_chapter_type_id" description:"章节名称"`
+}
+
+// GetResearchReportTypeInfo 获取研究报告类型详情
+func GetResearchReportTypeInfo(researchReportTypeId uint64) (item *ResearchReportTypeInfo, err error) {
+	sql := ` select rrt.research_report_type_title,rct.banner_url,rct.report_chapter_type_name,rrt.research_report_id,rrt.research_report_type_id,rrt.type_id,rct.report_chapter_type_name,rct.report_chapter_type_id
+            from research_report_type rrt
+            left join report_chapter_type rct on rct.report_chapter_type_id = rrt.type_id
+            where rrt.research_report_type_id =? limit 1`
+
+	err = global.DEFAULT_MYSQL.Raw(sql, researchReportTypeId).Scan(&item).Error
+	return
+}

+ 6 - 0
models/tables/user_record/query.go

@@ -25,3 +25,9 @@ func GetUserThirdRecordByUserId(userId int) (item *UserRecord, err error) {
 	err = global.DEFAULT_MYSQL.Where("user_id = ? ", userId).Order("user_record_id asc").First(&item).Error
 	err = global.DEFAULT_MYSQL.Where("user_id = ? ", userId).Order("user_record_id asc").First(&item).Error
 	return
 	return
 }
 }
+
+// GetFirstByUnionID 根据用户UnionID获取最小平台的用户关系(已经绑定了user_id的)
+func GetFirstByUnionID(unionID string) (item *UserRecord, err error) {
+	err = global.DEFAULT_MYSQL.Where("union_id = ? and user_id>0", unionID).Order("create_platform asc").First(&item).Error
+	return
+}

+ 1 - 0
routers/research_report.go

@@ -11,5 +11,6 @@ func InitResearchReport(r *gin.Engine) {
 	rGroup := r.Group("report").Use(middleware.Token())
 	rGroup := r.Group("report").Use(middleware.Token())
 	{
 	{
 		rGroup.GET("/research_report", report.GetResearchReportInfo)
 		rGroup.GET("/research_report", report.GetResearchReportInfo)
+		rGroup.GET("/research_report_chapter", report.GetResearchReportChapter)
 	}
 	}
 }
 }

+ 58 - 2
services/user/user.go

@@ -171,6 +171,62 @@ func GetWxUserItemByUnionId(unionId string, platform int) (userInfo UserInfo, er
 	return
 	return
 }
 }
 
 
+// GetFirstWxUserItemByUnionId 根据用户unionid获取最小平台的用户信息(已经绑定了user_id的)
+func GetFirstWxUserItemByUnionId(unionId string) (userInfo UserInfo, err error) {
+	// 获取用户信息
+	userRecord, userRecordErr := user_record.GetFirstByUnionID(unionId)
+	if userRecordErr != nil {
+		if userRecordErr == utils.ErrNoRow {
+			err = ERR_NO_USER_RECORD
+			return
+		} else {
+			err = userRecordErr
+			return
+		}
+	}
+
+	// 该union在系统中没有关联关系
+	if userRecord == nil {
+		err = ERR_NO_USER_RECORD
+		return
+	}
+
+	// 该openid没有绑定用户
+	if userRecord.UserID <= 0 {
+		err = ERR_USER_NOT_BIND
+		item := new(wx_user.WxUser)
+		//格式化返回用户数据
+		userInfo = formatWxUserAndUserRecord(item, userRecord)
+		return
+	}
+
+	item, wxUserErr := wx_user.GetByUserId(userRecord.UserID)
+	if wxUserErr != nil {
+		err = wxUserErr
+
+		// 如果是找不到数据,那么可能是该用户被删除了,但是user_record没有删除对应的关系
+		if wxUserErr == utils.ErrNoRow {
+			// 用户被删除了,但是user_record没有删除对应的关系,那么去解除绑定
+			userUnbindErr := user_record.UnBindUserRecordByUnionId(unionId, int(userRecord.CreatePlatform))
+			if userUnbindErr != nil {
+				err = userUnbindErr
+				return
+			}
+			// 返回状态为用户未绑定
+			err = ERR_USER_NOT_BIND
+			item := new(wx_user.WxUser)
+			// 格式化返回用户数据
+			userInfo = formatWxUserAndUserRecord(item, userRecord)
+			return
+		}
+		return
+	}
+	// 格式化返回用户数据
+	userInfo = formatWxUserAndUserRecord(item, userRecord)
+
+	return
+}
+
 // formatWxUserAndUserRecord 通过用户 关系表记录  和  用户记录  格式化返回 用户数据
 // formatWxUserAndUserRecord 通过用户 关系表记录  和  用户记录  格式化返回 用户数据
 func formatWxUserAndUserRecord(wxUser *wx_user.WxUser, userRecord *user_record.UserRecord) (userInfo UserInfo) {
 func formatWxUserAndUserRecord(wxUser *wx_user.WxUser, userRecord *user_record.UserRecord) (userInfo UserInfo) {
 	wxUser.OpenID = userRecord.OpenID
 	wxUser.OpenID = userRecord.OpenID
@@ -229,8 +285,8 @@ QUERY_WX_USER:
 		//插入成功后,需要重新查询该用户,并进入下面的逻辑
 		//插入成功后,需要重新查询该用户,并进入下面的逻辑
 		goto QUERY_WX_USER
 		goto QUERY_WX_USER
 	} else if wxUserErr == ERR_USER_NOT_BIND {
 	} else if wxUserErr == ERR_USER_NOT_BIND {
-		// 未绑定则去查询是否为弘则研究公众号用户,有相应的手机号邮箱信息则自动绑定
-		platformUser, platformErr := GetWxUserItemByUnionId(unionId, 1)
+		// 未绑定则去查询unionId是否已经绑定了用户(其他平台,不区分平台),有相应的手机号邮箱信息则自动绑定
+		platformUser, platformErr := GetFirstWxUserItemByUnionId(unionId)
 		if platformErr == nil {
 		if platformErr == nil {
 			// 当公众号用户存在时
 			// 当公众号用户存在时
 			if platformUser.Mobile != "" || platformUser.Email != "" {
 			if platformUser.Mobile != "" || platformUser.Email != "" {

+ 13 - 3
services/user/user_bind.go

@@ -52,10 +52,12 @@ func BindWxUser(openid, mobile, email, code string, bindType, areaNum, registerP
 		return
 		return
 	}
 	}
 
 
-	userInfo, err = bindWxUser(openid, mobile, email, areaNum, registerPlatform)
+	userInfo, errMsg, err = bindWxUser(openid, mobile, email, areaNum, registerPlatform)
 
 
 	if err != nil {
 	if err != nil {
-		errMsg = "绑定失败:" + err.Error()
+		if errMsg == `` {
+			errMsg = "绑定失败:" + err.Error()
+		}
 		return
 		return
 	}
 	}
 
 
@@ -117,7 +119,7 @@ func BindWxUser(openid, mobile, email, code string, bindType, areaNum, registerP
 }
 }
 
 
 // bindWxUser 用户注册/绑定
 // bindWxUser 用户注册/绑定
-func bindWxUser(openid, mobile, email string, areaNum, registerPlatform int) (userInfo UserInfo, err error) {
+func bindWxUser(openid, mobile, email string, areaNum, registerPlatform int) (userInfo UserInfo, errMsg string, err error) {
 	var source int8
 	var source int8
 	source = 6 //绑定来源,1:微信端,2:pc网页端,3:查研观向小程序,4:每日咨询
 	source = 6 //绑定来源,1:微信端,2:pc网页端,3:查研观向小程序,4:每日咨询
 	if mobile == "" && email == "" {
 	if mobile == "" && email == "" {
@@ -205,6 +207,14 @@ func bindWxUser(openid, mobile, email string, areaNum, registerPlatform int) (us
 	//如果存在该手机号/邮箱,那么需要校验
 	//如果存在该手机号/邮箱,那么需要校验
 	if userRecord.UserID > 0 && userRecord.UserID != userId {
 	if userRecord.UserID > 0 && userRecord.UserID != userId {
 		err = errors.New(fmt.Sprint("用户已绑定其他账户,已绑定的用户编号:", userRecord.UserID, ",不允许重复绑定"))
 		err = errors.New(fmt.Sprint("用户已绑定其他账户,已绑定的用户编号:", userRecord.UserID, ",不允许重复绑定"))
+		currUser, tmpErr := wx_user.GetByUserId(userRecord.UserID)
+		if tmpErr != utils.ErrNoRow {
+			currBindAccount := currUser.Mobile
+			if currBindAccount == `` {
+				currBindAccount = currUser.Email
+			}
+			errMsg = "微信已绑定其它账户:" + currBindAccount
+		}
 		return
 		return
 	}
 	}
 	if userRecord.UserID == 0 {
 	if userRecord.UserID == 0 {