common.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. package util
  2. import (
  3. "fmt"
  4. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXBase/rpc/bxbase"
  5. IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXBase/rpc/init"
  6. "log"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "app.yhyue.com/moapp/jybase/common"
  11. "app.yhyue.com/moapp/jybase/encrypt"
  12. elastic "app.yhyue.com/moapp/jybase/es"
  13. "app.yhyue.com/moapp/jybase/mongodb"
  14. "app.yhyue.com/moapp/jybase/mysql"
  15. "app.yhyue.com/moapp/jybase/redis"
  16. "go.mongodb.org/mongo-driver/bson/primitive"
  17. )
  18. const (
  19. query = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","subtype","s_winner","buyertel","winnertel","buyerclass"],"from":0,"size":%d}`
  20. 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,"winnertel":1,"s_winner":1,"buyertel":1,"attach_text":1}`
  21. 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}}`
  22. SearchGroupBidding = 1 // 搜索分组:1:招标采购公告;2:超前项目
  23. SearchGroupLeadingProject = 2 // 搜索分组:1:招标采购公告;2:超前项目
  24. SearchGroupAnnouncementProject = 3 // 搜索分组:招标公告
  25. SearchGroupForetellProject = 4 // 搜索分组:招标预告
  26. SearchGroupResultProject = 5 // 搜索分组:招标结果
  27. TopTypesBidding = "招标预告,招标公告,招标结果,招标信用信息"
  28. TopTypesLeadingProject = "拟建,采购意向"
  29. )
  30. // 是否是付费用户 -bool: true:是 fasle:不是
  31. func Power(userid string) (bool, map[string]interface{}) {
  32. isVip, isMember, isEnt := false, false, false
  33. vipstatus := 0
  34. phone := ""
  35. var registedate int64
  36. data := IC.Compatible.Select(userid, `"i_member_status":1,"i_vip_status":1,"s_m_phone":1,"s_phone":1,"o_vipjy":1,"l_registedate":1`)
  37. if data != nil && len(*data) > 0 {
  38. i_vip_status := common.IntAll((*data)["i_vip_status"])
  39. if i_vip_status > 1 {
  40. vipstatus = 1
  41. isVip = true
  42. }
  43. ovipjy, _ := (*data)["o_vipjy"].(map[string]interface{})
  44. if ovipjy["o_buyset"] != nil {
  45. o_buyset := ovipjy["o_buyset"].(map[string]interface{})
  46. if o_buyset["upgrade"] != nil && isVip {
  47. vipstatus = 2
  48. }
  49. }
  50. if i_member_status := common.IntAllDef((*data)["i_member_status"], 0); i_member_status > 0 {
  51. isMember = true
  52. }
  53. if s_phone, _ := (*data)["s_phone"].(string); s_phone != "" {
  54. phone = s_phone
  55. } else if s_m_phone, _ := (*data)["s_m_phone"].(string); s_m_phone != "" {
  56. phone = s_m_phone
  57. }
  58. if phone != "" {
  59. //已购买企业未过期
  60. if entInfo := *IC.MainMysql.SelectBySql(`SELECT status FROM entniche_info WHERE id IN (SELECT ent_id FROM entniche_user where phone = ? and power =1)`, phone); len(entInfo) > 0 {
  61. for _, v := range entInfo {
  62. if common.IntAll(v["status"]) == 1 {
  63. isEnt = true
  64. break
  65. }
  66. }
  67. }
  68. }
  69. registedate, _ = (*data)["l_registedate"].(int64)
  70. }
  71. return isVip || isEnt || isMember, map[string]interface{}{
  72. "vip": vipstatus,
  73. "member": isMember,
  74. "entniche": isEnt,
  75. "registedate": registedate,
  76. }
  77. }
  78. // 招标信息是否被收藏
  79. func IsCollByBids(bids, userid string) []string {
  80. res := []string{}
  81. collBidMap := map[string]bool{}
  82. isCollkey := fmt.Sprintf("isColl_%s", userid)
  83. collStatus := redis.GetInt("other", isCollkey)
  84. if collStatus == 0 {
  85. if count := int(IC.MainMysql.CountBySql(fmt.Sprintf(`select count(1)
  86. from %s where userid = ?`, "bdcollection"), userid)); count > 100 {
  87. collStatus = 2
  88. } else if count == 0 {
  89. collStatus = 0
  90. } else {
  91. collStatus = 1
  92. }
  93. redis.Put("other", isCollkey, collStatus, 259200)
  94. }
  95. if collStatus == 1 { //100条内 取redis
  96. list := GetCollRedis(userid, collStatus)
  97. for _, v := range list {
  98. collBidMap[v] = true
  99. }
  100. } else if collStatus == 2 { //大于100条 取mysql
  101. if labArr := *IC.MainMysql.SelectBySql(fmt.Sprintf("select bid from %s where userid = ?", "bdcollection"), userid); len(labArr) > 0 {
  102. for _, v := range labArr {
  103. bid_id := common.ObjToString(v["bid"])
  104. collBidMap[bid_id] = true
  105. }
  106. }
  107. } else { //0条
  108. return res
  109. }
  110. if bids == "" {
  111. for k, _ := range collBidMap {
  112. res = append(res, k)
  113. }
  114. } else {
  115. for _, v := range strings.Split(bids, ",") {
  116. //招标信息解密
  117. bid := DecodeId(v)
  118. if collBidMap[bid] {
  119. // url.QueryEscape(v)
  120. res = append(res, v)
  121. }
  122. }
  123. }
  124. return res
  125. }
  126. /*
  127. isColl int: 收藏条数的状态 (是否超过100条 超过:2 没超过:1)
  128. return
  129. []string:收藏的id
  130. */
  131. func GetCollRedis(userid string, isColl int) []string {
  132. redisCollKey := fmt.Sprintf("coll_%s", userid) //列表
  133. redisArr := []string{}
  134. if isColl == 1 {
  135. redisArr, _ = redis.Get("other", redisCollKey).([]string)
  136. if len(redisArr) == 0 {
  137. data := IC.MainMysql.SelectBySql(fmt.Sprintf(`select bid from %s where userid ='%s'`, "bdcollection", userid))
  138. if data != nil && len(*data) > 0 {
  139. for _, v := range *data {
  140. redisArr = append(redisArr, common.ObjToString(v["bid"]))
  141. }
  142. redis.Put("other", redisCollKey, redisArr, 259200)
  143. }
  144. }
  145. }
  146. return redisArr
  147. }
  148. // 招标信息 bid&userid 唯一
  149. type BidInfo struct {
  150. Bid string `json:"bid"` //招标信息id 加密后
  151. Buyerclass string `json:"buyerclass"` //采购单位类型
  152. Buyerinfo bool `json:"buyerinfo"` //是否有采购单位联系方式
  153. Winnerinfo bool `json:"winnerinfo"` //是否有中标企业联系方式
  154. Userid string `json:"userid"` //用户id
  155. Createdate string `json:"createdate"` //收藏时间
  156. Labelid string `json:"labelid"` //标签ids
  157. }
  158. func FormatColl(bidinfo []string) []BidInfo {
  159. es_ids := []string{}
  160. infos := map[string]interface{}{}
  161. for _, v := range bidinfo {
  162. es_ids = append(es_ids, DecodeId(v))
  163. }
  164. if len(es_ids) > 0 {
  165. list := elastic.Get("bidding", "bidding", fmt.Sprintf(query, strings.Join(es_ids, `","`), len(es_ids)))
  166. if list != nil {
  167. for _, v := range *list {
  168. _id := common.ObjToString(v["_id"])
  169. //中标电话 需要查企业库 和三级页保持一致
  170. winnertel := common.ObjToString(v["winnertel"])
  171. if winnertel == "" && isbid(v["subtype"]) {
  172. v["winnertel"] = getwinnertel(v["s_winner"])
  173. }
  174. infos[_id] = v
  175. }
  176. }
  177. }
  178. var bids []BidInfo
  179. if len(infos) > 0 {
  180. for _, v := range bidinfo {
  181. var bid BidInfo
  182. id := DecodeId(v)
  183. bid.Bid = v
  184. if infos[id] != nil {
  185. infoMap, _ := (infos[id]).(map[string]interface{})
  186. if common.ObjToString(infoMap["winnertel"]) != "" {
  187. bid.Winnerinfo = true
  188. }
  189. if common.ObjToString(infoMap["buyertel"]) != "" {
  190. bid.Buyerinfo = true
  191. }
  192. if common.ObjToString(infoMap["buyerclass"]) != "" {
  193. bid.Buyerclass = common.ObjToString(infoMap["buyerclass"])
  194. }
  195. }
  196. bids = append(bids, bid)
  197. }
  198. }
  199. return bids
  200. }
  201. func isbid(typ interface{}) bool {
  202. if typ != nil {
  203. subtype := common.ObjToString(typ)
  204. if subtype == "中标" || subtype == "合同" || subtype == "成交" {
  205. return true
  206. }
  207. }
  208. return false
  209. }
  210. func getwinnertel(company interface{}) string {
  211. if company != nil {
  212. data, _ := IC.MgoEnt.FindOneByField("winner_enterprise", map[string]interface{}{
  213. "company_name": common.ObjToString(company),
  214. }, map[string]interface{}{"company_phone": 1})
  215. if (*data)["company_phone"] != nil {
  216. return common.ObjToString((*data)["company_phone"])
  217. }
  218. }
  219. return ""
  220. }
  221. //修改redis中的收藏条数;
  222. /* typ:"d"删除 typ:"a"添加
  223. list:需要添加或删除的bid_id
  224. */
  225. func UpdateCollListRedis(typ, userid string, list []string) bool {
  226. bl := false
  227. if len(list) == 0 {
  228. return true
  229. }
  230. Blist := []string{}
  231. m := map[string]bool{}
  232. redisCollKey := fmt.Sprintf("coll_%s", userid)
  233. collTime := 3600 * 2
  234. if 7200 > 0 {
  235. collTime = 7200
  236. }
  237. redisIsCollKey := fmt.Sprintf("isColl_%s", userid) //是否超过100条 超过:2 没超过:1
  238. isCollTime := 3600 * 24 * 3
  239. if 259200 > 0 {
  240. isCollTime = 259200
  241. }
  242. collStatus := redis.GetInt("other", redisIsCollKey)
  243. redisArr := GetCollRedis(userid, collStatus)
  244. if len(redisArr) > 0 {
  245. for _, v := range redisArr {
  246. m[v] = true
  247. }
  248. }
  249. if typ == "a" {
  250. for _, v := range list {
  251. if m[v] {
  252. continue //去重
  253. }
  254. Blist = append(Blist, v)
  255. }
  256. } else if typ == "d" {
  257. for _, v := range list {
  258. delete(m, v)
  259. }
  260. if len(m) > 0 {
  261. for k, _ := range m {
  262. Blist = append(Blist, k)
  263. }
  264. }
  265. }
  266. arr := append(redisArr, Blist...)
  267. status := 1
  268. if len(arr) > 100 {
  269. status = 2
  270. arr = []string{}
  271. } else if len(arr) == 0 {
  272. status = 0
  273. }
  274. bl = redis.Put("other", redisCollKey, arr, collTime) &&
  275. redis.Put("other", redisIsCollKey, status, isCollTime)
  276. return bl
  277. }
  278. var PushMapping = &pushMapping{}
  279. type pushMapping struct {
  280. Area map[string]int
  281. City map[string]int
  282. Toptype map[string]int
  283. Subtype map[string]int
  284. Buyerclass map[string]int
  285. Subscopeclass map[string]int
  286. }
  287. func (p *pushMapping) Init(MainMysql *mysql.Mysql) {
  288. infotype := MainMysql.SelectBySql("select id,type,name from infotype")
  289. p.Toptype = map[string]int{}
  290. p.Subtype = map[string]int{}
  291. p.Buyerclass = map[string]int{}
  292. p.Subscopeclass = map[string]int{}
  293. for _, v := range *infotype {
  294. id := common.IntAll(v["id"])
  295. tp := common.IntAll(v["type"])
  296. name := common.ObjToString(v["name"])
  297. if tp == 1 {
  298. p.Toptype[name] = id
  299. } else if tp == 2 {
  300. p.Subtype[name] = id
  301. } else if tp == 3 {
  302. p.Buyerclass[name] = id
  303. } else if tp == 4 {
  304. p.Subscopeclass[name] = id
  305. }
  306. }
  307. if len(p.Toptype) == 0 {
  308. log.Fatalln("PushMapping Toptype Init Error")
  309. }
  310. if len(p.Subtype) == 0 {
  311. log.Fatalln("PushMapping Subtype Init Error")
  312. }
  313. if len(p.Buyerclass) == 0 {
  314. log.Fatalln("PushMapping Buyerclass Init Error")
  315. }
  316. if len(p.Subscopeclass) == 0 {
  317. log.Fatalln("PushMapping Subscopeclass Init Error")
  318. }
  319. //
  320. p.Area = map[string]int{}
  321. p.City = map[string]int{}
  322. province := MainMysql.SelectBySql("select id,level,name from province")
  323. for _, v := range *province {
  324. id := common.IntAll(v["id"])
  325. level := common.IntAll(v["level"])
  326. name := common.ObjToString(v["name"])
  327. if level == 1 {
  328. p.Area[name] = id
  329. } else if level == 2 {
  330. p.City[name] = id
  331. }
  332. }
  333. if len(p.Area) == 0 {
  334. log.Fatalln("PushMapping Area Init Error")
  335. }
  336. if len(p.City) == 0 {
  337. log.Fatalln("PushMapping City Init Error")
  338. }
  339. }
  340. type InfoList struct {
  341. Id string `json:"_id"`
  342. Title string `json:"title"`
  343. Area string `json:"area"`
  344. Buyerclass string `json:"buyerclass"`
  345. Type string `json:"type"`
  346. S_subscopeclass string `json:"s_subscopeclass"`
  347. Publishtime int64 `json:"publishtime"`
  348. Budget interface{} `json:"budget"`
  349. Bidamount interface{} `json:"bidamount"`
  350. Buyer string `json:"buyer"`
  351. S_winner string `json:"s_winner"`
  352. Bidopentime int64 `json:"bidopentime"`
  353. FileExists bool `json:"fileExists"`
  354. }
  355. // 根据id取内容
  356. func GetInfoById(Mgo_bidding mongodb.MongodbSim, bidding, bidding_back string, idlist []map[string]interface{}) []*InfoList {
  357. array := make([]*InfoList, len(idlist))
  358. if len(idlist) == 0 {
  359. return array
  360. }
  361. m := map[string]bool{}
  362. ids := []string{}
  363. for _, v := range idlist {
  364. if m[common.ObjToString(v["bid"])] {
  365. continue
  366. }
  367. m[common.ObjToString(v["bid"])] = true
  368. ids = append(ids, common.ObjToString(v["bid"]))
  369. }
  370. infos := map[string]map[string]interface{}{}
  371. //redis
  372. es_ids := []string{}
  373. for _, v := range ids {
  374. info_i := redis.Get("pushcache_1", fmt.Sprintf("info_%s", v))
  375. if info_i != nil {
  376. info_m, _ := info_i.(map[string]interface{})
  377. info_m["_id"] = v
  378. infos[v] = info_m
  379. } else {
  380. es_ids = append(es_ids, v)
  381. }
  382. }
  383. // log.Println(es_ids)
  384. //elasticsearch
  385. if len(es_ids) > 0 {
  386. list := elastic.Get("bidding", "bidding", fmt.Sprintf(querys, strings.Join(es_ids, `","`), len(es_ids)))
  387. if list != nil {
  388. for _, v := range *list {
  389. _id := common.ObjToString(v["_id"])
  390. v["attachment_count"] = common.If(v["filetext"] != nil, 1, 0).(int)
  391. infos[_id] = v
  392. }
  393. }
  394. }
  395. //mongodb bidding
  396. mgo_ids := []primitive.ObjectID{}
  397. for _, v := range es_ids {
  398. if infos[v] == nil {
  399. _id, _ := primitive.ObjectIDFromHex(v)
  400. mgo_ids = append(mgo_ids, _id)
  401. }
  402. }
  403. if len(mgo_ids) > 0 {
  404. list, ok := Mgo_bidding.Find(bidding, map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_ids}}, nil, mongodb_fields, false, -1, -1)
  405. if ok && *list != nil {
  406. for _, v := range *list {
  407. _id := mongodb.BsonIdToSId(v["_id"])
  408. v["_id"] = _id
  409. v["attachment_count"] = common.If(v["attach_text"] != nil, 1, 0).(int)
  410. infos[_id] = v
  411. }
  412. }
  413. }
  414. //mongodb bidding_back
  415. mgo_back_ids := []primitive.ObjectID{}
  416. for _, v := range mgo_ids {
  417. if infos[mongodb.BsonIdToSId(v)] == nil {
  418. mgo_back_ids = append(mgo_back_ids, v)
  419. }
  420. }
  421. if len(mgo_back_ids) > 0 {
  422. list, ok := Mgo_bidding.Find(bidding_back, map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_back_ids}}, nil, mongodb_fields, false, -1, -1)
  423. if ok && *list != nil {
  424. for _, v := range *list {
  425. _id := mongodb.BsonIdToSId(v["_id"])
  426. v["_id"] = _id
  427. v["attachment_count"] = common.If(v["attach_text"] != nil, 1, 0).(int)
  428. infos[_id] = v
  429. }
  430. }
  431. }
  432. //
  433. for k, v := range idlist {
  434. info := infos[common.ObjToString(v["bid"])]
  435. if info == nil {
  436. info = map[string]interface{}{}
  437. }
  438. array[k] = InfoFormat(common.ObjToString(v["bid"]), &info)
  439. }
  440. return array
  441. }
  442. // 列表单条信息格式化
  443. func InfoFormat(p string, info *map[string]interface{}) *InfoList {
  444. area := common.ObjToString((*info)["area"])
  445. if area == "A" {
  446. area = "全国"
  447. }
  448. industry := common.ObjToString((*info)["s_subscopeclass"])
  449. scs := strings.Split(industry, ",")
  450. if len(scs) > 0 {
  451. industry = scs[0]
  452. if industry != "" {
  453. iss := strings.Split(industry, "_")
  454. if len(iss) > 0 {
  455. industry = iss[0]
  456. }
  457. }
  458. }
  459. infotype := common.ObjToString((*info)["subtype"])
  460. if infotype == "" {
  461. infotype = common.ObjToString((*info)["toptype"])
  462. }
  463. if infotype == "" {
  464. infotype = common.ObjToString((*info)["type"])
  465. if infotype == "tender" {
  466. infotype = "招标"
  467. } else if infotype == "bid" {
  468. infotype = "中标"
  469. }
  470. }
  471. _id := p
  472. if _id == "" {
  473. _id = common.ObjToString((*info)["_id"])
  474. }
  475. return &InfoList{
  476. Id: encrypt.EncodeArticleId2ByCheck(_id),
  477. Title: common.ObjToString((*info)["title"]),
  478. Area: area,
  479. Buyerclass: common.ObjToString((*info)["buyerclass"]),
  480. Type: infotype,
  481. S_subscopeclass: industry,
  482. Publishtime: common.Int64All((*info)["publishtime"]),
  483. Budget: (*info)["budget"],
  484. Bidamount: (*info)["bidamount"],
  485. Buyer: common.ObjToString((*info)["buyer"]),
  486. S_winner: common.ObjToString((*info)["s_winner"]),
  487. Bidopentime: common.Int64All((*info)["bidopentime"]),
  488. FileExists: common.IntAll((*info)["attachment_count"]) > 0,
  489. }
  490. }
  491. // 搜藏列表
  492. func CollListSql(c *bxbase.ListReq, isPay bool, userid string) string {
  493. sql := fmt.Sprintf(`select bid from %s where userid ='%s'`, "bdcollection", userid)
  494. limit := 10
  495. //个人标签
  496. if c.Label != "" {
  497. i := 0
  498. sql += ` and `
  499. if labelArr := strings.Split(c.Label, ","); len(labelArr) > 0 {
  500. sql += `(`
  501. for _, v := range labelArr {
  502. i++
  503. labid := encrypt.SE.DecodeString(v)
  504. if i == len(labelArr) {
  505. sql += fmt.Sprintf(`FIND_IN_SET(%s,labelid)`, labid)
  506. } else {
  507. sql += fmt.Sprintf(`FIND_IN_SET(%s,labelid) or `, labid)
  508. }
  509. }
  510. sql += `)`
  511. }
  512. }
  513. now := time.Now()
  514. start, end := "", ""
  515. //收藏时间
  516. if c.SelectTime == "lately-7" { //最近7天
  517. start = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
  518. } else if c.SelectTime == "lately-30" { //最近30天
  519. start = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
  520. } else if c.SelectTime == "thisyear" { //去年
  521. start = fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
  522. end = fmt.Sprint(time.Date(now.Year()-1, 12, 31, 23, 59, 59, 0, time.Local).Format(Date_Full_Layout))
  523. } else if len(strings.Split(c.SelectTime, "_")) == 2 {
  524. if c.SelectTime != "0_0" {
  525. starttime := strings.Split(c.SelectTime, "_")[0]
  526. startstamp, _ := strconv.Atoi(starttime)
  527. start = time.Unix(int64(startstamp), 0).Format(Date_Full_Layout)
  528. endtime := strings.Split(c.SelectTime, "_")[1]
  529. et, _ := strconv.ParseInt(endtime, 0, 64)
  530. etTime := time.Unix(et, 0)
  531. end = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Format(Date_Full_Layout))
  532. }
  533. }
  534. if start != "" && end != "" {
  535. sql += ` and createdate >= '` + start + `' and createdate < '` + end + `'`
  536. } else if start != "" && end == "" {
  537. sql += ` and createdate >= '` + start + `'`
  538. } else if start == "" && end != "" {
  539. sql += ` and createdate < '` + end + `'`
  540. }
  541. if isPay {
  542. //采购单位 用,分隔开
  543. if c.Buyerclass != "" {
  544. i := 0
  545. sql += ` and buyerclass in (`
  546. if buyClassArr := strings.Split(c.Buyerclass, ","); len(buyClassArr) > 0 {
  547. for _, v := range buyClassArr {
  548. i++
  549. buyerclassid := fmt.Sprint(PushMapping.Buyerclass[v])
  550. if i == len(buyClassArr) {
  551. sql += buyerclassid + `)`
  552. } else {
  553. sql += buyerclassid + ","
  554. }
  555. }
  556. }
  557. }
  558. //是否存在采购单位电话
  559. if c.BuyerPhone == 1 {
  560. sql += ` and buyerinfo = 1`
  561. } else if c.BuyerPhone == -1 {
  562. sql += ` and buyerinfo = 0`
  563. }
  564. //是否存在中标单位电话
  565. if c.WinnerPhone == 1 {
  566. sql += ` and winnerinfo = 1`
  567. } else if c.WinnerPhone == -1 {
  568. sql += ` and winnerinfo = 0`
  569. }
  570. limit = 5000
  571. }
  572. sql += fmt.Sprintf(` order by createdate desc limit %v`, limit)
  573. return sql
  574. }