Commit 6cb45872 by mushishixian

完善

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