Commit 85ded841 by mushishixian

通用方法初步完成

parent 3eb86e03
......@@ -16,3 +16,12 @@ host = 192.168.2.250
database = test
table_prefix =
type = mysql
#'MYSQL_POWER'=>'mysql://spu:spu@192.168.1.234:3306',
[spu]
user_name = spu
password = spu
host = 192.168.1.234
database = liexin_spu
table_prefix =
type = mysql
\ No newline at end of file
......@@ -20,3 +20,4 @@ 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
POOL_ALIKE_GOODS=pool_alike_goods
\ No newline at end of file
[supplier_all]
1 ="rochester"
2 ="verical"
3 ="tme"
1 = "rochester"
2 = "verical"
3 = "tme"
#相似物料供应商
[alike_supplier]
1 = "ti"
[common]
'MOUSER_API'='http://footstone.liexin.net/webapi/handle_mouser'
'MOUSER_API' = 'http://footstone.liexin.net/webapi/handle_mouser'
[brand]
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_ZY_BRAND_IDS=23
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
[supplier]
# 供应商redis的首key
SUPPLIER_REDIS_PRE = SUPPLIER_REDIS_INFO_
[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
......@@ -30,9 +30,11 @@ func QuoteIndex(c *gin.Context) {
return
}
var res interface{}
if request.FollowHit != 0 && request.FollowHit != 1 {
service.GetGoodsBySupplier(request)
res,_ = service.GetGoodsBySupplier(request)
} else {
res,_ = service.GetGoodsBySupplier(request)
}
flag := 1
......@@ -43,7 +45,7 @@ func QuoteIndex(c *gin.Context) {
c.JSON(200, common.Response{
ErrCode: flag,
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
}
......@@ -8,9 +8,14 @@ type ApiGoods struct {
GoodsSn string `json:"goods_sn"`
GoodsType int `json:"goods_type"`
SupplierId int `json:"supplier_id"`
Moq int `json:"moq"`
Mpq int `json:"mpq"`
Stock int `json:"stock"`
Moq int `json:"-"`
MoqStr interface{} `json:"moq"`
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"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []LadderPrice `json:"ladder_price"`
......@@ -25,7 +30,6 @@ type ApiGoods struct {
GoodsImages string `json:"goods_images"`
GoodsBrief string `json:"goods_brief,omitempty"`
IsBuy int `json:"is_buy"`
Mpl int `json:"mpl"`
Status int `json:"status"`
Pdf string `json:"pdf"`
Encap string `json:"encap"`
......@@ -60,11 +64,32 @@ type ApiGoods struct {
ClassName3 string `json:"class_name3,omitempty"`
ErpTax bool `json:"erp_tax"`
ScmBrand ScmBrand `json:"scm_brand,omitempty"`
}
//经过处理后的商品数据
type DullGoodsData struct {
ApiGoods
//额外增加的字段
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"`
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"`
}
type Attr struct {
......@@ -79,17 +104,18 @@ type OtherAttrs struct {
}
type LadderPrice struct {
Purchases int `json:"purchases"`
Purchases int `json:"-"`
PurchasesStr interface{} `json:"purchases"`
PriceUs float64 `json:"price_us"`
PriceCn float64 `json:"price_cn"`
PriceAc float64 `json:"price_ac"`
PriceAc float64 `json:"price_ac,omitempty"`
}
type Coefficient struct {
Cn string `json:"cn"`
Hk string `json:"hk"`
ExtraRatio string `json:"extra_ratio"`
Ratio string `json:"ratio"`
Cn float64 `json:"cn"`
Hk float64 `json:"hk"`
ExtraRatio float64 `json:"extra_ratio"`
Ratio float64 `json:"ratio"`
Tax float64 `json:"tax"`
}
......
......@@ -6,18 +6,25 @@ import (
"search_server/pkg/gredis"
)
type QuoteSupplier struct {
type SupplierExtra struct {
HkDelivery string `json:"hk_delivery"`
CnDelivery string `json:"cn_delivery"`
PriceJson string `json:"price_json"`
PriceJson []PriceJson `json:"price_json"`
PriceJsonStr string `json:"-"`
AdText string `json:"ad_text"`
SupplierLogo string `json:"supplier_logo"`
AdUrl string `json:"ad_url"`
Sort int `json:"sort"`
}
type PriceJson struct {
Hk float64 `json:"hk"`
Cn float64 `json:"cn"`
Rate float64 `json:"rate"`
}
func getSupplier(supplierId string) {
redisCon := gredis.Conn("default_r")
redisCon := gredis.Conn("search_r")
defer redisCon.Close()
supplierInfoStr, _ := redis.String(redisCon.Do("HGET", config.Get("supplier.SUPPLIER_REDIS_PRE")))
if supplierInfoStr != "" {
......
......@@ -2,9 +2,12 @@ package common
import (
"crypto/md5"
"crypto/rand"
"encoding/hex"
"github.com/syyongx/php2go"
"math/big"
"regexp"
"search_server/pkg/vars"
"strconv"
)
......@@ -71,3 +74,51 @@ func CaseInsensitiveReplace(subject string, search string, replace string) strin
func lyActivityPrice() {
}
/*
* 反爬虫用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, _ := rand.Int(rand.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) {
Database: Get("bom.database").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.prefix").String(),
},
}
}
......@@ -2,19 +2,16 @@ package mysql
import (
"fmt"
"github.com/go-xorm/xorm"
_ "github.com/go-sql-driver/mysql"
"github.com/go-xorm/xorm"
"search_server/pkg/config"
"search_server/pkg/e"
)
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()
var err error
//循环生成数据库链接
......@@ -24,10 +21,10 @@ func Setup() error{
host := db.Host
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)
if err!=nil{
if err != nil {
return e.NewFatalError(err.Error()) //这里返回致命异常
}
......@@ -44,7 +41,6 @@ func Setup() error{
return nil
}
func Conn(conName string) *xorm.Engine {
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 {
FirstSearchPage int `form:"first_search_page"`
P int `form:"p"`
Topic int `form:"topic"`
K1 int `form:"k1"`
K2 int `form:"k2"`
}
func CheckQuoteRequest(r QuoteIndexRequest) (errCode int, errMsg string) {
......
package service
import (
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/imroc/req"
"github.com/syyongx/php2go"
......@@ -10,17 +9,18 @@ import (
"gopkg.in/olivere/elastic.v5"
"regexp"
"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/transformer"
"strings"
)
//获取商品信息,需要传入userId用于判断是否登陆
func GetGoodsInfo(goodsIdsStr string, userId int) (goodsListMap map[string]*model.ApiGoods, err error) {
func GetGoodsInfo(goodsIds []string, userId int) (goodsListMap map[string]model.ApiGoods, err error) {
isNewCustomer, isMember := CheckIsNewCustomer(userId)
goodsIdsStr := strings.Join(goodsIds, ",")
params := req.Param{
"goods_id": goodsIdsStr,
"power[newCustomer]": isNewCustomer,
......@@ -31,67 +31,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{
"goods_id": goodsIdsStr,
}
goodsList, _, err = CurlGoodsInfo(goodsIdsStr, params)
fmt.Println(goodsList[0].BrandId)
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:是否以字典形式返回值,默认是数组
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
goodsServerUrl := config.Get("goods.api_url").String()
resp, err := req.Post(goodsServerUrl+"/synchronization", params)
if err != nil {
return
}
goodsListMap = make(map[string]*model.ApiGoods, 1000)
goodsListMap = make(map[string]model.ApiGoods, 1000)
//先判断返回的data是不是字典,不是字典代表可能是返回字符串了
if gjson.Get(resp.String(), "data").IsObject() {
//排序操作
......@@ -184,10 +141,10 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []*model.Api
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.Cn = data.Get("coefficient.cn").Float()
goods.Coefficient.Hk = data.Get("coefficient.hk").Float()
goods.Coefficient.ExtraRatio = data.Get("coefficient.extra_ratio").Float()
goods.Coefficient.Ratio = data.Get("coefficient.ratio").Float()
goods.Coefficient.Tax = data.Get("coefficient.tax").Float()
//original_price
......@@ -213,10 +170,10 @@ func CurlGoodsInfo(goodsIdsStr string, params req.Param) (goodsList []*model.Api
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)
goodsListMap[goodsId] = &goods
goodsList = append(goodsList, goods)
goodsListMap[goodsId] = goods
} else {
goodsListMap[goodsId] = nil
goodsListMap[goodsId] = model.ApiGoods{}
}
}
}
......@@ -251,7 +208,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)
//获取查询条件
......@@ -259,13 +216,15 @@ func GetGoodsBySupplier(r requests.QuoteIndexRequest) (err error) {
queryString = ""
res, err := es.CurlES(supplierIndex, queryString)
goodsIds := GetGoodsIdsByEs(res)
//if err != nil {
// return err
//}
goodsIdsStr := strings.Join(goodsIds, ",")
goodsList, err := GetGoodsInfo(goodsIdsStr, 0)
fmt.Println(goodsList)
return nil
if err != nil {
return
}
goodsList, err := GetGoodsInfo(goodsIds, 0)
dullData, err := transformer.DullDataInfo(r, goodsList)
result = make(map[string]interface{})
result["data"] = dullData
result["total"] = gjson.Get(res, "hits.total").Int()
return result, nil
}
func getSupplierIndex(supplierId string) (supplierIndex string) {
......@@ -454,6 +413,11 @@ func getSupplierQuery(req requests.QuoteIndexRequest) (string, error) {
return searchRequest.Body()
}
//将供应商信息放到数据最外层,同时整合es相关数据
func getReturnSupplierData(dullData map[string]model.DullGoodsData) {
}
//根据es的结果获取goods_id列表
func GetGoodsIdsByEs(res string) (goodsIds []string) {
//直接用gjson去获取goods_id列表
......
package transformer
import (
"github.com/gomodule/redigo/redis"
"github.com/tidwall/gjson"
"search_server/dao"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/gredis"
"search_server/requests"
"strings"
)
//处理商品信息数据
func DullDataInfo(r requests.QuoteIndexRequest, 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(r.Keyword, goods)
//获取tes广告
goods = getTesAd(goods)
//供应商信息,读取redis,来源于基石配置
goods, err := getSupplierInfo(goods)
if err != nil {
return result, err
}
//todo:在不同的环境组装不同的url
//获取汇率相关
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 r.Keyword != "---" {
goods = MetGoodsInfo(goods, r.CheckButton, r.K1, r.K2)
}
//增加类似物料字段
goods = getGoodsAlike(r.Keyword, goods)
result = append(result,goods)
}
return
}
//在不同的环境组装不同的url
func spliceUrlByEnvironment(goods model.DullGoodsData) model.DullGoodsData {
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, checkButton, k1, k2 int) (result model.DullGoodsData) {
if checkButton == 2 || k1 != 0 || 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
} 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
}
}
......@@ -3,10 +3,25 @@ package main
import (
"flag"
"fmt"
"github.com/syyongx/php2go"
"search_server/boot"
"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() {
var path string
flag.StringVar(&path, "configPath", "conf", "配置文件")
......@@ -14,6 +29,5 @@ func main() {
if err := boot.Boot(path); err != nil {
fmt.Println(err)
}
service1:= service.GoodsService{}
fmt.Println(service1.GetGoodsInfoByApi("1151005920927710088,1150961641855982990,1150961724815213435"))
}
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