swordfish.go 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785
  1. package front
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "fmt"
  6. "html/template"
  7. "jfw/config"
  8. "jfw/jylabutil"
  9. "jfw/jyutil"
  10. "jfw/public"
  11. "jfw/wx"
  12. "log"
  13. "math/rand"
  14. . "mongodb"
  15. "net/url"
  16. "qfw/util"
  17. "qfw/util/elastic"
  18. "qfw/util/redis"
  19. "reflect"
  20. "regexp"
  21. "strconv"
  22. "strings"
  23. "sync"
  24. "time"
  25. "qfw/util/jy"
  26. "github.com/go-xweb/httpsession"
  27. "github.com/go-xweb/xweb"
  28. . "github.com/thinxer/go-word2vec"
  29. "go.mongodb.org/mongo-driver/bson"
  30. "go.mongodb.org/mongo-driver/bson/primitive"
  31. )
  32. const (
  33. pc_pageSize = 50 //招标搜索分页--每页显示数量
  34. pc_maxPageNum = 10 //招标搜索分页--最大页数
  35. wx_maxPageNum = 20
  36. wx_pageSize = 50
  37. bidSearch_field_1 = `"_id","title","publishtime","toptype","subtype","type","area","city","s_subscopeclass","bidamount","budget","buyerclass"`
  38. bidSearch_field = bidSearch_field_1 + `,"bidopentime","winner","buyer","projectname","projectcode","projectinfo"`
  39. bidSearch_sort = `{"publishtime":-1}`
  40. )
  41. var M *Model
  42. var recomKWChan chan bool = make(chan bool, 1)
  43. var listlock = &sync.Mutex{}
  44. func init() {
  45. M, _ = Load("./zb.bin")
  46. }
  47. //剑鱼标讯推送三级页点赞暂弃 改成剑鱼标讯实验室点赞功能
  48. func (m *Front) Praise() error {
  49. defer util.Catch()
  50. var flag = "F"
  51. var praiseflag = true
  52. thistype := m.GetString("type")
  53. uod := m.GetString("uod")
  54. util.Try(func() {
  55. pdata, _ := mongodb.FindOneByField("praise", `{"s_type":"`+thistype+`"}`, `{"s_no":1}`)
  56. if len(*pdata) != 0 {
  57. if uod == "U" {
  58. praiseflag = mongodb.Update("praise", `{"s_type":"`+thistype+`"}`, `{ "$inc" : { "s_no" : 1 }}`, false, false)
  59. } else {
  60. praiseflag = mongodb.Update("praise", `{"s_type":"`+thistype+`"}`, `{ "$inc" : { "s_no" : -1 }}`, false, false)
  61. }
  62. if praiseflag {
  63. flag = "T"
  64. }
  65. }
  66. }, func(e interface{}) {
  67. log.Println("剑鱼标讯实验室点赞出错", e)
  68. })
  69. m.ServeJson(map[string]interface{}{
  70. "flag": flag,
  71. })
  72. return nil
  73. }
  74. //剑鱼标讯pc首页-统计
  75. func (m *Front) NewSordfishC() error {
  76. var shareid = m.GetString("id")
  77. if len(shareid) == 0 {
  78. shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jysy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
  79. } else {
  80. redis.Del("other", "jypcindex")
  81. }
  82. m.T["logid"] = config.Seoconfig["jysy"].(string)
  83. m.T["shareid"] = se.EncodeString(shareid)
  84. if ret := redis.Get("other", "jypcindex"); ret != nil {
  85. return m.SetBody([]byte(ret.(string)))
  86. } else {
  87. m.DisableHttpCache()
  88. content, _ := m.Render4Cache("/pc/index.html", &m.T)
  89. redis.Put("other", "jypcindex", string(content), 60*60*2)
  90. return m.SetBody(content)
  91. }
  92. }
  93. //剑鱼标讯pc首页
  94. func (m *Front) NewSordfish() error {
  95. ispc, _ := m.GetInteger("ispc")
  96. var shareid = m.GetString("id")
  97. if len(shareid) == 0 {
  98. shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jysy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
  99. } else {
  100. redis.Del("other", "jypcindex")
  101. }
  102. m.T["logid"] = config.Seoconfig["jysy"].(string)
  103. m.T["shareid"] = se.EncodeString(shareid)
  104. m.T["activestart"] = config.ActiveConfig.DoubleEleven.Active_Start
  105. m.T["activeend"] = config.ActiveConfig.DoubleEleven.Active_End
  106. regex, _ := regexp.Compile("(Android|Mobile)")
  107. if ispc == 0 && len(regex.FindAllString(m.Header("User-Agent"), -1)) > 0 {
  108. m.T["s_m_openid"] = util.ObjToString(m.GetSession("s_m_openid"))
  109. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  110. m.T["nickname"] = util.ObjToString(m.GetSession("s_nickname"))
  111. m.T["avatar"] = util.ObjToString(m.GetSession("s_avatar"))
  112. return m.Render("/pc/mobileindex.html", &m.T)
  113. } else {
  114. if ret := redis.Get("other", "jypcindex"); ret != nil {
  115. return m.SetBody([]byte(ret.(string)))
  116. } else {
  117. m.T["live_Preheat_Start"] = config.ActiveConfig.Live_Preheat_Start
  118. m.T["live_Active_End"] = config.ActiveConfig.Live_Active_End
  119. content, _ := m.Render4Cache("/pc/index.html", &m.T)
  120. redis.Put("other", "jypcindex", string(content), 60*60*2)
  121. return m.SetBody(content)
  122. }
  123. }
  124. return m.Render("/pc/index.html", &m.T)
  125. }
  126. func structureLastBidsHtml(lastBidNews *[]map[string]interface{}) (string, string) {
  127. var tmp int = 0
  128. var olCount int = 0
  129. var lbnHtml string = ""
  130. var olHtml string = `<ol class="carousel-indicators">`
  131. for i := 0; i < len(*lastBidNews); i++ {
  132. lastBidNew := (*lastBidNews)[i]
  133. if tmp == 0 {
  134. olHtml += `<li data-target="#lastBidNews" data-slide-to="` + strconv.Itoa(olCount) + `"`
  135. if olCount == 0 {
  136. olHtml += ` class="active"`
  137. }
  138. olHtml += `></li>`
  139. olCount++
  140. }
  141. tmp++
  142. if tmp == 1 {
  143. lbnHtml += `<div class="item`
  144. if i == 0 {
  145. lbnHtml += ` active`
  146. }
  147. lbnHtml += `"><ul>`
  148. }
  149. 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>`
  150. area, _ := lastBidNew["area"].(string)
  151. area = strings.TrimSpace(area)
  152. finalType, _ := lastBidNew["subtype"].(string)
  153. if finalType == "" {
  154. finalType = util.ObjToString(lastBidNew["toptype"])
  155. }
  156. if finalType == "" {
  157. finalType = util.ObjToString(lastBidNew["type"])
  158. if finalType == "bid" {
  159. finalType = "中标"
  160. } else if finalType == "tender" {
  161. finalType = "招标"
  162. } else {
  163. finalType = ""
  164. }
  165. }
  166. industry := util.ObjToString(lastBidNew["industry"])
  167. stpadd, areaadd, induadd := classify(finalType, area, industry)
  168. if area != "" && area != "A" {
  169. lbnHtml += `<span class="com-area"><a href="/list/area/` + areaadd + `.html">` + area + `</a></span>`
  170. }
  171. if finalType != "" {
  172. lbnHtml += `<span class="com-type"><a href="/list/stype/` + stpadd + `.html">` + finalType + `</a></span>`
  173. }
  174. if util.ObjToString(lastBidNew["industry"]) != "" {
  175. lbnHtml += `<span class="com-industry"><a href="/list/industry/` + induadd + `.html">` + util.ObjToString(lastBidNew["industry"]) + `</a></span>`
  176. }
  177. publishtime, _ := lastBidNew["publishtime"].(float64)
  178. if publishtime != 0 {
  179. diff := util.TimeDiff(time.Unix(util.Int64All(publishtime), 0))
  180. if diff != "" {
  181. lbnHtml += `<span class="com-time" data-value="` + fmt.Sprint(util.Int64All(publishtime)) + `"><i class="glyphicon bofangjilu"></i>` + diff + `</span>`
  182. }
  183. }
  184. lbnHtml += `</div></li>`
  185. if tmp == 6 || i == len(*lastBidNews)-1 {
  186. tmp = 0
  187. lbnHtml += `</ul></div>`
  188. }
  189. }
  190. if olCount > 1 {
  191. olHtml += `</ol>`
  192. }
  193. return lbnHtml, olHtml
  194. }
  195. func detailLikeRpc(Interest []string, res *[]map[string]interface{}, flag bool) (mcontent map[string]interface{}) {
  196. //defer util.Catch()
  197. str := fmt.Sprintf("<div>根据您设置的关键词(%s),给您推送以下招标信息:</div>", strings.Join(Interest, ";"))
  198. //发送内容组合
  199. i := 0
  200. o_pushinfo := map[string]interface{}{}
  201. var details []string
  202. v := *res
  203. bmatch := false
  204. for _, k2 := range v {
  205. title := strings.Replace(k2["title"].(string), "\n", "", -1)
  206. province := util.ObjToString(k2["area"])
  207. if province != "" && province != "A" {
  208. title = `[<span class='area'>` + province + `</span>]` + title
  209. }
  210. i++
  211. str += "<div class='tslist'><span class='xh'>" + fmt.Sprintf("%d", i) + ".</span><a class='bt' target='_blank' sid='" + util.EncodeArticleId2ByCheck(BsonIdToSId(k2["_id"])) + "' eid='" + util.EncodeArticleId2ByCheck(BsonIdToSId(k2["_id"])) + "' href='" + k2["href"].(string) + "'>" + title + "</a></div>"
  212. o_pushinfo[strconv.Itoa(i)] = map[string]interface{}{
  213. "publishtime": k2["publishtime"],
  214. "stype": k2["type"],
  215. "topstype": k2["toptype"],
  216. "substype": k2["subtype"],
  217. }
  218. if flag {
  219. highlight, _ := k2["highlight"].(map[string][]string)
  220. detail := ""
  221. if len(highlight["detail"]) > 0 {
  222. detail = highlight["detail"][0]
  223. }
  224. details = append(details, detail)
  225. }
  226. }
  227. mcontent = map[string]interface{}{}
  228. if len(o_pushinfo) > 0 {
  229. bmatch = true
  230. mcontent["o_pushinfo"] = o_pushinfo
  231. mcontent["s_content"] = str
  232. mcontent["s_words"] = Interest
  233. }
  234. mcontent["bmatch"] = bmatch
  235. if flag {
  236. mcontent["details"] = details
  237. }
  238. return
  239. }
  240. //跳转到pc查询剑鱼标讯信息列表
  241. func (m *Front) Searchinfolist(p string) error {
  242. defer util.Catch()
  243. return m.Redirect("/jylab/supsearch/index.html")
  244. var shareid = m.GetString("id")
  245. if len(shareid) == 0 {
  246. shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jysslby"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
  247. }
  248. m.T["logid"] = config.Seoconfig["jysslby"].(string)
  249. m.T["shareid"] = se.EncodeString(shareid)
  250. keywords := m.GetString("keywords")
  251. searchvalue := jy.FilteKey(m.GetString("searchvalue"))
  252. area := m.GetString("area")
  253. publishtime := m.GetString("publishtime")
  254. toptype := m.GetString("toptype")
  255. subtype := m.GetString("subtype")
  256. industry := m.GetString("industry")
  257. minprice := m.GetString("minprice") //最低价格
  258. maxprice := m.GetString("maxprice") //最高价格
  259. selectType := m.GetString("selectType")
  260. selectTypesess := m.GetSession("selectType")
  261. if selectTypesess != nil && selectTypesess != "" {
  262. selectType = selectTypesess.(string)
  263. }
  264. if selectType == "" {
  265. selectType = "all"
  266. }
  267. var status = 1
  268. var count, totalPage int64
  269. tabularflag := ""
  270. var list *[]map[string]interface{}
  271. pages := make([]interface{}, 0)
  272. if len(searchvalue) > 0 || len(industry) > 0 {
  273. count, totalPage, list = getBidSearchData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, 0, true, selectType, "")
  274. //} else if m.Method() == "POST" {
  275. //status = 2
  276. //count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, "", 0, true, false)
  277. } else {
  278. status = 2
  279. if redis.Get("other", "index_list") == nil {
  280. intns := make([]int, 0)
  281. for i := 0; i < 10; i++ {
  282. if len(intns) == 0 {
  283. intns = append(intns, rand.Intn(100))
  284. } else {
  285. for {
  286. v := rand.Intn(intns[(i-1)] + 100)
  287. if v-intns[(i-1)] >= 30 {
  288. intns = append(intns, v)
  289. break
  290. }
  291. }
  292. }
  293. }
  294. for i := 0; i < 10; i++ {
  295. count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, tabularflag, intns[i], true, false)
  296. for k, v := range *list {
  297. v["k"] = (k + 1) + i*50
  298. t := time.Unix(util.Int64All(v["publishtime"]), 0)
  299. v["timetemp"] = fmt.Sprint(util.Int64All(v["publishtime"]))
  300. v["_id"] = util.EncodeArticleId2ByCheck(v["_id"].(string))
  301. v["time"] = util.TimeDiff(t)
  302. var stp = ""
  303. if v["subtype"] != nil {
  304. stp, _ = v["subtype"].(string)
  305. } else {
  306. stp = ""
  307. }
  308. if stp == "" && v["toptype"] != nil {
  309. stp, _ = v["toptype"].(string)
  310. }
  311. area, _ := v["area"].(string)
  312. v["href"] = util.CommonEncodeArticle("bdprivate", (util.GetRandom(22)))
  313. v["stypeadd"], v["areaadd"], _ = classify(stp, area, "")
  314. }
  315. pages = append(pages, list)
  316. }
  317. m.DisableHttpCache()
  318. redis.Put("other", "index_list", pages, 60*60*24*2)
  319. }
  320. }
  321. if status == 2 { //&& m.Method() == "GET" {
  322. pages := redis.Get("other", "index_list").([]interface{})
  323. p := util.IntAll(p)
  324. if p <= 0 || p > 10 {
  325. p = 1
  326. }
  327. if p-1 <= 0 {
  328. m.T["prev"] = 1
  329. } else {
  330. m.T["prev"] = p - 1
  331. }
  332. if p+1 >= 11 {
  333. m.T["next"] = 10
  334. } else {
  335. m.T["next"] = p + 1
  336. }
  337. m.T["cur"] = p
  338. m.T["list"] = pages[p-1]
  339. isopen, _ := m.GetInteger("isopen")
  340. m.T["isopen"] = isopen
  341. m.T["area"] = area
  342. m.T["publishtime"] = publishtime
  343. m.T["timeslot"] = m.GetString("timeslot")
  344. m.T["toptype"] = toptype
  345. m.T["subtype"] = subtype
  346. m.T["count"] = count
  347. m.T["totalPage"] = totalPage
  348. m.T["status"] = status
  349. m.T["keywords"] = keywords
  350. m.T["searchvalue"] = searchvalue
  351. m.T["selectType"] = selectType
  352. m.T["login"] = m.Session().Get("user")
  353. return m.Render("/pc/bidsearch_static.html", &m.T)
  354. } else {
  355. if list != nil {
  356. for _, v := range *list {
  357. v["_id"] = util.EncodeArticleId2ByCheck(v["_id"].(string))
  358. stp, _ := v["subtype"].(string)
  359. if stp == "" {
  360. stp, _ = v["toptype"].(string)
  361. }
  362. area, _ := v["area"].(string)
  363. v["stypeadd"], v["areaadd"], _ = classify(stp, area, "")
  364. //正文匹配检索关键词
  365. highlight, _ := v["highlight"].(map[string][]string)
  366. detail := ""
  367. for _, val := range highlight["detail"] {
  368. detail += public.ClearHtml.ReplaceAllString(val, "")
  369. }
  370. v["href"] = util.CommonEncodeArticle("bdprivate", (util.GetRandom(22)))
  371. v["detail"] = detail
  372. }
  373. }
  374. m.T["list"] = list
  375. isopen, _ := m.GetInteger("isopen")
  376. m.T["isopen"] = isopen
  377. m.T["area"] = area
  378. m.T["publishtime"] = publishtime
  379. m.T["timeslot"] = m.GetString("timeslot")
  380. m.T["toptype"] = toptype
  381. m.T["subtype"] = subtype
  382. m.T["count"] = count
  383. m.T["status"] = status
  384. m.T["keywords"] = keywords
  385. m.T["searchvalue"] = searchvalue
  386. m.T["selectType"] = selectType
  387. m.T["login"] = m.Session().Get("user")
  388. m.SetSession("paramkey", keywords)
  389. if publishtime == "lately-7" {
  390. m.SetSession("parampublishtime", "最近7天")
  391. } else if publishtime == "lately-30" {
  392. m.SetSession("parampublishtime", "最近30天")
  393. } else if publishtime == "thisyear" {
  394. m.SetSession("parampublishtime", "去年")
  395. } else {
  396. m.SetSession("parampublishtime", publishtime)
  397. }
  398. m.SetSession("paramarea", area)
  399. if subtype != "" {
  400. m.SetSession("paraminfotype", subtype)
  401. } else {
  402. m.SetSession("paraminfotype", toptype)
  403. }
  404. return m.Render("/pc/bidsearch.html", &m.T)
  405. }
  406. }
  407. //ajax分页请求
  408. func (m *Front) PcAjaxReq() {
  409. tabularflag := m.GetString("tabularflag")
  410. if tabularflag == "Y" && m.GetSession("userId") == nil {
  411. //判断用户是否登录进行表格查询,否则返回基本数据
  412. tabularflag = ""
  413. }
  414. reqType := m.GetString("reqType")
  415. //获取最新招标信息
  416. if reqType == "lastBids" {
  417. //ls := elastic.GetPage(INDEX, TYPE, "{}", bidSearch_sort, bidSearch_field_1, 0, 18)
  418. //jyutil.BidListConvert("", ls)
  419. ls := Newbids("")
  420. if len(ls) >= 18 {
  421. ls = ls[:18]
  422. }
  423. m.ServeJson(map[string]interface{}{
  424. "list": ls,
  425. })
  426. return
  427. }
  428. currentPage, _ := m.GetInteger("pageNumber")
  429. if currentPage > pc_maxPageNum {
  430. currentPage = pc_maxPageNum
  431. }
  432. start := (currentPage - 1) * pc_pageSize
  433. area := m.GetString("area")
  434. subtype := m.GetString("subtype")
  435. publishtime := m.GetString("publishtime")
  436. selectType := m.GetString("selectType")
  437. industry := strings.TrimSpace(m.GetString("industry"))
  438. minprice := m.GetString("minprice") //最低价格
  439. maxprice := m.GetString("maxprice") //最高价格
  440. m.SetSession("selectType", selectType)
  441. //只有前20条 有全字段,
  442. if subtype != "拟建" && currentPage != 1 {
  443. tabularflag = ""
  444. }
  445. if selectType == "" {
  446. selectType = "all"
  447. }
  448. b_word, a_word, s_word := jy.InterceptSearchKW(m.GetString("searchvalue"), selectType == "all", len(industry) == 0)
  449. var list *[]map[string]interface{}
  450. var secondList []map[string]interface{}
  451. var count, totalPage int64
  452. status, _ := m.GetInteger("status")
  453. isLimit := 1
  454. limitFlag := false
  455. secondFlag := ""
  456. secondKWS := ""
  457. pcAjaxFlag := ""
  458. if len(s_word) > 0 || len(industry) > 0 {
  459. if reqType == "filter" {
  460. if status == 1 {
  461. count, totalPage, list = getBidSearchData(s_word, area, publishtime, subtype, industry, minprice, maxprice, 0, true, selectType, tabularflag)
  462. } else if status == 2 {
  463. //count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, tabularflag, 0, true, true)
  464. }
  465. } else if reqType == "bidSearch" {
  466. //全文检索限制
  467. if selectType == "all" {
  468. limitFlag = public.Lst.Flag
  469. isLimit = public.Lst.IsLimited(m.Request, m.ResponseWriter, m.Session())
  470. if isLimit == 1 { //没有被限制
  471. defer public.Lst.Limit()
  472. }
  473. }
  474. if isLimit == 1 {
  475. if limitFlag {
  476. if start == 0 {
  477. limit_count := public.Lst.TotalPage * pc_pageSize
  478. count, totalPage, list = getBidSearchData_new(s_word, area, publishtime, subtype, industry, minprice, maxprice, 0, limit_count, true, selectType, tabularflag)
  479. if totalPage > int64(public.Lst.TotalPage) {
  480. totalPage = int64(public.Lst.TotalPage)
  481. }
  482. if count > int64(limit_count) {
  483. count = int64(limit_count)
  484. }
  485. }
  486. } else {
  487. count, totalPage, list = getBidSearchData(s_word, area, publishtime, subtype, industry, minprice, maxprice, start, true, selectType, tabularflag)
  488. }
  489. listSize := 0
  490. if list != nil {
  491. listSize = len(*list)
  492. }
  493. if len([]rune(s_word)) > 3 && int(count) < pc_pageSize && start == 0 {
  494. secondKWS = jy.HttpEs(s_word, "ik_smart", public.DbConf.Elasticsearch.Main.Address)
  495. findfields := `"title"`
  496. qstr := getSearchQuery(secondKWS, industry, minprice, maxprice, findfields, getBidSearchQuery(area, publishtime, subtype))
  497. secRel := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, 0, 2*pc_pageSize, 0, false)
  498. if secRel != nil {
  499. public.BidListConvert(industry, secRel)
  500. }
  501. if list != nil {
  502. list = public.MapArrSortMerge(*list, *secRel, "_id", "publishtime")
  503. } else {
  504. list = secRel
  505. }
  506. if len(*secRel) > 0 {
  507. if secondKWS != "" {
  508. s_word += "+" + secondKWS
  509. }
  510. secondFlag = "T"
  511. pcAjaxFlag = "T"
  512. }
  513. }
  514. public.SaveUserSearchLog(m.Request, util.ObjToString(m.GetSession("userId")), -1, "pc", "超级搜索", map[string]interface{}{
  515. "search_word": s_word,
  516. "search_area": area,
  517. "search_price": []string{minprice, maxprice},
  518. "search_publishtime": publishtime,
  519. "search_type": subtype,
  520. "search_industry": industry,
  521. "pagenum": currentPage,
  522. "pagesize": listSize,
  523. })
  524. }
  525. } else if reqType == "lastNews" {
  526. _, list = getLastNewsData(s_word, area, publishtime, subtype, industry, minprice, maxprice, tabularflag, start, false, true)
  527. }
  528. }
  529. if list != nil && len(*list) > 0 {
  530. for _, v := range *list {
  531. if v["_id"] != nil {
  532. v["_id"] = util.EncodeArticleId2ByCheck(v["_id"].(string))
  533. }
  534. stp, ok := v["subtype"].(string)
  535. if ok && stp == "" {
  536. stp = v["toptype"].(string)
  537. }
  538. area, ok := v["area"].(string)
  539. indtry := util.ObjToString(v["industry"])
  540. v["stypeadd"], v["areaadd"], v["indadd"] = classify(stp, area, indtry)
  541. //正文匹配检索关键词
  542. highlight, _ := v["highlight"].(map[string][]string)
  543. detail := ""
  544. for _, val := range highlight["detail"] {
  545. detail += public.ClearHtml.ReplaceAllString(val, "")
  546. }
  547. v["detail"] = detail
  548. v["href"] = util.EncodeArticleId2ByCheck(util.GetRandom(20))
  549. }
  550. if secondFlag != "" {
  551. if len(*list) > pc_pageSize {
  552. secondList = (*list)[pc_pageSize:]
  553. if len(secondList) > pc_pageSize {
  554. secondList = secondList[:pc_pageSize]
  555. }
  556. *list = (*list)[:pc_pageSize]
  557. totalPage = 2
  558. } else {
  559. totalPage = 1
  560. }
  561. }
  562. }
  563. //只有前20条
  564. m.ServeJson(map[string]interface{}{
  565. "limitFlag": limitFlag,
  566. "status": isLimit,
  567. "list": list,
  568. "count": count,
  569. "totalPage": totalPage,
  570. "interceptWord": a_word,
  571. "keywords": b_word,
  572. "searchvalue": s_word,
  573. "secondFlag": secondFlag,
  574. "secondList": secondList,
  575. "pcAjaxFlag": pcAjaxFlag,
  576. })
  577. }
  578. /**
  579. **页面搜索
  580. **/
  581. func getBidSearchData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice string, start int, isGetCount bool, selectType, tabularflag string) (count, totalPage int64, list *[]map[string]interface{}) {
  582. count, totalPage, list = getBidSearchData_new(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, start, pc_pageSize, isGetCount, selectType, tabularflag)
  583. return
  584. }
  585. func getBidSearchData_new(searchvalue, area, publishtime, subtype, industry, minprice, maxprice string, start, pageSize int, isGetCount bool, selectType, tabularflag string) (count, totalPage int64, list *[]map[string]interface{}) {
  586. //selectType:全文搜索(all)、标题搜索(title)
  587. findfields := `"title"`
  588. if selectType == "all" {
  589. findfields = `"title","detail"`
  590. }
  591. qstr := getSearchQuery(searchvalue, industry, minprice, maxprice, findfields, getBidSearchQuery(area, publishtime, subtype))
  592. if isGetCount && qstr != "" && start == 0 {
  593. count = elastic.Count(INDEX, TYPE, qstr)
  594. }
  595. if !isGetCount || count > 0 || start > 0 {
  596. var repl *[]map[string]interface{}
  597. if selectType == "all" {
  598. //全文搜索
  599. if tabularflag == "Y" {
  600. repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, start, pageSize, 115, true)
  601. } else {
  602. repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field_1, start, pageSize, 115, true)
  603. }
  604. } else {
  605. //标题搜索
  606. if tabularflag == "Y" {
  607. repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, start, pageSize, 0, false)
  608. } else {
  609. repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field_1, start, pageSize, 0, false)
  610. }
  611. }
  612. if repl != nil && *repl != nil && len(*repl) > 0 {
  613. public.BidListConvert(industry, repl)
  614. list = repl
  615. }
  616. }
  617. limitCount := int64(pc_pageSize * pc_maxPageNum)
  618. if count > limitCount {
  619. count = limitCount
  620. }
  621. totalPage = (count + int64(pc_pageSize) - 1) / int64(pc_pageSize)
  622. return
  623. }
  624. func getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, tabularflag string, start int, isGetCount bool, highlight bool) (count int64, list *[]map[string]interface{}) {
  625. //最新招标信息
  626. findfields := `"title"`
  627. qstr := getSearchQuery(searchvalue, industry, minprice, maxprice, findfields, getBidSearchQuery(area, publishtime, subtype))
  628. if isGetCount {
  629. count = elastic.Count(INDEX, TYPE, qstr)
  630. }
  631. if !isGetCount || count > 0 {
  632. if tabularflag == "Y" {
  633. repl := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, start, pc_pageSize, 115, highlight)
  634. if repl != nil && *repl != nil && len(*repl) > 0 {
  635. public.BidListConvert(industry, repl)
  636. list = repl
  637. }
  638. } else {
  639. repl := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field_1, start, pc_pageSize, 115, highlight)
  640. if repl != nil && *repl != nil && len(*repl) > 0 {
  641. public.BidListConvert(industry, repl)
  642. list = repl
  643. }
  644. }
  645. }
  646. limitCount := int64(pc_pageSize * pc_maxPageNum)
  647. if count > limitCount {
  648. count = limitCount
  649. }
  650. return
  651. }
  652. func getBidSearchQuery(area, publishtime, subtype string) string {
  653. query := ``
  654. if area != "" {
  655. query += `{"terms":{"area":[`
  656. for k, v := range strings.Split(area, ",") {
  657. if k > 0 {
  658. query += `,`
  659. }
  660. query += `"` + v + `"`
  661. }
  662. query += `]}}`
  663. }
  664. if publishtime != "" {
  665. if len(query) > 0 {
  666. query += ","
  667. }
  668. starttime, endtime := "", ""
  669. now := time.Now()
  670. if publishtime == "lately-7" { //最近7天
  671. starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
  672. } else if publishtime == "lately-30" { //最近30天
  673. starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
  674. } else if publishtime == "thisyear" { //去年
  675. starttime = fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Unix())
  676. endtime = fmt.Sprint(time.Date(now.Year()-1, 12, 31, 23, 59, 59, 0, time.Local).Unix())
  677. } else {
  678. starttime = strings.Split(publishtime, "_")[0]
  679. endtime = strings.Split(publishtime, "_")[1]
  680. etTime := time.Now()
  681. if endtime != "" {
  682. et, _ := strconv.ParseInt(endtime, 0, 64)
  683. etTime = time.Unix(et, 0)
  684. }
  685. endtime = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Unix())
  686. }
  687. query += `{"range":{"publishtime":{`
  688. if starttime != "" {
  689. query += `"gte":` + starttime
  690. }
  691. if starttime != "" && endtime != "" {
  692. query += `,`
  693. }
  694. if endtime != "" {
  695. query += `"lt":` + endtime
  696. }
  697. query += `}}}`
  698. }
  699. if subtype != "" {
  700. if len(query) > 0 {
  701. query += ","
  702. }
  703. query += `{"terms":{"subtype":[`
  704. for k, v := range strings.Split(subtype, ",") {
  705. if k > 0 {
  706. query += `,`
  707. }
  708. query += `"` + v + `"`
  709. }
  710. query += `]}}`
  711. }
  712. return query
  713. }
  714. func getLastNewsQuery(area, publishtime, subtype, industry string) string {
  715. query := ``
  716. if area != "" {
  717. query += `"area":{"$in":[`
  718. for k, v := range strings.Split(area, ",") {
  719. if k > 0 {
  720. query += `,`
  721. }
  722. query += `"` + v + `"`
  723. }
  724. query += `]}`
  725. }
  726. if publishtime != "" {
  727. if len(query) > 0 {
  728. query += ","
  729. }
  730. starttime, endtime := "", ""
  731. now := time.Now()
  732. if publishtime == "lately-7" { //最近7天
  733. starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
  734. } else if publishtime == "lately-30" { //最近30天
  735. starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
  736. } else if publishtime == "thisyear" { //去年
  737. starttime = fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Unix())
  738. endtime = fmt.Sprint(time.Date(now.Year()-1, 12, 31, 23, 59, 59, 0, time.Local).Unix())
  739. } else {
  740. starttime = strings.Split(publishtime, "_")[0]
  741. endtime = strings.Split(publishtime, "_")[1]
  742. et, _ := strconv.ParseInt(endtime, 0, 64)
  743. etTime := time.Unix(et, 0)
  744. endtime = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Unix())
  745. }
  746. if starttime != "" && endtime != "" {
  747. query += `"$and":[{"publishtime":{"$gte":` + starttime + `}},{"publishtime":{"$lt":` + endtime + `}}]`
  748. } else if starttime != "" && endtime == "" {
  749. query += `"publishtime":{"$gte":` + starttime + `}`
  750. } else if starttime == "" && endtime != "" {
  751. query += `"publishtime":{"$lt":` + endtime + `}`
  752. }
  753. }
  754. if subtype != "" {
  755. if len(query) > 0 {
  756. query += ","
  757. }
  758. query += `"subtype":{"$in":[`
  759. for k, v := range strings.Split(subtype, ",") {
  760. if k > 0 {
  761. query += `,`
  762. }
  763. query += `"` + v + `"`
  764. }
  765. query += `]}`
  766. }
  767. //
  768. if industry != "" {
  769. if len(query) > 0 {
  770. query += ","
  771. }
  772. query += `"s_subscopeclass":{"$in":[`
  773. for k, v := range strings.Split(industry, ",") {
  774. if k > 0 {
  775. query += `,`
  776. }
  777. query += `"` + v + `"`
  778. }
  779. query += `]}`
  780. }
  781. query = `{` + query + `}`
  782. return query
  783. }
  784. //进入订阅页面
  785. func (m *Front) Getpage() error {
  786. defer util.Catch()
  787. s_type := ""
  788. userid := util.ObjToString(m.GetSession("userId"))
  789. var msgset map[string]interface{}
  790. if userid != "" {
  791. one, _ := mongodb.FindById("user", userid, `{"o_jy":1}`)
  792. msg := (*one)["o_jy"]
  793. if msg != "" && msg != nil {
  794. msgset = msg.(map[string]interface{})
  795. }
  796. s_type = "tender"
  797. }
  798. m.ServeJson(map[string]interface{}{
  799. "msgset": msgset,
  800. "s_type": s_type,
  801. })
  802. return nil
  803. }
  804. //搜索结果,ajax分页请求
  805. func (m *Front) WxsearchlistPaging() {
  806. defer util.Catch()
  807. userid := m.GetSession("userId")
  808. var list *[]map[string]interface{}
  809. var secRel *[]map[string]interface{}
  810. pageNum, _ := m.GetInteger("pageNum")
  811. if userid != nil && pageNum <= wx_maxPageNum {
  812. //历史记录和订阅查询
  813. one, _ := mongodb.FindById("user", userid.(string), `{"o_jy":1}`)
  814. history := redis.GetStr("other", "s_"+userid.(string))
  815. arrs := strings.Split(history, ",")
  816. searchvalue := strings.TrimSpace(m.GetString("searchvalue"))
  817. var b_word, a_word string
  818. isLimit := 1
  819. limitFlag := false
  820. secondKWS := ""
  821. secondFlag := ""
  822. var secondList []map[string]interface{}
  823. if searchvalue != "" {
  824. filed := ""
  825. if pageNum == 1 {
  826. filed = bidSearch_field
  827. } else {
  828. filed = bidSearch_field_1
  829. }
  830. selectType := m.GetString("selectType")
  831. subtype := m.GetString("subtype")
  832. scope := m.GetString("scope")
  833. publishtime := m.GetString("publishtime")
  834. industry := strings.TrimSpace(m.GetString("industry"))
  835. m.SetSession("industry", industry)
  836. minprice := m.GetString("minprice")
  837. maxprice := m.GetString("maxprice")
  838. //全文检索限制
  839. if selectType == "all" {
  840. limitFlag = public.Lst.Flag
  841. isLimit = public.Lst.IsLimited(m.Request, m.ResponseWriter, m.Session())
  842. if isLimit == 1 { //没有被限制
  843. defer public.Lst.Limit()
  844. }
  845. }
  846. if isLimit == 1 {
  847. s_word := ""
  848. if limitFlag {
  849. if pageNum == 1 {
  850. list, b_word, a_word, s_word = getWxsearchlistData_new(searchvalue, scope, publishtime, subtype, industry, minprice, maxprice, pageNum, public.Lst.TotalPage*wx_pageSize, selectType, filed)
  851. }
  852. } else {
  853. list, b_word, a_word, s_word = getWxsearchlistData(searchvalue, scope, publishtime, subtype, industry, minprice, maxprice, pageNum, selectType, filed)
  854. }
  855. listSize := 0
  856. if list != nil {
  857. listSize = len(*list)
  858. }
  859. if len([]rune(s_word)) > 3 && listSize < pc_pageSize && pageNum == 1 {
  860. secondKWS = jy.HttpEs(s_word, "ik_smart", public.DbConf.Elasticsearch.Main.Address)
  861. findfields := `"title"`
  862. qstr := getSearchQuery(secondKWS, industry, minprice, maxprice, findfields, getBidSearchQuery(scope, publishtime, subtype))
  863. secRel = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, filed, 0, 2*pc_pageSize, 0, false)
  864. if secRel != nil && len(*secRel) > 0 {
  865. public.BidListConvert(industry, secRel)
  866. for _, v := range *secRel {
  867. v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
  868. }
  869. if list != nil {
  870. list = public.MapArrSortMerge(*list, *secRel, "_id", "publishtime")
  871. } else {
  872. list = secRel
  873. }
  874. secondFlag = "T"
  875. if len(*list) > pc_pageSize && selectType == "title" {
  876. secondList = (*list)[pc_pageSize:]
  877. if len(secondList) > pc_pageSize {
  878. secondList = secondList[:pc_pageSize]
  879. }
  880. *list = (*list)[:pc_pageSize]
  881. }
  882. } else {
  883. secondKWS = ""
  884. }
  885. }
  886. public.SaveUserSearchLog(m.Request, util.ObjToString(m.GetSession("userId")), -1, "wx", "超级搜索", map[string]interface{}{
  887. "search_word": searchvalue,
  888. "search_area": scope,
  889. "search_price": []string{minprice, maxprice},
  890. "search_publishtime": publishtime,
  891. "search_type": subtype,
  892. "search_industry": industry,
  893. "pagenum": pageNum,
  894. "pagesize": listSize,
  895. })
  896. }
  897. //新增历史记录
  898. if history == "" {
  899. arrs = make([]string, 0)
  900. }
  901. for k, v := range arrs {
  902. if v == strings.Trim(searchvalue, " ") {
  903. arrs = append(arrs[:k], arrs[k+1:]...)
  904. break
  905. }
  906. }
  907. arrs = append(arrs, searchvalue)
  908. if len(arrs) > 10 {
  909. arrs = arrs[1:11]
  910. }
  911. redis.Del("other", "s_"+userid.(string))
  912. redis.Put("other", "s_"+userid.(string), strings.Join(arrs, ","), -1)
  913. }
  914. m.T["history"] = arrs
  915. if one != nil && len(*one) > 0 {
  916. o_jy, _ := (*one)["o_jy"].(map[string]interface{})
  917. a_key, _ := o_jy["a_key"].([]interface{})
  918. var keys []interface{}
  919. for _, v := range a_key {
  920. keyMap, _ := v.(map[string]interface{})
  921. key, _ := keyMap["key"].([]interface{})
  922. keys = append(keys, key)
  923. }
  924. m.T["msgset"] = keys
  925. }
  926. hasNextPage := list != nil && len(*list) == wx_pageSize && pageNum < wx_maxPageNum
  927. if limitFlag {
  928. hasNextPage = false
  929. }
  930. m.ServeJson(map[string]interface{}{
  931. "limitFlag": limitFlag,
  932. "status": isLimit,
  933. "list": list,
  934. "hasNextPage": hasNextPage,
  935. "history": m.T["history"],
  936. "msgset": m.T["msgset"],
  937. "interceptWord": a_word,
  938. "keyWord": b_word,
  939. "secondFlag": secondFlag,
  940. "secondList": secondList,
  941. "secondKWS": secondKWS,
  942. })
  943. }
  944. }
  945. //微信端删除历史搜索
  946. func (m *Front) DelWxHistorySearch() {
  947. defer util.Catch()
  948. //定义一个无用参数作为返回值
  949. var rt string = "rt"
  950. userId := m.GetSession("userId")
  951. history := redis.GetStr("other", "s_"+userId.(string))
  952. if len(history) > 0 || history != "" {
  953. redis.Del("other", "s_"+userId.(string))
  954. }
  955. m.ServeJson(map[string]interface{}{
  956. "rt": rt,
  957. })
  958. }
  959. //微信端搜索
  960. func getWxsearchlistData(keywords, scope, publishtime, subtype, industry, minprice, maxprice string, pageNum int, selectType, field string) (list *[]map[string]interface{}, b_word, a_word, s_word string) {
  961. return getWxsearchlistData_new(keywords, scope, publishtime, subtype, industry, minprice, maxprice, pageNum, wx_pageSize, selectType, field)
  962. }
  963. func getWxsearchlistData_new(keywords, scope, publishtime, subtype, industry, minprice, maxprice string, pageNum, pageSize int, selectType, field string) (list *[]map[string]interface{}, b_word, a_word, s_word string) {
  964. b_word, a_word, s_word = jy.InterceptSearchKW(keywords, selectType == "all", len(industry) == 0)
  965. if len(b_word) == 0 {
  966. return list, b_word, a_word, s_word
  967. }
  968. findfields := `"title"`
  969. if selectType == "all" {
  970. findfields = `"title","detail"`
  971. }
  972. qstr := getSearchQuery(s_word, industry, minprice, maxprice, findfields, getBidSearchQuery(scope, publishtime, subtype))
  973. if selectType == "all" { //全文搜索
  974. list = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, field, (pageNum-1)*pageSize, pageSize, 100, true)
  975. } else { //标题搜索
  976. list = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, field, (pageNum-1)*pageSize, pageSize, 100, false)
  977. }
  978. if list != nil {
  979. public.BidListConvert(industry, list)
  980. for _, v := range *list {
  981. v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
  982. }
  983. }
  984. return list, b_word, a_word, s_word
  985. }
  986. //查看原文跳转
  987. func (m *Front) VisitRedirect() {
  988. defer util.Catch()
  989. sid := m.GetString("id")
  990. // regex, _ := regexp.Compile("(Android|Mobile)")
  991. // if len(regex.FindAllString(m.Header("User-Agent"), -1)) <= 0 {
  992. // m.Redirect("/article/p/" + sid + ".html")
  993. // }
  994. surl := m.GetString("url")
  995. sds := m.GetString("keywords")
  996. m.T["keywords"] = sds
  997. shareopenid := m.GetString("openid")
  998. if shareopenid != "" {
  999. m.T["shareopenid"] = shareopenid
  1000. }
  1001. myopenid, _ := m.Session().Get("s_m_openid").(string)
  1002. if myopenid == "" {
  1003. myopenid = shareopenid
  1004. m.T["openid"] = myopenid //"-1"
  1005. } else {
  1006. m.T["openid"] = se.EncodeString(myopenid) //"-1"
  1007. }
  1008. mynickname, _ := m.Session().Get("s_nickname").(string)
  1009. myavatar, _ := m.Session().Get("s_avatar").(string)
  1010. m.T["nickname"] = mynickname
  1011. m.T["avatar"] = myavatar
  1012. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  1013. userId, _ := m.GetSession("userId").(string)
  1014. var obj map[string]interface{}
  1015. obj = wxvisitD(sid, userId, myopenid)
  1016. if len(obj) > 0 {
  1017. //获取打赏文案
  1018. m.T["rewardText"], m.T["advertText"] = getRewardText()
  1019. m.T["obj"] = obj
  1020. m.Render("/weixin/wxinfocontent.html", &m.T)
  1021. return
  1022. }
  1023. if surl != "" {
  1024. m.Redirect(surl)
  1025. }
  1026. }
  1027. func wxvisitD(sid, userId, openId string) (objdata map[string]interface{}) {
  1028. defer util.Catch()
  1029. var obj map[string]interface{}
  1030. if len(sid) > 5 {
  1031. brobj, ok := mongodb.Find("bidding_rec", bson.M{"s_id": sid}, `{"l_recoverydate":-1}`, nil, false, 0, 1)
  1032. if ok && (*brobj) != nil && len(*brobj) == 1 && (*brobj)[0] != nil {
  1033. obj = (*brobj)[0]
  1034. } else {
  1035. aobj, ok := public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection, sid, nil)
  1036. if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
  1037. aobj, ok = public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection_back, sid, nil)
  1038. }
  1039. //aobj, ok := elastic.GetByIdField("bidding", "bidding", sid, ""), true
  1040. obj = *aobj
  1041. }
  1042. if ok && obj != nil && len(obj) >= 3 {
  1043. fwt := util.ObjToString(obj["subtype"])
  1044. ltfd := getLowestField(fwt)
  1045. if ltfd != "" {
  1046. obj["fwtsname"] = obj[ltfd]
  1047. obj["fwtscode"] = ltfd
  1048. }
  1049. obj["_id"] = util.EncodeArticleId2ByCheck(sid)
  1050. obj["url"] = obj["href"]
  1051. pt := obj["publishtime"]
  1052. obj["l_publishtime"] = pt
  1053. obj["publishtime"] = util.FormatDateWithObj(&pt, util.Date_Full_Layout)
  1054. //查询是否关注
  1055. obj["followFlag"] = false
  1056. obj["hasSession"] = false
  1057. var infoformat = obj["infoformat"]
  1058. if infoformat != nil && infoformat != "" {
  1059. obj["infoformat"] = util.IntAll(infoformat)
  1060. }
  1061. if userId != "" {
  1062. pcode, _ := obj["projectcode"].(string)
  1063. pname, _ := obj["projectname"].(string)
  1064. titleTmp := util.ObjToString(obj["title"])
  1065. obj["followFlag"], obj["followId"] = MFollow(userId, pname, pcode, titleTmp, openId)
  1066. if len([]rune(titleTmp)) > 100 {
  1067. titleTmp = string([]rune(titleTmp)[:100]) + "..."
  1068. }
  1069. titleTmp = public.ClearHtml.ReplaceAllString(titleTmp, "")
  1070. obj["title"] = titleTmp
  1071. obj["hasSession"] = true
  1072. }
  1073. if strings.Trim(util.ObjToString(obj["detail"]), " ") == "" {
  1074. obj["detail"] = ""
  1075. }
  1076. }
  1077. }
  1078. return obj
  1079. }
  1080. //获取权重最低的字段
  1081. func getLowestField(subtype string) string {
  1082. fields := util.ObjToMap(config.Sysconfig["recoveryField"])
  1083. result := ""
  1084. if subtype != "招标" {
  1085. subtype = "其他"
  1086. }
  1087. var fieldsArr = util.ObjArrToMapArr((*fields)[subtype].([]interface{}))
  1088. i := getWeightRandom(fieldsArr)
  1089. for k, v := range fieldsArr {
  1090. if k == i {
  1091. result = util.ObjToString(v["field"])
  1092. }
  1093. }
  1094. return result
  1095. }
  1096. //根据权重随机获取数组的索引
  1097. func getWeightRandom(array []map[string]interface{}) int {
  1098. var weightSum, stepWeightSum float64
  1099. for _, v := range array {
  1100. weightSum += v["proportion"].(float64)
  1101. }
  1102. randVal := rand.New(rand.NewSource(time.Now().UnixNano())).Float64()
  1103. for i := 0; i < len(array); i++ {
  1104. stepWeightSum += array[i]["proportion"].(float64)
  1105. if randVal <= stepWeightSum/weightSum {
  1106. return i
  1107. }
  1108. }
  1109. return 0
  1110. }
  1111. func MFollow(userId, pname, pcode, title, openid string) (bool, string) {
  1112. defer util.Catch()
  1113. var followId string
  1114. followFlag := false
  1115. follows, ok := mongodb.Find("follow_project", `{"s_userid":"`+userId+`"}`, `{"_id":1,"s_projectname":1,"s_projectcode":1}`, nil, false, -1, -1)
  1116. if ok && follows != nil && len(*follows) > 0 {
  1117. for _, v := range *follows {
  1118. pc, _ := v["s_projectcode"].(string)
  1119. pn, _ := v["s_projectname"].(string)
  1120. if (pc != "" && pc == pcode) || (pn != "" && pn == pname) {
  1121. followFlag = true
  1122. followId = util.EncodeArticleId2ByCheck(BsonIdToSId(v["_id"]))
  1123. break
  1124. }
  1125. }
  1126. }
  1127. return followFlag, followId
  1128. }
  1129. //查看原文跳转
  1130. //增加查询备份库数据、增加关键词、描述逻辑处理
  1131. func (m *Front) PcVisitRedirect(sid string) {
  1132. defer util.Catch()
  1133. kds := m.GetString("kds")
  1134. m.T["keywords"] = kds
  1135. sid = strings.Split(sid, "_")[0]
  1136. //sid = util.DecodeArticleId(sid)[0]
  1137. var shareid = m.GetString("id")
  1138. if len(shareid) == 0 {
  1139. shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jysskzy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
  1140. }
  1141. m.T["logid"] = config.Seoconfig["jysskzy"].(string)
  1142. m.T["shareid"] = se.EncodeString(shareid)
  1143. if ret := redis.Get("other", "jypcdetail_"+sid+kds); ret != nil {
  1144. m.SetBody([]byte(ret.(string)))
  1145. return
  1146. } else {
  1147. m.DisableHttpCache()
  1148. data := elastic.GetByIdField("bidding", "bidding", sid, `"href"`)
  1149. if data == nil || len(*data) == 0 {
  1150. m.Render("/_error.html")
  1151. return
  1152. }
  1153. href, _ := (*data)["href"].(string)
  1154. href = strings.Replace(href, "\n", "", -1)
  1155. if href != "" && !strings.HasPrefix(href, "http") {
  1156. href = "http://" + href
  1157. }
  1158. po, bo, wo, obj := pcVRT(sid, "")
  1159. if obj != nil && len(obj) > 0 {
  1160. if len(po) > 0 {
  1161. m.T["projectOther"] = po
  1162. }
  1163. if len(bo) > 0 {
  1164. m.T["buyerOther"] = bo
  1165. }
  1166. if len(wo) > 0 {
  1167. m.T["winnerOther"] = wo
  1168. }
  1169. obj["url"] = href
  1170. m.T["obj"] = obj
  1171. content, _ := m.Render4Cache("/pc/biddetail.html", &m.T)
  1172. redis.Put("other", "jypcdetail_"+sid+kds, string(content), 60*60*24)
  1173. m.SetBody(content)
  1174. return
  1175. }
  1176. if href != "" {
  1177. m.Redirect(href)
  1178. }
  1179. }
  1180. }
  1181. //pc三级页跳转
  1182. //20170821增加查询字段s_subscopeclass
  1183. func pcVRT(sid, industry string) (po, bo, wo []map[string]interface{}, objdata map[string]interface{}) {
  1184. defer util.Catch()
  1185. var projectOther, buyerOther, winnerOther []map[string]interface{}
  1186. var obj map[string]interface{}
  1187. if len(sid) > 5 {
  1188. brobj, ok := mongodb.Find("bidding_rec", bson.M{"s_id": sid}, `{"l_recoverydate":-1}`, nil, false, 0, 1)
  1189. if ok && (*brobj) != nil && len(*brobj) == 1 && (*brobj)[0] != nil {
  1190. obj = (*brobj)[0]
  1191. } else {
  1192. aobj, ok := public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection, sid, nil)
  1193. if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
  1194. aobj, ok = public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection_back, sid, nil)
  1195. }
  1196. obj = *aobj
  1197. }
  1198. //obj, ok := elastic.GetByIdField("bidding", "bidding", sid, ""), true
  1199. if ok && obj != nil && len(obj) > 0 {
  1200. //DealInfo(obj, coll)
  1201. //fwt := util.ObjToString(obj["fieldweights"])
  1202. //lwf := util.ObjToString(obj["lastwrongfield"])
  1203. //ltfd := getLowestField(fwt, lwf)
  1204. //if ltfd != "" {
  1205. // obj["fwtsname"] = obj[ltfd]
  1206. // obj["fwtscode"] = ltfd
  1207. //}
  1208. obj["_id"] = util.EncodeArticleId2ByCheck(sid)
  1209. var infoformat = obj["infoformat"]
  1210. if infoformat != nil && infoformat != "" {
  1211. obj["infoformat"] = util.IntAll(infoformat)
  1212. }
  1213. if strings.Trim(util.ObjToString(obj["detail"]), " ") == "" {
  1214. obj["detail"] = ""
  1215. }
  1216. titleStr := util.ObjToString(obj["title"])
  1217. if len([]rune(titleStr)) > 100 {
  1218. titleStr = string([]rune(titleStr)[:100]) + "..."
  1219. }
  1220. //titleTmp := util.If(len([]rune(titleStr)) > 100, string([]rune(titleStr)[:100])+"...", string(titleStr)).(string)
  1221. obj["title"] = public.ClearHtml.ReplaceAllString(titleStr, "")
  1222. area := obj["area"].(string)
  1223. finalType, _ := obj["subtype"].(string)
  1224. if finalType == "" {
  1225. finalType = util.ObjToString(obj["toptype"])
  1226. }
  1227. if finalType == "" {
  1228. finalType = util.ObjToString(obj["type"])
  1229. if finalType == "bid" {
  1230. finalType = "中标"
  1231. } else if finalType == "tender" {
  1232. finalType = "招标"
  1233. } else {
  1234. finalType = ""
  1235. }
  1236. }
  1237. if industry == "" {
  1238. industry = util.ObjToString(obj["s_subscopeclass"])
  1239. if industry != "" {
  1240. if strings.Contains(industry, "它") {
  1241. industry = strings.Replace(industry, "它", "他", -1)
  1242. }
  1243. industry = strings.Split(industry, ",")[0]
  1244. }
  1245. }
  1246. //detail字段 缺少标签 处理
  1247. if config.Sysconfig["detail_element"] != nil {
  1248. var arrTags = util.ObjArrToStringArr(config.Sysconfig["detail_element"].([]interface{}))
  1249. var _detail = util.ObjToString(obj["detail"])
  1250. for _, v := range arrTags {
  1251. var intOpen = strings.Count(_detail, "<"+v)
  1252. var intClose = strings.Count(_detail, "</"+v+">")
  1253. if intOpen >= intClose {
  1254. for di := 0; di < (intOpen - intClose); di++ {
  1255. _detail += "</" + v + ">"
  1256. }
  1257. } else {
  1258. for di := 0; di < (intClose - intOpen); di++ {
  1259. _detail = "<" + v + ">" + _detail
  1260. }
  1261. }
  1262. // log.Println(intOpen, "--", intClose)
  1263. }
  1264. // log.Println("_detail:", _detail)
  1265. obj["detail"] = _detail
  1266. }
  1267. obj["stypeadd"], obj["areaadd"], obj["indadd"] = classify(finalType, area, industry)
  1268. //增加处理信息逻辑
  1269. objdata = obj
  1270. queryStr := ""
  1271. commonQuery := func(mustquery string) *[]map[string]interface{} {
  1272. return elastic.GetPage("bidding", "bidding", queryStr, bidSearch_sort, `"_id","title","publishtime","toptype","subtype","type","area","href","s_subscopeclass"`, 0, 11)
  1273. }
  1274. //同一个项目的其他招标信息
  1275. projectName, _ := obj["projectname"].(string)
  1276. projectCode, _ := obj["projectcode"].(string)
  1277. if projectName != "" || projectCode != "" {
  1278. if projectName != "" && projectCode != "" {
  1279. queryStr = `{"$or":[{"TERM_projectname":"` + projectName + `"},{"TERM_projectcode":"` + projectCode + `"}]}`
  1280. } else if projectName != "" && projectCode == "" {
  1281. queryStr = `{"TERM_projectname":"` + projectName + `"}`
  1282. } else if projectName == "" && projectCode != "" {
  1283. queryStr = `{"TERM_projectcode":"` + projectCode + `"}`
  1284. }
  1285. projectOther = bidDataConvert(sid, commonQuery(queryStr))
  1286. }
  1287. //同一个业主最近的其他招标信息
  1288. buyer, _ := obj["buyer"].(string) //采购单位
  1289. if buyer != "" {
  1290. queryStr = `{"TERM_buyer":"` + buyer + `"}`
  1291. buyerOther = bidDataConvert(sid, commonQuery(queryStr))
  1292. }
  1293. //同一中标人最近中标的其他信息
  1294. subtype, _ := obj["subtype"].(string) //信息类型
  1295. winner, _ := obj["winner"].(string) //中标人
  1296. if winner != "" && subtype == "中标" {
  1297. queryStr = `{"TERM_s_winner":"` + winner + `"}`
  1298. winnerOther = bidDataConvert(sid, commonQuery(queryStr))
  1299. }
  1300. }
  1301. }
  1302. return projectOther, buyerOther, winnerOther, objdata
  1303. }
  1304. //数据转换
  1305. func bidDataConvert(id string, datas *[]map[string]interface{}) (array []map[string]interface{}) {
  1306. if datas == nil || len(*datas) == 0 {
  1307. return array
  1308. }
  1309. index := 0
  1310. public.BidListConvert("", datas)
  1311. for _, v := range *datas {
  1312. if len(array) >= 10 {
  1313. break
  1314. }
  1315. _id, _ := v["_id"].(string)
  1316. if _id == id {
  1317. continue
  1318. }
  1319. v["_id"] = util.EncodeArticleId2ByCheck(_id)
  1320. area, _ := v["area"].(string)
  1321. if area == "A" {
  1322. v["area"] = ""
  1323. }
  1324. tp, _ := v["subtype"].(string)
  1325. if tp == "" {
  1326. tp, _ = v["toptype"].(string)
  1327. }
  1328. if tp == "" {
  1329. tp, _ = v["type"].(string)
  1330. if tp == "bid" {
  1331. tp = "中标"
  1332. } else if tp == "tender" {
  1333. tp = "招标"
  1334. } else {
  1335. tp = ""
  1336. }
  1337. }
  1338. indtry := util.ObjToString(v["industry"])
  1339. v["stypeadd"], v["areaadd"], v["indadd"] = classify(tp, area, indtry)
  1340. v["type"] = tp
  1341. diff := ""
  1342. publishtime, _ := v["publishtime"].(float64)
  1343. if publishtime != 0 {
  1344. diff = util.TimeDiff(time.Unix(util.Int64All(publishtime), 0))
  1345. v["pbtime"] = util.Int64All(publishtime)
  1346. }
  1347. v["publishtime"] = diff
  1348. index++
  1349. v["index"] = index
  1350. array = append(array, v)
  1351. }
  1352. return array
  1353. }
  1354. //剑鱼标讯保存
  1355. func (m *Front) AjaxReq() error {
  1356. defer util.Catch()
  1357. reqType := m.GetString("reqType")
  1358. var flag = "n"
  1359. switch reqType {
  1360. case "feedback": //意见反馈
  1361. data := make(map[string]interface{})
  1362. userId, ok := m.GetSession("userId").(string)
  1363. if !ok || userId == "" {
  1364. break
  1365. }
  1366. userInfo, ok := mongodb.FindById("user", userId, nil)
  1367. if !ok {
  1368. break
  1369. }
  1370. data["i_type"] = 8
  1371. data["s_fromName"] = m.GetString("fromName")
  1372. value := m.GetString("value")
  1373. if len([]rune(value)) > 200 {
  1374. value = util.SubString(value, 0, 200)
  1375. }
  1376. data["s_remark"] = value
  1377. s_nickname, _ := (*userInfo)["s_nickname"].(string)
  1378. s_name, _ := (*userInfo)["s_name"].(string)
  1379. s_phone, _ := (*userInfo)["s_phone"].(string)
  1380. if s_name != "" {
  1381. data["s_submitname"] = s_name
  1382. } else if s_nickname != "" {
  1383. data["s_submitname"] = s_nickname
  1384. } else if s_phone != "" {
  1385. data["s_submitname"] = s_phone
  1386. } else {
  1387. data["s_submitname"] = userId
  1388. }
  1389. data["s_submitid"] = userId
  1390. data["s_title"] = m.GetString("title")
  1391. data["i_status"] = 0
  1392. if s_nickname != "" { //昵称
  1393. data["s_username"] = s_nickname
  1394. } else if s_name != "" { //s_name
  1395. data["s_username"] = s_name
  1396. } else if s_phone != "" { //s_name
  1397. data["s_username"] = s_phone
  1398. } else { //s_name
  1399. data["s_username"] = userId
  1400. }
  1401. data["l_submitdate"] = time.Now().Unix()
  1402. data["s_source"] = m.GetString("source")
  1403. data["s_fkid"] = m.GetString("fkid")
  1404. data["s_from"] = "wx"
  1405. id := mongodb.Save("interaction", data)
  1406. if len(id) > 0 {
  1407. flag = "y"
  1408. }
  1409. break
  1410. case "subscribe": //直接订阅
  1411. if userid := m.GetSession("userId"); userid != nil {
  1412. r, _ := mongodb.FindById("user", userid.(string), `{"o_jy":1}`)
  1413. o_jy, _ := (*r)["o_jy"].(map[string]interface{})
  1414. a_key, _ := o_jy["a_key"].([]interface{})
  1415. keysArray := processKeyword(m.GetString("keys"))
  1416. if keysArray == nil {
  1417. break
  1418. }
  1419. var isExists bool
  1420. for _, v := range a_key {
  1421. //count := 0
  1422. //for _, kay := range keysArray {
  1423. keyMap, _ := v.(map[string]interface{})
  1424. key, _ := keyMap["key"].([]interface{})
  1425. kystr := ""
  1426. for _, ky := range key {
  1427. kystr = kystr + " " + ky.(string)
  1428. }
  1429. if strings.TrimSpace(m.GetString("keys")) == strings.TrimSpace(kystr) {
  1430. isExists = true
  1431. flag = "y"
  1432. break
  1433. }
  1434. //}
  1435. //if count == len(keysArray) {
  1436. // isExists = true
  1437. // flag = "y"
  1438. // break
  1439. //}
  1440. }
  1441. //如果不存在
  1442. if !isExists {
  1443. if len(a_key) >= 10 {
  1444. flag = "o"
  1445. } else {
  1446. if mongodb.UpdateById("user", userid,
  1447. bson.M{
  1448. "$push": bson.M{"o_jy.a_key": bson.M{"key": keysArray}},
  1449. "$set": bson.M{"i_ts_guide": 1, "o_jy.l_modifydate": time.Now().Unix()},
  1450. }) {
  1451. flag = "y"
  1452. }
  1453. }
  1454. }
  1455. }
  1456. break
  1457. }
  1458. m.ServeJson(map[string]interface{}{
  1459. "flag": flag,
  1460. })
  1461. return nil
  1462. }
  1463. const (
  1464. INDEX = "bidding"
  1465. TYPE = "bidding"
  1466. FINDF = `"title"`
  1467. )
  1468. //预览结果
  1469. func (m *Front) WxpushView() error {
  1470. defer util.Catch()
  1471. userid := util.ObjToString(m.GetSession("userId"))
  1472. openid := util.ObjToString(m.GetSession("s_m_openid"))
  1473. if openid == "" || userid == "" {
  1474. return m.Redirect("/swordfish/share/-1")
  1475. }
  1476. a_key, list := public.PushViewDatas(userid, "", bidSearch_field_1, 1, wx_pageSize)
  1477. public.BidListConvert("", list)
  1478. m.T["firstPage"] = list
  1479. m.T["hasNextPage"] = list != nil && len(*list) == wx_pageSize
  1480. m.T["pageSize"] = wx_pageSize
  1481. m.T["a_key"] = a_key
  1482. mynickname, _ := m.Session().Get("s_nickname").(string)
  1483. myavatar, _ := m.Session().Get("s_avatar").(string)
  1484. m.T["nickname"] = mynickname
  1485. m.T["avatar"] = myavatar
  1486. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  1487. m.T["openid"] = se.EncodeString(openid)
  1488. return m.Render("/weixin/resultpreview.html", &m.T)
  1489. }
  1490. func (m *Front) WxpushViewPaging() {
  1491. defer util.Catch()
  1492. var list *[]map[string]interface{}
  1493. pageNum, _ := m.GetInteger("pageNum")
  1494. if userid := m.Session().Get("userId"); userid != nil && pageNum <= wx_maxPageNum {
  1495. _, list = public.PushViewDatas(userid.(string), "", bidSearch_field_1, pageNum, wx_pageSize)
  1496. }
  1497. public.BidListConvert("", list)
  1498. m.ServeJson(map[string]interface{}{
  1499. "list": list,
  1500. "hasNextPage": list != nil && len(*list) == wx_pageSize && pageNum < wx_maxPageNum,
  1501. })
  1502. }
  1503. func (m *Front) Guide(sign string) error {
  1504. defer util.Catch()
  1505. if m.Session().Get("userId") == nil || m.Session().Get("s_m_openid") == nil {
  1506. return m.Redirect("/swordfish/share/-1")
  1507. }
  1508. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  1509. mynickname, _ := m.Session().Get("s_nickname").(string)
  1510. myavatar, _ := m.Session().Get("s_avatar").(string)
  1511. m.T["nickname"] = mynickname
  1512. m.T["avatar"] = myavatar
  1513. myopenid, _ := m.Session().Get("s_m_openid").(string)
  1514. m.T["openid"] = se.EncodeString(myopenid)
  1515. m.T["sign"] = sign
  1516. if sign == "other" {
  1517. userInfo, ok := mongodb.FindById("user", m.GetSession("userId").(string), `{"o_jy_msgset":1}`)
  1518. if ok {
  1519. m.T["msgset"] = (*userInfo)["o_jy_msgset"]
  1520. }
  1521. }
  1522. if sign == "share" {
  1523. return m.Render("/weixin/wxshareguide.html", &m.T)
  1524. } else {
  1525. return m.Render("/weixin/wxindex.html", &m.T)
  1526. }
  1527. }
  1528. func (m *Front) Share(openids string) error {
  1529. return m.Redirect("/swordfish/about")
  1530. //
  1531. defer util.Catch()
  1532. var openid = ""
  1533. var jy_code = ""
  1534. if openids != "-1" {
  1535. wxid_code := strings.Split(openids, "__")
  1536. if len(wxid_code) > 0 {
  1537. openid = wxid_code[0]
  1538. jy_code = wxid_code[1]
  1539. }
  1540. }
  1541. m.T["openid"] = openid
  1542. m.T["jy_code"] = jy_code
  1543. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  1544. mynickname, _ := m.Session().Get("s_nickname").(string)
  1545. myavatar, _ := m.Session().Get("s_avatar").(string)
  1546. m.T["nickname"] = mynickname
  1547. m.T["avatar"] = myavatar
  1548. return m.Render("/weixin/wxshare.html", &m.T)
  1549. }
  1550. func (m *Front) WxpushAjaxReq() error {
  1551. defer util.Catch()
  1552. userId := util.ObjToString(m.GetSession("userId"))
  1553. if userId != "" {
  1554. vsid, _ := m.GetInteger("vsid")
  1555. jy.SubscribePush.Visit(public.PushMysql, userId, vsid)
  1556. }
  1557. return nil
  1558. }
  1559. //
  1560. func (m *Front) About() error {
  1561. defer util.Catch()
  1562. code := m.GetString("code") //渠道
  1563. // 点浏览器打开时保持在原页面
  1564. come := m.GetString("come")
  1565. flag := m.GetString("flag")
  1566. if !mobileReg.MatchString(m.UserAgent()) && flag == "" {
  1567. return m.Redirect("/front/aboutus.html" + util.If(code != "", "?code="+code, "").(string))
  1568. }
  1569. myopenid, _ := m.Session().Get("s_m_openid").(string)
  1570. mynickname, _ := m.Session().Get("s_nickname").(string)
  1571. myavatar, _ := m.Session().Get("s_avatar").(string)
  1572. if myopenid == "" {
  1573. if m.GetString("state") == "wx" {
  1574. //微信跳回来的
  1575. code := m.GetString("code")
  1576. if code != "" {
  1577. openid := jyutil.Getopenid(code)
  1578. userInfo, ok := mongodb.FindOneByField("user", map[string]interface{}{
  1579. "s_m_openid": openid,
  1580. "i_appid": 2,
  1581. }, `{"_id":-1,"s_nickname":1,"s_m_openid":1}`)
  1582. if ok && userInfo != nil && len(*userInfo) > 0 {
  1583. mynickname, _ = (*userInfo)["s_nickname"].(string)
  1584. myopenid, _ = (*userInfo)["s_m_openid"].(string)
  1585. }
  1586. }
  1587. } else {
  1588. if public.CheckWxBrowser(m.Request) {
  1589. //所有参数都不再使用,跳到微信验证用户
  1590. return m.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(m.Site()+m.Url()), "wx"), 302)
  1591. }
  1592. }
  1593. }
  1594. param := m.GetString("param")
  1595. var openid = ""
  1596. var activecode = ""
  1597. //分享后微信新用户打开落地页
  1598. if param != "-1" {
  1599. wxid_code := strings.Split(param, "__")
  1600. if len(wxid_code) > 0 {
  1601. openid = wxid_code[0]
  1602. }
  1603. if len(wxid_code) > 1 {
  1604. activecode = wxid_code[1]
  1605. }
  1606. }
  1607. qrcodeType := m.GetString("qrcodeType")
  1608. if qrcodeType != "" {
  1609. activecode = qrcodeType
  1610. }
  1611. m.T["code"] = code
  1612. m.T["source"] = m.GetString("source") //分享类型 app or 公众号
  1613. m.T["activecode"] = activecode
  1614. m.T["nickname"] = mynickname
  1615. m.T["avatar"] = myavatar
  1616. if openid == "" && myopenid != "" {
  1617. m.T["openid"] = se.EncodeString(myopenid)
  1618. } else {
  1619. m.T["openid"] = openid
  1620. }
  1621. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  1622. m.T["flag"] = flag
  1623. m.T["come"] = come
  1624. if come == "1" && !public.CheckWxBrowser(m.Request) {
  1625. return m.Redirect("https://www.jianyu360.com/jyapp/free/download/normal?source=weixinAutoRpl")
  1626. }
  1627. var open_infoid = ""
  1628. if m.GetString("source") == "open_infocontent" {
  1629. open_infoid = m.GetString("o")
  1630. m.T["open_infoid"] = open_infoid
  1631. m.T["code"] = "open00" + open_infoid
  1632. return m.Render("/weixin/about.html")
  1633. } else {
  1634. if myopenid == "" {
  1635. if public.CheckWxBrowser(m.Request) {
  1636. if code == "" {
  1637. m.T["code"] = "wx01" //新用户微信访问,统计app下载量
  1638. }
  1639. return m.Render("/weixin/sharePage.html")
  1640. } else {
  1641. return m.Redirect("/active/appExt/sh001")
  1642. }
  1643. } else {
  1644. if public.CheckWxBrowser(m.Request) {
  1645. m.T["isWeixin"] = 1
  1646. } else {
  1647. m.T["isWeixin"] = 0
  1648. }
  1649. return m.Render("/weixin/about.html")
  1650. }
  1651. }
  1652. }
  1653. //
  1654. func (m *Front) Shareabout(openids string) error {
  1655. defer util.Catch()
  1656. var openid = ""
  1657. if openids != "-1" {
  1658. wxid_code := strings.Split(openids, "__")
  1659. if len(wxid_code) > 0 {
  1660. openid = wxid_code[0]
  1661. }
  1662. }
  1663. myopenid, _ := m.Session().Get("s_m_openid").(string)
  1664. mynickname, _ := m.Session().Get("s_nickname").(string)
  1665. myavatar, _ := m.Session().Get("s_avatar").(string)
  1666. if openid == "" && myopenid != "" {
  1667. m.T["openid"] = se.EncodeString(myopenid)
  1668. } else {
  1669. m.T["openid"] = openid
  1670. }
  1671. m.T["nickname"] = mynickname
  1672. m.T["avatar"] = myavatar
  1673. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  1674. m.T["source"] = ""
  1675. if public.CheckWxBrowser(m.Request) {
  1676. m.T["isWeixin"] = 1
  1677. } else {
  1678. m.T["isWeixin"] = 0
  1679. }
  1680. return m.Render("/weixin/about.html")
  1681. }
  1682. //
  1683. func (m *Front) Aboutsearch() error {
  1684. myopenid, _ := m.Session().Get("s_m_openid").(string)
  1685. m.T["openid"] = se.EncodeString(myopenid)
  1686. mynickname, _ := m.Session().Get("s_nickname").(string)
  1687. myavatar, _ := m.Session().Get("s_avatar").(string)
  1688. m.T["nickname"] = mynickname
  1689. m.T["avatar"] = myavatar
  1690. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  1691. m.Render("/weixin/aboutsearch.html", &m.T)
  1692. return nil
  1693. }
  1694. //剑鱼标讯微信查询保存网站
  1695. func (m *Front) AboutSR() error {
  1696. defer util.Catch()
  1697. var flag = "N"
  1698. var sn = m.GetString("searchname")
  1699. var tp = m.GetString("tp")
  1700. if len(sn) > 0 {
  1701. switch tp {
  1702. case "S": //用户查询网站是否被收录
  1703. userId, ok := m.GetSession("userId").(string)
  1704. if !ok || userId == "" {
  1705. break
  1706. }
  1707. res, err := mongodb.FindOne("bidurlinfo", bson.M{"$or": []bson.M{bson.M{"s_name": sn}, bson.M{"s_url": sn}}})
  1708. if err {
  1709. if len(*res) > 0 {
  1710. flag = "T"
  1711. }
  1712. }
  1713. break
  1714. case "I": //用户提交数据
  1715. data := make(map[string]interface{})
  1716. userId, ok := m.GetSession("userId").(string)
  1717. if !ok || userId == "" {
  1718. break
  1719. }
  1720. userInfo, ok := mongodb.FindById("user", userId, nil)
  1721. if !ok {
  1722. break
  1723. }
  1724. data["i_type"] = 8
  1725. data["s_remark"] = sn
  1726. if (*userInfo)["s_name"] != nil {
  1727. data["s_submitname"] = (*userInfo)["s_name"].(string)
  1728. }
  1729. data["s_submitid"] = userId
  1730. data["s_title"] = m.GetString("title")
  1731. data["i_status"] = 0
  1732. if (*userInfo)["s_nickname"] != nil { //昵称
  1733. data["s_username"] = (*userInfo)["s_nickname"].(string)
  1734. } else if (*userInfo)["s_name"] != nil { //s_name
  1735. data["s_username"] = (*userInfo)["s_name"].(string)
  1736. }
  1737. data["l_submitdate"] = time.Now().Unix()
  1738. data["s_source"] = m.GetString("source")
  1739. data["s_from"] = "wx"
  1740. id := mongodb.Save("interaction", data)
  1741. if len(id) > 0 && len(sn) > 0 {
  1742. flag = "T"
  1743. }
  1744. break
  1745. }
  1746. }
  1747. m.ServeJson(map[string]interface{}{
  1748. "flag": flag,
  1749. })
  1750. return nil
  1751. }
  1752. //手动删除30天无更新数据
  1753. func (m *Front) DelOL() error {
  1754. defer util.Catch()
  1755. var ids []primitive.ObjectID
  1756. var flag = "F"
  1757. var arrid = strings.Split(m.GetString("arrid"), ",")
  1758. if len(arrid) > 0 {
  1759. for _, chid := range arrid {
  1760. _id, _ := primitive.ObjectIDFromHex(util.DecodeArticleId2ByCheck(chid)[0])
  1761. ids = append(ids, _id)
  1762. }
  1763. }
  1764. userId, ok := m.GetSession("userId").(string)
  1765. if !ok || userId == "" || len(ids) < 1 {
  1766. m.ServeJson(map[string]interface{}{
  1767. "flag": flag,
  1768. })
  1769. return nil
  1770. }
  1771. if datas, ok := mongodb.Find("follow_project", bson.M{"_id": bson.M{"$in": ids}, "s_userid": m.GetSession("userId").(string)}, nil, nil, false, -1, -1); ok && datas != nil {
  1772. for _, v := range *datas {
  1773. go delRelRedis(v["s_userid"], v["a_relationinfo"])
  1774. v["s_followid"] = BsonIdToSId(v["_id"])
  1775. delete(v, "_id")
  1776. v["i_status"] = 2
  1777. mongodb.Save("follow_project_back", v)
  1778. }
  1779. }
  1780. if mongodb.Del("follow_project", bson.M{"_id": bson.M{"$in": ids}, "s_userid": m.GetSession("userId").(string)}) {
  1781. flag = "T"
  1782. }
  1783. m.ServeJson(map[string]interface{}{
  1784. "flag": flag,
  1785. })
  1786. return nil
  1787. }
  1788. //获取我的反馈列表
  1789. func (f *Front) MyFeedbacks() error {
  1790. userId, _ := f.GetSession("userId").(string)
  1791. if userId == "" {
  1792. return f.Render("/_error.html")
  1793. }
  1794. 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)
  1795. if !ok {
  1796. return nil
  1797. }
  1798. if f.Method() == "GET" {
  1799. f.T["list"] = list
  1800. f.T["flag"] = true
  1801. mynickname, _ := f.Session().Get("s_nickname").(string)
  1802. myavatar, _ := f.Session().Get("s_avatar").(string)
  1803. myopenid, _ := f.GetSession("s_m_openid").(string)
  1804. f.T["nickname"] = mynickname
  1805. f.T["avatar"] = myavatar
  1806. f.T["signature"] = wx.SignJSSDK(f.Site() + f.Url())
  1807. f.T["openid"] = se.EncodeString(myopenid)
  1808. _, f.T["advertText"] = getRewardText()
  1809. f.T["advertImg"] = config.Sysconfig["advertImg"]
  1810. f.T["advertName"] = config.Sysconfig["advertName"]
  1811. f.T["advertUrl"] = config.Sysconfig["advertUrl"]
  1812. return f.Render("/weixin/feedback.html")
  1813. }
  1814. f.ServeJson(map[string]interface{}{
  1815. "list": list,
  1816. })
  1817. return nil
  1818. }
  1819. func (f *Front) GetRecomKWs() {
  1820. recomKWChan <- true
  1821. defer func() {
  1822. <-recomKWChan
  1823. }()
  1824. value := f.GetString("value")
  1825. count, _ := f.GetInteger("count")
  1826. ves := strings.Split(value, " ")
  1827. var pairs []map[string]interface{}
  1828. for _, v := range ves {
  1829. Pw, _ := M.MostSimilar(strings.Split(v, "+"), []string{}, count)
  1830. for _, p := range Pw {
  1831. sim := p.Sim
  1832. word := p.Word
  1833. if sim < float32(config.Sysconfig["recommendThreshold"].(float64)) {
  1834. continue
  1835. }
  1836. if strings.HasSuffix(word, "路") || public.DealString(word) {
  1837. continue
  1838. }
  1839. pairs = append(pairs, map[string]interface{}{
  1840. "sim": sim,
  1841. "word": word,
  1842. })
  1843. }
  1844. }
  1845. f.ServeJson(pairs)
  1846. }
  1847. //记录用户行为--推荐关键词
  1848. func (f *Front) BehaviorRecord() {
  1849. flag := saveBehaviorRecord(f.Session(),
  1850. bson.M{
  1851. "s_word": f.GetString("value"),
  1852. "s_type": f.GetString("type"),
  1853. "s_source": f.GetString("source"),
  1854. })
  1855. f.ServeJson(bson.M{"flag": flag})
  1856. }
  1857. //记录用户行为
  1858. func saveBehaviorRecord(sess *httpsession.Session, data bson.M) bool {
  1859. userid, _ := sess.Get("userId").(string)
  1860. //if openId == "" {
  1861. // return false
  1862. //}
  1863. nickName, _ := sess.Get("s_nickname").(string)
  1864. //data["s_openid"] = openId
  1865. data["s_userid"] = userid
  1866. data["s_nickname"] = nickName
  1867. data["l_createtime"] = time.Now().Unix()
  1868. return len(mongodb.Save("behavior", data)) > 0
  1869. }
  1870. //取得剑鱼标讯博客的信息列表
  1871. func (f *Front) Jyblog(param /*参数*/ string) error {
  1872. querymap := map[string]string{}
  1873. if len(param) == 0 {
  1874. querymap = map[string]string{
  1875. "perPage": f.GetString("perPage"),
  1876. "currentPage": f.GetString("currentPage"),
  1877. "contentType": "jybk",
  1878. "query": f.GetString("query"),
  1879. }
  1880. } else {
  1881. //反转生成map
  1882. paramstr := param[1:]
  1883. bs, _ := base64.StdEncoding.DecodeString(paramstr)
  1884. json.Unmarshal(bs, &querymap)
  1885. }
  1886. var shareid = f.GetString("id")
  1887. if len(shareid) == 0 {
  1888. shareid = fmt.Sprintf("%s%d", config.Seoconfig["jybky"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
  1889. }
  1890. f.T["logid"] = config.Seoconfig["jybky"].(string)
  1891. f.DisableHttpCache()
  1892. shareid = se.EncodeString(shareid)
  1893. data, pagination := searhWebContentblog(querymap)
  1894. f.Render("/pc/jyblog.html", &xweb.T{"querymap": querymap, "data": data, "pagination": pagination, "shareid": shareid})
  1895. return nil
  1896. }
  1897. //实际的查询剑鱼标讯博客
  1898. func searhWebContentblog(querymap map[string]string) (*[]map[string]interface{}, *[]interface{}) {
  1899. perPage, _ := strconv.Atoi(querymap["perPage"])
  1900. currentPage, _ := strconv.Atoi(querymap["currentPage"])
  1901. //修复
  1902. if perPage == 0 {
  1903. perPage = 5
  1904. }
  1905. if currentPage < 1 {
  1906. currentPage = 1
  1907. }
  1908. contentType := querymap["contentType"]
  1909. queryStr := querymap["query"]
  1910. str := ``
  1911. if queryStr != "" {
  1912. str = `{
  1913. "match": {
  1914. "s_title": {
  1915. "query":"` + queryStr + `",
  1916. "operator": "and"
  1917. }
  1918. }
  1919. },{
  1920. "match": {
  1921. "s_content": {
  1922. "query":"` + queryStr + `"
  1923. }
  1924. }
  1925. }`
  1926. }
  1927. var tempQuery = `{"query": {
  1928. "bool": {
  1929. "must":[{"term":{"s_contenttype":"` + contentType + `"}}],
  1930. "should": [` + str + `],
  1931. "minimum_should_match": 0
  1932. }
  1933. }}`
  1934. var query = tempQuery[:len(tempQuery)-1] +
  1935. `,"highlight":{
  1936. "pre_tags":["<span class='highlight'>"],
  1937. "post_tags":["</span>"],
  1938. "fields":{
  1939. "s_title":{"force_source": true}
  1940. ,"s_content":{"force_source": true}
  1941. }
  1942. },"_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"]
  1943. ,"from":` + fmt.Sprintf("%v", ((currentPage-1)*perPage)) + `,
  1944. "size":` + fmt.Sprintf("%v", perPage) +
  1945. `,"sort":[{"releasetime":{"order":"desc"}}] }`
  1946. total := elastic.Count("content", "content", tempQuery)
  1947. //查询列表数据
  1948. client := elastic.GetEsConn()
  1949. defer elastic.DestoryEsConn(client)
  1950. if client == nil {
  1951. return nil, nil
  1952. }
  1953. searchResult, err := client.Search().Index("content").Type("content").Source(query).Do()
  1954. if err != nil {
  1955. return nil, nil
  1956. }
  1957. var res []map[string]interface{}
  1958. if searchResult.Hits != nil {
  1959. resNum := len(searchResult.Hits.Hits)
  1960. res = make([]map[string]interface{}, resNum)
  1961. for i, hit := range searchResult.Hits.Hits {
  1962. json.Unmarshal(*hit.Source, &res[i])
  1963. //查询结果数据加工处理
  1964. for k, v := range hit.Highlight {
  1965. res[i][k] = v[0]
  1966. }
  1967. s_content, _ := res[i]["s_content"].(string)
  1968. if len(s_content) > 500 {
  1969. res[i]["s_content"] = ""
  1970. } else {
  1971. con, _ := regexp.Compile("^[^<]*?>")
  1972. content := con.ReplaceAllString(s_content, "")
  1973. con1, _ := regexp.Compile("<[^>]*$")
  1974. res[i]["s_content"] = template.HTML(con1.ReplaceAllString(content, ""))
  1975. }
  1976. s_title, _ := res[i]["s_title"].(string)
  1977. res[i]["s_title"] = template.HTML(s_title)
  1978. tmpdate, _ := res[i]["l_createdate"]
  1979. res[i]["l_createdate"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate.(float64)), 0))
  1980. tmpdate1, _ := res[i]["releasetime"]
  1981. res[i]["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1.(float64)), 0))
  1982. res[i]["s_pic"] = config.Seoconfig["jyadd"].(string) + res[i]["s_pic"].(string)
  1983. res[i]["s_pic1"] = config.Seoconfig["jyadd"].(string) + res[i]["s_pic1"].(string)
  1984. res[i]["_id"] = se.EncodeString(res[i]["_id"].(string))
  1985. }
  1986. }
  1987. //生成分页
  1988. pagination := MakePagination(perPage, currentPage, int(total), querymap, "/jyblog/index_%s.html")
  1989. return &res, &pagination
  1990. }
  1991. //计算分页,分页显示规则
  1992. func MakePagination(perPage, currentPage, total int, param map[string]string, urltpl string) []interface{} {
  1993. var totalPages int //总页数
  1994. if total == 0 {
  1995. totalPages = 1
  1996. } else {
  1997. totalPages = (total - 1 + perPage) / perPage //总页数
  1998. }
  1999. ret := make([]interface{}, 3)
  2000. index := 0
  2001. prePage, nextPage := currentPage-1, currentPage+1
  2002. if prePage < 1 {
  2003. prePage = 1
  2004. }
  2005. if nextPage > totalPages {
  2006. nextPage = totalPages
  2007. }
  2008. param["currentPage"] = strconv.Itoa(prePage)
  2009. bs, _ := json.Marshal(param)
  2010. paramstr := base64.StdEncoding.EncodeToString(bs)
  2011. url := fmt.Sprintf(urltpl, paramstr)
  2012. iscurrent := currentPage == 1
  2013. ret[index] = map[string]interface{}{"page": "< 上一页", "url": url, "iscurrent": iscurrent}
  2014. index = index + 1
  2015. param["currentPage"] = strconv.Itoa(currentPage)
  2016. bs, _ = json.Marshal(param)
  2017. paramstr = base64.StdEncoding.EncodeToString(bs)
  2018. url = fmt.Sprintf(urltpl, paramstr)
  2019. iscurrent = currentPage == currentPage
  2020. ret[index] = map[string]interface{}{"page": currentPage, "url": url, "iscurrent": iscurrent}
  2021. index = index + 1
  2022. param["currentPage"] = strconv.Itoa(nextPage)
  2023. bs, _ = json.Marshal(param)
  2024. paramstr = base64.StdEncoding.EncodeToString(bs)
  2025. url = fmt.Sprintf(urltpl, paramstr)
  2026. iscurrent = currentPage == totalPages
  2027. ret[index] = map[string]interface{}{"page": "下一页 >", "url": url, "iscurrent": iscurrent}
  2028. return ret
  2029. }
  2030. //博客三级页
  2031. func (f *Front) Jybdetail(_id string) error {
  2032. var shareid = f.GetString("id")
  2033. if len(shareid) == 0 {
  2034. shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jybky"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
  2035. }
  2036. f.T["logid"] = config.Seoconfig["jybky"].(string)
  2037. shareid = se.EncodeString(shareid)
  2038. if ret := redis.Get("other", "jyblog_"+_id); ret != nil {
  2039. var retlist *map[string]interface{}
  2040. b, _ := json.Marshal(ret)
  2041. json.Unmarshal(b, &retlist)
  2042. (*retlist)["s_content"] = template.HTML((*retlist)["s_content"].(string))
  2043. (*retlist)["_id"] = (*retlist)["_id"].(string)
  2044. f.T["data"] = retlist
  2045. } else {
  2046. id := se.DecodeString(_id)
  2047. 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"`)
  2048. if r != nil {
  2049. tmpdate1, _ := (*r)["l_createdate"]
  2050. (*r)["l_createdate"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1.(float64)), 0))
  2051. tmpdate2, _ := (*r)["releasetime"]
  2052. (*r)["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate2.(float64)), 0))
  2053. (*r)["s_content"] = template.HTML((*r)["s_content"].(string))
  2054. (*r)["_id"] = se.EncodeString((*r)["_id"].(string))
  2055. (*r)["s_pic"] = (*r)["s_pic"].(string)
  2056. }
  2057. f.DisableHttpCache()
  2058. redis.Put("other", "jyblog_"+_id, r, 2*60*60)
  2059. f.T["data"] = r
  2060. }
  2061. f.T["shareid"] = shareid
  2062. return f.Render("/pc/jyblogdetail.html", &f.T)
  2063. }
  2064. //
  2065. func (f *Front) Blogpraise() error {
  2066. defer util.Catch()
  2067. id := se.DecodeString(f.GetString("id"))
  2068. stype := f.GetString("type")
  2069. flag := "F"
  2070. var blogflag = true
  2071. util.Try(func() {
  2072. if id != "" {
  2073. if stype == "up" {
  2074. blogflag = mongodb.Update("content", `{"_id":"`+id+`"}`, `{ "$inc" : { "praise" : 1 }}`, false, false)
  2075. } else if stype == "down" {
  2076. blogflag = mongodb.Update("content", `{"_id":"`+id+`"}`, `{ "$inc" : { "praise" : -1 }}`, false, false)
  2077. }
  2078. if blogflag {
  2079. flag = "T"
  2080. r, _ := mongodb.FindById("content", id, "")
  2081. elastic.UpdateNewDoc("content", "content", r)
  2082. redis.Del("other", "jyblog_"+f.GetString("id"))
  2083. }
  2084. }
  2085. }, func(e interface{}) {
  2086. log.Println("文章点赞出错", e)
  2087. })
  2088. f.ServeJson(map[string]interface{}{
  2089. "flag": flag,
  2090. })
  2091. return nil
  2092. }
  2093. //
  2094. func getRewardText() (string, string) {
  2095. rewardText, _ := config.Sysconfig["rewardText"].([]interface{})
  2096. advertText, _ := config.Sysconfig["advertText"].([]interface{})
  2097. randVal := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(rewardText))
  2098. if len(advertText) != 0 {
  2099. advVal := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(advertText))
  2100. return util.ObjToString(rewardText[randVal]), util.ObjToString(advertText[advVal])
  2101. } else {
  2102. return util.ObjToString(rewardText[randVal]), ""
  2103. }
  2104. }
  2105. //
  2106. func searchresulthtml(list *[]map[string]interface{}) string {
  2107. var listhtml = ""
  2108. var j = 1
  2109. for i := 0; i < len(*list); i++ {
  2110. listdata := (*list)[i]
  2111. j = i + 1
  2112. listhtml += `<li><div class="liLuceneList"><div class="luce-left"><em>` + strconv.Itoa(j) + `.</em>`
  2113. if listdata["title"] != "" {
  2114. listhtml += `<div class="left-title"><a onclick="noIn(this)" dataId="` + util.ObjToString(listdata["_id"]) + `" target="_blank">` + util.ObjToString(listdata["title"]) + `</a></div></div><div class="luce-right">`
  2115. }
  2116. area, _ := listdata["area"].(string)
  2117. area = strings.TrimSpace(area)
  2118. finalType, _ := listdata["subtype"].(string)
  2119. if finalType == "" {
  2120. finalType = util.ObjToString(listdata["toptype"])
  2121. }
  2122. if finalType == "" {
  2123. finalType = util.ObjToString(listdata["type"])
  2124. if finalType == "bid" {
  2125. finalType = "中标"
  2126. } else if finalType == "tender" {
  2127. finalType = "招标"
  2128. } else {
  2129. finalType = ""
  2130. }
  2131. }
  2132. industry := util.ObjToString(listdata["industry"])
  2133. stpadd, areaadd, indadd := classify(finalType, area, industry)
  2134. if area != "" && area != "A" {
  2135. listhtml += `<a href="/list/area/` + areaadd + `.html">` + area + `</a>`
  2136. } else {
  2137. listhtml += `<a href="#" style="display:none;"></a>`
  2138. }
  2139. if finalType != "" {
  2140. listhtml += `<a href="/list/stype/` + stpadd + `.html">` + finalType + `</a>`
  2141. } else {
  2142. listhtml += `<a href="#" style="display:none;"></a>`
  2143. }
  2144. //industry, _ := listdata["industry"].(string)
  2145. if industry != "" {
  2146. listhtml += `<a href="/list/industry/` + indadd + `.html">` + industry + `</a>`
  2147. } else {
  2148. listhtml += `<a href="#" style="display:none;"></a>`
  2149. }
  2150. acount := ""
  2151. if listdata["bidamount"] != nil {
  2152. acount = ConversionMoeny(listdata["bidamount"])
  2153. } else if listdata["budget"] != nil {
  2154. acount = ConversionMoeny(listdata["budget"])
  2155. }
  2156. if acount != "" {
  2157. listhtml += `<a>` + acount + `</a>`
  2158. } else {
  2159. listhtml += `<a href="#" style="display:none;"></a>`
  2160. }
  2161. publishtime, _ := listdata["publishtime"].(float64)
  2162. if publishtime != 0 {
  2163. diff := util.TimeDiff(time.Unix(util.Int64All(publishtime), 0))
  2164. if diff != "" {
  2165. listhtml += `<span class="com-time">` + diff + `</span>`
  2166. }
  2167. }
  2168. listhtml += `</div></div></li>`
  2169. }
  2170. return listhtml
  2171. }
  2172. //标签查询
  2173. func (f *Front) SearchResult(at, name string) error {
  2174. defer util.Catch()
  2175. if at == "stype" && name == "NJ" {
  2176. return f.Redirect("/jylab/supsearch/proposedProject.html")
  2177. }
  2178. var no = 5
  2179. var area = ""
  2180. var stype = ""
  2181. var industry = ""
  2182. var startPage, currentPage, limitcount int
  2183. limitcount = util.IntAll(config.Seoconfig["limitcount"])
  2184. var res = ""
  2185. var seotitle = ""
  2186. var seokeywords = ""
  2187. var seodescription = ""
  2188. if len(industrylist) > 0 {
  2189. f.T["industrylist"], f.T["sortArray"] = industrylist, sortArray
  2190. } else {
  2191. f.T["industrylist"], f.T["sortArray"] = getindustrys()
  2192. }
  2193. var shareid = f.GetString("id")
  2194. if len(shareid) == 0 {
  2195. shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jybqy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
  2196. }
  2197. f.T["logid"] = config.Seoconfig["jybqy"].(string)
  2198. if at == "area" {
  2199. log.Println("config.Seoconfig", config.Seoconfig)
  2200. log.Println("config.Seoconfig.area", config.Seoconfig["area"])
  2201. areamp, _ := config.Seoconfig["area"].(map[string]interface{})
  2202. if areamp != nil {
  2203. areamp1 := areamp[name].(map[string]interface{})
  2204. if areamp1 != nil {
  2205. area = areamp1["NAME"].(string)
  2206. seotitle = areamp1["TITLE"].(string)
  2207. seokeywords = areamp1["KEYWORDS"].(string)
  2208. seodescription = areamp1["DESCRIPTION"].(string)
  2209. }
  2210. }
  2211. } else if at == "stype" {
  2212. stypemp, _ := config.Seoconfig["stype"].(map[string]interface{})
  2213. if stypemp != nil {
  2214. stypemp1 := stypemp[name].(map[string]interface{})
  2215. if stypemp1 != nil {
  2216. stype = stypemp1["NAME"].(string)
  2217. seotitle = stypemp1["TITLE"].(string)
  2218. seokeywords = stypemp1["KEYWORDS"].(string)
  2219. seodescription = stypemp1["DESCRIPTION"].(string)
  2220. }
  2221. }
  2222. } else if at == "industry" {
  2223. industrymp, _ := config.Seoconfig["industry"].(map[string]interface{})
  2224. if industrymp != nil {
  2225. industrymp1 := industrymp[name].(map[string]interface{})
  2226. if industrymp1 != nil {
  2227. industry = industrymp1["NAME"].(string)
  2228. seotitle = industrymp1["TITLE"].(string)
  2229. seokeywords = industrymp1["KEYWORDS"].(string)
  2230. seodescription = industrymp1["DESCRIPTION"].(string)
  2231. }
  2232. }
  2233. }
  2234. f.T["seoarea"] = area
  2235. f.T["seostype"] = stype
  2236. f.T["seotitle"] = seotitle
  2237. f.T["seokeywords"] = seokeywords
  2238. f.T["seodption"] = seodescription
  2239. if area == "全国" {
  2240. return f.Redirect("/swordfish/searchinfolist.html")
  2241. }
  2242. if area != "" || stype != "" || industry != "" {
  2243. list := redis.Get("other", "classify_"+name)
  2244. query1 := `{"query": {"bool": {"must":[`
  2245. if area != "" {
  2246. query1 += `{"term":{"area":"` + area + `"}}`
  2247. } else if stype != "" {
  2248. query1 += `{"term":{"subtype":"` + stype + `"}}`
  2249. } else if industry != "" {
  2250. query1 += `{"term":{"industry":"` + industry + `"}}`
  2251. }
  2252. query1 += `],"should": [],"minimum_should_match": 0}}}`
  2253. query := getLastNewsQuery(area, "", stype, industry)
  2254. var datas *[]map[string]interface{}
  2255. if list == nil {
  2256. count := elastic.Count(INDEX, TYPE, query1)
  2257. //log.Println("count:", count, "----", query)
  2258. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  2259. currentPage = no
  2260. startPage = r.Intn(currentPage * limitcount)
  2261. count1 := util.IntAll(count)
  2262. if count1 < startPage || startPage < 0 {
  2263. startPage = 0
  2264. }
  2265. datas = elastic.GetPage(INDEX, TYPE, query, bidSearch_sort, `"_id","title","publishtime","toptype","subtype","type","area","href","bidopentime","winner","buyer","bidamount","budget","s_subscopeclass","projectname"`, startPage, limitcount)
  2266. //log.Println("datas:", *datas)
  2267. if len(*datas) > 0 {
  2268. for _, v := range *datas {
  2269. v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
  2270. }
  2271. }
  2272. redis.Put("other", "classify_"+name, datas, 2*60*60)
  2273. } else {
  2274. b, _ := json.Marshal(list)
  2275. json.Unmarshal(b, &datas)
  2276. }
  2277. public.BidListConvert(industry, datas)
  2278. res = searchresulthtml(datas)
  2279. f.T["res"] = res
  2280. f.T["area"] = area
  2281. f.T["stype"] = stype
  2282. f.T["industry"] = industry
  2283. f.T["classifyname"] = name
  2284. f.SetSession("paramarea", area)
  2285. f.SetSession("paraminfotype", stype)
  2286. f.T["shareid"] = se.EncodeString(shareid)
  2287. }
  2288. //
  2289. if userid := f.GetSession("userId"); userid != nil {
  2290. f.T["portraitpower"] = jylabutil.IsAuthorized(userid.(string), "i_portraitpower")
  2291. }
  2292. return f.Render("/pc/classifylist.html", &f.T)
  2293. }
  2294. //
  2295. func (f *Front) GetClassifyList() error {
  2296. defer util.Catch()
  2297. //判断用户是否开启超级搜索?
  2298. classifyname := f.GetString("classifyname")
  2299. data := redis.Get("other", "classify_"+classifyname)
  2300. f.ServeJson(map[string]interface{}{
  2301. "data": data,
  2302. })
  2303. return nil
  2304. }
  2305. //
  2306. func classify(stp, area, industry string) (string, string, string) {
  2307. var areas, _ = config.Seoconfig["area"].(map[string]interface{})
  2308. var stypes, _ = config.Seoconfig["stype"].(map[string]interface{})
  2309. var industrys, _ = config.Seoconfig["industry"].(map[string]interface{})
  2310. var tpadd = ""
  2311. var areaadd = ""
  2312. var induadd = ""
  2313. if area != "" && area != "A" {
  2314. for k, v := range areas {
  2315. if area == v.(map[string]interface{})["NAME"] {
  2316. areaadd = k
  2317. }
  2318. }
  2319. }
  2320. //
  2321. if stp != "" {
  2322. for k, v := range stypes {
  2323. if stp == v.(map[string]interface{})["NAME"] {
  2324. tpadd = k
  2325. }
  2326. }
  2327. }
  2328. //
  2329. if industry != "" {
  2330. for k, v := range industrys {
  2331. if strings.Contains(util.ObjToString(v.(map[string]interface{})["NAME"]), industry) {
  2332. induadd = k
  2333. }
  2334. }
  2335. }
  2336. return tpadd, areaadd, induadd
  2337. }
  2338. func (f *Front) HasPushHistory() {
  2339. //获取时间
  2340. var formatTime string
  2341. selectTime := f.GetString("selectTime")
  2342. // log.Println(selectTime, "---", f.GetString("area"))
  2343. lenStr := len([]rune(selectTime))
  2344. if selectTime != "" {
  2345. if selectTime != "undefined" && lenStr >= 10 {
  2346. selectTime = selectTime[0:10]
  2347. select_time, _ := strconv.ParseInt(selectTime, 10, 64)
  2348. //转化
  2349. formatTime = time.Unix(select_time, 0).Format("2006-01-02")
  2350. } else if lenStr < 10 {
  2351. formatTime = ""
  2352. }
  2353. }
  2354. userId := util.ObjToString(f.GetSession("userId"))
  2355. var industry_ = []string{}
  2356. if userId == "" {
  2357. return
  2358. }
  2359. user, _ := jy.SubscribePush.UserInfo(public.MQFW, userId)
  2360. hasKeyFlag := false
  2361. isVipFlag := false
  2362. isPassCount := false
  2363. isExpire := -1
  2364. tedayNum := time.Unix(time.Now().Unix(), 1).Format("20060102")
  2365. isOnTail := 0
  2366. var o_jy map[string]interface{}
  2367. isread := false
  2368. var keys []string
  2369. otherFlag := false
  2370. if user != nil {
  2371. o_jy, _ = (*user)["o_jy"].(map[string]interface{})
  2372. if o_jy != nil || len(o_jy) == 0 {
  2373. a_key, _ := o_jy["a_key"].([]interface{})
  2374. if a_key != nil {
  2375. for _, v := range a_key {
  2376. kv := util.ObjToMap(v)
  2377. keys = append(keys, util.ObjArrToStringArr((*kv)["key"].([]interface{}))...)
  2378. }
  2379. }
  2380. }
  2381. if util.IntAll((*user)["i_vip_status"]) == 1 || util.IntAll((*user)["i_vip_status"]) == 2 {
  2382. //
  2383. var threeRemind = int64(3 * 24 * 60 * 60)
  2384. var twoRemind = int64(2 * 24 * 60 * 60)
  2385. var oneRemind = int64(1 * 24 * 60 * 60)
  2386. var o_vipjy map[string]interface{}
  2387. if (*user)["isread"] != nil {
  2388. isread = (*user)["isread"].(bool)
  2389. }
  2390. o_vipjy, _ = (*user)["o_vipjy"].(map[string]interface{})
  2391. industry_ = util.ObjArrToStringArr(o_vipjy["a_buyerclass"].([]interface{}))
  2392. if o_vipjy["a_items"] != nil {
  2393. a_itmes := util.ObjArrToMapArr(o_vipjy["a_items"].([]interface{}))
  2394. hasKeyFlag = len(a_itmes) > 0
  2395. }
  2396. isVipFlag = true
  2397. isPassCount = redis.GetInt("pushcache_2_a", "oncecount_"+tedayNum+"_"+userId) >= 2000
  2398. isOnTail = util.IntAll((*user)["i_vip_status"])
  2399. _endtime := (*user)["l_vip_endtime"]
  2400. //是否到期
  2401. if util.Int64All(_endtime)-time.Now().Unix() < threeRemind && util.Int64All(_endtime)-time.Now().Unix() >= twoRemind {
  2402. isExpire = 3 //即将到期
  2403. } else if util.Int64All(_endtime)-time.Now().Unix() < twoRemind && util.Int64All(_endtime)-time.Now().Unix() >= oneRemind {
  2404. isExpire = 2 //即将到期
  2405. } else if util.Int64All(_endtime)-time.Now().Unix() < oneRemind && util.Int64All(_endtime)-time.Now().Unix() >= 0 {
  2406. isExpire = 1 //即将到期
  2407. }
  2408. //判断首次用户是否推送的带有”其他“
  2409. t, _ := time.ParseInLocation("2006-01-02", time.Now().Format("2006-01-02"), time.Local)
  2410. today_1 := t.Unix()
  2411. today_2 := t.AddDate(0, 0, 1).Unix()
  2412. if public.PushMysql.CountBySql("select count(1) as count from pushsubscribe where isvip =1 and userid =? and buyerclass=? and (date between ? and ? )", f.GetSession("userId"), 93, today_1, today_2) > 0 {
  2413. otherFlag = true
  2414. }
  2415. } else {
  2416. if (*user)["i_vip_status"] == nil {
  2417. isExpire = 0
  2418. } else {
  2419. isOnTail = util.IntAll((*user)["i_vip_status"])
  2420. }
  2421. if o_jy != nil || len(o_jy) == 0 {
  2422. a_key, _ := o_jy["a_key"].([]interface{})
  2423. hasKeyFlag = len(a_key) > 0
  2424. }
  2425. isPassCount = redis.GetInt("pushcache_2_a", "oncecount_"+tedayNum+"_"+userId) >= 150
  2426. }
  2427. }
  2428. pageNum, _ := f.GetInteger("pageNum")
  2429. if pageNum == 0 {
  2430. pageNum = 1
  2431. }
  2432. area := f.GetString("area")
  2433. hasNextPage, list := jy.SubscribePush.Datas(public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.Collection, public.DbConf.Mongodb.Bidding.Collection_back, public.PushMysql, userId, pageNum, formatTime, area)
  2434. if hasKeyFlag && len(list) == 0 && formatTime == "" && area == "" && !isVipFlag {
  2435. flag, data := jy.SubscribePush.MakeHistoryDatas(public.MQFW, public.PushMysql, userId, public.PushView)
  2436. if flag && data != nil {
  2437. jsonBytes, err := json.Marshal(data)
  2438. err = json.Unmarshal(jsonBytes, &list)
  2439. if err != nil {
  2440. log.Println("err:", err)
  2441. }
  2442. }
  2443. }
  2444. //
  2445. f.ServeJson(map[string]interface{}{
  2446. "haskey": hasKeyFlag,
  2447. "data": list,
  2448. "hasNextPage": hasNextPage,
  2449. "isInTSguide": isInTSguide(userId),
  2450. "isVipSub": isVipFlag,
  2451. "isPassCount": isPassCount,
  2452. "isExpire": isExpire,
  2453. "isOnTail": isOnTail,
  2454. "userId": util.EncodeArticleId(userId),
  2455. "keys": keys,
  2456. "otherFlag": otherFlag,
  2457. "industry": industry_,
  2458. "isread": isread,
  2459. })
  2460. }
  2461. //历史推送
  2462. func (f *Front) Historypush() error {
  2463. myopenid := util.ObjToString(f.GetSession("s_m_openid"))
  2464. userId := util.ObjToString(f.GetSession("userId"))
  2465. if myopenid == "" || userId == "" {
  2466. return f.Redirect("/swordfish/share/-1")
  2467. }
  2468. //
  2469. times := f.GetString("times")
  2470. //
  2471. // 打开推送
  2472. data, ok := mongodb.FindById("user", userId, nil)
  2473. if ok && data != nil && len(*data) > 0 {
  2474. //VIP服务到期
  2475. vipSubtips := (*data)["i_vip_subtips"]
  2476. if vipSubtips == 0 {
  2477. if mongodb.UpdateById("user", userId, bson.M{"$set": bson.M{"i_vip_subtips": 1}}) {
  2478. return f.Redirect("/front/vipsubscribe/renewPage/exprie")
  2479. }
  2480. }
  2481. }
  2482. f.T["forceShareFlag"] = public.CheckUserNeedForceShare(myopenid, public.ShareType_push)
  2483. mynickname, _ := f.Session().Get("s_nickname").(string)
  2484. myavatar, _ := f.Session().Get("s_avatar").(string)
  2485. f.T["nickname"] = mynickname
  2486. f.T["avatar"] = myavatar
  2487. f.T["signature"] = wx.SignJSSDK(f.Site() + f.Url())
  2488. f.T["openid"] = se.EncodeString(myopenid)
  2489. f.T["stime"] = times
  2490. f.T["isVip"] = util.IntAll((*data)["i_vip_status"]) > 0
  2491. f.T["isread"] = (*data)["isread"]
  2492. f.T["userId"] = userId
  2493. //直播活动和预热活动期间
  2494. if config.ActiveConfig.Live_Active_End > time.Now().Unix() && time.Now().Unix() > config.ActiveConfig.Live_Preheat_Start {
  2495. f.T["LiveState"] = true
  2496. }
  2497. return f.Render("/weixin/historypush.html", &f.T)
  2498. }
  2499. func (f *Front) HistorypushPaging() error {
  2500. pageNum, _ := f.GetInteger("pageNum")
  2501. //
  2502. selectTime := f.GetString("selectTime")
  2503. var formatTime string
  2504. if selectTime != "" {
  2505. selectTime = selectTime[0:10]
  2506. select_time, _ := strconv.ParseInt(selectTime, 10, 64)
  2507. //转化
  2508. formatTime = time.Unix(select_time, 0).Format("2006-01-02")
  2509. }
  2510. area := f.GetString("area")
  2511. log.Println("~~~~~:", formatTime, "~~~~", selectTime, "~~~", pageNum, "~~~", area)
  2512. //
  2513. userId := util.ObjToString(f.GetSession("userId"))
  2514. if userId != "" {
  2515. // user, firstPushTime := public.HistoryPush.UserInfo(userId)
  2516. // if user == nil {
  2517. // return nil
  2518. // }
  2519. hasNextPage, list := jy.SubscribePush.Datas(public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.Collection, public.DbConf.Mongodb.Bidding.Collection, public.PushMysql, userId, pageNum, formatTime, area)
  2520. // hasNextPage, list, _ := public.HistoryPush.Datas(userId, pageNum, firstPushTime, formatTime)
  2521. f.ServeJson(map[string]interface{}{
  2522. "hasNextPage": hasNextPage,
  2523. "data": list,
  2524. })
  2525. }
  2526. return nil
  2527. }
  2528. //电脑端招标订阅
  2529. func (m *Front) Subscribe() error {
  2530. var shareid = m.GetString("id")
  2531. if len(shareid) == 0 {
  2532. shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jydyy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[7:14], rand.Intn(9))
  2533. }
  2534. m.T["logid"] = config.Seoconfig["jydyy"].(string)
  2535. m.T["noshareid"] = shareid
  2536. m.T["shareid"] = se.EncodeString(shareid)
  2537. myopenid, _ := m.Session().Get("s_m_openid").(string)
  2538. m.T["openid"] = se.EncodeString(myopenid)
  2539. mynickname, _ := m.Session().Get("s_nickname").(string)
  2540. myavatar, _ := m.Session().Get("s_avatar").(string)
  2541. m.T["nickname"] = mynickname
  2542. m.T["avatar"] = myavatar
  2543. m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
  2544. return m.Render("/pc/subscribe_new.html", &m.T)
  2545. }
  2546. //获取高级查询所需的参数
  2547. func getShouldQueryMap(findfield, searchvalue, industry string) []map[string]string {
  2548. mps := []map[string]string{}
  2549. for _, v := range strings.Split(industry, ",") {
  2550. mp := map[string]string{}
  2551. for _, v := range strings.Split(searchvalue, "+") {
  2552. mp[v] = findfield
  2553. }
  2554. mp[v] = "s_subscopeclass"
  2555. mps = append(mps, mp)
  2556. }
  2557. return mps
  2558. }
  2559. func getSearchQuery(keyword, industry, minprice, maxprice, findfields, mustquery string) (qstr string) {
  2560. multi_match := `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
  2561. //match_phrase := `{"match_phrase": {"s_subscopeclass": "%s"}}`
  2562. query := `{"query":{"bool":{"must":[%s]}}}`
  2563. query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
  2564. query_bools_must := `{"bool":{"must":[{"range":{"bidamount":{%s}}}],"must_not":[{"term":{"bidamount":0}},{"term":{"budget":0}}]}},{"bool":{"must":[{"term":{"bidamount":0}},{"range":{"budget":{%s}}}]}},{"bool":{"must":[{"term":{"budget":0}},{"range":{"bidamount":{%s}}}]}}`
  2565. query_bool_must := `{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
  2566. //rge := `{"range": {"bidamount": {%s}}},{"range": {"budget": {%s}}}`
  2567. gte := `"gte": %s`
  2568. lte := `"lte": %s`
  2569. musts := []string{}
  2570. if mustquery != "" {
  2571. musts = append(musts, mustquery)
  2572. }
  2573. if keyword != "" {
  2574. multi_match = fmt.Sprintf(multi_match, "%s", findfields)
  2575. shoulds := []string{}
  2576. for _, v := range strings.Split(keyword, "+") {
  2577. shoulds = append(shoulds, fmt.Sprintf(multi_match, elastic.ReplaceYH(v)))
  2578. }
  2579. musts = append(musts, fmt.Sprintf(elastic.NgramMust, strings.Join(shoulds, ",")))
  2580. }
  2581. if industry != "" {
  2582. industrys := strings.Split(industry, ",")
  2583. musts = append(musts, fmt.Sprintf(query_bool_must, `"`+strings.Join(industrys, `","`)+`"`))
  2584. }
  2585. if minprice != "" || maxprice != "" {
  2586. sq := ``
  2587. if minprice != "" {
  2588. min, _ := strconv.ParseFloat(minprice, 64)
  2589. minprice = fmt.Sprintf("%.0f", min*10000)
  2590. if minprice == "0" {
  2591. minprice = ""
  2592. }
  2593. }
  2594. if maxprice != "" {
  2595. max, _ := strconv.ParseFloat(maxprice, 64)
  2596. maxprice = fmt.Sprintf("%.0f", max*10000)
  2597. if maxprice == "0" {
  2598. maxprice = ""
  2599. }
  2600. }
  2601. if minprice != "" {
  2602. sq += fmt.Sprintf(gte, minprice)
  2603. }
  2604. if minprice != "" && maxprice != "" {
  2605. sq += `,`
  2606. }
  2607. if maxprice != "" {
  2608. sq += fmt.Sprintf(lte, maxprice)
  2609. }
  2610. query_price := fmt.Sprintf(query_bool_should, fmt.Sprintf(query_bools_must, sq, sq, sq))
  2611. musts = append(musts, query_price)
  2612. }
  2613. qstr = fmt.Sprintf(query, strings.Join(musts, ","))
  2614. //log.Println("getSearchQuery:", qstr)
  2615. return
  2616. }
  2617. //
  2618. func wxPushViewDatas(index, itype string, keys []elastic.KeyConfig, allquery, findfields, SortQuery, fields string, start, limit int) *[]map[string]interface{} {
  2619. query_all := `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match":1}}}`
  2620. match_detail := `{"match":{"detail":{"query":"%s","operator": "and"}}}`
  2621. minq := `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
  2622. highlightStr := `%s: {"fragment_size": %d,"number_of_fragments": 1}`
  2623. query_bool := `{"bool":{"must":[%s],"should":[%s],"must_not":[%s],"minimum_should_match":1}}`
  2624. bool_must := `{"bool":{"must":[%s]}}`
  2625. //
  2626. searchDetail := strings.Contains(findfields, `"detail"`)
  2627. if len(keys) > 0 {
  2628. qstr := ""
  2629. new_minq := fmt.Sprintf(minq, "%s", `"title"`)
  2630. not_new_minq := fmt.Sprintf(minq, "%s", `"title"`) //排除词只查询标题
  2631. musts := []string{}
  2632. for _, qs_words := range keys {
  2633. mq := []string{}
  2634. notmq := []string{}
  2635. shoulds := []string{}
  2636. keywords := []string{}
  2637. boolmusts := []string{}
  2638. for _, qs_word := range qs_words.Keys {
  2639. qs_word = elastic.ReplaceYH(qs_word)
  2640. keywords = append(keywords, qs_word)
  2641. boolmusts = append(boolmusts, fmt.Sprintf(new_minq, qs_word))
  2642. }
  2643. shoulds = append(shoulds, fmt.Sprintf(bool_must, strings.Join(boolmusts, ",")))
  2644. if searchDetail {
  2645. shoulds = append(shoulds, fmt.Sprintf(match_detail, strings.Join(keywords, " ")))
  2646. }
  2647. for _, qs_word := range qs_words.NotKeys {
  2648. notmq = append(notmq, fmt.Sprintf(not_new_minq, elastic.ReplaceYH(qs_word)))
  2649. if searchDetail {
  2650. notmq = append(notmq, fmt.Sprintf(match_detail, elastic.ReplaceYH(qs_word)))
  2651. }
  2652. }
  2653. if len(qs_words.Areas) > 0 {
  2654. mq = append(mq, fmt.Sprintf(`{"terms":{"area":["%s"]}}`, strings.Join(qs_words.Areas, `","`)))
  2655. }
  2656. if len(qs_words.InfoTypes) > 0 {
  2657. mq = append(mq, fmt.Sprintf(`{"terms":{"toptype":["%s"]}}`, strings.Join(qs_words.InfoTypes, `","`)))
  2658. }
  2659. musts = append(musts, fmt.Sprintf(query_bool, strings.Join(mq, ","), strings.Join(shoulds, ","), strings.Join(notmq, ",")))
  2660. }
  2661. qstr = fmt.Sprintf(query_all, "", strings.Join(musts, ","))
  2662. qstr = fmt.Sprintf(elastic.FilterQuery, allquery, qstr[1:])
  2663. ws := []string{}
  2664. for _, w := range strings.Split(findfields, ",") {
  2665. ws = append(ws, fmt.Sprintf(highlightStr, w, 1))
  2666. }
  2667. qstr = qstr[:len(qstr)-1] + `,` + fmt.Sprintf(elastic.HL, strings.Join(ws, ",")) + `}`
  2668. if len(fields) > 0 {
  2669. qstr = qstr[:len(qstr)-1] + `,"_source":[` + fields + "]}"
  2670. }
  2671. if len(SortQuery) > 0 {
  2672. qstr = qstr[:len(qstr)-1] + `,"sort":` + SortQuery + `}`
  2673. }
  2674. if start > -1 {
  2675. qstr = qstr[:len(qstr)-1] + `,"from":` + strconv.Itoa(start) + `,"size":` + strconv.Itoa(limit) + "}"
  2676. }
  2677. //log.Println("jy-ngram-find", qstr)
  2678. return elastic.Get(index, itype, qstr)
  2679. } else {
  2680. return nil
  2681. }
  2682. }
  2683. //金额转化 金额:0-万元以下单位为元 ,万元以上至亿元以下单位为万元 ,亿元以上单位为亿元。保留 小数点后 2 位,不进行四舍五入。
  2684. func ConversionMoeny(i_money interface{}) string {
  2685. m := ""
  2686. if reflect.TypeOf(i_money).Name() == "float64" {
  2687. m = strconv.FormatFloat(util.Float64All(i_money), 'f', -1, 64)
  2688. } else {
  2689. m = util.ObjToString(i_money)
  2690. }
  2691. if m == "" {
  2692. return m
  2693. }
  2694. m_arr := strings.Split(m, ".")
  2695. m_1 := m_arr[0]
  2696. len_m1 := len([]rune(m_1))
  2697. if len_m1 >= 9 {
  2698. m = m_1[0:len_m1-8] + "." + m_1[len_m1-8:len_m1-6] + "亿元"
  2699. } else if len_m1 >= 5 {
  2700. m = m_1[0:len_m1-4] + "." + m_1[len_m1-4:len_m1-2] + "万元"
  2701. } else {
  2702. if len(m_arr) == 1 {
  2703. return m + ".00元"
  2704. }
  2705. m_2 := m_arr[1]
  2706. if len([]rune(m_2)) > 1 {
  2707. m_2 = m_2[0:2]
  2708. } else {
  2709. m_2 = m_2[0:1] + "0"
  2710. }
  2711. m = m_1 + "." + m_2 + "元"
  2712. }
  2713. return m
  2714. }