Commit da7c534f by huangchengyi

1.0

parent 177910cb
......@@ -6,13 +6,16 @@ import (
"github.com/ichunt2019/logger"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/es"
"search_server/pkg/gredis"
"search_server/requests"
"search_server/service"
"search_server/service/ly"
"search_server/service/transformer"
"strconv"
"strings"
)
......@@ -33,6 +36,11 @@ func GetDataIndex(c *gin.Context) {
c.JSON(200, common.ErrorResponse(1, "供应商id有误"))
return
}
common.PrintDebugHtml(c,&r.Flag,r.SupplierId)
common.PrintDebugHtml(c,&r.Flag,r.Keyword)
if r.SupplierId != "" && r.IsSort == 2 {
//所有供应商列表
//如果供应商不在合并供应商列表,则实时更新数据
......@@ -45,6 +53,9 @@ func GetDataIndex(c *gin.Context) {
logger.Error("%s", err.Error())
}
if res {
//增加联营外链请求
outLinkDiv(&r.SupplierId,&supplierName,&r.Keyword)
//增加
_, err := redis.Bool(redisCon.Do("INCR", config.Get("redis_all.SEARCH_API_TOTAL_PRE").String()+r.SupplierName))
if err != nil {
logger.Error("%s", err.Error())
......@@ -74,6 +85,32 @@ func GetDataIndex(c *gin.Context) {
return
}
/*
联营外链请求
@param supplierId 渠道id
@param supplierName 渠道名称
@param keyword 关键词
*/
func outLinkDiv(supplierId *string,supplierName *string,keyWord * string){
var apiData map[string]*model.LyClearGoodsList = nil
switch *supplierName {
case "mouser": //调外链拿数据mouser外链请求更新修改
apiData = ly.OutLinkMouser(keyWord,"1")
break;
}
if apiData != nil {
//供应商详情
supplierId,_ := strconv.ParseInt(*supplierId, 10, 64)
lycon := ly.CommonLyService{}
lycon.GetSkuByGoodsSn(apiData,&model.SUPPLIER_REDIS_INFO{
SupplierId:supplierId,
SupplierNickname: *supplierName,
})
}
}
//获取查询es的条件语句
func getDataQueryStr(r requests.GetDataIndexRequest, supplierList []string) string {
getDataService := service.GetDataService{}
......
package controller
import (
"github.com/gin-gonic/gin"
"search_server/model"
"search_server/pkg/common"
"search_server/service/ly"
"fmt"
"strings"
)
//搜索型号
func GetMouserData(c *gin.Context) {
_REQUEST := make(map[string]string,0);
c.MultipartForm()
for requestName, requstValue := range c.Request.Form {
if requstValue[0] != "" {
_REQUEST[requestName] = strings.TrimSpace(requstValue[0])
}
}
goodsName := _REQUEST["goods_name"]
if goodsName == "" {
c.String(1001,"goods_name不得为空")
return
}
fmt.Println(goodsName)
//调外链拿数据
apiData := ly.OutLinkMouser(&goodsName,"-1")
//供应商详情
lycon := new(ly.CommonLyService)
err := lycon.GetSkuByGoodsSn(apiData,&model.SUPPLIER_REDIS_INFO{
SupplierId:14,
SupplierNickname: "mouser",
})
errCode := 0
if !err {
errCode = 1
}
c.JSON(200, common.BomResponse{
ErrCode: errCode,
ErrMsg: "查询成功",
Data: apiData,
})
}
package controller
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"search_server/service/ly"
)
//搜索型号
func GetMouserData(c *gin.Context) {
goodsName, _ := c.GetPostForm("goods_name")
//lycon := new(ly.CommonLyService)
//调外链拿数据
apiData := ly.OutLinkMouser2(&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("错误")
}
fmt.Println(len(josn))
c.String(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",
//})
}
......@@ -32,6 +32,7 @@ require (
github.com/tidwall/gjson v1.6.0
github.com/uniplaces/carbon v0.1.6
go.uber.org/zap v1.14.1 // indirect
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361
google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece // indirect
google.golang.org/grpc v1.29.1 // indirect
google.golang.org/protobuf v1.24.0
......
package common
import (
"bytes"
"crypto/md5"
crand "crypto/rand"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/syyongx/php2go"
"math/big"
"math/rand"
......@@ -17,6 +21,31 @@ import (
"time"
)
/*
格式化数据直接输出浏览器
@parm ctx gin上下文
@parm flag 是否调试标志
@parm data 打印调试内容
@parm jsondata 需要json输出的内容
*/
func PrintDebugHtml(ctx *gin.Context,flag *string,jsonStr interface{}) {
if *flag != "101" && jsonStr != "" {
return
}
ctx.Header("Content-Type", "text/html; charset=utf-8")
jsonData,err := json.Marshal(jsonStr)
if err != nil {
fmt.Println("错误:-----",err)
}
var str bytes.Buffer
_ = json.Indent(&str, []byte(string(jsonData)), "", " ")
fmt.Println("formated: ", str.String())
ctx.String(200,"</br>")
ctx.String(200,str.String())
}
// Md5 md5()
func Md5(str string) string {
hash := md5.New()
......
......@@ -2,16 +2,17 @@ package requests
//使用根据供应商获取商品信息方法的通用请求
type GetGoodsBySupplierRequest struct {
Keyword string `form:"keyword"`
SupplierName string `form:"supplier_name"`
Stock int `form:"stock"`
SupplierId string `form:"supplier_id"`
Keyword string `form:"keyword"`
SupplierName string `form:"supplier_name"`
Stock int `form:"stock"`
SupplierId string `form:"supplier_id"`
Offset int `form:"offset"`
FollowHit int `form:"follow_hit"`
CheckButton int `form:"check_button"`
GoodsNameEq string `form:"goods_name/eq"`
IsExact int `form:"is_exact"`
BrandId string `form:"brand_id"`
Flag string `form:"flag"` //调试标志
AvailRank int `form:"avail_rank"`
SingleRank int `form:"single_rank"`
StockRank int `form:"stock_rank"`
......
......@@ -50,28 +50,8 @@ 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>")
}
}
}
/*
联营入口
......@@ -83,7 +63,7 @@ func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoo
t.LyServerRun(); //初始化变量
if len(goodsList) == 0 {
PrintHtml(t.ctx,&t.flag,"没有数据","")
common.PrintDebugHtml(t.ctx,&t.flag,"没有数据")
return true
}
......@@ -99,21 +79,9 @@ 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",
//})
common.PrintDebugHtml(t.ctx,&t.flag,info)
common.PrintDebugHtml(t.ctx,&t.flag,"snSku:"+snSku+" 查询得出sku"+skuId+" info")
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,创建
......
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