浏览代码

新增判断 是否小套餐客户接口

rdluck 4 年之前
父节点
当前提交
42ce0e1ef9
共有 4 个文件被更改,包括 126 次插入13 次删除
  1. 22 0
      controllers/report.go
  2. 57 6
      controllers/user.go
  3. 38 3
      models/report.go
  4. 9 4
      models/wx_user.go

+ 22 - 0
controllers/report.go

@@ -136,6 +136,28 @@ func (this *ReportController) Detail() {
 			go utils.SendEmail(utils.APPNAME+"失败提醒", "新增报告阅读记录失败:Err:"+err.Error(), utils.EmailSendToUsers)
 		}
 	}
+	recommendList, err := models.GetRecommendList(reportId)
+	if err != nil {
+		br.Msg = "获取报告详情失败"
+		br.ErrMsg = "获取报告推荐列表信息失败,Err:" + err.Error()
+		return
+	}
+	recommendListLen := len(recommendList)
+	for i := 0; i < recommendListLen; i++ {
+		item := recommendList[i]
+		recommendList[i].Content = html.UnescapeString(item.Content)
+		recommendList[i].ContentSub = html.UnescapeString(item.ContentSub)
+		count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond)
+		if err != nil {
+			br.Msg = "获取报告详情失败"
+			br.ErrMsg = "判断报告权限信息失败,Err:" + err.Error()
+			return
+		}
+		if count > 0 {
+			recommendList[i].HasPermission = 1
+		}
+	}
+	resp.RecommendList = recommendList
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 57 - 6
controllers/user.go

@@ -5,6 +5,7 @@ import (
 	"hongze/hongze_api/models"
 	"hongze/hongze_api/services"
 	"hongze/hongze_api/utils"
+	"strconv"
 	"time"
 )
 
@@ -41,7 +42,13 @@ func (this *UserController) Detail() {
 		br.ErrMsg = "获取信息失败,Err:" + err.Error()
 		return
 	}
-
+	userPermission, err := services.CheckUserPermission(user.UserId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "判断用户权限信息失败,Err:" + err.Error()
+		return
+	}
+	item.UserPermission = userPermission
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
@@ -110,13 +117,13 @@ func (this *UserCommonController) CheckSmsCode() {
 		return
 	}
 	if req.Mobile != "" {
-		br.Msg="请输入手机号"
-		br.ErrMsg="请输入手机号"
+		br.Msg = "请输入手机号"
+		br.ErrMsg = "请输入手机号"
 		return
 	}
 	if req.SmsCode == "" {
-		br.Msg="请输入验证码"
-		br.ErrMsg="请输入验证码"
+		br.Msg = "请输入验证码"
+		br.ErrMsg = "请输入验证码"
 		return
 	}
 	//item,err:=models.GetMsgCode(req.Mobile,req.SmsCode)
@@ -147,7 +154,6 @@ func (this *UserCommonController) CheckSmsCode() {
     }
 */
 
-
 /*
 $app->post('api/user/checkSmsCode',"UserController@checkSmsCode");//校验短信验证码
 $app->get('api/user/getEmailCode',"UserController@getEmailCode");//获取邮件验证码
@@ -156,3 +162,48 @@ $app->post('api/user/login',"UserController@login");//登录
 $app->post('api/user/apply',"UserController@apply");//申请试用
 $app->get('api/user/smallLimit',"UserController@smallLimit");//是否小套餐客户
 */
+
+// @Title 是否小套餐客户
+// @Description 是否小套餐客户接口
+// @Success 200 {object} models.SmallLimitResp
+// @router /smallLimit [get]
+func (this *UserController) SmallLimit() {
+	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
+	}
+	userItem, err := models.GetWxUserItemByUserId(user.UserId)
+	if err != nil {
+		br.Msg = "获取用户信息失败"
+		br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+		return
+	}
+	if userItem == nil {
+		br.Msg = "获取用户信息失败"
+		br.ErrMsg = "用户信息不存在,UserId:" + strconv.Itoa(user.UserId)
+		return
+	}
+	maxCount, err := models.GetUserIsMaxPermission(userItem.CompanyId)
+	if err != nil {
+		br.Msg = "获取用户信息失败"
+		br.ErrMsg = "判断是否最大客户权限失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.SmallLimitResp)
+	if maxCount >= 15 {
+		resp.IsMaxPermission = 1
+	} else {
+		resp.IsMaxPermission = 0
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}

+ 38 - 3
models/report.go

@@ -119,11 +119,46 @@ func GetReportVarietyListByUserIdExt(userId int, reportType string) (list []*Rep
 }
 
 type ReportDetailResp struct {
-	Report *Report `description:"报告"`
-	Status int     `description:"状态:0:正常展示,1:报告不存在,2:无权限"`
-	Msg    string  `description:"提示信息"`
+	Report        *Report            `description:"报告"`
+	RecommendList []*RecommendReport `description:"推荐报告列表"`
+	Status        int                `description:"状态:0:正常展示,1:报告不存在,2:无权限"`
+	Msg           string             `description:"提示信息"`
 }
 
 type ReportRecordReq struct {
 	ReportId int `description:"报告Id"`
 }
+
+type RecommendReport struct {
+	Id                 int       `description:"报告Id"`
+	AddType            int       `description:"新增方式:1:新增报告,2:继承报告"`
+	ClassifyIdFirst    int       `description:"一级分类id"`
+	ClassifyNameFirst  string    `description:"一级分类名称"`
+	ClassifyIdSecond   int       `description:"二级分类id"`
+	ClassifyNameSecond string    `description:"二级分类名称"`
+	Title              string    `description:"标题"`
+	Abstract           string    `description:"摘要"`
+	Author             string    `description:"作者"`
+	Frequency          string    `description:"频度"`
+	CreateTime         string    `description:"创建时间"`
+	ModifyTime         time.Time `description:"修改时间"`
+	State              int       `description:"1:未发布,2:已发布"`
+	PublishTime        string    `description:"发布时间"`
+	Stage              int       `description:"期数"`
+	MsgIsSend          int       `description:"消息是否已发送,0:否,1:是"`
+	Content            string    `description:"内容"`
+	VideoUrl           string    `description:"音频文件URL"`
+	VideoName          string    `description:"音频文件名称"`
+	VideoPlaySeconds   string    `description:"音频播放时长"`
+	ContentSub         string    `description:"内容前两个章节"`
+	ClassifyName       string    `description:"分类名称"`
+	HasPermission      int       `description:"报告权限:0:无权限,1:有权限"`
+}
+
+func GetRecommendList(reportId int) (items []*RecommendReport, err error) {
+	o := orm.NewOrm()
+	o.Using("rddp")
+	sql := `SELECT * FROM report WHERE id<>? ORDER BY publish_time DESC LIMIT 3`
+	_, err = o.Raw(sql, reportId).QueryRows(&items)
+	return
+}

+ 9 - 4
models/wx_user.go

@@ -112,10 +112,11 @@ type WxLoginResp struct {
 }
 
 type UserDetail struct {
-	FirstLogin int    `description:"是否第一次登陆"`
-	Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
-	Mobile     string `description:"手机号码"`
-	Email      string `description:"邮箱"`
+	FirstLogin     int    `description:"是否第一次登陆"`
+	Headimgurl     string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
+	Mobile         string `description:"手机号码"`
+	Email          string `description:"邮箱"`
+	UserPermission int    `description:"用户权限状态:0:付费用户,可正常查看报告,40001:获取用户信息失败,40002:非付费用户"`
 }
 
 func GetUserDetailByUserId(userId int) (item *UserDetail, err error) {
@@ -129,3 +130,7 @@ type CheckSmsCodeReq struct {
 	Mobile  string `description:"邮箱"`
 	SmsCode string `description:"验证码"`
 }
+
+type SmallLimitResp struct {
+	IsMaxPermission int
+}