Commit b6e3891a by 孙龙

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

parents b570b378 129fe3d2
/go.sum
/.idea/
config.ini
database.ini
message.ini
rabmq_key.ini
redis_config.ini
redis_key.ini
search.ini
gowatch.yml
*.exe
*.exe~
......
[web]
port = 20001
port = 10001
mode = release
cors_domain = bom.ichunt.com
cors_domain = https://bom.ichunt.com
[message]
api_domain = http://api.ichunt.com/msg/sendMessageByAuto
......
[gorm]
mode = debug
[spu]
user_name = spu
password = spu
host = 192.168.1.234
database = liexin_spu
table_prefix =lie_
type = mysql
#线上地址
#SupDbUser:Supssy2@@!!@$#yxy@172.18.137.21:3306/liexin_supp
[supp]
user_name = liexin_ass
password = `liexin_ass#zsyM`
host = 192.168.2.232
database = liexin_ass
table_prefix =lie_
type = mysql
[cms]
user_name = ichuntcms
password = `ichuntcms#zsyM`
host = 192.168.2.232
database = ichuntcms
table_prefix =
type = mysql
[gorm]
mode = debug
#线上地址
#mysql://LxiCSpu:Mysx3Tyzlo00oxlmlly@172.18.137.29:3306
[spu]
user_name = LxiCSpu
password = Mysx3Tyzlo00oxlmlly
host = 172.18.137.29
database = liexin_spu
table_prefix =lie_
type = mysql
#线上地址
#SupDbUser:Supssy2@@!!@$#yxy@172.18.137.21:3306/liexin_supp
[supp]
user_name = SupDbUser
password = `Supssy2@@!!@$#yxy`
host = 172.18.137.21
database = liexin_supp
table_prefix =lie_
type = mysql
#线上地址
#mysql://dtuserread:dAtaL#ym2902m2lLX2y33@172.18.137.22:3306/icdata#utf8
[cms]
user_name = dtuserread
password = `dAtaL#ym2902m2lLX2y33`
host = 172.18.137.22
database = icdata
table_prefix =
type = mysql
[DINGDING]
SEARCH_API_MONITOR = 6d0fa85e01a02c39347d011ae973fd21b76c6c7ce582d3ea470c6b65a318848d
\ No newline at end of file
[DINGDING]
SEARCH_API_MONITOR = cd1661d0ce733a8ff0b603b532b317aae9de6dbaf39186b0352f272e47a860e8
\ No newline at end of file
[rabmq]
url = amqp://guest:guest@192.168.2.232:5672/
[rabmq]
url = amqp://huntweb:xMtMi29zTm@119.23.79.136:5672/
;存放本系统所有的队列名称
[rabmq_all]
; bom任务id
......
[default_redis_read]
host = 192.168.1.235:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
[default_redis_write]
host = 192.168.1.235:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
[api_redis]
host = 192.168.1.235:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
\ No newline at end of file
[default_redis_read]
host = 172.18.137.39:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
[default_redis_write]
host = 172.18.137.38:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
[api_redis_read]
host = 172.18.137.38:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
[api_redis_write]
host = 172.18.137.39:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
;存放本系统所有的redis键值对和解析
;存放本系统所有的redis键值对和解析
[redis_all]
;供应商redis的首key
SUPPLIER_REDIS_PRE=SUPPLIER_REDIS_INFO_
......
[SUPPLIER_ALL]
[SUPPLIER_ALL]
1 = future
2 = powerandsignal
3 = rochester
......@@ -13,56 +13,52 @@
12 = alliedelec
13 = avnet
14 = mouser
#16 = liexin_lianying1
15 = company
16 = liexin_lianying1
17 = zhuanmai
18 = liexin_ti
19 = peigenesis
20 = powell
21 = rs
1676 = buerklin
22 = liexin_sell
100 = ziying
101 = liexin_jingdiao
1672 = master
1673 = rutronik
1675 = corestaff
1676 = buerklin
1677 = microchip
1678 = heilind
1680 = wpg
1681 = jameco
1679 = ti
1684 = distrelec
1685 = tlc
1686 = adi
#搜索结果页合并供应商
[SEARCH_SUPPLIER_MERGE]
17 = zhuanmai
1 = future
3 = rochester
6 = element14
7 = digikey
8 = chip1stop
9 = aipco
12 = alliedelec
13 = avnet
19 = peigenesis
20 = powell
21 = rs
[SEARCH_SUPPLIER]
1 = future
#2 = powerandsignal
3 = rochester
4 = tme
5 = verical
6 = element14
7 = digikey
#7 = digikey
8 = chip1stop
9 = aipco
10 = arrow
#11 = bisco
12 = alliedelec
13 = avnet
14 = mouser
#15 = company
#16 = liexin_lianying1
17 = zhuanmai
#18 = liexin_ti
19 = peigenesis
20 = powell
21 = rs
#22 = liexin_sell
#100 = ziying
#101 = liexin_jingdiao
1676 = buerklin
1675 = corestaff
1677 = microchip
1678 = heilind
1680 = wpg
1681 = jameco
1679 = ti
1684 = distrelec
1685 = tlc
1686 = adi
#相似物料供应商
[ALIKE_SUPPLIER]
1 = ti
......
......@@ -37,9 +37,9 @@ func GetDataIndex(c *gin.Context) {
return
}
common.PrintDebugHeader(c,&r.Flag)
common.PrintDebugHtml(c,&r.Flag,r.SupplierId)
common.PrintDebugHtml(c,&r.Flag,r.Keyword)
common.PrintDebugHeader()
common.PrintDebugHtml(r.SupplierId)
common.PrintDebugHtml(r.Keyword)
if r.SupplierId != "" && r.IsSort == 2 {
//所有供应商列表
......@@ -96,7 +96,7 @@ func outLinkDiv(supplierId *string,supplierName *string,keyWord * string){
var apiData map[string]*model.LyClearGoodsList = nil
switch *supplierName {
case "mouser": //调外链拿数据mouser外链请求更新修改
apiData = ly.OutLinkMouser(keyWord,"1")
apiData = ly.OutLinkMouser(keyWord)
break;
}
......
......@@ -2,24 +2,18 @@ package controller
import (
"github.com/gin-gonic/gin"
"search_server/middleware"
"search_server/model"
"search_server/pkg/common"
"search_server/service/ly"
"strings"
)
//搜索型号
func GetMouserData(c *gin.Context) {
_REQUEST := make(map[string]string,0);
c.MultipartForm()
for requestName, requstValue := range c.Request.Form {
if requstValue[0] != "" {
_REQUEST[requestName] = strings.TrimSpace(requstValue[0])
}
}
goodsName := middleware.REQUEST["goods_name"]
goodsName := _REQUEST["goods_name"]
common.PrintDebugHeader() //debug
if goodsName == "" {
c.JSON(200,"goods_name不得为空")
......@@ -27,7 +21,7 @@ func GetMouserData(c *gin.Context) {
}
//调外链拿数据
apiData := ly.OutLinkMouser(&goodsName,"-1")
apiData := ly.OutLinkMouser(&goodsName)
//供应商详情
lycon := new(ly.CommonLyService)
......@@ -43,6 +37,6 @@ func GetMouserData(c *gin.Context) {
c.JSON(200, common.BomResponse{
ErrCode: errCode,
ErrMsg: "查询成功",
Data: apiData,
Data: "",
})
}
......@@ -65,7 +65,7 @@ func QuoteIndex(c *gin.Context) {
}
func mouserOrg(keyword, suppliedId string) (result map[string]interface{}, err error) {
mouserRes := ly.OutLinkMouser(&keyword, "1")
mouserRes := ly.OutLinkMouser(&keyword)
redisCon := gredis.Conn("search_r")
defer redisCon.Close()
skuMouser := make(map[string]string)
......
package controller
import (
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"search_server/pkg/common"
"search_server/pkg/gredis"
"search_server/requests"
"strings"
)
//封禁ip开关
func SetButton(c *gin.Context) {
var r requests.SetButtonRequest
c.ShouldBind(&r)
redisCon := gredis.Conn("search_w")
res, err := redis.Bool(redisCon.Do("SET", "spider_config_button", r.Val))
if err != nil {
common.Output(1, "操作redis失败", err.Error())
return
}
if res {
common.Output(0, "成功", res)
return
} else {
common.Output(1, "设置开关失败", res)
return
}
}
//获取白名单与黑名单信息
func GetWbList(c *gin.Context) {
var r requests.GetWbListRequest
c.ShouldBind(&r)
redisCon := gredis.Conn("search_w")
if r.ListType == 0 {
common.Output(1, "参数为空", nil)
return
}
keyName := "spider_black_list"
if r.ListType == 1 {
keyName = "spider_white_list"
}
res, err := redis.Strings(redisCon.Do("SMEMBERS", keyName))
if err != nil {
common.Output(1, "操作redis失败", err.Error())
return
}
list := make(map[string]interface{})
list["list"] = res
list["total"] = len(res)
common.Output(0, "成功", list)
return
}
//设置白名单与黑名单信息
func SetWbList(c *gin.Context) {
var r requests.SetWbListRequest
c.ShouldBind(&r)
if r.Type == "" || r.IpList == "" || r.AddOrRm == "" {
common.Output(1, "参数为空", nil)
}
redisCon := gredis.Conn("search_w")
keyName := "spider_black_list"
if r.Type == "1" {
keyName = "spider_white_list"
}
ipListSlice := strings.Split(r.IpList, ",")
if len(ipListSlice) > 0 {
for _, ip := range ipListSlice {
if r.AddOrRm == "1" {
redis.Bool(redisCon.Do("SADD", keyName, strings.TrimSpace(ip)))
} else {
redis.Bool(redisCon.Do("SREM", keyName, strings.TrimSpace(ip)))
}
}
}
common.Output(0, "成功!", nil)
}
//获取自我解禁ip访问频率自增数据
func GetIpalg() {
redisCon := gredis.Conn("search_r")
spiderAlgs, _ := redis.StringMap(redisCon.Do("HGETALL", "spider_connect_count_alg"))
spiderBans, _ := redis.Strings(redisCon.Do("SMEMBERS", "spider_ban"))
list := make(map[string]interface{})
if len(spiderAlgs) > 0 {
var dataList []map[string]string
for key, alg := range spiderAlgs {
data := make(map[string]string)
data["ip"] = key
data["num"] = alg
if !php2go.InArray(key, spiderBans) {
dataList = append(dataList, data)
}
}
list["list"] = dataList
list["total"] = len(dataList)
}
common.Output(0, "成功", list)
return
}
//设置自我解禁ip访问频率自增数据
func SetIpalg(c *gin.Context) {
var r requests.SetIpalgRequest
c.ShouldBind(&r)
if r.Ip == "" || r.ListType == 0 {
common.Output(1, "参数为空", nil)
return
}
redisCon := gredis.Conn("search_w")
ip := strings.TrimSpace(r.Ip)
if r.ListType == 1 {
_, err := redis.Bool(redisCon.Do("HSET", "spider_connect_count_alg", ip, r.Num))
if err != nil {
common.Output(1, "操作redis失败", err.Error())
}
} else {
_, err := redis.Bool(redisCon.Do("HDEL", "spider_connect_count_alg", ip))
if err != nil {
common.Output(1, "操作redis失败", err.Error())
}
}
common.Output(0, "成功", nil)
}
//设置参数配置信息
func SetConfig(c *gin.Context) {
request := common.GetAllRequestParams(c)
if request["server_id"] == "" {
//common.
}
}
......@@ -2,13 +2,22 @@ package middleware
import (
"github.com/gin-gonic/gin"
"strings"
)
var Context *gin.Context
var REQUEST map[string]string //等同于php 的$_REQUEST
//将gin的上下文放到全局变量
func ContextVars() gin.HandlerFunc {
return func(c *gin.Context) {
//接收所有的变量+值
REQUEST = make(map[string]string,0);
c.MultipartForm()
for requestName, requstValue := range c.Request.Form {
REQUEST[requestName] = strings.TrimSpace(requstValue[0])
}
//将gin的上下文放到全局变量
Context = c
c.Next()
......
......@@ -2,9 +2,9 @@ package model
//联营请求外链后格式化数据
type LyClearGoodsList struct {
SkuId string `json:"sku_id"` //平台型号id (非必填)
SpuId string `json:"spu_id"` //平台spuId (非必填)
BrandId string `json:"brand_id"` //平台品牌id (非必填)
SkuId string `json:"sku_id"` //平台型号id (非必填)
SpuId string `json:"spu_id"` //平台spuId (非必填)
BrandId string `json:"brand_id"` //平台品牌id (非必填)
GoodsName string `json:"goods_name"` //型号名称
BrandName string `json:"brand_name"` //品牌名称
Desc string `json:"desc"` //描述
......@@ -20,12 +20,12 @@ type LyClearGoodsList struct {
RestrictionMessage string `json:"RestrictionMessage"` //额外购买限制内容,如 ‘当前商品不在本地区销售’
Increment int64 `json:"increment"` //最小包装量、倍数 =Mpq
SinglePrice float64 `json:"single_price"` //最小单价
Stock int64 `json:"increment"` //库存
Stock int64 `json:"stock"` //库存
Moq int64 `json:"moq"` //最小起订量、起订量
RawGoodsId string `json:"raw_goods_id"` //外链原始goods_sn,如digikey:{'raw_goods_id': 'AT28C64X-25PC-ND', 'raw_brand_name': 'Microchip Technology'}
RawBrandName string `json:"raw_brand_name"` //外链原始品牌名称,如digikey:{'raw_goods_id': 'AT28C64X-25PC-ND', 'raw_brand_name': 'Microchip Technology'}
Tiered []*TierItem //价格梯度数量
PriceTemp []interface{} //拼接梯度,目前只有联营推送队列用
Tiered []*TierItem `json:"tiered"` //价格梯度数量
PriceTemp []interface{} `json:"price_temp"` //拼接梯度,目前只有联营推送队列用
}
type TierItem struct {
Purchases uint64 `json:"purchases"` //购买数量
......
package common
import (
"bytes"
"crypto/md5"
crand "crypto/rand"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/syyongx/php2go"
"math/big"
"math/rand"
......@@ -25,32 +23,28 @@ import (
/*
输出header
*/
func PrintDebugHeader(ctx *gin.Context,flag *string) {
if *flag == "101" {
ctx.Header("Content-Type", "text/html; charset=utf-8")
func PrintDebugHeader() {
if middleware.REQUEST["flag"] == "101" {
middleware.Context.Header("Content-Type", "text/html; charset=utf-8")
}
}
/*
格式化数据直接输出浏览器
@parm ctx gin上下文
@parm flag 是否调试标志
@parm data 打印调试内容
@parm jsondata 需要json输出的内容
@parm jsonStr 需要json输出的内容
*/
func PrintDebugHtml(ctx *gin.Context,flag *string,jsonStr interface{}) {
if *flag != "101" && jsonStr != "" {
func PrintDebugHtml(jsonStr interface{}) {
if middleware.REQUEST["flag"] != "101" || jsonStr == "" {
return
}
jsonData,err := json.Marshal(jsonStr)
if err != nil {
fmt.Println("错误:-----",err)
if v, p := jsonStr.(string); p {
middleware.Context.String(200,"</br></br>-----------"+v)
}else{
jsonData,err := json.Marshal(jsonStr)
if err != nil {
fmt.Println("错误:-----",err)
}
middleware.Context.String(200,"</br></br>-----------"+string(jsonData))
}
var str bytes.Buffer
_ = json.Indent(&str, []byte(string(jsonData)), "", " ")
fmt.Println("formated: ", str.String())
ctx.String(200,"</br>")
ctx.String(200,str.String())
}
// Md5 md5()
......@@ -378,4 +372,32 @@ func MapSort(mapList map[int]int) []int{
newList = append(newList,mapList[k])
}
return newList
}
\ No newline at end of file
}
////////////类型转换/////////////////////
func MyInt8(str string) int8 {
res,_ := strconv.ParseInt(str,10,64)
return int8(res)
}
func MyInt16(str string) int16 {
res,_ := strconv.ParseInt(str,10,64)
return int16(res)
}
func MyInt64(str string) int64 {
res,_ := strconv.ParseInt(str,10,64)
return int64(res)
}
func MyFloat32(str string) float32 {
res,_ := strconv.ParseFloat(str,64)
return float32(res)
}
func MyFloat64(str string) float64 {
res,_ := strconv.ParseFloat(str,64)
return float64(res)
}
func MyFloat64ToStr(numb float64) string {
return strconv.FormatFloat(numb,'f',6,64)
}
func MyInt64ToStr(numb int64) string {
return strconv.FormatInt(numb,10)
}
////////////类型转换/////////////////////
\ No newline at end of file
package common
import (
"github.com/gin-gonic/gin"
"strings"
)
type RecommendRequest struct {
GoodsName string `form:"goods_name"`
Attrs string `form:"attrs"`
......@@ -9,3 +14,15 @@ type RecommendRequest struct {
Flag int `form:"flag"`
BrandName string `form:"brand_name"`
}
//获取所有请求参数放到字典里面
func GetAllRequestParams(c *gin.Context) (request map[string]string){
request = make(map[string]string)
c.MultipartForm()
for name, value := range c.Request.Form {
if value[0] != "" {
request[name] = strings.TrimSpace(value[0])
}
}
return
}
package requests
type SetButtonRequest struct {
Val int `form:"val"`
}
type GetWbListRequest struct {
ListType int `form:"type"`
}
type SetWbListRequest struct {
Type string `form:"type"`
IpList string `form:"ip_list"`
AddOrRm string `form:"add_or_rm"`
}
type SetIpalgRequest struct {
Ip string `form:"ip"`
ListType int `form:"type"`
Num int `json:"num"`
}
\ No newline at end of file
......@@ -15,14 +15,16 @@ func InitRouter() *gin.Engine {
r.Use(middleware.Cors())
r.Use(middleware.ContextVars())
//路由
r.POST("/search/bom/autospu", controller.AutoSpu)
r.POST("/search/bom/recommend", controller.Recommend)
r.POST("search/ZiYing/zyh", controller.Zyh)
r.GET("search/ZiYing/zyh", controller.Zyh)
r.GET("search/ZiYing/index", controller.Index)
r.POST("search/ZiYing/index", controller.Index)
r.POST("search/mouser/GetMouserData", controller.GetMouserData)
r.GET("search/mouser/GetMouserData", controller.GetMouserData)
r.POST("search/mouser/a", controller.GetMouserData)
r.GET("search/mouser/a", controller.GetMouserData)
//bom相关
r.POST("/search/bom/autospu", controller.AutoSpu)
r.POST("/search/bom/recommend", controller.Recommend)
//快手平台相关
r.GET("/search/quote", controller.QuoteIndex)
......
#!/bin/bash
cd /data2/gocode/search_server
git pull origin master
git pull origin dev
cp /data2/gocode/search_server/config_prod.ini.demo /data2/gocode/search_server/config.ini
cp /data2/gocode/search_server/database_prod.ini.demo /data2/gocode/search_server/database.ini
cp /data2/gocode/search_server/message_prod.ini.demo /data2/gocode/search_server/message.ini
cp /data2/gocode/search_server/rabmq_key_prod.ini.demo /data2/gocode/search_server/rabmq_key.ini
cp /data2/gocode/search_server/redis_config_prod.ini.demo /data2/gocode/search_server/redis_config.ini
cp /data2/gocode/search_server/redis_key_prod.ini.demo /data2/gocode/search_server/redis_key.ini
cp /data2/gocode/search_server/search_prod.ini.demo /data2/gocode/search_server/search.ini
go build -o ./cmd/search_http_server ./cmd/search_http_server.go
supervisorctl restart search_server
......@@ -310,8 +310,7 @@ func ShowSku(goods model.DullGoodsData) {
return
}
referer := middleware.Context.Request.Header.Get("referer")
//if strings.Contains(referer, "www.ichunt.com/s/?k") {
if strings.Contains(referer, "") {
if strings.Contains(referer, "www.ichunt.com/s/?k") {
if goods.ProviderName != "" {
goods.BrandName = goods.ProviderName
}
......
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