Commit 258383ab by 孙龙

Merge branch 'dev' of http://119.23.72.7/mushishixian/search_server into dev

# Conflicts:
#	pkg/common/function.go
parents fe798240 ac1a02db
......@@ -2,8 +2,10 @@ package main
import (
"flag"
"fmt"
"os"
"search_server/boot"
"search_server/service"
)
func main() {
......@@ -30,7 +32,16 @@ func main() {
//fmt.Println(err)
//fmt.Println(attrName)
//os.Exit(1)
//dd := service.OutLink("LM358","-1")
ss := "LM358"
mouserRes := service.OutLink(&ss,"-1")
for k, mouseItem := range mouserRes {
fmt.Println(k)
fmt.Println(mouseItem.PriceTemp)
os.Exit(1)
}
//fmt.Errorf()
//lines := []string{
// `{"index":{"_index":"hcy1","_type":"goods","_id":"s1"} }`,
......@@ -43,6 +54,22 @@ func main() {
//result,err := es.BulkES(param)
//println(result,err)
//var skuEsUpdataList []string
//
//param := map[string]interface{}{
// "goods_status":1,
// "status":1,
// "encoded": "{'ddd'}",
//}
//
//paramjson,_ := json.Marshal(param)
//
//skuEsUpdataList = append(skuEsUpdataList,string(paramjson))
//skuEsUpdataList = append(skuEsUpdataList,string(paramjson))
//
//
//println(strings.Join(skuEsUpdataList,"\n"))
os.Exit(1)
}
......
[rabmq]
url = amqp://guest:guest@192.168.2.232:5672/
url = amqp:;guest:guest@192.168.2.232:5672/
;存放本系统所有的队列名称
[rabmq_all]
; bom任务id
MQ_BOM_ITEMS_LIST=bom_items_list
; bom更新数据队列
MQ_BOM_SKU_LIST=bom_sku_list
;联营数据推送入队列-》go后台任务消费(斌哥脚本)
search_sku_list=search_sku_list
SEARCH_SKU_UPDATE_LIST=search_sku_update_list
; bom任务id
ZIYING_MQ_BOM_ITEMS_LIST=ziying_bom_items_list
; bom更新数据队列
ZIYING_MQ_BOM_SKU_LIST=ziying_bom_sku_list
\ No newline at end of file
......@@ -150,3 +150,5 @@ Index = liexin_ziying
1678 = https://estore.heilindasia.com/search.asp?p=liexin
1680 = http://shop.wpgam.com/WPGAStore/index.php?route=product/search&filter_description=true&filter_name=liexin
SUPER_AUTH_KEY = fh6y5t4rr351d2c3bryi
SEARCH_TOKEN_EXPIRE_TIME = 30
\ No newline at end of file
......@@ -36,11 +36,12 @@ func GetDataIndex(c *gin.Context) {
if r.SupplierId != "" && r.IsSort == 2 {
//所有供应商列表
//如果供应商不在合并供应商列表,则实时更新数据
if supplierName != "" && !php2go.InArray(r.SupplierName, supplierList) {
if supplierName != "" && !php2go.InArray(supplierName, supplierList) {
redisCon := gredis.Conn("search_w")
defer redisCon.Close()
//获取stockFlag
res, err := redis.Bool(redisCon.Do("SADD", "search_keyword_member", r.Keyword+"_"+r.SupplierName))
fmt.Println(r.Keyword+"_"+r.SupplierName)
if err != nil {
fmt.Println(err)
}
......
......@@ -11,10 +11,8 @@ import (
func GetMouserData(c *gin.Context) {
goodsName, _ := c.GetPostForm("goods_name")
lycon := new(service.CommonLyService)
//调外链拿数据
apiData := service.OutLink(&goodsName,"1")
//供应商详情
supplierInfo := model.SUPPLIER_REDIS_INFO_{
SupplierId:14,
......@@ -30,5 +28,5 @@ func GetMouserData(c *gin.Context) {
ErrMsg: "",
Data: goods,
}
c.JSON(200, res)
c.JSON(200,res)
}
......@@ -18,6 +18,7 @@ func Zyh(ctx *gin.Context){
zyhRequest[requestName] = strings.TrimSpace(requstValue[0])
}
}
fmt.Println(zyhRequest)
zyServiceImpl := service.NewZyServiceImpl()
......
......@@ -9,6 +9,7 @@ import (
func Cors() gin.HandlerFunc {
corsDomain := config.Get("web.cors_domain").Strings(",")
corsDomain = append(corsDomain, "https://bom.ichunt.com")
return cors.New(cors.Config{
AllowOrigins: corsDomain,
AllowMethods: []string{"POST", "GET", "PUT", "DELETE"},
......
......@@ -13,7 +13,7 @@ type ApiGoods struct {
Mpq int `json:"-"`
MpqStr interface{} `json:"mpq"`
Mpl int `json:"-"`
MplStr interface{} `json:"mpl"`
MplStr interface{} `json:"mpl,omitempty"`
Stock int `json:"-"`
StockStr interface{} `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"`
......@@ -24,10 +24,12 @@ type ApiGoods struct {
BrandId int `json:"brand_id"`
ClassId1 int `json:"class_id1"`
ClassId2 int `json:"class_id2"`
ClassName string `json:"class_name"`
Encoded string `json:"encoded"`
Packing string `json:"packing,omitempty"`
GoodsUnit string `json:"goods_unit,goods_unit"`
GoodsImages string `json:"goods_images"`
GoodsDetails string `json:"goods_details"`
GoodsBrief string `json:"goods_brief,omitempty"`
IsBuy int `json:"is_buy"`
Status int `json:"status"`
......@@ -50,8 +52,8 @@ type ApiGoods struct {
ClassId1Name string `json:"class_id1_name"`
CLassId2Name string `json:"c_lass_id2_name"`
SpuId string `json:"spu_id,omitempty"`
BatchSn string `json:"batch_sn,omitempty"`
Canal string `json:"canal,omitempty"`
BatchSn string `json:"batch_sn"`
Canal string `json:"canal"`
CpTime int `json:"cp_time"`
Coefficient Coefficient `json:"coefficient,omitempty"`
OriginalPrice []OriginalPrice `json:"original_price,omitempty"`
......
......@@ -18,6 +18,7 @@ type LyClearGoodsList struct {
Stock int64 `json:"increment"` //库存
Moq int64 `json:"moq"` //最小起订量、起订量
Tiered []*TierItem //价格梯度数量
PriceTemp []interface{} //拼接梯度,目前只有联营推送队列用
}
type TierItem struct {
Purchases uint64 //购买数量
......
package model
......@@ -9,6 +9,8 @@ import (
"math/rand"
"reflect"
"regexp"
"search_server/middleware"
"search_server/pkg/config"
"search_server/pkg/vars"
"strconv"
"strings"
......@@ -150,14 +152,122 @@ func Rand(min, max int) int {
return int(n.Int64()) + min
}
func CopyMapString(distmap map[string]string) map[string]string{
tmpmap := make(map[string]string,0)
func CopyMapString(distmap map[string]string) map[string]string {
tmpmap := make(map[string]string, 0)
for k, v := range distmap {
tmpmap[k] = v
}
return tmpmap
}
//反爬虫加密验证
func CheckSignApi(params map[string]string) (resNo int) {
ctx := middleware.Context
if ctx == nil {
return
}
referer := ctx.Request.Referer()
request := make(map[string]string)
ctx.MultipartForm()
for name, value := range ctx.Request.Form {
if value[0] != "" {
request[name] = strings.TrimSpace(value[0])
}
}
if request["hcy_test"] == "1122" {
return 0
}
if request["no_rule"] == "1122" {
return 0
}
if request["check_button"] == "2" || strings.Contains(ctx.Request.Referer(), "liexin.com") {
return 0
}
//如果是内部验证通过,则内部通过
if auth() {
return 0
}
//验证必填参数
if referer == "" {
return 4
}
if ctx.Query("asdfghjkl") != "" {
params = request
}
if ctx.PostForm("asdfghjkl") != "" {
params = request
}
params["Yo4teW_gid"], _ = ctx.Cookie("Yo4teW_gid")
if params["asdfghjkl"] == "" || params["Yo4teW_gid"] == "" || params["qwertyuiop"] == "" {
return 1
}
var temp1 []string
//根据参数,按照规则进行签名生成
for k, v := range params {
if k == "asdfghjkl" || k == "_" || k == "callback" {
continue
}
if v == "" || v == "undefined" || v == "null" || v == "NULL" {
continue
}
if len(v) <= 0 {
continue
}
temp1 = append(temp1, k+"="+v)
}
SortSlice(temp1)
temp2 := strings.Join(temp1, "")
r := regexp.MustCompile(`[^0-9a-zA-Z]`)
temp2 = r.ReplaceAllString(temp2, "")
temp2 = strings.ToUpper(temp2)
r = regexp.MustCompile(`[ABC]`)
temp2 = r.ReplaceAllString(temp2, "")
temp3 := php2go.Sha1(temp2)
//'YO4TEW_GID%3DEFDDE3E06D15F887866E9D96DOM_RNK%3D1GOODS_NME%2FONDITION%3DLM358P%3D1PF%3D1TIME_LIEXIN%3D1545009990450';
//验证签名
if temp3 == params["asdfghjkl"] {
return 0
}
return 3
}
//内部免验证通过
func auth() bool {
ctx := middleware.Context
if ctx == nil {
return false
}
request := make(map[string]string)
ctx.MultipartForm()
for name, value := range ctx.Request.Form {
if value[0] != "" {
request[name] = strings.TrimSpace(value[0])
}
}
k1 := request["k1"]
k1Num, _ := strconv.Atoi(k1)
k2 := request["k2"]
key := config.Get("SUPER_AUTH_KEY").String()
if k1 != "" && int64(k1Num) < (time.Now().Unix()-600) {
return false
}
//md5(md5($pwd).$salt);
pwd := Md5(Md5(k1) + key)
if k2 == pwd {
return true
}
return false
}
}
// interface{}转为 []interface{}
......
package common
import (
"reflect"
"sort"
)
func getCommon(array interface{}) (reflect.Type, reflect.Value, int) {
t := reflect.TypeOf(array)
v := reflect.ValueOf(array)
l := v.Len()
return t, v, l
}
func SortSlice(array interface{}) {
t, v, _ := getCommon(array)
// res := make([]interface{}, l)
if t.Kind() == reflect.Slice {
switch v.Index(0).Kind() {
case reflect.Int:
array := array.([]int)
sort.Ints(array)
case reflect.String:
array := array.([]string)
sort.Strings(array)
case reflect.Float64:
array := array.([]float64)
sort.Float64s(array)
default:
panic("the param can only be int/string/float64 array")
}
} else {
panic("expects parameter 1 to be array")
}
}
......@@ -63,7 +63,7 @@ func BulkES(param string) (result string, err error) {
//req.Debug = true
header := make(http.Header)
header.Set("Content-Type", "application/x-ndjson")
resp, err := req.Post(esUrl+"/_bulk", header, param)
resp, err := req.Post(esUrl+"/_bulk?refresh=true", header, param) //refresh=true 立刻插入或修改 立刻生效,不需要等待es缓存写入文档
if err != nil {
return
}
......@@ -73,7 +73,7 @@ func BulkES(param string) (result string, err error) {
func CurlESMSearch(queryJson string) (result string, err error) {
endpoints := config.Get("es.urls").Strings(",")
//随机获取一个节点进行请求
req.Debug = true
req.Debug = false
esUrl := endpoints[rand.Intn(len(endpoints))]
params := req.BodyJSON(queryJson)
resp, err := req.Post(esUrl+"/_msearch", params)
......
......@@ -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"
......@@ -28,8 +29,11 @@ func InitRouter() *gin.Engine {
r.POST("/search/quote/getDataPur", controller.GetDataPur)
//GetData控制器相关
r.GET("/search/get_data/index", controller.GetDataIndex)
r.POST("/search/get_data/index", controller.GetDataIndex)
r.GET("/search/get_data", controller.GetDataIndex)
r.POST("/search/get_data", controller.GetDataIndex)
r.GET("/test", func(c *gin.Context) {
fmt.Println(c.Query("test"))
})
return r
}
......@@ -170,7 +170,7 @@ func getBomTermQuery(goodsName, brandName string, number int, isRawSearch bool)
if isRawSearch {
source.Size(100)
} else {
source.Size(1)
source.Size(50)
}
source.Sort("_score", false).Sort("sort", false).Sort("single_price", true)
queryRequest := elastic.NewSearchRequest().Source(source)
......
......@@ -4,12 +4,16 @@ package service
联营请求外链后 更新或者新增到平台 (es,redis,rabmq)
*/
import (
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"search_server/middleware"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/es"
"search_server/pkg/gredis"
"search_server/pkg/mq"
"search_server/pkg/mysql"
"strconv"
"strings"
......@@ -22,12 +26,14 @@ type CommonLyService struct {
supplierId int64 //调用当前方法的供应商ID
supplierName string //调用当前方法的供应商名称
skuEsUpdataList []string //组装批量更新es数据
flag string //调试开关
flagStr string //调试输出内容
ctx *gin.Context
}
//初始化类
func (t *CommonLyService) LyServerRun(){
CommonLyService := new(CommonLyService)
CommonLyService.supplier_over_time = map[string]int64{
t.supplier_over_time = map[string]int64{
"arrow":3600,
"verical":3600,
"mouser":3600,
......@@ -35,7 +41,13 @@ func (t *CommonLyService) LyServerRun(){
"tme":3600,
"buerklin":3600,
}
t.ctx = middleware.Context
t.ctx.MultipartForm()
for requestName, requstValue := range t.ctx.Request.Form {
if requestName == "flag" {
t.flag = strings.TrimSpace(requstValue[0])
}
}
}
/*
......@@ -254,20 +266,54 @@ func (t * CommonLyService) EsSkuInfo(skuInfo *model.LyClearGoodsList,spuId * str
}
paramjson,_ := json.Marshal(param)
_ = append(t.skuEsUpdataList,`{"index":{"_index":"`+t.supplierName+`","_type":"goods","_id":"`+skuInfo.GoodsId+`"}}`)
_ = append(t.skuEsUpdataList,string(paramjson))
t.skuEsUpdataList = append(t.skuEsUpdataList,`{"index":{"_index":"`+t.supplierName+`","_type":"goods","_id":"`+skuInfo.GoodsId+`"}}`)
t.skuEsUpdataList = append(t.skuEsUpdataList,string(paramjson))
}
/*
推入队列
推入队列=》(斌 go队列去消费更新db+mongodb..等操作)
*/
func toGoRabmq() {
func (t * CommonLyService) updateSkuDB(skuInfo *model.LyClearGoodsList) {
if skuInfo.GoodsId == "" {
return
}
param := map[string]interface{}{
"pn":t.supplierName,
"stock":skuInfo.Stock,
"tiered":skuInfo.PriceTemp,
"increment":skuInfo.Increment,
"sku_id":skuInfo.GoodsId,
"brand_name":skuInfo.BrandName,
"goods_name":skuInfo.GoodsName,
"goods_sn":skuInfo.GoodsSn,
}
paramjson,_ := json.Marshal(param)
if t.flag == "101" {
t.flagStr = "<br/><br/>";
t.flagStr = "推送到go更新db:";
t.flagStr = string(paramjson);
t.flagStr = "<br/><br/>";
}
mq.PushMsg(config.Get("rabmq_all.SEARCH_SKU_UPDATE_LIST").String(),string(paramjson))
}
/*
更新es
批量插入或者更新es
*/
func toEs() {
func (t *CommonLyService) pushEs() {
if len(t.skuEsUpdataList) == 0 {
if t.flag == "101" {
t.flagStr += "<br/>没有可插入es的数据"
}
return
}
param := strings.Join(t.skuEsUpdataList, "\n")+"\n"
result,_ := es.BulkES(param) //批量插入
if t.flag == "101" {
t.flagStr += "<br/>"
t.flagStr += "插入es:"
t.flagStr += param
t.flagStr += result
}
}
......@@ -85,6 +85,7 @@ func (gs *GetDataService) GetQuery(originKeyword, supplierName, brandId, goodsNa
source.Sort("update_time", false)
source.Sort("stock", false)
source.Sort("single_price", true)
source.FetchSourceContext(elastic.NewFetchSourceContext(true).Include("goods_id", "old_goods_id", "status"))
source.From(0)
source.Size(2)
......
package service
import (
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/imroc/req"
"github.com/tidwall/gjson"
......@@ -66,13 +65,16 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG
goods.GoodsType = int(data.Get("goods_type").Int())
goods.SupplierId = int(data.Get("supplier_id").Int())
goods.Mpq = int(data.Get("mpq").Int())
goods.MpqStr = int(data.Get("mpq").Int())
goods.Moq = int(data.Get("moq").Int())
goods.MoqStr = int(data.Get("moq").Int())
goods.Stock = int(data.Get("stock").Int())
goods.StockStr = int(data.Get("stock").Int())
goods.HkDeliveryTime = data.Get("hk_delivery_time").String()
goods.CnDeliveryTime = data.Get("cn_delivery_time").String()
goods.BrandName = data.Get("brand_name").String()
goods.SupplierName = data.Get("supplier_name").String()
goods.BrandId = int(data.Get("goods_id").Int())
goods.BrandId = int(data.Get("brand_id").Int())
goods.ClassId1 = int(data.Get("class_id1").Int())
goods.ClassId2 = int(data.Get("class_id2").Int())
goods.Encoded = data.Get("encoded").String()
......@@ -81,6 +83,7 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG
goods.GoodsImages = data.Get("goods_images").String()
goods.GoodsBrief = data.Get("goods_brief").String()
goods.Mpl = int(data.Get("mpl").Int())
goods.MplStr = int(data.Get("mpl").Int())
goods.Status = int(data.Get("status").Int())
goods.IsBuy = int(data.Get("is_buy").Int())
goods.Pdf = data.Get("pdf").String()
......@@ -96,6 +99,7 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG
goods.MpgUnitName = data.Get("mpg_unit_name").String()
goods.ScmBrandName = data.Get("scm_brand_name").String()
goods.AllowCoupon = int(data.Get("allow_coupon").Int())
goods.UpdateTime = int(data.Get("update_time").Int())
goods.ClassId1Name = data.Get("class_id1_name").String()
goods.CLassId2Name = data.Get("c_lass_id2_name").String()
goods.SpuId = data.Get("spu_id").String()
......@@ -108,6 +112,7 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG
goods.SpuBrief = data.Get("spu_brief").String()
goods.SpuDetail = data.Get("spu_detail").String()
goods.ClassName3 = data.Get("class_name3").String()
goods.ClassName = data.Get("class_name").String()
goods.ErpTax = data.Get("erp_tax").Bool()
goods.SupplierId = int(data.Get("supplier_id").Int())
goods.GoodsType = int(data.Get("goods_type").Int())
......@@ -116,10 +121,11 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG
ladderPrice := make([]model.LadderPrice, 0)
for _, price := range data.Get("ladder_price").Array() {
ladder := model.LadderPrice{
Purchases: int(price.Get("purchases").Int()),
PriceUs: price.Get("price_us").Float(),
PriceCn: price.Get("price_cn").Float(),
PriceAc: price.Get("price_ac").Float(),
Purchases: int(price.Get("purchases").Int()),
PurchasesStr: int(price.Get("purchases").Int()),
PriceUs: price.Get("price_us").Float(),
PriceCn: price.Get("price_cn").Float(),
PriceAc: price.Get("price_ac").Float(),
}
ladderPrice = append(ladderPrice, ladder)
}
......@@ -161,8 +167,8 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG
//supp_extend_fee
goods.SuppExtendFee.Cn.Max = int(data.Get("supp_extend_fee.cn.max").Int())
goods.SuppExtendFee.Cn.Price = data.Get("supp_extend_fee.cn.price").Float()
goods.SuppExtendFee.Hk.Max = int(data.Get("supp_extend_fee.cn.max").Int())
goods.SuppExtendFee.Hk.Price = data.Get("supp_extend_fee.cn.price").Float()
goods.SuppExtendFee.Hk.Max = int(data.Get("supp_extend_fee.hk.max").Int())
goods.SuppExtendFee.Hk.Price = data.Get("supp_extend_fee.hk.price").Float()
//scm_brand
goods.ScmBrand.ErpBrandName = data.Get("scm_brand.erp_brand_name").String()
......@@ -231,7 +237,6 @@ func GetGoodsIdsByEs(res string) (goodsIds []string) {
for _, item := range gjArray {
goodsIds = append(goodsIds, item.String())
}
fmt.Println(goodsIds)
return
}
......@@ -241,8 +246,5 @@ func GetGoodsIdsByEsMsearch(res string) (goodsIds []string) {
for _, item := range gjArray {
goodsIds = append(goodsIds, item.String())
}
fmt.Println(goodsIds)
return
}
......@@ -4,6 +4,8 @@ import (
"github.com/imroc/req"
"github.com/tidwall/gjson"
"search_server/model"
"strconv"
"strings"
"time"
)
//mouser外链网址
......@@ -25,8 +27,7 @@ func OutLink(goodsName *string,flag string) map[string]*model.LyClearGoodsList {
result = resp.String(); //请求外链拿到结果
}
var productList map[string]*model.LyClearGoodsList //格式化数据后返回的所有数据
productList = make(map[string]*model.LyClearGoodsList,0)
productList := make(map[string]*model.LyClearGoodsList,0)
apiGoodsList := gjson.Get(result, "SearchResults.Parts").Array()
for _, goods := range apiGoodsList {
......@@ -34,23 +35,36 @@ func OutLink(goodsName *string,flag string) map[string]*model.LyClearGoodsList {
goodsSn := goods.Get("MouserPartNumber").String()
ladderPrice := make([]*model.TierItem, 0)
priceTemp := make([]interface{}, 0)
//拼接价格梯度
apiPriceTi := goods.Get("PriceBreaks").Array()
var apiLowerPrice float64 = 0; //计算最低价格
for _,priceItem := range apiPriceTi{
priceItemStr := priceItem.String();
onePrice := gjson.Get(priceItemStr, "Price").Float()
//价格转换
onePrice := gjson.Get(priceItemStr, "Price").String()
onePrice = strings.ReplaceAll(strings.Trim(onePrice,"$"),",","")
skuPrice,_ := strconv.ParseFloat(onePrice,64) //转成float64
//数量转换
quantity := gjson.Get(priceItemStr, "Quantity").Uint()
if apiLowerPrice == 0 {
apiLowerPrice = onePrice
}else if apiLowerPrice > onePrice {
apiLowerPrice = onePrice
apiLowerPrice = skuPrice
}else if apiLowerPrice > skuPrice {
apiLowerPrice = skuPrice
}
ladder := model.TierItem{
Purchases: gjson.Get(priceItemStr, "Quantity").Uint(),
PriceUs: onePrice,
Purchases: quantity,
PriceUs: skuPrice,
PriceCn: 0,
}
ladderPrice = append(ladderPrice, &ladder)
//梯度缓存数据
priceTemp = append(priceTemp,[]interface{}{
quantity,
skuPrice,
})
}
//拼接联营数据
......@@ -67,6 +81,7 @@ func OutLink(goodsName *string,flag string) map[string]*model.LyClearGoodsList {
RestrictionMessage: goods.Get("RestrictionMessage").String(),
SinglePrice: apiLowerPrice,
Tiered:ladderPrice,
PriceTemp: priceTemp,
}
productList[goodsSn] = &LyClearGoodsList
......
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
......@@ -53,6 +50,9 @@ func (qs *QuoteService) GetGoodsBySupplierName(r requests.GetGoodsBySupplierRequ
goodsIds := GetGoodsIdsByEs(esResult)
goodsList, err := GetGoodsInfo(goodsIds)
dullData, err := transformer.DullDataInfo(r.Keyword, goodsList)
quoteTransformer := transformer.QuoteTransformer{}
//还要去转一下阶梯价比例
dullData = quoteTransformer.TransformLadderPrice(dullData)
result = GetReturnSupplierData(dullData)
result["total"] = gjson.Get(esResult, "hits.total").Int()
result["took"] = gjson.Get(esResult, "took").Int()
......
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))
}
}
......@@ -48,3 +48,21 @@ func (qt *QuoteTransformer) TransformCollectData(keyword, supplierName string, c
}
return
}
//提供给客服报价系统专用
func (qt *QuoteTransformer) TransformLadderPrice(dullData []model.DullGoodsData) (result []model.DullGoodsData) {
for key, data := range dullData {
if len(data.LadderPrice) > 0 {
for k, price := range data.LadderPrice {
if price.PriceUs != 0 {
if data.SupplierId == 6 {
dullData[key].LadderPrice[k].PriceUs = data.OriginalPrice[k].PriceUs * data.PriceHkxs
} else {
dullData[key].LadderPrice[k].PriceUs = data.OriginalPrice[k].PriceUs * data.ApiGoods.Coefficient.ExtraRatio
}
}
}
}
}
return dullData
}
......@@ -4,8 +4,9 @@ import (
"flag"
"fmt"
"github.com/syyongx/php2go"
"reflect"
"search_server/boot"
"search_server/pkg/mq"
"search_server/pkg/common"
)
func StrRandom(lenNum int) string {
......@@ -29,5 +30,22 @@ func main() {
if err := boot.Boot(path); err != nil {
fmt.Println(err)
}
mq.PushMsg("xian_test","test")
b := []string{"b", "z", "a"}
common.SortSlice(b)
fmt.Println(b)
}
func InterfaceSlice(slice interface{}) []interface{} {
s := reflect.ValueOf(slice)
if s.Kind() != reflect.Slice {
panic("InterfaceSlice() given a non-slice type")
}
ret := make([]interface{}, s.Len())
for i := 0; i < s.Len(); i++ {
ret[i] = s.Index(i).Interface()
}
return ret
}
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