From 0dd46c0c9d7ad7965620148012008f7f1fd7251c Mon Sep 17 00:00:00 2001 From: henry Date: Sat, 9 Oct 2021 17:32:23 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=AE=8C=E5=96=84=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/basic/config/public.go | 7 +- app/common/model/common.go | 17 ++++ app/common/model/manage_company.go | 37 +++++++ app/common/model/user_tenant.go | 2 +- app/enterprise/api/tenant.go | 19 ++++ app/enterprise/controller/technology/paper.go | 1 + app/enterprise/controller/tenant/instance.go | 1 + app/enterprise/controller/tenant/settled.go | 98 +++++++++++++++++++ app/enterprise/model/manage_company.go | 11 +++ app/enterprise/model/sys_tenant.go | 11 +++ 10 files changed, 199 insertions(+), 5 deletions(-) create mode 100644 app/common/model/manage_company.go create mode 100644 app/enterprise/api/tenant.go create mode 100644 app/enterprise/controller/tenant/instance.go create mode 100644 app/enterprise/controller/tenant/settled.go create mode 100644 app/enterprise/model/manage_company.go create mode 100644 app/enterprise/model/sys_tenant.go diff --git a/app/basic/config/public.go b/app/basic/config/public.go index a352a36..1e3dacb 100644 --- a/app/basic/config/public.go +++ b/app/basic/config/public.go @@ -9,10 +9,9 @@ type Area struct { } type ( - // IdentityForCompany 公身份信息 + // IdentityForCompany 公司附加信息 IdentityForCompany struct { - Name string `json:"name"` // 公司企业名称 - Code string `json:"code"` // 企业代码 - Area + Industry uint64 `json:"industry"` + Keywords []string `json:"keywords"` } ) diff --git a/app/common/model/common.go b/app/common/model/common.go index d3dab31..fbcfce8 100644 --- a/app/common/model/common.go +++ b/app/common/model/common.go @@ -66,6 +66,23 @@ const ( AccountStatusForDisable ) +// ExamineStatus 审核状态 +type ExamineStatus struct { + Status ExamineStatusKind `gorm:"column:status;type:tinyint(1);default:0;comment:审核状态(0:审核中,1:审核通过,2:审核拒绝)" json:"status"` +} + +// ExamineStatusKind 审核状态 +type ExamineStatusKind int + +const ( + // ExamineStatusForOngoing 审核中 + ExamineStatusForOngoing ExamineStatusKind = iota + // ExamineStatusForAgree 审核通过 + ExamineStatusForAgree + // ExamineStatusForRefuse 审核拒绝 + ExamineStatusForRefuse +) + type Area struct { Province uint64 `gorm:"column:province;type:int;default:0;comment:所在省" json:"province"` City uint64 `gorm:"column:city;type:int;default:0;comment:所在市" json:"city"` diff --git a/app/common/model/manage_company.go b/app/common/model/manage_company.go new file mode 100644 index 0000000..966cca8 --- /dev/null +++ b/app/common/model/manage_company.go @@ -0,0 +1,37 @@ +package model + +import "SciencesServer/utils" + +// ManageCompany 公司企业管理 +type ManageCompany struct { + Model + UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"` + 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 uint64 `gorm:"column:industry;type:int(11);default:0;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 + ModelDeleted + ModelAt +} + +func (m *ManageCompany) TableName() string { + return "manage_company" +} + +func (m *ManageCompany) GetKeywordAttribute() []string { + keywords := make([]string, 0) + _ = utils.FromJSON(m.Keyword, &keywords) + return keywords +} + +func (m *ManageCompany) SetKeywordAttribute(keywords []string) { + m.Keyword = utils.AnyToJSON(keywords) +} + +func NewManageCompany() *ManageCompany { + return &ManageCompany{} +} diff --git a/app/common/model/user_tenant.go b/app/common/model/user_tenant.go index 4ae4c70..1b1d2c8 100644 --- a/app/common/model/user_tenant.go +++ b/app/common/model/user_tenant.go @@ -3,7 +3,7 @@ package model type UserTenant struct { Model ModelTenant - UID uint64 `gorm:"column:uid;index:idx_tenant_user_uuid;type:int;default:0;comment:用户表UUID" json:"-"` + UID uint64 `gorm:"column:uid;index:idx_user_tenant_uid;type:int;default:0;comment:用户表UUID" json:"-"` Avatar string `gorm:"column:avatar;type:varchar(255);default:null;comment:头像" json:"avatar"` Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"` Email string `gorm:"column:email;type:varchar(50);default:null;comment:邮箱" json:"email"` diff --git a/app/enterprise/api/tenant.go b/app/enterprise/api/tenant.go new file mode 100644 index 0000000..55425fd --- /dev/null +++ b/app/enterprise/api/tenant.go @@ -0,0 +1,19 @@ +package api + +import ( + "SciencesServer/app/basic/api" + "SciencesServer/app/enterprise/controller/tenant" + "SciencesServer/app/service" + "github.com/gin-gonic/gin" +) + +type Tenant struct{} + +func (a *Tenant) SettledCompany(c *gin.Context) { + err := tenant.NewSettled()(api.GetSession()(c).(*service.SessionEnterprise)).Company(nil, nil) + api.APIResponse(err)(c) +} + +func (a *Tenant) SettledExpert(c *gin.Context) { + +} diff --git a/app/enterprise/controller/technology/paper.go b/app/enterprise/controller/technology/paper.go index 6c810f9..66bb602 100644 --- a/app/enterprise/controller/technology/paper.go +++ b/app/enterprise/controller/technology/paper.go @@ -69,6 +69,7 @@ func (c *Paper) Form(params *PaperParams) error { return errors.New("无权限操作") } } + mTechnologyPaper.UID = c.UID mTechnologyPaper.Title = params.Title mTechnologyPaper.Ext = params.Ext mTechnologyPaper.Author = params.Author diff --git a/app/enterprise/controller/tenant/instance.go b/app/enterprise/controller/tenant/instance.go new file mode 100644 index 0000000..d1c1acb --- /dev/null +++ b/app/enterprise/controller/tenant/instance.go @@ -0,0 +1 @@ +package tenant diff --git a/app/enterprise/controller/tenant/settled.go b/app/enterprise/controller/tenant/settled.go new file mode 100644 index 0000000..772030f --- /dev/null +++ b/app/enterprise/controller/tenant/settled.go @@ -0,0 +1,98 @@ +package tenant + +import ( + "SciencesServer/app/basic/config" + model2 "SciencesServer/app/common/model" + "SciencesServer/app/enterprise/model" + "SciencesServer/app/service" + "errors" +) + +// Settled 入驻 +type Settled struct{ *service.SessionEnterprise } + +type SettledHandle func(enterprise *service.SessionEnterprise) *Settled + +type SettledParams struct { + ID uint64 + Image string // logo图片 + Name string // 名称 + Code string // 唯一编码 + config.Area + Introduce string `json:"introduce"` +} + +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("无权限操作,未知的入驻信息") + } + return nil +} + +// Company 公司企业 +func (c *Settled) Company(params *SettledParams, other *config.IdentityForCompany) error { + mManageCompany := model.NewManageCompany() + + err := params.effect(c.UID, mManageCompany.ManageCompany) + + if err != nil { + return err + } + 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 = other.Industry + mManageCompany.SetKeywordAttribute(other.Keywords) + mManageCompany.Introduce = params.Introduce + + if mManageCompany.ID <= 0 { + return model2.Create(mManageCompany.ManageCompany) + } + if mManageCompany.UID != c.UID { + return errors.New("异常,无权限操作") + } else if mManageCompany.Status != model2.ExamineStatusForRefuse { + return errors.New("操作错误,不允许操作") + } + return model2.Updates(mManageCompany.ManageCompany, mManageCompany.ManageCompany) +} + +// Expert 专家 +func (c *Settled) Expert() { + +} + +// Research 研究机构 +func (c *Settled) Research() { + +} + +// Laboratory 实验室 +func (c *Settled) Laboratory() { + +} + +// Agent 经纪人 +func (c *Settled) Agent() { + +} + +func NewSettled() SettledHandle { + return func(enterprise *service.SessionEnterprise) *Settled { + return &Settled{enterprise} + } +} diff --git a/app/enterprise/model/manage_company.go b/app/enterprise/model/manage_company.go new file mode 100644 index 0000000..d3f8df1 --- /dev/null +++ b/app/enterprise/model/manage_company.go @@ -0,0 +1,11 @@ +package model + +import "SciencesServer/app/common/model" + +type ManageCompany struct { + *model.ManageCompany +} + +func NewManageCompany() *ManageCompany { + return &ManageCompany{} +} diff --git a/app/enterprise/model/sys_tenant.go b/app/enterprise/model/sys_tenant.go new file mode 100644 index 0000000..bfb69d5 --- /dev/null +++ b/app/enterprise/model/sys_tenant.go @@ -0,0 +1,11 @@ +package model + +import "SciencesServer/app/common/model" + +type SysTenant struct { + *model.SysTenant +} + +func NewSysTenant() *SysTenant { + return &SysTenant{model.NewSysTenant()} +}