浏览代码

登录模块完成

xingzai 2 年之前
父节点
当前提交
ecf4b6d389
共有 14 个文件被更改,包括 846 次插入21 次删除
  1. 1 2
      controllers/base_auth.go
  2. 253 0
      controllers/home.go
  3. 72 0
      controllers/resource.go
  4. 92 0
      controllers/user.go
  5. 273 0
      models/chart.go
  6. 9 1
      models/db.go
  7. 53 0
      models/home.go
  8. 36 0
      models/msg_code.go
  9. 8 9
      models/session.go
  10. 9 8
      models/user.go
  11. 8 0
      models/wx_user.go
  12. 27 0
      routers/commentsRouter.go
  13. 5 0
      routers/router.go
  14. 0 1
      utils/config.go

+ 1 - 2
controllers/base_auth.go

@@ -4,7 +4,6 @@ import (
 	"encoding/json"
 	"fmt"
 	beego "github.com/beego/beego/v2/adapter"
-	"hongze/hongze_clpt/services"
 	"net/http"
 	"net/url"
 	"strconv"
@@ -65,7 +64,7 @@ func (this *BaseAuthController) Prepare() {
 				this.StopRun()
 				return
 			}
-			wxUser, err := services.GetWxUserItemByOpenId(session.UnionId)
+			wxUser, err := models.GetWxUserItemByMobile(session.Mobile)
 			if err != nil && err.Error() != utils.ErrNoRow() {
 				this.JSON(models.BaseResponse{Ret: 408, Msg: "信息已变更,请重新登陆!", ErrMsg: "获取信息失败 " + strconv.Itoa(session.UserId)}, false, false)
 				this.StopRun()

+ 253 - 0
controllers/home.go

@@ -0,0 +1,253 @@
+package controllers
+
+import (
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"strconv"
+	"strings"
+)
+
+type HomeController struct {
+	BaseAuthController
+}
+
+type BaseHomeController struct {
+	BaseCommonController
+}
+
+
+// @Title 首页列表接口v6版本
+// @Description 首页列表接口v6版本
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   ChartPermissionId   query   int  true       "品类id,最新传0"
+// @Param   CtagId   query   int  true       "图表子类ID"
+// @Param   ListType   query   int  true       "列表类型,1最新,2 纪要 ,3图表 默认1"
+// @Success 200 {object} models.HomeArtAndChartListResp
+// @router /list [get]
+func (this *HomeController) List() {
+	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
+	}
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	chartPermissionId, _ := this.GetInt("ChartPermissionId")
+	ctagId, _ := this.GetInt("CtagId")
+	listType, _ := this.GetInt("ListType")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	if listType <= 0 {
+		listType = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+
+	var condition string
+	var pars []interface{}
+	var total, chartTotal int
+	resp := new(models.HomeArtAndChartListResp)
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	var chartList []*models.HomeChartListResp
+	var err error
+	if listType == 1 {
+		if currentIndex <= 2 {
+			listCtagId := [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
+			var chartIds string
+			for _, v := range listCtagId {
+				chartListTwo, err := models.GetChartList(`AND  ctag_id = `+strconv.Itoa(v), pars, 0, 2)
+				if err != nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+					return
+				}
+				for _, vChart := range chartListTwo {
+					chartIds += strconv.Itoa(vChart.ChartId) + ","
+				}
+			}
+			chartIds = strings.TrimRight(chartIds, ",")
+			condition += ` AND chart_id IN (` + chartIds + `) `
+			chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
+			if err != nil {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+				return
+			}
+
+		}
+	} else if listType == 3 {
+		if chartPermissionId > 0 {
+			condition += ` AND a.ptag_id =? `
+			pars = append(pars, chartPermissionId)
+		}
+		if ctagId > 0 {
+			condition += ` AND a.ctag_id =? `
+			pars = append(pars, ctagId)
+		}
+		chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+			return
+		}
+		chartTotal, err = models.GetChartCount(condition, pars)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.Msg = "获取帖子总数失败,Err:" + err.Error()
+			return
+		}
+	}
+	for k, v := range chartList {
+		if v.PtagName != "" {
+			chartList[k].CtagNamePc = v.PtagName
+		}
+		if v.CtagName != "" {
+			chartList[k].CtagNamePc += "," + v.CtagName
+		}
+		if v.PtagNameTwo != "" {
+			chartList[k].CtagNamePc += "," + v.PtagNameTwo
+		}
+		if v.CtagNameTwo != "" {
+			chartList[k].CtagNamePc += "," + v.CtagNameTwo
+		}
+		chartList[k].IsNeedJump = true
+		chartList[k].Source = 2
+	}
+	resp.ChartList = chartList
+
+	if listType != 3 {
+		//userType, _, err := services.GetUserType(user.CompanyId)
+		//if err != nil {
+		//	br.Msg = "获取信息失败"
+		//	br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+		//	return
+		//}
+		//condition = ` AND is_summary = 1  `
+		//if chartPermissionId > 0 {
+		//	categoryId, err := models.GetCategoryId(chartPermissionId)
+		//	if err != nil && err.Error() != utils.ErrNoRow() {
+		//		br.Msg = "获取信息失败"
+		//		br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
+		//		return
+		//	}
+		//	categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
+		//	if err != nil {
+		//		br.Msg = "获取信息失败"
+		//		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		//		return
+		//	}
+		//	if userType == 1 && strings.Contains(categoryinfo.PermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
+		//		resp.HaveResearch = false
+		//		resp.Paging = page
+		//		br.Ret = 200
+		//		br.Success = true
+		//		br.Msg = "获取成功"
+		//		br.Data = resp
+		//		return
+		//	}
+		//	page = paging.GetPaging(currentIndex, pageSize, total)
+		//	if categoryId != "" {
+		//		condition += ` AND category_id IN(` + categoryId + `)`
+		//		//condition += ` OR ( category_name  LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%' AND publish_status = 1 AND is_summary = 1 )`
+		//	} else {
+		//		condition += ` AND  category_name   LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
+		//	}
+		//}
+		////永续客户无法查看研选分类的内容
+		//if userType == 1 {
+		//	condition += ` AND  category_name  NOT LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
+		//}
+		//total, err = models.GetHomeCount(condition, pars)
+		//if err != nil {
+		//	br.Msg = "获取信息失败"
+		//	br.Msg = "获取帖子总数失败,Err:" + err.Error()
+		//	return
+		//}
+		//
+		//list, err := models.GetHomeList(condition, pars, startSize, pageSize)
+		//if err != nil {
+		//	br.Msg = "获取信息失败"
+		//	br.Msg = "获取帖子数据失败,Err:" + err.Error()
+		//	return
+		//}
+		////研选的五张图片
+		//detailResearch, err := models.GetConfigByCode("category_research_img_url")
+		//if err != nil {
+		//	br.Msg = "获取数据失败"
+		//	br.ErrMsg = "获取数据研选分类图片失败,Err:" + err.Error()
+		//	return
+		//}
+		//researchList := strings.Split(detailResearch.ConfigValue, "{|}")
+		////对应分类的所图片
+		//detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
+		//if err != nil {
+		//	br.Msg = "获取数据失败"
+		//	br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
+		//	return
+		//}
+		//categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
+		//mapCategoryUrl := make(map[string]string)
+		//var categoryId string
+		//var imgUrlChart string
+		//for _, v := range categoryUrlList {
+		//	vslice := strings.Split(v, "_")
+		//	categoryId = vslice[0]
+		//	imgUrlChart = vslice[len(vslice)-1]
+		//	mapCategoryUrl[categoryId] = imgUrlChart
+		//}
+		//
+		//for k, v := range list {
+		//	item := list[k]
+		//	//如果文章一开始的内容是图片,优先展示第一张图片
+		//	imgurl, _ := services.FixArticleImgUrl(html.UnescapeString(list[k].Body))
+		//	newBody, _ := services.GetReportContentTextSubByarticle(item.Body, item.Abstract, item.ArticleId)
+		//	list[k].Body = newBody
+		//	if imgurl != "" {
+		//		list[k].BodyHtml = imgurl
+		//	}
+		//	list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDateTimeNoSecond) //时间字符串格式转时间格式
+		//	if strings.Contains(item.CategoryName, utils.CHART_PERMISSION_NAME_YANXUAN) {
+		//		list[k].IsResearch = true
+		//	}
+		//	if item.Pv > 999 {
+		//		list[k].Pv = 999
+		//	}
+		//	//如果是研选系列的任意取五张图片的中的一张
+		//	if v.CategoryId == "0" {
+		//		knum := v.ArticleId % 5
+		//		list[k].ImgUrlPc = researchList[knum]
+		//	} else {
+		//		list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
+		//	}
+		//	if list[k].ArticleId < utils.SummaryArticleId {
+		//		list[k].HttpUrl = utils.StrategyPlatform + strconv.Itoa(v.ArticleId)
+		//		list[k].IsNeedJump = true
+		//	}
+		//	list[k].Source = 1
+		//}
+		//resp.List = list
+	}
+	if chartTotal > total {
+		total = chartTotal
+	}
+	page = paging.GetPaging(currentIndex, pageSize, total)
+	resp.Paging = page
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 72 - 0
controllers/resource.go

@@ -0,0 +1,72 @@
+package controllers
+
+import (
+	"encoding/json"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/services"
+	"hongze/hongze_clpt/utils"
+	"time"
+)
+
+//资源管理-图片上传,合同上传等
+type ResourceController struct {
+	BaseAuthController
+}
+type BaseResourceController struct {
+	BaseCommonController
+}
+
+// @Title 获取短信验证码
+// @Description 获取短信验证码接口
+// @Param	request	body models.MsgCodeResp true "type json string"
+// @Success Ret=200 获取成功
+// @router /getSmsCode [post]
+func (this *BaseResourceController) GetSmsCode() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	var req models.MsgCodeResp
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	mobile := req.Mobile
+	if mobile == "" {
+		br.Msg = "请输入手机号"
+		return
+	}
+	areaNum := req.AreaNum
+	msgCode := utils.GetRandDigit(4)
+	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
+}

+ 92 - 0
controllers/user.go

@@ -1,5 +1,14 @@
 package controllers
 
+import (
+	"encoding/json"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+	"strconv"
+	"strings"
+	"time"
+)
+
 type UserController struct {
 	BaseAuthController
 }
@@ -7,3 +16,86 @@ type UserController struct {
 type UserCommonController struct {
 	BaseCommonController
 }
+
+// @Title 登录
+// @Description 登录接口
+// @Param	request	body models.LoginReq true "type json string"
+// @Success 200 {object} models.LoginResp
+// @router /login [post]
+func (this *UserCommonController) Login() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var token string
+	var req models.LoginReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	mobile := req.Mobile
+	req.Mobile = strings.Trim(req.Mobile, " ")
+	if req.Mobile == "" {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,手机号为空"
+		return
+	}
+	code := req.VCode
+	if code == "" {
+		br.Msg = "参数错误"
+		br.ErrMsg = "Code 为空"
+		return
+	}
+	item, err := models.GetMsgCode(req.Mobile, req.VCode)
+	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
+	}
+	user, err := models.GetWxUserItemByMobile(mobile)
+	if err != nil {
+		br.Msg = "登录失败"
+		br.ErrMsg = "获取用户信息失败,GetUserDetailByMobile Err:" + err.Error()
+		return
+	}
+	timeUnix := time.Now().Unix()
+	timeUnixStr := strconv.FormatInt(timeUnix, 10)
+	token = utils.MD5(mobile) + utils.MD5(timeUnixStr)
+	itemsSession := new(models.CygxClptSession)
+	itemsSession.UserId = user.UserId
+	itemsSession.Mobile = mobile
+	itemsSession.AccessToken = token
+	itemsSession.CreatedTime = time.Now()
+	itemsSession.LastUpdatedTime = time.Now()
+	itemsSession.ExpireTime = time.Now().AddDate(0, 3, 0)
+	err = models.AddCygxClptSession(itemsSession)
+	if err != nil {
+		br.Msg = "获取用户信息失败"
+		br.ErrMsg = "添加Token失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.LoginResp)
+	resp.UserId = user.UserId
+	resp.Headimgurl = user.Headimgurl
+	resp.Mobile = user.Mobile
+	resp.Email = user.Email
+	resp.CompanyName = user.CompanyName
+	resp.Authorization = token
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 273 - 0
models/chart.go

@@ -0,0 +1,273 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"time"
+)
+
+type ChartResultApi struct {
+	Data []ChartResultApidate `json:"data"`
+	Code int                  `json:"code"`
+	Msg  string               `json:"msg"`
+}
+
+type ChartFavoritesResultApi struct {
+	Data       []ChartInfo `json:"data"`
+	Code       int         `json:"code"`
+	Msg        string      `json:"msg"`
+	Pagination Pagination  `json:"pagination"`
+}
+
+type Pagination struct {
+	Total     int `json:"total"`
+	Page      int `json:"id"`
+	PageSize  int `json:"page_size"`
+	PageTotal int `json:"page_total"`
+}
+
+type ChartInfo struct {
+	ChartInfo  *ChartResultApidate `json:"chart_info"`
+	ChartId    int                 `json:"chart_id"`
+	CreateDate string              `json:"add_favorites_time"`
+}
+
+type ChartResultApidate struct {
+	ChartId       int    `json:"id"`
+	PtagId        int    `json:"ptag_id"`
+	CtagId        int    `json:"ctag_id"`
+	Title         string `json:"title"`
+	TitleEn       string `json:"title_en"`
+	CreateDate    string `json:"create_date"`
+	UpdateDate    string `json:"update_date"`
+	PublishStatus int    `json:"publish_status"`
+	Cover         string `json:"cover"`
+	Iframe        string `json:"iframe"`
+	Ptag          Ptag   `json:"ptag"`
+	Ctag          Ptag   `json:"ctag"`
+	PtagTwo       Ptag   `json:"ptag1"`
+	CtagTwo       Ptag   `json:"ctag1"`
+}
+
+type Ptag struct {
+	Id          int    `json:"id"`
+	Name        string `json:"name"`
+	Description string `json:"description"`
+}
+
+type Ctag struct {
+	Id          int    `json:"id"`
+	Name        string `json:"name"`
+	Description string `json:"description"`
+	PtagId      int    `json:"ptag_id"`
+}
+
+type CygxChart struct {
+	Id            int       `orm:"column(id);pk"`
+	ChartId       int       `description:"图表id"`
+	PtagId        int       `description:"图表父类分类id"`
+	CtagId        int       `description:"图表子类分类id"`
+	PtagIdTwo     int       `description:"图表父类分类id"`
+	CtagIdTwo     int       `description:"图表子类分类id"`
+	Title         string    `description:"标题"`
+	TitleEn       string    `description:"英文标题 "`
+	CreateDate    string    `description:"本地创建时间"`
+	CreateDateApi time.Time `description:"图表创建时间"`
+	PublishStatus int       `description:"发布状态"`
+	PtagName      string    `description:"父类名称"`
+	CtagName      string    `description:"子类名称"`
+	Cover         string    `description:"图表图片"`
+	Iframe        string    `description:"图表详情跳转地址"`
+	PtagNameTwo   string    `description:"父类名称"`
+	CtagNameTwo   string    `description:"子类名称"`
+}
+
+type CygxChartDetail struct {
+	ChartId       int    `description:"图表id"`
+	Title         string `description:"标题"`
+	TitleEn       string `description:"英文标题 "`
+	IsCollection  bool   `description:"是否收藏 "`
+	CollectionNum int    `description:"本人收藏数量 "`
+	HttpUrl       string `orm:"column(iframe)";description:"文章链接跳转地址"`
+}
+
+func GetChartCountById(chartId int) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS count FROM cygx_chart WHERE chart_id = ? `
+	err = o.Raw(sql, chartId).QueryRow(&count)
+	return
+}
+
+//新增图表
+func AddCygxChart(item *CygxChart) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+//标签分类
+type ChartPtagResultApi struct {
+	Data []ChartPtagResultApidate `json:"data"`
+	Code int                      `json:"code"`
+	Msg  string                   `json:"msg"`
+}
+
+type ChartPtagResultApidate struct {
+	ChartPermissionId   int    `json:"id"`
+	ChartPermissionName string `json:"name"`
+	Ctag                []Ctag `json:"ctag"`
+}
+
+type ChartPtagResp struct {
+	ChartPermissionId int         `description:"分类ID"`
+	PermissionName    string      `description:"分类名称"`
+	List              []*CtagResp `description:"子分类"`
+}
+
+type CtagResp struct {
+	CtagId int    `description:"子分类ID"`
+	Name   string `description:"子分类名称"`
+}
+
+type ChartUserTokenResult struct {
+	AccessToken string `json:"access_token"`
+}
+
+type ChartUserTokenResultApi struct {
+	Data ChartUserTokenResult `json:"data"`
+	Code int                  `json:"code"`
+	Msg  string               `json:"msg"`
+}
+
+
+
+type HomeChartListItem struct {
+	IsBindingMobile bool `description:"是否绑定过手机号"`
+	Paging          *paging.PagingItem
+	List            []*HomeChartListResp `description:"图表列表"`
+}
+
+type ChartCollectReq struct {
+	ChartId int `description:"图表ID"`
+}
+
+//获取图表列表
+func GetChartList(condition string, pars []interface{}, startSize, pageSize int) (items []*HomeChartListResp, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY create_date DESC LIMIT ?,? `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+//获取所有同步过来的图表
+func GetChartListAll() (items []*HomeChartListResp, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT chart_id FROM cygx_chart  `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+////获取图表列表
+//func GetChartCtagIds(ctagId int ) (items []*HomeChartListResp, err error) {
+//	o := orm.NewOrm()
+//	sql := ` SELECT  * FROM cygx_chart AS a WHERE a.publish_status=1 AND  ctag_id = 1 ORDER BY create_date DESC LIMIT 2 `
+//	_, err = o.Raw(sql,ctagId).QueryRows(&items)
+//	return
+//}
+
+//获取图表列表
+func GetChartListCollection(chartIds string, userId, startSize, pageSize int) (items []*HomeChartListResp, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT a.*,
+			t.create_time AS t_create_time,
+			c.create_time AS c_create_time,
+			( SELECT COUNT(*) FROM cygx_chart_top AS t WHERE t.chart_id = a.chart_id AND t.user_id = ? ) AS num_top,
+			( SELECT COUNT(*) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS num_c 
+		FROM
+			cygx_chart_all AS a
+			LEFT JOIN cygx_chart_top AS t ON t.chart_id = a.chart_id
+			LEFT JOIN cygx_chart_collect AS c ON c.chart_id = a.chart_id 
+		WHERE
+			a.publish_status = 1 
+			AND a.chart_id IN (` + chartIds + `) 
+		GROUP BY
+			a.chart_id 
+		ORDER BY
+			t_create_time DESC,
+			c_create_time DESC LIMIT ?,? `
+	_, err = o.Raw(sql, userId, userId, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+//获取图表列表本地
+func GetChartListCollectionWithCygx(userId, startSize, pageSize int) (items []*HomeChartListResp, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT
+			a.*,
+			t.create_time AS t_create_time,
+			c.create_time AS c_create_time,
+			( SELECT COUNT(*) FROM cygx_chart_top AS t WHERE t.chart_id = a.chart_id AND t.user_id = ? ) AS num_top,
+			( SELECT COUNT(*) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS num_c 
+		FROM
+			cygx_chart_collect AS c
+			INNER JOIN cygx_chart AS a ON c.chart_id = a.chart_id
+			LEFT JOIN cygx_chart_top AS t ON t.chart_id = a.chart_id 
+		WHERE
+			a.publish_status = 1 
+			AND c.user_id =? 
+		GROUP BY
+			a.chart_id 
+		ORDER BY
+			t_create_time DESC,
+			c_create_time DESC LIMIT ?,? `
+	_, err = o.Raw(sql, userId, userId, userId, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+func GetChartListConfig() (items []*HomeChartListResp, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1    AND  ctag_id IN (7,8,9,10) GROUP BY ctag_id  ORDER BY create_date  DESC LIMIT 4 `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//获取图表数量
+func GetChartCount(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS count
+                FROM cygx_chart AS a
+                WHERE a.publish_status=1 `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+//获取图表数量
+func GetChartCollentCount(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS count
+                FROM cygx_chart_all AS a
+                WHERE a.publish_status=1 `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func GetChartDetailById(chartId, uid int) (item *CygxChartDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * ,( SELECT COUNT( 1 ) FROM cygx_chart_collect AS c WHERE c.chart_id = a.chart_id AND c.user_id = ? ) AS collection_num
+		FROM
+			cygx_chart_all  as a 
+		WHERE
+			a.chart_id =? `
+	err = o.Raw(sql, uid, chartId).QueryRow(&item)
+	return
+}

+ 9 - 1
models/db.go

@@ -17,14 +17,22 @@ func init() {
 	db, _ := orm.GetDB("default")
 	db.SetConnMaxLifetime(10 * time.Minute)
 
+	_ = orm.RegisterDataBase("rddp", "mysql", utils.MYSQL_URL_RDDP)
+	orm.SetMaxIdleConns("rddp", 50)
+	orm.SetMaxOpenConns("rddp", 100)
+
+	report_db, _ := orm.GetDB("rddp")
+	report_db.SetConnMaxLifetime(10 * time.Minute)
+
 	//注册对象
 	orm.RegisterModel(
 		new(WxUser),
 		new(WxUserCode),
 		new(UserRecord),
 		new(CygxUserRecord),
-		new(CygxXzsSession),
+		new(CygxClptSession),
 		new(CygxIndustryFllow),
+		new(MsgCode),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 53 - 0
models/home.go

@@ -0,0 +1,53 @@
+package models
+
+import (
+	//"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
+
+type HomeArtAndChartListResp struct {
+	Paging       *paging.PagingItem
+	List         []*HomeArticle       `description:"文章列表"`
+	ChartList    []*HomeChartListResp `description:"图表列表"`
+}
+
+
+type HomeArticle struct {
+	ArticleId        int    `description:"文章id"`
+	Title            string `description:"标题"`
+	TitleEn          string `description:"英文标题 "`
+	UpdateFrequency  string `description:"更新周期"`
+	CreateDate       string `description:"创建时间"`
+	PublishDate      string `description:"发布时间"`
+	Body             string `description:"内容"`
+	BodyHtml         string `description:"内容带有HTML标签"`
+	Abstract         string `description:"摘要"`
+	CategoryName     string `description:"一级分类"`
+	SubCategoryName  string `description:"二级分类"`
+	ExpertBackground string `description:"专家背景"`
+	IsResearch       bool   `description:"是否属于研选"`
+	Pv               int    `description:"PV"`
+	ImgUrlPc         string `description:"图片链接"`
+	CategoryId       string `description:"文章分类"`
+	HttpUrl          string `description:"文章链接跳转地址"`
+	IsNeedJump       bool   `description:"是否需要跳转链接地址"`
+	Source           int    `description:"来源  1:文章, 2:图表"`
+}
+
+type HomeChartListResp struct {
+	ChartId     int    `description:"图表ID"`
+	Title       string `description:"标题"`
+	TitleEn     string `description:"英文标题 "`
+	CreateDate  string `description:"创建时间"`
+	PtagName    string `description:"父类名称"`
+	CtagName    string `description:"子类名称"`
+	PtagNameTwo string `description:"父类名称"`
+	CtagNameTwo string `description:"子类名称"`
+	CtagNamePc  string `description:"Pc端所有的分类名称"`
+	BodyHtml    string `orm:"column(cover)";description:"图片链接"`
+	HttpUrl     string `orm:"column(iframe)";description:"文章链接跳转地址"`
+	IsNeedJump  bool   `description:"是否需要跳转链接地址"`
+	IsTop       bool   `description:"是否置顶"`
+	NumTop      int    `description:"置顶数量"`
+	Source      int    `description:"来源  1:文章, 2:图表"`
+}

+ 36 - 0
models/msg_code.go

@@ -0,0 +1,36 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type MsgCode struct {
+	MsgCodeId       int `orm:"column(msg_code_id);pk"`
+	OpenId          string
+	Mobile          string
+	Code            string
+	ExpiredIn       int64
+	Enabled         int
+	CreatedTime     time.Time
+	LastUpdatedTime time.Time
+}
+
+type MsgCodeResp struct {
+	Mobile  string `description:"手机号"`
+	AreaNum string `description:"地区编码 国内默认为空"`
+}
+
+//添加用户session信息
+func AddMsgCode(item *MsgCode) (err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	_, err = o.Insert(item)
+	return
+}
+
+func GetMsgCode(mobile, code string) (item *MsgCode, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM msg_code WHERE mobile=? AND code=? AND FROM_UNIXTIME(expired_in)>=NOW() `
+	err = o.Raw(sql, mobile, code).QueryRow(&item)
+	return
+}

+ 8 - 9
models/session.go

@@ -5,18 +5,17 @@ import (
 	"time"
 )
 
-func GetSessionByToken(token string) (item *CygxXzsSession, err error) {
-	sql := `SELECT * FROM cygx_xzs_session WHERE access_token=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
+func GetSessionByToken(token string) (item *CygxClptSession, err error) {
+	sql := `SELECT * FROM cygx_clpt_session WHERE access_token=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
 	o := orm.NewOrm()
 	err = o.Raw(sql, token).QueryRow(&item)
 	return
 }
 
-type CygxXzsSession struct {
+type CygxClptSession struct {
 	SessionId       int `orm:"column(session_id);pk"`
-	UnionId         string
+	Mobile          string
 	UserId          int
-	OpenId          string
 	AccessToken     string
 	ExpireTime      time.Time
 	CreatedTime     time.Time
@@ -24,21 +23,21 @@ type CygxXzsSession struct {
 }
 
 //添加用户session信息
-func AddCygxXzsSession(item *CygxXzsSession) (err error) {
+func AddCygxClptSession(item *CygxClptSession) (err error) {
 	o := orm.NewOrm()
 	_, err = o.Insert(item)
 	return
 }
 
 func GetXzsSessionCountByToken(token string) (count int, err error) {
-	sql := `SELECT COUNT(1) AS count FROM cygx_xzs_session WHERE access_token=? LIMIT 1 `
+	sql := `SELECT COUNT(1) AS count FROM cygx_clpt_session WHERE access_token=? LIMIT 1 `
 	o := orm.NewOrm()
 	err = o.Raw(sql, token).QueryRow(&count)
 	return
 }
 
 //获取用户token详情
-func GetUnionidByToken(token string) (item *CygxXzsSession, err error) {
+func GetUnionidByToken(token string) (item *CygxClptSession, err error) {
 	sql := `SELECT * FROM cygx_xzs_session WHERE access_token=?  LIMIT 1 `
 	o := orm.NewOrm()
 	err = o.Raw(sql, token).QueryRow(&item)
@@ -46,7 +45,7 @@ func GetUnionidByToken(token string) (item *CygxXzsSession, err error) {
 }
 
 //根据用户openid获取token
-func GetTokenByOpenId(openId string) (item *CygxXzsSession, err error) {
+func GetTokenByOpenId(openId string) (item *CygxClptSession, err error) {
 	sql := `SELECT * FROM cygx_xzs_session WHERE open_id=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
 	o := orm.NewOrm()
 	err = o.Raw(sql, openId).QueryRow(&item)

+ 9 - 8
models/user.go

@@ -30,17 +30,21 @@ func GetUserDetailByUserId(userId int) (item *UserDetail, err error) {
 	return
 }
 
+func GetUserDetailByMobile(mobile string) (item *UserDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM wx_user WHERE mobile = ? `
+	err = o.Raw(sql, mobile).QueryRow(&item)
+	return
+}
+
 type UserPermission struct {
 	CompanyName         string `description:"公司名称"`
 	ChartPermissionName string `description:"权限"`
 }
 
 type LoginReq struct {
-	LoginType   int    `description:"登录方式:1:微信手机,2:邮箱,3:自定义手机登录"`
-	Mobile      string `description:"手机号"`
-	Email       string `description:"邮箱"`
-	VCode       string `description:"验证码"`
-	CountryCode string `description:"区号"`
+	Mobile string `description:"手机号"`
+	VCode  string `description:"验证码"`
 }
 
 func PcBindMobile(unionId, mobile string, userId, loginType int) (wxUserId int, err error) {
@@ -122,9 +126,6 @@ type LoginResp struct {
 	Mobile        string `description:"手机号"`
 	Email         string `description:"邮箱"`
 	CompanyName   string `description:"客户名称"`
-	Status        string `description:"状态"`
-	EndDate       string `description:"到期日期"`
-	ProductName   string `description:"客户类型名称"`
 }
 
 type CheckStatusResp struct {

+ 8 - 0
models/wx_user.go

@@ -86,6 +86,14 @@ func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
 	return
 }
 
+func GetWxUserItemByMobile(mobile string) (item *WxUserItem, err error) {
+	sql := `SELECT a.*,b.company_name FROM wx_user AS a
+			LEFT JOIN company AS b on a.company_id=b.company_id
+			WHERE a.mobile=? `
+	err = orm.NewOrm().Raw(sql, mobile).QueryRow(&item)
+	return
+}
+
 type WxLoginResp struct {
 	Authorization string
 	UserId        int

+ 27 - 0
routers/commentsRouter.go

@@ -7,6 +7,15 @@ import (
 
 func init() {
 
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:BaseResourceController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:BaseResourceController"],
+        beego.ControllerComments{
+            Method: "GetSmsCode",
+            Router: `/getSmsCode`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ChartPermissionController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ChartPermissionController"],
         beego.ControllerComments{
             Method: "Detail",
@@ -16,4 +25,22 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:HomeController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:HomeController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:UserCommonController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:UserCommonController"],
+        beego.ControllerComments{
+            Method: "Login",
+            Router: `/login`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
 }

+ 5 - 0
routers/router.go

@@ -41,6 +41,11 @@ func init() {
 				&controllers.ChartPermissionAuthController{},
 			),
 		),
+		web.NSNamespace("/resource",
+			web.NSInclude(
+				&controllers.BaseResourceController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 0 - 1
utils/config.go

@@ -55,7 +55,6 @@ func init() {
 	fmt.Println(RunMode + " 模式")
 	MYSQL_URL = config["mysql_url"]
 	MYSQL_URL_RDDP = config["mysql_url_rddp"]
-	MYSQL_URL_TACTICS = config["mysql_url_tactics"]
 
 	REDIS_CACHE = config["beego_cache"]
 	if len(REDIS_CACHE) <= 0 {