ソースを参照

更新头像接口

ziwen 1 年間 前
コミット
07f60b11d0

+ 58 - 3
controllers/yanxuan_special.go

@@ -41,7 +41,7 @@ func (this *YanxuanSpecialController) List() {
 		pars = append(pars, userId)
 	}
 
-	specialUser, err = models.GetYanxuanSpecialAuthor(sysUser.UserId,sysUser.UserId)
+	specialUser, err = models.GetYanxuanSpecialAuthor(sysUser.UserId, sysUser.UserId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败, Err:" + err.Error()
@@ -111,7 +111,9 @@ func (this *YanxuanSpecialController) Detail() {
 		br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
 		return
 	}
-
+	if item.MyCollectNum > 0 {
+		item.IsCollect = 1
+	}
 	if item.Status != 3 && item.Status != 2 {
 		br.Msg = "获取失败,专栏未发布"
 		br.ErrMsg = "获取失败, 专栏未发布"
@@ -771,7 +773,7 @@ func (this *YanxuanSpecialController) AuthorList() {
 	var specialUser *models.CygxYanxuanSpecialAuthorItem
 	var err error
 
-	specialUser, err = models.GetYanxuanSpecialAuthor(sysUser.UserId,sysUser.UserId)
+	specialUser, err = models.GetYanxuanSpecialAuthor(sysUser.UserId, sysUser.UserId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败, Err:" + err.Error()
@@ -797,3 +799,56 @@ func (this *YanxuanSpecialController) AuthorList() {
 	br.Success = true
 	br.Msg = "获取成功"
 }
+
+// @Title 更新作者头像
+// @Description 更新作者头像
+// @Param	request	body help_doc.AddHelpDocReq true "type json string"
+// @Success 200 {object} models.AddEnglishReportResp
+// @router /author/head_img [post]
+func (this *YanxuanSpecialController) AuthorHeadImg() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.User
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	var req models.SaveCygxYanxuanSpecialAuthoHeadImgrReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.UserId <= 0 {
+		br.Msg = "用户id有误"
+		return
+	}
+	if req.HeadImg == "" {
+		br.Msg = "头像图片错误"
+		return
+	}
+
+	item := models.CygxYanxuanSpecialAuthor{
+		UserId: req.UserId,
+		HeadImg:    req.HeadImg,
+	}
+
+	err = models.UpdateYanxuanSpecialAuthorHeadImg(&item)
+	if err != nil {
+		br.Msg = "保存失败"
+		br.ErrMsg = "保存失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "保存成功"
+}

+ 13 - 0
models/cygx_yanxuan_special_user.go

@@ -114,3 +114,16 @@ type SpecialAuthorListResp struct {
 	List     []*CygxYanxuanSpecialAuthorItem
 	IsAuthor bool
 }
+
+type SaveCygxYanxuanSpecialAuthoHeadImgrReq struct {
+	UserId  int    // 用户ID
+	HeadImg string // 头像
+}
+
+func UpdateYanxuanSpecialAuthorHeadImg(item *CygxYanxuanSpecialAuthor) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special_author SET head_img=?,modify_time=NOW() WHERE user_id = ? `
+	_, err = o.Raw(sql, item.HeadImg, item.UserId).Exec()
+	return
+}

+ 9 - 0
routers/commentsRouter.go

@@ -1654,6 +1654,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:YanxuanSpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:YanxuanSpecialController"],
+        beego.ControllerComments{
+            Method: "AuthorHeadImg",
+            Router: `/author/head_img`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:YanxuanSpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:YanxuanSpecialController"],
         beego.ControllerComments{
             Method: "AuthorList",