|
@@ -5,8 +5,7 @@ import (
|
|
|
"container/list"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
- "github.com/go-xweb/httpsession"
|
|
|
- _ "github.com/go-xweb/xweb"
|
|
|
+ "github.com/go-xweb/xweb"
|
|
|
mgo "gopkg.in/mgo.v2"
|
|
|
. "gopkg.in/mgo.v2/bson"
|
|
|
"html/template"
|
|
@@ -132,206 +131,126 @@ func GetEntInfo(id string) map[string]interface{} {
|
|
|
(*res)["s_action"] = "N"
|
|
|
}
|
|
|
}
|
|
|
- log.Println(res)
|
|
|
- return *res
|
|
|
- }
|
|
|
- return nil
|
|
|
-}
|
|
|
-func WxGetEntInfo(id string, flag bool) interface{} {
|
|
|
- res := FindById("enterprise", id, `{"RegNo":1, "EntName":1, "EntType":1, "EntTypeName":1, "OpLocDistrict":1, "LeRep":1, "LegCerNO":1, "Tel":1, "Dom":1, "OpScope":1, "OpFrom":1, "OpTo":1, "RegCap":1, "EstDate":1, "CompForm":1, "CompFormName":1, "OpState":1, "OpStateName":1, "RegOrgName":1, "IssBLicDate":1, "Timestamp":1, "s_synopsis":1, "SourceType":1, "s_weixin":1, "s_enturl, "i_province":1, "i_city":1, "i_area":1,"s_action":1,"s_persion":1,"s_mobile":1,"s_address":1,"s_avatar":1,"s_microwebsite":1,"s_qq":1,"s_submitid":1}`)
|
|
|
- if res != nil {
|
|
|
- submitid := (*res)["s_submitid"]
|
|
|
- if submitid != nil {
|
|
|
- ud := FindById("user", submitid.(string), `{"i_comauthenttype":1}`)
|
|
|
- (*res)["i_comauthenttype"] = (*ud)["i_comauthenttype"]
|
|
|
- }
|
|
|
- opl, _ := (*res)["OpLocDistrict"].(string)
|
|
|
- if len(opl) >= 2 {
|
|
|
- if v, ok := city_map[opl[:2]]; ok {
|
|
|
- (*res)["OpLoc"] = v
|
|
|
- }
|
|
|
- }
|
|
|
- syno, _ := (*res)["s_synopsis"].(string)
|
|
|
- (*res)["s_synopsis"] = template.HTML(syno)
|
|
|
- ty, _ := (*res)["SourceType"].(string)
|
|
|
- if ty == "01" {
|
|
|
- (*res)["gs"] = true
|
|
|
- } else {
|
|
|
- (*res)["gs"] = false
|
|
|
- }
|
|
|
- OpFrom := (*res)["OpFrom"]
|
|
|
- if OpFrom != nil {
|
|
|
- (*res)["OpFrom"] = FormatDate(&OpFrom)
|
|
|
- }
|
|
|
- OpTo := (*res)["OpTo"]
|
|
|
- if OpFrom != nil {
|
|
|
- (*res)["OpTo"] = FormatDate(&OpTo)
|
|
|
- }
|
|
|
- IssBLicDate := (*res)["IssBLicDate"]
|
|
|
- s_action := (*res)["s_action"]
|
|
|
- if s_action == nil || s_action == "" {
|
|
|
- (*res)["s_action"] = "N"
|
|
|
- }
|
|
|
- if OpFrom != nil {
|
|
|
- (*res)["IssBLicDate"] = FormatDate(&IssBLicDate)
|
|
|
- }
|
|
|
- EstDate := (*res)["EstDate"]
|
|
|
- if OpFrom != nil {
|
|
|
- (*res)["EstDate"] = FormatDate(&EstDate)
|
|
|
- }
|
|
|
- //查询企业关系
|
|
|
- //relation := Find("entrelation", &map[string]interface{}{
|
|
|
- // "aid": ObjectIdHex(id),
|
|
|
- //}, nil, nil, false, -1, -1)
|
|
|
- EntType, _ := (*res)["EntType"].(string)
|
|
|
- //处理分公司
|
|
|
- if EntType != "" {
|
|
|
- if EntType == "5810" || EntType == "6810" || EntType == "7310" || EntType == "3200" || EntType == "3100" {
|
|
|
- (*res)["EntType"] = "5810"
|
|
|
- } else if len(EntType) > 1 {
|
|
|
- if EntType[:1] == "2" {
|
|
|
- (*res)["EntType"] = "5810"
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- en, _ := (*res)["EntName"].(string)
|
|
|
- if en == "" {
|
|
|
- (*res)["EntName"] = (*res)["LeRep"]
|
|
|
- }
|
|
|
- //
|
|
|
- (*res)["EntTypeLabel"] = (mobile.GetDiffName(EntType))[0]
|
|
|
- if flag {
|
|
|
- RegNo, _ := (*res)["RegNo"].(string)
|
|
|
- relation := makeRelation(RegNo, en)
|
|
|
- if relation != nil {
|
|
|
- (*res)["relation"] = relation
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- (*res)["entid"] = id
|
|
|
return *res
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-//企业黄查询结果
|
|
|
-func (yp *Yellowpage) WxenterpriseInfo(regNO string) error {
|
|
|
- r := FindOne("enterprise", M{"RegNo": regNO})
|
|
|
- if r == nil || len(*r) == 0 {
|
|
|
- return yp.Render("/yellowpage/error.html")
|
|
|
- }
|
|
|
- id := strings.Split(fmt.Sprintf("%s", (*r)["_id"]), `"`)[1]
|
|
|
- return yp.Redirect("/enterprise/" + id + ".html")
|
|
|
-}
|
|
|
-
|
|
|
//企业黄查询结果
|
|
|
func (yp *Yellowpage) EnterpriseInfo(id string) error {
|
|
|
id = strings.Split(id, "#")[0]
|
|
|
regex, _ := regexp.Compile("(Android|Mobile)")
|
|
|
- ismobile := regex.FindAllString(yp.Header("User-Agent"), -1)
|
|
|
+ ismobile := len(regex.FindAllString(yp.Header("User-Agent"), -1)) > 0
|
|
|
key := "enterpriseInfo_"
|
|
|
- if len(ismobile) > 0 {
|
|
|
+ if ismobile {
|
|
|
key = "menterpriseInfo_"
|
|
|
}
|
|
|
if ret, err := redis.GetBytes("enterprise", key+id); err == nil {
|
|
|
return yp.SetBody(*ret)
|
|
|
} else {
|
|
|
- if info := GetEntInfo(id); info != nil {
|
|
|
- yp.T["res"] = info
|
|
|
- regNo, _ := info["RegNo"].(string)
|
|
|
- entName, _ := info["EntName"].(string)
|
|
|
- relation, relflag := getRelation(regNo, entName)
|
|
|
- var nodes *[]map[string]interface{}
|
|
|
- if relflag {
|
|
|
- if d, err := json.Marshal(relation["nodes"]); err == nil && json.Unmarshal(d, &nodes) == nil && len(*nodes) > 0 {
|
|
|
- //相关企业
|
|
|
- var entmids []ObjectId
|
|
|
- for _, v := range *nodes {
|
|
|
- if v["type"] == "e" && v["entmid"] != nil && v["entmid"].(string) != "" {
|
|
|
- entmids = append(entmids, ObjectIdHex(v["entmid"].(string)))
|
|
|
- }
|
|
|
+ return CommonEntInfo(yp.Action, id, 0, ismobile)
|
|
|
+ }
|
|
|
+}
|
|
|
+func CommonEntInfo(yp *xweb.Action, id string, editFlag int, ismobile bool) error {
|
|
|
+ if info := GetEntInfo(id); info != nil {
|
|
|
+ yp.T["res"] = info
|
|
|
+ regNo, _ := info["RegNo"].(string)
|
|
|
+ entName, _ := info["EntName"].(string)
|
|
|
+ relation, relflag := getRelation(regNo, entName)
|
|
|
+ var nodes *[]map[string]interface{}
|
|
|
+ if relflag {
|
|
|
+ if d, err := json.Marshal(relation["nodes"]); err == nil && json.Unmarshal(d, &nodes) == nil && len(*nodes) > 0 {
|
|
|
+ //相关企业
|
|
|
+ var entmids []ObjectId
|
|
|
+ for _, v := range *nodes {
|
|
|
+ if v["type"] == "e" && v["entmid"] != nil && v["entmid"].(string) != "" {
|
|
|
+ entmids = append(entmids, ObjectIdHex(v["entmid"].(string)))
|
|
|
}
|
|
|
- if len(entmids) > 0 {
|
|
|
- relevantEnts := mongodbutil.Find("enterprise", cf.SysConfig.EntMongodbAlias, cf.SysConfig.EntMongodbName, M{"_id": M{"$in": entmids}}, nil, `{"s_avatar":1,"RegNo":1,"EntName":1}`, false, -1, -1)
|
|
|
- if relevantEnts != nil && len(*relevantEnts) > 0 {
|
|
|
- for _, relevantEnt := range *relevantEnts {
|
|
|
- relevantEnt["_id"] = util.BsonIdToSId(relevantEnt["_id"])
|
|
|
- for _, node := range *nodes {
|
|
|
- if node["entmid"] != nil && node["entmid"].(string) == relevantEnt["_id"] {
|
|
|
- node["haslink"] = true
|
|
|
- break
|
|
|
- }
|
|
|
+ }
|
|
|
+ if len(entmids) > 0 {
|
|
|
+ relevantEnts := mongodbutil.Find("enterprise", cf.SysConfig.EntMongodbAlias, cf.SysConfig.EntMongodbName, M{"_id": M{"$in": entmids}}, nil, `{"s_avatar":1,"RegNo":1,"EntName":1}`, false, -1, -1)
|
|
|
+ if relevantEnts != nil && len(*relevantEnts) > 0 {
|
|
|
+ for _, relevantEnt := range *relevantEnts {
|
|
|
+ relevantEnt["_id"] = util.BsonIdToSId(relevantEnt["_id"])
|
|
|
+ for _, node := range *nodes {
|
|
|
+ if node["entmid"] != nil && node["entmid"].(string) == relevantEnt["_id"] {
|
|
|
+ node["haslink"] = true
|
|
|
+ break
|
|
|
}
|
|
|
}
|
|
|
- yp.T["relevantEnts"] = relevantEnts
|
|
|
}
|
|
|
- relation["nodes"] = nodes
|
|
|
- redis.Put("enterprise", "relation-"+regNo, relation, 7*ONEDAY)
|
|
|
+ yp.T["relevantEnts"] = relevantEnts
|
|
|
}
|
|
|
+ relation["nodes"] = nodes
|
|
|
+ redis.Put("enterprise", "relation-"+regNo, relation, 7*ONEDAY)
|
|
|
}
|
|
|
}
|
|
|
- //相关新闻
|
|
|
- var ids []ObjectId
|
|
|
- newsIds := Find("rel_news", `{"s_entid":"`+id+`"}`, nil, `{"s_newsid":1}`, false, -1, -1)
|
|
|
- if newsIds != nil && len(*newsIds) > 0 {
|
|
|
- for _, v := range *newsIds {
|
|
|
- if v["s_newsid"] != nil {
|
|
|
- newsid, _ := v["s_newsid"].(string)
|
|
|
- if newsid == "" {
|
|
|
- continue
|
|
|
- }
|
|
|
- ids = append(ids, ObjectIdHex(newsid))
|
|
|
+ }
|
|
|
+ //相关新闻
|
|
|
+ var ids []ObjectId
|
|
|
+ newsIds := Find("rel_news", `{"s_entid":"`+id+`"}`, nil, `{"s_newsid":1}`, false, -1, -1)
|
|
|
+ if newsIds != nil && len(*newsIds) > 0 {
|
|
|
+ for _, v := range *newsIds {
|
|
|
+ if v["s_newsid"] != nil {
|
|
|
+ newsid, _ := v["s_newsid"].(string)
|
|
|
+ if newsid == "" {
|
|
|
+ continue
|
|
|
}
|
|
|
+ ids = append(ids, ObjectIdHex(newsid))
|
|
|
}
|
|
|
- if len(ids) > 0 {
|
|
|
- news := Find("trs_news", M{"_id": M{"$in": ids}}, `{"l_comeintime":-1}`, `{"s_link":1,"s_title":1,"l_comeintime":1}`, false, 0, 8)
|
|
|
- if news != nil && len(*news) > 0 {
|
|
|
- yp.T["relevantNews"] = news
|
|
|
- }
|
|
|
+ }
|
|
|
+ if len(ids) > 0 {
|
|
|
+ news := Find("trs_news", M{"_id": M{"$in": ids}}, `{"l_comeintime":-1}`, `{"s_link":1,"s_title":1,"l_comeintime":1}`, false, 0, 8)
|
|
|
+ if news != nil && len(*news) > 0 {
|
|
|
+ yp.T["relevantNews"] = news
|
|
|
}
|
|
|
}
|
|
|
- //失信信息第一页数据
|
|
|
- yp.T["dishonesty"] = getDishonesty(util.If(info["LegCerNO"] != nil, info["LegCerNO"], "").(string), 1)
|
|
|
- //服务列表第一页数据
|
|
|
- yp.T["service"] = findServiceByEntId(id, 1, yp.Session())
|
|
|
- //关系网数据
|
|
|
- yp.T["relflag"] = relflag
|
|
|
- //著作权
|
|
|
- yp.T["copyright"] = FindOne("enterprise_copyright", `{"EntId":"`+id+`"}`)
|
|
|
-
|
|
|
+ }
|
|
|
+ //失信信息第一页数据
|
|
|
+ yp.T["dishonesty"] = getDishonesty(util.If(info["LegCerNO"] != nil, info["LegCerNO"], "").(string), 1)
|
|
|
+ //关系网数据
|
|
|
+ yp.T["relflag"] = relflag
|
|
|
+ //著作权
|
|
|
+ yp.T["copyright"] = FindOne("enterprise_copyright", `{"EntId":"`+id+`"}`)
|
|
|
+ //编辑企业名片标识
|
|
|
+ yp.T["editFlag"] = editFlag
|
|
|
+ //过滤企业名
|
|
|
+ if relflag && nodes != nil && len(*nodes) > 0 {
|
|
|
+ go func() {
|
|
|
+ util.Try(func() {
|
|
|
+ if filterEntName(nodes) > 0 {
|
|
|
+ relation["nodes"] = nodes
|
|
|
+ redis.Put("enterprise", "relation-"+regNo, relation, 7*ONEDAY)
|
|
|
+ redis.Del("enterprise", "enterpriseInfo_"+id)
|
|
|
+ }
|
|
|
+ }, func(e interface{}) {
|
|
|
+ log.Println("过滤企业名出错:", e)
|
|
|
+ })
|
|
|
+ }()
|
|
|
+ }
|
|
|
+ if editFlag > 0 {
|
|
|
+ return yp.Render("/enterprise/detail.html", &yp.T)
|
|
|
+ } else {
|
|
|
+ //服务数量
|
|
|
+ yp.T["serviceCount"] = getEntServiceCount(id)
|
|
|
var contentuser []byte
|
|
|
var erruser error
|
|
|
- if len(ismobile) > 0 {
|
|
|
+ if ismobile {
|
|
|
contentuser, erruser = yp.Render4Cache("/member/incmobile/detailindex.html", &yp.T)
|
|
|
} else {
|
|
|
- contentuser, erruser = yp.Render4Cache("/yellowpage/enterpriseinfo.html", &yp.T)
|
|
|
+ contentuser, erruser = yp.Render4Cache("/enterprise/detail.html", &yp.T)
|
|
|
}
|
|
|
-
|
|
|
if erruser == nil {
|
|
|
- if len(ismobile) > 0 {
|
|
|
+ if ismobile {
|
|
|
redis.PutBytes("enterprise", "menterpriseInfo_"+id, &contentuser, 7*ONEDAY)
|
|
|
} else {
|
|
|
redis.PutBytes("enterprise", "enterpriseInfo_"+id, &contentuser, 7*ONEDAY)
|
|
|
}
|
|
|
}
|
|
|
- //过滤企业名
|
|
|
- if relflag && nodes != nil && len(*nodes) > 0 {
|
|
|
- go func() {
|
|
|
- util.Try(func() {
|
|
|
- if filterEntName(nodes) > 0 {
|
|
|
- relation["nodes"] = nodes
|
|
|
- redis.Put("enterprise", "relation-"+regNo, relation, 7*ONEDAY)
|
|
|
- redis.Del("enterprise", "enterpriseInfo_"+id)
|
|
|
- }
|
|
|
- }, func(e interface{}) {
|
|
|
- log.Println("过滤企业名出错:", e)
|
|
|
- })
|
|
|
- }()
|
|
|
- }
|
|
|
return yp.SetBody(contentuser)
|
|
|
- } else {
|
|
|
- return yp.Render("/_error.html")
|
|
|
}
|
|
|
+ } else {
|
|
|
+ return yp.Render("/_error.html")
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -608,67 +527,16 @@ func getDishonesty(legcerNo string, currentPage int) map[string]interface{} {
|
|
|
return ret
|
|
|
}
|
|
|
}
|
|
|
-func (yp *Yellowpage) FindServiceByEntId() error {
|
|
|
- if yp.Method() == "POST" {
|
|
|
- id := yp.GetString("entId")
|
|
|
- currentPage, _ := yp.GetInteger("currentPage")
|
|
|
- yp.ServeJson(findServiceByEntId(id, currentPage, yp.Session()))
|
|
|
- }
|
|
|
- return nil
|
|
|
-}
|
|
|
-func findServiceByEntId(id string, currentPage int, session *httpsession.Session) map[string]interface{} {
|
|
|
- var res map[string]interface{}
|
|
|
- if ret := redis.Get("enterprise", "service-"+id+"-"+fmt.Sprint(currentPage)); ret != nil {
|
|
|
- res = ret.(map[string]interface{})
|
|
|
- } else {
|
|
|
- limit := 10
|
|
|
- start := (currentPage - 1) * limit
|
|
|
- var count int64
|
|
|
- //分页
|
|
|
- mustnot := `{"term" : {"i_status" : 1 }}`
|
|
|
- var fields, collection, query, tempstrquery string
|
|
|
- collection = "service"
|
|
|
- tempstrquery = `{"query_string":{"default_field": "s_enterpriseid","query":"` + id + `"}}`
|
|
|
- servicequery := ""
|
|
|
- if session.Get("entid") == nil || session.Get("entid").(string) != id {
|
|
|
- servicequery = `,"must_not" : [` + mustnot + `]`
|
|
|
- }
|
|
|
- query = `{"query": {
|
|
|
+
|
|
|
+//获取该企业的服务数量
|
|
|
+func getEntServiceCount(id string) int64 {
|
|
|
+ query := `{"query": {
|
|
|
"bool": {
|
|
|
- "must":[` + tempstrquery + `]` + servicequery + `
|
|
|
+ "must":[{"query_string":{"default_field": "s_enterpriseid","query":"` + id + `"}}],"must_not" : [{"term" : {"i_status" : 1 }}]
|
|
|
}
|
|
|
}}`
|
|
|
- //需要查到的字段信息
|
|
|
- fields = `"_id","s_name","s_introduction","s_images","s_enterpriseid","s_isshow","i_status","s_pricemy","i_comments","f_price","i_sales"`
|
|
|
- if currentPage == 1 {
|
|
|
- count = elastic.Count("service", collection, query)
|
|
|
- }
|
|
|
- //查询服务列表数据
|
|
|
- result := elastic.Get("service", collection, `{"query":{"bool": {"must":[`+tempstrquery+`]`+servicequery+`}},
|
|
|
- _source:[`+fields+`],
|
|
|
- sort:{"l_createdate":"desc"},
|
|
|
- from:`+fmt.Sprintf("%v", start)+`,
|
|
|
- size:`+fmt.Sprintf("%v", limit)+`
|
|
|
- }`)
|
|
|
- for _, v := range *result {
|
|
|
- b, _ := checkAuth(v)
|
|
|
- if b {
|
|
|
- v["s_isEdit"] = "1"
|
|
|
- } else {
|
|
|
- v["s_isEdit"] = "0"
|
|
|
- }
|
|
|
- if util.IntAll(v["i_status"]) == 1 {
|
|
|
- v["s_remove"] = 1
|
|
|
- } else {
|
|
|
- v["s_remove"] = 0
|
|
|
- }
|
|
|
- }
|
|
|
- res = map[string]interface{}{"list": result, "count": count, "pageSize": limit}
|
|
|
- redis.Put("enterprise", "service-"+id+"-"+fmt.Sprint(currentPage), res, 7*24*60*60)
|
|
|
- }
|
|
|
- return res
|
|
|
+ return elastic.Count("service", "service", query)
|
|
|
}
|
|
|
-
|
|
|
func checkAuth(obj map[string]interface{}) (b bool, err string) {
|
|
|
if len(obj) > 0 {
|
|
|
//判断有没有预约的情况
|