model

package
v0.0.0-...-8b29e06 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2019 License: MIT Imports: 7 Imported by: 0

README

模型目录

一个go文件对应着一张表
来封装直接操作数据库的操作,比如表定义,表的关联,表的CRUD

Documentation

Index

Constants

View Source
const PAGE_SIZE int = 20

Variables

This section is empty.

Functions

func CheckFavourite

func CheckFavourite(uid int, tid int) (fav int, err error)

检查我的收藏

func CheckPostlike

func CheckPostlike(uid int, pid int) (like int, err error)

检查我的收藏

func CloseDB

func CloseDB()

func CountAttachsNum

func CountAttachsNum() (accachsNum int, err error)

统计当前网站共有附件的数量

func CountPostNum

func CountPostNum() (postNum int, err error)

统计当前共有帖子的数量:isfirst=0

func CountThreadsNum

func CountThreadsNum() (threadsNum int, err error)

统计一共共有多少thread

func CountUserNum

func CountUserNum() (usersNum int, err error)

* * @des 更新用户积分数 * @param whereMaps 条件 * @param updateItems 修改项 * @return error

func DelAttach

func DelAttach(id int) error

删除某个附件【应该删除具体的文件】

func DelMyFavourite

func DelMyFavourite(uid int, threadId int) error

func DelPostlike

func DelPostlike(uid int, postId int) error

func DelThread

func DelThread(ids string) (err error)

删除

func ExistForumByName

func ExistForumByName(username string) bool

检测name是否出现过

func ExistUserByEmail

func ExistUserByEmail(email string) bool

* * @des 判断邮箱是否使用 * @param email string 邮箱 * @return bool 是否

func ExistUserByName

func ExistUserByName(username string) bool

* * @des 判断用户名是否使用 * @param username string 用户名 * @return bool 是否

func ExistUserByPhone

func ExistUserByPhone(phone string) bool

* * @des 判断手机号是否使用 * @param phone string 手机号 * @return bool 是否

func GetDb

func GetDb() *gorm.DB

func GetForumTotal

func GetForumTotal(maps interface{}) (count int)

获取forum的数量

func GetThreadTotal

func GetThreadTotal(maps interface{}) (count int)

func GetThreadTotleCount

func GetThreadTotleCount() (totle int, err error)

获取帖子的总数

func GetUserTotal

func GetUserTotal(maps interface{}) (count int)

* * @des 获取指定条件的用户数 * @param maps where条件 * @return count int 总数

func Increment

func Increment(table string, id int, colum string) error

自增

func UpdateForumThreadsCnt

func UpdateForumThreadsCnt(id int, newCnt int) error

增加模块发帖量

func UpdateForumTodaypostsCnt

func UpdateForumTodaypostsCnt(id int, newCnt int) error

增加模块今日帖子回复量

func UpdateForumTodaythreadsCnt

func UpdateForumTodaythreadsCnt(id int, newCnt int) error

增加模块今日发帖量

func UpdatePostFilesNum

func UpdatePostFilesNum(id int, num int) error

修改附件的数量

func UpdatePostLikesNum

func UpdatePostLikesNum(id int, num int) error

修改点赞的数量

func UpdateThreadFavouriteCnt

func UpdateThreadFavouriteCnt(id int, num int) error

修改附件的数量

func UpdateThreadFilesNum

func UpdateThreadFilesNum(id int, num int) error

修改附件的数量

func UpdateThreadForum

func UpdateThreadForum(ids string, nfid int) error

修改帖子到新模块

func UpdateThreadTop

func UpdateThreadTop(id int, top int) error

修改置顶级别

func UpdateThreadTopTo

func UpdateThreadTopTo(threadID int, top int) (err error)

修改置顶选项

func UpdateThreadViewsCnt

func UpdateThreadViewsCnt(id int) error

增加阅读量

func UpdateUser

func UpdateUser(whereMaps interface{}, updateItems map[string]interface{}) (err error)

* * @des 新增用户 * @param whereMaps 条件 * @param updateItems 修改项 * @return error

func UpdateUserCreditsNum

func UpdateUserCreditsNum(id int, newCreditsNum int) (err error)

* * @des 更新用户积分数 * @param whereMaps 条件 * @param updateItems 修改项 * @return error

func UpdateUserPostsCnt

func UpdateUserPostsCnt(id int, newPostsCnt int) (err error)

* * @des 更新用户回帖数 * @param whereMaps 条件 * @param updateItems 修改项 * @return error

func UpdateUserThreadsCnt

func UpdateUserThreadsCnt(id int, newThreadsCnt int) (err error)

* * @des 更新用户发帖数 * @param whereMaps 条件 * @param updateItems 修改项 * @return error

Types

type Attach

type Attach struct {
	Model

	ThreadID     int    `gorm:"default:0" json:"thread_id"`     //主题id
	PostID       int    `gorm:"default:0" json:"post_id"`       //帖子id
	UserID       int    `gorm:"default:0" json:"user_id"`       //用户id
	Filesize     int    `gorm:"default:0" json:"filesize"`      //文件尺寸,单位字节
	Width        int    `gorm:"default:0" json:"width"`         //width > 0 则为图片
	Height       int    `gorm:"default:0" json:"height"`        //
	Filename     string `gorm:"default:''" json:"filename"`     //文件名称,会过滤,并且截断,保存后的文件名,不包含URL前缀 upload_url
	Orgfilename  string `gorm:"default:''" json:"orgfilename"`  //上传的原文件名
	Filetype     string `gorm:"default:''" json:"filetype"`     //image/txt/zip,小图标显示
	Comment      string `gorm:"default:''" json:"comment"`      //文件注释 方便于搜索
	DownloadsNum int    `gorm:"default:0" json:"downloads_num"` //下载次数
	CreditsNum   int    `gorm:"default:0" json:"credits_num"`   //需要的积分
	GoldsNum     int    `gorm:"default:0" json:"golds_num"`     //需要的金币
	RmbsNum      int    `gorm:"default:0" json:"rmbs_num"`      //需要的人民币
	Isimage      int    `gorm:"default:0" json:"isimage"`       //是否为图片
}

附件表

func AddAttach

func AddAttach(attach *Attach) (*Attach, error)

添加一个附件

func GetAttachsByPostId

func GetAttachsByPostId(postId int) (attachs []Attach, err error)

获取指定post的附件列表

type Cache

type Cache struct {
	Model

	K      string    `json:"k"`      //
	V      string    `json:"v"`      //
	Expiry time.Time `json:"expiry"` //
}

缓存表

type Forum

type Forum struct {
	Model

	Name            string `gorm:"default:''" json:"name"`            //
	Rank            int    `gorm:"default:0" json:"rank"`             //显示,倒序,数字越大越靠前
	ThreadsCnt      int    `gorm:"default:0" json:"threads_cnt"`      //主题数
	TodaypostsCnt   int    `gorm:"default:0" json:"todayposts_cnt"`   //今日发帖,计划任务每日凌晨0点清空为0
	TodaythreadsCnt int    `gorm:"default:0" json:"todaythreads_cnt"` //今日发主题,计划任务每日凌晨0点清空为0
	Brief           string `json:"brief"`                             //版块简介 允许HTML
	Announcement    string `json:"announcement"`                      //版块公告 允许HTML
	Accesson        int    `gorm:"default:0" json:"accesson"`         //是否开启权限控制
	Orderby         int    `gorm:"default:0" json:"orderby"`          //默认列表排序,0: 顶贴时间 last_date, 1: 发帖时间 tid
	Icon            string `gorm:"default:''" json:"icon"`            //板块是否有 icon,存放最后更新时间
	Moduids         string `gorm:"default:''" json:"moduids"`         //每个版块有多个版主,最多10个: 10*12 = 120,删除用户的时候,如果是版主,则调整后再删除。逗号分隔
	SeoTitle        string `gorm:"default:''" json:"seo_title"`       //SEO 标题,如果设置会代替版块名称
	SeoKeywords     string `gorm:"default:''" json:"seo_keywords"`    //
	DigestsNum      int    `gorm:"default:0" json:"digests_num"`      //
}

模块表

func AddForum

func AddForum(forumIcon string, forumName string, forumRank int) (forum *Forum, err error)

添加一条forum

func GetForum

func GetForum(maps interface{}) (forum Forum, err error)

给定条件 获取指定的forum

func GetForumByID

func GetForumByID(id int) (forum Forum, err error)

根据指定的id获取forum

func GetForumsList

func GetForumsList(orderby string) (forums []Forum, err error)

获取forum的列表【限定排序】

type ForumAccess

type ForumAccess struct {
	Model

	GroupId     int `gorm:"default:0" json:"group_id"`    //
	Allowread   int `gorm:"default:0" json:"allowread"`   //
	Allowthread int `gorm:"default:0" json:"allowthread"` //
	Allowpost   int `gorm:"default:0" json:"allowpost"`   //允许回复
	Allowattach int `gorm:"default:0" json:"allowattach"` //允许上传附件
	Allowdown   int `gorm:"default:0" json:"allowdown"`   //允许下载附件
}

模块权限表

type Group

type Group struct {
	Model

	Name            string `gorm:"default:''" json:"name"`           //用户组名称
	Creditsfrom     int    `gorm:"default:0" json:"creditsfrom"`     //积分从
	Creditsto       int    `gorm:"default:0" json:"creditsto"`       //积分到
	Allowread       int    `gorm:"default:0" json:"allowread"`       //允许访问
	Allowthread     int    `gorm:"default:0" json:"allowthread"`     //允许发主题
	Allowpost       int    `gorm:"default:0" json:"allowpost"`       //允许回帖
	Allowattach     int    `gorm:"default:0" json:"allowattach"`     //允许上传文件
	Allowdown       int    `gorm:"default:0" json:"allowdown"`       //允许下载文件
	Allowtop        int    `gorm:"default:0" json:"allowtop"`        //允许置顶
	Allowupdate     int    `gorm:"default:0" json:"allowupdate"`     //允许编辑
	Allowdelete     int    `gorm:"default:0" json:"allowdelete"`     //
	Allowmove       int    `gorm:"default:0" json:"allowmove"`       //
	Allowbanuser    int    `gorm:"default:0" json:"allowbanuser"`    //允许禁止用户
	Allowdeleteuser int    `gorm:"default:0" json:"allowdeleteuser"` //
	Allowviewip     int    `gorm:"default:0" json:"allowviewip"`     //允许查看用户敏感信息
}

用户角色分组表

func GetUserGroupList

func GetUserGroupList() (glist []Group, err error)

type Model

type Model struct {
	gorm.Model
}

type Modlog

type Modlog struct {
	Model

	UserId     int    `gorm:"default:0" json:"user_id"`     //
	ThreadId   int    `gorm:"default:0" json:"thread_id"`   //
	PostId     int    `gorm:"default:0" json:"post_id"`     //
	Subject    string `gorm:"default:''" json:"subject"`    //
	Comment    string `gorm:"default:''" json:"comment"`    //
	Rmbs       int    `gorm:"default:0" json:"rmbs"`        //
	CreateDate int    `gorm:"default:0" json:"create_date"` //
	Action     string `gorm:"default:''" json:"action"`     //
}

缓存表

type MyFavourite

type MyFavourite struct {
	Model

	UserID   int `gorm:"default:0" json:"user_id"`   //
	ThreadID int `gorm:"default:0" json:"thread_id"` //
	User     User
	Thread   Thread
}

我的帖子表

func AddMyFavourite

func AddMyFavourite(userID int, threadID int) (myFavourite *MyFavourite, err error)

func GetMyFavouriteList

func GetMyFavouriteList(uid int, page int, limit int, Orderby string) (threads []MyFavourite, err error)

type Mypost

type Mypost struct {
	Model

	UserID   int `gorm:"primary_key;default:0" json:"user_id"` //
	ThreadID int `gorm:"default:0" json:"thread_id"`           //
	PostID   int `gorm:"primary_key;default:0" json:"post_id"` //
	User     User
	Thread   Thread
	Post     Post
}

我的帖子表

func AddMyPost

func AddMyPost(userID int, threadID int, postID int) (myPost *Mypost, err error)

func GetMyPostList

func GetMyPostList(uid int, page int, limit int, Orderby string) (posts []Mypost, err error)

type Mythread

type Mythread struct {
	Model

	UserID   int `gorm:"default:0" json:"user_id"`   //
	ThreadID int `gorm:"default:0" json:"thread_id"` //
	User     User
	Thread   Thread
}

我的帖子表

func AddMyThread

func AddMyThread(userID int, threadID int) (myThread *Mythread, err error)

func GetMyThreadList

func GetMyThreadList(uid int, page int, limit int, Orderby string) (threads []Mythread, err error)

type Post

type Post struct {
	Model

	ThreadID    int    `gorm:"default:0" json:"thread_id"`     //主题id
	UserID      int    `gorm:"default:0" json:"user_id"`       //
	Isfirst     int    `gorm:"default:0" json:"isfirst"`       //是否为首帖,与 thread.firstpid 呼应
	Userip      string `gorm:"default:''" json:"userip"`       //发帖时用户ip ip2long()
	ImagesNum   int    `gorm:"default:0" json:"images"`        //附件中包含的图片数
	FilesNum    int    `gorm:"default:0" json:"files"`         //附件中包含的文件数
	Doctype     int    `gorm:"default:0" json:"doctype"`       //类型,0: html, 1: txt; 2: markdown; 3: ubb
	QuotePostId int    `gorm:"default:0" json:"quote_post_id"` //引用哪个 pid,可能不存在
	Message     string `gorm:"default:''" json:"message"`      //内容,用户提示的原始数据
	MessageFmt  string `gorm:"default:''" json:"message_fmt"`  //内容,存放的过滤后的html内容,可以定期清理,减肥
	Audited     int    `gorm:"default:1" json:"audited"`       // 通过审核 默认是通过的  有点模块的贴子需要审核才能显示
	LikesCnt    int    `gorm:"default:0" json:"likes_cnt"`     //点赞数
	User        User
	Thread      Thread
	Attach      []Attach
}

我的帖子表

func AddPost

func AddPost(post *Post) (*Post, error)

添加帖子

func GetPostById

func GetPostById(id int) (post Post, err error)

根据id获取post

func GetThreadFirstPostByTid

func GetThreadFirstPostByTid(tid int) (post Post, err error)

获取主题的具体内容:isfirst=1的一条

func GetThreadPostListByTid

func GetThreadPostListByTid(tid int, limit int, page int) (post []Post, err error)

获取主题的帖子列表:不要isfirst=1的一条

func UpdatePost

func UpdatePost(id int, post Post) (upPost Post, err error)

根据id更新post

type PostUpdateLog

type PostUpdateLog struct {
	Model

	PostID     int    `gorm:"default:0" json:"thread_id"`    //主题id
	UserID     int    `gorm:"default:0" json:"user_id"`      //
	Reason     string `gorm:"default:''" json:"reason"`      //内容,用户提示的原始数据
	Message    string `gorm:"default:''" json:"message"`     //内容,用户提示的原始数据
	OldMessage string `gorm:"default:''" json:"message_fmt"` //内容,存放的过滤后的html内容,可以定期清理,减肥
	Audited    int    `gorm:"default:1" json:"audited"`      // 通过审核 默认是通过的  有点模块的贴子需要审核才能显示
	User       User
	Post       Post
}

我的帖子表

func AddPostUpdateLog

func AddPostUpdateLog(postUpdateLog *PostUpdateLog) (*PostUpdateLog, error)

添加帖子

type Postlike

type Postlike struct {
	Model

	UserID int `gorm:"default:0" json:"user_id"` //
	PostID int `gorm:"default:0" json:"post_id"` //
	User   User
	Post   Post
}

我的帖子表

func AddPostlike

func AddPostlike(userID int, postID int) (postlike *Postlike, err error)

func GetMyPostlikeList

func GetMyPostlikeList(uid int, page int, limit int, Orderby string) (postlikes []Postlike, err error)

type Queue

type Queue struct {
	ID     int `gorm:"primary_key" json:"id"`    //
	Value  int `gorm:"primary_key" json:"value"` //
	Expiry int `json:"expiry"`                   //过期时间
}

任务队列表

type Results

type Results struct {
	Totle int
}

func SumAllForumThreads

func SumAllForumThreads() (threadsCount Results, err error)

统计一共有多少个threads = forum中的threanum之和

type Session

type Session struct {
	Model

	UserId    int    `gorm:"default:0" json:"user_id"`    //用户id 未登录为 0,可以重复
	ForumId   int    `gorm:"default:0" json:"forum_id"`   //所在的版块
	URL       string `gorm:"default:''" json:"url"`       //当前访问 url
	IP        int    `gorm:"default:0" json:"ip"`         //
	Useragent string `gorm:"default:''" json:"useragent"` //
	Data      string `gorm:"default:''" json:"data"`      //
	Bigdata   int    `gorm:"default:0" json:"bigdata"`    //是否有大数据
	LastDate  int    `gorm:"default:0" json:"last_date"`  //上次活动时间
}

任务队列表

type SessionData

type SessionData struct {
	SessionId string    `gorm:"primary_key" json:" - "` //
	LastDate  time.Time `json:"last_date"`              //
	Data      string    `json:"data"`                   //
}

任务队列表

type Thread

type Thread struct {
	Model

	ForumID      int       `gorm:"default:0" json:"forum_id"`      //版块 id
	Top          int       `gorm:"default:0" json:"top"`           //置顶级别: 0: 普通主题, 1-3 置顶的顺序
	UserID       int       `gorm:"default:0" json:"user_id"`       //
	Userip       string    `gorm:"default:''" json:"userip"`       //发帖时用户ip ip2long(),主要用来清理
	Subject      string    `gorm:"default:''" json:"subject"`      // 主题
	LastDate     time.Time `json:"last_date"`                      //最后回复时间
	ViewsCnt     int       `gorm:"default:0" json:"views_cnt"`     //查看次数, 剥离出去,单独的服务,避免 cache 失效
	PostsCnt     int       `gorm:"default:0" json:"posts_cnt"`     //回帖数
	FavouriteCnt int       `gorm:"default:0" json:"favourite_cnt"` //被收藏数
	ImagesNum    int       `gorm:"default:0" json:"images_num"`    //附件中包含的图片数
	FilesNum     int       `gorm:"default:0" json:"files_num"`     //附件中包含的文件数
	ModsCnt      int       `gorm:"default:0" json:"mods_cnt"`      //预留:版主操作次数,如果 > 0, 则查询 modlog,显示斑竹的评分
	Isclosed     int       `gorm:"default:0" json:"isclosed"`      //预留:是否关闭,关闭以后不能再回帖、编辑
	FirstPostID  int       `gorm:"default:0" json:"first_post_id"` //首贴 pid
	LastUserID   int       `gorm:"default:0" json:"last_user_id"`  //最近参与的 uid
	LastPostID   int       `gorm:"default:0" json:"last_post_id"`  //最后回复的 pid
	Digest       int       `gorm:"default:0" json:"digest"`        //
	Audited      int       `gorm:"default:1" json:"audited"`       // 通过审核 默认是通过的  有点模块的贴子需要审核才能显示
	User         User
	Forum        Forum
	LastUser     User
	Attach       []Attach
}

任务队列表

func AddThread

func AddThread(thread *Thread) (*Thread, error)

添加帖子

func GetThreadById

func GetThreadById(id int) (thread Thread, err error)

根据id获得thread

func GetThreadList

func GetThreadList(page int) (threads []Thread, err error)

首页用获取帖子列表

func GetThreadListByForumID

func GetThreadListByForumID(forumID int, page int, limit int, orderby string) (threads []Thread, err error)

func GetThreads

func GetThreads(whereMap interface{}, order string, limit int) (thread []Thread, err error)

func UpdateThread

func UpdateThread(id int, thread Thread) (upthread Thread, err error)

修改

type ThreadDigest

type ThreadDigest struct {
	ThreadId int `gorm:"primary_key" json:" - "`    //
	ForumId  int `gorm:"default:0" json:"forum_id"` //版块 id
	UserId   int `json:"user_id"`                   //
	Digest   int `json:"digest"`                    //
}

任务队列表

type ThreadTop

type ThreadTop struct {
	ThreadID int `gorm:"primary_key" json:" - "` //
	ForumID  int `json:"forum_id"`               //查找板块置顶
	Top      int `json:"top"`                    //top: 0 是普通最新贴,> 0 置顶贴
	Thread   Thread
}

置顶

func AddThreadToTop

func AddThreadToTop(thread *ThreadTop) (threadTop ThreadTop, err error)

创建一个置顶

func DelThreadTopByTid

func DelThreadTopByTid(threadID int) (threadTop ThreadTop, err error)

删除

func GetThreadTopByTid

func GetThreadTopByTid(threadID int) (threadTop ThreadTop, err error)

获得

func GetTopThreadsForum

func GetTopThreadsForum(forumId int) (threadTop []ThreadTop, err error)

获取置顶模块下置顶的帖子

func GetTopThreadsWholeWebSite

func GetTopThreadsWholeWebSite() (threadTop []ThreadTop, err error)

获取全站置顶的帖子

type User

type User struct {
	Model

	Username     string    `gorm:"default:''" json:"username"`     //用户名
	Realname     string    `gorm:"default:''" json:"realname"`     //用户实名
	GroupID      int       `gorm:"default:0" json:"group_id"`      //用户组编号
	Email        string    `gorm:"default:''" json:"email"`        //邮箱
	EmailChecked int       `gorm:"default:0" json:"email_checked"` //邮箱验证过
	Password     string    `gorm:"default:''" json:"password"`     //密码
	PasswordSms  string    `gorm:"default:''" json:"password_sms"` //密码
	Phone        string    `gorm:"default:''" json:"phone"`        //手机号
	IdNumber     string    `gorm:"default:''" json:"id_number"`    //用户名
	Qq           string    `gorm:"default:''" json:"qq"`           //QQ
	ThreadsCnt   int       `gorm:"default:0" json:"threads_cnt"`   //发帖数
	PostsCnt     int       `gorm:"default:0" json:"posts_cnt"`     //回帖数
	FavouriteCnt int       `gorm:"default:0" json:"favourite_cnt"` //收藏帖子数
	CreditsNum   int       `gorm:"default:0" json:"credits_num"`   //积分
	GoldsNum     int       `gorm:"default:0" json:"golds_num"`     //金币
	RmbsNum      int       `gorm:"default:0" json:"rmbs_num"`      //人民币
	CreateIp     string    `gorm:"default:''" json:"create_ip"`    //创建时IP
	LoginIp      string    `gorm:"default:''" json:"login_ip"`     //登录时IP
	LoginDate    time.Time `json:"login_date"`                     //登录时间
	LoginsCnt    int       `gorm:"default:0" json:"logins_cnt"`    //登录次数
	Avatar       string    `gorm:"default:''" json:"avatar"`       //用户最后更新图像时间
	DigestsCnt   int       `gorm:"default:0" json:"digests_cnt"`   //精华数
	State        int       `json:"state"`
	Group        Group
}

* * @des 用户模型

func AddUser

func AddUser(username, password, email, ip string) (user *User, err error)

* * @des 新增用户 * @param username string 用户名 * @param password string 密码 * @param email string 邮箱 * @param ip string 注册ip * @return User, error

func AddUserPro

func AddUserPro(userinfo *User) (user *User, err error)

* * @des 新增用户 * @param username string 用户名 * @param password string 密码 * @param email string 邮箱 * @param ip string 注册ip * @return User, error

func GetUser

func GetUser(maps interface{}) (user User, err error)

* * @des 根据条件获取一个用户 * @param maps interface{} 条件 * @return User, error

func GetUserByID

func GetUserByID(id int) (user User, err error)

* * @des 根据条件获取一个用户 * @param maps interface{} 条件 * @return User, error

func GetUsers

func GetUsers(num int, order string, maps interface{}) (user []User, err error)

* * @des 根据条件获取用户列表 * @param num int 数量 * @param order string 排序 * @param maps where条件 * @return []User, error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL