feat:完善信息
This commit is contained in:
@ -2,7 +2,6 @@ package controller
|
||||
|
||||
import (
|
||||
model3 "SciencesServer/app/api/manage/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/handle"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/config"
|
||||
@ -36,6 +35,7 @@ func (c *Account) Login(account, password, captchaKey, captchaValue, equipment,
|
||||
} else if !isExist {
|
||||
return nil, errors.New("该帐号信息不存在")
|
||||
}
|
||||
|
||||
if !mSysUser.ValidatePassword(password) {
|
||||
return nil, errors.New("密码错误")
|
||||
}
|
||||
@ -44,52 +44,12 @@ func (c *Account) Login(account, password, captchaKey, captchaValue, equipment,
|
||||
session.Name = mSysUser.Name
|
||||
session.Mobile = mSysUser.Mobile
|
||||
session.IsAdmin = mSysUser.IsAdminUser()
|
||||
// 非超级管理员
|
||||
if !session.IsAdmin {
|
||||
// 查询相应关系
|
||||
mSysUserTenant := model3.NewSysUserTenant()
|
||||
|
||||
if isExist, err = model2.FirstField(mSysUserTenant.SysUserTenant, []string{"id", "tenant_id", "identity", "status"},
|
||||
model2.NewWhere("uid", mSysUser.UUID)); err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("当前不属于任何租户,不可登录")
|
||||
}
|
||||
if mSysUserTenant.TenantID <= 0 {
|
||||
goto Complete
|
||||
}
|
||||
mSysTenant := model3.NewSysTenant()
|
||||
mSysTenant.ID = mSysUserTenant.TenantID
|
||||
|
||||
level := 0
|
||||
|
||||
for {
|
||||
if isExist, err = model2.FirstField(mSysTenant, []string{"id", "key", "parent_id", "deadline", "status"}); err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("租户信息不存在,不可登录")
|
||||
} else if mSysTenant.IsInvalid() {
|
||||
return nil, errors.New("租户协议已失效,不可登录")
|
||||
}
|
||||
if level <= 0 {
|
||||
session.TenantID = mSysTenant.ID
|
||||
//session.TenantKey = mSysTenant.Key
|
||||
}
|
||||
// 判断是否含有含有上级
|
||||
if mSysTenant.ParentID <= 0 {
|
||||
goto Complete
|
||||
}
|
||||
level++
|
||||
mSysTenant.ID = mSysTenant.ParentID
|
||||
}
|
||||
}
|
||||
Complete:
|
||||
uid := mSysUser.UUIDString()
|
||||
|
||||
session.Token = utils.JWTEncrypt(config.SettingInfo.TokenEffectTime, map[string]interface{}{config.TokenForUID: uid})
|
||||
|
||||
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, uid, session)
|
||||
|
||||
service.Publish(config.EventForAccountLoginProduce, session.TenantID, session.UID, equipment, ip)
|
||||
|
||||
return &AccountLoginResponse{Token: session.Token, EffectTime: config.SettingInfo.TokenEffectTime}, nil
|
||||
|
153
app/api/manage/controller/manage/examine.go
Normal file
153
app/api/manage/controller/manage/examine.go
Normal file
@ -0,0 +1,153 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/manage/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Examine struct {
|
||||
*service.Session
|
||||
local string
|
||||
}
|
||||
|
||||
type ExamineHandle func(session *service.Session, local string) *Examine
|
||||
|
||||
type ExamineManageInfo struct {
|
||||
IModel model2.IModel
|
||||
TenantID uint64 // 租户ID
|
||||
UID uint64 // 用户表UUID
|
||||
IdentityInfo model2.IUserIdentity
|
||||
}
|
||||
|
||||
// examineHandle 审核处理
|
||||
var examineHandle = map[int]func(uint64) (*ExamineManageInfo, error){
|
||||
config.TenantUserIdentityForCompany: examineCompany,
|
||||
config.TenantUserIdentityForExpert: examineExpert,
|
||||
}
|
||||
|
||||
func checkManage(IModel model2.IModel, id uint64) error {
|
||||
IModel.SetID(id)
|
||||
|
||||
if isExist, err := model2.First(IModel); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("数据信息不存在")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func examineCompany(id uint64) (*ExamineManageInfo, error) {
|
||||
mManageCompany := model.NewManageCompany()
|
||||
|
||||
err := checkManage(mManageCompany.ManageCompany, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if mManageCompany.Status != model2.ExamineStatusForOngoing {
|
||||
return nil, errors.New("当前入住信息已审核")
|
||||
}
|
||||
return &ExamineManageInfo{
|
||||
IModel: mManageCompany.ManageCompany, UID: mManageCompany.UID,
|
||||
IdentityInfo: &model2.UserIdentityForCompany{
|
||||
Industry: mManageCompany.Industry, Keyword: mManageCompany.Keyword,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func examineExpert(id uint64) (*ExamineManageInfo, error) {
|
||||
mManageExpert := model.NewManageExpert()
|
||||
|
||||
err := checkManage(mManageExpert.ManageExpert, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if mManageExpert.Status != model2.ExamineStatusForOngoing {
|
||||
return nil, errors.New("当前入住信息已审核")
|
||||
}
|
||||
return &ExamineManageInfo{
|
||||
IModel: mManageExpert.ManageExpert, UID: mManageExpert.UID,
|
||||
IdentityInfo: &model2.UserIdentityForExpert{
|
||||
Industry: mManageExpert.Industry, Keyword: mManageExpert.Keyword, Research: mManageExpert.Research,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Launch 发起审核
|
||||
func (c *Examine) Launch(id uint64, identity, status int) error {
|
||||
_status := model2.ExamineStatusKind(status)
|
||||
|
||||
if _status != model2.ExamineStatusForRefuse && _status != model2.ExamineStatusForAgree {
|
||||
return errors.New("未知的审核模式")
|
||||
}
|
||||
handle, has := examineHandle[identity]
|
||||
|
||||
if !has {
|
||||
return errors.New("未知的身份信息")
|
||||
}
|
||||
data, err := handle(id)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Updates(data.IModel, map[string]interface{}{
|
||||
"status": status, "updated_at": time.Now(),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
// 拒绝后,不执行以下数据
|
||||
if _status == model2.ExamineStatusForRefuse {
|
||||
return nil
|
||||
}
|
||||
mUserManage := model.NewUserManage()
|
||||
|
||||
isExist := true
|
||||
|
||||
if isExist, err = model2.FirstField(mUserManage.UserManage, []string{"id", "uid"}, model2.NewWhere("uid", data.UID),
|
||||
model2.NewWhere("identity", identity)); err != nil {
|
||||
return err
|
||||
}
|
||||
if !isExist {
|
||||
mUserManage.TenantID = data.TenantID
|
||||
mUserManage.UID = data.UID
|
||||
mUserManage.Identity = identity
|
||||
mUserManage.IdentityInfo = utils.AnyToJSON(data.IdentityInfo)
|
||||
} else {
|
||||
if err = model2.Updates(mUserManage.UserManage, map[string]interface{}{
|
||||
"identity_info": utils.AnyToJSON(data.IdentityInfo), "updated_at": time.Now(),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// 更新账户身份信息
|
||||
mUserInstance := model.NewUserInstance()
|
||||
|
||||
if _, err = model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "identity"},
|
||||
model2.NewWhere("uuid", data.UID)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = model2.Updates(mUserInstance.UserInstance, map[string]interface{}{
|
||||
"identity": mUserInstance.Identity | identity, "updated_at": time.Now(),
|
||||
}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func NewExamine() ExamineHandle {
|
||||
return func(session *service.Session, local string) *Examine {
|
||||
return &Examine{
|
||||
Session: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
19
app/api/manage/controller/manage/instance.go
Normal file
19
app/api/manage/controller/manage/instance.go
Normal file
@ -0,0 +1,19 @@
|
||||
package manage
|
||||
|
||||
import "SciencesServer/app/service"
|
||||
|
||||
type Instance struct {
|
||||
*service.Session
|
||||
local string
|
||||
}
|
||||
|
||||
type InstanceHandle func(session *service.Session, local string) *Instance
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *service.Session, local string) *Instance {
|
||||
return &Instance{
|
||||
Session: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user