feat:完善信息
This commit is contained in:
@ -9,7 +9,6 @@ import (
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
@ -25,7 +24,6 @@ type (
|
||||
// InstanceInfo 租户信息
|
||||
InstanceInfo struct {
|
||||
*model.SysTenantInfo
|
||||
Config *model2.SysTenantConfig `json:"config"`
|
||||
}
|
||||
// InstanceParams 租户参数信息
|
||||
InstanceParams struct {
|
||||
@ -72,7 +70,7 @@ func basic(id uint64) func(args ...interface{}) (interface{}, error) {
|
||||
}
|
||||
return &InstanceInfo{SysTenantInfo: &model.SysTenantInfo{
|
||||
SysTenant: mSysTenant.SysTenant,
|
||||
}, Config: mSysTenant.ConfigInfo()}, nil
|
||||
}}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,7 +163,7 @@ func (c *Instance) List(name string, status, page, pageSize int) (*controller.Re
|
||||
for _, v := range out {
|
||||
v.Image.Image = v.Image.Analysis(config.SettingInfo.Domain)
|
||||
|
||||
list = append(list, &InstanceInfo{SysTenantInfo: v, Config: v.ConfigInfo()})
|
||||
list = append(list, &InstanceInfo{SysTenantInfo: v})
|
||||
}
|
||||
return &controller.ReturnPages{Data: list, Page: page, TotalCount: count}, nil
|
||||
}
|
||||
@ -194,8 +192,6 @@ func (c *Instance) Add(params *InstanceParams) error {
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mSysTenant.Image.Image = params.Image
|
||||
mSysTenant.Name = params.Name
|
||||
mSysTenant.Config = utils.AnyToJSON(&model2.SysTenantConfig{MaxDevices: 0, MaxCustomer: 0, Protocol: 0})
|
||||
mSysTenant.Deadline = utils.DateTimeToTime(params.Deadline + " 23:59:59")
|
||||
mSysTenant.Remark = params.Remark
|
||||
|
||||
if err = model2.Create(mSysTenant.SysTenant, tx); err != nil {
|
||||
@ -220,7 +216,6 @@ func (c *Instance) Add(params *InstanceParams) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
service.Publish(config.EventForRedisListProduce, config.RedisKeyForTenant, mSysTenant.Key)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -338,20 +333,9 @@ func (c *Instance) Renewal(id uint64, deadline string) error {
|
||||
updates := make(map[string]interface{}, 0)
|
||||
updates["updated_at"] = now
|
||||
|
||||
_deadline := utils.DateTimeToTime(deadline + " 23:59:59")
|
||||
|
||||
if _deadline.Before(mSysTenant.Deadline) {
|
||||
return errors.New("续期时间异常")
|
||||
}
|
||||
updates["deadline"] = _deadline
|
||||
|
||||
if mSysTenant.Status != model2.SysTenantStatusForNormal && _deadline.After(now) {
|
||||
updates["status"] = model2.SysTenantStatusForNormal
|
||||
}
|
||||
if err = model2.Updates(mSysTenant.SysTenant, updates); err != nil {
|
||||
return err
|
||||
}
|
||||
service.Publish(config.EventForRedisListProduce, config.RedisKeyForTenant, mSysTenant.Key)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -372,19 +356,8 @@ func (c *Instance) StartUp(id uint64) error {
|
||||
} else if c.TenantID != mSysTenant.ParentID {
|
||||
return errors.New("不可启用其他租户/公司客户")
|
||||
}
|
||||
} else if mSysTenant.Status == model2.SysTenantStatusForNormal {
|
||||
return errors.New("该租户/公司/客户已是启用状态")
|
||||
}
|
||||
status := model2.SysTenantStatusForNormal
|
||||
|
||||
now := time.Now()
|
||||
|
||||
if mSysTenant.Deadline.Before(now) {
|
||||
status = model2.SysTenantStatusForExpired
|
||||
}
|
||||
if err = model2.Updates(mSysTenant.SysTenant, map[string]interface{}{
|
||||
"status": status, "updated_at": now,
|
||||
}); err != nil {
|
||||
if err = model2.Updates(mSysTenant.SysTenant, map[string]interface{}{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -392,31 +365,31 @@ func (c *Instance) StartUp(id uint64) error {
|
||||
|
||||
// Disable 禁用处理
|
||||
func (c *Instance) Disable(id uint64) error {
|
||||
mSysTenant := model.NewSysTenant()
|
||||
mSysTenant.ID = id
|
||||
//mSysTenant := model.NewSysTenant()
|
||||
//mSysTenant.ID = id
|
||||
//
|
||||
//isExist, err := model2.FirstWhere(mSysTenant.SysTenant)
|
||||
|
||||
isExist, err := model2.FirstWhere(mSysTenant.SysTenant)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("租户/公司/客户信息不存在")
|
||||
} else if c.TenantID > 0 {
|
||||
if mSysTenant.ParentID <= 0 {
|
||||
return errors.New("非超级管理员,不可操作")
|
||||
} else if c.TenantID != mSysTenant.ParentID {
|
||||
return errors.New("不可启用其他租户/公司/客户")
|
||||
}
|
||||
} else if mSysTenant.Status == model2.SysTenantStatusForDisable {
|
||||
return errors.New("该租户/公司/客户已是禁用状态")
|
||||
}
|
||||
if err = model2.Updates(mSysTenant.SysTenant, map[string]interface{}{
|
||||
"status": model2.SysTenantStatusForDisable, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO:推送用户强制退出,并强行删除所有产品数据
|
||||
service.Publish(config.EventForRedisListDestroy, config.RedisKeyForTenant, mSysTenant.Key)
|
||||
//if err != nil {
|
||||
// return err
|
||||
//} else if !isExist {
|
||||
// return errors.New("租户/公司/客户信息不存在")
|
||||
//} else if c.TenantID > 0 {
|
||||
// if mSysTenant.ParentID <= 0 {
|
||||
// return errors.New("非超级管理员,不可操作")
|
||||
// } else if c.TenantID != mSysTenant.ParentID {
|
||||
// return errors.New("不可启用其他租户/公司/客户")
|
||||
// }
|
||||
//} else if mSysTenant.Status == model2.SysTenantStatusForDisable {
|
||||
// return errors.New("该租户/公司/客户已是禁用状态")
|
||||
//}
|
||||
//if err = model2.Updates(mSysTenant.SysTenant, map[string]interface{}{
|
||||
// "status": model2.SysTenantStatusForDisable, "updated_at": time.Now(),
|
||||
//}); err != nil {
|
||||
// return err
|
||||
//}
|
||||
//// TODO:推送用户强制退出,并强行删除所有产品数据
|
||||
//service.Publish(config.EventForRedisListDestroy, config.RedisKeyForTenant, mSysTenant.Key)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SysTenant struct {
|
||||
@ -38,7 +37,7 @@ type (
|
||||
|
||||
// IsInvalid 判断是否有效
|
||||
func (m *SysTenant) IsInvalid() bool {
|
||||
return m.Status == model.SysTenantStatusForDisable || m.Status == model.SysTenantStatusForExpired || m.Deadline.Before(time.Now())
|
||||
return false
|
||||
}
|
||||
|
||||
// Tenants 租户信息
|
||||
|
@ -14,7 +14,7 @@ const (
|
||||
|
||||
// TenantUserIdentityData 用户身份信息
|
||||
var TenantUserIdentityData = map[int]string{
|
||||
TenantUserIdentityForPerson: "个人",
|
||||
TenantUserIdentityForPerson: "游客",
|
||||
TenantUserIdentityForCompany: "企业", TenantUserIdentityForExpert: "专家",
|
||||
TenantUserIdentityForResearch: "研究机构", TenantUserIdentityForLaboratory: "实验室",
|
||||
TenantUserIdentityForAgent: "科技经纪人",
|
||||
|
1
app/basic/controller/upload.go
Normal file
1
app/basic/controller/upload.go
Normal file
@ -0,0 +1 @@
|
||||
package controller
|
12
app/common/model/sys_industry.go
Normal file
12
app/common/model/sys_industry.go
Normal file
@ -0,0 +1,12 @@
|
||||
package model
|
||||
|
||||
type SysIndustry struct {
|
||||
}
|
||||
|
||||
func (*SysIndustry) TableName() string {
|
||||
return "sys_industry"
|
||||
}
|
||||
|
||||
func NewSysIndustry() *SysIndustry {
|
||||
return &SysIndustry{}
|
||||
}
|
@ -1,69 +1,25 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/utils"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type SysTenant struct {
|
||||
Model
|
||||
ParentID uint64 `gorm:"column:parent_id;type:int;default:0;comment:父级ID" json:"-"`
|
||||
Key string `gorm:"column:key;type:varchar(100);default:null;comment:租户/租户客户标识" json:"key"`
|
||||
Image
|
||||
Name string `gorm:"column:name;type:varchar(30);default:null;comment:租户名称/租户客户名称" json:"name"`
|
||||
Config string `gorm:"column:config;type:text;comment:租户/租户客户配置信息" json:"-"`
|
||||
Deadline time.Time `gorm:"column:deadline;type:datetime;default:null;comment:租户/租户客户协议截止时间" json:"deadline"`
|
||||
Status SysTenantStatus `gorm:"column:status;type:tinyint(1);default:1;comment:租户/租户客户状态" json:"status"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:null;comment:租户/租户客户备注" json:"remark"`
|
||||
Name string `gorm:"column:name;type:varchar(30);default:null;comment:名称" json:"name"`
|
||||
Code string `gorm:"column:code;type:varchar(30);default:null;comment:信用代码" json:"code"`
|
||||
Images
|
||||
Area
|
||||
Position string `gorm:"column:position;type:varchar(255);default:null;comment:坐标" json:"-"`
|
||||
Industry uint64 `gorm:"column:industry;type:int(11);default:0;comment:所属领域" json:"industry"`
|
||||
Introduce string `gorm:"column:introduce;type:text;comment:介绍描述" json:"introduce"`
|
||||
Config string `gorm:"column:config;type:varchar(255);default:null;comment:配置信息" json:"-"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
type SysTenantConfig struct {
|
||||
MaxDevices int `json:"max_devices"` // 最大可连接设备数
|
||||
MaxCustomer int `json:"max_customer"` // 最大可拥有的客户数
|
||||
Protocol uint `json:"protocol"` // 支持的协议模式
|
||||
}
|
||||
|
||||
type SysTenantStatus int
|
||||
|
||||
const (
|
||||
// SysTenantStatusForNormal 正常
|
||||
SysTenantStatusForNormal SysTenantStatus = iota + 1
|
||||
// SysTenantStatusForWellExpire 协议将到期
|
||||
SysTenantStatusForWellExpire
|
||||
// SysTenantStatusForExpired 协议已过期
|
||||
SysTenantStatusForExpired
|
||||
// SysTenantStatusForDisable 已禁用
|
||||
SysTenantStatusForDisable
|
||||
)
|
||||
|
||||
func (m *SysTenant) TableName() string {
|
||||
return "sys_tenant"
|
||||
}
|
||||
|
||||
func (m *SysTenant) BeforeCreate(db *gorm.DB) error {
|
||||
snowflake, _ := utils.NewSnowflake(1)
|
||||
m.Key = utils.IntToString(snowflake.GetID())
|
||||
m.CreatedAt = time.Now()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *SysTenant) ConfigInfo() *SysTenantConfig {
|
||||
config := new(SysTenantConfig)
|
||||
_ = utils.FromJSON(m.Config, config)
|
||||
return config
|
||||
}
|
||||
|
||||
func (m *SysTenant) StatusTitle() string {
|
||||
if m.Status == SysTenantStatusForDisable {
|
||||
return "禁用"
|
||||
}
|
||||
return "正常"
|
||||
}
|
||||
|
||||
func NewSysTenant() *SysTenant {
|
||||
return &SysTenant{}
|
||||
}
|
||||
|
@ -3,12 +3,12 @@ package model
|
||||
type UserTenant struct {
|
||||
Model
|
||||
ModelTenant
|
||||
UID uint64 `gorm:"column:uid;index:idx_tenant_user_uuid;type:int;default:0;comment:用户表UUID" json:"-"`
|
||||
Avatar string `gorm:"column:avatar;type:varchar(255);default:null;comment:头像" json:"avatar"`
|
||||
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
|
||||
Email string `gorm:"column:email;type:varchar(50);default:null;comment:邮箱" json:"email"`
|
||||
Identity int `gorm:"column:identity;type:tinyint(3);default:0;comment:身份信息" json:"-"`
|
||||
Area
|
||||
UID uint64 `gorm:"column:uid;index:idx_tenant_user_uuid;type:int;default:0;comment:用户表UUID" json:"-"`
|
||||
Avatar string `gorm:"column:avatar;type:varchar(255);default:null;comment:头像" json:"avatar"`
|
||||
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
|
||||
Email string `gorm:"column:email;type:varchar(50);default:null;comment:邮箱" json:"email"`
|
||||
Identity int `gorm:"column:identity;type:tinyint(3);default:0;comment:身份信息" json:"-"`
|
||||
Address string `gorm:"column:address;type:varchar(255);default:null;comment:详细地址" json:"address"`
|
||||
Selected UserTenantSelected `gorm:"column:selected;type:tinyint(1);default:0;comment:最后一次选中的身份状态,用于下次登陆展示" json:"-"`
|
||||
Other string `gorm:"column:other;type:varchar(255);default:null;comment:其他信息" json:"-"`
|
||||
Status UserTenantStatus `gorm:"column:status;type:tinyint(0);default:0;comment:状态" json:"-"`
|
||||
@ -28,12 +28,10 @@ const (
|
||||
type UserTenantStatus int
|
||||
|
||||
const (
|
||||
// UserTenantStatusForInit 初始化
|
||||
UserTenantStatusForInit UserTenantStatus = iota
|
||||
// UserTenantStatusForExamineRefuse 审核拒绝
|
||||
UserTenantStatusForExamineRefuse UserTenantStatus = iota
|
||||
// UserTenantStatusForExamining 审核中
|
||||
UserTenantStatusForExamining
|
||||
// UserTenantStatusForExamineRefuse 审核拒绝
|
||||
UserTenantStatusForExamineRefuse
|
||||
// UserTenantStatusForExaminePass 审核通过
|
||||
UserTenantStatusForExaminePass
|
||||
)
|
||||
|
@ -12,3 +12,7 @@ func (a *Config) Identity(c *gin.Context) {
|
||||
data := controller.NewConfig().Identity()
|
||||
api.APISuccess(data)
|
||||
}
|
||||
|
||||
func (a *Config) Industry(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,41 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/basic/api"
|
||||
"SciencesServer/app/enterprise/controller/user"
|
||||
"SciencesServer/app/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type User struct{}
|
||||
|
||||
func (a *User) Info(c *gin.Context) {
|
||||
data := user.NewInstance()(api.GetSession()(c).(*service.SessionEnterprise)).Info()
|
||||
api.APISuccess(data)
|
||||
}
|
||||
|
||||
func (a *User) Perfect(c *gin.Context) {
|
||||
form := &struct {
|
||||
Avatar string `json:"avatar" form:"avatar" binding:"required"` // 头像
|
||||
Name string `json:"name" form:"name" binding:"required"` // 名称
|
||||
Email string `json:"email" form:"email" binding:"required"` // 邮箱
|
||||
Job string `json:"job" form:"job" binding:"required"` // 职务
|
||||
Address string `json:"address" form:"address" ` // 地址
|
||||
Company user.TenantParamsForCompany `json:"company" form:"company"` // 公司属性
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewTenant()(api.GetSession()(c).(*service.SessionEnterprise)).Perfect(&user.TenantPerfectParams{
|
||||
TenantBasicParams: &user.TenantBasicParams{
|
||||
Avatar: form.Avatar, Name: form.Name, Email: form.Email, Job: form.Job, Address: form.Address,
|
||||
},
|
||||
TenantParamsForCompany: &form.Company,
|
||||
})
|
||||
api.APIResponse(err)
|
||||
}
|
||||
|
||||
func (a *User) SwitchIdentity(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ func (c *Instance) Login() InstanceLoginCallback {
|
||||
session.Identity = params.Identity
|
||||
session.SelectIdentity = params.SelectIdentity
|
||||
|
||||
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, utils.UintToString(params.UID), session)
|
||||
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, session.UIDToString(), session)
|
||||
|
||||
return &InstanceLoginReturn{Token: token, EffectTime: config.SettingInfo.TokenEffectTime}
|
||||
}
|
||||
|
@ -1,115 +1,26 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/enterprise/model"
|
||||
"SciencesServer/app/service"
|
||||
config2 "SciencesServer/config"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Instance struct{ *service.SessionEnterprise }
|
||||
|
||||
type InstanceHandle func(enterprise *service.SessionEnterprise) *Instance
|
||||
|
||||
type InstanceBasic struct {
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
Name string `json:"name"` // 名称
|
||||
Email string `json:"email"` // 邮箱
|
||||
}
|
||||
|
||||
type (
|
||||
// InstancePerfectParams 完善信息参数
|
||||
InstancePerfectParams struct {
|
||||
*InstanceBasic
|
||||
*config.Area
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
// InstanceInfoReturn 基本信息返回
|
||||
InstanceInfoReturn struct {
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
Identity string `json:"identity"`
|
||||
SelectIdentity string `json:"select_identity"` // 最后一次选中的身份信息
|
||||
Name string `json:"name"` // 名称
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
Identity int `json:"identity"` // 具体身份
|
||||
SelectIdentity int `json:"select_identity"` // 最后一次选中的身份信息
|
||||
}
|
||||
)
|
||||
|
||||
// Info 基本信息
|
||||
func (c *Instance) Info() *InstanceInfoReturn {
|
||||
return &InstanceInfoReturn{Name: c.Name}
|
||||
}
|
||||
|
||||
// Perfect 完善信息
|
||||
func (c *Instance) Perfect(params *InstancePerfectParams) error {
|
||||
// 查询用户身份信息
|
||||
mUserTenant := model.NewUserTenant()
|
||||
_, err := model2.FirstField(mUserTenant.UserTenant, []string{"id", "name", "identity"},
|
||||
model2.NewWhere("uuid", c.UID))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mUserTenant.Avatar = params.Avatar
|
||||
mUserTenant.Name = params.Name
|
||||
mUserTenant.Email = params.Email
|
||||
mUserTenant.Area = model2.Area{Province: params.Province, City: params.City, District: params.District, Address: params.Address}
|
||||
// 更新身份信息,提交审核
|
||||
if mUserTenant.Identity == 0 {
|
||||
mUserTenant.Identity = c.CurrentIdentity
|
||||
mUserTenant.Status = model2.UserTenantStatusForExamining
|
||||
}
|
||||
orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// ChangeIdentity 更改身份信息
|
||||
func (c *Instance) ChangeIdentity(identity int) error {
|
||||
if _, has := config.TenantUserIdentityData[identity]; !has {
|
||||
return errors.New("未知的身份信息")
|
||||
}
|
||||
if c.CurrentIdentity == identity {
|
||||
return nil
|
||||
}
|
||||
// 已存在相应的身份,更新最后
|
||||
if c.Identity&identity > 0 {
|
||||
mUserTenant := model.NewUserTenant()
|
||||
// 查询用户身份信息
|
||||
_, err := model2.FirstField(mUserTenant.UserTenant, []string{"id", "uuid", "identity"},
|
||||
model2.NewWhere("uuid", c.UID), model2.NewWhere("identity", identity))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//c.UID = mUserTenant.UUID
|
||||
|
||||
now := time.Now()
|
||||
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.UpdatesWhere(mUserTenant.UserTenant, map[string]interface{}{
|
||||
"selected": model2.UserTenantSelectedForNo, "updated_at": now,
|
||||
}, []*model2.ModelWhere{model2.NewWhere("uuid", c.UID)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return model2.UpdatesWhere(mUserTenant.UserTenant, map[string]interface{}{
|
||||
"selected": model2.UserTenantSelectedForYes, "updated_at": now,
|
||||
}, []*model2.ModelWhere{model2.NewWhere("uuid", c.UID),
|
||||
model2.NewWhere("identity", identity)}, tx)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
c.CurrentIdentity = identity
|
||||
service.Publish(config2.EventForRedisHashProduce, config2.RedisKeyForAccount, utils.UintToString(c.UID), c.SessionEnterprise)
|
||||
return nil
|
||||
return &InstanceInfoReturn{Name: c.Name, Avatar: c.Avatar, Identity: c.Identity, SelectIdentity: c.SelectIdentity}
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
|
166
app/enterprise/controller/user/tenant.go
Normal file
166
app/enterprise/controller/user/tenant.go
Normal file
@ -0,0 +1,166 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/enterprise/model"
|
||||
"SciencesServer/app/service"
|
||||
config2 "SciencesServer/config"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Tenant struct{ *service.SessionEnterprise }
|
||||
|
||||
type TenantHandle func(session *service.SessionEnterprise) *Tenant
|
||||
|
||||
type TenantBasicParams struct {
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
Name string `json:"name"` // 名称
|
||||
Email string `json:"email"` // 邮箱
|
||||
Job string `json:"job"` // 职务
|
||||
Address string `json:"address"` // 详细地址
|
||||
}
|
||||
|
||||
type TenantIndustryParams struct {
|
||||
}
|
||||
|
||||
type (
|
||||
// TenantPerfectParams 完善信息参数
|
||||
TenantPerfectParams struct {
|
||||
*TenantBasicParams // 基本信息
|
||||
*TenantParamsForCompany // 公司身份信息
|
||||
}
|
||||
// TenantParamsForCompany 公司参数信息
|
||||
TenantParamsForCompany struct {
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
config.Area
|
||||
model2.Position
|
||||
Industry string `json:"industry"`
|
||||
Introduce string `json:"introduce"`
|
||||
}
|
||||
)
|
||||
|
||||
var tenantHandlePerfect = map[int]func(params *TenantPerfectParams) (string, error){
|
||||
config.TenantUserIdentityForCompany: perfectForCompany,
|
||||
}
|
||||
|
||||
func perfectForCompany(params *TenantPerfectParams) (string, error) {
|
||||
if params.TenantParamsForCompany == nil {
|
||||
return "", errors.New("企业信息异常")
|
||||
}
|
||||
return utils.AnyToJSON(params.TenantParamsForCompany), nil
|
||||
}
|
||||
|
||||
func perfectForExpert() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func perfectForResearch() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Perfect 完善信息
|
||||
func (c *Tenant) Perfect(params *TenantPerfectParams) error {
|
||||
// 事件处理
|
||||
_handle, has := tenantHandlePerfect[c.SelectIdentity]
|
||||
|
||||
if !has {
|
||||
return errors.New("未知的身份处理方式")
|
||||
}
|
||||
// 查询用户身份信息
|
||||
mUserTenant := model.NewUserTenant()
|
||||
|
||||
isExist, err := model2.FirstField(mUserTenant.UserTenant, []string{"id", "name", "identity", "status"},
|
||||
model2.NewWhere("uid", c.UID), model2.NewWhere("identity", c.Identity))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
if mUserTenant.Status != model2.UserTenantStatusForExamining {
|
||||
return errors.New("资料审核中,不可修改")
|
||||
} else if mUserTenant.Status != model2.UserTenantStatusForExaminePass {
|
||||
return errors.New("资料审核已通过,不可修改")
|
||||
}
|
||||
}
|
||||
mUserTenant.Avatar = params.TenantBasicParams.Avatar
|
||||
mUserTenant.Name = params.TenantBasicParams.Name
|
||||
mUserTenant.Email = params.TenantBasicParams.Email
|
||||
mUserTenant.Identity = c.SelectIdentity
|
||||
mUserTenant.Address = params.TenantBasicParams.Address
|
||||
|
||||
if mUserTenant.Other, err = _handle(params); err != nil {
|
||||
return err
|
||||
}
|
||||
mUserTenant.Status = model2.UserTenantStatusForExamining
|
||||
|
||||
if isExist {
|
||||
if err = model2.Updates(mUserTenant.UserTenant, mUserTenant.UserTenant); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Updates(mUserTenant.UserTenant, map[string]interface{}{
|
||||
"selected": model2.UserTenantSelectedForNo, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
mUserTenant.Selected = model2.UserTenantSelectedForYes
|
||||
|
||||
return model2.Create(mUserTenant.UserTenant, tx)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Auth 认证
|
||||
func (c *Tenant) Auth() {
|
||||
|
||||
}
|
||||
|
||||
// Switch 切换身份
|
||||
func (c *Tenant) Switch(identity int) error {
|
||||
if _, has := config.TenantUserIdentityData[identity]; !has {
|
||||
return errors.New("未知的身份信息")
|
||||
}
|
||||
if c.SelectIdentity == identity {
|
||||
return nil
|
||||
}
|
||||
// 已存在相应的身份,更新最后
|
||||
if c.Identity&identity > 0 {
|
||||
mUserTenant := model.NewUserTenant()
|
||||
// 查询用户身份信息
|
||||
now := time.Now()
|
||||
|
||||
var err error
|
||||
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.UpdatesWhere(mUserTenant.UserTenant, map[string]interface{}{
|
||||
"selected": model2.UserTenantSelectedForNo, "updated_at": now,
|
||||
}, []*model2.ModelWhere{model2.NewWhere("uid", c.UID)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return model2.UpdatesWhere(mUserTenant.UserTenant, map[string]interface{}{
|
||||
"selected": model2.UserTenantSelectedForYes, "updated_at": now,
|
||||
}, []*model2.ModelWhere{model2.NewWhere("uid", c.UID),
|
||||
model2.NewWhere("identity", identity)}, tx)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
c.SelectIdentity = identity
|
||||
service.Publish(config2.EventForRedisHashProduce, config2.RedisKeyForAccount, c.UIDToString(), c.SessionEnterprise)
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewTenant() TenantHandle {
|
||||
return func(session *service.SessionEnterprise) *Tenant {
|
||||
return &Tenant{session}
|
||||
}
|
||||
}
|
11
app/enterprise/model/sys_industry.go
Normal file
11
app/enterprise/model/sys_industry.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type SysIndustry struct {
|
||||
*model.SysIndustry
|
||||
}
|
||||
|
||||
func NewSysIndustry() *SysIndustry {
|
||||
return &SysIndustry{SysIndustry: model.NewSysIndustry()}
|
||||
}
|
@ -9,7 +9,7 @@ type UserTenant struct {
|
||||
}
|
||||
|
||||
func (m *UserTenant) LastChooseInfo(uid uint64) error {
|
||||
_, err := model.FirstField(m.UserTenant, []string{"id", "uuid", "avatar", "identity"},
|
||||
_, err := model.FirstField(m.UserTenant, []string{"id", "uid", "avatar", "identity"},
|
||||
model.NewWhere("uid", uid),
|
||||
model.NewWhere("selected", model.UserTenantSelectedForYes))
|
||||
return err
|
||||
|
@ -38,6 +38,10 @@ type SessionEnterprise struct {
|
||||
SelectIdentity int `json:"select_identity"` // 选中身份信息
|
||||
}
|
||||
|
||||
func (this *SessionEnterprise) UIDToString() string {
|
||||
return utils.UintToString(this.UID)
|
||||
}
|
||||
|
||||
func (this *SessionEnterprise) MarshalBinary() ([]byte, error) {
|
||||
return json.Marshal(this)
|
||||
}
|
||||
|
Reference in New Issue
Block a user