|
@@ -0,0 +1,516 @@
|
|
|
+package jyutil
|
|
|
+
|
|
|
+import (
|
|
|
+ util "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ mgo "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
+ "app.yhyue.com/moapp/jypkg/public"
|
|
|
+ "fmt"
|
|
|
+ "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
+ "html/template"
|
|
|
+ "jy/src/jfw/modules/app/src/jfw/config"
|
|
|
+ "log"
|
|
|
+ "math/rand"
|
|
|
+ "regexp"
|
|
|
+ "sort"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ ColumnRelationship map[string]Navigation
|
|
|
+ se = &encrypt.SimpleEncrypt{Key: "topnet2015topnet2015"}
|
|
|
+ Date_yyyyMMdd_Bias = "2006/01/02"
|
|
|
+)
|
|
|
+
|
|
|
+type Navigation struct {
|
|
|
+ Name string
|
|
|
+ Code string
|
|
|
+ Href string
|
|
|
+ Pid string
|
|
|
+ Url string
|
|
|
+}
|
|
|
+
|
|
|
+type HelpColumn struct {
|
|
|
+ Id string `json:"id"` //文章id
|
|
|
+ Name string `json:"name"` //栏目名称或文章标题
|
|
|
+ Code string `json:"code"` //栏目code
|
|
|
+ IsColumn int `json:"isColumn"` //0 栏目 1 文章 2 视频
|
|
|
+ Href string `json:"href"`
|
|
|
+ SeedData []HelpColumn `json:"seedData"` //子集
|
|
|
+}
|
|
|
+
|
|
|
+func InitColumnData() {
|
|
|
+ ColumnRelationship = make(map[string]Navigation)
|
|
|
+ jySchoolUrl, _ := config.Seoconfig["strategyUrl"].(map[string]interface{})
|
|
|
+ fmt.Println("获取url", jySchoolUrl)
|
|
|
+ jySchoolCode := util.InterfaceToStr(config.Seoconfig["strategyCode"])
|
|
|
+
|
|
|
+ column, _ := mongodb.Find("column", nil, "", "", false, -1, -1)
|
|
|
+ if column != nil && len(*column) > 0 {
|
|
|
+ for _, v := range *column {
|
|
|
+ var (
|
|
|
+ data Navigation
|
|
|
+ href string
|
|
|
+ )
|
|
|
+ code := util.InterfaceToStr(v["s_columncode"])
|
|
|
+ pid := util.InterfaceToStr(v["pid"])
|
|
|
+ if code == jySchoolCode {
|
|
|
+ href = util.InterfaceToStr(jySchoolUrl["homeUrl"])
|
|
|
+ } else if pid == jySchoolCode {
|
|
|
+ href = fmt.Sprintf(util.InterfaceToStr(jySchoolUrl["towUrl"]), code)
|
|
|
+ } else {
|
|
|
+ log.Printf("未知栏目code,code:%s", code)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ data.Url = href
|
|
|
+ data.Code = code
|
|
|
+ data.Name = util.InterfaceToStr(v["s_columnname"])
|
|
|
+ data.Pid = pid
|
|
|
+ ColumnRelationship[code] = data
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func GetNewStrategy(t string, num int) (res []*InfoList) {
|
|
|
+ query := map[string]interface{}{"s_contenttype": t, "i_status": 1, "releasetime": map[string]interface{}{"$lt": time.Now().Unix()}}
|
|
|
+ data, _ := mongodb.Find("content", query, `{"releasetime":-1}`, `{"_id":1,"i_viewnum":1,s_title":1,"s_pic1":1,"s_pic":1,"releasetime":1,"s_description":1,"l_createdate":1,"s_contenttype":1,"s_secondclassifytype":1}`, false, 0, num)
|
|
|
+ if data != nil {
|
|
|
+ for _, v := range *data {
|
|
|
+ s_title := util.InterfaceToStr(v["s_title"])
|
|
|
+ res = append(res, &InfoList{
|
|
|
+ Title: s_title,
|
|
|
+ Url: fmt.Sprintf("/jySite/%s.html", se.EncodeString(util.InterfaceToStr(v["_id"]))),
|
|
|
+ })
|
|
|
+ v["_id"] = se.EncodeString(util.InterfaceToStr(v["_id"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res
|
|
|
+}
|
|
|
+
|
|
|
+// GuidelineColumn 攻略一级栏目与二级栏目
|
|
|
+func GuidelineColumn() HelpColumn {
|
|
|
+ return GuidelineAndIndustry(util.ObjToString(config.Seoconfig["strategyCode"]))
|
|
|
+}
|
|
|
+
|
|
|
+// 首页剑鱼攻略 s二级栏目
|
|
|
+func Guideline(s string, num int) *[]map[string]interface{} {
|
|
|
+ //columnCode, _ := config.Sysconfig["columnCode"].(map[string]interface{})
|
|
|
+ return GuidelineAndInformation(util.ObjToString(config.Seoconfig["strategyCode"]), s, num)
|
|
|
+}
|
|
|
+
|
|
|
+// GuidelineAndInformation t:一级栏目 s二级栏目 (首页剑鱼攻略与行业资讯首页公用)
|
|
|
+func GuidelineAndInformation(t, s string, num int) *[]map[string]interface{} {
|
|
|
+ query := map[string]interface{}{"s_contenttype": t, "s_secondclassifytype": s, "i_status": 1, "releasetime": map[string]interface{}{"$lt": time.Now().Unix()}}
|
|
|
+ data, _ := mongodb.Find("content", query, `{"releasetime":-1}`, `{"_id":1,s_title":1,"s_pic1":1,"s_pic":1,"releasetime":1,"s_description":1,"s_contenttype":1,"s_secondclassifytype":1}`, false, 0, num)
|
|
|
+ if data != nil {
|
|
|
+ for _, v := range *data {
|
|
|
+ s_title, _ := v["s_title"].(string)
|
|
|
+ v["s_title"] = template.HTML(s_title)
|
|
|
+ tmpdate1, _ := v["releasetime"]
|
|
|
+ //v["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1), 0))
|
|
|
+ reltime := time.Unix(util.Int64All(tmpdate1), 0)
|
|
|
+ v["time"] = reltime.Format(Date_yyyyMMdd_Bias) //首页展示
|
|
|
+ v["date"] = reltime //首页展示
|
|
|
+ v["_id"] = se.EncodeString(util.InterfaceToStr(v["_id"]))
|
|
|
+ v["s_pic"] = SPic(util.InterfaceToStr(v["s_pic"]))
|
|
|
+ v["s_pic1"] = SPic(util.InterfaceToStr(v["s_pic1"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return data
|
|
|
+}
|
|
|
+
|
|
|
+// GuidelineAndIndustry 获取攻略&资讯一级栏目与二级栏目 columnCode栏目code
|
|
|
+func GuidelineAndIndustry(columnCode string) HelpColumn {
|
|
|
+ var res HelpColumn
|
|
|
+ data1, ok := mongodb.FindOne("column", map[string]interface{}{
|
|
|
+ "s_columncode": columnCode,
|
|
|
+ })
|
|
|
+ //招投标攻略栏目一二级栏目获取
|
|
|
+ if ok && data1 != nil && len(*data1) > 0 {
|
|
|
+ res.Code = util.InterfaceToStr((*data1)["s_columncode"])
|
|
|
+ res.Name = util.InterfaceToStr((*data1)["s_columnname"])
|
|
|
+ data2, ok1 := mongodb.Find("column", map[string]interface{}{
|
|
|
+ "pid": columnCode,
|
|
|
+ }, `{"i_order":1}`, nil, false, -1, -1)
|
|
|
+ if ok1 && data2 != nil && len(*data2) > 0 {
|
|
|
+ var ss []HelpColumn
|
|
|
+ for _, v := range *data2 {
|
|
|
+ var s HelpColumn
|
|
|
+ s.Code = util.InterfaceToStr(v["s_columncode"])
|
|
|
+ s.Name = util.InterfaceToStr(v["s_columnname"])
|
|
|
+ ss = append(ss, s)
|
|
|
+ }
|
|
|
+ res.SeedData = ss
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res
|
|
|
+}
|
|
|
+
|
|
|
+func JyCmsSearch(query map[string]string, makePageFormat string) (*[]map[string]interface{}, *[]interface{}, int) {
|
|
|
+ perPage, _ := strconv.Atoi(query["perPage"])
|
|
|
+ currentPage, _ := strconv.Atoi(query["currentPage"])
|
|
|
+ //限制每页数量
|
|
|
+ if perPage <= 0 || perPage > 20 {
|
|
|
+ perPage = 5
|
|
|
+ }
|
|
|
+ if currentPage < 1 {
|
|
|
+ currentPage = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ queryStr := query["query"]
|
|
|
+ queryMap := map[string]interface{}{
|
|
|
+ "i_status": 1,
|
|
|
+ }
|
|
|
+ for _, v := range []string{"s_contenttype", "s_secondclassifytype", "s_threeclassifytype"} {
|
|
|
+ if query[v] != "" {
|
|
|
+ queryMap[v] = query[v]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ queryStrType := query["queryType"]
|
|
|
+ if queryStr != "" {
|
|
|
+ //攻略搜索只搜索标题
|
|
|
+ if queryStrType == "" {
|
|
|
+ queryMap["$or"] = []interface{}{
|
|
|
+ map[string]interface{}{
|
|
|
+ "s_title": map[string]interface{}{"$regex": queryStr},
|
|
|
+ },
|
|
|
+ map[string]interface{}{
|
|
|
+ "s_content": map[string]interface{}{"$regex": queryStr},
|
|
|
+ },
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ queryMap["$or"] = []interface{}{
|
|
|
+ map[string]interface{}{
|
|
|
+ "s_title": map[string]interface{}{"$regex": queryStr},
|
|
|
+ },
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ total := public.MQFW.Count("content", queryMap)
|
|
|
+ if total == 0 {
|
|
|
+ return nil, nil, 0
|
|
|
+ }
|
|
|
+ //查询列表数据
|
|
|
+ searchResult, _ := public.MQFW.Find("content", queryMap, `{"releasetime":-1}`, `{"s_title":1,"s_contenttype":1,"s_content":1,"releasetime":1,"s_description":1,"praise":1,"s_source":1,"s_pic":1,"s_pic1":1,"l_createdate":1,"_id":1,"s_author":1,"i_viewnum":1}`, false, (currentPage-1)*perPage, perPage)
|
|
|
+
|
|
|
+ var res []map[string]interface{}
|
|
|
+ if searchResult != nil && len(*searchResult) > 0 {
|
|
|
+ for _, m := range *searchResult {
|
|
|
+ s_content, _ := m["s_content"].(string)
|
|
|
+ if len(s_content) > 500 {
|
|
|
+ m["s_content"] = ""
|
|
|
+ } else {
|
|
|
+ con, _ := regexp.Compile("^[^<]*?>")
|
|
|
+ content := con.ReplaceAllString(s_content, "")
|
|
|
+ con1, _ := regexp.Compile("<[^>]*$")
|
|
|
+ m["s_content"] = template.HTML(con1.ReplaceAllString(content, ""))
|
|
|
+ }
|
|
|
+
|
|
|
+ s_title, _ := m["s_title"].(string)
|
|
|
+ m["s_title"] = template.HTML(s_title)
|
|
|
+
|
|
|
+ tmpdate, _ := m["l_createdate"]
|
|
|
+ m["l_createdate"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate), 0))
|
|
|
+ tmpdate1, _ := m["releasetime"]
|
|
|
+ m["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1), 0))
|
|
|
+ reltime := time.Unix(util.Int64All(tmpdate1), 0)
|
|
|
+ m["time"] = reltime.Format(Date_yyyyMMdd_Bias) //首页展示
|
|
|
+ s_pic, _ := m["s_pic"].(string)
|
|
|
+ if s_pic != "" {
|
|
|
+ s_pic = config.Seoconfig["jyadd"].(string) + s_pic
|
|
|
+ }
|
|
|
+ m["s_pic"] = s_pic
|
|
|
+ s_pic1, _ := m["s_pic1"].(string)
|
|
|
+ if s_pic1 != "" {
|
|
|
+ s_pic1 = config.Seoconfig["jyadd"].(string) + s_pic1
|
|
|
+ }
|
|
|
+ m["s_pic1"] = s_pic1
|
|
|
+ m["_id"] = se.EncodeString(mgo.BsonIdToSId(m["_id"]))
|
|
|
+ res = append(res, m)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //生成分页
|
|
|
+ /*if makePageFormat != "" {
|
|
|
+ pagination := MakePagination(perPage, currentPage, total, query, makePageFormat)
|
|
|
+ return &res, &pagination, total
|
|
|
+ }*/
|
|
|
+ return &res, nil, total
|
|
|
+}
|
|
|
+
|
|
|
+// 顶部分类导航
|
|
|
+func ClassNavBar() []Navigation {
|
|
|
+ var (
|
|
|
+ navigation []Navigation
|
|
|
+ )
|
|
|
+
|
|
|
+ column, ok := mongodb.Find("column", map[string]interface{}{"pid": util.ObjToString(config.Seoconfig["strategyCode"])}, `{"i_order":1}`, "", false, -1, -1)
|
|
|
+ if ok && column == nil || len(*column) == 0 {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ for _, v := range *column {
|
|
|
+ navigation = append(navigation, Navigation{
|
|
|
+ Name: util.ObjToString(v["s_columnname"]),
|
|
|
+ Code: util.ObjToString(v["s_columncode"]),
|
|
|
+ Pid: util.ObjToString(v["pid"]),
|
|
|
+ Href: fmt.Sprintf("/jySchool/%s/index.html", util.ObjToString(v["s_columncode"])),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return navigation
|
|
|
+}
|
|
|
+
|
|
|
+// GetBlogDetail 获取详情页内容
|
|
|
+func GetBlogDetail(_id string) (data *map[string]interface{}) {
|
|
|
+ id := se.DecodeString(_id)
|
|
|
+ r, _ := public.MQFW.FindById("content", id, `{"s_title":1,"s_contenttype":1,"s_content":1,"releasetime":1,"s_description":1,"praise":1,"s_source":1,"s_pic":1,"s_pic1":1,"l_createdate":1,"_id":1,"s_author":1,"s_editorname":1,"s_url":1,"s_subcontent":1,"s_keywords":1,"i_viewnum":1}`)
|
|
|
+ if r != nil {
|
|
|
+ tmpdate1, _ := (*r)["l_createdate"]
|
|
|
+ (*r)["l_createdate"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1), 0))
|
|
|
+ tmpdate2, _ := (*r)["releasetime"]
|
|
|
+ (*r)["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate2), 0))
|
|
|
+ newImg := fmt.Sprintf(`<img src="%simgFile`, util.InterfaceToStr(config.Seoconfig["jyadd"]))
|
|
|
+ s_content := strings.Replace(util.InterfaceToStr((*r)["s_content"]), `<img src="/imgFile`, newImg, -1)
|
|
|
+ (*r)["s_content"] = template.HTML(s_content)
|
|
|
+ (*r)["_id"] = se.EncodeString(mgo.BsonIdToSId((*r)["_id"]))
|
|
|
+ s_pic, _ := (*r)["s_pic"].(string)
|
|
|
+ if s_pic != "" {
|
|
|
+ s_pic = config.Seoconfig["jyadd"].(string) + s_pic
|
|
|
+ }
|
|
|
+ (*r)["s_pic"] = s_pic
|
|
|
+ s_pic1, _ := (*r)["s_pic1"].(string)
|
|
|
+ if s_pic1 != "" {
|
|
|
+ s_pic1 = config.Seoconfig["jyadd"].(string) + s_pic1
|
|
|
+ }
|
|
|
+ (*r)["s_pic1"] = s_pic1
|
|
|
+ i_viewnum := util.IntAll((*r)["i_viewnum"])
|
|
|
+ (*r)["i_viewnum"] = i_viewnum + 1
|
|
|
+ data = r
|
|
|
+
|
|
|
+ //增加浏览次数
|
|
|
+ go Browsing(id, i_viewnum)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GuidelineDetails 详情页 推荐
|
|
|
+func GuidelineDetails(id string, keyWord ...string) []map[string]interface{} {
|
|
|
+ doc, _ := mongodb.FindById("content", id, `{"releasetime":1,"i_viewnum":1,"s_contenttype":1,"s_secondclassifytype":1,"s_threeclassifytype":1}`)
|
|
|
+ if doc == nil || len(*doc) == 0 {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "i_status": 1,
|
|
|
+ "releasetime": map[string]interface{}{"$lt": time.Now().Unix()},
|
|
|
+ }
|
|
|
+ for _, t := range []string{"s_contenttype", "s_secondclassifytype", "s_threeclassifytype"} {
|
|
|
+ if tv, _ := (*doc)[t].(string); tv != "" && tv != "0" {
|
|
|
+ query[t] = tv
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _id, _ := primitive.ObjectIDFromHex(id)
|
|
|
+ if len(keyWord) > 0 {
|
|
|
+ query["s_title"] = map[string]interface{}{
|
|
|
+ "$regex": keyWord[0],
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //相关内容推荐
|
|
|
+ query["_id"] = map[string]interface{}{
|
|
|
+ "$ne": _id,
|
|
|
+ }
|
|
|
+
|
|
|
+ log.Println(" 详情页 推荐3", query)
|
|
|
+ var recommend []map[string]interface{}
|
|
|
+ dataRe, ok := mongodb.Find("content", query, `{"releasetime":-1}`, `{"_id":1,"i_viewnum":1,"s_title":1,"s_pic1":1,"s_pic":1,"releasetime":1,"s_description":1,"l_createdate":1,"s_contenttype":1,"s_secondclassifytype":1}`, false, 0, 500)
|
|
|
+ if ok && dataRe != nil && len(*dataRe) > 0 {
|
|
|
+ if len(*dataRe) > 3 {
|
|
|
+ for _, key := range GenerateRandomNumber(0, len(*dataRe), 3) {
|
|
|
+ recommend = append(recommend, (*dataRe)[key])
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ recommend = append(recommend, *dataRe...)
|
|
|
+ }
|
|
|
+ for _, v := range recommend {
|
|
|
+ v["_id"] = se.EncodeString(util.InterfaceToStr(v["_id"]))
|
|
|
+ s_title, _ := v["s_title"].(string)
|
|
|
+ v["s_title"] = template.HTML(s_title)
|
|
|
+
|
|
|
+ tmpdate, _ := v["l_createdate"]
|
|
|
+ v["l_createdate"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate), 0))
|
|
|
+ tmpdate1, _ := v["releasetime"]
|
|
|
+ //v["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1), 0))
|
|
|
+ reltime := time.Unix(util.Int64All(tmpdate1), 0)
|
|
|
+ v["time"] = reltime.Format(Date_yyyyMMdd_Bias) //首页展示
|
|
|
+ v["s_pic"] = SPic(util.InterfaceToStr(v["s_pic"]))
|
|
|
+ v["s_pic1"] = SPic(util.InterfaceToStr(v["s_pic1"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //IdFormat(&recommend)
|
|
|
+ return recommend
|
|
|
+}
|
|
|
+
|
|
|
+// GetNextInfo 获取同类别上一篇、下一篇
|
|
|
+func GetNextInfo(_id string, keyWord ...string) (lastId, nextId string) {
|
|
|
+ doc, _ := mongodb.FindById("content", _id, `{"releasetime":1,"i_viewnum":1,s_contenttype":1,"s_secondclassifytype":1,"s_threeclassifytype":1}`)
|
|
|
+ if doc == nil || len(*doc) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ commonQuery := map[string]interface{}{
|
|
|
+ "i_status": 1,
|
|
|
+ "releasetime": map[string]interface{}{
|
|
|
+ "$lt": time.Now().Unix(),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, t := range []string{"s_contenttype", "s_secondclassifytype", "s_threeclassifytype"} {
|
|
|
+ if tv, _ := (*doc)[t].(string); tv != "" && tv != "0" {
|
|
|
+ commonQuery[t] = tv
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(keyWord) > 0 {
|
|
|
+ commonQuery["s_title"] = map[string]interface{}{
|
|
|
+ "$regex": keyWord[0],
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Println("content上下文query:", commonQuery)
|
|
|
+ dataOn, ok := mongodb.Find("content", commonQuery, `{"releasetime":-1}`, `{"_id":1,"i_viewnum":1,releasetime":-1,"l_createdate":1}`, false, -1, -1)
|
|
|
+ if ok && dataOn != nil && len(*dataOn) > 0 {
|
|
|
+ for k, v := range *dataOn {
|
|
|
+ if util.InterfaceToStr(v["_id"]) == _id {
|
|
|
+ if k != 0 {
|
|
|
+ lastId = se.EncodeString(util.InterfaceToStr((*dataOn)[k-1]["_id"]))
|
|
|
+ }
|
|
|
+ if k < len(*dataOn)-1 {
|
|
|
+ nextId = se.EncodeString(util.InterfaceToStr((*dataOn)[k+1]["_id"]))
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// Browsing 浏览次数增加
|
|
|
+func Browsing(id string, viewNum int) {
|
|
|
+ mongodb.UpdateById("content", id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "i_viewnum": viewNum + 1,
|
|
|
+ }})
|
|
|
+}
|
|
|
+
|
|
|
+// GetSiteInfo 获取栏目
|
|
|
+func GetSiteInfo(id string) (sType, tType string) {
|
|
|
+ if res, _ := mongodb.FindById("content", id, `{"s_contenttype":1,"s_secondclassifytype":1}`); res != nil && len(*res) > 0 {
|
|
|
+ if value, ok := (*res)["s_contenttype"]; ok {
|
|
|
+ sType, _ = value.(string)
|
|
|
+ }
|
|
|
+ if value, ok := (*res)["s_secondclassifytype"]; ok {
|
|
|
+ tType, _ = value.(string)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 导航栏 isdetail是否是详情页面
|
|
|
+func NavigationBar(code string, isdetail bool) []Navigation {
|
|
|
+ var (
|
|
|
+ contentNavigat Navigation
|
|
|
+ navigation []Navigation
|
|
|
+ )
|
|
|
+ if mgo.IsObjectIdHex(code) {
|
|
|
+ doc, ok := mongodb.FindById("content", code, `{"s_title":1,"s_contente":1,"s_stypecondclassifytype":1}`)
|
|
|
+ if ok && doc == nil || len(*doc) == 0 {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ contentNavigat = Navigation{Name: util.InterfaceToStr((*doc)["s_title"])}
|
|
|
+ for _, v := range []string{"s_stypecondclassifytype", "s_contente"} {
|
|
|
+ if util.InterfaceToStr((*doc)[v]) != "" {
|
|
|
+ code = util.InterfaceToStr((*doc)[v])
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ navigation = PidColumn(code)
|
|
|
+ if contentNavigat.Name != "" {
|
|
|
+ navigation = append(navigation, contentNavigat)
|
|
|
+ }
|
|
|
+ //除去详情页面 移动端招投标攻略面包屑最后一个不加url
|
|
|
+ if !isdetail {
|
|
|
+ last := navigation[len(navigation)-1]
|
|
|
+ navigation[len(navigation)-1] = Navigation{
|
|
|
+ Name: last.Name,
|
|
|
+ Code: last.Code,
|
|
|
+ Url: "",
|
|
|
+ Href: "",
|
|
|
+ Pid: last.Pid,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return navigation
|
|
|
+}
|
|
|
+
|
|
|
+func PidColumn(id string) []Navigation {
|
|
|
+ var allColumn []Navigation
|
|
|
+ if ColumnRelationship[id].Pid != "" {
|
|
|
+ //存在父级目录
|
|
|
+ allColumn = append(allColumn, PidColumn(ColumnRelationship[id].Pid)...)
|
|
|
+ allColumn = append(allColumn, ColumnRelationship[id])
|
|
|
+ } else {
|
|
|
+ //剑鱼首页地址
|
|
|
+ //allColumn = append(allColumn, Navigation{Name: "剑鱼标讯", Url: "/"})
|
|
|
+ /*columnCode, _ := config.Sysconfig["columnCode"].(map[string]interface{})
|
|
|
+ if id == util.InterfaceToStr(columnCode["招投标攻略"]) {
|
|
|
+ //剑鱼课堂首页地址
|
|
|
+ allColumn = append(allColumn, Navigation{Name: "剑鱼学堂", Href: "/jySchool/index"})
|
|
|
+ }*/
|
|
|
+ //上级地址
|
|
|
+ allColumn = append(allColumn, ColumnRelationship[id])
|
|
|
+ }
|
|
|
+
|
|
|
+ return allColumn
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// SPic 图片链接处理
|
|
|
+func SPic(sPic string) string {
|
|
|
+ if sPic != "" && !strings.HasPrefix(sPic, "http") {
|
|
|
+ if strings.HasPrefix(sPic, "/") &&
|
|
|
+ strings.HasSuffix(util.InterfaceToStr(config.Seoconfig["jyadd"]), "/") {
|
|
|
+ sPic = util.InterfaceToStr(config.Seoconfig["jyadd"]) + sPic[1:]
|
|
|
+ } else if !strings.HasPrefix(sPic, "/") &&
|
|
|
+ !strings.HasSuffix(util.InterfaceToStr(config.Seoconfig["jyadd"]), "/") {
|
|
|
+ sPic = util.InterfaceToStr(config.Seoconfig["jyadd"]) + "/" + sPic
|
|
|
+ } else {
|
|
|
+ sPic = util.InterfaceToStr(config.Seoconfig["jyadd"]) + sPic
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sPic
|
|
|
+}
|
|
|
+
|
|
|
+// 生成count个[start,end)结束的不重复的随机数
|
|
|
+func GenerateRandomNumber(start int, end int, count int) []int {
|
|
|
+ //范围检查
|
|
|
+ if end < start || (end-start) < count {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ //存放结果的slice
|
|
|
+ nums := make([]int, 0)
|
|
|
+ //随机数生成器,加入时间戳保证每次生成的随机数不一样
|
|
|
+ r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
+ for len(nums) < count {
|
|
|
+ //生成随机数
|
|
|
+ num := r.Intn(end-start) + start
|
|
|
+ //查重
|
|
|
+ exist := false
|
|
|
+ for _, v := range nums {
|
|
|
+ if v == num {
|
|
|
+ exist = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !exist {
|
|
|
+ nums = append(nums, num)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sort.Ints(nums)
|
|
|
+ return nums
|
|
|
+}
|