浏览代码

product package item develop

abiao 4 年之前
父节点
当前提交
44dfc01871

+ 11 - 0
go/gopath/src/fohow.com/apps/controllers/order_controller/cart_controller.go

@@ -240,6 +240,17 @@ func (self *OrderController) GetCartList() {
 				item.ColorName = productColor.Name
 			}
 		}
+		if product.Package {
+			cart_package := &order_model.ProductItem{}
+			packageList := product_model.GetPackageList(product.Id, true)
+			for _, package_one := range packageList {
+				cart_package.ProductId = package_one.ProductId
+				cart_package.ItemId = package_one.ItemId
+				cart_package.ItemTitle = package_one.ItemTitle
+				cart_package.Nums = package_one.Nums
+				item.PackageList = append(item.PackageList, cart_package)
+			}
+		}
 		item.Cover = product_model.GetCoverByPId(item.ProductId, cache)
 		item.OriginalPrice = product.Price
 		item.ProductName = product.Name

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

@@ -67,6 +67,9 @@ func (self *ProductController) Latest() {
 				pd.SeckillStateCn = product_model.SECKILL_END_STATE_CN
 			}
 		}
+		if pd.Package {
+			pd.PackageList = product_model.GetPackageList(pd.Id, true)
+		}
 		pd.DeliverStartTime = pd.DeliverStartAt.Unix()
 		pd.DeliverStopTime = pd.DeliverStopAt.Unix()
 	}
@@ -112,6 +115,9 @@ func (self *ProductController) Get() {
 			pd.SeckillStateCn = product_model.SECKILL_END_STATE_CN
 		}
 	}
+	if pd.Package {
+		pd.PackageList = product_model.GetPackageList(pd.Id, true)
+	}
 	pd.HaveSize = false
 	if product_model.GetProductAttrConfig(pd.RelateProductId) != nil {
 		pd.HaveSize = true
@@ -171,6 +177,9 @@ func (self *ProductController) GetPdDetail() {
 		if product_model.GetProductAttrConfig(pd.RelateProductId) != nil {
 			pd.HaveSize = true
 		}
+		if pd.Package {
+			pd.PackageList = product_model.GetPackageList(pd.Id, true)
+		}
 		pd.DeliverStartTime = pd.DeliverStartAt.Unix()
 		pd.DeliverStopTime = pd.DeliverStopAt.Unix()
 	}
@@ -237,6 +246,9 @@ func (self *ProductController) GetProductsByCat() {
 				pd.SeckillState = product_model.SECKILL_END_STATE
 				pd.SeckillStateCn = product_model.SECKILL_END_STATE_CN
 			}
+			if pd.Package {
+				pd.PackageList = product_model.GetPackageList(pd.Id, true)
+			}
 		}
 
 		pd.DeliverStartTime = pd.DeliverStartAt.Unix()

+ 14 - 13
go/gopath/src/fohow.com/apps/models/order_model/cart.go

@@ -18,19 +18,20 @@ const (
 )
 
 type Cart struct {
-	Id            int64     `orm:"column(id);pk"                                       json:"id"`         // int(11)
-	ProductId     int64     `orm:"column(product_id)"                                  json:"product_id"` // int(11)
-	UserId        int64     `orm:"column(user_id)"                            json:"user_id"`             // varchar(64)
-	WxUserId      int64     `orm:"column(wx_user_id)"                                  json:"wx_user_id"`
-	CreatedAt     time.Time `orm:"column(created_at);null;auto_now_add;type(datetime)" json:"-"`    // datetime
-	Count         int64     `orm:"column(nums)"                                       json:"count"` // int(11)
-	IsBuy         bool      `orm:"column(is_buy)" 			json:"is_under_seckill"`
-	ProductName   string    `orm:"-"     json:"product_name"`   // decimal(10,2)
-	SizeName      string    `orm:"-"     json:"size_name"`      //   varchar(64)
-	ColorName     string    `orm:"-"     json:"color_name"`     //  varchar(64)
-	Cover         string    `orm:"-"     json:"cover"`          // decimal(10,2)
-	OriginalPrice int64     `orm:"-"     json:"original_price"` // decimal(10,2)
-	Attrs         string    `orm:"-"     json:"attrs"`          // decimal(10,2)
+	Id            int64          `orm:"column(id);pk"                                       json:"id"`         // int(11)
+	ProductId     int64          `orm:"column(product_id)"                                  json:"product_id"` // int(11)
+	UserId        int64          `orm:"column(user_id)"                            json:"user_id"`             // varchar(64)
+	WxUserId      int64          `orm:"column(wx_user_id)"                                  json:"wx_user_id"`
+	CreatedAt     time.Time      `orm:"column(created_at);null;auto_now_add;type(datetime)" json:"-"`    // datetime
+	Count         int64          `orm:"column(nums)"                                       json:"count"` // int(11)
+	IsBuy         bool           `orm:"column(is_buy)" 			json:"is_under_seckill"`
+	ProductName   string         `orm:"-"     json:"product_name"`      // decimal(10,2)
+	SizeName      string         `orm:"-"     json:"size_name"`         //   varchar(64)
+	ColorName     string         `orm:"-"     json:"color_name"`        //  varchar(64)
+	Cover         string         `orm:"-"     json:"cover"`             // decimal(10,2)
+	OriginalPrice int64          `orm:"-"     json:"original_price"`    // decimal(10,2)
+	Attrs         string         `orm:"-"     json:"attrs"`             // decimal(10,2)
+	PackageList   []*ProductItem `orm:"-"          json:"product_list"` // varchar(255)
 }
 
 func (self *Cart) TableName() string {

+ 1 - 1
go/gopath/src/fohow.com/apps/models/order_model/init.go

@@ -12,7 +12,7 @@ import (
 )
 
 func init() {
-	orm.RegisterModel(new(Order), new(Cart), new(OrderDetail), new(OrderRefund))
+	orm.RegisterModel(new(Order), new(Cart), new(OrderDetail), new(OrderRefund), new(OrderDtItem))
 }
 
 func GetCdnFullImgUrl(img string) string {

+ 8 - 0
go/gopath/src/fohow.com/apps/models/order_model/order_dt_item.go

@@ -23,3 +23,11 @@ type OrderDtItem struct {
 func (self *OrderDtItem) TableName() string {
 	return order_dt_items_tablename
 }
+
+type ProductItem struct {
+	ProductId int64  `orm:"column(product_id)"           json:"product_id"` // int(11)
+	Title     string `orm:"column(title);null"           json:"title"`      // varchar(64)
+	ItemId    int64  `orm:"column(item_id);null"         json:"item_id"`    // tinyint(1)
+	ItemTitle string `orm:"column(item_title);null"      json:"item_title"` // varchar(64)
+	Nums      int64  `orm:"column(nums);null"            json:"nums"`       // tinyint(1)
+}

+ 1 - 0
go/gopath/src/fohow.com/apps/models/product_model/init.go

@@ -16,6 +16,7 @@ func init() {
 		new(Picture),
 		new(ProductCat),
 		new(ProductCommend),
+		new(ProductItem),
 	)
 }
 

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

@@ -104,6 +104,10 @@ type Product struct {
 	SizeName         string `orm:"-"                                     json:"-"`         // varchar(255)
 	ColorName        string `orm:"-"                                     json:"-"`         // varchar(255)
 	SinglePurchLimit int64  `orm:"column(single_purch_limit)"            json:"-"`         // varchar(255)
+
+	Package     bool           `orm:"column(package)"                          json:"package"` // varchar(255)
+	PackageList []*ProductItem `orm:"-"                           json:"product_list"`         // varchar(255)
+
 }
 
 //获取最新推荐商品

+ 26 - 2
go/gopath/src/fohow.com/apps/models/product_model/product_item.go

@@ -1,6 +1,12 @@
 package product_model
 
-import "time"
+import (
+	"fmt"
+	"fohow.com/cache"
+	"github.com/astaxie/beego"
+	"github.com/astaxie/beego/orm"
+	"time"
+)
 
 const (
 	product_items_tablename = "product_items"
@@ -9,7 +15,7 @@ const (
 type ProductItem struct {
 	Id        int64     `orm:"column(id);pk"                json:"id"`                  // int(11)
 	ProductId int64     `orm:"column(product_id)"           json:"product_id"`          // int(11)
-	Title     string    `orm:"column(title);null"           json:"title"`               // varchar(64)
+	Title     string    `orm:"column(title);null"           json:"-"`                   // varchar(64)
 	ItemId    int64     `orm:"column(item_id);null"         json:"item_id"`             // tinyint(1)
 	ItemTitle string    `orm:"column(item_title);null"      json:"item_title"`          // varchar(64)
 	Nums      int64     `orm:"column(nums);null"            json:"nums"`                // tinyint(1)
@@ -20,3 +26,21 @@ type ProductItem struct {
 func (self *ProductItem) TableName() string {
 	return product_items_tablename
 }
+
+// 根据商品Id找出商品对应套装明细
+func GetPackageList(pId int64, useCache bool) (items []*ProductItem) {
+	k := fmt.Sprintf("product_model.GetPackageList(%d)", pId)
+	if useCache {
+		if ret, ok := cache.Cache.Get(k).([]*ProductItem); ok {
+			return ret
+		}
+	}
+	o := orm.NewOrm()
+	_, err := o.QueryTable(new(ProductItem)).Filter("product_id", 1).All(&items)
+	if err != nil {
+		beego.BeeLogger.Debug("GetPackageList err=%s", err)
+	}
+
+	cache.Cache.Put(k, items, 10*time.Minute)
+	return items
+}