Prechádzať zdrojové kódy

更改商品售量显示

abiao 4 rokov pred
rodič
commit
05b29d08b8

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

@@ -49,7 +49,9 @@ func (self *ProductController) Latest() {
 		if pd.Count > pd.SoldCount {
 			pd.LeftCount = pd.Count - pd.SoldCount
 		}
-		pd.SoldCount = pd.SoldCount + pd.VirtualSoldCount
+		//pd.SoldCount = pd.SoldCount + pd.VirtualSoldCount
+		pd.SoldCount = product_model.GetProductCountByRelateId(pd.RelateProductId, true)
+
 		if pd.SeckilShowPrice > 0 {
 			now := time.Now()
 			pd.SeckillStartAt = pd.SeckillStart.Unix()
@@ -144,7 +146,9 @@ func (self *ProductController) Get() {
 	if pd.Count > pd.SoldCount {
 		pd.LeftCount = pd.Count - pd.SoldCount
 	}
-	pd.SoldCount = pd.SoldCount + pd.VirtualSoldCount
+	//pd.SoldCount = pd.SoldCount + pd.VirtualSoldCount
+	pd.SoldCount = product_model.GetProductCountByRelateId(pd.RelateProductId, true)
+
 	pd.Cover = product_model.GetCoverByPId(pId, cache)
 	pd.Album = product_model.GetPicturesByPIdAndPType(pId, product_model.PIC_TYPE_ALBUM, cache)
 	pd.ShareImg = self.GetCdnFullImgUrl(pd.ShareImg)
@@ -229,7 +233,9 @@ func (self *ProductController) GetPdDetail() {
 		if pd.Count > pd.SoldCount {
 			pd.LeftCount = pd.Count - pd.SoldCount
 		}
-		pd.SoldCount = pd.SoldCount + pd.VirtualSoldCount
+		//pd.SoldCount = pd.SoldCount + pd.VirtualSoldCount
+		pd.SoldCount = product_model.GetProductCountByRelateId(pd.RelateProductId, true)
+
 		pd.Cover = product_model.GetCoverByPId(pd.Id, cache)
 		pd.Album = product_model.GetPicturesByPIdAndPType(pd.Id, product_model.PIC_TYPE_ALBUM, cache)
 		pd.ShareImg = self.GetCdnFullImgUrl(pd.ShareImg)
@@ -318,7 +324,9 @@ func (self *ProductController) GetProductsByCat() {
 		if pd.Count > pd.SoldCount {
 			pd.LeftCount = pd.Count - pd.SoldCount
 		}
-		pd.SoldCount = pd.SoldCount + pd.VirtualSoldCount
+		//pd.SoldCount = pd.SoldCount + pd.VirtualSoldCount
+		pd.SoldCount = product_model.GetProductCountByRelateId(pd.RelateProductId, true)
+
 		if pd.SeckilShowPrice > 0 {
 			now := time.Now()
 			pd.SeckillStartAt = pd.SeckillStart.Unix()

+ 25 - 0
go/gopath/src/fohow.com/apps/models/product_model/product.go

@@ -382,3 +382,28 @@ func GetProductByIdAndColorId(relateId, colorId int64, useCache bool) *Product {
 	cache.Cache.Put(k, item, 5*time.Minute)
 	return item
 }
+
+//获取某主商品销售总量
+func GetProductCountByRelateId(relateId int64, useCache bool) int64 {
+	type Ret struct {
+		Count int64
+	}
+	ret := &Ret{}
+	k := fmt.Sprintf("product_model.GetProductCountByRelateId(%d)", relateId)
+	if useCache {
+		if ret, ok := cache.Cache.Get(k).(int64); ok {
+			return ret
+		}
+	}
+	o := orm.NewOrm()
+	sql := fmt.Sprintf("SELECT sum(`virtual_sold_count`+ `sale_nums`) as count FROM `products` WHERE  relate_product_id=%d;", relateId)
+	err := o.Raw(sql).QueryRow(ret)
+	if err != nil {
+		beego.BeeLogger.Error("GetSumBalancePerfomance err=[%s]", err)
+		return 0
+	}
+
+	cache.Cache.Put(k, ret.Count, 10*time.Minute)
+	return ret.Count
+
+}