swordfish.go 91 KB

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