ソースを参照

update 供应链加入商品库

three
DengBiao 11ヶ月前
コミット
b79768a0bc
1個のファイルの変更160行の追加145行の削除
  1. +160
    -145
      consume/supply_cloud_chain_fenxiao_new_change.go

+ 160
- 145
consume/supply_cloud_chain_fenxiao_new_change.go ファイルの表示

@@ -1,7 +1,6 @@
package consume

import (
"applet/app/e"
svc2 "applet/app/svc"
"applet/app/utils"
"applet/app/utils/logx"
@@ -40,152 +39,10 @@ func SupplyCloudChainFenxiaoNewChangeConsume(queue md.MqQueue) {
res, ok = <-delivery
if ok == true {
fmt.Println(">>>>>>>>>>>>>>>>SupplyCloudChainFenxiaoNewChangeConsume<<<<<<<<<<<<<<<<<<<<<<<<<")
//解析mq中queue的数据结构体
var pushStuct struct {
Args struct {
md2.GoodsAddPriceConditions
} `json:"args"`
Mid string `json:"mid"`
}
err = json.Unmarshal(res.Body, &pushStuct)
err = handleSupplyCloudChainFenxiaoNewChangeConsume(res.Body)
if err != nil {
panic(err)
}

//设置masterId
var c = &gin.Context{}
c.Set("mid", pushStuct.Mid)
var t struct {
md2.GoodsAddPriceConditions
}
t = pushStuct.Args
var idsMap = map[string]string{}
for _, v := range t.Ids {
idsMap[v] = v
}
var idsArray []string
for _, v := range idsMap {
idsArray = append(idsArray, v)
}
t.Ids = idsArray

basicSetting, _ := svc.GetSupplyBasicSetting(c)
if basicSetting == nil {
fmt.Println("!!!!!功能开发中!!!!!")
continue
}
if basicSetting.AliCloudChainFenXiaoAppkey == "" || basicSetting.AliCloudChainFenXiaoAppsecret == "" || basicSetting.AliCloudChainFenXiaoAccesstoken == "" {
fmt.Println("!!!!!必要参数没有填写,功能已暂停!!!!!")
continue
}
get, systemMerchant, err1 := db.GetSystemMerchant(svc2.MasterDb(c))
if err1 != nil {
fmt.Println(err1.Error(), "!!!!!!!!!!!!!!!!!!!!")
continue
}
if !get {
fmt.Println("!!!!!请先去设置官方商家信息!!!!!")
continue
}
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("错误的数据", "!!!!!!!!!!!!!!!!!!!!")
continue
}
if message, ok := result["message"]; ok {
fmt.Println("!!!!!", message)
continue
}
resultList, ok := result["result"].([]interface{})
if !ok {
fmt.Println("!!!!!!错误的数据2!!!!!!!!!")
continue
}
if len(resultList) == 0 {
fmt.Println("!!!!!!错误的数据3!!!!!!!!!")
continue
}
var cloudChainGoods = map[string]map[string]interface{}{}
for _, v := range resultList {
tmp, ok1 := v.(map[string]interface{})
if !ok1 {
fmt.Println("!!!!!!错误的数据3-1!!!!!!!!!")
continue
}
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
fmt.Println("*****************err*************************", err)
}

utils.FilePutContents("cloudChainGoods", utils.SerializeStr(cloudChainGoods))
go func() {
for _, id := range ids {
if cloudChainGoods[id] == nil {
continue
}
var goods model.MallGoods
goods.CloudChainGoodsId = id
goods.MerchantId = systemMerchant.Id
getV2, err11 := goods.GetV2(svc2.MasterDb(c))
if err11 != nil {
fmt.Println("!!!!!!", err11.Error())
continue
}
if getV2 {
continue
}
var req md2.AddGoodsReq
req.Base.GoodsType = 1
req.Base.CloudChainGoodsId = id
req.Base.SaleState = enum.MallGoodsSaleStateOnShelf
req.Base.CategoryId = utils.StrToInt(t.CategoryId)
req.Base.MerchantId = systemMerchant.Id

err = svc.CloudChainFenXiaoGoodsChangeMallGoods(c, cloudChainGoods[id], &req)
if err != nil {
switch err.(type) {
case e.E:
err1 := err.(e.E)
fmt.Println("!!!!!!", err1.Error())
continue
default:
fmt.Println("!!!!!!", err.Error())
continue
}
}

err1 := svc.AddMallGoods(c, &req)
if err1 != nil {
switch err1.(type) {
case e.E:
err1 := err1.(e.E)
fmt.Println("!!!!!!", err1.Error())
continue
default:
fmt.Println("!!!!!!", err.Error())
continue
}
}

time.Sleep(10 * time.Millisecond)
}
}()
_ = res.Ack(true)
} else {
panic(errors.New("error getting message"))
@@ -210,3 +67,161 @@ func RemoveRepeatedElement(arr []string) (newArr []string) {
}
return
}

func handleSupplyCloudChainFenxiaoNewChangeConsume(msgData []byte) error {
//解析mq中queue的数据结构体
var pushStuct struct {
Args struct {
md2.GoodsAddPriceConditions
} `json:"args"`
Mid string `json:"mid"`
}
err := json.Unmarshal(msgData, &pushStuct)
if err != nil {
panic(err)
}

//设置masterId
var c = &gin.Context{}
c.Set("mid", pushStuct.Mid)
var t struct {
md2.GoodsAddPriceConditions
}
t = pushStuct.Args
var idsMap = map[string]string{}
for _, v := range t.Ids {
idsMap[v] = v
}
var idsArray []string
for _, v := range idsMap {
idsArray = append(idsArray, v)
}
t.Ids = idsArray

basicSetting, _ := svc.GetSupplyBasicSetting(c)
if basicSetting == nil {
return errors.New("!!!!!功能开发中")
}
if basicSetting.AliCloudChainFenXiaoAppkey == "" || basicSetting.AliCloudChainFenXiaoAppsecret == "" || basicSetting.AliCloudChainFenXiaoAccesstoken == "" {
return errors.New("!!!!!必要参数没有填写,功能已暂停")
}
get, systemMerchant, err1 := db.GetSystemMerchant(svc2.MasterDb(c))
if err1 != nil {
return err1
}
if !get {
return errors.New("!!!!!请先去设置官方商家信息")
}
ids := RemoveRepeatedElement(t.Ids)
var tmpIds []string
var resultList []interface{}
for _, v := range ids {
tmpIds = append(tmpIds, v)
if len(tmpIds) >= 20 {
goodsFrom1688s, err := utils1688.GetFenXiaoProductInfoFrom1688(basicSetting.AliCloudChainFenXiaoAppkey, basicSetting.AliCloudChainFenXiaoAppsecret, basicSetting.AliCloudChainFenXiaoAccesstoken, tmpIds)
if err != nil {
return err
}
result, ok := goodsFrom1688s["result"].(map[string]interface{})
if !ok {
return errors.New("!!!!!错误的数据")
}
if message, ok := result["message"]; ok {
fmt.Println("!!!!!!!!!!!!", message, "!!!!!!!!!!")
return errors.New("message 反射失败1")
}
tmpResultList, ok := result["result"].([]interface{})
if !ok {
return errors.New("!!!!!!错误的数据2")
}
if len(tmpResultList) == 0 {
return errors.New("!!!!!!错误的数据3")
}
for _, vv := range tmpResultList {
resultList = append(resultList, vv)
}
tmpIds = []string{}
}
}

if len(tmpIds) >= 0 {
goodsFrom1688s, err := utils1688.GetFenXiaoProductInfoFrom1688(basicSetting.AliCloudChainFenXiaoAppkey, basicSetting.AliCloudChainFenXiaoAppsecret, basicSetting.AliCloudChainFenXiaoAccesstoken, tmpIds)
if err != nil {
return err
}
result, ok := goodsFrom1688s["result"].(map[string]interface{})
if !ok {
return errors.New("!!!!!!错误的数据4")
}
if message, ok := result["message"]; ok {
fmt.Println("!!!!!", message)
return errors.New("message 反射失败2")
}
tmpResultList, ok := result["result"].([]interface{})
if !ok {
return errors.New("!!!!!!错误的数据4")
}
if len(tmpResultList) == 0 {
return errors.New("!!!!!!错误的数据5")
}
for _, vv := range tmpResultList {
resultList = append(resultList, vv)
}
}

var cloudChainGoods = map[string]map[string]interface{}{}
for _, v := range resultList {
tmp, ok1 := v.(map[string]interface{})
if !ok1 {
return errors.New("!!!!!!错误的数据6")
}
productInfo, ok1 := tmp["productInfo"].(map[string]interface{})
if !ok1 {
return errors.New("!!!!!!错误的数据7")
}
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 {
if cloudChainGoods[id] == nil {
continue
}
var goods model.MallGoods
goods.CloudChainGoodsId = id
goods.MerchantId = systemMerchant.Id
getV2, err11 := goods.GetV2(svc2.MasterDb(c))
if err11 != nil {
fmt.Println("!!!!!!", err11.Error())
continue
}
if getV2 {
continue
}
var req md2.AddGoodsReq
req.Base.GoodsType = 1
req.Base.CloudChainGoodsId = id
req.Base.SaleState = enum.MallGoodsSaleStateOnShelf
req.Base.CategoryId = utils.StrToInt(t.CategoryId)
req.Base.MerchantId = systemMerchant.Id

err := svc.CloudChainFenXiaoGoodsChangeMallGoods(c, cloudChainGoods[id], &req)
if err != nil {
return err
}

err111 := svc.AddMallGoods(c, &req)
if err111 != nil {
return err111
}
time.Sleep(12 * time.Millisecond)
}
return nil
}

読み込み中…
キャンセル
保存