2022-01-19 13:23:07 +08:00
|
|
|
package manage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"SciencesServer/app/api/admin/model"
|
2022-01-19 14:22:44 +08:00
|
|
|
"SciencesServer/app/basic/config"
|
2022-01-19 13:23:07 +08:00
|
|
|
"SciencesServer/app/basic/controller"
|
|
|
|
model2 "SciencesServer/app/common/model"
|
|
|
|
"SciencesServer/app/session"
|
2022-01-20 09:43:26 +08:00
|
|
|
config2 "SciencesServer/config"
|
2022-01-19 13:23:07 +08:00
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Company struct {
|
|
|
|
*session.Admin
|
|
|
|
}
|
|
|
|
|
|
|
|
type CompanyHandle func(session *session.Admin) *Company
|
|
|
|
|
|
|
|
type (
|
|
|
|
// CompanyInstance 公司企业信息
|
|
|
|
CompanyInstance struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
*model.ManageCompanyInfo
|
|
|
|
Industrys []string `json:"industrys"`
|
2022-01-19 16:03:47 +08:00
|
|
|
Address string `json:"address"`
|
2022-01-19 13:23:07 +08:00
|
|
|
Area string `json:"area"`
|
|
|
|
}
|
|
|
|
// CompanyDetail 公司企业详细信息
|
|
|
|
CompanyDetail struct {
|
2022-01-27 14:50:52 +08:00
|
|
|
ID string `json:"id"`
|
|
|
|
TenantID string `json:"tenant_id"`
|
|
|
|
InvitedCode string `json:"invited_code"`
|
2022-01-19 13:23:07 +08:00
|
|
|
*model2.ManageCompany
|
2022-01-20 09:43:26 +08:00
|
|
|
Industrys []*config.Industry `json:"industrys"`
|
|
|
|
Keywords []string `json:"keywords"`
|
|
|
|
Directions []string `json:"directions"`
|
|
|
|
Area string `json:"area"`
|
2022-01-19 13:23:07 +08:00
|
|
|
}
|
|
|
|
// CompanyParams 公司企业参数信息
|
|
|
|
CompanyParams struct {
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Instance 首页信息
|
|
|
|
func (c *Company) Instance(tenantID uint64, name string, status int, page, pageSize int) (*controller.ReturnPages, error) {
|
|
|
|
mManageCompany := model.NewManageCompany()
|
|
|
|
|
|
|
|
where := make([]*model2.ModelWhere, 0)
|
|
|
|
|
|
|
|
if c.TenantID > 0 {
|
|
|
|
where = append(where, model2.NewWhere("c.tenant_id", c.TenantID))
|
|
|
|
}
|
|
|
|
if tenantID > 0 {
|
|
|
|
where = append(where, model2.NewWhere("c.tenant_id", tenantID))
|
|
|
|
}
|
|
|
|
if name != "" {
|
|
|
|
where = append(where, model2.NewWhereLike("c.name", name))
|
|
|
|
}
|
|
|
|
if status > 0 {
|
|
|
|
where = append(where, model2.NewWhere("c.examine_status", status))
|
|
|
|
}
|
|
|
|
var count int64
|
|
|
|
|
2022-01-27 14:50:52 +08:00
|
|
|
out, err := mManageCompany.Companys(page, pageSize, &count, where...)
|
2022-01-19 13:23:07 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
list := make([]*CompanyInstance, 0)
|
|
|
|
|
|
|
|
for _, v := range out {
|
|
|
|
mManageCompany.Industry = v.Industry
|
|
|
|
|
2022-01-19 16:03:47 +08:00
|
|
|
_industrys := make([]string, 0)
|
|
|
|
|
|
|
|
for _, v := range mManageCompany.GetIndustryAttribute() {
|
2022-01-20 09:43:26 +08:00
|
|
|
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", "/").Value)
|
2022-01-19 16:03:47 +08:00
|
|
|
}
|
2022-01-19 13:23:07 +08:00
|
|
|
list = append(list, &CompanyInstance{
|
2022-01-19 16:03:47 +08:00
|
|
|
ID: v.GetEncodeID(), ManageCompanyInfo: v, Industrys: _industrys,
|
|
|
|
Address: v.FormatBasic(), Area: (&model2.Area{
|
|
|
|
Province: v.TenantProvince,
|
|
|
|
City: v.TenantCity,
|
|
|
|
}).FormatBasic(),
|
2022-01-19 13:23:07 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
return &controller.ReturnPages{Data: list, Count: count}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Form 数据操作
|
2022-01-19 14:22:44 +08:00
|
|
|
func (c *Company) Form(params *BasicParams, other *config.IdentityForCompany) error {
|
|
|
|
mManageCompany := model.NewManageCompany()
|
|
|
|
// 查询相应的企业入驻信息
|
|
|
|
if params.ID > 0 {
|
|
|
|
mManageCompany.ID = params.ID
|
|
|
|
|
|
|
|
isExist, err := model2.FirstField(mManageCompany.ManageCompany, []string{"id", "name", "code", "tenant_id", "created_at"})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
} else if !isExist {
|
|
|
|
return errors.New("操作错误,公司企业信息不存在或已被删除")
|
|
|
|
}
|
|
|
|
if c.TenantID > 0 {
|
|
|
|
if mManageCompany.TenantID != c.TenantID {
|
|
|
|
return errors.New("操作错误,无权限操作")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if mManageCompany.TenantID != params.TenantID {
|
|
|
|
if isExist, err = params.isExist(mManageCompany.ManageCompany, model2.NewWhere("tenant_id", params.TenantID),
|
|
|
|
model2.NewWhere("code", params.Code)); err != nil {
|
|
|
|
return err
|
|
|
|
} else if isExist {
|
|
|
|
return errors.New("操作错误,当前站点下已存在同一公司组织机构代码")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mManageCompany.TenantID = c.TenantID
|
2022-01-27 14:50:52 +08:00
|
|
|
mManageCompany.Kind = model2.ManageCompanyKind(other.Kind)
|
2022-01-19 14:22:44 +08:00
|
|
|
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.Product = other.Product
|
|
|
|
mManageCompany.Url = other.Url
|
|
|
|
mManageCompany.SetIndustryAttribute(params.Industrys)
|
|
|
|
mManageCompany.SetKeywordAttribute(params.Keywords)
|
|
|
|
mManageCompany.SetDirectionAttribute(other.Directions)
|
|
|
|
mManageCompany.Introduce = params.Introduce
|
|
|
|
|
|
|
|
if c.TenantID <= 0 {
|
|
|
|
mManageCompany.TenantID = params.TenantID
|
|
|
|
}
|
|
|
|
if mManageCompany.ID > 0 {
|
|
|
|
return model2.Updates(mManageCompany.ManageCompany, mManageCompany.ManageCompany)
|
|
|
|
}
|
|
|
|
// 查询手机号码是否在当前租户下是否已经注册了
|
|
|
|
mManageCompany.Name = params.Name
|
|
|
|
mManageCompany.Code = params.Code
|
2022-01-19 22:13:28 +08:00
|
|
|
mManageCompany.License = other.FilterLicense()
|
2022-01-20 11:09:29 +08:00
|
|
|
mManageCompany.ExamineStatus = model2.ExamineStatusForAgree
|
|
|
|
mManageCompany.ExamineRemark = "主动创建,无需审核"
|
2022-01-19 14:22:44 +08:00
|
|
|
|
|
|
|
if isExist, err := params.isExist(mManageCompany.ManageCompany, model2.NewWhere("tenant_id", params.TenantID),
|
|
|
|
model2.NewWhere("code", params.Code)); err != nil {
|
|
|
|
return err
|
|
|
|
} else if isExist {
|
|
|
|
return errors.New("操作错误,当前站点下已存在同一公司组织机构代码")
|
|
|
|
}
|
|
|
|
return model2.Create(mManageCompany.ManageCompany)
|
2022-01-19 13:23:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Detail 详细信息
|
|
|
|
func (c *Company) Detail(id uint64) (*CompanyDetail, error) {
|
|
|
|
mManageCompany := model.NewManageCompany()
|
|
|
|
|
|
|
|
out, err := mManageCompany.Company(id)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else if out.ManageCompany == nil {
|
|
|
|
return nil, errors.New("操作错误,公司企业信息不存在或已被删除")
|
|
|
|
}
|
2022-01-20 09:43:26 +08:00
|
|
|
_industrys := make([]*config.Industry, 0)
|
|
|
|
|
|
|
|
for _, v := range out.GetIndustryAttribute() {
|
|
|
|
_industrys = append(_industrys, config.GetIndustryInfo(v, "-", ">"))
|
|
|
|
}
|
|
|
|
out.Image.Image = out.Image.Analysis(config2.SystemConfig[config2.SysImageDomain])
|
|
|
|
out.License = (&model2.Image{Image: out.License}).Analysis(config2.SystemConfig[config2.SysImageDomain])
|
|
|
|
|
2022-01-19 13:23:07 +08:00
|
|
|
return &CompanyDetail{
|
|
|
|
ID: out.GetEncodeID(),
|
2022-01-20 09:43:26 +08:00
|
|
|
TenantID: out.GetEncodeTenantID(),
|
2022-01-27 14:50:52 +08:00
|
|
|
InvitedCode: (&model2.Model{ID: out.InviterID}).GetEncodeID(),
|
2022-01-19 13:23:07 +08:00
|
|
|
ManageCompany: out.ManageCompany,
|
2022-01-20 09:43:26 +08:00
|
|
|
Industrys: _industrys,
|
2022-01-19 13:23:07 +08:00
|
|
|
Keywords: out.GetKeywordAttribute(),
|
2022-01-27 14:50:52 +08:00
|
|
|
Directions: out.GetDirectionAttribute(),
|
|
|
|
//Area: out.FormatBasic(),
|
2022-01-19 13:23:07 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCompany() CompanyHandle {
|
|
|
|
return func(session *session.Admin) *Company {
|
|
|
|
return &Company{session}
|
|
|
|
}
|
|
|
|
}
|