feat:完善产品详情
This commit is contained in:
@ -1,11 +1,57 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
import (
|
||||
"SciencesServer/app/basic/config"
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type TechnologyProduct struct {
|
||||
*model.TechnologyProduct
|
||||
}
|
||||
|
||||
// TechnologyProductInfo 产品信息
|
||||
type TechnologyProductInfo struct {
|
||||
model.Model
|
||||
Title string `json:"title"`
|
||||
model.Image
|
||||
Maturity config.TechnologyMaturity `json:"maturity"`
|
||||
LeadStandard model.TechnologyProductLeadStandard `json:"lead_standard"`
|
||||
CooperationMode config.TechnologyCooperationMode `json:"cooperation_mode"`
|
||||
Industry string `json:"industry"`
|
||||
Keyword string `json:"keyword"`
|
||||
VisitCount int `json:"visit_count"`
|
||||
CollectCount int `json:"collect_count"`
|
||||
}
|
||||
|
||||
// Product 产品信息
|
||||
func (m *TechnologyProduct) Product(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyProductInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS p").
|
||||
Select("p.id", "p.title", "p.image", "p.maturity", "p.industry", "p.cooperation_mode", "p.keyword",
|
||||
"v.count AS v visit_count", "c.count AS collect_count").
|
||||
Joins(fmt.Sprintf("(SELECT company_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY company_id) AS v ON p.id = v.company_id",
|
||||
model.NewTechnologyProductVisit().TableName(), model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("(SELECT company_id, COUNT(id) AS count FROM %s WHERE is_deleted = %d GROUP BY company_id) AS c ON p.id = c.company_id",
|
||||
model.NewTechnologyProductCollect().TableName(), model.DeleteStatusForNot))
|
||||
|
||||
out := make([]*TechnologyProductInfo, 0)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("p.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
|
||||
}
|
||||
|
||||
func NewTechnologyProduct() *TechnologyProduct {
|
||||
return &TechnologyProduct{model.NewTechnologyProduct()}
|
||||
}
|
||||
|
11
app/api/enterprise/model/technology_product_collect.go
Normal file
11
app/api/enterprise/model/technology_product_collect.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type TechnologyProductCollect struct {
|
||||
*model.TechnologyProductCollect
|
||||
}
|
||||
|
||||
func NewTechnologyProductCollect() *TechnologyProductCollect {
|
||||
return &TechnologyProductCollect{model.NewTechnologyProductCollect()}
|
||||
}
|
Reference in New Issue
Block a user