Forráskód Böngészése

商品model更改

abiao 5 éve
szülő
commit
389d950704

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

@@ -114,6 +114,59 @@ func (self *ProductController) Get() {
 	self.ServeJSON()
 }
 
+//商品详情
+func (self *ProductController) GetPdDetail() {
+	_id := self.Ctx.Input.Param(":id")
+	pId, _ := strconv.ParseInt(_id, 10, 64)
+	_size_id := self.Ctx.Input.Param(":size_id")
+	sizeId, _ := strconv.ParseInt(_size_id, 10, 64)
+	_color_id := self.Ctx.Input.Param(":color_id")
+	colorId, _ := strconv.ParseInt(_color_id, 10, 64)
+	cache, _ := self.GetBool("cache", false)
+
+	pd := product_model.GetProductByIdAndSizeAndColor(pId, 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
+	}
+	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.Id) != nil {
+		pd.HaveSize = true
+	}
+
+	pd.DeliverStartTime = pd.DeliverStartAt.Unix()
+	pd.DeliverStopTime = pd.DeliverStopAt.Unix()
+	// ret.Product = pd
+	self.Data["json"] = pd
+	self.ServeJSON()
+}
+
 //商品分类
 func (self *ProductController) Categories() {
 	ancestry := self.GetString("ancestry")

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

@@ -306,3 +306,21 @@ func (self *Product) Save() error {
 	}
 	return nil
 }
+
+//根据关联商品Id,sizeId,colorId,获取商品信息
+func GetProductByIdAndSizeAndColor(id, sizeId, colorId int64, useCache bool) *Product {
+	k := fmt.Sprintf("product_model.GetProductByIdAndSizeAndColor[%d]", id)
+	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", id).Filter("size_id", sizeId).Filter("color_id", colorId).One(item); err != nil {
+		return nil
+	}
+	item.Cover = GetCoverByPId(id, useCache)
+	cache.Cache.Put(k, item, 5*time.Minute)
+	return item
+}

+ 2 - 0
go/gopath/src/fohow.com/routers/routes.go

@@ -87,6 +87,8 @@ func init() {
 	beego.Router("/v1/product/:id([0-9]+)", &product_controller.ProductController{}, "get:Get")
 	//商品规格明细
 	beego.Router("/v1/product_size/:id([0-9]+)", &product_controller.ProductController{}, "get:GetProductSizesByPid")
+	//商品详情 by size + color
+	beego.Router("/v1/product/:id([0-9]+)/:size_id([0-9]+)/:color_id([0-9]+)", &product_controller.ProductController{}, "get:GetPdDetail")
 
 	//----------- 订单相关 -----------
 	//商品下单