Commit ec2163bc by 杨树贤

兼容老数据

parent 3e48025c
Showing with 27 additions and 0 deletions
......@@ -148,6 +148,7 @@ type SpuExtra struct {
Name string `bson:"name" json:"name"`
Thumbnail string `bson:"thumbnail" json:"thumbnail"`
} `bson:"image_list" json:"image_list"`
SpuDetail string `bson:"spu_detail" json:"spu_detail"`
SpuId string `bson:"spu_id" json:"spu_id"`
}
......
......@@ -290,5 +290,31 @@ func (ls *LyService) GetSpuExtra(spuId string) (spuExtra model.SpuExtra) {
if err != nil && err != mgo.ErrNotFound {
logger.Select("sku_query").Error(err.Error())
}
//兼容老版本数据
if len(spuExtra.ImageList) == 0 {
type OldSpuExtra struct {
OldImageList map[string]struct {
Name string `bson:"name"`
Thumbnail string `bson:"thumbnail"`
} `bson:"image_list" json:"old_image_list"`
}
var oldSpuExtra OldSpuExtra
err = mongodb.DB("ichunt").C("spu_extra").Find(bson.M{"spu_id": spuId}).One(&oldSpuExtra)
for _, image := range oldSpuExtra.OldImageList {
spuExtra.ImageList = append(spuExtra.ImageList,struct {
Name string `bson:"name" json:"name"`
Thumbnail string `bson:"thumbnail" json:"thumbnail"`
}{
Name: image.Name,
Thumbnail: image.Thumbnail,
})
}
}
return spuExtra
}
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