初始化v1
This commit is contained in:
0
internal/dao/.gitkeep
Normal file
0
internal/dao/.gitkeep
Normal file
82
internal/dao/admin_log.go
Normal file
82
internal/dao/admin_log.go
Normal file
@@ -0,0 +1,82 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// internalAdminLogDao is internal type for wrapping internal DAO implements.
|
||||
type internalAdminLogDao struct {
|
||||
table string // table is the underlying table name of the DAO.
|
||||
group string // group is the database configuration group name of current DAO.
|
||||
columns AdminLogColumns // columns contains all the column names of Table for convenient usage.
|
||||
}
|
||||
|
||||
// AdminLogColumns defines and stores column names for table nl_admin_log.
|
||||
type AdminLogColumns struct {
|
||||
Id string // 日志ID
|
||||
AdminId string // 管理员ID
|
||||
Action string // 操作动作
|
||||
Module string // 操作模块
|
||||
Content string // 操作内容
|
||||
Ip string // IP地址
|
||||
UserAgent string // 用户代理
|
||||
CreatedAt string // 创建时间
|
||||
}
|
||||
|
||||
// adminLogColumns holds the columns for table nl_admin_log.
|
||||
var adminLogColumns = AdminLogColumns{
|
||||
Id: "id",
|
||||
AdminId: "admin_id",
|
||||
Action: "action",
|
||||
Module: "module",
|
||||
Content: "content",
|
||||
Ip: "ip",
|
||||
UserAgent: "user_agent",
|
||||
CreatedAt: "created_at",
|
||||
}
|
||||
|
||||
// NewAdminLogDao creates and returns a new DAO object for table data access.
|
||||
func NewAdminLogDao() *internalAdminLogDao {
|
||||
return &internalAdminLogDao{
|
||||
group: "default",
|
||||
table: "nl_admin_log",
|
||||
columns: adminLogColumns,
|
||||
}
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *internalAdminLogDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *internalAdminLogDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
// Columns returns the columns of current dao.
|
||||
func (dao *internalAdminLogDao) Columns() AdminLogColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *internalAdminLogDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *internalAdminLogDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
func (dao *internalAdminLogDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) error {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
88
internal/dao/attachment.go
Normal file
88
internal/dao/attachment.go
Normal file
@@ -0,0 +1,88 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// internalAttachmentDao is internal type for wrapping internal DAO implements.
|
||||
type internalAttachmentDao struct {
|
||||
table string // table is the underlying table name of the DAO.
|
||||
group string // group is the database configuration group name of current DAO.
|
||||
columns AttachmentColumns // columns contains all the column names of Table for convenient usage.
|
||||
}
|
||||
|
||||
// AttachmentColumns defines and stores column names for table nl_attachment.
|
||||
type AttachmentColumns struct {
|
||||
Id string // 附件ID
|
||||
Name string // 文件名
|
||||
Path string // 文件路径
|
||||
Url string // 访问URL
|
||||
Size string // 文件大小(字节)
|
||||
MimeType string // 文件类型
|
||||
Extension string // 文件扩展名
|
||||
UserId string // 上传用户ID
|
||||
Status string // 状态:0禁用,1启用
|
||||
CreatedAt string // 创建时间
|
||||
UpdatedAt string // 更新时间
|
||||
}
|
||||
|
||||
// attachmentColumns holds the columns for table nl_attachment.
|
||||
var attachmentColumns = AttachmentColumns{
|
||||
Id: "id",
|
||||
Name: "name",
|
||||
Path: "path",
|
||||
Url: "url",
|
||||
Size: "size",
|
||||
MimeType: "mime_type",
|
||||
Extension: "extension",
|
||||
UserId: "user_id",
|
||||
Status: "status",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
// NewAttachmentDao creates and returns a new DAO object for table data access.
|
||||
func NewAttachmentDao() *internalAttachmentDao {
|
||||
return &internalAttachmentDao{
|
||||
group: "default",
|
||||
table: "nl_attachment",
|
||||
columns: attachmentColumns,
|
||||
}
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *internalAttachmentDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *internalAttachmentDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
// Columns returns the columns of current dao.
|
||||
func (dao *internalAttachmentDao) Columns() AttachmentColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *internalAttachmentDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *internalAttachmentDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
func (dao *internalAttachmentDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) error {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
82
internal/dao/banner.go
Normal file
82
internal/dao/banner.go
Normal file
@@ -0,0 +1,82 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// internalBannerDao is internal type for wrapping internal DAO implements.
|
||||
type internalBannerDao struct {
|
||||
table string // table is the underlying table name of the DAO.
|
||||
group string // group is the database configuration group name of current DAO.
|
||||
columns BannerColumns // columns contains all the column names of Table for convenient usage.
|
||||
}
|
||||
|
||||
// BannerColumns defines and stores column names for table nl_banner.
|
||||
type BannerColumns struct {
|
||||
Id string // 轮播图ID
|
||||
Title string // 轮播图标题
|
||||
ImageUrl string // 图片URL
|
||||
LinkUrl string // 跳转链接
|
||||
Sort string // 排序
|
||||
Status string // 状态:0禁用,1启用
|
||||
CreatedAt string // 创建时间
|
||||
UpdatedAt string // 更新时间
|
||||
}
|
||||
|
||||
// bannerColumns holds the columns for table nl_banner.
|
||||
var bannerColumns = BannerColumns{
|
||||
Id: "id",
|
||||
Title: "title",
|
||||
ImageUrl: "image_url",
|
||||
LinkUrl: "link_url",
|
||||
Sort: "sort",
|
||||
Status: "status",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
// NewBannerDao creates and returns a new DAO object for table data access.
|
||||
func NewBannerDao() *internalBannerDao {
|
||||
return &internalBannerDao{
|
||||
group: "default",
|
||||
table: "nl_banner",
|
||||
columns: bannerColumns,
|
||||
}
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *internalBannerDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *internalBannerDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
// Columns returns the columns of current dao.
|
||||
func (dao *internalBannerDao) Columns() BannerColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *internalBannerDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *internalBannerDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
func (dao *internalBannerDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) error {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
84
internal/dao/comment.go
Normal file
84
internal/dao/comment.go
Normal file
@@ -0,0 +1,84 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// internalCommentDao is internal type for wrapping internal DAO implements.
|
||||
type internalCommentDao struct {
|
||||
table string // table is the underlying table name of the DAO.
|
||||
group string // group is the database configuration group name of current DAO.
|
||||
columns CommentColumns // columns contains all the column names of Table for convenient usage.
|
||||
}
|
||||
|
||||
// CommentColumns defines and stores column names for table nl_comment.
|
||||
type CommentColumns struct {
|
||||
Id string // 评论ID
|
||||
UserId string // 用户ID
|
||||
MovieId string // 影片ID
|
||||
ParentId string // 父评论ID,0为顶级评论
|
||||
Content string // 评论内容
|
||||
LikeCount string // 点赞数
|
||||
Status string // 状态:0待审核,1已通过,2已拒绝
|
||||
CreatedAt string // 创建时间
|
||||
UpdatedAt string // 更新时间
|
||||
}
|
||||
|
||||
// commentColumns holds the columns for table nl_comment.
|
||||
var commentColumns = CommentColumns{
|
||||
Id: "id",
|
||||
UserId: "user_id",
|
||||
MovieId: "movie_id",
|
||||
ParentId: "parent_id",
|
||||
Content: "content",
|
||||
LikeCount: "like_count",
|
||||
Status: "status",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
// NewCommentDao creates and returns a new DAO object for table data access.
|
||||
func NewCommentDao() *internalCommentDao {
|
||||
return &internalCommentDao{
|
||||
group: "default",
|
||||
table: "nl_comment",
|
||||
columns: commentColumns,
|
||||
}
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *internalCommentDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *internalCommentDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
// Columns returns the columns of current dao.
|
||||
func (dao *internalCommentDao) Columns() CommentColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *internalCommentDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *internalCommentDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
func (dao *internalCommentDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) error {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
20
internal/dao/comment_like.go
Normal file
20
internal/dao/comment_like.go
Normal file
@@ -0,0 +1,20 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"nl-video-api/internal/dao/internal"
|
||||
)
|
||||
|
||||
// internalCommentLikeDao is internal type for wrapping internal DAO implements.
|
||||
type internalCommentLikeDao = *internal.CommentLikeDao
|
||||
|
||||
// commentLikeDao is the data access object for table comment_like.
|
||||
// You can define custom methods on it to extend its functionality as you wish.
|
||||
type commentLikeDao struct {
|
||||
internalCommentLikeDao
|
||||
}
|
||||
|
||||
// Fill with you ideas below.
|
||||
20
internal/dao/comment_report.go
Normal file
20
internal/dao/comment_report.go
Normal file
@@ -0,0 +1,20 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"nl-video-api/internal/dao/internal"
|
||||
)
|
||||
|
||||
// internalCommentReportDao is internal type for wrapping internal DAO implements.
|
||||
type internalCommentReportDao = *internal.CommentReportDao
|
||||
|
||||
// commentReportDao is the data access object for table comment_report.
|
||||
// You can define custom methods on it to extend its functionality as you wish.
|
||||
type commentReportDao struct {
|
||||
internalCommentReportDao
|
||||
}
|
||||
|
||||
// Fill with you ideas below.
|
||||
82
internal/dao/config.go
Normal file
82
internal/dao/config.go
Normal file
@@ -0,0 +1,82 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// internalConfigDao is internal type for wrapping internal DAO implements.
|
||||
type internalConfigDao struct {
|
||||
table string // table is the underlying table name of the DAO.
|
||||
group string // group is the database configuration group name of current DAO.
|
||||
columns ConfigColumns // columns contains all the column names of Table for convenient usage.
|
||||
}
|
||||
|
||||
// ConfigColumns defines and stores column names for table nl_config.
|
||||
type ConfigColumns struct {
|
||||
Id string // 配置ID
|
||||
ConfigKey string // 配置键
|
||||
ConfigValue string // 配置值
|
||||
ConfigType string // 配置类型
|
||||
Description string // 配置描述
|
||||
Status string // 状态:0禁用,1启用
|
||||
CreatedAt string // 创建时间
|
||||
UpdatedAt string // 更新时间
|
||||
}
|
||||
|
||||
// configColumns holds the columns for table nl_config.
|
||||
var configColumns = ConfigColumns{
|
||||
Id: "id",
|
||||
ConfigKey: "config_key",
|
||||
ConfigValue: "config_value",
|
||||
ConfigType: "config_type",
|
||||
Description: "description",
|
||||
Status: "status",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
// NewConfigDao creates and returns a new DAO object for table data access.
|
||||
func NewConfigDao() *internalConfigDao {
|
||||
return &internalConfigDao{
|
||||
group: "default",
|
||||
table: "nl_config",
|
||||
columns: configColumns,
|
||||
}
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *internalConfigDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *internalConfigDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
// Columns returns the columns of current dao.
|
||||
func (dao *internalConfigDao) Columns() ConfigColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *internalConfigDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *internalConfigDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
func (dao *internalConfigDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) error {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
109
internal/dao/episode.go
Normal file
109
internal/dao/episode.go
Normal file
@@ -0,0 +1,109 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"nl-video-api/internal/model/entity"
|
||||
)
|
||||
|
||||
// EpisodeDao 集数数据访问对象
|
||||
type EpisodeDao struct{}
|
||||
|
||||
// episodeDao 集数DAO实例
|
||||
var episodeDao = &EpisodeDao{}
|
||||
|
||||
// NewEpisodeDao 创建集数DAO实例
|
||||
func NewEpisodeDao() *EpisodeDao {
|
||||
return episodeDao
|
||||
}
|
||||
|
||||
// GetByMovieId 根据影片ID获取集数列表
|
||||
func (d *EpisodeDao) GetByMovieId(ctx context.Context, movieId int) ([]*entity.Episode, error) {
|
||||
var episodes []*entity.Episode
|
||||
err := g.DB().Model("nl_episode").
|
||||
Where("movie_id = ? AND deleted_at = 0", movieId).
|
||||
Order("episode_num ASC, sort ASC").
|
||||
Scan(&episodes)
|
||||
return episodes, err
|
||||
}
|
||||
|
||||
// GetById 根据ID获取集数详情
|
||||
func (d *EpisodeDao) GetById(ctx context.Context, id int) (*entity.Episode, error) {
|
||||
var episode *entity.Episode
|
||||
err := g.DB().Model("nl_episode").
|
||||
Where("id = ? AND deleted_at = 0", id).
|
||||
Scan(&episode)
|
||||
return episode, err
|
||||
}
|
||||
|
||||
// Create 创建集数
|
||||
func (d *EpisodeDao) Create(ctx context.Context, episode *entity.Episode) (int64, error) {
|
||||
result, err := g.DB().Model("nl_episode").Data(episode).Insert()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.LastInsertId()
|
||||
}
|
||||
|
||||
// Update 更新集数
|
||||
func (d *EpisodeDao) Update(ctx context.Context, id int, data g.Map) error {
|
||||
data["updated_at"] = gtime.Now().Unix()
|
||||
_, err := g.DB().Model("nl_episode").Where("id = ?", id).Data(data).Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete 删除集数(软删除)
|
||||
func (d *EpisodeDao) Delete(ctx context.Context, id int) error {
|
||||
_, err := g.DB().Model("nl_episode").Where("id = ?", id).Data(g.Map{
|
||||
"deleted_at": gtime.Now().Unix(),
|
||||
"updated_at": gtime.Now().Unix(),
|
||||
}).Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateViewCount 更新观看次数
|
||||
func (d *EpisodeDao) UpdateViewCount(ctx context.Context, id int) error {
|
||||
_, err := g.DB().Model("nl_episode").Where("id = ?", id).Increment("view_count", 1)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetMaxEpisodeNum 获取影片的最大集数
|
||||
func (d *EpisodeDao) GetMaxEpisodeNum(ctx context.Context, movieId int) (int, error) {
|
||||
var maxNum int
|
||||
err := g.DB().Model("nl_episode").
|
||||
Where("movie_id = ? AND deleted_at = 0", movieId).
|
||||
Fields("MAX(episode_num) as max_num").
|
||||
Scan(&maxNum)
|
||||
return maxNum, err
|
||||
}
|
||||
|
||||
// BatchCreate 批量创建集数
|
||||
func (d *EpisodeDao) BatchCreate(ctx context.Context, episodes []*entity.Episode) error {
|
||||
if len(episodes) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := g.DB().Model("nl_episode").Data(episodes).Insert()
|
||||
return err
|
||||
}
|
||||
|
||||
// GetEpisodesByRange 获取指定范围的集数
|
||||
func (d *EpisodeDao) GetEpisodesByRange(ctx context.Context, movieId, startNum, endNum int) ([]*entity.Episode, error) {
|
||||
var episodes []*entity.Episode
|
||||
err := g.DB().Model("nl_episode").
|
||||
Where("movie_id = ? AND episode_num >= ? AND episode_num <= ? AND deleted_at = 0",
|
||||
movieId, startNum, endNum).
|
||||
Order("episode_num ASC").
|
||||
Scan(&episodes)
|
||||
return episodes, err
|
||||
}
|
||||
|
||||
// CheckEpisodeExists 检查集数是否存在
|
||||
func (d *EpisodeDao) CheckEpisodeExists(ctx context.Context, movieId, episodeNum int) (bool, error) {
|
||||
count, err := g.DB().Model("nl_episode").
|
||||
Where("movie_id = ? AND episode_num = ? AND deleted_at = 0", movieId, episodeNum).
|
||||
Count()
|
||||
return count > 0, err
|
||||
}
|
||||
75
internal/dao/internal.go
Normal file
75
internal/dao/internal.go
Normal file
@@ -0,0 +1,75 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"nl-video-api/internal/dao/internal"
|
||||
)
|
||||
|
||||
// internalDao is internal type for wrapping internal DAO implements.
|
||||
type internalDao = *internal.Dao
|
||||
|
||||
// Internal returns the internal DAO implements.
|
||||
func Internal() internalDao {
|
||||
return internal.New()
|
||||
}
|
||||
|
||||
// New returns the DAO implements.
|
||||
func New() *internal.Dao {
|
||||
return internal.New()
|
||||
}
|
||||
|
||||
var (
|
||||
// User is globally public accessible object for table nl_user operations.
|
||||
User = NewUserDao()
|
||||
|
||||
// Movie is globally public accessible object for table nl_movie operations.
|
||||
Movie = NewMovieDao()
|
||||
|
||||
// Episode is globally public accessible object for table nl_episode operations.
|
||||
Episode = NewEpisodeDao()
|
||||
|
||||
// Role is globally public accessible object for table nl_role operations.
|
||||
Role = &RoleDao{}
|
||||
|
||||
// Permission is globally public accessible object for table nl_permission operations.
|
||||
Permission = &PermissionDao{}
|
||||
|
||||
// UserCollect is globally public accessible object for table nl_user_collect operations.
|
||||
UserCollect = NewUserCollectDao()
|
||||
|
||||
// UserWatchHistory is globally public accessible object for table nl_user_watch_history operations.
|
||||
UserWatchHistory = NewUserWatchHistoryDao()
|
||||
|
||||
// Comment is globally public accessible object for table nl_comment operations.
|
||||
Comment = NewCommentDao()
|
||||
|
||||
// Banner is globally public accessible object for table nl_banner operations.
|
||||
Banner = NewBannerDao()
|
||||
|
||||
// PaymentOrder is globally public accessible object for table nl_payment_order operations.
|
||||
PaymentOrder = NewPaymentOrderDao()
|
||||
|
||||
// VipLevel is globally public accessible object for table nl_vip_level operations.
|
||||
VipLevel = NewVipLevelDao()
|
||||
|
||||
// Attachment is globally public accessible object for table nl_attachment operations.
|
||||
Attachment = NewAttachmentDao()
|
||||
|
||||
// Config is globally public accessible object for table nl_config operations.
|
||||
Config = NewConfigDao()
|
||||
|
||||
// AdminLog is globally public accessible object for table nl_admin_log operations.
|
||||
AdminLog = NewAdminLogDao()
|
||||
|
||||
// UserLog is globally public accessible object for table nl_user_log operations.
|
||||
UserLog = NewUserLogDao()
|
||||
|
||||
// CommentLike is globally public accessible object for table comment_like operations.
|
||||
CommentLike = internal.NewCommentLikeDao()
|
||||
|
||||
// CommentReport is globally public accessible object for table comment_report operations.
|
||||
CommentReport = internal.NewCommentReportDao()
|
||||
)
|
||||
69
internal/dao/internal/comment_like.go
Normal file
69
internal/dao/internal/comment_like.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// CommentLikeDao is the data access object for table comment_like.
|
||||
type CommentLikeDao struct {
|
||||
table string
|
||||
group string
|
||||
columns CommentLikeColumns
|
||||
}
|
||||
|
||||
// CommentLikeColumns defines and stores column names for table comment_like.
|
||||
type CommentLikeColumns struct {
|
||||
Id string
|
||||
CommentId string
|
||||
UserId string
|
||||
CreatedAt string
|
||||
}
|
||||
|
||||
// commentLikeColumns holds the columns for table comment_like.
|
||||
var commentLikeColumns = CommentLikeColumns{
|
||||
Id: "id",
|
||||
CommentId: "comment_id",
|
||||
UserId: "user_id",
|
||||
CreatedAt: "created_at",
|
||||
}
|
||||
|
||||
// NewCommentLikeDao creates and returns a new DAO object for table data access.
|
||||
func NewCommentLikeDao() *CommentLikeDao {
|
||||
return &CommentLikeDao{
|
||||
group: "default",
|
||||
table: "comment_like",
|
||||
columns: commentLikeColumns,
|
||||
}
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *CommentLikeDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *CommentLikeDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
// Columns returns the columns of current dao.
|
||||
func (dao *CommentLikeDao) Columns() CommentLikeColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *CommentLikeDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *CommentLikeDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
func (dao *CommentLikeDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
73
internal/dao/internal/comment_report.go
Normal file
73
internal/dao/internal/comment_report.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// CommentReportDao is the data access object for table comment_report.
|
||||
type CommentReportDao struct {
|
||||
table string
|
||||
group string
|
||||
columns CommentReportColumns
|
||||
}
|
||||
|
||||
// CommentReportColumns defines and stores column names for table comment_report.
|
||||
type CommentReportColumns struct {
|
||||
Id string
|
||||
CommentId string
|
||||
UserId string
|
||||
Reason string
|
||||
Status string
|
||||
CreatedAt string
|
||||
}
|
||||
|
||||
// commentReportColumns holds the columns for table comment_report.
|
||||
var commentReportColumns = CommentReportColumns{
|
||||
Id: "id",
|
||||
CommentId: "comment_id",
|
||||
UserId: "user_id",
|
||||
Reason: "reason",
|
||||
Status: "status",
|
||||
CreatedAt: "created_at",
|
||||
}
|
||||
|
||||
// NewCommentReportDao creates and returns a new DAO object for table data access.
|
||||
func NewCommentReportDao() *CommentReportDao {
|
||||
return &CommentReportDao{
|
||||
group: "default",
|
||||
table: "comment_report",
|
||||
columns: commentReportColumns,
|
||||
}
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *CommentReportDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *CommentReportDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
// Columns returns the columns of current dao.
|
||||
func (dao *CommentReportDao) Columns() CommentReportColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *CommentReportDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *CommentReportDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
func (dao *CommentReportDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
51
internal/dao/internal/dao.go
Normal file
51
internal/dao/internal/dao.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// Dao is the data access object for database operations.
|
||||
type Dao struct {
|
||||
table string
|
||||
group string
|
||||
columns []string
|
||||
}
|
||||
|
||||
// New creates and returns a new DAO object.
|
||||
func New() *Dao {
|
||||
return &Dao{
|
||||
group: "default",
|
||||
}
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *Dao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *Dao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
// Columns returns the columns of current dao.
|
||||
func (dao *Dao) Columns() []string {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *Dao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *Dao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
func (dao *Dao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
259
internal/dao/movie.go
Normal file
259
internal/dao/movie.go
Normal file
@@ -0,0 +1,259 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"nl-video-api/internal/model/entity"
|
||||
)
|
||||
|
||||
// MovieDao 影片数据访问对象
|
||||
type MovieDao struct{}
|
||||
|
||||
// movieDao 影片DAO实例
|
||||
var movieDao = &MovieDao{}
|
||||
|
||||
// NewMovieDao 创建影片DAO实例
|
||||
func NewMovieDao() *MovieDao {
|
||||
return movieDao
|
||||
}
|
||||
|
||||
// GetList 获取影片列表
|
||||
func (d *MovieDao) GetList(ctx context.Context, req *MovieListReq) ([]*entity.Movie, int, error) {
|
||||
db := g.DB()
|
||||
model := db.Model("nl_movie").Where("deleted_at = 0")
|
||||
|
||||
// 条件筛选
|
||||
if req.CategoryId > 0 {
|
||||
model = model.Where("category_id = ?", req.CategoryId)
|
||||
}
|
||||
if req.Type > 0 {
|
||||
model = model.Where("type = ?", req.Type)
|
||||
}
|
||||
if req.Year > 0 {
|
||||
model = model.Where("year = ?", req.Year)
|
||||
}
|
||||
if req.Area != "" {
|
||||
model = model.Where("area = ?", req.Area)
|
||||
}
|
||||
if req.Language != "" {
|
||||
model = model.Where("language = ?", req.Language)
|
||||
}
|
||||
if req.IsVip >= 0 {
|
||||
model = model.Where("is_vip = ?", req.IsVip)
|
||||
}
|
||||
if req.IsRecommend >= 0 {
|
||||
model = model.Where("is_recommend = ?", req.IsRecommend)
|
||||
}
|
||||
if req.IsHot >= 0 {
|
||||
model = model.Where("is_hot = ?", req.IsHot)
|
||||
}
|
||||
if req.IsNew >= 0 {
|
||||
model = model.Where("is_new = ?", req.IsNew)
|
||||
}
|
||||
if req.Status >= 0 {
|
||||
model = model.Where("status = ?", req.Status)
|
||||
}
|
||||
if req.Keyword != "" {
|
||||
model = model.Where("title LIKE ? OR original_title LIKE ? OR director LIKE ? OR actor LIKE ?",
|
||||
"%"+req.Keyword+"%", "%"+req.Keyword+"%", "%"+req.Keyword+"%", "%"+req.Keyword+"%")
|
||||
}
|
||||
|
||||
// 获取总数
|
||||
total, err := model.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 排序
|
||||
orderBy := "created_at DESC"
|
||||
if req.OrderBy != "" {
|
||||
orderBy = req.OrderBy
|
||||
}
|
||||
model = model.Order(orderBy)
|
||||
|
||||
// 分页
|
||||
if req.Page > 0 && req.PageSize > 0 {
|
||||
offset := (req.Page - 1) * req.PageSize
|
||||
model = model.Limit(req.PageSize).Offset(offset)
|
||||
}
|
||||
|
||||
var movies []*entity.Movie
|
||||
err = model.Scan(&movies)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return movies, total, nil
|
||||
}
|
||||
|
||||
// GetById 根据ID获取影片
|
||||
func (d *MovieDao) GetById(ctx context.Context, id int) (*entity.Movie, error) {
|
||||
var movie *entity.Movie
|
||||
err := g.DB().Model("nl_movie").Where("id = ? AND deleted_at = 0", id).Scan(&movie)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return movie, nil
|
||||
}
|
||||
|
||||
// Create 创建影片
|
||||
func (d *MovieDao) Create(ctx context.Context, movie *entity.Movie) (int64, error) {
|
||||
result, err := g.DB().Model("nl_movie").Data(movie).Insert()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// Update 更新影片
|
||||
func (d *MovieDao) Update(ctx context.Context, id int, data g.Map) error {
|
||||
data["updated_at"] = gtime.Now().Unix()
|
||||
_, err := g.DB().Model("nl_movie").Where("id = ?", id).Data(data).Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete 删除影片(软删除)
|
||||
func (d *MovieDao) Delete(ctx context.Context, id int) error {
|
||||
_, err := g.DB().Model("nl_movie").Where("id = ?", id).Data(g.Map{
|
||||
"deleted_at": gtime.Now().Unix(),
|
||||
"updated_at": gtime.Now().Unix(),
|
||||
}).Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateViewCount 更新观看次数
|
||||
func (d *MovieDao) UpdateViewCount(ctx context.Context, id int) error {
|
||||
_, err := g.DB().Model("nl_movie").Where("id = ?", id).Increment("view_count", 1)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateLikeCount 更新点赞数
|
||||
func (d *MovieDao) UpdateLikeCount(ctx context.Context, id int, increment int) error {
|
||||
_, err := g.DB().Model("nl_movie").Where("id = ?", id).Increment("like_count", increment)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateCollectCount 更新收藏数
|
||||
func (d *MovieDao) UpdateCollectCount(ctx context.Context, id int, increment int) error {
|
||||
_, err := g.DB().Model("nl_movie").Where("id = ?", id).Increment("collect_count", increment)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateCommentCount 更新评论数
|
||||
func (d *MovieDao) UpdateCommentCount(ctx context.Context, id int, increment int) error {
|
||||
_, err := g.DB().Model("nl_movie").Where("id = ?", id).Increment("comment_count", increment)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetHotMovies 获取热门影片
|
||||
func (d *MovieDao) GetHotMovies(ctx context.Context, limit int) ([]*entity.Movie, error) {
|
||||
var movies []*entity.Movie
|
||||
err := g.DB().Model("nl_movie").
|
||||
Where("status = 1 AND deleted_at = 0").
|
||||
Order("view_count DESC, rating DESC").
|
||||
Limit(limit).
|
||||
Scan(&movies)
|
||||
return movies, err
|
||||
}
|
||||
|
||||
// GetRecommendMovies 获取推荐影片
|
||||
func (d *MovieDao) GetRecommendMovies(ctx context.Context, limit int) ([]*entity.Movie, error) {
|
||||
var movies []*entity.Movie
|
||||
err := g.DB().Model("nl_movie").
|
||||
Where("is_recommend = 1 AND status = 1 AND deleted_at = 0").
|
||||
Order("sort ASC, created_at DESC").
|
||||
Limit(limit).
|
||||
Scan(&movies)
|
||||
return movies, err
|
||||
}
|
||||
|
||||
// GetNewMovies 获取最新影片
|
||||
func (d *MovieDao) GetNewMovies(ctx context.Context, limit int) ([]*entity.Movie, error) {
|
||||
var movies []*entity.Movie
|
||||
err := g.DB().Model("nl_movie").
|
||||
Where("status = 1 AND deleted_at = 0").
|
||||
Order("created_at DESC").
|
||||
Limit(limit).
|
||||
Scan(&movies)
|
||||
return movies, err
|
||||
}
|
||||
|
||||
// SearchMovies 搜索影片
|
||||
func (d *MovieDao) SearchMovies(ctx context.Context, keyword string, page, pageSize int) ([]*entity.Movie, int, error) {
|
||||
db := g.DB()
|
||||
model := db.Model("nl_movie").
|
||||
Where("deleted_at = 0 AND status = 1").
|
||||
Where("title LIKE ? OR original_title LIKE ? OR director LIKE ? OR actor LIKE ? OR description LIKE ?",
|
||||
"%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%")
|
||||
|
||||
// 获取总数
|
||||
total, err := model.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 分页
|
||||
if page > 0 && pageSize > 0 {
|
||||
offset := (page - 1) * pageSize
|
||||
model = model.Limit(pageSize).Offset(offset)
|
||||
}
|
||||
|
||||
var movies []*entity.Movie
|
||||
err = model.Order("rating DESC, view_count DESC").Scan(&movies)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return movies, total, nil
|
||||
}
|
||||
|
||||
// GetMoviesByCategory 根据分类获取影片
|
||||
func (d *MovieDao) GetMoviesByCategory(ctx context.Context, categoryId, page, pageSize int) ([]*entity.Movie, int, error) {
|
||||
db := g.DB()
|
||||
model := db.Model("nl_movie").
|
||||
Where("category_id = ? AND status = 1 AND deleted_at = 0", categoryId)
|
||||
|
||||
// 获取总数
|
||||
total, err := model.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 分页
|
||||
if page > 0 && pageSize > 0 {
|
||||
offset := (page - 1) * pageSize
|
||||
model = model.Limit(pageSize).Offset(offset)
|
||||
}
|
||||
|
||||
var movies []*entity.Movie
|
||||
err = model.Order("sort ASC, created_at DESC").Scan(&movies)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return movies, total, nil
|
||||
}
|
||||
|
||||
// MovieListReq 影片列表请求参数
|
||||
type MovieListReq struct {
|
||||
Page int `json:"page"` // 页码
|
||||
PageSize int `json:"page_size"` // 每页数量
|
||||
CategoryId int `json:"category_id"` // 分类ID
|
||||
Type int `json:"type"` // 类型
|
||||
Year int `json:"year"` // 年份
|
||||
Area string `json:"area"` // 地区
|
||||
Language string `json:"language"` // 语言
|
||||
IsVip int `json:"is_vip"` // 是否VIP专享
|
||||
IsRecommend int `json:"is_recommend"` // 是否推荐
|
||||
IsHot int `json:"is_hot"` // 是否热门
|
||||
IsNew int `json:"is_new"` // 是否最新
|
||||
Status int `json:"status"` // 状态
|
||||
Keyword string `json:"keyword"` // 关键词
|
||||
OrderBy string `json:"order_by"` // 排序
|
||||
}
|
||||
90
internal/dao/payment_order.go
Normal file
90
internal/dao/payment_order.go
Normal file
@@ -0,0 +1,90 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// internalPaymentOrderDao is internal type for wrapping internal DAO implements.
|
||||
type internalPaymentOrderDao struct {
|
||||
table string // table is the underlying table name of the DAO.
|
||||
group string // group is the database configuration group name of current DAO.
|
||||
columns PaymentOrderColumns // columns contains all the column names of Table for convenient usage.
|
||||
}
|
||||
|
||||
// PaymentOrderColumns defines and stores column names for table nl_payment_order.
|
||||
type PaymentOrderColumns struct {
|
||||
Id string // 订单ID
|
||||
OrderNo string // 订单号
|
||||
UserId string // 用户ID
|
||||
VipLevelId string // VIP等级ID
|
||||
Amount string // 订单金额
|
||||
PaymentMethod string // 支付方式
|
||||
PaymentStatus string // 支付状态:0待支付,1已支付,2已取消,3已退款
|
||||
PaymentTime string // 支付时间
|
||||
ExpireTime string // 过期时间
|
||||
Remark string // 备注
|
||||
CreatedAt string // 创建时间
|
||||
UpdatedAt string // 更新时间
|
||||
}
|
||||
|
||||
// paymentOrderColumns holds the columns for table nl_payment_order.
|
||||
var paymentOrderColumns = PaymentOrderColumns{
|
||||
Id: "id",
|
||||
OrderNo: "order_no",
|
||||
UserId: "user_id",
|
||||
VipLevelId: "vip_level_id",
|
||||
Amount: "amount",
|
||||
PaymentMethod: "payment_method",
|
||||
PaymentStatus: "payment_status",
|
||||
PaymentTime: "payment_time",
|
||||
ExpireTime: "expire_time",
|
||||
Remark: "remark",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
// NewPaymentOrderDao creates and returns a new DAO object for table data access.
|
||||
func NewPaymentOrderDao() *internalPaymentOrderDao {
|
||||
return &internalPaymentOrderDao{
|
||||
group: "default",
|
||||
table: "nl_payment_order",
|
||||
columns: paymentOrderColumns,
|
||||
}
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *internalPaymentOrderDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *internalPaymentOrderDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
// Columns returns the columns of current dao.
|
||||
func (dao *internalPaymentOrderDao) Columns() PaymentOrderColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *internalPaymentOrderDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *internalPaymentOrderDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
func (dao *internalPaymentOrderDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) error {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
248
internal/dao/permission.go
Normal file
248
internal/dao/permission.go
Normal file
@@ -0,0 +1,248 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"nl-video-api/internal/model/entity"
|
||||
)
|
||||
|
||||
// PermissionDao 权限数据访问对象
|
||||
type PermissionDao struct{}
|
||||
|
||||
// TableName 获取表名
|
||||
func (dao *PermissionDao) TableName() string {
|
||||
return "nl_permission"
|
||||
}
|
||||
|
||||
// Create 创建权限
|
||||
func (dao *PermissionDao) Create(ctx context.Context, data *entity.Permission) (int, error) {
|
||||
result, err := g.DB().Model(dao.TableName()).Ctx(ctx).Data(data).Insert()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return int(id), nil
|
||||
}
|
||||
|
||||
// GetById 根据ID获取权限
|
||||
func (dao *PermissionDao) GetById(ctx context.Context, id int) (*entity.Permission, error) {
|
||||
var permission *entity.Permission
|
||||
err := g.DB().Model(dao.TableName()).Ctx(ctx).Where("id = ? AND deleted_at = 0", id).Scan(&permission)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return permission, nil
|
||||
}
|
||||
|
||||
// GetByCode 根据权限编码获取权限
|
||||
func (dao *PermissionDao) GetByCode(ctx context.Context, code string) (*entity.Permission, error) {
|
||||
var permission *entity.Permission
|
||||
err := g.DB().Model(dao.TableName()).Ctx(ctx).Where("code = ? AND deleted_at = 0", code).Scan(&permission)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return permission, nil
|
||||
}
|
||||
|
||||
// Update 更新权限
|
||||
func (dao *PermissionDao) Update(ctx context.Context, id int, data g.Map) error {
|
||||
data["updated_at"] = gtime.Now().Unix()
|
||||
_, err := g.DB().Model(dao.TableName()).Ctx(ctx).Where("id = ?", id).Data(data).Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete 删除权限(软删除)
|
||||
func (dao *PermissionDao) Delete(ctx context.Context, id int) error {
|
||||
data := g.Map{
|
||||
"deleted_at": gtime.Now().Unix(),
|
||||
"updated_at": gtime.Now().Unix(),
|
||||
}
|
||||
_, err := g.DB().Model(dao.TableName()).Ctx(ctx).Where("id = ?", id).Data(data).Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// GetList 获取权限列表
|
||||
func (dao *PermissionDao) GetList(ctx context.Context, req *PermissionListReq) ([]*entity.Permission, int, error) {
|
||||
model := g.DB().Model(dao.TableName()).Ctx(ctx).Where("deleted_at = 0")
|
||||
|
||||
// 条件筛选
|
||||
if req.Name != "" {
|
||||
model = model.WhereLike("name", "%"+req.Name+"%")
|
||||
}
|
||||
if req.Code != "" {
|
||||
model = model.WhereLike("code", "%"+req.Code+"%")
|
||||
}
|
||||
if req.Type != "" {
|
||||
model = model.Where("type = ?", req.Type)
|
||||
}
|
||||
if req.Status >= 0 {
|
||||
model = model.Where("status = ?", req.Status)
|
||||
}
|
||||
if req.ParentId >= 0 {
|
||||
model = model.Where("parent_id = ?", req.ParentId)
|
||||
}
|
||||
|
||||
// 获取总数
|
||||
total, err := model.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 分页和排序
|
||||
if req.Page > 0 && req.PageSize > 0 {
|
||||
offset := (req.Page - 1) * req.PageSize
|
||||
model = model.Limit(req.PageSize).Offset(offset)
|
||||
}
|
||||
|
||||
model = model.OrderAsc("sort").OrderAsc("id")
|
||||
|
||||
var permissions []*entity.Permission
|
||||
err = model.Scan(&permissions)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return permissions, total, nil
|
||||
}
|
||||
|
||||
// GetTree 获取权限树形结构
|
||||
func (dao *PermissionDao) GetTree(ctx context.Context) ([]*entity.Permission, error) {
|
||||
var permissions []*entity.Permission
|
||||
err := g.DB().Model(dao.TableName()).Ctx(ctx).
|
||||
Where("deleted_at = 0 AND status = 1").
|
||||
OrderAsc("sort").OrderAsc("id").
|
||||
Scan(&permissions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 构建树形结构
|
||||
return dao.buildTree(permissions, 0), nil
|
||||
}
|
||||
|
||||
// buildTree 构建树形结构
|
||||
func (dao *PermissionDao) buildTree(permissions []*entity.Permission, parentId int) []*entity.Permission {
|
||||
var tree []*entity.Permission
|
||||
|
||||
for _, permission := range permissions {
|
||||
if permission.ParentId == parentId {
|
||||
children := dao.buildTree(permissions, permission.Id)
|
||||
if len(children) > 0 {
|
||||
// 这里需要在Permission实体中添加Children字段
|
||||
// permission.Children = children
|
||||
}
|
||||
tree = append(tree, permission)
|
||||
}
|
||||
}
|
||||
|
||||
return tree
|
||||
}
|
||||
|
||||
// GetAll 获取所有权限
|
||||
func (dao *PermissionDao) GetAll(ctx context.Context) ([]*entity.Permission, error) {
|
||||
var permissions []*entity.Permission
|
||||
err := g.DB().Model(dao.TableName()).Ctx(ctx).
|
||||
Where("deleted_at = 0 AND status = 1").
|
||||
OrderAsc("sort").OrderAsc("id").
|
||||
Scan(&permissions)
|
||||
return permissions, err
|
||||
}
|
||||
|
||||
// GetByParentId 根据父级ID获取权限
|
||||
func (dao *PermissionDao) GetByParentId(ctx context.Context, parentId int) ([]*entity.Permission, error) {
|
||||
var permissions []*entity.Permission
|
||||
err := g.DB().Model(dao.TableName()).Ctx(ctx).
|
||||
Where("parent_id = ? AND deleted_at = 0 AND status = 1", parentId).
|
||||
OrderAsc("sort").OrderAsc("id").
|
||||
Scan(&permissions)
|
||||
return permissions, err
|
||||
}
|
||||
|
||||
// GetByType 根据类型获取权限
|
||||
func (dao *PermissionDao) GetByType(ctx context.Context, permissionType string) ([]*entity.Permission, error) {
|
||||
var permissions []*entity.Permission
|
||||
err := g.DB().Model(dao.TableName()).Ctx(ctx).
|
||||
Where("type = ? AND deleted_at = 0 AND status = 1", permissionType).
|
||||
OrderAsc("sort").OrderAsc("id").
|
||||
Scan(&permissions)
|
||||
return permissions, err
|
||||
}
|
||||
|
||||
// CheckCodeExists 检查权限编码是否存在
|
||||
func (dao *PermissionDao) CheckCodeExists(ctx context.Context, code string, excludeId int) (bool, error) {
|
||||
model := g.DB().Model(dao.TableName()).Ctx(ctx).Where("code = ? AND deleted_at = 0", code)
|
||||
if excludeId > 0 {
|
||||
model = model.Where("id != ?", excludeId)
|
||||
}
|
||||
|
||||
count, err := model.Count()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// GetPermissionsByIds 根据ID列表获取权限
|
||||
func (dao *PermissionDao) GetPermissionsByIds(ctx context.Context, ids []int) ([]*entity.Permission, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*entity.Permission{}, nil
|
||||
}
|
||||
|
||||
var permissions []*entity.Permission
|
||||
err := g.DB().Model(dao.TableName()).Ctx(ctx).
|
||||
Where("id IN (?) AND deleted_at = 0", ids).
|
||||
OrderAsc("sort").OrderAsc("id").
|
||||
Scan(&permissions)
|
||||
return permissions, err
|
||||
}
|
||||
|
||||
// GetMenuPermissions 获取菜单权限
|
||||
func (dao *PermissionDao) GetMenuPermissions(ctx context.Context) ([]*entity.Permission, error) {
|
||||
var permissions []*entity.Permission
|
||||
err := g.DB().Model(dao.TableName()).Ctx(ctx).
|
||||
Where("type = 'menu' AND deleted_at = 0 AND status = 1").
|
||||
OrderAsc("sort").OrderAsc("id").
|
||||
Scan(&permissions)
|
||||
return permissions, err
|
||||
}
|
||||
|
||||
// GetApiPermissions 获取API权限
|
||||
func (dao *PermissionDao) GetApiPermissions(ctx context.Context) ([]*entity.Permission, error) {
|
||||
var permissions []*entity.Permission
|
||||
err := g.DB().Model(dao.TableName()).Ctx(ctx).
|
||||
Where("type = 'api' AND deleted_at = 0 AND status = 1").
|
||||
OrderAsc("sort").OrderAsc("id").
|
||||
Scan(&permissions)
|
||||
return permissions, err
|
||||
}
|
||||
|
||||
// GetUserPermissions 获取用户权限(通过角色)
|
||||
func (dao *PermissionDao) GetUserPermissions(ctx context.Context, userId int) ([]*entity.Permission, error) {
|
||||
var permissions []*entity.Permission
|
||||
err := g.DB().Model("nl_permission p").Ctx(ctx).
|
||||
LeftJoin("nl_role_permission rp", "p.id = rp.permission_id").
|
||||
LeftJoin("nl_admin a", "a.role_id = rp.role_id").
|
||||
Where("a.id = ? AND p.deleted_at = 0 AND p.status = 1", userId).
|
||||
OrderAsc("p.sort").OrderAsc("p.id").
|
||||
Scan(&permissions)
|
||||
return permissions, err
|
||||
}
|
||||
|
||||
// PermissionListReq 权限列表请求参数
|
||||
type PermissionListReq struct {
|
||||
Page int `json:"page" v:"min:1#页码最小为1"`
|
||||
PageSize int `json:"page_size" v:"min:1,max:100#每页数量范围1-100"`
|
||||
Name string `json:"name"` // 权限名称
|
||||
Code string `json:"code"` // 权限编码
|
||||
Type string `json:"type"` // 权限类型:menu-菜单,button-按钮,api-接口
|
||||
Status int `json:"status"` // 状态:-1-全部,0-禁用,1-启用
|
||||
ParentId int `json:"parent_id"` // 父级ID:-1-全部,0-顶级,>0-指定父级
|
||||
}
|
||||
200
internal/dao/role.go
Normal file
200
internal/dao/role.go
Normal file
@@ -0,0 +1,200 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"nl-video-api/internal/model/entity"
|
||||
)
|
||||
|
||||
// RoleDao 角色数据访问对象
|
||||
type RoleDao struct{}
|
||||
|
||||
// TableName 获取表名
|
||||
func (dao *RoleDao) TableName() string {
|
||||
return "nl_role"
|
||||
}
|
||||
|
||||
// Create 创建角色
|
||||
func (dao *RoleDao) Create(ctx context.Context, data *entity.Role) (int, error) {
|
||||
result, err := g.DB().Model(dao.TableName()).Ctx(ctx).Data(data).Insert()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return int(id), nil
|
||||
}
|
||||
|
||||
// GetById 根据ID获取角色
|
||||
func (dao *RoleDao) GetById(ctx context.Context, id int) (*entity.Role, error) {
|
||||
var role *entity.Role
|
||||
err := g.DB().Model(dao.TableName()).Ctx(ctx).Where("id = ? AND deleted_at = 0", id).Scan(&role)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return role, nil
|
||||
}
|
||||
|
||||
// GetByCode 根据角色编码获取角色
|
||||
func (dao *RoleDao) GetByCode(ctx context.Context, code string) (*entity.Role, error) {
|
||||
var role *entity.Role
|
||||
err := g.DB().Model(dao.TableName()).Ctx(ctx).Where("code = ? AND deleted_at = 0", code).Scan(&role)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return role, nil
|
||||
}
|
||||
|
||||
// Update 更新角色
|
||||
func (dao *RoleDao) Update(ctx context.Context, id int, data g.Map) error {
|
||||
data["updated_at"] = gtime.Now().Unix()
|
||||
_, err := g.DB().Model(dao.TableName()).Ctx(ctx).Where("id = ?", id).Data(data).Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete 删除角色(软删除)
|
||||
func (dao *RoleDao) Delete(ctx context.Context, id int) error {
|
||||
data := g.Map{
|
||||
"deleted_at": gtime.Now().Unix(),
|
||||
"updated_at": gtime.Now().Unix(),
|
||||
}
|
||||
_, err := g.DB().Model(dao.TableName()).Ctx(ctx).Where("id = ?", id).Data(data).Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// GetList 获取角色列表
|
||||
func (dao *RoleDao) GetList(ctx context.Context, req *RoleListReq) ([]*entity.Role, int, error) {
|
||||
model := g.DB().Model(dao.TableName()).Ctx(ctx).Where("deleted_at = 0")
|
||||
|
||||
// 条件筛选
|
||||
if req.Name != "" {
|
||||
model = model.WhereLike("name", "%"+req.Name+"%")
|
||||
}
|
||||
if req.Code != "" {
|
||||
model = model.WhereLike("code", "%"+req.Code+"%")
|
||||
}
|
||||
if req.Status >= 0 {
|
||||
model = model.Where("status = ?", req.Status)
|
||||
}
|
||||
if req.Level > 0 {
|
||||
model = model.Where("level = ?", req.Level)
|
||||
}
|
||||
|
||||
// 获取总数
|
||||
total, err := model.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 分页和排序
|
||||
if req.Page > 0 && req.PageSize > 0 {
|
||||
offset := (req.Page - 1) * req.PageSize
|
||||
model = model.Limit(req.PageSize).Offset(offset)
|
||||
}
|
||||
|
||||
model = model.OrderDesc("sort").OrderDesc("id")
|
||||
|
||||
var roles []*entity.Role
|
||||
err = model.Scan(&roles)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return roles, total, nil
|
||||
}
|
||||
|
||||
// GetAll 获取所有角色
|
||||
func (dao *RoleDao) GetAll(ctx context.Context) ([]*entity.Role, error) {
|
||||
var roles []*entity.Role
|
||||
err := g.DB().Model(dao.TableName()).Ctx(ctx).
|
||||
Where("deleted_at = 0 AND status = 1").
|
||||
OrderDesc("sort").OrderDesc("id").
|
||||
Scan(&roles)
|
||||
return roles, err
|
||||
}
|
||||
|
||||
// CheckCodeExists 检查角色编码是否存在
|
||||
func (dao *RoleDao) CheckCodeExists(ctx context.Context, code string, excludeId int) (bool, error) {
|
||||
model := g.DB().Model(dao.TableName()).Ctx(ctx).Where("code = ? AND deleted_at = 0", code)
|
||||
if excludeId > 0 {
|
||||
model = model.Where("id != ?", excludeId)
|
||||
}
|
||||
|
||||
count, err := model.Count()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// GetRolesByIds 根据ID列表获取角色
|
||||
func (dao *RoleDao) GetRolesByIds(ctx context.Context, ids []int) ([]*entity.Role, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*entity.Role{}, nil
|
||||
}
|
||||
|
||||
var roles []*entity.Role
|
||||
err := g.DB().Model(dao.TableName()).Ctx(ctx).
|
||||
Where("id IN (?) AND deleted_at = 0", ids).
|
||||
OrderDesc("sort").OrderDesc("id").
|
||||
Scan(&roles)
|
||||
return roles, err
|
||||
}
|
||||
|
||||
// GetRolePermissions 获取角色的权限列表
|
||||
func (dao *RoleDao) GetRolePermissions(ctx context.Context, roleId int) ([]*entity.Permission, error) {
|
||||
var permissions []*entity.Permission
|
||||
err := g.DB().Model("nl_permission p").Ctx(ctx).
|
||||
LeftJoin("nl_role_permission rp", "p.id = rp.permission_id").
|
||||
Where("rp.role_id = ? AND p.deleted_at = 0 AND p.status = 1", roleId).
|
||||
OrderAsc("p.sort").OrderAsc("p.id").
|
||||
Scan(&permissions)
|
||||
return permissions, err
|
||||
}
|
||||
|
||||
// AssignPermissions 为角色分配权限
|
||||
func (dao *RoleDao) AssignPermissions(ctx context.Context, roleId int, permissionIds []int) error {
|
||||
return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
// 先删除原有权限
|
||||
_, err := tx.Model("nl_role_permission").Ctx(ctx).Where("role_id = ?", roleId).Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 添加新权限
|
||||
if len(permissionIds) > 0 {
|
||||
data := make([]g.Map, 0, len(permissionIds))
|
||||
for _, permissionId := range permissionIds {
|
||||
data = append(data, g.Map{
|
||||
"role_id": roleId,
|
||||
"permission_id": permissionId,
|
||||
"created_at": gtime.Now().Unix(),
|
||||
})
|
||||
}
|
||||
_, err = tx.Model("nl_role_permission").Ctx(ctx).Data(data).Insert()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// RoleListReq 角色列表请求参数
|
||||
type RoleListReq struct {
|
||||
Page int `json:"page" v:"min:1#页码最小为1"`
|
||||
PageSize int `json:"page_size" v:"min:1,max:100#每页数量范围1-100"`
|
||||
Name string `json:"name"` // 角色名称
|
||||
Code string `json:"code"` // 角色编码
|
||||
Status int `json:"status"` // 状态:-1-全部,0-禁用,1-启用
|
||||
Level int `json:"level"` // 角色等级
|
||||
}
|
||||
356
internal/dao/user.go
Normal file
356
internal/dao/user.go
Normal file
@@ -0,0 +1,356 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"nl-video-api/internal/model/entity"
|
||||
)
|
||||
|
||||
// UserDao 用户数据访问对象
|
||||
type UserDao struct {
|
||||
table string
|
||||
group string
|
||||
columns UserColumns
|
||||
}
|
||||
|
||||
// UserColumns 用户表字段
|
||||
type UserColumns struct {
|
||||
Id string
|
||||
Username string
|
||||
Phone string
|
||||
Email string
|
||||
Password string
|
||||
Nickname string
|
||||
Avatar string
|
||||
Gender string
|
||||
Birthday string
|
||||
VipLevel string
|
||||
VipExpireAt string
|
||||
Balance string
|
||||
Points string
|
||||
Status string
|
||||
LastLoginAt string
|
||||
LastLoginIp string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
DeletedAt string
|
||||
}
|
||||
|
||||
// UserListReq 用户列表请求
|
||||
type UserListReq struct {
|
||||
Page int `json:"page" d:"1"`
|
||||
PageSize int `json:"page_size" d:"20"`
|
||||
Username string `json:"username"`
|
||||
Phone string `json:"phone"`
|
||||
Email string `json:"email"`
|
||||
Status int `json:"status"`
|
||||
VipLevel int `json:"vip_level"`
|
||||
Gender int `json:"gender"`
|
||||
StartTime string `json:"start_time"`
|
||||
EndTime string `json:"end_time"`
|
||||
}
|
||||
|
||||
// userDao 用户DAO实例
|
||||
var userDao = UserDao{
|
||||
table: "nl_user",
|
||||
group: "default",
|
||||
columns: UserColumns{
|
||||
Id: "id",
|
||||
Username: "username",
|
||||
Phone: "phone",
|
||||
Email: "email",
|
||||
Password: "password",
|
||||
Nickname: "nickname",
|
||||
Avatar: "avatar",
|
||||
Gender: "gender",
|
||||
Birthday: "birthday",
|
||||
VipLevel: "vip_level",
|
||||
VipExpireAt: "vip_expire_at",
|
||||
Balance: "balance",
|
||||
Points: "points",
|
||||
Status: "status",
|
||||
LastLoginAt: "last_login_at",
|
||||
LastLoginIp: "last_login_ip",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
DeletedAt: "deleted_at",
|
||||
},
|
||||
}
|
||||
|
||||
// NewUserDao 创建用户DAO实例
|
||||
func NewUserDao() *UserDao {
|
||||
return &userDao
|
||||
}
|
||||
|
||||
// Create 创建用户
|
||||
func (dao *UserDao) Create(ctx context.Context, data *entity.NlUser) (int64, error) {
|
||||
data.CreatedAt = int(gtime.Now().Unix())
|
||||
data.UpdatedAt = int(gtime.Now().Unix())
|
||||
|
||||
result, err := g.DB(dao.group).Model(dao.table).Data(data).Insert()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
id, err := result.LastInsertId()
|
||||
return id, err
|
||||
}
|
||||
|
||||
// GetById 根据ID获取用户
|
||||
func (dao *UserDao) GetById(ctx context.Context, id int) (*entity.NlUser, error) {
|
||||
var user *entity.NlUser
|
||||
err := g.DB(dao.group).Model(dao.table).
|
||||
Where(dao.columns.Id, id).
|
||||
Where(dao.columns.DeletedAt, 0).
|
||||
Scan(&user)
|
||||
return user, err
|
||||
}
|
||||
|
||||
// GetByUsername 根据用户名获取用户
|
||||
func (dao *UserDao) GetByUsername(ctx context.Context, username string) (*entity.NlUser, error) {
|
||||
var user *entity.NlUser
|
||||
err := g.DB(dao.group).Model(dao.table).
|
||||
Where(dao.columns.Username, username).
|
||||
Where(dao.columns.DeletedAt, 0).
|
||||
Scan(&user)
|
||||
return user, err
|
||||
}
|
||||
|
||||
// GetByPhone 根据手机号获取用户
|
||||
func (dao *UserDao) GetByPhone(ctx context.Context, phone string) (*entity.NlUser, error) {
|
||||
var user *entity.NlUser
|
||||
err := g.DB(dao.group).Model(dao.table).
|
||||
Where(dao.columns.Phone, phone).
|
||||
Where(dao.columns.DeletedAt, 0).
|
||||
Scan(&user)
|
||||
return user, err
|
||||
}
|
||||
|
||||
// GetByEmail 根据邮箱获取用户
|
||||
func (dao *UserDao) GetByEmail(ctx context.Context, email string) (*entity.NlUser, error) {
|
||||
var user *entity.NlUser
|
||||
err := g.DB(dao.group).Model(dao.table).
|
||||
Where(dao.columns.Email, email).
|
||||
Where(dao.columns.DeletedAt, 0).
|
||||
Scan(&user)
|
||||
return user, err
|
||||
}
|
||||
|
||||
// Update 更新用户
|
||||
func (dao *UserDao) Update(ctx context.Context, id int, data g.Map) error {
|
||||
data[dao.columns.UpdatedAt] = gtime.Now().Unix()
|
||||
|
||||
_, err := g.DB(dao.group).Model(dao.table).
|
||||
Where(dao.columns.Id, id).
|
||||
Where(dao.columns.DeletedAt, 0).
|
||||
Data(data).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete 删除用户(软删除)
|
||||
func (dao *UserDao) Delete(ctx context.Context, id int) error {
|
||||
_, err := g.DB(dao.group).Model(dao.table).
|
||||
Where(dao.columns.Id, id).
|
||||
Data(g.Map{
|
||||
dao.columns.DeletedAt: gtime.Now().Unix(),
|
||||
dao.columns.UpdatedAt: gtime.Now().Unix(),
|
||||
}).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// GetList 获取用户列表
|
||||
func (dao *UserDao) GetList(ctx context.Context, req *UserListReq) ([]*entity.NlUser, int, error) {
|
||||
model := g.DB(dao.group).Model(dao.table).Where(dao.columns.DeletedAt, 0)
|
||||
|
||||
// 添加查询条件
|
||||
if req.Username != "" {
|
||||
model = model.WhereLike(dao.columns.Username, "%"+req.Username+"%")
|
||||
}
|
||||
if req.Phone != "" {
|
||||
model = model.WhereLike(dao.columns.Phone, "%"+req.Phone+"%")
|
||||
}
|
||||
if req.Email != "" {
|
||||
model = model.WhereLike(dao.columns.Email, "%"+req.Email+"%")
|
||||
}
|
||||
if req.Status >= 0 {
|
||||
model = model.Where(dao.columns.Status, req.Status)
|
||||
}
|
||||
if req.VipLevel > 0 {
|
||||
model = model.Where(dao.columns.VipLevel, req.VipLevel)
|
||||
}
|
||||
if req.Gender >= 0 {
|
||||
model = model.Where(dao.columns.Gender, req.Gender)
|
||||
}
|
||||
if req.StartTime != "" {
|
||||
model = model.WhereGTE(dao.columns.CreatedAt, gtime.NewFromStr(req.StartTime).Unix())
|
||||
}
|
||||
if req.EndTime != "" {
|
||||
model = model.WhereLTE(dao.columns.CreatedAt, gtime.NewFromStr(req.EndTime).Unix())
|
||||
}
|
||||
|
||||
// 获取总数
|
||||
total, err := model.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
var users []*entity.NlUser
|
||||
err = model.Page(req.Page, req.PageSize).
|
||||
OrderDesc(dao.columns.CreatedAt).
|
||||
Scan(&users)
|
||||
|
||||
return users, total, err
|
||||
}
|
||||
|
||||
// BatchUpdateStatus 批量更新用户状态
|
||||
func (dao *UserDao) BatchUpdateStatus(ctx context.Context, ids []int, status int) error {
|
||||
_, err := g.DB(dao.group).Model(dao.table).
|
||||
WhereIn(dao.columns.Id, ids).
|
||||
Where(dao.columns.DeletedAt, 0).
|
||||
Data(g.Map{
|
||||
dao.columns.Status: status,
|
||||
dao.columns.UpdatedAt: gtime.Now().Unix(),
|
||||
}).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// BatchDelete 批量删除用户
|
||||
func (dao *UserDao) BatchDelete(ctx context.Context, ids []int) error {
|
||||
_, err := g.DB(dao.group).Model(dao.table).
|
||||
WhereIn(dao.columns.Id, ids).
|
||||
Data(g.Map{
|
||||
dao.columns.DeletedAt: gtime.Now().Unix(),
|
||||
dao.columns.UpdatedAt: gtime.Now().Unix(),
|
||||
}).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// GetUserStats 获取用户统计信息
|
||||
func (dao *UserDao) GetUserStats(ctx context.Context) (g.Map, error) {
|
||||
// 总用户数
|
||||
totalUsers, err := g.DB(dao.group).Model(dao.table).
|
||||
Where(dao.columns.DeletedAt, 0).
|
||||
Count()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 活跃用户数
|
||||
activeUsers, err := g.DB(dao.group).Model(dao.table).
|
||||
Where(dao.columns.DeletedAt, 0).
|
||||
Where(dao.columns.Status, 1).
|
||||
Count()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// VIP用户数
|
||||
vipUsers, err := g.DB(dao.group).Model(dao.table).
|
||||
Where(dao.columns.DeletedAt, 0).
|
||||
Where(dao.columns.VipLevel+" > ?", 1).
|
||||
Count()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 今日新增用户
|
||||
todayStart := gtime.Now().StartOfDay().Unix()
|
||||
todayUsers, err := g.DB(dao.group).Model(dao.table).
|
||||
Where(dao.columns.DeletedAt, 0).
|
||||
WhereGTE(dao.columns.CreatedAt, todayStart).
|
||||
Count()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return g.Map{
|
||||
"total_users": totalUsers,
|
||||
"active_users": activeUsers,
|
||||
"vip_users": vipUsers,
|
||||
"today_users": todayUsers,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateLoginInfo 更新登录信息
|
||||
func (dao *UserDao) UpdateLoginInfo(ctx context.Context, id int, ip string) error {
|
||||
_, err := g.DB(dao.group).Model(dao.table).
|
||||
Where(dao.columns.Id, id).
|
||||
Data(g.Map{
|
||||
dao.columns.LastLoginAt: gtime.Now().Unix(),
|
||||
dao.columns.LastLoginIp: ip,
|
||||
dao.columns.UpdatedAt: gtime.Now().Unix(),
|
||||
}).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// GetVipUsers 获取VIP用户列表
|
||||
func (dao *UserDao) GetVipUsers(ctx context.Context, page, pageSize int) ([]*entity.NlUser, int, error) {
|
||||
model := g.DB(dao.group).Model(dao.table).
|
||||
Where(dao.columns.DeletedAt, 0).
|
||||
Where(dao.columns.VipLevel+" > ?", 1)
|
||||
|
||||
// 获取总数
|
||||
total, err := model.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
var users []*entity.NlUser
|
||||
err = model.Page(page, pageSize).
|
||||
OrderDesc(dao.columns.VipLevel).
|
||||
OrderDesc(dao.columns.VipExpireAt).
|
||||
Scan(&users)
|
||||
|
||||
return users, total, err
|
||||
}
|
||||
|
||||
// GetExpiredVipUsers 获取VIP即将过期的用户
|
||||
func (dao *UserDao) GetExpiredVipUsers(ctx context.Context, days int) ([]*entity.NlUser, error) {
|
||||
expireTime := gtime.Now().AddDate(0, 0, days).Unix()
|
||||
|
||||
var users []*entity.NlUser
|
||||
err := g.DB(dao.group).Model(dao.table).
|
||||
Where(dao.columns.DeletedAt, 0).
|
||||
Where(dao.columns.VipLevel+" > ?", 1).
|
||||
Where(dao.columns.VipExpireAt+" <= ?", expireTime).
|
||||
Where(dao.columns.VipExpireAt+" > ?", gtime.Now().Unix()).
|
||||
Scan(&users)
|
||||
|
||||
return users, err
|
||||
}
|
||||
|
||||
// SearchUsers 搜索用户
|
||||
func (dao *UserDao) SearchUsers(ctx context.Context, keyword string, page, pageSize int) ([]*entity.NlUser, int, error) {
|
||||
model := g.DB(dao.group).Model(dao.table).
|
||||
Where(dao.columns.DeletedAt, 0).
|
||||
Where(g.Map{
|
||||
dao.columns.Username + " LIKE ? OR " + dao.columns.Phone + " LIKE ? OR " + dao.columns.Email + " LIKE ?": []interface{}{
|
||||
"%" + keyword + "%",
|
||||
"%" + keyword + "%",
|
||||
"%" + keyword + "%",
|
||||
},
|
||||
})
|
||||
|
||||
// 获取总数
|
||||
total, err := model.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
var users []*entity.NlUser
|
||||
err = model.Page(page, pageSize).
|
||||
OrderDesc(dao.columns.CreatedAt).
|
||||
Scan(&users)
|
||||
|
||||
return users, total, err
|
||||
}
|
||||
76
internal/dao/user_collect.go
Normal file
76
internal/dao/user_collect.go
Normal file
@@ -0,0 +1,76 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// internalUserCollectDao is internal type for wrapping internal DAO implements.
|
||||
type internalUserCollectDao struct {
|
||||
table string // table is the underlying table name of the DAO.
|
||||
group string // group is the database configuration group name of current DAO.
|
||||
columns UserCollectColumns // columns contains all the column names of Table for convenient usage.
|
||||
}
|
||||
|
||||
// UserCollectColumns defines and stores column names for table nl_user_collect.
|
||||
type UserCollectColumns struct {
|
||||
Id string // 收藏ID
|
||||
UserId string // 用户ID
|
||||
MovieId string // 影片ID
|
||||
CreatedAt string // 创建时间
|
||||
UpdatedAt string // 更新时间
|
||||
}
|
||||
|
||||
// userCollectColumns holds the columns for table nl_user_collect.
|
||||
var userCollectColumns = UserCollectColumns{
|
||||
Id: "id",
|
||||
UserId: "user_id",
|
||||
MovieId: "movie_id",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
// NewUserCollectDao creates and returns a new DAO object for table data access.
|
||||
func NewUserCollectDao() *internalUserCollectDao {
|
||||
return &internalUserCollectDao{
|
||||
group: "default",
|
||||
table: "nl_user_collect",
|
||||
columns: userCollectColumns,
|
||||
}
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *internalUserCollectDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *internalUserCollectDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
// Columns returns the columns of current dao.
|
||||
func (dao *internalUserCollectDao) Columns() UserCollectColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *internalUserCollectDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *internalUserCollectDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
func (dao *internalUserCollectDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) error {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
82
internal/dao/user_log.go
Normal file
82
internal/dao/user_log.go
Normal file
@@ -0,0 +1,82 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// internalUserLogDao is internal type for wrapping internal DAO implements.
|
||||
type internalUserLogDao struct {
|
||||
table string // table is the underlying table name of the DAO.
|
||||
group string // group is the database configuration group name of current DAO.
|
||||
columns UserLogColumns // columns contains all the column names of Table for convenient usage.
|
||||
}
|
||||
|
||||
// UserLogColumns defines and stores column names for table nl_user_log.
|
||||
type UserLogColumns struct {
|
||||
Id string // 日志ID
|
||||
UserId string // 用户ID
|
||||
Action string // 操作动作
|
||||
Module string // 操作模块
|
||||
Content string // 操作内容
|
||||
Ip string // IP地址
|
||||
UserAgent string // 用户代理
|
||||
CreatedAt string // 创建时间
|
||||
}
|
||||
|
||||
// userLogColumns holds the columns for table nl_user_log.
|
||||
var userLogColumns = UserLogColumns{
|
||||
Id: "id",
|
||||
UserId: "user_id",
|
||||
Action: "action",
|
||||
Module: "module",
|
||||
Content: "content",
|
||||
Ip: "ip",
|
||||
UserAgent: "user_agent",
|
||||
CreatedAt: "created_at",
|
||||
}
|
||||
|
||||
// NewUserLogDao creates and returns a new DAO object for table data access.
|
||||
func NewUserLogDao() *internalUserLogDao {
|
||||
return &internalUserLogDao{
|
||||
group: "default",
|
||||
table: "nl_user_log",
|
||||
columns: userLogColumns,
|
||||
}
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *internalUserLogDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *internalUserLogDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
// Columns returns the columns of current dao.
|
||||
func (dao *internalUserLogDao) Columns() UserLogColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *internalUserLogDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *internalUserLogDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
func (dao *internalUserLogDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) error {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
86
internal/dao/user_watch_history.go
Normal file
86
internal/dao/user_watch_history.go
Normal file
@@ -0,0 +1,86 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// internalUserWatchHistoryDao is internal type for wrapping internal DAO implements.
|
||||
type internalUserWatchHistoryDao struct {
|
||||
table string // table is the underlying table name of the DAO.
|
||||
group string // group is the database configuration group name of current DAO.
|
||||
columns UserWatchHistoryColumns // columns contains all the column names of Table for convenient usage.
|
||||
}
|
||||
|
||||
// UserWatchHistoryColumns defines and stores column names for table nl_user_watch_history.
|
||||
type UserWatchHistoryColumns struct {
|
||||
Id string // 观看记录ID
|
||||
UserId string // 用户ID
|
||||
MovieId string // 影片ID
|
||||
EpisodeId string // 集数ID
|
||||
WatchTime string // 观看时长(秒)
|
||||
TotalTime string // 总时长(秒)
|
||||
Progress string // 观看进度百分比
|
||||
LastWatchTime string // 最后观看时间
|
||||
CreatedAt string // 创建时间
|
||||
UpdatedAt string // 更新时间
|
||||
}
|
||||
|
||||
// userWatchHistoryColumns holds the columns for table nl_user_watch_history.
|
||||
var userWatchHistoryColumns = UserWatchHistoryColumns{
|
||||
Id: "id",
|
||||
UserId: "user_id",
|
||||
MovieId: "movie_id",
|
||||
EpisodeId: "episode_id",
|
||||
WatchTime: "watch_time",
|
||||
TotalTime: "total_time",
|
||||
Progress: "progress",
|
||||
LastWatchTime: "last_watch_time",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
// NewUserWatchHistoryDao creates and returns a new DAO object for table data access.
|
||||
func NewUserWatchHistoryDao() *internalUserWatchHistoryDao {
|
||||
return &internalUserWatchHistoryDao{
|
||||
group: "default",
|
||||
table: "nl_user_watch_history",
|
||||
columns: userWatchHistoryColumns,
|
||||
}
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *internalUserWatchHistoryDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *internalUserWatchHistoryDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
// Columns returns the columns of current dao.
|
||||
func (dao *internalUserWatchHistoryDao) Columns() UserWatchHistoryColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *internalUserWatchHistoryDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *internalUserWatchHistoryDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
func (dao *internalUserWatchHistoryDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) error {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
88
internal/dao/vip_level.go
Normal file
88
internal/dao/vip_level.go
Normal file
@@ -0,0 +1,88 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// internalVipLevelDao is internal type for wrapping internal DAO implements.
|
||||
type internalVipLevelDao struct {
|
||||
table string // table is the underlying table name of the DAO.
|
||||
group string // group is the database configuration group name of current DAO.
|
||||
columns VipLevelColumns // columns contains all the column names of Table for convenient usage.
|
||||
}
|
||||
|
||||
// VipLevelColumns defines and stores column names for table nl_vip_level.
|
||||
type VipLevelColumns struct {
|
||||
Id string // VIP等级ID
|
||||
Name string // VIP等级名称
|
||||
Level string // 等级数值
|
||||
Price string // 价格
|
||||
Duration string // 有效期(天)
|
||||
Description string // 等级描述
|
||||
Privileges string // 特权说明(JSON格式)
|
||||
Status string // 状态:0禁用,1启用
|
||||
Sort string // 排序
|
||||
CreatedAt string // 创建时间
|
||||
UpdatedAt string // 更新时间
|
||||
}
|
||||
|
||||
// vipLevelColumns holds the columns for table nl_vip_level.
|
||||
var vipLevelColumns = VipLevelColumns{
|
||||
Id: "id",
|
||||
Name: "name",
|
||||
Level: "level",
|
||||
Price: "price",
|
||||
Duration: "duration",
|
||||
Description: "description",
|
||||
Privileges: "privileges",
|
||||
Status: "status",
|
||||
Sort: "sort",
|
||||
CreatedAt: "created_at",
|
||||
UpdatedAt: "updated_at",
|
||||
}
|
||||
|
||||
// NewVipLevelDao creates and returns a new DAO object for table data access.
|
||||
func NewVipLevelDao() *internalVipLevelDao {
|
||||
return &internalVipLevelDao{
|
||||
group: "default",
|
||||
table: "nl_vip_level",
|
||||
columns: vipLevelColumns,
|
||||
}
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *internalVipLevelDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *internalVipLevelDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
// Columns returns the columns of current dao.
|
||||
func (dao *internalVipLevelDao) Columns() VipLevelColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *internalVipLevelDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *internalVipLevelDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
func (dao *internalVipLevelDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) error {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
Reference in New Issue
Block a user