feat:完善入驻信息管理
This commit is contained in:
@ -4,23 +4,31 @@ 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 {
|
||||
ID uint64
|
||||
Name, Image, Code, Introduce string
|
||||
config.Area
|
||||
Industrys, Keywords []string
|
||||
}
|
||||
|
||||
// filter 筛选信息
|
||||
func (c *BasicParams) filter(identity int, where ...*model2.ModelWhere) (bool, error) {
|
||||
func (c *BasicParams) filter(identity int, where ...*model2.ModelWhere) error {
|
||||
mSysIdentity := model.NewSysIdentity()
|
||||
_, err := model2.FirstField(mSysIdentity.SysIdentity, []string{"id", "register_count", "is_examine"}, model2.NewWhere("identity", identity))
|
||||
_, err := model2.FirstField(mSysIdentity.SysIdentity, []string{"id", "register_count"}, model2.NewWhere("identity", identity))
|
||||
|
||||
if err != nil {
|
||||
return true, err
|
||||
return err
|
||||
}
|
||||
var iModel model2.IModel
|
||||
|
||||
@ -40,10 +48,34 @@ func (c *BasicParams) filter(identity int, where ...*model2.ModelWhere) (bool, e
|
||||
where = append(where, model2.NewWhere("status", model2.InvalidStatusForNot))
|
||||
|
||||
if err = model2.Count(iModel, &count, where...); err != nil {
|
||||
return true, err
|
||||
return err
|
||||
}
|
||||
if count >= int64(mSysIdentity.RegisterCount) {
|
||||
return true, errors.New("操作错误,已超过当前身份最大入驻人数")
|
||||
return errors.New("操作错误,已超过当前身份最大入驻人数")
|
||||
}
|
||||
return mSysIdentity.IsExamine == model2.SysIdentityExamineForYes, nil
|
||||
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)
|
||||
}
|
||||
|
@ -6,10 +6,12 @@ import (
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Company 公司企业入驻信息
|
||||
type Company struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
@ -17,24 +19,33 @@ type Company struct {
|
||||
|
||||
type CompanyHandle func(session *session.Enterprise, local string) *Company
|
||||
|
||||
func (c *Company) Launch() {
|
||||
// Launch 发起入驻
|
||||
func (c *Company) Launch(params *BasicParams, inviterID uint64, other *config.IdentityForCompany) error {
|
||||
if c.Identity&config.TenantUserIdentityForCompany > 0 {
|
||||
return errors.New("操作错误,不可重复申请入驻")
|
||||
}
|
||||
mManageCompany := model.NewManageCompany()
|
||||
|
||||
// 查询相应的企业入驻信息
|
||||
isExist, err := model2.FirstField(mManageCompany.ManageCompany, []string{"id", "status"},
|
||||
model2.NewWhere("code", params.Code), model2.NewWhere("local", c.local),
|
||||
model2.NewWhere("status", model2.ExamineStatusForRefuse))
|
||||
model2.NewWhere("code", params.Code), model2.NewWhere("local", c.local))
|
||||
|
||||
isExamine := true
|
||||
// 过滤用户其他公司入驻信息
|
||||
mUserCompany := model.NewUserCompany()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
// 审核中
|
||||
if mManageCompany.Status == model2.ExamineStatusForOngoing {
|
||||
return errors.New("操作错误,当前企业信息审核中,不可入驻")
|
||||
return errors.New("操作错误,当前该企业信息审核中,不可入驻")
|
||||
}
|
||||
// 筛选企业条件
|
||||
if isExamine, err = c.filter(config.TenantUserIdentityForCompany, model2.NewWhere("company_id", mManageCompany.ID)); err != nil {
|
||||
return err
|
||||
// 审核通过
|
||||
if mManageCompany.Status == model2.ExamineStatusForAgree {
|
||||
// 筛选企业条件
|
||||
if err = params.filter(config.TenantUserIdentityForCompany,
|
||||
model2.NewWhere("company_id", mManageCompany.ID)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
mManageCompany.Local.Local = c.local
|
||||
@ -50,18 +61,17 @@ func (c *Company) Launch() {
|
||||
mManageCompany.SetKeywordAttribute(params.Keywords)
|
||||
mManageCompany.Introduce = params.Introduce
|
||||
|
||||
if isExamine {
|
||||
mManageCompany.Status = model2.ExamineStatusForAgree
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
// 删除区域相同编码公司信息
|
||||
if err = model2.DeleteWhere(mManageCompany.ManageCompany, []*model2.ModelWhere{
|
||||
model2.NewWhere("code", params.Code), model2.NewWhere("local", c.local)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if mManageCompany.ID <= 0 {
|
||||
if err = model2.Create(mManageCompany.ManageCompany, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// 过滤用户其他公司入驻信息
|
||||
mUserCompany := model.NewUserCompany()
|
||||
|
||||
if err := model2.UpdatesWhere(mUserCompany.UserCompany, map[string]interface{}{
|
||||
"status": model2.InvalidStatusForYes, "updated_at": time.Now(),
|
||||
}, []*model2.ModelWhere{model2.NewWhere("uid", c.UID)}, tx); err != nil {
|
||||
|
3
app/api/enterprise/controller/settled/expert.go
Normal file
3
app/api/enterprise/controller/settled/expert.go
Normal file
@ -0,0 +1,3 @@
|
||||
package settled
|
||||
|
||||
type Expert struct{}
|
20
app/api/enterprise/controller/settled/instance.go
Normal file
20
app/api/enterprise/controller/settled/instance.go
Normal file
@ -0,0 +1,20 @@
|
||||
package settled
|
||||
|
||||
import "SciencesServer/app/session"
|
||||
|
||||
type Instance struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type InstanceHandle func(session *session.Enterprise, local string) *Instance
|
||||
|
||||
func (c *Instance) Index() {
|
||||
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *session.Enterprise, local string) *Instance {
|
||||
return &Instance{Enterprise: session, local: local}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user