feat:完善入驻信息管理
This commit is contained in:
@ -13,13 +13,12 @@ type User struct{}
|
||||
type (
|
||||
// userSettledForm 入驻平台参数
|
||||
userSettledForm struct {
|
||||
api.IDStringForm
|
||||
api.ImageForm
|
||||
Name string `json:"name" form:"name"`
|
||||
Code string `json:"code" form:"code"`
|
||||
config.Area
|
||||
Introduce string `json:"introduce" form:"introduce"`
|
||||
Industry string `json:"industry" form:"industry"` // 行业领域
|
||||
Industrys []string `json:"industrys" form:"industrys"` // 行业领域
|
||||
Keywords []string `json:"keywords" form:"keywords"`
|
||||
}
|
||||
// userBankForm 银行平台信息参数
|
||||
@ -52,6 +51,7 @@ func (*User) BindMobile(c *gin.Context) {
|
||||
|
||||
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 {
|
||||
@ -59,9 +59,9 @@ func (*User) SettledCompany(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Company(&user.SettledParams{
|
||||
ID: form.Convert(), Image: form.FilterImageURL(), Name: form.Name, Code: form.Code,
|
||||
Area: form.Area, Introduce: form.Introduce, Industry: form.Industry, Keywords: form.Keywords,
|
||||
}, nil)
|
||||
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)
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ func (*User) SettledExpert(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
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,
|
||||
}, &form.IdentityForExpert)
|
||||
api.APIResponse(err)(c)
|
||||
@ -91,8 +91,8 @@ func (*User) SettledResearch(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Research(&user.SettledParams{
|
||||
ID: form.Convert(), Image: form.FilterImageURL(), Name: form.Name, Code: form.Code,
|
||||
Area: form.Area, Introduce: form.Introduce, Industry: form.Industry, Keywords: form.Keywords,
|
||||
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)
|
||||
}
|
||||
@ -107,14 +107,15 @@ func (*User) SettledLaboratory(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := user.NewSettled()(api.GetSession()(c).(*session.Enterprise)).Laboratory(&user.SettledParams{
|
||||
ID: form.Convert(), Image: form.FilterImageURL(), Name: form.Name, Code: form.Code,
|
||||
Area: form.Area, Introduce: form.Introduce, Industry: form.Industry, Keywords: form.Keywords,
|
||||
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 {
|
||||
@ -123,7 +124,7 @@ func (*User) SettledAgent(c *gin.Context) {
|
||||
}
|
||||
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, Industry: form.Industry, Keywords: form.Keywords,
|
||||
Area: form.Area, Introduce: form.Introduce, Industrys: form.Industrys, Keywords: form.Keywords,
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
@ -1,86 +1,134 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
model3 "SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
model3 "SciencesServer/app/api/manage/model"
|
||||
"SciencesServer/app/basic/config"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 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 {
|
||||
ID uint64
|
||||
Image string // logo图片
|
||||
Name string // 名称
|
||||
Code string // 唯一编码
|
||||
Name, Image, Code, Introduce string // 唯一编码
|
||||
config.Area
|
||||
Introduce string
|
||||
Industry string `json:"industry"`
|
||||
Keywords []string `json:"keywords"`
|
||||
Industrys, Keywords []string
|
||||
}
|
||||
|
||||
// effect 入驻信息有效性
|
||||
func (c *SettledParams) effect(uid uint64, iModel model2.IModel) error {
|
||||
if c.ID <= 0 {
|
||||
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
|
||||
}
|
||||
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("无权限操作,未知的入驻信息")
|
||||
}
|
||||
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(uid, mUID uint64, mStatus model2.ExamineStatusKind) bool {
|
||||
if mUID != uid || mStatus != model2.ExamineStatusForRefuse {
|
||||
return false
|
||||
func (c *SettledParams) pass(identity int, mStatus model2.ExamineStatusKind) (bool, error) {
|
||||
if mStatus != model2.ExamineStatusForRefuse {
|
||||
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 公司企业
|
||||
func (c *Settled) Company(params *SettledParams, other *config.IdentityForCompany) error {
|
||||
mManageCompany := model3.NewManageCompany()
|
||||
func (c *Settled) Company(params *SettledParams, inviterID uint64, other *config.IdentityForCompany) error {
|
||||
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 {
|
||||
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.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.Industry = params.Industry
|
||||
mManageCompany.WebUrl = other.WebUrl
|
||||
mManageCompany.SetIndustryAttribute(params.Industrys)
|
||||
mManageCompany.SetKeywordAttribute(params.Keywords)
|
||||
mManageCompany.Introduce = params.Introduce
|
||||
|
||||
if isExamine {
|
||||
mManageCompany.Status = model2.ExamineStatusForAgree
|
||||
}
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if mManageCompany.ID <= 0 {
|
||||
mManageCompany.UID = c.UID
|
||||
return model2.Create(mManageCompany.ManageCompany)
|
||||
if err = model2.Create(mManageCompany.ManageCompany, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
if !params.pass(c.UID, mManageCompany.UID, mManageCompany.Status) {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
mManageCompany.Status = model2.ExamineStatusForOngoing
|
||||
return model2.Updates(mManageCompany.ManageCompany, mManageCompany.ManageCompany)
|
||||
mUserCompany := model.NewUserCompany()
|
||||
mUserCompany.UID = c.UID
|
||||
mUserCompany.CompanyID = mManageCompany.ID
|
||||
return model2.Create(mUserCompany.UserCompany, tx)
|
||||
})
|
||||
}
|
||||
|
||||
// Expert 专家
|
||||
@ -95,7 +143,7 @@ func (c *Settled) Expert(params *SettledParams, other *config.IdentityForExpert)
|
||||
mManageExpert.Area = model2.Area{
|
||||
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.Introduce = params.Introduce
|
||||
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{
|
||||
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.Introduce = params.Introduce
|
||||
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{
|
||||
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.Introduce = params.Introduce
|
||||
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 {
|
||||
return func(session *session.Enterprise) *Settled {
|
||||
return &Settled{Enterprise: session}
|
||||
return func(session *session.Enterprise, local string) *Settled {
|
||||
return &Settled{Enterprise: session, local: local}
|
||||
}
|
||||
}
|
||||
|
11
app/api/enterprise/model/sys_identity.go
Normal file
11
app/api/enterprise/model/sys_identity.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type SysIdentity struct {
|
||||
*model.SysIdentity
|
||||
}
|
||||
|
||||
func NewSysIdentity() *SysIdentity {
|
||||
return &SysIdentity{model.NewSysIdentity()}
|
||||
}
|
11
app/api/enterprise/model/user_company.go
Normal file
11
app/api/enterprise/model/user_company.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type UserCompany struct {
|
||||
*model.UserCompany
|
||||
}
|
||||
|
||||
func NewUserCompany() *UserCompany {
|
||||
return &UserCompany{model.NewUserCompany()}
|
||||
}
|
@ -10,7 +10,9 @@ type Area struct {
|
||||
|
||||
type (
|
||||
// IdentityForCompany 公司附加信息
|
||||
IdentityForCompany struct{}
|
||||
IdentityForCompany struct {
|
||||
WebUrl string `json:"web_url" form:"web_url"`
|
||||
}
|
||||
// IdentityForExpert 专家附加信息
|
||||
IdentityForExpert struct {
|
||||
TenantID uint64 `json:"tenant_id" form:"tenant_id"`
|
||||
|
@ -103,6 +103,21 @@ const (
|
||||
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 {
|
||||
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"`
|
||||
|
@ -6,12 +6,13 @@ import "SciencesServer/utils"
|
||||
type ManageCompany struct {
|
||||
Model
|
||||
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"`
|
||||
Code string `gorm:"column:code;type:varchar(30);default:null;comment:信用代码" json:"code"`
|
||||
Image
|
||||
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"`
|
||||
Introduce string `gorm:"column:introduce;type:text;comment:介绍描述" json:"introduce"`
|
||||
ExamineStatus
|
||||
|
@ -30,6 +30,16 @@ func (m *ManageExpert) TableName() string {
|
||||
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 {
|
||||
keywords := make([]string, 0)
|
||||
_ = utils.FromJSON(m.Keyword, &keywords)
|
||||
|
@ -6,11 +6,18 @@ type SysIdentity struct {
|
||||
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"`
|
||||
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
|
||||
ModelAt
|
||||
}
|
||||
|
||||
type SysIdentityExamine int
|
||||
|
||||
const (
|
||||
SysIdentityExamineForNot SysIdentityExamine = iota
|
||||
SysIdentityExamineForYes
|
||||
)
|
||||
|
||||
func (m *SysIdentity) TableName() string {
|
||||
return "sys_identity"
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ type UserCompany struct {
|
||||
Model
|
||||
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:"-"`
|
||||
InvalidStatus
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
Reference in New Issue
Block a user