|
|
@@ -326,3 +326,39 @@ func GetProductByIdAndSizeAndColor(id, sizeId, colorId int64, useCache bool) *Pr
|
|
|
cache.Cache.Put(k, item, 5*time.Minute)
|
|
|
return item
|
|
|
}
|
|
|
+
|
|
|
+//根据商品 relate_Id 跟 sizeId,获取商品信息
|
|
|
+func GetProductByIdAndSizeId(relateId, sizeId int64, useCache bool) *Product {
|
|
|
+ k := fmt.Sprintf("product_model.GetProductByIdAndSizeId[%d]", relateId)
|
|
|
+ if useCache {
|
|
|
+ if v, ok := cache.Cache.Get(k).(*Product); ok {
|
|
|
+ return v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item := new(Product)
|
|
|
+ o := orm.NewOrm()
|
|
|
+ if err := o.QueryTable(item).Filter("relate_product_id", relateId).Filter("size_id", sizeId).One(item); err != nil {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ item.Cover = GetCoverByPId(relateId, useCache)
|
|
|
+ cache.Cache.Put(k, item, 5*time.Minute)
|
|
|
+ return item
|
|
|
+}
|
|
|
+
|
|
|
+//根据商品 relate_Id 跟 colorId,获取商品信息
|
|
|
+func GetProductByIdAndColorId(relateId, sizeId int64, useCache bool) *Product {
|
|
|
+ k := fmt.Sprintf("product_model.GetProductByIdAndColorId[%d]", relateId)
|
|
|
+ if useCache {
|
|
|
+ if v, ok := cache.Cache.Get(k).(*Product); ok {
|
|
|
+ return v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item := new(Product)
|
|
|
+ o := orm.NewOrm()
|
|
|
+ if err := o.QueryTable(item).Filter("relate_product_id", relateId).Filter("color_id", sizeId).One(item); err != nil {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ item.Cover = GetCoverByPId(relateId, useCache)
|
|
|
+ cache.Cache.Put(k, item, 5*time.Minute)
|
|
|
+ return item
|
|
|
+}
|