|
|
@@ -3,6 +3,8 @@ package product_model
|
|
|
import (
|
|
|
// "time"
|
|
|
|
|
|
+ "fmt"
|
|
|
+ "fohow.com/cache"
|
|
|
"github.com/astaxie/beego"
|
|
|
"github.com/astaxie/beego/orm"
|
|
|
"time"
|
|
|
@@ -31,6 +33,23 @@ func (self *ProductCommend) TableName() string {
|
|
|
return product_commends_tablename
|
|
|
}
|
|
|
|
|
|
+func (self *ProductCommend) Create(wxUId, pId, score int64, detail string) (item *ProductCommend) {
|
|
|
+ item = &ProductCommend{
|
|
|
+ ProductId: pId,
|
|
|
+ WxUserId: wxUId,
|
|
|
+ Detail: detail,
|
|
|
+ Score: score,
|
|
|
+ IsEnable: true,
|
|
|
+ }
|
|
|
+ id, err := orm.NewOrm().Insert(item)
|
|
|
+ if err != nil {
|
|
|
+ beego.BeeLogger.Error("Create ProductCommend err=[%s]", err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ item.Id = id
|
|
|
+ return item
|
|
|
+}
|
|
|
+
|
|
|
func GetProductCommendById(id int64) *ProductCommend {
|
|
|
cat := &ProductCommend{Id: id}
|
|
|
if err := orm.NewOrm().Read(cat); err != nil {
|
|
|
@@ -41,7 +60,13 @@ func GetProductCommendById(id int64) *ProductCommend {
|
|
|
}
|
|
|
|
|
|
//获取商品评论列表
|
|
|
-func GetProductCommends(productId int64, status bool, page, perPage int) (commends []*ProductCommend) {
|
|
|
+func GetProductCommends(productId int64, status, useCache bool, page, perPage int64) (commends []*ProductCommend) {
|
|
|
+ k := fmt.Sprintf("product_model.GetProductCommends(%d).page(%d).perPage(%d)", productId, page, perPage)
|
|
|
+ if useCache {
|
|
|
+ if ret, ok := cache.Cache.Get(k).([]*ProductCommend); ok {
|
|
|
+ return ret
|
|
|
+ }
|
|
|
+ }
|
|
|
commend := new(ProductCommend)
|
|
|
qs := orm.NewOrm().QueryTable(commend)
|
|
|
qs = qs.Filter("product_id", productId).Filter("is_enable", status)
|
|
|
@@ -51,5 +76,25 @@ func GetProductCommends(productId int64, status bool, page, perPage int) (commen
|
|
|
beego.BeeLogger.Debug("get productCommeds[%d] commend list err=[%s]", productId, err)
|
|
|
return nil
|
|
|
}
|
|
|
+ cache.Cache.Put(k, commends, 10*time.Minute)
|
|
|
+
|
|
|
return commends
|
|
|
}
|
|
|
+
|
|
|
+//获取商品评论列表总条数
|
|
|
+func GetProductCommendCountByProductId(productId int64, status, useCache bool) int64 {
|
|
|
+ k := fmt.Sprintf("product_model.GetProductCommendCountByProductId(%d)", productId)
|
|
|
+ if useCache {
|
|
|
+ if ret, ok := cache.Cache.Get(k).(int64); ok {
|
|
|
+ return ret
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item := new(Product)
|
|
|
+ o := orm.NewOrm()
|
|
|
+ qs := o.QueryTable(item)
|
|
|
+
|
|
|
+ count, _ := qs.Filter("is_enable", status).Filter("product_id", productId).Count()
|
|
|
+
|
|
|
+ cache.Cache.Put(k, count, 10*time.Minute)
|
|
|
+ return count
|
|
|
+}
|