wangkaiyue 4 years ago
parent
commit
6da07fade3

+ 29 - 72
src/jfw/front/dataExport.go

@@ -1,7 +1,6 @@
 package front
 package front
 
 
 import (
 import (
-	//"encoding/base64"
 	"encoding/json"
 	"encoding/json"
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
@@ -10,7 +9,6 @@ import (
 	"log"
 	"log"
 	"os"
 	"os"
 	"qfw/util"
 	"qfw/util"
-	"qfw/util/jy"
 	"qfw/util/redis"
 	"qfw/util/redis"
 	"regexp"
 	"regexp"
 	"strconv"
 	"strconv"
@@ -18,7 +16,6 @@ import (
 	"sync"
 	"sync"
 	"time"
 	"time"
 
 
-	//"github.com/SKatiyar/qr"
 	"github.com/go-xweb/xweb"
 	"github.com/go-xweb/xweb"
 	"github.com/tealeg/xlsx"
 	"github.com/tealeg/xlsx"
 )
 )
@@ -337,81 +334,41 @@ func (d *DataExport) SuperSearchExport() error {
 		return errors.New("未登录")
 		return errors.New("未登录")
 	}
 	}
 	//接收超级搜索页面参数
 	//接收超级搜索页面参数
-	keywords := d.GetString("keywords")                    //搜索词
-	publishtime := d.GetString("publishtime")              //发布时间
-	area := d.GetString("area")                            //地区
-	subtype := d.GetString("subtype")                      //信息类型
-	minprice := d.GetString("minprice")                    //最低价格
-	maxprice := d.GetString("maxprice")                    //最高价格
-	industry := strings.TrimSpace(d.GetString("industry")) //选中的行业
-	selectType := d.GetString("selectType")                //标题 or 全文
+	reqData := public.BidSearchExport{
+		Keywords:     d.GetString("keywords"),                    //搜索词
+		Publishtime:  d.GetString("publishtime"),                 //发布时间
+		Area:         d.GetString("area"),                        //地区
+		Subtype:      d.GetString("subtype"),                     //信息类型
+		Minprice:     d.GetString("minprice"),                    //最低价格
+		Maxprice:     d.GetString("maxprice"),                    //最高价格
+		Industry:     strings.TrimSpace(d.GetString("industry")), //选中的行业
+		SelectType:   d.GetString("selectType"),                  //标题 or 全文
+		Buyerclass:   d.GetString("buyerclass"),                  //采购单位行业
+		Hasbuyertel:  d.GetString("buyertel"),                    //是否有采购电话
+		Haswinnertel: d.GetString("winnertel"),                   //是否有中标电话
+	}
 
 
 	//数据回显
 	//数据回显
-	d.SetSession("Echo_keywords", keywords)
-	d.SetSession("Echo_publishtime", publishtime)
 	d.SetSession("Echo_timeslot", d.GetString("timeslot"))
 	d.SetSession("Echo_timeslot", d.GetString("timeslot"))
-	d.SetSession("Echo_area", area)
-	d.SetSession("Echo_subtype", subtype)
-	d.SetSession("Echo_minprice", minprice)
-	d.SetSession("Echo_maxprice", maxprice)
-	d.SetSession("Echo_industry", industry)
-	d.SetSession("Echo_selectType", selectType)
-
-	//数据存库转换
-	areaSave := []string{}
-	if len(area) > 0 {
-		areaSave = strings.Split(area, ",")
-	}
-	industrySave := []string{}
-	if len(industry) > 0 {
-		industrySave = strings.Split(industry, ",")
-	}
-	//格式化keywords
-	KeyWordSave := []public.KeyWord{}
-
-	if len(keywords) > 0 {
-		isIntercept := false
-		if selectType == "all" {
-			isIntercept = true
-		}
-		_, _, keywords = jy.InterceptSearchKW(keywords, isIntercept, len(industrySave) == 0)
-		keywords = strings.Replace(keywords, "+", " ", -1)
-		KeyWordSave = append(KeyWordSave, public.KeyWord{Keyword: keywords, Appended: []string{}, Exclude: []string{}})
-	}
-	//时间
-	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())
-		publishtime = fmt.Sprintf("%s_%d", starttime, now.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())
-		publishtime = fmt.Sprintf("%s_%d", starttime, now.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())
-		publishtime = fmt.Sprintf("%s_%s", starttime, endtime)
-	}
+	d.SetSession("Echo_keywords", reqData.Keywords)
+	d.SetSession("Echo_publishtime", reqData.Publishtime)
+	d.SetSession("Echo_area", reqData.Publishtime)
+	d.SetSession("Echo_subtype", reqData.Subtype)
+	d.SetSession("Echo_minprice", reqData.Minprice)
+	d.SetSession("Echo_maxprice", reqData.Maxprice)
+	d.SetSession("Echo_industry", reqData.Industry)
+	d.SetSession("Echo_selectType", reqData.SelectType)
+	d.SetSession("Echo_buyerclass", reqData.Buyerclass)
+	d.SetSession("Echo_hasBuyertel", reqData.Hasbuyertel)
+	d.SetSession("Echo_hasWinnertel", reqData.Haswinnertel)
 
 
-	data := map[string]interface{}{
-		"keywords":    KeyWordSave,
-		"publishtime": publishtime,
-		"area":        areaSave,
-		"subtype":     subtype,
-		"minprice":    minprice,
-		"maxprice":    maxprice,
-		"industry":    industrySave,
-		"selectType":  selectType,
-		"comeintime":  now.Unix(),
-		"s_openid":    openid,
-		"comeinfrom":  "supersearchPage",
-		"s_userid":    userId,
-	}
+	saveData := reqData.PassBidSearchExport()
+	saveData["s_openid"] = openid
+	saveData["s_userid"] = userId
 
 
 	//存入数据库
 	//存入数据库
-	_id := mongodb.Save(public.ExportTable, data)
-	//携带id跳转订单生成页面
-	d.Redirect("/front/dataExport/toCreateOrderPage/" + util.SE.Encode2Hex(_id))
-	return nil
+	_id := mongodb.Save(public.ExportTable, saveData)
+	return d.Redirect("/front/dataExport/toCreateOrderPage/" + util.SE.Encode2Hex(_id))
 }
 }
 func (d *DataExport) ToCreateOrderPage(_id string) error {
 func (d *DataExport) ToCreateOrderPage(_id string) error {
 	id := util.SE.Decode4Hex(_id)
 	id := util.SE.Decode4Hex(_id)

+ 4 - 1
src/jfw/front/supsearch.go

@@ -265,9 +265,12 @@ func (p *Pcsearch) PcSearchIndex() error {
 		subtype = util.ObjToString(p.GetSession("Echo_subtype"))
 		subtype = util.ObjToString(p.GetSession("Echo_subtype"))
 		minprice = util.ObjToString(p.GetSession("Echo_minprice"))
 		minprice = util.ObjToString(p.GetSession("Echo_minprice"))
 		maxprice = util.ObjToString(p.GetSession("Echo_maxprice"))
 		maxprice = util.ObjToString(p.GetSession("Echo_maxprice"))
-		industry = util.ObjToString(p.GetSession("Echo_industry"))
+		buyerclass = util.ObjToString(p.GetSession("Echo_buyerclass"))
 		selectType = util.ObjToString(p.GetSession("Echo_selectType"))
 		selectType = util.ObjToString(p.GetSession("Echo_selectType"))
 		timeslot = util.ObjToString(p.GetSession("Echo_timeslot"))
 		timeslot = util.ObjToString(p.GetSession("Echo_timeslot"))
+		if vipData.Status > 0 || vipData.VipStatus > 0 {
+			industry = util.ObjToString(p.GetSession("Echo_industry"))
+		}
 	}
 	}
 	b_word, s_word := "", ""
 	b_word, s_word := "", ""
 	if keywords != "" {
 	if keywords != "" {

+ 21 - 61
src/jfw/front/ws_dataExport.go

@@ -16,7 +16,6 @@ import (
 	"log"
 	"log"
 	"net/url"
 	"net/url"
 	"qfw/util"
 	"qfw/util"
-	"qfw/util/jy"
 	"qfw/util/redis"
 	"qfw/util/redis"
 	"strings"
 	"strings"
 	"time"
 	"time"
@@ -388,73 +387,34 @@ func (w *WsDataExport) SubmitOrder() error {
 }
 }
 
 
 //微信数据导出
 //微信数据导出
-func (w *WsDataExport) SearchExport() error {
-	openid := util.ObjToString(w.GetSession("s_m_openid"))
-	userId := util.ObjToString(w.GetSession("userId"))
+func (wd *WsDataExport) SearchExport() error {
+	openid := util.ObjToString(wd.GetSession("s_m_openid"))
+	userId := util.ObjToString(wd.GetSession("userId"))
 	if userId == "" {
 	if userId == "" {
 		return errors.New("未登录")
 		return errors.New("未登录")
 	}
 	}
 	//接收超级搜索页面参数
 	//接收超级搜索页面参数
-	keywords := w.GetString("searchvalue")                 //搜索词
-	publishtime := w.GetString("publishtime")              //发布时间
-	area := w.GetString("scope")                           //地区
-	subtype := w.GetString("subtype")                      //信息类型
-	minprice := w.GetString("minprice")                    //最低价格
-	maxprice := w.GetString("maxprice")                    //最高价格
-	industry := strings.TrimSpace(w.GetString("industry")) //选中的行业
-	selectType := w.GetString("selectType")                //标题 or 全文
-	//数据存库转换
-	areaSave := []string{}
-	if len(area) > 0 {
-		areaSave = strings.Split(area, ",")
-	}
-	industrySave := []string{}
-	if len(industry) > 0 {
-		industrySave = strings.Split(industry, ",")
+	reqData := public.BidSearchExport{
+		Keywords:     wd.GetString("keywords"),                    //搜索词
+		Publishtime:  wd.GetString("publishtime"),                 //发布时间
+		Area:         wd.GetString("area"),                        //地区
+		Subtype:      wd.GetString("subtype"),                     //信息类型
+		Minprice:     wd.GetString("minprice"),                    //最低价格
+		Maxprice:     wd.GetString("maxprice"),                    //最高价格
+		Industry:     strings.TrimSpace(wd.GetString("industry")), //选中的行业
+		SelectType:   wd.GetString("selectType"),                  //标题 or 全文
+		Buyerclass:   wd.GetString("buyerclass"),                  //采购单位行业
+		Hasbuyertel:  wd.GetString("buyertel"),                    //是否有采购电话
+		Haswinnertel: wd.GetString("winnertel"),                   //是否有中标电话
 	}
 	}
-	//格式化keywords
-	KeyWordSave := []public.KeyWord{}
 
 
-	if len(keywords) > 0 {
-		isIntercept := false
-		if selectType == "all" {
-			isIntercept = true
-		}
-		_, _, keywords = jy.InterceptSearchKW(keywords, isIntercept, len(industrySave) == 0)
-		keywords = strings.Replace(keywords, "+", " ", -1)
-		KeyWordSave = append(KeyWordSave, public.KeyWord{Keyword: keywords})
-	}
-	//时间
-	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())
-		publishtime = fmt.Sprintf("%s_%d", starttime, now.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())
-		publishtime = fmt.Sprintf("%s_%d", starttime, now.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())
-		publishtime = fmt.Sprintf("%s_%s", starttime, endtime)
-	}
-
-	data := map[string]interface{}{
-		"keywords":    KeyWordSave,
-		"publishtime": publishtime,
-		"area":        areaSave,
-		"subtype":     subtype,
-		"minprice":    minprice,
-		"maxprice":    maxprice,
-		"industry":    industrySave,
-		"selectType":  selectType,
-		"comeintime":  now.Unix(),
-		"s_openid":    openid,
-		"comeinfrom":  "supersearchPage",
-		"s_userid":    userId,
-	}
+	saveData := reqData.PassBidSearchExport()
+	saveData["s_openid"] = openid
+	saveData["s_userid"] = userId
 
 
 	//存入数据库
 	//存入数据库
-	_id := mongodb.Save(public.ExportTable, data)
-	w.ServeJson(bson.M{"_id": util.SE.Encode2Hex(_id)})
+	_id := mongodb.Save(public.ExportTable, saveData)
+
+	wd.ServeJson(bson.M{"_id": util.SE.Encode2Hex(_id)})
 	return nil
 	return nil
 }
 }

+ 22 - 73
src/jfw/modules/app/src/app/front/ws_dataExport.go

@@ -8,7 +8,6 @@ import (
 	"jfw/public"
 	"jfw/public"
 	"log"
 	"log"
 	"qfw/util"
 	"qfw/util"
-	"qfw/util/jy"
 	"qfw/util/redis"
 	"qfw/util/redis"
 	"regexp"
 	"regexp"
 	"strconv"
 	"strconv"
@@ -331,86 +330,36 @@ func isPhone(value string) bool {
 }
 }
 
 
 //微信数据导出
 //微信数据导出
-func (w *WsDataExport) SearchExport() error {
-	openid := util.ObjToString(w.GetSession("s_m_openid"))
-	userId := util.ObjToString(w.GetSession("userId"))
+func (wd *WsDataExport) SearchExport() error {
+	openid := util.ObjToString(wd.GetSession("s_m_openid"))
+	userId := util.ObjToString(wd.GetSession("userId"))
 	if userId == "" {
 	if userId == "" {
 		return errors.New("未登录")
 		return errors.New("未登录")
 	}
 	}
 	//接收超级搜索页面参数
 	//接收超级搜索页面参数
-	keywords := w.GetString("searchvalue")                 //搜索词
-	publishtime := w.GetString("publishtime")              //发布时间
-	area := w.GetString("scope")                           //地区
-	subtype := w.GetString("subtype")                      //信息类型
-	minprice := w.GetString("minprice")                    //最低价格
-	maxprice := w.GetString("maxprice")                    //最高价格
-	industry := strings.TrimSpace(w.GetString("industry")) //选中的行业
-	selectType := w.GetString("selectType")                //标题 or 全文
-	winner := w.GetString("winner")
-	buyerclass := w.GetString("buyerclass")
-	//数据存库转换
-	areaSave := []string{}
-	if len(area) > 0 {
-		areaSave = strings.Split(area, ",")
-	}
-	industrySave := []string{}
-	if len(industry) > 0 {
-		industrySave = strings.Split(industry, ",")
-	}
-	winnerSave := []string{}
-	if len(winner) > 0 {
-		winnerSave = strings.Split(winner, ",")
-	}
-	buyerclassSave := []string{}
-	if len(buyerclass) > 0 {
-		buyerclassSave = strings.Split(buyerclass, ",")
-	}
-	//格式化keywords
-	KeyWordSave := []public.KeyWord{}
-
-	if len(keywords) > 0 {
-		isIntercept := false
-		if selectType == "all" {
-			isIntercept = true
-		}
-		_, _, keywords = jy.InterceptSearchKW(keywords, isIntercept, len(industrySave) == 0)
-		keywords = strings.Replace(keywords, "+", " ", -1)
-		KeyWordSave = append(KeyWordSave, public.KeyWord{Keyword: keywords})
-	}
-	//时间
-	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())
-		publishtime = fmt.Sprintf("%s_%d", starttime, now.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())
-		publishtime = fmt.Sprintf("%s_%d", starttime, now.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())
-		publishtime = fmt.Sprintf("%s_%s", starttime, endtime)
+	reqData := public.BidSearchExport{
+		Keywords:     wd.GetString("keywords"),                    //搜索词
+		Publishtime:  wd.GetString("publishtime"),                 //发布时间
+		Area:         wd.GetString("area"),                        //地区
+		Subtype:      wd.GetString("subtype"),                     //信息类型
+		Minprice:     wd.GetString("minprice"),                    //最低价格
+		Maxprice:     wd.GetString("maxprice"),                    //最高价格
+		Industry:     strings.TrimSpace(wd.GetString("industry")), //选中的行业
+		SelectType:   wd.GetString("selectType"),                  //标题 or 全文
+		Buyerclass:   wd.GetString("buyerclass"),                  //采购单位行业
+		Winner:       wd.GetString("winner"),                      //中标单位
+		Hasbuyertel:  wd.GetString("buyertel"),                    //是否有采购电话
+		Haswinnertel: wd.GetString("winnertel"),                   //是否有中标电话
 	}
 	}
 
 
-	data := map[string]interface{}{
-		"keywords":    KeyWordSave,
-		"publishtime": publishtime,
-		"area":        areaSave,
-		"subtype":     subtype,
-		"minprice":    minprice,
-		"maxprice":    maxprice,
-		"industry":    industrySave,
-		"selectType":  selectType,
-		"comeintime":  now.Unix(),
-		"s_openid":    openid,
-		"comeinfrom":  "supersearchPage",
-		"s_userid":    userId,
-		"buyerclass":  buyerclassSave,
-		"winner":      winnerSave,
-	}
+	saveData := reqData.PassBidSearchExport()
+	saveData["s_openid"] = openid
+	saveData["s_userid"] = userId
 
 
 	//存入数据库
 	//存入数据库
-	_id := mongodb.Save(public.ExportTable, data)
-	w.ServeJson(bson.M{"_id": util.SE.Encode2Hex(_id)})
+	_id := mongodb.Save(public.ExportTable, saveData)
+
+	wd.ServeJson(bson.M{"_id": util.SE.Encode2Hex(_id)})
 	return nil
 	return nil
 }
 }
 
 

+ 252 - 0
src/jfw/modules/common/src/qfw/util/bidsearch/search.go

@@ -0,0 +1,252 @@
+package bidsearch
+
+import (
+	"fmt"
+	"jfw/public"
+	"qfw/util"
+	"qfw/util/elastic"
+	"qfw/util/jy"
+	"strconv"
+	"strings"
+	"time"
+)
+
+//pc、微信、app 招标信息搜索
+
+const (
+	INDEX          = "bidding"
+	TYPE           = "bidding"
+	bidSearch_sort = `{"publishtime":-1}`
+
+	//招标搜索分页--每页显示数量
+	SearchPageSize_APP = 50
+	SearchPageSize_WX  = 50
+	SearchPageSize_PC  = 50
+
+	//招标搜索分页--最大页数
+	SearchMaxPageNum_APP = 20
+	SearchMaxPageNum_WX  = 20
+	SearchMaxPageNum_PC  = 10
+)
+
+//GetWxsearchlistData 移动端招标信息搜索
+func GetWxsearchlistData(keywords, scope, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel 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, hasBuyerTel, hasWinnerTel, findfields, GetBidSearchQuery(scope, publishtime, subtype, winner, buyerclass))
+	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
+}
+
+//GetPcBidSearchData pc端招标信息搜索
+func GetPcBidSearchData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, winner, buyerclass, hasBuyerTel, hasWinnerTel string, start, pageSize int, isGetCount bool, selectType, field 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, hasBuyerTel, hasWinnerTel, findfields, GetBidSearchQuery(area, publishtime, subtype, winner, buyerclass))
+	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" {
+			//全文搜索
+			repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, field, start, pageSize, 115, true)
+		} else {
+			//标题搜索
+			repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, field, start, pageSize, 0, false)
+
+		}
+		if repl != nil && *repl != nil && len(*repl) > 0 {
+			public.BidListConvert(industry, repl)
+			list = repl
+		}
+	}
+	limitCount := int64(SearchPageSize_PC * SearchMaxPageNum_PC)
+	if count > limitCount {
+		count = limitCount
+	}
+	totalPage = (count + int64(SearchPageSize_PC) - 1) / int64(SearchPageSize_PC)
+	return
+}
+
+func GetBidSearchQuery(area, publishtime, subtype, winner, buyerclass 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 += `]}}`
+	}
+	if winner != "" {
+		if len(query) > 0 {
+			query += ","
+		}
+		query += `{"terms":{"s_winner":[`
+		for k, v := range strings.Split(winner, ",") {
+			if k > 0 {
+				query += `,`
+			}
+			query += `"` + v + `"`
+		}
+		query += `]}}`
+	}
+	if buyerclass != "" {
+		if len(query) > 0 {
+			query += ","
+		}
+		query += `{"terms":{"buyerclass":[`
+		for k, v := range strings.Split(buyerclass, ",") {
+			if k > 0 {
+				query += `,`
+			}
+			query += `"` + v + `"`
+		}
+		query += `]}}`
+	}
+	return query
+}
+
+func GetSearchQuery(keyword, industry, minprice, maxprice, hasBuyerTel, hasWinnerTel, findfields, mustquery string) (qstr string) {
+	multi_match := `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
+	query := `{"query":{"bool":{"must":[%s],"must_not":[%s]}}}`
+	query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
+	query_bools_must := `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
+	query_bool_must := `{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
+	query_missing := `{"constant_score":{"filter":{"missing":{"field":"%s"}}}}`
+	gte := `"gte": %s`
+	lte := `"lte": %s`
+	musts, must_not := []string{}, []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)
+		}
+		if minprice != "" || maxprice != "" {
+			query_price := fmt.Sprintf(query_bool_should, fmt.Sprintf(query_bools_must, sq, sq))
+			musts = append(musts, query_price)
+		}
+	}
+	if hasBuyerTel != "" {
+		if hasBuyerTel == "y" {
+			must_not = append(must_not, fmt.Sprintf(query_missing, "buyertel"))
+		} else {
+			musts = append(musts, fmt.Sprintf(query_missing, "buyertel"))
+		}
+	}
+	if hasWinnerTel != "" {
+		if hasWinnerTel == "y" {
+			must_not = append(must_not, fmt.Sprintf(query_missing, "winnertel"))
+		} else {
+			musts = append(musts, fmt.Sprintf(query_missing, "winnertel"))
+		}
+	}
+	qstr = fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(must_not, ","))
+	return
+}

+ 79 - 0
src/jfw/public/dataexport.go

@@ -2,9 +2,11 @@ package public
 
 
 import (
 import (
 	"fmt"
 	"fmt"
+	"jfw/modules/common/src/qfw/util/jy"
 	"log"
 	"log"
 	"qfw/util"
 	"qfw/util"
 	"qfw/util/mail"
 	"qfw/util/mail"
+	"strings"
 	"sync"
 	"sync"
 	"time"
 	"time"
 )
 )
@@ -91,3 +93,80 @@ func GetPriceDes_SieveCondition(minPrice, maxPrice string) string {
 	}
 	}
 	return des
 	return des
 }
 }
+
+//招标数据导出筛选
+type BidSearchExport struct {
+	Keywords     string //搜索词
+	Publishtime  string //发布时间
+	Area         string //地区
+	Subtype      string //信息类型
+	Minprice     string //最低价格
+	Maxprice     string //最高价格
+	Industry     string //选中的行业
+	SelectType   string //标题 or 全文
+	Winner       string //中标单位
+	Buyerclass   string //采购单位行业
+	Hasbuyertel  string //是否有采购电话
+	Haswinnertel string //是否有中标电话
+}
+
+func (this *BidSearchExport) PassBidSearchExport() map[string]interface{} {
+	areaSave, industrySave := []string{}, []string{}
+	winnerSave, buyerclassSave := []string{}, []string{}
+	publishtimeSave := ""
+	if len(this.Area) > 0 {
+		areaSave = strings.Split(this.Area, ",")
+	}
+	if len(this.Industry) > 0 {
+		industrySave = strings.Split(this.Industry, ",")
+	}
+	if len(this.Buyerclass) > 0 {
+		buyerclassSave = strings.Split(this.Buyerclass, ",")
+	}
+
+	if len(this.Winner) > 0 {
+		winnerSave = strings.Split(this.Winner, ",")
+	}
+
+	KeyWordSave := []KeyWord{}
+	if len(this.Keywords) > 0 {
+		isIntercept := false
+		if this.SelectType == "all" {
+			isIntercept = true
+		}
+		_, _, keywords := jy.InterceptSearchKW(this.Keywords, isIntercept, len(this.Industry) == 0)
+		keywords = strings.Replace(keywords, "+", " ", -1)
+		KeyWordSave = append(KeyWordSave, KeyWord{Keyword: keywords})
+	}
+
+	//时间
+	now := time.Now()
+	if this.Publishtime == "lately-7" { //最近7天
+		starttime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
+		publishtimeSave = fmt.Sprintf("%s_%d", starttime, now.Unix())
+	} else if this.Publishtime == "lately-30" { //最近30天
+		starttime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
+		publishtimeSave = fmt.Sprintf("%s_%d", starttime, now.Unix())
+	} else if this.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())
+		publishtimeSave = fmt.Sprintf("%s_%s", starttime, endtime)
+	}
+
+	return map[string]interface{}{
+		"keywords":     KeyWordSave,
+		"publishtime":  publishtimeSave,
+		"area":         areaSave,
+		"subtype":      this.Subtype,
+		"minprice":     this.Minprice,
+		"maxprice":     this.Maxprice,
+		"industry":     industrySave,
+		"selectType":   this.SelectType,
+		"buyerclass":   buyerclassSave,
+		"winner":       winnerSave,
+		"hasBuyertel":  this.Hasbuyertel,
+		"hasWinnertel": this.Haswinnertel,
+		"comeintime":   now.Unix(),
+		"comeinfrom":   "supersearchPage",
+	}
+}