101 lines
3.3 KiB
Go
101 lines
3.3 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"
|
|
"time"
|
|
)
|
|
|
|
// Expert 专家入驻信息
|
|
type Expert struct {
|
|
*session.Enterprise
|
|
local string
|
|
}
|
|
|
|
type ExpertHandle func(session *session.Enterprise, local string) *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("local", c.local))
|
|
|
|
mUserExpert := model.NewUserExpert()
|
|
|
|
if err != nil {
|
|
return err
|
|
} else if isExist {
|
|
// 审核中
|
|
if mManageExpert.Examine.ExamineStatus == model2.ExamineStatusForOngoing {
|
|
return errors.New("操作错误,当前该专家信息审核中,不可入驻")
|
|
}
|
|
// 审核通过
|
|
if mManageExpert.Examine.ExamineStatus == model2.ExamineStatusForAgree {
|
|
// 筛选企业条件
|
|
if err = params.filter(config.TenantUserIdentityForExpert,
|
|
model2.NewWhere("expert_id", mManageExpert.ID)); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
mUserExpert.ID = 0
|
|
}
|
|
mManageExpert.Local.Local = c.local
|
|
mManageExpert.ResearchID = other.ResearchID
|
|
mManageExpert.LaboratoryID = other.LaboratoryID
|
|
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.Position = params.Mobile
|
|
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
|
|
|
|
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
|
// 删除区域相同编码公司信息
|
|
if err = model2.DeleteWhere(mManageExpert.ManageExpert, []*model2.ModelWhere{
|
|
model2.NewWhere("mobile", params.Mobile), model2.NewWhere("local", c.local)}, tx); err != nil {
|
|
return err
|
|
}
|
|
if err = model2.Create(mManageExpert.ManageExpert, tx); err != nil {
|
|
return err
|
|
}
|
|
if err := model2.UpdatesWhere(mUserExpert.UserExpert, map[string]interface{}{
|
|
"invalid_status": model2.InvalidStatusForYes, "updated_at": time.Now(),
|
|
}, []*model2.ModelWhere{model2.NewWhere("uid", c.UID)}, 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, local string) *Expert {
|
|
return &Expert{
|
|
Enterprise: session,
|
|
local: local,
|
|
}
|
|
}
|
|
}
|