排班管理、主播管理、直播账号管理
This commit is contained in:
120
dao/data/anchor_dao.go
Normal file
120
dao/data/anchor_dao.go
Normal file
@@ -0,0 +1,120 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"context"
|
||||
consts "erp/consts/public"
|
||||
dto "erp/model/dto/data"
|
||||
entity "erp/model/entity/data"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var Anchor = new(anchorDao)
|
||||
|
||||
type anchorDao struct{}
|
||||
|
||||
// Insert 插入主播
|
||||
func (d *anchorDao) Insert(ctx context.Context, req *dto.CreateAnchorReq) (id int64, err error) {
|
||||
var res *entity.Anchor
|
||||
if err = gconv.Struct(req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.AnchorTable).Data(&res).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// Update 更新主播
|
||||
func (d *anchorDao) Update(ctx context.Context, req *dto.UpdateAnchorReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.AnchorTable).Data(&req).OmitEmpty().Where(entity.AnchorCols.Id, req.Id).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// Delete 删除主播
|
||||
func (d *anchorDao) Delete(ctx context.Context, req *dto.DeleteAnchorReq) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.AnchorTable).Where(entity.AnchorCols.Id, req.Id).Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetOne 获取单个主播
|
||||
func (d *anchorDao) GetOne(ctx context.Context, req *dto.GetAnchorReq) (res *entity.Anchor, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.AnchorTable).Where(entity.AnchorCols.Id, req.Id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// Count 获取主播数量
|
||||
func (d *anchorDao) Count(ctx context.Context, req *dto.ListAnchorReq) (count int, err error) {
|
||||
return d.buildListFilter(ctx, req).Count()
|
||||
}
|
||||
|
||||
// List 获取主播列表
|
||||
func (d *anchorDao) List(ctx context.Context, req *dto.ListAnchorReq) (res []entity.Anchor, total int, err error) {
|
||||
model := d.buildListFilter(ctx, req)
|
||||
model.OrderDesc(entity.AnchorCols.CreatedAt)
|
||||
if req.Page != nil {
|
||||
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
r, total, err := model.AllAndCount(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *anchorDao) buildListFilter(ctx context.Context, req *dto.ListAnchorReq) *gdb.Model {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.AnchorTable).Model
|
||||
if !g.IsEmpty(req.Keyword) {
|
||||
model.WhereLike(entity.AnchorCols.Name, "%"+req.Keyword+"%").
|
||||
WhereOrLike(entity.AnchorCols.Phone, "%"+req.Keyword+"%").
|
||||
WhereOrLike(entity.AnchorCols.Code, "%"+req.Keyword+"%")
|
||||
}
|
||||
model.Where(entity.AnchorCols.Name, req.Name)
|
||||
model.Where(entity.AnchorCols.Phone, req.Phone)
|
||||
model.Where(entity.AnchorCols.Code, req.Code)
|
||||
if req.Status != nil {
|
||||
model.Where(entity.AnchorCols.Status, *req.Status)
|
||||
}
|
||||
model.OmitEmptyWhere()
|
||||
return model
|
||||
}
|
||||
|
||||
// UpdateStatus 更新主播状态
|
||||
func (d *anchorDao) UpdateStatus(ctx context.Context, id int64, status int) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.AnchorTable).
|
||||
Data(map[string]interface{}{"status": status}).
|
||||
Where(entity.AnchorCols.Id, id).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetByCode 根据工号获取主播
|
||||
func (d *anchorDao) GetByCode(ctx context.Context, code string) (res *entity.Anchor, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.AnchorTable).
|
||||
Where(entity.AnchorCols.Code, code).
|
||||
One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user