Prechádzať zdrojové kódy

修改作者id为专栏栏目id

ziwen 1 rok pred
rodič
commit
6e9d360241

+ 40 - 26
controllers/yanxuan_special.go

@@ -36,15 +36,15 @@ func (this *YanxuanSpecialController) List() {
 		return
 	}
 
-	userId, _ := this.GetInt("UserId", 0)
+	specialColumnId, _ := this.GetInt("SpecialColumnId", 0)
 	var condition string
 	var pars []interface{}
 
 	var specialUser *models.CygxYanxuanSpecialAuthorItem
 	var err error
-	if userId > 0 {
-		condition += ` AND a.user_id = ? `
-		pars = append(pars, userId)
+	if specialColumnId > 0 {
+		condition += ` AND b.id = ? `
+		pars = append(pars, specialColumnId)
 	}
 
 	specialUser, err = models.GetYanxuanSpecialAuthor(sysUser.UserId, sysUser.UserId)
@@ -88,13 +88,21 @@ func (this *YanxuanSpecialController) List() {
 		if v.MyCollectNum > 0 {
 			v.IsCollect = 1
 		}
-		imgList := strings.Split(v.ImgUrl, ",")
-		for _, s := range imgList {
-			v.ImgUrlList = append(v.ImgUrlList, s)
+		if v.ImgUrl != "" {
+			imgList := strings.Split(v.ImgUrl, ",")
+			for _, s := range imgList {
+				v.ImgUrlList = append(v.ImgUrlList, s)
+			}
+		} else {
+			v.ImgUrlList = []string{}
 		}
-		tagList := strings.Split(v.Tags,",")
-		for _, s := range tagList {
-			v.TagList = append(v.TagList, s)
+		if v.Tags != "" {
+			tagList := strings.Split(v.Tags, ",")
+			for _, s := range tagList {
+				v.TagList = append(v.TagList, s)
+			}
+		} else {
+			v.TagList = []string{}
 		}
 	}
 	resp := new(models.SpecialListResp)
@@ -195,8 +203,8 @@ func (this *YanxuanSpecialController) AuthorSave() {
 		return
 	}
 
-	if req.UserId <= 0 {
-		br.Msg = "用户id有误"
+	if req.SpecialColumnId <= 0 {
+		br.Msg = "栏目id有误"
 		return
 	}
 	if req.SpecialName == "" {
@@ -209,7 +217,8 @@ func (this *YanxuanSpecialController) AuthorSave() {
 	}
 
 	item := models.CygxYanxuanSpecialAuthor{
-		UserId:       req.UserId,
+		Id:           req.SpecialColumnId,
+		UserId:       sysUser.UserId,
 		SpecialName:  req.SpecialName,
 		Introduction: req.Introduction,
 		Label:        req.Label,
@@ -347,11 +356,9 @@ func (this *YanxuanSpecialController) AuthorDetail() {
 		return
 	}
 
-	userId, _ := this.GetInt("UserId", 0)
-	if userId == 0 {
-		userId = sysUser.UserId
-	}
-	item, tmpErr := models.GetYanxuanSpecialAuthor(userId, sysUser.UserId)
+	specialColumnId, _ := this.GetInt("SpecialColumnId", 0)
+
+	item, tmpErr := models.GetYanxuanSpecialAuthorBySpecialColumnId(specialColumnId, sysUser.UserId)
 	if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
@@ -628,8 +635,8 @@ func (this *YanxuanSpecialController) Follow() {
 		return
 	}
 
-	if req.FollowUserId <= 0 {
-		br.Msg = "被关注的用户id"
+	if req.FollowSpecialColumnId <= 0 {
+		br.Msg = "被关注的专栏栏目id错误"
 		return
 	}
 	if req.Status <= 0 {
@@ -643,10 +650,17 @@ func (this *YanxuanSpecialController) Follow() {
 		br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
 		return
 	}
+	authorItem, err := models.GetYanxuanSpecialAuthorById(req.FollowSpecialColumnId)
+	if err != nil {
+		br.Msg = "查询栏目详情失败!"
+		br.ErrMsg = "查询栏目详情失败,Err:" + err.Error()
+		return
+	}
+
 	if req.Status == 1 {
 		item := models.CygxYanxuanSpecialFollow{
 			UserId:           sysUser.UserId,
-			FollowUserId:     req.FollowUserId,
+			FollowUserId:     authorItem.UserId,
 			Mobile:           sysUser.Mobile,
 			Email:            sysUser.Email,
 			CompanyId:        sysUser.CompanyId,
@@ -666,7 +680,7 @@ func (this *YanxuanSpecialController) Follow() {
 		}
 		br.Msg = "关注成功"
 	} else {
-		err = models.DelCygxYanxuanSpecialFollow(sysUser.UserId, req.FollowUserId)
+		err = models.DelCygxYanxuanSpecialFollow(sysUser.UserId, authorItem.UserId)
 		if err != nil {
 			br.Msg = "删除失败"
 			br.ErrMsg = "删除失败,Err:" + err.Error()
@@ -876,8 +890,8 @@ func (this *YanxuanSpecialController) AuthorHeadImg() {
 		return
 	}
 
-	if req.UserId <= 0 {
-		br.Msg = "用户id有误"
+	if req.SpecialColumnId <= 0 {
+		br.Msg = "专栏栏目id错误"
 		return
 	}
 	if req.HeadImg == "" {
@@ -886,7 +900,7 @@ func (this *YanxuanSpecialController) AuthorHeadImg() {
 	}
 
 	item := models.CygxYanxuanSpecialAuthor{
-		UserId:  req.UserId,
+		Id:      req.SpecialColumnId,
 		HeadImg: req.HeadImg,
 	}
 
@@ -920,7 +934,7 @@ func (this *YanxuanSpecialController) Delete() {
 		br.Ret = 408
 		return
 	}
-	var req models.EnableCygxYanxuanSpecialReq
+	var req models.DelCygxYanxuanSpecialReq
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
 		br.Msg = "参数解析异常!"

+ 32 - 31
models/cygx_yanxuan_special.go

@@ -22,34 +22,35 @@ type CygxYanxuanSpecial struct {
 }
 
 type CygxYanxuanSpecialItem struct {
-	Id            int      `orm:"column(id);pk"`
-	UserId        int      // 用户ID
-	CreateTime    string   // 创建时间
-	ModifyTime    string   // 修改时间
-	PublishTime   string   // 提审过审或驳回时间
-	Content       string   // 内容
-	Tags          string   // 标签
-	TagList       []string // 标签
-	Status        int      // 1:未发布,2:审核中 3:已发布 4:驳回
-	ImgUrl        string   // 图片链接
-	ImgUrlList    []string // 图片链接
-	DocUrl        string   // 文档链接
-	SpecialName   string   // 专栏名称
-	Introduction  string   // 介绍
-	Label         string   // 标签
-	NickName      string   // 昵称
-	RealName      string   // 姓名
-	Mobile        string   // 手机号
-	HeadImg       string   // 头像
-	BgImg         string   // 背景图
-	Reason        string   // 理由
-	Title         string   // 标题
-	Type          int      // 类型1:笔记,2:观点
-	CollectNum    int
-	MyCollectNum  int
-	IsCollect     int
-	ContentHasImg int //正文是否包含图片 1包含 0不包含
-	Docs          []Doc
+	Id              int      `orm:"column(id);pk"`
+	UserId          int      // 用户ID
+	SpecialColumnId int      // 专栏栏目ID
+	CreateTime      string   // 创建时间
+	ModifyTime      string   // 修改时间
+	PublishTime     string   // 提审过审或驳回时间
+	Content         string   // 内容
+	Tags            string   // 标签
+	TagList         []string // 标签
+	Status          int      // 1:未发布,2:审核中 3:已发布 4:驳回
+	ImgUrl          string   // 图片链接
+	ImgUrlList      []string // 图片链接
+	DocUrl          string   // 文档链接
+	SpecialName     string   // 专栏名称
+	Introduction    string   // 介绍
+	Label           string   // 标签
+	NickName        string   // 昵称
+	RealName        string   // 姓名
+	Mobile          string   // 手机号
+	HeadImg         string   // 头像
+	BgImg           string   // 背景图
+	Reason          string   // 理由
+	Title           string   // 标题
+	Type            int      // 类型1:笔记,2:观点
+	CollectNum      int
+	MyCollectNum    int
+	IsCollect       int
+	ContentHasImg   int //正文是否包含图片 1包含 0不包含
+	Docs            []Doc
 }
 
 type CygxYanxuanSpecialResp struct {
@@ -73,7 +74,7 @@ type DocReq struct {
 func GetYanxuanSpecialList(userId int, condition string, pars []interface{}) (items []*CygxYanxuanSpecialItem, err error) {
 	o := orm.NewOrm()
 	sql := ``
-	sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,b.nick_name,b.real_name,b.special_name,
+	sql = `SELECT a.*,b.id AS special_column_id,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,b.nick_name,b.real_name,b.special_name,
 ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac INNER JOIN wx_user as u ON  u.user_id = ac.user_id  WHERE ac.yanxuan_special_id = a.id  ) AS collect_num,
 ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id  AND user_id = ? ) AS my_collect_num 
 FROM cygx_yanxuan_special AS a
@@ -109,7 +110,7 @@ type SpecialListResp struct {
 func GetYanxuanSpecialById(specialId, userId int) (item *CygxYanxuanSpecialItem, err error) {
 	o := orm.NewOrm()
 	sql := ``
-	sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,
+	sql = `SELECT a.*,b.id AS special_column_id,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,
 b.nick_name,b.real_name,b.special_name,
 ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac INNER JOIN wx_user as u ON  u.user_id = ac.user_id  WHERE ac.yanxuan_special_id = a.id  ) AS collect_num,
 ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id  AND user_id = ? ) AS my_collect_num
@@ -123,7 +124,7 @@ JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
 type CygxYanxuanSpecialReq struct {
 	Id      int      `orm:"column(id);pk"`
 	Content string   // 内容
-	Tags    []string   // 标签
+	Tags    []string // 标签
 	DoType  int      // 1保存 2发布
 	ImgUrl  []string // 图片链接
 	Docs    []DocReq // 文档链接

+ 16 - 16
models/cygx_yanxuan_special_follow.go

@@ -6,25 +6,25 @@ import (
 )
 
 type CygxYanxuanSpecialFollow struct {
-	CygxYanxuanSpecialFollowId int        `orm:"column(cygx_yanxuan_special_follow_id);pk"`
-	UserId                     int        // 用户ID
-	FollowUserId               int        // 被关注用户ID
-	Mobile                     string     // 手机号
-	Email                      string     // 邮箱
-	CompanyId                  int        // 公司ID
-	CompanyName                string     // 公司名称
-	RealName                   string     // 用户实际名称
-	SellerName                 string     // 所属销售
-	CreateTime                 time.Time  // 创建时间
-	ModifyTime                 time.Time  // 修改时间
-	RegisterPlatform           int        // 来源 1小程序,2:网页
-	YanxuanSpecialId           int        // cygx_yanxuan_special 表主键ID
+	CygxYanxuanSpecialFollowId int       `orm:"column(cygx_yanxuan_special_follow_id);pk"`
+	UserId                     int       // 用户ID
+	FollowUserId               int       // 被关注用户ID
+	Mobile                     string    // 手机号
+	Email                      string    // 邮箱
+	CompanyId                  int       // 公司ID
+	CompanyName                string    // 公司名称
+	RealName                   string    // 用户实际名称
+	SellerName                 string    // 所属销售
+	CreateTime                 time.Time // 创建时间
+	ModifyTime                 time.Time // 修改时间
+	RegisterPlatform           int       // 来源 1小程序,2:网页
+	YanxuanSpecialId           int       // cygx_yanxuan_special 表主键ID
 }
 
 type FollowCygxYanxuanSpecialReq struct {
-	FollowUserId int // 被关注的用户id
-	Status       int // 1关注2取消关注
-	SpecialId    int // 研选专栏Id
+	FollowSpecialColumnId int // 被关注的专栏栏目id
+	Status                int // 1关注2取消关注
+	SpecialId             int // 研选专栏Id
 }
 
 func AddCygxYanxuanSpecialFollow(item *CygxYanxuanSpecialFollow) (err error) {

+ 39 - 13
models/cygx_yanxuan_special_user.go

@@ -32,7 +32,7 @@ type CygxYanxuanSpecialAuthorItem struct {
 	CompanyName       string    // 公司名
 	Mobile            string    // 手机号
 	CreateTime        string    // 创建时间
-	ModifyTime        time.Time    // 修改时间
+	ModifyTime        time.Time // 修改时间
 	HeadImg           string    // 头像
 	BgImg             string    // 背景图
 	BgImgPc           string    // 背景图
@@ -82,21 +82,39 @@ FROM
 	return
 }
 
+func GetYanxuanSpecialAuthorBySpecialColumnId(specialColumnId, sysUserId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `SELECT
+	a.*,c.company_name,
+	( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac  INNER JOIN cygx_yanxuan_special as cs ON  ac.yanxuan_special_id = cs.id  WHERE cs.user_id = a.user_id  ) AS collect_num,
+	( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf  WHERE cf.follow_user_id = a.user_id  ) AS follow_num,
+	( SELECT count( 1 ) FROM cygx_yanxuan_special AS ca  WHERE ca.user_id = a.user_id AND ca.status = 3 ) AS special_article_num,
+	( SELECT count( 1 ) FROM cygx_yanxuan_special_follow AS cf  INNER JOIN cygx_yanxuan_special_author AS ca ON cf.follow_user_id=ca.user_id 
+	WHERE cf.user_id = ? AND ca.id = ? ) AS is_follow 
+FROM
+	cygx_yanxuan_special_author as a
+	LEFT JOIN wx_user AS u ON u.user_id = a.user_id
+	LEFT JOIN company AS c ON c.company_id = u.company_id WHERE a.user_id=? `
+	err = o.Raw(sql, sysUserId, specialColumnId, sysUserId).QueryRow(&item)
+	return
+}
+
 type SaveCygxYanxuanSpecialAuthorReq struct {
-	UserId       int    // 用户ID
-	SpecialName  string // 专栏名称
-	Introduction string // 介绍
-	Label        string // 标签
-	NickName     string // 昵称
-	BgImg        string // 背景图
+	SpecialColumnId int    // 专栏栏目ID
+	SpecialName     string // 专栏名称
+	Introduction    string // 介绍
+	Label           string // 标签
+	NickName        string // 昵称
+	BgImg           string // 背景图
 }
 
 func UpdateYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (err error) {
 	o := orm.NewOrm()
 	sql := ``
 	sql = `UPDATE cygx_yanxuan_special_author SET special_name=?,introduction=?,label=?,nick_name=?
-	,modify_time=NOW() WHERE user_id = ? `
-	_, err = o.Raw(sql, item.SpecialName, item.Introduction, item.Label, item.NickName, item.UserId).Exec()
+	,modify_time=NOW() WHERE id = ? `
+	_, err = o.Raw(sql, item.SpecialName, item.Introduction, item.Label, item.NickName, item.Id).Exec()
 	return
 }
 
@@ -126,14 +144,22 @@ type SpecialAuthorListResp struct {
 }
 
 type SaveCygxYanxuanSpecialAuthoHeadImgrReq struct {
-	UserId  int    // 用户ID
-	HeadImg string // 头像
+	SpecialColumnId 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()
+	sql = `UPDATE cygx_yanxuan_special_author SET head_img=?,modify_time=NOW() WHERE id = ? `
+	_, err = o.Raw(sql, item.HeadImg, item.Id).Exec()
+	return
+}
+
+func GetYanxuanSpecialAuthorById(specialColumnId int) (item *CygxYanxuanSpecialAuthorItem, err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `SELECT * FROM cygx_yanxuan_special_author WHERE id = ? `
+	err = o.Raw(sql, specialColumnId).QueryRow(&item)
 	return
 }