Commit e5c069bf by huangchengyi

1.0

parent 62621c25
package controller
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"search_server/model"
"search_server/pkg/common"
"search_server/service/ly"
)
//搜索型号
func GetMouserData(c *gin.Context) {
goodsName, _ := c.GetPostForm("goods_name")
lycon := new(ly.CommonLyService)
//lycon := new(ly.CommonLyService)
//调外链拿数据
apiData := ly.OutLinkMouser(&goodsName,"1")
//供应商详情
supplierInfo := model.SUPPLIER_REDIS_INFO{
SupplierId:14,
SupplierNickname: "mouser",
}
err := lycon.GetSkuByGoodsSn(apiData,&supplierInfo)
var errCode int
if !err {
errCode = 1
}
res := common.BomResponse{
ErrCode: errCode,
ErrMsg: "",
Data: "",
apiData := ly.OutLinkMouser(&goodsName,"-1")
//var shu string
//for _, info := range apiData {
//
// //PrintHtml(t.ctx,&t.flag,"snSku:"+snSku+" 查询得出sku"+skuId+" info",info)
// //jsonDatas,_ := json.Marshal(map[string]interface{}{
// // "dddd":"333333",
// // "ninifa":"333333",
// // "3333":"333333",
// // "gagaga":"333333",
// //})
// //fmt.Println(len(info))
// josn, errs := json.Marshal(info)
// if errs != nil {
// fmt.Println("错误")
// }
// shu += string(josn)
//}
// jsonDatas,_ := json.Marshal(map[string]interface{}{
// "dddd":"333333",
// "ninifa":"333333",
// "3333":"333333",
// "gagaga":"333333",
// })
josn, errs := json.Marshal(apiData)
if errs != nil {
fmt.Println("错误")
}
c.JSON(200,res)
c.JSON(200,string(josn))
//供应商详情
//supplierInfo := model.SUPPLIER_REDIS_INFO{
// SupplierId:14,
// SupplierNickname: "mouser",
//}
//err := lycon.GetSkuByGoodsSn(apiData,&supplierInfo)
//var errCode int
//if !err {
// errCode = 1
//}
//res := common.BomResponse{
// ErrCode: errCode,
// ErrMsg: "",
// Data: "",
//}
//c.JSON(200, map[string]interface{}{
// "error_code":777777,
// "err_msg":"ddddd2",
//})
}
......@@ -21,6 +21,7 @@ func InitRouter() *gin.Engine {
r.POST("/search/bom/recommend", controller.Recommend)
r.POST("search/ZiYing/zyh", controller.Zyh)
r.POST("search/mouser/GetMouserData", controller.GetMouserData)
r.GET("search/mouser/GetMouserData", controller.GetMouserData)
//快手平台相关
r.GET("/search/quote", controller.QuoteIndex)
......
......@@ -50,6 +50,27 @@ func (t *CommonLyService) LyServerRun(){
t.flag = strings.TrimSpace(requstValue[0])
}
}
if t.flag == "101" {
t.ctx.Header("Content-Type", "text/html; charset=utf-8")
}
}
/*
格式化数据直接输出浏览器
*/
func PrintHtml(ctx *gin.Context,flag *string,data string,jsondata interface{}) {
if *flag == "101" {
if jsondata != "" {
jsonData,err := json.Marshal(jsondata)
if err != nil {
fmt.Println("错误:-----",err)
}else{
ctx.JSON(200,data+"</br>"+string(jsonData))
}
}else{
ctx.JSON(200,data+"</br>")
}
}
}
/*
......@@ -61,6 +82,11 @@ func (t *CommonLyService) LyServerRun(){
func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoodsList,supplierInfo *model.SUPPLIER_REDIS_INFO) bool {
t.LyServerRun(); //初始化变量
if len(goodsList) == 0 {
PrintHtml(t.ctx,&t.flag,"没有数据","")
return true
}
redisWrite := gredis.Conn("search_w")
defer redisWrite.Close()
......@@ -73,6 +99,21 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
snSku := php2go.Md5(strings.ToLower(goodsSn))
skuId,_ := gredis.String(redisWrite.Do("HGET",config.Get("redis_all.SKU_UNIQUE_JUDGE").String(),snSku)) //查询唯一值,反查sku_id
//PrintHtml(t.ctx,&t.flag,"snSku:"+snSku+" 查询得出sku"+skuId+" info",info)
//jsonData,err := json.Marshal(map[string]interface{}{
// "dddd":"333333",
// "ninifa":"333333",
// "3333":"333333",
// "gagaga":"333333",
//})
jsonData,err := json.Marshal(info)
if err != nil {
fmt.Println("错误:-----",err)
}else{
t.ctx.JSON(200,string(jsonData))
}
continue;
/**********新增sku**************/
skuFlag := false; //是否新增或者更新db+redis,为true则新增
if skuId == "" { //redis没有此sku,创建
......@@ -150,6 +191,7 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
}
t.pushEs(); //最后推送ES
return true
}
......
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