package search import ( "SciencesServer/app/api/website/model" model2 "SciencesServer/app/common/model" "fmt" "time" ) type ( // DemandInfo 需求信息 DemandInfo struct { ID string `json:"id"` Title string `json:"title"` Mode string `json:"mode"` Kind string `json:"kind"` Industrys []string `json:"industrys"` Budget float64 `json:"budget"` BudgetMode model2.TechnologyDemandBudgetMode `json:"budget_mode"` Deadline time.Time `json:"deadline"` } ) // searchDemand 需求搜索 func searchDemand(page, pageSize int, keyword, industry string, params map[string]interface{}) (interface{}, error) { mTechnologyDemand := model.NewTechnologyDemand() out := make([]*model2.TechnologyDemand, 0) where := []*model2.ModelWhereOrder{ &model2.ModelWhereOrder{ Where: model2.NewWhere("status", model2.TechnologyDemandStatusForAgree), Order: model2.NewOrder("id", model2.OrderModeToDesc), }, } if keyword != "" { where = append(where, &model2.ModelWhereOrder{ Where: model2.NewWhereLike("title", keyword), }) } if industry != "" { where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhereCondition("industry", "LIKE", "%"+fmt.Sprintf(`"%v`, industry)+"%")}) } if len(params) > 0 { for k, v := range params { where = append(where, &model2.ModelWhereOrder{ Where: model2.NewWhere(k, v), }) } } var count int64 if err := model2.PagesFields(mTechnologyDemand.TechnologyDemand, &out, []string{"id", "title", "mode", "kind", "industry", "budget", "budget_mode", "deadline"}, page, pageSize, &count, where...); err != nil { return nil, err } list := make([]*DemandInfo, 0) for _, v := range out { list = append(list, &DemandInfo{ ID: v.GetEncodeID(), Title: v.Title, Mode: v.Mode, Kind: v.Kind, Industrys: v.GetIndustryAttribute(), Budget: v.Budget, BudgetMode: v.BudgetMode, Deadline: v.Deadline, }) } return list, nil }