81 lines
2.2 KiB
Go
81 lines
2.2 KiB
Go
package settled
|
||
|
||
import (
|
||
"SciencesServer/app/api/enterprise/model"
|
||
"SciencesServer/app/basic/config"
|
||
model2 "SciencesServer/app/common/model"
|
||
"SciencesServer/app/session"
|
||
"errors"
|
||
"gorm.io/gorm"
|
||
"time"
|
||
)
|
||
|
||
// TODO:入驻流程
|
||
// 2021-12-02
|
||
// 一:
|
||
|
||
// BasicParams 基本信息
|
||
type BasicParams struct {
|
||
Name, Image, Code, Mobile, Introduce string
|
||
config.Area
|
||
Industrys, Keywords []string
|
||
}
|
||
|
||
// filter 筛选信息
|
||
func (c *BasicParams) filter(identity int, where ...*model2.ModelWhere) error {
|
||
mSysIdentity := model.NewSysIdentity()
|
||
_, err := model2.FirstField(mSysIdentity.SysIdentity, []string{"id", "register_count"}, model2.NewWhere("identity", identity))
|
||
|
||
if err != nil {
|
||
return err
|
||
}
|
||
var iModel model2.IModel
|
||
|
||
if identity&config.TenantUserIdentityForCompany > 0 {
|
||
iModel = model2.NewUserCompany()
|
||
} else if identity&config.TenantUserIdentityForExpert > 0 {
|
||
iModel = model2.NewUserExpert()
|
||
} else if identity&config.TenantUserIdentityForResearch > 0 {
|
||
iModel = model2.NewUserResearch()
|
||
} else if identity&config.TenantUserIdentityForLaboratory > 0 {
|
||
iModel = model2.NewUserLaboratory()
|
||
} else if identity&config.TenantUserIdentityForAgent > 0 {
|
||
iModel = model2.NewUserAgent()
|
||
}
|
||
var count int64
|
||
|
||
where = append(where, model2.NewWhere("status", model2.InvalidStatusForNot))
|
||
|
||
if err = model2.Count(iModel, &count, where...); err != nil {
|
||
return err
|
||
}
|
||
if count >= int64(mSysIdentity.RegisterCount) {
|
||
return errors.New("操作错误,已超过当前身份最大入驻人数")
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// fillIdentity 填充身份信息
|
||
func (c *BasicParams) fillIdentity(tx *gorm.DB, session *session.Enterprise, identity int) error {
|
||
if session.SelectIdentity <= 0 {
|
||
session.SelectIdentity = identity
|
||
}
|
||
session.Identity = session.Identity | identity
|
||
|
||
mUserInstance := model.NewUserInstance()
|
||
|
||
err := model2.UpdatesWhere(mUserInstance.UserInstance, map[string]interface{}{
|
||
"identity": session.Identity, "updated_at": time.Now(),
|
||
}, []*model2.ModelWhere{model2.NewWhere("uuid", session.UID)}, tx)
|
||
|
||
if err != nil {
|
||
return err
|
||
}
|
||
mUserIdentity := model.NewUserIdentity()
|
||
mUserIdentity.UID = session.UID
|
||
mUserIdentity.Name = session.Name
|
||
mUserIdentity.Identity = identity
|
||
|
||
return model2.Create(mUserIdentity.UserIdentity)
|
||
}
|