feat:完善项目信息
This commit is contained in:
@ -98,25 +98,25 @@ func (a *Tenant) MemberBind(c *gin.Context) {
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
Password string `json:"password" form:"password" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant.NewMember()(api.GetSession()(c).(*session.Admin)).Form((&api.IDStringForm{ID: form.TenantID}).Convert(),
|
||||
&tenant.MemberParams{Mobile: form.Mobile, Password: form.Password})
|
||||
APIResponse(err)(c)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Tenant) Menu(c *gin.Context) {
|
||||
form := &struct {
|
||||
TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := tenant.NewMenu()(getSession()(c).(*service.Session)).List(form.TenantID)
|
||||
APIResponse(err, data)(c)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Tenant) MenuBind(c *gin.Context) {
|
||||
@ -124,12 +124,12 @@ func (a *Tenant) MenuBind(c *gin.Context) {
|
||||
TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"`
|
||||
MenuIDs []uint64 `json:"menu_ids" form:"menu_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant.NewMenu()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.MenuIDs)
|
||||
APIResponse(err)(c)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (a *Tenant) AuthBind(c *gin.Context) {
|
||||
@ -137,10 +137,10 @@ func (a *Tenant) AuthBind(c *gin.Context) {
|
||||
TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"`
|
||||
AuthIDs []uint64 `json:"auth_ids" form:"auth_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := tenant.NewAuth()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.AuthIDs)
|
||||
APIResponse(err)(c)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
user2 "SciencesServer/app/api/admin/controller/user"
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -39,7 +40,7 @@ func (a *User) List(c *gin.Context) {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := user2.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Mobile, form.Status, form.Page, form.PageSize)
|
||||
data, err := user2.NewInstance()(getSession()(c).(*service.Session)).Index(form.Name, form.Mobile, form.Status, form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
@ -148,18 +149,18 @@ func (a *User) Edit(c *gin.Context) {
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *User) QuickPassword(c *gin.Context) {
|
||||
func (a *User) Password(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
api.IDStringForm
|
||||
Password string `json:"password" form:"password" binding:"required"`
|
||||
RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user2.NewInstance()(getSession()(c).(*service.Session)).Password(form.ID, form.Password, form.RepeatPwd)
|
||||
APIResponse(err)(c)
|
||||
err := user2.NewInstance()(getSession()(c).(*service.Session)).Password(form.Convert(), form.Password, form.RepeatPwd)
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -186,7 +187,7 @@ func (a *User) QuickPassword(c *gin.Context) {
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *User) EditPassword(c *gin.Context) {
|
||||
func (a *User) PasswordEdit(c *gin.Context) {
|
||||
form := &struct {
|
||||
OldPwd string `json:"original_pwd" form:"original_pwd" binding:"required"`
|
||||
Password string `json:"password" form:"password" binding:"required"`
|
||||
|
@ -68,7 +68,7 @@ func loginForSmsCaptcha(params *AccountLoginParams, tenantID uint64) (*model.Sys
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{
|
||||
"id", "tenant_id", "name", "mobile", "is_admin", "status",
|
||||
"id", "uuid", "tenant_id", "name", "mobile", "is_admin", "status",
|
||||
}, model2.NewWhere("tenant_id", tenantID), model2.NewWhere("mobile", params.Account))
|
||||
|
||||
if err != nil {
|
||||
@ -105,7 +105,7 @@ func (c *Account) Login(mode int, params *AccountLoginParams, equipment, ip stri
|
||||
_session.Token = utils.JWTEncrypt(config.SettingInfo.TokenEffectTime, map[string]interface{}{config.TokenForUID: _uid})
|
||||
|
||||
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccountAdmin, _uid, _session)
|
||||
service.Publish(config.EventForAccountLoginProduce, data.TenantID, _session.UID, equipment, ip)
|
||||
service.Publish(config.EventForAccountLoginProduce, data.TenantID, data.ID, equipment, ip)
|
||||
|
||||
return &AccountLoginResponse{Token: _session.Token, EffectTime: config.SettingInfo.TokenEffectTime}, nil
|
||||
}
|
||||
|
@ -2,16 +2,13 @@ package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
model3 "SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Instance struct{ *controller.Platform }
|
||||
@ -21,16 +18,18 @@ type InstanceHandle func(session *service.Session) *Instance
|
||||
type (
|
||||
// InstanceInfo 基本信息
|
||||
InstanceInfo struct {
|
||||
ID string `json:"id"`
|
||||
InstanceUserInfo
|
||||
Gender model2.GenderKind `json:"gender"`
|
||||
IsAdmin model2.SysUserAdministrator `json:"is_admin"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
// InstanceUserInfo 用户信息
|
||||
InstanceUserInfo struct {
|
||||
UID string `json:"uid"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Mobile string `json:"mobile"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
// InstanceUserInfo 用户信息
|
||||
InstanceUserInfo struct {
|
||||
*model3.SysUserTenantUser
|
||||
UID string `json:"uid"`
|
||||
}
|
||||
)
|
||||
|
||||
@ -43,45 +42,64 @@ type InstanceForm struct {
|
||||
}
|
||||
|
||||
// Info 用户信息
|
||||
func (c *Instance) Info() (*InstanceInfo, error) {
|
||||
mSysUser := model3.NewSysUser()
|
||||
func (c *Instance) Info() (*InstanceUserInfo, error) {
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
_, err := model2.FirstWhere(mSysUser.SysUser, model2.NewWhere("uuid", c.UID))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &InstanceInfo{
|
||||
UID: mSysUser.UUIDString(), Name: mSysUser.Name, Email: mSysUser.Email, Mobile: mSysUser.Mobile, Remark: mSysUser.Remark,
|
||||
return &InstanceUserInfo{
|
||||
UID: mSysUser.UUIDString(), Name: mSysUser.Name, Email: mSysUser.Email, Mobile: mSysUser.Mobile,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// List 列表信息
|
||||
func (c *Instance) List(name, mobile string, status, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
|
||||
where := []*model2.ModelWhere{model2.NewWhere("u_t.tenant_id", c.TenantID)}
|
||||
|
||||
// Index 列表信息
|
||||
func (c *Instance) Index(name, mobile string, status, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
where := []*model2.ModelWhereOrder{&model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}}
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("u.name", name))
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereLike("name", name),
|
||||
})
|
||||
}
|
||||
if mobile != "" {
|
||||
where = append(where, model2.NewWhereLike("u.mobile", mobile))
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhereLike("mobile", mobile),
|
||||
})
|
||||
}
|
||||
if status > 0 {
|
||||
where = append(where, model2.NewWhere("u_t.status", status))
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("status", status),
|
||||
})
|
||||
}
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
out := make([]*model2.SysUser, 0)
|
||||
|
||||
var count int64
|
||||
|
||||
out, err := mSysUserTenant.User(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
if err := model2.PagesFields(mSysUser.SysUser, out, []string{"id", "uid", "account", "name", "mobile", "gender",
|
||||
"is_admin", "created_at"}, page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*InstanceUserInfo, 0)
|
||||
list := make([]*InstanceInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &InstanceUserInfo{SysUserTenantUser: v, UID: utils.UintToString(v.UID)})
|
||||
list = append(list, &InstanceInfo{ID: v.GetEncodeID(),
|
||||
InstanceUserInfo: InstanceUserInfo{
|
||||
UID: v.UUIDString(),
|
||||
Name: v.Name,
|
||||
Email: v.Email,
|
||||
Mobile: v.Mobile,
|
||||
},
|
||||
Gender: v.Gender.Gender,
|
||||
IsAdmin: v.IsAdmin,
|
||||
CreatedAt: v.CreatedAt,
|
||||
})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
@ -89,20 +107,18 @@ func (c *Instance) List(name, mobile string, status, page, pageSize int) (*contr
|
||||
// Add 添加用户
|
||||
func (c *Instance) Add(params *InstanceForm) error {
|
||||
if utils.ValidateMobile(params.Mobile) {
|
||||
return errors.New("手机号码格式错误")
|
||||
return errors.New("操作错误,手机号码格式错误")
|
||||
}
|
||||
mSysUser := model3.NewSysUser()
|
||||
mSysUser := model.NewSysUser()
|
||||
// 查询登录账户或手机号码是否注册
|
||||
var count int64
|
||||
|
||||
err := model2.Count(mSysUser.SysUser, &count, model2.NewWhere("account", params.Account))
|
||||
err := model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile),
|
||||
model2.NewWhere("tenant_id", c.TenantID))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile)); err != nil {
|
||||
return err
|
||||
}
|
||||
mSysUser.Account = params.Account
|
||||
mSysUser.Name = params.Name
|
||||
mSysUser.Mobile = params.Mobile
|
||||
@ -110,136 +126,111 @@ func (c *Instance) Add(params *InstanceForm) error {
|
||||
mSysUser.Password = params.Password
|
||||
mSysUser.Remark = params.Remark
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Create(mSysUser.SysUser, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
mSysUserTenant.TenantID = c.TenantID
|
||||
mSysUserTenant.UID = mSysUser.UUID
|
||||
if len(params.Departments) > 0 {
|
||||
mSysUserTenant.Department = strings.Join(utils.ArrayStrings(params.Departments), ",")
|
||||
}
|
||||
if len(params.Roles) > 0 {
|
||||
mSysUserTenant.Role = strings.Join(utils.ArrayStrings(params.Roles), ",")
|
||||
}
|
||||
mSysUserTenant.Identity = model2.SysUserTenantIdentityForSystemUser
|
||||
|
||||
if err = model2.Create(mSysUserTenant.SysUserTenant, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return model2.Create(mSysUser.SysUser)
|
||||
}
|
||||
|
||||
// Edit 修改用户信息
|
||||
func (c *Instance) Edit(params *InstanceForm) error {
|
||||
if utils.ValidateMobile(params.Mobile) {
|
||||
return errors.New("手机号码格式错误")
|
||||
}
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
mSysUserTenant.ID = params.ID
|
||||
mSysUser := model.NewSysUser()
|
||||
mSysUser.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "tenant_id", "identity"})
|
||||
isExist, err := model2.First(mSysUser.SysUser)
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
} else if !isExist {
|
||||
return errors.New("用户信息不存在")
|
||||
} else if mSysUserTenant.TenantID != c.TenantID {
|
||||
return errors.New("不可修改他人用户信息")
|
||||
return errors.New("操作错误,用户信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mSysUser.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
// 查询用户信息
|
||||
mSysUser := model3.NewSysUser()
|
||||
|
||||
if isExist, err = model2.FirstWhere(mSysUser.SysUser, model2.NewWhere("uuid", mSysUserTenant.UID)); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("用户信息不存在")
|
||||
}
|
||||
if params.Mobile != mSysUser.Mobile {
|
||||
if mSysUser.Mobile != params.Mobile {
|
||||
if utils.ValidateMobile(params.Mobile) {
|
||||
return errors.New("操作错误,手机号码格式错误")
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err = model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile)); err != nil {
|
||||
return err
|
||||
if err = model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile),
|
||||
model2.NewWhere("tenant_id", c.TenantID)); err != nil {
|
||||
return nil
|
||||
} else if count > 0 {
|
||||
return errors.New("该手机号码已注册")
|
||||
return errors.New("操作错误,当前手机号码已注册")
|
||||
}
|
||||
mSysUser.Mobile = params.Mobile
|
||||
}
|
||||
now := time.Now()
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Updates(mSysUserTenant.SysUserTenant, map[string]interface{}{
|
||||
"department": strings.Join(utils.ArrayStrings(params.Departments), ","),
|
||||
"role": strings.Join(utils.ArrayStrings(params.Roles), ","),
|
||||
"updated_at": now,
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = model2.Updates(mSysUser.SysUser, map[string]interface{}{
|
||||
"name": params.Name, "mobile": params.Mobile, "gender": params.Gender, "remark": params.Remark, "updated_at": now,
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
mSysUser.Account = params.Account
|
||||
mSysUser.Name = params.Name
|
||||
mSysUser.Gender.Gender = model2.GenderKind(params.Gender)
|
||||
mSysUser.Remark = params.Remark
|
||||
|
||||
return model2.Updates(mSysUser.SysUser, mSysUser.SysUser)
|
||||
}
|
||||
|
||||
func (c *Instance) Password(id uint64, password, repeatPwd string) error {
|
||||
if password != repeatPwd {
|
||||
return errors.New("两次密码不一致")
|
||||
return errors.New("操作错误,两次密码输入不一致")
|
||||
}
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
mSysUserTenant.ID = id
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "tenant_id", "identity"})
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{"id", "uuid", "is_admin"})
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
} else if !isExist {
|
||||
return errors.New("用户信息不存在")
|
||||
} else if mSysUserTenant.TenantID != c.TenantID {
|
||||
return errors.New("不可修改他人用户密码")
|
||||
return errors.New("操作错误,用户信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mSysUser.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
mSysUser := model3.NewSysUser()
|
||||
mSysUser.Password = password
|
||||
mSysUser.Pass()
|
||||
|
||||
if err = model2.UpdatesWhere(mSysUser.SysUser, map[string]interface{}{
|
||||
return model2.Updates(mSysUser.SysUser, map[string]interface{}{
|
||||
"password": mSysUser.Password, "salt": mSysUser.Salt, "updated_at": time.Now(),
|
||||
}, []*model2.ModelWhere{
|
||||
model2.NewWhere("uuid", mSysUserTenant.UID),
|
||||
}); err != nil {
|
||||
})
|
||||
}
|
||||
|
||||
// PasswordEdit 主动修改密码
|
||||
func (c *Person) PasswordEdit(oldPassword, password, repeatPwd string) error {
|
||||
if password != repeatPwd {
|
||||
return errors.New("操作错误,两次密码输入不一致")
|
||||
}
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
_, err := model2.FirstField(mSysUser.SysUser, []string{"id", "uuid", "is_admin"}, model2.NewWhere("uuid", c.UID))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
if !mSysUser.ValidatePassword(oldPassword) {
|
||||
return errors.New("操作错误,旧密码输入错误")
|
||||
}
|
||||
mSysUser.Password = password
|
||||
mSysUser.Pass()
|
||||
|
||||
return model2.Updates(mSysUser.SysUser, map[string]interface{}{
|
||||
"password": mSysUser.Password, "salt": mSysUser.Salt, "updated_at": time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Instance) Delete(id uint64) error {
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
mSysUserTenant.ID = id
|
||||
mSysUser := model.NewSysUser()
|
||||
mSysUser.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "tenant_id", "identity"})
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{"id", "uuid", "is_admin"})
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
} else if !isExist {
|
||||
return errors.New("用户信息不存在")
|
||||
} else if mSysUserTenant.TenantID != c.TenantID {
|
||||
return errors.New("不可删除他人用户信息")
|
||||
return errors.New("操作错误,用户信息不存在或已被删除")
|
||||
} else if c.TenantID > 0 && mSysUser.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
} else if mSysUser.IsAdminUser() {
|
||||
return errors.New("操作错误,超管用户不允许删除")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Delete(mSysUserTenant.SysUserTenant, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mSysUser := model3.NewSysUser()
|
||||
|
||||
if err = model2.DeleteWhere(mSysUser.SysUser, []*model2.ModelWhere{
|
||||
model2.NewWhere("uuid", mSysUserTenant.UID),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err = model2.Delete(mSysUser.SysUser); err != nil {
|
||||
return err
|
||||
}
|
||||
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccountAdmin, utils.UintToString(mSysUser.UUID))
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
|
@ -3,8 +3,7 @@ package user
|
||||
import (
|
||||
"SciencesServer/app/api/admin/controller"
|
||||
menu2 "SciencesServer/app/api/admin/controller/menu"
|
||||
model3 "SciencesServer/app/api/admin/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/service"
|
||||
)
|
||||
|
||||
@ -14,23 +13,24 @@ type MenuHandle func(session *service.Session) *Menu
|
||||
|
||||
// List 菜单列表
|
||||
func (c *Menu) List() (interface{}, error) {
|
||||
mSysMenu := model3.NewSysMenu()
|
||||
mSysMenu := model.NewSysMenu()
|
||||
|
||||
if c.IsAdmin {
|
||||
return menu2.MenuForSystem(mSysMenu)
|
||||
}
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
|
||||
if isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "identity"},
|
||||
model2.NewWhere("tenant_id", c.TenantID), model2.NewWhere("uid", c.UID)); err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, nil
|
||||
}
|
||||
if mSysUserTenant.Identity == model2.SysUserTenantIdentityForSystemAdmin {
|
||||
return menu2.MenuForTenant(mSysMenu, c.TenantID)
|
||||
}
|
||||
return menu2.MenuForUser(mSysMenu, c.TenantID, c.UID)
|
||||
//mSysUserTenant := model.NewSysUserTenant()
|
||||
//
|
||||
//if isExist, err := model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "identity"},
|
||||
// model2.NewWhere("tenant_id", c.TenantID), model2.NewWhere("uid", c.UID)); err != nil {
|
||||
// return nil, err
|
||||
//} else if !isExist {
|
||||
// return nil, nil
|
||||
//}
|
||||
//if mSysUserTenant.Identity == model2.SysUserTenantIdentityForSystemAdmin {
|
||||
// return menu2.MenuForTenant(mSysMenu, c.TenantID)
|
||||
//}
|
||||
//return menu2.MenuForUser(mSysMenu, c.TenantID, c.UID)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func NewMenu() MenuHandle {
|
||||
|
@ -24,7 +24,7 @@ func (m *SysUser) IsAdminUser() bool {
|
||||
|
||||
func (m *SysUser) GetByAccountOrMobile(account string, tenantID uint64) (bool, error) {
|
||||
db := orm.GetDB().Table(m.TableName()).
|
||||
Select("id", "tenant_id", "name", "mobile", "password", "salt", "is_admin", "status").
|
||||
Select("id", "uuid", "tenant_id", "name", "mobile", "password", "salt", "is_admin", "status").
|
||||
Where("tenant_id = ?", tenantID).
|
||||
Where("(account = ? OR mobile = ?)", account, account).
|
||||
Where("is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
@ -1,83 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysUserTenant struct {
|
||||
*model.SysUserTenant
|
||||
}
|
||||
|
||||
type (
|
||||
// SysUserTenantBasic 基本信息
|
||||
SysUserTenantBasic struct {
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Mobile string `json:"mobile"`
|
||||
Status model.AccountStatus `json:"status"`
|
||||
}
|
||||
// SysUserTenantUser 用户信息
|
||||
SysUserTenantUser struct {
|
||||
*SysUserTenantBasic
|
||||
UID uint64 `json:"uid"`
|
||||
Email string `json:"email"`
|
||||
Identity model.SysUserTenantIdentity `json:"identity"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
)
|
||||
|
||||
// Member 成员信息
|
||||
func (m *SysUserTenant) Member(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysUserTenantBasic, error) {
|
||||
mSysUser := NewSysUser()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS u_t").
|
||||
Select("u_t.id, u.name, u.mobile, u_t.status").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON u_t.uid = u.uuid", mSysUser.TableName())).
|
||||
Where("u_t.is_deleted = ? AND u.is_deleted = ?", model.DeleteStatusForNot, model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*SysUserTenantBasic, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("u_t.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// User 用户信息
|
||||
func (m *SysUserTenant) User(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysUserTenantUser, error) {
|
||||
mSysUser := NewSysUser()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS u_t").
|
||||
Select("u_t.id, u_t.uid, u.name, u.mobile, u.email, u_t.identity, u_t.status, u.remark, u_t.created_at").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u ON u_t.uid = u.uuid", mSysUser.TableName())).
|
||||
Where("u_t.is_deleted = ? AND u.is_deleted = ?", model.DeleteStatusForNot, model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, wo := range where {
|
||||
db = db.Where(wo.Condition, wo.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*SysUserTenantUser, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("u_t.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewSysUserTenant() *SysUserTenant {
|
||||
return &SysUserTenant{SysUserTenant: model.NewSysUserTenant()}
|
||||
}
|
Reference in New Issue
Block a user