|
|
@@ -127,7 +127,7 @@ type Product struct {
|
|
|
}
|
|
|
|
|
|
//获取最新推荐商品
|
|
|
-func GetLatest(page, perPage, recommend, priceSort, saleSort, saleZone int64, ptype string, useCache bool) (products []*Product) {
|
|
|
+func GetLatest(page, perPage, recommend, priceSort, saleSort, saleZone, depart 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 {
|
|
|
@@ -136,24 +136,24 @@ func GetLatest(page, perPage, recommend, priceSort, saleSort, saleZone int64, pt
|
|
|
}
|
|
|
var saleZoneSql, priceSql, saleSql, orderSql string
|
|
|
if saleZone > int64(0) {
|
|
|
- saleZoneSql = fmt.Sprintf(" and sale_zone=%d", saleZone)
|
|
|
+ saleZoneSql = fmt.Sprintf(" and a.sale_zone=%d", saleZone)
|
|
|
}
|
|
|
if priceSort == int64(1) {
|
|
|
//降序
|
|
|
- priceSql = "price desc"
|
|
|
+ priceSql = "a.price desc"
|
|
|
} else if priceSort == int64(2) {
|
|
|
//升序
|
|
|
- priceSql = "price asc"
|
|
|
+ priceSql = "a.price asc"
|
|
|
}
|
|
|
if saleSort == int64(1) {
|
|
|
//降序
|
|
|
- saleSql = "sale_nums desc"
|
|
|
+ saleSql = "a.sale_nums desc"
|
|
|
} else if priceSort == int64(2) {
|
|
|
- saleSql = "sale_nums asc"
|
|
|
+ saleSql = "a.sale_nums asc"
|
|
|
}
|
|
|
if len(priceSql) <= 0 && len(saleSql) <= 0 {
|
|
|
//orderSql = "recommend desc,created_at desc"
|
|
|
- orderSql = " (virtual_sold_count + sale_nums) desc"
|
|
|
+ orderSql = " (a.virtual_sold_count + a.sale_nums) desc"
|
|
|
} else if len(priceSql) <= 0 {
|
|
|
orderSql = saleSql
|
|
|
} else if len(saleSql) <= 0 {
|
|
|
@@ -162,13 +162,13 @@ func GetLatest(page, perPage, recommend, priceSort, saleSort, saleZone int64, pt
|
|
|
orderSql = fmt.Sprintf("%s,%s", priceSql, saleSql)
|
|
|
}
|
|
|
sql := `
|
|
|
- select * from products
|
|
|
- where status = ? and recommend > ? and show_flag=? and ptype=? %s
|
|
|
+ select a.* from products a left join depart_records_products b on a.id=b.product_id
|
|
|
+ where a.status = ? and a.recommend > ? and a.show_flag=? and a.ptype=? and (b.depart_record_id=? or b.depart_record_id is null ) %s
|
|
|
order by %s limit %d, %d;
|
|
|
`
|
|
|
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)
|
|
|
+ _, err := orm.NewOrm().Raw(sql, 1, recommend, true, ptype, depart).QueryRows(&products)
|
|
|
|
|
|
if err != nil {
|
|
|
beego.BeeLogger.Debug("GetLatest err=%s", err)
|
|
|
@@ -184,6 +184,40 @@ func GetLatest(page, perPage, recommend, priceSort, saleSort, saleZone int64, pt
|
|
|
return products
|
|
|
}
|
|
|
|
|
|
+func GetNewLatestCount(recommend, saleZone, depart int64, ptype string, useCache bool) int64 {
|
|
|
+ k := fmt.Sprintf("product_model.GetNewLatestCount.recommend(%d)(%d)(%d)", recommend, saleZone, depart)
|
|
|
+ if useCache {
|
|
|
+ if ret, ok := cache.Cache.Get(k).(int64); ok {
|
|
|
+ return ret
|
|
|
+ }
|
|
|
+ }
|
|
|
+ type Ret struct {
|
|
|
+ Count int64 `json:"count"` //总数
|
|
|
+ }
|
|
|
+ ret := &Ret{}
|
|
|
+ o := orm.NewOrm()
|
|
|
+ sql := `
|
|
|
+ select count(DISTINCT a.id) from products a left join depart_records_products b on a.id=b.product_id
|
|
|
+ where a.status = ? and a.recommend > ? and a.show_flag=? and a.ptype=? and (b.depart_record_id=? or b.depart_record_id is null ) %s;
|
|
|
+ `
|
|
|
+ var saleZoneSql string
|
|
|
+ if saleZone > int64(0) {
|
|
|
+ saleZoneSql = fmt.Sprintf(" and a.sale_zone=%d", saleZone)
|
|
|
+ }
|
|
|
+ sql = fmt.Sprintf(sql, saleZoneSql)
|
|
|
+
|
|
|
+ err := o.Raw(sql, true, recommend, true, ptype, depart).QueryRow(ret)
|
|
|
+ if err != nil {
|
|
|
+ beego.BeeLogger.Error("GetLatestCount, depart:%d, err=[%s]", depart, err)
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ if ret.Count < 0 {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ cache.Cache.Put(k, ret.Count, 10*time.Minute)
|
|
|
+ return ret.Count
|
|
|
+}
|
|
|
+
|
|
|
func GetLatestCount(recommend, saleZone int64, ptype string, useCache bool) int64 {
|
|
|
k := fmt.Sprintf("product_model.GetLatestCount.recommend(%d)", recommend)
|
|
|
if useCache {
|