|
@@ -12,7 +12,8 @@ import (
|
|
|
"qfw/util/redis"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
- "sync"
|
|
|
+
|
|
|
+ // "sync"
|
|
|
"time"
|
|
|
"util"
|
|
|
|
|
@@ -25,6 +26,11 @@ const (
|
|
|
querys = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","title","detail","area","city","publishtime","projectname","buyer","buyerclass","s_winner","bidamount","subtype","toptype","projectcode","buyertel","budget","bidopentime","agency","projectscope","winnerperson","winnertel"],"from":0,"size":%d}}`
|
|
|
)
|
|
|
|
|
|
+var (
|
|
|
+ insertCollKey = []string{"userid", "bid", "buyerclass", "buyerinfo", "winnerinfo", "createdate"}
|
|
|
+ insertCollKey2 = []string{"userid", "bid", "labelid", "buyerclass", "buyerinfo", "winnerinfo", "createdate"}
|
|
|
+)
|
|
|
+
|
|
|
//招标信息是否被收藏
|
|
|
func IsCollByBids(bids, userid string) []string {
|
|
|
res := []string{}
|
|
@@ -57,12 +63,19 @@ func IsCollByBids(bids, userid string) []string {
|
|
|
} else { //0条
|
|
|
return res
|
|
|
}
|
|
|
- for _, v := range strings.Split(bids, ",") {
|
|
|
- //招标信息解密
|
|
|
- bid := util.DecodeId(v)
|
|
|
- if collBidMap[bid] {
|
|
|
- // url.QueryEscape(v)
|
|
|
- res = append(res, v)
|
|
|
+
|
|
|
+ if bids == "" {
|
|
|
+ for k, _ := range collBidMap {
|
|
|
+ res = append(res, k)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for _, v := range strings.Split(bids, ",") {
|
|
|
+ //招标信息解密
|
|
|
+ bid := util.DecodeId(v)
|
|
|
+ if collBidMap[bid] {
|
|
|
+ // url.QueryEscape(v)
|
|
|
+ res = append(res, v)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return res
|
|
@@ -121,7 +134,7 @@ type BidInfo struct {
|
|
|
func BidCollOrRemByIds(bidAction BidAction, userid string) map[string]interface{} {
|
|
|
var i = 0
|
|
|
ok, msg := true, ""
|
|
|
- var wg sync.WaitGroup
|
|
|
+ insertValue := []interface{}{}
|
|
|
maxCount := config.BidCollConfig.FreeUserCollLimit
|
|
|
isPay, _ := Power(userid)
|
|
|
redisArr := []string{}
|
|
@@ -130,53 +143,49 @@ func BidCollOrRemByIds(bidAction BidAction, userid string) map[string]interface{
|
|
|
}
|
|
|
//已收藏的次数
|
|
|
collCount := db.Mysql.Count(db.DbConf.Bdcollection, map[string]interface{}{"userid": userid})
|
|
|
+ collMap := map[string]bool{}
|
|
|
+ for _, v := range IsCollByBids("", userid) {
|
|
|
+ collMap[v] = true
|
|
|
+ }
|
|
|
//格式化数据
|
|
|
bidAction.Binfo = FormatColl(bidAction.Binfo)
|
|
|
- for _, v := range bidAction.Binfo {
|
|
|
- wg.Add(1)
|
|
|
- go func(bd BidInfo) {
|
|
|
- queryMap := map[string]interface{}{
|
|
|
- "bid": util.DecodeId(bd.Bid),
|
|
|
- "userid": userid,
|
|
|
+ for _, bd := range bidAction.Binfo {
|
|
|
+ queryMap := map[string]interface{}{
|
|
|
+ "bid": util.DecodeId(bd.Bid),
|
|
|
+ "userid": userid,
|
|
|
+ }
|
|
|
+ redisArr = append(redisArr, util.DecodeId(bd.Bid))
|
|
|
+ //移除收藏
|
|
|
+ if bidAction.Baction == "R" {
|
|
|
+ if db.Mysql.Delete(db.DbConf.Bdcollection, queryMap) {
|
|
|
+ i++
|
|
|
+ } else {
|
|
|
+ log.Printf("userid :%s,取消收藏失败 id : %s", userid, util.DecodeId(bd.Bid))
|
|
|
}
|
|
|
- redisArr = append(redisArr, util.DecodeId(bd.Bid))
|
|
|
- //移除收藏
|
|
|
- if bidAction.Baction == "R" {
|
|
|
- if db.Mysql.Delete(db.DbConf.Bdcollection, queryMap) {
|
|
|
- i++
|
|
|
- } else {
|
|
|
- log.Printf("userid :%s,取消收藏失败 id : %s", userid, util.DecodeId(bd.Bid))
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ //if db.Mysql.Count(db.DbConf.Bdcollection, queryMap) == 0 {
|
|
|
+ if int(collCount) >= maxCount {
|
|
|
+ ok, msg = false, qu.If(isPay, "付费用户收藏已达上限", "免费用户收藏已达上限").(string)
|
|
|
+ log.Printf("userid :%s,收藏失败 id : %s ,已收藏数量:%v ,上限数量:%v", userid, util.DecodeId(bd.Bid), collCount, maxCount)
|
|
|
} else {
|
|
|
- if db.Mysql.Count(db.DbConf.Bdcollection, queryMap) == 0 {
|
|
|
- if int(collCount) >= maxCount {
|
|
|
- ok, msg = false, qu.If(isPay, "付费用户收藏已达上限", "免费用户收藏已达上限").(string)
|
|
|
- log.Printf("userid :%s,收藏失败 id : %s ,已收藏数量:%v ,上限数量:%v", userid, util.DecodeId(bd.Bid), collCount, maxCount)
|
|
|
- } else {
|
|
|
- now := time.Now().Unix()
|
|
|
- inserMap := map[string]interface{}{
|
|
|
- "bid": util.DecodeId(bd.Bid),
|
|
|
- "buyerclass": jy.PushMapping.Buyerclass[bd.Buyerclass],
|
|
|
- "buyerinfo": bd.Buyerinfo,
|
|
|
- "winnerinfo": bd.Winnerinfo,
|
|
|
- "userid": userid,
|
|
|
- "createdate": qu.FormatDateByInt64(&now, qu.Date_Full_Layout),
|
|
|
- }
|
|
|
- if it := db.Mysql.Insert(db.DbConf.Bdcollection, inserMap); it > 0 {
|
|
|
- i++
|
|
|
- collCount++
|
|
|
- } else {
|
|
|
- log.Printf("userid :%s,收藏失败 id : %s", userid, util.DecodeId(bd.Bid))
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
+ if collMap[util.DecodeId(bd.Bid)] {
|
|
|
log.Printf("userid :%s,已收藏 id : %s", userid, util.DecodeId(bd.Bid))
|
|
|
+ } else {
|
|
|
+ now := time.Now().Unix()
|
|
|
+ insertValue = append(insertValue, userid, util.DecodeId(bd.Bid), jy.PushMapping.Buyerclass[bd.Buyerclass], bd.Buyerinfo, bd.Winnerinfo, qu.FormatDateByInt64(&now, qu.Date_Full_Layout))
|
|
|
+ collCount++
|
|
|
+ i++
|
|
|
}
|
|
|
}
|
|
|
- wg.Done()
|
|
|
- }(v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //批量插入
|
|
|
+ if len(insertValue)/len(insertCollKey) > 0 {
|
|
|
+ x, _ := db.Mysql.InsertBatch(db.DbConf.Bdcollection, insertCollKey, insertValue)
|
|
|
+ if x < 0 {
|
|
|
+ log.Printf("userid :%s收藏失败", userid)
|
|
|
+ }
|
|
|
}
|
|
|
- wg.Wait()
|
|
|
typ := "a" //新增
|
|
|
if bidAction.Baction == "R" {
|
|
|
typ = "d" //删除
|
|
@@ -262,65 +271,69 @@ func LabelAction(labInfo *LabelInfo, userid string) map[string]interface{} {
|
|
|
}
|
|
|
//收藏招标信息
|
|
|
if labInfo.Lids != "" && len(labInfo.Binfo) > 0 {
|
|
|
+ //获取标签
|
|
|
+ var lids = ""
|
|
|
+ for _, lv := range strings.Split(labInfo.Lids, ",") {
|
|
|
+ if lids != "" {
|
|
|
+ lids += "," + qu.SE.DecodeString(lv)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ lids += qu.SE.DecodeString(lv)
|
|
|
+ }
|
|
|
+ //更新需要的参数
|
|
|
+ updatesql := fmt.Sprintf("update %s set labelid=? where userid = ? and ", db.DbConf.Bdcollection) //更新语句
|
|
|
+ updateValue := []interface{}{lids, userid}
|
|
|
+ //新增需要的参数
|
|
|
+ insertValue := []interface{}{}
|
|
|
+ collMap := map[string]bool{} //获取用户收藏的列表
|
|
|
+ for _, v := range IsCollByBids("", userid) {
|
|
|
+ collMap[v] = true
|
|
|
+ }
|
|
|
maxCount := config.BidCollConfig.FreeUserCollLimit
|
|
|
isPay, _ := Power(userid)
|
|
|
if isPay {
|
|
|
maxCount = config.BidCollConfig.PayUserCollLimit
|
|
|
}
|
|
|
//已收藏的次数
|
|
|
- collCount := db.Mysql.Count(db.DbConf.Bdcollection, map[string]interface{}{"userid": userid})
|
|
|
+ collCount := len(collMap)
|
|
|
var i = 0
|
|
|
- var wg sync.WaitGroup
|
|
|
labInfo.Binfo = FormatColl(labInfo.Binfo)
|
|
|
- for _, v := range labInfo.Binfo {
|
|
|
- wg.Add(1)
|
|
|
- go func(bd BidInfo) {
|
|
|
- queryMap := map[string]interface{}{
|
|
|
- "bid": util.DecodeId(bd.Bid),
|
|
|
- "userid": userid,
|
|
|
- }
|
|
|
- now := time.Now().Unix()
|
|
|
- var lids = ""
|
|
|
- for _, lv := range strings.Split(labInfo.Lids, ",") {
|
|
|
- if lids != "" {
|
|
|
- lids += "," + qu.SE.DecodeString(lv)
|
|
|
- continue
|
|
|
- }
|
|
|
- lids += qu.SE.DecodeString(lv)
|
|
|
- }
|
|
|
- if db.Mysql.Count(db.DbConf.Bdcollection, queryMap) == 0 {
|
|
|
- if int(collCount) >= maxCount {
|
|
|
- ok, msg = false, qu.If(isPay, "付费用户收藏已达上限", "免费用户收藏已达上限").(string)
|
|
|
- log.Printf("userid :%s,收藏失败 id : %s ,已收藏数量:%v ,上限数量:%v", userid, util.DecodeId(bd.Bid), collCount, maxCount)
|
|
|
+ for _, bd := range labInfo.Binfo {
|
|
|
+ now := time.Now().Unix()
|
|
|
+ if collCount >= maxCount {
|
|
|
+ ok, msg = false, qu.If(isPay, "付费用户收藏已达上限", "免费用户收藏已达上限").(string)
|
|
|
+ log.Printf("userid :%s,收藏失败 id : %s ,已收藏数量:%v ,上限数量:%v", userid, util.DecodeId(bd.Bid), collCount, maxCount)
|
|
|
+ } else {
|
|
|
+ if collMap[util.DecodeId(bd.Bid)] {
|
|
|
+ //更新
|
|
|
+ if updatesql == fmt.Sprintf("update %s set labelid=? where userid = ? and ", db.DbConf.Bdcollection) {
|
|
|
+ updatesql += `( bid =? `
|
|
|
} else {
|
|
|
- inserMap := map[string]interface{}{
|
|
|
- "labelid": lids,
|
|
|
- "bid": util.DecodeId(bd.Bid),
|
|
|
- "buyerclass": jy.PushMapping.Buyerclass[bd.Buyerclass],
|
|
|
- "buyerinfo": bd.Buyerinfo,
|
|
|
- "winnerinfo": bd.Winnerinfo,
|
|
|
- "userid": userid,
|
|
|
- "createdate": qu.FormatDateByInt64(&now, qu.Date_Full_Layout),
|
|
|
- }
|
|
|
- if it := db.Mysql.Insert(db.DbConf.Bdcollection, inserMap); it > 0 {
|
|
|
- i++
|
|
|
- collCount++
|
|
|
- redisArr = append(redisArr, util.DecodeId(bd.Bid))
|
|
|
- } else {
|
|
|
- log.Printf("userid :%s,收藏失败 id : %s", userid, util.DecodeId(bd.Bid))
|
|
|
- }
|
|
|
+ updatesql += `or bid =? `
|
|
|
}
|
|
|
+ updateValue = append(updateValue, util.DecodeId(bd.Bid))
|
|
|
+ i++
|
|
|
} else {
|
|
|
- if db.Mysql.Update(db.DbConf.Bdcollection, queryMap, map[string]interface{}{"labelid": lids}) {
|
|
|
- i++
|
|
|
- } else {
|
|
|
- log.Printf("userid :%s,更新收藏失败 id : %s", userid, util.DecodeId(bd.Bid))
|
|
|
- }
|
|
|
+ i++
|
|
|
+ //新增并绑定标签 "userid", "bid", "labelid", "buyerclass", "buyerinfo", "winnerinfo", "createdate"
|
|
|
+ insertValue = append(insertValue, userid, util.DecodeId(bd.Bid), lids, jy.PushMapping.Buyerclass[bd.Buyerclass], bd.Buyerinfo, bd.Winnerinfo, qu.FormatDateByInt64(&now, qu.Date_Full_Layout))
|
|
|
}
|
|
|
- wg.Done()
|
|
|
- }(v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(updateValue) > 2 {
|
|
|
+ updatesql += `)`
|
|
|
+ log.Println("updatesql:", updatesql)
|
|
|
+ _, errs := db.Mysql.ExecBySql(updatesql, updateValue...)
|
|
|
+ if errs != nil {
|
|
|
+ log.Println("更新、绑定标签失败%s", userid, updateValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(insertValue) > 0 {
|
|
|
+ x, _ := db.Mysql.InsertBatch(db.DbConf.Bdcollection, insertCollKey2, insertValue)
|
|
|
+ if x < 0 {
|
|
|
+ log.Printf("userid:%s收藏失败", userid)
|
|
|
+ }
|
|
|
}
|
|
|
- wg.Wait()
|
|
|
ibool = i == len(labInfo.Binfo)
|
|
|
}
|
|
|
}
|
|
@@ -350,6 +363,7 @@ type CollList struct {
|
|
|
Buyerclass string `json:"buyerclass"` //采购单位 用,分隔开
|
|
|
BuyerPhone int `json:"buyerPhone"` //是否需要采购单位联系方式 1:需要 -1:不需要 0:未选中
|
|
|
WinnerPhone int `json:"winnerPhone"` //是否需要中标单位联系方式 1:需要 -1:不需要 0:未选中
|
|
|
+ Pagesize int `json:"pagesize"` //每页展示数量
|
|
|
}
|
|
|
|
|
|
func GetCollList(c *CollList, userid string) map[string]interface{} {
|
|
@@ -359,7 +373,6 @@ func GetCollList(c *CollList, userid string) map[string]interface{} {
|
|
|
"count": 0,
|
|
|
"haveNextPage": false,
|
|
|
"res": []map[string]interface{}{},
|
|
|
- "pageSize": pagesize_max,
|
|
|
}
|
|
|
sql := fmt.Sprintf(`select bid from %s where userid ='%s'`, db.DbConf.Bdcollection, userid)
|
|
|
isPay, _ := Power(userid)
|
|
@@ -443,11 +456,15 @@ func GetCollList(c *CollList, userid string) map[string]interface{} {
|
|
|
} else {
|
|
|
pagesize_max = config.BidCollConfig.FreeUserCollLimit
|
|
|
}
|
|
|
+ if c.Pagesize != 0 {
|
|
|
+ pagesize_max = c.Pagesize
|
|
|
+ }
|
|
|
sql += fmt.Sprintf(` order by createdate desc limit %v`, limit)
|
|
|
log.Println(sql)
|
|
|
data := db.Mysql.SelectBySql(sql)
|
|
|
count := 0
|
|
|
result := []map[string]interface{}{}
|
|
|
+ ids := ""
|
|
|
if data != nil && len(*data) > 0 {
|
|
|
if c.Pagenum <= 0 {
|
|
|
c.Pagenum = 1
|
|
@@ -461,12 +478,24 @@ func GetCollList(c *CollList, userid string) map[string]interface{} {
|
|
|
result = (*data)[start:end]
|
|
|
}
|
|
|
count = len(*data)
|
|
|
+ // util.CommonEncodeArticle("content", encodeId)
|
|
|
+ log.Println(time.Now())
|
|
|
+ for k, v := range *data {
|
|
|
+ if k == len(*data)-1 {
|
|
|
+ ids += util.EncodeId(qu.ObjToString(v["bid"]))
|
|
|
+ } else {
|
|
|
+ ids += util.EncodeId(qu.ObjToString(v["bid"])) + ","
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Println(time.Now())
|
|
|
}
|
|
|
haveNextPage := len(result) >= pagesize_max
|
|
|
// rdata["res"] = result
|
|
|
rdata["count"] = count
|
|
|
rdata["haveNextPage"] = haveNextPage
|
|
|
+ rdata["pageSize"] = pagesize_max
|
|
|
rdata["res"] = GetInfoById(db.Mgo_Bidding, db.DbConf.Mongodb.Bidding.Collection, db.DbConf.Mongodb.Bidding.Collection_change, result)
|
|
|
+ rdata["ids"] = ids
|
|
|
return rdata
|
|
|
}
|
|
|
|