Commit c058ee2a by 孙龙

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

# Conflicts:
#	conf/redis_key.ini
#	conf/search.ini
#	routes/router.go
#	test/test4.go
parents 8d014493 326ae7ed
...@@ -2,8 +2,8 @@ package main ...@@ -2,8 +2,8 @@ package main
import ( import (
"flag" "flag"
"fmt"
"os" "os"
"fmt"
"search_server/boot" "search_server/boot"
"search_server/pkg/gredis" "search_server/pkg/gredis"
"search_server/service" "search_server/service"
...@@ -19,12 +19,20 @@ func main() { ...@@ -19,12 +19,20 @@ func main() {
panic(err) panic(err)
} }
lock_key := "searchapi_6666"; //lock_key := "searchapi_668777";
//flag := gredis.Set(lock_key,php2go.Time()+2) ////flag := gredis.Set(lock_key,php2go.Time()+2)
flag := gredis.Setnx(lock_key,2222) //flag,_ := gredis.Setnx(lock_key,2222)
fmt.Println(flag) //
os.Exit(1) //fmt.Println(flag)
//os.Exit(1)
redisConn := gredis.Conn("search_r")
defer redisConn.Close()
attrName, err := gredis.String(redisConn.Do("GET", "hcy1"))
fmt.Println(err)
fmt.Println(attrName)
//os.Exit(1)
dd := service.OutLink("LM358","-1") dd := service.OutLink("LM358","-1")
print("niin") print("niin")
print(dd) print(dd)
......
...@@ -16,3 +16,11 @@ host = 192.168.2.250 ...@@ -16,3 +16,11 @@ host = 192.168.2.250
database = test database = test
table_prefix = table_prefix =
type = mysql type = mysql
[spu]
user_name = spu
password = spu
host = 192.168.1.234
database = liexin_spu
table_prefix =lie_
type = mysql
\ No newline at end of file
...@@ -6,6 +6,8 @@ SUPPLIER_REDIS_PRE=SUPPLIER_REDIS_INFO_ ...@@ -6,6 +6,8 @@ SUPPLIER_REDIS_PRE=SUPPLIER_REDIS_INFO_
SUPPLIER_REDIS_LIST_PRE=SUPPLIER_REDIS_LIST_INFO_ SUPPLIER_REDIS_LIST_PRE=SUPPLIER_REDIS_LIST_INFO_
;新增sku时判读sku是否存在 ;新增sku时判读sku是否存在
SKU_UNIQUE_JUDGE=sku_unique_judge SKU_UNIQUE_JUDGE=sku_unique_judge
;新增sku时判读sku是否存在
SPU_UNIQUE_JUDGE=sku_unique_judge
;品牌信息判断,根据md5后的品牌名称获取id ;品牌信息判断,根据md5后的品牌名称获取id
BRAND_NAME_ALL=brand_name_all BRAND_NAME_ALL=brand_name_all
;品牌id,获取品牌名称 ;品牌id,获取品牌名称
...@@ -25,3 +27,11 @@ TAX_CUSTOMS_INFO=tax_customs_info ...@@ -25,3 +27,11 @@ TAX_CUSTOMS_INFO=tax_customs_info
AGG_TABLE=sz_ziying_class_aggs AGG_TABLE=sz_ziying_class_aggs
FIRST_LISTS_TABLE=ziying_first_lists FIRST_LISTS_TABLE=ziying_first_lists
ZIYING_CLASS_KEY=ziying_class_string ZIYING_CLASS_KEY=ziying_class_string
TAX_CUSTOMS_INFO=tax_customs_info
;存放联营所有sku
SKU=sku
;存放联营所有spu
SPU=SPU
;存放digikey 型号映射
SKU_RAW_MAP=sku_raw_map
POOL_ALIKE_GOODS=pool_alike_goods
[supplier_all] [supplier_all]
1 ="rochester" 1 = "rochester"
2 ="verical" 2 = "verical"
3 ="tme" 3 = "tme"
#相似物料供应商 #相似物料供应商
[alike_supplier] [alike_supplier]
1 = "ti" 1 = "ti"
[common] [common]
'MOUSER_API'='http://footstone.liexin.net/webapi/handle_mouser' MOUSER_API='http://footstone.liexin.net/webapi/handle_mouser'
[brand] [brand]
IS_NOT_TI = 0 IS_NOT_TI = 0
TI_LY_BRAND_IDS=23,45069,7754,17484,43215,13421,5220,7636,44534,43556,44543,9429,758,9470,10430,10653,10707,11227,11276,11819,12608,12965,12997,13327,13675,13680,13752 TI_LY_BRAND_IDS = 23,45069,7754,17484,43215,13421,5220,7636,44534,43556,44543,9429,758,9470,10430,10653,10707,11227,11276,11819,12608,12965,12997,13327,13675,13680,13752
TI_ZY_BRAND_IDS=23 TI_ZY_BRAND_IDS = 23
[supplier] [supplier]
# 供应商redis的首key # 供应商redis的首key
...@@ -45,3 +46,34 @@ MK=MK(米客方德) ...@@ -45,3 +46,34 @@ MK=MK(米客方德)
[ZIYING_CONFIG] [ZIYING_CONFIG]
Index=liexin_ziying Index=liexin_ziying
[official_website]
1 = https://www.futureelectronics.cn/search/?text=liexin
2 = http://www.powerandsignal.com/Products/Search?searchBox=liexin
3 = https://www.rocelec.com/search?q=liexin
4 = https://www.tme.eu/zh/katalog/#search=liexin
5 = https://www.verical.com/s/liexin/
6 = https://cn.element14.com/search?st=liexin
7 = https://www.digikey.com/products/en?keywords=liexin
8 = https://www.chip1stop.com/CHN/zh/view/searchResult/SearchResultTop?keyword=liexin
9 = http://www.aipco.com/search.php?pn=liexin
10 = https://www.arrow.com/en/products/search?cat=&q=liexin
11 = https://www.biscoind.com?SEARCHTEXT=liexin
12 = https://www.alliedelec.com/view/search?keyword=liexin
13 = https://www.avnet.com/shop/apac/search/liexin
14 = https://www.mouser.com/Search/Refine?Keyword=liexin
15 =
16 =
18 =
19 = https://www.peigenesis.cn/cn/shop/f/liexin.html
20 = https://www.powell.com/e2wItemQuickSearch.aspx?searchText=liexin
21 = https://uk.rs-online.com/web/c/semiconductors/amplifiers-comparators/op-amps/?searchTerm=liexin
22 =
1672 = https://www.masterelectronics.com/parts.aspx?text=liexin
1673 = https://www.rutronik24.com/search-result/qs:liexin
1675 = https://www.zaikostore.com/zaikostore/stockList?productName_forFind=liexin
1676 = https://www.buerklin.com/en/search?text=liexin
1677 = https://www.microchipdirect.com/product/search/all/liexin
1678 = https://estore.heilindasia.com/search.asp?p=liexin
1680 = http://shop.wpgam.com/WPGAStore/index.php?route=product/search&filter_description=true&filter_name=liexin
...@@ -2,43 +2,33 @@ package controller ...@@ -2,43 +2,33 @@ package controller
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"search_server/framework/gin_" "search_server/model"
"search_server/protopb/mouser" "search_server/pkg/common"
"search_server/service" "search_server/service"
) )
func init() { //搜索型号
MouserService := service.NewMouserServiceImpl() func GetMouserData(c *gin.Context) {
gin_.NewBuilder().WithService(MouserService). goodsName, _ := c.GetPostForm("goods_name")
WithEndpoint(MouserGetData(MouserService)). lycon := new(service.CommonLyService)
WithRequest(MouserRequest()).
WithResponse(MouserResponse()).Build("/search/mouser/test", "POST")
} //调外链拿数据
//处理请求 apiData := service.OutLink(&goodsName,"1")
func MouserGetData(c *service.MouserServiceImpl) gin_.Endpoint {
return func(context *gin.Context, request interface{}) (response interface{}, err error) { //供应商详情
rsp := &mouser.MouserResponse{} supplierInfo := model.SUPPLIER_REDIS_INFO_{
//err = c.MouserGetData(context, request.(*mouser.MouserRequest), rsp) SupplierId:14,
return rsp, err SupplierNickname: "mouser",
}
}
//接收请求
func MouserRequest() gin_.EncodeRequestFunc {
return func(context *gin.Context) (i interface{}, e error) {
bReq := &mouser.MouserRequest{}
err := context.BindQuery(bReq) //使用的是query 参数
bReq.GoodsName, _ = context.GetPostForm("goods_name")
if err != nil {
return nil, err
} }
return bReq, nil goods := lycon.GetSkuByGoodsSn(apiData,&supplierInfo)
var errCode int
if len(goods) == 0 {
errCode = 1
} }
} res := common.BomResponse{
//响应请求 ErrCode: errCode,
func MouserResponse() gin_.DecodeResponseFunc { ErrMsg: "",
return func(context *gin.Context, res interface{}) error { Data: goods,
context.JSON(200, res)
return nil
} }
c.JSON(200, res)
} }
...@@ -30,9 +30,11 @@ func QuoteIndex(c *gin.Context) { ...@@ -30,9 +30,11 @@ func QuoteIndex(c *gin.Context) {
return return
} }
var res interface{}
if request.FollowHit != 0 && request.FollowHit != 1 { if request.FollowHit != 0 && request.FollowHit != 1 {
service.GetGoodsBySupplier(request) res,_ = service.GetGoodsBySupplier(request)
} else { } else {
res,_ = service.GetGoodsBySupplier(request)
} }
flag := 1 flag := 1
...@@ -43,7 +45,7 @@ func QuoteIndex(c *gin.Context) { ...@@ -43,7 +45,7 @@ func QuoteIndex(c *gin.Context) {
c.JSON(200, common.Response{ c.JSON(200, common.Response{
ErrCode: flag, ErrCode: flag,
ErrMsg: "", ErrMsg: "",
Data: nil, Data: res,
}) })
} }
package dao
import (
"encoding/json"
"github.com/ichunt2019/logger"
"search_server/model"
"search_server/pkg/mysql"
)
//根据id获取供应商信息
func GetSupplierExtraBySupplierId(supplierId int) (supplierExtra model.SupplierExtra, err error) {
_, err = mysql.Conn("spu").Table("lie_supplier_extra").Select("hk_delivery,cn_delivery,price_json as price_json_str,ad_text,supplier_logo,ad_url,sort").
Where("supplier_id = ?", supplierId).Get(&supplierExtra)
if supplierExtra.PriceJsonStr != "" {
err = json.Unmarshal([]byte(supplierExtra.PriceJsonStr), &supplierExtra.PriceJson)
if err != nil {
logger.Error("%s", err)
}
}
return
}
...@@ -4,6 +4,7 @@ go 1.14 ...@@ -4,6 +4,7 @@ go 1.14
require ( require (
github.com/basgys/goxml2json v1.1.0 github.com/basgys/goxml2json v1.1.0
github.com/coreos/etcd v3.3.18+incompatible
github.com/gin-contrib/cors v1.3.1 github.com/gin-contrib/cors v1.3.1
github.com/gin-gonic/gin v1.6.3 github.com/gin-gonic/gin v1.6.3
github.com/go-ini/ini v1.57.0 github.com/go-ini/ini v1.57.0
......
package middleware
import (
"github.com/gin-gonic/gin"
)
var Context *gin.Context
//将gin的上下文放到全局变量
func ContextVars() gin.HandlerFunc {
return func(c *gin.Context) {
//将gin的上下文放到全局变量
Context = c
c.Next()
}
}
...@@ -8,9 +8,14 @@ type ApiGoods struct { ...@@ -8,9 +8,14 @@ type ApiGoods struct {
GoodsSn string `json:"goods_sn"` GoodsSn string `json:"goods_sn"`
GoodsType int `json:"goods_type"` GoodsType int `json:"goods_type"`
SupplierId int `json:"supplier_id"` SupplierId int `json:"supplier_id"`
Moq int `json:"moq"` Moq int `json:"-"`
Mpq int `json:"mpq"` MoqStr interface{} `json:"moq"`
Stock int `json:"stock"` Mpq int `json:"-"`
MpqStr interface{} `json:"mpq"`
Mpl int `json:"-"`
MplStr interface{} `json:"mpl"`
Stock int `json:"-"`
StockStr interface{} `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"` HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"` CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []LadderPrice `json:"ladder_price"` LadderPrice []LadderPrice `json:"ladder_price"`
...@@ -25,7 +30,6 @@ type ApiGoods struct { ...@@ -25,7 +30,6 @@ type ApiGoods struct {
GoodsImages string `json:"goods_images"` GoodsImages string `json:"goods_images"`
GoodsBrief string `json:"goods_brief,omitempty"` GoodsBrief string `json:"goods_brief,omitempty"`
IsBuy int `json:"is_buy"` IsBuy int `json:"is_buy"`
Mpl int `json:"mpl"`
Status int `json:"status"` Status int `json:"status"`
Pdf string `json:"pdf"` Pdf string `json:"pdf"`
Encap string `json:"encap"` Encap string `json:"encap"`
...@@ -60,11 +64,34 @@ type ApiGoods struct { ...@@ -60,11 +64,34 @@ type ApiGoods struct {
ClassName3 string `json:"class_name3,omitempty"` ClassName3 string `json:"class_name3,omitempty"`
ErpTax bool `json:"erp_tax"` ErpTax bool `json:"erp_tax"`
ScmBrand ScmBrand `json:"scm_brand,omitempty"` ScmBrand ScmBrand `json:"scm_brand,omitempty"`
}
//经过处理后的商品数据
type DullGoodsData struct {
ApiGoods
//额外增加的字段 //额外增加的字段
GoodsNameTemp string `json:"goods_name_temp,omitempty"` GoodsNameTemp string `json:"goods_name_temp,omitempty"`
Multiple int `json:"multiple,omitempty"` Multiple int `json:"-"`
MultipleStr interface{} `json:"multiple,omitempty"`
SupplierLogo string `json:"supplier_logo,omitempty"`
SupplierSort int `json:"supplier_sort,omitempty"`
SupplierAd interface{} `json:"supplier_ad"`
SearchSampleApplication string `json:"search_sample_application"` SearchSampleApplication string `json:"search_sample_application"`
SearchContactExperts string `json:"search_contact_experts"` SearchContactExperts string `json:"search_contact_experts"`
PageFlag int `json:"page_flag"`
SupplierWebsite string `json:"supplier_website"`
PurchaseName string `json:"purchase_name"`
Ratio int `json:"ratio"`
PriceXs float64 `json:"price_xs"`
PriceProfit float64 `json:"price_profit"`
PriceHkxs float64 `json:"price_hkxs"`
CouponId int `json:"coupon_id"`
CouponTitle string `json:"coupon_title"`
LastSearchTime int `json:"last_search_time"`
CustomsTax string `json:"customs_tax"`
Alike string `json:"alike"`
BrandUrl string `json:"brand_url"`
GoodsUrl string `json:"goods_url"`
} }
type Attr struct { type Attr struct {
...@@ -79,17 +106,18 @@ type OtherAttrs struct { ...@@ -79,17 +106,18 @@ type OtherAttrs struct {
} }
type LadderPrice struct { type LadderPrice struct {
Purchases int `json:"purchases"` Purchases int `json:"-"`
PurchasesStr interface{} `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,omitempty"`
} }
type Coefficient struct { type Coefficient struct {
Cn string `json:"cn"` Cn float64 `json:"cn"`
Hk string `json:"hk"` Hk float64 `json:"hk"`
ExtraRatio string `json:"extra_ratio"` ExtraRatio float64 `json:"extra_ratio"`
Ratio string `json:"ratio"` Ratio float64 `json:"ratio"`
Tax float64 `json:"tax"` Tax float64 `json:"tax"`
} }
......
...@@ -11,14 +11,17 @@ type LyClearGoodsList struct { ...@@ -11,14 +11,17 @@ type LyClearGoodsList struct {
GoodsImg string `json:"goods_img"` //sku图片 GoodsImg string `json:"goods_img"` //sku图片
Cat string `json:"cat"` //分类 Cat string `json:"cat"` //分类
RestrictionMessage string `json:"RestrictionMessage"` //额外购买限制内容,如 ‘当前商品不在本地区销售’ RestrictionMessage string `json:"RestrictionMessage"` //额外购买限制内容,如 ‘当前商品不在本地区销售’
Increment uint64 `json:"increment"` //最小包装量、倍数 Increment int64 `json:"increment"` //最小包装量、倍数 =Mpq
SinglePrice float64 `json:"single_price"` //最小单价 SinglePrice float64 `json:"single_price"` //最小单价
Stock int64 `json:"increment"` //库存
Moq int64 `json:"moq"` //最小起订量、起订量
Tiered []*TierItem //价格梯度数量 Tiered []*TierItem //价格梯度数量
} }
type TierItem struct { type TierItem struct {
Purchases uint64 //购买数量 Purchases uint64 //购买数量
PriceUs float64 //数量对应的英文价格 PriceUs float64 //数量对应的英文价格
PriceCn float64 //数量对应的中文价格 PriceCn float64 //数量对应的中文价格
PriceAc float64 `json:"price_ac"`
} }
/* /*
...@@ -48,7 +51,7 @@ Array ...@@ -48,7 +51,7 @@ Array
) )
*/ */
type SUPPLIER_REDIS_INFO_ struct { type SUPPLIER_REDIS_INFO_ struct {
SupplierId string `json:"supplier_id"` //供应商id SupplierId int64 `json:"supplier_id"` //供应商id
SupplierNickname string `json:"supplier_nickname"` //供应商名称 SupplierNickname string `json:"supplier_nickname"` //供应商名称
AdText string `json:"ad_text"` //供应商描述 AdText string `json:"ad_text"` //供应商描述
CnDelivery string `json:"cn_delivery"` //国内交货时间 CnDelivery string `json:"cn_delivery"` //国内交货时间
...@@ -116,28 +119,23 @@ Array ...@@ -116,28 +119,23 @@ Array
type LySkuInfo struct { type LySkuInfo struct {
SpuId string `json:"spu_id"` //spu_id SpuId string `json:"spu_id"` //spu_id
Encoded string `json:"encoded"` Encoded string `json:"encoded"`
Moq int `json:"moq"` Moq int64 `json:"moq"`
Mpq int `json:"mpq"` Mpq int64 `json:"mpq"`
OldGoodsId int `json:"old_goods_id"` OldGoodsId int64 `json:"old_goods_id"`
GoodsType int `json:"goods_type"` GoodsType int `json:"goods_type"`
GoodsStatus int `json:"goods_status"` GoodsStatus int `json:"goods_status"`
BatchSn string `json:"batch_sn"` BatchSn string `json:"batch_sn"`
Stock string `json:"stock"` Stock int64 `json:"stock"`
UpdateTime string `json:"update_time"` UpdateTime int64 `json:"update_time"`
GoodsImages string `json:"goods_images"` GoodsImages string `json:"goods_images"`
Canal string `json:"canal"` Canal string `json:"canal"`
SupplierId string `json:"supplier_id"` SupplierId int64 `json:"supplier_id"`
IsExpire string `json:"is_expire"` IsExpire string `json:"is_expire"`
HkDeliveryTime string `json:"hk_delivery_time"` HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"` CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []*LadderPrice2 `json:"ladder_price"` LadderPrice []*TierItem `json:"ladder_price"`
}
type LadderPrice2 struct {
Purchases int `json:"purchases"` //数量
PriceUs float64 `json:"price_us"` //英文价格
PriceCn float64 `json:"price_cn"` //中文价格
PriceAc float64 `json:"price_ac"`
} }
/* /*
spu详情 spu详情
Array Array
...@@ -154,17 +152,17 @@ Array ...@@ -154,17 +152,17 @@ Array
[spu_brief] => [spu_brief] =>
[update_time] => 1540893752 [update_time] => 1540893752
) )
*/ */
type LySpuInfo struct { type LySpuInfo struct {
ClassId1 string `json:"class_id1"` //一级分类 ClassId1 int64 `json:"class_id1"` //一级分类
ClassId2 string `json:"class_id2"` //二级分类 ClassId2 int64 `json:"class_id2"` //二级分类
ClassId3 string `json:"class_id3"` //三级分类 ClassId3 int64 `json:"class_id3"` //三级分类
BrandId string `json:"brand_id"` //品牌ID BrandId int64 `json:"brand_id"` //品牌ID
SpuName string `json:"spu_name"` //型号名称 SpuName string `json:"spu_name"` //型号名称
Status string `json:"status"` // 状态 Status int `json:"status"` // 状态
ImagesL string `json:"images_l"` //图片 ImagesL string `json:"images_l"` //图片
Encap string `json:"encap"` //封装 Encap string `json:"encap"` //封装
Pdf string `json:"pdf"` //pdf Pdf string `json:"pdf"` //pdf
SpuBrief string `json:"spu_brief"` //描述 SpuBrief string `json:"spu_brief"` //描述
UpdateTime string `json:"update_time"` //更新时间 UpdateTime int64 `json:"update_time"` //更新时间
} }
...@@ -6,18 +6,25 @@ import ( ...@@ -6,18 +6,25 @@ import (
"search_server/pkg/gredis" "search_server/pkg/gredis"
) )
type QuoteSupplier struct { type SupplierExtra struct {
HkDelivery string `json:"hk_delivery"` HkDelivery string `json:"hk_delivery"`
CnDelivery string `json:"cn_delivery"` CnDelivery string `json:"cn_delivery"`
PriceJson string `json:"price_json"` PriceJson []PriceJson `json:"price_json"`
PriceJsonStr string `json:"-"`
AdText string `json:"ad_text"` AdText string `json:"ad_text"`
SupplierLogo string `json:"supplier_logo"` SupplierLogo string `json:"supplier_logo"`
AdUrl string `json:"ad_url"` AdUrl string `json:"ad_url"`
Sort int `json:"sort"` Sort int `json:"sort"`
} }
type PriceJson struct {
Hk float64 `json:"hk"`
Cn float64 `json:"cn"`
Rate float64 `json:"rate"`
}
func getSupplier(supplierId string) { func getSupplier(supplierId string) {
redisCon := gredis.Conn("default_r") redisCon := gredis.Conn("search_r")
defer redisCon.Close() defer redisCon.Close()
supplierInfoStr, _ := redis.String(redisCon.Do("HGET", config.Get("supplier.SUPPLIER_REDIS_PRE"))) supplierInfoStr, _ := redis.String(redisCon.Do("HGET", config.Get("supplier.SUPPLIER_REDIS_PRE")))
if supplierInfoStr != "" { if supplierInfoStr != "" {
......
...@@ -2,10 +2,16 @@ package common ...@@ -2,10 +2,16 @@ package common
import ( import (
"crypto/md5" "crypto/md5"
crand "crypto/rand"
"encoding/hex" "encoding/hex"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"math/big"
"math/rand"
"regexp" "regexp"
"search_server/pkg/vars"
"strconv" "strconv"
"strings"
"time"
) )
// Md5 md5() // Md5 md5()
...@@ -65,9 +71,80 @@ func CaseInsensitiveReplace(subject string, search string, replace string) strin ...@@ -65,9 +71,80 @@ func CaseInsensitiveReplace(subject string, search string, replace string) strin
return searchRegex.ReplaceAllString(subject, replace) return searchRegex.ReplaceAllString(subject, replace)
} }
/*
md5字符串
*/
func GetKey(s string) string {
return php2go.Md5(strings.ToLower(s))
}
/** /**
* 获取联营活动价 * 获取联营活动价
*/ */
func lyActivityPrice() { func lyActivityPrice() {
} }
/*构造SPU和SKU的ID
*生成19位纯数组id
*/
func CreateId(types string) string {
var id, db string
if types == "sku" {
id = "1"
db = strconv.Itoa(php2go.Rand(0, 9)) + strconv.Itoa(php2go.Rand(0, 9))
} else {
id = "2"
db = "0" + strconv.Itoa(php2go.Rand(0, 9))
}
s := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000)
return id + strconv.FormatInt(int64(s), 10) + strconv.FormatInt(php2go.Time(), 10) + db
}
/*
* 反爬虫用html标签替换数字,不包括“.”
* number 数字串
*/
func NumberToHtml(number int) (html string) {
numberToClassSlice := vars.NumberToClass
if number != 0 {
//数字转字符串
numberStr := ToString(number)
for i := 0; i < len(numberStr); i++ {
var classHtml string
numStr := php2go.Substr(numberStr, uint(i), 1)
if php2go.IsNumeric(numStr) {
num, _ := strconv.Atoi(numStr)
index := php2go.Rand(0, 3)
class := numberToClassSlice[num][index]
otherClass := StrRandom(3)
classHtml = `<font class="` + class + otherClass + `"></font>`
}
html = html + classHtml
return
}
}
return
}
/**
* 生成纯小写字母的字符串
* 返回形式如下 : yuiopkdsi rnvewjeil xmiqplmza
*/
func StrRandom(lenNum int) string {
randStr := "sdwpkxmiqplmzacbmeruwulurjlauejrifkfghjklzxcvbnmqwwertyuiopkdsieurnvewjeilweiskvnx"
strLen := len(randStr) - 9
var result string
for i := 0; i < lenNum; i++ {
start := php2go.Rand(0, strLen)
str := php2go.Substr(randStr, uint(start), 9)
result = result + " " + str
}
return result
}
//生成范围区间内的随机数
func Rand(min, max int) int {
n, _ := crand.Int(crand.Reader, big.NewInt(int64(max+1)))
return int(n.Int64()) + min
}
package common
import (
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"search_server/pkg/config"
"search_server/pkg/gredis"
"strings"
)
//获取上次查询时间等信息
func GetLastSearchTime(goodsId string) (timeStamp int) {
redisCon := gredis.Conn("search_r")
defer redisCon.Close()
key := config.Get("redis_all.SEARCH_SHOW_SKU_TIME").String()
timeStamp, err := redis.Int(redisCon.Do("HGET", key, goodsId))
if err != nil {
timeStamp = 0
}
return
}
//获取关税信息
func GetCustomsTax(goodsName, brandName string) (tax string) {
if goodsName == "" || brandName == "" {
return
}
redisCon := gredis.Conn("search_r")
defer redisCon.Close()
member := php2go.Md5(strings.ToUpper(goodsName + brandName))
key := config.Get("redis_all.TAX_CUSTOMS_INFO")
res, _ := redis.String(redisCon.Do("HGET", key, member))
taxRateRow := gjson.Get(res, "tax_rate_low").Float()
if res == "" || taxRateRow <= 0 {
return
}
return ToString(taxRateRow) + "%"
}
...@@ -27,5 +27,12 @@ func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) { ...@@ -27,5 +27,12 @@ func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) {
Database: Get("bom.database").String(), Database: Get("bom.database").String(),
Prefix: Get("mysql.prefix").String(), Prefix: Get("mysql.prefix").String(),
}, },
"spu": {
UserName: Get("spu.user_name").String(),
Password: Get("spu.password").String(),
Host: Get("spu.host").String(),
Database: Get("spu.database").String(),
Prefix: Get("spu.table_prefix").String(),
},
} }
} }
...@@ -2,19 +2,16 @@ package mysql ...@@ -2,19 +2,16 @@ package mysql
import ( import (
"fmt" "fmt"
"github.com/go-xorm/xorm"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/go-xorm/xorm"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/e" "search_server/pkg/e"
) )
var DatabaseConMap map[string]*xorm.Engine var DatabaseConMap map[string]*xorm.Engine
func Setup() error {
DatabaseConMap = make(map[string]*xorm.Engine, 0)
func Setup() error{
DatabaseConMap = make(map[string]*xorm.Engine,0)
DatabaseList := config.BuildDatabaseList() DatabaseList := config.BuildDatabaseList()
var err error var err error
//循环生成数据库链接 //循环生成数据库链接
...@@ -24,10 +21,10 @@ func Setup() error{ ...@@ -24,10 +21,10 @@ func Setup() error{
host := db.Host host := db.Host
database := db.Database database := db.Database
dataSourceName := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8",userName,password,host,database) 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 {
return e.NewFatalError(err.Error()) //这里返回致命异常 return e.NewFatalError(err.Error()) //这里返回致命异常
} }
...@@ -44,7 +41,7 @@ func Setup() error{ ...@@ -44,7 +41,7 @@ func Setup() error{
return nil return nil
} }
func Conn(conName string) *xorm.Engine { func Conn(conName string) *xorm.Engine {
return DatabaseConMap[conName] return DatabaseConMap[conName]
} }
package vars
//数字转class字符串,按顺序0-9
var NumberToClass = [][]string{
{"sfgdqwer", "asfgdtyhg", "asfgdpolk", "asfgdpoqw"},
{"sfgdrfdf","asfgderfd","asfgdwdsa","asfgdpoer"},
{"asfgdasde","asfgdqwsz","asfgdrtgd","asfgdpovv"},
{"asfgdwsxc","asfgdwsxz","asfgdrfvb","asfgdpoee"},
{"asfgdqazs","asfgdqasd","asfgdqwag","asfgdpogh"},
{"asfgdrtyh","asfgdyutr","asfgdeews","asfgdpotg"},
{"asfgdpluj","asfgdikjf","asfgdesgj","asfgdpfff"},
{"asfgdtrdb","asfgdiksf","asfgdsgkp","asfgdprty"},
{"asfgdpehl","asfgdstgb","asfgderll","asfgdpokf"},
{"asfgdpehg","asfgdstgf","asfgderlf","asfgdpogk"},
}
...@@ -22,6 +22,8 @@ type QuoteIndexRequest struct { ...@@ -22,6 +22,8 @@ type QuoteIndexRequest struct {
FirstSearchPage int `form:"first_search_page"` FirstSearchPage int `form:"first_search_page"`
P int `form:"p"` P int `form:"p"`
Topic int `form:"topic"` Topic int `form:"topic"`
K1 int `form:"k1"`
K2 int `form:"k2"`
} }
func CheckQuoteRequest(r QuoteIndexRequest) (errCode int, errMsg string) { func CheckQuoteRequest(r QuoteIndexRequest) (errCode int, errMsg string) {
......
...@@ -8,14 +8,21 @@ import ( ...@@ -8,14 +8,21 @@ import (
//初始化路由 //初始化路由
func InitRouter() *gin.Engine { func InitRouter() *gin.Engine {
r := gin.New() r := gin.New()
<<<<<<< HEAD
//r.Use(gin.Logger()) //r.Use(gin.Logger())
//r.Use(gin.Recovery()) //r.Use(gin.Recovery())
//r.Use(middleware.Cors()) //r.Use(middleware.Cors())
=======
r.Use(gin.Logger())
r.Use(gin.Recovery())
r.Use(middleware.Cors())
r.Use(middleware.ContextVars())
>>>>>>> 326ae7ed67d5d2db331dddd1277d36b8b1992b08
//路由 //路由
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.POST("search/mouser/GetMouserData", controller.GetMouserData)
//快手平台相关 //快手平台相关
r.GET("/search/quote", controller.QuoteIndex) r.GET("/search/quote", controller.QuoteIndex)
......
package service package service
import ( import (
"fmt" "github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
_ "github.com/tidwall/gjson"
"search_server/model" "search_server/model"
"search_server/pkg/common"
"search_server/pkg/config" "search_server/pkg/config"
_ "search_server/pkg/gredis" "search_server/pkg/gredis"
"search_server/pkg/mysql"
"strconv"
"strings" "strings"
"fmt"
"encoding/json"
) )
//定义类名
type CommonLyService struct {
supplier_over_time map[string]int64
supplierId int64 //调用当前方法的供应商ID
supplierName string //调用当前方法的供应商名称
skuEsUpdataList []map[string]interface{} //组装批量更新es数据
SKU_UNIQUE_JUDGE string //
SPU_UNIQUE_JUDGE string //
BRAND_NAME_ALL string //
SUPPLIER_BRAND_ALL string //
BRAND string //
SKU string //
SPU string
SKU_RAW_MAP string
}
//关键词搜索过期时间 //初始化类
var supplier_over_time = map[string]int64{ func (t *CommonLyService) LyServerRun(){
"arrow": 3600, CommonLyService := new(CommonLyService)
"verical": 3600, CommonLyService.supplier_over_time = map[string]int64{
"mouser": 3600, "arrow":3600,
"master": 3600, "verical":3600,
"tme": 3600, "mouser":3600,
"buerklin": 3600, "master":3600,
"tme":3600,
"buerklin":3600,
}
//用到的redis键值
CommonLyService.SKU_UNIQUE_JUDGE = config.Get("redis_all.SKU_UNIQUE_JUDGE").String() //
CommonLyService.SPU_UNIQUE_JUDGE = config.Get("redis_all.SPU_UNIQUE_JUDGE").String() //
CommonLyService.BRAND_NAME_ALL = config.Get("redis_all.BRAND_NAME_ALL").String() //
CommonLyService.SUPPLIER_BRAND_ALL = config.Get("redis_all.SUPPLIER_BRAND_ALL").String() //
CommonLyService.BRAND = config.Get("redis_all.BRAND").String() //
CommonLyService.SKU = config.Get("redis_all.SKU").String() //
CommonLyService.SPU = config.Get("redis_all.SPU").String()
CommonLyService.SKU_RAW_MAP = config.Get("redis_all.SKU_RAW_MAP").String()
} }
/* /*
...@@ -26,66 +57,179 @@ var supplier_over_time = map[string]int64{ ...@@ -26,66 +57,179 @@ var supplier_over_time = map[string]int64{
@param goods_list 请求联营格式化后的数据 @param goods_list 请求联营格式化后的数据
@param supplier_info 供应商商品详情 @param supplier_info 供应商商品详情
*/ */
func getSkuByGoodsSn(goods_list map[string]*model.LyClearGoodsList, supplier_info *model.SUPPLIER_REDIS_INFO_) map[string]interface{} { func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoodsList,supplierInfo *model.SUPPLIER_REDIS_INFO_) map[string]interface{}{
t.LyServerRun(); //初始化变量
//originGoods := make(map[string]interface{},0)
// redisRead := gredis.Conn("search_r")
//for goods_sn, goods_list := range goods_list { defer redisRead.Close()
// gredis.HGet("")
// t.supplierId = supplierInfo.SupplierId
// ladderPrice := make([]*model.TierItem, 0) t.supplierName = supplierInfo.SupplierNickname
//
// productList[goodsSn] = &LyClearGoodsList originGoods := make(map[string]interface{},0)
//}
// for goods_sn, info := range goodsList {
//fmt.Println(productList)
//return productList snSku := php2go.Md5(strings.ToLower(goods_sn))
originGoods := make(map[string]interface{}, 0) skuId,_ := gredis.String(redisRead.Do("HGET",t.SKU_UNIQUE_JUDGE,snSku)) //查询唯一值,反查sku_id
sku_uique_judge := config.Get("redis_all.SKU_UNIQUE_JUDGE").String()
var sku_flag bool = false; //是否新增或者更新db+redis,为true则新增
for goods_sn, info := range goods_list { if skuId == "" { //为空,先创建sku
lock_key := "searchapi_"+snSku;
sn_sku := php2go.Md5(strings.ToLower(goods_sn)) flag,_ := redis.Bool(redisRead.Do("SETNX", lock_key,php2go.Time()+2))
fmt.Println(sku_uique_judge, sn_sku) if flag { //不存在锁,直接新增
//sku_id, _ := gredis.IchuntRedis.Hget(sku_uique_judge, sn_sku) //查询唯一值,反查sku_id sku_flag = true
sku_id := "" redisRead.Do("EXP",lock_key,2) //给锁有效时间2秒
if sku_id == "" { //为空,先创建sku //sku_id = t.writeSkuInfo(info)
//sku_id, _ := gredis.HGet(sku_uique_judge, sn_sku) //查询唯一值,反查sku_id }else{ //存在锁
fmt.Println(sku_uique_judge, sn_sku)
sku_id := "" }
if sku_id == "" { //为空,先创建sku
//lock_key := "searchapi_"+sn_sku;
//flag := gredis.Setnx(lock_key,php2go.Time()+2)
//if flag { //存在锁
//
//}
} }
print(info) print(info)
print(sku_flag)
//productList[goodsSn] = &LyClearGoodsList //productList[goodsSn] = &LyClearGoodsList
} }
fmt.Println(originGoods) fmt.Println(originGoods)
return originGoods return originGoods
}
/*
生成或者更新 sku信息
*/
func (t *CommonLyService) writeSkuInfo(skuInfo *model.LyClearGoodsList,skuId string,) {
redisWrite := gredis.Conn("search_w")
defer redisWrite.Close()
spuKey := common.GetKey(skuInfo.GoodsName+"_"+skuInfo.BrandName)
spuId,_ := gredis.String(redisWrite.Do("HGET",t.SKU_UNIQUE_JUDGE,spuKey))
if spuId == "" { //不存在spu,创建新的spu
spuId = t.writeSpuInfo(skuInfo)
}
if skuId == "" {
skuId = common.CreateId("sku");
}
inSkuInfo := model.LySkuInfo{
SpuId: spuId,
Encoded: "",
Moq: skuInfo.Moq,
Mpq: skuInfo.Increment,
OldGoodsId: 0,
GoodsType: 1,
GoodsStatus: 1,
BatchSn:"",
Stock:skuInfo.Stock,
HkDeliveryTime: "",
CnDeliveryTime: "",
LadderPrice: skuInfo.Tiered,
UpdateTime: php2go.Time(),
GoodsImages: "",
Canal: "",
SupplierId:t.supplierId,
}
jsonStr, _ := json.Marshal(inSkuInfo)
redisWrite.Do("HSET","sku",spuId,jsonStr)
skuKey := common.GetKey(skuInfo.GoodsSn+"_"+strconv.FormatInt(t.supplierId,10))
redisWrite.Do("HSET",t.SKU_UNIQUE_JUDGE,skuKey,skuId)
//todo 如果是digikey新增,需要插入原始映射表
if t.supplierId == 7 {
//redisWrite.Do("HSET",SKU_RAW_MAP,skuKey,skuId)
} }
return nil
} }
/* /*
新增或者更新redis 生成spu
*/ */
func toRedis() { func (t *CommonLyService) writeSpuInfo(skuInfo *model.LyClearGoodsList) string {
redisWrite := gredis.Conn("search_w")
defer redisWrite.Close()
brand_key := common.GetKey(strings.ToLower(skuInfo.BrandName))
brandId,_ := redis.Int64(redisWrite.Do("HGET", t.BRAND_NAME_ALL,brand_key))
if brandId == 0 {
brandId,_ = redis.Int64(redisWrite.Do("HGET",t.SUPPLIER_BRAND_ALL,brand_key))
if brandId == 0 {
brandId = t.writeBrandInfo(skuInfo)
}
}
spuId := common.CreateId("spu") //创建spu的id
Spuinfo := model.LySpuInfo{
ClassId1:0,
ClassId2:0,
ClassId3:0,
BrandId:brandId,
SpuName:skuInfo.GoodsName,
Status:1,
ImagesL:"",
Encap:"",
Pdf:"",
SpuBrief:"",
UpdateTime:php2go.Time(),
}
jsonStr, _ := json.Marshal(Spuinfo)
redisWrite.Do("HSET","spu",spuId,jsonStr)
spuKey := common.GetKey(skuInfo.GoodsName+"_"+skuInfo.BrandName)
redisWrite.Do("HSET",t.SPU_UNIQUE_JUDGE,spuKey,spuId)
return spuId
} }
/*
生成品牌
*/
func (t *CommonLyService) writeBrandInfo(skuInfo *model.LyClearGoodsList) int64 {
var (
dbSpu = mysql.Conn("spu") //spu实例化链接
brandId int64 //品牌id
brandkey = common.GetKey(skuInfo.BrandName) //品牌唯一值
redisWrite = gredis.Conn("search_w")
)
defer redisWrite.Close()
has, err := dbSpu.Table("brand").Where("brand_name = ?", skuInfo.BrandName).Cols("id").Get(&brandId)
if err != nil {
fmt.Println(err) //查询错误
return 0
}
if has {//不存在品牌,则创建品牌
sql :="insert into brand(brand_name,create_time,insert_type) values (?, ?, ?)"
results, err := dbSpu.Exec(sql,skuInfo.BrandName, php2go.Time(),1)
if err != nil {
fmt.Println(err) //查询错误
return 0
}
brandId,_ = results.LastInsertId()
}
//更新redis 品牌数据
redisWrite.Do("HSET",t.BRAND_NAME_ALL,brandkey,brandId)
redisWrite.Do("HSET",t.BRAND,brandkey,brandId)
return brandId;
}
/* /*
推入队列 组装推送到es数据
*/
func esSkuInfo(skuInfo *model.LyClearGoodsList) {
}
/*
推入队列
*/ */
func toGoRabmq() { func toGoRabmq() {
} }
/* /*
更新es 更新es
*/ */
func toEs() { func toEs() {
......
package service package service
import ( import (
"fmt"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/imroc/req" "github.com/imroc/req"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
...@@ -9,18 +8,30 @@ import ( ...@@ -9,18 +8,30 @@ import (
"github.com/uniplaces/carbon" "github.com/uniplaces/carbon"
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
"regexp" "regexp"
"search_server/middleware"
"search_server/model" "search_server/model"
"search_server/pkg/common"
"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/requests" "search_server/requests"
"search_server/service/transformer"
"strconv"
"strings" "strings"
) )
//获取商品信息,需要传入userId用于判断是否登陆 //获取商品信息,需要传入userId用于判断是否登陆
func GetGoodsInfo(goodsIdsStr string, userId int) (goodsListMap map[string]*model.ApiGoods, err error) { func GetGoodsInfo(goodsIds []string) (goodsListMap map[string]model.ApiGoods, err error) {
var userIdStr string
userIdStr, err = middleware.Context.Cookie("Yo4teW_uid")
if err != nil {
return
}
userId, err := strconv.Atoi(userIdStr)
if err != nil {
return
}
isNewCustomer, isMember := CheckIsNewCustomer(userId) isNewCustomer, isMember := CheckIsNewCustomer(userId)
goodsIdsStr := strings.Join(goodsIds, ",")
params := req.Param{ params := req.Param{
"goods_id": goodsIdsStr, "goods_id": goodsIdsStr,
"power[newCustomer]": isNewCustomer, "power[newCustomer]": isNewCustomer,
...@@ -31,67 +42,24 @@ func GetGoodsInfo(goodsIdsStr string, userId int) (goodsListMap map[string]*mode ...@@ -31,67 +42,24 @@ func GetGoodsInfo(goodsIdsStr string, userId int) (goodsListMap map[string]*mode
} }
//获取商品信息 //获取商品信息
func GetGoodsInfoByApi(goodsIdsStr string) (goodsList []*model.ApiGoods, err error) { func GetGoodsInfoByApi(goodsIdsStr string) (goodsList []model.ApiGoods, err error) {
params := req.Param{ params := req.Param{
"goods_id": goodsIdsStr, "goods_id": goodsIdsStr,
} }
goodsList, _, err = CurlGoodsInfo(goodsIdsStr, params) goodsList, _, err = CurlGoodsInfo(goodsIdsStr, params)
fmt.Println(goodsList[0].BrandId)
return return
} }
//处理商品信息数据
func DullGoodsInfo(keyword string, goodsListMap map[string]*model.ApiGoods) map[string]*model.ApiGoods {
//获取redis链接
redisCon := gredis.Conn("default_r")
defer redisCon.Close()
for key, goods := range goodsListMap {
fmt.Println(key)
fmt.Println(goods)
if goods.Mpq == 0 {
goods.Mpq = 1
}
if goods.GoodsName == "" {
goods.GoodsName = goods.SpuName
}
//goods_name_temp
if keyword != "" {
replaceString := "<b class='f-red'>" + strings.ToUpper(keyword) + "</b>"
goods.GoodsNameTemp = common.CaseInsensitiveReplace(goods.GoodsName, keyword, replaceString)
} else {
goods.GoodsNameTemp = goods.GoodsName
}
if goods.Mpq > goods.Moq {
goods.Multiple = goods.Moq
} else {
goods.Multiple = goods.Mpq
}
//te广告按钮
teSwitch, _ := redis.Int(redisCon.Do("GET", "TeSwitch"))
if goods.BrandId == 161 && goods.GoodsId != "1152755238555810539" && teSwitch == 2 {
goods.SearchSampleApplication = "https://www.te.com.cn/chn-zh/solutions/sg-sample-request-form.html?te_bu=Cor&te_type=other&te_campaign=ich_chn_cor-ich-chn-part-selectmktg-fy19-srp-sample_sma-431_10&elqCampaignId=32896"
goods.SearchContactExperts = "https://www.te.com.cn/chn-zh/solutions/connectivity.html?te_bu=Cor&te_type=other&te_campaign=ich_chn_cor-ich-chn-part-selectmktg-fy19-srp-contact_sma-431_11&elqCampaignId=32897"
}
//供应商信息,读取redis,来源于基石配置
}
return nil
}
//isMap:是否以字典形式返回值,默认是数组 //isMap:是否以字典形式返回值,默认是数组
func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []*model.ApiGoods, goodsListMap map[string]*model.ApiGoods, err error) { func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []model.ApiGoods, goodsListMap map[string]model.ApiGoods, err error) {
//req.Debug = true //req.Debug = true
goodsServerUrl := config.Get("goods.api_url").String() 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) goodsListMap = make(map[string]model.ApiGoods, 1000)
//先判断返回的data是不是字典,不是字典代表可能是返回字符串了 //先判断返回的data是不是字典,不是字典代表可能是返回字符串了
if gjson.Get(resp.String(), "data").IsObject() { if gjson.Get(resp.String(), "data").IsObject() {
//排序操作 //排序操作
...@@ -184,10 +152,10 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []*model.Api ...@@ -184,10 +152,10 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []*model.Api
goods.Attrs = attrMap goods.Attrs = attrMap
//coefficient //coefficient
goods.Coefficient.Cn = data.Get("coefficient.cn").String() goods.Coefficient.Cn = data.Get("coefficient.cn").Float()
goods.Coefficient.Hk = data.Get("coefficient.hk").String() goods.Coefficient.Hk = data.Get("coefficient.hk").Float()
goods.Coefficient.ExtraRatio = data.Get("coefficient.extra_ratio").String() goods.Coefficient.ExtraRatio = data.Get("coefficient.extra_ratio").Float()
goods.Coefficient.Ratio = data.Get("coefficient.ratio").String() goods.Coefficient.Ratio = data.Get("coefficient.ratio").Float()
goods.Coefficient.Tax = data.Get("coefficient.tax").Float() goods.Coefficient.Tax = data.Get("coefficient.tax").Float()
//original_price //original_price
...@@ -213,10 +181,10 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []*model.Api ...@@ -213,10 +181,10 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []*model.Api
goods.ScmBrand.ErpBrandId = data.Get("scm_brand.erp_brand_id").String() goods.ScmBrand.ErpBrandId = data.Get("scm_brand.erp_brand_id").String()
goods.ScmBrand.ScmBrandId = data.Get("scm_brand.scm_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 goodsListMap[goodsId] = goods
} else { } else {
goodsListMap[goodsId] = nil goodsListMap[goodsId] = model.ApiGoods{}
} }
} }
} }
...@@ -251,7 +219,7 @@ func CheckIsNewCustomer(userId int) (isNewCustomer, isMember bool) { ...@@ -251,7 +219,7 @@ func CheckIsNewCustomer(userId int) (isNewCustomer, isMember bool) {
} }
//根据供应商获取商品信息 //根据供应商获取商品信息
func GetGoodsBySupplier(r requests.QuoteIndexRequest) (err error) { func GetGoodsBySupplier(r requests.QuoteIndexRequest) (result map[string]interface{}, err error) {
//索引字典 //索引字典
supplierIndex := getSupplierIndex(r.SupplierId) supplierIndex := getSupplierIndex(r.SupplierId)
//获取查询条件 //获取查询条件
...@@ -259,13 +227,15 @@ func GetGoodsBySupplier(r requests.QuoteIndexRequest) (err error) { ...@@ -259,13 +227,15 @@ func GetGoodsBySupplier(r requests.QuoteIndexRequest) (err error) {
queryString = "" queryString = ""
res, err := es.CurlES(supplierIndex, queryString) res, err := es.CurlES(supplierIndex, queryString)
goodsIds := GetGoodsIdsByEs(res) goodsIds := GetGoodsIdsByEs(res)
//if err != nil { if err != nil {
// return err return
//} }
goodsIdsStr := strings.Join(goodsIds, ",") goodsList, err := GetGoodsInfo(goodsIds)
goodsList, err := GetGoodsInfo(goodsIdsStr, 0) dullData, err := transformer.DullDataInfo(r.Keyword, goodsList)
fmt.Println(goodsList) result = make(map[string]interface{})
return nil result["data"] = dullData
result["total"] = gjson.Get(res, "hits.total").Int()
return result, nil
} }
func getSupplierIndex(supplierId string) (supplierIndex string) { func getSupplierIndex(supplierId string) (supplierIndex string) {
...@@ -454,6 +424,11 @@ func getSupplierQuery(req requests.QuoteIndexRequest) (string, error) { ...@@ -454,6 +424,11 @@ func getSupplierQuery(req requests.QuoteIndexRequest) (string, error) {
return searchRequest.Body() return searchRequest.Body()
} }
//将供应商信息放到数据最外层,同时整合es相关数据
func getReturnSupplierData(dullData map[string]model.DullGoodsData) {
}
//根据es的结果获取goods_id列表 //根据es的结果获取goods_id列表
func GetGoodsIdsByEs(res string) (goodsIds []string) { func GetGoodsIdsByEs(res string) (goodsIds []string) {
//直接用gjson去获取goods_id列表 //直接用gjson去获取goods_id列表
......
package service
//推送搜索关键词
func ShowSku() {
}
\ No newline at end of file
package transformer
import (
"github.com/gomodule/redigo/redis"
"github.com/tidwall/gjson"
"search_server/dao"
"search_server/middleware"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/gredis"
"strings"
)
//处理商品信息数据
func DullDataInfo(keyword string, goodsListMap map[string]model.ApiGoods) (result []model.DullGoodsData, err error) {
//获取redis链接
redisCon := gredis.Conn("search_r")
defer redisCon.Close()
for _, item := range goodsListMap {
var goods model.DullGoodsData
goods.ApiGoods = item
if goods.GoodsName == "" {
goods.GoodsName = goods.SpuName
}
//获取goods_temp_name字段
goods = getGoodsTempName(keyword, goods)
//获取tes广告
goods = getTesAd(goods)
//供应商信息,读取redis,来源于基石配置
goods, err := getSupplierInfo(goods)
if err != nil {
return result, err
}
//在不同的环境组装不同的url
goods = spliceUrlByEnvironment(goods)
//获取汇率相关
goods = getRatio(goods)
//todo:提供给客服报价系统专用(因为只是给快手用的,所以抽离出这个方法)
//整理数据
goods = arrangeData(goods)
//优惠券信息
goods = getCouponInfo(goods)
//最后查询时间
goods.LastSearchTime = common.GetLastSearchTime(goods.GoodsId)
//关税信息
goods.CustomsTax = common.GetCustomsTax(goods.GoodsName, goods.BrandName)
//todo : showsku方法
//价格等信息混淆
if keyword != "---" {
goods, err = MetGoodsInfo(goods)
if err != nil {
return result, err
}
}
//增加类似物料字段
goods = getGoodsAlike(keyword, goods)
result = append(result, goods)
}
return
}
//在不同的环境组装不同的url
func spliceUrlByEnvironment(goods model.DullGoodsData) model.DullGoodsData {
referer := middleware.Context.Request.Header.Get("referer")
refererTemp := strings.Split(referer, ".com")
if len(refererTemp) > 0 {
goods.BrandUrl = refererTemp[0] + ".com/v3/brand/list/" + common.ToString(goods.BrandId) + ".html"
goods.GoodsUrl = refererTemp[0] + ".com/goods_" + common.ToString(goods.GoodsId) + ".html"
}
return goods
}
//goods_name_temp
func getGoodsTempName(keyword string, goods model.DullGoodsData) model.DullGoodsData {
if keyword != "" {
replaceString := "<b class='f-red'>" + strings.ToUpper(keyword) + "</b>"
goods.GoodsNameTemp = common.CaseInsensitiveReplace(goods.GoodsName, keyword, replaceString)
} else {
goods.GoodsNameTemp = goods.GoodsName
}
if goods.Mpq > goods.Moq {
goods.Multiple = goods.Moq
} else {
goods.Multiple = goods.Mpq
}
return goods
}
//te广告按钮
func getTesAd(goods model.DullGoodsData) model.DullGoodsData {
redisCon := gredis.Conn("search_r")
defer redisCon.Close()
teSwitch, _ := redis.Int(redisCon.Do("GET", "TeSwitch"))
if goods.BrandId == 161 && goods.GoodsId != "1152755238555810539" && teSwitch == 2 {
goods.SearchSampleApplication = "https://www.te.com.cn/chn-zh/solutions/sg-sample-request-form.html?te_bu=Cor&te_type=other&te_campaign=ich_chn_cor-ich-chn-part-selectmktg-fy19-srp-sample_sma-431_10&elqCampaignId=32896"
goods.SearchContactExperts = "https://www.te.com.cn/chn-zh/solutions/connectivity.html?te_bu=Cor&te_type=other&te_campaign=ich_chn_cor-ich-chn-part-selectmktg-fy19-srp-contact_sma-431_11&elqCampaignId=32897"
}
return goods
}
//获取供应商相关信息
func getSupplierInfo(goods model.DullGoodsData) (model.DullGoodsData, error) {
redisCon := gredis.Conn("search_r")
defer redisCon.Close()
supplier, err := dao.GetSupplierExtraBySupplierId(goods.SupplierId)
if err != nil {
return model.DullGoodsData{}, err
}
supplier.SupplierLogo = "https://" +
strings.TrimLeft(supplier.SupplierLogo, "http://")
goods.SupplierLogo = supplier.SupplierLogo
goods.SupplierSort = supplier.Sort
ad := make(map[string]string)
if supplier.AdText != "" {
ad["ad"] = supplier.AdText
ad["url"] = supplier.AdUrl
goods.SupplierAd = ad
} else {
goods.SupplierAd = ""
}
goods.PageFlag = 2
//获取官网信息
officialWebsites := config.Cfg.Section("official_website").KeysHash()
if website, exist := officialWebsites[common.ToString(goods.SupplierId)]; exist {
goods.SupplierWebsite = strings.Replace(website, "liexin", goods.SupplierName, -1)
} else {
goods.SupplierWebsite = ""
}
//猎芯联营采购员 ,添加供应商采购员渠道不得为空
if goods.Canal != "" {
purchaseName, _ := redis.String(redisCon.Do("HGET", "search_supplier_canaltopurchase", goods.Canal))
goods.PurchaseName = purchaseName
}
return goods, err
}
//获取相关汇率
func getRatio(goods model.DullGoodsData) model.DullGoodsData {
//是否为过期,把优惠信息屏蔽
if goods.Status != 1 {
goods.AcType = 0
goods.Ratio = 0
}
//人民币汇率ratio
if goods.Coefficient.Ratio > 0 {
goods.PriceXs = goods.Coefficient.Ratio
}
//人民币利润点 cn
if goods.Coefficient.Cn > 0 {
goods.PriceProfit = goods.Coefficient.Cn
}
//香港汇率extra_ratio
if goods.Coefficient.ExtraRatio > 0 {
goods.PriceHkxs = goods.Coefficient.ExtraRatio
}
return goods
}
//获取优惠券信息
func getCouponInfo(goods model.DullGoodsData) model.DullGoodsData {
redisCon := gredis.Conn("search_r")
defer redisCon.Close()
couponInfoStr, _ := redis.String(redisCon.Do("HGET", "search_supplier_coupon_list", goods.SupplierId))
if couponInfoStr != "" {
goods.CouponId = int(gjson.Get(couponInfoStr, "tem_id").Int())
goods.CouponTitle = gjson.Get(couponInfoStr, "title").String()
}
return goods
}
//获取类似物料
func getGoodsAlike(keyword string, goods model.DullGoodsData) model.DullGoodsData {
redisCon := gredis.Conn("search_r")
defer redisCon.Close()
key := config.Get("redis_all.POOL_ALIKE_GOODS").String()
alikeGoodsStr, _ := redis.String(redisCon.Do("HGET", key, goods.GoodsId))
alikeGoodsStr = strings.ToUpper(strings.Replace(alikeGoodsStr, "€", ",", -1))
var alikeStr, redStr, redFirstStr string
keyword = strings.ToUpper(keyword)
alikeGoods := strings.Split(alikeGoodsStr, ",")
for _, goodsName := range alikeGoods {
if strings.Contains(goodsName, keyword) {
//替换字符串
replace := "<b class='f-red'>" + keyword + "</b>"
tempStr := common.CaseInsensitiveReplace(goodsName, keyword, replace)
if goodsName == keyword {
redFirstStr = tempStr + ","
} else {
redStr = tempStr + "," + redStr
}
} else {
alikeStr = goodsName + "," + alikeStr
}
}
str := redFirstStr + redStr + alikeStr
goods.Alike = strings.TrimRight(str, ",")
return goods
}
//整理数据
func arrangeData(goods model.DullGoodsData) model.DullGoodsData {
//判断期货是否展现
if len(goods.LadderPrice) == 0 {
goods.CnDeliveryTime = ""
goods.HkDeliveryTime = ""
}
if (len(goods.LadderPrice) > 0) && (goods.LadderPrice[0].PriceCn <= 0) {
goods.CnDeliveryTime = ""
}
if (len(goods.LadderPrice) > 0) && (goods.LadderPrice[0].PriceUs <= 0) {
goods.HkDeliveryTime = ""
}
//起订量对比第一阶梯价
if len(goods.LadderPrice) > 0 {
if goods.LadderPrice[0].Purchases > goods.Moq {
goods.Moq = goods.LadderPrice[0].Purchases
}
}
//是否过期
if goods.Status != 1 && goods.Stock > 0 {
goods.IsBuy = 3
}
//处理不正确的数据
if len(goods.GoodsImages) < 5 || !strings.Contains(goods.GoodsImages, "//") {
goods.GoodsImages = ""
}
if len(goods.Pdf) < 5 {
goods.Pdf = ""
}
if goods.Ratio < 0 {
goods.Ratio = 0
}
if goods.Mpq == 0 {
goods.Mpq = 1
}
return goods
}
//价格等信息混淆
func MetGoodsInfo(data model.DullGoodsData) (result model.DullGoodsData, err error) {
type CheckParams struct {
CheckButton int `form:"check_button"`
K1 int `form:"k1"`
K2 int `form:"k2"`
}
var checkParams CheckParams
err = middleware.Context.Bind(&checkParams)
if checkParams.CheckButton == 2 || checkParams.K1 != 0 || checkParams.K2 != 0 {
data.StockStr = data.Stock
data.MoqStr = data.Moq
data.MpqStr = data.Mpq
data.MplStr = data.Mpl
data.MultipleStr = data.Multiple
if len(data.LadderPrice) > 0 {
for key, price := range data.LadderPrice {
data.LadderPrice[key].PurchasesStr = price.Purchases
}
}
return data, err
} else {
if len(data.LadderPrice) > 0 {
for key, price := range data.LadderPrice {
data.LadderPrice[key].PurchasesStr = common.NumberToHtml(price.Purchases)
}
}
data.StockStr = common.NumberToHtml(data.Stock)
data.MoqStr = common.NumberToHtml(data.Moq)
data.MpqStr = common.NumberToHtml(data.Mpq)
data.MplStr = common.NumberToHtml(data.Mpl)
data.MultipleStr = common.NumberToHtml(data.Multiple)
return data, err
}
}
...@@ -3,10 +3,25 @@ package main ...@@ -3,10 +3,25 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"github.com/syyongx/php2go"
"search_server/boot" "search_server/boot"
"search_server/service" "search_server/service"
) )
func StrRandom(lenNum int) string {
randStr := "sdwpkxmiqplmzacbmeruwulurjlauejrifkfghjklzxcvbnmqwwertyuiopkdsieurnvewjeilweiskvnx"
strLen := len(randStr) - 9
var result string
for i := 0; i < lenNum; i++ {
//start := common.Rand(0, strLen)
start := php2go.Rand(0, strLen)
fmt.Println(start)
str := php2go.Substr(randStr, uint(start), 9)
result = result + " " + str
}
return result
}
func main() { func main() {
var path string var path string
flag.StringVar(&path, "configPath", "conf", "配置文件") flag.StringVar(&path, "configPath", "conf", "配置文件")
...@@ -14,6 +29,5 @@ func main() { ...@@ -14,6 +29,5 @@ func main() {
if err := boot.Boot(path); err != nil { if err := boot.Boot(path); err != nil {
fmt.Println(err) fmt.Println(err)
} }
service1:= service.GoodsService{}
fmt.Println(service1.GetGoodsInfoByApi("1151005920927710088,1150961641855982990,1150961724815213435"))
} }
package main package main
import ( import (
<<<<<<< HEAD
"bytes" "bytes"
"fmt" "fmt"
) )
...@@ -20,4 +21,28 @@ func intsToString(values []int) string { ...@@ -20,4 +21,28 @@ func intsToString(values []int) string {
func main() { func main() {
fmt.Println(intsToString([]int{1, 2, 3})) // "[1, 2, 3]" fmt.Println(intsToString([]int{1, 2, 3})) // "[1, 2, 3]"
=======
"fmt"
"strconv"
)
func main() {
var a,b,c float64
a=1.69*100
b=1.7*10
c=a*b/(100*10)
//ȷ2.873
fmt.Println(c)
//fmt.Println(fmt.Sprintf("%.2f",c))
//fmt.Println(FloatRound(c,2))
}
// ȡСλ
func FloatRound(f float64, n int) float64 {
format := "%." + strconv.Itoa(n) + "f"
//fmt.Println(format)
res, _ := strconv.ParseFloat(fmt.Sprintf(format, f), 64)
return res
>>>>>>> 326ae7ed67d5d2db331dddd1277d36b8b1992b08
} }
\ 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