|
|
@@ -0,0 +1,55 @@
|
|
|
+package product_model
|
|
|
+
|
|
|
+import (
|
|
|
+ // "time"
|
|
|
+
|
|
|
+ "github.com/astaxie/beego"
|
|
|
+ "github.com/astaxie/beego/orm"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+const (
|
|
|
+ product_commends_tablename = "product_commends"
|
|
|
+)
|
|
|
+
|
|
|
+type ProductCommend struct {
|
|
|
+ Id int64 `orm:"column(id);pk" json:"id"` // int(11)
|
|
|
+ NickName string `orm:"-" json:"nick_name"` // varchar(20)
|
|
|
+ Head string `orm:"-" json:"head"` // varchar(20)
|
|
|
+ WxUserId int64 `orm:"column(wx_user_id);null" json:"-"` // int(11)
|
|
|
+ ProductId int64 `orm:"column(product_id);null" json:"-"` // int(11)
|
|
|
+ Detail string `orm:"column(detail);" json:"detail"` // varchar(20)
|
|
|
+ IsEnable bool `orm:"column(is_enable);null" json:"-"` // tinyint(1)
|
|
|
+ IsTop bool `orm:"column(is_top);null" json:"-"` // tinyint(1)
|
|
|
+ Score int64 `orm:"column(score);null" json:"score"` // int(11)
|
|
|
+ Recommend int64 `orm:"column(recommend);null" json:"-"` // int(11)
|
|
|
+ CreatedAt time.Time `orm:"column(created_at);null;auto_now_add;type(datetime)" json:"-"` // datetime
|
|
|
+ UpdatedAt time.Time `orm:"column(updated_at);null;auto_now;type(datetime)" json:"-"` // datetime
|
|
|
+}
|
|
|
+
|
|
|
+func (self *ProductCommend) TableName() string {
|
|
|
+ return product_commends_tablename
|
|
|
+}
|
|
|
+
|
|
|
+func GetProductCommendById(id int64) *ProductCommend {
|
|
|
+ cat := &ProductCommend{Id: id}
|
|
|
+ if err := orm.NewOrm().Read(cat); err != nil {
|
|
|
+ // beego.BeeLogger.Error("get name product cat by id err=[%s][", err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return cat
|
|
|
+}
|
|
|
+
|
|
|
+//获取商品评论列表
|
|
|
+func GetProductCommends(productId int64, status bool, page, perPage int) (commends []*ProductCommend) {
|
|
|
+ commend := new(ProductCommend)
|
|
|
+ qs := orm.NewOrm().QueryTable(commend)
|
|
|
+ qs = qs.Filter("product_id", productId).Filter("is_enable", status)
|
|
|
+
|
|
|
+ if _, err := qs.OrderBy("-is_top", "-recommend", "-created_at").
|
|
|
+ Limit(perPage, (page-1)*perPage).All(&commends); err != nil {
|
|
|
+ beego.BeeLogger.Debug("get productCommeds[%d] commend list err=[%s]", productId, err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return commends
|
|
|
+}
|