Commit 7033d5ca by huangchengyi

1.0

parent fb447380
...@@ -96,7 +96,7 @@ func outLinkDiv(supplierId *string,supplierName *string,keyWord * string){ ...@@ -96,7 +96,7 @@ func outLinkDiv(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,"1") apiData = ly.OutLinkMouser(keyWord)
break; break;
} }
......
...@@ -2,25 +2,18 @@ package controller ...@@ -2,25 +2,18 @@ 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"
"strings"
) )
//搜索型号 //搜索型号
func GetMouserData(c *gin.Context) { func GetMouserData(c *gin.Context) {
_REQUEST := make(map[string]string,0); goodsName := middleware.REQUEST["goods_name"]
c.MultipartForm() flag := middleware.REQUEST["flag"]
for requestName, requstValue := range c.Request.Form {
if requstValue[0] != "" {
_REQUEST[requestName] = strings.TrimSpace(requstValue[0])
}
}
goodsName := _REQUEST["goods_name"]
flag := _REQUEST["flag"]
common.PrintDebugHeader(c,&flag) common.PrintDebugHeader(c,&flag)
if goodsName == "" { if goodsName == "" {
...@@ -29,7 +22,7 @@ func GetMouserData(c *gin.Context) { ...@@ -29,7 +22,7 @@ func GetMouserData(c *gin.Context) {
} }
//调外链拿数据 //调外链拿数据
apiData := ly.OutLinkMouser(&goodsName,"-1") apiData := ly.OutLinkMouser(&goodsName)
//供应商详情 //供应商详情
lycon := new(ly.CommonLyService) lycon := new(ly.CommonLyService)
......
...@@ -65,7 +65,7 @@ func QuoteIndex(c *gin.Context) { ...@@ -65,7 +65,7 @@ func QuoteIndex(c *gin.Context) {
} }
func mouserOrg(keyword, suppliedId string) (result map[string]interface{}, err error) { func mouserOrg(keyword, suppliedId string) (result map[string]interface{}, err error) {
mouserRes := ly.OutLinkMouser(&keyword, "1") mouserRes := ly.OutLinkMouser(&keyword)
redisCon := gredis.Conn("search_r") redisCon := gredis.Conn("search_r")
defer redisCon.Close() defer redisCon.Close()
skuMouser := make(map[string]string) skuMouser := make(map[string]string)
......
...@@ -2,13 +2,22 @@ package middleware ...@@ -2,13 +2,22 @@ package middleware
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"strings"
) )
var Context *gin.Context var Context *gin.Context
var REQUEST map[string]string //等同于php 的$_REQUEST
//将gin的上下文放到全局变量 //将gin的上下文放到全局变量
func ContextVars() gin.HandlerFunc { func ContextVars() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
//接收所有的变量+值
REQUEST = make(map[string]string,0);
c.MultipartForm()
for requestName, requstValue := range c.Request.Form {
REQUEST[requestName] = strings.TrimSpace(requstValue[0])
}
//将gin的上下文放到全局变量 //将gin的上下文放到全局变量
Context = c Context = c
c.Next() c.Next()
......
...@@ -2,9 +2,9 @@ package model ...@@ -2,9 +2,9 @@ package model
//联营请求外链后格式化数据 //联营请求外链后格式化数据
type LyClearGoodsList struct { type LyClearGoodsList struct {
SkuId string `json:"sku_id"` //平台型号id (非必填) SkuId string `json:"sku_id"` //平台型号id (非必填)
SpuId string `json:"spu_id"` //平台spuId (非必填) SpuId string `json:"spu_id"` //平台spuId (非必填)
BrandId string `json:"brand_id"` //平台品牌id (非必填) BrandId string `json:"brand_id"` //平台品牌id (非必填)
GoodsName string `json:"goods_name"` //型号名称 GoodsName string `json:"goods_name"` //型号名称
BrandName string `json:"brand_name"` //品牌名称 BrandName string `json:"brand_name"` //品牌名称
Desc string `json:"desc"` //描述 Desc string `json:"desc"` //描述
...@@ -20,12 +20,12 @@ type LyClearGoodsList struct { ...@@ -20,12 +20,12 @@ type LyClearGoodsList struct {
RestrictionMessage string `json:"RestrictionMessage"` //额外购买限制内容,如 ‘当前商品不在本地区销售’ RestrictionMessage string `json:"RestrictionMessage"` //额外购买限制内容,如 ‘当前商品不在本地区销售’
Increment int64 `json:"increment"` //最小包装量、倍数 =Mpq Increment int64 `json:"increment"` //最小包装量、倍数 =Mpq
SinglePrice float64 `json:"single_price"` //最小单价 SinglePrice float64 `json:"single_price"` //最小单价
Stock int64 `json:"stock"` //库存 Stock int64 `json:"stock"` //库存
Moq int64 `json:"moq"` //最小起订量、起订量 Moq int64 `json:"moq"` //最小起订量、起订量
RawGoodsId string `json:"raw_goods_id"` //外链原始goods_sn,如digikey:{'raw_goods_id': 'AT28C64X-25PC-ND', 'raw_brand_name': 'Microchip Technology'} RawGoodsId string `json:"raw_goods_id"` //外链原始goods_sn,如digikey:{'raw_goods_id': 'AT28C64X-25PC-ND', 'raw_brand_name': 'Microchip Technology'}
RawBrandName string `json:"raw_brand_name"` //外链原始品牌名称,如digikey:{'raw_goods_id': 'AT28C64X-25PC-ND', 'raw_brand_name': 'Microchip Technology'} RawBrandName string `json:"raw_brand_name"` //外链原始品牌名称,如digikey:{'raw_goods_id': 'AT28C64X-25PC-ND', 'raw_brand_name': 'Microchip Technology'}
Tiered []*TierItem `json:"tiered"` //价格梯度数量 Tiered []*TierItem `json:"tiered"` //价格梯度数量
PriceTemp []interface{} `json:"price_temp"` //拼接梯度,目前只有联营推送队列用 PriceTemp []interface{} `json:"price_temp"` //拼接梯度,目前只有联营推送队列用
} }
type TierItem struct { type TierItem struct {
Purchases uint64 `json:"purchases"` //购买数量 Purchases uint64 `json:"purchases"` //购买数量
......
...@@ -25,7 +25,7 @@ import ( ...@@ -25,7 +25,7 @@ import (
输出header 输出header
*/ */
func PrintDebugHeader(ctx *gin.Context,flag *string) { func PrintDebugHeader(ctx *gin.Context,flag *string) {
if *flag != "" { if *flag == "101" {
ctx.Header("Content-Type", "text/html; charset=utf-8") ctx.Header("Content-Type", "text/html; charset=utf-8")
} }
} }
...@@ -37,7 +37,7 @@ func PrintDebugHeader(ctx *gin.Context,flag *string) { ...@@ -37,7 +37,7 @@ func PrintDebugHeader(ctx *gin.Context,flag *string) {
@parm jsondata 需要json输出的内容 @parm jsondata 需要json输出的内容
*/ */
func PrintDebugHtml(ctx *gin.Context,flag *string,jsonStr interface{}) { func PrintDebugHtml(ctx *gin.Context,flag *string,jsonStr interface{}) {
if *flag == "" || jsonStr == "" { if *flag != "101" || jsonStr == "" {
return return
} }
if v, p := jsonStr.(string); p { if v, p := jsonStr.(string); p {
......
...@@ -21,8 +21,8 @@ func InitRouter() *gin.Engine { ...@@ -21,8 +21,8 @@ func InitRouter() *gin.Engine {
r.GET("search/ZiYing/zyh", controller.Zyh) r.GET("search/ZiYing/zyh", controller.Zyh)
r.GET("search/ZiYing/index", controller.Index) r.GET("search/ZiYing/index", controller.Index)
r.POST("search/ZiYing/index", controller.Index) r.POST("search/ZiYing/index", controller.Index)
r.POST("search/mouser/GetMouserData", controller.GetMouserData) r.POST("search/mouser/a", controller.GetMouserData)
r.GET("search/mouser/GetMouserData", controller.GetMouserData) r.GET("search/mouser/a", controller.GetMouserData)
//快手平台相关 //快手平台相关
r.GET("/search/quote", controller.QuoteIndex) r.GET("/search/quote", controller.QuoteIndex)
......
...@@ -3,6 +3,7 @@ package ly ...@@ -3,6 +3,7 @@ package ly
import ( import (
"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"
...@@ -13,13 +14,14 @@ import ( ...@@ -13,13 +14,14 @@ 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,flag string) map[string]*model.LyClearGoodsList { func OutLinkMouser(goodsName *string) map[string]*model.LyClearGoodsList {
if *goodsName == "" { if *goodsName == "" {
return nil return nil
} }
var result string; var result string;
var flag = middleware.REQUEST["flag"]
if flag == "-1" { //调试 if middleware.REQUEST["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)
...@@ -29,6 +31,7 @@ func OutLinkMouser(goodsName *string,flag string) map[string]*model.LyClearGoods ...@@ -29,6 +31,7 @@ func OutLinkMouser(goodsName *string,flag string) map[string]*model.LyClearGoods
print(err) print(err)
} }
result = resp.String(); //请求外链拿到结果 result = resp.String(); //请求外链拿到结果
common.PrintDebugHtml(middleware.Context,&flag,result)
} }
productList := make(map[string]*model.LyClearGoodsList,0) productList := make(map[string]*model.LyClearGoodsList,0)
......
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