This commit is contained in:
2025-07-07 20:11:59 +08:00
parent ab0fdbc447
commit 06e3aa2eb3
2009 changed files with 193082 additions and 0 deletions

View File

@ -0,0 +1,129 @@
// ==========================================================================
// GFast自动生成logic操作代码。
// 生成日期2024-07-26 15:32:12
// 生成路径: internal/app/system/logic/user_registration.go
// 生成人gfast
// desc:极光推送
// company:云南奇讯科技有限公司
// ==========================================================================
package logic
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
"github.com/tiger1103/gfast/v3/internal/app/system/model"
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
"github.com/tiger1103/gfast/v3/internal/app/system/service"
"github.com/tiger1103/gfast/v3/library/liberr"
)
func init() {
service.RegisterUserRegistration(New())
}
func New() *sUserRegistration {
return &sUserRegistration{}
}
type sUserRegistration struct{}
func (s *sUserRegistration) List(ctx context.Context, req *system.UserRegistrationSearchReq) (listRes *system.UserRegistrationSearchRes, err error) {
listRes = new(system.UserRegistrationSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.UserRegistration.Ctx(ctx).WithAll()
if req.Id != "" {
m = m.Where(dao.UserRegistration.Columns().Id+" = ?", req.Id)
}
if req.UserId != "" {
m = m.Where(dao.UserRegistration.Columns().UserId+" = ?", gconv.Int(req.UserId))
}
if req.OpenId != "" {
m = m.Where(dao.UserRegistration.Columns().OpenId+" = ?", req.OpenId)
}
if req.RegistrationId != "" {
m = m.Where(dao.UserRegistration.Columns().RegistrationId+" = ?", req.RegistrationId)
}
if len(req.DateRange) != 0 {
m = m.Where(dao.UserRegistration.Columns().CreatedAt+" >=? AND "+dao.UserRegistration.Columns().CreatedAt+" <=?", req.DateRange[0], req.DateRange[1])
}
listRes.Total, err = m.Count()
liberr.ErrIsNil(ctx, err, "获取总行数失败")
if req.PageNum == 0 {
req.PageNum = 1
}
listRes.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = consts.PageSize
}
order := "id asc"
if req.OrderBy != "" {
order = req.OrderBy
}
var res []*model.UserRegistrationInfoRes
err = m.Fields(system.UserRegistrationSearchRes{}).Page(req.PageNum, req.PageSize).Order(order).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取数据失败")
listRes.List = make([]*model.UserRegistrationListRes, len(res))
for k, v := range res {
listRes.List[k] = &model.UserRegistrationListRes{
Id: v.Id,
UserId: v.UserId,
OpenId: v.OpenId,
RegistrationId: v.RegistrationId,
CreatedAt: v.CreatedAt,
}
}
})
return
}
func (s *sUserRegistration) GetById(ctx context.Context, id uint) (res *model.UserRegistrationInfoRes, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.UserRegistration.Ctx(ctx).WithAll().Where(dao.UserRegistration.Columns().Id, id).Scan(&res)
liberr.ErrIsNil(ctx, err, "获取信息失败")
})
return
}
func (s *sUserRegistration) Add(ctx context.Context, req *system.UserRegistrationAddReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.UserRegistration.Ctx(ctx).Insert(do.UserRegistration{
UserId: req.UserId,
OpenId: req.OpenId,
RegistrationId: req.RegistrationId,
})
liberr.ErrIsNil(ctx, err, "添加失败")
})
return
}
func (s *sUserRegistration) Edit(ctx context.Context, req *system.UserRegistrationEditReq) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.UserRegistration.Ctx(ctx).WherePri(req.Id).Update(do.UserRegistration{
UserId: req.UserId,
OpenId: req.OpenId,
RegistrationId: req.RegistrationId,
})
liberr.ErrIsNil(ctx, err, "修改失败")
})
return
}
func (s *sUserRegistration) Delete(ctx context.Context, ids []uint) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.UserRegistration.Ctx(ctx).Delete(dao.UserRegistration.Columns().Id+" in (?)", ids)
liberr.ErrIsNil(ctx, err, "删除失败")
})
return
}
// IsBind 判断用户是否绑定过
func (s *sUserRegistration) IsBind(ctx context.Context, userID int) bool {
count, _ := dao.UserRegistration.Ctx(ctx).Where(dao.UserRegistration.Columns().UserId, userID).Count()
return count > 0
}