spu分离

parent a6cb873a
...@@ -13,5 +13,14 @@ max_idle = 2000 ...@@ -13,5 +13,14 @@ max_idle = 2000
max_active = 5000 max_active = 5000
idle_timeout = 20 idle_timeout = 20
;新spu redis
[default_redis_spu]
host = 192.168.1.234:6379
password = icDb29mLy2s
max_idle = 2000
max_active = 5000
idle_timeout = 20
;存放redis所有键 ;存放redis所有键
[redis_all] [redis_all]
\ No newline at end of file
...@@ -16,6 +16,8 @@ func BuildRedisConfigs() (RedisDatabaseMap map[string]RedisDatabase) { ...@@ -16,6 +16,8 @@ func BuildRedisConfigs() (RedisDatabaseMap map[string]RedisDatabase) {
redisReadMaxActive,_ := Get("default_redis_read.max_active").Int() redisReadMaxActive,_ := Get("default_redis_read.max_active").Int()
redisWriteMaxIdle,_ := Get("default_redis_write.max_idle").Int() redisWriteMaxIdle,_ := Get("default_redis_write.max_idle").Int()
redisWriteMaxActive,_ := Get("default_redis_write.max_active").Int() redisWriteMaxActive,_ := Get("default_redis_write.max_active").Int()
redisSpuMaxIdle,_ := Get("default_redis_spu.max_idle").Int()
redisSpuMaxActive,_ := Get("default_redis_spu.max_active").Int()
return map[string]RedisDatabase{ return map[string]RedisDatabase{
"search_r": { "search_r": {
Host: Get("default_redis_read.host").String(), Host: Get("default_redis_read.host").String(),
...@@ -35,5 +37,11 @@ func BuildRedisConfigs() (RedisDatabaseMap map[string]RedisDatabase) { ...@@ -35,5 +37,11 @@ func BuildRedisConfigs() (RedisDatabaseMap map[string]RedisDatabase) {
MaxIdle: redisWriteMaxIdle, MaxIdle: redisWriteMaxIdle,
MaxActive: redisWriteMaxActive, MaxActive: redisWriteMaxActive,
}, },
"spu": {
Host: Get("default_redis_spu.host").String(),
Password: Get("default_redis_spu.password").String(),
MaxIdle: redisSpuMaxIdle,
MaxActive: redisSpuMaxActive,
},
} }
} }
...@@ -32,8 +32,10 @@ type Power struct { ...@@ -32,8 +32,10 @@ type Power struct {
*/ */
func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan sync.Map) { func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan sync.Map) {
redisConn := gredis.Conn("search_r") redisConn := gredis.Conn("search_r")
redisConnSpu := gredis.Conn("spu")
defer func() { defer func() {
redisConn.Close() redisConn.Close()
redisConnSpu.Close()
}() }()
fast := ctx.Request.FormValue("power[fast]") fast := ctx.Request.FormValue("power[fast]")
//是否展示属性 //是否展示属性
...@@ -59,7 +61,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -59,7 +61,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
//读取包装字段的缓存 //读取包装字段的缓存
if sku.SupplierId == 7 || sku.SupplierId == 13 { if sku.SupplierId == 7 || sku.SupplierId == 13 {
//sku_raw_map哪里写入(成意写的) //sku_raw_map哪里写入(成意写的)
packing, _ := redis.String(redisConn.Do("HGET", "sku_raw_map", goodsId)) packing, _ := redis.String(redisConnSpu.Do("HGET", "sku_raw_map", goodsId))
sku.Packing = gjson.Get(packing, "pack").String() sku.Packing = gjson.Get(packing, "pack").String()
} }
sku = ls.GetGoodsImages(sku, spu) sku = ls.GetGoodsImages(sku, spu)
......
...@@ -16,6 +16,6 @@ func (ss *SpuService) getSpuList(skuArr map[string]string) (spuList map[string]s ...@@ -16,6 +16,6 @@ func (ss *SpuService) getSpuList(skuArr map[string]string) (spuList map[string]s
spuIds = append(spuIds, spuId) spuIds = append(spuIds, spuId)
} }
//批量获取spu详情 //批量获取spu详情
spuList = gredis.Hmget("default_r", "spu", spuIds) spuList = gredis.Hmget("spu", "spu", spuIds)
return return
} }
...@@ -34,9 +34,11 @@ type ZiyingService struct { ...@@ -34,9 +34,11 @@ type ZiyingService struct {
*/ */
func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan sync.Map) { func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan sync.Map) {
redisConn := gredis.Conn("search_r") redisConn := gredis.Conn("search_r")
redisConnSpu := gredis.Conn("spu")
defer func() { defer func() {
//wg.Done(); //wg.Done();
redisConn.Close() redisConn.Close()
redisConnSpu.Close()
}() }()
skuArr := gredis.Hmget("search_r", "Self_SelfGoods", goodsIds) //批量获取商品详情 skuArr := gredis.Hmget("search_r", "Self_SelfGoods", goodsIds) //批量获取商品详情
...@@ -108,7 +110,7 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context, goodsIds []string, ch c ...@@ -108,7 +110,7 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context, goodsIds []string, ch c
var brandId int64 var brandId int64
var brandName string var brandName string
if spuId != 0 { if spuId != 0 {
spuStr, _ := gredis.String(redisConn.Do("HGET", "spu", spuId)) spuStr, _ := gredis.String(redisConnSpu.Do("HGET", "spu", spuId))
brandId = gjson.Get(spuStr, "brand_id").Int() brandId = gjson.Get(spuStr, "brand_id").Int()
brandName, _ = gredis.String(redisConn.Do("HGET", "brand", brandId)) brandName, _ = gredis.String(redisConn.Do("HGET", "brand", brandId))
var ly LyService var ly LyService
......
package service package service
import ( import (
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/common" "go_sku_server/pkg/common"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/iancoleman/orderedmap" "github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
//自营公共函数类 //自营公共函数类
/* /*
计算单个sku总锁库数量 计算单个sku总锁库数量
*/ */
func (qs *ZiyingService) skuLockNum(c *redis.Conn, goodsId string) int64 { func (qs *ZiyingService) skuLockNum(c *redis.Conn, goodsId string) int64 {
reply, err := redis.Values((*c).Do("hvals", "Self_StockLock"+goodsId)) reply, err := redis.Values((*c).Do("hvals", "Self_StockLock"+goodsId))
if err != nil { if err != nil {
return 0 return 0
} }
var albums []int64 var albums []int64
if err := redis.ScanSlice(reply, &albums); err != nil { if err := redis.ScanSlice(reply, &albums); err != nil {
return 0 return 0
} }
if len(albums) == 0 { if len(albums) == 0 {
return 0 return 0
} else { } else {
var all int64 = 0 var all int64 = 0
for _, n := range albums { for _, n := range albums {
all = all + n all = all + n
} }
return all return all
} }
} }
/* /*
获取自营活动价 获取自营活动价
*/ */
func (qs *ZiyingService) ActivityPrice(ctx *gin.Context, SkuInfo string) *orderedmap.OrderedMap { func (qs *ZiyingService) ActivityPrice(ctx *gin.Context, SkuInfo string) *orderedmap.OrderedMap {
data := qs.HDActivityPrice(SkuInfo) data := qs.HDActivityPrice(SkuInfo)
if data != nil { if data != nil {
return data return data
} }
return nil return nil
} }
//获取活动相关信息 //获取活动相关信息
func (qs *ZiyingService) GetActivity(skuInfo string) (priceActivity model.PriceActivity, giftActivity model.GiftActivity) { func (qs *ZiyingService) GetActivity(skuInfo string) (priceActivity model.PriceActivity, giftActivity model.GiftActivity) {
//去判断是否有活动(促销打折活动和满赠活动) //去判断是否有活动(促销打折活动和满赠活动)
var standardBrandId int var standardBrandId int
spuId := gjson.Get(skuInfo, "spu_id").String() spuId := gjson.Get(skuInfo, "spu_id").String()
redisCon := gredis.Conn("default_r") redisCon := gredis.Conn("default_r")
spuStr, _ := redis.String(redisCon.Do("HGET", "spu", spuId)) redisConSpu := gredis.Conn("spu")
defer redisCon.Close() spuStr, _ := redis.String(redisConSpu.Do("HGET", "spu", spuId))
if spuStr == "" { defer func() {
standardBrandId = 0 redisCon.Close()
} else { redisConSpu.Close()
brandId := gjson.Get(spuStr, "brand_id").Int() }()
standardBrandId, _ = redis.Int(redisCon.Do("HGET", "standard_brand_mapping", brandId)) if spuStr == "" {
} standardBrandId = 0
checkData := model.ActivityCheckData{ } else {
SupplierId: 10000, brandId := gjson.Get(spuStr, "brand_id").Int()
BrandId: int(gjson.Get(skuInfo, "brand_id").Int()), standardBrandId, _ = redis.Int(redisCon.Do("HGET", "standard_brand_mapping", brandId))
StandardBrandId: standardBrandId, }
GoodsId: gjson.Get(skuInfo, "goods_id").String(), checkData := model.ActivityCheckData{
ClassId: int(gjson.Get(skuInfo, "class_id2").Int()), SupplierId: 10000,
} BrandId: int(gjson.Get(skuInfo, "brand_id").Int()),
var activityService ActivityService StandardBrandId: standardBrandId,
priceActivity, giftActivity = activityService.GetActivityData(checkData) GoodsId: gjson.Get(skuInfo, "goods_id").String(),
return ClassId: int(gjson.Get(skuInfo, "class_id2").Int()),
} }
var activityService ActivityService
/* priceActivity, giftActivity = activityService.GetActivityData(checkData)
计算活动价 return
}
ac_type说明: 0 没有活动
活动名称 ac_type 类型 /*
自营系数 6 自营 计算活动价
折扣(系数)活动 10 自营/联营
ac_type说明: 0 没有活动
*/ 活动名称 ac_type 类型
func (qs *ZiyingService) HDActivityPrice(SkuInfo string) *orderedmap.OrderedMap { 自营系数 6 自营
priceActivity, giftActivity := qs.GetActivity(SkuInfo) 折扣(系数)活动 10 自营/联营
ladderPriceArr := gjson.Get(SkuInfo, "ladder_price").Array()
A := orderedmap.New() */
//先去判断价格活动 func (qs *ZiyingService) HDActivityPrice(SkuInfo string) *orderedmap.OrderedMap {
if priceActivity.HasActivity && len(ladderPriceArr) > 0 { priceActivity, giftActivity := qs.GetActivity(SkuInfo)
ratio := priceActivity.Ratio ladderPriceArr := gjson.Get(SkuInfo, "ladder_price").Array()
ladderType := make([]model.LadderPrice, 0) A := orderedmap.New()
for _, v := range ladderPriceArr { //先去判断价格活动
priceCn := v.Get("price_cn").Float() if priceActivity.HasActivity && len(ladderPriceArr) > 0 {
priceAc := php2go.Round(priceCn*ratio/100*10000) / 10000 ratio := priceActivity.Ratio
ladderType = append(ladderType, model.LadderPrice{ ladderType := make([]model.LadderPrice, 0)
Purchases: v.Get("purchases").Int(), for _, v := range ladderPriceArr {
PriceUs: v.Get("price_us").Float(), priceCn := v.Get("price_cn").Float()
PriceCn: priceCn, priceAc := php2go.Round(priceCn*ratio/100*10000) / 10000
PriceAc: priceAc, ladderType = append(ladderType, model.LadderPrice{
}) Purchases: v.Get("purchases").Int(),
} PriceUs: v.Get("price_us").Float(),
PriceCn: priceCn,
A.Set("activity_info", priceActivity) PriceAc: priceAc,
})
A.Set("ladder_price", ladderType) }
A.Set("ratio", ratio)
A.Set("ac_type", 10) A.Set("activity_info", priceActivity)
}
A.Set("ladder_price", ladderType)
//再去判断满赠活动 A.Set("ratio", ratio)
if giftActivity.HasActivity { A.Set("ac_type", 10)
A.Set("has_gift_activity", 1) }
A.Set("gift_activity", giftActivity)
} //再去判断满赠活动
//其中一类活动不允许优惠券,这个商品就不允许使用优惠券 if giftActivity.HasActivity {
var allowCoupon int A.Set("has_gift_activity", 1)
if priceActivity.HasActivity && priceActivity.AllowCoupon == 2 { A.Set("gift_activity", giftActivity)
allowCoupon = 2 }
A.Set("allow_coupon", allowCoupon) //其中一类活动不允许优惠券,这个商品就不允许使用优惠券
} var allowCoupon int
if giftActivity.HasActivity && giftActivity.AllowCoupon == 2 { if priceActivity.HasActivity && priceActivity.AllowCoupon == 2 {
allowCoupon = 2 allowCoupon = 2
A.Set("allow_coupon", allowCoupon) A.Set("allow_coupon", allowCoupon)
} }
return A if giftActivity.HasActivity && giftActivity.AllowCoupon == 2 {
} allowCoupon = 2
A.Set("allow_coupon", allowCoupon)
/* }
获取当前锁住的库存 return A
*/ }
func (qs *ZiyingService) HDGoodsLimit(SkuID string, Stock string, c *redis.Conn) *orderedmap.OrderedMap {
/*
GoodsLimit, _ := redis.String((*c).Do("get", "Self_GoodsLimit_"+SkuID)) 获取当前锁住的库存
if GoodsLimit == "" { */
return nil func (qs *ZiyingService) HDGoodsLimit(SkuID string, Stock string, c *redis.Conn) *orderedmap.OrderedMap {
}
start_time := gjson.Get(GoodsLimit, "start_time").Int() GoodsLimit, _ := redis.String((*c).Do("get", "Self_GoodsLimit_"+SkuID))
end_time := gjson.Get(GoodsLimit, "end_time").Int() if GoodsLimit == "" {
buy_stock := gjson.Get(GoodsLimit, "buy_stock").Float() return nil
ac_stock := gjson.Get(GoodsLimit, "ac_stock").Float() }
schedule := gjson.Get(GoodsLimit, "schedule").Float() start_time := gjson.Get(GoodsLimit, "start_time").Int()
allow_coupon := gjson.Get(GoodsLimit, "allow_coupon").Int() end_time := gjson.Get(GoodsLimit, "end_time").Int()
buy_stock := gjson.Get(GoodsLimit, "buy_stock").Float()
if start_time < php2go.Time() && end_time > php2go.Time() { ac_stock := gjson.Get(GoodsLimit, "ac_stock").Float()
buy := buy_stock / ac_stock * 100 schedule := gjson.Get(GoodsLimit, "schedule").Float()
schedule := common.MyRound(buy+schedule, 2) allow_coupon := gjson.Get(GoodsLimit, "allow_coupon").Int()
if schedule < 100 {
A := orderedmap.New() if start_time < php2go.Time() && end_time > php2go.Time() {
//拼接梯度价格 buy := buy_stock / ac_stock * 100
ladder_price_arr := gjson.Get(GoodsLimit, "ac_price").Array() schedule := common.MyRound(buy+schedule, 2)
ladderType := make([]model.LadderPrice, 0) if schedule < 100 {
for _, v := range ladder_price_arr { A := orderedmap.New()
ladderType = append(ladderType, model.LadderPrice{ //拼接梯度价格
Purchases: v.Get("purchases").Int(), ladder_price_arr := gjson.Get(GoodsLimit, "ac_price").Array()
PriceCn: v.Get("price_cn").Float(), ladderType := make([]model.LadderPrice, 0)
PriceAc: v.Get("price_ac").Float(), for _, v := range ladder_price_arr {
}) ladderType = append(ladderType, model.LadderPrice{
} Purchases: v.Get("purchases").Int(),
PriceCn: v.Get("price_cn").Float(),
now_stock := ac_stock * ((100 - schedule) / 100) PriceAc: v.Get("price_ac").Float(),
})
A.Set("ac_type", 1) }
A.Set("ac_id", gjson.Get(GoodsLimit, "id").Int())
A.Set("ladder_price", ladderType) now_stock := ac_stock * ((100 - schedule) / 100)
A.Set("ac_stock", ac_stock)
A.Set("stock", now_stock) A.Set("ac_type", 1)
A.Set("schedule", schedule) A.Set("ac_id", gjson.Get(GoodsLimit, "id").Int())
A.Set("activity_end_time", end_time) A.Set("ladder_price", ladderType)
if allow_coupon > 0 { A.Set("ac_stock", ac_stock)
A.Set("allow_coupon", allow_coupon) A.Set("stock", now_stock)
} else { A.Set("schedule", schedule)
A.Set("allow_coupon", 1) A.Set("activity_end_time", end_time)
} if allow_coupon > 0 {
//活动库存大于当前可售库存,强制结束活动 A.Set("allow_coupon", allow_coupon)
if now_stock > common.MyFloat64(Stock) || now_stock == 0 { } else {
return nil A.Set("allow_coupon", 1)
} }
return A //活动库存大于当前可售库存,强制结束活动
} if now_stock > common.MyFloat64(Stock) || now_stock == 0 {
return nil
} }
return nil return A
} }
}
return nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment