|
@@ -2,6 +2,9 @@ package product_model
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
+ "strconv"
|
|
|
|
|
+ "strings"
|
|
|
|
|
+ "sync/atomic"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/astaxie/beego"
|
|
"github.com/astaxie/beego"
|
|
@@ -43,19 +46,32 @@ const (
|
|
|
|
|
|
|
|
//Employ Sort
|
|
//Employ Sort
|
|
|
ProdutEmploySort = 25
|
|
ProdutEmploySort = 25
|
|
|
|
|
+
|
|
|
|
|
+ LanguageZhCN = "zh-cn"
|
|
|
|
|
+ LanguageEn = "en"
|
|
|
|
|
+ LanguageRu = "ru"
|
|
|
|
|
+ LanguageZhTW = "zh-tw"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+var productCacheVersion int64 = time.Now().UnixNano()
|
|
|
|
|
+
|
|
|
func (self *Product) TableName() string {
|
|
func (self *Product) TableName() string {
|
|
|
return products_tablename
|
|
return products_tablename
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type Product struct {
|
|
type Product struct {
|
|
|
- Id int64 `orm:"column(id);pk" json:"id"` // int(11)
|
|
|
|
|
- Name string `orm:"column(name)" json:"name"` // varchar(100)
|
|
|
|
|
- Ptype string `orm:"column(ptype)" json:"ptype"` // varchar(100)
|
|
|
|
|
- CategoryId int64 `orm:"column(category_id);null" json:"-"` // int(11)
|
|
|
|
|
- Detail string `orm:"column(detail);null" json:"detail"` // text
|
|
|
|
|
- Price int64 `orm:"column(price)" json:"price"` // int(11)
|
|
|
|
|
|
|
+ Id int64 `orm:"column(id);pk" json:"id"` // int(11)
|
|
|
|
|
+ Name string `orm:"column(name)" json:"name"` // varchar(100)
|
|
|
|
|
+ NameEn string `orm:"column(name_en);null" json:"-"`
|
|
|
|
|
+ NameRu string `orm:"column(name_ru);null" json:"-"`
|
|
|
|
|
+ NameTw string `orm:"column(name_tw);null" json:"-"`
|
|
|
|
|
+ Ptype string `orm:"column(ptype)" json:"ptype"` // varchar(100)
|
|
|
|
|
+ CategoryId int64 `orm:"column(category_id);null" json:"-"` // int(11)
|
|
|
|
|
+ Detail string `orm:"column(detail);null" json:"detail"`
|
|
|
|
|
+ DetailEn string `orm:"column(detail_en);null" json:"-"`
|
|
|
|
|
+ DetailRu string `orm:"column(detail_ru);null" json:"-"`
|
|
|
|
|
+ DetailTw string `orm:"column(detail_tw);null" json:"-"`
|
|
|
|
|
+ Price int64 `orm:"column(price)" json:"price"` // int(11)
|
|
|
RoboBalancePrice int64 `orm:"column(robo_balance_price)" json:"robo_balance_price"`
|
|
RoboBalancePrice int64 `orm:"column(robo_balance_price)" json:"robo_balance_price"`
|
|
|
BuyPrice int64 `orm:"column(buy_price)" json:"-"` // int(11)
|
|
BuyPrice int64 `orm:"column(buy_price)" json:"-"` // int(11)
|
|
|
UserSalePrice int64 `orm:"column(user_sale_price)" json:"user_sale_price"` // int(11)
|
|
UserSalePrice int64 `orm:"column(user_sale_price)" json:"user_sale_price"` // int(11)
|
|
@@ -129,17 +145,197 @@ type Product struct {
|
|
|
CanBuy bool `orm:"-" json:"can_buy"` // bool
|
|
CanBuy bool `orm:"-" json:"can_buy"` // bool
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+type OrderProductLite struct {
|
|
|
|
|
+ Id int64 `orm:"column(id)" json:"id"`
|
|
|
|
|
+ Name string `orm:"column(name)" json:"name"`
|
|
|
|
|
+ Cover string `orm:"column(cover)" json:"cover"`
|
|
|
|
|
+ Package bool `orm:"column(package)" json:"package"`
|
|
|
|
|
+ UseQuan bool `orm:"column(use_quan)" json:"use_quan"`
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func productCacheKey(key string) string {
|
|
|
|
|
+ return fmt.Sprintf("product_cache.v(%d).%s", atomic.LoadInt64(&productCacheVersion), key)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func InvalidateProductCache() int64 {
|
|
|
|
|
+ version := time.Now().UnixNano()
|
|
|
|
|
+ atomic.StoreInt64(&productCacheVersion, version)
|
|
|
|
|
+ return version
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func NormalizeLanguage(lang string) string {
|
|
|
|
|
+ switch strings.ToLower(strings.TrimSpace(lang)) {
|
|
|
|
|
+ case "", "zh", "zh-cn", "zh_hans", "zh-hans", "cn":
|
|
|
|
|
+ return LanguageZhCN
|
|
|
|
|
+ case "en", "en-us", "en_us":
|
|
|
|
|
+ return LanguageEn
|
|
|
|
|
+ case "ru", "ru-ru", "ru_ru":
|
|
|
|
|
+ return LanguageRu
|
|
|
|
|
+ case "zh-tw", "zh_tw", "zh-hk", "zh_hk", "tw", "hk", "traditional":
|
|
|
|
|
+ return LanguageZhTW
|
|
|
|
|
+ default:
|
|
|
|
|
+ return LanguageZhCN
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func LocalizedProductNameExpr(tableAlias, lang string) string {
|
|
|
|
|
+ prefix := ""
|
|
|
|
|
+ if strings.TrimSpace(tableAlias) != "" {
|
|
|
|
|
+ prefix = strings.TrimSpace(tableAlias) + "."
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ switch NormalizeLanguage(lang) {
|
|
|
|
|
+ case LanguageEn:
|
|
|
|
|
+ return fmt.Sprintf("COALESCE(NULLIF(TRIM(%sname_en), ''), %sname)", prefix, prefix)
|
|
|
|
|
+ case LanguageRu:
|
|
|
|
|
+ return fmt.Sprintf("COALESCE(NULLIF(TRIM(%sname_ru), ''), %sname)", prefix, prefix)
|
|
|
|
|
+ case LanguageZhTW:
|
|
|
|
|
+ return fmt.Sprintf("COALESCE(NULLIF(TRIM(%sname_tw), ''), %sname)", prefix, prefix)
|
|
|
|
|
+ default:
|
|
|
|
|
+ return prefix + "name"
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func orderProductLiteCacheKey(id int64, lang string) string {
|
|
|
|
|
+ return productCacheKey(fmt.Sprintf("product_model.GetOrderProductLite(%d,%s)", id, NormalizeLanguage(lang)))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func formatInt64List(ids []int64) string {
|
|
|
|
|
+ formatted := make([]string, 0, len(ids))
|
|
|
|
|
+ for _, id := range ids {
|
|
|
|
|
+ formatted = append(formatted, strconv.FormatInt(id, 10))
|
|
|
|
|
+ }
|
|
|
|
|
+ return strings.Join(formatted, ",")
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func uniquePositiveProductIDs(ids []int64) []int64 {
|
|
|
|
|
+ seen := make(map[int64]struct{}, len(ids))
|
|
|
|
|
+ list := make([]int64, 0, len(ids))
|
|
|
|
|
+ for _, id := range ids {
|
|
|
|
|
+ if id <= 0 {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ if _, ok := seen[id]; ok {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ seen[id] = struct{}{}
|
|
|
|
|
+ list = append(list, id)
|
|
|
|
|
+ }
|
|
|
|
|
+ return list
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func GetOrderProductsByIds(ids []int64, lang string, useCache bool) map[int64]*OrderProductLite {
|
|
|
|
|
+ ret := make(map[int64]*OrderProductLite)
|
|
|
|
|
+ ids = uniquePositiveProductIDs(ids)
|
|
|
|
|
+ if len(ids) == 0 {
|
|
|
|
|
+ return ret
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ normalizedLang := NormalizeLanguage(lang)
|
|
|
|
|
+ missing := make([]int64, 0, len(ids))
|
|
|
|
|
+ for _, id := range ids {
|
|
|
|
|
+ if useCache {
|
|
|
|
|
+ if cached, ok := cache.Cache.Get(orderProductLiteCacheKey(id, normalizedLang)).(*OrderProductLite); ok && cached != nil {
|
|
|
|
|
+ ret[id] = cached
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ missing = append(missing, id)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if len(missing) == 0 {
|
|
|
|
|
+ return ret
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ nameExpr := LocalizedProductNameExpr("p", normalizedLang)
|
|
|
|
|
+ sql := fmt.Sprintf(`
|
|
|
|
|
+ SELECT
|
|
|
|
|
+ p.id,
|
|
|
|
|
+ %s AS name,
|
|
|
|
|
+ p.package,
|
|
|
|
|
+ p.use_quan,
|
|
|
|
|
+ IFNULL((
|
|
|
|
|
+ SELECT img
|
|
|
|
|
+ FROM product_pictures pp
|
|
|
|
|
+ WHERE pp.product_id = p.id AND pp.pic_type = %d
|
|
|
|
|
+ ORDER BY pp.sort DESC
|
|
|
|
|
+ LIMIT 1
|
|
|
|
|
+ ), '') AS cover
|
|
|
|
|
+ FROM
|
|
|
|
|
+ products p
|
|
|
|
|
+ WHERE
|
|
|
|
|
+ p.id IN (%s)
|
|
|
|
|
+ `, nameExpr, PIC_TYPE_ALBUM, formatInt64List(missing))
|
|
|
|
|
+
|
|
|
|
|
+ var list []*OrderProductLite
|
|
|
|
|
+ if _, err := orm.NewOrm().Raw(sql).QueryRows(&list); err != nil {
|
|
|
|
|
+ beego.BeeLogger.Warn("product_model.GetOrderProductsByIds(%d,%s) err=%s", len(missing), normalizedLang, err)
|
|
|
|
|
+ return ret
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for _, item := range list {
|
|
|
|
|
+ item.Cover = GetCdnFullImgUrl(item.Cover)
|
|
|
|
|
+ ret[item.Id] = item
|
|
|
|
|
+ if useCache {
|
|
|
|
|
+ cache.Cache.Put(orderProductLiteCacheKey(item.Id, normalizedLang), item, 5*time.Minute)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return ret
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (self *Product) Clone() *Product {
|
|
|
|
|
+ if self == nil {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+ item := *self
|
|
|
|
|
+ return &item
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (self *Product) ApplyLanguage(lang string) {
|
|
|
|
|
+ if self == nil {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ switch NormalizeLanguage(lang) {
|
|
|
|
|
+ case LanguageEn:
|
|
|
|
|
+ if strings.TrimSpace(self.NameEn) != "" {
|
|
|
|
|
+ self.Name = self.NameEn
|
|
|
|
|
+ }
|
|
|
|
|
+ if strings.TrimSpace(self.DetailEn) != "" {
|
|
|
|
|
+ self.Detail = self.DetailEn
|
|
|
|
|
+ }
|
|
|
|
|
+ case LanguageRu:
|
|
|
|
|
+ if strings.TrimSpace(self.NameRu) != "" {
|
|
|
|
|
+ self.Name = self.NameRu
|
|
|
|
|
+ }
|
|
|
|
|
+ if strings.TrimSpace(self.DetailRu) != "" {
|
|
|
|
|
+ self.Detail = self.DetailRu
|
|
|
|
|
+ }
|
|
|
|
|
+ case LanguageZhTW:
|
|
|
|
|
+ if strings.TrimSpace(self.NameTw) != "" {
|
|
|
|
|
+ self.Name = self.NameTw
|
|
|
|
|
+ }
|
|
|
|
|
+ if strings.TrimSpace(self.DetailTw) != "" {
|
|
|
|
|
+ self.Detail = self.DetailTw
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// 获取最新推荐商品
|
|
// 获取最新推荐商品
|
|
|
-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)
|
|
|
|
|
|
|
+func GetLatest(page, perPage, recommend, priceSort, saleSort, saleZone, depart int64, ptype string, onlyApp bool, useCache bool) (products []*Product) {
|
|
|
|
|
+ k := productCacheKey(fmt.Sprintf("product_model.GetLatest.page(%d).perPage(%d).recommend(%d).priceSort(%d).saleSort(%d).saleZone(%d).depart(%d).ptype(%s).onlyApp(%t)", page, perPage, recommend, priceSort, saleSort, saleZone, depart, ptype, onlyApp))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if ret, ok := cache.Cache.Get(k).([]*Product); ok {
|
|
if ret, ok := cache.Cache.Get(k).([]*Product); ok {
|
|
|
return ret
|
|
return ret
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- var saleZoneSql, priceSql, saleSql, orderSql string
|
|
|
|
|
|
|
+ var extraSql, priceSql, saleSql, orderSql string
|
|
|
if saleZone > int64(0) {
|
|
if saleZone > int64(0) {
|
|
|
- saleZoneSql = fmt.Sprintf(" and a.sale_zone=%d", saleZone)
|
|
|
|
|
|
|
+ extraSql += fmt.Sprintf(" and a.sale_zone=%d", saleZone)
|
|
|
|
|
+ }
|
|
|
|
|
+ if onlyApp {
|
|
|
|
|
+ extraSql += " and a.allow_app=1"
|
|
|
}
|
|
}
|
|
|
if priceSort == int64(1) {
|
|
if priceSort == int64(1) {
|
|
|
//降序
|
|
//降序
|
|
@@ -169,7 +365,7 @@ func GetLatest(page, perPage, recommend, priceSort, saleSort, saleZone, depart i
|
|
|
where a.status = ? and a.recommend > ? and a.show_flag=? and a.ptype=? and a.category_id!=? and (b.depart_record_id=? or b.depart_record_id is null ) %s
|
|
where a.status = ? and a.recommend > ? and a.show_flag=? and a.ptype=? and a.category_id!=? and (b.depart_record_id=? or b.depart_record_id is null ) %s
|
|
|
order by %s limit %d, %d;
|
|
order by %s limit %d, %d;
|
|
|
`
|
|
`
|
|
|
- sql = fmt.Sprintf(sql, saleZoneSql, orderSql, (page-1)*perPage, perPage)
|
|
|
|
|
|
|
+ sql = fmt.Sprintf(sql, extraSql, orderSql, (page-1)*perPage, perPage)
|
|
|
//beego.BeeLogger.Warn("sql=%s", sql)
|
|
//beego.BeeLogger.Warn("sql=%s", sql)
|
|
|
_, err := orm.NewOrm().Raw(sql, 1, recommend, true, ptype, ProdutEmploySort, depart).QueryRows(&products)
|
|
_, err := orm.NewOrm().Raw(sql, 1, recommend, true, ptype, ProdutEmploySort, depart).QueryRows(&products)
|
|
|
|
|
|
|
@@ -187,8 +383,8 @@ func GetLatest(page, perPage, recommend, priceSort, saleSort, saleZone, depart i
|
|
|
return products
|
|
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)
|
|
|
|
|
|
|
+func GetNewLatestCount(recommend, saleZone, depart int64, ptype string, onlyApp bool, useCache bool) int64 {
|
|
|
|
|
+ k := productCacheKey(fmt.Sprintf("product_model.GetNewLatestCount.recommend(%d).saleZone(%d).depart(%d).ptype(%s).onlyApp(%t)", recommend, saleZone, depart, ptype, onlyApp))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if ret, ok := cache.Cache.Get(k).(int64); ok {
|
|
if ret, ok := cache.Cache.Get(k).(int64); ok {
|
|
|
return ret
|
|
return ret
|
|
@@ -203,11 +399,14 @@ func GetNewLatestCount(recommend, saleZone, depart int64, ptype string, useCache
|
|
|
select count(DISTINCT a.id) as count from products a left join depart_records_products b on a.id=b.product_id
|
|
select count(DISTINCT a.id) as count 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;
|
|
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
|
|
|
|
|
|
|
+ var extraSql string
|
|
|
if saleZone > int64(0) {
|
|
if saleZone > int64(0) {
|
|
|
- saleZoneSql = fmt.Sprintf(" and a.sale_zone=%d", saleZone)
|
|
|
|
|
|
|
+ extraSql += fmt.Sprintf(" and a.sale_zone=%d", saleZone)
|
|
|
}
|
|
}
|
|
|
- sql = fmt.Sprintf(sql, saleZoneSql)
|
|
|
|
|
|
|
+ if onlyApp {
|
|
|
|
|
+ extraSql += " and a.allow_app=1"
|
|
|
|
|
+ }
|
|
|
|
|
+ sql = fmt.Sprintf(sql, extraSql)
|
|
|
|
|
|
|
|
err := o.Raw(sql, true, recommend, true, ptype, depart).QueryRow(ret)
|
|
err := o.Raw(sql, true, recommend, true, ptype, depart).QueryRow(ret)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -222,7 +421,7 @@ func GetNewLatestCount(recommend, saleZone, depart int64, ptype string, useCache
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func GetLatestCount(recommend, saleZone int64, ptype string, useCache bool) int64 {
|
|
func GetLatestCount(recommend, saleZone int64, ptype string, useCache bool) int64 {
|
|
|
- k := fmt.Sprintf("product_model.GetLatestCount.recommend(%d)", recommend)
|
|
|
|
|
|
|
+ k := productCacheKey(fmt.Sprintf("product_model.GetLatestCount.recommend(%d)", recommend))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if ret, ok := cache.Cache.Get(k).(int64); ok {
|
|
if ret, ok := cache.Cache.Get(k).(int64); ok {
|
|
|
return ret
|
|
return ret
|
|
@@ -243,7 +442,7 @@ func GetLatestCount(recommend, saleZone int64, ptype string, useCache bool) int6
|
|
|
// 根据商品Id,获取商品信息
|
|
// 根据商品Id,获取商品信息
|
|
|
func GetProductById(id int64, useCache bool) *Product {
|
|
func GetProductById(id int64, useCache bool) *Product {
|
|
|
//k := fmt.Sprintf("product_model.GetProductById[%d]", id)
|
|
//k := fmt.Sprintf("product_model.GetProductById[%d]", id)
|
|
|
- k := cache.GetKey(cache.GetProductByPId, id)
|
|
|
|
|
|
|
+ k := productCacheKey(cache.GetKey(cache.GetProductByPId, id))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if v, ok := cache.Cache.Get(k).(*Product); ok {
|
|
if v, ok := cache.Cache.Get(k).(*Product); ok {
|
|
|
return v
|
|
return v
|
|
@@ -262,7 +461,7 @@ func GetProductById(id int64, useCache bool) *Product {
|
|
|
// 判断商品是否在当前省可发货
|
|
// 判断商品是否在当前省可发货
|
|
|
func GetProductByIdAndProvince(id int64, province string, useCache bool) *Product {
|
|
func GetProductByIdAndProvince(id int64, province string, useCache bool) *Product {
|
|
|
//k := fmt.Sprintf("product_model.GetProductById[%d]", id)
|
|
//k := fmt.Sprintf("product_model.GetProductById[%d]", id)
|
|
|
- k := cache.GetKey(cache.GetProductByPIdAndProvince, id, province)
|
|
|
|
|
|
|
+ k := productCacheKey(cache.GetKey(cache.GetProductByPIdAndProvince, id, province))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if v, ok := cache.Cache.Get(k).(*Product); ok {
|
|
if v, ok := cache.Cache.Get(k).(*Product); ok {
|
|
|
return v
|
|
return v
|
|
@@ -286,7 +485,7 @@ func GetProductByIdAndProvince(id int64, province string, useCache bool) *Produc
|
|
|
// 判断商品是否在当前省受限
|
|
// 判断商品是否在当前省受限
|
|
|
func GetNoDeliveryPrd(id int64, province string, useCache bool) *Product {
|
|
func GetNoDeliveryPrd(id int64, province string, useCache bool) *Product {
|
|
|
//k := fmt.Sprintf("product_model.GetProductById[%d]", id)
|
|
//k := fmt.Sprintf("product_model.GetProductById[%d]", id)
|
|
|
- k := cache.GetKey(cache.GetNoDeliveryPrd, id, province)
|
|
|
|
|
|
|
+ k := productCacheKey(cache.GetKey(cache.GetNoDeliveryPrd, id, province))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if v, ok := cache.Cache.Get(k).(*Product); ok {
|
|
if v, ok := cache.Cache.Get(k).(*Product); ok {
|
|
|
return v
|
|
return v
|
|
@@ -308,7 +507,7 @@ func GetNoDeliveryPrd(id int64, province string, useCache bool) *Product {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func GetProductsByCatId(cId, saleZone, page, perPage, priceSort, saleSort int64, words string, useCache bool) (products []*Product) {
|
|
func GetProductsByCatId(cId, saleZone, page, perPage, priceSort, saleSort int64, words string, useCache bool) (products []*Product) {
|
|
|
- k := fmt.Sprintf("product_model.GetProductsByCatId(%d).page(%d).perPage(%d).words(%d)", cId, page, perPage, words)
|
|
|
|
|
|
|
+ k := productCacheKey(fmt.Sprintf("product_model.GetProductsByCatId(%d).page(%d).perPage(%d).words(%s)", cId, page, perPage, words))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if ret, ok := cache.Cache.Get(k).([]*Product); ok {
|
|
if ret, ok := cache.Cache.Get(k).([]*Product); ok {
|
|
|
return ret
|
|
return ret
|
|
@@ -371,7 +570,7 @@ func GetProductsByCatId(cId, saleZone, page, perPage, priceSort, saleSort int64,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func GetProductCountByCatId(cId, saleZone int64, words string, useCache bool) int64 {
|
|
func GetProductCountByCatId(cId, saleZone int64, words string, useCache bool) int64 {
|
|
|
- k := fmt.Sprintf("product_model.GetProductCountByCatId(%d)", cId)
|
|
|
|
|
|
|
+ k := productCacheKey(fmt.Sprintf("product_model.GetProductCountByCatId(%d).saleZone(%d).words(%s)", cId, saleZone, words))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if ret, ok := cache.Cache.Get(k).(int64); ok {
|
|
if ret, ok := cache.Cache.Get(k).(int64); ok {
|
|
|
return ret
|
|
return ret
|
|
@@ -398,7 +597,7 @@ func GetProductCountByCatId(cId, saleZone int64, words string, useCache bool) in
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func GetSeckillProducts(queryDate time.Time, useCache bool) (list []*Product) {
|
|
func GetSeckillProducts(queryDate time.Time, useCache bool) (list []*Product) {
|
|
|
- k := fmt.Sprintf("product_model.GetSeckillProducts(%s)", queryDate.Format("2006-01-02"))
|
|
|
|
|
|
|
+ k := productCacheKey(fmt.Sprintf("product_model.GetSeckillProducts(%s)", queryDate.Format("2006-01-02")))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if ret, ok := cache.Cache.Get(k).([]*Product); ok {
|
|
if ret, ok := cache.Cache.Get(k).([]*Product); ok {
|
|
|
return ret
|
|
return ret
|
|
@@ -425,7 +624,7 @@ func GetSeckillProducts(queryDate time.Time, useCache bool) (list []*Product) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func GetSeckillDates(startDate, endDate time.Time, useCache bool) (list []string) {
|
|
func GetSeckillDates(startDate, endDate time.Time, useCache bool) (list []string) {
|
|
|
- k := fmt.Sprintf("product_model.GetSeckillDates(%s, %s)", startDate.Format("2006-01-02"), endDate.Format("2006-01-02"))
|
|
|
|
|
|
|
+ k := productCacheKey(fmt.Sprintf("product_model.GetSeckillDates(%s, %s)", startDate.Format("2006-01-02"), endDate.Format("2006-01-02")))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if ret, ok := cache.Cache.Get(k).([]string); ok {
|
|
if ret, ok := cache.Cache.Get(k).([]string); ok {
|
|
|
return ret
|
|
return ret
|
|
@@ -456,7 +655,7 @@ type OnOffSeckillTime struct {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func GetSeckillOnOffSeckillTimeByDate(queryDate string, useCache bool) *OnOffSeckillTime {
|
|
func GetSeckillOnOffSeckillTimeByDate(queryDate string, useCache bool) *OnOffSeckillTime {
|
|
|
- k := fmt.Sprintf("product_model.GetSeckillOnOffSaleTimeByDate(%s)", queryDate)
|
|
|
|
|
|
|
+ k := productCacheKey(fmt.Sprintf("product_model.GetSeckillOnOffSaleTimeByDate(%s)", queryDate))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if ret, ok := cache.Cache.Get(k).(*OnOffSeckillTime); ok {
|
|
if ret, ok := cache.Cache.Get(k).(*OnOffSeckillTime); ok {
|
|
|
return ret
|
|
return ret
|
|
@@ -494,7 +693,7 @@ func (self *Product) Save() error {
|
|
|
|
|
|
|
|
// 根据关联商品Id,sizeId,colorId,获取商品信息
|
|
// 根据关联商品Id,sizeId,colorId,获取商品信息
|
|
|
func GetProductByIdAndSizeAndColor(id, sizeId, colorId int64, useCache bool) *Product {
|
|
func GetProductByIdAndSizeAndColor(id, sizeId, colorId int64, useCache bool) *Product {
|
|
|
- k := fmt.Sprintf("product_model.GetProductByIdAndSizeAndColor[%d]", id)
|
|
|
|
|
|
|
+ k := productCacheKey(fmt.Sprintf("product_model.GetProductByIdAndSizeAndColor[%d][%d][%d]", id, sizeId, colorId))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if v, ok := cache.Cache.Get(k).(*Product); ok {
|
|
if v, ok := cache.Cache.Get(k).(*Product); ok {
|
|
|
return v
|
|
return v
|
|
@@ -512,7 +711,7 @@ func GetProductByIdAndSizeAndColor(id, sizeId, colorId int64, useCache bool) *Pr
|
|
|
|
|
|
|
|
// 根据商品 relate_Id 跟 sizeId,获取商品信息
|
|
// 根据商品 relate_Id 跟 sizeId,获取商品信息
|
|
|
func GetProductByIdAndSizeId(relateId, sizeId int64, useCache bool) *Product {
|
|
func GetProductByIdAndSizeId(relateId, sizeId int64, useCache bool) *Product {
|
|
|
- k := fmt.Sprintf("product_model.GetProductByRelateId[%d]SizeId[%d]", relateId, sizeId)
|
|
|
|
|
|
|
+ k := productCacheKey(fmt.Sprintf("product_model.GetProductByRelateId[%d]SizeId[%d]", relateId, sizeId))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if v, ok := cache.Cache.Get(k).(*Product); ok {
|
|
if v, ok := cache.Cache.Get(k).(*Product); ok {
|
|
|
return v
|
|
return v
|
|
@@ -531,7 +730,7 @@ func GetProductByIdAndSizeId(relateId, sizeId int64, useCache bool) *Product {
|
|
|
|
|
|
|
|
// 根据商品 relate_Id 跟 colorId,获取商品信息
|
|
// 根据商品 relate_Id 跟 colorId,获取商品信息
|
|
|
func GetProductByIdAndColorId(relateId, colorId int64, useCache bool) *Product {
|
|
func GetProductByIdAndColorId(relateId, colorId int64, useCache bool) *Product {
|
|
|
- k := fmt.Sprintf("product_model.GetProductByRelateId[%d]ColorId[%d]", relateId, colorId)
|
|
|
|
|
|
|
+ k := productCacheKey(fmt.Sprintf("product_model.GetProductByRelateId[%d]ColorId[%d]", relateId, colorId))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if v, ok := cache.Cache.Get(k).(*Product); ok {
|
|
if v, ok := cache.Cache.Get(k).(*Product); ok {
|
|
|
return v
|
|
return v
|
|
@@ -553,7 +752,7 @@ func GetProductCountByRelateId(relateId int64, useCache bool) int64 {
|
|
|
Count int64
|
|
Count int64
|
|
|
}
|
|
}
|
|
|
ret := &Ret{}
|
|
ret := &Ret{}
|
|
|
- k := fmt.Sprintf("product_model.GetProductCountByRelateId(%d)", relateId)
|
|
|
|
|
|
|
+ k := productCacheKey(fmt.Sprintf("product_model.GetProductCountByRelateId(%d)", relateId))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if ret, ok := cache.Cache.Get(k).(int64); ok {
|
|
if ret, ok := cache.Cache.Get(k).(int64); ok {
|
|
|
return ret
|
|
return ret
|
|
@@ -573,7 +772,7 @@ func GetProductCountByRelateId(relateId int64, useCache bool) int64 {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func DepartGetProductsByCatId(cId, saleZone, page, perPage, priceSort, saleSort, depart int64, words string, useCache bool) (products []*Product) {
|
|
func DepartGetProductsByCatId(cId, saleZone, page, perPage, priceSort, saleSort, depart int64, words string, useCache bool) (products []*Product) {
|
|
|
- k := fmt.Sprintf("product_model.GetProductsByCatId(%d).page(%d).perPage(%d).words(%d)", cId, page, perPage, words)
|
|
|
|
|
|
|
+ k := productCacheKey(fmt.Sprintf("product_model.DepartGetProductsByCatId(%d).saleZone(%d).page(%d).perPage(%d).priceSort(%d).saleSort(%d).depart(%d).words(%s)", cId, saleZone, page, perPage, priceSort, saleSort, depart, words))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if ret, ok := cache.Cache.Get(k).([]*Product); ok {
|
|
if ret, ok := cache.Cache.Get(k).([]*Product); ok {
|
|
|
return ret
|
|
return ret
|
|
@@ -637,7 +836,7 @@ func DepartGetProductsByCatId(cId, saleZone, page, perPage, priceSort, saleSort,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func DepartGetProductCountByCatId(cId, saleZone, depart int64, words string, useCache bool) int64 {
|
|
func DepartGetProductCountByCatId(cId, saleZone, depart int64, words string, useCache bool) int64 {
|
|
|
- k := fmt.Sprintf("product_model.DepartGetProductCountByCatId(%d)saleZone(%d)depart(%d)", cId, saleZone, depart)
|
|
|
|
|
|
|
+ k := productCacheKey(fmt.Sprintf("product_model.DepartGetProductCountByCatId(%d).saleZone(%d).depart(%d).words(%s)", cId, saleZone, depart, words))
|
|
|
if useCache {
|
|
if useCache {
|
|
|
if ret, ok := cache.Cache.Get(k).(int64); ok {
|
|
if ret, ok := cache.Cache.Get(k).(int64); ok {
|
|
|
return ret
|
|
return ret
|