|
|
@@ -129,7 +129,7 @@ func GetLatest(page, perPage, recommend, priceSort, saleSort int64, ptype string
|
|
|
return ret
|
|
|
}
|
|
|
}
|
|
|
- var priceSql, saleSql string
|
|
|
+ var priceSql, saleSql, orderSql string
|
|
|
if priceSort == int64(1) {
|
|
|
//降序
|
|
|
priceSql = "price desc"
|
|
|
@@ -144,19 +144,20 @@ func GetLatest(page, perPage, recommend, priceSort, saleSort int64, ptype string
|
|
|
saleSql = "(virtual_sold_count+sale_nums) asc"
|
|
|
}
|
|
|
if len(priceSql) <= 0 && len(saleSql) <= 0 {
|
|
|
- priceSql = "recommend desc"
|
|
|
- saleSql = "created_at desc"
|
|
|
+ orderSql = "recommend desc,created_at desc"
|
|
|
} else if len(priceSql) <= 0 {
|
|
|
- priceSql = saleSql
|
|
|
+ orderSql = saleSql
|
|
|
} else if len(saleSql) <= 0 {
|
|
|
- saleSql = priceSql
|
|
|
+ orderSql = priceSql
|
|
|
+ } else {
|
|
|
+ orderSql = fmt.Sprintf("%s,%s", priceSql, saleSql)
|
|
|
}
|
|
|
sql := `
|
|
|
select * from products
|
|
|
where status = ? and recommend > ? and show_flag=? and ptype=?
|
|
|
- order by %s,%s limit %d, %d;
|
|
|
- `
|
|
|
- sql = fmt.Sprintf(sql, priceSql, saleSql, (page-1)*perPage, perPage)
|
|
|
+ order by %s limit %d, %d;
|
|
|
+ `
|
|
|
+ sql = fmt.Sprintf(sql, orderSql, (page-1)*perPage, perPage)
|
|
|
beego.BeeLogger.Warn("sql=%s", sql)
|
|
|
_, err := orm.NewOrm().Raw(sql, 1, recommend, true, ptype).QueryRows(&products)
|
|
|
|
|
|
@@ -215,8 +216,7 @@ func GetProductsByCatId(cId, page, perPage, priceSort, saleSort int64, words str
|
|
|
return ret
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- var priceSql, saleSql string
|
|
|
+ var priceSql, saleSql, orderSql string
|
|
|
if priceSort == int64(1) {
|
|
|
//降序
|
|
|
priceSql = "price desc"
|
|
|
@@ -231,9 +231,15 @@ func GetProductsByCatId(cId, page, perPage, priceSort, saleSort int64, words str
|
|
|
saleSql = "(virtual_sold_count+sale_nums) asc"
|
|
|
}
|
|
|
if len(priceSql) <= 0 && len(saleSql) <= 0 {
|
|
|
- saleSql = "created_at desc"
|
|
|
- priceSql = "recommend desc"
|
|
|
+ orderSql = "recommend desc,created_at desc"
|
|
|
+ } else if len(priceSql) <= 0 {
|
|
|
+ orderSql = saleSql
|
|
|
+ } else if len(saleSql) <= 0 {
|
|
|
+ orderSql = priceSql
|
|
|
+ } else {
|
|
|
+ orderSql = fmt.Sprintf("%s,%s", priceSql, saleSql)
|
|
|
}
|
|
|
+
|
|
|
var cidSql string
|
|
|
if cId != 0 {
|
|
|
cidSql = fmt.Sprintf("and category_id=%d", cId)
|
|
|
@@ -241,9 +247,9 @@ func GetProductsByCatId(cId, page, perPage, priceSort, saleSort int64, words str
|
|
|
sql := `
|
|
|
select * from products
|
|
|
where status = ? and show_flag=? and ptype=? %s
|
|
|
- order by %s,%s limit %d, %d ;
|
|
|
+ order by %s limit %d, %d ;
|
|
|
`
|
|
|
- sql = fmt.Sprintf(sql, cidSql, priceSql, saleSql, (page-1)*perPage, perPage)
|
|
|
+ sql = fmt.Sprintf(sql, cidSql, orderSql, (page-1)*perPage, perPage)
|
|
|
beego.BeeLogger.Warn("cate sql=%s", sql)
|
|
|
_, err := orm.NewOrm().Raw(sql, 1, true, TYPE_DIRECT_SALE).QueryRows(&products)
|
|
|
|