feat:完善信息,优化入驻接口

This commit is contained in:
henry
2022-01-28 16:59:15 +08:00
parent 4c57ca2878
commit aafff0f3fd
22 changed files with 275 additions and 137 deletions

View File

@ -9,7 +9,6 @@ import (
"SciencesServer/utils"
"errors"
"gorm.io/gorm"
"time"
)
// Expert 专家入驻信息
@ -28,26 +27,47 @@ func (c *Expert) Launch(params *BasicParams, other *config.IdentityForExpert) er
mManageExpert := model.NewManageExpert()
// 查询相应专家入驻信息
isExist, err := model2.FirstField(mManageExpert.ManageExpert, []string{"id", "examine_status"},
model2.NewWhere("mobile", params.Mobile), model2.NewWhere("tenant_id", c.tenantID))
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 {
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
})
}
mUserExpert.ID = 0
mManageExpert.ID = 0
}
mManageExpert.TenantID = c.tenantID
mManageExpert.ResearchID = other.ConvertResearch()
@ -58,7 +78,6 @@ func (c *Expert) Launch(params *BasicParams, other *config.IdentityForExpert) er
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.Education = other.Education
mManageExpert.School = other.School
mManageExpert.Major = other.Major
@ -70,21 +89,12 @@ func (c *Expert) Launch(params *BasicParams, other *config.IdentityForExpert) er
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.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)