mirror of
https://github.com/xinliangnote/go-gin-api.git
synced 2024-04-21 12:31:46 +00:00
- 将 middleware 命名为 interceptor - 将 deploy 命名为 deployments - 移除 pkg/errno - 使用 proposal 目录 - 优化代码
32 lines
865 B
Go
32 lines
865 B
Go
package admin
|
|
|
|
import (
|
|
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
|
"github.com/xinliangnote/go-gin-api/internal/pkg/password"
|
|
"github.com/xinliangnote/go-gin-api/internal/repository/mysql/admin"
|
|
)
|
|
|
|
type CreateAdminData struct {
|
|
Username string // 用户名
|
|
Nickname string // 昵称
|
|
Mobile string // 手机号
|
|
Password string // 密码
|
|
}
|
|
|
|
func (s *service) Create(ctx core.Context, adminData *CreateAdminData) (id int32, err error) {
|
|
model := admin.NewModel()
|
|
model.Username = adminData.Username
|
|
model.Password = password.GeneratePassword(adminData.Password)
|
|
model.Nickname = adminData.Nickname
|
|
model.Mobile = adminData.Mobile
|
|
model.CreatedUser = ctx.SessionUserInfo().UserName
|
|
model.IsUsed = 1
|
|
model.IsDeleted = -1
|
|
|
|
id, err = model.Create(s.db.GetDbW().WithContext(ctx.RequestContext()))
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return
|
|
}
|