Browse Source

增加店铺专区商品接口

abiao 5 years ago
parent
commit
f739a003f9

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

@@ -23,19 +23,24 @@ func (self *ProductController) Latest() {
 	page, _ := self.GetInt64("page")
 	perPage, _ := self.GetInt64("per_page")
 	cache, _ := self.GetBool("cache", false)
+	ptype := self.GetString("ptype")
+
 	if page <= 0 {
 		page = 1
 	}
 	if perPage <= 0 || perPage > 100 {
 		perPage = 20
 	}
+	if len(ptype) == 0 {
+		ptype = product_model.TYPE_DIRECT_SALE
+	}
 	type Ret struct {
 		List      []*product_model.Product `json:"list"`
 		ListCount int64                    `json:"list_count"`
 	}
 
-	pds := product_model.GetLatest(page, perPage, recommend, cache)
-	count := product_model.GetLatestCount(recommend, cache)
+	pds := product_model.GetLatest(page, perPage, recommend, ptype, cache)
+	count := product_model.GetLatestCount(recommend, ptype, cache)
 	for _, pd := range pds {
 		pd.SoldCount = pd.SaleNums
 		if pd.Count > pd.SoldCount {

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

@@ -104,7 +104,7 @@ type Product struct {
 }
 
 //获取最新推荐商品
-func GetLatest(page, perPage, recommend int64, useCache bool) (products []*Product) {
+func GetLatest(page, perPage, recommend int64, ptype string, useCache bool) (products []*Product) {
 	k := fmt.Sprintf("product_model.GetLatest.page(%d).perPage(%d).recommend(%d)", page, perPage, recommend)
 	if useCache {
 		if ret, ok := cache.Cache.Get(k).([]*Product); ok {
@@ -113,7 +113,7 @@ func GetLatest(page, perPage, recommend int64, useCache bool) (products []*Produ
 	}
 	o := orm.NewOrm()
 	_, err := o.QueryTable(new(Product)).Filter("status", 1).
-		Filter("recommend__gt", recommend).Filter("show_flag", true).
+		Filter("recommend__gt", recommend).Filter("show_flag", true).Filter("ptype", ptype).
 		OrderBy("-recommend", "-created_at").
 		Limit(perPage, (page-1)*perPage).
 		All(&products)
@@ -131,7 +131,7 @@ func GetLatest(page, perPage, recommend int64, useCache bool) (products []*Produ
 	return products
 }
 
-func GetLatestCount(recommend int64, useCache bool) int64 {
+func GetLatestCount(recommend int64, ptype string, useCache bool) int64 {
 	k := fmt.Sprintf("product_model.GetLatestCount.recommend(%d)", recommend)
 	if useCache {
 		if ret, ok := cache.Cache.Get(k).(int64); ok {
@@ -140,7 +140,7 @@ func GetLatestCount(recommend int64, useCache bool) int64 {
 	}
 	item := new(Product)
 	o := orm.NewOrm()
-	count, _ := o.QueryTable(item).Filter("recommend__gt", recommend).Filter("show_flag", true).Filter("status", 1).Count()
+	count, _ := o.QueryTable(item).Filter("recommend__gt", recommend).Filter("show_flag", true).Filter("ptype", ptype).Filter("status", 1).Count()
 
 	cache.Cache.Put(k, count, 10*time.Minute)
 	return count
@@ -172,7 +172,7 @@ func GetProductsByCatId(cId, page, perPage int64, useCache bool) (products []*Pr
 		}
 	}
 	o := orm.NewOrm()
-	qs := o.QueryTable(new(Product)).Filter("status", 1).Filter("show_flag", true)
+	qs := o.QueryTable(new(Product)).Filter("status", 1).Filter("show_flag", true).Filter("ptype", TYPE_DIRECT_SALE)
 	if cId != 0 {
 		qs = qs.Filter("category_id", cId)
 	} else {
@@ -209,7 +209,7 @@ func GetProductCountByCatId(cId int64, useCache bool) int64 {
 	} else {
 		qs = qs.Exclude("category_id", 3) //3为审核类别,暂写死
 	}
-	count, _ := qs.Filter("status", 1).Filter("show_flag", true).Count()
+	count, _ := qs.Filter("status", 1).Filter("show_flag", true).Filter("ptype", TYPE_DIRECT_SALE).Count()
 
 	cache.Cache.Put(k, count, 10*time.Minute)
 	return count