feat:完善产品详情
This commit is contained in:
@ -49,86 +49,6 @@ func (*User) BindMobile(c *gin.Context) {
|
|||||||
api.APIResponse(err)(c)
|
api.APIResponse(err)(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (*User) SettledCompany(c *gin.Context) {
|
|
||||||
// form := &struct {
|
|
||||||
// InviteCode string `json:"invite_code" form:"invite_code"`
|
|
||||||
// userSettledForm
|
|
||||||
// }{}
|
|
||||||
// if err := api.Bind(form)(c); err != nil {
|
|
||||||
// api.APIFailure(err.(error))(c)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Company(&user.SettledParams{
|
|
||||||
// Image: form.FilterImageURL(), Name: form.Name, Code: form.Code,
|
|
||||||
// Area: form.Area, Introduce: form.Introduce, Industrys: form.Industrys, Keywords: form.Keywords,
|
|
||||||
// }, (&api.IDStringForm{ID: form.InviteCode}).Convert(), nil)
|
|
||||||
// api.APIResponse(err)(c)
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (*User) SettledExpert(c *gin.Context) {
|
|
||||||
// form := &struct {
|
|
||||||
// userSettledForm
|
|
||||||
// config.IdentityForExpert
|
|
||||||
// }{}
|
|
||||||
// if err := api.Bind(form)(c); err != nil {
|
|
||||||
// api.APIFailure(err.(error))(c)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Expert(&user.SettledParams{
|
|
||||||
// Area: form.Area, Introduce: form.Introduce, Industrys: form.Industrys,
|
|
||||||
// Keywords: form.Keywords,
|
|
||||||
// }, &form.IdentityForExpert)
|
|
||||||
// api.APIResponse(err)(c)
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (*User) SettledResearch(c *gin.Context) {
|
|
||||||
// form := &struct {
|
|
||||||
// userSettledForm
|
|
||||||
// config.IdentityForResearch
|
|
||||||
// }{}
|
|
||||||
// if err := api.Bind(form)(c); err != nil {
|
|
||||||
// api.APIFailure(err.(error))(c)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Research(&user.SettledParams{
|
|
||||||
// Image: form.FilterImageURL(), Name: form.Name, Code: form.Code,
|
|
||||||
// Area: form.Area, Introduce: form.Introduce, Industrys: form.Industrys, Keywords: form.Keywords,
|
|
||||||
// }, &form.IdentityForResearch)
|
|
||||||
// api.APIResponse(err)(c)
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (*User) SettledLaboratory(c *gin.Context) {
|
|
||||||
// form := &struct {
|
|
||||||
// userSettledForm
|
|
||||||
// config.IdentityForLaboratory
|
|
||||||
// }{}
|
|
||||||
// if err := api.Bind(form)(c); err != nil {
|
|
||||||
// api.APIFailure(err.(error))(c)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Laboratory(&user.SettledParams{
|
|
||||||
// Image: form.FilterImageURL(), Name: form.Name, Code: form.Code,
|
|
||||||
// Area: form.Area, Introduce: form.Introduce, Industrys: form.Industrys, Keywords: form.Keywords,
|
|
||||||
// }, &form.IdentityForLaboratory)
|
|
||||||
// api.APIResponse(err)(c)
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (*User) SettledAgent(c *gin.Context) {
|
|
||||||
// form := &struct {
|
|
||||||
// api.IDStringForm
|
|
||||||
// userSettledForm
|
|
||||||
// }{}
|
|
||||||
// if err := api.Bind(form)(c); err != nil {
|
|
||||||
// api.APIFailure(err.(error))(c)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Agent(&user.SettledParams{
|
|
||||||
// ID: form.Convert(), Image: form.FilterImageURL(), Name: form.Name, Code: form.Code,
|
|
||||||
// Area: form.Area, Introduce: form.Introduce, Industrys: form.Industrys, Keywords: form.Keywords,
|
|
||||||
// })
|
|
||||||
// api.APIResponse(err)(c)
|
|
||||||
//}
|
|
||||||
|
|
||||||
func (*User) IdentityBasic(c *gin.Context) {
|
func (*User) IdentityBasic(c *gin.Context) {
|
||||||
data, err := user.NewIdentity()(api.GetSession()(c).(*session.Enterprise)).Basic()
|
data, err := user.NewIdentity()(api.GetSession()(c).(*session.Enterprise)).Basic()
|
||||||
api.APIResponse(err, data)(c)
|
api.APIResponse(err, data)(c)
|
||||||
|
@ -28,31 +28,31 @@ type InstanceExamineInfo struct {
|
|||||||
|
|
||||||
func (c *Instance) company() (bool, *model2.Examine, error) {
|
func (c *Instance) company() (bool, *model2.Examine, error) {
|
||||||
mUserCompany := model.NewUserCompany()
|
mUserCompany := model.NewUserCompany()
|
||||||
out, err := mUserCompany.Company(c.UID)
|
out, err := mUserCompany.Settled(c.UID)
|
||||||
return out.ID > 0, out.Examine, err
|
return out.ID > 0, out.Examine, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Instance) expert() (bool, *model2.Examine, error) {
|
func (c *Instance) expert() (bool, *model2.Examine, error) {
|
||||||
mUserExpert := model.NewUserExpert()
|
mUserExpert := model.NewUserExpert()
|
||||||
out, err := mUserExpert.Expert(c.UID)
|
out, err := mUserExpert.Settled(c.UID)
|
||||||
return out.ID > 0, out.Examine, err
|
return out.ID > 0, out.Examine, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Instance) research() (bool, *model2.Examine, error) {
|
func (c *Instance) research() (bool, *model2.Examine, error) {
|
||||||
mUserResearch := model.NewUserResearch()
|
mUserResearch := model.NewUserResearch()
|
||||||
out, err := mUserResearch.Research(c.UID)
|
out, err := mUserResearch.Settled(c.UID)
|
||||||
return out.ID > 0, out.Examine, err
|
return out.ID > 0, out.Examine, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Instance) laboratory() (bool, *model2.Examine, error) {
|
func (c *Instance) laboratory() (bool, *model2.Examine, error) {
|
||||||
mUserLaboratory := model.NewUserLaboratory()
|
mUserLaboratory := model.NewUserLaboratory()
|
||||||
out, err := mUserLaboratory.Laboratory(c.UID)
|
out, err := mUserLaboratory.Settled(c.UID)
|
||||||
return out.ID > 0, out.Examine, err
|
return out.ID > 0, out.Examine, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Instance) agent() (bool, *model2.Examine, error) {
|
func (c *Instance) agent() (bool, *model2.Examine, error) {
|
||||||
mUserAgent := model.NewUserAgent()
|
mUserAgent := model.NewUserAgent()
|
||||||
out, err := mUserAgent.Agent(c.UID)
|
out, err := mUserAgent.Settled(c.UID)
|
||||||
return out.ID > 0, out.Examine, err
|
return out.ID > 0, out.Examine, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,151 @@ type Identity struct{ *session.Enterprise }
|
|||||||
|
|
||||||
type IdentityHandle func(session *session.Enterprise) *Identity
|
type IdentityHandle func(session *session.Enterprise) *Identity
|
||||||
|
|
||||||
|
type (
|
||||||
|
// IdentityForCompany 公司信息
|
||||||
|
IdentityForCompany struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
*model2.ManageCompany
|
||||||
|
Industrys []string `json:"industrys"`
|
||||||
|
Keywords []string `json:"keywords"`
|
||||||
|
Directions []string `json:"directions"`
|
||||||
|
}
|
||||||
|
// IdentityForExpert 专家信息
|
||||||
|
IdentityForExpert struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
*model2.ManageExpert
|
||||||
|
Industrys []string `json:"industrys"`
|
||||||
|
Keywords []string `json:"keywords"`
|
||||||
|
Researchs []string `json:"researchs"`
|
||||||
|
}
|
||||||
|
// IdentityForResearch 科研机构信息
|
||||||
|
IdentityForResearch struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
*model2.ManageResearch
|
||||||
|
Industrys []string `json:"industrys"`
|
||||||
|
Keywords []string `json:"keywords"`
|
||||||
|
Researchs []string `json:"researchs"`
|
||||||
|
}
|
||||||
|
// IdentityForLaboratory 实验室信息
|
||||||
|
IdentityForLaboratory struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
*model2.ManageLaboratory
|
||||||
|
Industrys []string `json:"industrys"`
|
||||||
|
Keywords []string `json:"keywords"`
|
||||||
|
Researchs []string `json:"researchs"`
|
||||||
|
}
|
||||||
|
// IdentityForAgent 经纪人信息
|
||||||
|
IdentityForAgent struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
*model2.ManageAgent
|
||||||
|
Industrys []string `json:"industrys"`
|
||||||
|
Keywords []string `json:"keywords"`
|
||||||
|
IDImage *model2.ManageAgentIDImage `json:"id_images"`
|
||||||
|
CredentialImages []string `json:"credential_images"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// company 公司信息
|
||||||
|
func (c *Identity) company() (*IdentityForCompany, error) {
|
||||||
|
mUserCompany := model.NewUserCompany()
|
||||||
|
out, err := mUserCompany.Company(c.UID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if out.UserCompanyID <= 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return &IdentityForCompany{
|
||||||
|
ID: (&model2.Model{ID: out.UserCompanyID}).GetEncodeID(),
|
||||||
|
ManageCompany: out.ManageCompany,
|
||||||
|
Industrys: out.GetIndustryAttribute(),
|
||||||
|
Keywords: out.GetKeywordAttribute(),
|
||||||
|
Directions: out.GetDirectionAttribute(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Identity) companyEdit() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// expert 专家信息
|
||||||
|
func (c *Identity) expert() (*IdentityForExpert, error) {
|
||||||
|
mUserExpert := model.NewUserExpert()
|
||||||
|
out, err := mUserExpert.Expert(c.UID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if out.UserExpertID <= 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return &IdentityForExpert{
|
||||||
|
ID: (&model2.Model{ID: out.UserExpertID}).GetEncodeID(),
|
||||||
|
ManageExpert: out.ManageExpert,
|
||||||
|
Industrys: out.GetIndustryAttribute(),
|
||||||
|
Keywords: out.GetKeywordAttribute(),
|
||||||
|
Researchs: out.GetResearchAttribute(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// research 科研机构信息
|
||||||
|
func (c *Identity) research() (*IdentityForResearch, error) {
|
||||||
|
mUserResearch := model.NewUserResearch()
|
||||||
|
out, err := mUserResearch.Research(c.UID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if out.UserResearchID <= 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return &IdentityForResearch{
|
||||||
|
ID: (&model2.Model{ID: out.UserResearchID}).GetEncodeID(),
|
||||||
|
ManageResearch: out.ManageResearch,
|
||||||
|
Industrys: out.GetIndustryAttribute(),
|
||||||
|
Keywords: out.GetKeywordAttribute(),
|
||||||
|
Researchs: out.GetResearchAttribute(),
|
||||||
|
}, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Laboratory 实验室信息
|
||||||
|
func (c *Identity) laboratory() (*IdentityForLaboratory, error) {
|
||||||
|
mUserLaboratory := model.NewUserLaboratory()
|
||||||
|
out, err := mUserLaboratory.Laboratory(c.UID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if out.UserLaboratoryID <= 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return &IdentityForLaboratory{
|
||||||
|
ID: (&model2.Model{ID: out.UserLaboratoryID}).GetEncodeID(),
|
||||||
|
ManageLaboratory: out.ManageLaboratory,
|
||||||
|
Industrys: out.GetIndustryAttribute(),
|
||||||
|
Keywords: out.GetKeywordAttribute(),
|
||||||
|
Researchs: out.GetResearchAttribute(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// agent 经纪人信息
|
||||||
|
func (c *Identity) agent() (*IdentityForAgent, error) {
|
||||||
|
mUserAgent := model.NewUserAgent()
|
||||||
|
out, err := mUserAgent.Agent(c.UID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if out.UserAgentID <= 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return &IdentityForAgent{
|
||||||
|
ID: (&model2.Model{ID: out.UserAgentID}).GetEncodeID(),
|
||||||
|
ManageAgent: out.ManageAgent,
|
||||||
|
Industrys: out.GetIndustryAttribute(),
|
||||||
|
Keywords: out.GetKeywordAttribute(),
|
||||||
|
IDImage: out.GetIDImageAttribute(),
|
||||||
|
CredentialImages: out.GetCredentialImageAttribute(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Basic 详细信息
|
// Basic 详细信息
|
||||||
func (c *Identity) Basic() (*InstanceDetailInfo, error) {
|
func (c *Identity) Basic() (*InstanceDetailInfo, error) {
|
||||||
resp := &InstanceDetailInfo{InstanceInfo: InstanceInfo{Name: c.Name, Identity: c.Identity, SelectIdentity: c.SelectIdentity}}
|
resp := &InstanceDetailInfo{InstanceInfo: InstanceInfo{Name: c.Name, Identity: c.Identity, SelectIdentity: c.SelectIdentity}}
|
||||||
@ -40,7 +185,18 @@ func (c *Identity) Basic() (*InstanceDetailInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Detail 详细信息
|
// Detail 详细信息
|
||||||
func (c *Identity) Detail() (*InstanceDetailInfo, error) {
|
func (c *Identity) Detail() (interface{}, error) {
|
||||||
|
if c.Identity == config.TenantUserIdentityForCompany { // 公司企业身份
|
||||||
|
return c.company()
|
||||||
|
} else if c.Identity == config.TenantUserIdentityForExpert { // 专家身份
|
||||||
|
return c.expert()
|
||||||
|
} else if c.Identity == config.TenantUserIdentityForResearch { // 科研机构身份
|
||||||
|
return c.research()
|
||||||
|
} else if c.Identity == config.TenantUserIdentityForLaboratory { // 实验室身份
|
||||||
|
return c.laboratory()
|
||||||
|
} else if c.Identity == config.TenantUserIdentityForAgent { // 经纪人身份
|
||||||
|
return c.agent()
|
||||||
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,241 +0,0 @@
|
|||||||
package user
|
|
||||||
|
|
||||||
import (
|
|
||||||
"SciencesServer/app/api/enterprise/model"
|
|
||||||
"SciencesServer/app/basic/config"
|
|
||||||
model2 "SciencesServer/app/common/model"
|
|
||||||
"SciencesServer/app/session"
|
|
||||||
"errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Settled 入驻
|
|
||||||
type Settled struct {
|
|
||||||
*session.Enterprise
|
|
||||||
local string
|
|
||||||
}
|
|
||||||
|
|
||||||
type SettledHandle func(session *session.Enterprise, local string) *Settled
|
|
||||||
|
|
||||||
// SettledParams 绑定信息
|
|
||||||
type SettledParams struct {
|
|
||||||
Name, Image, Code, Introduce string // 唯一编码
|
|
||||||
config.Area
|
|
||||||
Industrys, Keywords []string
|
|
||||||
}
|
|
||||||
|
|
||||||
// effect 入驻信息有效性
|
|
||||||
func (c *SettledParams) effect(iModel model2.IModel, local string) error {
|
|
||||||
//var count int64
|
|
||||||
//
|
|
||||||
//if err := model2.Count(iModel, &count, model2.NewWhere("uid", uid)); err != nil {
|
|
||||||
// return err
|
|
||||||
//} else if count > 0 {
|
|
||||||
// return errors.New("无权限操作,当前身份下已含有申请入驻信息")
|
|
||||||
//}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// pass 入驻信息通过性
|
|
||||||
func (c *SettledParams) pass(identity int, mStatus model2.ExamineStatusKind) (bool, error) {
|
|
||||||
if mStatus != model2.ExamineStatusForRefuse {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter 筛选信息
|
|
||||||
func (c *Settled) filter(identity int, where ...*model2.ModelWhere) (bool, error) {
|
|
||||||
mSysIdentity := model.NewSysIdentity()
|
|
||||||
_, err := model2.FirstField(mSysIdentity.SysIdentity, []string{"id", "register_count", "is_examine"}, model2.NewWhere("identity", identity))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return true, err
|
|
||||||
}
|
|
||||||
var iModel model2.IModel
|
|
||||||
|
|
||||||
if identity&config.TenantUserIdentityForCompany > 0 {
|
|
||||||
iModel = model2.NewUserCompany()
|
|
||||||
} else if identity&config.TenantUserIdentityForExpert > 0 {
|
|
||||||
iModel = model2.NewUserExpert()
|
|
||||||
} else if identity&config.TenantUserIdentityForResearch > 0 {
|
|
||||||
iModel = model2.NewUserResearch()
|
|
||||||
} else if identity&config.TenantUserIdentityForLaboratory > 0 {
|
|
||||||
iModel = model2.NewUserLaboratory()
|
|
||||||
} else if identity&config.TenantUserIdentityForAgent > 0 {
|
|
||||||
iModel = model2.NewUserAgent()
|
|
||||||
}
|
|
||||||
var count int64
|
|
||||||
|
|
||||||
where = append(where, model2.NewWhere("status", model2.InvalidStatusForNot))
|
|
||||||
|
|
||||||
if err = model2.Count(iModel, &count, where...); err != nil {
|
|
||||||
return true, err
|
|
||||||
}
|
|
||||||
if count >= int64(mSysIdentity.RegisterCount) {
|
|
||||||
return true, errors.New("操作错误,已超过当前身份最大入驻人数")
|
|
||||||
}
|
|
||||||
return mSysIdentity.IsExamine == model2.SysIdentityExamineForYes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
//// Company 公司企业
|
|
||||||
//func (c *Settled) Company(params *SettledParams, inviterID uint64, other *config.IdentityForCompany) error {
|
|
||||||
// mManageCompany := model.NewManageCompany()
|
|
||||||
//
|
|
||||||
// isExist, err := model2.FirstField(mManageCompany.ManageCompany, []string{"id", "status"},
|
|
||||||
// model2.NewWhere("code", params.Code), model2.NewWhere("local", c.local),
|
|
||||||
// model2.NewWhere("status", model2.ExamineStatusForRefuse))
|
|
||||||
//
|
|
||||||
// isExamine := true
|
|
||||||
//
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// } else if isExist {
|
|
||||||
// if mManageCompany.ExamineStatus == model2.ExamineStatusForOngoing {
|
|
||||||
// return errors.New("操作错误,当前企业信息审核中,不可入驻")
|
|
||||||
// }
|
|
||||||
// // 筛选企业条件
|
|
||||||
// if isExamine, err = c.filter(config.TenantUserIdentityForCompany, model2.NewWhere("company_id", mManageCompany.ID)); err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// mManageCompany.Local.Local = c.local
|
|
||||||
// mManageCompany.InviterID = inviterID
|
|
||||||
// mManageCompany.Name = params.Name
|
|
||||||
// mManageCompany.Code = params.Code
|
|
||||||
// mManageCompany.Image = model2.Image{Image: params.Image}
|
|
||||||
// mManageCompany.Area = model2.Area{
|
|
||||||
// Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
|
|
||||||
// }
|
|
||||||
// mManageCompany.Url = other.Url
|
|
||||||
// mManageCompany.SetIndustryAttribute(params.Industrys)
|
|
||||||
// mManageCompany.SetKeywordAttribute(params.Keywords)
|
|
||||||
// mManageCompany.Introduce = params.Introduce
|
|
||||||
//
|
|
||||||
// if isExamine {
|
|
||||||
// mManageCompany.ExamineStatus = model2.ExamineStatusForAgree
|
|
||||||
// }
|
|
||||||
// return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
|
||||||
// if mManageCompany.ID <= 0 {
|
|
||||||
// if err = model2.Create(mManageCompany.ManageCompany, tx); err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// // 过滤用户其他公司入驻信息
|
|
||||||
// mUserCompany := model.NewUserCompany()
|
|
||||||
//
|
|
||||||
// if err := model2.UpdatesWhere(mUserCompany.UserCompany, map[string]interface{}{
|
|
||||||
// "status": model2.InvalidStatusForYes, "updated_at": time.Now(),
|
|
||||||
// }, []*model2.ModelWhere{model2.NewWhere("uid", c.UID)}, tx); err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// mUserCompany.UID = c.UID
|
|
||||||
// mUserCompany.CompanyID = mManageCompany.ID
|
|
||||||
// return model2.Create(mUserCompany.UserCompany, tx)
|
|
||||||
// })
|
|
||||||
//}
|
|
||||||
|
|
||||||
//
|
|
||||||
//// Expert 专家
|
|
||||||
//func (c *Settled) Expert(params *SettledParams, other *config.IdentityForExpert) error {
|
|
||||||
// mManageExpert := model3.NewManageExpert()
|
|
||||||
//
|
|
||||||
// err := params.effect(c.UID, mManageExpert.ManageExpert)
|
|
||||||
//
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// mManageExpert.Area = model2.Area{
|
|
||||||
// Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
|
|
||||||
// }
|
|
||||||
// mManageExpert.SetIndustryAttribute(params.Industrys)
|
|
||||||
// mManageExpert.SetKeywordAttribute(params.Keywords)
|
|
||||||
// mManageExpert.Introduce = params.Introduce
|
|
||||||
// mManageExpert.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude})
|
|
||||||
// mManageExpert.School = other.School
|
|
||||||
// mManageExpert.Major = other.Major
|
|
||||||
// mManageExpert.Job = other.Job
|
|
||||||
// mManageExpert.Title = other.Title
|
|
||||||
// mManageExpert.WorkAt = utils.DataTimeToDate(other.WorkAt)
|
|
||||||
// mManageExpert.Research = utils.AnyToJSON(other.Research)
|
|
||||||
//
|
|
||||||
// if mManageExpert.ID <= 0 {
|
|
||||||
// mManageExpert.UID = c.UID
|
|
||||||
// return model2.Create(mManageExpert.ManageExpert)
|
|
||||||
// }
|
|
||||||
// if !params.pass(c.UID, mManageExpert.UID, mManageExpert.Status) {
|
|
||||||
// return errors.New("操作错误,无权限操作")
|
|
||||||
// }
|
|
||||||
// mManageExpert.Status = model2.ExamineStatusForOngoing
|
|
||||||
// return model2.Updates(mManageExpert.ManageExpert, mManageExpert.ManageExpert)
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//// Research 研究机构
|
|
||||||
//func (c *Settled) Research(params *SettledParams, other *config.IdentityForResearch) error {
|
|
||||||
// mManageResearch := model3.NewManageResearch()
|
|
||||||
//
|
|
||||||
// err := params.effect(c.UID, mManageResearch.ManageResearch)
|
|
||||||
//
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// mManageResearch.Area = model2.Area{
|
|
||||||
// Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
|
|
||||||
// }
|
|
||||||
// mManageResearch.Industry = params.Industrys
|
|
||||||
// mManageResearch.SetKeywordAttribute(params.Keywords)
|
|
||||||
// mManageResearch.Introduce = params.Introduce
|
|
||||||
// mManageResearch.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude})
|
|
||||||
// mManageResearch.Research = other.Research
|
|
||||||
//
|
|
||||||
// if mManageResearch.ID <= 0 {
|
|
||||||
// mManageResearch.UID = c.UID
|
|
||||||
// return model2.Create(mManageResearch.ManageResearch)
|
|
||||||
// }
|
|
||||||
// if !params.pass(c.UID, mManageResearch.UID, mManageResearch.Status) {
|
|
||||||
// return errors.New("操作错误,无权限操作")
|
|
||||||
// }
|
|
||||||
// mManageResearch.Status = model2.ExamineStatusForOngoing
|
|
||||||
// return model2.Updates(mManageResearch.ManageResearch, mManageResearch.ManageResearch)
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//// Laboratory 实验室
|
|
||||||
//func (c *Settled) Laboratory(params *SettledParams, other *config.IdentityForLaboratory) error {
|
|
||||||
// mManageLaboratory := model3.NewManageLaboratory()
|
|
||||||
//
|
|
||||||
// err := params.effect(c.UID, mManageLaboratory.ManageLaboratory)
|
|
||||||
//
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// 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,
|
|
||||||
// }
|
|
||||||
// mManageLaboratory.Industry = params.Industrys
|
|
||||||
// mManageLaboratory.SetKeywordAttribute(params.Keywords)
|
|
||||||
// mManageLaboratory.Introduce = params.Introduce
|
|
||||||
// mManageLaboratory.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude})
|
|
||||||
// mManageLaboratory.Research = utils.AnyToJSON(other.Research)
|
|
||||||
//
|
|
||||||
// if mManageLaboratory.ID <= 0 {
|
|
||||||
// mManageLaboratory.UID = c.UID
|
|
||||||
// return model2.Create(mManageLaboratory.ManageLaboratory)
|
|
||||||
// }
|
|
||||||
// if !params.pass(c.UID, mManageLaboratory.UID, mManageLaboratory.Status) {
|
|
||||||
// return errors.New("操作错误,无权限操作")
|
|
||||||
// }
|
|
||||||
// mManageLaboratory.Status = model2.ExamineStatusForOngoing
|
|
||||||
// return model2.Updates(mManageLaboratory.ManageLaboratory, mManageLaboratory.ManageLaboratory)
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//// Agent 经纪人
|
|
||||||
//func (c *Settled) Agent(params *SettledParams) error {
|
|
||||||
// return nil
|
|
||||||
//}
|
|
||||||
|
|
||||||
func NewSettled() SettledHandle {
|
|
||||||
return func(session *session.Enterprise, local string) *Settled {
|
|
||||||
return &Settled{Enterprise: session, local: local}
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,7 +10,14 @@ type UserAgent struct {
|
|||||||
*model.UserAgent
|
*model.UserAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *UserAgent) Agent(uid uint64) (*UserSettledInfo, error) {
|
type (
|
||||||
|
UserAgentInfo struct {
|
||||||
|
UserAgentID uint64 `json:"-"`
|
||||||
|
*model.ManageAgent
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m *UserAgent) Settled(uid uint64) (*UserSettledInfo, error) {
|
||||||
out := new(UserSettledInfo)
|
out := new(UserSettledInfo)
|
||||||
|
|
||||||
err := orm.GetDB().Table(m.TableName()+" AS u").
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
@ -22,6 +29,19 @@ func (m *UserAgent) Agent(uid uint64) (*UserSettledInfo, error) {
|
|||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Agent 经纪人信息
|
||||||
|
func (m *UserAgent) Agent(uid uint64) (*UserAgentInfo, error) {
|
||||||
|
out := new(UserAgentInfo)
|
||||||
|
|
||||||
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
|
Select("u.id AS user_agent_id", "c.*").
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON u.agent_id = c.id", model.NewManageAgent().TableName())).
|
||||||
|
Where("u.uid = ?", uid).
|
||||||
|
Where("u.is_deleted = ? AND u.invalid_status = ?", model.DeleteStatusForNot, model.InvalidStatusForNot).
|
||||||
|
Scan(out).Error
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
func NewUserAgent() *UserAgent {
|
func NewUserAgent() *UserAgent {
|
||||||
return &UserAgent{model.NewUserAgent()}
|
return &UserAgent{model.NewUserAgent()}
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,19 @@ type UserCompany struct {
|
|||||||
*model.UserCompany
|
*model.UserCompany
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserSettledInfo struct {
|
type (
|
||||||
ID uint64 `json:"id"`
|
UserSettledInfo struct {
|
||||||
*model.Examine
|
ID uint64 `json:"id"`
|
||||||
}
|
*model.Examine
|
||||||
|
}
|
||||||
|
UserCompanyInfo struct {
|
||||||
|
*model.ManageCompany
|
||||||
|
UserCompanyID uint64 `json-"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// Company 公司信息
|
// Settled 入驻信息
|
||||||
func (m *UserCompany) Company(uid uint64) (*UserSettledInfo, error) {
|
func (m *UserCompany) Settled(uid uint64) (*UserSettledInfo, error) {
|
||||||
out := new(UserSettledInfo)
|
out := new(UserSettledInfo)
|
||||||
|
|
||||||
err := orm.GetDB().Table(m.TableName()+" AS u").
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
@ -28,6 +34,19 @@ func (m *UserCompany) Company(uid uint64) (*UserSettledInfo, error) {
|
|||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Company 公司信息
|
||||||
|
func (m *UserCompany) Company(uid uint64) (*UserCompanyInfo, error) {
|
||||||
|
out := new(UserCompanyInfo)
|
||||||
|
|
||||||
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
|
Select("u.id AS user_company_id", "c.*").
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON u.company_id = c.id", model.NewManageCompany().TableName())).
|
||||||
|
Where("u.uid = ?", uid).
|
||||||
|
Where("u.is_deleted = ? AND u.invalid_status = ?", model.DeleteStatusForNot, model.InvalidStatusForNot).
|
||||||
|
Scan(out).Error
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
func NewUserCompany() *UserCompany {
|
func NewUserCompany() *UserCompany {
|
||||||
return &UserCompany{model.NewUserCompany()}
|
return &UserCompany{model.NewUserCompany()}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,15 @@ type UserExpert struct {
|
|||||||
*model.UserExpert
|
*model.UserExpert
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *UserExpert) Expert(uid uint64) (*UserSettledInfo, error) {
|
type (
|
||||||
|
// UserExpertInfo 专家信息
|
||||||
|
UserExpertInfo struct {
|
||||||
|
UserExpertID uint64 `json:"-"`
|
||||||
|
*model.ManageExpert
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m *UserExpert) Settled(uid uint64) (*UserSettledInfo, error) {
|
||||||
out := new(UserSettledInfo)
|
out := new(UserSettledInfo)
|
||||||
|
|
||||||
err := orm.GetDB().Table(m.TableName()+" AS u").
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
@ -22,6 +30,19 @@ func (m *UserExpert) Expert(uid uint64) (*UserSettledInfo, error) {
|
|||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Expert 专家信息
|
||||||
|
func (m *UserExpert) Expert(uid uint64) (*UserExpertInfo, error) {
|
||||||
|
out := new(UserExpertInfo)
|
||||||
|
|
||||||
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
|
Select("u.id AS user_expert_id", "c.*").
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON u.expert_id = c.id", model.NewManageExpert().TableName())).
|
||||||
|
Where("u.uid = ?", uid).
|
||||||
|
Where("u.is_deleted = ? AND u.invalid_status = ?", model.DeleteStatusForNot, model.InvalidStatusForNot).
|
||||||
|
Scan(out).Error
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
func NewUserExpert() *UserExpert {
|
func NewUserExpert() *UserExpert {
|
||||||
return &UserExpert{model.NewUserExpert()}
|
return &UserExpert{model.NewUserExpert()}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,14 @@ type UserLaboratory struct {
|
|||||||
*model.UserLaboratory
|
*model.UserLaboratory
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *UserLaboratory) Laboratory(uid uint64) (*UserSettledInfo, error) {
|
type (
|
||||||
|
UserLaboratoryInfo struct {
|
||||||
|
UserLaboratoryID uint64 `json:"-"`
|
||||||
|
*model.ManageLaboratory
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m *UserLaboratory) Settled(uid uint64) (*UserSettledInfo, error) {
|
||||||
out := new(UserSettledInfo)
|
out := new(UserSettledInfo)
|
||||||
|
|
||||||
err := orm.GetDB().Table(m.TableName()+" AS u").
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
@ -22,6 +29,18 @@ func (m *UserLaboratory) Laboratory(uid uint64) (*UserSettledInfo, error) {
|
|||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *UserLaboratory) Laboratory(uid uint64) (*UserLaboratoryInfo, error) {
|
||||||
|
out := new(UserLaboratoryInfo)
|
||||||
|
|
||||||
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
|
Select("u.id AS user_laboratory_id", "c.*").
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON u.laboratory_id = c.id", model.NewManageLaboratory().TableName())).
|
||||||
|
Where("u.uid = ?", uid).
|
||||||
|
Where("u.is_deleted = ? AND u.invalid_status = ?", model.DeleteStatusForNot, model.InvalidStatusForNot).
|
||||||
|
Scan(out).Error
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
func NewUserLaboratory() *UserLaboratory {
|
func NewUserLaboratory() *UserLaboratory {
|
||||||
return &UserLaboratory{model.NewUserLaboratory()}
|
return &UserLaboratory{model.NewUserLaboratory()}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,14 @@ type UserResearch struct {
|
|||||||
*model.UserResearch
|
*model.UserResearch
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *UserResearch) Research(uid uint64) (*UserSettledInfo, error) {
|
type (
|
||||||
|
UserResearchInfo struct {
|
||||||
|
UserResearchID uint64 `json:"-"`
|
||||||
|
*model.ManageResearch
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m *UserResearch) Settled(uid uint64) (*UserSettledInfo, error) {
|
||||||
out := new(UserSettledInfo)
|
out := new(UserSettledInfo)
|
||||||
|
|
||||||
err := orm.GetDB().Table(m.TableName()+" AS u").
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
@ -22,6 +29,18 @@ func (m *UserResearch) Research(uid uint64) (*UserSettledInfo, error) {
|
|||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *UserResearch) Research(uid uint64) (*UserResearchInfo, error) {
|
||||||
|
out := new(UserResearchInfo)
|
||||||
|
|
||||||
|
err := orm.GetDB().Table(m.TableName()+" AS u").
|
||||||
|
Select("u.id AS user_research_id", "c.*").
|
||||||
|
Joins(fmt.Sprintf("LEFT JOIN %s AS c ON u.research_id = c.id", model.NewManageResearch().TableName())).
|
||||||
|
Where("u.uid = ?", uid).
|
||||||
|
Where("u.is_deleted = ? AND u.invalid_status = ?", model.DeleteStatusForNot, model.InvalidStatusForNot).
|
||||||
|
Scan(out).Error
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
func NewUserResearch() *UserResearch {
|
func NewUserResearch() *UserResearch {
|
||||||
return &UserResearch{model.NewUserResearch()}
|
return &UserResearch{model.NewUserResearch()}
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,7 @@ func (this *Serve) Run() {
|
|||||||
// })
|
// })
|
||||||
//})
|
//})
|
||||||
cache.Init()
|
cache.Init()
|
||||||
orm.NewInstance(
|
orm.NewInstance(orm.WithDebug(config.SettingInfo.Engine.Debug),
|
||||||
orm.WithDebug(config.SettingInfo.Engine.Debug),
|
|
||||||
orm.WithDBMode(config.SettingInfo.Engine.DBMode),
|
orm.WithDBMode(config.SettingInfo.Engine.DBMode),
|
||||||
orm.WithTablePrefix(config.SettingInfo.Engine.TablePrefix),
|
orm.WithTablePrefix(config.SettingInfo.Engine.TablePrefix),
|
||||||
orm.WithSingularTable(!config.SettingInfo.Engine.Complex),
|
orm.WithSingularTable(!config.SettingInfo.Engine.Complex),
|
||||||
@ -70,7 +69,10 @@ func (this *Serve) Run() {
|
|||||||
app.Init()
|
app.Init()
|
||||||
tools.Init()
|
tools.Init()
|
||||||
// 开启Elasticsearch
|
// 开启Elasticsearch
|
||||||
es.NewEs()(&es.EsConfig{Address: []string{"http://192.168.0.188:9200"}}).Run()
|
es.NewInstance(es.WithEsAddress([]string{""}),
|
||||||
|
es.WithEsUsername(""),
|
||||||
|
es.WithEsPassword(""),
|
||||||
|
).Init().Local()
|
||||||
// 开启web
|
// 开启web
|
||||||
web.NewWeb()(&web.WebConfig{
|
web.NewWeb()(&web.WebConfig{
|
||||||
Port: config.SettingInfo.Server.Port, ReadTimeout: config.SettingInfo.Server.ReadTimeout,
|
Port: config.SettingInfo.Server.Port, ReadTimeout: config.SettingInfo.Server.ReadTimeout,
|
||||||
|
@ -1,32 +1,71 @@
|
|||||||
package es
|
package es
|
||||||
|
|
||||||
import "github.com/elastic/go-elasticsearch/v7"
|
import (
|
||||||
|
"github.com/elastic/go-elasticsearch/v7"
|
||||||
|
)
|
||||||
|
|
||||||
type Es struct{ *EsConfig }
|
type Instance struct {
|
||||||
|
client *elasticsearch.Client
|
||||||
|
|
||||||
type EsConfig struct {
|
address []string
|
||||||
Address []string
|
username, password string
|
||||||
}
|
}
|
||||||
|
|
||||||
type EsServer func(*EsConfig) *Es
|
type Option func(*Instance)
|
||||||
|
|
||||||
var esClient = new(elasticsearch.Client)
|
var (
|
||||||
|
client *elasticsearch.Client
|
||||||
|
)
|
||||||
|
|
||||||
func (this *Es) Run() {
|
func WithEsAddress(address []string) Option {
|
||||||
|
return func(instance *Instance) {
|
||||||
|
instance.address = address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithEsUsername(username string) Option {
|
||||||
|
return func(instance *Instance) {
|
||||||
|
instance.username = username
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithEsPassword(password string) Option {
|
||||||
|
return func(instance *Instance) {
|
||||||
|
instance.password = password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Instance) Init() *Instance {
|
||||||
obj := elasticsearch.Config{
|
obj := elasticsearch.Config{
|
||||||
Addresses: this.Address,
|
Addresses: this.address,
|
||||||
Username: "",
|
Username: this.username,
|
||||||
Password: "",
|
Password: this.password,
|
||||||
}
|
}
|
||||||
var err error
|
client, err := elasticsearch.NewClient(obj)
|
||||||
|
|
||||||
if esClient, err = elasticsearch.NewClient(obj); err != nil {
|
if err != nil {
|
||||||
panic("Elasticsearch Error " + err.Error())
|
panic("Elasticsearch New Error " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err = client.Ping(); err != nil {
|
||||||
|
panic("Elasticsearch Ping Error " + err.Error())
|
||||||
|
|
||||||
|
}
|
||||||
|
this.client = client
|
||||||
|
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEs() EsServer {
|
func (this *Instance) Local() *Instance {
|
||||||
return func(config *EsConfig) *Es {
|
client = this.client
|
||||||
return &Es{config}
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewInstance(option ...Option) *Instance {
|
||||||
|
instance := new(Instance)
|
||||||
|
|
||||||
|
for _, v := range option {
|
||||||
|
v(instance)
|
||||||
|
}
|
||||||
|
return instance
|
||||||
}
|
}
|
||||||
|
23
serve/es/es_test.go
Normal file
23
serve/es/es_test.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package es
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
dataIndex = "test"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewInstance(t *testing.T) {
|
||||||
|
NewInstance(
|
||||||
|
WithEsAddress([]string{"http://192.168.0.188:9200"}),
|
||||||
|
).Init().Local()
|
||||||
|
var b strings.Builder
|
||||||
|
b.WriteString(`{"title" : "`)
|
||||||
|
b.WriteString("我是好人")
|
||||||
|
b.WriteString(`"}`)
|
||||||
|
resp, err := client.Create(dataIndex, "2", strings.NewReader(b.String()))
|
||||||
|
t.Log(err)
|
||||||
|
t.Log(resp)
|
||||||
|
}
|
@ -1,5 +1,10 @@
|
|||||||
package es
|
package es
|
||||||
|
|
||||||
func Set() {
|
func Create() error {
|
||||||
esClient.Search()
|
//_, err := client.Index().
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Search() {
|
||||||
|
//resp, err := client.Search()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user