// ============================================================================ // This is auto-generated by gf cli tool only once. Fill this file as you wish. // ============================================================================ package cms_news import ( "gfast/library/utils" "github.com/gogf/gf/errors/gerror" "github.com/gogf/gf/frame/g" "github.com/gogf/gf/os/gtime" "github.com/gogf/gf/util/gconv" ) // Fill with you ideas below. //添加文章参数 type ReqAddParams struct { NewsStatus uint `p:"status" v:"in:0,1#状态只能为0或1"` // 状态;1:已发布;0:未发布; IsTop uint `p:"IsTop" v:"in:0,1#置顶只能为0或1"` // 是否置顶;1:置顶;0:不置顶 Recommended uint `p:"recommended" v:"in:0,1#推荐只能为0或1"` // 是否推荐;1:推荐;0:不推荐 PublishedTime string `p:"published_time"` // 发布时间 NewsTitle string `p:"title" v:"required#标题不能为空"` // post标题 NewsKeywords string `p:"keywords"` // seo keywords NewsExcerpt string `p:"excerpt"` // post摘要 NewsSource string `p:"source" ` // 转载文章的来源 NewsContent string `p:"content" v:"required#文章内容不能为空"` // 文章内容 Thumbnail string `p:"thumbnail" ` // 缩略图 IsJump uint `p:"IsJump" v:"in:0,1#跳转类型只能为0或1"` // 是否跳转地址 JumpUrl string `p:"JumpUrl" ` // 跳转地址 } //添加文章操作 func AddNews(req *ReqAddParams, menuIds []int, userId int) (insId []int64, err error) { if len(menuIds) == 0 { err = gerror.New("栏目不能为空") return } tx, err := g.DB().Begin() if err != nil { g.Log().Error(err) err = gerror.New("保存失败") return } for _, menuId := range menuIds { entity := &Entity{ CateId: gconv.Uint(menuId), UserId: gconv.Uint64(userId), NewsStatus: req.NewsStatus, IsTop: req.IsTop, Recommended: req.Recommended, CreateTime: gconv.Uint(gtime.Timestamp()), PublishedTime: gconv.Uint(utils.StrToTimestamp(req.PublishedTime)), NewsTitle: req.NewsTitle, NewsKeywords: req.NewsKeywords, NewsExcerpt: req.NewsExcerpt, NewsSource: req.NewsExcerpt, NewsContent: req.NewsContent, Thumbnail: req.Thumbnail, IsJump: req.IsJump, JumpUrl: req.JumpUrl, } res, err := entity.Save() if err != nil { g.Log().Error(err) err = gerror.New("添加文章失败") tx.Rollback() return } id, err := res.LastInsertId() if err != nil { g.Log().Error(err) err = gerror.New("添加文章失败") tx.Rollback() return } insId = append(insId, id) } tx.Commit() return }