Commit 9365927c by mushishixian

fix

parents bed4ba30 2239aea7
......@@ -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,
})
}
......@@ -18,7 +18,7 @@ func Zyh(ctx *gin.Context){
zyhRequest[requestName] = strings.TrimSpace(requstValue[0])
}
}
fmt.Println(zyhRequest)
//fmt.Println(zyhRequest)
zyServiceImpl := service.NewZyServiceImpl()
......
......@@ -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
......
......@@ -72,6 +72,11 @@ type ApiGoods struct {
type ZiyinGoodsInfo struct {
GoodsNameOrg string `json:"goods_name_org"`
SampleStatus string `json:"sample_status"`
SampleMaxNumber string `json:"sample_max_number"`
SampleClassId string `json:"sample_class_id"`
SampleClassIdName string `json:"sample_class_id_name"`
Quota int `json:"quota"`
DullGoodsData
}
......
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()
......
package common
import "math"
//分页方法,根据传递过来的页数,每页数,总数,返回分页的内容 7个页数 前 1,2,3,4,5 后 的格式返回,小于5页返回具体页数
func Paginator(page, prepage int, nums int64) map[string]interface{} {
var firstpage int //前一页地址
var lastpage int //后一页地址
//根据nums总数,和prepage每页数量 生成分页总数
totalpages := int(math.Ceil(float64(nums) / float64(prepage))) //page总数
if page > totalpages {
page = totalpages
}
if page <= 0 {
page = 1
}
var pages []int
switch {
case page >= totalpages-5 && totalpages > 5: //最后5页
start := totalpages - 5 + 1
firstpage = page - 1
lastpage = int(math.Min(float64(totalpages), float64(page+1)))
pages = make([]int, 5)
for i, _ := range pages {
pages[i] = start + i
}
case page >= 3 && totalpages > 5:
start := page - 3 + 1
pages = make([]int, 5)
firstpage = page - 3
for i, _ := range pages {
pages[i] = start + i
}
firstpage = page - 1
lastpage = page + 1
default:
pages = make([]int, int(math.Min(5, float64(totalpages))))
for i, _ := range pages {
pages[i] = i + 1
}
firstpage = int(math.Max(float64(1), float64(page-1)))
lastpage = page + 1
//fmt.Println(pages)
}
paginatorMap := make(map[string]interface{})
paginatorMap["pages"] = pages
paginatorMap["totalpages"] = totalpages
paginatorMap["firstpage"] = firstpage
paginatorMap["lastpage"] = lastpage
paginatorMap["currpage"] = page
return paginatorMap
}
\ No newline at end of file
......@@ -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"`
......
......@@ -18,6 +18,7 @@ func InitRouter() *gin.Engine {
r.POST("/search/bom/autospu", controller.AutoSpu)
r.POST("/search/bom/recommend", controller.Recommend)
r.POST("search/ZiYing/zyh", controller.Zyh)
r.GET("search/ZiYing/zyh", controller.Zyh)
r.POST("search/mouser/GetMouserData", controller.GetMouserData)
r.GET("search/mouser/GetMouserData", controller.GetMouserData)
......
......@@ -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,创建
......
......@@ -13,6 +13,9 @@ const Mouser_api_url string = "https://api.mouser.com/api/v1/search/partnumber?a
//mouser请求外链
func OutLinkMouser(goodsName *string,flag string) map[string]*model.LyClearGoodsList {
if *goodsName == "" {
return nil
}
var result string;
if flag == "-1" { //调试
......@@ -89,4 +92,4 @@ func OutLinkMouser(goodsName *string,flag string) map[string]*model.LyClearGoods
//fmt.Println(productList)
return productList
}
\ No newline at end of file
}
package main
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