1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785 |
- package front
- import (
- "encoding/base64"
- "encoding/json"
- "fmt"
- "html/template"
- "jfw/config"
- "jfw/jylabutil"
- "jfw/jyutil"
- "jfw/public"
- "jfw/wx"
- "log"
- "math/rand"
- . "mongodb"
- "net/url"
- "qfw/util"
- "qfw/util/elastic"
- "qfw/util/redis"
- "reflect"
- "regexp"
- "strconv"
- "strings"
- "sync"
- "time"
- "qfw/util/jy"
- "github.com/go-xweb/httpsession"
- "github.com/go-xweb/xweb"
- . "github.com/thinxer/go-word2vec"
- "go.mongodb.org/mongo-driver/bson"
- "go.mongodb.org/mongo-driver/bson/primitive"
- )
- const (
- pc_pageSize = 50 //招标搜索分页--每页显示数量
- pc_maxPageNum = 10 //招标搜索分页--最大页数
- wx_maxPageNum = 20
- wx_pageSize = 50
- bidSearch_field_1 = `"_id","title","publishtime","toptype","subtype","type","area","city","s_subscopeclass","bidamount","budget","buyerclass"`
- bidSearch_field = bidSearch_field_1 + `,"bidopentime","winner","buyer","projectname","projectcode","projectinfo"`
- bidSearch_sort = `{"publishtime":-1}`
- )
- var M *Model
- var recomKWChan chan bool = make(chan bool, 1)
- var listlock = &sync.Mutex{}
- func init() {
- M, _ = Load("./zb.bin")
- }
- //剑鱼标讯推送三级页点赞暂弃 改成剑鱼标讯实验室点赞功能
- func (m *Front) Praise() error {
- defer util.Catch()
- var flag = "F"
- var praiseflag = true
- thistype := m.GetString("type")
- uod := m.GetString("uod")
- util.Try(func() {
- pdata, _ := mongodb.FindOneByField("praise", `{"s_type":"`+thistype+`"}`, `{"s_no":1}`)
- if len(*pdata) != 0 {
- if uod == "U" {
- praiseflag = mongodb.Update("praise", `{"s_type":"`+thistype+`"}`, `{ "$inc" : { "s_no" : 1 }}`, false, false)
- } else {
- praiseflag = mongodb.Update("praise", `{"s_type":"`+thistype+`"}`, `{ "$inc" : { "s_no" : -1 }}`, false, false)
- }
- if praiseflag {
- flag = "T"
- }
- }
- }, func(e interface{}) {
- log.Println("剑鱼标讯实验室点赞出错", e)
- })
- m.ServeJson(map[string]interface{}{
- "flag": flag,
- })
- return nil
- }
- //剑鱼标讯pc首页-统计
- func (m *Front) NewSordfishC() error {
- var shareid = m.GetString("id")
- if len(shareid) == 0 {
- shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jysy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
- } else {
- redis.Del("other", "jypcindex")
- }
- m.T["logid"] = config.Seoconfig["jysy"].(string)
- m.T["shareid"] = se.EncodeString(shareid)
- if ret := redis.Get("other", "jypcindex"); ret != nil {
- return m.SetBody([]byte(ret.(string)))
- } else {
- m.DisableHttpCache()
- content, _ := m.Render4Cache("/pc/index.html", &m.T)
- redis.Put("other", "jypcindex", string(content), 60*60*2)
- return m.SetBody(content)
- }
- }
- //剑鱼标讯pc首页
- func (m *Front) NewSordfish() error {
- ispc, _ := m.GetInteger("ispc")
- var shareid = m.GetString("id")
- if len(shareid) == 0 {
- shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jysy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
- } else {
- redis.Del("other", "jypcindex")
- }
- m.T["logid"] = config.Seoconfig["jysy"].(string)
- m.T["shareid"] = se.EncodeString(shareid)
- m.T["activestart"] = config.ActiveConfig.DoubleEleven.Active_Start
- m.T["activeend"] = config.ActiveConfig.DoubleEleven.Active_End
- regex, _ := regexp.Compile("(Android|Mobile)")
- if ispc == 0 && len(regex.FindAllString(m.Header("User-Agent"), -1)) > 0 {
- m.T["s_m_openid"] = util.ObjToString(m.GetSession("s_m_openid"))
- m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
- m.T["nickname"] = util.ObjToString(m.GetSession("s_nickname"))
- m.T["avatar"] = util.ObjToString(m.GetSession("s_avatar"))
- return m.Render("/pc/mobileindex.html", &m.T)
- } else {
- if ret := redis.Get("other", "jypcindex"); ret != nil {
- return m.SetBody([]byte(ret.(string)))
- } else {
- m.T["live_Preheat_Start"] = config.ActiveConfig.Live_Preheat_Start
- m.T["live_Active_End"] = config.ActiveConfig.Live_Active_End
- content, _ := m.Render4Cache("/pc/index.html", &m.T)
- redis.Put("other", "jypcindex", string(content), 60*60*2)
- return m.SetBody(content)
- }
- }
- return m.Render("/pc/index.html", &m.T)
- }
- func structureLastBidsHtml(lastBidNews *[]map[string]interface{}) (string, string) {
- var tmp int = 0
- var olCount int = 0
- var lbnHtml string = ""
- var olHtml string = `<ol class="carousel-indicators">`
- for i := 0; i < len(*lastBidNews); i++ {
- lastBidNew := (*lastBidNews)[i]
- if tmp == 0 {
- olHtml += `<li data-target="#lastBidNews" data-slide-to="` + strconv.Itoa(olCount) + `"`
- if olCount == 0 {
- olHtml += ` class="active"`
- }
- olHtml += `></li>`
- olCount++
- }
- tmp++
- if tmp == 1 {
- lbnHtml += `<div class="item`
- if i == 0 {
- lbnHtml += ` active`
- }
- lbnHtml += `"><ul>`
- }
- lbnHtml += `<li><div><a onclick="noIn(this),_czc.push(['_trackEvent', '最新招标信息', '点击扫码', 'lastBidNews'])" dataListId="` + util.EncodeArticleId2ByCheck(util.ObjToString(lastBidNew["_id"])) + `" target="_blank">` + strconv.Itoa(tmp) + `. ` + util.ObjToString(lastBidNew["title"]) + `</a></div><div>`
- area, _ := lastBidNew["area"].(string)
- area = strings.TrimSpace(area)
- finalType, _ := lastBidNew["subtype"].(string)
- if finalType == "" {
- finalType = util.ObjToString(lastBidNew["toptype"])
- }
- if finalType == "" {
- finalType = util.ObjToString(lastBidNew["type"])
- if finalType == "bid" {
- finalType = "中标"
- } else if finalType == "tender" {
- finalType = "招标"
- } else {
- finalType = ""
- }
- }
- industry := util.ObjToString(lastBidNew["industry"])
- stpadd, areaadd, induadd := classify(finalType, area, industry)
- if area != "" && area != "A" {
- lbnHtml += `<span class="com-area"><a href="/list/area/` + areaadd + `.html">` + area + `</a></span>`
- }
- if finalType != "" {
- lbnHtml += `<span class="com-type"><a href="/list/stype/` + stpadd + `.html">` + finalType + `</a></span>`
- }
- if util.ObjToString(lastBidNew["industry"]) != "" {
- lbnHtml += `<span class="com-industry"><a href="/list/industry/` + induadd + `.html">` + util.ObjToString(lastBidNew["industry"]) + `</a></span>`
- }
- publishtime, _ := lastBidNew["publishtime"].(float64)
- if publishtime != 0 {
- diff := util.TimeDiff(time.Unix(util.Int64All(publishtime), 0))
- if diff != "" {
- lbnHtml += `<span class="com-time" data-value="` + fmt.Sprint(util.Int64All(publishtime)) + `"><i class="glyphicon bofangjilu"></i>` + diff + `</span>`
- }
- }
- lbnHtml += `</div></li>`
- if tmp == 6 || i == len(*lastBidNews)-1 {
- tmp = 0
- lbnHtml += `</ul></div>`
- }
- }
- if olCount > 1 {
- olHtml += `</ol>`
- }
- return lbnHtml, olHtml
- }
- func detailLikeRpc(Interest []string, res *[]map[string]interface{}, flag bool) (mcontent map[string]interface{}) {
- //defer util.Catch()
- str := fmt.Sprintf("<div>根据您设置的关键词(%s),给您推送以下招标信息:</div>", strings.Join(Interest, ";"))
- //发送内容组合
- i := 0
- o_pushinfo := map[string]interface{}{}
- var details []string
- v := *res
- bmatch := false
- for _, k2 := range v {
- title := strings.Replace(k2["title"].(string), "\n", "", -1)
- province := util.ObjToString(k2["area"])
- if province != "" && province != "A" {
- title = `[<span class='area'>` + province + `</span>]` + title
- }
- i++
- str += "<div class='tslist'><span class='xh'>" + fmt.Sprintf("%d", i) + ".</span><a class='bt' target='_blank' sid='" + util.EncodeArticleId2ByCheck(BsonIdToSId(k2["_id"])) + "' eid='" + util.EncodeArticleId2ByCheck(BsonIdToSId(k2["_id"])) + "' href='" + k2["href"].(string) + "'>" + title + "</a></div>"
- o_pushinfo[strconv.Itoa(i)] = map[string]interface{}{
- "publishtime": k2["publishtime"],
- "stype": k2["type"],
- "topstype": k2["toptype"],
- "substype": k2["subtype"],
- }
- if flag {
- highlight, _ := k2["highlight"].(map[string][]string)
- detail := ""
- if len(highlight["detail"]) > 0 {
- detail = highlight["detail"][0]
- }
- details = append(details, detail)
- }
- }
- mcontent = map[string]interface{}{}
- if len(o_pushinfo) > 0 {
- bmatch = true
- mcontent["o_pushinfo"] = o_pushinfo
- mcontent["s_content"] = str
- mcontent["s_words"] = Interest
- }
- mcontent["bmatch"] = bmatch
- if flag {
- mcontent["details"] = details
- }
- return
- }
- //跳转到pc查询剑鱼标讯信息列表
- func (m *Front) Searchinfolist(p string) error {
- defer util.Catch()
- return m.Redirect("/jylab/supsearch/index.html")
- var shareid = m.GetString("id")
- if len(shareid) == 0 {
- shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jysslby"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
- }
- m.T["logid"] = config.Seoconfig["jysslby"].(string)
- m.T["shareid"] = se.EncodeString(shareid)
- keywords := m.GetString("keywords")
- searchvalue := jy.FilteKey(m.GetString("searchvalue"))
- area := m.GetString("area")
- publishtime := m.GetString("publishtime")
- toptype := m.GetString("toptype")
- subtype := m.GetString("subtype")
- industry := m.GetString("industry")
- minprice := m.GetString("minprice") //最低价格
- maxprice := m.GetString("maxprice") //最高价格
- selectType := m.GetString("selectType")
- selectTypesess := m.GetSession("selectType")
- if selectTypesess != nil && selectTypesess != "" {
- selectType = selectTypesess.(string)
- }
- if selectType == "" {
- selectType = "all"
- }
- var status = 1
- var count, totalPage int64
- tabularflag := ""
- var list *[]map[string]interface{}
- pages := make([]interface{}, 0)
- if len(searchvalue) > 0 || len(industry) > 0 {
- count, totalPage, list = getBidSearchData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, 0, true, selectType, "")
- //} else if m.Method() == "POST" {
- //status = 2
- //count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, "", 0, true, false)
- } else {
- status = 2
- if redis.Get("other", "index_list") == nil {
- intns := make([]int, 0)
- for i := 0; i < 10; i++ {
- if len(intns) == 0 {
- intns = append(intns, rand.Intn(100))
- } else {
- for {
- v := rand.Intn(intns[(i-1)] + 100)
- if v-intns[(i-1)] >= 30 {
- intns = append(intns, v)
- break
- }
- }
- }
- }
- for i := 0; i < 10; i++ {
- count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, tabularflag, intns[i], true, false)
- for k, v := range *list {
- v["k"] = (k + 1) + i*50
- t := time.Unix(util.Int64All(v["publishtime"]), 0)
- v["timetemp"] = fmt.Sprint(util.Int64All(v["publishtime"]))
- v["_id"] = util.EncodeArticleId2ByCheck(v["_id"].(string))
- v["time"] = util.TimeDiff(t)
- var stp = ""
- if v["subtype"] != nil {
- stp, _ = v["subtype"].(string)
- } else {
- stp = ""
- }
- if stp == "" && v["toptype"] != nil {
- stp, _ = v["toptype"].(string)
- }
- area, _ := v["area"].(string)
- v["href"] = util.CommonEncodeArticle("bdprivate", (util.GetRandom(22)))
- v["stypeadd"], v["areaadd"], _ = classify(stp, area, "")
- }
- pages = append(pages, list)
- }
- m.DisableHttpCache()
- redis.Put("other", "index_list", pages, 60*60*24*2)
- }
- }
- if status == 2 { //&& m.Method() == "GET" {
- pages := redis.Get("other", "index_list").([]interface{})
- p := util.IntAll(p)
- if p <= 0 || p > 10 {
- p = 1
- }
- if p-1 <= 0 {
- m.T["prev"] = 1
- } else {
- m.T["prev"] = p - 1
- }
- if p+1 >= 11 {
- m.T["next"] = 10
- } else {
- m.T["next"] = p + 1
- }
- m.T["cur"] = p
- m.T["list"] = pages[p-1]
- isopen, _ := m.GetInteger("isopen")
- m.T["isopen"] = isopen
- m.T["area"] = area
- m.T["publishtime"] = publishtime
- m.T["timeslot"] = m.GetString("timeslot")
- m.T["toptype"] = toptype
- m.T["subtype"] = subtype
- m.T["count"] = count
- m.T["totalPage"] = totalPage
- m.T["status"] = status
- m.T["keywords"] = keywords
- m.T["searchvalue"] = searchvalue
- m.T["selectType"] = selectType
- m.T["login"] = m.Session().Get("user")
- return m.Render("/pc/bidsearch_static.html", &m.T)
- } else {
- if list != nil {
- for _, v := range *list {
- v["_id"] = util.EncodeArticleId2ByCheck(v["_id"].(string))
- stp, _ := v["subtype"].(string)
- if stp == "" {
- stp, _ = v["toptype"].(string)
- }
- area, _ := v["area"].(string)
- v["stypeadd"], v["areaadd"], _ = classify(stp, area, "")
- //正文匹配检索关键词
- highlight, _ := v["highlight"].(map[string][]string)
- detail := ""
- for _, val := range highlight["detail"] {
- detail += public.ClearHtml.ReplaceAllString(val, "")
- }
- v["href"] = util.CommonEncodeArticle("bdprivate", (util.GetRandom(22)))
- v["detail"] = detail
- }
- }
- m.T["list"] = list
- isopen, _ := m.GetInteger("isopen")
- m.T["isopen"] = isopen
- m.T["area"] = area
- m.T["publishtime"] = publishtime
- m.T["timeslot"] = m.GetString("timeslot")
- m.T["toptype"] = toptype
- m.T["subtype"] = subtype
- m.T["count"] = count
- m.T["status"] = status
- m.T["keywords"] = keywords
- m.T["searchvalue"] = searchvalue
- m.T["selectType"] = selectType
- m.T["login"] = m.Session().Get("user")
- m.SetSession("paramkey", keywords)
- if publishtime == "lately-7" {
- m.SetSession("parampublishtime", "最近7天")
- } else if publishtime == "lately-30" {
- m.SetSession("parampublishtime", "最近30天")
- } else if publishtime == "thisyear" {
- m.SetSession("parampublishtime", "去年")
- } else {
- m.SetSession("parampublishtime", publishtime)
- }
- m.SetSession("paramarea", area)
- if subtype != "" {
- m.SetSession("paraminfotype", subtype)
- } else {
- m.SetSession("paraminfotype", toptype)
- }
- return m.Render("/pc/bidsearch.html", &m.T)
- }
- }
- //ajax分页请求
- func (m *Front) PcAjaxReq() {
- tabularflag := m.GetString("tabularflag")
- if tabularflag == "Y" && m.GetSession("userId") == nil {
- //判断用户是否登录进行表格查询,否则返回基本数据
- tabularflag = ""
- }
- reqType := m.GetString("reqType")
- //获取最新招标信息
- if reqType == "lastBids" {
- //ls := elastic.GetPage(INDEX, TYPE, "{}", bidSearch_sort, bidSearch_field_1, 0, 18)
- //jyutil.BidListConvert("", ls)
- ls := Newbids("")
- if len(ls) >= 18 {
- ls = ls[:18]
- }
- m.ServeJson(map[string]interface{}{
- "list": ls,
- })
- return
- }
- currentPage, _ := m.GetInteger("pageNumber")
- if currentPage > pc_maxPageNum {
- currentPage = pc_maxPageNum
- }
- start := (currentPage - 1) * pc_pageSize
- area := m.GetString("area")
- subtype := m.GetString("subtype")
- publishtime := m.GetString("publishtime")
- selectType := m.GetString("selectType")
- industry := strings.TrimSpace(m.GetString("industry"))
- minprice := m.GetString("minprice") //最低价格
- maxprice := m.GetString("maxprice") //最高价格
- m.SetSession("selectType", selectType)
- //只有前20条 有全字段,
- if subtype != "拟建" && currentPage != 1 {
- tabularflag = ""
- }
- if selectType == "" {
- selectType = "all"
- }
- b_word, a_word, s_word := jy.InterceptSearchKW(m.GetString("searchvalue"), selectType == "all", len(industry) == 0)
- var list *[]map[string]interface{}
- var secondList []map[string]interface{}
- var count, totalPage int64
- status, _ := m.GetInteger("status")
- isLimit := 1
- limitFlag := false
- secondFlag := ""
- secondKWS := ""
- pcAjaxFlag := ""
- if len(s_word) > 0 || len(industry) > 0 {
- if reqType == "filter" {
- if status == 1 {
- count, totalPage, list = getBidSearchData(s_word, area, publishtime, subtype, industry, minprice, maxprice, 0, true, selectType, tabularflag)
- } else if status == 2 {
- //count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, tabularflag, 0, true, true)
- }
- } else if reqType == "bidSearch" {
- //全文检索限制
- if selectType == "all" {
- limitFlag = public.Lst.Flag
- isLimit = public.Lst.IsLimited(m.Request, m.ResponseWriter, m.Session())
- if isLimit == 1 { //没有被限制
- defer public.Lst.Limit()
- }
- }
- if isLimit == 1 {
- if limitFlag {
- if start == 0 {
- limit_count := public.Lst.TotalPage * pc_pageSize
- count, totalPage, list = getBidSearchData_new(s_word, area, publishtime, subtype, industry, minprice, maxprice, 0, limit_count, true, selectType, tabularflag)
- if totalPage > int64(public.Lst.TotalPage) {
- totalPage = int64(public.Lst.TotalPage)
- }
- if count > int64(limit_count) {
- count = int64(limit_count)
- }
- }
- } else {
- count, totalPage, list = getBidSearchData(s_word, area, publishtime, subtype, industry, minprice, maxprice, start, true, selectType, tabularflag)
- }
- listSize := 0
- if list != nil {
- listSize = len(*list)
- }
- if len([]rune(s_word)) > 3 && int(count) < pc_pageSize && start == 0 {
- secondKWS = jy.HttpEs(s_word, "ik_smart", public.DbConf.Elasticsearch.Main.Address)
- findfields := `"title"`
- qstr := getSearchQuery(secondKWS, industry, minprice, maxprice, findfields, getBidSearchQuery(area, publishtime, subtype))
- secRel := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, 0, 2*pc_pageSize, 0, false)
- if secRel != nil {
- public.BidListConvert(industry, secRel)
- }
- if list != nil {
- list = public.MapArrSortMerge(*list, *secRel, "_id", "publishtime")
- } else {
- list = secRel
- }
- if len(*secRel) > 0 {
- if secondKWS != "" {
- s_word += "+" + secondKWS
- }
- secondFlag = "T"
- pcAjaxFlag = "T"
- }
- }
- public.SaveUserSearchLog(m.Request, util.ObjToString(m.GetSession("userId")), -1, "pc", "超级搜索", map[string]interface{}{
- "search_word": s_word,
- "search_area": area,
- "search_price": []string{minprice, maxprice},
- "search_publishtime": publishtime,
- "search_type": subtype,
- "search_industry": industry,
- "pagenum": currentPage,
- "pagesize": listSize,
- })
- }
- } else if reqType == "lastNews" {
- _, list = getLastNewsData(s_word, area, publishtime, subtype, industry, minprice, maxprice, tabularflag, start, false, true)
- }
- }
- if list != nil && len(*list) > 0 {
- for _, v := range *list {
- if v["_id"] != nil {
- v["_id"] = util.EncodeArticleId2ByCheck(v["_id"].(string))
- }
- stp, ok := v["subtype"].(string)
- if ok && stp == "" {
- stp = v["toptype"].(string)
- }
- area, ok := v["area"].(string)
- indtry := util.ObjToString(v["industry"])
- v["stypeadd"], v["areaadd"], v["indadd"] = classify(stp, area, indtry)
- //正文匹配检索关键词
- highlight, _ := v["highlight"].(map[string][]string)
- detail := ""
- for _, val := range highlight["detail"] {
- detail += public.ClearHtml.ReplaceAllString(val, "")
- }
- v["detail"] = detail
- v["href"] = util.EncodeArticleId2ByCheck(util.GetRandom(20))
- }
- if secondFlag != "" {
- if len(*list) > pc_pageSize {
- secondList = (*list)[pc_pageSize:]
- if len(secondList) > pc_pageSize {
- secondList = secondList[:pc_pageSize]
- }
- *list = (*list)[:pc_pageSize]
- totalPage = 2
- } else {
- totalPage = 1
- }
- }
- }
- //只有前20条
- m.ServeJson(map[string]interface{}{
- "limitFlag": limitFlag,
- "status": isLimit,
- "list": list,
- "count": count,
- "totalPage": totalPage,
- "interceptWord": a_word,
- "keywords": b_word,
- "searchvalue": s_word,
- "secondFlag": secondFlag,
- "secondList": secondList,
- "pcAjaxFlag": pcAjaxFlag,
- })
- }
- /**
- **页面搜索
- **/
- func getBidSearchData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice string, start int, isGetCount bool, selectType, tabularflag string) (count, totalPage int64, list *[]map[string]interface{}) {
- count, totalPage, list = getBidSearchData_new(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, start, pc_pageSize, isGetCount, selectType, tabularflag)
- return
- }
- 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{}) {
- //selectType:全文搜索(all)、标题搜索(title)
- findfields := `"title"`
- if selectType == "all" {
- findfields = `"title","detail"`
- }
- qstr := getSearchQuery(searchvalue, industry, minprice, maxprice, findfields, getBidSearchQuery(area, publishtime, subtype))
- if isGetCount && qstr != "" && start == 0 {
- count = elastic.Count(INDEX, TYPE, qstr)
- }
- if !isGetCount || count > 0 || start > 0 {
- var repl *[]map[string]interface{}
- if selectType == "all" {
- //全文搜索
- if tabularflag == "Y" {
- repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, start, pageSize, 115, true)
- } else {
- repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field_1, start, pageSize, 115, true)
- }
- } else {
- //标题搜索
- if tabularflag == "Y" {
- repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, start, pageSize, 0, false)
- } else {
- repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field_1, start, pageSize, 0, false)
- }
- }
- if repl != nil && *repl != nil && len(*repl) > 0 {
- public.BidListConvert(industry, repl)
- list = repl
- }
- }
- limitCount := int64(pc_pageSize * pc_maxPageNum)
- if count > limitCount {
- count = limitCount
- }
- totalPage = (count + int64(pc_pageSize) - 1) / int64(pc_pageSize)
- return
- }
- func getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, tabularflag string, start int, isGetCount bool, highlight bool) (count int64, list *[]map[string]interface{}) {
- //最新招标信息
- findfields := `"title"`
- qstr := getSearchQuery(searchvalue, industry, minprice, maxprice, findfields, getBidSearchQuery(area, publishtime, subtype))
- if isGetCount {
- count = elastic.Count(INDEX, TYPE, qstr)
- }
- if !isGetCount || count > 0 {
- if tabularflag == "Y" {
- repl := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, start, pc_pageSize, 115, highlight)
- if repl != nil && *repl != nil && len(*repl) > 0 {
- public.BidListConvert(industry, repl)
- list = repl
- }
- } else {
- repl := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field_1, start, pc_pageSize, 115, highlight)
- if repl != nil && *repl != nil && len(*repl) > 0 {
- public.BidListConvert(industry, repl)
- list = repl
- }
- }
- }
- limitCount := int64(pc_pageSize * pc_maxPageNum)
- if count > limitCount {
- count = limitCount
- }
- return
- }
- func getBidSearchQuery(area, publishtime, subtype string) string {
- query := ``
- if area != "" {
- query += `{"terms":{"area":[`
- for k, v := range strings.Split(area, ",") {
- if k > 0 {
- query += `,`
- }
- query += `"` + v + `"`
- }
- query += `]}}`
- }
- if publishtime != "" {
- if len(query) > 0 {
- query += ","
- }
- starttime, endtime := "", ""
- now := time.Now()
- if publishtime == "lately-7" { //最近7天
- starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
- } else if publishtime == "lately-30" { //最近30天
- starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
- } else if publishtime == "thisyear" { //去年
- starttime = fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Unix())
- endtime = fmt.Sprint(time.Date(now.Year()-1, 12, 31, 23, 59, 59, 0, time.Local).Unix())
- } else {
- starttime = strings.Split(publishtime, "_")[0]
- endtime = strings.Split(publishtime, "_")[1]
- etTime := time.Now()
- if endtime != "" {
- et, _ := strconv.ParseInt(endtime, 0, 64)
- etTime = time.Unix(et, 0)
- }
- endtime = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Unix())
- }
- query += `{"range":{"publishtime":{`
- if starttime != "" {
- query += `"gte":` + starttime
- }
- if starttime != "" && endtime != "" {
- query += `,`
- }
- if endtime != "" {
- query += `"lt":` + endtime
- }
- query += `}}}`
- }
- if subtype != "" {
- if len(query) > 0 {
- query += ","
- }
- query += `{"terms":{"subtype":[`
- for k, v := range strings.Split(subtype, ",") {
- if k > 0 {
- query += `,`
- }
- query += `"` + v + `"`
- }
- query += `]}}`
- }
- return query
- }
- func getLastNewsQuery(area, publishtime, subtype, industry string) string {
- query := ``
- if area != "" {
- query += `"area":{"$in":[`
- for k, v := range strings.Split(area, ",") {
- if k > 0 {
- query += `,`
- }
- query += `"` + v + `"`
- }
- query += `]}`
- }
- if publishtime != "" {
- if len(query) > 0 {
- query += ","
- }
- starttime, endtime := "", ""
- now := time.Now()
- if publishtime == "lately-7" { //最近7天
- starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
- } else if publishtime == "lately-30" { //最近30天
- starttime = fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
- } else if publishtime == "thisyear" { //去年
- starttime = fmt.Sprint(time.Date(now.Year()-1, 1, 1, 0, 0, 0, 0, time.Local).Unix())
- endtime = fmt.Sprint(time.Date(now.Year()-1, 12, 31, 23, 59, 59, 0, time.Local).Unix())
- } else {
- starttime = strings.Split(publishtime, "_")[0]
- endtime = strings.Split(publishtime, "_")[1]
- et, _ := strconv.ParseInt(endtime, 0, 64)
- etTime := time.Unix(et, 0)
- endtime = fmt.Sprint(time.Date(etTime.Year(), etTime.Month(), etTime.Day()+1, 0, 0, 0, 0, time.Local).Unix())
- }
- if starttime != "" && endtime != "" {
- query += `"$and":[{"publishtime":{"$gte":` + starttime + `}},{"publishtime":{"$lt":` + endtime + `}}]`
- } else if starttime != "" && endtime == "" {
- query += `"publishtime":{"$gte":` + starttime + `}`
- } else if starttime == "" && endtime != "" {
- query += `"publishtime":{"$lt":` + endtime + `}`
- }
- }
- if subtype != "" {
- if len(query) > 0 {
- query += ","
- }
- query += `"subtype":{"$in":[`
- for k, v := range strings.Split(subtype, ",") {
- if k > 0 {
- query += `,`
- }
- query += `"` + v + `"`
- }
- query += `]}`
- }
- //
- if industry != "" {
- if len(query) > 0 {
- query += ","
- }
- query += `"s_subscopeclass":{"$in":[`
- for k, v := range strings.Split(industry, ",") {
- if k > 0 {
- query += `,`
- }
- query += `"` + v + `"`
- }
- query += `]}`
- }
- query = `{` + query + `}`
- return query
- }
- //进入订阅页面
- func (m *Front) Getpage() error {
- defer util.Catch()
- s_type := ""
- userid := util.ObjToString(m.GetSession("userId"))
- var msgset map[string]interface{}
- if userid != "" {
- one, _ := mongodb.FindById("user", userid, `{"o_jy":1}`)
- msg := (*one)["o_jy"]
- if msg != "" && msg != nil {
- msgset = msg.(map[string]interface{})
- }
- s_type = "tender"
- }
- m.ServeJson(map[string]interface{}{
- "msgset": msgset,
- "s_type": s_type,
- })
- return nil
- }
- //搜索结果,ajax分页请求
- func (m *Front) WxsearchlistPaging() {
- defer util.Catch()
- userid := m.GetSession("userId")
- var list *[]map[string]interface{}
- var secRel *[]map[string]interface{}
- pageNum, _ := m.GetInteger("pageNum")
- if userid != nil && pageNum <= wx_maxPageNum {
- //历史记录和订阅查询
- one, _ := mongodb.FindById("user", userid.(string), `{"o_jy":1}`)
- history := redis.GetStr("other", "s_"+userid.(string))
- arrs := strings.Split(history, ",")
- searchvalue := strings.TrimSpace(m.GetString("searchvalue"))
- var b_word, a_word string
- isLimit := 1
- limitFlag := false
- secondKWS := ""
- secondFlag := ""
- var secondList []map[string]interface{}
- if searchvalue != "" {
- filed := ""
- if pageNum == 1 {
- filed = bidSearch_field
- } else {
- filed = bidSearch_field_1
- }
- selectType := m.GetString("selectType")
- subtype := m.GetString("subtype")
- scope := m.GetString("scope")
- publishtime := m.GetString("publishtime")
- industry := strings.TrimSpace(m.GetString("industry"))
- m.SetSession("industry", industry)
- minprice := m.GetString("minprice")
- maxprice := m.GetString("maxprice")
- //全文检索限制
- if selectType == "all" {
- limitFlag = public.Lst.Flag
- isLimit = public.Lst.IsLimited(m.Request, m.ResponseWriter, m.Session())
- if isLimit == 1 { //没有被限制
- defer public.Lst.Limit()
- }
- }
- if isLimit == 1 {
- s_word := ""
- if limitFlag {
- if pageNum == 1 {
- list, b_word, a_word, s_word = getWxsearchlistData_new(searchvalue, scope, publishtime, subtype, industry, minprice, maxprice, pageNum, public.Lst.TotalPage*wx_pageSize, selectType, filed)
- }
- } else {
- list, b_word, a_word, s_word = getWxsearchlistData(searchvalue, scope, publishtime, subtype, industry, minprice, maxprice, pageNum, selectType, filed)
- }
- listSize := 0
- if list != nil {
- listSize = len(*list)
- }
- if len([]rune(s_word)) > 3 && listSize < pc_pageSize && pageNum == 1 {
- secondKWS = jy.HttpEs(s_word, "ik_smart", public.DbConf.Elasticsearch.Main.Address)
- findfields := `"title"`
- qstr := getSearchQuery(secondKWS, industry, minprice, maxprice, findfields, getBidSearchQuery(scope, publishtime, subtype))
- secRel = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, filed, 0, 2*pc_pageSize, 0, false)
- if secRel != nil && len(*secRel) > 0 {
- public.BidListConvert(industry, secRel)
- for _, v := range *secRel {
- v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
- }
- if list != nil {
- list = public.MapArrSortMerge(*list, *secRel, "_id", "publishtime")
- } else {
- list = secRel
- }
- secondFlag = "T"
- if len(*list) > pc_pageSize && selectType == "title" {
- secondList = (*list)[pc_pageSize:]
- if len(secondList) > pc_pageSize {
- secondList = secondList[:pc_pageSize]
- }
- *list = (*list)[:pc_pageSize]
- }
- } else {
- secondKWS = ""
- }
- }
- public.SaveUserSearchLog(m.Request, util.ObjToString(m.GetSession("userId")), -1, "wx", "超级搜索", map[string]interface{}{
- "search_word": searchvalue,
- "search_area": scope,
- "search_price": []string{minprice, maxprice},
- "search_publishtime": publishtime,
- "search_type": subtype,
- "search_industry": industry,
- "pagenum": pageNum,
- "pagesize": listSize,
- })
- }
- //新增历史记录
- if history == "" {
- arrs = make([]string, 0)
- }
- for k, v := range arrs {
- if v == strings.Trim(searchvalue, " ") {
- arrs = append(arrs[:k], arrs[k+1:]...)
- break
- }
- }
- arrs = append(arrs, searchvalue)
- if len(arrs) > 10 {
- arrs = arrs[1:11]
- }
- redis.Del("other", "s_"+userid.(string))
- redis.Put("other", "s_"+userid.(string), strings.Join(arrs, ","), -1)
- }
- m.T["history"] = arrs
- if one != nil && len(*one) > 0 {
- o_jy, _ := (*one)["o_jy"].(map[string]interface{})
- a_key, _ := o_jy["a_key"].([]interface{})
- var keys []interface{}
- for _, v := range a_key {
- keyMap, _ := v.(map[string]interface{})
- key, _ := keyMap["key"].([]interface{})
- keys = append(keys, key)
- }
- m.T["msgset"] = keys
- }
- hasNextPage := list != nil && len(*list) == wx_pageSize && pageNum < wx_maxPageNum
- if limitFlag {
- hasNextPage = false
- }
- m.ServeJson(map[string]interface{}{
- "limitFlag": limitFlag,
- "status": isLimit,
- "list": list,
- "hasNextPage": hasNextPage,
- "history": m.T["history"],
- "msgset": m.T["msgset"],
- "interceptWord": a_word,
- "keyWord": b_word,
- "secondFlag": secondFlag,
- "secondList": secondList,
- "secondKWS": secondKWS,
- })
- }
- }
- //微信端删除历史搜索
- func (m *Front) DelWxHistorySearch() {
- defer util.Catch()
- //定义一个无用参数作为返回值
- var rt string = "rt"
- userId := m.GetSession("userId")
- history := redis.GetStr("other", "s_"+userId.(string))
- if len(history) > 0 || history != "" {
- redis.Del("other", "s_"+userId.(string))
- }
- m.ServeJson(map[string]interface{}{
- "rt": rt,
- })
- }
- //微信端搜索
- 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) {
- return getWxsearchlistData_new(keywords, scope, publishtime, subtype, industry, minprice, maxprice, pageNum, wx_pageSize, selectType, field)
- }
- 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) {
- b_word, a_word, s_word = jy.InterceptSearchKW(keywords, selectType == "all", len(industry) == 0)
- if len(b_word) == 0 {
- return list, b_word, a_word, s_word
- }
- findfields := `"title"`
- if selectType == "all" {
- findfields = `"title","detail"`
- }
- qstr := getSearchQuery(s_word, industry, minprice, maxprice, findfields, getBidSearchQuery(scope, publishtime, subtype))
- if selectType == "all" { //全文搜索
- list = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, field, (pageNum-1)*pageSize, pageSize, 100, true)
- } else { //标题搜索
- list = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, field, (pageNum-1)*pageSize, pageSize, 100, false)
- }
- if list != nil {
- public.BidListConvert(industry, list)
- for _, v := range *list {
- v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
- }
- }
- return list, b_word, a_word, s_word
- }
- //查看原文跳转
- func (m *Front) VisitRedirect() {
- defer util.Catch()
- sid := m.GetString("id")
- // regex, _ := regexp.Compile("(Android|Mobile)")
- // if len(regex.FindAllString(m.Header("User-Agent"), -1)) <= 0 {
- // m.Redirect("/article/p/" + sid + ".html")
- // }
- surl := m.GetString("url")
- sds := m.GetString("keywords")
- m.T["keywords"] = sds
- shareopenid := m.GetString("openid")
- if shareopenid != "" {
- m.T["shareopenid"] = shareopenid
- }
- myopenid, _ := m.Session().Get("s_m_openid").(string)
- if myopenid == "" {
- myopenid = shareopenid
- m.T["openid"] = myopenid //"-1"
- } else {
- m.T["openid"] = se.EncodeString(myopenid) //"-1"
- }
- mynickname, _ := m.Session().Get("s_nickname").(string)
- myavatar, _ := m.Session().Get("s_avatar").(string)
- m.T["nickname"] = mynickname
- m.T["avatar"] = myavatar
- m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
- userId, _ := m.GetSession("userId").(string)
- var obj map[string]interface{}
- obj = wxvisitD(sid, userId, myopenid)
- if len(obj) > 0 {
- //获取打赏文案
- m.T["rewardText"], m.T["advertText"] = getRewardText()
- m.T["obj"] = obj
- m.Render("/weixin/wxinfocontent.html", &m.T)
- return
- }
- if surl != "" {
- m.Redirect(surl)
- }
- }
- func wxvisitD(sid, userId, openId string) (objdata map[string]interface{}) {
- defer util.Catch()
- var obj map[string]interface{}
- if len(sid) > 5 {
- brobj, ok := mongodb.Find("bidding_rec", bson.M{"s_id": sid}, `{"l_recoverydate":-1}`, nil, false, 0, 1)
- if ok && (*brobj) != nil && len(*brobj) == 1 && (*brobj)[0] != nil {
- obj = (*brobj)[0]
- } else {
- aobj, ok := public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection, sid, nil)
- if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
- aobj, ok = public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection_back, sid, nil)
- }
- //aobj, ok := elastic.GetByIdField("bidding", "bidding", sid, ""), true
- obj = *aobj
- }
- if ok && obj != nil && len(obj) >= 3 {
- fwt := util.ObjToString(obj["subtype"])
- ltfd := getLowestField(fwt)
- if ltfd != "" {
- obj["fwtsname"] = obj[ltfd]
- obj["fwtscode"] = ltfd
- }
- obj["_id"] = util.EncodeArticleId2ByCheck(sid)
- obj["url"] = obj["href"]
- pt := obj["publishtime"]
- obj["l_publishtime"] = pt
- obj["publishtime"] = util.FormatDateWithObj(&pt, util.Date_Full_Layout)
- //查询是否关注
- obj["followFlag"] = false
- obj["hasSession"] = false
- var infoformat = obj["infoformat"]
- if infoformat != nil && infoformat != "" {
- obj["infoformat"] = util.IntAll(infoformat)
- }
- if userId != "" {
- pcode, _ := obj["projectcode"].(string)
- pname, _ := obj["projectname"].(string)
- titleTmp := util.ObjToString(obj["title"])
- obj["followFlag"], obj["followId"] = MFollow(userId, pname, pcode, titleTmp, openId)
- if len([]rune(titleTmp)) > 100 {
- titleTmp = string([]rune(titleTmp)[:100]) + "..."
- }
- titleTmp = public.ClearHtml.ReplaceAllString(titleTmp, "")
- obj["title"] = titleTmp
- obj["hasSession"] = true
- }
- if strings.Trim(util.ObjToString(obj["detail"]), " ") == "" {
- obj["detail"] = ""
- }
- }
- }
- return obj
- }
- //获取权重最低的字段
- func getLowestField(subtype string) string {
- fields := util.ObjToMap(config.Sysconfig["recoveryField"])
- result := ""
- if subtype != "招标" {
- subtype = "其他"
- }
- var fieldsArr = util.ObjArrToMapArr((*fields)[subtype].([]interface{}))
- i := getWeightRandom(fieldsArr)
- for k, v := range fieldsArr {
- if k == i {
- result = util.ObjToString(v["field"])
- }
- }
- return result
- }
- //根据权重随机获取数组的索引
- func getWeightRandom(array []map[string]interface{}) int {
- var weightSum, stepWeightSum float64
- for _, v := range array {
- weightSum += v["proportion"].(float64)
- }
- randVal := rand.New(rand.NewSource(time.Now().UnixNano())).Float64()
- for i := 0; i < len(array); i++ {
- stepWeightSum += array[i]["proportion"].(float64)
- if randVal <= stepWeightSum/weightSum {
- return i
- }
- }
- return 0
- }
- func MFollow(userId, pname, pcode, title, openid string) (bool, string) {
- defer util.Catch()
- var followId string
- followFlag := false
- follows, ok := mongodb.Find("follow_project", `{"s_userid":"`+userId+`"}`, `{"_id":1,"s_projectname":1,"s_projectcode":1}`, nil, false, -1, -1)
- if ok && follows != nil && len(*follows) > 0 {
- for _, v := range *follows {
- pc, _ := v["s_projectcode"].(string)
- pn, _ := v["s_projectname"].(string)
- if (pc != "" && pc == pcode) || (pn != "" && pn == pname) {
- followFlag = true
- followId = util.EncodeArticleId2ByCheck(BsonIdToSId(v["_id"]))
- break
- }
- }
- }
- return followFlag, followId
- }
- //查看原文跳转
- //增加查询备份库数据、增加关键词、描述逻辑处理
- func (m *Front) PcVisitRedirect(sid string) {
- defer util.Catch()
- kds := m.GetString("kds")
- m.T["keywords"] = kds
- sid = strings.Split(sid, "_")[0]
- //sid = util.DecodeArticleId(sid)[0]
- var shareid = m.GetString("id")
- if len(shareid) == 0 {
- shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jysskzy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
- }
- m.T["logid"] = config.Seoconfig["jysskzy"].(string)
- m.T["shareid"] = se.EncodeString(shareid)
- if ret := redis.Get("other", "jypcdetail_"+sid+kds); ret != nil {
- m.SetBody([]byte(ret.(string)))
- return
- } else {
- m.DisableHttpCache()
- data := elastic.GetByIdField("bidding", "bidding", sid, `"href"`)
- if data == nil || len(*data) == 0 {
- m.Render("/_error.html")
- return
- }
- href, _ := (*data)["href"].(string)
- href = strings.Replace(href, "\n", "", -1)
- if href != "" && !strings.HasPrefix(href, "http") {
- href = "http://" + href
- }
- po, bo, wo, obj := pcVRT(sid, "")
- if obj != nil && len(obj) > 0 {
- if len(po) > 0 {
- m.T["projectOther"] = po
- }
- if len(bo) > 0 {
- m.T["buyerOther"] = bo
- }
- if len(wo) > 0 {
- m.T["winnerOther"] = wo
- }
- obj["url"] = href
- m.T["obj"] = obj
- content, _ := m.Render4Cache("/pc/biddetail.html", &m.T)
- redis.Put("other", "jypcdetail_"+sid+kds, string(content), 60*60*24)
- m.SetBody(content)
- return
- }
- if href != "" {
- m.Redirect(href)
- }
- }
- }
- //pc三级页跳转
- //20170821增加查询字段s_subscopeclass
- func pcVRT(sid, industry string) (po, bo, wo []map[string]interface{}, objdata map[string]interface{}) {
- defer util.Catch()
- var projectOther, buyerOther, winnerOther []map[string]interface{}
- var obj map[string]interface{}
- if len(sid) > 5 {
- brobj, ok := mongodb.Find("bidding_rec", bson.M{"s_id": sid}, `{"l_recoverydate":-1}`, nil, false, 0, 1)
- if ok && (*brobj) != nil && len(*brobj) == 1 && (*brobj)[0] != nil {
- obj = (*brobj)[0]
- } else {
- aobj, ok := public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection, sid, nil)
- if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
- aobj, ok = public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection_back, sid, nil)
- }
- obj = *aobj
- }
- //obj, ok := elastic.GetByIdField("bidding", "bidding", sid, ""), true
- if ok && obj != nil && len(obj) > 0 {
- //DealInfo(obj, coll)
- //fwt := util.ObjToString(obj["fieldweights"])
- //lwf := util.ObjToString(obj["lastwrongfield"])
- //ltfd := getLowestField(fwt, lwf)
- //if ltfd != "" {
- // obj["fwtsname"] = obj[ltfd]
- // obj["fwtscode"] = ltfd
- //}
- obj["_id"] = util.EncodeArticleId2ByCheck(sid)
- var infoformat = obj["infoformat"]
- if infoformat != nil && infoformat != "" {
- obj["infoformat"] = util.IntAll(infoformat)
- }
- if strings.Trim(util.ObjToString(obj["detail"]), " ") == "" {
- obj["detail"] = ""
- }
- titleStr := util.ObjToString(obj["title"])
- if len([]rune(titleStr)) > 100 {
- titleStr = string([]rune(titleStr)[:100]) + "..."
- }
- //titleTmp := util.If(len([]rune(titleStr)) > 100, string([]rune(titleStr)[:100])+"...", string(titleStr)).(string)
- obj["title"] = public.ClearHtml.ReplaceAllString(titleStr, "")
- area := obj["area"].(string)
- finalType, _ := obj["subtype"].(string)
- if finalType == "" {
- finalType = util.ObjToString(obj["toptype"])
- }
- if finalType == "" {
- finalType = util.ObjToString(obj["type"])
- if finalType == "bid" {
- finalType = "中标"
- } else if finalType == "tender" {
- finalType = "招标"
- } else {
- finalType = ""
- }
- }
- if industry == "" {
- industry = util.ObjToString(obj["s_subscopeclass"])
- if industry != "" {
- if strings.Contains(industry, "它") {
- industry = strings.Replace(industry, "它", "他", -1)
- }
- industry = strings.Split(industry, ",")[0]
- }
- }
- //detail字段 缺少标签 处理
- if config.Sysconfig["detail_element"] != nil {
- var arrTags = util.ObjArrToStringArr(config.Sysconfig["detail_element"].([]interface{}))
- var _detail = util.ObjToString(obj["detail"])
- for _, v := range arrTags {
- var intOpen = strings.Count(_detail, "<"+v)
- var intClose = strings.Count(_detail, "</"+v+">")
- if intOpen >= intClose {
- for di := 0; di < (intOpen - intClose); di++ {
- _detail += "</" + v + ">"
- }
- } else {
- for di := 0; di < (intClose - intOpen); di++ {
- _detail = "<" + v + ">" + _detail
- }
- }
- // log.Println(intOpen, "--", intClose)
- }
- // log.Println("_detail:", _detail)
- obj["detail"] = _detail
- }
- obj["stypeadd"], obj["areaadd"], obj["indadd"] = classify(finalType, area, industry)
- //增加处理信息逻辑
- objdata = obj
- queryStr := ""
- commonQuery := func(mustquery string) *[]map[string]interface{} {
- return elastic.GetPage("bidding", "bidding", queryStr, bidSearch_sort, `"_id","title","publishtime","toptype","subtype","type","area","href","s_subscopeclass"`, 0, 11)
- }
- //同一个项目的其他招标信息
- projectName, _ := obj["projectname"].(string)
- projectCode, _ := obj["projectcode"].(string)
- if projectName != "" || projectCode != "" {
- if projectName != "" && projectCode != "" {
- queryStr = `{"$or":[{"TERM_projectname":"` + projectName + `"},{"TERM_projectcode":"` + projectCode + `"}]}`
- } else if projectName != "" && projectCode == "" {
- queryStr = `{"TERM_projectname":"` + projectName + `"}`
- } else if projectName == "" && projectCode != "" {
- queryStr = `{"TERM_projectcode":"` + projectCode + `"}`
- }
- projectOther = bidDataConvert(sid, commonQuery(queryStr))
- }
- //同一个业主最近的其他招标信息
- buyer, _ := obj["buyer"].(string) //采购单位
- if buyer != "" {
- queryStr = `{"TERM_buyer":"` + buyer + `"}`
- buyerOther = bidDataConvert(sid, commonQuery(queryStr))
- }
- //同一中标人最近中标的其他信息
- subtype, _ := obj["subtype"].(string) //信息类型
- winner, _ := obj["winner"].(string) //中标人
- if winner != "" && subtype == "中标" {
- queryStr = `{"TERM_s_winner":"` + winner + `"}`
- winnerOther = bidDataConvert(sid, commonQuery(queryStr))
- }
- }
- }
- return projectOther, buyerOther, winnerOther, objdata
- }
- //数据转换
- func bidDataConvert(id string, datas *[]map[string]interface{}) (array []map[string]interface{}) {
- if datas == nil || len(*datas) == 0 {
- return array
- }
- index := 0
- public.BidListConvert("", datas)
- for _, v := range *datas {
- if len(array) >= 10 {
- break
- }
- _id, _ := v["_id"].(string)
- if _id == id {
- continue
- }
- v["_id"] = util.EncodeArticleId2ByCheck(_id)
- area, _ := v["area"].(string)
- if area == "A" {
- v["area"] = ""
- }
- tp, _ := v["subtype"].(string)
- if tp == "" {
- tp, _ = v["toptype"].(string)
- }
- if tp == "" {
- tp, _ = v["type"].(string)
- if tp == "bid" {
- tp = "中标"
- } else if tp == "tender" {
- tp = "招标"
- } else {
- tp = ""
- }
- }
- indtry := util.ObjToString(v["industry"])
- v["stypeadd"], v["areaadd"], v["indadd"] = classify(tp, area, indtry)
- v["type"] = tp
- diff := ""
- publishtime, _ := v["publishtime"].(float64)
- if publishtime != 0 {
- diff = util.TimeDiff(time.Unix(util.Int64All(publishtime), 0))
- v["pbtime"] = util.Int64All(publishtime)
- }
- v["publishtime"] = diff
- index++
- v["index"] = index
- array = append(array, v)
- }
- return array
- }
- //剑鱼标讯保存
- func (m *Front) AjaxReq() error {
- defer util.Catch()
- reqType := m.GetString("reqType")
- var flag = "n"
- switch reqType {
- case "feedback": //意见反馈
- data := make(map[string]interface{})
- userId, ok := m.GetSession("userId").(string)
- if !ok || userId == "" {
- break
- }
- userInfo, ok := mongodb.FindById("user", userId, nil)
- if !ok {
- break
- }
- data["i_type"] = 8
- data["s_fromName"] = m.GetString("fromName")
- value := m.GetString("value")
- if len([]rune(value)) > 200 {
- value = util.SubString(value, 0, 200)
- }
- data["s_remark"] = value
- s_nickname, _ := (*userInfo)["s_nickname"].(string)
- s_name, _ := (*userInfo)["s_name"].(string)
- s_phone, _ := (*userInfo)["s_phone"].(string)
- if s_name != "" {
- data["s_submitname"] = s_name
- } else if s_nickname != "" {
- data["s_submitname"] = s_nickname
- } else if s_phone != "" {
- data["s_submitname"] = s_phone
- } else {
- data["s_submitname"] = userId
- }
- data["s_submitid"] = userId
- data["s_title"] = m.GetString("title")
- data["i_status"] = 0
- if s_nickname != "" { //昵称
- data["s_username"] = s_nickname
- } else if s_name != "" { //s_name
- data["s_username"] = s_name
- } else if s_phone != "" { //s_name
- data["s_username"] = s_phone
- } else { //s_name
- data["s_username"] = userId
- }
- data["l_submitdate"] = time.Now().Unix()
- data["s_source"] = m.GetString("source")
- data["s_fkid"] = m.GetString("fkid")
- data["s_from"] = "wx"
- id := mongodb.Save("interaction", data)
- if len(id) > 0 {
- flag = "y"
- }
- break
- case "subscribe": //直接订阅
- if userid := m.GetSession("userId"); userid != nil {
- r, _ := mongodb.FindById("user", userid.(string), `{"o_jy":1}`)
- o_jy, _ := (*r)["o_jy"].(map[string]interface{})
- a_key, _ := o_jy["a_key"].([]interface{})
- keysArray := processKeyword(m.GetString("keys"))
- if keysArray == nil {
- break
- }
- var isExists bool
- for _, v := range a_key {
- //count := 0
- //for _, kay := range keysArray {
- keyMap, _ := v.(map[string]interface{})
- key, _ := keyMap["key"].([]interface{})
- kystr := ""
- for _, ky := range key {
- kystr = kystr + " " + ky.(string)
- }
- if strings.TrimSpace(m.GetString("keys")) == strings.TrimSpace(kystr) {
- isExists = true
- flag = "y"
- break
- }
- //}
- //if count == len(keysArray) {
- // isExists = true
- // flag = "y"
- // break
- //}
- }
- //如果不存在
- if !isExists {
- if len(a_key) >= 10 {
- flag = "o"
- } else {
- if mongodb.UpdateById("user", userid,
- bson.M{
- "$push": bson.M{"o_jy.a_key": bson.M{"key": keysArray}},
- "$set": bson.M{"i_ts_guide": 1, "o_jy.l_modifydate": time.Now().Unix()},
- }) {
- flag = "y"
- }
- }
- }
- }
- break
- }
- m.ServeJson(map[string]interface{}{
- "flag": flag,
- })
- return nil
- }
- const (
- INDEX = "bidding"
- TYPE = "bidding"
- FINDF = `"title"`
- )
- //预览结果
- func (m *Front) WxpushView() error {
- defer util.Catch()
- userid := util.ObjToString(m.GetSession("userId"))
- openid := util.ObjToString(m.GetSession("s_m_openid"))
- if openid == "" || userid == "" {
- return m.Redirect("/swordfish/share/-1")
- }
- a_key, list := public.PushViewDatas(userid, "", bidSearch_field_1, 1, wx_pageSize)
- public.BidListConvert("", list)
- m.T["firstPage"] = list
- m.T["hasNextPage"] = list != nil && len(*list) == wx_pageSize
- m.T["pageSize"] = wx_pageSize
- m.T["a_key"] = a_key
- mynickname, _ := m.Session().Get("s_nickname").(string)
- myavatar, _ := m.Session().Get("s_avatar").(string)
- m.T["nickname"] = mynickname
- m.T["avatar"] = myavatar
- m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
- m.T["openid"] = se.EncodeString(openid)
- return m.Render("/weixin/resultpreview.html", &m.T)
- }
- func (m *Front) WxpushViewPaging() {
- defer util.Catch()
- var list *[]map[string]interface{}
- pageNum, _ := m.GetInteger("pageNum")
- if userid := m.Session().Get("userId"); userid != nil && pageNum <= wx_maxPageNum {
- _, list = public.PushViewDatas(userid.(string), "", bidSearch_field_1, pageNum, wx_pageSize)
- }
- public.BidListConvert("", list)
- m.ServeJson(map[string]interface{}{
- "list": list,
- "hasNextPage": list != nil && len(*list) == wx_pageSize && pageNum < wx_maxPageNum,
- })
- }
- func (m *Front) Guide(sign string) error {
- defer util.Catch()
- if m.Session().Get("userId") == nil || m.Session().Get("s_m_openid") == nil {
- return m.Redirect("/swordfish/share/-1")
- }
- m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
- mynickname, _ := m.Session().Get("s_nickname").(string)
- myavatar, _ := m.Session().Get("s_avatar").(string)
- m.T["nickname"] = mynickname
- m.T["avatar"] = myavatar
- myopenid, _ := m.Session().Get("s_m_openid").(string)
- m.T["openid"] = se.EncodeString(myopenid)
- m.T["sign"] = sign
- if sign == "other" {
- userInfo, ok := mongodb.FindById("user", m.GetSession("userId").(string), `{"o_jy_msgset":1}`)
- if ok {
- m.T["msgset"] = (*userInfo)["o_jy_msgset"]
- }
- }
- if sign == "share" {
- return m.Render("/weixin/wxshareguide.html", &m.T)
- } else {
- return m.Render("/weixin/wxindex.html", &m.T)
- }
- }
- func (m *Front) Share(openids string) error {
- return m.Redirect("/swordfish/about")
- //
- defer util.Catch()
- var openid = ""
- var jy_code = ""
- if openids != "-1" {
- wxid_code := strings.Split(openids, "__")
- if len(wxid_code) > 0 {
- openid = wxid_code[0]
- jy_code = wxid_code[1]
- }
- }
- m.T["openid"] = openid
- m.T["jy_code"] = jy_code
- m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
- mynickname, _ := m.Session().Get("s_nickname").(string)
- myavatar, _ := m.Session().Get("s_avatar").(string)
- m.T["nickname"] = mynickname
- m.T["avatar"] = myavatar
- return m.Render("/weixin/wxshare.html", &m.T)
- }
- func (m *Front) WxpushAjaxReq() error {
- defer util.Catch()
- userId := util.ObjToString(m.GetSession("userId"))
- if userId != "" {
- vsid, _ := m.GetInteger("vsid")
- jy.SubscribePush.Visit(public.PushMysql, userId, vsid)
- }
- return nil
- }
- //
- func (m *Front) About() error {
- defer util.Catch()
- code := m.GetString("code") //渠道
- // 点浏览器打开时保持在原页面
- come := m.GetString("come")
- flag := m.GetString("flag")
- if !mobileReg.MatchString(m.UserAgent()) && flag == "" {
- return m.Redirect("/front/aboutus.html" + util.If(code != "", "?code="+code, "").(string))
- }
- myopenid, _ := m.Session().Get("s_m_openid").(string)
- mynickname, _ := m.Session().Get("s_nickname").(string)
- myavatar, _ := m.Session().Get("s_avatar").(string)
- if myopenid == "" {
- if m.GetString("state") == "wx" {
- //微信跳回来的
- code := m.GetString("code")
- if code != "" {
- openid := jyutil.Getopenid(code)
- userInfo, ok := mongodb.FindOneByField("user", map[string]interface{}{
- "s_m_openid": openid,
- "i_appid": 2,
- }, `{"_id":-1,"s_nickname":1,"s_m_openid":1}`)
- if ok && userInfo != nil && len(*userInfo) > 0 {
- mynickname, _ = (*userInfo)["s_nickname"].(string)
- myopenid, _ = (*userInfo)["s_m_openid"].(string)
- }
- }
- } else {
- if public.CheckWxBrowser(m.Request) {
- //所有参数都不再使用,跳到微信验证用户
- return m.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(m.Site()+m.Url()), "wx"), 302)
- }
- }
- }
- param := m.GetString("param")
- var openid = ""
- var activecode = ""
- //分享后微信新用户打开落地页
- if param != "-1" {
- wxid_code := strings.Split(param, "__")
- if len(wxid_code) > 0 {
- openid = wxid_code[0]
- }
- if len(wxid_code) > 1 {
- activecode = wxid_code[1]
- }
- }
- qrcodeType := m.GetString("qrcodeType")
- if qrcodeType != "" {
- activecode = qrcodeType
- }
- m.T["code"] = code
- m.T["source"] = m.GetString("source") //分享类型 app or 公众号
- m.T["activecode"] = activecode
- m.T["nickname"] = mynickname
- m.T["avatar"] = myavatar
- if openid == "" && myopenid != "" {
- m.T["openid"] = se.EncodeString(myopenid)
- } else {
- m.T["openid"] = openid
- }
- m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
- m.T["flag"] = flag
- m.T["come"] = come
- if come == "1" && !public.CheckWxBrowser(m.Request) {
- return m.Redirect("https://www.jianyu360.com/jyapp/free/download/normal?source=weixinAutoRpl")
- }
- var open_infoid = ""
- if m.GetString("source") == "open_infocontent" {
- open_infoid = m.GetString("o")
- m.T["open_infoid"] = open_infoid
- m.T["code"] = "open00" + open_infoid
- return m.Render("/weixin/about.html")
- } else {
- if myopenid == "" {
- if public.CheckWxBrowser(m.Request) {
- if code == "" {
- m.T["code"] = "wx01" //新用户微信访问,统计app下载量
- }
- return m.Render("/weixin/sharePage.html")
- } else {
- return m.Redirect("/active/appExt/sh001")
- }
- } else {
- if public.CheckWxBrowser(m.Request) {
- m.T["isWeixin"] = 1
- } else {
- m.T["isWeixin"] = 0
- }
- return m.Render("/weixin/about.html")
- }
- }
- }
- //
- func (m *Front) Shareabout(openids string) error {
- defer util.Catch()
- var openid = ""
- if openids != "-1" {
- wxid_code := strings.Split(openids, "__")
- if len(wxid_code) > 0 {
- openid = wxid_code[0]
- }
- }
- myopenid, _ := m.Session().Get("s_m_openid").(string)
- mynickname, _ := m.Session().Get("s_nickname").(string)
- myavatar, _ := m.Session().Get("s_avatar").(string)
- if openid == "" && myopenid != "" {
- m.T["openid"] = se.EncodeString(myopenid)
- } else {
- m.T["openid"] = openid
- }
- m.T["nickname"] = mynickname
- m.T["avatar"] = myavatar
- m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
- m.T["source"] = ""
- if public.CheckWxBrowser(m.Request) {
- m.T["isWeixin"] = 1
- } else {
- m.T["isWeixin"] = 0
- }
- return m.Render("/weixin/about.html")
- }
- //
- func (m *Front) Aboutsearch() error {
- myopenid, _ := m.Session().Get("s_m_openid").(string)
- m.T["openid"] = se.EncodeString(myopenid)
- mynickname, _ := m.Session().Get("s_nickname").(string)
- myavatar, _ := m.Session().Get("s_avatar").(string)
- m.T["nickname"] = mynickname
- m.T["avatar"] = myavatar
- m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
- m.Render("/weixin/aboutsearch.html", &m.T)
- return nil
- }
- //剑鱼标讯微信查询保存网站
- func (m *Front) AboutSR() error {
- defer util.Catch()
- var flag = "N"
- var sn = m.GetString("searchname")
- var tp = m.GetString("tp")
- if len(sn) > 0 {
- switch tp {
- case "S": //用户查询网站是否被收录
- userId, ok := m.GetSession("userId").(string)
- if !ok || userId == "" {
- break
- }
- res, err := mongodb.FindOne("bidurlinfo", bson.M{"$or": []bson.M{bson.M{"s_name": sn}, bson.M{"s_url": sn}}})
- if err {
- if len(*res) > 0 {
- flag = "T"
- }
- }
- break
- case "I": //用户提交数据
- data := make(map[string]interface{})
- userId, ok := m.GetSession("userId").(string)
- if !ok || userId == "" {
- break
- }
- userInfo, ok := mongodb.FindById("user", userId, nil)
- if !ok {
- break
- }
- data["i_type"] = 8
- data["s_remark"] = sn
- if (*userInfo)["s_name"] != nil {
- data["s_submitname"] = (*userInfo)["s_name"].(string)
- }
- data["s_submitid"] = userId
- data["s_title"] = m.GetString("title")
- data["i_status"] = 0
- if (*userInfo)["s_nickname"] != nil { //昵称
- data["s_username"] = (*userInfo)["s_nickname"].(string)
- } else if (*userInfo)["s_name"] != nil { //s_name
- data["s_username"] = (*userInfo)["s_name"].(string)
- }
- data["l_submitdate"] = time.Now().Unix()
- data["s_source"] = m.GetString("source")
- data["s_from"] = "wx"
- id := mongodb.Save("interaction", data)
- if len(id) > 0 && len(sn) > 0 {
- flag = "T"
- }
- break
- }
- }
- m.ServeJson(map[string]interface{}{
- "flag": flag,
- })
- return nil
- }
- //手动删除30天无更新数据
- func (m *Front) DelOL() error {
- defer util.Catch()
- var ids []primitive.ObjectID
- var flag = "F"
- var arrid = strings.Split(m.GetString("arrid"), ",")
- if len(arrid) > 0 {
- for _, chid := range arrid {
- _id, _ := primitive.ObjectIDFromHex(util.DecodeArticleId2ByCheck(chid)[0])
- ids = append(ids, _id)
- }
- }
- userId, ok := m.GetSession("userId").(string)
- if !ok || userId == "" || len(ids) < 1 {
- m.ServeJson(map[string]interface{}{
- "flag": flag,
- })
- return nil
- }
- 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 {
- for _, v := range *datas {
- go delRelRedis(v["s_userid"], v["a_relationinfo"])
- v["s_followid"] = BsonIdToSId(v["_id"])
- delete(v, "_id")
- v["i_status"] = 2
- mongodb.Save("follow_project_back", v)
- }
- }
- if mongodb.Del("follow_project", bson.M{"_id": bson.M{"$in": ids}, "s_userid": m.GetSession("userId").(string)}) {
- flag = "T"
- }
- m.ServeJson(map[string]interface{}{
- "flag": flag,
- })
- return nil
- }
- //获取我的反馈列表
- func (f *Front) MyFeedbacks() error {
- userId, _ := f.GetSession("userId").(string)
- if userId == "" {
- return f.Render("/_error.html")
- }
- 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)
- if !ok {
- return nil
- }
- if f.Method() == "GET" {
- f.T["list"] = list
- f.T["flag"] = true
- mynickname, _ := f.Session().Get("s_nickname").(string)
- myavatar, _ := f.Session().Get("s_avatar").(string)
- myopenid, _ := f.GetSession("s_m_openid").(string)
- f.T["nickname"] = mynickname
- f.T["avatar"] = myavatar
- f.T["signature"] = wx.SignJSSDK(f.Site() + f.Url())
- f.T["openid"] = se.EncodeString(myopenid)
- _, f.T["advertText"] = getRewardText()
- f.T["advertImg"] = config.Sysconfig["advertImg"]
- f.T["advertName"] = config.Sysconfig["advertName"]
- f.T["advertUrl"] = config.Sysconfig["advertUrl"]
- return f.Render("/weixin/feedback.html")
- }
- f.ServeJson(map[string]interface{}{
- "list": list,
- })
- return nil
- }
- func (f *Front) GetRecomKWs() {
- recomKWChan <- true
- defer func() {
- <-recomKWChan
- }()
- value := f.GetString("value")
- count, _ := f.GetInteger("count")
- ves := strings.Split(value, " ")
- var pairs []map[string]interface{}
- for _, v := range ves {
- Pw, _ := M.MostSimilar(strings.Split(v, "+"), []string{}, count)
- for _, p := range Pw {
- sim := p.Sim
- word := p.Word
- if sim < float32(config.Sysconfig["recommendThreshold"].(float64)) {
- continue
- }
- if strings.HasSuffix(word, "路") || public.DealString(word) {
- continue
- }
- pairs = append(pairs, map[string]interface{}{
- "sim": sim,
- "word": word,
- })
- }
- }
- f.ServeJson(pairs)
- }
- //记录用户行为--推荐关键词
- func (f *Front) BehaviorRecord() {
- flag := saveBehaviorRecord(f.Session(),
- bson.M{
- "s_word": f.GetString("value"),
- "s_type": f.GetString("type"),
- "s_source": f.GetString("source"),
- })
- f.ServeJson(bson.M{"flag": flag})
- }
- //记录用户行为
- func saveBehaviorRecord(sess *httpsession.Session, data bson.M) bool {
- userid, _ := sess.Get("userId").(string)
- //if openId == "" {
- // return false
- //}
- nickName, _ := sess.Get("s_nickname").(string)
- //data["s_openid"] = openId
- data["s_userid"] = userid
- data["s_nickname"] = nickName
- data["l_createtime"] = time.Now().Unix()
- return len(mongodb.Save("behavior", data)) > 0
- }
- //取得剑鱼标讯博客的信息列表
- func (f *Front) Jyblog(param /*参数*/ string) error {
- querymap := map[string]string{}
- if len(param) == 0 {
- querymap = map[string]string{
- "perPage": f.GetString("perPage"),
- "currentPage": f.GetString("currentPage"),
- "contentType": "jybk",
- "query": f.GetString("query"),
- }
- } else {
- //反转生成map
- paramstr := param[1:]
- bs, _ := base64.StdEncoding.DecodeString(paramstr)
- json.Unmarshal(bs, &querymap)
- }
- var shareid = f.GetString("id")
- if len(shareid) == 0 {
- shareid = fmt.Sprintf("%s%d", config.Seoconfig["jybky"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
- }
- f.T["logid"] = config.Seoconfig["jybky"].(string)
- f.DisableHttpCache()
- shareid = se.EncodeString(shareid)
- data, pagination := searhWebContentblog(querymap)
- f.Render("/pc/jyblog.html", &xweb.T{"querymap": querymap, "data": data, "pagination": pagination, "shareid": shareid})
- return nil
- }
- //实际的查询剑鱼标讯博客
- func searhWebContentblog(querymap map[string]string) (*[]map[string]interface{}, *[]interface{}) {
- perPage, _ := strconv.Atoi(querymap["perPage"])
- currentPage, _ := strconv.Atoi(querymap["currentPage"])
- //修复
- if perPage == 0 {
- perPage = 5
- }
- if currentPage < 1 {
- currentPage = 1
- }
- contentType := querymap["contentType"]
- queryStr := querymap["query"]
- str := ``
- if queryStr != "" {
- str = `{
- "match": {
- "s_title": {
- "query":"` + queryStr + `",
- "operator": "and"
- }
- }
- },{
- "match": {
- "s_content": {
- "query":"` + queryStr + `"
- }
- }
- }`
- }
- var tempQuery = `{"query": {
- "bool": {
- "must":[{"term":{"s_contenttype":"` + contentType + `"}}],
- "should": [` + str + `],
- "minimum_should_match": 0
- }
- }}`
- var query = tempQuery[:len(tempQuery)-1] +
- `,"highlight":{
- "pre_tags":["<span class='highlight'>"],
- "post_tags":["</span>"],
- "fields":{
- "s_title":{"force_source": true}
- ,"s_content":{"force_source": true}
- }
- },"_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"]
- ,"from":` + fmt.Sprintf("%v", ((currentPage-1)*perPage)) + `,
- "size":` + fmt.Sprintf("%v", perPage) +
- `,"sort":[{"releasetime":{"order":"desc"}}] }`
- total := elastic.Count("content", "content", tempQuery)
- //查询列表数据
- client := elastic.GetEsConn()
- defer elastic.DestoryEsConn(client)
- if client == nil {
- return nil, nil
- }
- searchResult, err := client.Search().Index("content").Type("content").Source(query).Do()
- if err != nil {
- return nil, nil
- }
- var res []map[string]interface{}
- if searchResult.Hits != nil {
- resNum := len(searchResult.Hits.Hits)
- res = make([]map[string]interface{}, resNum)
- for i, hit := range searchResult.Hits.Hits {
- json.Unmarshal(*hit.Source, &res[i])
- //查询结果数据加工处理
- for k, v := range hit.Highlight {
- res[i][k] = v[0]
- }
- s_content, _ := res[i]["s_content"].(string)
- if len(s_content) > 500 {
- res[i]["s_content"] = ""
- } else {
- con, _ := regexp.Compile("^[^<]*?>")
- content := con.ReplaceAllString(s_content, "")
- con1, _ := regexp.Compile("<[^>]*$")
- res[i]["s_content"] = template.HTML(con1.ReplaceAllString(content, ""))
- }
- s_title, _ := res[i]["s_title"].(string)
- res[i]["s_title"] = template.HTML(s_title)
- tmpdate, _ := res[i]["l_createdate"]
- res[i]["l_createdate"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate.(float64)), 0))
- tmpdate1, _ := res[i]["releasetime"]
- res[i]["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1.(float64)), 0))
- res[i]["s_pic"] = config.Seoconfig["jyadd"].(string) + res[i]["s_pic"].(string)
- res[i]["s_pic1"] = config.Seoconfig["jyadd"].(string) + res[i]["s_pic1"].(string)
- res[i]["_id"] = se.EncodeString(res[i]["_id"].(string))
- }
- }
- //生成分页
- pagination := MakePagination(perPage, currentPage, int(total), querymap, "/jyblog/index_%s.html")
- return &res, &pagination
- }
- //计算分页,分页显示规则
- func MakePagination(perPage, currentPage, total int, param map[string]string, urltpl string) []interface{} {
- var totalPages int //总页数
- if total == 0 {
- totalPages = 1
- } else {
- totalPages = (total - 1 + perPage) / perPage //总页数
- }
- ret := make([]interface{}, 3)
- index := 0
- prePage, nextPage := currentPage-1, currentPage+1
- if prePage < 1 {
- prePage = 1
- }
- if nextPage > totalPages {
- nextPage = totalPages
- }
- param["currentPage"] = strconv.Itoa(prePage)
- bs, _ := json.Marshal(param)
- paramstr := base64.StdEncoding.EncodeToString(bs)
- url := fmt.Sprintf(urltpl, paramstr)
- iscurrent := currentPage == 1
- ret[index] = map[string]interface{}{"page": "< 上一页", "url": url, "iscurrent": iscurrent}
- index = index + 1
- param["currentPage"] = strconv.Itoa(currentPage)
- bs, _ = json.Marshal(param)
- paramstr = base64.StdEncoding.EncodeToString(bs)
- url = fmt.Sprintf(urltpl, paramstr)
- iscurrent = currentPage == currentPage
- ret[index] = map[string]interface{}{"page": currentPage, "url": url, "iscurrent": iscurrent}
- index = index + 1
- param["currentPage"] = strconv.Itoa(nextPage)
- bs, _ = json.Marshal(param)
- paramstr = base64.StdEncoding.EncodeToString(bs)
- url = fmt.Sprintf(urltpl, paramstr)
- iscurrent = currentPage == totalPages
- ret[index] = map[string]interface{}{"page": "下一页 >", "url": url, "iscurrent": iscurrent}
- return ret
- }
- //博客三级页
- func (f *Front) Jybdetail(_id string) error {
- var shareid = f.GetString("id")
- if len(shareid) == 0 {
- shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jybky"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
- }
- f.T["logid"] = config.Seoconfig["jybky"].(string)
- shareid = se.EncodeString(shareid)
- if ret := redis.Get("other", "jyblog_"+_id); ret != nil {
- var retlist *map[string]interface{}
- b, _ := json.Marshal(ret)
- json.Unmarshal(b, &retlist)
- (*retlist)["s_content"] = template.HTML((*retlist)["s_content"].(string))
- (*retlist)["_id"] = (*retlist)["_id"].(string)
- f.T["data"] = retlist
- } else {
- id := se.DecodeString(_id)
- 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"`)
- if r != nil {
- tmpdate1, _ := (*r)["l_createdate"]
- (*r)["l_createdate"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1.(float64)), 0))
- tmpdate2, _ := (*r)["releasetime"]
- (*r)["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate2.(float64)), 0))
- (*r)["s_content"] = template.HTML((*r)["s_content"].(string))
- (*r)["_id"] = se.EncodeString((*r)["_id"].(string))
- (*r)["s_pic"] = (*r)["s_pic"].(string)
- }
- f.DisableHttpCache()
- redis.Put("other", "jyblog_"+_id, r, 2*60*60)
- f.T["data"] = r
- }
- f.T["shareid"] = shareid
- return f.Render("/pc/jyblogdetail.html", &f.T)
- }
- //
- func (f *Front) Blogpraise() error {
- defer util.Catch()
- id := se.DecodeString(f.GetString("id"))
- stype := f.GetString("type")
- flag := "F"
- var blogflag = true
- util.Try(func() {
- if id != "" {
- if stype == "up" {
- blogflag = mongodb.Update("content", `{"_id":"`+id+`"}`, `{ "$inc" : { "praise" : 1 }}`, false, false)
- } else if stype == "down" {
- blogflag = mongodb.Update("content", `{"_id":"`+id+`"}`, `{ "$inc" : { "praise" : -1 }}`, false, false)
- }
- if blogflag {
- flag = "T"
- r, _ := mongodb.FindById("content", id, "")
- elastic.UpdateNewDoc("content", "content", r)
- redis.Del("other", "jyblog_"+f.GetString("id"))
- }
- }
- }, func(e interface{}) {
- log.Println("文章点赞出错", e)
- })
- f.ServeJson(map[string]interface{}{
- "flag": flag,
- })
- return nil
- }
- //
- func getRewardText() (string, string) {
- rewardText, _ := config.Sysconfig["rewardText"].([]interface{})
- advertText, _ := config.Sysconfig["advertText"].([]interface{})
- randVal := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(rewardText))
- if len(advertText) != 0 {
- advVal := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(advertText))
- return util.ObjToString(rewardText[randVal]), util.ObjToString(advertText[advVal])
- } else {
- return util.ObjToString(rewardText[randVal]), ""
- }
- }
- //
- func searchresulthtml(list *[]map[string]interface{}) string {
- var listhtml = ""
- var j = 1
- for i := 0; i < len(*list); i++ {
- listdata := (*list)[i]
- j = i + 1
- listhtml += `<li><div class="liLuceneList"><div class="luce-left"><em>` + strconv.Itoa(j) + `.</em>`
- if listdata["title"] != "" {
- 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">`
- }
- area, _ := listdata["area"].(string)
- area = strings.TrimSpace(area)
- finalType, _ := listdata["subtype"].(string)
- if finalType == "" {
- finalType = util.ObjToString(listdata["toptype"])
- }
- if finalType == "" {
- finalType = util.ObjToString(listdata["type"])
- if finalType == "bid" {
- finalType = "中标"
- } else if finalType == "tender" {
- finalType = "招标"
- } else {
- finalType = ""
- }
- }
- industry := util.ObjToString(listdata["industry"])
- stpadd, areaadd, indadd := classify(finalType, area, industry)
- if area != "" && area != "A" {
- listhtml += `<a href="/list/area/` + areaadd + `.html">` + area + `</a>`
- } else {
- listhtml += `<a href="#" style="display:none;"></a>`
- }
- if finalType != "" {
- listhtml += `<a href="/list/stype/` + stpadd + `.html">` + finalType + `</a>`
- } else {
- listhtml += `<a href="#" style="display:none;"></a>`
- }
- //industry, _ := listdata["industry"].(string)
- if industry != "" {
- listhtml += `<a href="/list/industry/` + indadd + `.html">` + industry + `</a>`
- } else {
- listhtml += `<a href="#" style="display:none;"></a>`
- }
- acount := ""
- if listdata["bidamount"] != nil {
- acount = ConversionMoeny(listdata["bidamount"])
- } else if listdata["budget"] != nil {
- acount = ConversionMoeny(listdata["budget"])
- }
- if acount != "" {
- listhtml += `<a>` + acount + `</a>`
- } else {
- listhtml += `<a href="#" style="display:none;"></a>`
- }
- publishtime, _ := listdata["publishtime"].(float64)
- if publishtime != 0 {
- diff := util.TimeDiff(time.Unix(util.Int64All(publishtime), 0))
- if diff != "" {
- listhtml += `<span class="com-time">` + diff + `</span>`
- }
- }
- listhtml += `</div></div></li>`
- }
- return listhtml
- }
- //标签查询
- func (f *Front) SearchResult(at, name string) error {
- defer util.Catch()
- if at == "stype" && name == "NJ" {
- return f.Redirect("/jylab/supsearch/proposedProject.html")
- }
- var no = 5
- var area = ""
- var stype = ""
- var industry = ""
- var startPage, currentPage, limitcount int
- limitcount = util.IntAll(config.Seoconfig["limitcount"])
- var res = ""
- var seotitle = ""
- var seokeywords = ""
- var seodescription = ""
- if len(industrylist) > 0 {
- f.T["industrylist"], f.T["sortArray"] = industrylist, sortArray
- } else {
- f.T["industrylist"], f.T["sortArray"] = getindustrys()
- }
- var shareid = f.GetString("id")
- if len(shareid) == 0 {
- shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jybqy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[8:14], rand.Intn(9))
- }
- f.T["logid"] = config.Seoconfig["jybqy"].(string)
- if at == "area" {
- log.Println("config.Seoconfig", config.Seoconfig)
- log.Println("config.Seoconfig.area", config.Seoconfig["area"])
- areamp, _ := config.Seoconfig["area"].(map[string]interface{})
- if areamp != nil {
- areamp1 := areamp[name].(map[string]interface{})
- if areamp1 != nil {
- area = areamp1["NAME"].(string)
- seotitle = areamp1["TITLE"].(string)
- seokeywords = areamp1["KEYWORDS"].(string)
- seodescription = areamp1["DESCRIPTION"].(string)
- }
- }
- } else if at == "stype" {
- stypemp, _ := config.Seoconfig["stype"].(map[string]interface{})
- if stypemp != nil {
- stypemp1 := stypemp[name].(map[string]interface{})
- if stypemp1 != nil {
- stype = stypemp1["NAME"].(string)
- seotitle = stypemp1["TITLE"].(string)
- seokeywords = stypemp1["KEYWORDS"].(string)
- seodescription = stypemp1["DESCRIPTION"].(string)
- }
- }
- } else if at == "industry" {
- industrymp, _ := config.Seoconfig["industry"].(map[string]interface{})
- if industrymp != nil {
- industrymp1 := industrymp[name].(map[string]interface{})
- if industrymp1 != nil {
- industry = industrymp1["NAME"].(string)
- seotitle = industrymp1["TITLE"].(string)
- seokeywords = industrymp1["KEYWORDS"].(string)
- seodescription = industrymp1["DESCRIPTION"].(string)
- }
- }
- }
- f.T["seoarea"] = area
- f.T["seostype"] = stype
- f.T["seotitle"] = seotitle
- f.T["seokeywords"] = seokeywords
- f.T["seodption"] = seodescription
- if area == "全国" {
- return f.Redirect("/swordfish/searchinfolist.html")
- }
- if area != "" || stype != "" || industry != "" {
- list := redis.Get("other", "classify_"+name)
- query1 := `{"query": {"bool": {"must":[`
- if area != "" {
- query1 += `{"term":{"area":"` + area + `"}}`
- } else if stype != "" {
- query1 += `{"term":{"subtype":"` + stype + `"}}`
- } else if industry != "" {
- query1 += `{"term":{"industry":"` + industry + `"}}`
- }
- query1 += `],"should": [],"minimum_should_match": 0}}}`
- query := getLastNewsQuery(area, "", stype, industry)
- var datas *[]map[string]interface{}
- if list == nil {
- count := elastic.Count(INDEX, TYPE, query1)
- //log.Println("count:", count, "----", query)
- r := rand.New(rand.NewSource(time.Now().UnixNano()))
- currentPage = no
- startPage = r.Intn(currentPage * limitcount)
- count1 := util.IntAll(count)
- if count1 < startPage || startPage < 0 {
- startPage = 0
- }
- 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)
- //log.Println("datas:", *datas)
- if len(*datas) > 0 {
- for _, v := range *datas {
- v["_id"] = util.EncodeArticleId2ByCheck(util.ObjToString(v["_id"]))
- }
- }
- redis.Put("other", "classify_"+name, datas, 2*60*60)
- } else {
- b, _ := json.Marshal(list)
- json.Unmarshal(b, &datas)
- }
- public.BidListConvert(industry, datas)
- res = searchresulthtml(datas)
- f.T["res"] = res
- f.T["area"] = area
- f.T["stype"] = stype
- f.T["industry"] = industry
- f.T["classifyname"] = name
- f.SetSession("paramarea", area)
- f.SetSession("paraminfotype", stype)
- f.T["shareid"] = se.EncodeString(shareid)
- }
- //
- if userid := f.GetSession("userId"); userid != nil {
- f.T["portraitpower"] = jylabutil.IsAuthorized(userid.(string), "i_portraitpower")
- }
- return f.Render("/pc/classifylist.html", &f.T)
- }
- //
- func (f *Front) GetClassifyList() error {
- defer util.Catch()
- //判断用户是否开启超级搜索?
- classifyname := f.GetString("classifyname")
- data := redis.Get("other", "classify_"+classifyname)
- f.ServeJson(map[string]interface{}{
- "data": data,
- })
- return nil
- }
- //
- func classify(stp, area, industry string) (string, string, string) {
- var areas, _ = config.Seoconfig["area"].(map[string]interface{})
- var stypes, _ = config.Seoconfig["stype"].(map[string]interface{})
- var industrys, _ = config.Seoconfig["industry"].(map[string]interface{})
- var tpadd = ""
- var areaadd = ""
- var induadd = ""
- if area != "" && area != "A" {
- for k, v := range areas {
- if area == v.(map[string]interface{})["NAME"] {
- areaadd = k
- }
- }
- }
- //
- if stp != "" {
- for k, v := range stypes {
- if stp == v.(map[string]interface{})["NAME"] {
- tpadd = k
- }
- }
- }
- //
- if industry != "" {
- for k, v := range industrys {
- if strings.Contains(util.ObjToString(v.(map[string]interface{})["NAME"]), industry) {
- induadd = k
- }
- }
- }
- return tpadd, areaadd, induadd
- }
- func (f *Front) HasPushHistory() {
- //获取时间
- var formatTime string
- selectTime := f.GetString("selectTime")
- // log.Println(selectTime, "---", f.GetString("area"))
- lenStr := len([]rune(selectTime))
- if selectTime != "" {
- if selectTime != "undefined" && lenStr >= 10 {
- selectTime = selectTime[0:10]
- select_time, _ := strconv.ParseInt(selectTime, 10, 64)
- //转化
- formatTime = time.Unix(select_time, 0).Format("2006-01-02")
- } else if lenStr < 10 {
- formatTime = ""
- }
- }
- userId := util.ObjToString(f.GetSession("userId"))
- var industry_ = []string{}
- if userId == "" {
- return
- }
- user, _ := jy.SubscribePush.UserInfo(public.MQFW, userId)
- hasKeyFlag := false
- isVipFlag := false
- isPassCount := false
- isExpire := -1
- tedayNum := time.Unix(time.Now().Unix(), 1).Format("20060102")
- isOnTail := 0
- var o_jy map[string]interface{}
- isread := false
- var keys []string
- otherFlag := false
- if user != nil {
- o_jy, _ = (*user)["o_jy"].(map[string]interface{})
- if o_jy != nil || len(o_jy) == 0 {
- a_key, _ := o_jy["a_key"].([]interface{})
- if a_key != nil {
- for _, v := range a_key {
- kv := util.ObjToMap(v)
- keys = append(keys, util.ObjArrToStringArr((*kv)["key"].([]interface{}))...)
- }
- }
- }
- if util.IntAll((*user)["i_vip_status"]) == 1 || util.IntAll((*user)["i_vip_status"]) == 2 {
- //
- var threeRemind = int64(3 * 24 * 60 * 60)
- var twoRemind = int64(2 * 24 * 60 * 60)
- var oneRemind = int64(1 * 24 * 60 * 60)
- var o_vipjy map[string]interface{}
- if (*user)["isread"] != nil {
- isread = (*user)["isread"].(bool)
- }
- o_vipjy, _ = (*user)["o_vipjy"].(map[string]interface{})
- industry_ = util.ObjArrToStringArr(o_vipjy["a_buyerclass"].([]interface{}))
- if o_vipjy["a_items"] != nil {
- a_itmes := util.ObjArrToMapArr(o_vipjy["a_items"].([]interface{}))
- hasKeyFlag = len(a_itmes) > 0
- }
- isVipFlag = true
- isPassCount = redis.GetInt("pushcache_2_a", "oncecount_"+tedayNum+"_"+userId) >= 2000
- isOnTail = util.IntAll((*user)["i_vip_status"])
- _endtime := (*user)["l_vip_endtime"]
- //是否到期
- if util.Int64All(_endtime)-time.Now().Unix() < threeRemind && util.Int64All(_endtime)-time.Now().Unix() >= twoRemind {
- isExpire = 3 //即将到期
- } else if util.Int64All(_endtime)-time.Now().Unix() < twoRemind && util.Int64All(_endtime)-time.Now().Unix() >= oneRemind {
- isExpire = 2 //即将到期
- } else if util.Int64All(_endtime)-time.Now().Unix() < oneRemind && util.Int64All(_endtime)-time.Now().Unix() >= 0 {
- isExpire = 1 //即将到期
- }
- //判断首次用户是否推送的带有”其他“
- t, _ := time.ParseInLocation("2006-01-02", time.Now().Format("2006-01-02"), time.Local)
- today_1 := t.Unix()
- today_2 := t.AddDate(0, 0, 1).Unix()
- if public.PushMysql.CountBySql("select count(1) as count from pushsubscribe where isvip =1 and userid =? and buyerclass=? and (date between ? and ? )", f.GetSession("userId"), 93, today_1, today_2) > 0 {
- otherFlag = true
- }
- } else {
- if (*user)["i_vip_status"] == nil {
- isExpire = 0
- } else {
- isOnTail = util.IntAll((*user)["i_vip_status"])
- }
- if o_jy != nil || len(o_jy) == 0 {
- a_key, _ := o_jy["a_key"].([]interface{})
- hasKeyFlag = len(a_key) > 0
- }
- isPassCount = redis.GetInt("pushcache_2_a", "oncecount_"+tedayNum+"_"+userId) >= 150
- }
- }
- pageNum, _ := f.GetInteger("pageNum")
- if pageNum == 0 {
- pageNum = 1
- }
- area := f.GetString("area")
- hasNextPage, list := jy.SubscribePush.Datas(public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.Collection, public.DbConf.Mongodb.Bidding.Collection_back, public.PushMysql, userId, pageNum, formatTime, area)
- if hasKeyFlag && len(list) == 0 && formatTime == "" && area == "" && !isVipFlag {
- flag, data := jy.SubscribePush.MakeHistoryDatas(public.MQFW, public.PushMysql, userId, public.PushView)
- if flag && data != nil {
- jsonBytes, err := json.Marshal(data)
- err = json.Unmarshal(jsonBytes, &list)
- if err != nil {
- log.Println("err:", err)
- }
- }
- }
- //
- f.ServeJson(map[string]interface{}{
- "haskey": hasKeyFlag,
- "data": list,
- "hasNextPage": hasNextPage,
- "isInTSguide": isInTSguide(userId),
- "isVipSub": isVipFlag,
- "isPassCount": isPassCount,
- "isExpire": isExpire,
- "isOnTail": isOnTail,
- "userId": util.EncodeArticleId(userId),
- "keys": keys,
- "otherFlag": otherFlag,
- "industry": industry_,
- "isread": isread,
- })
- }
- //历史推送
- func (f *Front) Historypush() error {
- myopenid := util.ObjToString(f.GetSession("s_m_openid"))
- userId := util.ObjToString(f.GetSession("userId"))
- if myopenid == "" || userId == "" {
- return f.Redirect("/swordfish/share/-1")
- }
- //
- times := f.GetString("times")
- //
- // 打开推送
- data, ok := mongodb.FindById("user", userId, nil)
- if ok && data != nil && len(*data) > 0 {
- //VIP服务到期
- vipSubtips := (*data)["i_vip_subtips"]
- if vipSubtips == 0 {
- if mongodb.UpdateById("user", userId, bson.M{"$set": bson.M{"i_vip_subtips": 1}}) {
- return f.Redirect("/front/vipsubscribe/renewPage/exprie")
- }
- }
- }
- f.T["forceShareFlag"] = public.CheckUserNeedForceShare(myopenid, public.ShareType_push)
- mynickname, _ := f.Session().Get("s_nickname").(string)
- myavatar, _ := f.Session().Get("s_avatar").(string)
- f.T["nickname"] = mynickname
- f.T["avatar"] = myavatar
- f.T["signature"] = wx.SignJSSDK(f.Site() + f.Url())
- f.T["openid"] = se.EncodeString(myopenid)
- f.T["stime"] = times
- f.T["isVip"] = util.IntAll((*data)["i_vip_status"]) > 0
- f.T["isread"] = (*data)["isread"]
- f.T["userId"] = userId
- //直播活动和预热活动期间
- if config.ActiveConfig.Live_Active_End > time.Now().Unix() && time.Now().Unix() > config.ActiveConfig.Live_Preheat_Start {
- f.T["LiveState"] = true
- }
- return f.Render("/weixin/historypush.html", &f.T)
- }
- func (f *Front) HistorypushPaging() error {
- pageNum, _ := f.GetInteger("pageNum")
- //
- selectTime := f.GetString("selectTime")
- var formatTime string
- if selectTime != "" {
- selectTime = selectTime[0:10]
- select_time, _ := strconv.ParseInt(selectTime, 10, 64)
- //转化
- formatTime = time.Unix(select_time, 0).Format("2006-01-02")
- }
- area := f.GetString("area")
- log.Println("~~~~~:", formatTime, "~~~~", selectTime, "~~~", pageNum, "~~~", area)
- //
- userId := util.ObjToString(f.GetSession("userId"))
- if userId != "" {
- // user, firstPushTime := public.HistoryPush.UserInfo(userId)
- // if user == nil {
- // return nil
- // }
- hasNextPage, list := jy.SubscribePush.Datas(public.Mgo_Bidding, public.DbConf.Mongodb.Bidding.Collection, public.DbConf.Mongodb.Bidding.Collection, public.PushMysql, userId, pageNum, formatTime, area)
- // hasNextPage, list, _ := public.HistoryPush.Datas(userId, pageNum, firstPushTime, formatTime)
- f.ServeJson(map[string]interface{}{
- "hasNextPage": hasNextPage,
- "data": list,
- })
- }
- return nil
- }
- //电脑端招标订阅
- func (m *Front) Subscribe() error {
- var shareid = m.GetString("id")
- if len(shareid) == 0 {
- shareid = "10" //fmt.Sprintf("%s%d", config.Seoconfig["jydyy"].(string)+fmt.Sprintf("%d", time.Now().UnixNano())[7:14], rand.Intn(9))
- }
- m.T["logid"] = config.Seoconfig["jydyy"].(string)
- m.T["noshareid"] = shareid
- m.T["shareid"] = se.EncodeString(shareid)
- myopenid, _ := m.Session().Get("s_m_openid").(string)
- m.T["openid"] = se.EncodeString(myopenid)
- mynickname, _ := m.Session().Get("s_nickname").(string)
- myavatar, _ := m.Session().Get("s_avatar").(string)
- m.T["nickname"] = mynickname
- m.T["avatar"] = myavatar
- m.T["signature"] = wx.SignJSSDK(m.Site() + m.Url())
- return m.Render("/pc/subscribe_new.html", &m.T)
- }
- //获取高级查询所需的参数
- func getShouldQueryMap(findfield, searchvalue, industry string) []map[string]string {
- mps := []map[string]string{}
- for _, v := range strings.Split(industry, ",") {
- mp := map[string]string{}
- for _, v := range strings.Split(searchvalue, "+") {
- mp[v] = findfield
- }
- mp[v] = "s_subscopeclass"
- mps = append(mps, mp)
- }
- return mps
- }
- func getSearchQuery(keyword, industry, minprice, maxprice, findfields, mustquery string) (qstr string) {
- multi_match := `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
- //match_phrase := `{"match_phrase": {"s_subscopeclass": "%s"}}`
- query := `{"query":{"bool":{"must":[%s]}}}`
- query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
- 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}}}]}}`
- query_bool_must := `{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
- //rge := `{"range": {"bidamount": {%s}}},{"range": {"budget": {%s}}}`
- gte := `"gte": %s`
- lte := `"lte": %s`
- musts := []string{}
- if mustquery != "" {
- musts = append(musts, mustquery)
- }
- if keyword != "" {
- multi_match = fmt.Sprintf(multi_match, "%s", findfields)
- shoulds := []string{}
- for _, v := range strings.Split(keyword, "+") {
- shoulds = append(shoulds, fmt.Sprintf(multi_match, elastic.ReplaceYH(v)))
- }
- musts = append(musts, fmt.Sprintf(elastic.NgramMust, strings.Join(shoulds, ",")))
- }
- if industry != "" {
- industrys := strings.Split(industry, ",")
- musts = append(musts, fmt.Sprintf(query_bool_must, `"`+strings.Join(industrys, `","`)+`"`))
- }
- if minprice != "" || maxprice != "" {
- sq := ``
- if minprice != "" {
- min, _ := strconv.ParseFloat(minprice, 64)
- minprice = fmt.Sprintf("%.0f", min*10000)
- if minprice == "0" {
- minprice = ""
- }
- }
- if maxprice != "" {
- max, _ := strconv.ParseFloat(maxprice, 64)
- maxprice = fmt.Sprintf("%.0f", max*10000)
- if maxprice == "0" {
- maxprice = ""
- }
- }
- if minprice != "" {
- sq += fmt.Sprintf(gte, minprice)
- }
- if minprice != "" && maxprice != "" {
- sq += `,`
- }
- if maxprice != "" {
- sq += fmt.Sprintf(lte, maxprice)
- }
- query_price := fmt.Sprintf(query_bool_should, fmt.Sprintf(query_bools_must, sq, sq, sq))
- musts = append(musts, query_price)
- }
- qstr = fmt.Sprintf(query, strings.Join(musts, ","))
- //log.Println("getSearchQuery:", qstr)
- return
- }
- //
- func wxPushViewDatas(index, itype string, keys []elastic.KeyConfig, allquery, findfields, SortQuery, fields string, start, limit int) *[]map[string]interface{} {
- query_all := `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match":1}}}`
- match_detail := `{"match":{"detail":{"query":"%s","operator": "and"}}}`
- minq := `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
- highlightStr := `%s: {"fragment_size": %d,"number_of_fragments": 1}`
- query_bool := `{"bool":{"must":[%s],"should":[%s],"must_not":[%s],"minimum_should_match":1}}`
- bool_must := `{"bool":{"must":[%s]}}`
- //
- searchDetail := strings.Contains(findfields, `"detail"`)
- if len(keys) > 0 {
- qstr := ""
- new_minq := fmt.Sprintf(minq, "%s", `"title"`)
- not_new_minq := fmt.Sprintf(minq, "%s", `"title"`) //排除词只查询标题
- musts := []string{}
- for _, qs_words := range keys {
- mq := []string{}
- notmq := []string{}
- shoulds := []string{}
- keywords := []string{}
- boolmusts := []string{}
- for _, qs_word := range qs_words.Keys {
- qs_word = elastic.ReplaceYH(qs_word)
- keywords = append(keywords, qs_word)
- boolmusts = append(boolmusts, fmt.Sprintf(new_minq, qs_word))
- }
- shoulds = append(shoulds, fmt.Sprintf(bool_must, strings.Join(boolmusts, ",")))
- if searchDetail {
- shoulds = append(shoulds, fmt.Sprintf(match_detail, strings.Join(keywords, " ")))
- }
- for _, qs_word := range qs_words.NotKeys {
- notmq = append(notmq, fmt.Sprintf(not_new_minq, elastic.ReplaceYH(qs_word)))
- if searchDetail {
- notmq = append(notmq, fmt.Sprintf(match_detail, elastic.ReplaceYH(qs_word)))
- }
- }
- if len(qs_words.Areas) > 0 {
- mq = append(mq, fmt.Sprintf(`{"terms":{"area":["%s"]}}`, strings.Join(qs_words.Areas, `","`)))
- }
- if len(qs_words.InfoTypes) > 0 {
- mq = append(mq, fmt.Sprintf(`{"terms":{"toptype":["%s"]}}`, strings.Join(qs_words.InfoTypes, `","`)))
- }
- musts = append(musts, fmt.Sprintf(query_bool, strings.Join(mq, ","), strings.Join(shoulds, ","), strings.Join(notmq, ",")))
- }
- qstr = fmt.Sprintf(query_all, "", strings.Join(musts, ","))
- qstr = fmt.Sprintf(elastic.FilterQuery, allquery, qstr[1:])
- ws := []string{}
- for _, w := range strings.Split(findfields, ",") {
- ws = append(ws, fmt.Sprintf(highlightStr, w, 1))
- }
- qstr = qstr[:len(qstr)-1] + `,` + fmt.Sprintf(elastic.HL, strings.Join(ws, ",")) + `}`
- if len(fields) > 0 {
- qstr = qstr[:len(qstr)-1] + `,"_source":[` + fields + "]}"
- }
- if len(SortQuery) > 0 {
- qstr = qstr[:len(qstr)-1] + `,"sort":` + SortQuery + `}`
- }
- if start > -1 {
- qstr = qstr[:len(qstr)-1] + `,"from":` + strconv.Itoa(start) + `,"size":` + strconv.Itoa(limit) + "}"
- }
- //log.Println("jy-ngram-find", qstr)
- return elastic.Get(index, itype, qstr)
- } else {
- return nil
- }
- }
- //金额转化 金额:0-万元以下单位为元 ,万元以上至亿元以下单位为万元 ,亿元以上单位为亿元。保留 小数点后 2 位,不进行四舍五入。
- func ConversionMoeny(i_money interface{}) string {
- m := ""
- if reflect.TypeOf(i_money).Name() == "float64" {
- m = strconv.FormatFloat(util.Float64All(i_money), 'f', -1, 64)
- } else {
- m = util.ObjToString(i_money)
- }
- if m == "" {
- return m
- }
- m_arr := strings.Split(m, ".")
- m_1 := m_arr[0]
- len_m1 := len([]rune(m_1))
- if len_m1 >= 9 {
- m = m_1[0:len_m1-8] + "." + m_1[len_m1-8:len_m1-6] + "亿元"
- } else if len_m1 >= 5 {
- m = m_1[0:len_m1-4] + "." + m_1[len_m1-4:len_m1-2] + "万元"
- } else {
- if len(m_arr) == 1 {
- return m + ".00元"
- }
- m_2 := m_arr[1]
- if len([]rune(m_2)) > 1 {
- m_2 = m_2[0:2]
- } else {
- m_2 = m_2[0:1] + "0"
- }
- m = m_1 + "." + m_2 + "元"
- }
- return m
- }
|