Commit 91fb86ec by mushishixian

showSku队列

parent 4ce1049d
package model
......@@ -39,7 +39,7 @@ func DingDingPush(content string) (result DingDingResponse, err error) {
"Content-Type": "application/json",
"charset": "UTF-8",
})
if resp==nil {
if resp == nil {
return
}
result.Errcode = int(gjson.Get(resp.String(), "errcode").Int())
......
package routes
import (
"fmt"
"github.com/gin-gonic/gin"
"search_server/controller"
"search_server/middleware"
......@@ -31,5 +32,8 @@ func InitRouter() *gin.Engine {
r.GET("/search/get_data/index", controller.GetDataIndex)
r.POST("/search/get_data/index", controller.GetDataIndex)
r.GET("/test", func(c *gin.Context) {
fmt.Println(c.Query("test"))
})
return r
}
package query
import (
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/uniplaces/carbon"
......@@ -33,6 +34,7 @@ func GetSupplierIndex(supplierId string) (supplierIndex string) {
return
}
//根据供应商名称查询商品的ES查询
func GetGoodsBySupplierNameQuery(r requests.GetGoodsBySupplierRequest) (string, error) {
query := elastic.NewBoolQuery()
subQuery := elastic.NewBoolQuery()
......@@ -44,7 +46,6 @@ func GetGoodsBySupplierNameQuery(r requests.GetGoodsBySupplierRequest) (string,
stockFlag, _ := redis.Int(redisCon.Do("GET", "StockSwitch"))
//todo : type=goods
keywordSlice := strings.Split(strings.ToUpper(strings.TrimSpace(r.Keyword)), " ")
r1, _ := regexp.Compile(`/[\x{4e00}-\x{9fff}]+/u`)
//去除中文?
removeCnKeyword := r1.ReplaceAllString(r.Keyword, "")
......@@ -168,7 +169,6 @@ func GetGoodsBySupplierNameQuery(r requests.GetGoodsBySupplierRequest) (string,
source.Query(query)
searchRequest := elastic.NewSearchRequest().Source(source).Preference("_primary_first")
return searchRequest.Body()
}
......@@ -332,6 +332,6 @@ func GetGoodsBySupplierIdQuery(r requests.GetGoodsBySupplierRequest) (string, er
}
source.Query(query)
searchRequest := elastic.NewSearchRequest().Source(source).Preference("_primary_first")
fmt.Println(searchRequest.Body())
return searchRequest.Body()
}
......@@ -2,7 +2,6 @@ package service
import (
"encoding/json"
"fmt"
"github.com/imroc/req"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
......@@ -44,8 +43,6 @@ func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest)
func (qs *QuoteService) GetGoodsBySupplierName(r requests.GetGoodsBySupplierRequest) (result map[string]interface{}, err error) {
supplierIndex := r.SupplierName
queryString, err := query.GetGoodsBySupplierNameQuery(r)
fmt.Println(supplierIndex)
fmt.Println(queryString)
esResult, err := es.CurlES(supplierIndex, queryString)
if err != nil {
return
......
package service
import (
"search_server/middleware"
"search_server/model"
"strings"
)
//推送搜索关键词
func ShowSku(goods model.DullGoodsData) {
goodsIdLen := len(goods.GoodsId)
if goods.GoodsId == "" || goods.BrandName == "" || goods.SupplierName == "" {
return
}
referer := middleware.Context.Request.Header.Get("referer")
if strings.Contains(referer, "www.ichunt.com/s/?k") {
if goods.ProviderName != "" {
goods.BrandName = goods.ProviderName
}
if goods.CompanyName != "" {
goods.SupplierName = goods.CompanyName
}
result := make(map[string]string)
result["goods_id"] = goods.GoodsId
//todo : brand_name正则转换
result["brand_name"] = goods.BrandName
if goods.SupplierId == 17 {
result["supplier_name"] = goods.SupplierName + "-" + goods.Canal
result["supplier_type"] = goods.SupplierName
} else if goods.CompanyName != "" && goods.ProviderName != "" {
result["supplier_name"] = "撮合-" + goods.SupplierName
result["supplier_type"] = "撮合"
} else {
result["supplier_name"] = goods.SupplierName
result["supplier_type"] = goods.SupplierName
}
//todo : goods_name正则替换
result["goods_name"] = goods.GoodsName
if (goodsIdLen < 19 || goods.SupplierId == 10000) && result["supplier_type"] != "撮合" {
result["keyword"] = strings.TrimSpace("keyword")
}
result["adtag"], _ = middleware.Context.Cookie("adtag")
if goodsIdLen < 19 {
result["status"] = "1"
}
}
type SkuService struct {
}
package transformer
import (
"encoding/json"
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/tidwall/gjson"
"regexp"
"search_server/dao"
"search_server/middleware"
"search_server/model"
......@@ -10,6 +13,7 @@ import (
"search_server/pkg/config"
"search_server/pkg/gredis"
"strings"
"time"
)
//处理商品信息数据
......@@ -46,8 +50,7 @@ func DullDataInfo(keyword string, goodsListMap map[string]model.ApiGoods) (resul
goods.LastSearchTime = common.GetLastSearchTime(goods.GoodsId)
//关税信息
goods.CustomsTax = common.GetCustomsTax(goods.GoodsName, goods.BrandName)
//todo : showsku方法
ShowSku(goods)
//价格等信息混淆
if keyword != "---" {
goods, err = MetGoodsInfo(goods)
......@@ -281,3 +284,81 @@ func MetGoodsInfo(data model.DullGoodsData) (result model.DullGoodsData, err err
return data, err
}
}
//推送搜索商品信息
func ShowSku(goods model.DullGoodsData) {
//绑定需要接收的参数
type ShowSkuParams struct {
GoodsNameEq string `form:"goods_name/eq"`
Keyword string `form:"keyword"`
}
var params ShowSkuParams
middleware.Context.Bind(&params)
goodsIdLen := len(goods.GoodsId)
if goods.GoodsId == "" || goods.BrandName == "" || goods.SupplierName == "" {
return
}
referer := middleware.Context.Request.Header.Get("referer")
//if strings.Contains(referer, "www.ichunt.com/s/?k") {
if strings.Contains(referer, "") {
if goods.ProviderName != "" {
goods.BrandName = goods.ProviderName
}
if goods.CompanyName != "" {
goods.SupplierName = goods.CompanyName
}
r := regexp.MustCompile(`<b .+?>(.+?)<\/b>`)
result := make(map[string]interface{})
result["goods_id"] = goods.GoodsId
//brand_name正则转换
goods.BrandName = r.ReplaceAllString(goods.BrandName, `${1}`)
result["brand_name"] = goods.BrandName
if goods.SupplierId == 17 {
result["supplier_name"] = goods.SupplierName + "-" + goods.Canal
result["supplier_type"] = goods.SupplierName
} else if goods.CompanyName != "" && goods.ProviderName != "" {
result["supplier_name"] = "撮合-" + goods.SupplierName
result["supplier_type"] = "撮合"
} else {
result["supplier_name"] = goods.SupplierName
result["supplier_type"] = goods.SupplierName
}
//goods_name正则替换
goods.GoodsName = r.ReplaceAllString(goods.GoodsName, `${1}`)
result["goods_name"] = goods.GoodsName
if (goodsIdLen < 19 || goods.SupplierId == 10000) && result["supplier_type"] != "撮合" {
result["keyword"] = strings.TrimSpace(params.GoodsNameEq)
} else {
if params.Keyword != "" {
result["keyword"] = strings.TrimSpace(params.Keyword)
} else {
result["keyword"] = goods.GoodsName
}
}
//价格记录
if len(goods.LadderPrice) > 0 {
result["ladder_price"] = goods.LadderPrice
} else {
result["ladder_price"] = []string{}
}
//moq
result["moq"] = goods.Moq
result["show_time"] = time.Now().Unix()
//cookie获取
result["adtag"], _ = middleware.Context.Cookie("adtag")
//状态判断
if goodsIdLen < 19 {
result["status"] = 1
} else {
if goods.Status == 1 {
result["status"] = 1
} else {
result["status"] = 2
}
}
res, _ := json.Marshal(result)
fmt.Println(string(res))
//mq.PushMsg("search_show_sku_list", string(res))
}
}
......@@ -4,8 +4,8 @@ import (
"flag"
"fmt"
"github.com/syyongx/php2go"
"regexp"
"search_server/boot"
"search_server/pkg/mq"
)
func StrRandom(lenNum int) string {
......@@ -29,5 +29,10 @@ func main() {
if err := boot.Boot(path); err != nil {
fmt.Println(err)
}
mq.PushMsg("xian_test","test")
temp:=1
result:=float64(temp)
fmt.Println(result)
r := regexp.MustCompile(`<b .+?>(.+?)<\/b>`)
name := r.ReplaceAllString(`<b>219038021wdksa;ldas</b>`, `${1}`)
fmt.Println(name)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment