|
|
@@ -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)
|
|
|
}
|