瀏覽代碼

新增申请接口

rdluck 4 年之前
父節點
當前提交
78f9facccb
共有 2 個文件被更改,包括 147 次插入4 次删除
  1. 77 4
      controllers/article.go
  2. 70 0
      models/article_interview_apply.go

+ 77 - 4
controllers/article.go

@@ -51,7 +51,7 @@ func (this *ArticleController) Detail() {
 // @Param	request	body models.ArticleCollectReq true "type json string"
 // @Success 200 {object} models.FontsCollectResp
 // @router /collect [post]
-func (this *ArticleController) FunnyCollect() {
+func (this *ArticleController) ArticleCollect() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		this.Data["json"] = br
@@ -80,7 +80,6 @@ func (this *ArticleController) FunnyCollect() {
 	resp := new(models.ArticleCollectResp)
 	if count <= 0 {
 		item := new(models.CygxArticleCollect)
-		item.CreateTime = time.Now()
 		item.ArticleId = req.ArticleId
 		item.UserId = uid
 		item.CreateTime = time.Now()
@@ -108,8 +107,82 @@ func (this *ArticleController) FunnyCollect() {
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
 		return
 	}
-	resp.CollectCount=collectTotal
+	resp.CollectCount = collectTotal
 	br.Ret = 200
 	br.Success = true
 	br.Data = resp
-}
+}
+
+// @Title 访谈申请
+// @Description 访谈申请
+// @Param	request	body models.ArticleInterviewApplyReq true "type json string"
+// @Success 200 {object} models.FontsCollectResp
+// @router /interview/apply [post]
+func (this *ArticleController) InterviewApply() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
+	var req models.ArticleInterviewApplyReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	article, err := models.GetArticleDetailById(req.ArticleId)
+	if err != nil {
+		br.Msg = "获取纪要失败!"
+		br.ErrMsg = "获取纪要失败,Err:" + err.Error()
+		return
+	}
+
+	count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
+	if err != nil {
+		br.Msg = "获取数据失败!"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	resp := new(models.ArticleInterviewApplyResp)
+	if count <= 0 {
+		item := new(models.CygxInterviewApply)
+		item.ArticleId = req.ArticleId
+		item.UserId = uid
+		item.CompanyId = this.User.CompanyId
+		item.Status = "待邀请"
+		item.Sort = 1
+		item.ArticleTitle = article.Title
+		item.InterviewTime = time.Now()
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		_, err = models.AddCygxInterviewApply(item)
+		if err != nil {
+			br.Msg = "收藏申请"
+			br.ErrMsg = "收藏申请,Err:" + err.Error()
+			return
+		}
+		br.Msg = "收藏成功"
+		resp.Status = 1
+	} else {
+		err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
+		if err != nil {
+			br.Msg = "取消申请失败"
+			br.ErrMsg = "取消申请失败,Err:" + err.Error()
+			return
+		}
+		br.Msg = "已取消申请"
+		resp.Status = 2
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Data = resp
+}

+ 70 - 0
models/article_interview_apply.go

@@ -0,0 +1,70 @@
+package models
+
+import (
+	"rdluck_tools/orm"
+	"time"
+)
+
+type CygxInterviewApply struct {
+	InterviewApplyId int       `orm:"column(interview_apply_id);pk"`
+	UserId           int       `description:"用户id"`
+	CompanyId        int       `description:"客户id"`
+	Status           string    `description:"'待邀请','待访谈','已完成','已取消'"`
+	InterviewTime    time.Time `description:"访谈时间"`
+	ArticleId        int       `description:"纪要id"`
+	Sort             int       `description:"排序"`
+	ArticleTitle     string    `description:"纪要标题"`
+	CreateTime       time.Time `description:"创建时间"`
+	ModifyTime       time.Time `description:"修改时间"`
+}
+
+//添加申请访谈信息
+func AddCygxInterviewApply(item *CygxInterviewApply) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+type ArticleInterviewApplyReq struct {
+	ArticleId int `description:"报告id"`
+}
+
+type ArticleInterviewApplyResp struct {
+	Status       int `description:"1:收藏,2:取消收藏"`
+	CollectCount int `description:"收藏总数"`
+}
+
+func RemoveArticleInterviewApply(userId, articleId int) (err error) {
+	o := orm.NewOrm()
+	sql := `DELETE FROM cygx_interview_apply WHERE user_id=? AND article_id=? `
+	_, err = o.Raw(sql, userId, articleId).Exec()
+	return
+}
+
+func GetArticleInterviewApplyUsersCount(articleId int) (count int, err error) {
+	sql := `SELECT COUNT(user_id) AS count FROM cygx_interview_apply WHERE article_id=? `
+	err = orm.NewOrm().Raw(sql, articleId).QueryRow(&count)
+	return
+}
+
+func GetArticleInterviewApplyCount(userId, articleId int) (count int, err error) {
+	sql := `SELECT COUNT(1) AS count FROM cygx_article_collect WHERE user_id=? AND article_id=? `
+	err = orm.NewOrm().Raw(sql, userId, articleId).QueryRow(&count)
+	return
+}
+
+type ArticleInterviewApplyList struct {
+	Id              int `orm:"column(id);pk"`
+	ArticleId       int
+	UserId          int
+	CreateTime      time.Time
+	Title           string `description:"标题"`
+	TitleEn         string `description:"英文标题 "`
+	UpdateFrequency string `description:"更新周期"`
+	CreateDate      string `description:"创建时间"`
+	PublishDate     string `description:"发布时间"`
+	Body            string `description:"内容"`
+	Abstract        string `description:"摘要"`
+	CategoryName    string `description:"一级分类"`
+	SubCategoryName string `description:"二级分类"`
+}