123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type CygxYanxuanSpecialAuthor struct {
- Id int `orm:"column(id);pk"`
- UserId int // 用户ID
- SpecialName string // 专栏名称
- Introduction string // 介绍
- Label string // 标签
- NickName string // 昵称
- RealName string // 姓名
- Mobile string // 手机号
- CreateTime time.Time // 创建时间
- ModifyTime time.Time // 修改时间
- HeadImg string // 头像
- BgImg string // 背景图上部分
- BgImgDown string // 背景图下部分
- Status int // 1启用2禁用
- }
- type CygxYanxuanSpecialAuthorItem struct {
- Id int `orm:"column(id);pk"`
- UserId int // 用户ID
- SpecialName string // 专栏名称
- Introduction string // 介绍
- Label string // 标签
- NickName string // 昵称
- RealName string // 姓名
- CompanyName string // 公司名
- Mobile string // 手机号
- CreateTime string // 创建时间
- ModifyTime time.Time // 修改时间
- HeadImg string // 头像
- BgImg string // 背景图
- BgImgDown string // 背景图下半部分
- Status int // 1启用2禁用
- CollectNum int // 被收藏数
- FollowNum int // 被关注数
- SpecialArticleNum int // 文章数
- LatestPublishTime time.Time // 最近更新时间
- LatestPublishDate string // 最近更新时间
- IsFollow int // 是否已关注 1已关注 0 未关注
- }
- func AddCygxYanxuanSpecialAuthor(item *CygxYanxuanSpecialAuthor) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- type EnableCygxYanxuanSpecialAuthorReq struct {
- UserId int // 用户ID
- Status int // 1启用2禁用
- }
- // 启用禁用作者
- func EnableYanxuanSpecialAuthor(userId, status int) (err error) {
- o := orm.NewOrm()
- sql := ``
- sql = `UPDATE cygx_yanxuan_special_author SET status=?,modify_time=NOW() WHERE user_id = ? `
- _, err = o.Raw(sql, status, userId).Exec()
- return
- }
- func GetYanxuanSpecialAuthor(reqUserId, sysUserId int,cond string) (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 WHERE cf.follow_user_id =? AND cf.user_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=? `
- if cond != "" {
- sql += cond
- }
- err = o.Raw(sql, reqUserId, sysUserId, reqUserId).QueryRow(&item)
- return
- }
- type SaveCygxYanxuanSpecialAuthorReq struct {
- UserId 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()
- return
- }
- func GetYanxuanSpecialAuthorList() (items []*CygxYanxuanSpecialAuthorItem, err error) {
- o := orm.NewOrm()
- sql := ``
- sql = `SELECT
- a.*,
- c.company_name,
- IFNULL(( SELECT publish_time FROM cygx_yanxuan_special WHERE user_id = a.user_id AND STATUS = 3 ORDER BY publish_time DESC LIMIT 1 ), a.modify_time) AS latest_publish_time
- FROM
- cygx_yanxuan_special_author AS a
- INNER JOIN wx_user AS u ON u.user_id = a.user_id
- INNER JOIN company AS c ON c.company_id = u.company_id
- WHERE
- a.nick_name <> ''
- ORDER BY
- latest_publish_time DESC `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- 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
- }
|