Commit 0f0554dd by huangchengyi

1.1

parent 260a37e3
......@@ -8,11 +8,20 @@ import (
func main() {
//MouserService := service.NewMouserServiceImpl()
//MouserGetData(MouserService)
dd := service.OutLink("LM358","-1")
print("niin")
print(dd)
os.Exit(1)
}
//xml := strings.NewReader(resp)
//json, err := xj.Convert(xml)
//if err != nil {
// panic("That's embarrassing...")
//}
//
//json_str := json.String();
////ss := gjson.Get(json_str,"hello").String()
//
//fmt.Println(json_str)
\ No newline at end of file
......@@ -27,6 +27,7 @@ require (
github.com/prometheus/client_golang v1.5.1 // indirect
github.com/prometheus/common v0.10.0
github.com/prometheus/procfs v0.0.11 // indirect
github.com/silenceper/gowatch v0.0.0-20200624073703-8e473a9db258 // indirect
github.com/sirupsen/logrus v1.5.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/testify v1.5.1 // indirect
......@@ -35,6 +36,7 @@ require (
go.uber.org/zap v1.14.1 // indirect
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 // indirect
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361
google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece // indirect
google.golang.org/grpc v1.29.1 // indirect
google.golang.org/protobuf v1.24.0
......
......@@ -2,22 +2,157 @@ package model
//联营请求外链后格式化数据
type LyClearGoodsList struct {
GoodsName string `json:"goods_name"` //型号名称
BrandName string `json:"brand_name"` //品牌名称
Desc string `json:"desc"` //描述
GoodsSn string `json:"goods_sn"` //api唯一编码
Docurl string `json:"docurl"` //sku对应供应商的文档路径
Url string `json:"url"` //sku对应供应商的商品详情
GoodsImg string `json:"goods_img"` //sku图片
Cat string `json:"cat"` //分类
RestrictionMessage string `json:"RestrictionMessage"` //额外购买限制内容,如 ‘当前商品不在本地区销售’
increment int `json:"increment"` //最小包装量、倍数
SinglePrice float64 `json:"single_price"` //最小单价
Tiered []*TierItem //价格梯度数量
GoodsName string `json:"goods_name"` //型号名称
BrandName string `json:"brand_name"` //品牌名称
Desc string `json:"desc"` //描述
GoodsSn string `json:"goods_sn"` //api唯一编码
Docurl string `json:"docurl"` //sku对应供应商的文档路径
Url string `json:"url"` //sku对应供应商的商品详情
GoodsImg string `json:"goods_img"` //sku图片
Cat string `json:"cat"` //分类
RestrictionMessage string `json:"RestrictionMessage"` //额外购买限制内容,如 ‘当前商品不在本地区销售’
Increment uint64 `json:"increment"` //最小包装量、倍数
SinglePrice float64 `json:"single_price"` //最小单价
Tiered []*TierItem //价格梯度数量
}
type TierItem struct {
Purchases int //购买数量
Purchases uint64 //购买数量
PriceUs float64 //数量对应的英文价格
PriceCn float64 //数量对应的中文价格
PriceCn float64 //数量对应的中文价格
}
/*
供应商详情
Array
(
[supplier_id] => 4
[supplier_nickname] => tme
[ad_text] => 电子元器件、电工产品和工业自动化元件的全球分销商
[cn_delivery] => 5-9工作日
[hk_delivery] => 4-7工作日
[ad_url] => https://www.ichunt.com/
[sort] => 0
[supplier_logo] => http://img.ichunt.com/images/cms/201912/11/b2c4e3aae9a2312dfe6b9c318b430354.jpg
[status] => 1
[describe] => 电子元器件、电工产品和工业自动化元件的全球分销商
[price_json] => Array
(
[0] => Array
(
[hk] => 1.197
[cn] => 9.2534796
[rate] => 6.9
)
)
)
*/
type SUPPLIER_REDIS_INFO_ struct {
SupplierId string `json:"supplier_id"` //供应商id
SupplierNickname string `json:"supplier_nickname"` //供应商名称
AdText string `json:"ad_text"` //供应商描述
CnDelivery string `json:"cn_delivery"` //国内交货时间
HkDelivery string `json:"hk_delivery"` //香港交货时间
AdUrl string `json:"ad_url"` //供应商官网
Sort string `json:"sort"` //排序
SupplierLogo string `json:"supplier_logo"` //供应商logo
Status string `json:"status"` //状态,1开启
Describe string `json:"describe"` //描述
PriceJson []*PriceJsonItem //价格
}
type PriceJsonItem struct {
hk float64 //购买数量
cn float64 //数量对应的英文价格
rate float64 //数量对应的中文价格
}
/*
联营sku详情
Array
(
[spu_id] => 2.1540893752409E+18
[encoded] =>
[moq] => 624
[mpq] => 1
[old_goods_id] => 0
[goods_type] => 1
[goods_status] => 1
[batch_sn] =>
[stock] => 0
[hk_delivery_time] =>
[cn_delivery_time] =>
[update_time] => 1540967156
[goods_images] =>
[canal] =>
[supplier_id] => 10
[is_expire] => 1
[ladder_price] => Array
(
[0] => Array
(
[purchases] => 624
[price_cn] => 0
[price_us] => 13.42
)
[1] => Array
(
[purchases] => 6240
[price_cn] => 0
[price_us] => 12.12
)
[2] => Array
(
[purchases] => 624000
[price_cn] => 0
[price_us] => 2.383
)
)
)
*/
type LySkuInfo struct {
SpuId string `json:"spu_id"` //spu_id
Encoded string `json:"encoded"`
Moq int `json:"moq"`
Mpq int `json:"mpq"`
OldGoodsId int `json:"old_goods_id"`
GoodsType int `json:"goods_type"`
GoodsStatus int `json:"goods_status"`
BatchSn string `json:"batch_sn"`
Stock string `json:"stock"`
UpdateTime string `json:"update_time"`
GoodsImages string `json:"goods_images"`
Canal string `json:"canal"`
SupplierId string `json:"supplier_id"`
IsExpire string `json:"is_expire"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []*LadderPrice2 `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详情
Array
(
[class_id1] => 0
[class_id2] => 0
[class_id3] => 0
[brand_id] => 7087
[spu_name] => SI4704-D50-GM
[status] => 1
[images_l] =>
[encap] =>
[pdf] =>
[spu_brief] =>
[update_time] => 1540893752
)
*/
\ No newline at end of file
......@@ -56,4 +56,11 @@ func ToString(a interface{}) string {
return strconv.FormatFloat(v, 'f', -1, 32)
}
return "change to String error"
}
/**
* 获取联营活动价
*/
func lyActivityPrice() {
}
\ No newline at end of file
package service
import (
"github.com/imroc/req"
"os"
"fmt"
"search_server/model"
"github.com/imroc/req"
"github.com/tidwall/gjson"
"search_server/model"
"time"
)
//mouser外链网址
......@@ -17,7 +16,6 @@ func NewMouserServiceImpl() *MouserServiceImpl {
return &MouserServiceImpl{}
}
//mouser请求外链
func OutLink(goodsName string,flag string) map[string]*model.LyClearGoodsList {
var result string;
......@@ -39,49 +37,49 @@ func OutLink(goodsName string,flag string) map[string]*model.LyClearGoodsList {
apiGoodsList := gjson.Get(result, "SearchResults.Parts").Array()
for _, goods := range apiGoodsList {
fmt.Println(goods)
os.Exit(1)
//拼接价格梯度
//PriceBreaks := goods["PriceBreaks"]
goodsStr := goods.String()
goodsSn := gjson.Get(goodsStr, "MouserPartNumber").String() //供应商唯一编码
ladderPrice := make([]*model.TierItem, 0)
ladder := model.TierItem{
Purchases: 1,
PriceUs: 0.44,
PriceCn: 1.55,
//拼接价格梯度
apiPriceTi := gjson.Get(goodsStr, "PriceBreaks").Array()
var apiLowerPrice float64 = 0; //计算最低价格
for _,priceItem := range apiPriceTi{
priceItemStr := priceItem.String();
onePrice := gjson.Get(priceItemStr, "Price").Float()
if apiLowerPrice == 0 {
apiLowerPrice = onePrice
}else if apiLowerPrice > onePrice {
apiLowerPrice = onePrice
}
ladder := model.TierItem{
Purchases: gjson.Get(priceItemStr, "Quantity").Uint(),
PriceUs: onePrice,
PriceCn: 0,
}
ladderPrice = append(ladderPrice, &ladder)
}
ladderPrice = append(ladderPrice, &ladder)
goodsStr := goods.String()
//拼接联营数据
LyClearGoodsList := model.LyClearGoodsList{
GoodsName: gjson.Get(goodsStr, "ManufacturerPartNumber").String(),
BrandName: gjson.Get(goodsStr, "Manufacturer").String(),
Desc: gjson.Get(goodsStr, "Description").String(),
GoodsSn: gjson.Get(goodsStr, "MouserPartNumber").String(),
GoodsSn: goodsSn,
Docurl: gjson.Get(goodsStr, "DataSheetUrl").String(),
Url: gjson.Get(goodsStr, "ProductDetailUrl").String(),
GoodsImg: gjson.Get(goodsStr, "ImagePath").String(),
Cat: gjson.Get(goodsStr, "Category").String(),
Increment: gjson.Get(goodsStr, "Mult").Uint(),
RestrictionMessage: gjson.Get(goodsStr, "RestrictionMessage").String(),
SinglePrice: apiLowerPrice,
Tiered:ladderPrice,
}
productList["595-LM358BIDR"] = &LyClearGoodsList
productList[goodsSn] = &LyClearGoodsList
}
fmt.Println(productList)
return productList
os.Exit(1)
//xml := strings.NewReader(resp)
//json, err := xj.Convert(xml)
//if err != nil {
// panic("That's embarrassing...")
//}
//
//json_str := json.String();
////ss := gjson.Get(json_str,"hello").String()
//
//fmt.Println(json_str)
}
\ 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