|
|
@@ -1,15 +1,6 @@
|
|
|
package product_model
|
|
|
|
|
|
import (
|
|
|
- "fmt"
|
|
|
-
|
|
|
- // "fmt"
|
|
|
- // "time"
|
|
|
- "github.com/astaxie/beego"
|
|
|
-
|
|
|
- // "github.com/astaxie/beego"
|
|
|
- // "github.com/astaxie/beego/orm"
|
|
|
- "github.com/astaxie/beego/orm"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
@@ -19,22 +10,6 @@ const (
|
|
|
product_attr_configs_tablename = "product_attr_configs"
|
|
|
)
|
|
|
|
|
|
-type ProductAttr struct {
|
|
|
- Id int64 `orm:"column(id);pk" json:"id"` // int(11)
|
|
|
- ProductAttrKeyId int64 `orm:"column(product_attr_key_id)" json:"product_attr_key_id"` // int(11)
|
|
|
- Name string `orm:"column(name);null" json:"name"` // varchar(64)
|
|
|
- CustomAttrValuePic string `orm:"column(custom_attr_value_pic);null" json:"custom_attr_value_pic"` // varchar(20)
|
|
|
- Recommend int64 `orm:"column(use_custom);null" json:"use_custom"` // tinyint(1)
|
|
|
- CreatedAt time.Time `orm:"column(created_at);auto_now_add;type(datetime)" json:"-"` // datetime
|
|
|
- UpdatedAt time.Time `orm:"column(updated_at);auto_now;type(datetime)" json:"-"` // datetime
|
|
|
- ProductAttrKey *ProductAttrKey `orm:"-" json:"attr_key"`
|
|
|
- ProductAttrValue *ProductAttrValue `orm:"-" json:"attr_value"`
|
|
|
-}
|
|
|
-
|
|
|
-func (self *ProductAttr) TableName() string {
|
|
|
- return product_attrs_tablename
|
|
|
-}
|
|
|
-
|
|
|
type ProductAttrKey struct {
|
|
|
Id int64 `orm:"column(id);pk" json:"id"` // int(11)
|
|
|
Name string `orm:"column(name)" json:"name"` // varchar(20)
|
|
|
@@ -47,90 +22,33 @@ func (self *ProductAttrKey) TableName() string {
|
|
|
return product_attr_keys_tablename
|
|
|
}
|
|
|
|
|
|
-type ProductAttrValue struct {
|
|
|
- Id int64 `orm:"column(id);pk" json:"id,omitempty"` // int(11)
|
|
|
- ProductAttrKeyId int64 `orm:"column(product_attr_key_id)" json:"product_attr_key_id"` // int(11)
|
|
|
- Name string `orm:"column(name)" json:"name"` // varchar(64)
|
|
|
- Pic string `orm:"column(pic)" json:"pic"` // varchar(255)
|
|
|
- Color string `orm:"column(color)" json:"color"` // varchar(64)
|
|
|
- CreatedBy int64 `orm:"column(created_by);null" json:"created_by"` // int(11)
|
|
|
- Status int64 `orm:"column(status);null" json:"status"` // tinyint(1)
|
|
|
- CreatedAt time.Time `orm:"column(created_at);auto_now_add;type(datetime)" json:"-"` // datetime
|
|
|
- UpdatedAt time.Time `orm:"column(updated_at);auto_now;type(datetime)" json:"-"` // datetime
|
|
|
-}
|
|
|
-
|
|
|
-func (self *ProductAttrValue) TableName() string {
|
|
|
- return product_attr_configs_tablename
|
|
|
-}
|
|
|
-
|
|
|
-// 根据product_attr_configs表Id查找记录
|
|
|
-func GetProductAttrValue(id int64) (v *ProductAttrValue) {
|
|
|
- v = &ProductAttrValue{}
|
|
|
- if err := orm.NewOrm().QueryTable(v).Filter("id", id).Limit(1).
|
|
|
- One(v); err != nil {
|
|
|
- beego.BeeLogger.Error("get product attr value by record_id=%s err=%s", id, err)
|
|
|
- return nil
|
|
|
- }
|
|
|
- return v
|
|
|
-}
|
|
|
-
|
|
|
-// 根据product_attr_keys表Id查找记录
|
|
|
-func GetProductAttrKey(id int64) (k *ProductAttrKey) {
|
|
|
- k = &ProductAttrKey{}
|
|
|
- if err := orm.NewOrm().QueryTable(k).Filter("id", id).Limit(1).
|
|
|
- One(k); err != nil {
|
|
|
- beego.BeeLogger.Error("get product attr key by record_id=%s err=%s", id, err)
|
|
|
- return nil
|
|
|
- }
|
|
|
- return k
|
|
|
-}
|
|
|
-
|
|
|
-// 根据product_attrs表Id查找记录
|
|
|
-func GetProductAttr(id int64) (pa *ProductAttr) {
|
|
|
- pa = &ProductAttr{}
|
|
|
- if err := orm.NewOrm().QueryTable(pa).Filter("id", id).Filter("status", 1).Limit(1).
|
|
|
- One(pa); err != nil {
|
|
|
- beego.BeeLogger.Error("get product attr by record_id=%s err=%s", id, err)
|
|
|
- return nil
|
|
|
- }
|
|
|
- return pa
|
|
|
+type ProductAttr struct {
|
|
|
+ Id int64 `orm:"column(id);pk" json:"id"` // int(11)
|
|
|
+ AttrKeyId int64 `orm:"column(attr_key_id)" json:"attr_key_id"` // int(11)
|
|
|
+ Name string `orm:"column(name);null" json:"name"` // varchar(64)
|
|
|
+ Recommend int64 `orm:"column(use_custom);null" json:"use_custom"` // tinyint(1)
|
|
|
+ CreatedAt time.Time `orm:"column(created_at);auto_now_add;type(datetime)" json:"-"` // datetime
|
|
|
+ UpdatedAt time.Time `orm:"column(updated_at);auto_now;type(datetime)" json:"-"` // datetime
|
|
|
+ ProductAttrKey *ProductAttrKey `orm:"-" json:"attr_key"`
|
|
|
+ ProductAttrValue *ProductAttrValue `orm:"-" json:"attr_value"`
|
|
|
}
|
|
|
|
|
|
-// 根据商品Id和keyId找出商品对应某个属性Key的所有属性记录
|
|
|
-func GetProductAttrsByKeyId(pId, kId int64) (items []*ProductAttr) {
|
|
|
- o := orm.NewOrm()
|
|
|
- item := new(ProductAttr)
|
|
|
- _, err := o.QueryTable(item).Filter("product_attr_key_id", kId).
|
|
|
- Filter("product_id", pId).Filter("status", 1).
|
|
|
- All(&items)
|
|
|
- if err != nil {
|
|
|
- beego.BeeLogger.Error("GetProductAttrs(%d) err=%s", pId, err)
|
|
|
- }
|
|
|
- return items
|
|
|
+func (self *ProductAttr) TableName() string {
|
|
|
+ return product_attrs_tablename
|
|
|
}
|
|
|
|
|
|
-func GetProductGroupAttrs(pId int64) (items []*ProductAttr) {
|
|
|
- var j ProductAttr
|
|
|
- o := orm.NewOrm()
|
|
|
- var sql string
|
|
|
- sql = fmt.Sprintf("SELECT * FROM `%s` WHERE product_id=? and status=1 GROUP BY product_attr_key_id", j.TableName())
|
|
|
- _, err := o.Raw(sql, pId).QueryRows(&items)
|
|
|
- if err != nil {
|
|
|
- beego.BeeLogger.Error("GetProductGroupAttrs pId[%d], err=[%s] ", pId, err)
|
|
|
- return nil
|
|
|
- }
|
|
|
- return items
|
|
|
+type ProductAttrValue struct {
|
|
|
+ Id int64 `orm:"column(id);pk" json:"id,omitempty"` // int(11)
|
|
|
+ AttrKeyId int64 `orm:"column(attr_key_id)" json:"attr_key_id"` // int(11)
|
|
|
+ Name string `orm:"column(name)" json:"name"` // varchar(64)
|
|
|
+ Pic string `orm:"column(pic)" json:"pic"` // varchar(255)
|
|
|
+ Color string `orm:"column(color)" json:"color"` // varchar(64)
|
|
|
+ CreatedBy int64 `orm:"column(created_by);null" json:"created_by"` // int(11)
|
|
|
+ Status int64 `orm:"column(status);null" json:"status"` // tinyint(1)
|
|
|
+ CreatedAt time.Time `orm:"column(created_at);auto_now_add;type(datetime)" json:"-"` // datetime
|
|
|
+ UpdatedAt time.Time `orm:"column(updated_at);auto_now;type(datetime)" json:"-"` // datetime
|
|
|
}
|
|
|
|
|
|
-func GetAttrCustomPic(vId int64, vPic string) string {
|
|
|
- if vPic == "" {
|
|
|
- return fmt.Sprintf("%s/v5/images/logo_32.jpg",
|
|
|
- beego.AppConfig.String("RailsHost"))
|
|
|
- } else {
|
|
|
- return fmt.Sprintf("%s/product_attr_custom_pic/%d/%s",
|
|
|
- beego.AppConfig.String("AliOssImgHost"),
|
|
|
- vId,
|
|
|
- vPic)
|
|
|
- }
|
|
|
-
|
|
|
+func (self *ProductAttrValue) TableName() string {
|
|
|
+ return product_attr_configs_tablename
|
|
|
}
|