|
@@ -0,0 +1,620 @@
|
|
|
+package jyutil
|
|
|
+
|
|
|
+import (
|
|
|
+ "app.yhyue.com/moapp/jyMarketing/rpc/activity"
|
|
|
+ util "app.yhyue.com/moapp/jybase/common"
|
|
|
+ . "app.yhyue.com/moapp/jybase/date"
|
|
|
+ mgo "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ "bytes"
|
|
|
+ "context"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "github.com/gogf/gf/v2/frame/g"
|
|
|
+ "github.com/gogf/gf/v2/os/gcfg"
|
|
|
+ "github.com/gogf/gf/v2/os/gctx"
|
|
|
+ "github.com/zeromicro/go-zero/core/discov"
|
|
|
+ "github.com/zeromicro/go-zero/zrpc"
|
|
|
+ "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
+ "html/template"
|
|
|
+ "io/ioutil"
|
|
|
+ "jy/src/jfw/config"
|
|
|
+ "log"
|
|
|
+ "math"
|
|
|
+ "math/rand"
|
|
|
+ "net/http"
|
|
|
+ "sort"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ ColumnRelationship map[string]Navigation
|
|
|
+)
|
|
|
+
|
|
|
+type Navigation struct {
|
|
|
+ Name string
|
|
|
+ Code string
|
|
|
+ Href string
|
|
|
+ Pid 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 init() {
|
|
|
+ go ActivityInit()
|
|
|
+ log.Println("开始初始化column")
|
|
|
+ ColumnRelationship = make(map[string]Navigation)
|
|
|
+ industryInfoUrl, _ := config.Sysconfig["industryInfoUrl"].(map[string]interface{})
|
|
|
+ jySchoolUrl, _ := config.Sysconfig["jySchoolUrl"].(map[string]interface{})
|
|
|
+ columnCode, _ := config.Sysconfig["columnCode"].(map[string]interface{})
|
|
|
+ jySchoolCode := util.InterfaceToStr(columnCode["招投标攻略"])
|
|
|
+ industryInfoCode := util.InterfaceToStr(columnCode["行业资讯"])
|
|
|
+
|
|
|
+ util.InterfaceToStr(columnCode["行业资讯"])
|
|
|
+ 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 code == industryInfoCode {
|
|
|
+ href = util.InterfaceToStr(industryInfoUrl["homeUrl"])
|
|
|
+ } else if pid == jySchoolCode {
|
|
|
+ href = fmt.Sprintf(util.InterfaceToStr(jySchoolUrl["towUrl"]), code)
|
|
|
+ } else if pid == industryInfoCode {
|
|
|
+ href = fmt.Sprintf(util.InterfaceToStr(industryInfoUrl["towUrl"]), code)
|
|
|
+ } else {
|
|
|
+ log.Printf("未知栏目code,code:%s", code)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ data.Href = href
|
|
|
+ data.Code = code
|
|
|
+ data.Name = util.InterfaceToStr(v["s_columnname"])
|
|
|
+ data.Pid = pid
|
|
|
+ ColumnRelationship[code] = data
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+var Activity activity.Activity
|
|
|
+
|
|
|
+// 活动初始化
|
|
|
+func ActivityInit() {
|
|
|
+ log.Println("开始初始化活动rpc")
|
|
|
+ g.Cfg().GetAdapter().(*gcfg.AdapterFile).SetFileName("config.yaml")
|
|
|
+ var ctx = gctx.New()
|
|
|
+ Activity = activity.NewActivity(zrpc.MustNewClient(zrpc.RpcClientConf{
|
|
|
+ Etcd: discov.EtcdConf{
|
|
|
+ Hosts: g.Cfg().MustGet(ctx, "etcd.hosts").Strings(),
|
|
|
+ Key: g.Cfg().MustGet(ctx, "activityKey").String(),
|
|
|
+ },
|
|
|
+ }))
|
|
|
+}
|
|
|
+
|
|
|
+func ActivityData() map[string][]*activity.LotteryJson {
|
|
|
+ resp, err := Activity.GetAllLottery(context.Background(), &activity.Request{
|
|
|
+ AppId: "10000",
|
|
|
+ ProductCode: "111",
|
|
|
+ })
|
|
|
+ log.Println(resp, err)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("奖券获取失败")
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ lotteryMap := map[string][]*activity.LotteryJson{}
|
|
|
+ for _, activityValue := range resp.ActivityJson {
|
|
|
+ for _, lotteryValue := range activityValue.LotteryJson {
|
|
|
+ for _, productValue := range lotteryValue.UseProductList {
|
|
|
+ lotteryValue.UseProductList = []*activity.ProductJson{}
|
|
|
+ lotteryMap[productValue.ProductCode] = append(lotteryMap[productValue.ProductCode], lotteryValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return lotteryMap
|
|
|
+}
|
|
|
+
|
|
|
+// Course 剑鱼课堂首页课程 & 帮助中心热门视频 classify:0:中标比听课视频 1:帮助中心视频(获取所有)
|
|
|
+func Course(num, iType int) *[]map[string]interface{} {
|
|
|
+ //热门课程
|
|
|
+ /*var HotCourse *[]map[string]interface{}
|
|
|
+ hotQuery := map[string]interface{}{"i_type": 3, "i_status": 1, "l_endtime": map[string]interface{}{"$gt": time.Now().Unix()}, "l_publishtime": map[string]interface{}{"$lt": time.Now().Unix()}}
|
|
|
+ HotCourse = mongodb.Find("jy_course", hotQuery, `{"i_clickRate":-1}`, nil, false, 0, 8)
|
|
|
+ if HotCourse != nil && len(*HotCourse) > 0 {
|
|
|
+ for key, value := range *HotCourse {
|
|
|
+ timeNow := time.Now().Unix()
|
|
|
+ if util.Int64All(value["l_endtime"]) < timeNow {
|
|
|
+ (*HotCourse)[key]["isExpired"] = true
|
|
|
+ } else {
|
|
|
+ (*HotCourse)[key]["isExpired"] = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ var page int
|
|
|
+ if iType == 4 {
|
|
|
+ page = -1
|
|
|
+ num = -1
|
|
|
+ }
|
|
|
+ //最新课程
|
|
|
+ lotteryMap := ActivityData()
|
|
|
+ var LatestCourses *[]map[string]interface{}
|
|
|
+ latestQuery := map[string]interface{}{"i_type": iType, "i_status": 1, "l_endtime": map[string]interface{}{"$gt": time.Now().Unix()}, "l_publishtime": map[string]interface{}{"$lt": time.Now().Unix()}}
|
|
|
+ LatestCourses, _ = mongodb.Find("jy_course", latestQuery, `{"l_publishtime":-1}`, "", false, page, num)
|
|
|
+ if LatestCourses != nil && len(*LatestCourses) > 0 {
|
|
|
+ for key, value := range *LatestCourses {
|
|
|
+ (*LatestCourses)[key]["_id"] = util.InterfaceToStr((*LatestCourses)[key]["_id"])
|
|
|
+ timeNow := time.Now().Unix()
|
|
|
+ if util.Int64All(value["l_endtime"]) < timeNow {
|
|
|
+ (*LatestCourses)[key]["isExpired"] = true
|
|
|
+ } else {
|
|
|
+ (*LatestCourses)[key]["isExpired"] = false
|
|
|
+ }
|
|
|
+ productPrice := util.Float64All(value["i_price"])
|
|
|
+ fool, discountPrice := OptimalSelection(util.InterfaceToStr(value["_id"]), productPrice, lotteryMap)
|
|
|
+ (*LatestCourses)[key]["isDiscount"] = fool
|
|
|
+ if fool {
|
|
|
+ (*LatestCourses)[key]["discountPrice"] = productPrice - discountPrice
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //精选课程
|
|
|
+ /*var idSlice []primitive.ObjectID
|
|
|
+ for _, value := range *HotCourse {
|
|
|
+ idSlice = append(idSlice, value["_id"].(primitive.ObjectID))
|
|
|
+ }
|
|
|
+ for _, value := range *LatestCourses {
|
|
|
+ idSlice = append(idSlice, value["_id"].(primitive.ObjectID))
|
|
|
+ }
|
|
|
+ var SelectedCourse *[]map[string]interface{}
|
|
|
+ otherQuery := map[string]interface{}{"i_type": 3, "i_status": 1, "_id": map[string]interface{}{"$nin": idSlice}, "l_publishtime": map[string]interface{}{"$lt": time.Now().Unix()}}
|
|
|
+ SelectedCourse = mongodb.Find("jy_course", otherQuery, "-l_endtime,-i_tradeRate,-i_clickRate,-l_publishtime", "", false, 0, 0)
|
|
|
+ for key, value := range *SelectedCourse {
|
|
|
+ timeNow := time.Now().Unix()
|
|
|
+ if util.Int64All(value["l_endtime"]) < timeNow {
|
|
|
+ (*SelectedCourse)[key]["isExpired"] = true
|
|
|
+ } else {
|
|
|
+ (*SelectedCourse)[key]["isExpired"] = false
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ //IdFormat(LatestCourses)
|
|
|
+ return LatestCourses
|
|
|
+}
|
|
|
+
|
|
|
+// 奖券详情
|
|
|
+func OptimalSelection(id string, price float64, lotteryMap map[string][]*activity.LotteryJson) (bool, float64) {
|
|
|
+ if price == 0 {
|
|
|
+ return false, 0
|
|
|
+ }
|
|
|
+ discountPrice := float64(0)
|
|
|
+
|
|
|
+ lotteryStr := lotteryMap[id]
|
|
|
+ if lotteryStr == nil {
|
|
|
+ return false, discountPrice
|
|
|
+ }
|
|
|
+ for _, lottery := range lotteryStr {
|
|
|
+ lotteryType := lottery.LotteryType
|
|
|
+ full := util.Float64All(lottery.Full)
|
|
|
+ full *= 100
|
|
|
+ //类型:0满减、1折扣券、2满赠、3促销、4限时折扣、5限时减免
|
|
|
+ switch lotteryType {
|
|
|
+ case 1: //满折
|
|
|
+ if full <= price {
|
|
|
+ discount := util.Float64All(lottery.Discount)
|
|
|
+ preferential := (1 - discount/10) * price
|
|
|
+ preferential = math.Trunc(preferential*1e0 + 0.5)
|
|
|
+ if preferential > discountPrice {
|
|
|
+ discountPrice = preferential
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break
|
|
|
+ case 3: //3促销
|
|
|
+ promotionalPrice := util.Float64All(lottery.PromotionalPrice)
|
|
|
+ if util.Float64All(price-promotionalPrice) > discountPrice {
|
|
|
+ discountPrice = util.Float64All(price - promotionalPrice)
|
|
|
+ }
|
|
|
+ break
|
|
|
+ case 4: //4限时折扣
|
|
|
+ discount := util.Float64All(lottery.Discount)
|
|
|
+ preferential := (1 - discount/10) * price
|
|
|
+ preferential = math.Trunc(preferential*1e0 + 0.5)
|
|
|
+ if preferential > discountPrice {
|
|
|
+ discountPrice = preferential
|
|
|
+ }
|
|
|
+ break
|
|
|
+ case 5: //5限时减免
|
|
|
+ reduce := util.Float64All(lottery.Reduce)
|
|
|
+ if reduce > discountPrice {
|
|
|
+ discountPrice = reduce
|
|
|
+ }
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ if full <= price {
|
|
|
+ reduce := util.Float64All(lottery.Reduce) * 100
|
|
|
+ if reduce > discountPrice {
|
|
|
+ discountPrice = reduce
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if discountPrice > 0 {
|
|
|
+ return true, discountPrice
|
|
|
+ }
|
|
|
+ return false, discountPrice
|
|
|
+}
|
|
|
+
|
|
|
+// Library 文库
|
|
|
+func Library(num int) (map[string]interface{}, error) {
|
|
|
+ if data := redis.Get("other", fmt.Sprintf("library_%d", num)); data != nil {
|
|
|
+ dataMap, _ := data.(map[string]interface{})
|
|
|
+ return dataMap, nil
|
|
|
+ }
|
|
|
+ b, _ := json.Marshal(map[string]interface{}{
|
|
|
+ "sign": "new",
|
|
|
+ "num": num,
|
|
|
+ })
|
|
|
+ buffer := bytes.NewBuffer(b)
|
|
|
+ client := NewClient()
|
|
|
+ log.Println("libraryTopList====", config.Sysconfig["libraryTopList"])
|
|
|
+ req, _ := http.NewRequest("POST", fmt.Sprintf(util.InterfaceToStr(config.Sysconfig["libraryTopList"]), num), buffer)
|
|
|
+ res, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ log.Printf("post topList err:%s", err.Error())
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ defer req.Body.Close()
|
|
|
+ bArr, err := ioutil.ReadAll(res.Body)
|
|
|
+ if err != nil {
|
|
|
+ log.Printf("ReadAll topList err:%s", err.Error())
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ m := map[string]interface{}{}
|
|
|
+ err = json.Unmarshal(bArr, &m)
|
|
|
+ data, _ := m["data"].([]interface{})
|
|
|
+ for _, v := range util.ObjArrToMapArr(data) {
|
|
|
+ v["docFileSize"] = FormatSize(util.Float64All(v["docFileSize"]), "B")
|
|
|
+ }
|
|
|
+ m["data"] = data
|
|
|
+ redis.Put("other", fmt.Sprintf("library_%d", num), m, 5*60)
|
|
|
+ return m, nil
|
|
|
+}
|
|
|
+
|
|
|
+// function formatSize (size, pointLength, units) {
|
|
|
+// size = Number(size)
|
|
|
+// let unit = ''
|
|
|
+// units = units || ['B', 'K', 'M', 'G', 'TB']
|
|
|
+// while ((unit = units.shift()) && size > 1024) {
|
|
|
+// size = size / 1024
|
|
|
+// }
|
|
|
+// return (unit === 'B' ? size : size.toFixed(pointLength === undefined ? 2 : pointLength)) + (unit || '')
|
|
|
+// }
|
|
|
+func FormatSize(size float64, unit string) string {
|
|
|
+ sizeName := fmt.Sprintf("%.2f%s", size, unit)
|
|
|
+ var units = []string{"B", "K", "M", "G", "TB"}
|
|
|
+ if size >= 1024 {
|
|
|
+ for k, v := range units {
|
|
|
+ if v == unit && unit != units[len(units)-1] && k < len(units)-1 {
|
|
|
+ size = size / 1024
|
|
|
+ if size >= 1024 {
|
|
|
+ return strings.ReplaceAll(FormatSize(size, units[k+1]), ".00", "")
|
|
|
+ } else {
|
|
|
+ sizeName = fmt.Sprintf("%.2f%s", size, units[k+1])
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return strings.ReplaceAll(sizeName, ".00", "")
|
|
|
+}
|
|
|
+
|
|
|
+// 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,"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, _ := 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_Point) //首页展示
|
|
|
+ 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"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //IdFormat(data)
|
|
|
+ return data
|
|
|
+}
|
|
|
+
|
|
|
+// 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
|
|
|
+}
|
|
|
+
|
|
|
+// ArticleRecommendation 攻略&资讯详情页 内容推荐&重要咨询
|
|
|
+// 传参 t 一级栏目 num数量
|
|
|
+func ArticleRecommendation(t string, num int) map[string]interface{} {
|
|
|
+ var res2 []map[string]interface{}
|
|
|
+ //用招投标攻略文章最新10篇&随机调用招投标攻略文章,显示10篇
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "s_contenttype": t, //一级栏目
|
|
|
+ "i_status": 1,
|
|
|
+ "releasetime": map[string]interface{}{"$lt": time.Now().Unix()},
|
|
|
+ //"s_secondclassifytype": 1, //二级栏目
|
|
|
+ }
|
|
|
+ res1, 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, num)
|
|
|
+ if ok && res1 != nil && len(*res1) > 0 {
|
|
|
+ if len(*res1) == num {
|
|
|
+ res, _ := 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)
|
|
|
+ for _, v := range GenerateRandomNumber(0, len(*res), num) {
|
|
|
+ s_title, _ := (*res)[v]["s_title"].(string)
|
|
|
+ (*res)[v]["s_title"] = template.HTML(s_title)
|
|
|
+ tmpdate, _ := (*res)[v]["l_createdate"]
|
|
|
+ (*res)[v]["l_createdate"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate), 0))
|
|
|
+ tmpdate1, _ := (*res)[v]["releasetime"]
|
|
|
+ //v["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1), 0))
|
|
|
+ reltime := time.Unix(util.Int64All(tmpdate1), 0)
|
|
|
+ (*res)[v]["time"] = reltime.Format(Date_yyyyMMdd_Point) //首页展示
|
|
|
+ (*res)[v]["s_pic"] = SPic(util.InterfaceToStr((*res)[v]["s_pic"]))
|
|
|
+ (*res)[v]["s_pic1"] = SPic(util.InterfaceToStr((*res)[v]["s_pic1"]))
|
|
|
+ (*res)[v]["_id"] = se.EncodeString(util.InterfaceToStr((*res)[v]["_id"]))
|
|
|
+ res2 = append(res2, (*res)[v])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, v := range *res1 {
|
|
|
+ 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_Point) //首页展示
|
|
|
+ v["s_pic"] = SPic(util.InterfaceToStr(v["s_pic"]))
|
|
|
+ v["s_pic1"] = SPic(util.InterfaceToStr(v["s_pic1"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(res2) > 0 {
|
|
|
+ return map[string]interface{}{"latestPush": res1, "randomExtraction": res2}
|
|
|
+ }
|
|
|
+ return map[string]interface{}{"latestPush": res1, "randomExtraction": res1}
|
|
|
+}
|
|
|
+
|
|
|
+// 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
|
|
|
+}
|
|
|
+
|
|
|
+// 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_Point) //首页展示
|
|
|
+ v["s_pic"] = SPic(util.InterfaceToStr(v["s_pic"]))
|
|
|
+ v["s_pic1"] = SPic(util.InterfaceToStr(v["s_pic1"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //IdFormat(&recommend)
|
|
|
+ return recommend
|
|
|
+}
|
|
|
+
|
|
|
+// 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 NavigationBar(code string) []Navigation {
|
|
|
+ //config.Sysconfig["libraryTopList"]
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+
|
|
|
+ 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: "剑鱼标讯", Href: "/"})
|
|
|
+ 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
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func Browsing(id string, viewNum int) {
|
|
|
+ mongodb.UpdateById("content", id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "i_viewnum": viewNum + 1,
|
|
|
+ }})
|
|
|
+}
|