Files

101 lines
3.3 KiB
Go
Raw Normal View History

2021-12-02 15:23:48 +08:00
package settled
2021-12-02 18:05:53 +08:00
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
2022-01-13 18:07:40 +08:00
tenantID uint64
2021-12-02 18:05:53 +08:00
}
2022-01-13 18:07:40 +08:00
type ExpertHandle func(session *session.Enterprise, tenantID uint64) *Expert
2021-12-02 18:05:53 +08:00
// Launch 发起入驻
func (c *Expert) Launch(params *BasicParams, other *config.IdentityForExpert) error {
if c.Identity&config.TenantUserIdentityForExpert > 0 {
return errors.New("操作错误,不可重复申请入驻")
}
mManageExpert := model.NewManageExpert()
// 查询相应专家入驻信息
2021-12-03 14:18:06 +08:00
isExist, err := model2.FirstField(mManageExpert.ManageExpert, []string{"id", "examine_status"},
2022-01-13 18:07:40 +08:00
model2.NewWhere("mobile", params.Mobile), model2.NewWhere("tenant_id", c.tenantID))
2021-12-02 18:05:53 +08:00
mUserExpert := model.NewUserExpert()
if err != nil {
return err
} else if isExist {
// 审核中
2021-12-03 10:08:23 +08:00
if mManageExpert.Examine.ExamineStatus == model2.ExamineStatusForOngoing {
2021-12-02 18:05:53 +08:00
return errors.New("操作错误,当前该专家信息审核中,不可入驻")
}
// 审核通过
2021-12-03 10:08:23 +08:00
if mManageExpert.Examine.ExamineStatus == model2.ExamineStatusForAgree {
2021-12-02 18:05:53 +08:00
// 筛选企业条件
2021-12-03 10:08:23 +08:00
if err = params.filter(config.TenantUserIdentityForExpert,
2021-12-02 18:05:53 +08:00
model2.NewWhere("expert_id", mManageExpert.ID)); err != nil {
return err
}
}
mUserExpert.ID = 0
}
2022-01-13 18:07:40 +08:00
mManageExpert.TenantID = c.tenantID
2021-12-02 18:05:53 +08:00
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{
2022-01-13 18:07:40 +08:00
model2.NewWhere("mobile", params.Mobile), model2.NewWhere("tenant_id", c.tenantID)}, tx); err != nil {
2021-12-02 18:05:53 +08:00
return err
}
if err = model2.Create(mManageExpert.ManageExpert, tx); err != nil {
return err
}
if err := model2.UpdatesWhere(mUserExpert.UserExpert, map[string]interface{}{
2021-12-03 10:08:23 +08:00
"invalid_status": model2.InvalidStatusForYes, "updated_at": time.Now(),
2021-12-02 18:05:53 +08:00
}, []*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 {
2022-01-13 18:07:40 +08:00
return func(session *session.Enterprise, tenantID uint64) *Expert {
2021-12-02 18:05:53 +08:00
return &Expert{
Enterprise: session,
2022-01-13 18:07:40 +08:00
tenantID: tenantID,
2021-12-02 18:05:53 +08:00
}
}
}