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
64ff5f14
authored
Nov 10, 2025
by
hcy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
并发问题
parent
4bd6c57d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
208 additions
and
17 deletions
controller/sku_controller.go
service/service_ly.go
service/service_spu.go
controller/sku_controller.go
View file @
64ff5f14
...
@@ -126,7 +126,7 @@ func CommonController(ctx *gin.Context) map[string]interface{} {
...
@@ -126,7 +126,7 @@ func CommonController(ctx *gin.Context) map[string]interface{} {
}
}
//设置查询公共变量
//设置查询公共变量
SpuService
.
SetInit
(
redisLySkuArr
,
zyGoodsId
)
SpuService
.
SetInit
(
redisLySkuArr
,
zyGoodsId
,
lyGoodsId
)
/////////////////多线程///////////////////////////
/////////////////多线程///////////////////////////
...
...
service/service_ly.go
View file @
64ff5f14
...
@@ -62,6 +62,8 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, sk
...
@@ -62,6 +62,8 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, sk
sku
:=
model
.
InitSkuData
(
skuStr
)
sku
:=
model
.
InitSkuData
(
skuStr
)
spu
:=
spuStr
spu
:=
spuStr
supplierIdStr
:=
gconv
.
String
(
sku
.
SupplierId
)
//供应商字符串
sku
.
GoodsId
=
goodsId
sku
.
GoodsId
=
goodsId
//读取包装字段的缓存(分别是DGK,avnet,mro)
//读取包装字段的缓存(分别是DGK,avnet,mro)
if
sku
.
SupplierId
==
7
||
sku
.
SupplierId
==
13
||
sku
.
SupplierId
==
1688
||
sku
.
SupplierId
==
17
{
if
sku
.
SupplierId
==
7
||
sku
.
SupplierId
==
13
||
sku
.
SupplierId
==
1688
||
sku
.
SupplierId
==
17
{
...
@@ -206,11 +208,18 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, sk
...
@@ -206,11 +208,18 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, sk
//仅提供价格和库存
//仅提供价格和库存
if
fast
!=
"1"
{
if
fast
!=
"1"
{
feekey
:=
supplierIdStr
deliveryKey
:=
supplierIdStr
if
sku
.
SupplierId
==
17
{
feekey
=
"17."
+
sku
.
Canal
deliveryKey
=
sku
.
Canal
}
if
sku
.
SupplierId
!=
0
{
if
sku
.
SupplierId
!=
0
{
sku
.
SuppExtendFee
=
ls
.
GetExtendFee
(
sku
.
SupplierId
,
sku
.
Canal
)
sku
.
SuppExtendFee
=
AllExtendFee
[
feekey
]
}
}
//还要处理货期
//还要处理货期
delivery
:=
ls
.
GetDelivery
(
sku
.
SupplierId
,
sku
.
Canal
)
delivery
:=
AllDelivery
[
deliveryKey
]
if
sku
.
CnDeliveryTime
==
""
{
if
sku
.
CnDeliveryTime
==
""
{
sku
.
CnDeliveryTime
=
delivery
[
"cn_delivery"
]
sku
.
CnDeliveryTime
=
delivery
[
"cn_delivery"
]
}
}
...
@@ -256,15 +265,13 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, sk
...
@@ -256,15 +265,13 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, sk
sku
.
Stock
=
ls
.
GetStock
(
sku
)
sku
.
Stock
=
ls
.
GetStock
(
sku
)
//获取标签信息
//获取标签信息
var
TagService
TagsService
sku
.
GoodsTag
=
AllLyGoodsTag
[
goodsId
]
sku
.
GoodsTag
=
TagService
.
GetLyTags
(
sku
)
//获取关税以及价格转换
//获取关税以及价格转换
sku
=
ls
.
GetTariffAndPrice
(
sku
)
sku
=
ls
.
GetTariffAndPrice
(
sku
)
//最后一步,将sku的全部信息放到有序map里面
//最后一步,将sku的全部信息放到有序map里面
GoodsRes
.
Store
(
goodsId
,
sku
)
GoodsRes
.
Store
(
goodsId
,
sku
)
//(*goodsRes)[goodsId] = A
//退出通道
//退出通道
ch
<-
GoodsRes
ch
<-
GoodsRes
...
...
service/service_spu.go
View file @
64ff5f14
package
service
package
service
import
(
import
(
"encoding/json"
"github.com/gogf/gf/util/gconv"
"github.com/gogf/gf/util/gconv"
"github.com/syyongx/php2go"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/vars"
"strings"
)
)
var
UsdRate
float64
//美金匯率
var
UsdRate
float64
//美金匯率
var
AllCurrencyRate
map
[
string
]
string
//所有汇率
var
AllCurrencyRate
map
[
string
]
string
//所有汇率
var
AllLyBrand
map
[
string
]
string
//所有联营品牌
var
AllLyBrand
map
[
string
]
string
//所有联营品牌
var
AllSkuRawMap
map
[
string
]
string
//所有原始编码 sku_raw_map 数据
var
AllSkuRawMap
map
[
string
]
string
//所有原始编码 sku_raw_map 数据
var
AllSkuLockMap
map
[
string
]
string
//自营锁库库存
var
AllSkuLockMap
map
[
string
]
string
//自营锁库库存
var
AllExtendFee
map
[
string
]
string
//所有附加费
var
AllExtendFee
map
[
string
]
interface
{}
//所有附加费
var
AllDelivery
map
[
string
]
map
[
string
]
string
//所有货期,下标:专卖是 canl ,代购 供应商id
var
AllLyGoodsTag
map
[
string
]
model
.
GoodsTag
//所有联营标签
var
GoodsSourceTags
map
[
string
]
string
//标签a {"system_tags":["oyr","新品推荐","可议价","可替代","爆款"]}
var
GoodsLabelTags
map
[
string
]
string
//标签b{"system_tags":["新品推荐","可替代"]}
// 币种中文
// 币种中文
var
CURRENCY_CN
=
map
[
int
]
string
{
var
CURRENCY_CN
=
map
[
int
]
string
{
1
:
"人民币"
,
1
:
"人民币"
,
...
@@ -31,6 +38,33 @@ var CURRENCY_CN = map[int]string{
...
@@ -31,6 +38,33 @@ var CURRENCY_CN = map[int]string{
13
:
"越南盾"
,
13
:
"越南盾"
,
}
}
// 来源常量
var
Source
=
map
[
int
]
string
{
1
:
"代购采集"
,
2
:
"代购API"
,
3
:
"代购数据包"
,
4
:
"专营API"
,
5
:
"专营数据包"
,
6
:
"专营后台上传"
,
7
:
"专营云芯上传"
,
8
:
"专营采集"
,
9
:
"芯链人工上传"
,
10
:
"爱智后台上传"
,
11
:
"爱智API对接"
,
12
:
"芯链寄售上传"
,
}
// `goods_label` '分类: 0 无 1 国内现货,2国际现货, 3 猎芯期货 ,4 询价现货,5原厂直售,6猎芯精选
var
GoodsLabel
=
map
[
int
]
string
{
0
:
"无"
,
1
:
"国内现货"
,
2
:
"国际现货"
,
3
:
"猎芯期货"
,
4
:
"询价现货"
,
5
:
"原厂直售"
,
6
:
"猎芯精选"
,
}
type
SpuService
struct
{
type
SpuService
struct
{
}
}
...
@@ -58,21 +92,37 @@ func (ss *SpuService) GetSpuList(skuArr map[string]string) map[string]string {
...
@@ -58,21 +92,37 @@ func (ss *SpuService) GetSpuList(skuArr map[string]string) map[string]string {
}
}
// 设置查询公共变量
// 设置查询公共变量
func
(
ss
*
SpuService
)
SetInit
(
redisLySkuArr
map
[
string
]
string
,
zyGoodsId
[]
string
)
{
func
(
ss
*
SpuService
)
SetInit
(
redisLySkuArr
map
[
string
]
string
,
zyGoodsId
,
lyGoodsId
[]
string
)
{
needRawGoodsIds
:=
make
([]
string
,
0
)
//批量获取 原始编码
needRawGoodsIds
:=
make
([]
string
,
0
)
//批量获取 原始编码
needExtendFeeId
:=
make
([]
string
,
0
)
//批量获取 附加费
needExtendFeeId
:=
make
([]
string
,
0
)
//批量获取 附加费
canals
:=
make
([]
string
,
0
)
//所有渠道,目前只有专卖有
supplierIds
:=
make
([]
string
,
0
)
//所有供应商查询货期的key,排除专卖
//zhuanmaiGoodsIds := make([]string, 0) //专卖的所有goods_id
sourceIds
:=
make
([]
string
,
0
)
//所有来源id
for
goods_id
,
info
:=
range
redisLySkuArr
{
for
goods_id
,
info
:=
range
redisLySkuArr
{
supplierId
:=
gjson
.
Get
(
info
,
"supplier_id"
)
.
Int
()
supplierId
:=
gjson
.
Get
(
info
,
"supplier_id"
)
.
Int
()
source
:=
gjson
.
Get
(
info
,
"source"
)
.
Int
()
source
:=
gjson
.
Get
(
info
,
"source"
)
.
Int
()
canal
:=
gjson
.
Get
(
info
,
"canal"
)
.
String
()
canal
:=
gjson
.
Get
(
info
,
"canal"
)
.
String
()
sourceStr
:=
gconv
.
String
(
source
)
if
!
php2go
.
InArray
(
sourceStr
,
sourceIds
)
{
sourceIds
=
append
(
sourceIds
,
sourceStr
)
}
if
canal
!=
""
{
canals
=
append
(
canals
,
canal
)
}
if
supplierId
!=
17
&&
!
php2go
.
InArray
(
supplierId
,
supplierIds
)
{
supplierIds
=
append
(
supplierIds
,
gconv
.
String
(
supplierId
))
}
if
php2go
.
InArray
(
supplierId
,
[]
int
{
7
,
13
,
1688
,
17
})
{
if
php2go
.
InArray
(
supplierId
,
[]
int
{
7
,
13
,
1688
,
17
})
{
needRawGoodsIds
=
append
(
needRawGoodsIds
,
goods_id
)
needRawGoodsIds
=
append
(
needRawGoodsIds
,
goods_id
)
}
}
if
source
==
12
||
php2go
.
InArray
(
canal
,
[]
string
{
"L0018319"
,
"L0013521"
,
"L0018562"
,
"L0017764"
,
"L0003270"
,
"L0012413"
,
"L0013521"
})
{
if
source
==
12
||
php2go
.
InArray
(
canal
,
[]
string
{
"L0018319"
,
"L0013521"
,
"L0018562"
,
"L0017764"
,
"L0003270"
,
"L0012413"
,
"L0013521"
})
{
zyGoodsId
=
append
(
zyGoodsId
,
goods_id
)
zyGoodsId
=
append
(
zyGoodsId
,
goods_id
)
}
}
feekey
:=
""
feekey
:=
""
if
supplierId
==
17
{
if
supplierId
==
17
{
feekey
=
"17."
+
canal
feekey
=
"17."
+
canal
...
@@ -86,16 +136,150 @@ func (ss *SpuService) SetInit(redisLySkuArr map[string]string, zyGoodsId []strin
...
@@ -86,16 +136,150 @@ func (ss *SpuService) SetInit(redisLySkuArr map[string]string, zyGoodsId []strin
//批量获取汇率
//批量获取汇率
AllCurrencyRate
=
gredis
.
Hmget
(
"default_r"
,
"erp_rate"
,
[]
string
{
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"10"
,
"11"
,
"12"
,
"13"
})
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"
])
UsdRate
=
gconv
.
Float64
(
AllCurrencyRate
[
"2"
])
//批量获取标签a
GoodsSourceTags
=
gredis
.
Hmget
(
"default_r"
,
"goods_source_tags"
,
[]
string
{
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"10"
,
"11"
,
"12"
})
//批量获取标签b
GoodsLabelTags
=
gredis
.
Hmget
(
"default_r"
,
"goods_source_tags"
,
[]
string
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
})
//批量获取原始编码
//批量获取原始编码
if
len
(
needRawGoodsIds
)
>
0
{
if
needRawGoodsIds
!=
nil
{
AllSkuRawMap
=
gredis
.
Hmget
(
"default_r"
,
"sku_raw_map"
,
needRawGoodsIds
)
AllSkuRawMap
=
gredis
.
Hmget
(
"default_r"
,
"sku_raw_map"
,
needRawGoodsIds
)
}
}
//批量获取锁库信息
//批量获取锁库信息
if
len
(
zyGoodsId
)
>
0
{
if
zyGoodsId
!=
nil
{
AllSkuLockMap
=
gredis
.
Hmget
(
"default_r"
,
"sku_lock_stock"
,
zyGoodsId
)
//所有锁库信息
AllSkuLockMap
=
gredis
.
Hmget
(
"default_r"
,
"sku_lock_stock"
,
zyGoodsId
)
//所有锁库信息
}
}
//查询附加费
//查询附加费
if
needExtendFeeId
!=
nil
{
redisFeeArr
:=
gredis
.
Hmget
(
"default_r"
,
"supp_extend_fee"
,
needExtendFeeId
)
for
keyOne
,
feeone
:=
range
redisFeeArr
{
if
feeone
==
""
{
AllExtendFee
[
keyOne
]
=
false
continue
}
if
php2go
.
Stripos
(
keyOne
,
"17."
,
0
)
>
-
1
{
if
strings
.
Contains
(
feeone
,
"cn"
)
{
var
extendFee
ExtendFee
json
.
Unmarshal
([]
byte
(
feeone
),
&
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
}
}
}
//获取供应商货期
if
canals
!=
nil
{
//专营货期
supplierRatios
:=
gredis
.
Hmget
(
"default_r"
,
"supp_ratio"
,
canals
)
for
dkey
,
supplierRatio
:=
range
supplierRatios
{
if
supplierRatio
==
""
{
AllDelivery
[
dkey
][
"cn_delivery"
]
=
""
AllDelivery
[
dkey
][
"hk_delivery"
]
=
""
continue
}
cnDeliveryTime
:=
gjson
.
Get
(
supplierRatio
,
"cn_delivery_time"
)
.
String
()
usDeliveryTime
:=
gjson
.
Get
(
supplierRatio
,
"us_delivery_time"
)
.
String
()
//为了兼容供应商修改的问题
if
cnDeliveryTime
!=
"周"
&&
cnDeliveryTime
!=
"天"
{
AllDelivery
[
dkey
][
"cn_delivery"
]
=
gjson
.
Get
(
supplierRatio
,
"cn_delivery_time"
)
.
String
()
}
else
{
AllDelivery
[
dkey
][
"cn_delivery"
]
=
""
}
if
usDeliveryTime
!=
"周"
&&
usDeliveryTime
!=
"天"
{
AllDelivery
[
dkey
][
"hk_delivery"
]
=
gjson
.
Get
(
supplierRatio
,
"us_delivery_time"
)
.
String
()
}
else
{
AllDelivery
[
dkey
][
"hk_delivery"
]
=
""
}
}
}
if
supplierIds
!=
nil
{
//代购货期
supplierRatios
:=
gredis
.
Hmget
(
"default_r"
,
"SUPPLIER_REDIS_INFO_"
,
supplierIds
)
for
dkey
,
sinfo
:=
range
supplierRatios
{
cnDelivery
:=
gjson
.
Get
(
sinfo
,
"cn_delivery"
)
.
String
()
hkDelivery
:=
gjson
.
Get
(
sinfo
,
"hk_delivery"
)
.
String
()
if
cnDelivery
!=
""
||
hkDelivery
!=
""
{
AllDelivery
[
dkey
][
"cn_delivery"
]
=
cnDelivery
AllDelivery
[
dkey
][
"hk_delivery"
]
=
hkDelivery
return
}
else
{
AllDelivery
[
dkey
][
"cn_delivery"
]
=
""
AllDelivery
[
dkey
][
"hk_delivery"
]
=
""
}
}
}
//批量获取联营tags-标签
if
lyGoodsId
!=
nil
{
goodsTagArr
:=
gredis
.
Hmget
(
"default_r"
,
"goods_tag"
,
lyGoodsId
)
var
tags
[]
int
for
goods_id
,
goodsTagsStr
:=
range
goodsTagArr
{
if
goodsTagsStr
==
""
{
continue
}
var
tagNames
[]
string
var
goodsTags
model
.
GoodsTag
skuStr
:=
redisLySkuArr
[
goods_id
]
source
:=
gjson
.
Get
(
skuStr
,
"source"
)
.
Int
()
goods_label
:=
gjson
.
Get
(
skuStr
,
"goods_label"
)
.
String
()
org_id
:=
gjson
.
Get
(
skuStr
,
"org_id"
)
.
Int
()
goodsLabelType
:=
int
(
gjson
.
Get
(
goodsTagsStr
,
"goods_label"
)
.
Int
())
goodsLabelMap
:=
vars
.
GoodsLabel
goodsTags
.
GoodsLabelName
=
goodsLabelMap
[
goodsLabelType
]
goodsTags
.
GoodsLabel
=
goodsLabelType
//自定义标签
customerTag
:=
gjson
.
Get
(
goodsTagsStr
,
"customer_tag"
)
.
String
()
if
customerTag
!=
""
{
customerTagArr
:=
php2go
.
Explode
(
" "
,
php2go
.
Trim
(
customerTag
))
for
_
,
cname
:=
range
customerTagArr
{
//如果是爱智的话,去掉可议价标签
if
org_id
==
3
&&
cname
==
"可议价"
{
continue
}
tagNames
=
append
(
tagNames
,
cname
)
}
}
if
source
==
12
{
if
!
php2go
.
InArray
(
"当天发货"
,
tagNames
)
{
tagNames
=
append
(
tagNames
,
"当天发货"
)
}
}
//goods_source_tags
sourceTagsStr
:=
GoodsSourceTags
[
gconv
.
String
(
source
)]
if
sourceTagsStr
!=
""
{
systemTags
:=
gjson
.
Get
(
sourceTagsStr
,
"system_tags"
)
.
Array
()
for
_
,
tag
:=
range
systemTags
{
tagNames
=
append
(
tagNames
,
tag
.
String
())
}
}
//goods_label_tags
labelTagsStr
:=
GoodsLabelTags
[
goods_label
]
if
labelTagsStr
!=
""
{
labelTags
:=
gjson
.
Get
(
labelTagsStr
,
"system_tags"
)
.
Array
()
for
_
,
tag
:=
range
labelTags
{
tagNames
=
append
(
tagNames
,
tag
.
String
())
}
}
//去重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