|
@@ -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()
|
|
|
}
|