fix: shama sync

master
howell 4 years ago
parent a09c84c758
commit d4a41d2413

@ -2,6 +2,7 @@ package task
import (
"errors"
"fmt"
"log"
"recook/internal/v2/lib/jcook"
"recook/internal/v2/lib/shama"
@ -112,7 +113,7 @@ func ShaMaSyncPageData(page, size uint, categories []RecookShaMaCategory) error
if len(skuEntries.Entries) == 0 {
return empty
}
skuMap := make(map[uint]shama.SkuInfo)
ids := make([]uint, 0)
if e := mysql2.Db.Transaction(func(tx *gorm.DB) error {
for _, v := range skuEntries.Entries {
var t goods.RecookGoodsSkuModel
@ -124,6 +125,7 @@ func ShaMaSyncPageData(page, size uint, categories []RecookShaMaCategory) error
}
}
if rCate == "" {
fmt.Println("分类错误:", v.CategoryThirdName, v.SkuID)
continue
}
tx.First(&t, "third_party_sku_id = ? AND third_party_type = 4", strconv.Itoa(int(v.SkuID)))
@ -142,7 +144,7 @@ func ShaMaSyncPageData(page, size uint, categories []RecookShaMaCategory) error
continue
}
skuMap[v.SkuID] = v
ids = append(ids, v.SkuID)
var bt goods.RecookGoodsBrandModel
tx.First(&bt, "name = ?", v.BrandName)
if bt.Id == 0 {
@ -154,15 +156,10 @@ func ShaMaSyncPageData(page, size uint, categories []RecookShaMaCategory) error
}
}
if len(skuMap) == 0 {
if len(ids) == 0 {
return nil
}
ids := make([]uint, 0)
for k, _ := range skuMap {
ids = append(ids, k)
}
rq := shama.SkuBrotherReq{
SkuIDSet: ids,
}
@ -170,16 +167,11 @@ func ShaMaSyncPageData(page, size uint, categories []RecookShaMaCategory) error
if err := c.Exec(rq, &bes); err != nil {
return err
}
for index, v := range bes {
if len(v.BrotherSkuIDs) == 0 {
bes[index].BrotherSkuIDs = append(bes[index].BrotherSkuIDs, ids[index])
}
for index := range bes {
bes[index].BrotherSkuIDs = append(bes[index].BrotherSkuIDs, ids[index])
}
for _, v := range bes {
if len(v.BrotherSkuIDs) == 0 {
continue
}
var res []jcook.SkuDetailResp
rq2 := jcook.SkuDetailReq{
SkuIDSet: v.BrotherSkuIDs,
@ -187,6 +179,10 @@ func ShaMaSyncPageData(page, size uint, categories []RecookShaMaCategory) error
if err := c.Exec(rq2, &res); err != nil {
return err
}
if len(res) == 0 {
fmt.Println("detail err:", v.BrotherSkuIDs)
continue
}
var gs1 goods.RecookGoodsInfoModel
VendorID := 3000

@ -134,8 +134,10 @@ func main() {
c.Stop()
close(idleConnClosed)
}()
cron.Task(c)
c.Start()
if configs.IsProductionEnv() {
cron.Task(c)
c.Start()
}
if err := g.Wait(); err != nil {
log.Fatal(err)
}

Loading…
Cancel
Save