Browse Source

新增pc端接口

rdluck 4 years ago
parent
commit
ff160e35bd

+ 1 - 1
controllers/base_auth.go

@@ -101,7 +101,7 @@ func (c *BaseAuthController) ServeJSON(encoding ...bool) {
 		return
 		return
 	}
 	}
 	baseRes := c.Data["json"].(*models.BaseResponse)
 	baseRes := c.Data["json"].(*models.BaseResponse)
-	if baseRes != nil && baseRes.Ret != 200 && baseRes.Ret != 408 {
+	if baseRes != nil && baseRes.Ret != 200 && baseRes.Ret != 408 && baseRes.IsSendEmail {
 		body, _ := json.Marshal(baseRes)
 		body, _ := json.Marshal(baseRes)
 		go utils.SendEmail(utils.APPNAME+" "+utils.RunMode+" 失败提醒", "URI:"+c.Ctx.Input.URI()+"<br/> ErrMsg:"+baseRes.ErrMsg+";<br/>Msg:"+baseRes.Msg+";<br/> Body:"+string(body), utils.EmailSendToUsers)
 		go utils.SendEmail(utils.APPNAME+" "+utils.RunMode+" 失败提醒", "URI:"+c.Ctx.Input.URI()+"<br/> ErrMsg:"+baseRes.ErrMsg+";<br/>Msg:"+baseRes.Msg+";<br/> Body:"+string(body), utils.EmailSendToUsers)
 	}
 	}

+ 48 - 1
controllers/base_common.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"encoding/json"
 	"net/http"
 	"net/http"
 	"net/url"
 	"net/url"
+	"strconv"
 
 
 	"github.com/astaxie/beego"
 	"github.com/astaxie/beego"
 
 
@@ -13,6 +14,8 @@ import (
 
 
 type BaseCommonController struct {
 type BaseCommonController struct {
 	beego.Controller
 	beego.Controller
+	User  *models.WxUserItem
+	Token string
 }
 }
 
 
 func (this *BaseCommonController) Prepare() {
 func (this *BaseCommonController) Prepare() {
@@ -25,6 +28,50 @@ func (this *BaseCommonController) Prepare() {
 	}
 	}
 	ip := this.Ctx.Input.IP()
 	ip := this.Ctx.Input.IP()
 	apiLog.Println("请求地址:", this.Ctx.Input.URI(), "RequestBody:", requestBody, "IP:", ip)
 	apiLog.Println("请求地址:", this.Ctx.Input.URI(), "RequestBody:", requestBody, "IP:", ip)
+
+	authorization := this.Ctx.Input.Header("Authorization")
+	if authorization == "" {
+		cookie := this.Ctx.GetCookie("rddp_access_token")
+		utils.FileLog.Info("authorization:%s,cookie:%s", authorization, cookie)
+		authorization = cookie
+	}
+
+	if authorization != "" {
+		session, err := models.GetSessionByToken(authorization)
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				this.JSON(models.BaseResponse{Ret: 408, Msg: "信息已变更,请重新登陆!", ErrMsg: "Token 信息已变更:Token: " + authorization}, false, false)
+				this.StopRun()
+				return
+			}
+			this.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "获取用户信息异常,Eerr:" + err.Error()}, false, false)
+			this.StopRun()
+			return
+		}
+		if session == nil {
+			this.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "sesson is empty "}, false, false)
+			this.StopRun()
+			return
+		}
+		wxUser, err := models.GetWxUserItemByUserId(session.UserId)
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				this.JSON(models.BaseResponse{Ret: 408, Msg: "信息已变更,请重新登陆!", ErrMsg: "获取admin 信息失败 " + strconv.Itoa(session.UserId)}, false, false)
+				this.StopRun()
+				return
+			}
+			this.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "获取wx_user信息异常,Eerr:" + err.Error()}, false, false)
+			this.StopRun()
+			return
+		}
+		if wxUser == nil {
+			this.JSON(models.BaseResponse{Ret: 408, Msg: "网络异常,请稍后重试!", ErrMsg: "admin is empty "}, false, false)
+			this.StopRun()
+			return
+		}
+		this.User = wxUser
+	}
+	this.Token=authorization
 }
 }
 
 
 func (c *BaseCommonController) ServeJSON(encoding ...bool) {
 func (c *BaseCommonController) ServeJSON(encoding ...bool) {
@@ -43,7 +90,7 @@ func (c *BaseCommonController) ServeJSON(encoding ...bool) {
 		return
 		return
 	}
 	}
 	baseRes := c.Data["json"].(*models.BaseResponse)
 	baseRes := c.Data["json"].(*models.BaseResponse)
-	if baseRes != nil && !baseRes.Success {
+	if baseRes != nil && !baseRes.Success && baseRes.IsSendEmail {
 		go utils.SendEmail(utils.APPNAME+" "+utils.RunMode+" 失败提醒", "URI:"+c.Ctx.Input.URI()+" ErrMsg:"+baseRes.ErrMsg+";Msg"+baseRes.Msg, utils.EmailSendToUsers)
 		go utils.SendEmail(utils.APPNAME+" "+utils.RunMode+" 失败提醒", "URI:"+c.Ctx.Input.URI()+" ErrMsg:"+baseRes.ErrMsg+";Msg"+baseRes.Msg, utils.EmailSendToUsers)
 	}
 	}
 	c.JSON(c.Data["json"], hasIndent, hasEncoding)
 	c.JSON(c.Data["json"], hasIndent, hasEncoding)

+ 47 - 3
controllers/classify.go

@@ -1,6 +1,8 @@
 package controllers
 package controllers
 
 
-import "hongze/hongze_api/models"
+import (
+	"hongze/hongze_api/models"
+)
 
 
 type ClassifyController struct {
 type ClassifyController struct {
 	BaseAuthController
 	BaseAuthController
@@ -13,7 +15,7 @@ type ClassifyCommonController struct {
 // @Title 获取分类详情信息
 // @Title 获取分类详情信息
 // @Description 获取分类详情信息接口
 // @Description 获取分类详情信息接口
 // @Param   ClassifyId   query   int  true       "分类id"
 // @Param   ClassifyId   query   int  true       "分类id"
-// @Success 200 {object} models.Classify
+// @Success 200 {object} models.ClassifyDetail
 // @router /detail [get]
 // @router /detail [get]
 func (this *ClassifyController) Detail() {
 func (this *ClassifyController) Detail() {
 	br := new(models.BaseResponse).Init()
 	br := new(models.BaseResponse).Init()
@@ -32,12 +34,19 @@ func (this *ClassifyController) Detail() {
 		br.ErrMsg = "参数错误,分类id小于等于0"
 		br.ErrMsg = "参数错误,分类id小于等于0"
 		return
 		return
 	}
 	}
-	item, err := models.GetClassifyById(classifyId)
+	item, err := models.GetClassifyDetailById(classifyId)
 	if err != nil {
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取信息失败,Err:" + err.Error()
 		br.ErrMsg = "获取信息失败,Err:" + err.Error()
 		return
 		return
 	}
 	}
+	commentList, err := models.GetCustomerComment()
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+	item.CommentList = commentList
 	br.Ret = 200
 	br.Ret = 200
 	br.Success = true
 	br.Success = true
 	br.Msg = "获取数据成功"
 	br.Msg = "获取数据成功"
@@ -65,3 +74,38 @@ func (this *ClassifyCommonController) List() {
 	br.Msg = "获取数据成功"
 	br.Msg = "获取数据成功"
 	br.Data = item
 	br.Data = item
 }
 }
+
+
+// @Title 获取二级分类列表
+// @Description 获取二级分类列表接口
+// @Param   ClassifyId   query   int  true       "分类id"
+// @Success 200 {object} models.ClassifyDetail
+// @router /pc/second/list [get]
+func (this *ClassifyCommonController) SecondList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	classifyId, err := this.GetInt("ClassifyId")
+	if err != nil {
+		br.Msg = "参数获取失败"
+		br.ErrMsg = "参数获取失败,Err:" + err.Error()
+		return
+	}
+	if classifyId <= 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,分类id小于等于0"
+		return
+	}
+	item, err := models.GetClassifySecondList(classifyId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取数据成功"
+	br.Data = item
+}

+ 1 - 69
controllers/home.go

@@ -3,8 +3,6 @@ package controllers
 import (
 import (
 	"hongze/hongze_api/models"
 	"hongze/hongze_api/models"
 	"hongze/hongze_api/services"
 	"hongze/hongze_api/services"
-	"hongze/hongze_api/utils"
-	"rdluck_tools/paging"
 )
 )
 
 
 //首页
 //首页
@@ -63,7 +61,7 @@ func (this *HomeController) ListBanner() {
 		this.Data["json"] = br
 		this.Data["json"] = br
 		this.ServeJSON()
 		this.ServeJSON()
 	}()
 	}()
-	list, err := models.GetHomeBannerList()
+	list, err := models.GetHomeBannerList("")
 	if err != nil {
 	if err != nil {
 		br.Msg = "获取数据失败"
 		br.Msg = "获取数据失败"
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
@@ -74,69 +72,3 @@ func (this *HomeController) ListBanner() {
 	br.Msg = "获取数据成功"
 	br.Msg = "获取数据成功"
 	br.Data = list
 	br.Data = list
 }
 }
-
-// @Title pc-首页列表接口
-// @Description pc-首页列表接口
-// @Param   PageSize   query   int  true       "每页数据条数"
-// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
-// @Param   ClassifyId   query   int  true       "分类id"
-// @Success 200 {object} models.PcListHomeResp
-// @router /pc/list [get]
-func (this *HomeCommonController) ListHome() {
-	br := new(models.BaseResponse).Init()
-	defer func() {
-		this.Data["json"] = br
-		this.ServeJSON()
-	}()
-	authorization := this.Ctx.Input.Header("Authorization")
-	pageSize, _ := this.GetInt("PageSize")
-	currentIndex, _ := this.GetInt("CurrentIndex")
-
-	var startSize int
-	if pageSize <= 0 {
-		pageSize = utils.PageSize20
-	}
-	if currentIndex <= 0 {
-		currentIndex = 1
-	}
-	startSize = paging.StartIndex(currentIndex, pageSize)
-
-	classifyId, _ := this.GetInt("ClassifyId")
-	if classifyId <= 0 {
-		br.Msg = "参数错误"
-		br.ErrMsg = "参数错误"
-		return
-	}
-	total, err := models.PcListHomeCount(classifyId)
-	if err != nil {
-		br.Msg = "获取数据失败"
-		br.ErrMsg = "获取数据失败,Err:" + err.Error()
-		return
-	}
-	list, err := models.PcListHome(classifyId, startSize, pageSize)
-	if err != nil {
-		br.Msg = "获取数据失败"
-		br.ErrMsg = "获取数据失败,Err:" + err.Error()
-		return
-	}
-	for i := 0; i < len(list); i++ {
-		item := list[i]
-		if item.ClassifyName == "权益研报" {
-			list[i].ReportInfo.TitleType = "权益"
-		} else {
-			list[i].ReportInfo.TitleType = "FICC"
-		}
-
-		if authorization == "" {
-			list[i].ReportInfo.VideoUrl = ""
-		}
-	}
-	page := paging.GetPaging(currentIndex, pageSize, total)
-	resp := new(models.PcListHomeResp)
-	resp.Paging = page
-	resp.List = list
-	br.Ret = 200
-	br.Success = true
-	br.Msg = "获取数据成功"
-	br.Data = resp
-}

+ 119 - 0
controllers/home_pc.go

@@ -0,0 +1,119 @@
+package controllers
+
+import (
+	"hongze/hongze_api/models"
+	"hongze/hongze_api/utils"
+	"rdluck_tools/paging"
+)
+
+// @Title 首页专栏接口
+// @Description 首页专栏接口
+// @Success 200 {object} models.Classify
+// @router /pc/column/list [get]
+func (this *HomeCommonController) PcColumnList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	list, err := models.GetColumnList()
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取数据成功"
+	br.Data = list
+}
+
+// @Title pc-首页列表接口
+// @Description pc-首页列表接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   ClassifyId   query   int  true       "分类id"
+// @Success 200 {object} models.PcListHomeResp
+// @router /pc/list [get]
+func (this *HomeCommonController) ListHome() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+
+	classifyId, _ := this.GetInt("ClassifyId")
+	if classifyId <= 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误"
+		return
+	}
+	total, err := models.PcListHomeCount(classifyId)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	list, err := models.PcListHome(classifyId, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	for i := 0; i < len(list); i++ {
+		item := list[i]
+		if item.ClassifyName == "权益研报" {
+			list[i].ReportInfo.TitleType = "权益"
+		} else {
+			list[i].ReportInfo.TitleType = "FICC"
+		}
+
+		if this.Token == "" {
+			list[i].ReportInfo.VideoUrl = ""
+			list[i].ReportInfo.VideoName = ""
+			list[i].ReportInfo.VideoPlaySeconds = ""
+			list[i].ReportInfo.VideoSize = ""
+		}
+	}
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp := new(models.PcListHomeResp)
+	resp.Paging = page
+	resp.List = list
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取数据成功"
+	br.Data = resp
+}
+
+// @Title 首页列表接口
+// @Description 首页列表接口
+// @Success 200 {object} models.Banner
+// @router /pc/banner [get]
+func (this *HomeCommonController) PcListBanner() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	list, err := models.GetHomeBannerList("pc")
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取数据成功"
+	br.Data = list
+}

+ 23 - 7
controllers/report.go

@@ -14,6 +14,11 @@ type ReportController struct {
 	BaseAuthController
 	BaseAuthController
 }
 }
 
 
+//报告
+type ReportCommonController struct {
+	BaseCommonController
+}
+
 // @Title 日评详情
 // @Title 日评详情
 // @Description 日评详情接口
 // @Description 日评详情接口
 // @Param   ReportId   query   int  true       "报告id"
 // @Param   ReportId   query   int  true       "报告id"
@@ -45,7 +50,9 @@ func (this *ReportController) Detail() {
 		br.ErrMsg = "参数错误,报告id小于等于0"
 		br.ErrMsg = "参数错误,报告id小于等于0"
 		return
 		return
 	}
 	}
+
 	report, err := models.GetReportById(reportId)
 	report, err := models.GetReportById(reportId)
+
 	if err != nil {
 	if err != nil {
 		br.Msg = "获取报告详情失败"
 		br.Msg = "获取报告详情失败"
 		br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
 		br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
@@ -59,12 +66,11 @@ func (this *ReportController) Detail() {
 	report.Content = html.UnescapeString(report.Content)
 	report.Content = html.UnescapeString(report.Content)
 
 
 	productId := 0
 	productId := 0
-	if report.ClassifyNameSecond == "近期路演精华" {
+	if report.ClassifyName == "权益研报" {
 		productId = 2
 		productId = 2
 	} else {
 	} else {
 		productId = 1
 		productId = 1
 	}
 	}
-
 	company, err := models.GetCompanyProductById(user.CompanyId, productId)
 	company, err := models.GetCompanyProductById(user.CompanyId, productId)
 	if err != nil {
 	if err != nil {
 		if err.Error() != utils.ErrNoRow() {
 		if err.Error() != utils.ErrNoRow() {
@@ -89,13 +95,14 @@ func (this *ReportController) Detail() {
 			report.Content = report.ContentSub
 			report.Content = report.ContentSub
 		}
 		}
 	}
 	}
+
 	if productId == 1 {
 	if productId == 1 {
 		reportType := "rddp"
 		reportType := "rddp"
-		reportPermissionList, err := models.GetReportVarietyListByUserIdExt(user.UserId, reportType)
+		reportPermissionList, err := models.GetReportVarietyListByUserIdExt(user.UserId, reportType) //获取客户拥有权限的报告id
 		if err != nil {
 		if err != nil {
 			if err.Error() != utils.ErrNoRow() {
 			if err.Error() != utils.ErrNoRow() {
 				br.Msg = "获取报告详情失败"
 				br.Msg = "获取报告详情失败"
-				br.ErrMsg = "获取用户管理企业信息失败,Err:" + err.Error()
+				br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
 				return
 				return
 			} else {
 			} else {
 				status = 2
 				status = 2
@@ -114,6 +121,7 @@ func (this *ReportController) Detail() {
 				permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId
 				permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId
 			}
 			}
 		}
 		}
+
 		if _, ok := permissionMap[reportId]; !ok {
 		if _, ok := permissionMap[reportId]; !ok {
 			tips := ""
 			tips := ""
 			status = 2
 			status = 2
@@ -194,6 +202,14 @@ func (this *ReportController) Detail() {
 		}
 		}
 	}
 	}
 	resp.RecommendList = recommendList
 	resp.RecommendList = recommendList
+
+	item, err := models.GetClassifyDetailById(report.ClassifyIdSecond)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取详情专栏失败,Err:" + err.Error()
+		return
+	}
+	resp.Classify = item
 	br.Ret = 200
 	br.Ret = 200
 	br.Success = true
 	br.Success = true
 	br.Msg = "获取成功"
 	br.Msg = "获取成功"
@@ -255,8 +271,8 @@ func (this *ReportController) ListReport() {
 	listLen := len(list)
 	listLen := len(list)
 	for i := 0; i < listLen; i++ {
 	for i := 0; i < listLen; i++ {
 		item := list[i]
 		item := list[i]
-		list[i].Content = html.UnescapeString(item.Content)
-		list[i].ContentSub = html.UnescapeString(item.ContentSub)
+		//list[i].Content = html.UnescapeString(item.Content)
+		//list[i].ContentSub = html.UnescapeString(item.ContentSub)
 		count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond)
 		count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond)
 		if err != nil {
 		if err != nil {
 			br.Msg = "获取失败"
 			br.Msg = "获取失败"
@@ -465,4 +481,4 @@ func (this *ReportController) AuthorDetail() {
 	br.Success = true
 	br.Success = true
 	br.Msg = "获取成功"
 	br.Msg = "获取成功"
 	br.Data = author
 	br.Data = author
-}
+}

+ 135 - 0
controllers/report_pc.go

@@ -0,0 +1,135 @@
+package controllers
+
+import (
+	"hongze/hongze_api/models"
+)
+
+// @Title 研报列表
+// @Description 研报列表接口
+// @Param   ClassifyId   query   int  true       "分类id"
+// @Success 200 {object} models.ResearchReportListResp
+// @router /pc/research/report/list [get]
+func (this *ReportCommonController) ResearchReportList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	classifyId, _ := this.GetInt("ClassifyId")
+	if classifyId <= 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,分类id小于等于0"
+		return
+	}
+	list, err := models.GetResearchReportList(classifyId)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.ResearchReportListResp)
+	resp.List = list
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title 研报PC端搜索接口
+// @Param   KeyWord   query   string  true       "搜索关键词"
+// @Success 200 {object} models.PcSearchReportListResp
+// @router /pc/search/report/list [get]
+func (this *ReportCommonController) PcSearchReportList() {
+	// @Description 研报PC端搜索接口
+	// @Param   PageSize   query   int  true       "每页数据条数"
+	// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	keyWord := this.GetString("KeyWord")
+
+	//pageSize, _ := this.GetInt("PageSize")
+	//currentIndex, _ := this.GetInt("CurrentIndex")
+	//classifyId, _ := this.GetInt("ClassifyId")
+	//if classifyId <= 0 {
+	//	br.Msg = "参数错误"
+	//	br.ErrMsg = "参数错误,分类id小于等于0"
+	//	return
+	//}
+	//
+	//page := paging.GetPaging(currentIndex, pageSize, 0)
+	resp := new(models.PcSearchReportListResp)
+	var condition string
+	//var pars []interface{}
+
+	if keyWord != "" {
+		condition += ` AND (a.title LIKE '%` + keyWord + `%' OR a.abstract LIKE '%` + keyWord + `%') `
+	} else {
+		list := make([]*models.ReportList, 0)
+		resp.List = list
+		//resp.Paging = page
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		br.Data = resp
+		return
+	}
+
+	//var startSize int
+	//if pageSize <= 0 {
+	//	pageSize = utils.PageSize20
+	//}
+	//if currentIndex <= 0 {
+	//	currentIndex = 1
+	//}
+	//startSize = utils.StartIndex(currentIndex, pageSize)
+
+	//total, err := models.GetSearchReportListCount(condition)
+	//if err != nil {
+	//	br.Msg = "获取数据失败"
+	//	br.ErrMsg = "获取数据失败,Err:" + err.Error()
+	//	return
+	//}
+
+	list, err := models.GetSearchReportList(condition)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	listLen := len(list)
+	for i := 0; i < listLen; i++ {
+		item := list[i]
+		if this.Token != "" {
+			count, err := models.GetReportPermission(this.User.UserId, item.ClassifyNameSecond)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "判断报告是否拥有权限失败,Err:" + err.Error()
+				return
+			}
+			if count > 0 {
+				list[i].HasPermission = 1
+			}
+		}else{
+			list[i].VideoUrl = ""
+			list[i].VideoName = ""
+			list[i].VideoPlaySeconds = ""
+			list[i].VideoSize = ""
+		}
+		if item.ClassifyNameFirst == "权益研报" {
+			list[i].TitleType = "图说逻辑"
+		} else {
+			list[i].TitleType = "FICC"
+		}
+	}
+	//page = paging.GetPaging(currentIndex, pageSize, total)
+	resp.List = list
+	//resp.Paging = page
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 337 - 38
controllers/user_pc.go

@@ -46,7 +46,7 @@ func (this *UserCommonController) GetGraphicVerifyCode() {
 	item := new(models.GraphicVerifyCode)
 	item := new(models.GraphicVerifyCode)
 	item.VerifyId = verifyId
 	item.VerifyId = verifyId
 	item.VerifyCode = char.CaptchaItem.VerifyValue
 	item.VerifyCode = char.CaptchaItem.VerifyValue
-	item.CreateTime=time.Now()
+	item.CreateTime = time.Now()
 	err := models.AddGraphicVerifyCode(item)
 	err := models.AddGraphicVerifyCode(item)
 	if err != nil {
 	if err != nil {
 		br.Msg = "获取失败"
 		br.Msg = "获取失败"
@@ -62,12 +62,84 @@ func (this *UserCommonController) GetGraphicVerifyCode() {
 	br.Success = true
 	br.Success = true
 }
 }
 
 
+// @Title pc端获取短信验证码
+// @Description pc端获取短信验证码接口
+// @Param   Mobile   query   string  true       "手机号码"
+// @Param   AreaNum   query   string  true       "地区编码"
+// @Param   VerifyId   query   string  true       "图形验证码id"
+// @Param   VerifyCode   query   string  true       "图形验证码code"
+// @Success Ret=200 获取成功
+// @router /pc/getSmsCode [get]
+func (this *UserCommonController) PcGetSmsCode() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	mobile := this.GetString("Mobile")
+	if mobile == "" {
+		br.Msg = "请输入手机号"
+		return
+	}
+	areaNum := this.GetString("AreaNum")
+	msgCode := utils.GetRandDigit(4)
+	verifyId := this.GetString("VerifyId")
+	verifyCode := this.GetString("VerifyCode")
+
+	item, err := models.GetGraphicVerifyById(verifyId)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "验证码不存在,请刷新页面!"
+			return
+		}
+		br.Msg = "校验验证码失败!"
+		return
+	}
+	if item.VerifyCode != verifyCode {
+		br.Msg = "验证码错误,请重新输入!"
+		return
+	}
+	checkoutTime := time.Now().Add(15 * time.Minute)
+	if item.CreateTime.After(checkoutTime) {
+		br.Msg = "验证码过期,请重新输入!"
+		return
+	}
+
+	var result bool
+	if areaNum == "86" || areaNum == "" || areaNum == "0" {
+		result = services.SendSmsCode(mobile, msgCode)
+	} else {
+		result = services.SendSmsCodeGj(mobile, msgCode, areaNum)
+	}
+	//发送成功
+	if result {
+		item := new(models.MsgCode)
+		item.OpenId = ""
+		item.Code = msgCode
+		item.Mobile = mobile
+		item.ExpiredIn = time.Now().Add(15 * time.Minute).Unix()
+		item.Enabled = 1
+		item.CreatedTime = time.Now()
+		err := models.AddMsgCode(item)
+		if err != nil {
+			br.Msg = "发送失败"
+			br.ErrMsg = "发送失败,Err:" + err.Error()
+			return
+		}
+		br.Msg = "发送成功"
+	} else {
+		br.Msg = "发送失败"
+	}
+	br.Ret = 200
+	br.Success = true
+}
+
 // @Title 登录
 // @Title 登录
 // @Description 登录接口
 // @Description 登录接口
 // @Param	request	body models.LoginReq true "type json string"
 // @Param	request	body models.LoginReq true "type json string"
 // @Success 200 {object} models.LoginResp
 // @Success 200 {object} models.LoginResp
 // @router /pc/login [post]
 // @router /pc/login [post]
-func (this *UserCommonController) Login() {
+func (this *UserCommonController) PcLogin() {
 	br := new(models.BaseResponse).Init()
 	br := new(models.BaseResponse).Init()
 	defer func() {
 	defer func() {
 		this.Data["json"] = br
 		this.Data["json"] = br
@@ -80,37 +152,50 @@ func (this *UserCommonController) Login() {
 		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 		return
 	}
 	}
-	newUserId := 0
-	userId:=0
+	userId := 0
 	var isAdd bool
 	var isAdd bool
 	if req.LoginType == 1 {
 	if req.LoginType == 1 {
-		if req.VerifyId == "" {
-			br.Msg = "参数错误!"
+		if req.Mobile == "" {
+			br.Msg = "请输入手机号"
+			br.ErrMsg = "请输入手机号"
 			return
 			return
 		}
 		}
-		if req.VerifyCode == "" {
-			br.Msg="请输入验证码"
+		if req.SmsCode == "" {
+			br.Msg = "请输入有效手机验证码"
+			br.ErrMsg = "请输入有效手机验证码"
 			return
 			return
 		}
 		}
-		item,err:=models.GetGraphicVerifyById(req.VerifyId)
-		if err!=nil {
-			if err.Error()==utils.ErrNoRow() {
-				br.Msg = "验证码不存在,请刷新页面!"
+		item, err := models.GetMsgCode(req.Mobile, req.SmsCode)
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				br.Msg = "验证码错误,请重新输入"
+				br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+				return
+			} else {
+				br.Msg = "验证码错误,请重新输入"
+				br.ErrMsg = "校验验证码失败,Err:" + err.Error()
 				return
 				return
 			}
 			}
-			br.Msg = "校验验证码失败!"
-			return
 		}
 		}
-		if item.VerifyCode!=req.VerifyCode {
-			br.Msg = "验证码错误,请重新输入!"
+		if item == nil {
+			br.Msg = "手机验证码错误,请重新输入"
 			return
 			return
 		}
 		}
-		checkoutTime:=time.Now().Add(15*time.Minute)
-		if item.CreateTime.After(checkoutTime) {
-			br.Msg = "验证码过期,请重新输入!"
-			return
+		wxUser, err := models.GetWxUserItemByMobile(req.Mobile)
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				isAdd = true
+			} else {
+				br.Msg = "登陆失败"
+				br.ErrMsg = "根据邮箱获取用户信息失败,Err:" + err.Error()
+				return
+			}
+		}
+		if wxUser == nil {
+			isAdd = true
+		} else {
+			userId = wxUser.UserId
 		}
 		}
-
 		//BindMobile(openId, mobile string, userId, loginType int) (err error) {
 		//BindMobile(openId, mobile string, userId, loginType int) (err error) {
 		//newUserId, err = models.BindMobile(openId, req.Mobile, userId, req.LoginType)
 		//newUserId, err = models.BindMobile(openId, req.Mobile, userId, req.LoginType)
 	} else if req.LoginType == 2 {
 	} else if req.LoginType == 2 {
@@ -124,41 +209,74 @@ func (this *UserCommonController) Login() {
 			br.Msg = "邮箱格式错误,请重新输入"
 			br.Msg = "邮箱格式错误,请重新输入"
 			return
 			return
 		}
 		}
+		if req.SmsCode == "" {
+			br.Msg = "请输入有效验证码"
+			br.ErrMsg = "请输入有效验证码"
+			return
+		}
+		item, err := models.GetMsgCode(req.Email, req.SmsCode)
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				br.Msg = "验证码错误,请重新输入"
+				br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+				return
+			} else {
+				br.Msg = "验证码错误,请重新输入"
+				br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+				return
+			}
+		}
+		if item == nil {
+			br.Msg = "邮箱证码错误,请重新输入"
+			return
+		}
 		wxUser, err := models.GetWxUserItemByEmail(req.Email)
 		wxUser, err := models.GetWxUserItemByEmail(req.Email)
-		if err!=nil {
-			if err.Error()==utils.ErrNoRow() {
-				isAdd=true
-			}else{
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				isAdd = true
+			} else {
 				br.Msg = "登陆失败"
 				br.Msg = "登陆失败"
 				br.ErrMsg = "根据邮箱获取用户信息失败,Err:" + err.Error()
 				br.ErrMsg = "根据邮箱获取用户信息失败,Err:" + err.Error()
 				return
 				return
 			}
 			}
 		}
 		}
-		if wxUser==nil {
-			isAdd=true
-		}else{
-			userId=wxUser.UserId
+		if wxUser == nil {
+			isAdd = true
+		} else {
+			userId = wxUser.UserId
 		}
 		}
 	} else {
 	} else {
 		br.Msg = "无效的登录方式"
 		br.Msg = "无效的登录方式"
-		br.ErrMsg = "无效的登录方式,Err:" + err.Error()
-		return
+		br.ErrMsg = "无效的登录方式,loginType:" + strconv.Itoa(req.LoginType)
 	}
 	}
-
 	if isAdd {
 	if isAdd {
 		user := new(models.WxUser)
 		user := new(models.WxUser)
 		user.CompanyId = 1
 		user.CompanyId = 1
 		user.CreatedTime = time.Now()
 		user.CreatedTime = time.Now()
 		user.FirstLogin = 1
 		user.FirstLogin = 1
 		user.Enabled = 1
 		user.Enabled = 1
-		user.RegisterTime=time.Now()
-		lastId,err := models.AddWxUser(user)
-		if err!=nil {
+		user.RegisterTime = time.Now()
+		user.LoginTime = time.Now()
+		user.IsFreeLogin = req.IsFreeLogin
+		lastId, err := models.AddWxUser(user)
+		if err != nil {
 			br.Msg = "登录失败"
 			br.Msg = "登录失败"
 			br.ErrMsg = "登录失败,Err:" + err.Error()
 			br.ErrMsg = "登录失败,Err:" + err.Error()
 			return
 			return
 		}
 		}
-		userId=int(lastId)
+		userId = int(lastId)
+	} else {
+		err = models.ModifyLoginTime(userId, req.IsFreeLogin)
+		if err != nil {
+			br.Msg = "登录失败"
+			br.ErrMsg = "登录失败,修改登录信息失败,Err:" + err.Error()
+			return
+		}
+	}
+	if userId == 0 {
+		br.Msg = "登录失败"
+		br.ErrMsg = "登录失败,id为 0"
+		return
 	}
 	}
 	timeUnix := time.Now().Unix()
 	timeUnix := time.Now().Unix()
 	timeUnixStr := strconv.FormatInt(timeUnix, 10)
 	timeUnixStr := strconv.FormatInt(timeUnix, 10)
@@ -179,7 +297,7 @@ func (this *UserCommonController) Login() {
 		}
 		}
 	}
 	}
 
 
-	userPermission, err := services.CheckUserPermission(newUserId)
+	userPermission, err := services.CheckUserPermission(userId)
 	if err != nil {
 	if err != nil {
 		br.Msg = "登录失败"
 		br.Msg = "登录失败"
 		br.ErrMsg = "登录失败,判断权限失败:" + err.Error()
 		br.ErrMsg = "登录失败,判断权限失败:" + err.Error()
@@ -191,16 +309,197 @@ func (this *UserCommonController) Login() {
 		br.ErrMsg = "登录失败,判断权限失败:" + err.Error()
 		br.ErrMsg = "登录失败,判断权限失败:" + err.Error()
 		return
 		return
 	}
 	}
+	newUser, _ := models.GetWxUserItemByUserId(userId)
+	checkPermissionCount, err := models.GetCustomPermission(newUser.CompanyId)
+	if err != nil {
+		br.Msg = "登录失败"
+		br.ErrMsg = "校验提示权限信息失败 Err:" + err.Error()
+		return
+	}
+
 	resp := new(models.LoginResp)
 	resp := new(models.LoginResp)
-	resp.UserId = newUserId
+	resp.UserId = newUser.UserId
 	resp.UserPermission = userPermission
 	resp.UserPermission = userPermission
 	resp.Authorization = token
 	resp.Authorization = token
+	resp.Headimgurl = newUser.Headimgurl
+	resp.Mobile = newUser.Mobile
+	resp.Email = newUser.Email
+
+	if checkPermissionCount <= 0 {
+		resp.IsTips = true
+	}
+
 	br.Ret = 200
 	br.Ret = 200
 	br.Success = true
 	br.Success = true
 	br.Data = resp
 	br.Data = resp
 	br.Msg = "登录成功"
 	br.Msg = "登录成功"
 }
 }
 
 
+// @Title 绑定手机号或邮箱
+// @Description 绑定手机号或邮箱
+// @Param	request	body models.BindReq true "type json string"
+// @Success Ret=200 绑定成功
+// @router /pc/bind [post]
+func (this *UserController) PcBind() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req models.BindReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	openId := this.User.OpenId
+	userId := this.User.UserId
+	var newUserId int
+	if req.BindType == 1 { //手机号
+		if req.Mobile == "" {
+			br.Msg = "请输入手机号"
+			br.ErrMsg = "请输入手机号"
+			return
+		}
+		if req.VerifyCode == "" {
+			br.Msg = "请输入有效手机验证码"
+			br.ErrMsg = "请输入有效手机验证码"
+			return
+		}
+		item, err := models.GetMsgCode(req.Mobile, req.VerifyCode)
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				br.Msg = "验证码错误,请重新输入"
+				br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+				return
+			} else {
+				br.Msg = "验证码错误,请重新输入"
+				br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+				return
+			}
+		}
+		if item == nil {
+			br.Msg = "手机验证码错误,请重新输入"
+			return
+		}
+		newUserId, err = models.BindMobile(openId, req.Mobile, userId, req.BindType)
+		if err != nil {
+			br.ErrMsg = "绑定失败"
+			br.Msg = "绑定失败,Err:" + err.Error()
+			return
+		}
+	} else if req.BindType == 2 {
+		if req.Email == "" {
+			br.ErrMsg = "邮箱不能为空,请输入邮箱"
+			br.Msg = "邮箱不能为空,请输入邮箱"
+			return
+		}
+		if req.VerifyCode == "" {
+			br.Msg = "请填写有效的邮箱验证码"
+			br.ErrMsg = "请填写有效的邮箱验证码"
+			return
+		}
+		if !utils.ValidateEmailFormatat(req.Email) {
+			br.ErrMsg = "邮箱格式错误,请重新输入"
+			br.Msg = "邮箱格式错误,请重新输入"
+			return
+		}
+		item, err := models.GetMsgCode(req.Email, req.VerifyCode)
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				br.Msg = "验证码错误,请重新输入"
+				br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+				return
+			} else {
+				br.Msg = "验证码错误,请重新输入"
+				br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+				return
+			}
+		}
+		if item == nil {
+			br.Msg = "邮箱证码错误,请重新输入"
+			return
+		}
+		newUserId, err = models.BindMobile(openId, req.Mobile, userId, req.BindType)
+		if err != nil {
+			br.ErrMsg = "绑定失败"
+			br.Msg = "绑定失败,Err:" + err.Error()
+			return
+		}
+	} else {
+		br.Msg = "无效的绑定方式"
+		br.ErrMsg = "无效的绑定方式,bindType:" + strconv.Itoa(req.BindType)
+		return
+	}
+	timeUnix := time.Now().Unix()
+	timeUnixStr := strconv.FormatInt(timeUnix, 10)
+	token := utils.MD5(strconv.Itoa(userId)) + utils.MD5(timeUnixStr)
+	//新增session
+	{
+		session := new(models.Session)
+		session.UserId = userId
+		session.CreatedTime = time.Now()
+		session.LastUpdatedTime = time.Now()
+		session.ExpireTime = time.Now().AddDate(1, 0, 0)
+		session.AccessToken = token
+		err = models.AddSession(session)
+		if err != nil {
+			br.Msg = "绑定失败"
+			br.ErrMsg = "绑定失败,新增用户session信息失败:" + err.Error()
+			return
+		}
+	}
+	userPermission, err := services.CheckUserPermission(newUserId)
+	if err != nil {
+		br.Msg = "绑定失败"
+		br.ErrMsg = "绑定失败,判断权限失败:" + err.Error()
+		return
+	}
+	err = models.ModifyFirstLogin(newUserId)
+	if err != nil {
+		br.Msg = "绑定失败"
+		br.ErrMsg = "绑定失败,判断权限失败:" + err.Error()
+		return
+	}
+	resp := new(models.LoginResp)
+	resp.UserId = newUserId
+	resp.UserPermission = userPermission
+	resp.Authorization = token
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+	br.Msg = "绑定成功"
+}
+
+// @Title 校验免登陆
+// @Description 校验免登陆
+// @Success Ret=200 绑定成功
+// @router /pc/check/login [get]
+func (this *UserController) CheckLogin() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	if this.User.IsFreeLogin == 1 {
+		if this.User.LoginTime.AddDate(0, 0, 30).After(time.Now()) {
+			br.Ret = 600
+		} else {
+			br.Ret = 408
+		}
+	} else {
+		if this.User.LoginTime.AddDate(0, 0, 1).After(time.Now()) {
+			br.Ret = 600 //正常状态,不需要登录
+		} else {
+			br.Ret = 408
+		}
+	}
+	br.IsSendEmail = false
+	br.Success = true
+	br.Msg = "获取成功"
+}
+
 /*
 /*
 var (
 var (
 	searcher = riot.New("zh")
 	searcher = riot.New("zh")

+ 3 - 4
controllers/wechat.go

@@ -142,7 +142,6 @@ func (this *WechatCommonController) WechatLogin() {
 	}
 	}
 	resp := new(models.WxLoginResp)
 	resp := new(models.WxLoginResp)
 	resp.UserId = userId
 	resp.UserId = userId
-	resp.OpenId = openId
 	resp.Code = 0
 	resp.Code = 0
 	resp.FirstLogin = firstLogin
 	resp.FirstLogin = firstLogin
 	resp.Authorization = token
 	resp.Authorization = token
@@ -153,8 +152,8 @@ func (this *WechatCommonController) WechatLogin() {
 	br.Data = resp
 	br.Data = resp
 }
 }
 
 
-// @Title 微信登录接口
-// @Description 微信登录接口
+// @Title 微信获取签名接口
+// @Description 微信获取签名接口
 // @Param   Url   query   string  true       "url地址"
 // @Param   Url   query   string  true       "url地址"
 // @Success 200 {object} models.WechatSign
 // @Success 200 {object} models.WechatSign
 // @router /getWxSign [get]
 // @router /getWxSign [get]
@@ -201,4 +200,4 @@ func (this *WechatController) GetWxSign() {
 
 
 /*
 /*
 $app->bag('api/wechat/check', "WechatController@check");
 $app->bag('api/wechat/check', "WechatController@check");
-*/
+*/

+ 157 - 0
controllers/wechat_pc.go

@@ -0,0 +1,157 @@
+package controllers
+
+import (
+	"fmt"
+	"hongze/hongze_api/models"
+	"hongze/hongze_api/services"
+	"hongze/hongze_api/utils"
+	"strconv"
+	"time"
+)
+
+// @Title pc端微信登录接口
+// @Description pc端微信登录接口
+// @Param   Code   query   string  true       "微信唯一编码code"
+// @Success 200 {object} models.WxLoginResp
+// @router /pc/login [get]
+func (this *WechatCommonController) PcWechatLogin() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	code := this.GetString("Code")
+	fmt.Println("code:", code)
+	item, err := services.PcWxGetUserOpenIdByCode(code)
+	if err != nil {
+		br.Msg = "获取用户信息失败"
+		br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+		return
+	}
+	if item.Errcode != 0 {
+		br.Msg = "获取用户信息失败"
+		br.ErrMsg = "获取access_token 失败 errcode:" + strconv.Itoa(item.Errcode) + " ;errmsg:" + item.Errmsg
+		return
+	}
+	openId := item.Openid
+	firstLogin := 1
+	userId := 0
+	//获取成功
+	if openId != "" {
+		wxUser, err := models.GetWxUserItemByOpenId(openId)
+		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.PcWxGetAccessToken()
+			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
+			}
+			user := new(models.WxUser)
+			user.OpenId = openId
+			user.CompanyId = 1
+			user.CreatedTime = time.Now()
+			user.UnionId = wxUserInfo.Unionid
+			user.Unionid = wxUserInfo.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.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
+				}
+			}
+			userId = wxUser.UserId
+		} else {
+			firstLogin = wxUser.FirstLogin
+			userId = wxUser.UserId
+		}
+	} else {
+		br.Msg = "获取用户信息失败"
+		br.ErrMsg = "获取openid失败,openid:" + item.Openid
+		return
+	}
+	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(1, 0, 0)
+		session.AccessToken = token
+		err = models.AddSession(session)
+		if err != nil {
+			br.Msg = "登录失败"
+			br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
+			return
+		}
+	}
+	permission, err := services.CheckUserPermission(userId)
+	if err != nil {
+		br.Msg = "登录失败"
+		br.ErrMsg = "登录失败,判断权限失败:" + err.Error()
+		return
+	}
+	newUser, _ := models.GetWxUserItemByUserId(userId)
+	checkPermissionCount, err := models.GetCustomPermission(newUser.CompanyId)
+	if err != nil {
+		br.Msg = "登录失败"
+		br.ErrMsg = "校验提示权限信息失败 Err:" + err.Error()
+		return
+	}
+
+	resp := new(models.WxLoginResp)
+	resp.UserId = userId
+	resp.Code = 0
+	resp.FirstLogin = firstLogin
+	resp.Authorization = token
+	resp.UserPermission = permission
+	resp.Email = newUser.Email
+	resp.Headimgurl = newUser.Headimgurl
+	resp.Mobile = newUser.Mobile
+	if newUser.Mobile == "" && newUser.Email == "" {
+		resp.IsBind = true
+	}
+	if checkPermissionCount <= 0 {
+		resp.IsTips = true
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "登录成功"
+	br.Data = resp
+}

+ 22 - 10
models/banner.go

@@ -6,20 +6,32 @@ import (
 )
 )
 
 
 type Banner struct {
 type Banner struct {
-	Id           int       `orm:"column(id);pk"`
-	ClassifyId   int       `description:"分类id"`
-	ImageUrl     string    `description:"图片路径"`
-	BannerType   int       `description:"类型 1:轮播图,2:头部海报"`
-	CreateTime   time.Time `description:"创建时间"`
-	ModifyTime   time.Time `description:"修改时间"`
-	ClassifyName string    `description:"分类名称"`
-	JumpUrl      string    `description:"跳转地址"`
+	Id             int       `orm:"column(id);pk"`
+	ClassifyId     int       `description:"分类id"`
+	ImageUrl       string    `description:"图片路径"`
+	BannerType     int       `description:"类型 1:轮播图,2:头部海报"`
+	CreateTime     time.Time `description:"创建时间"`
+	ModifyTime     time.Time `description:"修改时间"`
+	ClassifyName   string    `description:"分类名称"`
+	JumpUrl        string    `description:"跳转地址"`
+	Abstract       string    `description:"栏目简介"`
+	Descript       string    `description:"分享描述"`
+	ReportAuthor   string    `description:"栏目作者"`
+	AuthorDescript string    `description:"作者简介"`
+	ColumnImgUrl   string    `description:"栏目配图"`
+	HeadImgUrl     string    `description:"头部banner"`
+	AvatarImgUrl   string    `description:"头像"`
+	ReportImgUrl   string    `description:"报告配图"`
 }
 }
+
 //获取轮播图列表
 //获取轮播图列表
-func GetHomeBannerList() (items []*Banner, err error) {
+func GetHomeBannerList(platform string) (items []*Banner, err error) {
 	sql := ` SELECT * FROM banner WHERE banner_type=1 ORDER BY modify_time DESC `
 	sql := ` SELECT * FROM banner WHERE banner_type=1 ORDER BY modify_time DESC `
+	if platform == "pc" {
+		sql += ` LIMIT 1`
+	}
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	o.Using("rddp")
 	o.Using("rddp")
 	_, err = o.Raw(sql).QueryRows(&items)
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 	return
-}
+}

+ 2 - 1
models/base.go

@@ -7,6 +7,7 @@ type BaseResponse struct {
 	ErrCode string
 	ErrCode string
 	Data    interface{}
 	Data    interface{}
 	Success bool `description:"true 执行成功,false 执行失败"`
 	Success bool `description:"true 执行成功,false 执行失败"`
+	IsSendEmail bool `json:"-"`
 }
 }
 
 
 type BaseResponseRef struct {
 type BaseResponseRef struct {
@@ -26,5 +27,5 @@ type BaseResponseResult struct {
 }
 }
 
 
 func (r *BaseResponse) Init() *BaseResponse {
 func (r *BaseResponse) Init() *BaseResponse {
-	return &BaseResponse{Ret: 403}
+	return &BaseResponse{Ret: 403,IsSendEmail: true}
 }
 }

+ 52 - 8
models/classify.go

@@ -6,14 +6,20 @@ import (
 )
 )
 
 
 type Classify struct {
 type Classify struct {
-	Id           int       `orm:"column(id);pk"`
-	ClassifyName string    `description:"分类名称"`
-	Sort         int       `json:"-"`
-	ParentId     int       `description:"父级分类id"`
-	CreateTime   time.Time `description:"创建时间"`
-	ModifyTime   time.Time `description:"修改时间"`
-	Abstract     string    `description:"简介"`
-	Descript     string    `description:"描述"`
+	Id             int       `orm:"column(id);pk"`
+	ClassifyName   string    `description:"分类名称"`
+	Sort           int       `json:"-"`
+	ParentId       int       `description:"父级分类id"`
+	CreateTime     time.Time `description:"创建时间"`
+	ModifyTime     time.Time `description:"修改时间"`
+	Abstract       string    `description:"栏目简介"`
+	Descript       string    `description:"分享描述"`
+	ReportAuthor   string    `description:"栏目作者"`
+	AuthorDescript string    `description:"作者简介"`
+	ColumnImgUrl   string    `description:"栏目配图"`
+	HeadImgUrl     string    `description:"头部banner"`
+	AvatarImgUrl   string    `description:"头像"`
+	ReportImgUrl   string    `description:"报告配图"`
 }
 }
 
 
 func GetClassifyById(classifyId int) (item *Classify, err error) {
 func GetClassifyById(classifyId int) (item *Classify, err error) {
@@ -31,3 +37,41 @@ func GetClassifyList() (item []*Classify, err error) {
 	_, err = o.Raw(sql).QueryRows(&item)
 	_, err = o.Raw(sql).QueryRows(&item)
 	return
 	return
 }
 }
+
+func GetClassifySecondList(classifyId int) (item []*ClassifyDetail, err error) {
+	sql := ` SELECT a.id AS classify_id,a.classify_name,a.sort,a.parent_id,a.create_time,a.modify_time,a.abstract,a.descript,a.report_author,a.author_descript,a.report_img_url,a.head_img_url,a.avatar_img_url,a.column_img_url,a.is_home_column,MAX(b.stage) AS stage FROM classify AS a 
+			LEFT JOIN report AS b ON a.id=b.classify_id_second 
+			WHERE a.parent_id = ?
+			GROUP BY a.id  `
+	o := orm.NewOrm()
+	o.Using("rddp")
+	_, err = o.Raw(sql, classifyId).QueryRows(&item)
+	return
+}
+
+type ClassifyDetail struct {
+	ClassifyId     int       `description:"分类id"`
+	ClassifyName   string    `description:"分类名称"`
+	Sort           int       `json:"-"`
+	ParentId       int       `description:"父级分类id"`
+	CreateTime     time.Time `description:"创建时间"`
+	ModifyTime     time.Time `description:"修改时间"`
+	Abstract       string    `description:"栏目简介"`
+	Descript       string    `description:"分享描述"`
+	ReportAuthor   string    `description:"栏目作者"`
+	AuthorDescript string    `description:"作者简介"`
+	ColumnImgUrl   string    `description:"栏目配图"`
+	HeadImgUrl     string    `description:"头部banner"`
+	AvatarImgUrl   string    `description:"头像"`
+	ReportImgUrl   string    `description:"报告配图"`
+	Stage          int       `description:"最新期数"`
+	CommentList    []*CustomerComment
+}
+
+func GetClassifyDetailById(classifyId int) (item *ClassifyDetail, err error) {
+	sql := ` SELECT id AS classify_id,classify_name,sort,parent_id,create_time,modify_time,abstract,descript,report_author,author_descript,report_img_url,head_img_url,avatar_img_url,column_img_url FROM classify WHERE id = ?  `
+	o := orm.NewOrm()
+	o.Using("rddp")
+	err = o.Raw(sql, classifyId).QueryRow(&item)
+	return
+}

+ 20 - 0
models/customer_comment.go

@@ -0,0 +1,20 @@
+package models
+
+import "rdluck_tools/orm"
+
+type CustomerComment struct {
+	Id           int
+	HeadImgUrl   string
+	CustomerName string
+	CompanyName  string
+	Comment      string
+}
+
+
+func GetCustomerComment() (item []*CustomerComment, err error) {
+	sql := ` SELECT * FROM customer_comment `
+	o := orm.NewOrm()
+	o.Using("rddp")
+	_, err = o.Raw(sql).QueryRows(&item)
+	return
+}

+ 10 - 3
models/home.go

@@ -81,6 +81,14 @@ func ListHome(userId, maxPermission, userPermission int, permissionStr string) (
 type PcHomeClassifyItem struct {
 type PcHomeClassifyItem struct {
 	ClassifyId   int    `orm:"column(id)"`
 	ClassifyId   int    `orm:"column(id)"`
 	ClassifyName string `description:"分类名称"`
 	ClassifyName string `description:"分类名称"`
+	Abstract       string    `description:"栏目简介"`
+	Descript       string    `description:"分享描述"`
+	ReportAuthor   string    `description:"栏目作者"`
+	AuthorDescript string    `description:"作者简介"`
+	ColumnImgUrl   string    `description:"栏目配图"`
+	HeadImgUrl     string    `description:"头部banner"`
+	AvatarImgUrl   string    `description:"头像"`
+	ReportImgUrl   string    `description:"报告配图"`
 	ReportInfo   *PcReport
 	ReportInfo   *PcReport
 }
 }
 
 
@@ -95,7 +103,7 @@ func PcListHomeCount(classifyId int) (count int, err error) {
 func PcListHome(classifyId, startSize, pageSize int) (items []*PcHomeClassifyItem, err error) {
 func PcListHome(classifyId, startSize, pageSize int) (items []*PcHomeClassifyItem, err error) {
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	o.Using("rddp")
 	o.Using("rddp")
-	subSql := ` SELECT id ,classify_name FROM classify WHERE parent_id=?  `
+	subSql := ` SELECT * FROM classify WHERE parent_id=?  `
 	subSql += ` ORDER BY create_time ASC LIMIT ?,? `
 	subSql += ` ORDER BY create_time ASC LIMIT ?,? `
 	_, err = o.Raw(subSql, classifyId, startSize, pageSize).QueryRows(&items)
 	_, err = o.Raw(subSql, classifyId, startSize, pageSize).QueryRows(&items)
 	if err != nil {
 	if err != nil {
@@ -105,11 +113,10 @@ func PcListHome(classifyId, startSize, pageSize int) (items []*PcHomeClassifyIte
 	lenSub := len(items)
 	lenSub := len(items)
 	for k := 0; k < lenSub; k++ {
 	for k := 0; k < lenSub; k++ {
 		subItem := items[k]
 		subItem := items[k]
-		reportSql := ` SELECT a.id,a.classify_name,b.*,c.*,
+		reportSql := ` SELECT a.*,b.*,
                 CASE WHEN DATE(b.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
                 CASE WHEN DATE(b.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
                 FROM classify AS a
                 FROM classify AS a
                 INNER JOIN report AS b ON a.id=b.classify_id_second
                 INNER JOIN report AS b ON a.id=b.classify_id_second
-                INNER JOIN report_author AS c ON b.author=c.report_author
                 WHERE b.state=2 AND a.id=?
                 WHERE b.state=2 AND a.id=?
                 ORDER BY b.publish_time DESC LIMIT 1  `
                 ORDER BY b.publish_time DESC LIMIT 1  `
 		report := new(PcReport)
 		report := new(PcReport)

+ 11 - 0
models/home_pc.go

@@ -0,0 +1,11 @@
+package models
+
+import "rdluck_tools/orm"
+
+func GetColumnList() (items []*Classify, err error) {
+	o := orm.NewOrm()
+	o.Using("rddp")
+	sql := `SELECT * FROM classify WHERE is_home_column=1`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 14 - 14
models/report.go

@@ -26,6 +26,7 @@ type Report struct {
 	VideoUrl           string    `description:"音频文件URL"`
 	VideoUrl           string    `description:"音频文件URL"`
 	VideoName          string    `description:"音频文件名称"`
 	VideoName          string    `description:"音频文件名称"`
 	VideoPlaySeconds   string    `description:"音频播放时长"`
 	VideoPlaySeconds   string    `description:"音频播放时长"`
+	VideoSize          string    `description:"音频文件大小,单位M"`
 	ContentSub         string    `description:"内容前两个章节"`
 	ContentSub         string    `description:"内容前两个章节"`
 	IsShowNewLabel     int       `description:"是否显示新标签"`
 	IsShowNewLabel     int       `description:"是否显示新标签"`
 	IsCurrentDate      int       `description:"是否当前日期"`
 	IsCurrentDate      int       `description:"是否当前日期"`
@@ -53,9 +54,10 @@ type ReportList struct {
 	VideoUrl           string    `description:"音频文件URL"`
 	VideoUrl           string    `description:"音频文件URL"`
 	VideoName          string    `description:"音频文件名称"`
 	VideoName          string    `description:"音频文件名称"`
 	VideoPlaySeconds   string    `description:"音频播放时长"`
 	VideoPlaySeconds   string    `description:"音频播放时长"`
-	ContentSub         string    `description:"内容前两个章节"`
+	VideoSize          string    `description:"音频文件大小,单位M"`
 	HasPermission      int       `description:"是否拥有报告权限,1:拥有,0:没有"`
 	HasPermission      int       `description:"是否拥有报告权限,1:拥有,0:没有"`
 	TitleType          string    `description:"标题类型,FICC或者权益"`
 	TitleType          string    `description:"标题类型,FICC或者权益"`
+	ClassifyDetail
 }
 }
 
 
 type ReportListResp struct {
 type ReportListResp struct {
@@ -74,7 +76,12 @@ func GetReportListCount(classifyId int) (count int, err error) {
 func GetReportList(classifyId, startSize, pageSize int) (items []*ReportList, err error) {
 func GetReportList(classifyId, startSize, pageSize int) (items []*ReportList, err error) {
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	o.Using("rddp")
 	o.Using("rddp")
-	sql := ` SELECT * FROM report WHERE state=2 AND classify_id_second=? ORDER BY  publish_time DESC LIMIT ?,? `
+	sql := ` SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,
+			a.create_time,a.modify_time,a.state,a.publish_time,a.stage,a.msg_is_send,b.id AS classify_id,b.classify_name,b.abstract,b.descript,b.report_author,b.author_descript,
+            b.report_img_url,b.head_img_url,b.avatar_img_url,b.column_img_url,a.video_url,a.video_name,a.video_play_seconds,a.video_size
+            FROM report AS a
+			INNER JOIN  classify AS b ON a.classify_id_second=b.id
+			WHERE a.state=2 AND a.classify_id_second=? ORDER BY  a.publish_time DESC LIMIT ?,? `
 	_, err = o.Raw(sql, classifyId, startSize, pageSize).QueryRows(&items)
 	_, err = o.Raw(sql, classifyId, startSize, pageSize).QueryRows(&items)
 	return
 	return
 }
 }
@@ -115,6 +122,7 @@ type ReportDetail struct {
 	VideoUrl           string `description:"音频文件URL"`
 	VideoUrl           string `description:"音频文件URL"`
 	VideoName          string `description:"音频文件名称"`
 	VideoName          string `description:"音频文件名称"`
 	VideoPlaySeconds   string `description:"音频播放时长"`
 	VideoPlaySeconds   string `description:"音频播放时长"`
+	VideoSize          string `description:"音频文件大小,单位M"`
 	ContentSub         string `description:"内容前两个章节"`
 	ContentSub         string `description:"内容前两个章节"`
 	IsShowNewLabel     int    `description:"是否显示新标签"`
 	IsShowNewLabel     int    `description:"是否显示新标签"`
 	IsCurrentDate      int    `description:"是否当前日期"`
 	IsCurrentDate      int    `description:"是否当前日期"`
@@ -152,6 +160,7 @@ type ReportDetailResp struct {
 	RecommendList []*RecommendReport `description:"推荐报告列表"`
 	RecommendList []*RecommendReport `description:"推荐报告列表"`
 	Status        int                `description:"状态:0:正常展示,1:报告不存在,2:无权限"`
 	Status        int                `description:"状态:0:正常展示,1:报告不存在,2:无权限"`
 	Msg           string             `description:"提示信息"`
 	Msg           string             `description:"提示信息"`
+	Classify      *ClassifyDetail    `description:"对应专栏"`
 }
 }
 
 
 type ReportRecordReq struct {
 type ReportRecordReq struct {
@@ -179,6 +188,7 @@ type RecommendReport struct {
 	VideoUrl           string    `description:"音频文件URL"`
 	VideoUrl           string    `description:"音频文件URL"`
 	VideoName          string    `description:"音频文件名称"`
 	VideoName          string    `description:"音频文件名称"`
 	VideoPlaySeconds   string    `description:"音频播放时长"`
 	VideoPlaySeconds   string    `description:"音频播放时长"`
+	VideoSize          string    `description:"音频文件大小,单位M"`
 	ContentSub         string    `description:"内容前两个章节"`
 	ContentSub         string    `description:"内容前两个章节"`
 	ClassifyName       string    `description:"分类名称"`
 	ClassifyName       string    `description:"分类名称"`
 	HasPermission      int       `description:"报告权限:0:无权限,1:有权限"`
 	HasPermission      int       `description:"报告权限:0:无权限,1:有权限"`
@@ -232,26 +242,16 @@ type PcReport struct {
 	VideoUrl           string    `description:"音频文件URL"`
 	VideoUrl           string    `description:"音频文件URL"`
 	VideoName          string    `description:"音频文件名称"`
 	VideoName          string    `description:"音频文件名称"`
 	VideoPlaySeconds   string    `description:"音频播放时长"`
 	VideoPlaySeconds   string    `description:"音频播放时长"`
+	VideoSize          string    `description:"音频文件大小,单位M"`
 	ContentSub         string    `json:"-" description:"内容前两个章节"`
 	ContentSub         string    `json:"-" description:"内容前两个章节"`
 	IsShowNewLabel     int       `description:"是否显示新标签"`
 	IsShowNewLabel     int       `description:"是否显示新标签"`
 	IsCurrentDate      int       `description:"是否当前日期"`
 	IsCurrentDate      int       `description:"是否当前日期"`
 	ClassifyName       string    `description:"分类名称"`
 	ClassifyName       string    `description:"分类名称"`
 	TitleType          string    `description:"标题类型,FICC或者权益"`
 	TitleType          string    `description:"标题类型,FICC或者权益"`
-	ReportAuthor
 }
 }
 
 
 type ReportAuthor struct {
 type ReportAuthor struct {
-	ReportAuthor             string `description:"报告作者名称"`
-	AuthorTitle              string `description:"标题"`
-	AuthorSummaryBase        string `description:"基础介绍"`
-	AuthorHeadSmallUrl       string `description:"小头像"`
-	AuthorHeadSmallDoubleUrl string `description:"两倍小头像"`
-	AuthorHeadBigUrl         string `description:"大头像"`
-	AuthorHeadBigDoubleUrl   string `description:"两倍大头像"`
-	AuthorSummaryExt         string `description:"扩展介绍"`
-	SpeakerBase              string `description:"主讲人"`
-	SpeakerExt               string `description:"主讲人"`
-	AuthorHeadSquare         string `description:"方形头像"`
+	ReportAuthor string `description:"报告作者名称"`
 }
 }
 
 
 func GetReportAuthor(reportAuthor string) (item *ReportAuthor, err error) {
 func GetReportAuthor(reportAuthor string) (item *ReportAuthor, err error) {

+ 68 - 0
models/report_pc.go

@@ -0,0 +1,68 @@
+package models
+
+import (
+	"rdluck_tools/orm"
+	"rdluck_tools/paging"
+	"time"
+)
+
+type ResearchReportList struct {
+	Id             int       `orm:"column(id);pk"`
+	ClassifyName   string    `description:"分类名称"`
+	Sort           int       `json:"-"`
+	ParentId       int       `description:"父级分类id"`
+	CreateTime     time.Time `description:"创建时间"`
+	ModifyTime     time.Time `description:"修改时间"`
+	Abstract       string    `description:"栏目简介"`
+	Descript       string    `description:"分享描述"`
+	ReportAuthor   string    `description:"栏目作者"`
+	AuthorDescript string    `description:"作者简介"`
+	ColumnImgUrl   string    `description:"栏目配图"`
+	HeadImgUrl     string    `description:"头部banner"`
+	AvatarImgUrl   string    `description:"头像"`
+}
+
+func GetResearchReportList(classifyId int) (list []*ResearchReportList, err error) {
+	o := orm.NewOrm()
+	o.Using("rddp")
+	sql := `SELECT * FROM classify WHERE parent_id=? ORDER BY sort ASC `
+	_, err = o.Raw(sql, classifyId).QueryRows(&list)
+	return
+}
+
+type ResearchReportListResp struct {
+	List []*ResearchReportList
+}
+
+func GetSearchReportListCount(condition string) (count int, err error) {
+	o := orm.NewOrm()
+	o.Using("rddp")
+	sql := ` SELECT COUNT(1) AS count FROM report WHERE 1=1 AND state=2 `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql).QueryRow(&count)
+	return
+}
+
+func GetSearchReportList(condition string) (items []*ReportList, err error) {
+	o := orm.NewOrm()
+	o.Using("rddp")
+	sql := ` SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,
+			a.create_time,a.modify_time,a.state,a.publish_time,a.stage,a.msg_is_send,b.id AS classify_id,b.classify_name,b.abstract,b.descript,b.report_author,b.author_descript,
+            b.report_img_url,b.head_img_url,b.avatar_img_url,b.column_img_url,a.video_url,a.video_name,a.video_play_seconds,a.video_size
+            FROM report AS a
+			INNER JOIN  classify AS b ON a.classify_id_second=b.id
+			WHERE a.state=2  `
+	if condition != "" {
+		sql += condition
+	}
+	sql += `ORDER BY  a.publish_time DESC `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+type PcSearchReportListResp struct {
+	List []*ReportList
+	Paging *paging.PagingItem
+}

+ 24 - 0
models/wx_token_pc.go

@@ -0,0 +1,24 @@
+package models
+
+import "rdluck_tools/orm"
+
+func PcGetWxToken() (item *WxToken, err error) {
+	sql := `SELECT *  FROM pc_wx_token `
+	o := orm.NewOrm()
+	err = o.Raw(sql).QueryRow(&item)
+	return
+}
+
+func PcAddWxToken(token string, expiresIn int64) (err error) {
+	sql := `INSERT INTO pc_wx_token(access_token, expires_in)VALUES(?,?) `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, token, expiresIn).Exec()
+	return
+}
+
+func PcUpdateWxToken(token string, expiresIn int64,id int) (err error) {
+	sql := `UPDATE pc_wx_token SET access_token=?, expires_in=? WHERE id=? `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, token, expiresIn,id).Exec()
+	return
+}

+ 66 - 25
models/wx_user.go

@@ -40,21 +40,25 @@ type WxUser struct {
 	FromType        string    `description:"report' COMMENT 'report:研报,teleconference:电话会"`
 	FromType        string    `description:"report' COMMENT 'report:研报,teleconference:电话会"`
 	ApplyMethod     int       `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
 	ApplyMethod     int       `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
 	RegisterTime    time.Time `description:"注册时间"`
 	RegisterTime    time.Time `description:"注册时间"`
+	IsFreeLogin     bool      `description:"是否免登陆,true:免登陆,false:非免登陆"`
+	LoginTime       time.Time `description:"最近一次登录时间"`
 }
 }
 
 
 type WxUserItem struct {
 type WxUserItem struct {
-	UserId      int    `description:"用户id"`
-	OpenId      string `description:"open_id"`
-	UnionId     string `description:"union_id"`
-	CompanyId   int    `description:"客户id"`
-	NickName    string `description:"用户昵称"`
-	RealName    string `description:"用户实际名称"`
-	Mobile      string `description:"手机号码"`
-	BindAccount string `description:"绑定时的账号"`
-	Email       string `description:"邮箱"`
-	Headimgurl  string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
-	ApplyMethod int    `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
-	FirstLogin  int    `description:"是否第一次登陆"`
+	UserId      int       `description:"用户id"`
+	OpenId      string    `description:"open_id"`
+	UnionId     string    `description:"union_id"`
+	CompanyId   int       `description:"客户id"`
+	NickName    string    `description:"用户昵称"`
+	RealName    string    `description:"用户实际名称"`
+	Mobile      string    `description:"手机号码"`
+	BindAccount string    `description:"绑定时的账号"`
+	Email       string    `description:"邮箱"`
+	Headimgurl  string    `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
+	ApplyMethod int       `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
+	FirstLogin  int       `description:"是否第一次登陆"`
+	IsFreeLogin int       `description:"是否免登陆,true:免登陆,false:非免登陆"`
+	LoginTime   time.Time `description:"登录时间"`
 }
 }
 
 
 func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
 func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
@@ -98,7 +102,7 @@ func GetUserIsMaxPermission(companyId int) (count int, err error) {
 }
 }
 
 
 //添加用户信息
 //添加用户信息
-func AddWxUser(item *WxUser) (lastId int64,err error) {
+func AddWxUser(item *WxUser) (lastId int64, err error) {
 	o := orm.NewOrm()
 	o := orm.NewOrm()
 	lastId, err = o.Insert(item)
 	lastId, err = o.Insert(item)
 	return
 	return
@@ -106,12 +110,16 @@ func AddWxUser(item *WxUser) (lastId int64,err error) {
 
 
 type WxLoginResp struct {
 type WxLoginResp struct {
 	Code           int
 	Code           int
-	OpenId         string
 	Authorization  string
 	Authorization  string
 	UserId         int
 	UserId         int
 	Expires        time.Time
 	Expires        time.Time
 	FirstLogin     int
 	FirstLogin     int
-	UserPermission int `description:"状态码"`
+	UserPermission int    `description:"状态码"`
+	Headimgurl     string `description:"用户头像"`
+	Mobile         string `description:"手机号"`
+	Email          string `description:"邮箱"`
+	IsBind         bool   `description:"true:需要绑定邮箱或验证码,false:不需要绑定邮箱或验证码"`
+	IsTips         bool   `description:"true:需要提示,false:不需要提示"`
 }
 }
 
 
 type UserDetail struct {
 type UserDetail struct {
@@ -175,9 +183,13 @@ type LoginReq struct {
 }
 }
 
 
 type LoginResp struct {
 type LoginResp struct {
-	UserId         int `description:"用户id"`
-	UserPermission int `description:"手机号"`
-	Authorization  string
+	UserId         int    `description:"用户id"`
+	UserPermission int    `description:"权限"`
+	Authorization  string `description:"Token"`
+	Headimgurl     string `description:"用户头像"`
+	Mobile         string `description:"手机号"`
+	Email          string `description:"邮箱"`
+	IsTips         bool   `description:"true:需要提示,false:不需要提示"`
 }
 }
 
 
 func BindMobile(openId, mobile string, userId, loginType int) (wxUserId int, err error) {
 func BindMobile(openId, mobile string, userId, loginType int) (wxUserId int, err error) {
@@ -232,17 +244,46 @@ func ModifyFirstLogin(userId int) (err error) {
 	return
 	return
 }
 }
 
 
-
 func GetWxUserItemByEmail(email string) (item *WxUserItem, err error) {
 func GetWxUserItemByEmail(email string) (item *WxUserItem, err error) {
 	sql := `SELECT * FROM wx_user WHERE email=? `
 	sql := `SELECT * FROM wx_user WHERE email=? `
 	err = orm.NewOrm().Raw(sql, email).QueryRow(&item)
 	err = orm.NewOrm().Raw(sql, email).QueryRow(&item)
 	return
 	return
 }
 }
 
 
+func GetWxUserItemByMobile(mobile string) (item *WxUserItem, err error) {
+	sql := `SELECT * FROM wx_user WHERE mobile=? OR mobile_two=? `
+	err = orm.NewOrm().Raw(sql, mobile, mobile).QueryRow(&item)
+	return
+}
+
 type PcLoginReq struct {
 type PcLoginReq struct {
-	LoginType int    `description:"登录方式:1:手机,2:邮箱"`
-	Mobile    string `description:"手机号"`
-	Email     string `description:"邮箱"`
-	VerifyId   string
-	VerifyCode string
-}
+	LoginType   int    `description:"登录方式:1:手机,2:邮箱"`
+	Mobile      string `description:"手机号"`
+	Email       string `description:"邮箱"`
+	SmsCode     string `description:"短信/邮箱验证码"`
+	IsFreeLogin bool   `description:"是否免登陆,true:免登陆,false:非免登陆"`
+}
+
+type BindReq struct {
+	BindType   int    `description:"绑定方式:1:手机,2:邮箱"`
+	Mobile     string `description:"手机号"`
+	Email      string `description:"邮箱"`
+	VerifyCode string `description:"短信/邮箱 验证码"`
+}
+
+func ModifyLoginTime(userId int, isFreeLogin bool) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE wx_user SET is_free_login=?,login_time=NOW() WHERE user_id = ? `
+	_, err = o.Raw(sql, isFreeLogin, userId).Exec()
+	return
+}
+
+func GetCustomPermission(companyId int) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS count FROM company AS a
+			INNER JOIN company_product AS b ON a.company_id=b.company_id
+			WHERE b.company_id=? AND b.status IN('试用','正式')
+			GROUP BY b.company_id`
+	err = o.Raw(sql, companyId).QueryRow(&count)
+	return
+}

+ 3 - 0
routers/router.go

@@ -38,6 +38,9 @@ func init() {
 			beego.NSInclude(
 			beego.NSInclude(
 				&controllers.ReportShareController{},
 				&controllers.ReportShareController{},
 			),
 			),
+			beego.NSInclude(
+				&controllers.ReportCommonController{},
+			),
 		),
 		),
 		beego.NSNamespace("/classify",
 		beego.NSNamespace("/classify",
 			beego.NSInclude(
 			beego.NSInclude(

+ 87 - 0
services/wechat_pc.go

@@ -0,0 +1,87 @@
+package services
+
+import (
+	"encoding/json"
+	"errors"
+	"fmt"
+	"hongze/hongze_api/models"
+	"hongze/hongze_api/utils"
+	"rdluck_tools/http"
+	"time"
+)
+
+
+func PcWxGetUserOpenIdByCode(code string) (item *WxAccessToken, err error) {
+	if code == "" {
+		err = errors.New("code is empty")
+		return nil, err
+	}
+	requestUrl := `https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code`
+	requestUrl = fmt.Sprintf(requestUrl, utils.PcWxAppId, utils.PcWxAppSecret, code)
+	result, err := http.Get(requestUrl)
+	if err != nil {
+		return nil, err
+	}
+	utils.FileLog.Info("WxGetUserOpenIdByCode:%s",string(result))
+	err = json.Unmarshal(result, &item)
+	return
+}
+
+
+func PcWxGetAccessToken() (accessToken string, err error) {
+	wxToken, err := models.GetWxToken()
+	fmt.Println(err,wxToken)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+	//wx_token 不存在
+	if wxToken == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
+		token, err := PcWxGetToken()
+		if err != nil {
+			return accessToken, err
+		}
+		if token.Errmsg != "" {
+			err = errors.New("获取access_token 失败 errcode:" + token.Errmsg + " ;errmsg:" + token.Errmsg)
+			return "", err
+		}
+		expiresIn := time.Now().Add(110 * time.Minute).Unix()
+		err = models.PcAddWxToken(token.AccessToken, expiresIn)
+		if err != nil {
+			err = errors.New("新增wx_token失败" + err.Error())
+			return accessToken, err
+		}
+		accessToken = token.AccessToken
+	} else {
+		if wxToken.ExpiresIn <= time.Now().Unix() {
+			token, err := PcWxGetToken()
+			if err != nil {
+				return accessToken, err
+			}
+			if token.Errmsg != "" {
+				err = errors.New("获取access_token 失败 errcode:" + token.Errmsg + " ;errmsg:" + token.Errmsg)
+				return "", err
+			}
+			expiresIn := time.Now().Add(110 * time.Minute).Unix()
+			err = models.PcUpdateWxToken(token.AccessToken, expiresIn, wxToken.Id)
+			if err != nil {
+				err = errors.New("修改wx_token失败" + err.Error())
+				return accessToken, err
+			}
+			accessToken = token.AccessToken
+		} else {
+			accessToken = wxToken.AccessToken
+		}
+	}
+	return
+}
+
+func PcWxGetToken() (item *WxToken, err error) {
+	requestUrl := `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s`
+	requestUrl = fmt.Sprintf(requestUrl, utils.PcWxAppId, utils.PcWxAppSecret)
+	result, err := http.Get(requestUrl)
+	if err != nil {
+		return nil, err
+	}
+	err = json.Unmarshal(result, &item)
+	return
+}

+ 16 - 1
utils/config.go

@@ -24,6 +24,15 @@ var (
 	TemplateRedirectUrl string //模板消息跳转地址
 	TemplateRedirectUrl string //模板消息跳转地址
 )
 )
 
 
+//pc端微信配置信息
+var (
+	PcWxId                string //微信原始ID
+	PcWxAppId             string
+	PcWxAppSecret         string
+	PcTemplateIdByProduct string //产品运行报告通知-模板ID
+	PcTemplateRedirectUrl string //模板消息跳转地址
+)
+
 func init() {
 func init() {
 	RunMode = beego.AppConfig.String("run_mode")
 	RunMode = beego.AppConfig.String("run_mode")
 	config, err := beego.AppConfig.GetSection(RunMode)
 	config, err := beego.AppConfig.GetSection(RunMode)
@@ -42,6 +51,9 @@ func init() {
 		TemplateIdByProduct = "Cp2wF8gvBtxyWV4DeYuI172oqwyYXVRSm3AyJO42d84"
 		TemplateIdByProduct = "Cp2wF8gvBtxyWV4DeYuI172oqwyYXVRSm3AyJO42d84"
 		TemplateRedirectUrl = "https://ficc.hzinsights.com/reportdtl?id="
 		TemplateRedirectUrl = "https://ficc.hzinsights.com/reportdtl?id="
 
 
+		PcWxId = "wx615472d6874eeb7f"
+		PcWxAppId = "97fe374fb0cc90ef58c4b49d431366f1"
+
 		STATIC_DIR = "/home/static/imgs/"
 		STATIC_DIR = "/home/static/imgs/"
 	} else {
 	} else {
 		WxAppId = "wx9b5d7291e581233a"
 		WxAppId = "wx9b5d7291e581233a"
@@ -50,10 +62,13 @@ func init() {
 		TemplateIdByProduct = "-YjuPOB7Fqd-S3ilabYa6wvjDY9aXmeEfPN6DCiy-EY"
 		TemplateIdByProduct = "-YjuPOB7Fqd-S3ilabYa6wvjDY9aXmeEfPN6DCiy-EY"
 		TemplateRedirectUrl = "http://rddpweb.brilliantstart.cn/reportdtl?id="
 		TemplateRedirectUrl = "http://rddpweb.brilliantstart.cn/reportdtl?id="
 
 
+		PcWxId = "wx615472d6874eeb7f"
+		PcWxAppId = "26c586e7ccb3c575433f0f37797b3eeb"
+
 		STATIC_DIR = "/home/static/imgs/"
 		STATIC_DIR = "/home/static/imgs/"
 	}
 	}
 }
 }
 
 
 //http://webapi.brilliantstart.cn/api/
 //http://webapi.brilliantstart.cn/api/
 //http://webapi.brilliantstart.cn/swagger/
 //http://webapi.brilliantstart.cn/swagger/
-//http://139.196.122.219:8603/swagger/
+//http://139.196.122.219:8603/swagger/