swordfish.go 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178
  1. package front
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "fmt"
  6. "html/template"
  7. "jfw/config"
  8. "jfw/tools"
  9. "jfw/wx"
  10. "log"
  11. "math/rand"
  12. "qfw/util"
  13. "qfw/util/elastic"
  14. "qfw/util/redis"
  15. "regexp"
  16. "strconv"
  17. "strings"
  18. "sync"
  19. "time"
  20. "github.com/go-xweb/xweb"
  21. . "github.com/thinxer/go-word2vec"
  22. "gopkg.in/mgo.v2/bson"
  23. )
  24. const (
  25. bidSearch_pageSize = 50 //招标搜索分页--每页显示数量
  26. bidSearch_maxPageSize = 10 //招标搜索分页--最大页数
  27. wx_maxPageNum = 20
  28. wx_pageSize = 50
  29. bidSearch_field_1 = `"_id","title","publishtime","toptype","subtype","type","area","href","bidopentime","winner","agency","bidamount","budget","biddingcontent","projectname"`
  30. bidSearch_field = bidSearch_field_1 + `,"detail"`
  31. bidSearch_sort = `{"publishtime":-1}`
  32. )
  33. var M *Model
  34. var recomKWChan chan bool = make(chan bool, 1)
  35. var listlock = &sync.Mutex{}
  36. var clearHtml *regexp.Regexp
  37. func init() {
  38. M, _ = Load("./zb.bin")
  39. clearHtml, _ = regexp.Compile("<[^>]*>")
  40. }
  41. //剑鱼推送三级页点赞暂弃 改成剑鱼实验室点赞功能
  42. func (m *Front) Praise() error {
  43. defer util.Catch()
  44. var flag = "F"
  45. var praiseflag = true
  46. thistype := m.GetString("type")
  47. uod := m.GetString("uod")
  48. util.Try(func() {
  49. pdata, _ := mongodb.FindOneByField("praise", `{"s_type":"`+thistype+`"}`, `{"s_no":1}`)
  50. if len(*pdata) != 0 {
  51. if uod == "U" {
  52. praiseflag = mongodb.Update("praise", `{"s_type":"`+thistype+`"}`, `{ "$inc" : { "s_no" : 1 }}`, false, false)
  53. } else {
  54. praiseflag = mongodb.Update("praise", `{"s_type":"`+thistype+`"}`, `{ "$inc" : { "s_no" : -1 }}`, false, false)
  55. }
  56. if praiseflag {
  57. flag = "T"
  58. }
  59. }
  60. }, func(e interface{}) {
  61. log.Println("剑鱼实验室点赞出错", e)
  62. })
  63. m.ServeJson(map[string]interface{}{
  64. "flag": flag,
  65. })
  66. return nil
  67. }
  68. func (m *Front) Getpraise() error {
  69. defer util.Catch()
  70. thistype := m.GetString("type")
  71. praiseno := 125
  72. switchstatus := 0
  73. if m.Session().Get("s_m_openid") == nil {
  74. return m.Redirect("/swordfish/about")
  75. }
  76. util.Try(func() {
  77. data := make(map[string]interface{})
  78. pdata, _ := mongodb.FindOneByField("praise", `{"s_type":"`+thistype+`"}`, `{"s_no":1}`)
  79. myopenid := m.Session().Get("s_m_openid")
  80. tmp, _ := mongodb.FindOneByField("user", `{"s_m_openid":"`+myopenid.(string)+`"}`, `{"i_smartset":1,"i_dataexport":1,"i_supersearch":1,"i_entsesearch":1,"i_followent":1,"i_smartsetiknow":1,"i_dataexportiknow":1,"i_supersearchiknow":1,"i_entsesearchiknow":1,"i_followentiknow":1}`)
  81. if thistype == "zndy" {
  82. data["s_name"] = "剑鱼实验室-智能订阅"
  83. switchstatus = util.IntAll((*tmp)["i_smartset"])
  84. } else if thistype == "sjdc" {
  85. data["s_name"] = "剑鱼实验室-数据导出"
  86. switchstatus = util.IntAll((*tmp)["i_dataexport"])
  87. } else if thistype == "cjss" {
  88. data["s_name"] = "剑鱼实验室-超级搜索"
  89. switchstatus = util.IntAll((*tmp)["i_supersearch"])
  90. } else if thistype == "zbqy" {
  91. data["s_name"] = "剑鱼实验室-中标企业"
  92. switchstatus = util.IntAll((*tmp)["i_entsesearch"])
  93. } else if thistype == "gzqy" {
  94. data["s_name"] = "剑鱼实验室-关注企业"
  95. switchstatus = util.IntAll((*tmp)["i_followent"])
  96. }
  97. if len(*pdata) == 0 {
  98. data["s_type"] = thistype
  99. data["s_no"] = 125
  100. data["l_date"] = time.Now().Unix()
  101. mongodb.Save("praise", data)
  102. } else {
  103. praiseno = util.IntAll((*pdata)["s_no"])
  104. }
  105. }, func(e interface{}) {
  106. log.Println("剑鱼实验室取赞出错", e)
  107. })
  108. m.ServeJson(map[string]interface{}{
  109. "praiseno": praiseno,
  110. "switchstatus": switchstatus,
  111. })
  112. return nil
  113. }
  114. //剑鱼pc首页
  115. func (m *Front) NewSordfish() error {
  116. ispc, _ := m.GetInteger("ispc")
  117. var shareid = m.GetString("id")
  118. if len(shareid) == 0 {
  119. shareid = fmt.Sprintf("%s%d", config.Seoconfig["jysy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
  120. } else {
  121. redis.Del("other", "jypcindex")
  122. }
  123. m.T["logid"] = config.Seoconfig["jysy"].(string)
  124. m.T["shareid"] = se.EncodeString(shareid)
  125. regex, _ := regexp.Compile("(Android|Mobile)")
  126. if ispc == 0 && len(regex.FindAllString(m.Header("User-Agent"), -1)) > 0 {
  127. return m.Render("/pc/mobileindex.html", &m.T)
  128. } else {
  129. if ret := redis.Get("other", "jypcindex"); ret != nil {
  130. return m.SetBody([]byte(ret.(string)))
  131. } else {
  132. m.DisableHttpCache()
  133. lastBids := elastic.GetPage("bidding", "bidding", "{}", bidSearch_sort, `"_id","title","publishtime","toptype","subtype","type","area","href","biddingcontent"`, 0, 18)
  134. if lastBids != nil && len(*lastBids) > 0 {
  135. bidListConvert("", lastBids)
  136. lbnHtml, olHtml := structureLastBidsHtml(lastBids)
  137. m.T["lbnHtml"] = lbnHtml
  138. m.T["olHtml"] = olHtml
  139. }
  140. content, _ := m.Render4Cache("/pc/index.html", &m.T)
  141. redis.Put("other", "jypcindex", string(content), 60*60*2)
  142. return m.SetBody(content)
  143. }
  144. }
  145. return m.Render("/pc/index.html", &m.T)
  146. }
  147. func structureLastBidsHtml(lastBidNews *[]map[string]interface{}) (string, string) {
  148. var tmp int = 0
  149. var olCount int = 0
  150. var lbnHtml string = ""
  151. var olHtml string = `<ol class="carousel-indicators">`
  152. for i := 0; i < len(*lastBidNews); i++ {
  153. lastBidNew := (*lastBidNews)[i]
  154. if tmp == 0 {
  155. olHtml += `<li data-target="#lastBidNews" data-slide-to="` + strconv.Itoa(olCount) + `"`
  156. if olCount == 0 {
  157. olHtml += ` class="active"`
  158. }
  159. olHtml += `></li>`
  160. olCount++
  161. }
  162. tmp++
  163. if tmp == 1 {
  164. lbnHtml += `<div class="item`
  165. if i == 0 {
  166. lbnHtml += ` active`
  167. }
  168. lbnHtml += `"><ul>`
  169. }
  170. lbnHtml += `<li><div><a onclick="noIn(this),_czc.push(['_trackEvent', '最新招标信息', '点击扫码', 'lastBidNews'])" dataListId="` + util.EncodeArticleId2ByCheck(util.ObjToString(lastBidNew["_id"])) + `" target="_blank">` + strconv.Itoa(tmp) + `.&nbsp;&nbsp;` + util.ObjToString(lastBidNew["title"]) + `</a></div><div>`
  171. area, _ := lastBidNew["area"].(string)
  172. area = strings.TrimSpace(area)
  173. finalType, _ := lastBidNew["subtype"].(string)
  174. if finalType == "" {
  175. finalType = util.ObjToString(lastBidNew["toptype"])
  176. }
  177. if finalType == "" {
  178. finalType = util.ObjToString(lastBidNew["type"])
  179. if finalType == "bid" {
  180. finalType = "中标"
  181. } else if finalType == "tender" {
  182. finalType = "招标"
  183. } else {
  184. finalType = ""
  185. }
  186. }
  187. stpadd, areaadd := classify(finalType, area)
  188. if area != "" && area != "A" {
  189. lbnHtml += `<span class="com-area"><a href="/list/area/` + areaadd + `.html">` + area + `</a></span>`
  190. }
  191. if finalType != "" {
  192. lbnHtml += `<span class="com-type"><a href="/list/stype/` + stpadd + `.html">` + finalType + `</a></span>`
  193. }
  194. publishtime, _ := lastBidNew["publishtime"].(float64)
  195. if publishtime != 0 {
  196. diff := util.TimeDiff(time.Unix(util.Int64All(publishtime), 0))
  197. if diff != "" {
  198. lbnHtml += `<span class="com-time" data-value="` + fmt.Sprint(util.Int64All(publishtime)) + `"><i class="glyphicon bofangjilu"></i>` + diff + `</span>`
  199. }
  200. }
  201. lbnHtml += `</div></li>`
  202. if tmp == 6 || i == len(*lastBidNews)-1 {
  203. tmp = 0
  204. lbnHtml += `</ul></div>`
  205. }
  206. }
  207. if olCount > 1 {
  208. olHtml += `</ol>`
  209. }
  210. return lbnHtml, olHtml
  211. }
  212. func detailLikeRpc(Interest []string, res *[]map[string]interface{}, flag bool) (mcontent map[string]interface{}) {
  213. //defer util.Catch()
  214. str := fmt.Sprintf("<div>根据您设置的关键词(%s),给您推送以下招标信息:</div>", strings.Join(Interest, ";"))
  215. //发送内容组合
  216. i := 0
  217. o_pushinfo := map[string]interface{}{}
  218. var details []string
  219. v := *res
  220. bmatch := false
  221. for _, k2 := range v {
  222. title := strings.Replace(k2["title"].(string), "\n", "", -1)
  223. province := util.ObjToString(k2["area"])
  224. if province != "" && province != "A" {
  225. title = `[<span class='area'>` + province + `</span>]` + title
  226. }
  227. i++
  228. str += "<div class='tslist'><span class='xh'>" + fmt.Sprintf("%d", i) + ".</span><a class='bt' target='_blank' sid='" + util.EncodeArticleId2ByCheck(util.BsonIdToSId(k2["_id"])) + "' eid='" + util.EncodeArticleId2ByCheck(util.BsonIdToSId(k2["_id"])) + "' href='" + k2["href"].(string) + "'>" + title + "</a></div>"
  229. o_pushinfo[strconv.Itoa(i)] = map[string]interface{}{
  230. "publishtime": k2["publishtime"],
  231. "stype": k2["type"],
  232. "topstype": k2["toptype"],
  233. "substype": k2["subtype"],
  234. }
  235. if flag {
  236. highlight, _ := k2["highlight"].(map[string][]string)
  237. detail := ""
  238. if len(highlight["detail"]) > 0 {
  239. detail = highlight["detail"][0]
  240. }
  241. details = append(details, detail)
  242. }
  243. }
  244. mcontent = map[string]interface{}{}
  245. if len(o_pushinfo) > 0 {
  246. bmatch = true
  247. mcontent["o_pushinfo"] = o_pushinfo
  248. mcontent["s_content"] = str
  249. mcontent["s_words"] = Interest
  250. }
  251. mcontent["bmatch"] = bmatch
  252. if flag {
  253. mcontent["details"] = details
  254. }
  255. return
  256. }
  257. //跳转到pc查询剑鱼信息列表
  258. func (m *Front) Searchinfolist(p string) error {
  259. defer util.Catch()
  260. var shareid = m.GetString("id")
  261. if len(shareid) == 0 {
  262. shareid = fmt.Sprintf("%s%d", config.Seoconfig["jysslby"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
  263. }
  264. m.T["logid"] = config.Seoconfig["jysslby"].(string)
  265. m.T["shareid"] = se.EncodeString(shareid)
  266. keywords := m.GetString("keywords")
  267. searchvalue := m.GetString("searchvalue")
  268. area := m.GetString("area")
  269. publishtime := m.GetString("publishtime")
  270. toptype := m.GetString("toptype")
  271. subtype := m.GetString("subtype")
  272. industry := m.GetString("industry")
  273. selectType := m.GetString("selectType")
  274. selectTypesess := m.GetSession("selectType")
  275. if selectTypesess != nil && selectTypesess != "" {
  276. selectType = selectTypesess.(string)
  277. }
  278. if selectType == "" {
  279. selectType = "all"
  280. }
  281. var status = 1
  282. var count int64
  283. var list *[]map[string]interface{}
  284. pages := make([]interface{}, 0)
  285. if len(searchvalue) > 0 {
  286. count, list = getBidSearchData(searchvalue, area, publishtime, subtype, industry, 0, true, selectType)
  287. } else if m.Method() == "POST" {
  288. status = 2
  289. count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, 0, true)
  290. } else {
  291. status = 2
  292. if redis.Get("other", "index_list") == nil {
  293. intns := make([]int, 0)
  294. for i := 0; i < 10; i++ {
  295. if len(intns) == 0 {
  296. intns = append(intns, rand.Intn(100))
  297. } else {
  298. for {
  299. v := rand.Intn(intns[(i-1)] + 100)
  300. if v-intns[(i-1)] >= 30 {
  301. intns = append(intns, v)
  302. break
  303. }
  304. }
  305. }
  306. }
  307. for i := 0; i < 10; i++ {
  308. count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, intns[i], true)
  309. for k, v := range *list {
  310. v["k"] = (k + 1) + i*50
  311. t := time.Unix(util.Int64All(v["publishtime"]), 0)
  312. v["timetemp"] = fmt.Sprint(util.Int64All(v["publishtime"]))
  313. v["_id"] = util.EncodeArticleId2ByCheck(v["_id"].(string))
  314. v["time"] = util.TimeDiff(t)
  315. var stp = ""
  316. if v["subtype"] != nil {
  317. stp, _ = v["subtype"].(string)
  318. } else {
  319. stp = ""
  320. }
  321. if stp == "" && v["toptype"] != nil {
  322. stp, _ = v["toptype"].(string)
  323. }
  324. area, _ := v["area"].(string)
  325. v["stypeadd"], v["areaadd"] = classify(stp, area)
  326. }
  327. pages = append(pages, list)
  328. }
  329. m.DisableHttpCache()
  330. redis.Put("other", "index_list", pages, 60*60*2)
  331. }
  332. }
  333. if status == 2 && m.Method() == "GET" {
  334. pages := redis.Get("other", "index_list").([]interface{})
  335. p := util.IntAll(p)
  336. if p <= 0 || p > 10 {
  337. p = 1
  338. }
  339. if p-1 <= 0 {
  340. m.T["prev"] = 1
  341. } else {
  342. m.T["prev"] = p - 1
  343. }
  344. if p+1 >= 11 {
  345. m.T["next"] = 10
  346. } else {
  347. m.T["next"] = p + 1
  348. }
  349. m.T["cur"] = p
  350. m.T["list"] = pages[p-1]
  351. return m.Render("/pc/bidsearch_static.html", &m.T)
  352. } else {
  353. if list != nil {
  354. for _, v := range *list {
  355. v["_id"] = util.EncodeArticleId2ByCheck(v["_id"].(string))
  356. stp, _ := v["subtype"].(string)
  357. if stp == "" {
  358. stp, _ = v["toptype"].(string)
  359. }
  360. area, _ := v["area"].(string)
  361. v["stypeadd"], v["areaadd"] = classify(stp, area)
  362. //正文匹配检索关键词
  363. highlight, _ := v["highlight"].(map[string][]string)
  364. detail := ""
  365. for _, val := range highlight["detail"] {
  366. detail += clearHtml.ReplaceAllString(val, "")
  367. }
  368. v["detail"] = detail
  369. }
  370. }
  371. m.T["list"] = list
  372. isopen, _ := m.GetInteger("isopen")
  373. m.T["isopen"] = isopen
  374. m.T["area"] = area
  375. m.T["publishtime"] = publishtime
  376. m.T["timeslot"] = m.GetString("timeslot")
  377. m.T["toptype"] = toptype
  378. m.T["subtype"] = subtype
  379. m.T["count"] = count
  380. m.T["status"] = status
  381. m.T["keywords"] = keywords
  382. m.T["searchvalue"] = searchvalue
  383. m.T["selectType"] = selectType
  384. m.T["login"] = m.Session().Get("user")
  385. m.SetSession("paramkey", keywords)
  386. if publishtime == "lately-7" {
  387. m.SetSession("parampublishtime", "最近7天")
  388. } else if publishtime == "lately-30" {
  389. m.SetSession("parampublishtime", "最近30天")
  390. } else if publishtime == "thisyear" {
  391. m.SetSession("parampublishtime", "去年")
  392. } else {
  393. m.SetSession("parampublishtime", publishtime)
  394. }
  395. m.SetSession("paramarea", area)
  396. if subtype != "" {
  397. m.SetSession("paraminfotype", subtype)
  398. } else {
  399. m.SetSession("paraminfotype", toptype)
  400. }
  401. return m.Render("/pc/bidsearch.html", &m.T)
  402. }
  403. }
  404. //ajax分页请求
  405. func (m *Front) PcAjaxReq() {
  406. reqType := m.GetString("reqType")
  407. //获取最新招标信息
  408. if reqType == "lastBids" {
  409. ls := elastic.GetPage(INDEX, TYPE, "{}", bidSearch_sort, bidSearch_field_1, 0, 18)
  410. bidListConvert("", ls)
  411. m.ServeJson(map[string]interface{}{
  412. "list": ls,
  413. })
  414. return
  415. } else if reqType == "rewardText" {
  416. rewardText, _ := getRewardText()
  417. m.Write(rewardText)
  418. return
  419. }
  420. currentPage, _ := m.GetInteger("pageNumber")
  421. if currentPage > bidSearch_maxPageSize {
  422. currentPage = bidSearch_maxPageSize
  423. }
  424. start := (currentPage - 1) * bidSearch_pageSize
  425. area := m.GetString("area")
  426. subtype := m.GetString("subtype")
  427. searchvalue := m.GetString("searchvalue")
  428. publishtime := m.GetString("publishtime")
  429. selectType := m.GetString("selectType")
  430. industry := m.GetString("industry")
  431. m.SetSession("selectType", selectType)
  432. fmt.Println(selectType)
  433. var list *[]map[string]interface{}
  434. var count int64
  435. status, _ := m.GetInteger("status")
  436. if reqType == "filter" {
  437. if status == 1 {
  438. count, list = getBidSearchData(searchvalue, area, publishtime, subtype, industry, 0, true, selectType)
  439. } else if status == 2 {
  440. count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, 0, true)
  441. }
  442. } else if reqType == "bidSearch" {
  443. _, list = getBidSearchData(searchvalue, area, publishtime, subtype, industry, start, false, selectType)
  444. } else if reqType == "lastNews" {
  445. _, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, start, false)
  446. }
  447. if list != nil && len(*list) > 0 {
  448. for _, v := range *list {
  449. if v["_id"] != nil {
  450. v["_id"] = util.EncodeArticleId2ByCheck(v["_id"].(string))
  451. }
  452. stp, ok := v["subtype"].(string)
  453. if ok && stp == "" {
  454. stp = v["toptype"].(string)
  455. }
  456. area, ok := v["area"].(string)
  457. v["stypeadd"], v["areaadd"] = classify(stp, area)
  458. //正文匹配检索关键词
  459. highlight, _ := v["highlight"].(map[string][]string)
  460. detail := ""
  461. for _, val := range highlight["detail"] {
  462. detail += clearHtml.ReplaceAllString(val, "")
  463. }
  464. v["detail"] = detail
  465. }
  466. }
  467. m.ServeJson(map[string]interface{}{
  468. "list": list,
  469. "count": count,
  470. })
  471. }
  472. /**
  473. **页面搜索
  474. **/
  475. func getBidSearchData(searchvalue, area, publishtime, subtype, industry string, start int, isGetCount bool, selectType string) (count int64, list *[]map[string]interface{}) {
  476. query := getBidSearchQuery(area, publishtime, subtype, industry)
  477. //selectType:全文搜索(all)、标题搜索(title)
  478. var qstr string
  479. qstr = elastic.GetNgramQuery(searchvalue, query, `"title","detail"` /*FINDF*/)
  480. if isGetCount && qstr != "" {
  481. count = elastic.Count(INDEX, TYPE, qstr)
  482. }
  483. if !isGetCount || count > 0 {
  484. var repl *[]map[string]interface{}
  485. if selectType == "all" {
  486. //全文搜索
  487. repl = elastic.GetByNgramOther(INDEX, TYPE, searchvalue, query, `"title","detail"` /*FINDF*/, bidSearch_sort, bidSearch_field, start, bidSearch_pageSize, true, false, 115)
  488. } else {
  489. //标题搜索
  490. repl = elastic.GetByNgram(INDEX, TYPE, searchvalue, query, `"title"` /*FINDF*/, bidSearch_sort, bidSearch_field, start, bidSearch_pageSize)
  491. }
  492. if repl != nil && *repl != nil && len(*repl) > 0 {
  493. bidListConvert(industry, repl)
  494. list = repl
  495. }
  496. }
  497. limitCount := int64(bidSearch_pageSize * bidSearch_maxPageSize)
  498. if count > limitCount {
  499. count = limitCount
  500. }
  501. return
  502. }
  503. func getLastNewsData(searchvalue, area, publishtime, subtype, industry string, start int, isGetCount bool) (count int64, list *[]map[string]interface{}) {
  504. //最新招标信息
  505. query := getBidSearchQuery(area, publishtime, subtype, industry)
  506. strquery := `{"query":{"bool":{"must":[` + query + `],"must_not":[],"should":[],"minimum_should_match" : 1}}}`
  507. if isGetCount {
  508. count = elastic.Count(INDEX, TYPE, strquery)
  509. //count = elastic.Count(INDEX, TYPE, elastic.MakeQuery(query, "", "", -1, -1))
  510. }
  511. if !isGetCount || count > 0 {
  512. //repl := elastic.GetPage(INDEX, TYPE, query, bidSearch_sort, bidSearch_field, start, bidSearch_pageSize)
  513. if query == "{}" {
  514. query = ""
  515. }
  516. repl := elastic.GetByNgramOther(INDEX, TYPE, searchvalue, query, `"title","detail"` /*FINDF*/, bidSearch_sort, bidSearch_field, start, bidSearch_pageSize, true, false, 115)
  517. if repl != nil && *repl != nil && len(*repl) > 0 {
  518. bidListConvert(industry, repl)
  519. list = repl
  520. }
  521. }
  522. limitCount := int64(bidSearch_pageSize * bidSearch_maxPageSize)
  523. if count > limitCount {
  524. count = limitCount
  525. }
  526. return
  527. }
  528. func getBidSearchQuery(area, publishtime, subtype, industry string) string {
  529. query := ``
  530. if area != "" {
  531. query += `{"terms":{"area":[`
  532. for k, v := range strings.Split(area, ",") {
  533. if k > 0 {
  534. query += `,`
  535. }
  536. query += `"` + v + `"`
  537. }
  538. query += `]}}`
  539. }
  540. if publishtime != "" {
  541. if len(query) > 0 {
  542. query += ","
  543. }
  544. starttime, endtime := "", ""
  545. now := time.Now()
  546. if publishtime == "lately-7" { //最近7天
  547. starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
  548. } else if publishtime == "lately-30" { //最近30天
  549. starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
  550. } else if publishtime == "thisyear" { //去年
  551. starttime = fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Unix())
  552. endtime = fmt.Sprint(time.Date(now.Year(), 1, 1, 0, 0, 0, 0, time.Local).Unix())
  553. } else {
  554. starttime = strings.Split(publishtime, "_")[0]
  555. endtime = strings.Split(publishtime, "_")[1]
  556. etTime := time.Now()
  557. if endtime != "" {
  558. et, _ := strconv.ParseInt(endtime, 0, 64)
  559. etTime = time.Unix(et, 0)
  560. }
  561. endtime = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Unix())
  562. }
  563. query += `{"range":{"publishtime":{`
  564. if starttime != "" {
  565. query += `"gte":` + starttime
  566. }
  567. if starttime != "" && endtime != "" {
  568. query += `,`
  569. }
  570. if endtime != "" {
  571. query += `"lt":` + endtime
  572. }
  573. query += `}}}`
  574. }
  575. if subtype != "" {
  576. if len(query) > 0 {
  577. query += ","
  578. }
  579. query += `{"terms":{"subtype":[`
  580. for k, v := range strings.Split(subtype, ",") {
  581. if k > 0 {
  582. query += `,`
  583. }
  584. query += `"` + v + `"`
  585. }
  586. query += `]}}`
  587. }
  588. if industry != "" {
  589. if len(query) > 0 {
  590. query += ","
  591. }
  592. query += `{"regexp":{"industry":".*(`
  593. for k, v := range strings.Split(industry, ",") {
  594. if k > 0 {
  595. query += `|`
  596. }
  597. query += "," + v + ","
  598. }
  599. query += `).*"}}`
  600. }
  601. return query
  602. }
  603. func getLastNewsQuery(area, publishtime, subtype string) string {
  604. query := ``
  605. if area != "" {
  606. query += `"area":{"$in":[`
  607. for k, v := range strings.Split(area, ",") {
  608. if k > 0 {
  609. query += `,`
  610. }
  611. query += `"` + v + `"`
  612. }
  613. query += `]}`
  614. }
  615. if publishtime != "" {
  616. if len(query) > 0 {
  617. query += ","
  618. }
  619. starttime, endtime := "", ""
  620. now := time.Now()
  621. if publishtime == "lately-7" { //最近7天
  622. starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
  623. } else if publishtime == "lately-30" { //最近30天
  624. starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
  625. } else if publishtime == "thisyear" { //去年
  626. starttime = fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Unix())
  627. endtime = fmt.Sprint(time.Date(now.Year(), 1, 1, 0, 0, 0, 0, time.Local).Unix())
  628. } else {
  629. starttime = strings.Split(publishtime, "_")[0]
  630. endtime = strings.Split(publishtime, "_")[1]
  631. et, _ := strconv.ParseInt(endtime, 0, 64)
  632. etTime := time.Unix(et, 0)
  633. endtime = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Unix())
  634. }
  635. if starttime != "" && endtime != "" {
  636. query += `"$and":[{"publishtime":{"$gte":` + starttime + `}},{"publishtime":{"$lt":` + endtime + `}}]`
  637. } else if starttime != "" && endtime == "" {
  638. query += `"publishtime":{"$gte":` + starttime + `}`
  639. } else if starttime == "" && endtime != "" {
  640. query += `"publishtime":{"$lt":` + endtime + `}`
  641. }
  642. }
  643. if subtype != "" {
  644. if len(query) > 0 {
  645. query += ","
  646. }
  647. query += `"subtype":{"$in":[`
  648. for k, v := range strings.Split(subtype, ",") {
  649. if k > 0 {
  650. query += `,`
  651. }
  652. query += `"` + v + `"`
  653. }
  654. query += `]}`
  655. }
  656. query = `{` + query + `}`
  657. return query
  658. }
  659. //进入订阅页面
  660. func (m *Front) Wxrssset() error {
  661. myopenid, _ := m.Session().Get("s_m_openid").(string)
  662. if isInTSguide(myopenid) {
  663. return m.Redirect("/front/tenderSubscribe/guide")
  664. }
  665. m.T["openid"] = se.EncodeString(myopenid)
  666. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  667. mynickname, _ := m.Session().Get("s_nickname").(string)
  668. myavatar, _ := m.Session().Get("s_avatar").(string)
  669. m.T["nickname"] = mynickname
  670. m.T["avatar"] = myavatar
  671. return m.Render("/weixin/wxrssset.html", &m.T)
  672. }
  673. //进入订阅页面
  674. func (m *Front) Getpage() error {
  675. defer util.Catch()
  676. s_type := ""
  677. openid := m.Session().Get("s_m_openid")
  678. var msgset map[string]interface{}
  679. if openid != nil {
  680. one, _ := mongodb.FindOneByField("user", `{"s_m_openid":"`+openid.(string)+`"}`, `{"o_jy":1}`)
  681. msg := (*one)["o_jy"]
  682. if msg != "" && msg != nil {
  683. msgset = msg.(map[string]interface{})
  684. }
  685. s_type = "tender"
  686. }
  687. m.ServeJson(map[string]interface{}{
  688. "msgset": msgset,
  689. "s_type": s_type,
  690. })
  691. return nil
  692. }
  693. //微信搜索界面
  694. func (m *Front) Wxsearch() error {
  695. defer util.Catch()
  696. shname := m.GetSession("shname")
  697. toptype := m.GetSession("toptype")
  698. subtype := m.GetSession("subtype")
  699. scope := m.GetSession("scope")
  700. publishtime := m.GetSession("publishtime")
  701. industry := m.GetSession("industry")
  702. if shname != "" && shname != nil {
  703. m.T["shname"] = shname
  704. }
  705. m.T["toptype"] = toptype
  706. m.T["subtype"] = subtype
  707. m.T["scope"] = scope
  708. m.T["publishtime"] = publishtime
  709. m.T["industry"] = industry
  710. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  711. mynickname, _ := m.Session().Get("s_nickname").(string)
  712. myavatar, _ := m.Session().Get("s_avatar").(string)
  713. m.T["nickname"] = mynickname
  714. m.T["avatar"] = myavatar
  715. myopenid, _ := m.Session().Get("s_m_openid").(string)
  716. m.T["openid"] = se.EncodeString(myopenid)
  717. if userId := m.GetSession("userId"); userId != nil {
  718. one, _ := mongodb.FindOneByField("user", bson.M{"_id": bson.ObjectIdHex(userId.(string))}, `{"o_jy":1}`)
  719. history := redis.GetStr("other", "s_"+userId.(string))
  720. arrs := strings.Split(history, ",")
  721. if history == "" {
  722. arrs = make([]string, 0)
  723. }
  724. l := len(arrs) - 1
  725. for i := 0; i < len(arrs)/2; i++ {
  726. tmp := arrs[l-i]
  727. arrs[l-i] = arrs[i]
  728. arrs[i] = tmp
  729. }
  730. m.T["history"] = arrs
  731. if one != nil && len(*one) > 0 {
  732. o_jy, _ := (*one)["o_jy"].(map[string]interface{})
  733. a_key, _ := o_jy["a_key"].([]interface{})
  734. var keys []interface{}
  735. for _, v := range a_key {
  736. keyMap, _ := v.(map[string]interface{})
  737. key, _ := keyMap["key"].([]interface{})
  738. keys = append(keys, key)
  739. }
  740. m.T["msgset"] = keys
  741. }
  742. }
  743. return m.Render("/weixin/wxsearch.html", &m.T)
  744. }
  745. //剑鱼微信查询结果页面
  746. func (m *Front) Wxsearchlist() error {
  747. defer util.Catch()
  748. keywords := m.GetString("searchname")
  749. searchvalue := m.GetString("searchvalue")
  750. toptype := m.GetString("toptype")
  751. subtype := m.GetString("subtype")
  752. industry := m.GetString("industry")
  753. scope := m.GetString("scope")
  754. publishtime := m.GetString("publishtime")
  755. selectType := m.GetString("selectType")
  756. m.SetSession("shname", keywords)
  757. m.SetSession("toptype", toptype)
  758. m.SetSession("subtype", subtype)
  759. m.SetSession("industry", industry)
  760. m.SetSession("scope", scope)
  761. m.SetSession("publishtime", publishtime)
  762. var list *[]map[string]interface{}
  763. if userid := m.GetSession("userId"); userid != nil {
  764. if len(keywords) > 0 {
  765. if selectType == "" { //默认设置为全文搜索
  766. selectType = "all"
  767. }
  768. list = getWxsearchlistData(keywords, searchvalue, scope, publishtime, subtype, industry, 1, selectType)
  769. r := redis.GetStr("other", "s_"+userid.(string))
  770. arrs := strings.Split(r, ",")
  771. if r == "" {
  772. arrs = make([]string, 0)
  773. }
  774. var historyFlag = 0
  775. for _, v := range arrs {
  776. if v == strings.Trim(keywords, " ") {
  777. historyFlag = 1
  778. break
  779. }
  780. }
  781. if historyFlag != 1 {
  782. arrs = append(arrs, keywords)
  783. if len(arrs) > 5 {
  784. arrs = arrs[1:6]
  785. }
  786. redis.Del("other", "s_"+userid.(string))
  787. redis.Put("other", "s_"+userid.(string), strings.Join(arrs, ","), -1)
  788. }
  789. }
  790. }
  791. m.T["list"] = list
  792. m.T["pageSize"] = wx_pageSize
  793. m.T["keywords"] = keywords
  794. m.T["searchvalue"] = searchvalue
  795. m.T["toptype"] = toptype
  796. m.T["subtype"] = subtype
  797. m.T["scope"] = scope
  798. m.T["publishtime"] = publishtime
  799. //搜索列表增加分享
  800. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  801. myopenid, _ := m.Session().Get("s_m_openid").(string)
  802. m.T["openid"] = se.EncodeString(myopenid)
  803. mynickname, _ := m.Session().Get("s_nickname").(string)
  804. myavatar, _ := m.Session().Get("s_avatar").(string)
  805. m.T["nickname"] = mynickname
  806. m.T["avatar"] = myavatar
  807. return m.Render("/weixin/wxsearchlist.html", &m.T)
  808. }
  809. //搜索结果,ajax分页请求
  810. func (m *Front) WxsearchlistPaging() {
  811. defer util.Catch()
  812. userid := m.GetSession("userId")
  813. var list *[]map[string]interface{}
  814. pageNum, _ := m.GetInteger("pageNum")
  815. if userid != nil && pageNum <= wx_maxPageNum {
  816. keywords := strings.Trim(m.GetString("searchname"), " ")
  817. searchvalue := m.GetString("searchvalue")
  818. subtype := m.GetString("subtype")
  819. scope := m.GetString("scope")
  820. publishtime := m.GetString("publishtime")
  821. selectType := m.GetString("selectType")
  822. industry := m.GetString("industry")
  823. list = getWxsearchlistData(keywords, searchvalue, scope, publishtime, subtype, industry, pageNum, selectType)
  824. }
  825. m.ServeJson(map[string]interface{}{
  826. "list": list,
  827. "hasNextPage": list != nil && len(*list) == wx_pageSize && pageNum < wx_maxPageNum,
  828. })
  829. }
  830. //微信端删除历史搜索
  831. func (m *Front) DelWxHistorySearch() {
  832. defer util.Catch()
  833. //定义一个无用参数作为返回值
  834. var rt string = "rt"
  835. userId := m.GetSession("userId")
  836. history := redis.GetStr("other", "s_"+userId.(string))
  837. if len(history) > 0 || history != "" {
  838. redis.Del("other", "s_"+userId.(string))
  839. }
  840. m.ServeJson(map[string]interface{}{
  841. "rt": rt,
  842. })
  843. }
  844. //微信端搜索
  845. func getWxsearchlistData(keywords, searchvalue, scope, publishtime, subtype, industry string, pageNum int, selectType string) (list *[]map[string]interface{}) {
  846. query := getBidSearchQuery(scope, publishtime, subtype, industry) //scope是地区对应传进的areas, stype是类型对应scope
  847. if len(keywords) > 0 {
  848. if selectType == "all" { //全文搜索
  849. list = elastic.GetByNgramOther(INDEX, TYPE, searchvalue, query, `"title","detail"`, bidSearch_sort, bidSearch_field_1, (pageNum-1)*wx_pageSize, wx_pageSize, true, false, 100)
  850. } else { //标题搜索
  851. list = elastic.GetByNgram(INDEX, TYPE, searchvalue, query, `"title"` /*FINDF*/, bidSearch_sort, bidSearch_field_1, (pageNum-1)*wx_pageSize, wx_pageSize)
  852. }
  853. if list != nil {
  854. bidListConvert("", list)
  855. for _, v := range *list {
  856. v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
  857. }
  858. }
  859. }
  860. return list
  861. }
  862. //查看原文跳转
  863. func (m *Front) VisitRedirect() {
  864. fmt.Sprintln("^6^^^^^")
  865. defer util.Catch()
  866. sid := m.GetString("id")
  867. // regex, _ := regexp.Compile("(Android|Mobile)")
  868. // if len(regex.FindAllString(m.Header("User-Agent"), -1)) <= 0 {
  869. // m.Redirect("/article/p/" + sid + ".html")
  870. // }
  871. surl := m.GetString("url")
  872. sds := m.GetString("keywords")
  873. m.T["keywords"] = sds
  874. shareopenid := m.GetString("openid")
  875. if shareopenid != "" {
  876. m.T["shareopenid"] = shareopenid
  877. }
  878. myopenid, _ := m.Session().Get("s_m_openid").(string)
  879. if myopenid == "" {
  880. myopenid = shareopenid
  881. m.T["openid"] = myopenid //"-1"
  882. } else {
  883. m.T["openid"] = se.EncodeString(myopenid) //"-1"
  884. }
  885. mynickname, _ := m.Session().Get("s_nickname").(string)
  886. myavatar, _ := m.Session().Get("s_avatar").(string)
  887. m.T["nickname"] = mynickname
  888. m.T["avatar"] = myavatar
  889. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  890. userId, _ := m.GetSession("userId").(string)
  891. var obj map[string]interface{}
  892. obj = wxvisitD(sid, surl, userId)
  893. if len(obj) > 0 {
  894. //获取打赏文案
  895. m.T["rewardText"], m.T["advertText"] = getRewardText()
  896. m.T["obj"] = obj
  897. m.Render("/weixin/wxinfocontent.html", &m.T)
  898. return
  899. }
  900. if surl != "" {
  901. m.Redirect(surl)
  902. }
  903. }
  904. func wxvisitD(sid, surl, userId string) (objdata map[string]interface{}) {
  905. defer util.Catch()
  906. var obj map[string]interface{}
  907. if len(sid) > 5 {
  908. aobj, ok := mongodb.FindById("bidding", sid, nil)
  909. if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
  910. aobj, ok = mongodb.FindById("bidding_back", sid, nil)
  911. }
  912. obj = *aobj
  913. if ok && obj != nil && len(obj) >= 3 {
  914. obj["_id"] = util.EncodeArticleId2ByCheck(sid)
  915. obj["url"] = surl
  916. pt := obj["publishtime"]
  917. obj["l_publishtime"] = pt
  918. obj["publishtime"] = util.FormatDateWithObj(&pt, util.Date_Full_Layout)
  919. //查询是否关注
  920. obj["followFlag"] = false
  921. obj["hasSession"] = false
  922. var infoformat = obj["infoformat"]
  923. if infoformat != nil && infoformat != "" {
  924. obj["infoformat"] = util.IntAll(infoformat)
  925. }
  926. if userId != "" {
  927. pcode, _ := obj["projectcode"].(string)
  928. pname, _ := obj["projectname"].(string)
  929. titleTmp, _ := obj["title"].(string)
  930. obj["followFlag"], obj["followId"] = MFollow(userId, pname, pcode, titleTmp)
  931. obj["hasSession"] = true
  932. }
  933. if strings.Trim(util.ObjToString(obj["detail"]), " ") == "" {
  934. obj["detail"] = ""
  935. }
  936. }
  937. }
  938. return obj
  939. }
  940. func MFollow(userId string, pname string, pcode string, title string) (bool, string) {
  941. defer util.Catch()
  942. var followId string
  943. followFlag := false
  944. follows, ok := mongodb.Find("follow_project", `{"s_userid":"`+userId+`"}`, `{"_id":1,"s_projectname":1,"s_projectcode":1}`, nil, false, -1, -1)
  945. if ok && follows != nil && len(*follows) > 0 {
  946. for _, v := range *follows {
  947. pc, _ := v["s_projectcode"].(string)
  948. if pc != "" && pc == pcode {
  949. followFlag = true
  950. } else {
  951. pn, _ := v["s_projectname"].(string)
  952. if pn != "" && pn == pname {
  953. followFlag = true
  954. }
  955. }
  956. if followFlag {
  957. followId = util.EncodeArticleId2ByCheck(util.BsonIdToSId(v["_id"]))
  958. break
  959. }
  960. }
  961. }
  962. return followFlag, followId
  963. }
  964. //查看原文跳转
  965. //增加查询备份库数据、增加关键词、描述逻辑处理
  966. func (m *Front) PcVisitRedirect(sid string) {
  967. defer util.Catch()
  968. kds := m.GetString("kds")
  969. m.T["keywords"] = kds
  970. sid = strings.Split(sid, "_")[0]
  971. //sid = util.DecodeArticleId(sid)[0]
  972. var shareid = m.GetString("id")
  973. if len(shareid) == 0 {
  974. shareid = fmt.Sprintf("%s%d", config.Seoconfig["jysskzy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
  975. }
  976. m.T["logid"] = config.Seoconfig["jysskzy"].(string)
  977. m.T["shareid"] = se.EncodeString(shareid)
  978. if ret := redis.Get("other", "jypcdetail_"+sid+kds); ret != nil {
  979. m.SetBody([]byte(ret.(string)))
  980. return
  981. } else {
  982. m.DisableHttpCache()
  983. data := elastic.GetByIdField("bidding", "bidding", sid, `"href"`)
  984. if data == nil || len(*data) == 0 {
  985. m.Render("/_error.html")
  986. return
  987. }
  988. href, _ := (*data)["href"].(string)
  989. href = strings.Replace(href, "\n", "", -1)
  990. if href != "" && !strings.HasPrefix(href, "http") {
  991. href = "http://" + href
  992. }
  993. po, bo, wo, obj := pcVRT(sid)
  994. if obj != nil && len(obj) > 0 {
  995. if len(po) > 0 {
  996. m.T["projectOther"] = po
  997. }
  998. if len(bo) > 0 {
  999. m.T["buyerOther"] = bo
  1000. }
  1001. if len(wo) > 0 {
  1002. m.T["winnerOther"] = wo
  1003. }
  1004. obj["url"] = href
  1005. m.T["obj"] = obj
  1006. content, _ := m.Render4Cache("/pc/biddetail.html", &m.T)
  1007. redis.Put("other", "jypcdetail_"+sid+kds, string(content), 60*60*24)
  1008. m.SetBody(content)
  1009. return
  1010. }
  1011. if href != "" {
  1012. m.Redirect(href)
  1013. }
  1014. }
  1015. }
  1016. //pc三级页跳转
  1017. func pcVRT(sid string) (po, bo, wo []map[string]interface{}, objdata map[string]interface{}) {
  1018. defer util.Catch()
  1019. var projectOther, buyerOther, winnerOther []map[string]interface{}
  1020. if len(sid) > 5 {
  1021. coll := "bidding"
  1022. obj, ok := mongodb.FindById(coll, sid, nil)
  1023. if ok && (obj == nil || *obj == nil || len(*obj) == 0) {
  1024. coll = "bidding_back"
  1025. obj, ok = mongodb.FindById(coll, sid, nil)
  1026. }
  1027. if ok && obj != nil && len(*obj) > 0 {
  1028. //DealInfo(obj, coll)
  1029. (*obj)["_id"] = util.EncodeArticleId2ByCheck(sid)
  1030. var infoformat = (*obj)["infoformat"]
  1031. if infoformat != nil && infoformat != "" {
  1032. (*obj)["infoformat"] = util.IntAll(infoformat)
  1033. }
  1034. if strings.Trim(util.ObjToString((*obj)["detail"]), " ") == "" {
  1035. (*obj)["detail"] = ""
  1036. }
  1037. area := (*obj)["area"].(string)
  1038. finalType, _ := (*obj)["subtype"].(string)
  1039. if finalType == "" {
  1040. finalType = util.ObjToString((*obj)["toptype"])
  1041. }
  1042. if finalType == "" {
  1043. finalType = util.ObjToString((*obj)["type"])
  1044. if finalType == "bid" {
  1045. finalType = "中标"
  1046. } else if finalType == "tender" {
  1047. finalType = "招标"
  1048. } else {
  1049. finalType = ""
  1050. }
  1051. }
  1052. (*obj)["stypeadd"], (*obj)["areaadd"] = classify(finalType, area)
  1053. //增加处理信息逻辑
  1054. objdata = *obj
  1055. queryStr := ""
  1056. commonQuery := func(mustquery string) *[]map[string]interface{} {
  1057. return elastic.GetPage("bidding", "bidding", queryStr, bidSearch_sort, `"_id","title","publishtime","toptype","subtype","type","area","href"`, 0, 11)
  1058. }
  1059. //同一个项目的其他招标信息
  1060. projectName, _ := (*obj)["projectname"].(string)
  1061. projectCode, _ := (*obj)["projectcode"].(string)
  1062. if projectName != "" || projectCode != "" {
  1063. if projectName != "" && projectCode != "" {
  1064. queryStr = `{"$or":[{"TERM_projectname":"` + projectName + `"},{"TERM_projectcode":"` + projectCode + `"}]}`
  1065. } else if projectName != "" && projectCode == "" {
  1066. queryStr = `{"TERM_projectname":"` + projectName + `"}`
  1067. } else if projectName == "" && projectCode != "" {
  1068. queryStr = `{"TERM_projectcode":"` + projectCode + `"}`
  1069. }
  1070. projectOther = bidDataConvert(sid, commonQuery(queryStr))
  1071. }
  1072. //同一个业主最近的其他招标信息
  1073. buyer, _ := (*obj)["buyer"].(string) //采购单位
  1074. if buyer != "" {
  1075. queryStr = `{"TERM_buyer":"` + buyer + `"}`
  1076. buyerOther = bidDataConvert(sid, commonQuery(queryStr))
  1077. }
  1078. //同一中标人最近中标的其他信息
  1079. subtype, _ := (*obj)["subtype"].(string) //信息类型
  1080. winner, _ := (*obj)["winner"].(string) //中标人
  1081. if winner != "" && subtype == "中标" {
  1082. queryStr = `{"TERM_winner":"` + winner + `"}`
  1083. winnerOther = bidDataConvert(sid, commonQuery(queryStr))
  1084. }
  1085. }
  1086. }
  1087. return projectOther, buyerOther, winnerOther, objdata
  1088. }
  1089. //数据转换
  1090. func bidDataConvert(id string, datas *[]map[string]interface{}) (array []map[string]interface{}) {
  1091. if datas == nil || len(*datas) == 0 {
  1092. return array
  1093. }
  1094. index := 0
  1095. for _, v := range *datas {
  1096. if len(array) >= 10 {
  1097. break
  1098. }
  1099. _id, _ := v["_id"].(string)
  1100. if _id == id {
  1101. continue
  1102. }
  1103. v["_id"] = util.EncodeArticleId2ByCheck(_id)
  1104. area, _ := v["area"].(string)
  1105. if area == "A" {
  1106. v["area"] = ""
  1107. }
  1108. tp, _ := v["subtype"].(string)
  1109. if tp == "" {
  1110. tp, _ = v["toptype"].(string)
  1111. }
  1112. if tp == "" {
  1113. tp, _ = v["type"].(string)
  1114. if tp == "bid" {
  1115. tp = "中标"
  1116. } else if tp == "tender" {
  1117. tp = "招标"
  1118. } else {
  1119. tp = ""
  1120. }
  1121. }
  1122. v["stypeadd"], v["areaadd"] = classify(tp, area)
  1123. v["type"] = tp
  1124. diff := ""
  1125. publishtime, _ := v["publishtime"].(float64)
  1126. if publishtime != 0 {
  1127. diff = util.TimeDiff(time.Unix(util.Int64All(publishtime), 0))
  1128. v["pbtime"] = util.Int64All(publishtime)
  1129. }
  1130. v["publishtime"] = diff
  1131. index++
  1132. v["index"] = index
  1133. array = append(array, v)
  1134. }
  1135. return array
  1136. }
  1137. //剑鱼保存
  1138. func (m *Front) AjaxReq() error {
  1139. defer util.Catch()
  1140. reqType := m.GetString("reqType")
  1141. var flag = "n"
  1142. switch reqType {
  1143. case "feedback": //意见反馈
  1144. data := make(map[string]interface{})
  1145. userId, ok := m.GetSession("userId").(string)
  1146. if !ok || userId == "" {
  1147. break
  1148. }
  1149. userInfo, ok := mongodb.FindById("user", userId, nil)
  1150. if !ok {
  1151. break
  1152. }
  1153. data["i_type"] = 8
  1154. data["s_fromName"] = m.GetString("fromName")
  1155. value := m.GetString("value")
  1156. if len([]rune(value)) > 200 {
  1157. value = util.SubString(value, 0, 200)
  1158. }
  1159. data["s_remark"] = value
  1160. if (*userInfo)["s_name"] != nil {
  1161. data["s_submitname"] = (*userInfo)["s_name"].(string)
  1162. }
  1163. data["s_submitid"] = userId
  1164. data["s_title"] = m.GetString("title")
  1165. data["i_status"] = 0
  1166. if (*userInfo)["s_nickname"] != nil { //昵称
  1167. data["s_username"] = (*userInfo)["s_nickname"].(string)
  1168. } else if (*userInfo)["s_name"] != nil { //s_name
  1169. data["s_username"] = (*userInfo)["s_name"].(string)
  1170. }
  1171. data["l_submitdate"] = time.Now().Unix()
  1172. data["s_source"] = m.GetString("source")
  1173. data["s_fkid"] = m.GetString("fkid")
  1174. id := mongodb.Save("interaction", data)
  1175. if len(id) > 0 {
  1176. flag = "y"
  1177. }
  1178. break
  1179. case "subscribe": //直接订阅
  1180. if openid := m.GetSession("s_m_openid"); openid != nil {
  1181. r, _ := mongodb.FindOneByField("user", bson.M{"s_m_openid": openid.(string)}, `{"o_jy":1}`)
  1182. o_jy, _ := (*r)["o_jy"].(map[string]interface{})
  1183. a_key, _ := o_jy["a_key"].([]interface{})
  1184. keysArray := processKeyword(m.GetString("keys"))
  1185. if keysArray == nil {
  1186. break
  1187. }
  1188. var isExists bool
  1189. for _, v := range a_key {
  1190. count := 0
  1191. for _, kay := range keysArray {
  1192. keyMap, _ := v.(map[string]interface{})
  1193. key, _ := keyMap["key"].([]interface{})
  1194. for _, ky := range key {
  1195. if kay == ky {
  1196. count++
  1197. break
  1198. }
  1199. }
  1200. }
  1201. if count == len(keysArray) {
  1202. isExists = true
  1203. flag = "y"
  1204. break
  1205. }
  1206. }
  1207. //如果不存在
  1208. if !isExists {
  1209. if len(a_key) >= 10 {
  1210. flag = "o"
  1211. } else {
  1212. if mongodb.Update("user", bson.M{"s_m_openid": openid.(string)},
  1213. bson.M{
  1214. "$push": bson.M{"o_jy.a_key": bson.M{"key": keysArray}},
  1215. "$set": bson.M{"o_jy.l_modifydate": time.Now().Unix()},
  1216. }, false, false) {
  1217. flag = "y"
  1218. }
  1219. }
  1220. }
  1221. }
  1222. break
  1223. default:
  1224. if openid := m.GetSession("s_m_openid"); openid != nil {
  1225. keys := m.GetSlice("keys")
  1226. scopes := m.GetString("scope")
  1227. email := m.GetString("s_email")
  1228. mode, _ := m.GetInteger("mode")
  1229. set := make(map[string]interface{})
  1230. set["o_jy.a_key"] = keys
  1231. set["o_jy.s_scope"] = scopes
  1232. set["o_jy.s_email"] = email
  1233. if mode == 0 {
  1234. mode = 1
  1235. }
  1236. set["o_jy.i_mode"] = mode
  1237. set["o_jy.l_modifydate"] = time.Now().Unix()
  1238. if mongodb.Update("user", `{"s_m_openid":"`+openid.(string)+`"}`, &map[string]interface{}{"$set": set}, false, false) {
  1239. flag = "y"
  1240. }
  1241. }
  1242. break
  1243. }
  1244. m.ServeJson(map[string]interface{}{
  1245. "flag": flag,
  1246. })
  1247. return nil
  1248. }
  1249. const (
  1250. INDEX = "bidding"
  1251. TYPE = "bidding"
  1252. FINDF = `"title"`
  1253. )
  1254. //预览结果
  1255. func (m *Front) WxpushView() error {
  1256. defer util.Catch()
  1257. myopenid, _ := m.Session().Get("s_m_openid").(string)
  1258. if myopenid == "" {
  1259. return m.Redirect("/swordfish/share/-1")
  1260. }
  1261. a_key, list := getWxpushViewData(myopenid, 1)
  1262. m.T["firstPage"] = list
  1263. m.T["hasNextPage"] = list != nil && len(*list) == wx_pageSize
  1264. m.T["pageSize"] = wx_pageSize
  1265. m.T["a_key"] = a_key
  1266. mynickname, _ := m.Session().Get("s_nickname").(string)
  1267. myavatar, _ := m.Session().Get("s_avatar").(string)
  1268. m.T["nickname"] = mynickname
  1269. m.T["avatar"] = myavatar
  1270. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  1271. m.T["openid"] = se.EncodeString(myopenid)
  1272. return m.Render("/weixin/resultpreview.html", &m.T)
  1273. }
  1274. func (m *Front) WxpushViewPaging() {
  1275. defer util.Catch()
  1276. var list *[]map[string]interface{}
  1277. pageNum, _ := m.GetInteger("pageNum")
  1278. if myopenid := m.Session().Get("s_m_openid"); myopenid != nil && pageNum <= wx_maxPageNum {
  1279. _, list = getWxpushViewData(myopenid.(string), pageNum)
  1280. }
  1281. m.ServeJson(map[string]interface{}{
  1282. "list": list,
  1283. "hasNextPage": list != nil && len(*list) == wx_pageSize && pageNum < wx_maxPageNum,
  1284. })
  1285. }
  1286. func getWxpushViewData(myopenid string, pageNum int) (keys []interface{}, list *[]map[string]interface{}) {
  1287. if myopenid == "" {
  1288. return
  1289. }
  1290. tmp, ok := mongodb.FindOneByField("user", `{"s_m_openid":"`+myopenid+`"}`, `{"_id":1,"o_jy":1}`)
  1291. if !ok || tmp == nil || len(*tmp) == 0 {
  1292. return
  1293. }
  1294. o_jy := (*tmp)["o_jy"].(map[string]interface{})
  1295. a_key, _ := o_jy["a_key"].([]interface{})
  1296. if len(a_key) == 0 {
  1297. return
  1298. }
  1299. for _, v := range a_key {
  1300. keyMap, _ := v.(map[string]interface{})
  1301. key, _ := keyMap["key"].([]interface{})
  1302. keys = append(keys, key)
  1303. }
  1304. field := `"_id","title","publishtime","toptype","subtype","type","area","href","areaval"`
  1305. var allkeys []elastic.KeyConfig //用户配置
  1306. _bs, err := json.Marshal(a_key)
  1307. if err == nil {
  1308. json.Unmarshal(_bs, &allkeys)
  1309. }
  1310. list = elastic.GetResForJY(INDEX, TYPE, allkeys, "", `"title"`, `{"publishtime":"desc"}`, field, (pageNum-1)*wx_pageSize, wx_pageSize)
  1311. if list != nil {
  1312. for _, v := range *list {
  1313. v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
  1314. }
  1315. }
  1316. return
  1317. }
  1318. func (m *Front) Guide(sign string) error {
  1319. defer util.Catch()
  1320. if m.Session().Get("s_m_openid") == nil {
  1321. return m.Redirect("/swordfish/share/-1")
  1322. }
  1323. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  1324. mynickname, _ := m.Session().Get("s_nickname").(string)
  1325. myavatar, _ := m.Session().Get("s_avatar").(string)
  1326. m.T["nickname"] = mynickname
  1327. m.T["avatar"] = myavatar
  1328. myopenid, _ := m.Session().Get("s_m_openid").(string)
  1329. m.T["openid"] = se.EncodeString(myopenid)
  1330. m.T["sign"] = sign
  1331. if sign == "other" {
  1332. userInfo, ok := mongodb.FindById("user", m.GetSession("userId").(string), `{"o_jy_msgset":1}`)
  1333. if ok {
  1334. m.T["msgset"] = (*userInfo)["o_jy_msgset"]
  1335. }
  1336. }
  1337. if sign == "share" {
  1338. return m.Render("/weixin/wxshareguide.html", &m.T)
  1339. } else {
  1340. return m.Render("/weixin/wxindex.html", &m.T)
  1341. }
  1342. }
  1343. func (m *Front) Share(openids string) error {
  1344. defer util.Catch()
  1345. var openid = ""
  1346. var jy_code = ""
  1347. if openids != "-1" {
  1348. wxid_code := strings.Split(openids, "__")
  1349. if len(wxid_code) > 0 {
  1350. openid = wxid_code[0]
  1351. jy_code = wxid_code[1]
  1352. }
  1353. }
  1354. m.T["openid"] = openid
  1355. m.T["jy_code"] = jy_code
  1356. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  1357. mynickname, _ := m.Session().Get("s_nickname").(string)
  1358. myavatar, _ := m.Session().Get("s_avatar").(string)
  1359. m.T["nickname"] = mynickname
  1360. m.T["avatar"] = myavatar
  1361. return m.Render("/weixin/wxshare.html", &m.T)
  1362. }
  1363. func (m *Front) WxpushAjaxReq() error {
  1364. defer util.Catch()
  1365. index, _ := m.GetInteger("index")
  1366. mongodb.Update("wxpush", `{"_id":"`+m.GetString("_id")+`"}`, map[string]interface{}{
  1367. "$addToSet": map[string]interface{}{"a_visitedindex": index},
  1368. }, false, false)
  1369. return nil
  1370. }
  1371. //
  1372. func (m *Front) About() error {
  1373. defer util.Catch()
  1374. myopenid, _ := m.Session().Get("s_m_openid").(string)
  1375. mynickname, _ := m.Session().Get("s_nickname").(string)
  1376. myavatar, _ := m.Session().Get("s_avatar").(string)
  1377. m.T["nickname"] = mynickname
  1378. m.T["avatar"] = myavatar
  1379. if myopenid != "" {
  1380. m.T["A"] = "A"
  1381. }
  1382. m.T["openid"] = se.EncodeString(myopenid)
  1383. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  1384. m.Render("/weixin/about.html")
  1385. return nil
  1386. }
  1387. //
  1388. func (m *Front) Shareabout(openids string) error {
  1389. defer util.Catch()
  1390. var openid = ""
  1391. if openids != "-1" {
  1392. wxid_code := strings.Split(openids, "__")
  1393. if len(wxid_code) > 0 {
  1394. openid = wxid_code[0]
  1395. }
  1396. }
  1397. myopenid, _ := m.Session().Get("s_m_openid").(string)
  1398. mynickname, _ := m.Session().Get("s_nickname").(string)
  1399. myavatar, _ := m.Session().Get("s_avatar").(string)
  1400. if openid == "" {
  1401. m.T["openid"] = se.EncodeString(myopenid)
  1402. } else {
  1403. m.T["A"] = "A"
  1404. m.T["openid"] = openid
  1405. }
  1406. m.T["nickname"] = mynickname
  1407. m.T["avatar"] = myavatar
  1408. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  1409. m.Render("/weixin/about.html")
  1410. return nil
  1411. }
  1412. //
  1413. func (m *Front) Aboutsearch() error {
  1414. myopenid, _ := m.Session().Get("s_m_openid").(string)
  1415. m.T["openid"] = se.EncodeString(myopenid)
  1416. mynickname, _ := m.Session().Get("s_nickname").(string)
  1417. myavatar, _ := m.Session().Get("s_avatar").(string)
  1418. m.T["nickname"] = mynickname
  1419. m.T["avatar"] = myavatar
  1420. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  1421. m.Render("/weixin/aboutsearch.html", &m.T)
  1422. return nil
  1423. }
  1424. //剑鱼微信查询保存网站
  1425. func (m *Front) AboutSR() error {
  1426. defer util.Catch()
  1427. var flag = "N"
  1428. var sn = m.GetString("searchname")
  1429. var tp = m.GetString("tp")
  1430. if len(sn) > 0 {
  1431. switch tp {
  1432. case "S": //用户查询网站是否被收录
  1433. userId, ok := m.GetSession("userId").(string)
  1434. if !ok || userId == "" {
  1435. break
  1436. }
  1437. res, err := mongodb.FindOne("bidurlinfo", bson.M{"$or": []bson.M{bson.M{"s_name": sn}, bson.M{"s_url": sn}}})
  1438. if err {
  1439. if len(*res) > 0 {
  1440. flag = "T"
  1441. }
  1442. }
  1443. break
  1444. case "I": //用户提交数据
  1445. data := make(map[string]interface{})
  1446. userId, ok := m.GetSession("userId").(string)
  1447. if !ok || userId == "" {
  1448. break
  1449. }
  1450. userInfo, ok := mongodb.FindById("user", userId, nil)
  1451. if !ok {
  1452. break
  1453. }
  1454. data["i_type"] = 8
  1455. data["s_remark"] = sn
  1456. if (*userInfo)["s_name"] != nil {
  1457. data["s_submitname"] = (*userInfo)["s_name"].(string)
  1458. }
  1459. data["s_submitid"] = userId
  1460. data["s_title"] = m.GetString("title")
  1461. data["i_status"] = 0
  1462. if (*userInfo)["s_nickname"] != nil { //昵称
  1463. data["s_username"] = (*userInfo)["s_nickname"].(string)
  1464. } else if (*userInfo)["s_name"] != nil { //s_name
  1465. data["s_username"] = (*userInfo)["s_name"].(string)
  1466. }
  1467. data["l_submitdate"] = time.Now().Unix()
  1468. data["s_source"] = m.GetString("source")
  1469. id := mongodb.Save("interaction", data)
  1470. if len(id) > 0 && len(sn) > 0 {
  1471. flag = "T"
  1472. }
  1473. break
  1474. }
  1475. }
  1476. m.ServeJson(map[string]interface{}{
  1477. "flag": flag,
  1478. })
  1479. return nil
  1480. }
  1481. //手动删除30天无更新数据
  1482. func (m *Front) DelOL() error {
  1483. defer util.Catch()
  1484. var ids []bson.ObjectId
  1485. var flag = "F"
  1486. var arrid = strings.Split(m.GetString("arrid"), ",")
  1487. if len(arrid) > 0 {
  1488. for _, chid := range arrid {
  1489. ids = append(ids, bson.ObjectIdHex(util.DecodeArticleId2ByCheck(chid)[0]))
  1490. }
  1491. }
  1492. userId, ok := m.GetSession("userId").(string)
  1493. if !ok || userId == "" || len(ids) < 1 {
  1494. m.ServeJson(map[string]interface{}{
  1495. "flag": flag,
  1496. })
  1497. return nil
  1498. }
  1499. if datas, ok := mongodb.Find("follow_project", bson.M{"_id": bson.M{"$in": ids}, "s_userid": userId}, nil, nil, false, -1, -1); ok && datas != nil {
  1500. for _, v := range *datas {
  1501. delete(v, "_id")
  1502. v["i_status"] = 2
  1503. mongodb.Save("follow_project_back", v)
  1504. go delRelRedis(v["s_openid"], v["a_relationinfo"])
  1505. }
  1506. }
  1507. if mongodb.Del("follow_project", bson.M{"_id": bson.M{"$in": ids}, "s_userid": userId}) {
  1508. flag = "T"
  1509. }
  1510. m.ServeJson(map[string]interface{}{
  1511. "flag": flag,
  1512. })
  1513. return nil
  1514. }
  1515. //获取我的反馈列表
  1516. func (f *Front) MyFeedbacks() error {
  1517. userId, _ := f.GetSession("userId").(string)
  1518. if userId == "" {
  1519. return f.Render("/_error.html")
  1520. }
  1521. list, ok := mongodb.Find("interaction", bson.M{"s_submitid": userId}, `{"l_submitdate":-1}`, `{"s_remark":1,"l_submitdate":1,"s_opinion":1,"i_status":1}`, false, 0, 200)
  1522. if !ok {
  1523. return nil
  1524. }
  1525. if f.Method() == "GET" {
  1526. f.T["list"] = list
  1527. f.T["flag"] = true
  1528. return f.Render("/weixin/feedback.html")
  1529. }
  1530. f.ServeJson(map[string]interface{}{
  1531. "list": list,
  1532. })
  1533. return nil
  1534. }
  1535. func (f *Front) GetRecomKWs() {
  1536. recomKWChan <- true
  1537. defer func() {
  1538. <-recomKWChan
  1539. }()
  1540. value := f.GetString("value")
  1541. count, _ := f.GetInteger("count")
  1542. ves := strings.Split(value, " ")
  1543. var pairs []map[string]interface{}
  1544. for _, v := range ves {
  1545. Pw, _ := M.MostSimilar(strings.Split(v, "+"), []string{}, count)
  1546. for _, p := range Pw {
  1547. sim := p.Sim
  1548. word := p.Word
  1549. if sim < float32(config.Sysconfig["recommendThreshold"].(float64)) {
  1550. continue
  1551. }
  1552. if strings.HasSuffix(word, "路") || tools.DealString(word) {
  1553. continue
  1554. }
  1555. pairs = append(pairs, map[string]interface{}{
  1556. "sim": sim,
  1557. "word": word,
  1558. })
  1559. }
  1560. }
  1561. f.ServeJson(pairs)
  1562. }
  1563. //记录用户行为--推荐关键词
  1564. func (f *Front) BehaviorRecord() {
  1565. flag := saveBehaviorRecord(f.Action,
  1566. bson.M{
  1567. "s_word": f.GetString("value"),
  1568. "s_type": f.GetString("type"),
  1569. "s_source": f.GetString("source"),
  1570. })
  1571. f.ServeJson(bson.M{"flag": flag})
  1572. }
  1573. //记录用户行为
  1574. func saveBehaviorRecord(action *xweb.Action, data bson.M) bool {
  1575. openId, _ := action.GetSession("s_m_openid").(string)
  1576. //if openId == "" {
  1577. // return false
  1578. //}
  1579. nickName, _ := action.GetSession("s_nickname").(string)
  1580. data["s_openid"] = openId
  1581. data["s_nickname"] = nickName
  1582. data["l_createtime"] = time.Now().Unix()
  1583. return len(mongodb.Save("behavior", data)) > 0
  1584. }
  1585. //取得剑鱼博客的信息列表
  1586. func (f *Front) Jyblog(param /*参数*/ string) error {
  1587. querymap := map[string]string{}
  1588. if len(param) == 0 {
  1589. querymap = map[string]string{
  1590. "perPage": f.GetString("perPage"),
  1591. "currentPage": f.GetString("currentPage"),
  1592. "contentType": "jybk",
  1593. "query": f.GetString("query"),
  1594. }
  1595. } else {
  1596. //反转生成map
  1597. paramstr := param[1:]
  1598. bs, _ := base64.StdEncoding.DecodeString(paramstr)
  1599. json.Unmarshal(bs, &querymap)
  1600. }
  1601. var shareid = f.GetString("id")
  1602. if len(shareid) == 0 {
  1603. shareid = fmt.Sprintf("%s%d", config.Seoconfig["jybky"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
  1604. }
  1605. f.T["logid"] = config.Seoconfig["jybky"].(string)
  1606. f.DisableHttpCache()
  1607. shareid = se.EncodeString(shareid)
  1608. data, pagination := searhWebContentblog(querymap)
  1609. f.Render("/pc/jyblog.html", &xweb.T{"querymap": querymap, "data": data, "pagination": pagination, "shareid": shareid})
  1610. return nil
  1611. }
  1612. //实际的查询剑鱼博客
  1613. func searhWebContentblog(querymap map[string]string) (*[]map[string]interface{}, *[]interface{}) {
  1614. perPage, _ := strconv.Atoi(querymap["perPage"])
  1615. currentPage, _ := strconv.Atoi(querymap["currentPage"])
  1616. //修复
  1617. if perPage == 0 {
  1618. perPage = 5
  1619. }
  1620. if currentPage < 1 {
  1621. currentPage = 1
  1622. }
  1623. contentType := querymap["contentType"]
  1624. queryStr := querymap["query"]
  1625. str := ``
  1626. if queryStr != "" {
  1627. str = `{
  1628. "match": {
  1629. "s_title": {
  1630. "query":"` + queryStr + `",
  1631. "operator": "and"
  1632. }
  1633. }
  1634. },{
  1635. "match": {
  1636. "s_content": {
  1637. "query":"` + queryStr + `"
  1638. }
  1639. }
  1640. }`
  1641. }
  1642. var tempQuery = `{"query": {
  1643. "bool": {
  1644. "must":[{"term":{"s_contenttype":"` + contentType + `"}}],
  1645. "should": [` + str + `],
  1646. "minimum_should_match": 1
  1647. }
  1648. }}`
  1649. var query = tempQuery[:len(tempQuery)-1] +
  1650. `,"highlight":{
  1651. "pre_tags":["<span class='highlight'>"],
  1652. "post_tags":["</span>"],
  1653. "fields":{
  1654. "s_title":{"force_source": true}
  1655. ,"s_content":{"force_source": true}
  1656. }
  1657. },"_source":["s_title","s_date","s_contenttype","s_content","releasetime","s_description","praise","s_source","s_pic","s_pic1","l_createdate","s_code","_id","s_author"]
  1658. ,"from":` + fmt.Sprintf("%v", ((currentPage-1)*perPage)) + `,
  1659. "size":` + fmt.Sprintf("%v", perPage) +
  1660. `,"sort":[{"releasetime":{"order":"desc"}}] }`
  1661. total := elastic.Count("content", "content", tempQuery)
  1662. //查询列表数据
  1663. client := elastic.GetEsConn()
  1664. defer elastic.DestoryEsConn(client)
  1665. if client == nil {
  1666. return nil, nil
  1667. }
  1668. searchResult, err := client.Search().Index("content").Type("content").Source(query).Do()
  1669. if err != nil {
  1670. return nil, nil
  1671. }
  1672. var res []map[string]interface{}
  1673. if searchResult.Hits != nil {
  1674. resNum := len(searchResult.Hits.Hits)
  1675. res = make([]map[string]interface{}, resNum)
  1676. for i, hit := range searchResult.Hits.Hits {
  1677. json.Unmarshal(*hit.Source, &res[i])
  1678. //查询结果数据加工处理
  1679. for k, v := range hit.Highlight {
  1680. res[i][k] = v[0]
  1681. }
  1682. s_content, _ := res[i]["s_content"].(string)
  1683. if len(s_content) > 500 {
  1684. res[i]["s_content"] = ""
  1685. } else {
  1686. con, _ := regexp.Compile("^[^<]*?>")
  1687. content := con.ReplaceAllString(s_content, "")
  1688. con1, _ := regexp.Compile("<[^>]*$")
  1689. res[i]["s_content"] = template.HTML(con1.ReplaceAllString(content, ""))
  1690. }
  1691. s_title, _ := res[i]["s_title"].(string)
  1692. res[i]["s_title"] = template.HTML(s_title)
  1693. tmpdate, _ := res[i]["l_createdate"]
  1694. res[i]["l_createdate"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate.(float64)), 0))
  1695. tmpdate1, _ := res[i]["releasetime"]
  1696. res[i]["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1.(float64)), 0))
  1697. res[i]["_id"] = se.EncodeString(res[i]["_id"].(string))
  1698. res[i]["s_pic"] = config.Seoconfig["jyadd"].(string) + res[i]["s_pic"].(string)
  1699. res[i]["s_pic1"] = config.Seoconfig["jyadd"].(string) + res[i]["s_pic1"].(string)
  1700. }
  1701. }
  1702. //生成分页
  1703. pagination := MakePagination(perPage, currentPage, int(total), querymap, "/jyblog/index_%s.html")
  1704. return &res, &pagination
  1705. }
  1706. //计算分页,分页显示规则
  1707. func MakePagination(perPage, currentPage, total int, param map[string]string, urltpl string) []interface{} {
  1708. var totalPages int //总页数
  1709. if total == 0 {
  1710. totalPages = 1
  1711. } else {
  1712. totalPages = (total - 1 + perPage) / perPage //总页数
  1713. }
  1714. ret := make([]interface{}, 3)
  1715. index := 0
  1716. prePage, nextPage := currentPage-1, currentPage+1
  1717. if prePage < 1 {
  1718. prePage = 1
  1719. }
  1720. if nextPage > totalPages {
  1721. nextPage = totalPages
  1722. }
  1723. param["currentPage"] = strconv.Itoa(prePage)
  1724. bs, _ := json.Marshal(param)
  1725. paramstr := base64.StdEncoding.EncodeToString(bs)
  1726. url := fmt.Sprintf(urltpl, paramstr)
  1727. iscurrent := currentPage == 1
  1728. ret[index] = map[string]interface{}{"page": "< 上一页", "url": url, "iscurrent": iscurrent}
  1729. index = index + 1
  1730. param["currentPage"] = strconv.Itoa(currentPage)
  1731. bs, _ = json.Marshal(param)
  1732. paramstr = base64.StdEncoding.EncodeToString(bs)
  1733. url = fmt.Sprintf(urltpl, paramstr)
  1734. iscurrent = currentPage == currentPage
  1735. ret[index] = map[string]interface{}{"page": currentPage, "url": url, "iscurrent": iscurrent}
  1736. index = index + 1
  1737. param["currentPage"] = strconv.Itoa(nextPage)
  1738. bs, _ = json.Marshal(param)
  1739. paramstr = base64.StdEncoding.EncodeToString(bs)
  1740. url = fmt.Sprintf(urltpl, paramstr)
  1741. iscurrent = currentPage == totalPages
  1742. ret[index] = map[string]interface{}{"page": "下一页 >", "url": url, "iscurrent": iscurrent}
  1743. return ret
  1744. }
  1745. //博客三级页
  1746. func (f *Front) Jybdetail(_id string) error {
  1747. var shareid = f.GetString("id")
  1748. if len(shareid) == 0 {
  1749. shareid = fmt.Sprintf("%s%d", config.Seoconfig["jybky"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
  1750. }
  1751. f.T["logid"] = config.Seoconfig["jybky"].(string)
  1752. shareid = se.EncodeString(shareid)
  1753. if ret := redis.Get("other", "jyblog_"+_id); ret != nil {
  1754. var retlist *map[string]interface{}
  1755. b, _ := json.Marshal(ret)
  1756. json.Unmarshal(b, &retlist)
  1757. (*retlist)["s_content"] = template.HTML((*retlist)["s_content"].(string))
  1758. (*retlist)["_id"] = (*retlist)["_id"].(string)
  1759. f.T["data"] = retlist
  1760. } else {
  1761. id := se.DecodeString(_id)
  1762. r := elastic.GetByIdField("content", "content", id, `"_id","s_title","l_createdate","s_pic","s_author","s_editorname","s_contenttype","praise","releasetime","s_subcontent","s_url","s_content","s_source","s_keywords","s_description","s_contenttype"`)
  1763. if r != nil {
  1764. tmpdate1, _ := (*r)["l_createdate"]
  1765. (*r)["l_createdate"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1.(float64)), 0))
  1766. tmpdate2, _ := (*r)["releasetime"]
  1767. (*r)["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate2.(float64)), 0))
  1768. (*r)["s_content"] = template.HTML((*r)["s_content"].(string))
  1769. (*r)["_id"] = se.EncodeString((*r)["_id"].(string))
  1770. (*r)["s_pic"] = (*r)["s_pic"].(string)
  1771. }
  1772. f.DisableHttpCache()
  1773. redis.Put("other", "jyblog_"+_id, r, 2*60*60)
  1774. f.T["data"] = r
  1775. }
  1776. f.T["shareid"] = shareid
  1777. return f.Render("/pc/jyblogdetail.html", &f.T)
  1778. }
  1779. //
  1780. func (f *Front) Blogpraise() error {
  1781. defer util.Catch()
  1782. id := se.DecodeString(f.GetString("id"))
  1783. stype := f.GetString("type")
  1784. flag := "F"
  1785. var blogflag = true
  1786. util.Try(func() {
  1787. if id != "" {
  1788. if stype == "up" {
  1789. blogflag = mongodb.Update("content", `{"_id":"`+id+`"}`, `{ "$inc" : { "praise" : 1 }}`, false, false)
  1790. } else if stype == "down" {
  1791. blogflag = mongodb.Update("content", `{"_id":"`+id+`"}`, `{ "$inc" : { "praise" : -1 }}`, false, false)
  1792. }
  1793. if blogflag {
  1794. flag = "T"
  1795. r, _ := mongodb.FindById("content", id, "")
  1796. elastic.UpdateNewDoc("content", "content", r)
  1797. redis.Del("other", "jyblog_"+f.GetString("id"))
  1798. }
  1799. }
  1800. }, func(e interface{}) {
  1801. log.Println("文章点赞出错", e)
  1802. })
  1803. f.ServeJson(map[string]interface{}{
  1804. "flag": flag,
  1805. })
  1806. return nil
  1807. }
  1808. //
  1809. func getRewardText() (string, string) {
  1810. rewardText, _ := config.Sysconfig["rewardText"].([]interface{})
  1811. advertText, _ := config.Sysconfig["advertText"].([]interface{})
  1812. randVal := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(rewardText))
  1813. if len(advertText) != 0 {
  1814. advVal := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(advertText))
  1815. return util.ObjToString(rewardText[randVal]), util.ObjToString(advertText[advVal])
  1816. } else {
  1817. return util.ObjToString(rewardText[randVal]), ""
  1818. }
  1819. }
  1820. //
  1821. func searchresulthtml(list *[]map[string]interface{}) string {
  1822. var listhtml = ""
  1823. var j = 1
  1824. for i := 0; i < len(*list); i++ {
  1825. listdata := (*list)[i]
  1826. j = i + 1
  1827. listhtml += `<li><div>` + strconv.Itoa(j) + `.</div>`
  1828. if listdata["title"] != "" {
  1829. listhtml += `<div><a onclick="noIn(this)" dataId="` + util.EncodeArticleId2ByCheck(util.ObjToString(listdata["_id"])) + `" target="_blank">` + util.ObjToString(listdata["title"]) + `</a></div><div>`
  1830. }
  1831. area, _ := listdata["area"].(string)
  1832. area = strings.TrimSpace(area)
  1833. finalType, _ := listdata["subtype"].(string)
  1834. if finalType == "" {
  1835. finalType = util.ObjToString(listdata["toptype"])
  1836. }
  1837. if finalType == "" {
  1838. finalType = util.ObjToString(listdata["type"])
  1839. if finalType == "bid" {
  1840. finalType = "中标"
  1841. } else if finalType == "tender" {
  1842. finalType = "招标"
  1843. } else {
  1844. finalType = ""
  1845. }
  1846. }
  1847. stpadd, areaadd := classify(finalType, area)
  1848. if area != "" && area != "A" {
  1849. listhtml += `<span class="com-area"><a href="/list/area/` + areaadd + `.html">` + area + `</a></span>`
  1850. }
  1851. if finalType != "" {
  1852. listhtml += `<span class="com-type"><a href="/list/stype/` + stpadd + `.html">` + finalType + `</a></span>`
  1853. }
  1854. publishtime, _ := listdata["publishtime"].(float64)
  1855. if publishtime != 0 {
  1856. diff := util.TimeDiff(time.Unix(util.Int64All(publishtime), 0))
  1857. if diff != "" {
  1858. listhtml += `<span class="com-time"><i class="glyphicon bofangjilu"></i>` + diff + `</span>`
  1859. }
  1860. }
  1861. listhtml += `</div></li>`
  1862. }
  1863. return listhtml
  1864. }
  1865. //标签查询
  1866. func (f *Front) SearchResult(at, name string) error {
  1867. defer util.Catch()
  1868. var no = 5
  1869. var area = ""
  1870. var stype = ""
  1871. var startPage, currentPage, limitcount int
  1872. limitcount = util.IntAll(config.Seoconfig["limitcount"])
  1873. var res = ""
  1874. var seotitle = ""
  1875. var seokeywords = ""
  1876. var seodescription = ""
  1877. var shareid = f.GetString("id")
  1878. if len(shareid) == 0 {
  1879. shareid = fmt.Sprintf("%s%d", config.Seoconfig["jybqy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
  1880. }
  1881. f.T["logid"] = config.Seoconfig["jybqy"].(string)
  1882. if at == "area" {
  1883. areamp, _ := config.Seoconfig["area"].(map[string]interface{})
  1884. if areamp != nil {
  1885. areamp1 := areamp[name].(map[string]interface{})
  1886. if areamp1 != nil {
  1887. area = areamp1["NAME"].(string)
  1888. seotitle = areamp1["TITLE"].(string)
  1889. seokeywords = areamp1["KEYWORDS"].(string)
  1890. seodescription = areamp1["DESCRIPTION"].(string)
  1891. }
  1892. }
  1893. } else if at == "stype" {
  1894. stypemp, _ := config.Seoconfig["stype"].(map[string]interface{})
  1895. if stypemp != nil {
  1896. stypemp1 := stypemp[name].(map[string]interface{})
  1897. if stypemp1 != nil {
  1898. stype = stypemp1["NAME"].(string)
  1899. seotitle = stypemp1["TITLE"].(string)
  1900. seokeywords = stypemp1["KEYWORDS"].(string)
  1901. seodescription = stypemp1["DESCRIPTION"].(string)
  1902. }
  1903. }
  1904. }
  1905. f.T["seoarea"] = area
  1906. f.T["seostype"] = stype
  1907. f.T["seotitle"] = seotitle
  1908. f.T["seokeywords"] = seokeywords
  1909. f.T["seodption"] = seodescription
  1910. if area == "全国" {
  1911. return f.Redirect("/swordfish/searchinfolist.html")
  1912. }
  1913. if area != "" || stype != "" {
  1914. list := redis.Get("other", "classify_"+name)
  1915. query1 := `{"query": {"bool": {"must":[`
  1916. if area != "" {
  1917. query1 += `{"term":{"area":"` + area + `"}}`
  1918. } else if stype != "" {
  1919. query1 += `{"term":{"subtype":"` + stype + `"}}`
  1920. }
  1921. query1 += `],"should": [],"minimum_should_match": 1}}}`
  1922. query := getLastNewsQuery(area, "", stype)
  1923. var datas *[]map[string]interface{}
  1924. if list == nil {
  1925. count := elastic.Count(INDEX, TYPE, query1)
  1926. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  1927. currentPage = no
  1928. startPage = r.Intn(currentPage * limitcount)
  1929. count1 := util.IntAll(count)
  1930. if count1 < startPage || startPage < 0 {
  1931. startPage = 0
  1932. }
  1933. datas = elastic.GetPage(INDEX, TYPE, query, bidSearch_sort, `"_id","title","publishtime","toptype","subtype","type","area","href"`, startPage, limitcount)
  1934. redis.Put("other", "classify_"+name, datas, 2*60*60)
  1935. } else {
  1936. b, _ := json.Marshal(list)
  1937. json.Unmarshal(b, &datas)
  1938. }
  1939. res = searchresulthtml(datas)
  1940. f.T["res"] = res
  1941. f.T["area"] = area
  1942. f.T["stype"] = stype
  1943. f.SetSession("paramarea", area)
  1944. f.SetSession("paraminfotype", stype)
  1945. f.T["shareid"] = se.EncodeString(shareid)
  1946. }
  1947. return f.Render("/pc/classifylist.html", &f.T)
  1948. }
  1949. //
  1950. func classify(stp, area string) (string, string) {
  1951. var areas, _ = config.Seoconfig["area"].(map[string]interface{})
  1952. var stypes, _ = config.Seoconfig["stype"].(map[string]interface{})
  1953. var tpadd = ""
  1954. var areaadd = ""
  1955. if area != "" && area != "A" {
  1956. for k, v := range areas {
  1957. if area == v.(map[string]interface{})["NAME"] {
  1958. areaadd = k
  1959. }
  1960. }
  1961. }
  1962. if stp != "" {
  1963. for k, v := range stypes {
  1964. if stp == v.(map[string]interface{})["NAME"] {
  1965. tpadd = k
  1966. }
  1967. }
  1968. }
  1969. return tpadd, areaadd
  1970. }
  1971. //历史推送
  1972. func (f *Front) Historypush() error {
  1973. userId, _ := f.GetSession("userId").(string)
  1974. if userId == "" {
  1975. return f.Redirect("/swordfish/share/-1")
  1976. }
  1977. myopenid, _ := f.GetSession("s_m_openid").(string)
  1978. mynickname, _ := f.Session().Get("s_nickname").(string)
  1979. myavatar, _ := f.Session().Get("s_avatar").(string)
  1980. var thistime int64
  1981. var list *[]map[string]interface{}
  1982. var success bool
  1983. if userId != "" {
  1984. lasttime := time.Now().Local().Unix()
  1985. thistime, list = getHistorypush(lasttime, userId, nil, 0)
  1986. if list != nil && len(*list) > 0 {
  1987. success = true
  1988. }
  1989. }
  1990. f.T["data"] = list
  1991. f.T["thistime"] = thistime
  1992. f.T["success"] = success
  1993. f.T["nickname"] = mynickname
  1994. f.T["avatar"] = myavatar
  1995. f.T["signature"] = wx.SignJSSDK(f.Site() + f.Url())
  1996. f.T["openid"] = se.EncodeString(myopenid)
  1997. return f.Render("/weixin/historypush.html")
  1998. }
  1999. func (f *Front) HistorypushPaging() error {
  2000. lasttime, _ := f.GetInt("lasttime")
  2001. userId, _ := f.GetSession("userId").(string)
  2002. res := map[string]interface{}{}
  2003. res["success"] = false
  2004. if userId != "" && lasttime > 0 {
  2005. if lasttime == 1 {
  2006. lasttime = time.Now().Local().Unix()
  2007. }
  2008. thistime, list := getHistorypush(lasttime, userId, nil, 0)
  2009. if list != nil && len(*list) > 0 {
  2010. res["success"] = true
  2011. res["data"] = &list
  2012. res["thistime"] = thistime
  2013. }
  2014. }
  2015. f.ServeJson(&res)
  2016. return nil
  2017. }
  2018. func getHistorypush(lasttime int64, sid string, res []map[string]interface{}, count int) (thistime int64, list *[]map[string]interface{}) {
  2019. thistime = lasttime
  2020. if res == nil {
  2021. res = make([]map[string]interface{}, 0)
  2022. }
  2023. list = &res
  2024. tmps, ok := mongodb.Find("wxpush", &map[string]interface{}{
  2025. "s_uid": sid,
  2026. "l_date": map[string]interface{}{
  2027. "$lt": lasttime,
  2028. },
  2029. }, `{"l_date":-1}`, nil, false, 0, 1)
  2030. if ok && (*tmps) != nil && len(*tmps) == 1 && (*tmps)[0] != nil {
  2031. tmp := (*tmps)[0]
  2032. at := tmp["o_pushinfo"]
  2033. if at != nil {
  2034. ats := at.(map[string]interface{})
  2035. thistime = tmp["l_date"].(int64)
  2036. count += len(ats)
  2037. tmp["count"] = len(ats)
  2038. res = append(res, tmp)
  2039. list = &res
  2040. if count >= wx_pageSize {
  2041. return
  2042. }
  2043. } else {
  2044. return
  2045. }
  2046. } else {
  2047. return
  2048. }
  2049. return getHistorypush(thistime, sid, res, count)
  2050. }
  2051. //电脑端招标订阅
  2052. func (m *Front) Subscribe() error {
  2053. var shareid = m.GetString("id")
  2054. if len(shareid) == 0 {
  2055. shareid = fmt.Sprintf("%s%d", config.Seoconfig["jydyy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
  2056. }
  2057. m.T["logid"] = config.Seoconfig["jydyy"].(string)
  2058. m.T["noshareid"] = shareid
  2059. m.T["shareid"] = se.EncodeString(shareid)
  2060. myopenid, _ := m.Session().Get("s_m_openid").(string)
  2061. m.T["openid"] = se.EncodeString(myopenid)
  2062. mynickname, _ := m.Session().Get("s_nickname").(string)
  2063. myavatar, _ := m.Session().Get("s_avatar").(string)
  2064. m.T["nickname"] = mynickname
  2065. m.T["avatar"] = myavatar
  2066. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  2067. return m.Render("/pc/subscribe.html", &m.T)
  2068. }
  2069. /*
  2070. * 结果列表转换,目前只换行行业字段
  2071. * 所有的招标搜索都要调用此方法,列表中有展示行业的也可以用
  2072. * industry 搜索条件中的行业,默认为空
  2073. */
  2074. func bidListConvert(industry string, list *[]map[string]interface{}) {
  2075. if list == nil {
  2076. return
  2077. }
  2078. commonSubstring := func(v string) (value string) {
  2079. bcs := strings.Split(v, "_")
  2080. if len(bcs) == 1 {
  2081. value = bcs[0]
  2082. } else if len(bcs) == 2 {
  2083. value = bcs[1]
  2084. if strings.TrimSpace(value) == "" {
  2085. value = bcs[0]
  2086. }
  2087. }
  2088. return
  2089. }
  2090. for _, v := range *list {
  2091. value := ""
  2092. biddingcontent, _ := v["biddingcontent"].([]interface{})
  2093. bct := util.ObjArrToStringArr(biddingcontent)
  2094. if bct == nil || len(bct) == 0 {
  2095. continue
  2096. }
  2097. //搜索条件中没有行业的话,取查询结果中第一个行业
  2098. if industry == "" {
  2099. value = commonSubstring(bct[0])
  2100. } else { //搜索条件中有行业的话,取行业中和搜索条件相对应的第一个
  2101. industrys := strings.Split(industry, ",")
  2102. L:
  2103. for _, bc := range bct {
  2104. for _, is := range industrys {
  2105. if bc == is {
  2106. value = commonSubstring(bc)
  2107. break L
  2108. }
  2109. }
  2110. }
  2111. }
  2112. if strings.TrimSpace(value) == "" {
  2113. continue
  2114. }
  2115. v["industry"] = value
  2116. }
  2117. }