diff --git a/app/api/enterprise/api/technology.go b/app/api/enterprise/api/technology.go index 7bb0662..1a96432 100644 --- a/app/api/enterprise/api/technology.go +++ b/app/api/enterprise/api/technology.go @@ -503,6 +503,20 @@ func (*Technology) Product(c *gin.Context) { api.APIResponse(err, data)(c) } +func (*Technology) ProductVisit(c *gin.Context) { + form := &struct { + api.IDStringForm + api.PageForm + }{} + if err := api.Bind(form)(c); err != nil { + api.APIFailure(err.(error))(c) + return + } + data, err := technology2.NewProduct()(api.GetSession()(c).(*session.Enterprise), api.GetLocal()(c).(string)). + Visit(form.Convert(), form.Page, form.PageSize) + api.APIResponse(err, data)(c) +} + func (*Technology) ProductAdd(c *gin.Context) { form := new(productForm) diff --git a/app/api/enterprise/controller/settled/company.go b/app/api/enterprise/controller/settled/company.go index b4deaaf..8154b46 100644 --- a/app/api/enterprise/controller/settled/company.go +++ b/app/api/enterprise/controller/settled/company.go @@ -23,7 +23,6 @@ type CompanyHandle func(session *session.Enterprise, local string) *Company type CompanyInfo struct { ID string `json:"id"` *model2.ManageCompany - Kinds []int `json:"kinds"` Industry []string `json:"industrys"` Keywords []string `json:"keywords"` } @@ -46,7 +45,6 @@ func (c *Company) Get(code string) (*CompanyInfo, error) { return &CompanyInfo{ ID: mManageCompany.GetEncodeID(), ManageCompany: mManageCompany.ManageCompany, - Kinds: mManageCompany.GetKindAttribute(), Industry: mManageCompany.GetIndustryAttribute(), Keywords: mManageCompany.GetKeywordAttribute(), }, nil @@ -84,7 +82,7 @@ func (c *Company) Launch(params *BasicParams, inviterID uint64, other *config.Id } mManageCompany.Local.Local = c.local mManageCompany.InviterID = inviterID - mManageCompany.SetKindAttribute(other.Kinds) + mManageCompany.Kind = model2.ManageCompanyKind(other.Kind) mManageCompany.Name = params.Name mManageCompany.Code = params.Code mManageCompany.Image = model2.Image{Image: params.Image} diff --git a/app/api/enterprise/controller/technology/product.go b/app/api/enterprise/controller/technology/product.go index 35dcbdb..f323a22 100644 --- a/app/api/enterprise/controller/technology/product.go +++ b/app/api/enterprise/controller/technology/product.go @@ -3,8 +3,10 @@ package technology import ( "SciencesServer/app/api/enterprise/model" "SciencesServer/app/basic/config" + "SciencesServer/app/basic/controller" model2 "SciencesServer/app/common/model" "SciencesServer/app/session" + config2 "SciencesServer/config" "errors" "time" ) @@ -30,6 +32,12 @@ type ( Customers []string `json:"customers"` Keywords []string `json:"keywords"` } + // ProductVisitInfo 产品浏览信息 + ProductVisitInfo struct { + ID string `json:"id"` + *model.TechnologyProductVisitInfo + CompanyKeywords []string `json:"company_keywords"` + } // ProductParams 产品参数信息 ProductParams struct { ID uint64 @@ -105,10 +113,36 @@ func (c *Product) Match(id uint64) { } -func (c *Product) Visit(id uint64, page, pageSize int) { +// Visit 访问信息 +func (c *Product) Visit(id uint64, page, pageSize int) (*controller.ReturnPages, error) { mTechnologyProductVisit := model.NewTechnologyProductVisit() + + where := []*model2.ModelWhere{ + model2.NewWhere("product_id", id), + } var count int64 - mTechnologyProductVisit.Visit(page, pageSize, &count) + + out, err := mTechnologyProductVisit.Visit(page, pageSize, &count, where...) + + if err != nil { + return nil, err + } + list := make([]*ProductVisitInfo, 0) + + mManageCompany := model.NewManageCompany() + + for _, v := range out { + mManageCompany.Keyword = v.CompanyKeyword + mManageCompany.Image.Image = v.CompanyImage + v.CompanyImage = mManageCompany.Image.Analysis(config2.SettingInfo.Domain) + + list = append(list, &ProductVisitInfo{ + ID: v.GetEncodeID(), + TechnologyProductVisitInfo: v, + CompanyKeywords: mManageCompany.GetKeywordAttribute(), + }) + } + return &controller.ReturnPages{Data: list, Count: count}, nil } // Form 数据操作 diff --git a/app/api/enterprise/model/technology_product_visit.go b/app/api/enterprise/model/technology_product_visit.go index 3d0348d..1966f9f 100644 --- a/app/api/enterprise/model/technology_product_visit.go +++ b/app/api/enterprise/model/technology_product_visit.go @@ -4,6 +4,7 @@ import ( "SciencesServer/app/common/model" "SciencesServer/serve/orm" "fmt" + "time" ) type TechnologyProductVisit struct { @@ -11,11 +12,15 @@ type TechnologyProductVisit struct { } type TechnologyProductVisitInfo struct { + model.Model + VisitAt time.Time `json:"visit_at"` + model.ManageCompanyBasic } func (m *TechnologyProductVisit) Visit(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyProductVisitInfo, error) { db := orm.GetDB().Table(m.TableName()+" AS v"). - Select("v.id"). + Select("v.id", "v.visit_at", "c.id AS company_id", "c.name AS company_name", "c.image AS company_image", + "c.kind AS company_kind", "c.url AS company_url"). Joins(fmt.Sprintf("LEFT JOIN %s AS c ON v.company_id = c.id", model.NewManageCompany().TableName())). Where("v.is_deleted = ?", model.DeleteStatusForNot) diff --git a/app/basic/config/public.go b/app/basic/config/public.go index 3525d87..64aeb7d 100644 --- a/app/basic/config/public.go +++ b/app/basic/config/public.go @@ -11,10 +11,10 @@ type Area struct { type ( // IdentityForCompany 公司附加信息 IdentityForCompany struct { - Kinds []int `json:"kinds" form:"kinds"` - Product string `json:"product" form:"product" binding:"required"` - Url string `json:"url" form:"url"` // 企业网站 - License string `json:"license" form:"license" binding:"required"` + Kind int `json:"kind" form:"kind" binding:"required"` // 企业类型 + Product string `json:"product" form:"product" binding:"required"` // 企业产品 + Url string `json:"url" form:"url"` // 企业网站 + License string `json:"license" form:"license" binding:"required"` // 营业执照 } // IdentityForExpert 专家附加信息 IdentityForExpert struct { diff --git a/app/common/model/manage_company.go b/app/common/model/manage_company.go index 84f5cbf..c531216 100644 --- a/app/common/model/manage_company.go +++ b/app/common/model/manage_company.go @@ -6,10 +6,10 @@ import "SciencesServer/utils" type ManageCompany struct { Model Local - InviterID uint64 `gorm:"column:inviter_id;type:int;default:0;comment:邀请人ID" json:"inviter_id"` - Kind string `gorm:"column:kind;type:varchar(255);default:'';comment:类型" json:"kind"` - Name string `gorm:"column:name;type:varchar(30);default:'';comment:名称" json:"name"` - Code string `gorm:"column:code;type:varchar(30);default:'';comment:信用代码" json:"code"` + InviterID uint64 `gorm:"column:inviter_id;type:int;default:0;comment:邀请人ID" json:"inviter_id"` + Kind ManageCompanyKind `gorm:"column:kind;type:tinyint(1);default:0;comment:企业类型" json:"kind"` + Name string `gorm:"column:name;type:varchar(30);default:'';comment:企业名称" json:"name"` + Code string `gorm:"column:code;type:varchar(30);default:'';comment:信用代码" json:"code"` Image Area Product string `gorm:"column:product;type:varchar(255);default:'';comment:产品信息" json:"product"` @@ -23,6 +23,16 @@ type ManageCompany struct { ModelAt } +// ManageCompanyBasic 公司信息 +type ManageCompanyBasic struct { + CompanyID uint64 `json:"company_id"` + CompanyKind ManageCompanyKind `json:"company_kind"` + CompanyName string `json:"company_name"` + CompanyImage string `json:"company_image"` + CompanyUrl string `json:"company_url"` + CompanyKeyword string `json:"company_keyword"` +} + type ManageCompanyKind int const ( @@ -33,16 +43,6 @@ func (m *ManageCompany) TableName() string { return "manage_company" } -func (m *ManageCompany) GetKindAttribute() []int { - out := make([]int, 0) - _ = utils.FromJSON(m.Industry, &out) - return out -} - -func (m *ManageCompany) SetKindAttribute(value []int) { - m.Industry = utils.AnyToJSON(value) -} - func (m *ManageCompany) GetIndustryAttribute() []string { out := make([]string, 0) _ = utils.FromJSON(m.Industry, &out) diff --git a/app/common/model/technology_prodcut_visit.go b/app/common/model/technology_prodcut_visit.go index c995f08..6dbd4f8 100644 --- a/app/common/model/technology_prodcut_visit.go +++ b/app/common/model/technology_prodcut_visit.go @@ -1,10 +1,13 @@ package model +import "time" + // TechnologyProductVisit 技术产品访问数据模型 type TechnologyProductVisit struct { Model - ProductID uint64 `gorm:"column:product_id;type:int(11);default:0;comment:科技产品ID" json:"product_id"` - CompanyID uint64 `gorm:"column:company_id;type:int(11);default:0;comment:公司ID" json:"company_id"` + ProductID uint64 `gorm:"column:product_id;index:idx_product_visit_product;type:int(11);default:0;comment:科技产品ID" json:"product_id"` + CompanyID uint64 `gorm:"column:company_id;type:int(11);default:0;comment:公司ID" json:"company_id"` + VisitAt time.Time `gorm:"column:visit_at;type:datetime;not null;comment:浏览时间" json:"visit_at"` ModelDeleted ModelAt } diff --git a/router/address.go b/router/address.go index 0a6360e..27933ad 100644 --- a/router/address.go +++ b/router/address.go @@ -202,6 +202,7 @@ func registerEnterpriseAPI(app *gin.Engine) { technologyV1.POST("/topic/edit", _api.TopicEdit) technologyV1.POST("/topic/delete", _api.TopicDelete) technologyV1.POST("/product", _api.Product) + technologyV1.POST("/product/visit", _api.ProductVisit) technologyV1.POST("/product/add", _api.ProductAdd) technologyV1.POST("/product/edit", _api.ProductEdit) technologyV1.POST("/product/shelf", _api.ProductShelf)