Commit 9d46f31c by huangchengyi

1.0

parent 1fa6d352
Showing with 725 additions and 1071 deletions
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/micro/go-micro/v2/web" "github.com/micro/go-micro/v2/web"
"search_server/boot" "search_server/boot"
//_ "search_server/controller"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/routes" "search_server/routes"
) )
......
2020-10-15 11:23:24.344 INFO (ziyin_service.go:service.searchZiYingGoods:336) es搜索查詢條件 {"_source":{"includes":["goods_id","goods_name","sample_max_number","sample_status","sample_class_id"]},"aggregations":{"brand_id":{"terms":{"field":"brand_id","size":1000}},"class_id2":{"terms":{"field":"class_id2","size":1000}},"encap":{"terms":{"field":"encap","size":1000}},"packing":{"terms":{"field":"packing","size":1000}}},"from":0,"query":{"bool":{"must":[{"terms":{"class_id2":[1]}},{"range":{"dc_time":{"from":1578363419,"include_lower":true,"include_upper":true,"to":1578363420}}},{"term":{"goods_status":1}}]}},"size":10,"sort":[{"sort":{"order":"desc"}}]}
2020-10-15 11:23:24.532 INFO (ziyin_service.go:service.searchZiYingGoods:342) 查詢結果:{"took":169,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]},"aggregations":{"class_id2":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[]},"encap":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[]},"packing":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[]},"brand_id":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[]}}}
2020-10-15 11:23:28.008 INFO (ziyin_service.go:service.searchZiYingGoods:336) es搜索查詢條件 {"_source":{"includes":["goods_id","goods_name","sample_max_number","sample_status","sample_class_id"]},"aggregations":{"brand_id":{"terms":{"field":"brand_id","size":1000}},"class_id2":{"terms":{"field":"class_id2","size":1000}},"encap":{"terms":{"field":"encap","size":1000}},"packing":{"terms":{"field":"packing","size":1000}}},"from":0,"query":{"bool":{"must":[{"range":{"dc_time":{"from":1578363419,"include_lower":true,"include_upper":true,"to":1578363420}}},{"terms":{"class_id2":[1]}},{"term":{"goods_status":1}}]}},"size":10,"sort":[{"sort":{"order":"desc"}}]}
2020-10-15 11:23:28.071 INFO (ziyin_service.go:service.searchZiYingGoods:342) 查詢結果:{"took":34,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]},"aggregations":{"class_id2":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[]},"encap":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[]},"packing":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[]},"brand_id":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[]}}}
2020-10-15 11:23:28.78 INFO (ziyin_service.go:service.searchZiYingGoods:336) es搜索查詢條件 {"_source":{"includes":["goods_id","goods_name","sample_max_number","sample_status","sample_class_id"]},"aggregations":{"brand_id":{"terms":{"field":"brand_id","size":1000}},"class_id2":{"terms":{"field":"class_id2","size":1000}},"encap":{"terms":{"field":"encap","size":1000}},"packing":{"terms":{"field":"packing","size":1000}}},"from":0,"query":{"bool":{"must":[{"range":{"dc_time":{"from":1578363419,"include_lower":true,"include_upper":true,"to":1578363420}}},{"terms":{"class_id2":[1]}},{"term":{"goods_status":1}}]}},"size":10,"sort":[{"sort":{"order":"desc"}}]}
2020-10-15 11:23:28.786 INFO (ziyin_service.go:service.searchZiYingGoods:342) 查詢結果:{"took":4,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]},"aggregations":{"class_id2":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[]},"encap":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[]},"packing":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[]},"brand_id":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[]}}}
package main ackage main
import ( import (
"context" "context"
......
[web] [web]
port = 9000 port = 9000
mode = debug mode = debug
cors_domain = http://bom.liexin.com cors_domain = http://bom.liexin.com
domain = liexin.com
[message]
api_domain = http://api.ichunt.com/msg/sendMessageByAuto
[message] api_md5_str = fh6y5t4rr351d2c3bryi
api_domain = http://api.ichunt.com/msg/sendMessageByAuto
api_md5_str = fh6y5t4rr351d2c3bryi [goods]
api_url = http://192.168.2.232:60004
[goods] sz_api_url = http://192.168.2.232:60004
api_url = http://192.168.2.232:60004
sz_api_url = http://192.168.2.232:60004 [DINGDING]
SEARCH_API_MONITOR = 6d0fa85e01a02c39347d011ae973fd21b76c6c7ce582d3ea470c6b65a318848d
[es]
url = http://192.168.2.232:9200
urls = http://192.168.2.232:9200,http://192.168.2.232:9200 [database]
index_name = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,zhuanmai,peigenesis,powell,rs,buerklin,liexin_ziying user_name = root
search_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin,zhuanmai password = root
hk_delivery_type_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin host = 192.168.2.239
attr_index = goods_map database = test
table_prefix =
type = mysql
[redis]
write_host = 192.168.1.235:6379
read_host = 192.168.1.235:6379 [mongo]
write_password = icDb29mLy2s host = 192.168.1.237:27017
read_password = icDb29mLy2s username = "ichunt"
max_idle = 10 password = "huntmon6699"
max_active = 10 database = ichunt
idle_timeout = 20 maxPoolSize="100"
[mongo] [ZIYING_CACHE]
host = 192.168.1.237:27017 is_no_ziying_cache=true
username = "ichunt"
password = "huntmon6699" #是否是测试环境
database = ichunt [IS_SZ]
maxPoolSize=100 is_sz = true
[ZIYING_CACHE] #自营mongodb缓存表 正式线ziying_class_aggs
is_no_ziying_cache=true [AGG_TABLE]
agg_table = sz_ziying_class_aggs
#是否是测试环境
[IS_SZ]
is_sz = true #自营mongodb缓存表 正式线 ziying_first_lists
[FIRSTLISTS_TABLE]
#自营mongodb缓存表 正式线ziying_class_aggs firstLists_table = sz_ziying_first_lists
[AGG_TABLE] \ No newline at end of file
agg_table = ziying_class_aggs
#自营mongodb缓存表 正式线 ziying_first_lists
[FIRSTLISTS_TABLE]
firstLists_table = ziying_first_lists
\ No newline at end of file
[gorm] [gorm]
mode = debug mode = debug
[spu] [spu]
user_name = spu user_name = spu
password = spu password = spu
host = 192.168.1.234 host = 192.168.1.234
database = liexin_spu database = liexin_spu
table_prefix =lie_ table_prefix =lie_
type = mysql type = mysql
#线上地址 [supp]
#SupDbUser:Supssy2@@!!@$#yxy@172.18.137.21:3306/liexin_supp user_name = liexin_ass
[supp] password = `liexin_ass#zsyM`
user_name = liexin_ass host = 192.168.2.232
password = `liexin_ass#zsyM` database = liexin_ass
host = 192.168.2.232 table_prefix =lie_
database = liexin_ass type = mysql
table_prefix =lie_
type = mysql [cms]
user_name = ichuntcms
[cms] password = `ichuntcms#zsyM`
user_name = ichuntcms host = 192.168.2.232
password = `ichuntcms#zsyM` database = ichuntcms
host = 192.168.2.232 table_prefix =
database = ichuntcms type = mysql
table_prefix =
type = mysql
;存放es配置
[es]
url = http://192.168.2.232:9200
urls = http://192.168.2.232:9200,http://192.168.2.232:9200
index_name = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,zhuanmai,peigenesis,powell,rs,buerklin,liexin_ziying
search_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin,zhuanmai
hk_delivery_type_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin
attr_index = goods_map
\ No newline at end of file
;存放mongodb连接信息
[mongo]
host = 192.168.1.237:27017
username = "ichunt"
password = "huntmon6699"
database = ichunt
maxPoolSize=100
\ No newline at end of file
[rabmq] ;存放本系统所有rabmq配置
url = amqp://guest:guest@192.168.2.232:5672/ [rabmq]
;存放本系统所有的队列名称 url = amqp://guest:guest@192.168.2.232:5672/
[rabmq_all]
; bom任务id ;存放本系统所有的队列名称
MQ_BOM_ITEMS_LIST=bom_items_list [rabmq_all]
; bom更新数据队列 ; bom任务id
MQ_BOM_SKU_LIST=bom_sku_list MQ_BOM_ITEMS_LIST=bom_items_list
;联营数据更新-推送入队列-》go后台任务消费(斌哥脚本) ; bom更新数据队列
SEARCH_SKU_UPDATE_LIST=search_sku_update_list MQ_BOM_SKU_LIST=bom_sku_list
;联营数据新增-推送入队列-》go后台任务消费(斌哥脚本) ;联营数据更新-推送入队列-》go后台任务消费(斌哥脚本)
SEARCH_SKU_LIST=search_sku_list SEARCH_SKU_UPDATE_LIST=search_sku_update_list
; bom任务id ;联营数据新增-推送入队列-》go后台任务消费(斌哥脚本)
ZIYING_MQ_BOM_ITEMS_LIST=ziying_bom_items_list SEARCH_SKU_LIST=search_sku_list
; bom更新数据队列 ; bom任务id
ZIYING_MQ_BOM_ITEMS_LIST=ziying_bom_items_list
; bom更新数据队列
ZIYING_MQ_BOM_SKU_LIST=ziying_bom_sku_list ZIYING_MQ_BOM_SKU_LIST=ziying_bom_sku_list
\ No newline at end of file
;存放本系统所有的redis键值对和解析 ;redis连接信息
[redis_all] [default_redis_read]
;供应商redis的首key host = 192.168.1.235:6379
SUPPLIER_REDIS_PRE=SUPPLIER_REDIS_INFO_ password = icDb29mLy2s
;需要展示的供应商列表 max_idle = 500
SUPPLIER_REDIS_LIST_PRE=SUPPLIER_REDIS_LIST_INFO_ max_active = 500
;新增sku时判读sku是否存在 idle_timeout = 20
SKU_UNIQUE_JUDGE=sku_unique_judge
;新增sku时判读sku是否存在 [default_redis_write]
SPU_UNIQUE_JUDGE=sku_unique_judge host = 192.168.1.235:6379
;品牌信息判断,根据md5后的品牌名称获取id password = icDb29mLy2s
BRAND_NAME_ALL=brand_name_all max_idle = 500
;品牌id,获取品牌名称 max_active = 500
BRAND=brand idle_timeout = 20
;供应商品牌信息判断,存在多对一的情况,根据md5后的品牌名称获取标准品牌id
SUPPLIER_BRAND_ALL=supplier_brand_all [api_redis]
;统计调用外联接口的次数的key的前缀 后面接mouser、verical、arrow、master host = 192.168.1.235:6379
SEARCH_API_TOTAL_PRE=search_api_total_ password = icDb29mLy2s
;统计调用外联接口失败的次数的key的前缀 后面接mouser、verical、arrow、master max_idle = 50
SEARCH_API_ERORR_PRE=search_api_overtime_ max_active = 100
;曝光时间记录哈希集合 idle_timeout = 20
SEARCH_SHOW_SKU_TIME=search_show_sku_time
;获取关税信息,根据goods_name,brand_name获取 ;存放本系统所有的redis键值对和解析
TAX_CUSTOMS_INFO=tax_customs_info [redis_all]
;存放联营外链原始映射 ;供应商redis的首key
SKU_RAW_MAP=sku_raw_map SUPPLIER_REDIS_PRE=SUPPLIER_REDIS_INFO_
;需要展示的供应商列表
[redis_ziyin] SUPPLIER_REDIS_LIST_PRE=SUPPLIER_REDIS_LIST_INFO_
AGG_TABLE=sz_ziying_class_aggs ;新增sku时判读sku是否存在
FIRST_LISTS_TABLE=ziying_first_lists SKU_UNIQUE_JUDGE=sku_unique_judge
ZIYING_CLASS_KEY=ziying_class_string ;新增sku时判读sku是否存在
TAX_CUSTOMS_INFO=tax_customs_info SPU_UNIQUE_JUDGE=spu_unique_judge
;存放联营所有sku ;品牌信息判断,根据md5后的品牌名称获取id
SKU=sku BRAND_NAME_ALL=brand_name_all
;存放联营所有spu ;所有联营sku缓存
SPU=SPU SKU=sku
;存放digikey 型号映射 ;所有联营spu缓存
SKU_RAW_MAP=sku_raw_map SPU=spu
POOL_ALIKE_GOODS=pool_alike_goods ;品牌id,获取品牌名称
BRAND=brand
;供应商品牌信息判断,存在多对一的情况,根据md5后的品牌名称获取标准品牌id
SUPPLIER_BRAND_ALL=supplier_brand_all
;统计调用外联接口的次数的key的前缀 后面接mouser、verical、arrow、master
SEARCH_API_TOTAL_PRE=search_api_total_
;统计调用外联接口失败的次数的key的前缀 后面接mouser、verical、arrow、master
SEARCH_API_ERORR_PRE=search_api_overtime_
;曝光时间记录哈希集合
SEARCH_SHOW_SKU_TIME=search_show_sku_time
;获取关税信息,根据goods_name,brand_name获取
TAX_CUSTOMS_INFO=tax_customs_info
;存放联营外链原始映射
SKU_RAW_MAP=sku_raw_map
;digikey秘钥
digikey_access_token=digikey_access_token
;查属性id获取属性名称 ,表 lie_class_attr eg: hget("class_attr_by_id",101) = "容差"
class_attr_by_id = class_attr_by_id
;查属名称性获取属性id ,对应表 lie_class_attr eg: hget("class_attr_by_val", "容差") = 101
class_attr_by_val=class_attr_by_val
;查 参数值id 获取 参数值,表lie_class_attr_value eg: hget("class_attr_value_by_id",65) = "1.8W"
class_attr_value_by_id=class_attr_value_by_id
;查 参数值 获取 参数id,表lie_class_attr_value eg: hget("class_attr_value_by_val", "1.8W") = 65
class_attr_value_by_val=class_attr_value_by_val
[redis_ziyin]
AGG_TABLE=sz_ziying_class_aggs
FIRST_LISTS_TABLE=ziying_first_lists
ZIYING_CLASS_KEY=ziying_class_string
TAX_CUSTOMS_INFO=tax_customs_info
;存放联营所有sku
SKU=sku
;存放联营所有spu
SPU=SPU
;存放digikey 型号映射
SKU_RAW_MAP=sku_raw_map
POOL_ALIKE_GOODS=pool_alike_goods
[SUPPLIER_ALL] ;存放搜索相关配置
1 = future [SUPPLIER_ALL]
2 = powerandsignal 1 = future
3 = rochester 2 = powerandsignal
4 = tme 3 = rochester
5 = verical 4 = tme
6 = element14 5 = verical
7 = digikey 6 = element14
8 = chip1stop 7 = digikey
9 = aipco 8 = chip1stop
10 = arrow 9 = aipco
11 = bisco 10 = arrow
12 = alliedelec 11 = bisco
13 = avnet 12 = alliedelec
14 = mouser 13 = avnet
#16 = liexin_lianying1 14 = mouser
17 = zhuanmai #16 = liexin_lianying1
18 = liexin_ti 17 = zhuanmai
19 = peigenesis 18 = liexin_ti
20 = powell 19 = peigenesis
21 = rs 20 = powell
1676 = buerklin 21 = rs
1676 = buerklin
[SEARCH_SUPPLIER_MERGE]
17 = zhuanmai [SEARCH_SUPPLIER_MERGE]
1 = future 17 = zhuanmai
3 = rochester 1 = future
6 = element14 3 = rochester
7 = digikey 6 = element14
8 = chip1stop 7 = digikey
9 = aipco 8 = chip1stop
12 = alliedelec 9 = aipco
13 = avnet 12 = alliedelec
19 = peigenesis 13 = avnet
20 = powell 19 = peigenesis
21 = rs 20 = powell
21 = rs
[SEARCH_SUPPLIER]
1 = future [SEARCH_SUPPLIER]
#2 = powerandsignal 1 = future
3 = rochester #2 = powerandsignal
4 = tme 3 = rochester
5 = verical 4 = tme
6 = element14 5 = verical
7 = digikey 6 = element14
8 = chip1stop 7 = digikey
9 = aipco 8 = chip1stop
10 = arrow 9 = aipco
#11 = bisco 10 = arrow
12 = alliedelec #11 = bisco
13 = avnet 12 = alliedelec
14 = mouser 13 = avnet
#15 = company 14 = mouser
#16 = liexin_lianying1 #15 = company
17 = zhuanmai #16 = liexin_lianying1
#18 = liexin_ti 17 = zhuanmai
19 = peigenesis #18 = liexin_ti
20 = powell 19 = peigenesis
21 = rs 20 = powell
#22 = liexin_sell 21 = rs
#22 = liexin_sell
#100 = ziying
#101 = liexin_jingdiao #100 = ziying
1676 = buerklin #101 = liexin_jingdiao
1676 = buerklin
#相似物料供应商
[ALIKE_SUPPLIER] #相似物料供应商
1 = ti [ALIKE_SUPPLIER]
1 = ti
[common]
MOUSER_API = 'http://footstone.liexin.net/webapi/handle_mouser' [common]
MOUSER_API = 'http://footstone.liexin.net/webapi/handle_mouser'
[BRAND]
IS_NOT_TI = 0 [BRAND]
TI_LY_BRAND_IDS = 23,45069,7754,17484,43215,13421,5220,7636,44534,43556,44543,9429,758,9470,10430,10653,10707,11227,11276,11819,12608,12965,12997,13327,13675,13680,13752 IS_NOT_TI = 0
TI_ZY_BRAND_IDS = 23 TI_LY_BRAND_IDS = 23,45069,7754,17484,43215,13421,5220,7636,44534,43556,44543,9429,758,9470,10430,10653,10707,11227,11276,11819,12608,12965,12997,13327,13675,13680,13752
TI_ZY_BRAND_IDS = 23
[supplier]
# 供应商redis的首key [supplier]
SUPPLIER_REDIS_PRE = SUPPLIER_REDIS_INFO_ # 供应商redis的首key
SUPPLIER_REDIS_PRE = SUPPLIER_REDIS_INFO_
[ZIYING_BRAND_REPLACE]
FH = FH(风华) [ZIYING_BRAND_REPLACE]
BL = BL(上海贝岭) FH = FH(风华)
TE = TE(泰科) BL = BL(上海贝岭)
FM = FM(富满) TE = TE(泰科)
CJ = CJ(长电) FM = FM(富满)
ST = ST(意法) CJ = CJ(长电)
SK = SK(时科) ST = ST(意法)
ON = ON(安森美) SK = SK(时科)
TM = TM(天微) ON = ON(安森美)
TP = TP(拓微) TM = TM(天微)
TI = TI(德州仪器) TP = TP(拓微)
MD = MD(明达) TI = TI(德州仪器)
EG = EG(屹晶微) MD = MD(明达)
HF = HF(宏发) EG = EG(屹晶微)
DY = DY(迪一) HF = HF(宏发)
MK = MK(米客方德) DY = DY(迪一)
国民 = Nationz(国民技术) MK = MK(米客方德)
中芯 = SMIC(中芯国际) 国民 = Nationz(国民技术)
富士 = Fuji Electric(富士电机) 中芯 = SMIC(中芯国际)
国星 = Nationstar(国星光电) 富士 = Fuji Electric(富士电机)
贝岭 = BL(上海贝岭) 国星 = Nationstar(国星光电)
贝岭 = BL(上海贝岭)
[ZIYING_CONFIG]
Index = liexin_ziying [ZIYING_CONFIG]
Index = liexin_ziying
[SEARCH_KEYWORD_MAPPING]
`^(.* )?([\d\.]+)(欧|欧姆|R|r)( .*)?$` = ${1}${2}Ω${4} [SEARCH_KEYWORD_MAPPING]
`^(.* )?([\d\.]+)(U|u|μ)(.?)( .*)?$` = ${1}${2}Μ${4}${5} `^(.* )?([\d\.]+)(欧|欧姆|R|r)( .*)?$` = ${1}${2}Ω${4}
`COG` = C0G `^(.* )?([\d\.]+)(U|u|μ)(.?)( .*)?$` = ${1}${2}Μ${4}${5}
`NPO` = NP0 `COG` = C0G
`华科|华新科技|华新科` = 华新 `NPO` = NP0
`华科|华新科技|华新科` = 华新
[mathExactGoodsName]
0=M7 [mathExactGoodsName]
1=M1 0=M7
2=M4 1=M1
3=M2 2=M4
4=A7 3=M2
5=F7 4=A7
6=X2 5=F7
7=G4 6=X2
8=X4 7=G4
9=m7 8=X4
10=m1 9=m7
11=m4 10=m1
12=m2 11=m4
13=a7 12=m2
14=f7 13=a7
15=x2 14=f7
16=g4 15=x2
17=x4 16=g4
17=x4
;自营以某些单位进行搜索时,进行特殊处理
[ZIYING_MEASURE] ;自营以某些单位进行搜索时,进行特殊处理
0=kΩ [ZIYING_MEASURE]
1=uf 0=
2=v 1=uf
3=kg 2=v
4=MHz 3=kg
5=pf 4=MHz
6=pin 5=pf
7=ppm 6=pin
8=kw 7=ppm
8=kw
[OFFICIAL_WEBSITE]
1 = https://www.futureelectronics.cn/search/?text=liexin [OFFICIAL_WEBSITE]
2 = http://www.powerandsignal.com/Products/Search?searchBox=liexin 1 = https://www.futureelectronics.cn/search/?text=liexin
3 = https://www.rocelec.com/search?q=liexin 2 = http://www.powerandsignal.com/Products/Search?searchBox=liexin
4 = https://www.tme.eu/zh/katalog/#search=liexin 3 = https://www.rocelec.com/search?q=liexin
5 = https://www.verical.com/s/liexin/ 4 = https://www.tme.eu/zh/katalog/#search=liexin
6 = https://cn.element14.com/search?st=liexin 5 = https://www.verical.com/s/liexin/
7 = https://www.digikey.com/products/en?keywords=liexin 6 = https://cn.element14.com/search?st=liexin
8 = https://www.chip1stop.com/CHN/zh/view/searchResult/SearchResultTop?keyword=liexin 7 = https://www.digikey.com/products/en?keywords=liexin
9 = http://www.aipco.com/search.php?pn=liexin 8 = https://www.chip1stop.com/CHN/zh/view/searchResult/SearchResultTop?keyword=liexin
10 = https://www.arrow.com/en/products/search?cat=&q=liexin 9 = http://www.aipco.com/search.php?pn=liexin
11 = https://www.biscoind.com?SEARCHTEXT=liexin 10 = https://www.arrow.com/en/products/search?cat=&q=liexin
12 = https://www.alliedelec.com/view/search?keyword=liexin 11 = https://www.biscoind.com?SEARCHTEXT=liexin
13 = https://www.avnet.com/shop/apac/search/liexin 12 = https://www.alliedelec.com/view/search?keyword=liexin
14 = https://www.mouser.com/Search/Refine?Keyword=liexin 13 = https://www.avnet.com/shop/apac/search/liexin
15 = 14 = https://www.mouser.com/Search/Refine?Keyword=liexin
16 = 15 =
18 = 16 =
19 = https://www.peigenesis.cn/cn/shop/f/liexin.html 18 =
20 = https://www.powell.com/e2wItemQuickSearch.aspx?searchText=liexin 19 = https://www.peigenesis.cn/cn/shop/f/liexin.html
21 = https://uk.rs-online.com/web/c/semiconductors/amplifiers-comparators/op-amps/?searchTerm=liexin 20 = https://www.powell.com/e2wItemQuickSearch.aspx?searchText=liexin
22 = 21 = https://uk.rs-online.com/web/c/semiconductors/amplifiers-comparators/op-amps/?searchTerm=liexin
1672 = https://www.masterelectronics.com/parts.aspx?text=liexin 22 =
1673 = https://www.rutronik24.com/search-result/qs:liexin 1672 = https://www.masterelectronics.com/parts.aspx?text=liexin
1675 = https://www.zaikostore.com/zaikostore/stockList?productName_forFind=liexin 1673 = https://www.rutronik24.com/search-result/qs:liexin
1676 = https://www.buerklin.com/en/search?text=liexin 1675 = https://www.zaikostore.com/zaikostore/stockList?productName_forFind=liexin
1677 = https://www.microchipdirect.com/product/search/all/liexin 1676 = https://www.buerklin.com/en/search?text=liexin
1678 = https://estore.heilindasia.com/search.asp?p=liexin 1677 = https://www.microchipdirect.com/product/search/all/liexin
1680 = http://shop.wpgam.com/WPGAStore/index.php?route=product/search&filter_description=true&filter_name=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
[AUTH]
SUPER_AUTH_KEY = fh6y5t4rr351d2c3bryi [AUTH]
SEARCH_TOKEN_EXPIRE_TIME = 30 SUPER_AUTH_KEY = fh6y5t4rr351d2c3bryi
SEARCH_TOKEN_EXPIRE_TIME = 30
[UNIT_SUPPLIER_LOG_CODE]
333333 = arrow [UNIT_SUPPLIER_LOG_CODE]
444444 = master 333333 = arrow
555555 = mouser 444444 = master
666666 = verical 555555 = mouser
777777 = tme 666666 = verical
888888 = buerklin 777777 = tme
999999 = zhuanmai 888888 = buerklin
999999 = zhuanmai
[SEARCH_API_LOG]
SEARCH_API_ERROR_PRE = search_api_overtime_ [SEARCH_API_LOG]
\ No newline at end of file SEARCH_API_ERROR_PRE = search_api_overtime_
[LY_UPDATE_LIMIT]
;联营是否开启立刻更新:0否 1是
isUpdate = 0
[web]
port = 9000
mode = debug
cors_domain = http://bom.liexin.com
[message]
api_domain = http://api.ichunt.com/msg/sendMessageByAuto
api_md5_str = fh6y5t4rr351d2c3bryi
[goods]
api_url = http://192.168.2.232:60004
[es]
url = http://192.168.2.232:9200
urls = http://192.168.2.232:9200,http://192.168.2.232:9200
index_name = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,zhuanmai,peigenesis,powell,rs,buerklin,liexin_ziying
search_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin,zhuanmai
hk_delivery_type_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin
attr_index = goods_map
[database]
user_name = root
password = root
host = 192.168.2.239
database = test
table_prefix =
type = mysql
[redis]
write_host = 192.168.1.235:6379
read_host = 192.168.1.235:6379
write_password = icDb29mLy2s
read_password = icDb29mLy2s
max_idle = 10
max_active = 10
idle_timeout = 20
[mongo]
host = 127.0.0.1:27017
database = liexin_config
[brand]
#是否开启排除品牌
IS_NOT_TI = 1
TI_LY_BRAND_IDS = 23,45069,7754,17484,43215,13421,5220,7636,44534,43556,44543,9429,758,9470,10430,10653,10707,11227,11276,11819,12608,12965,12997,13327,13675,13680,13752
ti_zy_brand_id = 23
\ No newline at end of file
[DINGDING]
SEARCH_API_MONITOR = 6d0fa85e01a02c39347d011ae973fd21b76c6c7ce582d3ea470c6b65a318848d
\ No newline at end of file
[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
[web]
port = 10001
mode = release
cors_domain = https://bom.ichunt.com
domain = ichunt.com
[message]
api_domain = http://api.ichunt.com/msg/sendMessageByAuto
api_md5_str = fh6y5t4rr351d2c3bryi
[goods]
api_url = http://47.106.60.211:60004
sz_api_url = http://47.106.60.211:60004
[es]
url = http://172.18.137.29:9211
urls = http://172.18.137.29:9211,http://172.18.137.30:9211
index_name = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,zhuanmai,peigenesis,powell,rs,buerklin,liexin_ziying
search_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin,zhuanmai
hk_delivery_type_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin
attr_index = goods_map
[redis]
write_host = 172.18.137.38:6379
read_host = 172.18.137.39:6379
write_password = icDb29mLy2s
read_password = icDb29mLy2s
max_idle = 10
max_active = 10
idle_timeout = 20
[mongo]
host = 172.18.137.23:27017
username = "ichunt"
password = "huntmon66499"
database = ichunt
maxPoolSize=100
[ZIYING_CACHE]
is_no_ziying_cache=true
#是否是测试环境
[IS_SZ]
is_sz = false
#自营mongodb缓存表 正式线ziying_class_aggs
[AGG_TABLE]
agg_table = ziying_class_aggs
#自营mongodb缓存表 正式线 ziying_first_lists
[FIRSTLISTS_TABLE]
firstLists_table = ziying_first_lists
\ No newline at end of file
[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 = dtuser
password = `dAtaL#ym2902m2lLX2y33`
host = appdb-master.ichunt.db
database = icdata
table_prefix =
type = mysql
[DINGDING]
SEARCH_API_MONITOR = cd1661d0ce733a8ff0b603b532b317aae9de6dbaf39186b0352f272e47a860e8
\ No newline at end of file
[rabmq]
url = amqp://huntweb:xMtMi29zTm@119.23.79.136:5672/
;存放本系统所有的队列名称
[rabmq_all]
; bom任务id
MQ_BOM_ITEMS_LIST=bom_items_list
; bom更新数据队列
MQ_BOM_SKU_LIST=bom_sku_list
;联营数据更新-推送入队列-》go后台任务消费(斌哥脚本)
SEARCH_SKU_UPDATE_LIST=search_sku_update_list
;联营数据新增-推送入队列-》go后台任务消费(斌哥脚本)
SEARCH_SKU_LIST=search_sku_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
[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_all]
;供应商redis的首key
SUPPLIER_REDIS_PRE=SUPPLIER_REDIS_INFO_
;需要展示的供应商列表
SUPPLIER_REDIS_LIST_PRE=SUPPLIER_REDIS_LIST_INFO_
;新增sku时判读sku是否存在
SKU_UNIQUE_JUDGE=sku_unique_judge
;新增sku时判读sku是否存在
SPU_UNIQUE_JUDGE=sku_unique_judge
;品牌信息判断,根据md5后的品牌名称获取id
BRAND_NAME_ALL=brand_name_all
;品牌id,获取品牌名称
BRAND=brand
;供应商品牌信息判断,存在多对一的情况,根据md5后的品牌名称获取标准品牌id
SUPPLIER_BRAND_ALL=supplier_brand_all
;统计调用外联接口的次数的key的前缀 后面接mouser、verical、arrow、master
SEARCH_API_TOTAL_PRE=search_api_total_
;统计调用外联接口失败的次数的key的前缀 后面接mouser、verical、arrow、master
SEARCH_API_ERORR_PRE=search_api_overtime_
;曝光时间记录哈希集合
SEARCH_SHOW_SKU_TIME=search_show_sku_time
;获取关税信息,根据goods_name,brand_name获取
TAX_CUSTOMS_INFO=tax_customs_info
;存放联营外链原始映射
SKU_RAW_MAP=sku_raw_map
[redis_ziyin]
AGG_TABLE=sz_ziying_class_aggs
FIRST_LISTS_TABLE=ziying_first_lists
ZIYING_CLASS_KEY=ziying_class_string
TAX_CUSTOMS_INFO=tax_customs_info
;存放联营所有sku
SKU=sku
;存放联营所有spu
SPU=SPU
;存放digikey 型号映射
SKU_RAW_MAP=sku_raw_map
POOL_ALIKE_GOODS=pool_alike_goods
[SUPPLIER_ALL]
1 = future
2 = powerandsignal
3 = rochester
4 = tme
5 = verical
6 = element14
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
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]
1 = future
3 = rochester
6 = element14
#7 = digikey
8 = chip1stop
9 = aipco
12 = alliedelec
13 = avnet
19 = peigenesis
20 = powell
21 = rs
1675 = corestaff
1677 = microchip
1678 = heilind
1680 = wpg
1681 = jameco
1679 = ti
1684 = distrelec
1685 = tlc
1686 = adi
#相似物料供应商
[ALIKE_SUPPLIER]
1 = ti
[common]
MOUSER_API = 'http://footstone.liexin.net/webapi/handle_mouser'
[BRAND]
IS_NOT_TI = 0
TI_LY_BRAND_IDS = 23,45069,7754,17484,43215,13421,5220,7636,44534,43556,44543,9429,758,9470,10430,10653,10707,11227,11276,11819,12608,12965,12997,13327,13675,13680,13752
TI_ZY_BRAND_IDS = 23
[supplier]
# 供应商redis的首key
SUPPLIER_REDIS_PRE = SUPPLIER_REDIS_INFO_
[ZIYING_BRAND_REPLACE]
FH = FH(风华)
BL = BL(上海贝岭)
TE = TE(泰科)
FM = FM(富满)
CJ = CJ(长电)
ST = ST(意法)
SK = SK(时科)
ON = ON(安森美)
TM = TM(天微)
TP = TP(拓微)
TI = TI(德州仪器)
MD = MD(明达)
EG = EG(屹晶微)
HF = HF(宏发)
DY = DY(迪一)
MK = MK(米客方德)
国民 = Nationz(国民技术)
中芯 = SMIC(中芯国际)
富士 = Fuji Electric(富士电机)
国星 = Nationstar(国星光电)
贝岭 = BL(上海贝岭)
[ZIYING_CONFIG]
Index = liexin_ziying
[SEARCH_KEYWORD_MAPPING]
`^(.* )?([\d\.]+)(欧|欧姆|R|r)( .*)?$` = ${1}${2}Ω${4}
`^(.* )?([\d\.]+)(U|u|μ)(.?)( .*)?$` = ${1}${2}Μ${4}${5}
`COG` = C0G
`NPO` = NP0
`华科|华新科技|华新科` = 华新
[mathExactGoodsName]
0=M7
1=M1
2=M4
3=M2
4=A7
5=F7
6=X2
7=G4
8=X4
9=m7
10=m1
11=m4
12=m2
13=a7
14=f7
15=x2
16=g4
17=x4
;自营以某些单位进行搜索时,进行特殊处理
[ZIYING_MEASURE]
0=kΩ
1=uf
2=v
3=kg
4=MHz
5=pf
6=pin
7=ppm
8=kw
[OFFICIAL_WEBSITE]
1 = https://www.futureelectronics.cn/search/?text=liexin
2 = http://www.powerandsignal.com/Products/Search?searchBox=liexin
3 = https://www.rocelec.com/search?q=liexin
4 = https://www.tme.eu/zh/katalog/#search=liexin
5 = https://www.verical.com/s/liexin/
6 = https://cn.element14.com/search?st=liexin
7 = https://www.digikey.com/products/en?keywords=liexin
8 = https://www.chip1stop.com/CHN/zh/view/searchResult/SearchResultTop?keyword=liexin
9 = http://www.aipco.com/search.php?pn=liexin
10 = https://www.arrow.com/en/products/search?cat=&q=liexin
11 = https://www.biscoind.com?SEARCHTEXT=liexin
12 = https://www.alliedelec.com/view/search?keyword=liexin
13 = https://www.avnet.com/shop/apac/search/liexin
14 = https://www.mouser.com/Search/Refine?Keyword=liexin
15 =
16 =
18 =
19 = https://www.peigenesis.cn/cn/shop/f/liexin.html
20 = https://www.powell.com/e2wItemQuickSearch.aspx?searchText=liexin
21 = https://uk.rs-online.com/web/c/semiconductors/amplifiers-comparators/op-amps/?searchTerm=liexin
22 =
1672 = https://www.masterelectronics.com/parts.aspx?text=liexin
1673 = https://www.rutronik24.com/search-result/qs:liexin
1675 = https://www.zaikostore.com/zaikostore/stockList?productName_forFind=liexin
1676 = https://www.buerklin.com/en/search?text=liexin
1677 = https://www.microchipdirect.com/product/search/all/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
[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_
...@@ -24,17 +24,17 @@ func AutoSpu(c *gin.Context) { ...@@ -24,17 +24,17 @@ func AutoSpu(c *gin.Context) {
} }
//获取推荐列表 //获取推荐列表
func Recommend(c *gin.Context) { func Recommend(ctx *gin.Context) {
req := &common.RecommendRequest{} req := &common.RecommendRequest{}
err := c.Bind(&req) //使用的是post参数 err := ctx.Bind(&req) //使用的是post参数
if err != nil { if err != nil {
logger.Error("%s", err.Error()) logger.Error("%s", err.Error())
} }
if req.Flag == 0 { if req.Flag == 0 {
common.Output(101, "参数不全", nil) common.Output(ctx,101, "参数不全", nil)
return return
} }
data := service.Recommend(req) data := service.Recommend(ctx,req)
common.Output(req.Flag, "", data) common.Output(ctx,req.Flag, "", data)
return return
} }
...@@ -19,9 +19,9 @@ import ( ...@@ -19,9 +19,9 @@ import (
"strings" "strings"
) )
func GetDataIndex(c *gin.Context) { func GetDataIndex(ctx *gin.Context) {
var r requests.GetDataIndexRequest var r requests.GetDataIndexRequest
_ = c.ShouldBind(&r) _ = ctx.ShouldBind(&r)
if r.Keyword != "" { if r.Keyword != "" {
word, _ := php2go.URLDecode(r.Keyword) word, _ := php2go.URLDecode(r.Keyword)
r.Keyword = strings.ToUpper(word) r.Keyword = strings.ToUpper(word)
...@@ -33,13 +33,13 @@ func GetDataIndex(c *gin.Context) { ...@@ -33,13 +33,13 @@ func GetDataIndex(c *gin.Context) {
supplierList := config.GetSectionValues("SEARCH_SUPPLIER_MERGE") supplierList := config.GetSectionValues("SEARCH_SUPPLIER_MERGE")
supplierName := config.Get("SUPPLIER_ALL." + r.SupplierId).String() supplierName := config.Get("SUPPLIER_ALL." + r.SupplierId).String()
if supplierName == "" && r.IsSort != 2 { if supplierName == "" && r.IsSort != 2 {
c.JSON(200, common.ErrorResponse(1, "供应商id有误")) ctx.JSON(200, common.ErrorResponse(1, "供应商id有误"))
return return
} }
common.PrintDebugHeader() common.PrintDebugHeader(ctx)
common.PrintDebugHtml(r.SupplierId) common.PrintDebugHtml(ctx,r.SupplierId)
common.PrintDebugHtml(r.Keyword) common.PrintDebugHtml(ctx,r.Keyword)
if r.SupplierId != "" && r.IsSort == 2 { if r.SupplierId != "" && r.IsSort == 2 {
//所有供应商列表 //所有供应商列表
...@@ -54,7 +54,7 @@ func GetDataIndex(c *gin.Context) { ...@@ -54,7 +54,7 @@ func GetDataIndex(c *gin.Context) {
} }
if res { if res {
//增加联营外链请求 //增加联营外链请求
outLinkDiv(&r.SupplierId,&supplierName,&r.Keyword) outLinkDiv(ctx,&r.SupplierId,&supplierName,&r.Keyword)
//增加 //增加
_, err := redis.Bool(redisCon.Do("INCR", config.Get("redis_all.SEARCH_API_TOTAL_PRE").String()+r.SupplierName)) _, err := redis.Bool(redisCon.Do("INCR", config.Get("redis_all.SEARCH_API_TOTAL_PRE").String()+r.SupplierName))
if err != nil { if err != nil {
...@@ -63,8 +63,8 @@ func GetDataIndex(c *gin.Context) { ...@@ -63,8 +63,8 @@ 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(ctx,r.GetGoodsBySupplierRequest)
common.Output(1, "", result) common.Output(ctx,1, "", result)
return return
} }
} }
...@@ -76,12 +76,12 @@ func GetDataIndex(c *gin.Context) { ...@@ -76,12 +76,12 @@ func GetDataIndex(c *gin.Context) {
return return
} }
goodsIds := service.GetGoodsIdsByEsMsearch(esResult) goodsIds := service.GetGoodsIdsByEsMsearch(esResult)
goodsList, err := service.GetGoodsInfo(goodsIds) goodsList, err := service.GetGoodsInfo(ctx,goodsIds)
dullData, err := transformer.DullDataInfo(r.Keyword, goodsList) dullData, err := transformer.DullDataInfo(ctx,r.Keyword, goodsList)
result := service.GetReturnSupplierData(dullData) result := service.GetReturnSupplierData(dullData)
result["total"] = gjson.Get(esResult, "hits.total").Int() result["total"] = gjson.Get(esResult, "hits.total").Int()
result["took"] = gjson.Get(esResult, "took").Int() result["took"] = gjson.Get(esResult, "took").Int()
common.Output(0, "", result) common.Output(ctx,0, "", result)
return return
} }
...@@ -91,12 +91,12 @@ func GetDataIndex(c *gin.Context) { ...@@ -91,12 +91,12 @@ func GetDataIndex(c *gin.Context) {
@param supplierName 渠道名称 @param supplierName 渠道名称
@param keyword 关键词 @param keyword 关键词
*/ */
func outLinkDiv(supplierId *string,supplierName *string,keyWord * string){ func outLinkDiv(ctx *gin.Context,supplierId *string,supplierName *string,keyWord * string){
var apiData map[string]*model.LyClearGoodsList = nil var apiData map[string]*model.LyClearGoodsList = nil
switch *supplierName { switch *supplierName {
case "mouser": //调外链拿数据mouser外链请求更新修改 case "mouser": //调外链拿数据mouser外链请求更新修改
apiData = ly.OutLinkMouser(keyWord) apiData = ly.OutLinkMouser(ctx,keyWord)
break; break;
} }
...@@ -104,7 +104,7 @@ func outLinkDiv(supplierId *string,supplierName *string,keyWord * string){ ...@@ -104,7 +104,7 @@ func outLinkDiv(supplierId *string,supplierName *string,keyWord * string){
//供应商详情 //供应商详情
supplierId,_ := strconv.ParseInt(*supplierId, 10, 64) supplierId,_ := strconv.ParseInt(*supplierId, 10, 64)
lycon := ly.CommonLyService{} lycon := ly.CommonLyService{}
lycon.GetSkuByGoodsSn(apiData,&model.SUPPLIER_REDIS_INFO{ lycon.GetSkuByGoodsSn(ctx,apiData,&model.SUPPLIER_REDIS_INFO{
SupplierId:supplierId, SupplierId:supplierId,
SupplierNickname: *supplierName, SupplierNickname: *supplierName,
}) })
......
...@@ -2,33 +2,32 @@ package controller ...@@ -2,33 +2,32 @@ package controller
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"search_server/middleware"
"search_server/model" "search_server/model"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/service/ly" "search_server/service/ly"
) )
//搜索型号 //搜索型号
func GetDigikeyData(c *gin.Context) { func GetDigikeyData(ctx *gin.Context) {
goodsName := middleware.REQUEST["k"] //关键词 goodsName := ctx.Request.FormValue("k") //关键词
common.PrintDebugHeader() //debug common.PrintDebugHeader(ctx) //debug
if goodsName == "" { if goodsName == "" {
common.Output(1001, "查询关键词不得为空", "") common.Output(ctx,1001, "查询关键词不得为空", "")
return return
} }
//调外链拿数据 //调外链拿数据
apiData := ly.OutLinkDigikey(&goodsName) apiData := ly.OutLinkDigikey(ctx,&goodsName)
//供应商详情 //供应商详情
lycon := new(ly.CommonLyService) lycon := new(ly.CommonLyService)
lycon.GetSkuByGoodsSn(apiData, &model.SUPPLIER_REDIS_INFO{ lycon.GetSkuByGoodsSn(ctx,apiData, &model.SUPPLIER_REDIS_INFO{
SupplierId: 14, SupplierId: 14,
SupplierNickname: "mouser", SupplierNickname: "mouser",
}) })
common.PrintDebugHtml("-----执行结束----") //debug common.PrintDebugHtml(ctx,"-----执行结束----") //debug
} }
\ No newline at end of file
...@@ -2,30 +2,29 @@ package controller ...@@ -2,30 +2,29 @@ package controller
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"search_server/middleware"
"search_server/model" "search_server/model"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/service/ly" "search_server/service/ly"
) )
//搜索型号 //搜索型号
func GetMouserData(c *gin.Context) { func GetMouserData(ctx *gin.Context) {
goodsName := middleware.REQUEST["goods_name"] goodsName := ctx.Request.FormValue("goods_name")
common.PrintDebugHeader() //debug common.PrintDebugHeader(ctx) //debug
if goodsName == "" { if goodsName == "" {
common.Output(1001, "查询关键词不得为空", "") common.Output(ctx,1001, "查询关键词不得为空", "")
return return
} }
//调外链拿数据 //调外链拿数据
apiData := ly.OutLinkMouser(&goodsName) apiData := ly.OutLinkMouser(ctx,&goodsName)
//供应商详情 //供应商详情
lycon := new(ly.CommonLyService) lycon := new(ly.CommonLyService)
err := lycon.GetSkuByGoodsSn(apiData,&model.SUPPLIER_REDIS_INFO{ err := lycon.GetSkuByGoodsSn(ctx,apiData,&model.SUPPLIER_REDIS_INFO{
SupplierId:14, SupplierId:14,
SupplierNickname: "mouser", SupplierNickname: "mouser",
}) })
...@@ -34,6 +33,6 @@ func GetMouserData(c *gin.Context) { ...@@ -34,6 +33,6 @@ func GetMouserData(c *gin.Context) {
errCode = 1 errCode = 1
} }
common.PrintDebugHtml("-----执行结束----") //debug common.PrintDebugHtml(ctx,"-----执行结束----") //debug
common.Output(errCode, "查询成功", "") common.Output(ctx,errCode, "查询成功", "")
} }
...@@ -2,33 +2,32 @@ package controller ...@@ -2,33 +2,32 @@ package controller
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"search_server/middleware"
"search_server/model" "search_server/model"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/service/ly" "search_server/service/ly"
) )
//搜索型号 //搜索型号
func GetTmeData(c *gin.Context) { func GetTmeData(ctx *gin.Context) {
goodsName := middleware.REQUEST["k"] //关键词 goodsName := ctx.Request.FormValue("k") //关键词
common.PrintDebugHeader() //debug common.PrintDebugHeader(ctx) //debug
if goodsName == "" { if goodsName == "" {
common.Output(1001, "查询关键词不得为空", "") common.Output(ctx,1001, "查询关键词不得为空", "")
return return
} }
//调外链拿数据 //调外链拿数据
apiData := ly.OutLinkTme(&goodsName) apiData := ly.OutLinkTme(ctx,&goodsName)
//供应商详情 //供应商详情
lycon := new(ly.CommonLyService) lycon := new(ly.CommonLyService)
lycon.GetSkuByGoodsSn(apiData, &model.SUPPLIER_REDIS_INFO{ lycon.GetSkuByGoodsSn(ctx,apiData, &model.SUPPLIER_REDIS_INFO{
SupplierId: 4, SupplierId: 4,
SupplierNickname: "tme", SupplierNickname: "tme",
}) })
common.PrintDebugHtml("-----执行结束----") //debug common.PrintDebugHtml(ctx,"-----执行结束----") //debug
} }
\ No newline at end of file
...@@ -7,23 +7,23 @@ import ( ...@@ -7,23 +7,23 @@ import (
) )
//参数分类统计 //参数分类统计
func OptimumAttr(c *gin.Context) { func OptimumAttr(ctx *gin.Context) {
common.PrintDebugHeader() //debug common.PrintDebugHeader(ctx) //debug
optimumservice := service.OptimumService{} optimumservice := service.OptimumService{}
apiData := optimumservice.GetOptimumAttr() apiData := optimumservice.GetOptimumAttr(ctx)
common.Output(apiData.ErrorCode, apiData.ErrorMsg, apiData.Data) common.Output(ctx,apiData.ErrorCode, apiData.ErrorMsg, apiData.Data)
common.PrintDebugHtml("-----执行结束----") //debug common.PrintDebugHtml(ctx,"-----执行结束----") //debug
} }
//参数+分类 商品详情 //参数+分类 商品详情
func OptimumGoods(c *gin.Context) { func OptimumGoods(ctx *gin.Context) {
common.PrintDebugHeader() //debug common.PrintDebugHeader(ctx) //debug
optimumservice := service.OptimumService{} optimumservice := service.OptimumService{}
apiData := optimumservice.GetOptimumAttrInfo() apiData := optimumservice.GetOptimumAttrInfo(ctx)
common.Output(apiData.ErrorCode, apiData.ErrorMsg, apiData.Data) common.Output(ctx,apiData.ErrorCode, apiData.ErrorMsg, apiData.Data)
common.PrintDebugHtml("-----执行结束----") //debug common.PrintDebugHtml(ctx,"-----执行结束----") //debug
} }
\ No newline at end of file
...@@ -10,19 +10,19 @@ import ( ...@@ -10,19 +10,19 @@ import (
) )
//查询联营型号是否有库存 //查询联营型号是否有库存
func CheckHasStock(c *gin.Context) { func CheckHasStock(ctx *gin.Context) {
noRule, _ := c.GetPostForm("no_rule") noRule, _ := ctx.GetPostForm("no_rule")
if noRule != "1122" { if noRule != "1122" {
flag := common.CheckSignApi() flag := common.CheckSignApi(ctx)
if flag > 0 { if flag > 0 {
common.Output(flag, "验证不通过:", nil) common.Output(ctx,flag, "验证不通过:", nil)
return return
} }
} }
goodsName, _ := c.GetPostForm("goods_name") goodsName, _ := ctx.GetPostForm("goods_name")
if goodsName == "" { if goodsName == "" {
common.Output(1001, "型号不存在", nil) common.Output(ctx,1001, "型号不存在", nil)
return return
} }
replace, _ := regexp.Compile("[^A-Za-z0-9]+") replace, _ := regexp.Compile("[^A-Za-z0-9]+")
...@@ -31,10 +31,10 @@ func CheckHasStock(c *gin.Context) { ...@@ -31,10 +31,10 @@ func CheckHasStock(c *gin.Context) {
otherService := service.OtherService{} otherService := service.OtherService{}
hasStock, err := otherService.CheckHasStock(goodsName) hasStock, err := otherService.CheckHasStock(goodsName)
if err != nil { if err != nil {
common.Output(1, "查询失败,系统报错"+err.Error(), nil) common.Output(ctx,1, "查询失败,系统报错"+err.Error(), nil)
return return
} }
common.Output(0, "查询成功:"+goodsName, hasStock) common.Output(ctx,0, "查询成功:"+goodsName, hasStock)
return return
} }
...@@ -43,10 +43,10 @@ func ExactGoods(c *gin.Context) { ...@@ -43,10 +43,10 @@ func ExactGoods(c *gin.Context) {
var r requests.ExactGoodsRequest var r requests.ExactGoodsRequest
c.ShouldBind(&r) c.ShouldBind(&r)
if r.GoodsName == "" { if r.GoodsName == "" {
common.Output(1, "查询型号名称不得为空", nil) common.Output(c,1, "查询型号名称不得为空", nil)
return return
} }
//查询条件 //查询条件
otherService := service.OtherService{} otherService := service.OtherService{}
otherService.ExactGoods(r.SupplierId, r.GoodsName) otherService.ExactGoods(c,r.SupplierId, r.GoodsName)
} }
...@@ -18,28 +18,28 @@ import ( ...@@ -18,28 +18,28 @@ import (
//搜索快手搜搜 //搜索快手搜搜
//check_button=2&pf=1&keyword=123213&supplier_id=7&offset=2&follow_hit=1&p=1&_=1593582814402 //check_button=2&pf=1&keyword=123213&supplier_id=7&offset=2&follow_hit=1&p=1&_=1593582814402
func QuoteIndex(c *gin.Context) { func QuoteIndex(ctx *gin.Context) {
var r requests.QuoteIndexRequest var r requests.QuoteIndexRequest
//绑定参数到结构体 //绑定参数到结构体
if err := c.ShouldBind(&r); err != nil { if err := ctx.ShouldBind(&r); err != nil {
logger.Error("%s", 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 {
common.Output(errCode, errMsg, nil) common.Output(ctx,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(ctx,r.GetGoodsBySupplierRequest)
if res != nil { if res != nil {
flag = 0 flag = 0
common.Output(flag, "", res) common.Output(ctx,flag, "", res)
} else { } else {
common.Output(flag, "", nil) common.Output(ctx,flag, "", nil)
} }
return return
} }
...@@ -47,25 +47,25 @@ func QuoteIndex(c *gin.Context) { ...@@ -47,25 +47,25 @@ func QuoteIndex(c *gin.Context) {
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 {
common.Output(1, "供应商有误", nil) common.Output(ctx,1, "供应商有误", nil)
return return
} }
if supplierName == "mouser" { if supplierName == "mouser" {
//mouser同步请求搜索 //mouser同步请求搜索
res, _ = mouserOrg(r.Keyword, r.SupplierId) res, _ = mouserOrg(ctx,r.Keyword, r.SupplierId)
} else { } else {
r.GetGoodsBySupplierRequest.SupplierName = supplierName r.GetGoodsBySupplierRequest.SupplierName = supplierName
res, _ = quoteService.GetGoodsBySupplierName(r.GetGoodsBySupplierRequest) res, _ = quoteService.GetGoodsBySupplierName(ctx,r.GetGoodsBySupplierRequest)
} }
if len(res) > 0 { if len(res) > 0 {
flag = 0 flag = 0
} }
common.Output(flag, "", res) common.Output(ctx,flag, "", res)
return return
} }
func mouserOrg(keyword, suppliedId string) (result map[string]interface{}, err error) { func mouserOrg(ctx *gin.Context,keyword, suppliedId string) (result map[string]interface{}, err error) {
mouserRes := ly.OutLinkMouser(&keyword) mouserRes := ly.OutLinkMouser(ctx,&keyword)
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)
...@@ -81,12 +81,12 @@ func mouserOrg(keyword, suppliedId string) (result map[string]interface{}, err e ...@@ -81,12 +81,12 @@ func mouserOrg(keyword, suppliedId string) (result map[string]interface{}, err e
goodsIds = append(goodsIds, skuId) goodsIds = append(goodsIds, skuId)
} }
} }
goodsList, err := service.GetGoodsInfo(goodsIds) goodsList, err := service.GetGoodsInfo(ctx,goodsIds)
if err != nil { if err != nil {
return return
} }
dullData, err := transformer.DullDataInfo(keyword, goodsList) dullData, err := transformer.DullDataInfo(ctx,keyword, goodsList)
result = service.GetReturnSupplierData(dullData) result = service.GetReturnSupplierData(dullData)
if err != nil { if err != nil {
return return
......
...@@ -12,10 +12,10 @@ import ( ...@@ -12,10 +12,10 @@ import (
) )
//提供日志接口给日志系统 //提供日志接口给日志系统
func SearchLogIndex(c *gin.Context) { func SearchLogIndex(ctx *gin.Context) {
request := make(map[string]string, 0) request := make(map[string]string, 0)
c.MultipartForm() ctx.MultipartForm()
for name, value := range c.Request.Form { for name, value := range ctx.Request.Form {
if value[0] != "" { if value[0] != "" {
request[name] = strings.TrimSpace(value[0]) request[name] = strings.TrimSpace(value[0])
} }
...@@ -24,10 +24,10 @@ func SearchLogIndex(c *gin.Context) { ...@@ -24,10 +24,10 @@ func SearchLogIndex(c *gin.Context) {
searchLogService := service.SearchLogService{} searchLogService := service.SearchLogService{}
result, err := searchLogService.GetIndexData(request) result, err := searchLogService.GetIndexData(request)
if err != nil { if err != nil {
common.ReturnData(1, "获取ES数据失败 : "+err.Error(), nil) common.ReturnData(ctx,1, "获取ES数据失败 : "+err.Error(), nil)
} }
common.ReturnData(0, "", result) common.ReturnData(ctx,0, "", result)
return return
} }
...@@ -35,7 +35,7 @@ func Scroll(c *gin.Context) { ...@@ -35,7 +35,7 @@ func Scroll(c *gin.Context) {
var r requests.ScrollRequest var r requests.ScrollRequest
c.ShouldBind(&r) c.ShouldBind(&r)
if r.ScrollId == 0 { if r.ScrollId == 0 {
common.ReturnData(1, "", nil) common.ReturnData(c,1, "", nil)
} }
params := make(map[string]interface{}) params := make(map[string]interface{})
if r.Scroll > 0 { if r.Scroll > 0 {
...@@ -47,16 +47,16 @@ func Scroll(c *gin.Context) { ...@@ -47,16 +47,16 @@ func Scroll(c *gin.Context) {
paramsStr, _ := json.Marshal(params) paramsStr, _ := json.Marshal(params)
_, err := es.ScrollES(string(paramsStr)) _, err := es.ScrollES(string(paramsStr))
if err != nil { if err != nil {
common.ReturnData(1, "Scroll失败 : "+err.Error(), nil) common.ReturnData(c,1, "Scroll失败 : "+err.Error(), nil)
} }
} }
//根据搜索日志统计出时间短访问最多的ip' //根据搜索日志统计出时间短访问最多的ip'
func SumIp(c *gin.Context) { func SumIp(c *gin.Context) {
//统计品牌下的商品数量 //统计品牌下的商品数量
flag := common.CheckSignApi() flag := common.CheckSignApi(c)
if flag > 0 { if flag > 0 {
common.ReturnData(flag, "", nil) common.ReturnData(c,flag, "", nil)
return return
} }
var r requests.SumIpRequest var r requests.SumIpRequest
...@@ -64,9 +64,9 @@ func SumIp(c *gin.Context) { ...@@ -64,9 +64,9 @@ func SumIp(c *gin.Context) {
searchLogService := service.SearchLogService{} searchLogService := service.SearchLogService{}
res, err := searchLogService.GetSumIp(r) res, err := searchLogService.GetSumIp(r)
if err != nil { if err != nil {
common.ReturnData(1, err.Error(), nil) common.ReturnData(c,1, err.Error(), nil)
return return
} }
common.ReturnData(0, "", res) common.ReturnData(c,0, "", res)
return return
} }
...@@ -11,20 +11,20 @@ import ( ...@@ -11,20 +11,20 @@ import (
) )
//封禁ip开关 //封禁ip开关
func SetButton(c *gin.Context) { func SetButton(ctx *gin.Context) {
var r requests.SetButtonRequest var r requests.SetButtonRequest
c.ShouldBind(&r) ctx.ShouldBind(&r)
redisCon := gredis.Conn("search_w") redisCon := gredis.Conn("search_w")
res, err := redis.Bool(redisCon.Do("SET", "spider_config_button", r.Val)) res, err := redis.Bool(redisCon.Do("SET", "spider_config_button", r.Val))
if err != nil { if err != nil {
common.Output(1, "操作redis失败", err.Error()) common.Output(ctx,1, "操作redis失败", err.Error())
return return
} }
if res { if res {
common.Output(0, "成功", res) common.Output(ctx,0, "成功", res)
return return
} else { } else {
common.Output(1, "设置开关失败", res) common.Output(ctx,1, "设置开关失败", res)
return return
} }
} }
...@@ -35,7 +35,7 @@ func GetWbList(c *gin.Context) { ...@@ -35,7 +35,7 @@ func GetWbList(c *gin.Context) {
c.ShouldBind(&r) c.ShouldBind(&r)
redisCon := gredis.Conn("search_w") redisCon := gredis.Conn("search_w")
if r.ListType == 0 { if r.ListType == 0 {
common.Output(1, "参数为空", nil) common.Output(c,1, "参数为空", nil)
return return
} }
keyName := "spider_black_list" keyName := "spider_black_list"
...@@ -45,13 +45,13 @@ func GetWbList(c *gin.Context) { ...@@ -45,13 +45,13 @@ func GetWbList(c *gin.Context) {
res, err := redis.Strings(redisCon.Do("SMEMBERS", keyName)) res, err := redis.Strings(redisCon.Do("SMEMBERS", keyName))
if err != nil { if err != nil {
common.Output(1, "操作redis失败", err.Error()) common.Output(c,1, "操作redis失败", err.Error())
return return
} }
list := make(map[string]interface{}) list := make(map[string]interface{})
list["list"] = res list["list"] = res
list["total"] = len(res) list["total"] = len(res)
common.Output(0, "成功", list) common.Output(c,0, "成功", list)
return return
} }
...@@ -60,7 +60,7 @@ func SetWbList(c *gin.Context) { ...@@ -60,7 +60,7 @@ func SetWbList(c *gin.Context) {
var r requests.SetWbListRequest var r requests.SetWbListRequest
c.ShouldBind(&r) c.ShouldBind(&r)
if r.Type == "" || r.IpList == "" || r.AddOrRm == "" { if r.Type == "" || r.IpList == "" || r.AddOrRm == "" {
common.Output(1, "参数为空", nil) common.Output(c,1, "参数为空", nil)
} }
redisCon := gredis.Conn("search_w") redisCon := gredis.Conn("search_w")
keyName := "spider_black_list" keyName := "spider_black_list"
...@@ -78,11 +78,11 @@ func SetWbList(c *gin.Context) { ...@@ -78,11 +78,11 @@ func SetWbList(c *gin.Context) {
} }
} }
common.Output(0, "成功!", nil) common.Output(c,0, "成功!", nil)
} }
//获取自我解禁ip访问频率自增数据 //获取自我解禁ip访问频率自增数据
func GetIpalg() { func GetIpalg(c *gin.Context) {
redisCon := gredis.Conn("search_r") redisCon := gredis.Conn("search_r")
spiderAlgs, _ := redis.StringMap(redisCon.Do("HGETALL", "spider_connect_count_alg")) spiderAlgs, _ := redis.StringMap(redisCon.Do("HGETALL", "spider_connect_count_alg"))
spiderBans, _ := redis.Strings(redisCon.Do("SMEMBERS", "spider_ban")) spiderBans, _ := redis.Strings(redisCon.Do("SMEMBERS", "spider_ban"))
...@@ -100,7 +100,7 @@ func GetIpalg() { ...@@ -100,7 +100,7 @@ func GetIpalg() {
list["list"] = dataList list["list"] = dataList
list["total"] = len(dataList) list["total"] = len(dataList)
} }
common.Output(0, "成功", list) common.Output(c,0, "成功", list)
return return
} }
...@@ -109,7 +109,7 @@ func SetIpalg(c *gin.Context) { ...@@ -109,7 +109,7 @@ func SetIpalg(c *gin.Context) {
var r requests.SetIpalgRequest var r requests.SetIpalgRequest
c.ShouldBind(&r) c.ShouldBind(&r)
if r.Ip == "" || r.ListType == 0 { if r.Ip == "" || r.ListType == 0 {
common.Output(1, "参数为空", nil) common.Output(c,1, "参数为空", nil)
return return
} }
...@@ -118,16 +118,16 @@ func SetIpalg(c *gin.Context) { ...@@ -118,16 +118,16 @@ func SetIpalg(c *gin.Context) {
if r.ListType == 1 { if r.ListType == 1 {
_, err := redis.Bool(redisCon.Do("HSET", "spider_connect_count_alg", ip, r.Num)) _, err := redis.Bool(redisCon.Do("HSET", "spider_connect_count_alg", ip, r.Num))
if err != nil { if err != nil {
common.Output(1, "操作redis失败", err.Error()) common.Output(c,1, "操作redis失败", err.Error())
} }
} else { } else {
_, err := redis.Bool(redisCon.Do("HDEL", "spider_connect_count_alg", ip)) _, err := redis.Bool(redisCon.Do("HDEL", "spider_connect_count_alg", ip))
if err != nil { if err != nil {
common.Output(1, "操作redis失败", err.Error()) common.Output(c,1, "操作redis失败", err.Error())
} }
} }
common.Output(0, "成功", nil) common.Output(c,0, "成功", nil)
} }
//设置参数配置信息 //设置参数配置信息
......
...@@ -29,10 +29,10 @@ func Zyh(ctx *gin.Context){ ...@@ -29,10 +29,10 @@ func Zyh(ctx *gin.Context){
if err != nil{ if err != nil{
zyhResponse.ErrorCode = 1 zyhResponse.ErrorCode = 1
zyhResponse.ErrorMsg = fmt.Sprintf("%s",err) zyhResponse.ErrorMsg = fmt.Sprintf("%s",err)
common.Output(int(zyhResponse.ErrorCode), zyhResponse.ErrorMsg, zyhResponse.Data) common.Output(ctx,int(zyhResponse.ErrorCode), zyhResponse.ErrorMsg, zyhResponse.Data)
} }
common.Output(int(zyhResponse.ErrorCode), zyhResponse.ErrorMsg, zyhResponse.Data) common.Output(ctx,int(zyhResponse.ErrorCode), zyhResponse.ErrorMsg, zyhResponse.Data)
} }
func Aggs(ctx *gin.Context){ func Aggs(ctx *gin.Context){
...@@ -53,10 +53,10 @@ func Aggs(ctx *gin.Context){ ...@@ -53,10 +53,10 @@ func Aggs(ctx *gin.Context){
if err != nil{ if err != nil{
zyhResponse.ErrorCode = 1 zyhResponse.ErrorCode = 1
zyhResponse.ErrorMsg = fmt.Sprintf("%s",err) zyhResponse.ErrorMsg = fmt.Sprintf("%s",err)
common.Output(int(zyhResponse.ErrorCode), zyhResponse.ErrorMsg, zyhResponse.Data) common.Output(ctx,int(zyhResponse.ErrorCode), zyhResponse.ErrorMsg, zyhResponse.Data)
} }
common.Output(int(zyhResponse.ErrorCode), zyhResponse.ErrorMsg, zyhResponse.Data) common.Output(ctx,int(zyhResponse.ErrorCode), zyhResponse.ErrorMsg, zyhResponse.Data)
} }
...@@ -78,7 +78,7 @@ func AggSample(ctx *gin.Context){ ...@@ -78,7 +78,7 @@ func AggSample(ctx *gin.Context){
zyhResponse = zyServiceImpl.AggSample(ctx,zyhRequest) zyhResponse = zyServiceImpl.AggSample(ctx,zyhRequest)
common.Output(int(zyhResponse.ErrorCode), zyhResponse.ErrorMsg, zyhResponse.Data) common.Output(ctx,int(zyhResponse.ErrorCode), zyhResponse.ErrorMsg, zyhResponse.Data)
} }
func Index(ctx *gin.Context){ func Index(ctx *gin.Context){
...@@ -94,6 +94,6 @@ func Index(ctx *gin.Context){ ...@@ -94,6 +94,6 @@ func Index(ctx *gin.Context){
zyServiceImpl := service.NewZyServiceImpl() zyServiceImpl := service.NewZyServiceImpl()
zyhResponse = zyServiceImpl.Index(ctx,zyhRequest) zyhResponse = zyServiceImpl.Index(ctx,zyhRequest)
common.Output(int(zyhResponse.ErrorCode), zyhResponse.ErrorMsg, zyhResponse.Data) common.Output(ctx,int(zyhResponse.ErrorCode), zyhResponse.ErrorMsg, zyhResponse.Data)
return return
} }
\ No newline at end of file
File mode changed
package test package main
import ( import (
"fmt" "fmt"
"github.com/gin-gonic/gin"
"github.com/imroc/req" "github.com/imroc/req"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"search_server/middleware"
"search_server/model" "search_server/model"
"search_server/pkg/common" "search_server/pkg/common"
"strconv" "strconv"
...@@ -24,7 +24,7 @@ const tme_token string = "3381c9d5d9663be68eb69ea3ce00af3a2b5789094c7cd488a4"// ...@@ -24,7 +24,7 @@ const tme_token string = "3381c9d5d9663be68eb69ea3ce00af3a2b5789094c7cd488a4"//
const tme_app_secret string = "a1d8647fa38710140628" //账号 const tme_app_secret string = "a1d8647fa38710140628" //账号
//tme请求外链 //tme请求外链
func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList { func OutLinkTme(ctx *gin.Context,goodsName *string) map[string]*model.LyClearGoodsList {
if *goodsName == "" { if *goodsName == "" {
return nil return nil
} }
...@@ -33,17 +33,17 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList { ...@@ -33,17 +33,17 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList {
SymbolList string //外链原始数据的goods_sn SymbolList string //外链原始数据的goods_sn
); );
if middleware.REQUEST["flags"] == "-1" { //原始数据调试 if ctx.Request.FormValue("flags") == "-1" { //原始数据调试
result = `{"Status":"OK","Data":{"ProductList":[{"Symbol":"0402WGF1000TCE","CustomerSymbol":"","OriginalSymbol":"0402WGF1000TCE","Producer":"ROYAL OHM","Description":"Resistor: thick film; SMD; 0402; 100\u03a9; 63mW; \u00b11%; -55\u00f7155\u00b0C","CategoryId":"100578","Category":"0402 SMD resistors","Photo":"\/\/ce8dc832c.cloudimg.io\/fit\/640x480\/n@4760e4647bc7d903de9205a51f321b69cdbed098\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg?mark_url=_tme-wrk_%2Ftme_new_render3d.png&mark_pos=center&mark_size=100pp","Thumbnail":"\/\/ce8dc832c.cloudimg.io\/fit\/100x75\/webp@3ec3fbcb8427a46b791b093cd6e191b483328d8a\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg","Weight":0.01,"WeightUnit":"g","SuppliedAmount":0,"MinAmount":10000,"Multiples":10000,"ProductStatusList":[],"Unit":"pcs","ProductInformationPage":"\/\/www.tme.eu\/en\/details\/0402wgf1000tce\/0402-smd-resistors\/royal-ohm\/","Guarantee":null,"OfferId":null},{"Symbol":"SMD0402-100R-1%","CustomerSymbol":"","OriginalSymbol":"0402WGF1000TCE","Producer":"ROYAL OHM","Description":"Resistor: thick film; SMD; 0402; 100\u03a9; 63mW; \u00b11%; -55\u00f7155\u00b0C","CategoryId":"100578","Category":"0402 SMD resistors","Photo":"\/\/ce8dc832c.cloudimg.io\/fit\/640x480\/n@4760e4647bc7d903de9205a51f321b69cdbed098\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg?mark_url=_tme-wrk_%2Ftme_new_render3d.png&mark_pos=center&mark_size=100pp","Thumbnail":"\/\/ce8dc832c.cloudimg.io\/fit\/100x75\/webp@3ec3fbcb8427a46b791b093cd6e191b483328d8a\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg","Weight":0.006,"WeightUnit":"g","SuppliedAmount":0,"MinAmount":100,"Multiples":100,"ProductStatusList":[],"Unit":"pcs","ProductInformationPage":"\/\/www.tme.eu\/en\/details\/smd0402-100r-1%\/0402-smd-resistors\/royal-ohm\/0402wgf1000tce\/","Guarantee":null,"OfferId":null}],"Amount":2,"PageNumber":1,"CategoryList":{"111000":2,"100299":2,"100300":2,"100578":2,"112309":2}}}`; result = `{"Status":"OK","Data":{"ProductList":[{"Symbol":"0402WGF1000TCE","CustomerSymbol":"","OriginalSymbol":"0402WGF1000TCE","Producer":"ROYAL OHM","Description":"Resistor: thick film; SMD; 0402; 100\u03a9; 63mW; \u00b11%; -55\u00f7155\u00b0C","CategoryId":"100578","Category":"0402 SMD resistors","Photo":"\/\/ce8dc832c.cloudimg.io\/fit\/640x480\/n@4760e4647bc7d903de9205a51f321b69cdbed098\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg?mark_url=_tme-wrk_%2Ftme_new_render3d.png&mark_pos=center&mark_size=100pp","Thumbnail":"\/\/ce8dc832c.cloudimg.io\/fit\/100x75\/webp@3ec3fbcb8427a46b791b093cd6e191b483328d8a\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg","Weight":0.01,"WeightUnit":"g","SuppliedAmount":0,"MinAmount":10000,"Multiples":10000,"ProductStatusList":[],"Unit":"pcs","ProductInformationPage":"\/\/www.tme.eu\/en\/details\/0402wgf1000tce\/0402-smd-resistors\/royal-ohm\/","Guarantee":null,"OfferId":null},{"Symbol":"SMD0402-100R-1%","CustomerSymbol":"","OriginalSymbol":"0402WGF1000TCE","Producer":"ROYAL OHM","Description":"Resistor: thick film; SMD; 0402; 100\u03a9; 63mW; \u00b11%; -55\u00f7155\u00b0C","CategoryId":"100578","Category":"0402 SMD resistors","Photo":"\/\/ce8dc832c.cloudimg.io\/fit\/640x480\/n@4760e4647bc7d903de9205a51f321b69cdbed098\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg?mark_url=_tme-wrk_%2Ftme_new_render3d.png&mark_pos=center&mark_size=100pp","Thumbnail":"\/\/ce8dc832c.cloudimg.io\/fit\/100x75\/webp@3ec3fbcb8427a46b791b093cd6e191b483328d8a\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg","Weight":0.006,"WeightUnit":"g","SuppliedAmount":0,"MinAmount":100,"Multiples":100,"ProductStatusList":[],"Unit":"pcs","ProductInformationPage":"\/\/www.tme.eu\/en\/details\/smd0402-100r-1%\/0402-smd-resistors\/royal-ohm\/0402wgf1000tce\/","Guarantee":null,"OfferId":null}],"Amount":2,"PageNumber":1,"CategoryList":{"111000":2,"100299":2,"100300":2,"100578":2,"112309":2}}}`;
}else{ }else{
params1 := "Country=US&Currency=USD&Language=EN&SearchPlain="+*goodsName+"&Token="+tme_token params1 := "Country=US&Currency=USD&Language=EN&SearchPlain="+*goodsName+"&Token="+tme_token
param := "POST"+"&"+php2go.Rawurlencode(tme_api_url_product)+"&"+php2go.Rawurlencode(params1) param := "POST"+"&"+php2go.Rawurlencode(tme_api_url_product)+"&"+php2go.Rawurlencode(params1)
common.PrintDebugHtml(param) common.PrintDebugHtml(ctx,param)
sign := common.Sha1(param,tme_app_secret) //生成签名 sign := common.Sha1(param,tme_app_secret) //生成签名
postParam := params1+"&ApiSignature="+php2go.URLEncode(sign); postParam := params1+"&ApiSignature="+php2go.URLEncode(sign);
common.PrintDebugHtml(postParam) common.PrintDebugHtml(ctx,postParam)
req.SetTimeout(30 * time.Second) req.SetTimeout(30 * time.Second)
//resp, err := req.Post(params2,postParam) //resp, err := req.Post(params2,postParam)
...@@ -63,11 +63,11 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList { ...@@ -63,11 +63,11 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList {
} }
result = resp.String(); //请求外链拿到结果 result = resp.String(); //请求外链拿到结果
} }
common.PrintDebugHtml("原始数据:"+result) common.PrintDebugHtml(ctx,"原始数据:"+result)
productList := make(map[string]*model.LyClearGoodsList,0) productList := make(map[string]*model.LyClearGoodsList,0)
if gjson.Get(result,"Status").String() != "OK" { if gjson.Get(result,"Status").String() != "OK" {
common.PrintDebugHtml("请求出错-没有数据") common.PrintDebugHtml(ctx,"请求出错-没有数据")
return nil return nil
} }
apiGoodsList := gjson.Get(result, "Data.ProductList").Array() apiGoodsList := gjson.Get(result, "Data.ProductList").Array()
...@@ -121,7 +121,7 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList { ...@@ -121,7 +121,7 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList {
fmt.Println(result,SymbolList) fmt.Println(result,SymbolList)
if gjson.Get(result,"Status").String() != "OK" { if gjson.Get(result,"Status").String() != "OK" {
common.PrintDebugHtml("请求出错-价格库存") common.PrintDebugHtml(ctx,"请求出错-价格库存")
return nil return nil
} }
......
*
!.gitignore
\ No newline at end of file
package middleware
import (
"github.com/gin-gonic/gin"
"strings"
)
var Context *gin.Context
var REQUEST map[string]string //等同于php 的$_REQUEST,只接收非数组值
var REQUEST_MAP map[string][]string //接收参数的数组,只支持二维
//将gin的上下文放到全局变量
func ContextVars() gin.HandlerFunc {
return func(c *gin.Context) {
//接收所有的变量+值
REQUEST = make(map[string]string)
REQUEST_MAP = make(map[string][]string)
c.MultipartForm()
for requestName, requstValue := range c.Request.Form {
values := make([]string,0);
if len(requstValue) == 1 {
REQUEST[requestName] = strings.TrimSpace(requstValue[0])
REQUEST_MAP[requestName] = append(values,requstValue[0])
}
if len(requstValue) > 1 { //接收多维数组
var i int
for i = 0; i < len(requstValue); i++ {
values = append(values,requstValue[i])
}
REQUEST_MAP[requestName] = values
}
}
//将gin的上下文放到全局变量
Context = c
c.Next()
}
}
...@@ -9,12 +9,14 @@ import ( ...@@ -9,12 +9,14 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/gin-gonic/gin"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"math"
"math/big" "math/big"
"math/rand" "math/rand"
"reflect" "reflect"
"regexp" "regexp"
"search_server/middleware"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/vars" "search_server/pkg/vars"
"sort" "sort"
...@@ -24,11 +26,28 @@ import ( ...@@ -24,11 +26,28 @@ import (
) )
/* /*
gjson 判断某值是否存在 map
@param json string 分析json字符串
@param arrk string 分析的json键值转成map
@param targetk string 目标ID
*/
func GInArray(json string,arrK string,targetK string) bool{
s := gjson.Get(json,"brand_id").Array()
d := make([]string,0)
for _,a := range s {
c := a.String()
d = append(d,c)
}
return php2go.InArray(targetK,d)
}
/*
sha1加密(tme目前在用) sha1加密(tme目前在用)
@param string query 查询字符串 @param string query 查询字符串
@param string pri_key 加密字符串 @param string pri_key 加密字符串
@return 返回加密后的字符串 @return 返回加密后的字符串
*/ */
func Sha1(query string, pri_key string) string { func Sha1(query string, pri_key string) string {
key := []byte(pri_key) key := []byte(pri_key)
mac := hmac.New(sha1.New, key) mac := hmac.New(sha1.New, key)
...@@ -40,27 +59,27 @@ func Sha1(query string, pri_key string) string { ...@@ -40,27 +59,27 @@ func Sha1(query string, pri_key string) string {
/* /*
输出header 输出header
*/ */
func PrintDebugHeader() { func PrintDebugHeader(ctx *gin.Context) {
if middleware.REQUEST["flag"] == "101" { if ctx.Request.FormValue("flag") == "101" {
middleware.Context.Header("Content-Type", "text/html; charset=utf-8") ctx.Header("Content-Type", "text/html; charset=utf-8")
} }
} }
/* /*
格式化数据直接输出浏览器 格式化数据直接输出浏览器
@parm jsonStr 需要json输出的内容 @parm jsonStr 需要json输出的内容
*/ */
func PrintDebugHtml(jsonStr interface{}) { func PrintDebugHtml(ctx *gin.Context,jsonStr interface{}) {
if middleware.REQUEST["flag"] != "101" || jsonStr == "" { if ctx.Request.FormValue("flag") != "101" || jsonStr == "" {
return return
} }
if v, p := jsonStr.(string); p { if v, p := jsonStr.(string); p {
middleware.Context.String(200,"</br></br>-----------"+v) ctx.String(200,"</br></br>-----------"+v)
}else{ }else{
jsonData,err := json.Marshal(jsonStr) jsonData,err := json.Marshal(jsonStr)
if err != nil { if err != nil {
fmt.Println("错误:-----",err) fmt.Println("错误:-----",err)
} }
middleware.Context.String(200,"</br></br>-----------"+string(jsonData)) ctx.String(200,"</br></br>-----------"+string(jsonData))
} }
} }
...@@ -208,9 +227,8 @@ func CopyMapString(distmap map[string]string) map[string]string { ...@@ -208,9 +227,8 @@ func CopyMapString(distmap map[string]string) map[string]string {
} }
//反爬虫加密验证 //反爬虫加密验证
func CheckSignApi() (resNo int) { func CheckSignApi(ctx *gin.Context) (resNo int) {
params := make(map[string]string) params := make(map[string]string)
ctx := middleware.Context
if ctx == nil { if ctx == nil {
return return
} }
...@@ -234,7 +252,7 @@ func CheckSignApi() (resNo int) { ...@@ -234,7 +252,7 @@ func CheckSignApi() (resNo int) {
} }
//如果是内部验证通过,则内部通过 //如果是内部验证通过,则内部通过
if auth() { if auth(ctx) {
return 0 return 0
} }
...@@ -288,8 +306,7 @@ func CheckSignApi() (resNo int) { ...@@ -288,8 +306,7 @@ func CheckSignApi() (resNo int) {
} }
//内部免验证通过 //内部免验证通过
func auth() bool { func auth(ctx *gin.Context) bool {
ctx := middleware.Context
if ctx == nil { if ctx == nil {
return false return false
} }
...@@ -421,4 +438,29 @@ func MyFloat64ToStr(numb float64) string { ...@@ -421,4 +438,29 @@ func MyFloat64ToStr(numb float64) string {
func MyInt64ToStr(numb int64) string { func MyInt64ToStr(numb int64) string {
return strconv.FormatInt(numb,10) return strconv.FormatInt(numb,10)
} }
func MyIntToStr(i int) string {
return strconv.Itoa(i)
}
/*
四舍五入取多少位
@param float64 x 目标分析字符串
@param int wei 取小数多少位
*/
func MyRound(x float64,wei int) float64{
if wei == 0 {
return math.Floor(x + 0.5)
}
weis := map[int]float64{
1:10,
2:100,
3:1000,
4:10000,
5:100000,
6:1000000,
}
weishu := weis[wei]
a := math.Floor(x*weishu + 0.5)/weishu
return a
}
////////////类型转换///////////////////// ////////////类型转换/////////////////////
\ No newline at end of file
...@@ -2,11 +2,11 @@ package common ...@@ -2,11 +2,11 @@ package common
import ( import (
"encoding/json" "encoding/json"
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/ichunt2019/logger" "github.com/ichunt2019/logger"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"os" "os"
"search_server/middleware"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/gredis" "search_server/pkg/gredis"
"search_server/pkg/message" "search_server/pkg/message"
...@@ -27,10 +27,9 @@ type SearchApiLog struct { ...@@ -27,10 +27,9 @@ type SearchApiLog struct {
Method string `json:"method"` Method string `json:"method"`
} }
func AnalyzeSearchError(code int, ip, errMsg, file, line, method string) (log SearchApiLog) { func AnalyzeSearchError(ctx *gin.Context,code int, ip, errMsg, file, line, method string) (log SearchApiLog) {
//获取所有参数 //获取所有参数
request := make(map[string]string) request := make(map[string]string)
ctx := middleware.Context
ctx.MultipartForm() ctx.MultipartForm()
for name, value := range ctx.Request.Form { for name, value := range ctx.Request.Form {
if value[0] != "" { if value[0] != "" {
......
...@@ -2,8 +2,8 @@ package common ...@@ -2,8 +2,8 @@ package common
import ( import (
"encoding/json" "encoding/json"
"github.com/gin-gonic/gin"
"runtime" "runtime"
"search_server/middleware"
"strconv" "strconv"
"strings" "strings"
) )
...@@ -39,7 +39,7 @@ func ErrorResponse(errCode int, errMsg string) Response { ...@@ -39,7 +39,7 @@ func ErrorResponse(errCode int, errMsg string) Response {
} }
//统一输出,里面还要去处理jsonp //统一输出,里面还要去处理jsonp
func Output(errCode int, errMsg string, data interface{}) { func Output(ctx *gin.Context,errCode int, errMsg string, data interface{}) {
if data == nil { if data == nil {
data = []string{} data = []string{}
} }
...@@ -49,9 +49,8 @@ func Output(errCode int, errMsg string, data interface{}) { ...@@ -49,9 +49,8 @@ func Output(errCode int, errMsg string, data interface{}) {
Data: data, Data: data,
} }
if errCode >= 100 { if errCode >= 100 {
SearchApiLogger(errCode, errMsg) SearchApiLogger(ctx,errCode, errMsg)
} }
ctx := middleware.Context
if ctx.DefaultQuery("callback", "") != "" { if ctx.DefaultQuery("callback", "") != "" {
ctx.JSONP(200, response) ctx.JSONP(200, response)
} else { } else {
...@@ -66,7 +65,7 @@ func Output(errCode int, errMsg string, data interface{}) { ...@@ -66,7 +65,7 @@ func Output(errCode int, errMsg string, data interface{}) {
} }
//简单的返回数据方法 //简单的返回数据方法
func ReturnData(errCode int, errMsg string, data interface{}) { func ReturnData(ctx *gin.Context,errCode int, errMsg string, data interface{}) {
if data == nil { if data == nil {
data = []string{} data = []string{}
if errCode == 0 { if errCode == 0 {
...@@ -78,18 +77,16 @@ func ReturnData(errCode int, errMsg string, data interface{}) { ...@@ -78,18 +77,16 @@ func ReturnData(errCode int, errMsg string, data interface{}) {
ErrMsg: errMsg, ErrMsg: errMsg,
Data: data, Data: data,
} }
ctx := middleware.Context
ctx.JSON(200, response) ctx.JSON(200, response)
} }
//错误的搜索日志记录 //错误的搜索日志记录
func SearchApiLogger(code int, msg string) { func SearchApiLogger(ctx *gin.Context,code int, msg string) {
pc, file, line, _ := runtime.Caller(2) pc, file, line, _ := runtime.Caller(2)
f := runtime.FuncForPC(pc) f := runtime.FuncForPC(pc)
ctx := middleware.Context
errMsg := "提示信息:" + msg + ",请求url:" + ctx.Request.URL.String() errMsg := "提示信息:" + msg + ",请求url:" + ctx.Request.URL.String()
lineNo := strconv.Itoa(line) lineNo := strconv.Itoa(line)
searchLog := AnalyzeSearchError(code, ctx.ClientIP(), errMsg, file, lineNo, f.Name()) searchLog := AnalyzeSearchError(ctx,code, ctx.ClientIP(), errMsg, file, lineNo, f.Name())
searchLogByte, _ := json.Marshal(searchLog) searchLogByte, _ := json.Marshal(searchLog)
WriteSearchErrorLog(string(searchLogByte)) WriteSearchErrorLog(string(searchLogByte))
} }
...@@ -11,8 +11,7 @@ var ( ...@@ -11,8 +11,7 @@ var (
func SetUp(path string) (err error) { func SetUp(path string) (err error) {
//引入多个文件 //引入多个文件
Cfg, err = ini.LooseLoad(path+"/config.ini", path+"/search.ini", path+"/redis_key.ini", path+"/rabmq_key.ini", path+"/database.ini", Cfg, err = ini.LooseLoad(path+"/config.ini", path+"/database.ini", path+"/elastic.ini", path+"/rabmq.ini", path+"/redis.ini",path+"/search.ini")
path+"/redis_config.ini", path+"/message.ini")
return return
} }
......
...@@ -4,32 +4,30 @@ type RedisDatabase struct { ...@@ -4,32 +4,30 @@ type RedisDatabase struct {
Password string Password string
Host string Host string
Database string Database string
MaxIdle string MaxIdle int
MaxActive string MaxActive int
MaxAIdleTimeoutctive string MaxAIdleTimeoutctive string
Prefix string Prefix string
} }
//多数据库配置 //多数据库配置
func BuildRedisConfgs() (RedisDatabaseMap map[string]RedisDatabase) { func BuildRedisConfgs() (RedisDatabaseMap map[string]RedisDatabase) {
redis_read_max_idle,_ := Get("default_redis_read.max_idle").Int()
redis_read_max_active,_ := Get("default_redis_read.max_active").Int()
redis_write_max_idle,_ := Get("default_redis_write.max_idle").Int()
redis_write_max_active,_ := Get("default_redis_write.max_active").Int()
return map[string]RedisDatabase{ return map[string]RedisDatabase{
"search_r": { "search_r": {
Host: Get("default_redis_read.host").String(), Host: Get("default_redis_read.host").String(),
Password: Get("default_redis_read.password").String(), Password: Get("default_redis_read.password").String(),
MaxIdle: Get("default_redis_read.max_idle").String(), MaxIdle: redis_read_max_idle,
MaxActive: Get("default_redis_read.max_active").String(), MaxActive: redis_read_max_active,
}, },
"search_w": { "search_w": {
Host: Get("default_redis_write.host").String(), Host: Get("default_redis_write.host").String(),
Password: Get("default_redis_write.password").String(), Password: Get("default_redis_write.password").String(),
MaxIdle: Get("default_redis_read.max_idle").String(), MaxIdle: redis_write_max_idle,
MaxActive: Get("default_redis_read.max_active").String(), MaxActive: redis_write_max_active,
},
"api_redis": {
Host: Get("api_redis.host").String(),
Password: Get("api_redis.password").String(),
MaxIdle: Get("api_redis.max_idle").String(),
MaxActive: Get("api_redis.max_active").String(),
}, },
} }
} }
...@@ -13,7 +13,11 @@ func InitRouter() *gin.Engine { ...@@ -13,7 +13,11 @@ func InitRouter() *gin.Engine {
r.Use(gin.Logger()) r.Use(gin.Logger())
r.Use(gin.Recovery()) r.Use(gin.Recovery())
r.Use(middleware.Cors()) r.Use(middleware.Cors())
r.Use(middleware.ContextVars())
//健康监测
r.POST("Health", func(c *gin.Context) {
c.String(200,"ok")
})
//联营参数选择搜索 //联营参数选择搜索
r.POST("optimum/optimumAttr", controller.OptimumAttr) r.POST("optimum/optimumAttr", controller.OptimumAttr)
......
...@@ -2,6 +2,7 @@ package service ...@@ -2,6 +2,7 @@ package service
import ( import (
"context" "context"
"github.com/gin-gonic/gin"
"github.com/prometheus/common/log" "github.com/prometheus/common/log"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
...@@ -65,7 +66,7 @@ func getTermQuery(goodsName string) (query *elastic.BoolQuery) { ...@@ -65,7 +66,7 @@ func getTermQuery(goodsName string) (query *elastic.BoolQuery) {
} }
//推荐商品搜索 //推荐商品搜索
func Recommend(req *common.RecommendRequest) (goodsList []model.ApiGoods) { func Recommend(ctx *gin.Context,req *common.RecommendRequest) (goodsList []model.ApiGoods) {
var err error var err error
//先去请求参数,看是否是参数,如果是参数的话,需要修改请求的商品名称 //先去请求参数,看是否是参数,如果是参数的话,需要修改请求的商品名称
var goodsName string var goodsName string
...@@ -102,7 +103,7 @@ func Recommend(req *common.RecommendRequest) (goodsList []model.ApiGoods) { ...@@ -102,7 +103,7 @@ func Recommend(req *common.RecommendRequest) (goodsList []model.ApiGoods) {
goodsIdList = append(goodsIdList, goodsId) goodsIdList = append(goodsIdList, goodsId)
} }
goodsIdListStr = strings.Join(goodsIdList, ",") goodsIdListStr = strings.Join(goodsIdList, ",")
goodsList, err = GetGoodsInfoByApi(goodsIdListStr) goodsList, err = GetGoodsInfoByApi(ctx,goodsIdListStr)
return goodsList return goodsList
} }
......
package service package service
import ( import (
"github.com/gin-gonic/gin"
"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"
"search_server/middleware"
"search_server/model" "search_server/model"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/pkg/config" "search_server/pkg/config"
...@@ -14,9 +14,9 @@ import ( ...@@ -14,9 +14,9 @@ import (
) )
//获取商品信息,需要传入userId用于判断是否登陆 //获取商品信息,需要传入userId用于判断是否登陆
func GetGoodsInfo(goodsIds []string) (goodsList []model.ApiGoods, err error) { func GetGoodsInfo(ctx *gin.Context,goodsIds []string) (goodsList []model.ApiGoods, err error) {
var userIdStr string var userIdStr string
userIdStr, _ = middleware.Context.Cookie("Yo4teW_uid") userIdStr, _ = ctx.Cookie("Yo4teW_uid")
userId, _ := strconv.Atoi(userIdStr) userId, _ := strconv.Atoi(userIdStr)
isNewCustomer, isMember := CheckIsNewCustomer(userId) isNewCustomer, isMember := CheckIsNewCustomer(userId)
goodsIdsStr := strings.Join(goodsIds, ",") goodsIdsStr := strings.Join(goodsIds, ",")
...@@ -25,22 +25,22 @@ func GetGoodsInfo(goodsIds []string) (goodsList []model.ApiGoods, err error) { ...@@ -25,22 +25,22 @@ func GetGoodsInfo(goodsIds []string) (goodsList []model.ApiGoods, err error) {
"power[newCustomer]": isNewCustomer, "power[newCustomer]": isNewCustomer,
"power[member]": isMember, "power[member]": isMember,
} }
goodsList, _, err = CurlGoodsInfo(goodsIdsStr, params) goodsList, _, err = CurlGoodsInfo(ctx,goodsIdsStr, params)
return return
} }
//获取商品信息 //获取商品信息
func GetGoodsInfoByApi(goodsIdsStr string) (goodsList []model.ApiGoods, err error) { func GetGoodsInfoByApi(ctx *gin.Context,goodsIdsStr string) (goodsList []model.ApiGoods, err error) {
params := req.Param{ params := req.Param{
"goods_id": goodsIdsStr, "goods_id": goodsIdsStr,
} }
goodsList, _, err = CurlGoodsInfo(goodsIdsStr, params) goodsList, _, err = CurlGoodsInfo(ctx,goodsIdsStr, params)
return return
} }
//isMap:是否以字典形式返回值,默认是数组 //isMap:是否以字典形式返回值,默认是数组
func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiGoods, goodsListMap map[string]model.ApiGoods, err error) { func CurlGoodsInfo(ctx *gin.Context,goodsIdsStr string, params req.Param) (goodsList []model.ApiGoods, goodsListMap map[string]model.ApiGoods, err error) {
goodsIdList := strings.Split(goodsIdsStr, ",") goodsIdList := strings.Split(goodsIdsStr, ",")
if len(goodsIdList) == 0 { if len(goodsIdList) == 0 {
return return
...@@ -54,9 +54,9 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG ...@@ -54,9 +54,9 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiG
} }
resp, err := req.Post(goodsServerUrl+"/synchronization", params) resp, err := req.Post(goodsServerUrl+"/synchronization", params)
common.PrintDebugHtml(goodsServerUrl+"/synchronization") //debug common.PrintDebugHtml(ctx,goodsServerUrl+"/synchronization") //debug
common.PrintDebugHtml(params) //debug common.PrintDebugHtml(ctx,params) //debug
common.PrintDebugHtml(resp.String()) //debug common.PrintDebugHtml(ctx,resp.String()) //debug
if err != nil { if err != nil {
return return
......
package ly package ly
import ( import (
"github.com/gin-gonic/gin"
"github.com/imroc/req" "github.com/imroc/req"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"search_server/middleware"
"search_server/model" "search_server/model"
"search_server/pkg/common" "search_server/pkg/common"
"strconv" "strconv"
...@@ -18,12 +18,12 @@ const arrow_api_url string = "http://api.arrow.com/itemservice/v3/en/search/toke ...@@ -18,12 +18,12 @@ const arrow_api_url string = "http://api.arrow.com/itemservice/v3/en/search/toke
/* /*
单独请求arrow获取数据 单独请求arrow获取数据
*/ */
func ArrowApi(goodsName *string) string { func ArrowApi(ctx *gin.Context,goodsName *string) string {
if *goodsName == "" { if *goodsName == "" {
return "" return ""
} }
var result string; var result string;
if middleware.REQUEST["flags"] == "-1" { //原始数据调试 if ctx.Request.FormValue("flags") == "-1" { //原始数据调试
result = `{"itemserviceresult":{"serviceMetaData":[{"version":"3.0.2"}],"transactionArea":[{"response":{"returnCode":"0","returnMsg":"","success":true},"responseSequence":{"transactionTime":"8.395 ms","queryTime":"0 ms","dbTime":"0 ms","totalItems":1,"resources":[],"qq":150}}],"data":[{"resources":[{"type":"search","uri":"https:\/\/www.arrow.com\/en\/products\/search?q=nrc06j240trf"}],"PartList":[{"itemId":1731466,"partNum":"NRC06J240TRF","manufacturer":{"mfrCd":"NIC","mfrName":"NIC Components"},"desc":"Res Thick Film 0603 24 Ohm 5% 0.1W(1\/10W) \u00b1200ppm\/\u00b0C Pad SMD Automotive T\/R","packageType":"","resources":[{"type":"cloud_part_detail","uri":"https:\/\/www.arrow.com\/en\/products\/nrc06j240trf\/nic-components"},{"type":"api_part_detail","uri":"http:\/\/api.arrow.com\/itemservice\/v2\/en\/detail?mfrCd=NIC&partNum=NRC06J240TRF"},{"type":"part_detail","uri":"http:\/\/api.arrow.com\/itemservice\/v2\/en\/detail?pkey=d4reVMqt21-TTjZ2c-CxBfkjR7Jr9jVALOn2A_ewFOo"}],"EnvData":{"compliance":[{"displayLabel":"eurohs","displayValue":"Compliant with Exemption"},{"displayLabel":"cnrohs","displayValue":"Compliant with Exemption"}]},"InvOrg":{"sources":[{"currency":"USD","sourceCd":"VERICAL","displayName":"Verical","sourceParts":[{"packSize":5000,"minimumOrderQuantity":5000,"sourcePartNumber":"","sourcePartId":"20192988","Prices":{"resaleList":[{"displayPrice":"0.0022","price":0.0022,"minQty":22778,"maxQty":99999999}]},"Availability":[{"fohQty":65000,"availabilityCd":"INSTK","availabilityMessage":"In Stock","pipeline":[]}],"customerSpecificPricing":[],"customerSpecificInventory":[],"dateCode":"","resources":[{"type":"detail","uri":"https:\/\/www.verical.com\/pd\/nic-fixed-single---surface-mount-NRC06J240TRF-2087567"},{"type":"add_to_cart","uri":"https:\/\/www.verical.com\/pd\/nic-fixed-single---surface-mount-NRC06J240TRF-2087567"}],"inStock":true,"mfrLeadTime":0,"isNcnr":false,"isNpi":false,"isASA":false,"requestQuantity":0,"productCode":"","iccLevels":[],"cloudMfrCode":"","eccnCode":"EAR99","htsCode":"8533.21.00.30","countryOfOrigin":"TW","locationId":49,"containerType":""},{"packSize":1,"minimumOrderQuantity":16667,"sourcePartNumber":"","sourcePartId":"30238877","Prices":{"resaleList":[{"displayPrice":"0.00050","price":0.0005,"minQty":16667,"maxQty":99999999}]},"Availability":[{"fohQty":18977,"availabilityCd":"INSTK","availabilityMessage":"In Stock","pipeline":[]}],"customerSpecificPricing":[],"customerSpecificInventory":[],"dateCode":"1710","resources":[{"type":"detail","uri":"https:\/\/www.verical.com\/pd\/nic-fixed-single---surface-mount-NRC06J240TRF-2087567"},{"type":"add_to_cart","uri":"https:\/\/www.verical.com\/pd\/nic-fixed-single---surface-mount-NRC06J240TRF-2087567"}],"inStock":true,"mfrLeadTime":0,"isNcnr":false,"isNpi":false,"isASA":false,"requestQuantity":0,"productCode":"","iccLevels":[],"cloudMfrCode":"","eccnCode":"EAR99","htsCode":"8533.21.00.30","countryOfOrigin":"TW","locationId":175,"containerType":""}]},{"currency":"USD","sourceCd":"ACNA","displayName":"Arrow Americas","sourceParts":[{"packSize":5000,"minimumOrderQuantity":5000,"sourcePartNumber":"","sourcePartId":"V36:1790_16243328","Prices":{"resaleList":[{"displayPrice":"0.002","price":0.002,"minQty":5000,"maxQty":999999999}]},"Availability":[{"fohQty":0,"availabilityCd":"NOSTK","availabilityMessage":"No Stock","pipeline":[]}],"customerSpecificPricing":[],"customerSpecificInventory":[],"dateCode":"","resources":[{"type":"detail","uri":"https:\/\/www.arrow.com\/en\/products\/nrc06j240trf\/nic-components"},{"type":"add_to_cart","uri":"https:\/\/www.arrow.com\/en\/products\/nrc06j240trf\/nic-components"}],"inStock":false,"mfrLeadTime":20,"isNcnr":false,"isNpi":false,"isASA":false,"requestQuantity":0,"productCode":"","iccLevels":[],"cloudMfrCode":"","eccnCode":"EAR99","htsCode":"8533.21.00.30","locationId":175,"containerType":""},{"packSize":1,"minimumOrderQuantity":1,"sourcePartNumber":"","sourcePartId":"V72:2272_16243328","Prices":{"resaleList":[{"displayPrice":"0.0046","price":0.0046,"minQty":1,"maxQty":9},{"displayPrice":"0.0025","price":0.0025,"minQty":10,"maxQty":99},{"displayPrice":"0.0012","price":0.0012,"minQty":100,"maxQty":499},{"displayPrice":"0.0011","price":0.0011,"minQty":500,"maxQty":999},{"displayPrice":"0.00070","price":0.0007,"minQty":1000,"maxQty":2999},{"displayPrice":"0.00050","price":0.0005,"minQty":3000,"maxQty":999999999}]},"Availability":[{"fohQty":18977,"availabilityCd":"CSTRP","availabilityMessage":"Cut Strips","pipeline":[]}],"customerSpecificPricing":[],"customerSpecificInventory":[],"dateCode":"1710","resources":[{"type":"detail","uri":"https:\/\/www.arrow.com\/en\/products\/nrc06j240trf\/nic-components"},{"type":"add_to_cart","uri":"https:\/\/www.arrow.com\/en\/products\/nrc06j240trf\/nic-components"}],"inStock":true,"mfrLeadTime":20,"isNcnr":false,"isNpi":false,"isASA":false,"requestQuantity":0,"productCode":"","iccLevels":[],"cloudMfrCode":"","eccnCode":"EAR99","htsCode":"8533.21.00.30","countryOfOrigin":"TW","locationId":175,"containerType":"Cut Strips"}]}]},"hasDatasheet":true}]}]}}`; result = `{"itemserviceresult":{"serviceMetaData":[{"version":"3.0.2"}],"transactionArea":[{"response":{"returnCode":"0","returnMsg":"","success":true},"responseSequence":{"transactionTime":"8.395 ms","queryTime":"0 ms","dbTime":"0 ms","totalItems":1,"resources":[],"qq":150}}],"data":[{"resources":[{"type":"search","uri":"https:\/\/www.arrow.com\/en\/products\/search?q=nrc06j240trf"}],"PartList":[{"itemId":1731466,"partNum":"NRC06J240TRF","manufacturer":{"mfrCd":"NIC","mfrName":"NIC Components"},"desc":"Res Thick Film 0603 24 Ohm 5% 0.1W(1\/10W) \u00b1200ppm\/\u00b0C Pad SMD Automotive T\/R","packageType":"","resources":[{"type":"cloud_part_detail","uri":"https:\/\/www.arrow.com\/en\/products\/nrc06j240trf\/nic-components"},{"type":"api_part_detail","uri":"http:\/\/api.arrow.com\/itemservice\/v2\/en\/detail?mfrCd=NIC&partNum=NRC06J240TRF"},{"type":"part_detail","uri":"http:\/\/api.arrow.com\/itemservice\/v2\/en\/detail?pkey=d4reVMqt21-TTjZ2c-CxBfkjR7Jr9jVALOn2A_ewFOo"}],"EnvData":{"compliance":[{"displayLabel":"eurohs","displayValue":"Compliant with Exemption"},{"displayLabel":"cnrohs","displayValue":"Compliant with Exemption"}]},"InvOrg":{"sources":[{"currency":"USD","sourceCd":"VERICAL","displayName":"Verical","sourceParts":[{"packSize":5000,"minimumOrderQuantity":5000,"sourcePartNumber":"","sourcePartId":"20192988","Prices":{"resaleList":[{"displayPrice":"0.0022","price":0.0022,"minQty":22778,"maxQty":99999999}]},"Availability":[{"fohQty":65000,"availabilityCd":"INSTK","availabilityMessage":"In Stock","pipeline":[]}],"customerSpecificPricing":[],"customerSpecificInventory":[],"dateCode":"","resources":[{"type":"detail","uri":"https:\/\/www.verical.com\/pd\/nic-fixed-single---surface-mount-NRC06J240TRF-2087567"},{"type":"add_to_cart","uri":"https:\/\/www.verical.com\/pd\/nic-fixed-single---surface-mount-NRC06J240TRF-2087567"}],"inStock":true,"mfrLeadTime":0,"isNcnr":false,"isNpi":false,"isASA":false,"requestQuantity":0,"productCode":"","iccLevels":[],"cloudMfrCode":"","eccnCode":"EAR99","htsCode":"8533.21.00.30","countryOfOrigin":"TW","locationId":49,"containerType":""},{"packSize":1,"minimumOrderQuantity":16667,"sourcePartNumber":"","sourcePartId":"30238877","Prices":{"resaleList":[{"displayPrice":"0.00050","price":0.0005,"minQty":16667,"maxQty":99999999}]},"Availability":[{"fohQty":18977,"availabilityCd":"INSTK","availabilityMessage":"In Stock","pipeline":[]}],"customerSpecificPricing":[],"customerSpecificInventory":[],"dateCode":"1710","resources":[{"type":"detail","uri":"https:\/\/www.verical.com\/pd\/nic-fixed-single---surface-mount-NRC06J240TRF-2087567"},{"type":"add_to_cart","uri":"https:\/\/www.verical.com\/pd\/nic-fixed-single---surface-mount-NRC06J240TRF-2087567"}],"inStock":true,"mfrLeadTime":0,"isNcnr":false,"isNpi":false,"isASA":false,"requestQuantity":0,"productCode":"","iccLevels":[],"cloudMfrCode":"","eccnCode":"EAR99","htsCode":"8533.21.00.30","countryOfOrigin":"TW","locationId":175,"containerType":""}]},{"currency":"USD","sourceCd":"ACNA","displayName":"Arrow Americas","sourceParts":[{"packSize":5000,"minimumOrderQuantity":5000,"sourcePartNumber":"","sourcePartId":"V36:1790_16243328","Prices":{"resaleList":[{"displayPrice":"0.002","price":0.002,"minQty":5000,"maxQty":999999999}]},"Availability":[{"fohQty":0,"availabilityCd":"NOSTK","availabilityMessage":"No Stock","pipeline":[]}],"customerSpecificPricing":[],"customerSpecificInventory":[],"dateCode":"","resources":[{"type":"detail","uri":"https:\/\/www.arrow.com\/en\/products\/nrc06j240trf\/nic-components"},{"type":"add_to_cart","uri":"https:\/\/www.arrow.com\/en\/products\/nrc06j240trf\/nic-components"}],"inStock":false,"mfrLeadTime":20,"isNcnr":false,"isNpi":false,"isASA":false,"requestQuantity":0,"productCode":"","iccLevels":[],"cloudMfrCode":"","eccnCode":"EAR99","htsCode":"8533.21.00.30","locationId":175,"containerType":""},{"packSize":1,"minimumOrderQuantity":1,"sourcePartNumber":"","sourcePartId":"V72:2272_16243328","Prices":{"resaleList":[{"displayPrice":"0.0046","price":0.0046,"minQty":1,"maxQty":9},{"displayPrice":"0.0025","price":0.0025,"minQty":10,"maxQty":99},{"displayPrice":"0.0012","price":0.0012,"minQty":100,"maxQty":499},{"displayPrice":"0.0011","price":0.0011,"minQty":500,"maxQty":999},{"displayPrice":"0.00070","price":0.0007,"minQty":1000,"maxQty":2999},{"displayPrice":"0.00050","price":0.0005,"minQty":3000,"maxQty":999999999}]},"Availability":[{"fohQty":18977,"availabilityCd":"CSTRP","availabilityMessage":"Cut Strips","pipeline":[]}],"customerSpecificPricing":[],"customerSpecificInventory":[],"dateCode":"1710","resources":[{"type":"detail","uri":"https:\/\/www.arrow.com\/en\/products\/nrc06j240trf\/nic-components"},{"type":"add_to_cart","uri":"https:\/\/www.arrow.com\/en\/products\/nrc06j240trf\/nic-components"}],"inStock":true,"mfrLeadTime":20,"isNcnr":false,"isNpi":false,"isASA":false,"requestQuantity":0,"productCode":"","iccLevels":[],"cloudMfrCode":"","eccnCode":"EAR99","htsCode":"8533.21.00.30","countryOfOrigin":"TW","locationId":175,"containerType":"Cut Strips"}]}]},"hasDatasheet":true}]}]}}`;
}else{ }else{
req.SetTimeout(10 * time.Second) req.SetTimeout(10 * time.Second)
...@@ -34,7 +34,7 @@ func ArrowApi(goodsName *string) string { ...@@ -34,7 +34,7 @@ func ArrowApi(goodsName *string) string {
} }
result = resp.String(); //请求外链拿到结果 result = resp.String(); //请求外链拿到结果
} }
common.PrintDebugHtml("原始数据:"+result) common.PrintDebugHtml(ctx,"原始数据:"+result)
return result return result
} }
...@@ -44,14 +44,14 @@ func ArrowApi(goodsName *string) string { ...@@ -44,14 +44,14 @@ func ArrowApi(goodsName *string) string {
@param string apiResult 请求arrow接口返回的所有数据,关键词查询 @param string apiResult 请求arrow接口返回的所有数据,关键词查询
@return 返回格式化后的数据 @return 返回格式化后的数据
*/ */
func GetDataArrow(apiResult *string,stype string) map[string]*model.LyClearGoodsList { func GetDataArrow(ctx *gin.Context,apiResult *string,stype string) map[string]*model.LyClearGoodsList {
if apiResult == nil { if apiResult == nil {
return nil return nil
} }
productList := make(map[string]*model.LyClearGoodsList,0) productList := make(map[string]*model.LyClearGoodsList,0)
if gjson.Get(*apiResult,"itemserviceresult.data").String() == "" { if gjson.Get(*apiResult,"itemserviceresult.data").String() == "" {
common.PrintDebugHtml("返回数据存在问题"+*apiResult) common.PrintDebugHtml(ctx,"返回数据存在问题"+*apiResult)
return nil return nil
} }
if stype == "1" { if stype == "1" {
......
package ly package ly
import ( import (
"github.com/gin-gonic/gin"
"github.com/imroc/req" "github.com/imroc/req"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"search_server/middleware"
"search_server/model" "search_server/model"
"search_server/pkg/common" "search_server/pkg/common"
"strconv" "strconv"
...@@ -14,13 +14,13 @@ import ( ...@@ -14,13 +14,13 @@ import (
const mouser_api_url string = "https://api.mouser.com/api/v1/search/partnumber?apiKey=0a11fa6f-ddcb-4ddf-9947-e42b2f3b4723" const mouser_api_url string = "https://api.mouser.com/api/v1/search/partnumber?apiKey=0a11fa6f-ddcb-4ddf-9947-e42b2f3b4723"
//mouser请求外链 //mouser请求外链
func OutLinkMouser(goodsName *string) map[string]*model.LyClearGoodsList { func OutLinkMouser(ctx *gin.Context,goodsName *string) map[string]*model.LyClearGoodsList {
if *goodsName == "" { if *goodsName == "" {
return nil return nil
} }
var result string; var result string;
if middleware.REQUEST["flags"] == "-1" { //原始数据调试 if ctx.Request.FormValue("flags") == "-1" { //原始数据调试
result = `{"Errors":[],"SearchResults":{"NumberOfResult":80,"Parts":[{"Availability":"15242 有庫存","DataSheetUrl":"","Description":"運算放大器 - 運放器 1.2 MHz industry standard dual-channel amplifier with -40C to 85C operation 8-SOIC -40 to 85","FactoryStock":"0","ImagePath":"https://www.mouser.com/images/texasinstruments/images/ITP_TI_SOIC-8_D_t.jpg","Category":"運算放大器 - 運放器","LeadTime":"42 日數","LifecycleStatus":"New Product","Manufacturer":"Texas Instruments","ManufacturerPartNumber":"LM358BIDR","Min":"1","Mult":"1","MouserPartNumber":"595-LM358BIDR","ProductAttributes":[{"AttributeName":"封裝","AttributeValue":"Cut Tape"},{"AttributeName":"封裝","AttributeValue":"MouseReel"},{"AttributeName":"封裝","AttributeValue":"Reel"},{"AttributeName":"標準包裝數量","AttributeValue":"2500"}],"PriceBreaks":[{"Quantity":1,"Price":"$0.44","Currency":"USD"},{"Quantity":10,"Price":"$0.287","Currency":"USD"},{"Quantity":100,"Price":"$0.154","Currency":"USD"}],"AlternatePackagings":null,"ProductDetailUrl":"https://www.mouser.hk/ProductDetail/Texas-Instruments/LM358BIDR?qs=byeeYqUIh0MUqg09TCRNgA%3D%3D","Reeling":true,"ROHSStatus":"RoHS Compliant","SuggestedReplacement":"","MultiSimBlue":0,"ProductCompliance":[{"ComplianceName":"CNHTS","ComplianceValue":"8542339000"},{"ComplianceName":"USHTS","ComplianceValue":"8542330001"},{"ComplianceName":"TARIC","ComplianceValue":"8542330000"},{"ComplianceName":"ECCN","ComplianceValue":"EAR99"}]}]}}`; result = `{"Errors":[],"SearchResults":{"NumberOfResult":80,"Parts":[{"Availability":"15242 有庫存","DataSheetUrl":"","Description":"運算放大器 - 運放器 1.2 MHz industry standard dual-channel amplifier with -40C to 85C operation 8-SOIC -40 to 85","FactoryStock":"0","ImagePath":"https://www.mouser.com/images/texasinstruments/images/ITP_TI_SOIC-8_D_t.jpg","Category":"運算放大器 - 運放器","LeadTime":"42 日數","LifecycleStatus":"New Product","Manufacturer":"Texas Instruments","ManufacturerPartNumber":"LM358BIDR","Min":"1","Mult":"1","MouserPartNumber":"595-LM358BIDR","ProductAttributes":[{"AttributeName":"封裝","AttributeValue":"Cut Tape"},{"AttributeName":"封裝","AttributeValue":"MouseReel"},{"AttributeName":"封裝","AttributeValue":"Reel"},{"AttributeName":"標準包裝數量","AttributeValue":"2500"}],"PriceBreaks":[{"Quantity":1,"Price":"$0.44","Currency":"USD"},{"Quantity":10,"Price":"$0.287","Currency":"USD"},{"Quantity":100,"Price":"$0.154","Currency":"USD"}],"AlternatePackagings":null,"ProductDetailUrl":"https://www.mouser.hk/ProductDetail/Texas-Instruments/LM358BIDR?qs=byeeYqUIh0MUqg09TCRNgA%3D%3D","Reeling":true,"ROHSStatus":"RoHS Compliant","SuggestedReplacement":"","MultiSimBlue":0,"ProductCompliance":[{"ComplianceName":"CNHTS","ComplianceValue":"8542339000"},{"ComplianceName":"USHTS","ComplianceValue":"8542330001"},{"ComplianceName":"TARIC","ComplianceValue":"8542330000"},{"ComplianceName":"ECCN","ComplianceValue":"EAR99"}]}]}}`;
}else{ }else{
req.SetTimeout(10 * time.Second) req.SetTimeout(10 * time.Second)
...@@ -31,7 +31,7 @@ func OutLinkMouser(goodsName *string) map[string]*model.LyClearGoodsList { ...@@ -31,7 +31,7 @@ func OutLinkMouser(goodsName *string) map[string]*model.LyClearGoodsList {
} }
result = resp.String(); //请求外链拿到结果 result = resp.String(); //请求外链拿到结果
} }
common.PrintDebugHtml("原始数据:"+result) common.PrintDebugHtml(ctx,"原始数据:"+result)
productList := make(map[string]*model.LyClearGoodsList,0) productList := make(map[string]*model.LyClearGoodsList,0)
......
package ly package ly
import ( import (
"github.com/gin-gonic/gin"
"github.com/imroc/req" "github.com/imroc/req"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"search_server/middleware"
"search_server/model" "search_server/model"
"search_server/pkg/common" "search_server/pkg/common"
"strconv" "strconv"
...@@ -23,7 +23,7 @@ const tme_token string = "3381c9d5d9663be68eb69ea3ce00af3a2b5789094c7cd488a4"// ...@@ -23,7 +23,7 @@ const tme_token string = "3381c9d5d9663be68eb69ea3ce00af3a2b5789094c7cd488a4"//
const tme_app_secret string = "a1d8647fa38710140628" //账号 const tme_app_secret string = "a1d8647fa38710140628" //账号
//tme请求外链 //tme请求外链
func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList { func OutLinkTme(ctx *gin.Context,goodsName *string) map[string]*model.LyClearGoodsList {
if *goodsName == "" { if *goodsName == "" {
return nil return nil
} }
...@@ -32,12 +32,12 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList { ...@@ -32,12 +32,12 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList {
SymbolList string //外链原始数据的goods_sn SymbolList string //外链原始数据的goods_sn
); );
if middleware.REQUEST["flags"] == "-1" { //原始数据调试 if ctx.Request.FormValue("flags") == "-1" { //原始数据调试
result = `{"Status":"OK","Data":{"ProductList":[{"Symbol":"0402WGF1000TCE","CustomerSymbol":"","OriginalSymbol":"0402WGF1000TCE","Producer":"ROYAL OHM","Description":"Resistor: thick film; SMD; 0402; 100\u03a9; 63mW; \u00b11%; -55\u00f7155\u00b0C","CategoryId":"100578","Category":"0402 SMD resistors","Photo":"\/\/ce8dc832c.cloudimg.io\/fit\/640x480\/n@4760e4647bc7d903de9205a51f321b69cdbed098\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg?mark_url=_tme-wrk_%2Ftme_new_render3d.png&mark_pos=center&mark_size=100pp","Thumbnail":"\/\/ce8dc832c.cloudimg.io\/fit\/100x75\/webp@3ec3fbcb8427a46b791b093cd6e191b483328d8a\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg","Weight":0.01,"WeightUnit":"g","SuppliedAmount":0,"MinAmount":10000,"Multiples":10000,"ProductStatusList":[],"Unit":"pcs","ProductInformationPage":"\/\/www.tme.eu\/en\/details\/0402wgf1000tce\/0402-smd-resistors\/royal-ohm\/","Guarantee":null,"OfferId":null},{"Symbol":"SMD0402-100R-1%","CustomerSymbol":"","OriginalSymbol":"0402WGF1000TCE","Producer":"ROYAL OHM","Description":"Resistor: thick film; SMD; 0402; 100\u03a9; 63mW; \u00b11%; -55\u00f7155\u00b0C","CategoryId":"100578","Category":"0402 SMD resistors","Photo":"\/\/ce8dc832c.cloudimg.io\/fit\/640x480\/n@4760e4647bc7d903de9205a51f321b69cdbed098\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg?mark_url=_tme-wrk_%2Ftme_new_render3d.png&mark_pos=center&mark_size=100pp","Thumbnail":"\/\/ce8dc832c.cloudimg.io\/fit\/100x75\/webp@3ec3fbcb8427a46b791b093cd6e191b483328d8a\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg","Weight":0.006,"WeightUnit":"g","SuppliedAmount":0,"MinAmount":100,"Multiples":100,"ProductStatusList":[],"Unit":"pcs","ProductInformationPage":"\/\/www.tme.eu\/en\/details\/smd0402-100r-1%\/0402-smd-resistors\/royal-ohm\/0402wgf1000tce\/","Guarantee":null,"OfferId":null}],"Amount":2,"PageNumber":1,"CategoryList":{"111000":2,"100299":2,"100300":2,"100578":2,"112309":2}}}`; result = `{"Status":"OK","Data":{"ProductList":[{"Symbol":"0402WGF1000TCE","CustomerSymbol":"","OriginalSymbol":"0402WGF1000TCE","Producer":"ROYAL OHM","Description":"Resistor: thick film; SMD; 0402; 100\u03a9; 63mW; \u00b11%; -55\u00f7155\u00b0C","CategoryId":"100578","Category":"0402 SMD resistors","Photo":"\/\/ce8dc832c.cloudimg.io\/fit\/640x480\/n@4760e4647bc7d903de9205a51f321b69cdbed098\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg?mark_url=_tme-wrk_%2Ftme_new_render3d.png&mark_pos=center&mark_size=100pp","Thumbnail":"\/\/ce8dc832c.cloudimg.io\/fit\/100x75\/webp@3ec3fbcb8427a46b791b093cd6e191b483328d8a\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg","Weight":0.01,"WeightUnit":"g","SuppliedAmount":0,"MinAmount":10000,"Multiples":10000,"ProductStatusList":[],"Unit":"pcs","ProductInformationPage":"\/\/www.tme.eu\/en\/details\/0402wgf1000tce\/0402-smd-resistors\/royal-ohm\/","Guarantee":null,"OfferId":null},{"Symbol":"SMD0402-100R-1%","CustomerSymbol":"","OriginalSymbol":"0402WGF1000TCE","Producer":"ROYAL OHM","Description":"Resistor: thick film; SMD; 0402; 100\u03a9; 63mW; \u00b11%; -55\u00f7155\u00b0C","CategoryId":"100578","Category":"0402 SMD resistors","Photo":"\/\/ce8dc832c.cloudimg.io\/fit\/640x480\/n@4760e4647bc7d903de9205a51f321b69cdbed098\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg?mark_url=_tme-wrk_%2Ftme_new_render3d.png&mark_pos=center&mark_size=100pp","Thumbnail":"\/\/ce8dc832c.cloudimg.io\/fit\/100x75\/webp@3ec3fbcb8427a46b791b093cd6e191b483328d8a\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg","Weight":0.006,"WeightUnit":"g","SuppliedAmount":0,"MinAmount":100,"Multiples":100,"ProductStatusList":[],"Unit":"pcs","ProductInformationPage":"\/\/www.tme.eu\/en\/details\/smd0402-100r-1%\/0402-smd-resistors\/royal-ohm\/0402wgf1000tce\/","Guarantee":null,"OfferId":null}],"Amount":2,"PageNumber":1,"CategoryList":{"111000":2,"100299":2,"100300":2,"100578":2,"112309":2}}}`;
}else{ }else{
params1 := "Country=US&Currency=USD&Language=EN&SearchPlain="+*goodsName+"&Token="+tme_token params1 := "Country=US&Currency=USD&Language=EN&SearchPlain="+*goodsName+"&Token="+tme_token
param := "POST"+"&"+php2go.Rawurlencode(tme_api_url_product)+"&"+php2go.Rawurlencode(params1) param := "POST"+"&"+php2go.Rawurlencode(tme_api_url_product)+"&"+php2go.Rawurlencode(params1)
common.PrintDebugHtml(param) common.PrintDebugHtml(ctx,param)
sign := common.Sha1(param,tme_app_secret) //生成签名 sign := common.Sha1(param,tme_app_secret) //生成签名
req.SetTimeout(10 * time.Second) req.SetTimeout(10 * time.Second)
...@@ -57,11 +57,11 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList { ...@@ -57,11 +57,11 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList {
} }
result = resp.String(); //请求外链拿到结果 result = resp.String(); //请求外链拿到结果
} }
common.PrintDebugHtml("原始数据:"+result) common.PrintDebugHtml(ctx,"原始数据:"+result)
productList := make(map[string]*model.LyClearGoodsList,0) productList := make(map[string]*model.LyClearGoodsList,0)
if gjson.Get(result,"Status").String() != "OK" { if gjson.Get(result,"Status").String() != "OK" {
common.PrintDebugHtml("请求出错-没有数据") common.PrintDebugHtml(ctx,"请求出错-没有数据")
return nil return nil
} }
apiGoodsList := gjson.Get(result, "Data.ProductList").Array() apiGoodsList := gjson.Get(result, "Data.ProductList").Array()
...@@ -104,7 +104,7 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList { ...@@ -104,7 +104,7 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList {
//查询价格库存 //查询价格库存
params_s2 := "Country=US&Currency=USD&Language=EN"+SymbolList+"&Token="+tme_token params_s2 := "Country=US&Currency=USD&Language=EN"+SymbolList+"&Token="+tme_token
param_s3 := "POST"+"&"+php2go.Rawurlencode(tme_api_url_stock)+"&"+php2go.Rawurlencode(params_s2) param_s3 := "POST"+"&"+php2go.Rawurlencode(tme_api_url_stock)+"&"+php2go.Rawurlencode(params_s2)
common.PrintDebugHtml(param_s3) common.PrintDebugHtml(ctx,param_s3)
req.SetTimeout(10 * time.Second) req.SetTimeout(10 * time.Second)
req.Debug = true req.Debug = true
...@@ -118,7 +118,7 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList { ...@@ -118,7 +118,7 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList {
"ApiSignature":common.Sha1(param_s3,tme_app_secret), "ApiSignature":common.Sha1(param_s3,tme_app_secret),
} }
common.PrintDebugHtml(postParam2) common.PrintDebugHtml(ctx,postParam2)
resp2, err := req.Post(tme_api_url_stock,req.BodyJSON(postParam2)) resp2, err := req.Post(tme_api_url_stock,req.BodyJSON(postParam2))
if err != nil { if err != nil {
...@@ -127,7 +127,7 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList { ...@@ -127,7 +127,7 @@ func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList {
} }
result_s2 := resp2.String() result_s2 := resp2.String()
if gjson.Get(result_s2,"Status").String() != "OK" { if gjson.Get(result_s2,"Status").String() != "OK" {
common.PrintDebugHtml("请求出错-价格库存:"+result_s2) common.PrintDebugHtml(ctx,"请求出错-价格库存:"+result_s2)
return nil return nil
} }
......
package service package service
import ( import (
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/iancoleman/orderedmap" "github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"search_server/middleware"
"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/es"
"search_server/pkg/gredis" "search_server/pkg/gredis"
"search_server/service/query" "search_server/service/query"
"strconv"
"strings" "strings"
) )
type OptimumService struct { type OptimumService struct {
} }
var REQUEST_MAP map[string][]string //接收参数的数组,只支持二维
/* /*
整理接收数组参数 整理接收数组参数
*/ */
func (qs *OptimumService) getQueryAttr() (map[string]map[string]string){ func (qs *OptimumService) getQueryAttr(ctx *gin.Context) (map[string]map[string]string){
//接收参数,接收参数搜索 //接收参数,接收参数搜索
allAttrs := make(map[string]map[string]string,0) allAttrs := make(map[string]map[string]string,0)
for k,v := range middleware.REQUEST_MAP { REQUEST_MAP := make(map[string][]string)
ctx.MultipartForm()
for requestName, requstValue := range ctx.Request.Form {
if len(requstValue) > 1 { //接收多维数组
values := make([]string,0);
var i int
for i = 0; i < len(requstValue); i++ {
values = append(values,requstValue[i])
}
REQUEST_MAP[requestName] = values
}
}
for k,v := range REQUEST_MAP {
subAttrs := make(map[string]string,0) subAttrs := make(map[string]string,0)
var i int; var i int;
for i = 0;i<len(v);i++ { for i = 0;i<len(v);i++ {
...@@ -66,10 +81,10 @@ func (qs *OptimumService) getQueryAttr() (map[string]map[string]string){ ...@@ -66,10 +81,10 @@ func (qs *OptimumService) getQueryAttr() (map[string]map[string]string){
class_id2=3&attr[brand][]=30485&attr[brand][]=30509&attr[brand][]=37727&attr[1002][]=2001 class_id2=3&attr[brand][]=30485&attr[brand][]=30509&attr[brand][]=37727&attr[1002][]=2001
*/ */
func (qs *OptimumService) GetOptimumAttr() (results model.LyResponse) { func (qs *OptimumService) GetOptimumAttr(ctx *gin.Context) (results model.LyResponse) {
allAttrs := qs.getQueryAttr() allAttrs := qs.getQueryAttr(ctx)
//获取查询条件 //获取查询条件
queryString, err := query.GetOptimumAttrQuery(allAttrs,1) queryString, err := query.GetOptimumAttrQuery(ctx,allAttrs,1)
if err != nil { if err != nil {
results.ErrorCode = 1001; results.ErrorCode = 1001;
results.ErrorMsg = err.Error() results.ErrorMsg = err.Error()
...@@ -82,7 +97,7 @@ func (qs *OptimumService) GetOptimumAttr() (results model.LyResponse) { ...@@ -82,7 +97,7 @@ func (qs *OptimumService) GetOptimumAttr() (results model.LyResponse) {
results.ErrorMsg = err.Error() results.ErrorMsg = err.Error()
return return
} }
common.PrintDebugHtml(esResult) common.PrintDebugHtml(ctx,esResult)
//判断返回总条数 //判断返回总条数
total := gjson.Get(esResult, "hits.total").Int() total := gjson.Get(esResult, "hits.total").Int()
...@@ -139,7 +154,7 @@ func (qs *OptimumService) GetOptimumAttr() (results model.LyResponse) { ...@@ -139,7 +154,7 @@ func (qs *OptimumService) GetOptimumAttr() (results model.LyResponse) {
attr_value_name := valueMap["key"].String() //属性值:1V attr_value_name := valueMap["key"].String() //属性值:1V
attr_value_id,_ := gredis.String(redisConn.Do("HGET",config.Get("redis_all.class_attr_value_by_val").String(),attr_value_name)) //查询唯一值,反查 attr_value_id,_ := gredis.String(redisConn.Do("HGET",config.Get("redis_all.class_attr_value_by_val").String(),attr_value_name)) //查询唯一值,反查
ischeck := "0" //是否选中 ischeck := "0" //是否选中redigo
if _, ok := allAttrs[attr_value_id][attr_value_id]; ok { if _, ok := allAttrs[attr_value_id][attr_value_id]; ok {
ischeck = "1" ischeck = "1"
} }
...@@ -158,11 +173,11 @@ func (qs *OptimumService) GetOptimumAttr() (results model.LyResponse) { ...@@ -158,11 +173,11 @@ func (qs *OptimumService) GetOptimumAttr() (results model.LyResponse) {
/* /*
返回供应商详情 返回供应商详情
*/ */
func (qs *OptimumService) GetOptimumAttrInfo() (results model.LyResponse) { func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.LyResponse) {
//索引字典 //索引字典
allAttrs := qs.getQueryAttr() allAttrs := qs.getQueryAttr(ctx)
//获取查询条件 //获取查询条件
queryString, err := query.GetOptimumAttrQuery(allAttrs,2) queryString, err := query.GetOptimumAttrQuery(ctx,allAttrs,2)
if err != nil { if err != nil {
results.ErrorCode = 1001; results.ErrorCode = 1001;
results.ErrorMsg = err.Error() results.ErrorMsg = err.Error()
...@@ -191,14 +206,36 @@ func (qs *OptimumService) GetOptimumAttrInfo() (results model.LyResponse) { ...@@ -191,14 +206,36 @@ func (qs *OptimumService) GetOptimumAttrInfo() (results model.LyResponse) {
A.Set("took", gjson.Get(esResult, "took").Int()) //查询总条数 A.Set("took", gjson.Get(esResult, "took").Int()) //查询总条数
//aggs := orderedmap.New() //拼接aggs //aggs := orderedmap.New() //拼接aggs
common.PrintDebugHtml(goodsIds) common.PrintDebugHtml(ctx,goodsIds)
//组装商品详情 //组装商品详情
goodsList, _ := GetGoodsInfo(goodsIds) endArr := make([]model.DullGoodsData,0)
//for _,v := range goodsList{ goodsList, _ := GetGoodsInfo(ctx,goodsIds)
// v. for _,v := range goodsList{
//}
GoodsUrl := ""
BrandUrl := ""
referer := ctx.GetHeader("Referer")
if referer != ""{
dome := strings.Split(referer,".com")
if len(dome) > 0{
if v.SupplierName == "猎芯自营" {
GoodsUrl = dome[0]+".com/item/"+v.GoodsId+".html"
BrandUrl = dome[0]+".com/v3/brand/list/"+strconv.Itoa(v.BrandId)+".html"
}else{
GoodsUrl = dome[0]+".com/goods_"+v.GoodsId+".html"
BrandUrl = dome[0]+".com/v3/brand/list/"+strconv.Itoa(v.BrandId)+".html"
}
}
}
endArr = append(endArr,model.DullGoodsData{
ApiGoods:v,
GoodsUrl: GoodsUrl,
BrandUrl: BrandUrl,
})
}
A.Set("goods_lists",goodsList) A.Set("goods_lists",endArr)
results.Data = A; results.Data = A;
return return
} }
...@@ -2,6 +2,7 @@ package service ...@@ -2,6 +2,7 @@ package service
import ( import (
"fmt" "fmt"
"github.com/gin-gonic/gin"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"regexp" "regexp"
...@@ -33,7 +34,7 @@ func (os *OtherService) CheckHasStock(goodsName string) (hasStock int, err error ...@@ -33,7 +34,7 @@ func (os *OtherService) CheckHasStock(goodsName string) (hasStock int, err error
return return
} }
func (os *OtherService) ExactGoods(supplierId, goodsName string) { func (os *OtherService) ExactGoods(ctx *gin.Context,supplierId, goodsName string) {
//获取索引 //获取索引
index := getExactGoodsIndex(supplierId) index := getExactGoodsIndex(supplierId)
r1, _ := regexp.Compile(`/[\x{4e00}-\x{9fff}]+/u`) r1, _ := regexp.Compile(`/[\x{4e00}-\x{9fff}]+/u`)
...@@ -69,7 +70,7 @@ func (os *OtherService) ExactGoods(supplierId, goodsName string) { ...@@ -69,7 +70,7 @@ func (os *OtherService) ExactGoods(supplierId, goodsName string) {
} }
result = goodsIds result = goodsIds
} }
common.Output(0, "", result) common.Output(ctx,0, "", result)
return return
} }
......
...@@ -2,8 +2,8 @@ package query ...@@ -2,8 +2,8 @@ package query
import ( import (
"errors" "errors"
"github.com/gin-gonic/gin"
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
"search_server/middleware"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/gredis" "search_server/pkg/gredis"
...@@ -17,13 +17,13 @@ cat_id=398&attr[brand][]=30485&attr[brand][]=30509&attr[brand][]=37727&attr[bran ...@@ -17,13 +17,13 @@ cat_id=398&attr[brand][]=30485&attr[brand][]=30509&attr[brand][]=37727&attr[bran
@param attrs 前端组装好post参数 @param attrs 前端组装好post参数
@param types int 返回统计还是结果: 1单独返回统计 2单独返回查询结果 @param types int 返回统计还是结果: 1单独返回统计 2单独返回查询结果
*/ */
func GetOptimumAttrQuery(attrs map[string]map[string]string,types int) (param string, err error){ func GetOptimumAttrQuery(ctx *gin.Context,attrs map[string]map[string]string,types int) (param string, err error){
query := elastic.NewBoolQuery() query := elastic.NewBoolQuery()
query1 := elastic.NewBoolQuery() query1 := elastic.NewBoolQuery()
query2 := elastic.NewBoolQuery() query2 := elastic.NewBoolQuery()
//二级分类查询 //二级分类查询
class_id2 := middleware.REQUEST["class_id2"] class_id2 := ctx.Request.FormValue("class_id2")
if class_id2 == "" { if class_id2 == "" {
return "",errors.New("二级分类不得为空") return "",errors.New("二级分类不得为空")
}else{ }else{
...@@ -59,8 +59,8 @@ func GetOptimumAttrQuery(attrs map[string]map[string]string,types int) (param s ...@@ -59,8 +59,8 @@ func GetOptimumAttrQuery(attrs map[string]map[string]string,types int) (param s
source.Size(0) source.Size(0)
} }
if types == 2 { //不需要统计,返回分页数据 if types == 2 { //不需要统计,返回分页数据
page := middleware.REQUEST["page"] page := ctx.Request.FormValue("page")
page_size := middleware.REQUEST["page_size"] page_size := ctx.Request.FormValue("page_size")
page_from := 1 page_from := 1
if page == "" { if page == "" {
page = "1"; page = "1";
...@@ -90,7 +90,7 @@ func GetOptimumAttrQuery(attrs map[string]map[string]string,types int) (param s ...@@ -90,7 +90,7 @@ func GetOptimumAttrQuery(attrs map[string]map[string]string,types int) (param s
searchRequest := elastic.NewSearchRequest().Source(source) searchRequest := elastic.NewSearchRequest().Source(source)
param, _ = searchRequest.Body() param, _ = searchRequest.Body()
common.PrintDebugHtml(param) common.PrintDebugHtml(ctx,param)
return return
} }
/* /*
......
...@@ -3,6 +3,7 @@ package service ...@@ -3,6 +3,7 @@ package service
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/gin-gonic/gin"
"github.com/imroc/req" "github.com/imroc/req"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
...@@ -19,7 +20,7 @@ type QuoteService struct { ...@@ -19,7 +20,7 @@ type QuoteService struct {
} }
//根据供应商获取商品信息 //根据供应商获取商品信息
func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest) (result map[string]interface{}, err error) { func (qs *QuoteService) GetGoodsBySupplier(ctx *gin.Context,r requests.GetGoodsBySupplierRequest) (result map[string]interface{}, err error) {
//索引字典 //索引字典
supplierIndex := query.GetSupplierIndex(r.SupplierId) supplierIndex := query.GetSupplierIndex(r.SupplierId)
//获取查询条件 //获取查询条件
...@@ -32,8 +33,8 @@ func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest) ...@@ -32,8 +33,8 @@ func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest)
return return
} }
goodsIds := GetGoodsIdsByEs(esResult) goodsIds := GetGoodsIdsByEs(esResult)
goodsList, err := GetGoodsInfo(goodsIds) goodsList, err := GetGoodsInfo(ctx,goodsIds)
dullData, err := transformer.DullDataInfo(r.Keyword, goodsList) dullData, err := transformer.DullDataInfo(ctx,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()
...@@ -44,7 +45,7 @@ func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest) ...@@ -44,7 +45,7 @@ func (qs *QuoteService) GetGoodsBySupplier(r requests.GetGoodsBySupplierRequest)
return return
} }
func (qs *QuoteService) GetGoodsBySupplierName(r requests.GetGoodsBySupplierRequest) (result map[string]interface{}, err error) { func (qs *QuoteService) GetGoodsBySupplierName(ctx *gin.Context,r requests.GetGoodsBySupplierRequest) (result map[string]interface{}, err error) {
supplierIndex := r.SupplierName supplierIndex := r.SupplierName
queryString, err := query.GetGoodsBySupplierNameQuery(r) queryString, err := query.GetGoodsBySupplierNameQuery(r)
esResult, err := es.CurlES(supplierIndex, queryString) esResult, err := es.CurlES(supplierIndex, queryString)
...@@ -54,8 +55,8 @@ func (qs *QuoteService) GetGoodsBySupplierName(r requests.GetGoodsBySupplierRequ ...@@ -54,8 +55,8 @@ func (qs *QuoteService) GetGoodsBySupplierName(r requests.GetGoodsBySupplierRequ
fmt.Println(esResult) fmt.Println(esResult)
goodsIds := GetGoodsIdsByEs(esResult) goodsIds := GetGoodsIdsByEs(esResult)
fmt.Println(goodsIds) fmt.Println(goodsIds)
goodsList, err := GetGoodsInfo(goodsIds) goodsList, err := GetGoodsInfo(ctx,goodsIds)
dullData, err := transformer.DullDataInfo(r.Keyword, goodsList) dullData, err := transformer.DullDataInfo(ctx,r.Keyword, goodsList)
quoteTransformer := transformer.QuoteTransformer{} quoteTransformer := transformer.QuoteTransformer{}
//还要去转一下阶梯价比例 //还要去转一下阶梯价比例
dullData = quoteTransformer.TransformLadderPrice(dullData) dullData = quoteTransformer.TransformLadderPrice(dullData)
......
...@@ -2,11 +2,11 @@ package transformer ...@@ -2,11 +2,11 @@ package transformer
import ( import (
"encoding/json" "encoding/json"
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"regexp" "regexp"
"search_server/dao" "search_server/dao"
"search_server/middleware"
"search_server/model" "search_server/model"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/pkg/config" "search_server/pkg/config"
...@@ -17,7 +17,7 @@ import ( ...@@ -17,7 +17,7 @@ import (
) )
//处理商品信息数据 //处理商品信息数据
func DullDataInfo(keyword string, goodsList []model.ApiGoods) (result []model.DullGoodsData, err error) { func DullDataInfo(ctx *gin.Context,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()
...@@ -37,11 +37,11 @@ func DullDataInfo(keyword string, goodsList []model.ApiGoods) (result []model.Du ...@@ -37,11 +37,11 @@ func DullDataInfo(keyword string, goodsList []model.ApiGoods) (result []model.Du
return result, err return result, err
} }
//在不同的环境组装不同的url //在不同的环境组装不同的url
goods = spliceUrlByEnvironment(goods) goods = spliceUrlByEnvironment(ctx,goods)
//获取汇率相关 //获取汇率相关
goods = getRatio(goods) goods = getRatio(goods)
//提供给客服报价系统专用 //提供给客服报价系统专用
if strings.Contains(middleware.Context.Request.URL.String(), "quote") { if strings.Contains(ctx.Request.URL.String(), "quote") {
for key, price := range goods.LadderPrice { for key, price := range goods.LadderPrice {
if price.PriceUs != 0 { if price.PriceUs != 0 {
if goods.SupplierId == 6 { if goods.SupplierId == 6 {
...@@ -61,10 +61,10 @@ func DullDataInfo(keyword string, goodsList []model.ApiGoods) (result []model.Du ...@@ -61,10 +61,10 @@ func DullDataInfo(keyword string, goodsList []model.ApiGoods) (result []model.Du
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)
go ShowSku(goods) go ShowSku(ctx,goods)
//价格等信息混淆 //价格等信息混淆
if keyword != "---" { if keyword != "---" {
goods, err = MetGoodsInfo(goods) goods, err = MetGoodsInfo(ctx,goods)
if err != nil { if err != nil {
return result, err return result, err
} }
...@@ -77,8 +77,8 @@ func DullDataInfo(keyword string, goodsList []model.ApiGoods) (result []model.Du ...@@ -77,8 +77,8 @@ func DullDataInfo(keyword string, goodsList []model.ApiGoods) (result []model.Du
} }
//在不同的环境组装不同的url //在不同的环境组装不同的url
func spliceUrlByEnvironment(goods model.DullGoodsData) model.DullGoodsData { func spliceUrlByEnvironment(ctx *gin.Context,goods model.DullGoodsData) model.DullGoodsData {
referer := middleware.Context.Request.Header.Get("referer") referer := ctx.Request.Header.Get("referer")
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"
...@@ -261,14 +261,14 @@ func arrangeData(goods model.DullGoodsData) model.DullGoodsData { ...@@ -261,14 +261,14 @@ func arrangeData(goods model.DullGoodsData) model.DullGoodsData {
} }
//价格等信息混淆 //价格等信息混淆
func MetGoodsInfo(data model.DullGoodsData) (result model.DullGoodsData, err error) { func MetGoodsInfo(ctx *gin.Context,data model.DullGoodsData) (result model.DullGoodsData, err error) {
type CheckParams struct { type CheckParams struct {
CheckButton int `form:"check_button"` CheckButton int `form:"check_button"`
K1 int `form:"k1"` K1 int `form:"k1"`
K2 int `form:"k2"` K2 int `form:"k2"`
} }
var checkParams CheckParams var checkParams CheckParams
err = middleware.Context.Bind(&checkParams) err = ctx.Bind(&checkParams)
if checkParams.CheckButton == 2 || checkParams.K1 != 0 || checkParams.K2 != 0 { if checkParams.CheckButton == 2 || checkParams.K1 != 0 || checkParams.K2 != 0 {
data.StockStr = data.Stock data.StockStr = data.Stock
data.MoqStr = data.Moq data.MoqStr = data.Moq
...@@ -297,19 +297,19 @@ func MetGoodsInfo(data model.DullGoodsData) (result model.DullGoodsData, err err ...@@ -297,19 +297,19 @@ func MetGoodsInfo(data model.DullGoodsData) (result model.DullGoodsData, err err
} }
//推送搜索商品信息 //推送搜索商品信息
func ShowSku(goods model.DullGoodsData) { func ShowSku(ctx *gin.Context,goods model.DullGoodsData) {
//绑定需要接收的参数 //绑定需要接收的参数
type ShowSkuParams struct { type ShowSkuParams struct {
GoodsNameEq string `form:"goods_name/eq"` GoodsNameEq string `form:"goods_name/eq"`
Keyword string `form:"keyword"` Keyword string `form:"keyword"`
} }
var params ShowSkuParams var params ShowSkuParams
middleware.Context.Bind(&params) ctx.Bind(&params)
goodsIdLen := len(goods.GoodsId) goodsIdLen := len(goods.GoodsId)
if goods.GoodsId == "" || goods.BrandName == "" || goods.SupplierName == "" { if goods.GoodsId == "" || goods.BrandName == "" || goods.SupplierName == "" {
return return
} }
referer := middleware.Context.Request.Header.Get("referer") referer := ctx.Request.Header.Get("referer")
if strings.Contains(referer, "www.ichunt.com/s/?k") { if strings.Contains(referer, "www.ichunt.com/s/?k") {
if goods.ProviderName != "" { if goods.ProviderName != "" {
goods.BrandName = goods.ProviderName goods.BrandName = goods.ProviderName
...@@ -356,7 +356,7 @@ func ShowSku(goods model.DullGoodsData) { ...@@ -356,7 +356,7 @@ func ShowSku(goods model.DullGoodsData) {
result["moq"] = goods.Moq result["moq"] = goods.Moq
result["show_time"] = time.Now().Unix() result["show_time"] = time.Now().Unix()
//cookie获取 //cookie获取
result["adtag"], _ = middleware.Context.Cookie("adtag") result["adtag"], _ = ctx.Cookie("adtag")
//状态判断 //状态判断
if goodsIdLen < 19 { if goodsIdLen < 19 {
result["status"] = 1 result["status"] = 1
......
...@@ -14,7 +14,6 @@ import ( ...@@ -14,7 +14,6 @@ import (
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
"math" "math"
"regexp" "regexp"
"search_server/middleware"
"search_server/model" "search_server/model"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/pkg/config" "search_server/pkg/config"
...@@ -61,7 +60,7 @@ func (this *ZyServiceImpl) Zyh(ctx *gin.Context, req map[string]string) (rsp *mo ...@@ -61,7 +60,7 @@ func (this *ZyServiceImpl) Zyh(ctx *gin.Context, req map[string]string) (rsp *mo
//设置cookie //设置cookie
setCookie(ctx,req) setCookie(ctx,req)
rsp = zy(req ,_type,0) rsp = zy(ctx,req ,_type,0)
return rsp,nil return rsp,nil
} }
...@@ -72,7 +71,7 @@ func (this *ZyServiceImpl)Aggs(ctx *gin.Context, req map[string]string) (rsp *mo ...@@ -72,7 +71,7 @@ func (this *ZyServiceImpl)Aggs(ctx *gin.Context, req map[string]string) (rsp *mo
return rsp,nil return rsp,nil
} }
rsp = zy(req ,2,1) rsp = zy(ctx,req ,2,1)
return rsp,nil return rsp,nil
} }
...@@ -98,7 +97,7 @@ func ajaxReturn(rsp *model.ZyhResponse,err_code int64,err_msg string,data interf ...@@ -98,7 +97,7 @@ func ajaxReturn(rsp *model.ZyhResponse,err_code int64,err_msg string,data interf
//自营筛选接口数据输出 //自营筛选接口数据输出
//@param _type 1:输出所有(属性统计+分类+数据详情),2 只输出属性(属性统计) //@param _type 1:输出所有(属性统计+分类+数据详情),2 只输出属性(属性统计)
func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){ func zy(ctx *gin.Context,req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){
var ( var (
classid int64 classid int64
err error err error
...@@ -152,7 +151,7 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){ ...@@ -152,7 +151,7 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){
req2 = common.CopyMapString(req) req2 = common.CopyMapString(req)
zy_orgin_search = common.CopyMapString(req)//原始搜索數據 zy_orgin_search = common.CopyMapString(req)//原始搜索數據
delete(req2,"class_id/condition") delete(req2,"class_id/condition")
rsp =searchZiYingGoods(req2,true,zhyClassList,classLight,_type) rsp =searchZiYingGoods(ctx,req2,true,zhyClassList,classLight,_type)
if _type == 2{ if _type == 2{
data,ok := rsp.Data.(map[string]interface{}) data,ok := rsp.Data.(map[string]interface{})
if ok { if ok {
...@@ -171,7 +170,7 @@ func(this *ZyServiceImpl) Index(ctx *gin.Context, req map[string]string) (rsp *m ...@@ -171,7 +170,7 @@ func(this *ZyServiceImpl) Index(ctx *gin.Context, req map[string]string) (rsp *m
if ok { if ok {
return rsp return rsp
} }
rsp = searchZiYingGoods(req2,false,nil,nil,1) rsp = searchZiYingGoods(ctx,req2,false,nil,nil,1)
return rsp return rsp
} }
...@@ -183,7 +182,7 @@ func(this *ZyServiceImpl) Index(ctx *gin.Context, req map[string]string) (rsp *m ...@@ -183,7 +182,7 @@ func(this *ZyServiceImpl) Index(ctx *gin.Context, req map[string]string) (rsp *m
* @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) (rsp *model.ZyhResponse){ func searchZiYingGoods(ctx *gin.Context, req map[string]string,zy bool,classList *model.ZhyClassList,classLight []*model.ZhyClassListModel,aType byte) (rsp *model.ZyhResponse){
var ( var (
goods_name_arr []string goods_name_arr []string
keyword string keyword string
...@@ -471,7 +470,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL ...@@ -471,7 +470,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
for _,v := range goodsIds{ for _,v := range goodsIds{
goodsIdsStrArr = append(goodsIdsStrArr,v.String()) goodsIdsStrArr = append(goodsIdsStrArr,v.String())
} }
goodsList,_ := GetGoodsInfo(goodsIdsStrArr) goodsList,_ := GetGoodsInfo(ctx,goodsIdsStrArr)
flag = 0 flag = 0
response["total"] = gjson.Get(result,"hits.total").String() response["total"] = gjson.Get(result,"hits.total").String()
for _ ,esGoodsInfo := range hitsHits{ for _ ,esGoodsInfo := range hitsHits{
...@@ -480,7 +479,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL ...@@ -480,7 +479,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
//goods_id := esGoodsInfo.Map()["_id"].Int() //goods_id := esGoodsInfo.Map()["_id"].Int()
goods_id_str := esGoodsInfo.Map()["_id"].String() goods_id_str := esGoodsInfo.Map()["_id"].String()
//整理自营数据参数 //整理自营数据参数
goodsInfo,ok := dullZiYingGoodsInfo(goods_id_str,keyword,goods_name_arr,goodsList) goodsInfo,ok := dullZiYingGoodsInfo(ctx,goods_id_str,keyword,goods_name_arr,goodsList)
if !ok { if !ok {
continue continue
} }
...@@ -513,7 +512,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL ...@@ -513,7 +512,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
} }
} }
referer := middleware.Context.GetHeader("Referer") referer := ctx.GetHeader("Referer")
if flag <= 0 && php2go.Stripos(referer,"/s/?k=",0) == -1{ if flag <= 0 && php2go.Stripos(referer,"/s/?k=",0) == -1{
response = getPage(response,length,hitsTotal) response = getPage(response,length,hitsTotal)
} }
...@@ -882,7 +881,7 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions ...@@ -882,7 +881,7 @@ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions
//整理自营数据参数 //整理自营数据参数
func dullZiYingGoodsInfo(goods_id_str string,keyword string,goods_name_arr []string,goods_list []model.ApiGoods) (ziyinGoodsInfo model.ZiyinGoodsInfo, ok bool){ func dullZiYingGoodsInfo(ctx *gin.Context,goods_id_str string,keyword string,goods_name_arr []string,goods_list []model.ApiGoods) (ziyinGoodsInfo model.ZiyinGoodsInfo, ok bool){
isHas := false isHas := false
for _,goods_info:= range goods_list{ for _,goods_info:= range goods_list{
if goods_info.GoodsId == goods_id_str{ if goods_info.GoodsId == goods_id_str{
...@@ -951,7 +950,7 @@ func dullZiYingGoodsInfo(goods_id_str string,keyword string,goods_name_arr []str ...@@ -951,7 +950,7 @@ func dullZiYingGoodsInfo(goods_id_str string,keyword string,goods_name_arr []str
} }
referer := middleware.Context.GetHeader("Referer") referer := ctx.GetHeader("Referer")
if referer != ""{ if referer != ""{
dome := strings.Split(referer,".com") dome := strings.Split(referer,".com")
if len(dome) > 0{ if len(dome) > 0{
...@@ -967,7 +966,7 @@ func dullZiYingGoodsInfo(goods_id_str string,keyword string,goods_name_arr []str ...@@ -967,7 +966,7 @@ func dullZiYingGoodsInfo(goods_id_str string,keyword string,goods_name_arr []str
ziyinGoodsInfo.LastSearchTime = common.GetLastSearchTime(goods_id_str) ziyinGoodsInfo.LastSearchTime = common.GetLastSearchTime(goods_id_str)
//go transformer.ShowSku(model.DullGoodsData{ApiGoods:ziyinGoodsInfo.ApiGoods}) //go transformer.ShowSku(model.DullGoodsData{ApiGoods:ziyinGoodsInfo.ApiGoods})
if keyword != "---"{ if keyword != "---"{
dullGoodsData,err:= transformer.MetGoodsInfo(ziyinGoodsInfo.DullGoodsData) dullGoodsData,err:= transformer.MetGoodsInfo(ctx,ziyinGoodsInfo.DullGoodsData)
if err == nil{ if err == nil{
ziyinGoodsInfo.DullGoodsData = dullGoodsData ziyinGoodsInfo.DullGoodsData = dullGoodsData
} }
......
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