Browse Source

update 供应链加入商品库

three
DengBiao 10 months ago
parent
commit
2fb78736c9
2 changed files with 55 additions and 33 deletions
  1. +53
    -31
      consume/supply_cloud_chain_fenxiao_new_change.go
  2. +2
    -2
      supply/1688/utils/aliApi.go

+ 53
- 31
consume/supply_cloud_chain_fenxiao_new_change.go View File

@@ -18,6 +18,7 @@ import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/streadway/amqp" "github.com/streadway/amqp"
"strings"
"time" "time"
) )


@@ -87,7 +88,57 @@ func SupplyCloudChainFenxiaoNewChangeConsume(queue md.MqQueue) {
return return
} }
ids := RemoveRepeatedElement(t.Ids) ids := RemoveRepeatedElement(t.Ids)

goodsFrom1688s, err := utils1688.GetFenXiaoProductInfoFrom1688(basicSetting.AliCloudChainFenXiaoAppkey, basicSetting.AliCloudChainFenXiaoAppsecret, basicSetting.AliCloudChainFenXiaoAccesstoken, ids)
if err != nil {
logx.Error(err)
continue
}
result, ok := goodsFrom1688s["result"].(map[string]interface{})
if !ok {
fmt.Println("错误的数据", "!!!!!!!!!!!!!!!!!!!!")
return
}
if message, ok := result["message"]; ok {
fmt.Println("!!!!!", message)
return
}
resultList, ok := result["result"].([]interface{})
if !ok {
fmt.Println("!!!!!!错误的数据2!!!!!!!!!")
return
}
if len(resultList) == 0 {
fmt.Println("!!!!!!错误的数据3!!!!!!!!!")
return
}
var cloudChainGoods = map[string]map[string]interface{}{}
for _, v := range resultList {
tmp, ok1 := v.(map[string]interface{})
if !ok1 {
fmt.Println("!!!!!!错误的数据3-1!!!!!!!!!")
return
}
productInfo, ok1 := tmp["productInfo"].(map[string]interface{})
if !ok1 {
fmt.Println("!!!!!!错误的数据3-2!!!!!!!!!")
}
var productId = utils.AnyToString(productInfo["productID"])
for strings.HasSuffix(productId, "0") {
productId = strings.TrimSuffix(productId, "0")
}
if strings.HasSuffix(productId, ".") {
productId = strings.TrimSuffix(productId, ".")
}
cloudChainGoods[productId] = tmp
}

utils.FilePutContents("cloudChainGoods", utils.SerializeStr(cloudChainGoods))

for _, id := range ids { for _, id := range ids {
if cloudChainGoods[id] == nil {
continue
}
var goods model.MallGoods var goods model.MallGoods
goods.CloudChainGoodsId = id goods.CloudChainGoodsId = id
goods.MerchantId = systemMerchant.Id goods.MerchantId = systemMerchant.Id
@@ -99,43 +150,14 @@ func SupplyCloudChainFenxiaoNewChangeConsume(queue md.MqQueue) {
if getV2 { if getV2 {
continue continue
} }

goodsFrom1688, err := utils1688.GetFenXiaoProductInfoFrom1688(basicSetting.AliCloudChainFenXiaoAppkey, basicSetting.AliCloudChainFenXiaoAppsecret, basicSetting.AliCloudChainFenXiaoAccesstoken, id)
if err != nil {
logx.Error(err)
continue
}
var req md2.AddGoodsReq var req md2.AddGoodsReq
req.Base.GoodsType = 1 req.Base.GoodsType = 1
req.Base.CloudChainGoodsId = id req.Base.CloudChainGoodsId = id
req.Base.SaleState = enum.MallGoodsSaleStateOnShelf req.Base.SaleState = enum.MallGoodsSaleStateOnShelf
req.Base.CategoryId = utils.StrToInt(t.CategoryId) req.Base.CategoryId = utils.StrToInt(t.CategoryId)
req.Base.MerchantId = systemMerchant.Id req.Base.MerchantId = systemMerchant.Id
result, ok := goodsFrom1688["result"].(map[string]interface{})
if !ok {
fmt.Println("错误的数据", "!!!!!!!!!!!!!!!!!!!!")
return
}
if message, ok := result["message"]; ok {
fmt.Println("!!!!!", message)
return
}
resultList, ok := result["result"].([]interface{})
if !ok {
fmt.Println("!!!!!!错误的数据2!!!!!!!!!")
return
}
if len(resultList) == 0 {
fmt.Println("!!!!!!错误的数据3!!!!!!!!!")
return
}
cloudChainGoods, ok := resultList[0].(map[string]interface{})
if !ok {
fmt.Println("!!!!!!错误的数据4!!!!!!!!!")
return
}
utils.FilePutContents("cloudChainGoods", utils.SerializeStr(cloudChainGoods))
err = svc.CloudChainFenXiaoGoodsChangeMallGoods(c, cloudChainGoods, &req)

err = svc.CloudChainFenXiaoGoodsChangeMallGoods(c, cloudChainGoods[id], &req)
if err != nil { if err != nil {
switch err.(type) { switch err.(type) {
case e.E: case e.E:


+ 2
- 2
supply/1688/utils/aliApi.go View File

@@ -1037,13 +1037,13 @@ func NewGetFenXiaoSearchCybOffersFrom1688(appKey, appSecret string, req *NewFenX
return api1688, err return api1688, err
} }


func GetFenXiaoProductInfoFrom1688(appKey, appSecret, accessToken, offerId string) (map[string]interface{}, error) {
func GetFenXiaoProductInfoFrom1688(appKey, appSecret, accessToken string, offerIds []string) (map[string]interface{}, error) {
if accessToken == "" { if accessToken == "" {
accessToken = "2101cd32-8762-49ed-a87b-94e25ab0c40d" accessToken = "2101cd32-8762-49ed-a87b-94e25ab0c40d"
} }
reqMap := make(map[string]interface{}) reqMap := make(map[string]interface{})
reqMap["access_token"] = accessToken reqMap["access_token"] = accessToken
reqMap["offerIds"] = []int64{utils.StrToInt64(offerId)}
reqMap["offerIds"] = offerIds
parameters := make([]string, 0) parameters := make([]string, 0)
for key, value := range reqMap { for key, value := range reqMap {
if value != "" { if value != "" {


Loading…
Cancel
Save