Browse Source

wip:采购信息搜索

wangshan 9 tháng trước cách đây
mục cha
commit
ee39ec6056

+ 29 - 29
jyBXCore/api/bxcore.api

@@ -272,35 +272,35 @@ type (
 		UserId           string `header:"userId,optional"`
 		Phone            string `header:"phone,optional"`
 		NewUserId        string `header:"newUserId,optional"`
-		EntId            int64  `header:"entId,optional"`
-		EntUserId        int64  `header:"entUserId,optional"`
-		AccountId        string `header:"accountId,optional"`      //账户id
-		EntAccountId     int64  `header:"entAccountId,optional"`   //企业账户id
-		PositionType     string `header:"positionType,optional"`   //职位类型 0个人 1企业
-		PositionId       string `header:"positionId,optional"`     //职位id
-		MgoUserId        string `header:"mgoUserId,optional"`      //原userId
-		PageNum          int64  `json:"pageNum,optional"`          //页码
-		PageSize         int64  `json:"pageSize,optional"`         //每页数量
-		PublishTime      string `json:"publishTime,optional"`      //发布时间
-		SelectType       string `json:"selectType,optional"`       //搜索范围:默认全部;标题:title;标的物:purchasing
-		DomainFirstType  string `json:"domainFirstType,optional"`  //领域一级分类
-		DomainSecondType string `json:"domainSecondType,optional"` //领域二级分类
-		DomainThirdType  string `json:"domainThirdType,optional"`  //领域三级分类
-		DeadlineStatus   int64  `json:"deadlineStatus,optional"`   //报名截止状态
-		DeadlineTime     string `json:"deadlineTime,optional"`     //报名截止时间
-		DeliveryArea     string `json:"deliveryArea,optional"`     //交付地点-省份
-		DeliveryCity     string `json:"deliveryCity,optional"`     //交付地点-城市
-		DeliveryDistrict string `json:"deliveryDistrict,optional"` //交付地点-县区
-		ProjectArea      string `json:"projectArea,optional"`      //项目地区-省份
-		ProjectCity      string `json:"projectCity,optional"`      //项目地区-城市
-		ProjectDistrict  string `json:"projectDistrict,optional"`  //项目地区-县区
-		Industry         string `json:"industry,optional"`         //行业
-		FileExists       int64  `json:"fileExists,optional"`       //附件
-		Publisher        int64  `json:"publisher,optional"`        //发布者:可选:全部、用户发布:1、平台发布:2。
-		KeyWords         string `json:"keyWords,optional"`         //关键词
-		AdditionalWords  string `json:"additionalWords,optional"`  // 附加词
-		SearchMode       int64  `json:"searchMode,optional"`       //搜索模式:0:精准搜索;1:模糊搜索
-		WordsMode        int64  `json:"wordsMode,optional"`        //搜索关键词模式;默认0:包含所有,1:包含任意
+		EntId            int64  `header:"entId,optional,omitempty"`
+		EntUserId        int64  `header:"entUserId,optional,omitempty"`
+		AccountId        string `header:"accountId,optional,omitempty"`    //账户id
+		EntAccountId     int64  `header:"entAccountId,optional,omitempty"` //企业账户id
+		PositionType     int    `header:"positionType,optional"`           //职位类型 0个人 1企业
+		PositionId       string `header:"positionId,optional"`             //职位id
+		MgoUserId        string `header:"mgoUserId,optional"`              //原userId
+		PageNum          int64  `json:"pageNum,optional"`                  //页码
+		PageSize         int64  `json:"pageSize,optional"`                 //每页数量
+		PublishTime      string `json:"publishTime,optional"`              //发布时间
+		SelectType       string `json:"selectType,optional"`               //搜索范围:默认全部;标题:title;标的物:purchasing
+		DomainFirstType  string `json:"domainFirstType,optional"`          //领域一级分类
+		DomainSecondType string `json:"domainSecondType,optional"`         //领域二级分类
+		DomainThirdType  string `json:"domainThirdType,optional"`          //领域三级分类
+		DeadlineStatus   int64  `json:"deadlineStatus,optional"`           //报名截止状态
+		DeadlineTime     string `json:"deadlineTime,optional"`             //报名截止时间
+		DeliveryArea     string `json:"deliveryArea,optional"`             //交付地点-省份
+		DeliveryCity     string `json:"deliveryCity,optional"`             //交付地点-城市
+		DeliveryDistrict string `json:"deliveryDistrict,optional"`         //交付地点-县区
+		ProjectArea      string `json:"projectArea,optional"`              //项目地区-省份
+		ProjectCity      string `json:"projectCity,optional"`              //项目地区-城市
+		ProjectDistrict  string `json:"projectDistrict,optional"`          //项目地区-县区
+		Industry         string `json:"industry,optional"`                 //行业
+		FileExists       int64  `json:"fileExists,optional"`               //附件
+		Publisher        int64  `json:"publisher,optional"`                //发布者:可选:全部、用户发布:1、平台发布:2。
+		KeyWords         string `json:"keyWords,optional"`                 //关键词
+		AdditionalWords  string `json:"additionalWords,optional"`          // 附加词
+		SearchMode       int64  `json:"searchMode,optional"`               //搜索模式:0:精准搜索;1:模糊搜索
+		WordsMode        int64  `json:"wordsMode,optional"`                //搜索关键词模式;默认0:包含所有,1:包含任意
 	}
 )
 

+ 3 - 1
jyBXCore/api/internal/logic/purchase/purchaseSearchLogic.go

@@ -25,11 +25,13 @@ func NewPurchaseSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *
 		Logger: logx.WithContext(ctx),
 		ctx:    ctx,
 		svcCtx: svcCtx,
+		r:      r,
 	}
 }
 
 func (l *PurchaseSearchLogic) PurchaseSearch(req *types.PurSearchReq) (resp *types.CommonResp, err error) {
 	defer common.Catch()
+	logx.Info("--------------------")
 	res, err := l.svcCtx.BxCore.PurchaseSearch(l.ctx, &bxcore.PurchaseReq{
 		AppId:            req.AppId,
 		UserId:           req.UserId,
@@ -39,7 +41,7 @@ func (l *PurchaseSearchLogic) PurchaseSearch(req *types.PurSearchReq) (resp *typ
 		EntUserId:        req.EntUserId,
 		AccountId:        req.AccountId,
 		EntAccountId:     req.EntAccountId,
-		PositionType:     req.PositionType,
+		PositionType:     int64(req.PositionType),
 		PositionId:       req.PositionId,
 		MgoUserId:        req.MgoUserId,
 		PageNum:          req.PageNum,

+ 29 - 29
jyBXCore/api/internal/types/types.go

@@ -231,33 +231,33 @@ type PurSearchReq struct {
 	UserId           string `header:"userId,optional"`
 	Phone            string `header:"phone,optional"`
 	NewUserId        string `header:"newUserId,optional"`
-	EntId            int64  `header:"entId,optional"`
-	EntUserId        int64  `header:"entUserId,optional"`
-	AccountId        string `header:"accountId,optional"`      //账户id
-	EntAccountId     int64  `header:"entAccountId,optional"`   //企业账户id
-	PositionType     string `header:"positionType,optional"`   //职位类型 0个人 1企业
-	PositionId       string `header:"positionId,optional"`     //职位id
-	MgoUserId        string `header:"mgoUserId,optional"`      //原userId
-	PageNum          int64  `json:"pageNum,optional"`          //页码
-	PageSize         int64  `json:"pageSize,optional"`         //每页数量
-	PublishTime      string `json:"publishTime,optional"`      //发布时间
-	SelectType       string `json:"selectType,optional"`       //搜索范围:默认全部;标题:title;标的物:purchasing
-	DomainFirstType  string `json:"domainFirstType,optional"`  //领域一级分类
-	DomainSecondType string `json:"domainSecondType,optional"` //领域二级分类
-	DomainThirdType  string `json:"domainThirdType,optional"`  //领域三级分类
-	DeadlineStatus   int64  `json:"deadlineStatus,optional"`   //报名截止状态
-	DeadlineTime     string `json:"deadlineTime,optional"`     //报名截止时间
-	DeliveryArea     string `json:"deliveryArea,optional"`     //交付地点-省份
-	DeliveryCity     string `json:"deliveryCity,optional"`     //交付地点-城市
-	DeliveryDistrict string `json:"deliveryDistrict,optional"` //交付地点-县区
-	ProjectArea      string `json:"projectArea,optional"`      //项目地区-省份
-	ProjectCity      string `json:"projectCity,optional"`      //项目地区-城市
-	ProjectDistrict  string `json:"projectDistrict,optional"`  //项目地区-县区
-	Industry         string `json:"industry,optional"`         //行业
-	FileExists       int64  `json:"fileExists,optional"`       //附件
-	Publisher        int64  `json:"publisher,optional"`        //发布者:可选:全部、用户发布:1、平台发布:2。
-	KeyWords         string `json:"keyWords,optional"`         //关键词
-	AdditionalWords  string `json:"additionalWords,optional"`  // 附加词
-	SearchMode       int64  `json:"searchMode,optional"`       //搜索模式:0:精准搜索;1:模糊搜索
-	WordsMode        int64  `json:"wordsMode,optional"`        //搜索关键词模式;默认0:包含所有,1:包含任意
+	EntId            int64  `header:"entId,optional,omitempty"`
+	EntUserId        int64  `header:"entUserId,optional,omitempty"`
+	AccountId        string `header:"accountId,optional,omitempty"`    //账户id
+	EntAccountId     int64  `header:"entAccountId,optional,omitempty"` //企业账户id
+	PositionType     int    `header:"positionType,optional"`           //职位类型 0个人 1企业
+	PositionId       string `header:"positionId,optional"`             //职位id
+	MgoUserId        string `header:"mgoUserId,optional"`              //原userId
+	PageNum          int64  `json:"pageNum,optional"`                  //页码
+	PageSize         int64  `json:"pageSize,optional"`                 //每页数量
+	PublishTime      string `json:"publishTime,optional"`              //发布时间
+	SelectType       string `json:"selectType,optional"`               //搜索范围:默认全部;标题:title;标的物:purchasing
+	DomainFirstType  string `json:"domainFirstType,optional"`          //领域一级分类
+	DomainSecondType string `json:"domainSecondType,optional"`         //领域二级分类
+	DomainThirdType  string `json:"domainThirdType,optional"`          //领域三级分类
+	DeadlineStatus   int64  `json:"deadlineStatus,optional"`           //报名截止状态
+	DeadlineTime     string `json:"deadlineTime,optional"`             //报名截止时间
+	DeliveryArea     string `json:"deliveryArea,optional"`             //交付地点-省份
+	DeliveryCity     string `json:"deliveryCity,optional"`             //交付地点-城市
+	DeliveryDistrict string `json:"deliveryDistrict,optional"`         //交付地点-县区
+	ProjectArea      string `json:"projectArea,optional"`              //项目地区-省份
+	ProjectCity      string `json:"projectCity,optional"`              //项目地区-城市
+	ProjectDistrict  string `json:"projectDistrict,optional"`          //项目地区-县区
+	Industry         string `json:"industry,optional"`                 //行业
+	FileExists       int64  `json:"fileExists,optional"`               //附件
+	Publisher        int64  `json:"publisher,optional"`                //发布者:可选:全部、用户发布:1、平台发布:2。
+	KeyWords         string `json:"keyWords,optional"`                 //关键词
+	AdditionalWords  string `json:"additionalWords,optional"`          // 附加词
+	SearchMode       int64  `json:"searchMode,optional"`               //搜索模式:0:精准搜索;1:模糊搜索
+	WordsMode        int64  `json:"wordsMode,optional"`                //搜索关键词模式;默认0:包含所有,1:包含任意
 }

+ 1 - 1
jyBXCore/rpc/bxcore.proto

@@ -650,7 +650,7 @@ message PurchaseReq {
   int64  entUserId = 6;//企业用户id  当前企业下的员工id 没有企业默认0
   string accountId = 7; //账户id
   int64 entAccountId = 8; //企业账户id
-  string positionType = 9; //职位类型 0个人 1企业
+  int64 positionType = 9; //职位类型 0个人 1企业
   string positionId = 10;  //职位id
   string mgoUserId = 11;  //原userId
   int64  pageNum = 12;//当前页码

+ 1 - 0
jyBXCore/rpc/etc/bxcore.yaml

@@ -81,3 +81,4 @@ Stages:
 SearchWinner:
   Switch: true
   RegWinner: ".+[司院厂所心处普行]$"
+PurchaseCode: ygzc_cgxx

+ 1 - 0
jyBXCore/rpc/internal/config/config.go

@@ -68,6 +68,7 @@ type Config struct {
 		Switch    bool
 		RegWinner string
 	}
+	PurchaseCode string
 }
 type Db struct {
 	Mysql     entity.Mysql      `json:"mysql"`

+ 15 - 11
jyBXCore/rpc/internal/logic/purchasesearchlogic.go

@@ -2,15 +2,13 @@ package logic
 
 import (
 	IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/init"
+	"bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/service"
+	"bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/type/bxcore"
 	"context"
 	"fmt"
-	"log"
-
-	"bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/internal/svc"
-	"bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/type/bxcore"
-
 	"github.com/zeromicro/go-zero/core/logx"
+	"log"
 )
 
 type PurchaseSearchLogic struct {
@@ -29,7 +27,18 @@ func NewPurchaseSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Pu
 
 // 采购信息搜索
 func (l *PurchaseSearchLogic) PurchaseSearch(in *bxcore.PurchaseReq) (*bxcore.PurchaseResp, error) {
-	if IC.C.NoLoginSearch.Switch {
+	var (
+		res = &bxcore.PurchaseResp{
+			Data: &bxcore.PurchaseData{
+				List: []*bxcore.PurchaseList{},
+			},
+		}
+	)
+	ps := service.NewPurchase(in)
+	ps.FilterCriteriaFormat()
+	//更新历史记录
+	go ps.HistoryKeywords()
+	if IC.C.NoLoginSearch.Switch && ps.UserId == "" {
 		flag := IC.ReqLimitInit.Limit(context.Background())
 		if flag == 1 {
 			defer IC.ReqLimitInit.Release()
@@ -44,11 +53,6 @@ func (l *PurchaseSearchLogic) PurchaseSearch(in *bxcore.PurchaseReq) (*bxcore.Pu
 			return &bxcore.PurchaseResp{}, fmt.Errorf("暂无数据")
 		}
 	}
-	var (
-		res = &bxcore.PurchaseResp{}
-	)
-	ps := service.NewPurchase(in)
-	ps.FilterCriteriaFormat()
 	list, err := ps.GetPurchaseData()
 	if err == nil && len(list) > 0 {
 		res.Data.List = list

+ 2 - 2
jyBXCore/rpc/model/es/es.go

@@ -13,7 +13,7 @@ import (
 const (
 	queryBoolMustTermDomain = `{"bool": {"must": [{ "term": {"bid_field": "%s" }}]}}` // 领域化数据类型
 	MultiMatch              = `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
-	query                   = `{"query":{"bool":{"must":[%s],"must_not":[%s]}}}`
+	Query                   = `{"query":{"bool":{"must":[%s],"must_not":[%s]}}}`
 	QueryBoolShould         = `{"bool":{"should":[%s],"minimum_should_match": 1}}`
 	queryBoolMustBoolShould = `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
 	queryBoolMustScopeClass = `{"bool":{"should":[{"terms":{"s_subscopeclass":[%s]}},{"bool":{"must":[{"terms":{"s_topscopeclass":[%s]}},{"bool":{"must_not":[{"exists":{"field":"s_subscopeclass"}}]}}]}}],"minimum_should_match":1}}` //`{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
@@ -43,7 +43,7 @@ const (
 	LoginTypeNoLogin = 3            // 未登录用户
 	//直采-采购信息
 	PurchaseIndex, PurchaseType = "bidding_yg", "bidding_yg"
-	PurchaseBaseField           = `"_id","title"`
+	PurchaseBaseField           = `"_id","title","area","city","district","buyerclass","publishtime","isValidFile","budget","bidamount","signendtime","deliver_area","deliver_city","deliver_district","buyer","buyertel","s_subscopeclass","public_type","purchasing","purchasinglist","projectname","spidercode","subtype"`
 	PurchaseSearchSort          = `{"dataweight":-1,"publishtime":-1}`
 )
 

+ 1 - 1
jyBXCore/rpc/model/es/search.go

@@ -300,7 +300,7 @@ func GetSearchQuery(in *bxcore.SearchReq, mustQuery string) (qstr string) {
 		}
 	}
 	//in.BidField  剑鱼默认招标信息搜索 此参数为空**
-	qstr = fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(mustNot, ","))
+	qstr = fmt.Sprintf(Query, strings.Join(musts, ","), strings.Join(mustNot, ","))
 	log.Println("qstr:", qstr)
 	return
 }

+ 97 - 26
jyBXCore/rpc/service/purchase.go

@@ -13,6 +13,7 @@ import (
 	"bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/util"
 	"encoding/json"
 	"fmt"
+	"github.com/zeromicro/go-zero/core/logx"
 	"log"
 	"strconv"
 	"strings"
@@ -60,12 +61,13 @@ type Purchase struct {
 	TipMsg           string `json:"tipMsg"`                      //关键词提示信息
 	HighlightWords   string `json:"highlightWords"`              //需要高亮的词,多个,号分割
 	Total            int64  `json:"total"`                       //数据总量
+	IsPay            bool   `json:"isPay"`                       //是否是付费用户
+	IsPower          bool   `json:"isPower"`                     //是否有权限
 }
 
 func NewPurchase(in *bxcore.PurchaseReq) *Purchase {
 	baseUserId, _ := strconv.ParseInt(in.NewUserId, 10, 64)
 	accountId, _ := strconv.ParseInt(in.AccountId, 10, 64)
-	positionType, _ := strconv.ParseInt(in.PositionType, 10, 64)
 	positionId, _ := strconv.ParseInt(in.PositionId, 10, 64)
 	return &Purchase{
 		AppId:            in.AppId,
@@ -76,7 +78,7 @@ func NewPurchase(in *bxcore.PurchaseReq) *Purchase {
 		EntUserId:        in.EntUserId,
 		AccountId:        accountId,
 		EntAccountId:     in.EntAccountId,
-		PositionType:     positionType,
+		PositionType:     in.PositionType,
 		PositionId:       positionId,
 		MgoUserId:        in.MgoUserId,
 		PageNum:          in.PageNum,
@@ -108,12 +110,52 @@ func NewPurchase(in *bxcore.PurchaseReq) *Purchase {
 
 var (
 	AreaLabelLink = "/list/%s/%s.html"
+	noPower       = "点击查看"
 )
 
+// 缓存
+func (p *Purchase) HistoryKeywords() {
+	var (
+		cacheKey         = fmt.Sprintf("history_purchase_v_%s", p.UserId)
+		keys             []string
+		code             = "other"
+		isExist          = map[string]bool{}
+		duplicateRemoval = func(values []string) (keys []string) {
+			for _, kv := range values {
+				kv = strings.TrimSpace(kv)
+				if isExist[kv] {
+					continue
+				}
+				isExist[kv] = true
+				keys = append(keys, kv)
+			}
+			return
+		}
+	)
+	values := redis.GetStr(code, cacheKey)
+	if values != "" {
+		keys = append(keys, duplicateRemoval(strings.Split(values, ","))...)
+	}
+	if p.KeyWords != "" {
+		keys = append(keys, duplicateRemoval(strings.Split(p.KeyWords, ","))...)
+	}
+	if p.AdditionalWords != "" {
+		keys = append(keys, duplicateRemoval(strings.Split(p.AdditionalWords, ","))...)
+	}
+	if len(keys) > 10 {
+		keys = keys[len(keys)-10:]
+	}
+	ok := redis.Put(code, cacheKey, strings.Join(keys, ","), -1)
+	if !ok {
+		logx.Info(" history keywords err:", keys)
+	}
+}
+
 // 格式化
-func (p *Purchase) PurchaseListFormat(res *[]map[string]interface{}) (list []*bxcore.PurchaseList) {
-	for _, rv := range *res {
-		id := MC.InterfaceToStr(rv["id"])
+func (p *Purchase) PurchaseListFormat(res []map[string]interface{}) (list []*bxcore.PurchaseList) {
+	for _, rv := range res {
+		logx.Info("title:", MC.InterfaceToStr(rv["title"]))
+		id := MC.InterfaceToStr(rv["_id"])
 		area := MC.InterfaceToStr(rv["area"])
 		city := MC.InterfaceToStr(rv["city"])
 		district := MC.InterfaceToStr(rv["district"])
@@ -136,10 +178,15 @@ func (p *Purchase) PurchaseListFormat(res *[]map[string]interface{}) (list []*bx
 		if set := MC.Int64All(rv["signendtime"]); set > 0 {
 			signEndTime = date.FormatDateByInt64(&set, "2006-01-02 15:04")
 		}
-		//deliver_area  交付省份
-		//deliver_city  交付城市
-		//deliver_district  交付区县
+		//deliver_area  交付省份//deliver_city  交付城市//deliver_district  交付区县
 		deliveryLoc := fmt.Sprintf("%s-%s-%s", MC.InterfaceToStr(rv["deliver_area"]), MC.InterfaceToStr(rv["deliver_city"]), MC.InterfaceToStr(rv["deliver_district"]))
+		buyer := noPower
+		buyerTel := noPower
+		if p.IsPower {
+			buyer = MC.InterfaceToStr(rv["buyer"])
+			buyerTel = MC.InterfaceToStr(rv["buyertel"])
+		}
+		isValidFile, _ := rv["isValidFile"].(bool)
 		list = append(list, &bxcore.PurchaseList{
 			Id:           encrypt.EncodeArticleId2ByCheck(id),
 			Area:         MC.InterfaceToStr(rv["area"]),
@@ -148,11 +195,11 @@ func (p *Purchase) PurchaseListFormat(res *[]map[string]interface{}) (list []*bx
 			RegionUrl:    regionUrl,
 			BuyerClass:   MC.InterfaceToStr(rv["buyerclass"]),
 			PublishTime:  MC.Int64All(rv["publishtime"]),
-			FileExists:   rv["isValidFile"].(bool),
+			FileExists:   isValidFile,
 			Title:        MC.InterfaceToStr(rv["title"]),
 			Price:        price,
-			Buyer:        MC.InterfaceToStr(rv["buyer"]),
-			BuyerTel:     MC.InterfaceToStr(rv["buyertel"]),
+			Buyer:        buyer,
+			BuyerTel:     buyerTel,
 			DeadlineTime: signEndTime,
 			DeliveryLoc:  deliveryLoc,
 			Industry:     util.IndustryFormat(p.Industry, strings.Trim(MC.ObjToString(rv["s_subscopeclass"]), ",")),
@@ -261,7 +308,7 @@ func (p *Purchase) PurchaseQuery() (query string) {
 		areaQuery = append(areaQuery, fmt.Sprintf(areaTerms, "area", strings.ReplaceAll(p.ProjectArea, ",", "\",\"")))
 	}
 	if p.ProjectCity != "" {
-		areaQuery = append(areaQuery, fmt.Sprintf(areaTerms, "city", strings.ReplaceAll(p.ProjectArea, ",", "\",\"")))
+		areaQuery = append(areaQuery, fmt.Sprintf(areaTerms, "city", strings.ReplaceAll(p.ProjectCity, ",", "\",\"")))
 	}
 	if p.ProjectDistrict != "" {
 		for _, v := range strings.Split(p.ProjectDistrict, ",") {
@@ -315,9 +362,13 @@ func (p *Purchase) PurchaseQuery() (query string) {
 			timeQuery += fmt.Sprintf(`"lt":%d`, p.DeadlineEnd)
 		}
 		timeQuery += `}}}`
+		must = append(must, timeQuery)
 	}
 	//领域
 	areaQuery = []string{}
+	if p.DomainFirstType != "" {
+		areaQuery = append(areaQuery, fmt.Sprintf(areaTerms, "domain_firsttype", strings.ReplaceAll(p.DomainFirstType, ",", "\",\"")))
+	}
 	if p.DomainSecondType != "" {
 		areaQuery = append(areaQuery, fmt.Sprintf(areaTerms, "domain_secondtype", strings.ReplaceAll(p.DomainSecondType, ",", "\",\"")))
 	}
@@ -328,14 +379,17 @@ func (p *Purchase) PurchaseQuery() (query string) {
 		must = append(must, fmt.Sprintf(es.QueryBoolShould, strings.Join(areaQuery, ",")))
 	}
 	//直采 采购信息 搜索
-	query = fmt.Sprintf(query, strings.Join(must, ","), strings.Join(mustNot, ","))
+	query = fmt.Sprintf(es.Query, strings.Join(must, ","), strings.Join(mustNot, ","))
 	log.Println("zc-query:", query)
 	return
 }
 
-func (p *Purchase) FindDataFromES() (total int64, list *[]map[string]interface{}, err error) {
+func (p *Purchase) FindDataFromES() (int64, []map[string]interface{}, error) {
 	var (
 		start = int((p.PageNum - 1) * p.PageSize)
+		total int64
+		list  *[]map[string]interface{}
+		err   error
 	)
 	biddingSearch := es.SearchByES{
 		Index:      es.PurchaseIndex,
@@ -350,13 +404,16 @@ func (p *Purchase) FindDataFromES() (total int64, list *[]map[string]interface{}
 		HighLight:  false, //是否高亮正文
 	}
 	total, list = biddingSearch.GetAllByNgramWithCount(es.LoginTypePay)
-	fmt.Println(total, "-------------------", *list)
+	fmt.Println(total, "-------------------", list)
 	p.Total = total
 	total = int64(util.SearchPageSize * util.SearchMaxPageNum)
 	if p.Total > total {
 		p.Total = total
 	}
-	return
+	if total == 0 || list == nil {
+		return 0, nil, fmt.Errorf("暂无数据")
+	}
+	return total, *list, err
 }
 
 var (
@@ -367,7 +424,8 @@ var (
 
 func (p *Purchase) GetPurchaseData() (list []*bxcore.PurchaseList, err error) {
 	var (
-		res *[]map[string]interface{}
+		res   []map[string]interface{}
+		total int64
 	)
 	if p.IsEmptySearch() {
 		//查缓存
@@ -381,21 +439,23 @@ func (p *Purchase) GetPurchaseData() (list []*bxcore.PurchaseList, err error) {
 			}
 			err = json.Unmarshal((*cacheBytes)[start:end], res)
 		}
-		if len(*res) == 0 {
+		if len(res) == 0 {
 			p.PageNum = 1
 			p.PageSize = int64(util.SearchPageSize * util.SearchMaxPageNum)
-			_, res, err = p.FindDataFromES()
-			*cacheBytes, err = json.Marshal(res)
-			if err == nil && len(*cacheBytes) > 0 {
-				err = redis.PutBytes(redisCode, purchaseCacheKey, cacheBytes, purchaseCacheExpire)
+			total, res, err = p.FindDataFromES()
+			if total > 0 && res != nil {
+				*cacheBytes, err = json.Marshal(res)
+				if err == nil && len(*cacheBytes) > 0 {
+					err = redis.PutBytes(redisCode, purchaseCacheKey, cacheBytes, purchaseCacheExpire)
+				}
 			}
 		}
-		*res = (*res)[start:pageSize]
+		res = (res)[start:pageSize]
 	} else {
 		//实时查询
 		_, res, err = p.FindDataFromES()
 	}
-	if len(*res) > 0 {
+	if len(res) > 0 {
 		list = p.PurchaseListFormat(res)
 	}
 	return
@@ -419,6 +479,17 @@ var (
 
 // 筛选条件格式化
 func (p *Purchase) FilterCriteriaFormat() {
+	if p.UserId != "" {
+		//判断用户身份
+		userInfo := IC.Middleground.PowerCheckCenter.Check(p.AppId, p.MgoUserId, p.BaseUserId, p.AccountId, p.EntId, p.PositionType, p.PositionId)
+		if userInfo != nil {
+			p.IsPay = !userInfo.Free.IsFree
+		}
+		res := IC.Middleground.ResourceCenter.Haspowers(p.AccountId, p.EntAccountId, p.EntId, p.EntUserId)
+		if res != nil {
+			p.IsPower = strings.Contains(strings.Join(res.Powers, ","), IC.C.PurchaseCode)
+		}
+	}
 	//搜索范围
 	if p.SelectType != "" {
 		var selectTypes []string
@@ -523,7 +594,7 @@ func (p *Purchase) FilterCriteriaFormat() {
 	if len(strings.Split(p.DeadlineTime, "-")) > 1 {
 		p.DeadlineStart, _ = strconv.ParseInt(strings.Split(p.DeadlineTime, "-")[0], 10, 64)
 		p.DeadlineEnd, _ = strconv.ParseInt(strings.Split(p.DeadlineTime, "-")[1], 10, 64)
-		if p.DeadlineEnd > p.DeadlineStart {
+		if p.DeadlineEnd < p.DeadlineStart {
 			var deadline = p.DeadlineStart
 			p.DeadlineStart = p.DeadlineEnd
 			p.DeadlineEnd = deadline
@@ -536,7 +607,7 @@ func (p *Purchase) FilterCriteriaFormat() {
 			p.DeadlineEnd = 0
 		}
 	case 2: //已截止
-		if p.DeadlineEnd > time.Now().Unix() {
+		if p.DeadlineEnd == 0 || p.DeadlineEnd > time.Now().Unix() {
 			p.DeadlineStart = 0
 			p.DeadlineEnd = time.Now().Unix()
 		}

+ 4 - 4
jyBXCore/rpc/type/bxcore/bxcore.pb.go

@@ -6098,7 +6098,7 @@ type PurchaseReq struct {
 	EntUserId        int64  `protobuf:"varint,6,opt,name=entUserId,proto3" json:"entUserId,omitempty"`               //企业用户id  当前企业下的员工id 没有企业默认0
 	AccountId        string `protobuf:"bytes,7,opt,name=accountId,proto3" json:"accountId,omitempty"`                //账户id
 	EntAccountId     int64  `protobuf:"varint,8,opt,name=entAccountId,proto3" json:"entAccountId,omitempty"`         //企业账户id
-	PositionType     string `protobuf:"bytes,9,opt,name=positionType,proto3" json:"positionType,omitempty"`          //职位类型 0个人 1企业
+	PositionType     int64  `protobuf:"varint,9,opt,name=positionType,proto3" json:"positionType,omitempty"`         //职位类型 0个人 1企业
 	PositionId       string `protobuf:"bytes,10,opt,name=positionId,proto3" json:"positionId,omitempty"`             //职位id
 	MgoUserId        string `protobuf:"bytes,11,opt,name=mgoUserId,proto3" json:"mgoUserId,omitempty"`               //原userId
 	PageNum          int64  `protobuf:"varint,12,opt,name=pageNum,proto3" json:"pageNum,omitempty"`                  //当前页码
@@ -6215,11 +6215,11 @@ func (x *PurchaseReq) GetEntAccountId() int64 {
 	return 0
 }
 
-func (x *PurchaseReq) GetPositionType() string {
+func (x *PurchaseReq) GetPositionType() int64 {
 	if x != nil {
 		return x.PositionType
 	}
-	return ""
+	return 0
 }
 
 func (x *PurchaseReq) GetPositionId() string {
@@ -7678,7 +7678,7 @@ var file_bxcore_proto_rawDesc = []byte{
 	0x0a, 0x0c, 0x65, 0x6e, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x08,
 	0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x65, 0x6e, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74,
 	0x49, 0x64, 0x12, 0x22, 0x0a, 0x0c, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x79,
-	0x70, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69,
+	0x70, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0c, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69,
 	0x6f, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69,
 	0x6f, 0x6e, 0x49, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x6f, 0x73, 0x69,
 	0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x6d, 0x67, 0x6f, 0x55, 0x73, 0x65,