feat:完善信息,增加socket
This commit is contained in:
@ -9,7 +9,6 @@ import (
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Company 公司企业入驻信息
|
||||
@ -56,27 +55,50 @@ func (c *Company) Launch(params *BasicParams, inviterID uint64, other *config.Id
|
||||
return errors.New("操作错误,不可重复申请入驻")
|
||||
}
|
||||
mManageCompany := model.NewManageCompany()
|
||||
// 查询相应的企业入驻信息
|
||||
isExist, err := model2.FirstField(mManageCompany.ManageCompany, []string{"id", "examine_status"},
|
||||
model2.NewWhere("code", params.Code), model2.NewWhere("tenant_id", c.tenantID))
|
||||
|
||||
// 过滤用户其他公司入驻信息
|
||||
mUserCompany := model.NewUserCompany()
|
||||
// 查询相应的企业入驻信息,code唯一的
|
||||
isExist, err := model2.LastWhere(mManageCompany.ManageCompany, []string{"id", "examine_status", "created_at"},
|
||||
model2.NewWhere("code", params.Code))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
// 审核中
|
||||
if mManageCompany.Examine.ExamineStatus == model2.ExamineStatusForOngoing {
|
||||
return errors.New("操作错误,当前该企业信息审核中,不可入驻")
|
||||
}
|
||||
// 审核通过
|
||||
if mManageCompany.Examine.ExamineStatus == model2.ExamineStatusForAgree {
|
||||
// 筛选企业条件
|
||||
if err = params.filter(config.TenantUserIdentityForCompany,
|
||||
model2.NewWhere("company_id", mManageCompany.ID)); err != nil {
|
||||
}
|
||||
// 用户入驻信息
|
||||
mUserCompany := model.NewUserCompany()
|
||||
|
||||
// 存在
|
||||
if isExist {
|
||||
if mManageCompany.Examine.ExamineStatus == model2.ExamineStatusForOngoing ||
|
||||
mManageCompany.Examine.ExamineStatus == model2.ExamineStatusForAgree {
|
||||
// 筛选判断是否满足入驻条件
|
||||
if err = params.filter(config.TenantUserIdentityForCompany, model2.NewWhere("company_id", mManageCompany.ID)); err != nil {
|
||||
return err
|
||||
}
|
||||
// 判断当前用户是否入驻
|
||||
var count int64
|
||||
|
||||
if err = model2.Count(mUserCompany.UserCompany, &count, model2.NewWhere("company_id", mManageCompany.ID),
|
||||
model2.NewWhere("uid", c.UID), model2.NewWhere("invalid_status", model2.InvalidStatusForNot)); err != nil {
|
||||
return err
|
||||
}
|
||||
if count > 0 {
|
||||
return errors.New("操作错误,已申请入驻,不可重复申请")
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
mUserCompany.UID = c.UID
|
||||
mUserCompany.CompanyID = mManageCompany.ID
|
||||
|
||||
if err = model2.Create(mUserCompany.UserCompany, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
// 直接同步身份信息
|
||||
if mManageCompany.Examine.ExamineStatus == model2.ExamineStatusForAgree {
|
||||
if err = params.fillIdentity(tx, c.Enterprise, config.TenantUserIdentityForCompany); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
mManageCompany.ID = 0
|
||||
}
|
||||
@ -98,19 +120,9 @@ func (c *Company) Launch(params *BasicParams, inviterID uint64, other *config.Id
|
||||
mManageCompany.Introduce = params.Introduce
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
// 删除区域相同编码公司信息
|
||||
if err = model2.DeleteWhere(mManageCompany.ManageCompany, []*model2.ModelWhere{
|
||||
model2.NewWhere("code", params.Code), model2.NewWhere("tenant_id", c.tenantID)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = model2.Create(mManageCompany.ManageCompany, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := model2.UpdatesWhere(mUserCompany.UserCompany, map[string]interface{}{
|
||||
"invalid_status": model2.InvalidStatusForYes, "updated_at": time.Now(),
|
||||
}, []*model2.ModelWhere{model2.NewWhere("uid", c.UID)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mUserCompany.UID = c.UID
|
||||
mUserCompany.CompanyID = mManageCompany.ID
|
||||
return model2.Create(mUserCompany.UserCompany, tx)
|
||||
|
Reference in New Issue
Block a user