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
37fbe663
authored
Nov 10, 2025
by
hcy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
并发问题
parent
7510df85
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
195 additions
and
120 deletions
service/service_spu.go
service/service_spu.go
View file @
37fbe663
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/vars"
"go_sku_server/pkg/vars"
"strings"
"strings"
"sync"
)
)
var
UsdRate
float64
//美金匯率
var
UsdRate
float64
//美金匯率
...
@@ -94,10 +95,11 @@ func (ss *SpuService) GetSpuList(skuArr map[string]string) map[string]string {
...
@@ -94,10 +95,11 @@ func (ss *SpuService) GetSpuList(skuArr map[string]string) map[string]string {
// 设置查询公共变量
// 设置查询公共变量
func
(
ss
*
SpuService
)
SetInit
(
redisLySkuArr
map
[
string
]
string
,
zyGoodsId
,
lyGoodsId
[]
string
)
{
func
(
ss
*
SpuService
)
SetInit
(
redisLySkuArr
map
[
string
]
string
,
zyGoodsId
,
lyGoodsId
[]
string
)
{
needRawGoodsIds
:=
make
([]
string
,
0
)
//批量获取 原始编码
AllDelivery
=
make
(
map
[
string
]
map
[
string
]
string
,
0
)
//获取供应商货期
needExtendFeeId
:=
make
([]
string
,
0
)
//批量获取 附加费
needRawGoodsIds
:=
make
([]
string
,
0
)
//批量获取 原始编码
canals
:=
make
([]
string
,
0
)
//所有渠道,目前只有专卖有
needExtendFeeId
:=
make
([]
string
,
0
)
//批量获取 附加费
supplierIds
:=
make
([]
string
,
0
)
//所有供应商查询货期的key,排除专卖
canals
:=
make
([]
string
,
0
)
//所有渠道,目前只有专卖有
supplierIds
:=
make
([]
string
,
0
)
//所有供应商查询货期的key,排除专卖
//zhuanmaiGoodsIds := make([]string, 0) //专卖的所有goods_id
//zhuanmaiGoodsIds := make([]string, 0) //专卖的所有goods_id
sourceIds
:=
make
([]
string
,
0
)
//所有来源id
sourceIds
:=
make
([]
string
,
0
)
//所有来源id
...
@@ -134,160 +136,233 @@ func (ss *SpuService) SetInit(redisLySkuArr map[string]string, zyGoodsId, lyGood
...
@@ -134,160 +136,233 @@ func (ss *SpuService) SetInit(redisLySkuArr map[string]string, zyGoodsId, lyGood
needExtendFeeId
=
append
(
needExtendFeeId
,
feekey
)
needExtendFeeId
=
append
(
needExtendFeeId
,
feekey
)
}
}
}
}
//批量获取汇率
AllCurrencyRate
=
gredis
.
Hmget
(
"default_r"
,
"erp_rate"
,
[]
string
{
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"10"
,
"11"
,
"12"
,
"13"
})
UsdRate
=
gconv
.
Float64
(
AllCurrencyRate
[
"2"
])
//批量获取标签a
//批量获取标签a
GoodsSourceTags
=
gredis
.
Hmget
(
"default_r"
,
"goods_source_tags"
,
[]
string
{
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"10"
,
"11"
,
"12"
})
GoodsSourceTags
=
gredis
.
Hmget
(
"default_r"
,
"goods_source_tags"
,
[]
string
{
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"10"
,
"11"
,
"12"
})
//批量获取标签b
//批量获取标签b
GoodsLabelTags
=
gredis
.
Hmget
(
"default_r"
,
"goods_source_tags"
,
[]
string
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
})
GoodsLabelTags
=
gredis
.
Hmget
(
"default_r"
,
"goods_label_tags"
,
[]
string
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
})
var
wg
sync
.
WaitGroup
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
go
BatchCurrency
()
//批量获取汇率
}()
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
go
BatchLyRawGoods
(
needRawGoodsIds
)
//批量获取原始编码
}()
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
go
BatchZyLockStock
(
zyGoodsId
)
//批量获取锁库信息
}()
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
go
BatchLyFee
(
needExtendFeeId
)
//查询附加费
}()
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
go
BatchZhuanmaiDelivery
(
canals
)
//专营货期
}()
//批量获取原始编码
wg
.
Add
(
1
)
if
len
(
needRawGoodsIds
)
>
0
{
go
func
()
{
AllSkuRawMap
=
gredis
.
Hmget
(
"default_r"
,
"sku_raw_map"
,
needRawGoodsIds
)
defer
wg
.
Done
()
go
BatchSeaDelivery
(
supplierIds
)
//代购货期
}()
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
go
BatchLyTags
(
redisLySkuArr
,
lyGoodsId
)
// 批量获取联营tags
}()
wg
.
Wait
()
}
// 批量获取汇率
func
BatchCurrency
()
{
AllCurrencyRate
=
gredis
.
Hmget
(
"default_r"
,
"erp_rate"
,
[]
string
{
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"10"
,
"11"
,
"12"
,
"13"
})
UsdRate
=
gconv
.
Float64
(
AllCurrencyRate
[
"2"
])
}
// 批量获取原始编码
func
BatchLyRawGoods
(
needRawGoodsIds
[]
string
)
{
if
len
(
needRawGoodsIds
)
==
0
{
return
}
}
//批量获取锁库信息
AllSkuRawMap
=
gredis
.
Hmget
(
"default_r"
,
"sku_raw_map"
,
needRawGoodsIds
)
if
len
(
zyGoodsId
)
>
0
{
}
AllSkuLockMap
=
gredis
.
Hmget
(
"default_r"
,
"sku_lock_stock"
,
zyGoodsId
)
//所有锁库信息
// 查询自营锁库信息
func
BatchZyLockStock
(
zyGoodsId
[]
string
)
{
if
len
(
zyGoodsId
)
==
0
{
return
}
}
//查询附加费
AllSkuLockMap
=
gredis
.
Hmget
(
"default_r"
,
"sku_lock_stock"
,
zyGoodsId
)
//所有锁库信息
if
len
(
needExtendFeeId
)
>
0
{
}
AllExtendFee
=
make
(
map
[
string
]
interface
{})
redisFeeArr
:=
gredis
.
Hmget
(
"default_r"
,
"supp_extend_fee"
,
needExtendFeeId
)
// 查询附加费
for
keyOne
,
feeone
:=
range
redisFeeArr
{
func
BatchLyFee
(
needExtendFeeId
[]
string
)
{
if
feeone
==
""
{
if
len
(
needExtendFeeId
)
==
0
{
AllExtendFee
[
keyOne
]
=
false
return
continue
}
}
AllExtendFee
=
make
(
map
[
string
]
interface
{})
if
php2go
.
Stripos
(
keyOne
,
"17."
,
0
)
>
-
1
{
redisFeeArr
:=
gredis
.
Hmget
(
"default_r"
,
"supp_extend_fee"
,
needExtendFeeId
)
if
strings
.
Contains
(
feeone
,
"cn"
)
{
for
keyOne
,
feeone
:=
range
redisFeeArr
{
var
extendFee
ExtendFee
if
feeone
==
""
{
json
.
Unmarshal
([]
byte
(
feeone
),
&
extendFee
)
AllExtendFee
[
keyOne
]
=
false
AllExtendFee
[
keyOne
]
=
extendFee
continue
}
else
{
}
var
extendFee
[]
map
[
string
]
interface
{}
if
php2go
.
Stripos
(
keyOne
,
"17."
,
0
)
>
-
1
{
json
.
Unmarshal
([]
byte
(
feeone
),
&
extendFee
)
if
strings
.
Contains
(
feeone
,
"cn"
)
{
AllExtendFee
[
keyOne
]
=
extendFee
}
}
else
{
var
extendFee
ExtendFee
var
extendFee
ExtendFee
json
.
Unmarshal
([]
byte
(
feeone
),
&
extendFee
)
json
.
Unmarshal
([]
byte
(
feeone
),
&
extendFee
)
AllExtendFee
[
keyOne
]
=
extendFee
AllExtendFee
[
keyOne
]
=
extendFee
}
else
{
var
extendFee
[]
map
[
string
]
interface
{}
json
.
Unmarshal
([]
byte
(
feeone
),
&
extendFee
)
AllExtendFee
[
keyOne
]
=
extendFee
}
}
}
else
{
var
extendFee
ExtendFee
json
.
Unmarshal
([]
byte
(
feeone
),
&
extendFee
)
AllExtendFee
[
keyOne
]
=
extendFee
}
}
}
}
//获取供应商货期
}
AllDelivery
=
make
(
map
[
string
]
map
[
string
]
string
,
0
)
if
len
(
canals
)
>
0
{
//专营货期
// 专营货期
supplierRatios
:=
gredis
.
Hmget
(
"default_r"
,
"supp_ratio"
,
canals
)
func
BatchZhuanmaiDelivery
(
canals
[]
string
)
{
for
dkey
,
supplierRatio
:=
range
supplierRatios
{
if
len
(
canals
)
==
0
{
//专营货期
if
supplierRatio
==
""
{
return
AllDelivery
[
dkey
][
"cn_delivery"
]
=
""
}
AllDelivery
[
dkey
][
"hk_delivery"
]
=
""
supplierRatios
:=
gredis
.
Hmget
(
"default_r"
,
"supp_ratio"
,
canals
)
continue
for
dkey
,
supplierRatio
:=
range
supplierRatios
{
}
cn_delivery
:=
""
hk_delivery
:=
""
if
supplierRatio
!=
""
{
cnDeliveryTime
:=
gjson
.
Get
(
supplierRatio
,
"cn_delivery_time"
)
.
String
()
cnDeliveryTime
:=
gjson
.
Get
(
supplierRatio
,
"cn_delivery_time"
)
.
String
()
usDeliveryTime
:=
gjson
.
Get
(
supplierRatio
,
"us_delivery_time"
)
.
String
()
usDeliveryTime
:=
gjson
.
Get
(
supplierRatio
,
"us_delivery_time"
)
.
String
()
//为了兼容供应商修改的问题
//为了兼容供应商修改的问题
if
cnDeliveryTime
!=
"周"
&&
cnDeliveryTime
!=
"天"
{
if
cnDeliveryTime
!=
"周"
&&
cnDeliveryTime
!=
"天"
{
AllDelivery
[
dkey
][
"cn_delivery"
]
=
gjson
.
Get
(
supplierRatio
,
"cn_delivery_time"
)
.
String
()
cn_delivery
=
gjson
.
Get
(
supplierRatio
,
"cn_delivery_time"
)
.
String
()
}
else
{
}
else
{
AllDelivery
[
dkey
][
"cn_delivery"
]
=
""
cn_delivery
=
""
}
}
if
usDeliveryTime
!=
"周"
&&
usDeliveryTime
!=
"天"
{
if
usDeliveryTime
!=
"周"
&&
usDeliveryTime
!=
"天"
{
AllDelivery
[
dkey
][
"hk_delivery"
]
=
gjson
.
Get
(
supplierRatio
,
"us_delivery_time"
)
.
String
()
hk_delivery
=
gjson
.
Get
(
supplierRatio
,
"us_delivery_time"
)
.
String
()
}
else
{
}
else
{
AllDelivery
[
dkey
][
"hk_delivery"
]
=
""
hk_delivery
=
""
}
}
}
}
AllDelivery
[
dkey
]
=
map
[
string
]
string
{
"cn_delivery"
:
cn_delivery
,
"hk_delivery"
:
hk_delivery
,
}
}
}
if
len
(
supplierIds
)
>
0
{
//代购货期
}
supplierRatios
:=
gredis
.
Hmget
(
"default_r"
,
"SUPPLIER_REDIS_INFO_"
,
supplierIds
)
for
dkey
,
sinfo
:=
range
supplierRatios
{
// 代购货期
cnDelivery
:=
gjson
.
Get
(
sinfo
,
"cn_delivery"
)
.
String
()
func
BatchSeaDelivery
(
supplierIds
[]
string
)
{
hkDelivery
:=
gjson
.
Get
(
sinfo
,
"hk_delivery"
)
.
String
()
if
len
(
supplierIds
)
==
0
{
if
cnDelivery
!=
""
||
hkDelivery
!=
""
{
return
AllDelivery
[
dkey
]
=
map
[
string
]
string
{
}
"cn_delivery"
:
cnDelivery
,
supplierRatios
:=
gredis
.
Hmget
(
"default_r"
,
"SUPPLIER_REDIS_INFO_"
,
supplierIds
)
"hk_delivery"
:
hkDelivery
,
for
dkey
,
sinfo
:=
range
supplierRatios
{
}
cnDelivery
:=
gjson
.
Get
(
sinfo
,
"cn_delivery"
)
.
String
()
}
else
{
hkDelivery
:=
gjson
.
Get
(
sinfo
,
"hk_delivery"
)
.
String
()
AllDelivery
[
dkey
]
=
map
[
string
]
string
{
if
cnDelivery
!=
""
||
hkDelivery
!=
""
{
"cn_delivery"
:
""
,
AllDelivery
[
dkey
]
=
map
[
string
]
string
{
"hk_delivery"
:
""
,
"cn_delivery"
:
cnDelivery
,
}
"hk_delivery"
:
hkDelivery
,
}
}
else
{
AllDelivery
[
dkey
]
=
map
[
string
]
string
{
"cn_delivery"
:
""
,
"hk_delivery"
:
""
,
}
}
}
}
}
}
}
//批量获取联营tags-标签
// 批量获取联营tags
if
len
(
lyGoodsId
)
>
0
{
func
BatchLyTags
(
redisLySkuArr
map
[
string
]
string
,
lyGoodsId
[]
string
)
{
AllLyGoodsTag
=
make
(
map
[
string
]
model
.
GoodsTag
,
0
)
if
len
(
lyGoodsId
)
==
0
{
goodsTagArr
:=
gredis
.
Hmget
(
"default_r"
,
"goods_tag"
,
lyGoodsId
)
return
var
tags
[]
int
}
for
goods_id
,
goodsTagsStr
:=
range
goodsTagArr
{
if
goodsTagsStr
==
""
{
AllLyGoodsTag
=
make
(
map
[
string
]
model
.
GoodsTag
,
0
)
continue
goodsTagArr
:=
gredis
.
Hmget
(
"default_r"
,
"goods_tag"
,
lyGoodsId
)
}
var
tags
[]
int
var
tagNames
[]
string
for
goods_id
,
goodsTagsStr
:=
range
goodsTagArr
{
var
goodsTags
model
.
GoodsTag
if
goodsTagsStr
==
""
{
continue
skuStr
:=
redisLySkuArr
[
goods_id
]
}
source
:=
gjson
.
Get
(
skuStr
,
"source"
)
.
Int
()
var
tagNames
[]
string
goods_label
:=
gjson
.
Get
(
skuStr
,
"goods_label"
)
.
String
()
var
goodsTags
model
.
GoodsTag
org_id
:=
gjson
.
Get
(
skuStr
,
"org_id"
)
.
Int
()
skuStr
:=
redisLySkuArr
[
goods_id
]
goodsLabelType
:=
int
(
gjson
.
Get
(
goodsTagsStr
,
"goods_label"
)
.
Int
())
source
:=
gjson
.
Get
(
skuStr
,
"source"
)
.
Int
()
goodsLabelMap
:=
vars
.
GoodsLabel
goods_label
:=
gjson
.
Get
(
skuStr
,
"goods_label"
)
.
String
()
goodsTags
.
GoodsLabelName
=
goodsLabelMap
[
goodsLabelType
]
org_id
:=
gjson
.
Get
(
skuStr
,
"org_id"
)
.
Int
()
goodsTags
.
GoodsLabel
=
goodsLabelType
goodsLabelType
:=
int
(
gjson
.
Get
(
goodsTagsStr
,
"goods_label"
)
.
Int
())
//自定义标签
goodsLabelMap
:=
vars
.
GoodsLabel
customerTag
:=
gjson
.
Get
(
goodsTagsStr
,
"customer_tag"
)
.
String
()
goodsTags
.
GoodsLabelName
=
goodsLabelMap
[
goodsLabelType
]
if
customerTag
!=
""
{
goodsTags
.
GoodsLabel
=
goodsLabelType
customerTagArr
:=
php2go
.
Explode
(
" "
,
php2go
.
Trim
(
customerTag
))
for
_
,
cname
:=
range
customerTagArr
{
//自定义标签
//如果是爱智的话,去掉可议价标签
customerTag
:=
gjson
.
Get
(
goodsTagsStr
,
"customer_tag"
)
.
String
()
if
org_id
==
3
&&
cname
==
"可议价"
{
if
customerTag
!=
""
{
continue
customerTagArr
:=
php2go
.
Explode
(
" "
,
php2go
.
Trim
(
customerTag
))
}
for
_
,
cname
:=
range
customerTagArr
{
tagNames
=
append
(
tagNames
,
cname
)
//如果是爱智的话,去掉可议价标签
if
org_id
==
3
&&
cname
==
"可议价"
{
continue
}
}
tagNames
=
append
(
tagNames
,
cname
)
}
}
}
if
source
==
12
{
if
source
==
12
{
if
!
php2go
.
InArray
(
"当天发货"
,
tagNames
)
{
if
!
php2go
.
InArray
(
"当天发货"
,
tagNames
)
{
tagNames
=
append
(
tagNames
,
"当天发货"
)
tagNames
=
append
(
tagNames
,
"当天发货"
)
}
}
}
}
//goods_source_tags
//goods_source_tags
sourceTagsStr
:=
GoodsSourceTags
[
gconv
.
String
(
source
)]
sourceTagsStr
:=
GoodsSourceTags
[
gconv
.
String
(
source
)]
if
sourceTagsStr
!=
""
{
if
sourceTagsStr
!=
""
{
systemTags
:=
gjson
.
Get
(
sourceTagsStr
,
"system_tags"
)
.
Array
()
systemTags
:=
gjson
.
Get
(
sourceTagsStr
,
"system_tags"
)
.
Array
()
for
_
,
tag
:=
range
systemTags
{
for
_
,
tag
:=
range
systemTags
{
tagNames
=
append
(
tagNames
,
tag
.
String
())
tagNames
=
append
(
tagNames
,
tag
.
String
())
}
}
}
}
//goods_label_tags
//goods_label_tags
labelTagsStr
:=
GoodsLabelTags
[
goods_label
]
labelTagsStr
:=
GoodsLabelTags
[
goods_label
]
if
labelTagsStr
!=
""
{
if
labelTagsStr
!=
""
{
labelTags
:=
gjson
.
Get
(
labelTagsStr
,
"system_tags"
)
.
Array
()
labelTags
:=
gjson
.
Get
(
labelTagsStr
,
"system_tags"
)
.
Array
()
for
_
,
tag
:=
range
labelTags
{
for
_
,
tag
:=
range
labelTags
{
tagNames
=
append
(
tagNames
,
tag
.
String
())
tagNames
=
append
(
tagNames
,
tag
.
String
())
}
}
}
//去重tagNames
tagNames
=
removeDuplicateString
(
tagNames
)
goodsTags
.
GoodsTagNames
=
tagNames
goodsTags
.
GoodsTag
=
tags
AllLyGoodsTag
[
goods_id
]
=
goodsTags
}
}
//去重tagNames
tagNames
=
removeDuplicateString
(
tagNames
)
goodsTags
.
GoodsTagNames
=
tagNames
goodsTags
.
GoodsTag
=
tags
AllLyGoodsTag
[
goods_id
]
=
goodsTags
}
}
}
}
// 获取指定的币种汇率
// 获取指定的币种汇率
...
...
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