112 lines
3.6 KiB
Go
112 lines
3.6 KiB
Go
package settled
|
|
|
|
import (
|
|
"SciencesServer/app/api/enterprise/model"
|
|
"SciencesServer/app/basic/config"
|
|
model2 "SciencesServer/app/common/model"
|
|
"SciencesServer/app/session"
|
|
"SciencesServer/serve/orm"
|
|
"SciencesServer/utils"
|
|
"errors"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Expert 专家入驻信息
|
|
type Expert struct {
|
|
*session.Enterprise
|
|
tenantID uint64
|
|
}
|
|
|
|
type ExpertHandle func(session *session.Enterprise, tenantID uint64) *Expert
|
|
|
|
// Launch 发起入驻
|
|
func (c *Expert) Launch(params *BasicParams, other *config.IdentityForExpert) error {
|
|
if c.Identity&config.TenantUserIdentityForExpert > 0 {
|
|
return errors.New("操作错误,不可重复申请入驻")
|
|
}
|
|
mManageExpert := model.NewManageExpert()
|
|
// 查询相应专家入驻信息
|
|
isExist, err := model2.FirstField(mManageExpert.ManageExpert, []string{"id", "examine_status"},
|
|
model2.NewWhere("mobile", params.Mobile),
|
|
//, model2.NewWhere("tenant_id", c.tenantID)
|
|
)
|
|
mUserExpert := model.NewUserExpert()
|
|
|
|
if err != nil {
|
|
return err
|
|
} else if isExist {
|
|
if mManageExpert.Examine.ExamineStatus == model2.ExamineStatusForOngoing ||
|
|
mManageExpert.Examine.ExamineStatus == model2.ExamineStatusForAgree {
|
|
// 筛选判断是否满足入驻条件
|
|
if err = params.filter(config.TenantUserIdentityForExpert, model2.NewWhere("expert_id", mManageExpert.ID)); err != nil {
|
|
return err
|
|
}
|
|
// 判断当前用户是否入驻
|
|
var count int64
|
|
|
|
if err = model2.Count(mUserExpert.UserExpert, &count, model2.NewWhere("expert_id", mManageExpert.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 {
|
|
mUserExpert.UID = c.UID
|
|
mUserExpert.ExpertID = mManageExpert.ID
|
|
|
|
if err = model2.Create(mUserExpert.UserExpert, tx); err != nil {
|
|
return err
|
|
}
|
|
// 直接同步身份信息
|
|
if mManageExpert.Examine.ExamineStatus == model2.ExamineStatusForAgree {
|
|
if err = params.fillIdentity(tx, c.Enterprise, config.TenantUserIdentityForExpert); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
mManageExpert.ID = 0
|
|
}
|
|
mManageExpert.TenantID = c.tenantID
|
|
mManageExpert.ResearchID = other.ConvertResearch()
|
|
mManageExpert.LaboratoryID = other.ConvertLaboratory()
|
|
mManageExpert.Image.Image = params.Image
|
|
mManageExpert.Name = params.Name
|
|
mManageExpert.Mobile = params.Mobile
|
|
mManageExpert.Area = model2.Area{
|
|
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
|
|
}
|
|
mManageExpert.Education = other.Education
|
|
mManageExpert.School = other.School
|
|
mManageExpert.Major = other.Major
|
|
mManageExpert.Job = other.Job
|
|
mManageExpert.Title = other.Title
|
|
mManageExpert.Gender = model2.Gender{Gender: model2.GenderKind(other.Gender)}
|
|
mManageExpert.WorkAt = utils.DataTimeToDate(other.WorkAt)
|
|
mManageExpert.SetIndustryAttribute(params.Industrys)
|
|
mManageExpert.SetKeywordAttribute(params.Keywords)
|
|
mManageExpert.SetResearchAttribute(other.Researchs)
|
|
mManageExpert.Introduce = params.Introduce
|
|
mManageExpert.ExamineStatus = model2.ExamineStatusForOngoing
|
|
|
|
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
|
if err = model2.Create(mManageExpert.ManageExpert, tx); err != nil {
|
|
return err
|
|
}
|
|
mUserExpert.UID = c.UID
|
|
mUserExpert.ExpertID = mManageExpert.ID
|
|
return model2.Create(mUserExpert.UserExpert, tx)
|
|
})
|
|
}
|
|
|
|
func NewExpert() ExpertHandle {
|
|
return func(session *session.Enterprise, tenantID uint64) *Expert {
|
|
return &Expert{
|
|
Enterprise: session,
|
|
tenantID: tenantID,
|
|
}
|
|
}
|
|
}
|