feat:完善入驻信息管理
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user