123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529 |
- package front
- import (
- "fmt"
- "jfw/config"
- "jfw/filter"
- "jfw/jylabutil"
- "jfw/public"
- "math/rand"
- "net/http"
- "qfw/util"
- "qfw/util/elastic"
- "qfw/util/jy"
- "qfw/util/redis"
- "strconv"
- "strings"
- "time"
- uc "ucbsutil"
- "github.com/SKatiyar/qr"
- "github.com/go-xweb/xweb"
- "github.com/gocql/gocql"
- )
- type Pcsearch struct {
- *xweb.Action
- pcSearchIndex xweb.Mapper `xweb:"/jylab/supsearch/index.html"` //搜索首页
- getNewBids xweb.Mapper `xweb:"/jylab/supsearch/getNewBids"` //最新招标信息
- getstatus xweb.Mapper `xweb:"/jylab/supsearch/getstatus"` //实验室开启状态
- proposedProject xweb.Mapper `xweb:"/jylab/supsearch/proposedProject.html"` //拟建项目
- qr xweb.Mapper `xweb:"/jylab/supsearch/qr/(.*)"` //生成进入实验室的二维码
- changePro xweb.Mapper `xweb:"/jylab/changePro"` //修改提示信息状态
- }
- //
- var industrylist map[string][]string
- var sortArray []string
- var industryname string
- //
- func init() {
- xweb.AddAction(&Pcsearch{})
- industryname = util.ObjToString(config.Sysconfig["industry"])
- industrylist, sortArray = getindustrys()
- }
- //
- func (p *Pcsearch) ChangePro() {
- defer util.Catch()
- userid := p.GetSession("userId")
- if userid != nil {
- jylabutil.UpdateAuthory(userid.(string), "i_tablepro", 1)
- }
- }
- //
- func (p *Pcsearch) ProposedProject() error {
- defer util.Catch()
- var shareid = p.GetString("id")
- if len(shareid) == 0 {
- shareid = "10"
- }
- p.T["logid"] = config.Seoconfig["jynjxmy"].(string)
- b_word, _, s_word := jy.InterceptSearchKW(p.GetString("keywords"), false, true)
- area := p.GetString("area") //地区
- publishtime := p.GetString("publishtime") //发布时间
- subtype := p.GetString("subtype") //信息类型
- if subtype == "" {
- subtype = "拟建"
- }
- var totalPage int64
- var list *[]map[string]interface{}
- var status = 1
- if len(s_word) > 0 {
- status = 2
- var count int64
- count, totalPage, list = getBidSearchData(s_word, area, publishtime, subtype, "", "", "", 0, true, "", "")
- listSize := 0
- if list != nil {
- listSize = len(*list)
- }
- SaveUserSearchLog(p.Request, util.ObjToString(p.GetSession("userId")), count, "pc", "拟建", map[string]interface{}{
- "search_word": s_word,
- "search_area": area,
- "search_publishtime": publishtime,
- "pagenum": 1,
- "pagesize": listSize,
- })
- } else {
- p.DisableHttpCache()
- p.T["list"] = Newbids("nijian")[0]
- }
- if status == 2 {
- 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["detail"] = detail
- }
- }
- p.T["list"] = list
- }
- p.T["area"] = area
- p.T["subtype"] = subtype
- p.T["publishtime"] = publishtime
- p.T["timeslot"] = p.GetString("timeslot")
- p.T["totalPage"] = totalPage
- p.T["keywords"] = b_word
- p.T["searchvalue"] = s_word
- p.T["login"] = p.Session().Get("user")
- p.SetSession("paramkey", b_word)
- if publishtime == "lately-7" {
- p.SetSession("parampublishtime", "最近7天")
- } else if publishtime == "lately-30" {
- p.SetSession("parampublishtime", "最近30天")
- } else if publishtime == "thisyear" {
- p.SetSession("parampublishtime", "去年")
- } else {
- p.SetSession("parampublishtime", publishtime)
- }
- p.SetSession("paramarea", area)
- p.T["shareid"] = se.EncodeString(shareid)
- return p.Render("/pc/proproject.html", &p.T)
- }
- //
- func (p *Pcsearch) Getstatus() error {
- defer util.Catch()
- var supstatus, entstatus, tablepro, dataexportstatus, portraitpower, followent, smartstatus bool
- if userid := util.ObjToString(p.GetSession("userId")); userid != "" {
- user, b := mongodb.FindById("user", userid,
- `{"i_tablepro":1}`)
- if len(*user) > 0 && b {
- tablepro = util.Int64All((*user)["i_tablepro"]) == 1
- }
- }
- p.ServeJson(map[string]interface{}{
- "smartstatus": smartstatus,
- "supstatus": supstatus,
- "entstatus": entstatus,
- "tablepro": tablepro,
- "dataexportstatus": dataexportstatus,
- "portraitpower": portraitpower,
- "followent": followent,
- })
- return nil
- }
- //
- func (p *Pcsearch) GetNewBids() error {
- pagenum, _ := p.GetInteger("pageNumber")
- pageType := p.GetString("pageType")
- list := util.ObjArrToMapArr(Newbids(pageType)[pagenum-1].([]interface{}))
- if pageType == "" { //最新招标信息仅第一页条展示表格多字段
- for k, v := range list {
- if pagenum == 1 && k < 20 {
- continue
- }
- delete(v, "areaadd")
- delete(v, "bidopentime")
- delete(v, "buyer")
- delete(v, "indadd")
- delete(v, "k")
- delete(v, "projectcode")
- delete(v, "projectname")
- delete(v, "stypeadd")
- delete(v, "winner")
- delete(v, "timetemp")
- delete(v, "budget")
- delete(v, "s_subscopeclass")
- delete(v, "toptype")
- }
- }
- p.ServeJson(map[string]interface{}{
- "list": list,
- })
- return nil
- }
- //
- func (p *Pcsearch) PcSearchIndex() error {
- defer util.Catch()
- var shareid = p.GetString("id")
- if len(shareid) == 0 {
- shareid = "10"
- }
- p.T["logid"] = config.Seoconfig["jysslby"].(string)
- fmt.Println("logid:", config.Seoconfig["jysslby"].(string))
- keywords := p.GetString("keywords")
- area := p.GetString("area") //地区
- publishtime := p.GetString("publishtime") //发布时间
- timeslot := p.GetString("timeslot") //显示选择时间
- toptype := p.GetString("toptype") //信息类型
- subtype := p.GetString("subtype") //信息类型
- minprice := p.GetString("minprice") //最低价格
- maxprice := p.GetString("maxprice") //最高价格
- industry := strings.TrimSpace(p.GetString("industry")) //选中的行业
- p.SetSession("industry", industry)
- selectType := p.GetString("selectType") //标题或全文
- selectTypesess := p.GetSession("selectType")
- if selectTypesess != nil && selectTypesess != "" {
- selectType = selectTypesess.(string)
- }
- //if selectType == "" {
- selectType = "title"
- //}
- //历史导出数据回显
- if strings.Contains(p.Url(), "?goback") {
- keywords = util.ObjToString(p.GetSession("Echo_keywords"))
- publishtime = util.ObjToString(p.GetSession("Echo_publishtime"))
- area = util.ObjToString(p.GetSession("Echo_area"))
- subtype = util.ObjToString(p.GetSession("Echo_subtype"))
- minprice = util.ObjToString(p.GetSession("Echo_minprice"))
- maxprice = util.ObjToString(p.GetSession("Echo_maxprice"))
- industry = util.ObjToString(p.GetSession("Echo_industry"))
- selectType = util.ObjToString(p.GetSession("Echo_selectType"))
- timeslot = util.ObjToString(p.GetSession("Echo_timeslot"))
- }
- b_word, _, s_word := jy.InterceptSearchKW(keywords, false, len(industry) == 0)
- var list *[]map[string]interface{}
- var status = 1
- var count, totalPage int64
- secondFlag := ""
- secondKWS := ""
- if len(s_word) > 0 || len(industry) > 0 {
- status = 2
- count, totalPage, list = getBidSearchData(s_word, area, publishtime, subtype, industry, minprice, maxprice, 0, true, selectType, "")
- listSize := 0
- if list != nil {
- listSize = len(*list)
- }
- //所有的再次分词查询 只查标题
- if len([]rune(s_word)) > 3 && int(count) < pc_pageSize {
- secondKWS = jy.HttpEs(s_word, "ik_smart", config.Sysconfig["elasticsearch"].(string))
- findfields := `"title"`
- qstr := getSearchQuery(secondKWS, industry, minprice, maxprice, findfields, getBidSearchQuery(area, publishtime, subtype))
- secondLimit := 2*pc_pageSize - int(count)
- secRel := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, 0, secondLimit, 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"
- }
- }
- SaveUserSearchLog(p.Request, util.ObjToString(p.GetSession("userId")), count, "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": 1,
- "pagesize": listSize,
- })
- } else {
- p.DisableHttpCache()
- p.T["list"] = Newbids("")[0]
- }
- if status == 2 {
- 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)
- 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
- }
- }
- if secondFlag == "" {
- p.T["list"] = list
- } else {
- if len(*list) > pc_pageSize {
- p.T["list"] = (*list)[:pc_pageSize]
- p.T["secondList"] = (*list)[pc_pageSize:]
- } else {
- p.T["list"] = list
- p.T["secondList"] = ""
- totalPage = 1
- }
- }
- }
- p.T["secondFlag"] = secondFlag
- p.T["area"] = area
- p.T["publishtime"] = publishtime
- p.T["timeslot"] = timeslot
- p.T["toptype"] = toptype
- p.T["subtype"] = subtype
- p.T["keywords"] = b_word
- p.T["searchvalue"] = s_word
- p.T["selectType"] = selectType
- p.T["industry"] = industry
- p.T["minprice"] = minprice
- p.T["maxprice"] = maxprice
- p.T["login"] = p.Session().Get("user")
- p.T["totalPage"] = totalPage
- p.T["count"] = count
- p.SetSession("paramkey", b_word)
- if publishtime == "lately-7" {
- p.SetSession("parampublishtime", "最近7天")
- } else if publishtime == "lately-30" {
- p.SetSession("parampublishtime", "最近30天")
- } else if publishtime == "thisyear" {
- p.SetSession("parampublishtime", "去年")
- } else {
- p.SetSession("parampublishtime", publishtime)
- }
- p.SetSession("paramarea", area)
- if subtype != "" {
- p.SetSession("paraminfotype", subtype)
- } else {
- p.SetSession("paraminfotype", toptype)
- }
- p.T["industrylist"] = industrylist
- p.T["sortArray"] = sortArray
- p.T["shareid"] = se.EncodeString(shareid)
- //
- if userid := p.GetSession("userId"); userid != nil {
- p.T["portraitpower"] = jylabutil.IsAuthorized(userid.(string), "i_portraitpower")
- }
- return p.Render("/pc/supsearch.html", &p.T)
- }
- //
- func getindustrys() (industry map[string][]string, sortArray []string) {
- industry = map[string][]string{}
- sortArray = []string{}
- classdata, ok1 := mongodb.FindOneByField("rc_task", `{"s_name":"`+industryname+`"}`, `{"s_class":1}`)
- if ok1 && len(*classdata) > 0 {
- classid := ""
- if util.ObjToString((*classdata)["s_class"]) != "" {
- classids := strings.Split(util.ObjToString((*classdata)["s_class"]), ",")
- for k, v := range classids {
- if k > 0 {
- classid += `,`
- }
- classid += `"` + v + `"`
- }
- }
- industryData, ok := mongodb.Find("rc_rule", `{"s_pid":{"$ne":""},"s_classid":{"$in":[`+classid+`]}}`, `{"i_order":1}`, `{"_id":1,"s_name":1}`, false, -1, -1)
- if ok && industryData != nil && len(*industryData) > 0 {
- for _, v := range *industryData {
- fatFlag := 0
- industryname, _ := v["s_name"].(string)
- if strings.Contains(industryname, "_") {
- fat := strings.Split(industryname, "_")[0]
- child := strings.Split(industryname, "_")[1]
- if len(industry[fat]) == 0 {
- sortArray = append(sortArray, fat)
- }
- for _, fv := range industry[fat] {
- if fv == strings.Trim(child, " ") {
- fatFlag = 1
- break
- }
- }
- if fatFlag != 1 {
- industry[fat] = append(industry[fat], child)
- }
- }
- }
- }
- }
- return industry, sortArray
- }
- //
- func Newbids(p string) []interface{} {
- pages, _ := redis.Get("other", "index_list"+p).([]interface{})
- if len(pages) == 0 {
- var list *[]map[string]interface{}
- subtype := ""
- if len(p) > 0 {
- subtype = "拟建"
- }
- 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++ {
- _, list = getLastNewsData("", "", "", subtype, "", "", "", "Y", 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)
- indtry := util.ObjToString(v["industry"])
- v["stypeadd"], v["areaadd"], v["indadd"] = classify(stp, area, indtry)
- }
- pages = append(pages, list)
- }
- redis.Put("other", "index_list"+p, pages, 60*60*24*2)
- }
- return pages
- }
- //二维码图片
- func (p *Pcsearch) Qr(t string) error {
- openid := p.GetSession("openid")
- if openid == nil {
- return nil
- }
- w := p.ResponseWriter
- w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
- w.Header().Set("Pragma", "no-cache")
- w.Header().Set("Expires", "0")
- w.Header().Set("Content-Type", "image/png")
- data := config.Sysconfig["webdomain"].(string) + "/front/sess/" + sewx.EncodeString(openid.(string)+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",qrToLab") + "__" + t
- r, _ := qr.Encode(data, qr.M)
- pngdat := r.PNG()
- _, err := w.Write(pngdat)
- return err
- }
- //保存用户搜索日志
- func SaveUserSearchLog(request *http.Request, userid string, count int64, platform, source string, condition map[string]interface{}) {
- go func() {
- data := map[string]interface{}{
- "ip": filter.GetIp(request),
- "count": count,
- "openid": userid,
- "pform": platform,
- "source": source,
- "date": time.Now(),
- "uagent": request.Header.Get("User-Agent"),
- }
- for _, v := range []string{"pagenum", "pagesize", "search_word", "search_area", "search_publishtime", "search_industry", "search_price", "search_type"} {
- if vv := condition[v]; vv != nil {
- //替换key
- if v == "search_word" {
- v = "word"
- } else if v == "search_area" {
- v = "area"
- } else if v == "search_publishtime" {
- v = "ptime"
- } else if v == "search_industry" {
- v = "indst"
- } else if v == "search_price" {
- v = "price"
- } else if v == "search_type" {
- v = "type"
- } else if v == "pagenum" {
- v = "pnum"
- } else if v == "pagesize" {
- v = "psize"
- }
- data[v] = vv
- }
- }
- data["id"] = uc.DayShortTime()
- data["tuid"] = gocql.TimeUUID()
- if !public.Ca_Log.SaveCache("jy_search", data) {
- data := map[string]interface{}{
- "ip": filter.GetIp(request),
- "count": count,
- "s_userid": userid,
- "platform": platform,
- "source": source,
- "createtime": time.Now().Unix(),
- "userAgent": request.Header.Get("User-Agent"),
- }
- for _, v := range []string{"pagenum", "pagesize", "search_word", "search_area", "search_publishtime", "search_industry", "search_price", "search_type"} {
- if vv := condition[v]; vv != nil {
- data[v] = vv
- }
- }
- mongodb.Save("jy_search_log", data)
- }
- }()
- }
|