ソースを参照

商品规格更改返回

abiao 5 年 前
コミット
ec1aa04648

+ 2 - 2
go/gopath/src/fohow.com/apps/controllers/product_controller/product_controller.go

@@ -312,7 +312,7 @@ func (self *ProductController) GetProductSizesByPid() {
 				if item.SizeType == product_model.SIZE_TYPE_1 {
 					attrList := product_model.GetProductAttrsByKId(productKeyConfig.Id)
 					for _, attr := range attrList {
-						prodSize := product_model.GetProductByIdAndSizeId(product.RelateProductId, attr.Id, false)
+						prodSize := product_model.GetProductByIdAndSizeId(product.RelateProductId, attr.Id, true)
 						if prodSize != nil {
 							size := &product_model.ProductAttr{}
 							size.Id = attr.Id
@@ -326,7 +326,7 @@ func (self *ProductController) GetProductSizesByPid() {
 				if item.SizeType == product_model.SIZE_TYPE_2 {
 					attrList := product_model.GetProductAttrsByKId(productKeyConfig.Id)
 					for _, attr := range attrList {
-						prodColor := product_model.GetProductByIdAndColorId(product.RelateProductId, attr.Id, false)
+						prodColor := product_model.GetProductByIdAndColorId(product.RelateProductId, attr.Id, true)
 						if prodColor != nil {
 							size := &product_model.ProductAttr{}
 							size.Id = attr.Id

+ 5 - 28
go/gopath/src/fohow.com/apps/models/product_model/product.go

@@ -335,16 +335,14 @@ func GetProductByIdAndSizeId(relateId, sizeId int64, useCache bool) *Product {
 			return v
 		}
 	}
-	beego.BeeLogger.Warn("size_id --- %d size_id --- %d", relateId, sizeId)
-
 	item := new(Product)
 	o := orm.NewOrm()
 	if err := o.QueryTable(item).Filter("relate_product_id", relateId).Filter("size_id", sizeId).Limit(1).One(item); err != nil {
 		beego.BeeLogger.Warn("product_model.GetProductByIdAndSizeId(%d) err=%s", sizeId, err)
 		return nil
 	}
-	beego.BeeLogger.Warn("1--size_id --- %d 2---size_id --- %d", relateId, sizeId)
-
+	item.Cover = GetCoverByPId(relateId, useCache)
+	cache.Cache.Put(k, item, 5*time.Minute)
 	return item
 }
 
@@ -358,31 +356,10 @@ func GetProductByIdAndColorId(relateId, colorId int64, useCache bool) *Product {
 	}
 	item := new(Product)
 	o := orm.NewOrm()
-	if err := o.QueryTable(item).Filter("relate_product_id", relateId).Filter("color_id", colorId).One(item); err != nil {
-		return nil
-	}
-
-	return item
-}
-
-func GetProductByIdAndSizeIdSql(relateId, sizeId int64, useCache bool) *Product {
-
-	sql := `
-		SELECT
-			 *
-		FROM
-			products
-		WHERE
-			relate_product_id = ?
-		and size_id = 1
-		limit 1
-		`
-
-	var item *Product
-	err := orm.NewOrm().Raw(sql, relateId, sizeId).QueryRow(&item)
-	if err != nil {
-		beego.BeeLogger.Warn("product_model.GetProductByIdAndSizeIdSql(%s) err=%s", sizeId, err)
+	if err := o.QueryTable(item).Filter("relate_product_id", relateId).Filter("color_id", colorId).Limit(1).One(item); err != nil {
 		return nil
 	}
+	item.Cover = GetCoverByPId(relateId, useCache)
+	cache.Cache.Put(k, item, 5*time.Minute)
 	return item
 }