2021-10-13 17:17:28 +08:00
|
|
|
package user
|
2021-10-09 17:32:23 +08:00
|
|
|
|
|
|
|
import (
|
2021-10-15 15:06:02 +08:00
|
|
|
model3 "SciencesServer/app/api/enterprise/model"
|
2021-10-09 17:32:23 +08:00
|
|
|
"SciencesServer/app/basic/config"
|
|
|
|
model2 "SciencesServer/app/common/model"
|
|
|
|
"SciencesServer/app/service"
|
2021-10-11 16:30:53 +08:00
|
|
|
"SciencesServer/utils"
|
2021-10-09 17:32:23 +08:00
|
|
|
"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
|
2021-10-11 16:30:53 +08:00
|
|
|
Introduce string
|
2021-11-01 11:19:49 +08:00
|
|
|
Industry string `json:"industry"`
|
2021-10-11 16:30:53 +08:00
|
|
|
Keywords []string `json:"keywords"`
|
2021-10-09 17:32:23 +08:00
|
|
|
}
|
|
|
|
|
2021-10-11 16:30:53 +08:00
|
|
|
// effect 入驻信息有效性
|
2021-10-09 17:32:23 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-10-11 16:30:53 +08:00
|
|
|
// pass 入驻信息通过性
|
|
|
|
func (c *SettledParams) pass(uid, mUID uint64, mStatus model2.ExamineStatusKind) bool {
|
|
|
|
if mUID != uid || mStatus != model2.ExamineStatusForRefuse {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-10-09 17:32:23 +08:00
|
|
|
// Company 公司企业
|
|
|
|
func (c *Settled) Company(params *SettledParams, other *config.IdentityForCompany) error {
|
2021-10-15 15:06:02 +08:00
|
|
|
mManageCompany := model3.NewManageCompany()
|
2021-10-09 17:32:23 +08:00
|
|
|
|
2021-11-01 11:19:49 +08:00
|
|
|
err := params.effect(c.UID, mManageCompany.ManageCompany)
|
2021-10-09 17:32:23 +08:00
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
2021-10-11 16:30:53 +08:00
|
|
|
mManageCompany.Industry = params.Industry
|
|
|
|
mManageCompany.SetKeywordAttribute(params.Keywords)
|
2021-10-09 17:32:23 +08:00
|
|
|
mManageCompany.Introduce = params.Introduce
|
|
|
|
|
|
|
|
if mManageCompany.ID <= 0 {
|
2021-11-01 11:19:49 +08:00
|
|
|
mManageCompany.UID = c.UID
|
2021-10-09 17:32:23 +08:00
|
|
|
return model2.Create(mManageCompany.ManageCompany)
|
|
|
|
}
|
2021-11-01 11:19:49 +08:00
|
|
|
if !params.pass(c.UID, mManageCompany.UID, mManageCompany.Status) {
|
2021-10-11 16:30:53 +08:00
|
|
|
return errors.New("操作错误,无权限操作")
|
2021-10-09 17:32:23 +08:00
|
|
|
}
|
2021-10-11 16:30:53 +08:00
|
|
|
mManageCompany.Status = model2.ExamineStatusForOngoing
|
2021-10-09 17:32:23 +08:00
|
|
|
return model2.Updates(mManageCompany.ManageCompany, mManageCompany.ManageCompany)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expert 专家
|
2021-10-11 16:30:53 +08:00
|
|
|
func (c *Settled) Expert(params *SettledParams, other *config.IdentityForExpert) error {
|
2021-10-15 15:06:02 +08:00
|
|
|
mManageExpert := model3.NewManageExpert()
|
2021-10-11 16:30:53 +08:00
|
|
|
|
2021-11-01 11:19:49 +08:00
|
|
|
err := params.effect(c.UID, mManageExpert.ManageExpert)
|
2021-10-09 17:32:23 +08:00
|
|
|
|
2021-10-11 16:30:53 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
mManageExpert.TenantID = other.TenantID
|
|
|
|
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.SetKeywordAttribute(params.Keywords)
|
|
|
|
mManageExpert.Introduce = params.Introduce
|
|
|
|
mManageExpert.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude})
|
|
|
|
mManageExpert.School = other.School
|
|
|
|
mManageExpert.Major = other.Major
|
|
|
|
mManageExpert.Job = other.Job
|
|
|
|
mManageExpert.Title = other.Title
|
|
|
|
mManageExpert.WorkAt = utils.DataTimeToDate(other.WorkAt)
|
|
|
|
mManageExpert.Research = utils.AnyToJSON(other.Research)
|
|
|
|
|
|
|
|
if mManageExpert.ID <= 0 {
|
2021-11-01 11:19:49 +08:00
|
|
|
mManageExpert.UID = c.UID
|
2021-10-11 16:30:53 +08:00
|
|
|
return model2.Create(mManageExpert.ManageExpert)
|
|
|
|
}
|
2021-11-01 11:19:49 +08:00
|
|
|
if !params.pass(c.UID, mManageExpert.UID, mManageExpert.Status) {
|
2021-10-11 16:30:53 +08:00
|
|
|
return errors.New("操作错误,无权限操作")
|
|
|
|
}
|
|
|
|
mManageExpert.Status = model2.ExamineStatusForOngoing
|
|
|
|
return model2.Updates(mManageExpert.ManageExpert, mManageExpert.ManageExpert)
|
2021-10-09 17:32:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Research 研究机构
|
2021-10-11 16:30:53 +08:00
|
|
|
func (c *Settled) Research(params *SettledParams, other *config.IdentityForResearch) error {
|
2021-10-15 15:06:02 +08:00
|
|
|
mManageResearch := model3.NewManageResearch()
|
2021-10-09 17:32:23 +08:00
|
|
|
|
2021-11-01 11:19:49 +08:00
|
|
|
err := params.effect(c.UID, mManageResearch.ManageResearch)
|
2021-10-11 16:30:53 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
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.SetKeywordAttribute(params.Keywords)
|
|
|
|
mManageResearch.Introduce = params.Introduce
|
|
|
|
mManageResearch.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude})
|
|
|
|
mManageResearch.Research = other.Research
|
|
|
|
|
|
|
|
if mManageResearch.ID <= 0 {
|
2021-11-01 11:19:49 +08:00
|
|
|
mManageResearch.UID = c.UID
|
2021-10-11 16:30:53 +08:00
|
|
|
return model2.Create(mManageResearch.ManageResearch)
|
|
|
|
}
|
2021-11-01 11:19:49 +08:00
|
|
|
if !params.pass(c.UID, mManageResearch.UID, mManageResearch.Status) {
|
2021-10-11 16:30:53 +08:00
|
|
|
return errors.New("操作错误,无权限操作")
|
|
|
|
}
|
|
|
|
mManageResearch.Status = model2.ExamineStatusForOngoing
|
|
|
|
return model2.Updates(mManageResearch.ManageResearch, mManageResearch.ManageResearch)
|
2021-10-09 17:32:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Laboratory 实验室
|
2021-10-11 16:30:53 +08:00
|
|
|
func (c *Settled) Laboratory(params *SettledParams, other *config.IdentityForLaboratory) error {
|
2021-10-15 15:06:02 +08:00
|
|
|
mManageLaboratory := model3.NewManageLaboratory()
|
2021-10-11 16:30:53 +08:00
|
|
|
|
2021-11-01 11:19:49 +08:00
|
|
|
err := params.effect(c.UID, mManageLaboratory.ManageLaboratory)
|
2021-10-09 17:32:23 +08:00
|
|
|
|
2021-10-11 16:30:53 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
mManageLaboratory.TenantID = other.TenantID
|
|
|
|
mManageLaboratory.Name = params.Name
|
|
|
|
mManageLaboratory.Code = params.Code
|
|
|
|
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.SetKeywordAttribute(params.Keywords)
|
|
|
|
mManageLaboratory.Introduce = params.Introduce
|
|
|
|
mManageLaboratory.Position = utils.AnyToJSON(model2.Position{Longitude: other.Longitude, Latitude: other.Latitude})
|
|
|
|
mManageLaboratory.Research = utils.AnyToJSON(other.Research)
|
|
|
|
|
|
|
|
if mManageLaboratory.ID <= 0 {
|
2021-11-01 11:19:49 +08:00
|
|
|
mManageLaboratory.UID = c.UID
|
2021-10-11 16:30:53 +08:00
|
|
|
return model2.Create(mManageLaboratory.ManageLaboratory)
|
|
|
|
}
|
2021-11-01 11:19:49 +08:00
|
|
|
if !params.pass(c.UID, mManageLaboratory.UID, mManageLaboratory.Status) {
|
2021-10-11 16:30:53 +08:00
|
|
|
return errors.New("操作错误,无权限操作")
|
|
|
|
}
|
|
|
|
mManageLaboratory.Status = model2.ExamineStatusForOngoing
|
|
|
|
return model2.Updates(mManageLaboratory.ManageLaboratory, mManageLaboratory.ManageLaboratory)
|
2021-10-09 17:32:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Agent 经纪人
|
|
|
|
func (c *Settled) Agent() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSettled() SettledHandle {
|
|
|
|
return func(enterprise *service.SessionEnterprise) *Settled {
|
|
|
|
return &Settled{enterprise}
|
|
|
|
}
|
|
|
|
}
|