xingzai преди 3 години
родител
ревизия
6b68fd1113
променени са 4 файла, в които са добавени 100 реда и са изтрити 1 реда
  1. 1 1
      controllers/activity.go
  2. 68 0
      controllers/article.go
  3. 30 0
      models/article_ask.go
  4. 1 0
      models/db.go

+ 1 - 1
controllers/activity.go

@@ -2131,5 +2131,5 @@ func (this *ActivityCoAntroller) AskAdd() {
 	}
 	br.Ret = 200
 	br.Success = true
-	br.Msg = "新增成功"
+	br.Msg = "提交成功"
 }

+ 68 - 0
controllers/article.go

@@ -605,3 +605,71 @@ Loop:
 	br.Msg = "操作成功"
 	br.Data = resp
 }
+
+// @Title 文章带问
+// @Description 新增文章带问接口
+// @Param	request	body models.AddArticleAskRep true "type json string"
+// @Success Ret=200 新增成功
+// @router /askAdd [post]
+func (this *ArticleController) AskAdd() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req models.AddArticleAskRep
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.Content == "" {
+		br.Msg = "建议内容不可为空"
+		return
+	}
+	articleId := req.ArticleId
+	content := req.Content
+	count, _ := models.GetArticleCountById(articleId)
+	if count == 0 {
+		br.Msg = "操作失败"
+		br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
+		return
+	}
+	companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
+	if err != nil {
+		br.Msg = "提交失败!"
+		br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
+		return
+	}
+	if companyDetail == nil {
+		br.Msg = "提交失败!"
+		br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
+		return
+	}
+	item := new(models.CygxArticleAsk)
+	item.UserId = user.UserId
+	item.ArticleId = req.ArticleId
+	item.CompanyId = user.CompanyId
+	item.CompanyName = companyDetail.CompanyName
+	item.CreateTime = time.Now()
+	item.Mobile = user.Mobile
+	item.Email = user.Email
+	item.Content = content
+	_, err = models.AddArticleAsk(item)
+	if err != nil {
+		br.Msg = "提交失败"
+		br.ErrMsg = "提交失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "提交成功"
+}

+ 30 - 0
models/article_ask.go

@@ -0,0 +1,30 @@
+package models
+
+import (
+	"rdluck_tools/orm"
+	"time"
+)
+
+type CygxArticleAsk struct {
+	AskId       int       `orm:"column(ask_id);pk" description:"带问id"`
+	UserId      int       `description:"用户id"`
+	ArticleId   int       `description:"文章id"`
+	CreateTime  time.Time `description:"创建时间"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	Content     string    `description:"内容"`
+}
+
+//添加优化建议
+func AddArticleAsk(item *CygxArticleAsk) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+type AddArticleAskRep struct {
+	ArticleId int    `description:"文章id"`
+	Content   string `description:"内容"`
+}

+ 1 - 0
models/db.go

@@ -59,5 +59,6 @@ func init() {
 		new(CygxActivityHelpAsk),
 		new(CygxIndustryFllow),
 		new(CygxArticleDepartmentFollow),
+		new(CygxArticleAsk),
 	)
 }