Commit 8d014493 by 孙龙

up

parent 3eb86e03
......@@ -20,3 +20,8 @@ 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
[redis_ziyin]
AGG_TABLE=sz_ziying_class_aggs
FIRST_LISTS_TABLE=ziying_first_lists
ZIYING_CLASS_KEY=ziying_class_string
\ No newline at end of file
......@@ -19,3 +19,29 @@ TI_ZY_BRAND_IDS=23
# 供应商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
\ No newline at end of file
package controller
import (
"fmt"
"github.com/gin-gonic/gin"
"net/http"
"search_server/model"
"search_server/service"
)
......@@ -10,18 +10,23 @@ import (
func Zyh(ctx *gin.Context){
zyServiceImpl := service.NewZyServiceImpl()
zyhRequest := &model.ZyhRequest{}
zyhResponse := &model.ZyhResponse{}
if err := ctx.ShouldBind(zyhRequest); err != nil{
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
zyhRequest := make(map[string]string,0);
ctx.MultipartForm()
for requestName, requstValue := range ctx.Request.Form {
if requstValue[0] != "" {
zyhRequest[requestName] = requstValue[0]
}
}
zyServiceImpl := service.NewZyServiceImpl()
zyhResponse := &model.ZyhResponse{}
err := zyServiceImpl.Zyh(ctx,zyhRequest,zyhResponse)
if err != nil{
zyhResponse.ErrorCode = 1
zyhResponse.ErrorMsg = fmt.Sprintf("%s",err)
ctx.JSON(200,zyhResponse)
}
ctx.JSON(200,zyhResponse)
}
......@@ -7,6 +7,7 @@ require (
github.com/gin-contrib/cors v1.3.1
github.com/gin-gonic/gin v1.6.3
github.com/go-ini/ini v1.57.0
github.com/go-playground/locales v0.13.0
github.com/go-sql-driver/mysql v1.5.0
github.com/go-xorm/xorm v0.7.9
github.com/gogo/protobuf v1.3.1 // indirect
......
package model
type ZyhRequest struct {
Yo4tewUid string `form:"Yo4teW_uid"`
ClassIdcondition int64 `form:"class_id/condition"`
Brand_idCondition string `form:"brand_id/condition"`
StockRank string `form:"stock_rank"` //库存排序
AvailRank string `form:"avail_rank"` //显示有货的
ComRank string `form:"com_rank"` //综合排序
SingleRank string `form:"single_rank"` //价格排序
PackingCondition string `form:"packing/condition"`
EncapCondition string `form:"encap/condition"`
P string `form:"p"`
NeedAggs string `form:"need_aggs"`
}
//type ZyhRequest struct {
// Yo4tewUid string `form:"Yo4teW_uid"`
// ClassIdcondition int64 `form:"class_id/condition"`
// ClassId2condition int64 `form:"class_id2/condition"`
// Brand_idCondition string `form:"brand_id/condition"`
// StockRank string `form:"stock_rank"` //库存排序
// AvailRank string `form:"avail_rank"` //显示有货的
// ComRank string `form:"com_rank"` //综合排序
// SingleRank string `form:"single_rank"` //价格排序
// PackingCondition string `form:"packing/condition"`
// EncapCondition string `form:"encap/condition"`
// P int `form:"p"`
// NeedAggs string `form:"need_aggs"`
// GoodsNameCondition string `form:"goods_name/condition"`
//
//}
type ZhyClassListModel struct {
ClassID1Name string `json:"class_id1_name"`
ClassID1 int64 `json:"class_id1"`
Flag int `json:"flag"`
ClassID1Num int64 `json:"class_id1_num"`
ClassID2List []*ZhyClassID2List `json:"class_id2_list"`
}
type ZhyClassID2List struct {
ClassID2Name string `json:"class_id2_name"`
ClassID2 int64 `json:"class_id2"`
Flag int `json:"flag"`
ClassID2Num int64 `json:"class_id2_num"`
}
type ZhyClassList []*ZhyClassListModel
type ZyhResponse struct {
error_code int64 `json:"error_code"`
error_msg string `json:"error_msg"`
data interface{}
ErrorCode int64 `json:"error_code"`
ErrorMsg string `json:"error_msg"`
Data interface{} `json:"data"`
}
\ No newline at end of file
......@@ -3,15 +3,14 @@ package routes
import (
"github.com/gin-gonic/gin"
"search_server/controller"
"search_server/middleware"
)
//初始化路由
func InitRouter() *gin.Engine {
r := gin.New()
r.Use(gin.Logger())
r.Use(gin.Recovery())
r.Use(middleware.Cors())
//r.Use(gin.Logger())
//r.Use(gin.Recovery())
//r.Use(middleware.Cors())
//路由
r.POST("/search/bom/autospu", controller.AutoSpu)
r.POST("/search/bom/recommend", controller.Recommend)
......
package service
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"reflect"
"github.com/gomodule/redigo/redis"
"github.com/ichunt2019/logger"
"gopkg.in/olivere/elastic.v5"
"search_server/model"
"search_server/pkg/config"
"search_server/pkg/gredis"
"strconv"
"strings"
)
type ZyServiceImpl struct{}
......@@ -15,15 +20,15 @@ type ZyServiceImpl struct{}
/*
自营搜索
*/
func (this *ZyServiceImpl) Zyh(ctx *gin.Context, req *model.ZyhRequest, rsp *model.ZyhResponse) error {
//fmt.Printf("%+v",req)
fmt.Println(req.NeedAggs)
fmt.Println(5566)
func (this *ZyServiceImpl) Zyh(ctx *gin.Context, req map[string]string, rsp *model.ZyhResponse) (error) {
////fmt.Printf("%+v",req)
//fmt.Println(req.NeedAggs)
//fmt.Println(5566)
var (
need_aggs bool
_type byte
)
if req.NeedAggs != ""{
if req["need_aggs"] != ""{
need_aggs = false
}else{
need_aggs = true
......@@ -37,7 +42,7 @@ func (this *ZyServiceImpl) Zyh(ctx *gin.Context, req *model.ZyhRequest, rsp *mod
}
//设置cookie
setCookie(ctx,req)
rsp = zy(ctx , req ,_type,0)
rsp = zy(req ,_type,0)
return nil
}
......@@ -45,27 +50,123 @@ func NewZyServiceImpl() *ZyServiceImpl {
return &ZyServiceImpl{}
}
func setCookie(ctx *gin.Context, req *model.ZyhRequest) error{
func setCookie(ctx *gin.Context, req map[string]string) error{
//接收用户id
if req.Yo4tewUid != "" && req.Yo4tewUid != "false" {
if req["Yo4tewUid"] != "" && req["Yo4tewUid"] != "false" {
domain := config.Get("web.domain").String()
ctx.SetCookie("Yo4teW_uid", req.Yo4tewUid, 3600, "/", domain, false, true)
ctx.SetCookie("Yo4teW_uid", req["Yo4tewUid"], 3600, "/", domain, false, true)
}
return nil
}
func ajaxReturn(rsp *model.ZyhResponse,err_code int64,err_msg string,data interface{}) (*model.ZyhResponse){
rsp.ErrorCode=err_code
rsp.ErrorMsg=err_msg
rsp.Data = data
return rsp
}
//自营筛选接口数据输出
//@param _type 1:输出所有(属性统计+分类+数据详情),2 只输出属性(属性统计)
func zy(ctx *gin.Context, req *model.ZyhRequest,_type byte,isCheck byte) (rsp *model.ZyhResponse){
fmt.Printf("%+v",req)
fmt.Println(reflect.TypeOf(req.ClassIdcondition))
fmt.Println(req.ClassIdcondition)
redis_s_r :=gredis.Conn("search_r")
func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){
var (
classid int64
err error
)
rsp = &model.ZyhResponse{}
zhyClassList := &model.ZhyClassList{}
redisConn :=gredis.Conn("search_r")
classLight := make([]*model.ZhyClassListModel,0)
defer func(){
redis_s_r.Close()
redisConn.Close()
}()
classList,err := redis.String(redisConn.Do("GET",config.Get("redis_ziyin.ZIYING_CLASS_KEY")))
if(err != nil || classList == ""){
logger.Error("暂无分类信息 %s",err)
return ajaxReturn(rsp,1,"暂无分类",nil)
}
err = json.Unmarshal([]byte(classList),zhyClassList)
if err != nil{
logger.Error("解析自营分类列表失败 s%,%s",err,classList)
}
//fmt.Println(classList)
classidstr := req["class_id/condition"]
classid,err = strconv.ParseInt(classidstr, 10, 64)
if err != nil{
classid = 0
}
if classid > 0{
OuterLoop:
for _,item := range *zhyClassList{
if classid > 0 && item.ClassID1 == classid{
item.Flag = 1
classLight = append(classLight,item)
break OuterLoop
}
for _,item2 := range item.ClassID2List{
if classid > 0 && item2.ClassID2 == classid{
item2.Flag = 1
classLight = append(classLight,item)
break OuterLoop
}
}
}
}
searchZiYingGoods(req,true,zhyClassList,classLight,_type)
return nil
}
//自营型号查询
/*
@param type $arr 参数
* @param type $zy true为自营现货 false为其他页面
* @param type $class_list 所有自营分类
* @param type $class_light 高亮分类
* @param type $type 1:全部输出(属性统计+列表) 2:只输出属性统计 3:只输出列表
*/
func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassList,classLight []*model.ZhyClassListModel,aType byte){
var (
goods_name_arr []map[string]string
)
goods_name_arr = make([]map[string]string,0)
if req["goods_name/condition"] != "" {
goodsNameCondition := strings.ToUpper(req["goods_name/condition"])
ziyingBrandReplace := config.Cfg.Section("ZIYING_BRAND_REPLACE").KeysHash()
if ziyingBrandReplace != nil && ziyingBrandReplace[goodsNameCondition] != "" {
goods_name_arr = append(goods_name_arr,map[string]string{"brand_name/condition":ziyingBrandReplace[goodsNameCondition]})
}
}
if req["p"] == "" || req["p"] == "0"{
req["p"] = "1"
}
//index := config.Get("ZIYING_CONFIG")
upper_field := []string{"goods_name","encap","packing","brand_name"}
int_field := []string{"status","class_id2","class_id1","single_price","stock","goods_id","goods_type","sort",
"brand_id","sample_class_id","sample_status","sample_max_number"}
upper_field=upper_field
int_field=int_field
source := elastic.NewSearchSource()
source.StoredFields("goods_id","goods_name","sample_max_number","sample_status","sample_class_id")
query := elastic.NewBoolQuery()
fmt.Println(query)
for k,v:=range req{
k_temp := make([]string,0)
v = v
if strings.Contains(k,"/"){
k_temp = strings.Split(k,"/")
fmt.Println(k_temp)
}
}
}
package main
import (
"bytes"
"fmt"
)
func intsToString(values []int) string {
var buf bytes.Buffer
buf.WriteByte('[')
for i, v := range values {
if i > 0 {
buf.WriteString(", ")
}
fmt.Fprintf(&buf, "%d", v)
}
buf.WriteByte(']')
return buf.String()
}
func main() {
fmt.Println(intsToString([]int{1, 2, 3})) // "[1, 2, 3]"
}
\ No newline at end of file
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