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 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 { 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.TenantID = c.tenantID 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("tenant_id", c.tenantID)}, 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, tenantID uint64) *Expert { return &Expert{ Enterprise: session, tenantID: tenantID, } } }