Commit 6cb45872 by mushishixian

完善

parent 19b5ff3b
The file could not be displayed because it is too large.
......@@ -14,6 +14,6 @@ func main() {
flag.Parse()
configs.Setup(path)
model.Setup()
logic.MatchGoods(11)
logic.MatchGoods(46)
queue.Sync()
}
......@@ -25,7 +25,6 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
return
}
}
}
return nil
}
......@@ -4,8 +4,9 @@ import (
"bom_server/configs"
"bom_server/internal/model"
"encoding/json"
"fmt"
"github.com/imroc/req"
"reflect"
"strconv"
"strings"
"time"
)
......@@ -18,7 +19,7 @@ type GoodsMap struct {
Number int
}
func UpdateGoodsData(goodsMapList []GoodsMap) () {
func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
//根据goodsIds去商品服务获取对应的商品信息
var (
goodsIds []string
......@@ -35,11 +36,11 @@ func UpdateGoodsData(goodsMapList []GoodsMap) () {
//req.Debug = true
resp, err := req.Post(goodsServerUrl+"/synchronization", params)
if err != nil {
fmt.Println(err)
return
}
var responseData model.ApiGoodsResponse
if err := resp.ToJSON(&responseData); err != nil {
fmt.Println(err)
if err = resp.ToJSON(&responseData); err != nil {
return
}
var bomMatchingList []model.BomItemMatching
for _, goodsMap := range goodsMapList {
......@@ -63,20 +64,33 @@ func UpdateGoodsData(goodsMapList []GoodsMap) () {
Encap: goods.Encap,
Status: goods.Status,
AddTime: int(time.Now().Unix()),
UpdateTime: 0,
}
//阶梯价处理
if len(goods.LadderPrice) > 0 {
ladderPriceStr, err := json.Marshal(goods.LadderPrice)
if err != nil {
fmt.Println(err)
return err
}
bomMatching.LadderPrice = string(ladderPriceStr)
//获取美元和人民币的价格(需要去判断数量)
if len(goods.LadderPrice) > 0 {
for _, price := range goods.LadderPrice {
if goodsMap.Number <= price.Purchases {
//要先去断言,因为商品服务返回的json的值类型不确定...
value := reflect.ValueOf(price.Purchases).Type().String()
var purchases int
if value == "string" {
tempNumber, _ := strconv.ParseInt(price.Purchases.(string), 10, 10)
purchases = int(tempNumber)
} else {
purchases = price.Purchases.(int)
}
if goodsMap.Number <= purchases {
//判断是否有优惠价,有的话取优惠价
if price.PriceAc != 0 {
bomMatching.CnPrice = price.PriceAc
} else {
bomMatching.CnPrice = price.PriceCn
}
bomMatching.HkPrice = price.PriceUs
break
}
......@@ -89,6 +103,7 @@ func UpdateGoodsData(goodsMapList []GoodsMap) () {
}
err = BatchSaveMatchings(bomId, bomMatchingList)
if err != nil {
fmt.Println(err)
return
}
return
}
......@@ -23,44 +23,46 @@ import (
func MatchGoods(bomId int) {
//获取bom
//bom := GetBomInfoWithItems(11)
//bomItems := bom.BomItems
bomItems := []model.BomItem{
{
BomID: 7,
BomItemID: 1,
BrandName: "ADVID",
GoodsName: "ECC15DCKNS1562",
Number: 1,
},
{
BomID: 7,
BomItemID: 2,
BrandName: "ADVID",
GoodsName: "ECC15DCKNS1562",
Number: 1,
},
{
BomID: 7,
BomItemID: 3,
BrandName: "ADVID",
GoodsName: "ECC15DCKNS15621",
Number: 1,
},
{
BomID: 7,
BomItemID: 4,
BrandName: "ADVID",
GoodsName: "ECC15DCKNS1562",
Number: 1,
},
}
bomId = 11
bom := GetBomInfoWithItems(bomId)
bomItems := bom.BomItems
//bomItems := []model.BomItem{
// {
// BomID: 7,
// BomItemID: 1,
// BrandName: "ADVID",
// GoodsName: "ECC15DCKNS1562",
// Number: 1,
// },
// {
// BomID: 7,
// BomItemID: 2,
// BrandName: "ADVID",
// GoodsName: "ECC15DCKNS1562",
// Number: 1,
// },
// {
// BomID: 7,
// BomItemID: 3,
// BrandName: "ADVID",
// GoodsName: "ECC15DCKNS15621",
// Number: 1,
// },
// {
// BomID: 7,
// BomItemID: 4,
// BrandName: "ADVID",
// GoodsName: "ECC15DCKNS1562",
// Number: 1,
// },
//}
SearchGoods(bomId, bomItems)
}
//去es搜索商品,得到对应的商品对应关系
func SearchGoods(bomId int, bomItems []model.BomItem) {
func SearchGoods(bomId int, bomItems []model.BomItem) (err error) {
if len(bomItems) == 0 {
return
}
client, err := es.NewClient(es.SetURL(configs.ESSetting.Url))
if err != nil {
panic(err)
......@@ -82,7 +84,8 @@ func SearchGoods(bomId int, bomItems []model.BomItem) {
if err != nil {
fmt.Println(err)
}
UpdateGoodsData(goodsMapList)
err = UpdateGoodsData(goodsMapList)
return
}
func getUpdateGoodsData(bomId int, bomItems []model.BomItem, client *es.Client, rawSearch bool) (goodsMapList []GoodsMap, err error) {
......
......@@ -11,7 +11,7 @@ type Goods struct {
ClassID1 int `json:"class_id1"`
ClassID2 int `json:"class_id2"`
ClassID3 int `json:"class_id3"`
SpuID int `json:"spu_id"`
SpuID string `json:"spu_id"`
SaleTime int `json:"sale_time"`
GoodsDetails string `json:"goods_details"`
CreateTime int `json:"create_time"`
......@@ -54,9 +54,10 @@ type ApiGoods struct {
CnDeliveryTime string `json:"cn_delivery_time"`
GoodsDetails string `json:"goods_details"`
LadderPrice []struct {
Purchases int `json:"purchases"`
Purchases interface{} `json:"purchases"`
PriceUs float64 `json:"price_us"`
PriceCn float64 `json:"price_cn"`
PriceAc float64 `json:"price_ac"`
} `json:"ladder_price"`
GoodsImages string `json:"goods_images"`
Canal string `json:"canal"`
......@@ -74,21 +75,21 @@ type ApiGoods struct {
Ratio string `json:"ratio"`
Tax float64 `json:"tax"`
} `json:"coefficient"`
OriginalPrice []struct {
Purchases int `json:"purchases"`
PriceCn int `json:"price_cn"`
PriceUs float64 `json:"price_us"`
} `json:"original_price"`
SuppExtendFee struct {
Cn struct {
Max string `json:"max"`
Price string `json:"price"`
} `json:"cn"`
Hk struct {
Max int `json:"max"`
Price int `json:"price"`
} `json:"hk"`
} `json:"supp_extend_fee"`
//OriginalPrice []struct {
// Purchases int `json:"purchases"`
// PriceCn int `json:"price_cn"`
// PriceUs float64 `json:"price_us"`
//} `json:"original_price"`
//SuppExtendFee struct {
// Cn struct {
// Max string `json:"max"`
// Price string `json:"price"`
// } `json:"cn"`
// Hk struct {
// Max int `json:"max"`
// Price int `json:"price"`
// } `json:"hk"`
//} `json:"supp_extend_fee"`
IsBuy int `json:"is_buy"`
ClassID1 int `json:"class_id1"`
ClassID2 int `json:"class_id2"`
......
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