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

@ -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 mManageCompany.ID <= 0 {
mManageCompany.UID = c.UID
return model2.Create(mManageCompany.ManageCompany)
if isExamine {
mManageCompany.Status = model2.ExamineStatusForAgree
}
if !params.pass(c.UID, mManageCompany.UID, mManageCompany.Status) {
return errors.New("操作错误,无权限操作")
}
mManageCompany.Status = model2.ExamineStatusForOngoing
return model2.Updates(mManageCompany.ManageCompany, mManageCompany.ManageCompany)
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()
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}
}
}