Commit 3e7012c7 by huangchengyi

Merge branch 'dev' of http://119.23.72.7/mushishixian/search_server into dev

# Conflicts:
#	service/common_ly_service.go
parents e76f9d77 578ce9ad
...@@ -15,7 +15,7 @@ func AutoSpu(c *gin.Context) { ...@@ -15,7 +15,7 @@ func AutoSpu(c *gin.Context) {
if len(goods) == 0 { if len(goods) == 0 {
errCode = 1 errCode = 1
} }
res := common.Response{ res := common.BomResponse{
ErrCode: errCode, ErrCode: errCode,
ErrMsg: "", ErrMsg: "",
Data: goods, Data: goods,
......
package middleware
import (
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"search_server/pkg/config"
"time"
)
func Cors() gin.HandlerFunc {
corsDomain := config.Get("web.cors_domain").Strings(",")
return cors.New(cors.Config{
AllowOrigins: corsDomain,
AllowMethods: []string{"POST", "GET", "PUT", "DELETE"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
})
}
package model package model
type ApiGoods struct { type ApiGoods struct {
GoodsID string `json:"goods_id"` PickType int `json:"pick_type"`
GoodsName string `json:"goods_name"` BarCode string `json:"bar_code"`
GoodsType int `json:"goods_type"` GoodsId string `json:"goods_id"`
SupplierID int `json:"supplier_id"` GoodsName string `json:"goods_name"`
Moq int `json:"moq"` GoodsType int `json:"goods_type"`
Mpq int `json:"mpq"` SupplierId int `json:"supplier_id"`
Stock int `json:"stock"` Moq int `json:"moq"`
HkDeliveryTime string `json:"hk_delivery_time"` Mpq int `json:"mpq"`
CnDeliveryTime string `json:"cn_delivery_time"` Stock int `json:"stock"`
LadderPrice []LadderPrice `json:"ladder_price"` HkDeliveryTime string `json:"hk_delivery_time"`
BrandName string `json:"brand_name"` CnDeliveryTime string `json:"cn_delivery_time"`
SupplierName string `json:"supplier_name"` LadderPrice []LadderPrice `json:"ladder_price"`
BrandID int `json:"brand_id"` BrandName string `json:"brand_name"`
IsBuy int `json:"is_buy"` SupplierName string `json:"supplier_name"`
Mpl int `json:"mpl"` BrandId int `json:"brand_id"`
Status int `json:"status"` ClassId1 int `json:"class_id1"`
Pdf string `json:"pdf"` ClassId2 int `json:"class_id2"`
Encap string `json:"encap"` Encoded string `json:"encoded"`
AcType int `json:"ac_type"` Packing string `json:"packing"`
//ErpTax bool `json:"erp_tax"` GoodsUnit string `json:"goods_unit"`
GoodsImages string `json:"goods_images"`
GoodsBrief string `json:"goods_brief"`
IsBuy int `json:"is_buy"`
Mpl int `json:"mpl"`
Status int `json:"status"`
Pdf string `json:"pdf"`
Encap string `json:"encap"`
AcType int `json:"ac_type"`
OtherAttrs OtherAttrs `json:"other_attrs"`
UpdateTime int `json:"update_time"`
SkuName string `json:"sku_name"`
Attrs Attrs `json:"attrs"`
Cost string `json:"cost"`
NewCost string `json:"new_cost"`
SupplierStock int `json:"supplier_stock"`
SelfSupplierType int `json:"self_supplier_type"`
GoodsUnitName string `json:"goods_unit_name"`
PackingName string `json:"packing_name"`
MpgUnitName string `json:"mpg_unit_name"`
ScmBrandName string `json:"scm_brand_name"`
AllowCoupon int `json:"allow_coupon"`
ClassId1Name string `json:"class_id1_name"`
CLassId2Name string `json:"c_lass_id2_name"`
SpuId string `json:"spu_id,omitempty"`
BatchSn string `json:"batch_sn,omitempty"`
Canal string `json:"canal,omitempty"`
CpTime int `json:"cp_time,omitempty"`
Coefficient Coefficient `json:"coefficient,omitempty"`
OriginalPrice []OriginalPrice `json:"original_price,omitempty"`
SuppExtendFee SuppExtendFee `json:"supp_extend_fee,omitempty"`
ClassId3 int `json:"class_id3,omitempty"`
SpuName string `json:"spu_name,omitempty"`
ImagesL string `json:"images_l,omitempty"`
SpuBrief string `json:"spu_brief,omitempty"`
SpuDetail string `json:"spu_detail,omitempty"`
ClassName3 string `json:"class_name3,omitempty"`
ErpTax bool `json:"erp_tax,omitempty"`
ScmBrand ScmBrand `json:"scm_brand,omitempty"`
}
type Attr struct {
AttrName string
AttrValue string
}
type Attrs map[string]Attr
type OtherAttrs struct {
GrossWeight string `json:"gross_weight"`
} }
type LadderPrice struct { type LadderPrice struct {
Purchases int `json:"purchases"` Purchases int `json:"purchases"`
PriceUs float64 `json:"price_us"` PriceUs float64 `json:"price_us"`
PriceCn float64 `json:"price_cn"` PriceCn float64 `json:"price_cn"`
PriceAc float64 `json:"price_ac"` PriceAc float64 `json:"price_ac"`
} }
\ No newline at end of file
type Coefficient struct {
Cn string `json:"cn"`
Hk string `json:"hk"`
ExtraRatio string `json:"extra_ratio"`
Ratio string `json:"ratio"`
Tax float64 `json:"tax"`
}
type OriginalPrice struct {
Purchases int `json:"purchases"`
PriceCn float64 `json:"price_cn"`
PriceUs float64 `json:"price_us"`
}
type SuppExtendFee struct {
Cn struct {
Max int `json:"max"`
Price float64 `json:"price"`
} `json:"cn,omitempty"`
Hk struct{
Max int `json:"max"`
Price float64 `json:"price"`
} `json:"hk,omitempty"`
}
type ScmBrand struct {
ErpBrandName string `json:"erp_brand_name"`
ErpBrandId string `json:"erp_brand_id"`
ScmBrandId string `json:"scm_brand_id"`
}
package common package common
type Response struct { type Response struct {
ErrCode int `json:"err_code"` ErrCode int `json:"error_code"`
ErrMsg string `json:"err_msg"` ErrMsg string `json:"err_msg"`
Data interface{} `json:"data"` Data interface{} `json:"data"`
} }
type BomResponse struct { type BomResponse struct {
ErrCode int `json:"err_code"` ErrCode int `json:"error_code"`
ErrMsg string `json:"err_msg"` ErrMsg string `json:"error_msg"`
Flag int `json:"flag"` Flag int `json:"flag"`
Total int `json:"total"` Total int `json:"total"`
Data interface{} `json:"data"` Data interface{} `json:"data"`
......
...@@ -13,42 +13,17 @@ type RedisDatabase struct { ...@@ -13,42 +13,17 @@ type RedisDatabase struct {
//多数据库配置 //多数据库配置
func BuildRedisConfgs() (RedisDatabaseMap map[string]RedisDatabase) { func BuildRedisConfgs() (RedisDatabaseMap map[string]RedisDatabase) {
return map[string]RedisDatabase{ return map[string]RedisDatabase{
"search_read": { "search_r": {
Host: Get("default_redis_read.host").String(), Host: Get("default_redis_read.host").String(),
Password: Get("default_redis_read.password").String(), Password: Get("default_redis_read.password").String(),
MaxIdle: Get("default_redis_read.max_idle").String(), MaxIdle: Get("default_redis_read.max_idle").String(),
MaxActive: Get("default_redis_read.max_active").String(), MaxActive: Get("default_redis_read.max_active").String(),
}, },
"search_write": { "search_w": {
Host: Get("default_redis_write.host").String(), Host: Get("default_redis_write.host").String(),
Password: Get("default_redis_write.password").String(), Password: Get("default_redis_write.password").String(),
MaxIdle: Get("default_redis_read.max_idle").String(), MaxIdle: Get("default_redis_read.max_idle").String(),
MaxActive: Get("default_redis_read.max_active").String(), MaxActive: Get("default_redis_read.max_active").String(),
}, },
"spu_read": {
Host: Get("default_redis_read.host").String(),
Password: Get("default_redis_read.password").String(),
MaxIdle: Get("default_redis_read.max_idle").String(),
MaxActive: Get("default_redis_read.max_active").String(),
},
"spu_write": {
Host: Get("default_redis_write.host").String(),
Password: Get("default_redis_write.password").String(),
MaxIdle: Get("default_redis_read.max_idle").String(),
MaxActive: Get("default_redis_read.max_active").String(),
},
"api_read": {
Host: Get("api_redis_read.host").String(),
Password: Get("api_redis_read.password").String(),
MaxIdle: Get("api_redis_read.max_idle").String(),
MaxActive: Get("api_redis_read.max_active").String(),
},
"api_write": {
Host: Get("api_redis_write.host").String(),
Password: Get("api_redis_write.password").String(),
MaxIdle: Get("api_redis_write.max_idle").String(),
MaxActive: Get("api_redis_write.max_active").String(),
},
} }
} }
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
) )
type ichuntRedis struct { type ichuntRedis struct {
RedisList map[string]*redis.Pool RedisList map[string]*redis.Pool
} }
...@@ -30,11 +29,9 @@ func Setup() (err error) { ...@@ -30,11 +29,9 @@ func Setup() (err error) {
panic(err) panic(err)
} }
} }
return nil return nil
} }
func getConn(writeHost, password string) (pool *redis.Pool, err error) { func getConn(writeHost, password string) (pool *redis.Pool, err error) {
maxIdle, _ := config.Get("redis.max_idle").Int() maxIdle, _ := config.Get("redis.max_idle").Int()
maxActive, _ := config.Get("redis.max_active").Int() maxActive, _ := config.Get("redis.max_active").Int()
...@@ -60,6 +57,4 @@ func getConn(writeHost, password string) (pool *redis.Pool, err error) { ...@@ -60,6 +57,4 @@ func getConn(writeHost, password string) (pool *redis.Pool, err error) {
}, },
} }
return return
} }
\ No newline at end of file
package mysql package mysql
import ( import (
"fmt"
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"search_server/pkg/config" "search_server/pkg/config"
...@@ -12,7 +13,7 @@ var DatabaseConMap map[string]*xorm.Engine ...@@ -12,7 +13,7 @@ var DatabaseConMap map[string]*xorm.Engine
func _setup() error{ func Setup() error{
DatabaseConMap = make(map[string]*xorm.Engine,0) DatabaseConMap = make(map[string]*xorm.Engine,0)
DatabaseList := config.BuildDatabaseList() DatabaseList := config.BuildDatabaseList()
var err error var err error
...@@ -23,7 +24,7 @@ func _setup() error{ ...@@ -23,7 +24,7 @@ func _setup() error{
host := db.Host host := db.Host
database := db.Database database := db.Database
dataSourceName := userName + ":" + password + "@tcp(" + host + ")/" + database + "?charset=utf8" dataSourceName := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8",userName,password,host,database)
DatabaseConMap[conName], err = xorm.NewEngine("mysql", dataSourceName) DatabaseConMap[conName], err = xorm.NewEngine("mysql", dataSourceName)
if err!=nil{ if err!=nil{
......
...@@ -3,6 +3,7 @@ package routes ...@@ -3,6 +3,7 @@ package routes
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"search_server/controller" "search_server/controller"
"search_server/middleware"
) )
//初始化路由 //初始化路由
...@@ -10,11 +11,11 @@ func InitRouter() *gin.Engine { ...@@ -10,11 +11,11 @@ func InitRouter() *gin.Engine {
r := gin.New() r := gin.New()
r.Use(gin.Logger()) r.Use(gin.Logger())
r.Use(gin.Recovery()) r.Use(gin.Recovery())
r.Use(middleware.Cors())
//路由 //路由
r.POST("/search/bom/autospu", controller.AutoSpu) r.POST("/search/bom/autospu", controller.AutoSpu)
r.POST("/search/bom/recommend", controller.Recommend) r.POST("/search/bom/recommend", controller.Recommend)
//r.POST("search/ZiYing/zyh", controller.Zyh) r.POST("search/ZiYing/zyh", controller.Zyh)
//快手平台相关 //快手平台相关
//r.GET("/search/quote", controller.QuoteIndex) //r.GET("/search/quote", controller.QuoteIndex)
......
...@@ -3,6 +3,7 @@ package service ...@@ -3,6 +3,7 @@ package service
import ( import (
"fmt" "fmt"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
_ "github.com/gomodule/redigo/redis"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
"regexp" "regexp"
...@@ -10,6 +11,7 @@ import ( ...@@ -10,6 +11,7 @@ import (
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/es" "search_server/pkg/es"
"search_server/pkg/gredis" "search_server/pkg/gredis"
_ "search_server/pkg/gredis"
"strconv" "strconv"
"strings" "strings"
) )
...@@ -46,7 +48,9 @@ func SearchAttr(attrOrigin, encap string) (goodsName string, err error) { ...@@ -46,7 +48,9 @@ func SearchAttr(attrOrigin, encap string) (goodsName string, err error) {
numberR, _ := regexp.Compile(common.PureNumberRegular) numberR, _ := regexp.Compile(common.PureNumberRegular)
pureNumber := numberR.FindString(encap) pureNumber := numberR.FindString(encap)
//再去找对应属性 //再去找对应属性
attrName, _ := redis.String(gredis.HGet("sku_map2", pureNumber)) redisConn := gredis.Conn("default_redis_read")
defer redisConn.Close()
attrName, _ := redis.String(redisConn.Do("HGET", "sku_map2", pureNumber))
if attrName != "" { if attrName != "" {
attrValue := attrName + "€" + pureNumber attrValue := attrName + "€" + pureNumber
attrsSlice = append(attrsSlice, attrValue) attrsSlice = append(attrsSlice, attrValue)
...@@ -199,7 +203,9 @@ func getAttrValueByAttr(attr string) (attrValue string) { ...@@ -199,7 +203,9 @@ func getAttrValueByAttr(attr string) (attrValue string) {
} }
} else { } else {
//再去找没有单位的对应属性 //再去找没有单位的对应属性
attrName, _ = redis.String(gredis.HGet("sku_map2", attr)) redisConn := gredis.Conn("default_redis_read")
defer redisConn.Close()
attrName, _ := redis.String(redisConn.Do("HGET", "sku_map2", pureNumber))
if attrName != "" { if attrName != "" {
attrValue = attrName + "€" + attr attrValue = attrName + "€" + attr
} else { } else {
......
...@@ -101,7 +101,8 @@ func Recommend(req *common.RecommendRequest) (rsp *common.BomResponse) { ...@@ -101,7 +101,8 @@ func Recommend(req *common.RecommendRequest) (rsp *common.BomResponse) {
goodsIdList = append(goodsIdList, goodsId) goodsIdList = append(goodsIdList, goodsId)
} }
goodsIdListStr = strings.Join(goodsIdList, ",") goodsIdListStr = strings.Join(goodsIdList, ",")
goodsList, err := GetGoodsInfo(goodsIdListStr) goodsService := GoodsService{}
goodsList, err := goodsService.GetGoodsInfoByApi(goodsIdListStr)
response.Data = goodsList response.Data = goodsList
response.Flag = req.Flag response.Flag = req.Flag
return &response return &response
......
package service package service
import ( import (
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/imroc/req" "github.com/imroc/req"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"github.com/uniplaces/carbon" "github.com/uniplaces/carbon"
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
"regexp" "regexp"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/protopb/bom" "search_server/pkg/es"
"search_server/pkg/gredis"
"search_server/requests" "search_server/requests"
"strings" "strings"
) )
func GetGoodsInfo(goodsIdsStr string) (goodsList []*bom.GoodsModel, err error) { type GoodsService struct {
goodsServerUrl := config.Get("goods.api_url").String() }
//获取商品信息,需要传入userId用于判断是否登陆
func (gs *GoodsService) GetGoodsInfo(goodsIdsStr string, userId int) (goodsListMap map[string]*model.ApiGoods, err error) {
isNewCustomer, isMember := CheckIsNewCustomer(userId)
params := req.Param{
"goods_id": goodsIdsStr,
"power[newCustomer]": isNewCustomer,
"power[member]": isMember,
}
_, goodsListMap, err = CurlGoodsInfo(goodsIdsStr, params)
return
}
//获取商品信息
func (gs *GoodsService) GetGoodsInfoByApi(goodsIdsStr string) (goodsList []*model.ApiGoods, err error) {
params := req.Param{ params := req.Param{
"goods_id": goodsIdsStr, "goods_id": goodsIdsStr,
} }
//fmt.Println(goodsIdsStr) goodsList, _, err = CurlGoodsInfo(goodsIdsStr, params)
fmt.Println(goodsList[0].BrandId)
return
}
//isMap:是否以字典形式返回值,默认是数组
func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []*model.ApiGoods, goodsListMap map[string]*model.ApiGoods, err error) {
//req.Debug = true
goodsServerUrl := config.Get("goods.api_url").String()
resp, err := req.Post(goodsServerUrl+"/synchronization", params) resp, err := req.Post(goodsServerUrl+"/synchronization", params)
if err != nil { if err != nil {
return return
} }
goodsListMap = make(map[string]*model.ApiGoods, 1000)
//先判断返回的data是不是字典,不是字典代表可能是返回字符串了 //先判断返回的data是不是字典,不是字典代表可能是返回字符串了
if gjson.Get(resp.String(), "data").IsObject() { if gjson.Get(resp.String(), "data").IsObject() {
//排序操作 //排序操作
...@@ -29,39 +59,124 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []*bom.GoodsModel, err error) { ...@@ -29,39 +59,124 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []*bom.GoodsModel, err error) {
for _, goodsId := range goodsIdList { for _, goodsId := range goodsIdList {
for _, data := range gjson.Get(resp.String(), "data").Map() { for _, data := range gjson.Get(resp.String(), "data").Map() {
if goodsId == data.Get("goods_id").String() { if goodsId == data.Get("goods_id").String() {
//还要去判断是否是bool //还要去判断是否是false,因为商品服务可能返回 "1000":false 这样子的形式
if data.IsObject() { if data.IsObject() {
var goods bom.GoodsModel var goods model.ApiGoods
goods.GoodsName = data.Get("goods_name").String() goods.PickType = int(data.Get("pick_type").Int())
goods.BarCode = data.Get("bar_code").String()
goods.GoodsId = data.Get("goods_id").String() goods.GoodsId = data.Get("goods_id").String()
goods.BrandId = data.Get("goods_id").Int() goods.GoodsName = data.Get("goods_name").String()
goods.Pdf = data.Get("pdf").String() goods.GoodsType = int(data.Get("goods_type").Int())
goods.Stock = data.Get("stock").Int() goods.SupplierId = int(data.Get("supplier_id").Int())
goods.Mpq = data.Get("mpq").Int() goods.Mpq = int(data.Get("mpq").Int())
goods.Moq = data.Get("moq").Int() goods.Moq = int(data.Get("moq").Int())
goods.SupplierName = data.Get("supplier_name").String() goods.Stock = int(data.Get("stock").Int())
goods.BrandName = data.Get("brand_name").String() goods.HkDeliveryTime = data.Get("hk_delivery_time").String()
goods.HkDeliveryType = data.Get("hk_delivery_time").String()
goods.CnDeliveryTime = data.Get("cn_delivery_time").String() goods.CnDeliveryTime = data.Get("cn_delivery_time").String()
goods.IsBuy = data.Get("is_buy").Int() goods.BrandName = data.Get("brand_name").String()
goods.Mpl = data.Get("mpl").Int() goods.SupplierName = data.Get("supplier_name").String()
goods.BrandId = int(data.Get("goods_id").Int())
goods.ClassId1 = int(data.Get("class_id1").Int())
goods.ClassId2 = int(data.Get("class_id2").Int())
goods.Encoded = data.Get("encoded").String()
goods.Packing = data.Get("packing").String()
goods.GoodsUnit = data.Get("goods_unit").String()
goods.GoodsImages = data.Get("goods_images").String()
goods.GoodsBrief = data.Get("goods_brief").String()
goods.Mpl = int(data.Get("mpl").Int())
goods.Status = int(data.Get("status").Int())
goods.IsBuy = int(data.Get("is_buy").Int())
goods.Pdf = data.Get("pdf").String()
goods.Encap = data.Get("encap").String() goods.Encap = data.Get("encap").String()
goods.SupplierId = data.Get("supplier_id").Int() goods.AcType = int(data.Get("ac_type").Int())
goods.Status = data.Get("status").Int() goods.SkuName = data.Get("sku_name").String()
goods.GoodsType = data.Get("goods_type").Int() goods.Cost = data.Get("const").String()
goods.AcType = data.Get("ac_type").Int() goods.NewCost = data.Get("new_const").String()
ladderPrice := make([]*bom.LadderPrice, 0) goods.SupplierStock = int(data.Get("supplier_stock").Int())
goods.SelfSupplierType = int(data.Get("self_supplier_type").Int())
goods.GoodsUnitName = data.Get("goods_unit_name").String()
goods.PackingName = data.Get("packing_name").String()
goods.MpgUnitName = data.Get("mpg_unit_name").String()
goods.ScmBrandName = data.Get("scm_brand_name").String()
goods.AllowCoupon = int(data.Get("allow_coupon").Int())
goods.ClassId1Name = data.Get("class_id1_name").String()
goods.CLassId2Name = data.Get("c_lass_id2_name").String()
goods.SpuId = data.Get("spu_id").String()
goods.BatchSn = data.Get("batch_sn").String()
goods.Canal = data.Get("canal").String()
goods.CpTime = int(data.Get("cp_time").Int())
goods.ClassId3 = int(data.Get("class_id3").Int())
goods.SpuName = data.Get("spu_name").String()
goods.ImagesL = data.Get("images_l").String()
goods.SpuBrief = data.Get("spu_brief").String()
goods.SpuDetail = data.Get("spu_detail").String()
goods.ClassName3 = data.Get("class_name3").String()
goods.ErpTax = data.Get("erp_tax").Bool()
goods.SupplierId = int(data.Get("supplier_id").Int())
goods.GoodsType = int(data.Get("goods_type").Int())
//ladder_price
ladderPrice := make([]model.LadderPrice, 0)
for _, price := range data.Get("ladder_price").Array() { for _, price := range data.Get("ladder_price").Array() {
ladder := bom.LadderPrice{ ladder := model.LadderPrice{
Purchases: price.Get("purchases").Int(), Purchases: int(price.Get("purchases").Int()),
PriceUs: float32(price.Get("price_us").Float()), PriceUs: price.Get("price_us").Float(),
PriceCn: float32(price.Get("price_cn").Float()), PriceCn: price.Get("price_cn").Float(),
PriceAc: float32(price.Get("price_ac").Float()), PriceAc: price.Get("price_ac").Float(),
} }
ladderPrice = append(ladderPrice, &ladder) ladderPrice = append(ladderPrice, ladder)
} }
goods.LadderPrice = ladderPrice goods.LadderPrice = ladderPrice
//other_attrs
goods.OtherAttrs.GrossWeight = data.Get("other_attrs.gross_weight").String()
//Attrs
attrMap := make(map[string]model.Attr, 0)
for key, attr := range data.Get("attrs").Array() {
attr := model.Attr{
AttrName: attr.Get("attr_name").String(),
AttrValue: attr.Get("attr_value").String(),
}
attrMap[common.ToString(key)] = attr
}
goods.Attrs = attrMap
//coefficient
goods.Coefficient.Cn = data.Get("coefficient.cn").String()
goods.Coefficient.Hk = data.Get("coefficient.hk").String()
goods.Coefficient.ExtraRatio = data.Get("coefficient.extra_ratio").String()
goods.Coefficient.Ratio = data.Get("coefficient.ratio").String()
goods.Coefficient.Tax = data.Get("coefficient.tax").Float()
//original_price
originalPrice := make([]model.OriginalPrice, 0)
for _, price := range data.Get("ladder_price").Array() {
price := model.OriginalPrice{
Purchases: int(price.Get("purchases").Int()),
PriceUs: price.Get("price_us").Float(),
PriceCn: price.Get("price_cn").Float(),
}
originalPrice = append(originalPrice, price)
}
goods.OriginalPrice = originalPrice
//supp_extend_fee
goods.SuppExtendFee.Cn.Max = int(data.Get("supp_extend_fee.cn.max").Int())
goods.SuppExtendFee.Cn.Price = data.Get("supp_extend_fee.cn.price").Float()
goods.SuppExtendFee.Hk.Max = int(data.Get("supp_extend_fee.cn.max").Int())
goods.SuppExtendFee.Hk.Price = data.Get("supp_extend_fee.cn.price").Float()
//scm_brand
goods.ScmBrand.ErpBrandName = data.Get("scm_brand.erp_brand_name").String()
goods.ScmBrand.ErpBrandId = data.Get("scm_brand.erp_brand_id").String()
goods.ScmBrand.ScmBrandId = data.Get("scm_brand.scm_brand_id").String()
goodsList = append(goodsList, &goods) goodsList = append(goodsList, &goods)
goodsListMap[goodsId] = &goods
} else {
goodsListMap[goodsId] = nil
} }
} }
} }
...@@ -70,16 +185,40 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []*bom.GoodsModel, err error) { ...@@ -70,16 +185,40 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []*bom.GoodsModel, err error) {
return return
} }
func CheckIsNewCustomer(userId int) (isNewCustomer, isMember bool) {
//判断新客价
if userId != 0 {
redisConn := gredis.Conn("default_redis_read")
defer redisConn.Close()
userInfoStr, err := redis.String(redisConn.Do("HGET", "api_user", userId))
if err != nil {
return
}
// 新客户显示新客价
isNewExist := gjson.Get(userInfoStr, "is_new").Exists()
isNew := gjson.Get(userInfoStr, "is_new").Int()
if isNewExist && isNew == 0 {
isNewCustomer = true
}
isMember = true
} else {
// 未登录显示新客价
isNewCustomer = true
isMember = false
}
return
}
//根据供应商获取商品信息 //根据供应商获取商品信息
func GetGoodsInfoBySupplier(req requests.QuoteIndexRequest) error { func GetGoodsInfoBySupplier(req requests.QuoteIndexRequest) error {
//supplierIndex := config.Get("es.search_supplier").String() supplierIndex := config.Get("es.search_supplier").String()
////获取查询条件 //获取查询条件
//queryString := getSupplierQuery(req) queryString, err := getSupplierQuery(req)
//res, err := es.CurlES(supplierIndex, queryString) res, err := es.CurlES(supplierIndex, queryString)
//if err != nil { if err != nil {
// return err return err
//} }
//fmt.Println(supplierIndex) fmt.Println(res)
return nil return nil
} }
...@@ -240,7 +379,10 @@ func getSupplierQuery(req requests.QuoteIndexRequest) (string, error) { ...@@ -240,7 +379,10 @@ func getSupplierQuery(req requests.QuoteIndexRequest) (string, error) {
//todo : $params['preference'] = '_primary_first'; //todo : $params['preference'] = '_primary_first';
//判断是否要排除某些品牌 //判断是否要排除某些品牌
//todo : 待确定需不需要接入 excludeBrandId := model.GetExcludeBrandIds(1)
for _, brandId := range excludeBrandId {
query.MustNot(elastic.NewTermQuery("brand_id", brandId))
}
searchRequest := elastic.NewSearchRequest().Source(source) searchRequest := elastic.NewSearchRequest().Source(source)
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"reflect" "reflect"
"search_server/model" "search_server/model"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/gredis"
) )
type ZyServiceImpl struct{} type ZyServiceImpl struct{}
...@@ -59,5 +60,12 @@ func zy(ctx *gin.Context, req *model.ZyhRequest,_type byte,isCheck byte) (rsp *m ...@@ -59,5 +60,12 @@ func zy(ctx *gin.Context, req *model.ZyhRequest,_type byte,isCheck byte) (rsp *m
fmt.Printf("%+v",req) fmt.Printf("%+v",req)
fmt.Println(reflect.TypeOf(req.ClassIdcondition)) fmt.Println(reflect.TypeOf(req.ClassIdcondition))
fmt.Println(req.ClassIdcondition) fmt.Println(req.ClassIdcondition)
redis_s_r :=gredis.Conn("search_r")
defer func(){
redis_s_r.Close()
}()
return nil return nil
} }
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"search_server/boot" "search_server/boot"
"search_server/pkg/mysql" "search_server/service"
) )
func main() { func main() {
...@@ -14,20 +14,6 @@ func main() { ...@@ -14,20 +14,6 @@ func main() {
if err := boot.Boot(path); err != nil { if err := boot.Boot(path); err != nil {
fmt.Println(err) fmt.Println(err)
} }
type Result struct { service1:= service.GoodsService{}
BinId int `json:"bin_id"` fmt.Println(service1.GetGoodsInfoByApi("1151005920927710088,1150961641855982990,1150961724815213435"))
Bin string `json:"bin"`
}
var result []Result
mysql.Connection("bom").Raw("SELECT * FROM lie_bin").Scan(&result)
//mysql.Connection()("bom").Table("bin").Find(&result)
fmt.Println(result)
type Result2 struct {
BusinessName string `json:"business_name"`
}
var result2 []Result2
mysql.Connection("mysql").Raw("SELECT * FROM lie_business").Scan(&result2)
//mysql.GetDB("bom").Table("bin").Find(&result)
fmt.Println(result2)
} }
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