123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type CygxYanxuanSpecial struct {
- Id int `orm:"column(id);pk"`
- UserId int // 用户ID
- CreateTime time.Time // 创建时间
- ModifyTime time.Time // 修改时间
- PublishTime time.Time // 提审过审或驳回时间
- Content string // 内容
- Tags string // 标签
- Status int // 1:未发布,2:审核中 3:已发布 4:驳回
- ImgUrl string // 图片链接
- DocUrl string // 文档链接
- Reason string // 理由
- Title string // 标题
- Type int // 类型1:笔记,2:观点
- }
- type CygxYanxuanSpecialItem struct {
- Id int `orm:"column(id);pk"`
- UserId int // 用户ID
- CreateTime string // 创建时间
- ModifyTime string // 修改时间
- PublishTime string // 提审过审或驳回时间
- Content string // 内容
- Tags string // 标签
- Status int // 1:未发布,2:审核中 3:已发布 4:驳回
- ImgUrl 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 {
- CygxYanxuanSpecialItem
- Docs []Doc
- }
- type Doc struct {
- DocName string
- DocSuffix string
- DocUrl string
- DocIcon string
- }
- 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,
- ( 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
- JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
- WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += `ORDER BY a.publish_time DESC `
- _, err = o.Raw(sql, userId, pars).QueryRows(&items)
- return
- }
- type EnableCygxYanxuanSpecialReq struct {
- Id int // 文章id
- Status int // 1通过2驳回
- Reason string //理由
- }
- func EnableYanxuanSpecial(id, status int, reason string) (err error) {
- o := orm.NewOrm()
- sql := ``
- sql = `UPDATE cygx_yanxuan_special SET status=?,reason=?,publish_time=NOW() WHERE id = ? `
- _, err = o.Raw(sql, status, reason, id).Exec()
- return
- }
- type SpecialListResp struct {
- List []*CygxYanxuanSpecialItem
- IsAuthor bool
- }
- 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,
- 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
- JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
- WHERE a.id=? `
- err = o.Raw(sql, userId, specialId).QueryRow(&item)
- return
- }
- type CygxYanxuanSpecialReq struct {
- Id int `orm:"column(id);pk"`
- Content string // 内容
- Tags string // 标签
- DoType int // 1保存 2发布
- ImgUrl string // 图片链接
- DocUrl string // 文档链接
- Title string // 标题
- Type int // 类型1:笔记,2:观点
- }
- func AddCygxYanxuanSpecial(item *CygxYanxuanSpecial) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- func UpdateYanxuanSpecial(item *CygxYanxuanSpecial) (err error) {
- o := orm.NewOrm()
- sql := ``
- sql = `UPDATE cygx_yanxuan_special SET title=?,content=?,tags=?,img_url=?,doc_url=?,type=?,status=?,
- modify_time=NOW(),publish_time=NOW() WHERE id = ? `
- _, err = o.Raw(sql, item.Title, item.Content, item.Tags, item.ImgUrl, item.DocUrl, item.Type, item.Status, item.Id).Exec()
- return
- }
- func GetYanxuanSpecialIndustry(keyword string) (IndustryNames []string, err error) {
- o := orm.NewOrm()
- sql := ``
- if keyword == "" {
- sql = `SELECT industry_name FROM cygx_yanxuan_special_industry `
- } else {
- sql = `SELECT industry_name FROM cygx_yanxuan_special_industry WHERE industry_name LIKE '%` + keyword + `%' `
- }
- _, err = o.Raw(sql).QueryRows(&IndustryNames)
- return
- }
- type CancelPublishCygxYanxuanSpecialReq struct {
- Id int // 文章id
- }
- func CancelPublishYanxuanSpecial(id int) (err error) {
- o := orm.NewOrm()
- sql := ``
- sql = `UPDATE cygx_yanxuan_special SET status=1,publish_time=NOW() WHERE id = ? `
- _, err = o.Raw(sql, id).Exec()
- return
- }
- type DelCygxYanxuanSpecialReq struct {
- Id int // 文章id
- }
- func DelYanxuanSpecial(id int) (err error) {
- o := orm.NewOrm()
- sql := ``
- sql = `DELETE FROM cygx_yanxuan_special WHERE id = ? `
- _, err = o.Raw(sql, id).Exec()
- return
- }
|