|
@@ -30,6 +30,7 @@ type EnterpriseSearch struct {
|
|
PageSize int //每页数量
|
|
PageSize int //每页数量
|
|
PageNum int //页码
|
|
PageNum int //页码
|
|
IsVip bool //是否是会员
|
|
IsVip bool //是否是会员
|
|
|
|
+ IsFree bool //是否免费用户
|
|
}
|
|
}
|
|
|
|
|
|
const (
|
|
const (
|
|
@@ -254,7 +255,7 @@ func (es *EnterpriseSearch) GetQuerySql() (string, string) {
|
|
// DoQuery 根据EnterpriseSearch参数进行企业相关查询
|
|
// DoQuery 根据EnterpriseSearch参数进行企业相关查询
|
|
func (es *EnterpriseSearch) DoQuery() (list *[]map[string]interface{}, total int64, err error) {
|
|
func (es *EnterpriseSearch) DoQuery() (list *[]map[string]interface{}, total int64, err error) {
|
|
if es.isEmptySearch() { //是否是空查询,返回默认企业
|
|
if es.isEmptySearch() { //是否是空查询,返回默认企业
|
|
- list = GetEntIndexShow()
|
|
|
|
|
|
+ list = GetEntIndexShow(es.IsFree)
|
|
if list != nil {
|
|
if list != nil {
|
|
total = int64(len(*list))
|
|
total = int64(len(*list))
|
|
start := es.PageNum * es.PageSize
|
|
start := es.PageNum * es.PageSize
|
|
@@ -287,7 +288,7 @@ func (es *EnterpriseSearch) DoQuery() (list *[]map[string]interface{}, total int
|
|
sql = sql[:len(sql)-1] + fmt.Sprintf(`,"from":%d,"size":%d}`, start, limit)
|
|
sql = sql[:len(sql)-1] + fmt.Sprintf(`,"from":%d,"size":%d}`, start, limit)
|
|
list = elastic.Get(index, itype, sql)
|
|
list = elastic.Get(index, itype, sql)
|
|
|
|
|
|
- list = formatData(list)
|
|
|
|
|
|
+ list = formatData(list, es.IsFree)
|
|
if total > config.Config.EntSearchLimit {
|
|
if total > config.Config.EntSearchLimit {
|
|
total = config.Config.EntSearchLimit
|
|
total = config.Config.EntSearchLimit
|
|
}
|
|
}
|
|
@@ -295,9 +296,13 @@ func (es *EnterpriseSearch) DoQuery() (list *[]map[string]interface{}, total int
|
|
}
|
|
}
|
|
|
|
|
|
// //格式化字段,加密id
|
|
// //格式化字段,加密id
|
|
-func formatData(list *[]map[string]interface{}) *[]map[string]interface{} {
|
|
|
|
|
|
+func formatData(list *[]map[string]interface{}, isFree bool) *[]map[string]interface{} {
|
|
if list != nil {
|
|
if list != nil {
|
|
- for index, _ := range *list {
|
|
|
|
|
|
+ delStr := []string{"_id", "establish_date"}
|
|
|
|
+ if isFree {
|
|
|
|
+ delStr = append(delStr, "company_phone")
|
|
|
|
+ }
|
|
|
|
+ for index := range *list {
|
|
(*list)[index]["id"] = encrypt.EncodeArticleId2ByCheck(qutil.ObjToString((*list)[index]["_id"]))
|
|
(*list)[index]["id"] = encrypt.EncodeArticleId2ByCheck(qutil.ObjToString((*list)[index]["_id"]))
|
|
if shortname, ok := ((*list)[index]["company_shortname"]).(string); !ok || shortname == "" {
|
|
if shortname, ok := ((*list)[index]["company_shortname"]).(string); !ok || shortname == "" {
|
|
(*list)[index]["company_shortname"] = getCompanyShortName(qutil.ObjToString((*list)[index]["company_name"]))
|
|
(*list)[index]["company_shortname"] = getCompanyShortName(qutil.ObjToString((*list)[index]["company_name"]))
|
|
@@ -308,7 +313,7 @@ func formatData(list *[]map[string]interface{}) *[]map[string]interface{} {
|
|
}
|
|
}
|
|
|
|
|
|
//清除多余字段
|
|
//清除多余字段
|
|
- for _, key := range []string{"_id", "establish_date"} {
|
|
|
|
|
|
+ for _, key := range delStr {
|
|
delete((*list)[index], key)
|
|
delete((*list)[index], key)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -335,7 +340,7 @@ type entIds struct {
|
|
} `json:"entids"`
|
|
} `json:"entids"`
|
|
}
|
|
}
|
|
|
|
|
|
-func GetEntIndexShow() (list *[]map[string]interface{}) {
|
|
|
|
|
|
+func GetEntIndexShow(isFree bool) (list *[]map[string]interface{}) {
|
|
bytes, err := redis.GetBytes(entSearchCacheDB, entSearchCacheKey)
|
|
bytes, err := redis.GetBytes(entSearchCacheDB, entSearchCacheKey)
|
|
if err == nil {
|
|
if err == nil {
|
|
if err = json.Unmarshal(*bytes, &list); err == nil && list != nil && len(*list) > 0 {
|
|
if err = json.Unmarshal(*bytes, &list); err == nil && list != nil && len(*list) > 0 {
|
|
@@ -366,7 +371,7 @@ func GetEntIndexShow() (list *[]map[string]interface{}) {
|
|
sql = sql[:len(sql)-1] + fmt.Sprintf(`,"from":%d,"size":%d}`, 0, 100)
|
|
sql = sql[:len(sql)-1] + fmt.Sprintf(`,"from":%d,"size":%d}`, 0, 100)
|
|
listTmp := elastic.Get(index, itype, sql)
|
|
listTmp := elastic.Get(index, itype, sql)
|
|
if listTmp != nil && len(*listTmp) > 0 {
|
|
if listTmp != nil && len(*listTmp) > 0 {
|
|
- list = formatData(listTmp)
|
|
|
|
|
|
+ list = formatData(listTmp, isFree)
|
|
redis.Put(entSearchCacheDB, entSearchCacheKey, list, 60*60*10)
|
|
redis.Put(entSearchCacheDB, entSearchCacheKey, list, 60*60*10)
|
|
}
|
|
}
|
|
return
|
|
return
|