Sfoglia il codice sorgente

商品规格更改返回

abiao 5 anni fa
parent
commit
fde20aaad1

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

@@ -128,45 +128,45 @@ func (self *ProductController) GetPdDetail() {
 		self.ReturnError(403, apps.NoExist, "", nil)
 	}
 	pd := product_model.GetProductByIdAndSizeAndColor(beginPd.RelateProductId, sizeId, colorId, cache)
-	if pd == nil {
-		self.ReturnError(403, apps.NoExist, "", nil)
-	}
-
-	pd.SoldCount = pd.SaleNums
-	if pd.Count > pd.SoldCount {
-		pd.LeftCount = pd.Count - pd.SoldCount
+	type Ret struct {
+		Product *product_model.Product `json:"product"`
 	}
-	pd.SoldCount = pd.SoldCount + pd.VirtualSoldCount
-	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)
-
-	if pd.SeckilShowPrice > 0 {
-		now := time.Now()
-		pd.SeckillStartAt = pd.SeckillStart.Unix()
-		pd.SeckillEndAt = pd.SeckillEnd.Unix()
-		if pd.SeckillStart.Unix() > now.Unix() {
-			pd.SeckillState = product_model.SECKILL_PREPARING_STATE
-			pd.SeckillStateCn = product_model.SECKILL_PREPARING_STATE_CN
-			pd.SoldCount = pd.SoldCount - pd.VirtualSoldCount //准备中不加虚拟量
-		} else if pd.SeckillStart.Unix() <= now.Unix() && now.Unix() < pd.SeckillEnd.Unix() {
-			pd.IsUnderSeckill = true
-			pd.SeckillState = product_model.SECKILL_UNDER_STATE
-			pd.SeckillStateCn = product_model.SECKILL_UNDER_STATE_CN
-		} else {
-			pd.SeckillState = product_model.SECKILL_END_STATE
-			pd.SeckillStateCn = product_model.SECKILL_END_STATE_CN
+	if pd != nil {
+		pd.SoldCount = pd.SaleNums
+		if pd.Count > pd.SoldCount {
+			pd.LeftCount = pd.Count - pd.SoldCount
 		}
+		pd.SoldCount = pd.SoldCount + pd.VirtualSoldCount
+		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)
+		if pd.SeckilShowPrice > 0 {
+			now := time.Now()
+			pd.SeckillStartAt = pd.SeckillStart.Unix()
+			pd.SeckillEndAt = pd.SeckillEnd.Unix()
+			if pd.SeckillStart.Unix() > now.Unix() {
+				pd.SeckillState = product_model.SECKILL_PREPARING_STATE
+				pd.SeckillStateCn = product_model.SECKILL_PREPARING_STATE_CN
+				pd.SoldCount = pd.SoldCount - pd.VirtualSoldCount //准备中不加虚拟量
+			} else if pd.SeckillStart.Unix() <= now.Unix() && now.Unix() < pd.SeckillEnd.Unix() {
+				pd.IsUnderSeckill = true
+				pd.SeckillState = product_model.SECKILL_UNDER_STATE
+				pd.SeckillStateCn = product_model.SECKILL_UNDER_STATE_CN
+			} else {
+				pd.SeckillState = product_model.SECKILL_END_STATE
+				pd.SeckillStateCn = product_model.SECKILL_END_STATE_CN
+			}
+		}
+		pd.HaveSize = false
+		if product_model.GetProductAttrConfig(pd.RelateProductId) != nil {
+			pd.HaveSize = true
+		}
+		pd.DeliverStartTime = pd.DeliverStartAt.Unix()
+		pd.DeliverStopTime = pd.DeliverStopAt.Unix()
 	}
-	pd.HaveSize = false
-	if product_model.GetProductAttrConfig(pd.RelateProductId) != nil {
-		pd.HaveSize = true
-	}
-
-	pd.DeliverStartTime = pd.DeliverStartAt.Unix()
-	pd.DeliverStopTime = pd.DeliverStopAt.Unix()
-	// ret.Product = pd
-	self.Data["json"] = pd
+	ret := &Ret{}
+	ret.Product = pd
+	self.Data["json"] = ret
 	self.ServeJSON()
 }