Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
go_sku_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
32cb67b8
authored
Jul 17, 2023
by
SUDPTDUBLXEROFX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
spu分离
parent
494a5de2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
214 additions
and
188 deletions
conf/dev/redis.ini
pkg/config/redis.go
service/service_ly.go
service/service_spu.go
service/service_zy.go
service/service_zy_common.go
conf/dev/redis.ini
View file @
32cb67b8
...
...
@@ -13,5 +13,14 @@ max_idle = 2000
max_active
=
5000
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_all]
\ No newline at end of file
pkg/config/redis.go
View file @
32cb67b8
...
...
@@ -16,6 +16,8 @@ func BuildRedisConfigs() (RedisDatabaseMap map[string]RedisDatabase) {
redisReadMaxActive
,
_
:=
Get
(
"default_redis_read.max_active"
)
.
Int
()
redisWriteMaxIdle
,
_
:=
Get
(
"default_redis_write.max_idle"
)
.
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
{
"search_r"
:
{
Host
:
Get
(
"default_redis_read.host"
)
.
String
(),
...
...
@@ -35,5 +37,11 @@ func BuildRedisConfigs() (RedisDatabaseMap map[string]RedisDatabase) {
MaxIdle
:
redisWriteMaxIdle
,
MaxActive
:
redisWriteMaxActive
,
},
"spu"
:
{
Host
:
Get
(
"default_redis_spu.host"
)
.
String
(),
Password
:
Get
(
"default_redis_spu.password"
)
.
String
(),
MaxIdle
:
redisSpuMaxIdle
,
MaxActive
:
redisSpuMaxActive
,
},
}
}
service/service_ly.go
View file @
32cb67b8
...
...
@@ -32,8 +32,10 @@ type Power struct {
*/
func
(
ls
*
LyService
)
LyGoodsDetail
(
ctx
*
gin
.
Context
,
goodsIds
[]
string
,
ch
chan
sync
.
Map
)
{
redisConn
:=
gredis
.
Conn
(
"search_r"
)
redisConnSpu
:=
gredis
.
Conn
(
"spu"
)
defer
func
()
{
redisConn
.
Close
()
redisConnSpu
.
Close
()
}()
fast
:=
ctx
.
Request
.
FormValue
(
"power[fast]"
)
//是否展示属性
...
...
@@ -59,7 +61,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
//读取包装字段的缓存
if
sku
.
SupplierId
==
7
||
sku
.
SupplierId
==
13
{
//sku_raw_map哪里写入(成意写的)
packing
,
_
:=
redis
.
String
(
redisConn
.
Do
(
"HGET"
,
"sku_raw_map"
,
goodsId
))
packing
,
_
:=
redis
.
String
(
redisConn
Spu
.
Do
(
"HGET"
,
"sku_raw_map"
,
goodsId
))
sku
.
Packing
=
gjson
.
Get
(
packing
,
"pack"
)
.
String
()
}
sku
=
ls
.
GetGoodsImages
(
sku
,
spu
)
...
...
service/service_spu.go
View file @
32cb67b8
...
...
@@ -16,6 +16,6 @@ func (ss *SpuService) getSpuList(skuArr map[string]string) (spuList map[string]s
spuIds
=
append
(
spuIds
,
spuId
)
}
//批量获取spu详情
spuList
=
gredis
.
Hmget
(
"
default_r
"
,
"spu"
,
spuIds
)
spuList
=
gredis
.
Hmget
(
"
spu
"
,
"spu"
,
spuIds
)
return
}
service/service_zy.go
View file @
32cb67b8
...
...
@@ -34,9 +34,11 @@ type ZiyingService struct {
*/
func
(
qs
*
ZiyingService
)
ZyGoodsDetail
(
ctx
*
gin
.
Context
,
goodsIds
[]
string
,
ch
chan
sync
.
Map
)
{
redisConn
:=
gredis
.
Conn
(
"search_r"
)
redisConnSpu
:=
gredis
.
Conn
(
"spu"
)
defer
func
()
{
//wg.Done();
redisConn
.
Close
()
redisConnSpu
.
Close
()
}()
skuArr
:=
gredis
.
Hmget
(
"search_r"
,
"Self_SelfGoods"
,
goodsIds
)
//批量获取商品详情
...
...
@@ -108,7 +110,7 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context, goodsIds []string, ch c
var
brandId
int64
var
brandName
string
if
spuId
!=
0
{
spuStr
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"spu"
,
spuId
))
spuStr
,
_
:=
gredis
.
String
(
redisConn
Spu
.
Do
(
"HGET"
,
"spu"
,
spuId
))
brandId
=
gjson
.
Get
(
spuStr
,
"brand_id"
)
.
Int
()
brandName
,
_
=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"brand"
,
brandId
))
var
ly
LyService
...
...
service/service_zy_common.go
View file @
32cb67b8
package
service
import
(
"go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis"
"github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
)
//自营公共函数类
/*
计算单个sku总锁库数量
*/
func
(
qs
*
ZiyingService
)
skuLockNum
(
c
*
redis
.
Conn
,
goodsId
string
)
int64
{
reply
,
err
:=
redis
.
Values
((
*
c
)
.
Do
(
"hvals"
,
"Self_StockLock"
+
goodsId
))
if
err
!=
nil
{
return
0
}
var
albums
[]
int64
if
err
:=
redis
.
ScanSlice
(
reply
,
&
albums
);
err
!=
nil
{
return
0
}
if
len
(
albums
)
==
0
{
return
0
}
else
{
var
all
int64
=
0
for
_
,
n
:=
range
albums
{
all
=
all
+
n
}
return
all
}
}
/*
获取自营活动价
*/
func
(
qs
*
ZiyingService
)
ActivityPrice
(
ctx
*
gin
.
Context
,
SkuInfo
string
)
*
orderedmap
.
OrderedMap
{
data
:=
qs
.
HDActivityPrice
(
SkuInfo
)
if
data
!=
nil
{
return
data
}
return
nil
}
//获取活动相关信息
func
(
qs
*
ZiyingService
)
GetActivity
(
skuInfo
string
)
(
priceActivity
model
.
PriceActivity
,
giftActivity
model
.
GiftActivity
)
{
//去判断是否有活动(促销打折活动和满赠活动)
var
standardBrandId
int
spuId
:=
gjson
.
Get
(
skuInfo
,
"spu_id"
)
.
String
()
redisCon
:=
gredis
.
Conn
(
"default_r"
)
spuStr
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"spu"
,
spuId
))
defer
redisCon
.
Close
()
if
spuStr
==
""
{
standardBrandId
=
0
}
else
{
brandId
:=
gjson
.
Get
(
spuStr
,
"brand_id"
)
.
Int
()
standardBrandId
,
_
=
redis
.
Int
(
redisCon
.
Do
(
"HGET"
,
"standard_brand_mapping"
,
brandId
))
}
checkData
:=
model
.
ActivityCheckData
{
SupplierId
:
10000
,
BrandId
:
int
(
gjson
.
Get
(
skuInfo
,
"brand_id"
)
.
Int
()),
StandardBrandId
:
standardBrandId
,
GoodsId
:
gjson
.
Get
(
skuInfo
,
"goods_id"
)
.
String
(),
ClassId
:
int
(
gjson
.
Get
(
skuInfo
,
"class_id2"
)
.
Int
()),
}
var
activityService
ActivityService
priceActivity
,
giftActivity
=
activityService
.
GetActivityData
(
checkData
)
return
}
/*
计算活动价
ac_type说明: 0 没有活动
活动名称 ac_type 类型
自营系数 6 自营
折扣(系数)活动 10 自营/联营
*/
func
(
qs
*
ZiyingService
)
HDActivityPrice
(
SkuInfo
string
)
*
orderedmap
.
OrderedMap
{
priceActivity
,
giftActivity
:=
qs
.
GetActivity
(
SkuInfo
)
ladderPriceArr
:=
gjson
.
Get
(
SkuInfo
,
"ladder_price"
)
.
Array
()
A
:=
orderedmap
.
New
()
//先去判断价格活动
if
priceActivity
.
HasActivity
&&
len
(
ladderPriceArr
)
>
0
{
ratio
:=
priceActivity
.
Ratio
ladderType
:=
make
([]
model
.
LadderPrice
,
0
)
for
_
,
v
:=
range
ladderPriceArr
{
priceCn
:=
v
.
Get
(
"price_cn"
)
.
Float
()
priceAc
:=
php2go
.
Round
(
priceCn
*
ratio
/
100
*
10000
)
/
10000
ladderType
=
append
(
ladderType
,
model
.
LadderPrice
{
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
PriceUs
:
v
.
Get
(
"price_us"
)
.
Float
(),
PriceCn
:
priceCn
,
PriceAc
:
priceAc
,
})
}
A
.
Set
(
"activity_info"
,
priceActivity
)
A
.
Set
(
"ladder_price"
,
ladderType
)
A
.
Set
(
"ratio"
,
ratio
)
A
.
Set
(
"ac_type"
,
10
)
}
//再去判断满赠活动
if
giftActivity
.
HasActivity
{
A
.
Set
(
"has_gift_activity"
,
1
)
A
.
Set
(
"gift_activity"
,
giftActivity
)
}
//其中一类活动不允许优惠券,这个商品就不允许使用优惠券
var
allowCoupon
int
if
priceActivity
.
HasActivity
&&
priceActivity
.
AllowCoupon
==
2
{
allowCoupon
=
2
A
.
Set
(
"allow_coupon"
,
allowCoupon
)
}
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
}
start_time
:=
gjson
.
Get
(
GoodsLimit
,
"start_time"
)
.
Int
()
end_time
:=
gjson
.
Get
(
GoodsLimit
,
"end_time"
)
.
Int
()
buy_stock
:=
gjson
.
Get
(
GoodsLimit
,
"buy_stock"
)
.
Float
()
ac_stock
:=
gjson
.
Get
(
GoodsLimit
,
"ac_stock"
)
.
Float
()
schedule
:=
gjson
.
Get
(
GoodsLimit
,
"schedule"
)
.
Float
()
allow_coupon
:=
gjson
.
Get
(
GoodsLimit
,
"allow_coupon"
)
.
Int
()
if
start_time
<
php2go
.
Time
()
&&
end_time
>
php2go
.
Time
()
{
buy
:=
buy_stock
/
ac_stock
*
100
schedule
:=
common
.
MyRound
(
buy
+
schedule
,
2
)
if
schedule
<
100
{
A
:=
orderedmap
.
New
()
//拼接梯度价格
ladder_price_arr
:=
gjson
.
Get
(
GoodsLimit
,
"ac_price"
)
.
Array
()
ladderType
:=
make
([]
model
.
LadderPrice
,
0
)
for
_
,
v
:=
range
ladder_price_arr
{
ladderType
=
append
(
ladderType
,
model
.
LadderPrice
{
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
PriceCn
:
v
.
Get
(
"price_cn"
)
.
Float
(),
PriceAc
:
v
.
Get
(
"price_ac"
)
.
Float
(),
})
}
now_stock
:=
ac_stock
*
((
100
-
schedule
)
/
100
)
A
.
Set
(
"ac_type"
,
1
)
A
.
Set
(
"ac_id"
,
gjson
.
Get
(
GoodsLimit
,
"id"
)
.
Int
())
A
.
Set
(
"ladder_price"
,
ladderType
)
A
.
Set
(
"ac_stock"
,
ac_stock
)
A
.
Set
(
"stock"
,
now_stock
)
A
.
Set
(
"schedule"
,
schedule
)
A
.
Set
(
"activity_end_time"
,
end_time
)
if
allow_coupon
>
0
{
A
.
Set
(
"allow_coupon"
,
allow_coupon
)
}
else
{
A
.
Set
(
"allow_coupon"
,
1
)
}
//活动库存大于当前可售库存,强制结束活动
if
now_stock
>
common
.
MyFloat64
(
Stock
)
||
now_stock
==
0
{
return
nil
}
return
A
}
}
return
nil
}
package
service
import
(
"go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis"
"github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
)
//自营公共函数类
/*
计算单个sku总锁库数量
*/
func
(
qs
*
ZiyingService
)
skuLockNum
(
c
*
redis
.
Conn
,
goodsId
string
)
int64
{
reply
,
err
:=
redis
.
Values
((
*
c
)
.
Do
(
"hvals"
,
"Self_StockLock"
+
goodsId
))
if
err
!=
nil
{
return
0
}
var
albums
[]
int64
if
err
:=
redis
.
ScanSlice
(
reply
,
&
albums
);
err
!=
nil
{
return
0
}
if
len
(
albums
)
==
0
{
return
0
}
else
{
var
all
int64
=
0
for
_
,
n
:=
range
albums
{
all
=
all
+
n
}
return
all
}
}
/*
获取自营活动价
*/
func
(
qs
*
ZiyingService
)
ActivityPrice
(
ctx
*
gin
.
Context
,
SkuInfo
string
)
*
orderedmap
.
OrderedMap
{
data
:=
qs
.
HDActivityPrice
(
SkuInfo
)
if
data
!=
nil
{
return
data
}
return
nil
}
//获取活动相关信息
func
(
qs
*
ZiyingService
)
GetActivity
(
skuInfo
string
)
(
priceActivity
model
.
PriceActivity
,
giftActivity
model
.
GiftActivity
)
{
//去判断是否有活动(促销打折活动和满赠活动)
var
standardBrandId
int
spuId
:=
gjson
.
Get
(
skuInfo
,
"spu_id"
)
.
String
()
redisCon
:=
gredis
.
Conn
(
"default_r"
)
redisConSpu
:=
gredis
.
Conn
(
"spu"
)
spuStr
,
_
:=
redis
.
String
(
redisConSpu
.
Do
(
"HGET"
,
"spu"
,
spuId
))
defer
func
()
{
redisCon
.
Close
()
redisConSpu
.
Close
()
}()
if
spuStr
==
""
{
standardBrandId
=
0
}
else
{
brandId
:=
gjson
.
Get
(
spuStr
,
"brand_id"
)
.
Int
()
standardBrandId
,
_
=
redis
.
Int
(
redisCon
.
Do
(
"HGET"
,
"standard_brand_mapping"
,
brandId
))
}
checkData
:=
model
.
ActivityCheckData
{
SupplierId
:
10000
,
BrandId
:
int
(
gjson
.
Get
(
skuInfo
,
"brand_id"
)
.
Int
()),
StandardBrandId
:
standardBrandId
,
GoodsId
:
gjson
.
Get
(
skuInfo
,
"goods_id"
)
.
String
(),
ClassId
:
int
(
gjson
.
Get
(
skuInfo
,
"class_id2"
)
.
Int
()),
}
var
activityService
ActivityService
priceActivity
,
giftActivity
=
activityService
.
GetActivityData
(
checkData
)
return
}
/*
计算活动价
ac_type说明: 0 没有活动
活动名称 ac_type 类型
自营系数 6 自营
折扣(系数)活动 10 自营/联营
*/
func
(
qs
*
ZiyingService
)
HDActivityPrice
(
SkuInfo
string
)
*
orderedmap
.
OrderedMap
{
priceActivity
,
giftActivity
:=
qs
.
GetActivity
(
SkuInfo
)
ladderPriceArr
:=
gjson
.
Get
(
SkuInfo
,
"ladder_price"
)
.
Array
()
A
:=
orderedmap
.
New
()
//先去判断价格活动
if
priceActivity
.
HasActivity
&&
len
(
ladderPriceArr
)
>
0
{
ratio
:=
priceActivity
.
Ratio
ladderType
:=
make
([]
model
.
LadderPrice
,
0
)
for
_
,
v
:=
range
ladderPriceArr
{
priceCn
:=
v
.
Get
(
"price_cn"
)
.
Float
()
priceAc
:=
php2go
.
Round
(
priceCn
*
ratio
/
100
*
10000
)
/
10000
ladderType
=
append
(
ladderType
,
model
.
LadderPrice
{
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
PriceUs
:
v
.
Get
(
"price_us"
)
.
Float
(),
PriceCn
:
priceCn
,
PriceAc
:
priceAc
,
})
}
A
.
Set
(
"activity_info"
,
priceActivity
)
A
.
Set
(
"ladder_price"
,
ladderType
)
A
.
Set
(
"ratio"
,
ratio
)
A
.
Set
(
"ac_type"
,
10
)
}
//再去判断满赠活动
if
giftActivity
.
HasActivity
{
A
.
Set
(
"has_gift_activity"
,
1
)
A
.
Set
(
"gift_activity"
,
giftActivity
)
}
//其中一类活动不允许优惠券,这个商品就不允许使用优惠券
var
allowCoupon
int
if
priceActivity
.
HasActivity
&&
priceActivity
.
AllowCoupon
==
2
{
allowCoupon
=
2
A
.
Set
(
"allow_coupon"
,
allowCoupon
)
}
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
}
start_time
:=
gjson
.
Get
(
GoodsLimit
,
"start_time"
)
.
Int
()
end_time
:=
gjson
.
Get
(
GoodsLimit
,
"end_time"
)
.
Int
()
buy_stock
:=
gjson
.
Get
(
GoodsLimit
,
"buy_stock"
)
.
Float
()
ac_stock
:=
gjson
.
Get
(
GoodsLimit
,
"ac_stock"
)
.
Float
()
schedule
:=
gjson
.
Get
(
GoodsLimit
,
"schedule"
)
.
Float
()
allow_coupon
:=
gjson
.
Get
(
GoodsLimit
,
"allow_coupon"
)
.
Int
()
if
start_time
<
php2go
.
Time
()
&&
end_time
>
php2go
.
Time
()
{
buy
:=
buy_stock
/
ac_stock
*
100
schedule
:=
common
.
MyRound
(
buy
+
schedule
,
2
)
if
schedule
<
100
{
A
:=
orderedmap
.
New
()
//拼接梯度价格
ladder_price_arr
:=
gjson
.
Get
(
GoodsLimit
,
"ac_price"
)
.
Array
()
ladderType
:=
make
([]
model
.
LadderPrice
,
0
)
for
_
,
v
:=
range
ladder_price_arr
{
ladderType
=
append
(
ladderType
,
model
.
LadderPrice
{
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
PriceCn
:
v
.
Get
(
"price_cn"
)
.
Float
(),
PriceAc
:
v
.
Get
(
"price_ac"
)
.
Float
(),
})
}
now_stock
:=
ac_stock
*
((
100
-
schedule
)
/
100
)
A
.
Set
(
"ac_type"
,
1
)
A
.
Set
(
"ac_id"
,
gjson
.
Get
(
GoodsLimit
,
"id"
)
.
Int
())
A
.
Set
(
"ladder_price"
,
ladderType
)
A
.
Set
(
"ac_stock"
,
ac_stock
)
A
.
Set
(
"stock"
,
now_stock
)
A
.
Set
(
"schedule"
,
schedule
)
A
.
Set
(
"activity_end_time"
,
end_time
)
if
allow_coupon
>
0
{
A
.
Set
(
"allow_coupon"
,
allow_coupon
)
}
else
{
A
.
Set
(
"allow_coupon"
,
1
)
}
//活动库存大于当前可售库存,强制结束活动
if
now_stock
>
common
.
MyFloat64
(
Stock
)
||
now_stock
==
0
{
return
nil
}
return
A
}
}
return
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment