Commit 4ece115c by huangchengyi

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

# Conflicts:
#	controller/quote_controller.go
parents e7fc6f26 45f76ff4
[gorm] [gorm]
mode = debug mode = debug
[mysql]
user_name = root
password = root
host = 192.168.2.250
database = test1
table_prefix =
type = mysql
[bom]
user_name = root
password = root
host = 192.168.2.250
database = test
table_prefix =
type = mysql
[spu] [spu]
user_name = spu user_name = spu
password = spu password = spu
...@@ -29,7 +13,7 @@ type = mysql ...@@ -29,7 +13,7 @@ type = mysql
#SupDbUser:Supssy2@@!!@$#yxy@172.18.137.21:3306/liexin_supp #SupDbUser:Supssy2@@!!@$#yxy@172.18.137.21:3306/liexin_supp
[supp] [supp]
user_name = liexin_ass user_name = liexin_ass
password = liexin_ass#zsyM password = `liexin_ass#zsyM`
host = 192.168.2.232 host = 192.168.2.232
database = liexin_ass database = liexin_ass
table_prefix =lie_ table_prefix =lie_
...@@ -37,7 +21,7 @@ type = mysql ...@@ -37,7 +21,7 @@ type = mysql
[cms] [cms]
user_name = ichuntcms user_name = ichuntcms
password = ichuntcms#zsyM password = `ichuntcms#zsyM`
host = 192.168.2.232 host = 192.168.2.232
database = ichuntcms database = ichuntcms
table_prefix = table_prefix =
......
...@@ -150,3 +150,19 @@ Index = liexin_ziying ...@@ -150,3 +150,19 @@ Index = liexin_ziying
1678 = https://estore.heilindasia.com/search.asp?p=liexin 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 1680 = http://shop.wpgam.com/WPGAStore/index.php?route=product/search&filter_description=true&filter_name=liexin
[AUTH]
SUPER_AUTH_KEY = fh6y5t4rr351d2c3bryi
SEARCH_TOKEN_EXPIRE_TIME = 30
[UNIT_SUPPLIER_LOG_CODE]
333333 = arrow
444444 = master
555555 = mouser
666666 = verical
777777 = tme
888888 = buerklin
999999 = zhuanmai
[SEARCH_API_LOG]
SEARCH_API_ERROR_PRE = search_api_overtime_
\ No newline at end of file
...@@ -41,7 +41,7 @@ func GetDataIndex(c *gin.Context) { ...@@ -41,7 +41,7 @@ func GetDataIndex(c *gin.Context) {
defer redisCon.Close() defer redisCon.Close()
//获取stockFlag //获取stockFlag
res, err := redis.Bool(redisCon.Do("SADD", "search_keyword_member", r.Keyword+"_"+r.SupplierName)) res, err := redis.Bool(redisCon.Do("SADD", "search_keyword_member", r.Keyword+"_"+r.SupplierName))
fmt.Println(r.Keyword+"_"+r.SupplierName) fmt.Println(r.Keyword + "_" + r.SupplierName)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
...@@ -54,7 +54,7 @@ func GetDataIndex(c *gin.Context) { ...@@ -54,7 +54,7 @@ func GetDataIndex(c *gin.Context) {
r.FirstSearchPage = 2 r.FirstSearchPage = 2
quoteService := service.QuoteService{} quoteService := service.QuoteService{}
result, _ := quoteService.GetGoodsBySupplier(r.GetGoodsBySupplierRequest) result, _ := quoteService.GetGoodsBySupplier(r.GetGoodsBySupplierRequest)
c.JSON(200, common.SuccessResponse(1, "", result)) common.Output(1, "", result)
return return
} }
} }
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/ichunt2019/logger"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"search_server/dao" "search_server/dao"
"search_server/pkg/common" "search_server/pkg/common"
...@@ -22,47 +23,50 @@ func QuoteIndex(c *gin.Context) { ...@@ -22,47 +23,50 @@ func QuoteIndex(c *gin.Context) {
var r requests.QuoteIndexRequest var r requests.QuoteIndexRequest
//绑定参数到结构体 //绑定参数到结构体
if err := c.ShouldBind(&r); err != nil { if err := c.ShouldBind(&r); err != nil {
fmt.Println(err) logger.Error("%s", err)
} }
quoteService := service.QuoteService{} quoteService := service.QuoteService{}
//检查参数,有错误就返回错误 //检查参数,有错误就返回错误
errCode, errMsg := requests.CheckQuoteRequest(r) errCode, errMsg := requests.CheckQuoteRequest(r)
if errCode != 0 { if errCode != 0 {
c.JSON(200, common.ErrorResponse(errCode, errMsg)) common.Output(errCode, errMsg, nil)
return return
} }
flag := 1 flag := 1
var res map[string]interface{} var res map[string]interface{}
if r.FollowHit != 0 && r.FollowHit != 1 { if r.FollowHit != 0 && r.FollowHit != 1 {
res, _ = quoteService.GetGoodsBySupplier(r.GetGoodsBySupplierRequest) res, _ = quoteService.GetGoodsBySupplier(r.GetGoodsBySupplierRequest)
if len(res) > 0 { if res != nil {
flag = 0 flag = 0
common.Output(flag, "", res)
} else {
common.Output(flag, "", nil)
} }
c.JSON(200, common.SuccessResponse(flag, "", res))
return return
} }
//获取供应商名称 //获取供应商名称
supplierNameMap := config.Cfg.Section("SUPPLIER_ALL").KeysHash() supplierNameMap := config.Cfg.Section("SUPPLIER_ALL").KeysHash()
supplierName, exist := supplierNameMap[r.SupplierId] supplierName, exist := supplierNameMap[r.SupplierId]
if !exist { if !exist {
c.JSON(200, common.ErrorResponse(1, "供应商有误")) common.Output(1, "供应商有误", nil)
return return
} }
if supplierName == "mouser" { if supplierName == "mouser" {
//mouser同步请求搜索 //mouser同步请求搜索
res, _ = mouserOrg(r.Keyword, r.SupplierId) res, _ = mouserOrg(r.Keyword, r.SupplierId)
} else { } else {
r.GetGoodsBySupplierRequest.SupplierName = supplierName
res, _ = quoteService.GetGoodsBySupplierName(r.GetGoodsBySupplierRequest) res, _ = quoteService.GetGoodsBySupplierName(r.GetGoodsBySupplierRequest)
} }
if len(res) > 0 { if len(res) > 0 {
flag = 0 flag = 0
} }
c.JSON(200, common.SuccessResponse(flag, "", res)) common.Output(flag, "", res)
return return
} }
func mouserOrg(keyword, suppliedId string) (result map[string]interface{}, err error) { func mouserOrg(keyword, suppliedId string) (result map[string]interface{}, err error) {
mouserRes := ly.OutLink(&keyword, "-1") mouserRes := ly.OutLink(&keyword, "1")
redisCon := gredis.Conn("search_r") redisCon := gredis.Conn("search_r")
defer redisCon.Close() defer redisCon.Close()
skuMouser := make(map[string]string) skuMouser := make(map[string]string)
...@@ -71,7 +75,7 @@ func mouserOrg(keyword, suppliedId string) (result map[string]interface{}, err e ...@@ -71,7 +75,7 @@ func mouserOrg(keyword, suppliedId string) (result map[string]interface{}, err e
if k == "N/A" { if k == "N/A" {
continue continue
} }
snSku := php2go.Md5(strings.ToUpper(k + "_" + suppliedId)) snSku := php2go.Md5(strings.ToLower(k + "_" + suppliedId))
skuId, _ := redis.String(redisCon.Do("HGET", config.Get("SKU_UNIQUE_JUDGE").String(), snSku)) skuId, _ := redis.String(redisCon.Do("HGET", config.Get("SKU_UNIQUE_JUDGE").String(), snSku))
if skuId != "" { if skuId != "" {
skuMouser[skuId] = mouseItem.RestrictionMessage skuMouser[skuId] = mouseItem.RestrictionMessage
...@@ -92,44 +96,48 @@ func mouserOrg(keyword, suppliedId string) (result map[string]interface{}, err e ...@@ -92,44 +96,48 @@ func mouserOrg(keyword, suppliedId string) (result map[string]interface{}, err e
return return
} }
//获取内部编码对应关系
func GetDataPur(c *gin.Context) { func GetDataPur(c *gin.Context) {
supplierData, err := dao.GetAllSupplierCodeAndUid() supplierData, err := dao.GetAllSupplierCodeAndUid()
if err != nil { if err != nil {
c.String(200, err.Error()) c.JSON(200, err.Error())
return return
} }
intracode, err := dao.GetAllIntraCode() intracode, err := dao.GetAllIntraCode()
if err != nil { if err != nil {
c.String(200, err.Error()) c.JSON(200, err.Error())
return return
} }
userInfo, err := dao.GetAllUserBaseInfo() userInfo, err := dao.GetAllUserBaseInfo()
if err != nil { if err != nil {
c.String(200, err.Error()) c.JSON(200, err.Error())
return return
} }
temp := make(map[int]string) userInfoData := make(map[int]string)
for _, user := range userInfo { for _, user := range userInfo {
if user.Name == "" && user.Email != "" { if user.Name == "" && user.Email != "" {
temp[user.UserId] = user.Email userInfoData[user.UserId] = user.Email
} else { } else {
temp[user.UserId] = user.Name fmt.Println(user.UserId)
userInfoData[user.UserId] = user.Name
} }
} }
temp2 := make(map[int]string) temp2 := make(map[int]string)
for _, code := range intracode { for _, code := range intracode {
if _, exist := temp[code.AdminId]; exist { //fmt.Println(userInfoData[code.AdminId])
temp2[code.CodeId] = temp[code.AdminId] if _, exist := userInfoData[code.AdminId]; exist {
temp2[code.CodeId] = userInfoData[code.AdminId]
} else { } else {
temp2[code.CodeId] = "" temp2[code.CodeId] = ""
} }
} }
redisCon := gredis.Conn("search_r") redisCon := gredis.Conn("search_w")
defer redisCon.Close() defer redisCon.Close()
for _, supplier := range supplierData { for _, supplier := range supplierData {
if value, exist := temp2[supplier.ChannelUid]; exist { if value, exist := temp2[supplier.ChannelUid]; exist {
fmt.Println(value)
fmt.Println(temp2[supplier.ChannelUid])
res, err := redis.Bool(redisCon.Do("HSET", "search_supplier_canaltopurchase_test", supplier.SupplierCode, value)) res, err := redis.Bool(redisCon.Do("HSET", "search_supplier_canaltopurchase_test", supplier.SupplierCode, value))
if err != nil || !res { if err != nil || !res {
c.String(200, "失败") c.String(200, "失败")
...@@ -145,5 +153,6 @@ func GetDataPur(c *gin.Context) { ...@@ -145,5 +153,6 @@ func GetDataPur(c *gin.Context) {
func GetData(keyword, supplierName string) (res interface{}) { func GetData(keyword, supplierName string) (res interface{}) {
quoteService := service.QuoteService{} quoteService := service.QuoteService{}
res, _ = quoteService.GetData(keyword, supplierName) res, _ = quoteService.GetData(keyword, supplierName)
fmt.Println(res)
return return
} }
...@@ -18,16 +18,20 @@ func Zyh(ctx *gin.Context){ ...@@ -18,16 +18,20 @@ func Zyh(ctx *gin.Context){
zyhRequest[requestName] = strings.TrimSpace(requstValue[0]) zyhRequest[requestName] = strings.TrimSpace(requstValue[0])
} }
} }
fmt.Println(zyhRequest)
zyServiceImpl := service.NewZyServiceImpl() zyServiceImpl := service.NewZyServiceImpl()
zyhResponse := &model.ZyhResponse{} zyhResponse := &model.ZyhResponse{}
err := zyServiceImpl.Zyh(ctx,zyhRequest,zyhResponse) zyhResponse,err := zyServiceImpl.Zyh(ctx,zyhRequest)
if err != nil{ if err != nil{
zyhResponse.ErrorCode = 1 zyhResponse.ErrorCode = 1
zyhResponse.ErrorMsg = fmt.Sprintf("%s",err) zyhResponse.ErrorMsg = fmt.Sprintf("%s",err)
ctx.JSON(200,zyhResponse) ctx.JSON(200,zyhResponse)
} }
fmt.Println("6666666666666")
fmt.Printf("%+v",zyhResponse)
ctx.JSON(200,zyhResponse) ctx.JSON(200,zyhResponse)
} }
...@@ -7,13 +7,12 @@ import ( ...@@ -7,13 +7,12 @@ import (
//获取所有内部编码 //获取所有内部编码
func GetAllIntraCode() (intracode []model.Intracode, err error) { func GetAllIntraCode() (intracode []model.Intracode, err error) {
_, err = mysql.Conn("cms").Table("lie_intracode").Select("supplier_code,channel_uid"). err = mysql.Conn("cms").Table("lie_intracode").Select("code_id,admin_id").Find(&intracode)
Where("status = ?", 2).Get(&intracode)
return return
} }
//获取所有的用户基础信息 //获取所有的用户基础信息
func GetAllUserBaseInfo() (userBaseInfo []model.CmsUserInfo, err error) { func GetAllUserBaseInfo() (userBaseInfo []model.CmsUserInfo, err error) {
_, err = mysql.Conn("cms").Table("user_info").Select("name,email,userId").Get(&userBaseInfo) err = mysql.Conn("cms").Table("user_info").Select("name,email,userId").Find(&userBaseInfo)
return return
} }
...@@ -7,8 +7,7 @@ import ( ...@@ -7,8 +7,7 @@ import (
//获取供应商编码和渠道开发员id //获取供应商编码和渠道开发员id
func GetAllSupplierCodeAndUid() (supplierChannels []model.SupplierChannel, err error) { func GetAllSupplierCodeAndUid() (supplierChannels []model.SupplierChannel, err error) {
_, err = mysql.Conn("supp").Table("lie_supplier_extra").Select("supplier_code,channel_uid"). err = mysql.Conn("supp").Table("lie_supplier_channel").Select("supplier_code,channel_uid").
Where("status = ?", 2).Get(&supplierChannels) Where("status = ?", 2).Find(&supplierChannels)
return return
} }
...@@ -25,7 +25,7 @@ require ( ...@@ -25,7 +25,7 @@ require (
github.com/prometheus/client_golang v1.5.1 // indirect github.com/prometheus/client_golang v1.5.1 // indirect
github.com/prometheus/common v0.10.0 github.com/prometheus/common v0.10.0
github.com/prometheus/procfs v0.0.11 // indirect github.com/prometheus/procfs v0.0.11 // indirect
github.com/sirupsen/logrus v1.5.0 // indirect github.com/sirupsen/logrus v1.5.0
github.com/smartystreets/goconvey v1.6.4 // indirect github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/testify v1.5.1 // indirect github.com/stretchr/testify v1.5.1 // indirect
github.com/syyongx/php2go v0.9.4 github.com/syyongx/php2go v0.9.4
......
...@@ -9,6 +9,8 @@ import ( ...@@ -9,6 +9,8 @@ import (
func Cors() gin.HandlerFunc { func Cors() gin.HandlerFunc {
corsDomain := config.Get("web.cors_domain").Strings(",") corsDomain := config.Get("web.cors_domain").Strings(",")
corsDomain = append(corsDomain, "https://bom.ichunt.com")
corsDomain = append(corsDomain, "https://bom.ichunt.com")
return cors.New(cors.Config{ return cors.New(cors.Config{
AllowOrigins: corsDomain, AllowOrigins: corsDomain,
AllowMethods: []string{"POST", "GET", "PUT", "DELETE"}, AllowMethods: []string{"POST", "GET", "PUT", "DELETE"},
......
...@@ -2,18 +2,18 @@ package model ...@@ -2,18 +2,18 @@ package model
//内部编码表 //内部编码表
type Intracode struct { type Intracode struct {
CodeId int `json:"code_id"` CodeId int `xorm:"code_id"`
AdminId int `json:"admin_id"` AdminId int `xorm:"admin_id"`
UserId int `json:"user_id"` UserId int `xorm:"user_id"`
CreateTime int `json:"create_time"` CreateTime int `xorm:"create_time"`
UpdateTime int `json:"update_time"` UpdateTime int `xorm:"update_time"`
} }
type CmsUserInfo struct { type CmsUserInfo struct {
UserId int `json:"userId"` UserId int `json:"userId" xorm:"userId"`
Name string `json:"name"` Name string `xorm:"name"`
EngName string `json:"engName"` EngName string `xorm:"engName"`
Email string `json:"email"` Email string `xorm:"email"`
Mobile string `json:"mobile"` Mobile string `xorm:"mobile"`
} }
\ No newline at end of file
...@@ -7,13 +7,14 @@ type ApiGoods struct { ...@@ -7,13 +7,14 @@ type ApiGoods struct {
GoodsName string `json:"goods_name"` GoodsName string `json:"goods_name"`
GoodsSn string `json:"goods_sn"` GoodsSn string `json:"goods_sn"`
GoodsType int `json:"goods_type"` GoodsType int `json:"goods_type"`
GoodsStatus int `json:"goods_status"`
SupplierId int `json:"supplier_id"` SupplierId int `json:"supplier_id"`
Moq int `json:"-"` Moq int `json:"-"`
MoqStr interface{} `json:"moq"` MoqStr interface{} `json:"moq"`
Mpq int `json:"-"` Mpq int `json:"-"`
MpqStr interface{} `json:"mpq"` MpqStr interface{} `json:"mpq"`
Mpl int `json:"-"` Mpl int `json:"-"`
MplStr interface{} `json:"mpl"` MplStr interface{} `json:"mpl,omitempty"`
Stock int `json:"-"` Stock int `json:"-"`
StockStr interface{} `json:"stock"` StockStr interface{} `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"` HkDeliveryTime string `json:"hk_delivery_time"`
...@@ -24,10 +25,12 @@ type ApiGoods struct { ...@@ -24,10 +25,12 @@ type ApiGoods struct {
BrandId int `json:"brand_id"` BrandId int `json:"brand_id"`
ClassId1 int `json:"class_id1"` ClassId1 int `json:"class_id1"`
ClassId2 int `json:"class_id2"` ClassId2 int `json:"class_id2"`
ClassName string `json:"class_name"`
Encoded string `json:"encoded"` Encoded string `json:"encoded"`
Packing string `json:"packing,omitempty"` Packing string `json:"packing,omitempty"`
GoodsUnit string `json:"goods_unit,goods_unit"` GoodsUnit string `json:"goods_unit,goods_unit"`
GoodsImages string `json:"goods_images"` GoodsImages string `json:"goods_images"`
GoodsDetails string `json:"goods_details"`
GoodsBrief string `json:"goods_brief,omitempty"` GoodsBrief string `json:"goods_brief,omitempty"`
IsBuy int `json:"is_buy"` IsBuy int `json:"is_buy"`
Status int `json:"status"` Status int `json:"status"`
...@@ -50,20 +53,21 @@ type ApiGoods struct { ...@@ -50,20 +53,21 @@ type ApiGoods struct {
ClassId1Name string `json:"class_id1_name"` ClassId1Name string `json:"class_id1_name"`
CLassId2Name string `json:"c_lass_id2_name"` CLassId2Name string `json:"c_lass_id2_name"`
SpuId string `json:"spu_id,omitempty"` SpuId string `json:"spu_id,omitempty"`
BatchSn string `json:"batch_sn,omitempty"` BatchSn string `json:"batch_sn"`
Canal string `json:"canal,omitempty"` Canal string `json:"canal"`
CpTime int `json:"cp_time"` CpTime int `json:"cp_time"`
Coefficient Coefficient `json:"coefficient,omitempty"` Coefficient Coefficient `json:"coefficient,omitempty"`
OriginalPrice []OriginalPrice `json:"original_price,omitempty"` OriginalPrice []OriginalPrice `json:"original_price,omitempty"`
SuppExtendFee SuppExtendFee `json:"supp_extend_fee,omitempty"` SuppExtendFee SuppExtendFee `json:"supp_extend_fee,omitempty"`
ClassId3 int `json:"class_id3,omitempty"` ClassId3 int `json:"class_id3"`
SpuName string `json:"spu_name,omitempty"` SpuName string `json:"spu_name,omitempty"`
ImagesL string `json:"images_l,omitempty"` ImagesL string `json:"images_l,omitempty"`
SpuBrief string `json:"spu_brief"` SpuBrief string `json:"spu_brief"`
SpuDetail string `json:"spu_detail,omitempty"` SpuDetail string `json:"spu_detail"`
ClassName3 string `json:"class_name3,omitempty"` ClassName3 string `json:"class_name3"`
ErpTax bool `json:"erp_tax"` ErpTax bool `json:"erp_tax"`
ScmBrand ScmBrand `json:"scm_brand,omitempty"` ScmBrand ScmBrand `json:"scm_brand,omitempty"`
ActivityEndTime int64 `json:"activity_end_time,omitempty"`
} }
//经过处理后的商品数据 //经过处理后的商品数据
......
package model package model
type SupplierChannel struct { type SupplierChannel struct {
SupplierCode string `json:"supplier_code"` SupplierCode string `xorm:"supplier_code"`
ChannelUid int `json:"channel_uid"` ChannelUid int `xorm:"channel_uid"`
} }
...@@ -45,3 +45,5 @@ type ZyhResponse struct { ...@@ -45,3 +45,5 @@ type ZyhResponse struct {
ErrorMsg string `json:"error_msg"` ErrorMsg string `json:"error_msg"`
Data interface{} `json:"data"` Data interface{} `json:"data"`
} }
...@@ -7,7 +7,10 @@ import ( ...@@ -7,7 +7,10 @@ import (
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"math/big" "math/big"
"math/rand" "math/rand"
"reflect"
"regexp" "regexp"
"search_server/middleware"
"search_server/pkg/config"
"search_server/pkg/vars" "search_server/pkg/vars"
"strconv" "strconv"
"strings" "strings"
...@@ -148,10 +151,152 @@ func Rand(min, max int) int { ...@@ -148,10 +151,152 @@ func Rand(min, max int) int {
return int(n.Int64()) + min return int(n.Int64()) + min
} }
func CopyMapString(distmap map[string]string) map[string]string{ func CopyMapString(distmap map[string]string) map[string]string {
tmpmap := make(map[string]string,0) tmpmap := make(map[string]string, 0)
for k, v := range distmap { for k, v := range distmap {
tmpmap[k] = v tmpmap[k] = v
} }
return tmpmap 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("AUTH.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{}
//將任意類型的切片轉為 []interface{}
func CreateAnyTypeSlice(slice interface{}) ([]interface{}, bool) {
val, ok := isSlice(slice)
if !ok {
return nil, false
}
sliceLen := val.Len()
out := make([]interface{}, sliceLen)
for i := 0; i < sliceLen; i++ {
out[i] = val.Index(i).Interface()
}
return out, true
}
// 判断是否为slcie数据
func isSlice(arg interface{}) (val reflect.Value, ok bool) {
val = reflect.ValueOf(arg)
if val.Kind() == reflect.Slice {
ok = true
}
return
}
package common package common
import (
"regexp"
"runtime"
"search_server/middleware"
"search_server/pkg/log_report"
"strconv"
)
type Response struct { type Response struct {
ErrCode int `json:"error_code"` ErrCode int `json:"error_code"`
ErrMsg string `json:"err_msg"` ErrMsg string `json:"err_msg"`
...@@ -29,3 +37,43 @@ func ErrorResponse(errCode int, errMsg string) Response { ...@@ -29,3 +37,43 @@ func ErrorResponse(errCode int, errMsg string) Response {
Data: []string{}, Data: []string{},
} }
} }
//统一输出,里面还要去处理jsonp
func Output(errCode int, errMsg string, data interface{}) {
if data == nil {
data = []string{}
}
response := Response{
ErrCode: errCode,
ErrMsg: errMsg,
Data: data,
}
ctx := middleware.Context
if ctx.DefaultQuery("callback", "") != "" {
ctx.JSONP(200, response)
} else {
referer := ctx.Request.Referer()
r, _ := regexp.Compile(`/^(\w+:\/\/)?([^\/]+)/i`)
var match string
matches := r.FindStringSubmatch(referer)
if len(matches) > 0 {
match = matches[0]
}
ctx.Header("Access-Control-Allow-Origin", match)
ctx.Header("Access-Control-Allow-Credentials", "true")
//允许跨站访问的站点域名
//跨域请求头设置
ctx.JSONP(200, response)
}
}
//错误的搜索日志记录
func SearchApiLog(code int, msg string) {
pc, file, line, _ := runtime.Caller(0)
f := runtime.FuncForPC(pc)
ctx := middleware.Context
errMsg := "提示信息:" + msg + ",请求url:" + ctx.Request.URL.String()
lineNo := strconv.Itoa(line)
log_report.AnalyzeSearchError(code, ctx.ClientIP(), errMsg, file, lineNo, f.Name())
}
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")
}
}
...@@ -13,20 +13,6 @@ type BaseDatabase struct { ...@@ -13,20 +13,6 @@ type BaseDatabase struct {
//多数据库配置 //多数据库配置
func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) { func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) {
return map[string]BaseDatabase{ return map[string]BaseDatabase{
"mysql": {
UserName: Get("mysql.user_name").String(),
Password: Get("mysql.password").String(),
Host: Get("mysql.host").String(),
Database: Get("mysql.database").String(),
Prefix: Get("mysql.prefix").String(),
},
"bom": {
UserName: Get("bom.user_name").String(),
Password: Get("bom.password").String(),
Host: Get("bom.host").String(),
Database: Get("bom.database").String(),
Prefix: Get("mysql.prefix").String(),
},
"spu": { "spu": {
UserName: Get("spu.user_name").String(), UserName: Get("spu.user_name").String(),
Password: Get("spu.password").String(), Password: Get("spu.password").String(),
...@@ -35,11 +21,18 @@ func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) { ...@@ -35,11 +21,18 @@ func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) {
Prefix: Get("spu.table_prefix").String(), Prefix: Get("spu.table_prefix").String(),
}, },
"supp": { "supp": {
UserName: Get("spu.user_name").String(), UserName: Get("supp.user_name").String(),
Password: Get("spu.password").String(), Password: Get("supp.password").String(),
Host: Get("spu.host").String(), Host: Get("supp.host").String(),
Database: Get("spu.database").String(), Database: Get("supp.database").String(),
Prefix: Get("spu.table_prefix").String(), Prefix: Get("supp.table_prefix").String(),
},
"cms": {
UserName: Get("cms.user_name").String(),
Password: Get("cms.password").String(),
Host: Get("cms.host").String(),
Database: Get("cms.database").String(),
Prefix: Get("cms.table_prefix").String(),
}, },
} }
} }
package log_report
import (
"encoding/json"
log "github.com/sirupsen/logrus"
"os"
)
type SearchApiLog struct {
Msg string
MsgCode int
Ts int64
DateStr string
App string
ServerIp string
FileName string
LineNo string
Method string
}
func AnalyzeSearchError(code int, ip, errMsg, file, line, method string) (log SearchApiLog) {
//log.Msg = "" + errMsg
//log.MsgCode = 1
//log.Ts = time.Now().Unix()
//log.DateStr = time.Now().Format("2006-01-02 15:04:05")
//log.App = "search_api"
//log.ServerIp = ip
//log.FileName = file
//log.LineNo = line
//log.Method = method
//
////还要判断是否要推送消息
//unitSupplierLogCode := config.Cfg.Section("UNIT_SUPPLIER_LOG_CODE").KeysHash()
//codeStr := strconv.Itoa(code)
//if unitSupplierLogCode[codeStr] == "" {
// if !strings.Contains(strings.ToUpper(errMsg), "SOAP-ERROR") {
// //推送到钉钉
// result, err := message.DingDingPush(errMsg)
// if err != nil || result.Errcode != 0 {
// //logger.Errorf("%s", err, result)
// }
// }
//} else {
// redisCon := gredis.Conn("search_w")
// defer redisCon.Close()
// key := config.Get("SEARCH_API_LOG.SEARCH_API_ERROR_PRE").String() + unitSupplierLogCode[codeStr]
// redisCon.Do("INCR", key)
//}
return
}
type LogFormatter struct{}
//格式详情
func (s *LogFormatter) Format(entry *log.Entry) ([]byte, error) {
msg := entry.Message
return []byte(msg), nil
}
//写入到特定的文件夹给ELK使用的日志
func WriteSearchErrorLog(searchLog SearchApiLog) {
logJson, _ := json.Marshal(searchLog)
// 设置日志格式为json格式
log.SetFormatter(new(LogFormatter))
//设置output,默认为stderr,可以为任何io.Writer,比如文件*os.File
file, _ := os.OpenFile("1.log", os.O_CREATE|os.O_WRONLY, 0666)
log.SetOutput(file)
log.Error(logJson)
}
func WriteSearchErrorLogTest(searchLog string) {
// 设置日志格式为json格式
log.SetFormatter(new(LogFormatter))
//设置output,默认为stderr,可以为任何io.Writer,比如文件*os.File
file, _ := os.OpenFile("1.log", os.O_CREATE|os.O_WRONLY, 0666)
log.SetOutput(file)
log.Error(searchLog)
}
...@@ -2,7 +2,6 @@ package message ...@@ -2,7 +2,6 @@ package message
import ( import (
"encoding/json" "encoding/json"
"fmt"
"github.com/imroc/req" "github.com/imroc/req"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"search_server/pkg/config" "search_server/pkg/config"
...@@ -32,7 +31,6 @@ func DingDingPush(content string) (result DingDingResponse, err error) { ...@@ -32,7 +31,6 @@ func DingDingPush(content string) (result DingDingResponse, err error) {
req.Debug = false req.Debug = false
dataStrByte, _ := json.Marshal(data) dataStrByte, _ := json.Marshal(data)
dataStr := string(dataStrByte) dataStr := string(dataStrByte)
fmt.Println(dataStr)
dataStr = strings.Replace(dataStr, "\\", "\\\\", -1) dataStr = strings.Replace(dataStr, "\\", "\\\\", -1)
params := req.BodyJSON(dataStr) params := req.BodyJSON(dataStr)
resp, err := req.Post(webhook, params, req.Header{ resp, err := req.Post(webhook, params, req.Header{
......
...@@ -44,4 +44,3 @@ func Setup() error { ...@@ -44,4 +44,3 @@ func Setup() error {
func Conn(conName string) *xorm.Engine { func Conn(conName string) *xorm.Engine {
return DatabaseConMap[conName] return DatabaseConMap[conName]
} }
...@@ -170,7 +170,7 @@ func getBomTermQuery(goodsName, brandName string, number int, isRawSearch bool) ...@@ -170,7 +170,7 @@ func getBomTermQuery(goodsName, brandName string, number int, isRawSearch bool)
if isRawSearch { if isRawSearch {
source.Size(100) source.Size(100)
} else { } else {
source.Size(1) source.Size(50)
} }
source.Sort("_score", false).Sort("sort", false).Sort("single_price", true) source.Sort("_score", false).Sort("sort", false).Sort("single_price", true)
queryRequest := elastic.NewSearchRequest().Source(source) queryRequest := elastic.NewSearchRequest().Source(source)
......
...@@ -85,6 +85,7 @@ func (gs *GetDataService) GetQuery(originKeyword, supplierName, brandId, goodsNa ...@@ -85,6 +85,7 @@ func (gs *GetDataService) GetQuery(originKeyword, supplierName, brandId, goodsNa
source.Sort("update_time", false) source.Sort("update_time", false)
source.Sort("stock", false) source.Sort("stock", false)
source.Sort("single_price", true) source.Sort("single_price", true)
source.FetchSourceContext(elastic.NewFetchSourceContext(true).Include("goods_id", "old_goods_id", "status"))
source.From(0) source.From(0)
source.Size(2) source.Size(2)
......
package service package service
import ( import (
"fmt"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/imroc/req" "github.com/imroc/req"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
...@@ -14,7 +13,7 @@ import ( ...@@ -14,7 +13,7 @@ import (
) )
//获取商品信息,需要传入userId用于判断是否登陆 //获取商品信息,需要传入userId用于判断是否登陆
func GetGoodsInfo(goodsIds []string) (goodsListMap map[string]model.ApiGoods, err error) { func GetGoodsInfo(goodsIds []string) (goodsList []model.ApiGoods, err error) {
var userIdStr string var userIdStr string
userIdStr, _ = middleware.Context.Cookie("Yo4teW_uid") userIdStr, _ = middleware.Context.Cookie("Yo4teW_uid")
userId, _ := strconv.Atoi(userIdStr) userId, _ := strconv.Atoi(userIdStr)
...@@ -25,7 +24,7 @@ func GetGoodsInfo(goodsIds []string) (goodsListMap map[string]model.ApiGoods, er ...@@ -25,7 +24,7 @@ func GetGoodsInfo(goodsIds []string) (goodsListMap map[string]model.ApiGoods, er
"power[newCustomer]": isNewCustomer, "power[newCustomer]": isNewCustomer,
"power[member]": isMember, "power[member]": isMember,
} }
_, goodsListMap, err = CurlGoodsInfo(goodsIdsStr, params) goodsList, _, err = CurlGoodsInfo(goodsIdsStr, params)
return return
} }
...@@ -64,15 +63,19 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG ...@@ -64,15 +63,19 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG
goods.GoodsName = data.Get("goods_name").String() goods.GoodsName = data.Get("goods_name").String()
goods.GoodsSn = data.Get("goods_sn").String() goods.GoodsSn = data.Get("goods_sn").String()
goods.GoodsType = int(data.Get("goods_type").Int()) goods.GoodsType = int(data.Get("goods_type").Int())
goods.GoodsStatus = int(data.Get("goods_status").Int())
goods.SupplierId = int(data.Get("supplier_id").Int()) goods.SupplierId = int(data.Get("supplier_id").Int())
goods.Mpq = int(data.Get("mpq").Int()) goods.Mpq = int(data.Get("mpq").Int())
goods.MpqStr = int(data.Get("mpq").Int())
goods.Moq = int(data.Get("moq").Int()) goods.Moq = int(data.Get("moq").Int())
goods.MoqStr = int(data.Get("moq").Int())
goods.Stock = int(data.Get("stock").Int()) goods.Stock = int(data.Get("stock").Int())
goods.StockStr = int(data.Get("stock").Int())
goods.HkDeliveryTime = data.Get("hk_delivery_time").String() goods.HkDeliveryTime = data.Get("hk_delivery_time").String()
goods.CnDeliveryTime = data.Get("cn_delivery_time").String() goods.CnDeliveryTime = data.Get("cn_delivery_time").String()
goods.BrandName = data.Get("brand_name").String() goods.BrandName = data.Get("brand_name").String()
goods.SupplierName = data.Get("supplier_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.ClassId1 = int(data.Get("class_id1").Int())
goods.ClassId2 = int(data.Get("class_id2").Int()) goods.ClassId2 = int(data.Get("class_id2").Int())
goods.Encoded = data.Get("encoded").String() goods.Encoded = data.Get("encoded").String()
...@@ -81,6 +84,7 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG ...@@ -81,6 +84,7 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG
goods.GoodsImages = data.Get("goods_images").String() goods.GoodsImages = data.Get("goods_images").String()
goods.GoodsBrief = data.Get("goods_brief").String() goods.GoodsBrief = data.Get("goods_brief").String()
goods.Mpl = int(data.Get("mpl").Int()) goods.Mpl = int(data.Get("mpl").Int())
goods.MplStr = int(data.Get("mpl").Int())
goods.Status = int(data.Get("status").Int()) goods.Status = int(data.Get("status").Int())
goods.IsBuy = int(data.Get("is_buy").Int()) goods.IsBuy = int(data.Get("is_buy").Int())
goods.Pdf = data.Get("pdf").String() goods.Pdf = data.Get("pdf").String()
...@@ -96,6 +100,7 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG ...@@ -96,6 +100,7 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG
goods.MpgUnitName = data.Get("mpg_unit_name").String() goods.MpgUnitName = data.Get("mpg_unit_name").String()
goods.ScmBrandName = data.Get("scm_brand_name").String() goods.ScmBrandName = data.Get("scm_brand_name").String()
goods.AllowCoupon = int(data.Get("allow_coupon").Int()) 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.ClassId1Name = data.Get("class_id1_name").String()
goods.CLassId2Name = data.Get("c_lass_id2_name").String() goods.CLassId2Name = data.Get("c_lass_id2_name").String()
goods.SpuId = data.Get("spu_id").String() goods.SpuId = data.Get("spu_id").String()
...@@ -108,6 +113,7 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG ...@@ -108,6 +113,7 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG
goods.SpuBrief = data.Get("spu_brief").String() goods.SpuBrief = data.Get("spu_brief").String()
goods.SpuDetail = data.Get("spu_detail").String() goods.SpuDetail = data.Get("spu_detail").String()
goods.ClassName3 = data.Get("class_name3").String() goods.ClassName3 = data.Get("class_name3").String()
goods.ClassName = data.Get("class_name").String()
goods.ErpTax = data.Get("erp_tax").Bool() goods.ErpTax = data.Get("erp_tax").Bool()
goods.SupplierId = int(data.Get("supplier_id").Int()) goods.SupplierId = int(data.Get("supplier_id").Int())
goods.GoodsType = int(data.Get("goods_type").Int()) goods.GoodsType = int(data.Get("goods_type").Int())
...@@ -117,6 +123,7 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG ...@@ -117,6 +123,7 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG
for _, price := range data.Get("ladder_price").Array() { for _, price := range data.Get("ladder_price").Array() {
ladder := model.LadderPrice{ ladder := model.LadderPrice{
Purchases: int(price.Get("purchases").Int()), Purchases: int(price.Get("purchases").Int()),
PurchasesStr: int(price.Get("purchases").Int()),
PriceUs: price.Get("price_us").Float(), PriceUs: price.Get("price_us").Float(),
PriceCn: price.Get("price_cn").Float(), PriceCn: price.Get("price_cn").Float(),
PriceAc: price.Get("price_ac").Float(), PriceAc: price.Get("price_ac").Float(),
...@@ -148,7 +155,7 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG ...@@ -148,7 +155,7 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG
//original_price //original_price
originalPrice := make([]model.OriginalPrice, 0) originalPrice := make([]model.OriginalPrice, 0)
for _, price := range data.Get("ladder_price").Array() { for _, price := range data.Get("original_price").Array() {
price := model.OriginalPrice{ price := model.OriginalPrice{
Purchases: int(price.Get("purchases").Int()), Purchases: int(price.Get("purchases").Int()),
PriceUs: price.Get("price_us").Float(), PriceUs: price.Get("price_us").Float(),
...@@ -161,13 +168,14 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG ...@@ -161,13 +168,14 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG
//supp_extend_fee //supp_extend_fee
goods.SuppExtendFee.Cn.Max = int(data.Get("supp_extend_fee.cn.max").Int()) 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.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.Max = int(data.Get("supp_extend_fee.hk.max").Int())
goods.SuppExtendFee.Hk.Price = data.Get("supp_extend_fee.cn.price").Float() goods.SuppExtendFee.Hk.Price = data.Get("supp_extend_fee.hk.price").Float()
//scm_brand //scm_brand
goods.ScmBrand.ErpBrandName = data.Get("scm_brand.erp_brand_name").String() goods.ScmBrand.ErpBrandName = data.Get("scm_brand.erp_brand_name").String()
goods.ScmBrand.ErpBrandId = data.Get("scm_brand.erp_brand_id").String() goods.ScmBrand.ErpBrandId = data.Get("scm_brand.erp_brand_id").String()
goods.ScmBrand.ScmBrandId = data.Get("scm_brand.scm_brand_id").String() goods.ScmBrand.ScmBrandId = data.Get("scm_brand.scm_brand_id").String()
goods.ActivityEndTime = data.Get("activity_end_time").Int()
goodsList = append(goodsList, goods) goodsList = append(goodsList, goods)
goodsListMap[goodsId] = goods goodsListMap[goodsId] = goods
...@@ -231,7 +239,6 @@ func GetGoodsIdsByEs(res string) (goodsIds []string) { ...@@ -231,7 +239,6 @@ func GetGoodsIdsByEs(res string) (goodsIds []string) {
for _, item := range gjArray { for _, item := range gjArray {
goodsIds = append(goodsIds, item.String()) goodsIds = append(goodsIds, item.String())
} }
fmt.Println(goodsIds)
return return
} }
...@@ -241,8 +248,5 @@ func GetGoodsIdsByEsMsearch(res string) (goodsIds []string) { ...@@ -241,8 +248,5 @@ func GetGoodsIdsByEsMsearch(res string) (goodsIds []string) {
for _, item := range gjArray { for _, item := range gjArray {
goodsIds = append(goodsIds, item.String()) goodsIds = append(goodsIds, item.String())
} }
fmt.Println(goodsIds)
return return
} }
package query package query
import ( import (
"fmt"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/uniplaces/carbon" "github.com/uniplaces/carbon"
...@@ -77,7 +76,6 @@ func GetGoodsBySupplierNameQuery(r requests.GetGoodsBySupplierRequest) (string, ...@@ -77,7 +76,6 @@ func GetGoodsBySupplierNameQuery(r requests.GetGoodsBySupplierRequest) (string,
query.MustNot(elastic.NewTermQuery("status", 10)) query.MustNot(elastic.NewTermQuery("status", 10))
if r.BrandId != "" { if r.BrandId != "" {
brandIdSlice := strings.Split(r.BrandId, ",") brandIdSlice := strings.Split(r.BrandId, ",")
//todo : 取整
query.MustNot(elastic.NewTermQuery("brand_id", brandIdSlice)) query.MustNot(elastic.NewTermQuery("brand_id", brandIdSlice))
} }
...@@ -332,6 +330,5 @@ func GetGoodsBySupplierIdQuery(r requests.GetGoodsBySupplierRequest) (string, er ...@@ -332,6 +330,5 @@ func GetGoodsBySupplierIdQuery(r requests.GetGoodsBySupplierRequest) (string, er
} }
source.Query(query) source.Query(query)
searchRequest := elastic.NewSearchRequest().Source(source).Preference("_primary_first") searchRequest := elastic.NewSearchRequest().Source(source).Preference("_primary_first")
fmt.Println(searchRequest.Body())
return searchRequest.Body() return searchRequest.Body()
} }
...@@ -26,7 +26,6 @@ func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest) ...@@ -26,7 +26,6 @@ func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest)
if err != nil { if err != nil {
return return
} }
queryString = ""
esResult, err := es.CurlES(supplierIndex, queryString) esResult, err := es.CurlES(supplierIndex, queryString)
if err != nil { if err != nil {
return return
...@@ -34,8 +33,12 @@ func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest) ...@@ -34,8 +33,12 @@ func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest)
goodsIds := GetGoodsIdsByEs(esResult) goodsIds := GetGoodsIdsByEs(esResult)
goodsList, err := GetGoodsInfo(goodsIds) goodsList, err := GetGoodsInfo(goodsIds)
dullData, err := transformer.DullDataInfo(r.Keyword, goodsList) dullData, err := transformer.DullDataInfo(r.Keyword, goodsList)
//整合供应商数据
result = GetReturnSupplierData(dullData) result = GetReturnSupplierData(dullData)
result["total"] = gjson.Get(esResult, "hits.total").Int() result["total"] = gjson.Get(esResult, "hits.total").Int()
if gjson.Get(esResult, "hits.total").Int() == 0 {
return nil, err
}
result["took"] = gjson.Get(esResult, "took").Int() result["took"] = gjson.Get(esResult, "took").Int()
return return
} }
...@@ -67,6 +70,7 @@ func (qs *QuoteService) GetData(keyword, supplier string) (res interface{}, err ...@@ -67,6 +70,7 @@ func (qs *QuoteService) GetData(keyword, supplier string) (res interface{}, err
} }
quoteTransformer := transformer.QuoteTransformer{} quoteTransformer := transformer.QuoteTransformer{}
res = quoteTransformer.TransformCollectData(keyword, supplier, collectData) res = quoteTransformer.TransformCollectData(keyword, supplier, collectData)
return return
} }
......
...@@ -2,7 +2,6 @@ package transformer ...@@ -2,7 +2,6 @@ package transformer
import ( import (
"encoding/json" "encoding/json"
"fmt"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"regexp" "regexp"
...@@ -12,16 +11,17 @@ import ( ...@@ -12,16 +11,17 @@ import (
"search_server/pkg/common" "search_server/pkg/common"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/gredis" "search_server/pkg/gredis"
"search_server/pkg/mq"
"strings" "strings"
"time" "time"
) )
//处理商品信息数据 //处理商品信息数据
func DullDataInfo(keyword string, goodsListMap map[string]model.ApiGoods) (result []model.DullGoodsData, err error) { func DullDataInfo(keyword string, goodsList []model.ApiGoods) (result []model.DullGoodsData, err error) {
//获取redis链接 //获取redis链接
redisCon := gredis.Conn("search_r") redisCon := gredis.Conn("search_r")
defer redisCon.Close() defer redisCon.Close()
for _, item := range goodsListMap { for _, item := range goodsList {
var goods model.DullGoodsData var goods model.DullGoodsData
goods.ApiGoods = item goods.ApiGoods = item
if goods.GoodsName == "" { if goods.GoodsName == "" {
...@@ -40,7 +40,18 @@ func DullDataInfo(keyword string, goodsListMap map[string]model.ApiGoods) (resul ...@@ -40,7 +40,18 @@ func DullDataInfo(keyword string, goodsListMap map[string]model.ApiGoods) (resul
goods = spliceUrlByEnvironment(goods) goods = spliceUrlByEnvironment(goods)
//获取汇率相关 //获取汇率相关
goods = getRatio(goods) goods = getRatio(goods)
//todo:提供给客服报价系统专用(因为只是给快手用的,所以抽离出这个方法) //提供给客服报价系统专用
if strings.Contains(middleware.Context.Request.URL.String(), "quote") {
for key, price := range goods.LadderPrice {
if price.PriceUs != 0 {
if goods.SupplierId == 6 {
goods.LadderPrice[key].PriceUs = goods.OriginalPrice[key].PriceUs * goods.PriceHkxs
} else {
goods.LadderPrice[key].PriceUs = goods.OriginalPrice[key].PriceUs * goods.Coefficient.ExtraRatio
}
}
}
}
//整理数据 //整理数据
goods = arrangeData(goods) goods = arrangeData(goods)
...@@ -50,7 +61,7 @@ func DullDataInfo(keyword string, goodsListMap map[string]model.ApiGoods) (resul ...@@ -50,7 +61,7 @@ func DullDataInfo(keyword string, goodsListMap map[string]model.ApiGoods) (resul
goods.LastSearchTime = common.GetLastSearchTime(goods.GoodsId) goods.LastSearchTime = common.GetLastSearchTime(goods.GoodsId)
//关税信息 //关税信息
goods.CustomsTax = common.GetCustomsTax(goods.GoodsName, goods.BrandName) goods.CustomsTax = common.GetCustomsTax(goods.GoodsName, goods.BrandName)
ShowSku(goods) go ShowSku(goods)
//价格等信息混淆 //价格等信息混淆
if keyword != "---" { if keyword != "---" {
goods, err = MetGoodsInfo(goods) goods, err = MetGoodsInfo(goods)
...@@ -71,7 +82,7 @@ func spliceUrlByEnvironment(goods model.DullGoodsData) model.DullGoodsData { ...@@ -71,7 +82,7 @@ func spliceUrlByEnvironment(goods model.DullGoodsData) model.DullGoodsData {
refererTemp := strings.Split(referer, ".com") refererTemp := strings.Split(referer, ".com")
if len(refererTemp) > 0 { if len(refererTemp) > 0 {
goods.BrandUrl = refererTemp[0] + ".com/v3/brand/list/" + common.ToString(goods.BrandId) + ".html" goods.BrandUrl = refererTemp[0] + ".com/v3/brand/list/" + common.ToString(goods.BrandId) + ".html"
goods.GoodsUrl = refererTemp[0] + ".com/goods_" + common.ToString(goods.GoodsId) + ".html" goods.GoodsUrl = refererTemp[0] + ".com/goods_" + goods.GoodsId + ".html"
} }
return goods return goods
} }
...@@ -358,7 +369,6 @@ func ShowSku(goods model.DullGoodsData) { ...@@ -358,7 +369,6 @@ func ShowSku(goods model.DullGoodsData) {
} }
} }
res, _ := json.Marshal(result) res, _ := json.Marshal(result)
fmt.Println(string(res)) mq.PushMsg("search_show_sku_list", string(res))
//mq.PushMsg("search_show_sku_list", string(res))
} }
} }
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/ichunt2019/logger" "github.com/ichunt2019/logger"
"github.com/prometheus/common/log"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
...@@ -13,6 +14,7 @@ import ( ...@@ -13,6 +14,7 @@ import (
"search_server/model" "search_server/model"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/es"
"search_server/pkg/gredis" "search_server/pkg/gredis"
"strconv" "strconv"
"strings" "strings"
...@@ -24,10 +26,7 @@ type ZyServiceImpl struct{} ...@@ -24,10 +26,7 @@ type ZyServiceImpl struct{}
/* /*
自营搜索 自营搜索
*/ */
func (this *ZyServiceImpl) Zyh(ctx *gin.Context, req map[string]string, rsp *model.ZyhResponse) (error) { func (this *ZyServiceImpl) Zyh(ctx *gin.Context, req map[string]string) (rsp *model.ZyhResponse,err error) {
////fmt.Printf("%+v",req)
//fmt.Println(req.NeedAggs)
//fmt.Println(5566)
var ( var (
need_aggs bool need_aggs bool
_type byte _type byte
...@@ -42,12 +41,12 @@ func (this *ZyServiceImpl) Zyh(ctx *gin.Context, req map[string]string, rsp *mod ...@@ -42,12 +41,12 @@ func (this *ZyServiceImpl) Zyh(ctx *gin.Context, req map[string]string, rsp *mod
if need_aggs { if need_aggs {
_type = 1 _type = 1
}else{ }else{
_type = 1 _type = 3
} }
//设置cookie //设置cookie
setCookie(ctx,req) setCookie(ctx,req)
rsp = zy(req ,_type,0) rsp = zy(req ,_type,0)
return nil return rsp,nil
} }
func NewZyServiceImpl() *ZyServiceImpl { func NewZyServiceImpl() *ZyServiceImpl {
...@@ -125,8 +124,9 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){ ...@@ -125,8 +124,9 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){
req2 := make(map[string]string,0) req2 := make(map[string]string,0)
req2 = common.CopyMapString(req) req2 = common.CopyMapString(req)
delete(req2,"class_id/condition") delete(req2,"class_id/condition")
searchZiYingGoods(req2,true,zhyClassList,classLight,_type) rsp =searchZiYingGoods(req2,true,zhyClassList,classLight,_type)
return nil //fmt.Printf("返回數據:%+v",rsp)
return rsp
} }
...@@ -138,12 +138,24 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){ ...@@ -138,12 +138,24 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){
* @param type $class_light 高亮分类 * @param type $class_light 高亮分类
* @param type $type 1:全部输出(属性统计+列表) 2:只输出属性统计 3:只输出列表 * @param type $type 1:全部输出(属性统计+列表) 2:只输出属性统计 3:只输出列表
*/ */
func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassList,classLight []*model.ZhyClassListModel,aType byte){ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassList,classLight []*model.ZhyClassListModel,aType byte) (rsp *model.ZyhResponse){
var ( var (
goods_name_arr []map[string]string goods_name_arr []map[string]string
keyword string keyword string
is_sample bool is_sample bool
redisConn redis.Conn
response map[string]interface{}
) )
defer func() {
redisConn.Close()
}()
rsp = &model.ZyhResponse{}
rsp.ErrorMsg = ""
rsp.ErrorCode = 0
response = make(map[string]interface{},0)
keyword = "" keyword = ""
goods_name_arr = make([]map[string]string,0) goods_name_arr = make([]map[string]string,0)
if req["goods_name/condition"] != "" { if req["goods_name/condition"] != "" {
...@@ -159,7 +171,10 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL ...@@ -159,7 +171,10 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
} }
goods_temp_status := 0 goods_temp_status := 0
source := elastic.NewSearchSource() source := elastic.NewSearchSource()
source.StoredFields("goods_id","goods_name","sample_max_number","sample_status","sample_class_id")
//source.fie("goods_id","goods_name","sample_max_number","sample_status","sample_class_id")
source.FetchSourceContext(elastic.NewFetchSourceContext(true).
Include("goods_id","goods_name","sample_max_number","sample_status","sample_class_id"))
query := elastic.NewBoolQuery() query := elastic.NewBoolQuery()
if(len(req) > 0){ if(len(req) > 0){
...@@ -251,9 +266,140 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL ...@@ -251,9 +266,140 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
from = 10000-length from = 10000-length
} }
source.From(int(from)).Size(int(length)) source.From(int(from)).Size(int(length))
excludeBrandIds := model.GetExcludeBrandIds(1)
if len(excludeBrandIds) > 0{
brandIdTermsQuery,ok := common.CreateAnyTypeSlice(excludeBrandIds)
if ok {
query.MustNot(elastic.NewTermsQuery("brand_id",brandIdTermsQuery...))
}
}
source.Query(query) source.Query(query)
res,_ := elastic.NewSearchRequest().Source(source).Body() queryJson,_ := elastic.NewSearchRequest().Source(source).Body()
fmt.Println(res) //fmt.Println(queryJson)
result, err := es.CurlES(config.Get("ZIYING_CONFIG.Index").String(), queryJson)
if err != nil {
log.Error(err)
}
//fmt.Println(result)
logger.Info(result)
//单独返回goods_id
if just_id,ok :=req["just_id"];ok && just_id == "2"{
hits2 := gjson.Get(result, "hits.hits.#._source").Array()
hitsTotal := gjson.Get(result, "hits.total").Int()
var flag int64
var goodsIdList []string
flag = 1
if hitsTotal >0 && len(hits2) > 0{
flag = 0
//fmt.Println(hits2)
for _,goods:=range hits2{
goodsId := gjson.Get(goods.String(), "goods_id").String()
goodsIdList = append(goodsIdList, goodsId)
}
}
rsp.ErrorCode=flag
rsp.ErrorMsg=""
rsp.Data = goodsIdList
return rsp
}
//处理聚合运算数据
res := make(map[string]map[string]map[string]interface{},0)
res["aggs"] = make(map[string]map[string]interface{},0)
aggregations := gjson.Get(result,"aggregations").Map()
redisConn = gredis.Conn("search_r")
if len(aggregations) > 0{
//brand_id class_id2 packing
for field,vbuckets :=range aggregations{
if field == "attrs"{
continue
}
buckets := gjson.Get(vbuckets.String(),"buckets").Array()
res["aggs"][field] = make(map[string]interface{},0)
aggsFieldList := make([]map[string]string,0)
for k,v := range buckets{
aggregationsKeyBuckets := v.Map()
id:=aggregationsKeyBuckets["key"].String()
aggregationsKeyBucketsStr := ""
switch field {
case "brand_id":
brand_j,err :=redis.String(redisConn.Do("Hget","Self_Brand",aggregationsKeyBuckets["key"]))
if err != nil{
aggregationsKeyBucketsStr = ""
}else{
aggregationsKeyBucketsStr = gjson.Get(brand_j,"brand_name").String()
}
case "class_id2":
arr_oj,err := redis.String(redisConn.Do("Hget","Self_SelfClassInfo",aggregationsKeyBuckets["key"]))
if err == nil{
aggregationsKeyBucketsStr = gjson.Get(arr_oj,"class_name").String()
}
case "packing":
Self_UnitAliasInfo,err :=redis.String(redisConn.Do("Hget","Self_UnitAlias",aggregationsKeyBuckets["key"]))
fmt.Println("packing",aggregationsKeyBuckets["key"],Self_UnitAliasInfo)
if err == nil{
aggregationsKeyBucketsStr = Self_UnitAliasInfo
}
}
if zy {
fieldMd5 := common.Md5(field)
aggsFieldList = append(aggsFieldList,map[string]string{
"name":aggregationsKeyBucketsStr,
"id":id,
"num":aggregationsKeyBuckets["doc_count"].String(),
})
res["aggs"][field]["list"] = aggsFieldList
res["aggs"][field]["name"] = fieldMd5[8:24]
}else{
res["aggs"][field][strconv.Itoa(k)] = map[string]string{
"name":aggregationsKeyBucketsStr,
"id":id,
"num":aggregationsKeyBuckets["doc_count"].String(),
}
}
}
}
//attrs
attrsAttrNameBuckets := gjson.Get(aggregations["attrs"].String(),"attr_name.buckets").Array()
if zy && len(attrsAttrNameBuckets) > 0{
//fmt.Println("attrsAttrNameBuckets",attrsAttrNameBuckets)
aggsFieldList := make([]map[string]string,0)
for _,vbuckets:=range attrsAttrNameBuckets{
vbucketsMap := vbuckets.Map()
attr_value_buckets := gjson.Get(vbuckets.String(),"attr_value.buckets")
for _,v := range attr_value_buckets.Map(){
fieldMd5 := common.Md5(vbucketsMap["key"].String())
aggsFieldList = append(aggsFieldList,map[string]string{
"name":v.Map()["key"].String(),
"id":v.Map()["key"].String(),
"num":v.Map()["doc_count"].String(),
})
res["aggs"][vbucketsMap["key"].String()]["list"] = aggsFieldList
res["aggs"][vbucketsMap["key"].String()]["name"] = fieldMd5[8:24]
}
}
}
response["aggs"] = res["aggs"]
}
flag := 1
flag = flag
//如果是类目点进来,则高亮类目
if zy {
response["class"] = classList
response["class_light"] = classLight
}
//todo 添加属性单独搜索
if aType == 2 {
rsp.Data = response
return rsp
}
rsp.Data = response
return rsp
} }
func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions []string,goods_temp_status *int,searchValue *string, func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions []string,goods_temp_status *int,searchValue *string,
...@@ -369,7 +515,11 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions ...@@ -369,7 +515,11 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
for k,v:=range term_v{ for k,v:=range term_v{
term_v[k] = reg.ReplaceAllString(v,"") term_v[k] = reg.ReplaceAllString(v,"")
} }
query.Must(elastic.NewTermsQuery("auto_brand_name2",term_v)) auto_brand_name2_terms,ok := common.CreateAnyTypeSlice(term_v)
if ok{
query.Must(elastic.NewTermsQuery("auto_brand_name2",auto_brand_name2_terms...))
}
} }
case "stock": case "stock":
if stockValue,err = strconv.ParseInt(*searchValue, 10, 64);err == nil{ if stockValue,err = strconv.ParseInt(*searchValue, 10, 64);err == nil{
...@@ -395,7 +545,7 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions ...@@ -395,7 +545,7 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
break break
} }
} }
query.Must(elastic.NewTermsQuery(searchKey,term_v_interface)) query.Must(elastic.NewTermsQuery(searchKey,term_v_interface...))
} }
case "order": case "order":
orderSort := false orderSort := false
...@@ -479,8 +629,11 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions ...@@ -479,8 +629,11 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
termsQuerySlice = append(termsQuerySlice,term_v1_int) termsQuerySlice = append(termsQuerySlice,term_v1_int)
} }
} }
supplierIdTerms ,ok:=common.CreateAnyTypeSlice(termsQuerySlice)
if ok{
query.Must(elastic.NewTermsQuery("supplier_id",supplierIdTerms...))
}
query.Must(elastic.NewTermsQuery("supplier_id",termsQuerySlice))
} }
} }
......
...@@ -3,9 +3,11 @@ package main ...@@ -3,9 +3,11 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
log "github.com/sirupsen/logrus"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"reflect" "reflect"
"search_server/boot" "search_server/boot"
"search_server/controller"
) )
func StrRandom(lenNum int) string { func StrRandom(lenNum int) string {
...@@ -22,6 +24,14 @@ func StrRandom(lenNum int) string { ...@@ -22,6 +24,14 @@ func StrRandom(lenNum int) string {
return result return result
} }
type LogFormatter struct{}
//格式详情
func (s *LogFormatter) Format(entry *log.Entry) ([]byte, error) {
msg := entry.Message + "\n"
return []byte(msg), nil
}
func main() { func main() {
var path string var path string
flag.StringVar(&path, "configPath", "conf", "配置文件") flag.StringVar(&path, "configPath", "conf", "配置文件")
...@@ -29,11 +39,18 @@ func main() { ...@@ -29,11 +39,18 @@ func main() {
if err := boot.Boot(path); err != nil { if err := boot.Boot(path); err != nil {
fmt.Println(err) fmt.Println(err)
} }
a := []int{1,2,3} //log.SetFormatter(new(LogFormatter))
fmt.Println(InterfaceSlice(a)) ////设置output,默认为stderr,可以为任何io.Writer,比如文件*os.File
} //str, _ := os.Getwd()
//file, _ := os.OpenFile(str+"/logs/search/1.log", os.O_CREATE|os.O_WRONLY, 0666)
//log.SetOutput(file)
//fmt.Println(str)
//log.Error("sadsadsadsa")
//log.Error("sadsadsadsa")
//log.Error("sadsadsadsa")
controller.GetData("LM358","arrow")
}
func InterfaceSlice(slice interface{}) []interface{} { func InterfaceSlice(slice interface{}) []interface{} {
s := reflect.ValueOf(slice) s := reflect.ValueOf(slice)
......
package main package main
import ( import (
"log" "fmt"
"time" "reflect"
) )
func main(){ // interface{}转为 []interface{}
bigSlowOperation() func CreateAnyTypeSlice(slice interface{}) ([]interface{}, bool) {
val, ok := isSlice(slice)
if !ok {
return nil, false
}
sliceLen := val.Len()
out := make([]interface{}, sliceLen)
for i := 0; i < sliceLen; i++ {
out[i] = val.Index(i).Interface()
}
return out, true
} }
func bigSlowOperation() { // 判断是否为slcie数据
defer trace("bigSlowOperation")() // don't forget the func isSlice(arg interface{}) (val reflect.Value, ok bool) {
// ...lots of work… val = reflect.ValueOf(arg)
time.Sleep(10 * time.Second) // simulate slow
if val.Kind() == reflect.Slice {
ok = true
}
return
} }
func trace(msg string) func() {
start := time.Now()
log.Printf("enter %s", msg) // 看需求写的代码
return func() { func faa(arg interface{}) {
log.Printf("exit %s (%s)", msg,time.Since(start)) slice, ok := CreateAnyTypeSlice(arg)
if !ok {
return
} }
for index,value := range slice {
fmt.Println(index,value)
}
}
func main() {
intSlice := []int{1,2,3,4,5,6,7,8}
strSlice := []string{"a","b","c","d"}
boolSlice := []bool{true,true,false,true}
faa(intSlice)
faa(strSlice)
faa(boolSlice)
} }
\ No newline at end of file
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