feat:完善入驻信息管理
This commit is contained in:
91
app/api/enterprise/controller/settled/research.go
Normal file
91
app/api/enterprise/controller/settled/research.go
Normal file
@ -0,0 +1,91 @@
|
||||
package settled
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Research 研究机构入驻信息
|
||||
type Research struct {
|
||||
*session.Enterprise
|
||||
local string
|
||||
}
|
||||
|
||||
type ResearchHandle func(session *session.Enterprise, local string) *Research
|
||||
|
||||
// Launch 研究机构入驻
|
||||
func (c *Research) Launch(params *BasicParams, other *config.IdentityForResearch) error {
|
||||
if c.Identity&config.TenantUserIdentityForResearch > 0 {
|
||||
return errors.New("操作错误,不可重复申请入驻")
|
||||
}
|
||||
mManageResearch := model.NewManageResearch()
|
||||
// 查询相应专家入驻信息
|
||||
isExist, err := model2.FirstField(mManageResearch.ManageResearch, []string{"id", "status"},
|
||||
model2.NewWhere("code", params.Code), model2.NewWhere("local", c.local))
|
||||
|
||||
mUserResearch := model.NewUserResearch()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
// 审核中
|
||||
if mManageResearch.Status == model2.ExamineStatusForOngoing {
|
||||
return errors.New("操作错误,当前该研究机构信息审核中,不可入驻")
|
||||
}
|
||||
// 审核通过
|
||||
if mManageResearch.Status == model2.ExamineStatusForAgree {
|
||||
// 筛选企业条件
|
||||
if err = params.filter(config.TenantUserIdentityForCompany,
|
||||
model2.NewWhere("research_id", mManageResearch.ID)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
mManageResearch.ID = 0
|
||||
}
|
||||
mManageResearch.Local.Local = c.local
|
||||
mManageResearch.Image.Image = params.Image
|
||||
mManageResearch.Name = params.Name
|
||||
mManageResearch.Code = params.Code
|
||||
mManageResearch.Area = model2.Area{
|
||||
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
|
||||
}
|
||||
//mManageExpert.Position = params.Mobile
|
||||
mManageResearch.SetIndustryAttribute(params.Industrys)
|
||||
mManageResearch.SetKeywordAttribute(params.Keywords)
|
||||
mManageResearch.SetResearchAttribute(other.Researchs)
|
||||
mManageResearch.Introduce = params.Introduce
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
// 删除区域相同编码公司信息
|
||||
if err = model2.DeleteWhere(mManageResearch.ManageResearch, []*model2.ModelWhere{
|
||||
model2.NewWhere("code", params.Code), model2.NewWhere("local", c.local)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = model2.Create(mManageResearch.ManageResearch, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := model2.UpdatesWhere(mUserResearch.UserResearch, map[string]interface{}{
|
||||
"status": model2.InvalidStatusForYes, "updated_at": time.Now(),
|
||||
}, []*model2.ModelWhere{model2.NewWhere("uid", c.UID)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mUserResearch.UID = c.UID
|
||||
mUserResearch.ResearchID = mManageResearch.ID
|
||||
return model2.Create(mUserResearch.UserResearch, tx)
|
||||
})
|
||||
}
|
||||
|
||||
func NewResearch() ResearchHandle {
|
||||
return func(session *session.Enterprise, local string) *Research {
|
||||
return &Research{
|
||||
Enterprise: session,
|
||||
local: local,
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user