瀏覽代碼

增加 商品专区逻辑

abiao 3 年之前
父節點
當前提交
4ebc283ed3

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

@@ -26,6 +26,7 @@ func (self *ProductController) Latest() {
 	ptype := self.GetString("ptype")
 	price_sort, _ := self.GetInt64("price_sort")
 	sale_sort, _ := self.GetInt64("sale_sort")
+	sale_zone, _ := self.GetInt64("sale_zone")
 
 	if page <= 0 {
 		page = 1
@@ -44,8 +45,8 @@ func (self *ProductController) Latest() {
 		ListCount int64                    `json:"list_count"`
 	}
 
-	pds := product_model.GetLatest(page, perPage, recommend, price_sort, sale_sort, ptype, cache)
-	count := product_model.GetLatestCount(recommend, ptype, cache)
+	pds := product_model.GetLatest(page, perPage, recommend, price_sort, sale_sort, sale_zone, ptype, cache)
+	count := product_model.GetLatestCount(recommend, sale_zone, ptype, cache)
 	for _, pd := range pds {
 		pd.SoldCount = pd.SaleNums
 		if pd.Count > pd.SoldCount {
@@ -330,6 +331,7 @@ func (self *ProductController) GetProductsByCat() {
 	cache, _ := self.GetBool("cache", false)
 	price_sort, _ := self.GetInt64("price_sort")
 	sale_sort, _ := self.GetInt64("sale_sort")
+	sale_zone, _ := self.GetInt64("sale_zone")
 
 	if page <= 0 {
 		page = 1
@@ -341,8 +343,8 @@ func (self *ProductController) GetProductsByCat() {
 		List      []*product_model.Product `json:"list"`
 		ListCount int64                    `json:"list_count"`
 	}
-	list := product_model.GetProductsByCatId(catId, page, perPage, price_sort, sale_sort, words, cache)
-	count := product_model.GetProductCountByCatId(catId, words, cache)
+	list := product_model.GetProductsByCatId(catId, sale_zone, page, perPage, price_sort, sale_sort, words, cache)
+	count := product_model.GetProductCountByCatId(catId, sale_zone, words, cache)
 	for _, pd := range list {
 		pd.SoldCount = pd.SaleNums
 		if pd.Count > pd.SoldCount {

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

@@ -127,14 +127,17 @@ type Product struct {
 }
 
 //获取最新推荐商品
-func GetLatest(page, perPage, recommend, priceSort, saleSort int64, ptype string, useCache bool) (products []*Product) {
+func GetLatest(page, perPage, recommend, priceSort, saleSort, saleZone 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 {
 			return ret
 		}
 	}
-	var priceSql, saleSql, orderSql string
+	var saleZoneSql, priceSql, saleSql, orderSql string
+	if saleZone > int64(0) {
+		saleZoneSql = fmt.Sprintf("and sale_zone=?", saleZone)
+	}
 	if priceSort == int64(1) {
 		//降序
 		priceSql = "price desc"
@@ -159,10 +162,10 @@ func GetLatest(page, perPage, recommend, priceSort, saleSort int64, ptype string
 	}
 	sql := `
 		select * from products
-		where status = ? and recommend > ? and show_flag=? and ptype=?
+		where status = ? and recommend > ? and show_flag=? and ptype=? %s
 		order by %s limit %d, %d; 
 	`
-	sql = fmt.Sprintf(sql, orderSql, (page-1)*perPage, perPage)
+	sql = fmt.Sprintf(sql, saleZoneSql, orderSql, (page-1)*perPage, perPage)
 	//beego.BeeLogger.Warn("sql=%s", sql)
 	_, err := orm.NewOrm().Raw(sql, 1, recommend, true, ptype).QueryRows(&products)
 
@@ -180,7 +183,7 @@ func GetLatest(page, perPage, recommend, priceSort, saleSort int64, ptype string
 	return products
 }
 
-func GetLatestCount(recommend int64, ptype string, useCache bool) int64 {
+func GetLatestCount(recommend, saleZone 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 {
@@ -189,7 +192,11 @@ func GetLatestCount(recommend int64, ptype string, useCache bool) int64 {
 	}
 	item := new(Product)
 	o := orm.NewOrm()
-	count, _ := o.QueryTable(item).Filter("recommend__gt", recommend).Filter("show_flag", true).Filter("ptype", ptype).Filter("status", 1).Count()
+	qs := o.QueryTable(item).Filter("recommend__gt", recommend).Filter("show_flag", true).Filter("ptype", ptype).Filter("status", 1)
+	if saleZone > int64(0) {
+		qs = qs.Filter("sale_zone", saleZone)
+	}
+	count, _ := qs.Count()
 
 	cache.Cache.Put(k, count, 10*time.Minute)
 	return count
@@ -262,7 +269,7 @@ func GetNoDeliveryPrd(id int64, province string, useCache bool) *Product {
 	return item
 }
 
-func GetProductsByCatId(cId, page, perPage, priceSort, saleSort int64, words string, useCache bool) (products []*Product) {
+func GetProductsByCatId(cId, saleZone, page, perPage, priceSort, saleSort int64, words string, useCache bool) (products []*Product) {
 	k := fmt.Sprintf("product_model.GetProductsByCatId(%d).page(%d).perPage(%d).words(%d)", cId, page, perPage, words)
 	if useCache {
 		if ret, ok := cache.Cache.Get(k).([]*Product); ok {
@@ -297,6 +304,9 @@ func GetProductsByCatId(cId, page, perPage, priceSort, saleSort int64, words str
 	if cId != 0 {
 		cidSql = fmt.Sprintf("and category_id=%d", cId)
 	}
+	if saleZone != 0 {
+		cidSql = cidSql + fmt.Sprintf("and sale_zone=%d", saleZone)
+	}
 
 	if len(words) > 0 {
 		cidSql = cidSql + fmt.Sprintf(" and key_words like '%s'", "%"+words+"%")
@@ -321,7 +331,7 @@ func GetProductsByCatId(cId, page, perPage, priceSort, saleSort int64, words str
 	return products
 }
 
-func GetProductCountByCatId(cId int64, words string, useCache bool) int64 {
+func GetProductCountByCatId(cId, saleZone int64, words string, useCache bool) int64 {
 	k := fmt.Sprintf("product_model.GetProductCountByCatId(%d)", cId)
 	if useCache {
 		if ret, ok := cache.Cache.Get(k).(int64); ok {
@@ -334,6 +344,11 @@ func GetProductCountByCatId(cId int64, words string, useCache bool) int64 {
 	if cId != 0 {
 		qs = qs.Filter("category_id", cId)
 	}
+
+	if saleZone != 0 {
+		qs = qs.Filter("sale_zone", saleZone)
+	}
+
 	if len(words) > 0 {
 		qs = qs.Filter("key_words__icontains", words)
 	}