|
@@ -1,17 +1,29 @@
|
|
|
package entity
|
|
|
|
|
|
import (
|
|
|
+ "config"
|
|
|
"db"
|
|
|
"fmt"
|
|
|
"log"
|
|
|
+ mg "mongodb"
|
|
|
"net/url"
|
|
|
qu "qfw/util"
|
|
|
+ "qfw/util/elastic"
|
|
|
"qfw/util/jy"
|
|
|
+ "qfw/util/redis"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
"util"
|
|
|
+
|
|
|
+ "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
+)
|
|
|
+
|
|
|
+const (
|
|
|
+ query = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","area", "publishtime", "s_subscopeclass", "subtype", "title", "toptype", "type", "buyerclass","bidamount","budget"],"from":0,"size":%d}`
|
|
|
+ mongodb_fields = `{"_id":1,"area":1,"publishtime":1,"s_subscopeclass":1,"subtype":1,"title":1,"toptype":1,"type":1, "buyerclass":1,"budget":1,"bidamount":1}`
|
|
|
+ querys = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","title","detail","area","city","publishtime","projectname","buyer","buyerclass","s_winner","bidamount","subtype","toptype","href","projectcode","buyerperson","buyertel","budget","bidopentime","agency","projectscope","winnerperson","winnertel"]}`
|
|
|
)
|
|
|
|
|
|
//招标信息是否被收藏
|
|
@@ -207,3 +219,283 @@ func LabelAction(labInfo *LabelInfo, userid string) (ibool bool) {
|
|
|
}
|
|
|
return ibool
|
|
|
}
|
|
|
+
|
|
|
+//收藏列表
|
|
|
+type CollList struct {
|
|
|
+ Pagenum int `json:"pagenum"` //页数
|
|
|
+ Label string `json:"label"` //标签 用,分隔开
|
|
|
+ Colltime_start int64 `json:"colltime_start"` //收藏开始时间
|
|
|
+ Colltime_end int64 `json:"colltime_end"` //收藏结束时间
|
|
|
+ Buyerclass string `json:"buyerclass"` //采购单位 用,分隔开
|
|
|
+ BuyerPhone int `json:"buyerPhone"` //是否需要采购单位联系方式 1:需要 -1:不需要 0:未选中
|
|
|
+ WinnerPhone int `json:"winnerPhone"` //是否需要中标单位联系方式 1:需要 -1:不需要 0:未选中
|
|
|
+}
|
|
|
+
|
|
|
+func GetCollList(c *CollList, userid string) map[string]interface{} {
|
|
|
+ pagesize_max := config.BidCollConfig.Pagesize
|
|
|
+ rdata := map[string]interface{}{
|
|
|
+ "count": 0,
|
|
|
+ "haveNextPage": false,
|
|
|
+ "res": []map[string]interface{}{},
|
|
|
+ }
|
|
|
+ sql := fmt.Sprintf(`select bid from %s where userid ='%s'`, db.DbConf.Bdcollection, userid)
|
|
|
+ isPay := Power(userid)
|
|
|
+ limit := config.BidCollConfig.FreeUserCollLimit
|
|
|
+ if isPay {
|
|
|
+ //收藏时间
|
|
|
+ start, end := "", ""
|
|
|
+ if c.Colltime_start > 0 {
|
|
|
+ start = time.Unix(c.Colltime_start, 0).Format(qu.Date_Full_Layout)
|
|
|
+ }
|
|
|
+ if c.Colltime_end > 0 {
|
|
|
+ end = time.Unix(c.Colltime_end, 0).Format(qu.Date_Full_Layout)
|
|
|
+ }
|
|
|
+ if start != "" && end != "" {
|
|
|
+ sql += ` and createdate >= '` + start + `' and createdate <= '` + end + `'`
|
|
|
+ } else if start != "" && end == "" {
|
|
|
+ sql += ` and createdate >= '` + start + `'`
|
|
|
+ } else if start == "" && end != "" {
|
|
|
+ sql += ` and createdate <= '` + end + `'`
|
|
|
+ }
|
|
|
+ //采购单位 用,分隔开
|
|
|
+ if c.Buyerclass != "" {
|
|
|
+ i := 0
|
|
|
+ sql += ` and buyerclass in (`
|
|
|
+ if buyClassArr := strings.Split(c.Buyerclass, ","); len(buyClassArr) > 0 {
|
|
|
+ for _, v := range buyClassArr {
|
|
|
+ i++
|
|
|
+ buyerclassid := fmt.Sprint(jy.PushMapping.Buyerclass[v])
|
|
|
+ if i == len(buyClassArr) {
|
|
|
+ sql += buyerclassid + `)`
|
|
|
+ } else {
|
|
|
+ sql += buyerclassid + ","
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //个人标签
|
|
|
+ if c.Label != "" {
|
|
|
+ i := 0
|
|
|
+ sql += ` and `
|
|
|
+ if labelArr := strings.Split(c.Label, ","); len(labelArr) > 0 {
|
|
|
+ for _, v := range labelArr {
|
|
|
+ i++
|
|
|
+ labid := qu.SE.DecodeString(v)
|
|
|
+ if i == len(labelArr) {
|
|
|
+ sql += fmt.Sprintf(`FIND_IN_SET(%s,labelid)`, labid)
|
|
|
+ } else {
|
|
|
+ sql += fmt.Sprintf(`FIND_IN_SET(%s,labelid) or `, labid)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //是否存在采购单位电话
|
|
|
+ if c.BuyerPhone == 1 {
|
|
|
+ sql += ` and buyerinfo = 1`
|
|
|
+ } else if c.BuyerPhone == -1 {
|
|
|
+ sql += ` and buyerinfo = 0`
|
|
|
+ }
|
|
|
+ //是否存在中标单位电话
|
|
|
+ if c.WinnerPhone == 1 {
|
|
|
+ sql += ` and winnerinfo = 1`
|
|
|
+ } else if c.WinnerPhone == -1 {
|
|
|
+ sql += ` and winnerinfo = 0`
|
|
|
+ }
|
|
|
+ limit = config.BidCollConfig.PayUserCollLimit
|
|
|
+ }
|
|
|
+ sql += fmt.Sprintf(` order by createdate desc limit %v`, limit)
|
|
|
+ log.Println(sql)
|
|
|
+ data := db.Mysql.SelectBySql(sql)
|
|
|
+ result := []map[string]interface{}{}
|
|
|
+ if data != nil && len(*data) > 0 {
|
|
|
+ if c.Pagenum <= 0 {
|
|
|
+ c.Pagenum = 1
|
|
|
+ }
|
|
|
+ start := (c.Pagenum - 1) * pagesize_max
|
|
|
+ end := c.Pagenum * pagesize_max
|
|
|
+ if end > len(*data) {
|
|
|
+ end = len(*data)
|
|
|
+ }
|
|
|
+ if start < len(*data) {
|
|
|
+ result = (*data)[start:end]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ count := len(*data)
|
|
|
+ haveNextPage := len(result) >= pagesize_max
|
|
|
+ // rdata["res"] = result
|
|
|
+ rdata["count"] = count
|
|
|
+ rdata["haveNextPage"] = haveNextPage
|
|
|
+ rdata["res"] = GetInfoById(db.Mgo_Bidding, db.DbConf.Mongodb.Bidding.Collection, db.DbConf.Mongodb.Bidding.Collection_change, result)
|
|
|
+ return rdata
|
|
|
+}
|
|
|
+
|
|
|
+//是否是付费用户 -bool: true:是 fasle:不是
|
|
|
+func Power(userid string) bool {
|
|
|
+ isVip, isMember, isEnt := false, false, false
|
|
|
+ phone := ""
|
|
|
+ data, ok := db.Mgo.FindById("user", userid, `"i_member_status":1,"i_vip_status":1,"s_m_phone":1,"s_phone":1`)
|
|
|
+ if data != nil && len(*data) > 0 && ok {
|
|
|
+ i_vip_status := qu.IntAll((*data)["i_vip_status"])
|
|
|
+ if i_vip_status > 0 {
|
|
|
+ isVip = true
|
|
|
+ }
|
|
|
+ if i_member_status := qu.IntAllDef((*data)["i_member_status"], 0); i_member_status > 0 {
|
|
|
+ isMember = true
|
|
|
+ }
|
|
|
+ if s_phone, _ := (*data)["s_phone"].(string); s_phone != "" {
|
|
|
+ phone = s_phone
|
|
|
+ } else if s_m_phone, _ := (*data)["s_m_phone"].(string); s_m_phone != "" {
|
|
|
+ phone = s_m_phone
|
|
|
+ }
|
|
|
+ if phone != "" {
|
|
|
+ if db.Mysql.CountBySql(`select count(1) from entniche_user where phone = ? and power =1`, phone) > 0 {
|
|
|
+ isEnt = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Println(isVip, isEnt, isMember)
|
|
|
+ return isVip || isEnt || isMember
|
|
|
+}
|
|
|
+
|
|
|
+type InfoList struct {
|
|
|
+ Id string `json:"_id"`
|
|
|
+ Title string `json:"title"`
|
|
|
+ Area string `json:"area"`
|
|
|
+ Buyerclass string `json:"buyerclass"`
|
|
|
+ Type string `json:"type"`
|
|
|
+ S_subscopeclass string `json:"s_subscopeclass"`
|
|
|
+ Publishtime int64 `json:"publishtime"`
|
|
|
+ Budget interface{} `json:"budget"`
|
|
|
+ Bidamount interface{} `json:"bidamount"`
|
|
|
+}
|
|
|
+
|
|
|
+//根据id取内容
|
|
|
+func GetInfoById(Mgo_bidding mg.MongodbSim, bidding, bidding_back string, idlist []map[string]interface{}) []*InfoList {
|
|
|
+ array := make([]*InfoList, len(idlist))
|
|
|
+ if len(idlist) == 0 {
|
|
|
+ return array
|
|
|
+ }
|
|
|
+ m := map[string]bool{}
|
|
|
+ ids := []string{}
|
|
|
+ for _, v := range idlist {
|
|
|
+ if m[qu.ObjToString(v["bid"])] {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ m[qu.ObjToString(v["bid"])] = true
|
|
|
+ ids = append(ids, qu.ObjToString(v["bid"]))
|
|
|
+ }
|
|
|
+ infos := map[string]map[string]interface{}{}
|
|
|
+ //redis
|
|
|
+ es_ids := []string{}
|
|
|
+ for _, v := range ids {
|
|
|
+ info_i := redis.Get("pushcache_1", fmt.Sprintf("info_%s", v))
|
|
|
+ if info_i != nil {
|
|
|
+ info_m, _ := info_i.(map[string]interface{})
|
|
|
+ info_m["_id"] = v
|
|
|
+ infos[v] = info_m
|
|
|
+ } else {
|
|
|
+ es_ids = append(es_ids, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // log.Println(es_ids)
|
|
|
+ //elasticsearch
|
|
|
+ if len(es_ids) > 0 {
|
|
|
+ list := elastic.Get("bidding", "bidding", fmt.Sprintf(query, strings.Join(es_ids, `","`), len(es_ids)))
|
|
|
+ if list != nil {
|
|
|
+ for _, v := range *list {
|
|
|
+ _id := qu.ObjToString(v["_id"])
|
|
|
+ infos[_id] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //mongodb bidding
|
|
|
+ mgo_ids := []primitive.ObjectID{}
|
|
|
+ for _, v := range es_ids {
|
|
|
+ if infos[v] == nil {
|
|
|
+ _id, _ := primitive.ObjectIDFromHex(v)
|
|
|
+ mgo_ids = append(mgo_ids, _id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(mgo_ids) > 0 {
|
|
|
+ list, ok := Mgo_bidding.Find(bidding, map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_ids}}, nil, mongodb_fields, false, -1, -1)
|
|
|
+ if ok && *list != nil {
|
|
|
+ for _, v := range *list {
|
|
|
+ _id := mg.BsonIdToSId(v["_id"])
|
|
|
+ v["_id"] = _id
|
|
|
+ infos[_id] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //mongodb bidding_back
|
|
|
+ mgo_back_ids := []primitive.ObjectID{}
|
|
|
+ for _, v := range mgo_ids {
|
|
|
+ if infos[mg.BsonIdToSId(v)] == nil {
|
|
|
+ mgo_back_ids = append(mgo_back_ids, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(mgo_back_ids) > 0 {
|
|
|
+ list, ok := Mgo_bidding.Find(bidding_back, map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_back_ids}}, nil, mongodb_fields, false, -1, -1)
|
|
|
+ if ok && *list != nil {
|
|
|
+ for _, v := range *list {
|
|
|
+ _id := mg.BsonIdToSId(v["_id"])
|
|
|
+ v["_id"] = _id
|
|
|
+ infos[_id] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //
|
|
|
+ for k, v := range idlist {
|
|
|
+ info := infos[qu.ObjToString(v["bid"])]
|
|
|
+ if info == nil {
|
|
|
+ info = map[string]interface{}{}
|
|
|
+ }
|
|
|
+ array[k] = InfoFormat(qu.ObjToString(v["bid"]), &info)
|
|
|
+ }
|
|
|
+ return array
|
|
|
+}
|
|
|
+
|
|
|
+//历史推送记录中单条信息格式化
|
|
|
+func InfoFormat(p string, info *map[string]interface{}) *InfoList {
|
|
|
+ area := qu.ObjToString((*info)["area"])
|
|
|
+ if area == "A" {
|
|
|
+ area = "全国"
|
|
|
+ }
|
|
|
+ industry := qu.ObjToString((*info)["s_subscopeclass"])
|
|
|
+ scs := strings.Split(industry, ",")
|
|
|
+ if len(scs) > 0 {
|
|
|
+ industry = scs[0]
|
|
|
+ if industry != "" {
|
|
|
+ iss := strings.Split(industry, "_")
|
|
|
+ if len(iss) > 0 {
|
|
|
+ industry = iss[0]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ infotype := qu.ObjToString((*info)["subtype"])
|
|
|
+ if infotype == "" {
|
|
|
+ infotype = qu.ObjToString((*info)["toptype"])
|
|
|
+ }
|
|
|
+ if infotype == "" {
|
|
|
+ infotype = qu.ObjToString((*info)["type"])
|
|
|
+ if infotype == "tender" {
|
|
|
+ infotype = "招标"
|
|
|
+ } else if infotype == "bid" {
|
|
|
+ infotype = "中标"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _id := p
|
|
|
+ if _id == "" {
|
|
|
+ _id = qu.ObjToString((*info)["_id"])
|
|
|
+ }
|
|
|
+ return &InfoList{
|
|
|
+ Id: qu.EncodeArticleId2ByCheck(_id),
|
|
|
+ Title: qu.ObjToString((*info)["title"]),
|
|
|
+ Area: area,
|
|
|
+ Buyerclass: qu.ObjToString((*info)["buyerclass"]),
|
|
|
+ Type: infotype,
|
|
|
+ S_subscopeclass: industry,
|
|
|
+ Publishtime: qu.Int64All((*info)["publishtime"]),
|
|
|
+ Budget: (*info)["budget"],
|
|
|
+ Bidamount: (*info)["bidamount"],
|
|
|
+ }
|
|
|
+}
|