feat:完善入驻信息管理

This commit is contained in:
henry
2021-12-02 18:05:53 +08:00
parent 5c4d883c97
commit 199e6f0669
23 changed files with 626 additions and 55 deletions

View File

@ -0,0 +1,28 @@
package settled
import (
"SciencesServer/app/basic/config"
"SciencesServer/app/session"
)
// Company 经纪人入驻信息
type Agent struct {
*session.Enterprise
local string
}
type AgentHandle func(session *session.Enterprise, local string) *Agent
// Launch 经纪人入驻
func (c *Agent) Launch(params *BasicParams, other *config.IdentityForAgent) error {
return nil
}
func NewAgent() AgentHandle {
return func(session *session.Enterprise, local string) *Agent {
return &Agent{
Enterprise: session,
local: local,
}
}
}

View File

@ -16,8 +16,7 @@ import (
// BasicParams 基本信息
type BasicParams struct {
ID uint64
Name, Image, Code, Introduce string
Name, Image, Code, Mobile, Introduce string
config.Area
Industrys, Keywords []string
}

View File

@ -47,6 +47,7 @@ func (c *Company) Launch(params *BasicParams, inviterID uint64, other *config.Id
return err
}
}
mManageCompany.ID = 0
}
mManageCompany.Local.Local = c.local
mManageCompany.InviterID = inviterID
@ -56,7 +57,7 @@ func (c *Company) Launch(params *BasicParams, inviterID uint64, other *config.Id
mManageCompany.Area = model2.Area{
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
}
mManageCompany.WebUrl = other.WebUrl
mManageCompany.Url = other.Url
mManageCompany.SetIndustryAttribute(params.Industrys)
mManageCompany.SetKeywordAttribute(params.Keywords)
mManageCompany.Introduce = params.Introduce
@ -67,10 +68,8 @@ func (c *Company) Launch(params *BasicParams, inviterID uint64, other *config.Id
model2.NewWhere("code", params.Code), model2.NewWhere("local", c.local)}, tx); err != nil {
return err
}
if mManageCompany.ID <= 0 {
if err = model2.Create(mManageCompany.ManageCompany, tx); err != nil {
return err
}
if err = model2.Create(mManageCompany.ManageCompany, tx); err != nil {
return err
}
if err := model2.UpdatesWhere(mUserCompany.UserCompany, map[string]interface{}{
"status": model2.InvalidStatusForYes, "updated_at": time.Now(),

View File

@ -1,3 +1,100 @@
package settled
type Expert struct{}
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", "status"},
model2.NewWhere("mobile", params.Mobile), model2.NewWhere("local", c.local))
mUserExpert := model.NewUserExpert()
if err != nil {
return err
} else if isExist {
// 审核中
if mManageExpert.Status == model2.ExamineStatusForOngoing {
return errors.New("操作错误,当前该专家信息审核中,不可入驻")
}
// 审核通过
if mManageExpert.Status == model2.ExamineStatusForAgree {
// 筛选企业条件
if err = params.filter(config.TenantUserIdentityForCompany,
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{}{
"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,
}
}
}

View File

@ -0,0 +1,93 @@
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"
)
// Laboratory 实验室入驻信息
type Laboratory struct {
*session.Enterprise
local string
}
type LaboratoryHandle func(session *session.Enterprise, local string) *Laboratory
// Launch 实验室入驻
func (c *Laboratory) Launch(params *BasicParams, other *config.IdentityForLaboratory) error {
if c.Identity&config.TenantUserIdentityForLaboratory > 0 {
return errors.New("操作错误,不可重复申请入驻")
}
mManageLaboratory := model.NewManageLaboratory()
// 查询相应专家入驻信息
isExist, err := model2.FirstField(mManageLaboratory.ManageLaboratory, []string{"id", "status"},
model2.NewWhere("code", params.Code), model2.NewWhere("local", c.local))
mUserLaboratory := model.NewUserLaboratory()
if err != nil {
return err
} else if isExist {
// 审核中
if mManageLaboratory.Status == model2.ExamineStatusForOngoing {
return errors.New("操作错误,当前该实验室信息审核中,不可入驻")
}
// 审核通过
if mManageLaboratory.Status == model2.ExamineStatusForAgree {
// 筛选企业条件
if err = params.filter(config.TenantUserIdentityForCompany,
model2.NewWhere("laboratory_id", mManageLaboratory.ID)); err != nil {
return err
}
}
mManageLaboratory.ID = 0
}
mManageLaboratory.Local.Local = c.local
mManageLaboratory.ResearchID = other.ResearchID
mManageLaboratory.Image.Image = params.Image
mManageLaboratory.Name = params.Name
mManageLaboratory.Code = params.Code
mManageLaboratory.Area = model2.Area{
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
}
//mManageExpert.Position = params.Mobile
mManageLaboratory.Url = other.Url
mManageLaboratory.SetIndustryAttribute(params.Industrys)
mManageLaboratory.SetKeywordAttribute(params.Keywords)
mManageLaboratory.SetResearchAttribute(other.Researchs)
mManageLaboratory.Introduce = params.Introduce
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
// 删除区域相同编码公司信息
if err = model2.DeleteWhere(mManageLaboratory.ManageLaboratory, []*model2.ModelWhere{
model2.NewWhere("code", params.Code), model2.NewWhere("local", c.local)}, tx); err != nil {
return err
}
if err = model2.Create(mManageLaboratory.ManageLaboratory, tx); err != nil {
return err
}
if err := model2.UpdatesWhere(mUserLaboratory.UserLaboratory, map[string]interface{}{
"status": model2.InvalidStatusForYes, "updated_at": time.Now(),
}, []*model2.ModelWhere{model2.NewWhere("uid", c.UID)}, tx); err != nil {
return err
}
mUserLaboratory.UID = c.UID
mUserLaboratory.LaboratoryID = mManageLaboratory.ID
return model2.Create(mUserLaboratory.UserLaboratory, tx)
})
}
func NewLaboratory() LaboratoryHandle {
return func(session *session.Enterprise, local string) *Laboratory {
return &Laboratory{
Enterprise: session,
local: local,
}
}
}

View 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,
}
}
}