package advisory import ( "fmt" "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" "time" ) type AdvisoryArticle struct { ArticleId int `orm:"column(advisory_article_id);pk"` Title string `description:"标题"` Body string `description:"内容"` Abstract string `description:"简介"` PublishStatus int `description:"发布状态1已发布、0未发布"` ChartPermissionId int `description:"所属分类ID"` ChartPermissionName string `description:"所属分类名称"` ActualPublishTime time.Time `description:"实际发布时间"` TimingPublishTime time.Time `description:"定时发布时间"` LinkName string `description:"链接名称"` LinkAddress string `description:"链接地址"` CreateTime time.Time `description:"创建时间"` LastUpdateTime time.Time `description:"修改时间"` AdminId int `description:"发布者的用户ID"` IsTiming int `description:"是否定时发布,1,定时发布,0不定时"` Code string `description:"分享字符串"` } type AdvisoryArticleLog struct { ArticleId int `orm:"column(advisory_article_id);pk"` Title string `description:"标题"` Body string `description:"内容"` Abstract string `description:"简介"` PublishStatus int `description:"发布状态1已发布、0未发布"` ChartPermissionId int `description:"所属分类ID"` ChartPermissionName string `description:"所属分类名称"` ActualPublishTime time.Time `description:"实际发布时间"` TimingPublishTime time.Time `description:"定时发布时间"` LinkName string `description:"链接名称"` LinkAddress string `description:"链接地址"` CreateTime time.Time `description:"创建时间"` LastUpdateTime time.Time `description:"修改时间"` AdminId int `description:"发布者的用户ID"` } //文章详情 type AdvisoryArticleDetail struct { ArticleId int `orm:"column(advisory_article_id);pk"` Title string `description:"标题"` Body string `description:"内容"` Abstract string `description:"简介"` PublishStatus int `description:"发布状态1已发布、0未发布"` ChartPermissionId int `description:"所属分类ID"` ChartPermissionName string `description:"所属分类名称"` ActualPublishTime string `description:"实际发布时间"` TimingPublishTime string `description:"定时发布时间"` LinkName string `description:"链接名称"` LinkAddress string `description:"链接地址"` CreateTime string `description:"创建时间"` LastUpdateTime string `description:"修改时间"` AdminId int `description:"发布者的用户ID"` Code string `description:"分享字符串"` ArtCode string `orm:"column(code);"` } //预览文章详情带文章所属分类 type PreviewArticleDetail struct { WhatWeek string `description:"周几"` ArticleId int `orm:"column(advisory_article_id);pk"` Title string `description:"标题"` Body string `description:"内容"` ChartPermissionId int `description:"所属分类ID"` ChartPermissionName string `description:"所属分类名称"` LinkName string `description:"链接名称"` LinkAddress string `description:"链接地址"` TimingPublishTime string `description:"定时发布时间"` PublishStatus int `description:"发布状态1已发布、0未发布"` //ClassifyChartPermissionName string `description:"所属一级分类名称"` ActualPublishTime string `description:"实际发布时间"` LastUpdateTime string `description:"上次编辑的时间"` Pv int `description:"PV"` Uv int `description:"UV"` } type PreviewArticleDetailList struct { List []*PreviewArticleDetail } type ArticleAddReq struct { ArticleId int `orm:"column(advisory_article_id);pk"` Title string `description:"标题"` Body string `description:"内容"` Abstract string `description:"文章个简介"` ChartPermissionId int `description:"所属分类ID"` ChartPermissionName string `description:"所属分类名称"` TimingPublishTime string `description:"定时发布时间"` LinkName string `description:"链接名称"` LinkAddress string `description:"链接地址"` } //保存文章 type PreservationArticle struct { ArticleId int `orm:"column(advisory_article_id);pk"` Title string `description:"标题"` Body string `description:"内容"` Abstract string `description:"文章个简介"` ChartPermissionId int `description:"所属分类ID"` ChartPermissionName string `description:"所属分类名称"` TimingPublishTime string `description:"定时发布时间"` LinkName string `description:"链接名称"` LinkAddress string `description:"链接地址"` } type ArticleDeleteReq struct { ArticleId int64 `description:"ArticleId"` } //添加文章 func AddArticle(item *AdvisoryArticle) (newId int64, err error) { fmt.Println(item) o := orm.NewOrm() newId, err = o.Insert(item) fmt.Println(newId) return } //添加文章日志 func AddArticleLog(item *AdvisoryArticleLog) (newId int64, err error) { o := orm.NewOrm() newId, err = o.Insert(item) return } //编辑文章 func EditArticle(item *AdvisoryArticle) (err error) { o := orm.NewOrm() sql := " UPDATE advisory_article SET title = ?, body = ?, chart_permission_id = ?,chart_permission_name=?,timing_publish_time=?,publish_status=?, link_name=?, link_address=?, actual_publish_time=? ,is_timing=? ,last_update_time = NOW() WHERE advisory_article_id = ? " o.Raw(sql, item.Title, item.Body, item.ChartPermissionId, item.ChartPermissionName, item.TimingPublishTime, item.PublishStatus, item.LinkName, item.LinkAddress, item.ActualPublishTime, item.IsTiming, item.ArticleId).Exec() return } //获取文章详情 func GetUserArticleInfo(Uid int, ArticleId int64) (items *AdvisoryArticleDetail, err error) { o := orm.NewOrm() sql := `SELECT * FROM advisory_article WHERE advisory_article_id = ? LIMIT 1` err = o.Raw(sql, ArticleId).QueryRow(&items) return } //获取文章详情 func GetUserArticleInfoByCode(Code string) (items *AdvisoryArticleDetail, err error) { o := orm.NewOrm() sql := `SELECT * FROM advisory_article WHERE publish_status = 1 AND code = ?` err = o.Raw(sql, Code).QueryRow(&items) return } //获取管理员今天是否在这个类目下发文章 func GetUserTodayRticleInfo(Uid int, ChartPermissionId int) (items *AdvisoryArticleDetail, err error) { o := orm.NewOrm() sql := `SELECT * FROM advisory_article WHERE admin_id = ? AND chart_permission_id = ? AND publish_status = 1 AND last_update_time>=date(now()) and last_update_time