feat:完善入驻信息管理

This commit is contained in:
henry
2021-12-01 17:14:12 +08:00
parent 3abfe92add
commit 88077da6f0
10 changed files with 174 additions and 67 deletions

View File

@ -13,13 +13,12 @@ type User struct{}
type ( type (
// userSettledForm 入驻平台参数 // userSettledForm 入驻平台参数
userSettledForm struct { userSettledForm struct {
api.IDStringForm
api.ImageForm api.ImageForm
Name string `json:"name" form:"name"` Name string `json:"name" form:"name"`
Code string `json:"code" form:"code"` Code string `json:"code" form:"code"`
config.Area config.Area
Introduce string `json:"introduce" form:"introduce"` Introduce string `json:"introduce" form:"introduce"`
Industry string `json:"industry" form:"industry"` // 行业领域 Industrys []string `json:"industrys" form:"industrys"` // 行业领域
Keywords []string `json:"keywords" form:"keywords"` Keywords []string `json:"keywords" form:"keywords"`
} }
// userBankForm 银行平台信息参数 // userBankForm 银行平台信息参数
@ -52,6 +51,7 @@ func (*User) BindMobile(c *gin.Context) {
func (*User) SettledCompany(c *gin.Context) { func (*User) SettledCompany(c *gin.Context) {
form := &struct { form := &struct {
InviteCode string `json:"invite_code" form:"invite_code"`
userSettledForm userSettledForm
}{} }{}
if err := api.Bind(form)(c); err != nil { if err := api.Bind(form)(c); err != nil {
@ -59,9 +59,9 @@ func (*User) SettledCompany(c *gin.Context) {
return return
} }
err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Company(&user.SettledParams{ err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Company(&user.SettledParams{
ID: form.Convert(), Image: form.FilterImageURL(), Name: form.Name, Code: form.Code, Image: form.FilterImageURL(), Name: form.Name, Code: form.Code,
Area: form.Area, Introduce: form.Introduce, Industry: form.Industry, Keywords: form.Keywords, Area: form.Area, Introduce: form.Introduce, Industrys: form.Industrys, Keywords: form.Keywords,
}, nil) }, (&api.IDStringForm{ID: form.InviteCode}).Convert(), nil)
api.APIResponse(err)(c) api.APIResponse(err)(c)
} }
@ -75,7 +75,7 @@ func (*User) SettledExpert(c *gin.Context) {
return return
} }
err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Expert(&user.SettledParams{ err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Expert(&user.SettledParams{
ID: form.Convert(), Area: form.Area, Introduce: form.Introduce, Industry: form.Industry, Area: form.Area, Introduce: form.Introduce, Industrys: form.Industrys,
Keywords: form.Keywords, Keywords: form.Keywords,
}, &form.IdentityForExpert) }, &form.IdentityForExpert)
api.APIResponse(err)(c) api.APIResponse(err)(c)
@ -91,8 +91,8 @@ func (*User) SettledResearch(c *gin.Context) {
return return
} }
err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Research(&user.SettledParams{ err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Research(&user.SettledParams{
ID: form.Convert(), Image: form.FilterImageURL(), Name: form.Name, Code: form.Code, Image: form.FilterImageURL(), Name: form.Name, Code: form.Code,
Area: form.Area, Introduce: form.Introduce, Industry: form.Industry, Keywords: form.Keywords, Area: form.Area, Introduce: form.Introduce, Industrys: form.Industrys, Keywords: form.Keywords,
}, &form.IdentityForResearch) }, &form.IdentityForResearch)
api.APIResponse(err)(c) api.APIResponse(err)(c)
} }
@ -107,14 +107,15 @@ func (*User) SettledLaboratory(c *gin.Context) {
return return
} }
err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Laboratory(&user.SettledParams{ err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Laboratory(&user.SettledParams{
ID: form.Convert(), Image: form.FilterImageURL(), Name: form.Name, Code: form.Code, Image: form.FilterImageURL(), Name: form.Name, Code: form.Code,
Area: form.Area, Introduce: form.Introduce, Industry: form.Industry, Keywords: form.Keywords, Area: form.Area, Introduce: form.Introduce, Industrys: form.Industrys, Keywords: form.Keywords,
}, &form.IdentityForLaboratory) }, &form.IdentityForLaboratory)
api.APIResponse(err)(c) api.APIResponse(err)(c)
} }
func (*User) SettledAgent(c *gin.Context) { func (*User) SettledAgent(c *gin.Context) {
form := &struct { form := &struct {
api.IDStringForm
userSettledForm userSettledForm
}{} }{}
if err := api.Bind(form)(c); err != nil { if err := api.Bind(form)(c); err != nil {
@ -123,7 +124,7 @@ func (*User) SettledAgent(c *gin.Context) {
} }
err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Agent(&user.SettledParams{ err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Agent(&user.SettledParams{
ID: form.Convert(), Image: form.FilterImageURL(), Name: form.Name, Code: form.Code, ID: form.Convert(), Image: form.FilterImageURL(), Name: form.Name, Code: form.Code,
Area: form.Area, Introduce: form.Introduce, Industry: form.Industry, Keywords: form.Keywords, Area: form.Area, Introduce: form.Introduce, Industrys: form.Industrys, Keywords: form.Keywords,
}) })
api.APIResponse(err)(c) api.APIResponse(err)(c)
} }

View File

@ -1,86 +1,134 @@
package user package user
import ( import (
model3 "SciencesServer/app/api/enterprise/model" "SciencesServer/app/api/enterprise/model"
model3 "SciencesServer/app/api/manage/model"
"SciencesServer/app/basic/config" "SciencesServer/app/basic/config"
model2 "SciencesServer/app/common/model" model2 "SciencesServer/app/common/model"
"SciencesServer/app/session" "SciencesServer/app/session"
"SciencesServer/serve/orm"
"SciencesServer/utils" "SciencesServer/utils"
"errors" "errors"
"gorm.io/gorm"
) )
// Settled 入驻 // Settled 入驻
type Settled struct{ *session.Enterprise } type Settled struct {
*session.Enterprise
local string
}
type SettledHandle func(session *session.Enterprise) *Settled type SettledHandle func(session *session.Enterprise, local string) *Settled
// SettledParams 绑定信息
type SettledParams struct { type SettledParams struct {
ID uint64 Name, Image, Code, Introduce string // 唯一编码
Image string // logo图片
Name string // 名称
Code string // 唯一编码
config.Area config.Area
Introduce string Industrys, Keywords []string
Industry string `json:"industry"`
Keywords []string `json:"keywords"`
} }
// effect 入驻信息有效性 // effect 入驻信息有效性
func (c *SettledParams) effect(uid uint64, iModel model2.IModel) error { func (c *SettledParams) effect(iModel model2.IModel, local string) error {
if c.ID <= 0 { //var count int64
var count int64 //
//if err := model2.Count(iModel, &count, model2.NewWhere("uid", uid)); err != nil {
if err := model2.Count(iModel, &count, model2.NewWhere("uid", uid)); err != nil { // return err
return err //} else if count > 0 {
} else if count > 0 { // return errors.New("无权限操作,当前身份下已含有申请入驻信息")
return errors.New("无权限操作,当前身份下已含有申请入驻信息") //}
}
return nil
}
if isExist, err := model2.FirstField(iModel, []string{"id", "uid", "status"}, model2.NewWhere("id", c.ID)); err != nil {
return err
} else if !isExist {
return errors.New("无权限操作,未知的入驻信息")
}
return nil return nil
} }
// pass 入驻信息通过性 // pass 入驻信息通过性
func (c *SettledParams) pass(uid, mUID uint64, mStatus model2.ExamineStatusKind) bool { func (c *SettledParams) pass(identity int, mStatus model2.ExamineStatusKind) (bool, error) {
if mUID != uid || mStatus != model2.ExamineStatusForRefuse { if mStatus != model2.ExamineStatusForRefuse {
return false return false, nil
} }
return true 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 公司企业 // Company 公司企业
func (c *Settled) Company(params *SettledParams, other *config.IdentityForCompany) error { func (c *Settled) Company(params *SettledParams, inviterID uint64, other *config.IdentityForCompany) error {
mManageCompany := model3.NewManageCompany() mManageCompany := model.NewManageCompany()
err := params.effect(c.UID, mManageCompany.ManageCompany) 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 { if err != nil {
return err return err
} else if isExist {
if mManageCompany.Status == 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.Name = params.Name
mManageCompany.Code = params.Code mManageCompany.Code = params.Code
mManageCompany.Image = model2.Image{Image: params.Image} mManageCompany.Image = model2.Image{Image: params.Image}
mManageCompany.Area = model2.Area{ mManageCompany.Area = model2.Area{
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address, Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
} }
mManageCompany.Industry = params.Industry mManageCompany.WebUrl = other.WebUrl
mManageCompany.SetIndustryAttribute(params.Industrys)
mManageCompany.SetKeywordAttribute(params.Keywords) mManageCompany.SetKeywordAttribute(params.Keywords)
mManageCompany.Introduce = params.Introduce mManageCompany.Introduce = params.Introduce
if isExamine {
mManageCompany.Status = model2.ExamineStatusForAgree
}
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
if mManageCompany.ID <= 0 { if mManageCompany.ID <= 0 {
mManageCompany.UID = c.UID if err = model2.Create(mManageCompany.ManageCompany, tx); err != nil {
return model2.Create(mManageCompany.ManageCompany) return err
} }
if !params.pass(c.UID, mManageCompany.UID, mManageCompany.Status) {
return errors.New("操作错误,无权限操作")
} }
mManageCompany.Status = model2.ExamineStatusForOngoing mUserCompany := model.NewUserCompany()
return model2.Updates(mManageCompany.ManageCompany, mManageCompany.ManageCompany) mUserCompany.UID = c.UID
mUserCompany.CompanyID = mManageCompany.ID
return model2.Create(mUserCompany.UserCompany, tx)
})
} }
// Expert 专家 // Expert 专家
@ -95,7 +143,7 @@ func (c *Settled) Expert(params *SettledParams, other *config.IdentityForExpert)
mManageExpert.Area = model2.Area{ mManageExpert.Area = model2.Area{
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address, Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
} }
mManageExpert.Industry = params.Industry mManageExpert.SetIndustryAttribute(params.Industrys)
mManageExpert.SetKeywordAttribute(params.Keywords) mManageExpert.SetKeywordAttribute(params.Keywords)
mManageExpert.Introduce = params.Introduce mManageExpert.Introduce = params.Introduce
mManageExpert.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude}) mManageExpert.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude})
@ -129,7 +177,7 @@ func (c *Settled) Research(params *SettledParams, other *config.IdentityForResea
mManageResearch.Area = model2.Area{ mManageResearch.Area = model2.Area{
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address, Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
} }
mManageResearch.Industry = params.Industry mManageResearch.Industry = params.Industrys
mManageResearch.SetKeywordAttribute(params.Keywords) mManageResearch.SetKeywordAttribute(params.Keywords)
mManageResearch.Introduce = params.Introduce mManageResearch.Introduce = params.Introduce
mManageResearch.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude}) mManageResearch.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude})
@ -160,7 +208,7 @@ func (c *Settled) Laboratory(params *SettledParams, other *config.IdentityForLab
mManageLaboratory.Area = model2.Area{ mManageLaboratory.Area = model2.Area{
Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address, Province: params.Area.Province, City: params.Area.City, District: params.Area.District, Address: params.Area.Address,
} }
mManageLaboratory.Industry = params.Industry mManageLaboratory.Industry = params.Industrys
mManageLaboratory.SetKeywordAttribute(params.Keywords) mManageLaboratory.SetKeywordAttribute(params.Keywords)
mManageLaboratory.Introduce = params.Introduce mManageLaboratory.Introduce = params.Introduce
mManageLaboratory.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude}) mManageLaboratory.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude})
@ -183,7 +231,7 @@ func (c *Settled) Agent(params *SettledParams) error {
} }
func NewSettled() SettledHandle { func NewSettled() SettledHandle {
return func(session *session.Enterprise) *Settled { return func(session *session.Enterprise, local string) *Settled {
return &Settled{Enterprise: session} return &Settled{Enterprise: session, local: local}
} }
} }

View File

@ -0,0 +1,11 @@
package model
import "SciencesServer/app/common/model"
type SysIdentity struct {
*model.SysIdentity
}
func NewSysIdentity() *SysIdentity {
return &SysIdentity{model.NewSysIdentity()}
}

View File

@ -0,0 +1,11 @@
package model
import "SciencesServer/app/common/model"
type UserCompany struct {
*model.UserCompany
}
func NewUserCompany() *UserCompany {
return &UserCompany{model.NewUserCompany()}
}

View File

@ -10,7 +10,9 @@ type Area struct {
type ( type (
// IdentityForCompany 公司附加信息 // IdentityForCompany 公司附加信息
IdentityForCompany struct{} IdentityForCompany struct {
WebUrl string `json:"web_url" form:"web_url"`
}
// IdentityForExpert 专家附加信息 // IdentityForExpert 专家附加信息
IdentityForExpert struct { IdentityForExpert struct {
TenantID uint64 `json:"tenant_id" form:"tenant_id"` TenantID uint64 `json:"tenant_id" form:"tenant_id"`

View File

@ -103,6 +103,21 @@ const (
ExamineStatusForRefuse ExamineStatusForRefuse
) )
// InvalidStatus 失效状态
type InvalidStatus struct {
Status ExamineStatusKind `gorm:"column:status;type:tinyint(1);default:0;comment:失效状态0未失效1已失效" json:"status"`
}
// InvalidStatusKind 失效状态
type InvalidStatusKind int
const (
// InvalidStatusForNot 未失效
InvalidStatusForNot InvalidStatusKind = iota
// InvalidStatusForYes 已失效
InvalidStatusForYes
)
type Area struct { type Area struct {
Province string `gorm:"column:province;type:varchar(8);default:null;comment:所在省" json:"province"` Province string `gorm:"column:province;type:varchar(8);default:null;comment:所在省" json:"province"`
City string `gorm:"column:city;type:varchar(8);default:null;comment:所在市" json:"city"` City string `gorm:"column:city;type:varchar(8);default:null;comment:所在市" json:"city"`

View File

@ -6,12 +6,13 @@ import "SciencesServer/utils"
type ManageCompany struct { type ManageCompany struct {
Model Model
Local Local
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"` InviterID uint64 `gorm:"column:inviter_id;type:int;default:0;comment:邀请人ID" json:"inviter_id"`
Name string `gorm:"column:name;type:varchar(30);default:null;comment:名称" json:"name"` Name string `gorm:"column:name;type:varchar(30);default:null;comment:名称" json:"name"`
Code string `gorm:"column:code;type:varchar(30);default:null;comment:信用代码" json:"code"` Code string `gorm:"column:code;type:varchar(30);default:null;comment:信用代码" json:"code"`
Image Image
Area Area
Industry string `gorm:"column:industry;type:varchar(255);default:0;comment:行业领域" json:"industry"` WebUrl string `gorm:"column:web_url;type:varchar(255);default:null;comment:企业网站" json:"web_url"`
Industry string `gorm:"column:industry;type:varchar(255);default:null;comment:行业领域" json:"industry"`
Keyword string `gorm:"column:keyword;type:varchar(255);default:null;comment:关键词" json:"keyword"` Keyword string `gorm:"column:keyword;type:varchar(255);default:null;comment:关键词" json:"keyword"`
Introduce string `gorm:"column:introduce;type:text;comment:介绍描述" json:"introduce"` Introduce string `gorm:"column:introduce;type:text;comment:介绍描述" json:"introduce"`
ExamineStatus ExamineStatus

View File

@ -30,6 +30,16 @@ func (m *ManageExpert) TableName() string {
return "manage_expert" return "manage_expert"
} }
func (m *ManageExpert) GetIndustryAttribute() []string {
out := make([]string, 0)
_ = utils.FromJSON(m.Industry, &out)
return out
}
func (m *ManageExpert) SetIndustryAttribute(value []string) {
m.Industry = utils.AnyToJSON(value)
}
func (m *ManageExpert) GetKeywordAttribute() []string { func (m *ManageExpert) GetKeywordAttribute() []string {
keywords := make([]string, 0) keywords := make([]string, 0)
_ = utils.FromJSON(m.Keyword, &keywords) _ = utils.FromJSON(m.Keyword, &keywords)

View File

@ -6,11 +6,18 @@ type SysIdentity struct {
Identity int `gorm:"column:identity;uniqueIndex:idx_sys_identity;type:tinyint(3);default:0;comment:身份信息" json:"identity"` Identity int `gorm:"column:identity;uniqueIndex:idx_sys_identity;type:tinyint(3);default:0;comment:身份信息" json:"identity"`
Name string `gorm:"column:name;type:varchar(20);default:null;comment:身份名称" json:"name"` Name string `gorm:"column:name;type:varchar(20);default:null;comment:身份名称" json:"name"`
RegisterCount int `gorm:"column:register_count;type:tinyint(3);default:0;comment:每个平台下可以最大注册人数,-1不作限制" json:"register_count"` RegisterCount int `gorm:"column:register_count;type:tinyint(3);default:0;comment:每个平台下可以最大注册人数,-1不作限制" json:"register_count"`
IsExamine int `gorm:"column:is_examine;type:tinyint(1);default:0;comment:是否需要后台审核" json:"is_examine"` IsExamine SysIdentityExamine `gorm:"column:is_examine;type:tinyint(1);default:1;comment:是否需要后台审核" json:"is_examine"`
ModelDeleted ModelDeleted
ModelAt ModelAt
} }
type SysIdentityExamine int
const (
SysIdentityExamineForNot SysIdentityExamine = iota
SysIdentityExamineForYes
)
func (m *SysIdentity) TableName() string { func (m *SysIdentity) TableName() string {
return "sys_identity" return "sys_identity"
} }

View File

@ -5,6 +5,7 @@ type UserCompany struct {
Model Model
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"` UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
CompanyID uint64 `gorm:"column:company_id;type:int(11);default:0;comment:公司模型ID" json:"-"` CompanyID uint64 `gorm:"column:company_id;type:int(11);default:0;comment:公司模型ID" json:"-"`
InvalidStatus
ModelDeleted ModelDeleted
ModelAt ModelAt
} }