rdluck 4 years ago
parent
commit
11f8bf078e

+ 1 - 1
controllers/base_auth.go

@@ -101,7 +101,7 @@ func (c *BaseAuthController) ServeJSON(encoding ...bool) {
 		return
 	}
 	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)
 		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)
 	}

+ 53 - 1
controllers/base_common.go

@@ -4,6 +4,8 @@ import (
 	"encoding/json"
 	"net/http"
 	"net/url"
+	"strconv"
+	"strings"
 
 	"github.com/astaxie/beego"
 
@@ -13,6 +15,8 @@ import (
 
 type BaseCommonController struct {
 	beego.Controller
+	User  *models.WxUserItem
+	Token string
 }
 
 func (this *BaseCommonController) Prepare() {
@@ -25,6 +29,54 @@ func (this *BaseCommonController) Prepare() {
 	}
 	ip := this.Ctx.Input.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
+	}
+	uri := this.Ctx.Input.URI()
+	utils.FileLog.Info("URI:%s", uri)
+	if strings.Contains(uri, "/api/wechat/login") {
+		authorization = ""
+	}
+	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) {
@@ -43,7 +95,7 @@ func (c *BaseCommonController) ServeJSON(encoding ...bool) {
 		return
 	}
 	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)
 	}
 	c.JSON(c.Data["json"], hasIndent, hasEncoding)

+ 106 - 0
controllers/bill.go

@@ -0,0 +1,106 @@
+package controllers
+
+import (
+	"fmt"
+	"hongze/hongze_api/models"
+	"hongze/hongze_api/utils"
+	"time"
+)
+
+//年度账单
+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
+	}
+	uid := user.UserId
+	var realName, togetherDay, createDate string
+
+	resp := new(models.BillDetailResp)
+	if user.RealName == "" {
+		realName = user.NickName
+	} else {
+		realName = user.RealName
+	}
+	if !user.CreatedTime.IsZero() {
+		sub := time.Now().Sub(user.CreatedTime)
+		if sub < 0 {
+			sub = 0
+		}
+		expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
+		togetherDay = expireDay
+		createDate = user.CreatedTime.Format(utils.FormatDate)
+	} else {
+		sub := time.Now().Sub(user.LastUpdatedTime)
+		if sub < 0 {
+			sub = 0
+		}
+		expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
+		togetherDay = expireDay
+		createDate = user.LastUpdatedTime.Format(utils.FormatDate)
+	}
+
+	uid = 41555
+
+	firstReadReportType, firstReadReportTitle, err := models.GetFirstReportInfo(uid)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败GetFirstReportInfo,Err:" + err.Error()
+		return
+	}
+	listenCount, listenVideoPlaySeconds, err := models.GetListenInfo(uid)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败GetListenInfo,Err:" + err.Error()
+		return
+	}
+	maxReadReportCount, maxReadReportDate, err := models.GetMaxReadReportInfo(uid)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败GetListenInfo,Err:" + err.Error()
+		return
+	}
+	/*
+	   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
+	resp.TogetherDay = togetherDay
+	resp.CreateDate = createDate
+	resp.FirstReadReportType = firstReadReportType
+	resp.FirstReadReportTitle = firstReadReportTitle
+	resp.ListenReportCount = listenCount
+	resp.ListenReportDuration = utils.FixFloat((listenVideoPlaySeconds / 60.00), 2)
+	resp.MaxReadReportCount = maxReadReportCount
+	resp.MaxReadReportDate = maxReadReportDate.Format(utils.FormatDate)
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 47 - 3
controllers/classify.go

@@ -1,6 +1,8 @@
 package controllers
 
-import "hongze/hongze_api/models"
+import (
+	"hongze/hongze_api/models"
+)
 
 type ClassifyController struct {
 	BaseAuthController
@@ -13,7 +15,7 @@ type ClassifyCommonController struct {
 // @Title 获取分类详情信息
 // @Description 获取分类详情信息接口
 // @Param   ClassifyId   query   int  true       "分类id"
-// @Success 200 {object} models.Classify
+// @Success 200 {object} models.ClassifyDetail
 // @router /detail [get]
 func (this *ClassifyController) Detail() {
 	br := new(models.BaseResponse).Init()
@@ -32,12 +34,19 @@ func (this *ClassifyController) Detail() {
 		br.ErrMsg = "参数错误,分类id小于等于0"
 		return
 	}
-	item, err := models.GetClassifyById(classifyId)
+	item, err := models.GetClassifyDetailById(classifyId)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取信息失败,Err:" + err.Error()
 		return
 	}
+	commentList, err := models.GetCustomerComment()
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+	item.CommentList = commentList
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取数据成功"
@@ -65,3 +74,38 @@ func (this *ClassifyCommonController) List() {
 	br.Msg = "获取数据成功"
 	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 (
 	"hongze/hongze_api/models"
 	"hongze/hongze_api/services"
-	"hongze/hongze_api/utils"
-	"rdluck_tools/paging"
 )
 
 //首页
@@ -69,7 +67,7 @@ func (this *HomeController) ListBanner() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	list, err := models.GetHomeBannerList()
+	list, err := models.GetHomeBannerList("")
 	if err != nil {
 		br.Msg = "获取数据失败"
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
@@ -80,69 +78,3 @@ func (this *HomeController) ListBanner() {
 	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()
-	}()
-	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
-}

+ 186 - 0
controllers/home_pc.go

@@ -0,0 +1,186 @@
+package controllers
+
+import (
+	"hongze/hongze_api/models"
+	"hongze/hongze_api/services"
+	"hongze/hongze_api/utils"
+	"rdluck_tools/paging"
+	"time"
+)
+
+// @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()
+	}()
+	var uid int
+
+	if this.Token != "" && this.User != nil {
+		uid = this.User.UserId
+	}
+
+	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
+	}
+
+	endDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
+
+	total, err := models.PcListHomeCount(classifyId, endDate)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据条数失败,Err:" + err.Error()
+		return
+	}
+
+	list, err := models.PcListHome(classifyId, uid, startSize, pageSize, endDate)
+	if err != nil {
+		br.Msg = "获取数据失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	var hasPermission bool
+	if this.Token != "" && this.User != nil {
+		userPermission, err := services.CheckUserPermission(uid)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "判断权限失败,判断权限失败:" + err.Error()
+			return
+		}
+
+		if userPermission == 0 {
+			hasPermission = true
+		}
+	}
+
+	reportType := "rddp"
+	reportPermissionList, err := models.GetReportVarietyListByUserIdExt(uid, 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
+		}
+	}
+
+	for i := 0; i < len(list); i++ {
+		item := list[i]
+		if uid > 0 {
+			count, err := models.GetReportPermission(uid, item.ClassifyNameSecond)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				br.Msg = "获取失败"
+				br.ErrMsg = "判断报告是否拥有权限失败,Err:" + err.Error()
+				return
+			}
+			if count <= 0 {
+				list[i].VideoUrl = ""
+				list[i].VideoName = ""
+				list[i].VideoPlaySeconds = ""
+				list[i].VideoSize = ""
+			}
+		}
+
+		if item.ClassifyName == "权益研报" {
+			list[i].TitleType = "权益"
+		} else {
+			list[i].TitleType = "FICC"
+		}
+
+		if !hasPermission {
+			list[i].VideoUrl = ""
+			list[i].VideoName = ""
+			list[i].VideoPlaySeconds = ""
+			list[i].VideoSize = ""
+		}
+	}
+
+	if len(list) == 0 {
+		list = make([]*models.PcHomeClassifyItem, 0)
+	}
+
+	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 首页banner接口
+// @Description 首页banner接口
+// @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
+}

+ 95 - 12
controllers/report.go

@@ -3,6 +3,7 @@ package controllers
 import (
 	"encoding/json"
 	"hongze/hongze_api/models"
+	"hongze/hongze_api/services"
 	"hongze/hongze_api/utils"
 	"html"
 	"strings"
@@ -14,6 +15,11 @@ type ReportController struct {
 	BaseAuthController
 }
 
+//报告
+type ReportCommonController struct {
+	BaseCommonController
+}
+
 // @Title 日评详情
 // @Description 日评详情接口
 // @Param   ReportId   query   int  true       "报告id"
@@ -45,7 +51,9 @@ func (this *ReportController) Detail() {
 		br.ErrMsg = "参数错误,报告id小于等于0"
 		return
 	}
+
 	report, err := models.GetReportById(reportId)
+
 	if err != nil {
 		br.Msg = "获取报告详情失败"
 		br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
@@ -59,12 +67,14 @@ func (this *ReportController) Detail() {
 	report.Content = html.UnescapeString(report.Content)
 
 	productId := 0
-	if report.ClassifyNameFirst == "权益研报" {
+	maxPermissionCount := 0
+	if report.ClassifyName == "权益研报" {
 		productId = 2
+		maxPermissionCount = 5
 	} else {
 		productId = 1
+		maxPermissionCount = 15
 	}
-
 	company, err := models.GetCompanyProductById(user.CompanyId, productId)
 	if err != nil {
 		if err.Error() != utils.ErrNoRow() {
@@ -74,39 +84,35 @@ func (this *ReportController) Detail() {
 		} else {
 			status = 2
 			msg = "您还未开通权限,如有需要请联系对口销售"
-			report.Content = report.ContentSub
 		}
 	}
 	if company == nil {
 		status = 2
 		msg = "您还未开通权限,如有需要请联系对口销售"
-		report.Content = report.ContentSub
 	} else {
 		if company.Status == utils.COMPANY_STATUS_LOSE ||
 			company.Status == utils.COMPANY_STATUS_FREEZE {
 			status = 2
 			msg = "您还未开通权限,如有需要请联系对口销售"
-			report.Content = report.ContentSub
 		}
 	}
+
 	if productId == 1 {
 		reportType := "rddp"
-		reportPermissionList, err := models.GetReportVarietyListByUserIdExt(user.UserId, reportType)
+		reportPermissionList, err := models.GetReportVarietyListByUserIdExt(user.UserId, reportType) //获取客户拥有权限的报告id
 		if err != nil {
 			if err.Error() != utils.ErrNoRow() {
 				br.Msg = "获取报告详情失败"
-				br.ErrMsg = "获取用户管理企业信息失败,Err:" + err.Error()
+				br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
 				return
 			} else {
 				status = 2
 				msg = "您还未开通权限,如有需要请联系对口销售"
-				report.Content = report.ContentSub
 			}
 		}
 		if len(reportPermissionList) == 0 {
 			status = 2
 			msg = "您还未开通权限,如有需要请联系对口销售"
-			report.Content = report.ContentSub
 		}
 		permissionMap := make(map[int]int)
 		for _, v := range reportPermissionList {
@@ -114,10 +120,10 @@ func (this *ReportController) Detail() {
 				permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId
 			}
 		}
+
 		if _, ok := permissionMap[reportId]; !ok {
 			tips := ""
 			status = 2
-			report.Content = report.ContentSub
 			classifyNameSecond := report.ClassifyNameSecond
 			if strings.Contains(classifyNameSecond, "宏观商品复盘") ||
 				strings.Contains(classifyNameSecond, "股债日评") ||
@@ -147,7 +153,29 @@ func (this *ReportController) Detail() {
 	} else {
 		report.TitleType = "FICC"
 	}
+	//判断大小权限
+	{
+		if status == 2 {
+			permissionCount, err := models.GetCompanyProductPermissionCount(company.CompanyId, productId)
+			if err != nil {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
+				return
+			}
+			if permissionCount >= maxPermissionCount {
+				status = 0
+				msg = ""
+			}
+		}
+	}
 
+	if status == 2 {
+		report.Content = report.ContentSub
+		report.VideoUrl = ""
+		report.VideoSize = ""
+		report.VideoPlaySeconds = ""
+		report.VideoName = ""
+	}
 	resp := new(models.ReportDetailResp)
 	resp.Status = status
 	resp.Msg = msg
@@ -202,6 +230,14 @@ func (this *ReportController) Detail() {
 		}
 	}
 	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.Success = true
 	br.Msg = "获取成功"
@@ -260,11 +296,44 @@ func (this *ReportController) ListReport() {
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
+
+	var hasPermission bool
+	userPermission, err := services.CheckUserPermission(this.User.UserId)
+	if err != nil {
+		br.Msg = "绑定失败"
+		br.ErrMsg = "绑定失败,判断权限失败:" + err.Error()
+		return
+	}
+
+	if userPermission == 0 {
+		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 = "获取失败"
@@ -284,6 +353,20 @@ func (this *ReportController) ListReport() {
 		} else {
 			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 = ""
+			list[i].VideoName = ""
+			list[i].VideoPlaySeconds = ""
+		}
 	}
 
 	page := models.GetPaging(currentIndex, pageSize, total)

+ 173 - 0
controllers/report_pc.go

@@ -0,0 +1,173 @@
+package controllers
+
+import (
+	"hongze/hongze_api/models"
+	"hongze/hongze_api/utils"
+)
+
+// @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
+	//}
+	var uid int
+	if this.Token != "" && this.User != nil {
+		uid = this.User.UserId
+	}
+	var hasPermission bool
+	reportType := "rddp"
+	reportPermissionList, err := models.GetReportVarietyListByUserIdExt(uid, 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
+		}
+	}
+
+	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(uid, item.ClassifyNameSecond)
+			if err != nil && err.Error()!=utils.ErrNoRow() {
+				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 = ""
+			}
+		} else {
+			list[i].VideoUrl = ""
+			list[i].VideoName = ""
+			list[i].VideoPlaySeconds = ""
+			list[i].VideoSize = ""
+		}
+
+		if hasPermission == false {
+			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
+}

+ 30 - 18
controllers/user.go

@@ -309,26 +309,38 @@ func (this *UserController) Login() {
 		br.ErrMsg = "无效的登录方式,Err:" + err.Error()
 		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
-		}
+	var token string
+	tokenItem, err := models.GetTokenByUid(userId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "登录失败"
+		br.ErrMsg = "登录失败,获取token失败:" + err.Error()
+		return
 	}
 
+	if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
+		token = tokenItem.AccessToken
+		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 {
+		token = tokenItem.AccessToken
+	}
 	userPermission, err := services.CheckUserPermission(newUserId)
 	if err != nil {
 		br.Msg = "登录失败"

+ 689 - 0
controllers/user_pc.go

@@ -1,3 +1,692 @@
 package controllers
 
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/mojocn/base64Captcha"
+	"hongze/hongze_api/services"
+	"hongze/hongze_api/utils"
+	"strconv"
 
+	"hongze/hongze_api/models"
+	"image/color"
+	"time"
+)
+
+// @Title 获取图形验证码
+// @Description 获取图形验证码
+// @Success 200 {object} models.GraphicVerifyCodeResp
+// @router /pc/getGraphicVerifyCode [get]
+func (this *UserCommonController) GetGraphicVerifyCode() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	var configC = base64Captcha.ConfigCharacter{
+		Height:             26,
+		Width:              67,
+		Mode:               base64Captcha.CaptchaModeNumber,
+		ComplexOfNoiseText: base64Captcha.CaptchaComplexLower,
+		ComplexOfNoiseDot:  base64Captcha.CaptchaComplexLower,
+		IsUseSimpleFont:    true,
+		IsShowHollowLine:   false,
+		IsShowNoiseDot:     true,
+		IsShowNoiseText:    true,
+		IsShowSlimeLine:    false,
+		IsShowSineLine:     false,
+		CaptchaLen:         4,
+		BgColor:            &color.RGBA{255, 255, 255, 1},
+	}
+	char := base64Captcha.EngineCharCreate(configC)
+
+	base64stringC := base64Captcha.CaptchaWriteToBase64Encoding(char)
+	verifyId := fmt.Sprintf("%d", time.Now().UnixNano())
+	item := new(models.GraphicVerifyCode)
+	item.VerifyId = verifyId
+	item.VerifyCode = char.CaptchaItem.VerifyValue
+	item.CreateTime = time.Now()
+	err := models.AddGraphicVerifyCode(item)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.GraphicVerifyCodeResp)
+	resp.VerifyId = verifyId
+	resp.VerifyCode = base64stringC
+	br.Ret = 200
+	br.Data = resp
+	br.Msg = "获取成功"
+	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 登录
+// @Description 登录接口
+// @Param	request	body models.LoginReq true "type json string"
+// @Success 200 {object} models.LoginResp
+// @router /pc/login [post]
+func (this *UserCommonController) PcLogin() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req models.PcLoginReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	userId := 0
+	var isAdd bool
+	if req.LoginType == 1 {
+		if req.Mobile == "" {
+			br.Msg = "请输入手机号"
+			br.ErrMsg = "请输入手机号"
+			return
+		}
+		if req.SmsCode == "" {
+			br.Msg = "请输入有效手机验证码"
+			br.ErrMsg = "请输入有效手机验证码"
+			return
+		}
+		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
+			}
+		}
+		if item == nil {
+			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) {
+		//newUserId, err = models.BindMobile(openId, req.Mobile, userId, req.LoginType)
+	} else if req.LoginType == 2 {
+		if req.Email == "" {
+			br.ErrMsg = "邮箱不能为空,请输入邮箱"
+			br.Msg = "邮箱不能为空,请输入邮箱"
+			return
+		}
+		if !utils.ValidateEmailFormatat(req.Email) {
+			br.ErrMsg = "邮箱格式错误,请重新输入"
+			br.Msg = "邮箱格式错误,请重新输入"
+			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)
+		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
+		}
+	} else {
+		br.Msg = "无效的登录方式"
+		br.ErrMsg = "无效的登录方式,loginType:" + strconv.Itoa(req.LoginType)
+	}
+	if isAdd {
+		user := new(models.WxUser)
+		user.CompanyId = 1
+		user.CreatedTime = time.Now()
+		user.FirstLogin = 1
+		user.Enabled = 1
+		user.Email = req.Email
+		user.Mobile = req.Mobile
+		if req.LoginType == 1 {
+			user.BindAccount = user.Mobile
+		} else {
+			user.BindAccount = user.Email
+		}
+		user.RegisterTime = time.Now()
+		user.LoginTime = time.Now()
+		user.IsFreeLogin = req.IsFreeLogin
+		user.RegisterPlatform = 2
+		lastId, err := models.AddWxUser(user)
+		if err != nil {
+			br.Msg = "登录失败"
+			br.ErrMsg = "登录失败,新增客户信息失败,Err:" + err.Error()
+			return
+		}
+		userId = int(lastId)
+
+		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(0, 1, 0)
+			session.AccessToken = token
+			err = models.AddSession(session)
+			if err != nil {
+				br.Msg = "登录失败"
+				br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
+				return
+			}
+		}
+	} 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
+	}
+
+	userPermission, err := services.CheckUserPermission(userId)
+	if err != nil {
+		br.Msg = "登录失败"
+		br.ErrMsg = "登录失败,判断权限失败:" + err.Error()
+		return
+	}
+	err = models.ModifyFirstLogin(userId)
+	if err != nil {
+		br.Msg = "登录失败"
+		br.ErrMsg = "登录失败,判断权限失败:" + err.Error()
+		return
+	}
+	var token string
+	tokenItem, err := models.GetTokenByUid(userId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "登录失败"
+		br.ErrMsg = "登录失败,获取token失败:" + err.Error()
+		return
+	}
+
+	if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
+		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(0, 1, 0)
+			session.AccessToken = token
+			err = models.AddSession(session)
+			if err != nil {
+				br.Msg = "登录失败"
+				br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
+				return
+			}
+		}
+	} else {
+		token = tokenItem.AccessToken
+	}
+
+	cp, err := models.GetCompanyProductsByUserId(userId)
+	if err != nil {
+		br.Msg = "登录失败"
+		br.ErrMsg = "登录失败,获取客户信息失败:" + err.Error()
+		return
+	}
+	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
+			if v.EndDate != "" {
+				endDate = endDate + "/" + v.Status + ":" + v.EndDate
+			}
+			productName = productName + "/" + v.ProductName
+		} else {
+			status = v.Status
+			if v.EndDate != "" {
+				endDate = v.Status + ":" + v.EndDate
+			}
+			productName = v.ProductName
+		}
+	}
+	newUser, _ := models.GetWxUserItemByUserId(userId)
+	resp := new(models.LoginResp)
+	resp.UserId = newUser.UserId
+	resp.UserPermission = userPermission
+	resp.Authorization = token
+	resp.Headimgurl = newUser.Headimgurl
+	resp.Mobile = newUser.Mobile
+	resp.Email = newUser.Email
+	resp.CompanyName = companyName
+	resp.EndDate = endDate
+	resp.Status = status
+	resp.ProductName = productName
+
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+	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
+	}
+	unionId := this.User.UnionId
+	userId := this.User.UserId
+
+	utils.FileLog.Info("绑定unionId:%s", unionId)
+	utils.FileLog.Info("userId:%d", 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
+		}
+		fmt.Println("bind")
+		fmt.Println(unionId, req.Mobile, userId, req.BindType)
+
+		newUserId, err = models.PcBindMobile(unionId, 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.PcBindMobile(unionId, req.Email, 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
+	}
+
+	var token string
+	tokenItem, err := models.GetTokenByUid(newUserId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "登录失败"
+		br.ErrMsg = "登录失败,获取token失败:" + err.Error()
+		return
+	}
+	if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
+		timeUnix := time.Now().Unix()
+		timeUnixStr := strconv.FormatInt(timeUnix, 10)
+		token = utils.MD5(strconv.Itoa(newUserId)) + utils.MD5(timeUnixStr)
+		//新增session
+		{
+			session := new(models.Session)
+			session.UserId = newUserId
+			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 {
+		token = tokenItem.AccessToken
+	}
+
+	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
+	}
+
+	cp, err := models.GetCompanyProductsByUserId(newUserId)
+	if err != nil {
+		br.Msg = "登录失败"
+		br.ErrMsg = "登录失败,获取客户信息失败:" + err.Error()
+		return
+	}
+	var companyName, status, endDate, productName string
+	for _, v := range cp {
+		companyName = v.CompanyName
+		if status != "" {
+			status = status + "/" + v.Status
+			endDate = endDate + "/" + v.EndDate
+			productName = productName + "/" + v.ProductName
+		} else {
+			status = v.Status
+			endDate = v.EndDate
+			productName = v.ProductName
+		}
+	}
+
+	newUser, err := models.GetWxUserItemByUserId(newUserId)
+	if err != nil {
+		br.Msg = "登录失败"
+		br.ErrMsg = "获取客户信息失败 GetWxUserItemByUserId:" + err.Error()
+		return
+	}
+
+	resp := new(models.LoginResp)
+	resp.UserId = newUserId
+	resp.UserPermission = userPermission
+	resp.Authorization = token
+	resp.Email = newUser.Email
+	resp.Headimgurl = newUser.Headimgurl
+	resp.Mobile = newUser.Mobile
+	resp.CompanyName = companyName
+	resp.EndDate = endDate
+	resp.Status = status
+	resp.ProductName = productName
+
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+	br.Msg = "绑定成功"
+}
+
+// @Title 校验免登陆
+// @Description 校验免登陆
+// @Success 200 {object} models.CheckLoginResp
+// @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
+		}
+	}
+	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
+	}
+	br.IsSendEmail = false
+	//判断token是否过期
+	if br.Ret == 408 {
+		tokenCount, err := models.GetSessionCountByToken(authorization)
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				br.Ret = 408
+			} else {
+				br.ErrMsg = "登录失败,Err:" + err.Error()
+				br.ErrMsg = "登录失败"
+				br.IsSendEmail = true
+				return
+			}
+		}
+		if tokenCount > 0 {
+			br.Ret = 600
+		}
+	}
+	resp := new(models.CheckLoginResp)
+	if br.Ret == 600 {
+		checkPermissionCount, err := models.GetCustomPermission(this.User.CompanyId)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "登录失败"
+			br.ErrMsg = "校验提示权限信息失败 Err:" + err.Error()
+			return
+		}
+		if checkPermissionCount <= 0 && this.User.CompanyId > 1 {
+			resp.IsTips = true
+		}
+
+		if this.User.Mobile == "" && this.User.Email == "" {
+			resp.IsBind = true
+		}
+	}
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+//
+//var (
+//	searcher = riot.New("zh")
+//)
+//
+//func init() {
+//	fmt.Sprintf("start")
+//	data := types.DocData{Content: `I wonder how, I wonder why
+//		, I wonder where they are`}
+//	data1 := types.DocData{Content: "所以, 你好, 再见"}
+//	data2 := types.DocData{Content: "没有理由"}
+//	data3 := types.DocData{Content: "你好,中国"}
+//	data4 := types.DocData{Content: "晚上好"}
+//	data5 := types.DocData{Content: "中国人民,你好啊,2020年"}
+//	data6 := types.DocData{Content: "中国的新冠疫情算基本得到了有效的控制,随着各地的纷纷复工,甚至有些省市已经开始了复学,大量的外籍华人、旅居的、留学的平时召唤都召唤不来的那些人纷纷回国,这都说明了我们伟大的中国,伟大的中国人民战胜了这次肆虐全球的瘟疫。\n\n  在这这次的抗击新冠疫情中,我们的白衣天使们,我们的专家、学者、科学家们,纷纷的冲在了抗疫第一线。看着84岁高龄的钟南山院士坐在高铁座位上睡着的照片,看着73岁的第一个提出武汉封城的李兰娟院士数次往返于武汉,脸上那一道道的长时间佩戴口罩和护目镜留下的压痕,看着一个个的花季少女剪掉秀发只是为了更好的穿戴防护装备,看着一车车的物资涌向武汉,看着一张张按着手印的奔赴疫区申请书,听着一句句熟悉而又温暖的入党誓词,感动无不充盈心腔,眼泪也从未吝啬。对最美逆行者的赞美是多么的诚挚!"}
+//	data7 := types.DocData{Content: "在此,我除了表达对他们由衷的感动,还想说:我们中国千万万的普普通通的老百姓也是最伟大、最可爱的人。从来没有一个朝代,从来没有一个国家,像我们中国的老百姓这样如此的对待疫情。平凡的老百姓节衣缩食,也要将物资援助最需要的地方,宁愿几个月不出门,也不给国家增加一分的负担。试问世界上有哪个国家的人民有我们中国的人民对国家如母亲般的感情呢?\n\n  近期看到的最多的新闻就是国外疫情的泛滥,不说在抗疫中每个国家的责任和力量,就说普通的百姓不戴口罩到处跑的,一只狗被遛了三十二次的,最硬核的就是用棍棒打腿的,这些都说明了他们的意识,他们面对疫情的态度和我们的同胞不是一个层次,他们对待国家的情感是不能和我们比拟的!当然,我们国家也不排除有个别的另类出现,但一定会收到最严厉的惩戒。\n\n  中国人民在这次的抗击新冠疫情的战役中表现出来的智慧、勇气、精神,都使我感到作为一个中国人是多么幸运。"}
+//
+//	searcher.Index("1", data)
+//	searcher.Index("2", data1)
+//	searcher.IndexDoc("3", data2)
+//	searcher.IndexDoc("4", data3)
+//	searcher.IndexDoc("5", data4)
+//	searcher.IndexDoc("6", data5)
+//	searcher.IndexDoc("7", data6)
+//	searcher.IndexDoc("8", data7)
+//	searcher.Flush()
+//
+//	req := types.SearchReq{Text: "中国人民",Orderless: false,CountDocsOnly: false}
+//	search := searcher.Search(req)
+//	jsonStr,_:=json.Marshal(search)
+//	fmt.Println(string(jsonStr))
+//	utils.FileLog.Info("%s",string(jsonStr))
+//	fmt.Sprintf("end")
+//}
+//

+ 111 - 69
controllers/wechat.go

@@ -1,6 +1,7 @@
 package controllers
 
 import (
+	"encoding/json"
 	"fmt"
 	"hongze/hongze_api/models"
 	"hongze/hongze_api/services"
@@ -42,69 +43,65 @@ 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
-			}*/
 			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.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.Remark = wxUserInfo.Remark
 			user.FirstLogin = 1
 			user.Enabled = 1
-			user.FromType="report"
-			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
-				}
+			user.RegisterPlatform=1
+			user.RegisterTime = time.Now()
+			_, err = models.AddWxUser(user)
+			wxUser, err = models.GetWxUserItemByUnionid(unionid)
+			if err != nil{
+				br.Msg = "获取用户信息失败"
+				br.ErrMsg = "unionid登录,获取微信用户信息失败,Err:" + err.Error()
+				return
 			}
 			userId = wxUser.UserId
 		} else {
@@ -112,38 +109,87 @@ 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
 	}
-	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
 	}
+	var token string
+	tokenItem, err := models.GetTokenByUid(userId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "登录失败"
+		br.ErrMsg = "登录失败,获取token失败:" + err.Error()
+		return
+	}
+
+	if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
+		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 {
+		token = tokenItem.AccessToken
+	}
 	resp := new(models.WxLoginResp)
 	resp.UserId = userId
-	resp.OpenId = openId
 	resp.Code = 0
 	resp.FirstLogin = firstLogin
 	resp.Authorization = token
@@ -154,8 +200,8 @@ func (this *WechatCommonController) WechatLogin() {
 	br.Data = resp
 }
 
-// @Title 微信登录接口
-// @Description 微信登录接口
+// @Title 微信获取签名接口
+// @Description 微信获取签名接口
 // @Param   Url   query   string  true       "url地址"
 // @Success 200 {object} models.WechatSign
 // @router /getWxSign [get]
@@ -198,8 +244,4 @@ func (this *WechatController) GetWxSign() {
 	br.Success = true
 	br.Msg = "获取签名成功"
 	br.Data = resp
-}
-
-/*
-$app->bag('api/wechat/check', "WechatController@check");
-*/
+}

+ 252 - 0
controllers/wechat_pc.go

@@ -0,0 +1,252 @@
+package controllers
+
+import (
+	"encoding/json"
+	"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
+
+	//accessToken, err := services.PcWxGetAccessToken()
+	//utils.FileLog.Info("accessToken:%s", accessToken)
+	//if err != nil {
+	//	br.Msg = "获取用户信息失败"
+	//	br.ErrMsg = "获取access_token失败,err:" + err.Error()
+	//	return
+	//}
+	utils.FileLog.Info("item.AccessToken):%s", item.AccessToken)
+
+	//获取用户信息
+	wxUserInfo, err := services.PcWxGetUserInfo(openId, item.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
+	}
+	var unionid string
+	unionid = item.Unionid
+	utils.FileLog.Info("item unionid:%s", unionid)
+	if unionid == "" {
+		unionid = wxUserInfo.Unionid
+	}
+	utils.FileLog.Info("openId:%s", openId)
+	utils.FileLog.Info("unionid:%s", unionid)
+
+	firstLogin := 1
+	userId := 0
+	//获取成功
+	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()) {
+			utils.FileLog.Info("用户不存在,注册")
+			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.RegisterTime = time.Now()
+			user.RegisterPlatform = 2
+			_, err = models.AddWxUser(user)
+			wxUser, err = models.GetWxUserItemByUnionid(wxUserInfo.Unionid)
+			if err != nil {
+				br.Msg = "获取用户信息失败"
+				br.ErrMsg = "获取微信用户信息失败,Err:" + err.Error()
+				return
+			}
+			userId = wxUser.UserId
+		} else {
+			utils.FileLog.Info("用户已经存在")
+			firstLogin = wxUser.FirstLogin
+			userId = wxUser.UserId
+			utils.FileLog.Info("用户已经存在,用户id:%d", 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
+			}
+		}
+	}
+
+	permission, err := services.CheckUserPermission(userId)
+	if err != nil {
+		br.Msg = "登录失败"
+		br.ErrMsg = "登录失败,判断权限失败:" + err.Error()
+		return
+	}
+	newUser, _ := models.GetWxUserItemByUserId(userId)
+	utils.FileLog.Info("获取用户信息:%d", userId)
+
+	var token string
+	tokenItem, err := models.GetTokenByUid(userId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "登录失败"
+		br.ErrMsg = "登录失败,获取token失败:" + err.Error()
+		return
+	}
+	if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
+		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(0, 1, 0)
+			session.AccessToken = token
+			err = models.AddSession(session)
+			if err != nil {
+				br.Msg = "登录失败"
+				br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
+				return
+			}
+		}
+	} else {
+		token = tokenItem.AccessToken
+	}
+
+	cp, err := models.GetCompanyProductsByUserId(userId)
+	if err != nil {
+		br.Msg = "登录失败"
+		br.ErrMsg = "登录失败,获取客户信息失败:" + err.Error()
+		return
+	}
+	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
+			if v.EndDate != "" {
+				endDate = endDate + "/" + v.Status + ":" + v.EndDate
+			}
+			productName = productName + "/" + v.ProductName
+		} else {
+			status = v.Status
+			if v.EndDate != "" {
+				endDate = v.Status + ":" + v.EndDate
+			}
+			productName = v.ProductName
+		}
+	}
+
+	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
+	resp.CompanyName = companyName
+	resp.EndDate = endDate
+	resp.Status = status
+	resp.ProductName = productName
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "登录成功"
+	br.Data = resp
+}
+
+//func init() {
+//	accessToken:=`40_6_YtSyR4Kg9MYbODrNVc1mpztpbZDPWb8aiNzgq96vfvSLGb59dTZk6dprQuhCdsPrqYRKFvaAAij0_NzR-rnMCb0Bxsngov9eLBuk4WQoI`
+//	openId:=`oNUl652NjgjPz_C4M1ezCIro_s98`
+//	item,err:=services.WxGetUserInfo(openId, accessToken)
+//	fmt.Println(err)
+//	fmt.Println(item)
+//}
+
+//func init() {
+//	fmt.Println("start accessToken")
+//	accessToken, err := services.PcWxGetAccessToken()
+//	fmt.Println(err)
+//	utils.FileLog.Info("accessToken:%s",accessToken)
+//	fmt.Println("end accessToken")
+//}

+ 2 - 1
main.go

@@ -2,6 +2,7 @@ package main
 
 import (
 	"fmt"
+	"hongze/hongze_api/services"
 	"runtime"
 	"time"
 
@@ -18,7 +19,7 @@ func main() {
 		beego.BConfig.WebConfig.DirectoryIndex = true
 		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
 	}
-
+	go services.Task()
 	beego.BConfig.RecoverFunc = Recover
 	beego.Run()
 }

+ 22 - 10
models/banner.go

@@ -6,20 +6,32 @@ import (
 )
 
 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 `
+	if platform == "pc" {
+		sql += ` LIMIT 1`
+	}
 	o := orm.NewOrm()
 	o.Using("rddp")
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
-}
+}

+ 2 - 1
models/base.go

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

+ 322 - 0
models/bill.go

@@ -0,0 +1,322 @@
+package models
+
+import (
+	"hongze/hongze_api/utils"
+	"rdluck_tools/orm"
+	"time"
+)
+
+type BillDetailResp struct {
+	RealName                     string  `description:"用户实际名称"`
+	TogetherDay                  string  `description:"相伴天数"`
+	CreateDate                   string  `description:"创建时间"`
+	FirstReadReportType          string  `description:"首次阅读报告类型"`
+	FirstReadReportTitle         string  `description:"首次阅读报告标题"`
+	ListenReportCount            int     `description:"收听报告次数"`
+	ListenReportDuration         float64 `description:"收听报告时长"`
+	MaxReadReportDate            string  `description:"阅读报告最多的一天"`
+	MaxReadReportCount           int  `description:"阅读报告最多的一天,报告数量"`
+	LatestReadReportDate         string  `description:"阅读报告时间最晚的一天"`
+	LatestReadReportTime         string  `description:"阅读报告时间最晚的一天,最晚的时间"`
+	LatestReadReportDateDuration string  `description:"阅读报告时间最晚的一天,总共阅读报告的时长"`
+	MaxOpenReportClassify        string  `description:"打开次数最多报告的栏目"`
+	MaxOpenReportCount           string  `description:"打开次数最多报告的栏目下,用户阅读的报告数"`
+	TotalReadDuration            string  `description:"总阅读时长"`
+	TotalReportDayCount          string  `description:"总阅读晨报数"`
+	TotalReportWeekCount         string  `description:"总阅读周报数"`
+	TotalReportMonthCount        string  `description:"总阅读月报数"`
+	TotalReportTwoWeekCount      string  `description:"总阅读双周报数"`
+	TotalReportRddpCount         string  `description:"总阅读点评数"`
+	LearnDay                     string  `description:"连续学习天数"`
+}
+
+type ReadReportType struct {
+	ReportType string
+	CreateTime time.Time
+	Title      string
+	Stage      int
+}
+
+func GetRddpMinReportType(uid int) (item *ReadReportType, err error) {
+	o := orm.NewOrm()
+	o.Using("rddp")
+	sql := `SELECT 'rddp' AS report_type,MIN(a.create_time) AS create_time,b.title,b.stage FROM report_view_record AS a
+			INNER JOIN  report AS b ON a.report_id=b.id
+			WHERE a.user_id=? `
+	err = o.Raw(sql, uid).QueryRow(&item)
+	return
+}
+
+func GetWeekMinReportType(uid int) (item *ReadReportType, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT b.type AS report_type,MIN(a.created_time) AS create_time,b.research_report_name AS title,b.periods AS stage FROM user_view_history AS a
+			INNER JOIN  research_report AS b ON a.research_report_id=b.research_report_id
+			WHERE a.user_id=? `
+	err = o.Raw(sql, uid).QueryRow(&item)
+	return
+}
+
+func GetFirstReportInfo(uid int) (firstReadReportType, firstReadReportTitle string, err error) {
+	rddpFlag := true
+	weekFlag := true
+	rddpMinReportItem, err := GetRddpMinReportType(uid)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			rddpFlag = false
+		} else {
+			return
+		}
+	}
+	if rddpMinReportItem == nil {
+		rddpFlag = false
+	}
+	weekMinReportItem, err := GetWeekMinReportType(uid)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			weekFlag = false
+		} else {
+			return
+		}
+	}
+	if weekMinReportItem == nil {
+		weekFlag = false
+	}
+
+	if rddpFlag && weekFlag {
+		if rddpMinReportItem.CreateTime.After(weekMinReportItem.CreateTime) {
+			firstReadReportType = rddpMinReportItem.ReportType
+			firstReadReportTitle = rddpMinReportItem.Title
+		} else {
+			firstReadReportType = weekMinReportItem.ReportType
+			firstReadReportTitle = weekMinReportItem.Title
+		}
+	} else {
+		if rddpFlag == false && weekFlag {
+			firstReadReportType = weekMinReportItem.ReportType
+			firstReadReportTitle = weekMinReportItem.Title
+		}
+		if rddpFlag && weekFlag == false {
+			firstReadReportType = rddpMinReportItem.ReportType
+			firstReadReportTitle = rddpMinReportItem.Title
+		}
+	}
+	return
+}
+
+type Listen struct {
+	Count            int
+	VideoPlaySeconds float64
+}
+
+func GetRddpListen(uid int) (item *Listen, err error) {
+	o := orm.NewOrm()
+	o.Using("rddp")
+	sql := ` SELECT COUNT(1),SUM(b.video_play_seconds) FROM  report_audio_record AS a
+			 INNER JOIN report AS b ON a.report_id=b.id
+			 WHERE user_id=? LIMIT 1`
+	err = o.Raw(sql, uid).QueryRow(&item)
+	return
+}
+
+func GetWeekListen(uid int) (item *Listen, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS count,SUM(b.video_play_seconds) AS video_play_seconds FROM voice_record AS a
+			INNER JOIN teleconference AS b ON a.teleconference_id=b.teleconference_id
+			WHERE a.uid=? LIMIT 1`
+	err = o.Raw(sql, uid).QueryRow(&item)
+	return
+}
+
+func GetListenInfo(uid int) (count int, videoPlaySeconds float64, err error) {
+	rddpFlag := true
+	weekFlag := true
+	rddpListenItem, err := GetRddpListen(uid)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			rddpFlag = false
+		} else {
+			return
+		}
+	}
+	if rddpListenItem == nil {
+		rddpFlag = false
+	}
+	weekListenItem, err := GetWeekListen(uid)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			weekFlag = false
+		} else {
+			return
+		}
+	}
+	if weekListenItem == nil {
+		weekFlag = false
+	}
+
+	if rddpFlag && weekFlag {
+		count = rddpListenItem.Count + weekListenItem.Count
+		videoPlaySeconds = rddpListenItem.VideoPlaySeconds + weekListenItem.VideoPlaySeconds
+	} else {
+		if rddpFlag == false && weekFlag {
+			count = weekListenItem.Count
+			videoPlaySeconds = weekListenItem.VideoPlaySeconds
+		}
+		if rddpFlag && weekFlag == false {
+			count = rddpListenItem.Count
+			videoPlaySeconds = rddpListenItem.VideoPlaySeconds
+		}
+	}
+	return
+}
+
+type MaxReadReportCount struct {
+	Count      int
+	CreateDate time.Time
+}
+
+func GetRddpMaxReadReportCount(uid int) (item *MaxReadReportCount, err error) {
+	o := orm.NewOrm()
+	o.Using("rddp")
+	sql := ` SELECT DATE(create_time)AS create_date,COUNT(1) AS count FROM report_view_record AS a
+				WHERE a.user_id=?
+				GROUP BY DATE(create_time)
+				ORDER BY num DESC
+				LIMIT 1 `
+	err = o.Raw(sql, uid).QueryRow(&item)
+	return
+}
+
+func GetWeekMaxReadReportCount(uid int) (item *MaxReadReportCount, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT DATE(a.created_time)AS create_date,COUNT(1) AS count  FROM user_view_history AS a
+			WHERE a.user_id=?
+			GROUP BY DATE(created_time)
+			ORDER BY num DESC
+			LIMIT 1 `
+	err = o.Raw(sql, uid).QueryRow(&item)
+	return
+}
+
+func GetMaxReadReportInfo(uid int) (count int, createDate time.Time, err error) {
+	rddpFlag := true
+	weekFlag := true
+	rddpReadReportItem, err := GetRddpMaxReadReportCount(uid)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			rddpFlag = false
+		} else {
+			return
+		}
+	}
+	if rddpReadReportItem == nil {
+		rddpFlag = false
+	}
+	weekReadReportItem, err := GetWeekMaxReadReportCount(uid)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			weekFlag = false
+		} else {
+			return
+		}
+	}
+	if weekReadReportItem == nil {
+		weekFlag = false
+	}
+
+	if rddpFlag && weekFlag {
+		if rddpReadReportItem.Count>weekReadReportItem.Count {
+			count=rddpReadReportItem.Count
+			createDate=rddpReadReportItem.CreateDate
+		}else{
+			count=weekReadReportItem.Count
+			createDate=weekReadReportItem.CreateDate
+		}
+	} else {
+		if rddpFlag == false && weekFlag {
+			count=weekReadReportItem.Count
+			createDate=weekReadReportItem.CreateDate
+		}
+		if rddpFlag && weekFlag == false {
+			count=rddpReadReportItem.Count
+			createDate=rddpReadReportItem.CreateDate
+		}
+	}
+	return
+}
+
+//
+//
+//type MaxReadReportCount struct {
+//	Count      int
+//	CreateDate time.Time
+//}
+//
+//func GetRddpMaxReadReportCount(uid int) (item *MaxReadReportCount, err error) {
+//	o := orm.NewOrm()
+//	o.Using("rddp")
+//	sql := ` SELECT DATE(create_time)AS create_date,COUNT(1) AS count FROM report_view_record AS a
+//				WHERE a.user_id=?
+//				GROUP BY DATE(create_time)
+//				ORDER BY num DESC
+//				LIMIT 1 `
+//	err = o.Raw(sql, uid).QueryRow(&item)
+//	return
+//}
+//
+//func GetWeekMaxReadReportCount(uid int) (item *MaxReadReportCount, err error) {
+//	o := orm.NewOrm()
+//	sql := ` SELECT DATE(a.created_time)AS create_date,COUNT(1) AS count  FROM user_view_history AS a
+//			WHERE a.user_id=?
+//			GROUP BY DATE(created_time)
+//			ORDER BY num DESC
+//			LIMIT 1 `
+//	err = o.Raw(sql, uid).QueryRow(&item)
+//	return
+//}
+//
+//func GetMaxReadReportInfo(uid int) (count int, createDate time.Time, err error) {
+//	rddpFlag := true
+//	weekFlag := true
+//	rddpReadReportItem, err := GetRddpMaxReadReportCount(uid)
+//	if err != nil {
+//		if err.Error() == utils.ErrNoRow() {
+//			rddpFlag = false
+//		} else {
+//			return
+//		}
+//	}
+//	if rddpReadReportItem == nil {
+//		rddpFlag = false
+//	}
+//	weekReadReportItem, err := GetWeekMaxReadReportCount(uid)
+//	if err != nil {
+//		if err.Error() == utils.ErrNoRow() {
+//			weekFlag = false
+//		} else {
+//			return
+//		}
+//	}
+//	if weekReadReportItem == nil {
+//		weekFlag = false
+//	}
+//
+//	if rddpFlag && weekFlag {
+//		if rddpReadReportItem.Count>weekReadReportItem.Count {
+//			count=rddpReadReportItem.Count
+//			createDate=rddpReadReportItem.CreateDate
+//		}else{
+//			count=weekReadReportItem.Count
+//			createDate=weekReadReportItem.CreateDate
+//		}
+//	} else {
+//		if rddpFlag == false && weekFlag {
+//			count=weekReadReportItem.Count
+//			createDate=weekReadReportItem.CreateDate
+//		}
+//		if rddpFlag && weekFlag == false {
+//			count=rddpReadReportItem.Count
+//			createDate=rddpReadReportItem.CreateDate
+//		}
+//	}
+//	return
+//}

+ 57 - 9
models/classify.go

@@ -6,14 +6,21 @@ import (
 )
 
 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:"报告配图"`
+	HomeImgUrl     string    `description:"首页配图"`
 }
 
 func GetClassifyById(classifyId int) (item *Classify, err error) {
@@ -25,9 +32,50 @@ 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)
 	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.home_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 
+            ORDER BY sort ASC `
+	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:"报告配图"`
+	HomeImgUrl     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
+}

+ 55 - 1
models/company_product.go

@@ -1,6 +1,9 @@
 package models
 
-import "time"
+import (
+	"rdluck_tools/orm"
+	"time"
+)
 
 type CompanyProduct struct {
 	CompanyProductId int       `orm:"column(company_product_id);pk" description:"客户产品id"`
@@ -30,3 +33,54 @@ type CompanyProduct struct {
 	LossTime         time.Time `description:"流失时间"`
 	CompanyType      string    `description:"客户类型"`
 }
+
+//判断客户权限总数
+func GetCompanyProductPermissionCount(companyId, productId int) (count int, err error) {
+	sql := ` SELECT COUNT(DISTINCT c.chart_permission_id) AS COUNT FROM company AS a
+				INNER JOIN company_product AS b ON a.company_id=b.company_id 
+				INNER JOIN company_report_permission AS c ON a.company_id=c.company_id
+				WHERE  b.company_id=? AND b.product_id=?
+				AND b.status IN('正式','试用')
+				AND c.product_id=? `
+	o := orm.NewOrm()
+	err = o.Raw(sql, companyId, productId, productId).QueryRow(&count)
+	return
+}
+
+
+type CompanyProductDetail struct {
+	CompanyProductId int       `orm:"column(company_product_id);pk" description:"客户产品id"`
+	CompanyId        int       `description:"客户id"`
+	ProductId        int       `description:"产品id"`
+	ProductName      string    `description:"产品名称"`
+	CompanyName      string    `description:"客户名称"`
+	Source           string    `description:"来源"`
+	Reasons          string    `description:"新增理由"`
+	Status           string    `description:"客户状态"`
+	IndustryId       int       `description:"行业id"`
+	IndustryName     string    `description:"行业名称"`
+	SellerId         int       `description:"销售id"`
+	SellerName       string    `description:"销售名称"`
+	GroupId          int       `description:"销售分组id"`
+	DepartmentId     int       `description:"销售部门id"`
+	IsSuspend        int       `description:"1:暂停,0:启用"`
+	SuspendTime      time.Time `description:"暂停启用时间"`
+	ApproveStatus    string    `description:"审批状态:'审批中','通过','驳回'"`
+	FreezeTime       time.Time `description:"冻结时间"`
+	Remark           string    `description:"备注信息"`
+	CreateTime       time.Time `description:"创建时间"`
+	ModifyTime       time.Time `description:"修改时间"`
+	StartDate        string    `description:"开始日期"`
+	EndDate          string    `description:"结束日期"`
+	LoseReason       string    `description:"流失原因"`
+	LossTime         time.Time `description:"流失时间"`
+}
+
+func GetCompanyProductsByUserId(userId int) (items []*CompanyProductDetail, err error) {
+	sql := ` SELECT a.* FROM company_product AS a
+			INNER JOIN wx_user AS b ON a.company_id=b.company_id
+			WHERE b.user_id=? `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, userId).QueryRows(&items)
+	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
+}

+ 1 - 0
models/db.go

@@ -40,5 +40,6 @@ func init() {
 		new(WxUser),
 		new(Session),
 		new(MsgCode),
+		new(GraphicVerifyCode),
 	)
 }

+ 37 - 0
models/graphic_verify_code.go

@@ -0,0 +1,37 @@
+package models
+
+import (
+	"rdluck_tools/orm"
+	"time"
+)
+
+type GraphicVerifyCode struct {
+	Id         int `orm:"column(id);pk"`
+	VerifyId   string
+	VerifyCode string
+	CreateTime time.Time
+}
+
+//添加用户session信息
+func AddGraphicVerifyCode(item *GraphicVerifyCode) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+type GraphicVerifyCodeResp struct {
+	VerifyId   string
+	VerifyCode string
+}
+
+type CheckGraphicVerifyCodeReq struct {
+	VerifyId   string
+	VerifyCode string
+}
+
+func GetGraphicVerifyById(verifyId string) (item *GraphicVerifyCode, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM graphic_verify_code WHERE verify_id=? `
+	err = o.Raw(sql, verifyId).QueryRow(&item)
+	return
+}

+ 35 - 32
models/home.go

@@ -79,49 +79,52 @@ func ListHome(userId, maxPermission, userPermission int, permissionStr string) (
 }
 
 type PcHomeClassifyItem struct {
-	ClassifyId   int    `orm:"column(id)"`
-	ClassifyName string `description:"分类名称"`
-	ReportInfo   *PcReport
+	ClassifyId     int
+	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:"报告配图"`
+	HomeImgUrl     string `description:"首页配图"`
+	PcReport
 }
 
-func PcListHomeCount(classifyId int) (count int, err error) {
+func PcListHomeCount(classifyId int, endDate string) (count int, err error) {
 	o := orm.NewOrm()
 	o.Using("rddp")
-	sql := `SELECT COUNT(1) AS count FROM classify WHERE parent_id=? `
-	err = o.Raw(sql, classifyId).QueryRow(&count)
+
+	sql := `SELECT COUNT(1) AS count
+                FROM classify AS a
+                INNER JOIN report AS b ON a.id=b.classify_id_second
+                WHERE b.state=2 AND b.classify_id_first=? AND b.publish_time>=?`
+	err = o.Raw(sql, classifyId, endDate).QueryRow(&count)
 	return
 }
 
-func PcListHome(classifyId, startSize, pageSize int) (items []*PcHomeClassifyItem, err error) {
+func PcListHome(classifyId, uid, startSize, pageSize int, endDate string) (items []*PcHomeClassifyItem, err error) {
 	o := orm.NewOrm()
 	o.Using("rddp")
-	subSql := ` SELECT id ,classify_name FROM classify WHERE parent_id=?  `
-	subSql += ` ORDER BY create_time ASC LIMIT ?,? `
-	_, err = o.Raw(subSql, classifyId, startSize, pageSize).QueryRows(&items)
-	if err != nil {
-		fmt.Println("Sub Err:" + err.Error())
-		return
-	}
-	lenSub := len(items)
-	for k := 0; k < lenSub; k++ {
-		subItem := items[k]
-		reportSql := ` SELECT a.id,a.classify_name,b.*,c.*,
+	if uid > 0 {
+		reportSql := ` SELECT a.id AS classify_id,a.head_img_url,a.avatar_img_url,a.column_img_url,a.report_img_url,a.home_img_url,b.*,
+                (SELECT COUNT(1) FROM report_view_log AS c WHERE c.user_id=? AND c.report_id=b.id ) AS is_show_new_label,
                 CASE WHEN DATE(b.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
                 FROM classify AS a
                 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=?
-                ORDER BY b.publish_time DESC LIMIT 1  `
-		report := new(PcReport)
-		err = o.Raw(reportSql, subItem.ClassifyId).QueryRow(&report)
-		if err != nil {
-			if err.Error() != utils.ErrNoRow() {
-				return
-			} else {
-				err = nil
-			}
-		}
-		items[k].ReportInfo = report
+                WHERE b.state=2 AND b.classify_id_first=? AND b.publish_time>=?
+                ORDER BY b.publish_time DESC LIMIT ?,? `
+		_, err = o.Raw(reportSql, uid, classifyId, endDate, startSize, pageSize).QueryRows(&items)
+	} else {
+		reportSql := ` SELECT a.id AS classify_id,a.head_img_url,a.avatar_img_url,a.column_img_url,a.report_img_url,a.home_img_url,b.*,
+                CASE WHEN DATE(b.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
+                 FROM classify AS a
+                INNER JOIN report AS b ON a.id=b.classify_id_second
+                WHERE b.state=2 AND b.classify_id_first=? AND b.publish_time>=?
+                ORDER BY b.publish_time DESC LIMIT ?,? `
+		_, err = o.Raw(reportSql, classifyId, endDate, startSize, pageSize).QueryRows(&items)
 	}
 	return
 }
@@ -129,4 +132,4 @@ func PcListHome(classifyId, startSize, pageSize int) (items []*PcHomeClassifyIte
 type PcListHomeResp struct {
 	Paging *paging.PagingItem
 	List   []*PcHomeClassifyItem
-}
+}

+ 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
+}

+ 18 - 16
models/report.go

@@ -26,6 +26,7 @@ type Report struct {
 	VideoUrl           string    `description:"音频文件URL"`
 	VideoName          string    `description:"音频文件名称"`
 	VideoPlaySeconds   string    `description:"音频播放时长"`
+	VideoSize          string    `description:"音频文件大小,单位M"`
 	ContentSub         string    `description:"内容前两个章节"`
 	IsShowNewLabel     int       `description:"是否显示新标签"`
 	IsCurrentDate      int       `description:"是否当前日期"`
@@ -53,9 +54,11 @@ type ReportList struct {
 	VideoUrl           string    `description:"音频文件URL"`
 	VideoName          string    `description:"音频文件名称"`
 	VideoPlaySeconds   string    `description:"音频播放时长"`
-	ContentSub         string    `description:"内容前两个章节"`
+	VideoSize          string    `description:"音频文件大小,单位M"`
 	HasPermission      int       `description:"是否拥有报告权限,1:拥有,0:没有"`
 	TitleType          string    `description:"标题类型,FICC或者权益"`
+	IsCurrentDate      int       `description:"是否当前日期:1是,0不是"`
+	ClassifyDetail
 }
 
 type ReportListResp struct {
@@ -74,7 +77,13 @@ func GetReportListCount(classifyId int) (count int, err error) {
 func GetReportList(classifyId, startSize, pageSize int) (items []*ReportList, err error) {
 	o := orm.NewOrm()
 	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.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,
+            CASE WHEN DATE(a.modify_time)=DATE(NOW()) THEN 1 ELSE 0 END AS is_current_date
+            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)
 	return
 }
@@ -115,6 +124,7 @@ type ReportDetail struct {
 	VideoUrl           string `description:"音频文件URL"`
 	VideoName          string `description:"音频文件名称"`
 	VideoPlaySeconds   string `description:"音频播放时长"`
+	VideoSize          string `description:"音频文件大小,单位M"`
 	ContentSub         string `description:"内容前两个章节"`
 	IsShowNewLabel     int    `description:"是否显示新标签"`
 	IsCurrentDate      int    `description:"是否当前日期"`
@@ -152,6 +162,7 @@ type ReportDetailResp struct {
 	RecommendList []*RecommendReport `description:"推荐报告列表"`
 	Status        int                `description:"状态:0:正常展示,1:报告不存在,2:无权限"`
 	Msg           string             `description:"提示信息"`
+	Classify      *ClassifyDetail    `description:"对应专栏"`
 }
 
 type ReportRecordReq struct {
@@ -179,6 +190,7 @@ type RecommendReport struct {
 	VideoUrl           string    `description:"音频文件URL"`
 	VideoName          string    `description:"音频文件名称"`
 	VideoPlaySeconds   string    `description:"音频播放时长"`
+	VideoSize          string    `description:"音频文件大小,单位M"`
 	ContentSub         string    `description:"内容前两个章节"`
 	ClassifyName       string    `description:"分类名称"`
 	HasPermission      int       `description:"报告权限:0:无权限,1:有权限"`
@@ -232,26 +244,16 @@ type PcReport struct {
 	VideoUrl           string    `description:"音频文件URL"`
 	VideoName          string    `description:"音频文件名称"`
 	VideoPlaySeconds   string    `description:"音频播放时长"`
+	VideoSize          string    `description:"音频文件大小,单位M"`
 	ContentSub         string    `json:"-" description:"内容前两个章节"`
-	IsShowNewLabel     int       `description:"是否显示新标签"`
-	IsCurrentDate      int       `description:"是否当前日期"`
+	IsShowNewLabel     int       `description:"是否显示新标签,等于0不显示,大于0显示"`
+	IsCurrentDate      int       `description:"是否当前日期:1是,0不是"`
 	ClassifyName       string    `description:"分类名称"`
 	TitleType          string    `description:"标题类型,FICC或者权益"`
-	ReportAuthor
 }
 
 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) {

+ 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.descript,b.report_author,b.author_descript,
+            b.report_img_url,b.head_img_url,b.avatar_img_url,b.column_img_url,b.home_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
+}

+ 17 - 1
models/session.go

@@ -23,10 +23,26 @@ func GetSessionByToken(token string) (item *Session, err error) {
 	return
 }
 
+func GetSessionCountByToken(token string) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM session WHERE access_token=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
+	o := orm.NewOrm()
+	o.Using("rddp")
+	err = o.Raw(sql, token).QueryRow(&count)
+	return
+}
+
 //添加用户session信息
 func AddSession(item *Session) (err error) {
 	o := orm.NewOrm()
 	o.Using("rddp")
 	_, err = o.Insert(item)
 	return
-}
+}
+
+func GetTokenByUid(uid int) (item *Session, err error) {
+	sql := `SELECT * FROM session WHERE user_id=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
+	o := orm.NewOrm()
+	o.Using("rddp")
+	err = o.Raw(sql, uid).QueryRow(&item)
+	return
+}

+ 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 wx_pc_token `
+	o := orm.NewOrm()
+	err = o.Raw(sql).QueryRow(&item)
+	return
+}
+
+func PcAddWxToken(token string, expiresIn int64) (err error) {
+	sql := `INSERT INTO wx_pc_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 wx_pc_token SET access_token=?, expires_in=? WHERE id=? `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, token, expiresIn,id).Exec()
+	return
+}

+ 284 - 44
models/wx_user.go

@@ -1,6 +1,7 @@
 package models
 
 import (
+	"fmt"
 	"hongze/hongze_api/utils"
 	"rdluck_tools/orm"
 	"strings"
@@ -8,54 +9,61 @@ import (
 )
 
 type WxUser struct {
-	UserId          int       `orm:"column(user_id);pk"`
+	UserId           int       `orm:"column(user_id);pk"`
+	OpenId           string    `description:"open_id"`
+	UnionId          string    `description:"union_id"`
+	Subscribe        string    `description:"是否关注"`
+	CompanyId        int       `description:"客户id"`
+	NickName         string    `description:"用户昵称"`
+	RealName         string    `description:"用户实际名称"`
+	UserCode         string    `description:"用户编码"`
+	Mobile           string    `description:"手机号码"`
+	BindAccount      string    `description:"绑定时的账号"`
+	WxCode           string    `description:"微信号"`
+	Profession       string    `description:"职业"`
+	Email            string    `description:"邮箱"`
+	Telephone        string    `description:"座机"`
+	Sex              int       `description:"普通用户性别,1为男性,2为女性"`
+	Province         string    `description:"普通用户个人资料填写的省份"`
+	City             string    `description:"普通用户个人资料填写的城市"`
+	Country          string    `description:"国家,如中国为CN"`
+	SubscribeTime    int       `description:"关注时间"`
+	Remark           string    `description:"备注"`
+	Headimgurl       string    `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
+	Privilege        string    `description:"用户特权信息,json数组,如微信沃卡用户为(chinaunicom)"`
+	Unionid          string    `description:"用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。"`
+	FirstLogin       int       `description:"是否第一次登陆"`
+	Enabled          int       `description:"是否可用"`
+	CreatedTime      time.Time `description:"创建时间"`
+	LastUpdatedTime  time.Time `description:"最新一次修改时间"`
+	Seller           string    `description:"销售员"`
+	Note             string    `description:"客户备份信息"`
+	IsNote           int       `description:"是否备注过信息"`
+	FromType         string    `description:"report' COMMENT 'report:研报,teleconference:电话会"`
+	ApplyMethod      int       `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
+	RegisterTime     time.Time `description:"注册时间"`
+	RegisterPlatform int       `description:"注册平台,1:微信端,2:PC网页端"`
+	IsFreeLogin      bool      `description:"是否免登陆,true:免登陆,false:非免登陆"`
+	LoginTime        time.Time `description:"最近一次登录时间"`
+}
+
+type WxUserItem struct {
+	UserId          int       `description:"用户id"`
 	OpenId          string    `description:"open_id"`
 	UnionId         string    `description:"union_id"`
-	Subscribe       string    `description:"是否关注"`
 	CompanyId       int       `description:"客户id"`
 	NickName        string    `description:"用户昵称"`
 	RealName        string    `description:"用户实际名称"`
-	UserCode        string    `description:"用户编码"`
 	Mobile          string    `description:"手机号码"`
 	BindAccount     string    `description:"绑定时的账号"`
-	WxCode          string    `description:"微信号"`
-	Profession      string    `description:"职业"`
 	Email           string    `description:"邮箱"`
-	Telephone       string    `description:"座机"`
-	Sex             int       `description:"普通用户性别,1为男性,2为女性"`
-	Province        string    `description:"普通用户个人资料填写的省份"`
-	City            string    `description:"普通用户个人资料填写的城市"`
-	Country         string    `description:"国家,如中国为CN"`
-	SubscribeTime   int       `description:"关注时间"`
-	Remark          string    `description:"备注"`
 	Headimgurl      string    `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
-	Privilege       string    `description:"用户特权信息,json数组,如微信沃卡用户为(chinaunicom)"`
-	Unionid         string    `description:"用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。"`
+	ApplyMethod     int       `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
 	FirstLogin      int       `description:"是否第一次登陆"`
-	Enabled         int       `description:"是否可用"`
+	IsFreeLogin     int       `description:"是否免登陆,true:免登陆,false:非免登陆"`
+	LoginTime       time.Time `description:"登录时间"`
 	CreatedTime     time.Time `description:"创建时间"`
-	LastUpdatedTime time.Time `description:"最新一次修改时间"`
-	Seller          string    `description:"销售员"`
-	Note            string    `description:"客户备份信息"`
-	IsNote          int       `description:"是否备注过信息"`
-	FromType        string    `description:"report' COMMENT 'report:研报,teleconference:电话会"`
-	ApplyMethod     int       `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
-	RegisterTime    time.Time `description:"注册时间"`
-}
-
-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:"是否第一次登陆"`
+	LastUpdatedTime time.Time `description:"最近一次修改时间"`
 }
 
 func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
@@ -99,20 +107,26 @@ func GetUserIsMaxPermission(companyId int) (count int, err error) {
 }
 
 //添加用户信息
-func AddWxUser(item *WxUser) (err error) {
+func AddWxUser(item *WxUser) (lastId int64, err error) {
 	o := orm.NewOrm()
-	_, err = o.Insert(item)
+	lastId, err = o.Insert(item)
 	return
 }
 
 type WxLoginResp struct {
 	Code           int
-	OpenId         string
 	Authorization  string
 	UserId         int
 	Expires        time.Time
 	FirstLogin     int
-	UserPermission int `description:"状态码"`
+	UserPermission int    `description:"状态码"`
+	Headimgurl     string `description:"用户头像"`
+	Mobile         string `description:"手机号"`
+	Email          string `description:"邮箱"`
+	CompanyName    string `description:"客户名称"`
+	Status         string `description:"状态"`
+	EndDate        string `description:"到期日期"`
+	ProductName    string `description:"客户类型名称"`
 }
 
 type UserDetail struct {
@@ -176,9 +190,16 @@ type LoginReq 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:"邮箱"`
+	CompanyName    string `description:"客户名称"`
+	Status         string `description:"状态"`
+	EndDate        string `description:"到期日期"`
+	ProductName    string `description:"客户类型名称"`
 }
 
 func BindMobile(openId, mobile string, userId, loginType int) (wxUserId int, err error) {
@@ -193,19 +214,25 @@ func BindMobile(openId, mobile string, userId, loginType int) (wxUserId int, err
 	user := new(WxUser)
 	o := orm.NewOrm()
 	err = o.Raw(sql, mobile).QueryRow(&user)
+	fmt.Println("err:", err)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		return
 	}
+	fmt.Println(user)
 	if user == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
+		fmt.Println("line  210")
 		msql := ``
 		if loginType == 1 {
 			msql = "UPDATE wx_user SET mobile = ?,bind_account = ? where open_id = ? "
 		} else {
 			msql = "UPDATE wx_user SET email = ?,bind_account = ? where open_id = ?  "
 		}
+		fmt.Println("bind")
+		fmt.Println(msql, mobile, mobile, openId)
 		_, err = o.Raw(msql, mobile, mobile, openId).Exec()
 		wxUserId = userId
 	} else {
+		fmt.Println("line  223")
 		if user.OpenId == "" {
 			wxUserId = user.UserId
 			dsql := ` DELETE FROM wx_user WHERE open_id = ? `
@@ -221,6 +248,156 @@ func BindMobile(openId, mobile string, userId, loginType int) (wxUserId int, err
 			}
 			_, err = o.Raw(msql, openId, mobile, mobile).Exec()
 		} else {
+			fmt.Println("line  239")
+			wxUserId = userId
+		}
+	}
+	return
+}
+
+func PcBindMobile(unionId, mobile string, userId, loginType int) (wxUserId int, err error) {
+	//loginType  登录方式:1:手机,2:邮箱
+
+	utils.FileLog.Info("绑定参数:%s %s %d %d", unionId, mobile, userId, loginType)
+
+	sql := ``
+	if loginType == 1 {
+		sql = `SELECT * FROM wx_user WHERE mobile = ? `
+	} else {
+		sql = "SELECT * FROM wx_user WHERE email = ? "
+	}
+	user := new(WxUser)
+	o := orm.NewOrm()
+	err = o.Raw(sql, mobile).QueryRow(&user)
+
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+
+	if user == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
+		utils.FileLog.Info("用户不存在,根据union_id绑定")
+		msql := ``
+		if loginType == 1 {
+			msql = "UPDATE wx_user SET mobile = ?,bind_account = ? WHERE union_id = ? "
+		} else {
+			msql = "UPDATE wx_user SET email = ?,bind_account = ? WHERE union_id = ?  "
+		}
+		_, err = o.Raw(msql, mobile, mobile, unionId).Exec()
+		wxUserId = userId
+	} else {
+		utils.FileLog.Info("用户存在,user.UnionId:%s", user.UnionId)
+		if user.UnionId == "" {
+			sql = `SELECT * FROM wx_user WHERE union_id = ? `
+			userInfo := new(WxUser)
+			o := orm.NewOrm()
+			err = o.Raw(sql, unionId).QueryRow(&userInfo)
+			if err != nil {
+				return
+			}
+
+			utils.FileLog.Info("user.RegisterTime %s", user.RegisterTime.Format(utils.FormatDateTime))
+			utils.FileLog.Info("userInfo.RegisterTime %s", userInfo.RegisterTime.Format(utils.FormatDateTime))
+
+			var maxRegisterTime time.Time
+			if user.RegisterTime.Before(userInfo.RegisterTime) {
+				maxRegisterTime = user.RegisterTime
+				utils.FileLog.Info("after")
+			} else {
+				maxRegisterTime = userInfo.RegisterTime
+				utils.FileLog.Info("not after")
+			}
+			var realName string
+			if user.RealName != "" {
+				realName = user.RealName
+			} else {
+				realName = userInfo.RealName
+			}
+			utils.FileLog.Info("maxRegisterTime %s", maxRegisterTime.Format(utils.FormatDateTime))
+			wxUserId = user.UserId
+			dsql := ` DELETE FROM wx_user WHERE user_id = ? `
+			_, err = o.Raw(dsql, wxUserId).Exec()
+			if err != nil {
+				return wxUserId, err
+			}
+			msql := ``
+			if loginType == 1 {
+				msql = ` UPDATE wx_user SET mobile=?,bind_account = ?,created_time=NOW(),register_time=?,real_name=? `
+				if user.CompanyId > 0 {
+					msql += ` ,company_id = ? `
+				}
+				msql += ` WHERE union_id = ? `
+			} else {
+				msql = ` UPDATE wx_user SET email=?,bind_account = ?,created_time=NOW(),register_time=?,real_name=? `
+				if user.CompanyId > 0 {
+					msql += ` ,company_id = ? `
+				}
+				msql += `  WHERE union_id = ? `
+			}
+			if user.CompanyId > 0 {
+				_, err = o.Raw(msql, mobile, mobile, maxRegisterTime, realName, user.CompanyId, unionId).Exec()
+			} else {
+				_, err = o.Raw(msql, mobile, mobile, maxRegisterTime, realName, unionId).Exec()
+			}
+			wxUserId = userInfo.UserId
+		} else {
+			sql = `SELECT * FROM wx_user WHERE union_id = ? `
+			userInfo := new(WxUser)
+			o := orm.NewOrm()
+			err = o.Raw(sql, unionId).QueryRow(&userInfo)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				return
+			}
+			if userInfo.UserId != user.UserId {
+				isDelete := 0
+				if userInfo.CompanyId <= 1 {
+					dsql := ` DELETE FROM wx_user WHERE user_id = ? `
+					_, err = o.Raw(dsql, userInfo.UserId).Exec()
+					if err != nil {
+						return userInfo.UserId, err
+					}
+					isDelete = 1
+				}
+
+				if user.CompanyId <= 1 {
+					dsql := ` DELETE FROM wx_user WHERE user_id = ? `
+					_, err = o.Raw(dsql, user.UserId).Exec()
+					if err != nil {
+						return userInfo.UserId, err
+					}
+					isDelete = 2
+				}
+
+				if userInfo.CompanyId > 1 && user.CompanyId > 1 {
+					dsql := ` DELETE FROM wx_user WHERE user_id = ? `
+					_, err = o.Raw(dsql, user.UserId).Exec()
+					if err != nil {
+						return userInfo.UserId, err
+					}
+					isDelete = 2
+				}
+				if isDelete == 1 {
+					msql := ` UPDATE wx_user SET union_id = ?,unionid=?,bind_account = ?,created_time=NOW(),register_time=NOW()  `
+					if loginType == 1 {
+						msql += ` ,mobile = ? `
+					} else {
+						msql += ` ,email = ? `
+					}
+					msql += ` WHERE user_id = ? `
+					_, err = o.Raw(msql, user.Unionid, user.Unionid, mobile, mobile, user.UserId).Exec()
+					wxUserId = user.UserId
+				} else {
+					msql := ` UPDATE wx_user SET union_id = ?,unionid=?,bind_account = ?,created_time=NOW(),register_time=NOW()  `
+					if loginType == 1 {
+						msql += ` ,mobile = ? `
+					} else {
+						msql += ` ,email = ? `
+					}
+					msql += ` WHERE user_id = ? `
+					_, err = o.Raw(msql, unionId, unionId, mobile, mobile, userInfo.UserId).Exec()
+					wxUserId = userInfo.UserId
+				}
+			}
+			utils.FileLog.Info("用户存在,bind:%s,%d", unionId, wxUserId)
 			wxUserId = userId
 		}
 	}
@@ -233,3 +410,66 @@ func ModifyFirstLogin(userId int) (err error) {
 	_, err = o.Raw(sql, userId).Exec()
 	return
 }
+
+func GetWxUserItemByEmail(email string) (item *WxUserItem, err error) {
+	sql := `SELECT * FROM wx_user WHERE email=? `
+	err = orm.NewOrm().Raw(sql, email).QueryRow(&item)
+	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 {
+	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
+}
+
+type CheckLoginResp struct {
+	IsTips bool `description:"true:需要提示,false:不需要提示"`
+	IsBind bool `description:"true:需要绑定邮箱或验证码,false:不需要绑定邮箱或验证码"`
+}
+
+func GetOpenIdAll() (items []*WxUserItem, err error) {
+	sql := ` SELECT * FROM wx_user WHERE open_id<>'' AND union_id IS NULL `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+func ModifyWxUserUnionId(unionId string, userId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE wx_user SET union_id=?,unionid=? WHERE user_id = ? `
+	_, err = o.Raw(sql, unionId, unionId, userId).Exec()
+	return
+}

+ 8 - 0
routers/router.go

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

+ 10 - 0
services/task.go

@@ -0,0 +1,10 @@
+package services
+
+import "fmt"
+
+func Task() {
+	fmt.Println("start")
+	//InitSetUnionId()
+	//FixUnionId()
+	fmt.Println("end")
+}

+ 47 - 6
services/wechat.go

@@ -17,8 +17,9 @@ type WxAccessToken struct {
 	ExpiresIn    int    `json:"expires_in"`
 	RefreshToken string `json:"refresh_token"`
 	Openid       string `json:"openid"`
+	Unionid      string `json:"unionid"`
 	Scope        string `json:"scope"`
-	Errcode      int `json:"errcode"`
+	Errcode      int    `json:"errcode"`
 	Errmsg       string `json:"errmsg"`
 }
 
@@ -33,7 +34,7 @@ func WxGetUserOpenIdByCode(code string) (item *WxAccessToken, err error) {
 	if err != nil {
 		return nil, err
 	}
-	utils.FileLog.Info("WxGetUserOpenIdByCode:%s",string(result))
+	utils.FileLog.Info("WxGetUserOpenIdByCode:%s", string(result))
 	err = json.Unmarshal(result, &item)
 	return
 }
@@ -62,7 +63,7 @@ func WxGetToken() (item *WxToken, err error) {
 
 func WxGetAccessToken() (accessToken string, err error) {
 	wxToken, err := models.GetWxToken()
-	fmt.Println(err,wxToken)
+	fmt.Println(err, wxToken)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		return
 	}
@@ -121,18 +122,20 @@ type WxUserInfo struct {
 	Remark         string `json:"remark"`
 	Groupid        int    `json:"groupid"`
 	SubscribeScene string `json:"subscribe_scene"`
-	Errcode        int `json:"errcode"`
+	Errcode        int    `json:"errcode"`
 	Errmsg         string `json:"errmsg"`
 }
 
-func WxGetUserInfo(openId,accessToken string) (item *WxUserInfo, err error) {
+func WxGetUserInfo(openId, accessToken string) (item *WxUserInfo, err error) {
 	requestUrl := `https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=%s`
 	requestUrl = fmt.Sprintf(requestUrl, accessToken, openId)
 	result, err := http.Get(requestUrl)
 	if err != nil {
 		return
 	}
-	utils.FileLog.Info("WxGetUserInfo:%s openId:%s,accessToken:%s ",string(result),openId,accessToken)
+	fmt.Println("result:", string(result))
+	utils.FileLog.Info("WxGetUserInfo:%s openId:%s,accessToken:%s ", string(result), openId, accessToken)
+	utils.FileLog.Info("WxGetUserInfo Result:%s ", string(result))
 	err = json.Unmarshal(result, &item)
 	return
 }
@@ -164,3 +167,41 @@ func GetWxSignature(ticket, url, noncestr string) (string, string, int64) {
 	fmt.Println("signStr", signStr)
 	return signature, noncestr, timestamp
 }
+
+type WxUserDetail struct {
+	Unionid    string
+	Headimgurl string
+	Nickname   string
+}
+
+func FixUnionId() {
+	accessToken := `41_fMVI8r0fzoDjGOsKjMBhVN9b0j34TWTFNHIX1cQ4IOJ8SnJ2Cjz6MhvHvtH9gU_ztKo-rRQopCgSjNSZB5z25KgB5o61822LDH1sR5ow_Rfoa_Ro6KwcdP2Gp_naNM0AwMGZaF5OMifMny-FFEXfAJAXWP`
+
+	users, err := models.GetOpenIdAll()
+	if err != nil {
+		fmt.Println("GetOpenIdAll Err:" + err.Error())
+		return
+	}
+	for _, v := range users {
+		openId := v.OpenId
+		fmt.Println("openId:",openId,v.UserId)
+		userInfoUrl := `https://api.weixin.qq.com/cgi-bin/user/info?access_token=` + accessToken + `&openid=` + openId + `&lang=zh_CN`
+		result, err := http.Get(userInfoUrl)
+		fmt.Println("err:", err)
+		utils.FileLog.Info("%s", string(result))
+		item := new(WxUserDetail)
+		err = json.Unmarshal(result, &item)
+		if err != nil {
+			fmt.Println("json.Unmarshal Err:" + err.Error())
+			return
+		}
+		if item.Unionid != "" {
+			err = models.ModifyWxUserUnionId(item.Unionid, v.UserId)
+			if err!=nil {
+				fmt.Println("ModifyWxUserUnionId Err:"+err.Error())
+				return
+			}
+			//return
+		}
+	}
+}

+ 143 - 0
services/wechat_pc.go

@@ -0,0 +1,143 @@
+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.PcGetWxToken()
+	fmt.Println(err, wxToken)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+
+	fmt.Println(wxToken, err)
+	//wx_token 不存在
+	if wxToken == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
+		fmt.Println("token is nil")
+		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 {
+		fmt.Println("token is not nil")
+		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)
+	utils.FileLog.Info("result:%s", string(result))
+	if err != nil {
+		return nil, err
+	}
+	err = json.Unmarshal(result, &item)
+	return
+}
+
+func InitSetUnionId() {
+	list, err := models.GetOpenIdAll()
+	if err != nil {
+		fmt.Println("err:" + err.Error())
+		return
+	}
+	accessToken := "40_2L4GKbzCZ7qLtlATugEBKBIO6NZJBf4_0O6bHcelPSSSHbgeZhLFyU2jLdLeAP5d_DAinICR2ifS5M_TK-cmGwSKnVz4oa2nnR2UyhD3WbIbvMv3lRbXo06Ujtmwht_gilx_dU26kTHxOKpYDTEjAAAVLW"
+	for k, v := range list {
+		fmt.Println(k, v.OpenId)
+		wxUserInfo, err := WxGetUserInfo(v.OpenId, accessToken)
+		if err != nil {
+			fmt.Println("Err:" + err.Error())
+			return
+		}
+		unionId := wxUserInfo.Unionid
+		if unionId != "" {
+			err = models.ModifyWxUserUnionId(unionId, v.UserId)
+			if err != nil {
+				fmt.Println("ModifyWxUserUnionId Err:" + err.Error())
+				return
+			}
+		}
+	}
+}
+
+type PcWxUserInfo struct {
+	Openid         string `json:"openid"`
+	Nickname       string `json:"nickname"`
+	Sex            int    `json:"sex"`
+	Language       string `json:"language"`
+	City           string `json:"city"`
+	Province       string `json:"province"`
+	Country        string `json:"country"`
+	Headimgurl     string `json:"headimgurl"`
+	Unionid        string `json:"unionid"`
+	Errcode        int    `json:"errcode"`
+	Errmsg         string `json:"errmsg"`
+}
+
+func PcWxGetUserInfo(openId, accessToken string) (item *PcWxUserInfo, err error) {
+	requestUrl := `https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s`
+	requestUrl = fmt.Sprintf(requestUrl, accessToken, openId)
+	result, err := http.Get(requestUrl)
+	if err != nil {
+		return
+	}
+	fmt.Println("result:",string(result))
+	utils.FileLog.Info("WxGetUserInfo:%s openId:%s,accessToken:%s ", string(result), openId, accessToken)
+	utils.FileLog.Info("WxGetUserInfo Result:%s ", string(result))
+	err = json.Unmarshal(result, &item)
+	return
+}

+ 15 - 1
utils/config.go

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