feat:完成首页搜索功能

This commit is contained in:
henry
2022-01-18 16:29:29 +08:00
parent 478182dcb0
commit 10224e8db6
21 changed files with 572 additions and 167 deletions

View File

@ -17,8 +17,8 @@ type TechnologyAchievementInfo struct {
CollectCount int `json:"collect_count"`
}
// Achievement 成果信息
func (m *TechnologyAchievement) Achievement(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyAchievementInfo, error) {
// Achievements 成果信息
func (m *TechnologyAchievement) Achievements(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*TechnologyAchievementInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS a").
Select("a.id", "a.title", "a.mode", "a.image", "a.charge_info", "a.industry", "a.customer", "a.maturity",
"a.cooperation_mode", "a.keyword", "v.count AS visit_count", "c.count AS collect_count").
@ -45,6 +45,32 @@ func (m *TechnologyAchievement) Achievement(page, pageSize int, count *int64, wh
return out, nil
}
// Achievement 成果信息
func (m *TechnologyAchievement) Achievement(where ...*model.ModelWhere) ([]*TechnologyAchievementInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS a").
Select("a.id", "a.title", "a.mode", "a.image", "a.charge_info", "a.industry", "a.customer", "a.maturity",
"a.cooperation_mode", "a.keyword", "v.count AS visit_count", "c.count AS collect_count").
Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, SUM(count) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS v ON a.id = v.object_id",
model.NewUserVisit().TableName(), model.UserCollectKindForTechnologyAchievement, model.DeleteStatusForNot)).
Joins(fmt.Sprintf("LEFT JOIN (SELECT object_id, COUNT(id) AS count FROM %s WHERE kind = %d AND is_deleted = %d GROUP BY object_id) AS c ON a.id = c.object_id",
model.NewUserCollect().TableName(), model.UserCollectKindForTechnologyAchievement, model.DeleteStatusForNot)).
Where("a.status = ?", model.TechnologyAchievementStatusForAgree).
Where("a.is_deleted = ?", model.DeleteStatusForNot)
out := make([]*TechnologyAchievementInfo, 0)
if len(where) > 0 {
for _, v := range where {
db = db.Where(v.Condition, v.Value)
}
}
if err := db.Order("a.id " + model.OrderModeToDesc).Scan(&out).Error; err != nil {
return nil, err
}
return out, nil
}
// Detail 成果详细信息
func (m *TechnologyAchievement) Detail(id uint64) (*TechnologyAchievementInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS a").