Files

82 lines
2.3 KiB
Go
Raw Normal View History

2021-12-02 09:06:15 +08:00
package settled
import (
"SciencesServer/app/api/enterprise/model"
"SciencesServer/app/basic/config"
model2 "SciencesServer/app/common/model"
2021-12-02 15:23:48 +08:00
"SciencesServer/app/session"
2021-12-02 09:06:15 +08:00
"errors"
2021-12-02 15:23:48 +08:00
"gorm.io/gorm"
"time"
2021-12-02 09:06:15 +08:00
)
2021-12-02 15:23:48 +08:00
// TODO入驻流程
// 2021-12-02
// 一:
2021-12-02 09:06:15 +08:00
// BasicParams 基本信息
type BasicParams struct {
2021-12-02 15:23:48 +08:00
ID uint64
2021-12-02 09:06:15 +08:00
Name, Image, Code, Introduce string
config.Area
Industrys, Keywords []string
}
// filter 筛选信息
2021-12-02 15:23:48 +08:00
func (c *BasicParams) filter(identity int, where ...*model2.ModelWhere) error {
2021-12-02 09:06:15 +08:00
mSysIdentity := model.NewSysIdentity()
2021-12-02 15:23:48 +08:00
_, err := model2.FirstField(mSysIdentity.SysIdentity, []string{"id", "register_count"}, model2.NewWhere("identity", identity))
2021-12-02 09:06:15 +08:00
if err != nil {
2021-12-02 15:23:48 +08:00
return err
2021-12-02 09:06:15 +08:00
}
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 {
2021-12-02 15:23:48 +08:00
return err
2021-12-02 09:06:15 +08:00
}
if count >= int64(mSysIdentity.RegisterCount) {
2021-12-02 15:23:48 +08:00
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
2021-12-02 09:06:15 +08:00
}
2021-12-02 15:23:48 +08:00
mUserIdentity := model.NewUserIdentity()
mUserIdentity.UID = session.UID
mUserIdentity.Name = session.Name
mUserIdentity.Identity = identity
return model2.Create(mUserIdentity.UserIdentity)
2021-12-02 09:06:15 +08:00
}