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
01398960
authored
Nov 10, 2025
by
hcy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
并发问题
parent
37fbe663
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
126 additions
and
29 deletions
controller/sku_controller.go
service/service_ly.go
service/service_spu.go
controller/sku_controller.go
View file @
01398960
...
...
@@ -126,7 +126,7 @@ func CommonController(ctx *gin.Context) map[string]interface{} {
}
//设置查询公共变量
SpuService
.
SetInit
(
redisLySkuArr
,
zyGoodsId
,
lyGoodsId
)
SpuService
.
SetInit
(
redisLySkuArr
,
redisLySpuArr
,
zyGoodsId
,
lyGoodsId
)
/////////////////多线程///////////////////////////
...
...
service/service_ly.go
View file @
01398960
...
...
@@ -3,6 +3,7 @@ package service
import
(
"context"
"github.com/gogf/gf/util/gconv"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/common"
...
...
@@ -13,6 +14,7 @@ import (
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"sort"
"strings"
"sync"
)
...
...
@@ -99,9 +101,10 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, sk
sku
=
ls
.
GetGoodsClass
(
sku
,
spu
)
//仅提供价格和库存
if
sku
.
GoodsName
!=
""
&&
brandId
!=
0
{
sku
.
ErpTax
=
ls
.
GetErpTax
(
sku
.
GoodsName
,
brandName
)
erpmd5
:=
php2go
.
Md5
(
strings
.
ToUpper
(
sku
.
GoodsName
+
brandName
))
sku
.
ErpTax
=
AllErpTax
[
erpmd5
]
}
sku
.
SupplierName
=
ls
.
GetPoolSupplierName
(
sku
.
SupplierId
)
sku
.
SupplierName
=
AllSupplierName
[
gconv
.
String
(
sku
.
SupplierId
)]
if
showAttr
==
"1"
{
//获取属性
sku
.
Attrs
=
ls
.
GetSpuAttr
(
sku
.
SpuId
)
...
...
@@ -144,7 +147,7 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, sk
sku
.
ScmBrand
=
ls
.
GetScmBrand
(
brandId
)
//获取新版的标准品牌
sku
.
StandardBrand
=
ls
.
GetStandardBrand
(
brandId
)
sku
.
StandardBrand
=
AllStandardBrands
[
gconv
.
String
(
brandId
)]
//处理过期, 2022.7.13 专卖没有过期
if
sku
.
SupplierId
!=
17
&&
gjson
.
Get
(
skuStr
,
"is_expire"
)
.
Int
()
!=
0
{
...
...
@@ -278,7 +281,7 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, sk
if
(
gconv
.
Int64
(
start_time
)
-
gconv
.
Int64
(
common
.
ProTime
()))
>
2
{
println
(
"---超时:"
+
gconv
.
String
(
tag
)
+
"-----goodsId:"
+
goodsId
+
"--start_time:"
+
start_time
+
" ---end_time:"
+
common
.
ProTime
())
}
//println("---超时:" + gconv.String(tag) + "-----goodsId:" + goodsId + "--start_time:" + start_time + " ---end_time:" + common.ProTime())
}
// 获取活动
...
...
service/service_spu.go
View file @
01398960
...
...
@@ -12,16 +12,23 @@ import (
"sync"
)
var
UsdRate
float64
//美金匯率
var
AllCurrencyRate
map
[
string
]
string
//所有汇率
var
AllLyBrand
map
[
string
]
string
//所有联营品牌
var
AllSkuRawMap
map
[
string
]
string
//所有原始编码 sku_raw_map 数据
var
AllSkuLockMap
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
(
UsdRate
float64
//美金匯率
AllCurrencyRate
map
[
string
]
string
//所有汇率
AllLyBrand
map
[
string
]
string
//所有联营品牌
AllSkuRawMap
map
[
string
]
string
//所有原始编码 sku_raw_map 数据
AllSkuLockMap
map
[
string
]
string
//自营锁库库存
AllExtendFee
map
[
string
]
interface
{}
//所有附加费
AllDelivery
map
[
string
]
map
[
string
]
string
//所有货期,下标:专卖是 canl ,代购 供应商id
AllLyGoodsTag
map
[
string
]
model
.
GoodsTag
//所有联营标签
GoodsSourceTags
map
[
string
]
string
//标签a {"system_tags":["oyr","新品推荐","可议价","可替代","爆款"]}
GoodsLabelTags
map
[
string
]
string
//标签b{"system_tags":["新品推荐","可替代"]}
GoodsClassName
map
[
string
]
string
//分类名称
AllStandardBrands
map
[
string
]
model
.
StandardBrand
//标准品牌
AllErpTax
map
[
string
]
interface
{}
//获取税务信息,对接税务系统
AllSupplierName
map
[
string
]
string
//供应商名称
)
// 币种中文
var
CURRENCY_CN
=
map
[
int
]
string
{
1
:
"人民币"
,
...
...
@@ -69,7 +76,7 @@ var GoodsLabel = map[int]string{
type
SpuService
struct
{
}
// 批量获取spu+品牌
// 批量获取
spu+品牌
func
(
ss
*
SpuService
)
GetSpuList
(
skuArr
map
[
string
]
string
)
map
[
string
]
string
{
var
spuIds
[]
string
for
_
,
skuStr
:=
range
skuArr
{
...
...
@@ -78,36 +85,52 @@ func (ss *SpuService) GetSpuList(skuArr map[string]string) map[string]string {
}
//批量获取spu详情
spuList
:=
gredis
.
Hmget
(
"spu"
,
"spu"
,
spuIds
)
//批量查询普通品牌名称
brandIds
:=
make
([]
string
,
0
)
for
_
,
spuInfo
:=
range
spuList
{
//设置查询公共变量
brandId
:=
gjson
.
Get
(
spuInfo
,
"brand_id"
)
.
String
()
if
!
php2go
.
InArray
(
brandId
,
brandIds
)
{
brandIds
=
append
(
brandIds
,
brandId
)
}
}
AllLyBrand
=
gredis
.
Hmget
(
"default_r"
,
"brand"
,
brandIds
)
return
spuList
}
// 设置查询公共变量
func
(
ss
*
SpuService
)
SetInit
(
redisLySkuArr
map
[
string
]
string
,
zyGoodsId
,
lyGoodsId
[]
string
)
{
func
(
ss
*
SpuService
)
SetInit
(
redisLySkuArr
,
redisLySpuArr
map
[
string
]
string
,
zyGoodsId
,
lyGoodsId
[]
string
)
{
AllDelivery
=
make
(
map
[
string
]
map
[
string
]
string
,
0
)
//获取供应商货期
needRawGoodsIds
:=
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
brandIds
:=
make
([]
string
,
0
)
//所有品牌id
ClassIds
:=
make
([]
string
,
0
)
//所有分类id
erpMd5Key
:=
make
([]
string
,
0
)
//查询税率
//预查询
for
_
,
info
:=
range
redisLySkuArr
{
spuId
:=
gjson
.
Get
(
info
,
"spu_id"
)
.
String
()
spuInfo
:=
redisLySpuArr
[
spuId
]
//普通品牌id
brandIds
=
append
(
brandIds
,
gjson
.
Get
(
spuInfo
,
"brand_id"
)
.
String
())
}
BatchLyBrand
(
brandIds
)
//批量查询品牌
for
goods_id
,
info
:=
range
redisLySkuArr
{
supplierId
:=
gjson
.
Get
(
info
,
"supplier_id"
)
.
Int
()
supplierIdStr
:=
gconv
.
String
(
supplierId
)
source
:=
gjson
.
Get
(
info
,
"source"
)
.
Int
()
canal
:=
gjson
.
Get
(
info
,
"canal"
)
.
String
()
spuId
:=
gjson
.
Get
(
info
,
"spu_id"
)
.
String
()
spuInfo
:=
redisLySpuArr
[
spuId
]
brandId
:=
gjson
.
Get
(
spuInfo
,
"brand_id"
)
.
String
()
//分类id
spuClassId1
:=
gjson
.
Get
(
spuInfo
,
"class_id1"
)
.
String
()
spuClassId2
:=
gjson
.
Get
(
spuInfo
,
"class_id2"
)
.
String
()
spuClassId3
:=
gjson
.
Get
(
spuInfo
,
"class_id3"
)
.
String
()
ClassIds
=
append
(
ClassIds
,
[]
string
{
spuClassId1
,
spuClassId2
,
spuClassId3
}
...
)
//普通品牌id
brandIds
=
append
(
brandIds
,
brandId
)
//erp-key
spuName
:=
gjson
.
Get
(
spuInfo
,
"spu_name"
)
.
String
()
if
spuName
!=
""
{
erpmd5
:=
php2go
.
Md5
(
strings
.
ToUpper
(
spuName
+
AllLyBrand
[
brandId
]))
erpMd5Key
=
append
(
erpMd5Key
,
erpmd5
)
}
sourceStr
:=
gconv
.
String
(
source
)
if
!
php2go
.
InArray
(
sourceStr
,
sourceIds
)
{
...
...
@@ -143,6 +166,19 @@ func (ss *SpuService) SetInit(redisLySkuArr map[string]string, zyGoodsId, lyGood
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
()
BatchLyClassName
(
ClassIds
)
//批量查询分类
}()
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
BatchErpTax
(
erpMd5Key
)
//批量查询品牌
}()
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
...
...
@@ -189,6 +225,64 @@ func (ss *SpuService) SetInit(redisLySkuArr map[string]string, zyGoodsId, lyGood
}
// 获取税务信息,对接税务系统
func
BatchErpTax
(
upmd5Str
[]
string
)
{
taxArr
:=
gredis
.
Hmget
(
"default_r"
,
"tax_customs_info"
,
removeDuplicateString
(
upmd5Str
))
//批量查询品牌
AllErpTax
=
make
(
map
[
string
]
interface
{},
0
)
for
md5k
,
info
:=
range
taxArr
{
data
:=
make
(
map
[
string
]
interface
{})
if
gjson
.
Get
(
info
,
"tax_rate_low"
)
.
String
()
!=
""
||
gjson
.
Get
(
info
,
"supervision_con"
)
.
Int
()
>
0
{
data
[
"tariffRate"
]
=
gjson
.
Get
(
info
,
"tax_rate_low"
)
.
String
()
data
[
"types"
]
=
gjson
.
Get
(
info
,
"supervision_con"
)
.
String
()
AllErpTax
[
md5k
]
=
data
}
else
{
AllErpTax
[
md5k
]
=
false
}
}
}
// 获取联营供应商的名字
func
BatchGetSupplierName
(
supplierId
[]
string
)
{
AllSupplierName
=
gredis
.
Hmget
(
"default_r"
,
"supplier"
,
removeDuplicateString
(
supplierId
))
//批量查询品牌
}
// 批量查询分类名称
func
BatchLyClassName
(
classIds
[]
string
)
{
GoodsClassName
=
make
(
map
[
string
]
string
)
allClass
:=
gredis
.
Hmget
(
"default_r"
,
"pool_class_info"
,
removeDuplicateString
(
classIds
))
//批量查询品牌
for
classId
,
info
:=
range
allClass
{
className
:=
gjson
.
Get
(
info
,
"class_name"
)
.
String
()
GoodsClassName
[
classId
]
=
className
}
}
// 批量查询品牌
func
BatchLyBrand
(
brandIds
[]
string
)
{
brandIds
=
removeDuplicateString
(
brandIds
)
AllLyBrand
=
gredis
.
Hmget
(
"default_r"
,
"brand"
,
brandIds
)
//批量查询普通品牌
brandMappingArr
:=
gredis
.
Hmget
(
"default_r"
,
"standard_brand_mapping"
,
brandIds
)
//查询品牌映射品牌
standardBrandIds
:=
make
([]
string
,
0
)
for
_
,
standardBrandId
:=
range
brandMappingArr
{
if
standardBrandId
!=
""
{
standardBrandIds
=
append
(
standardBrandIds
,
standardBrandId
)
}
}
standardBrandArr
:=
gredis
.
Hmget
(
"default_r"
,
"standard_brand"
,
removeDuplicateString
(
standardBrandIds
))
//查询品牌映射品牌
AllStandardBrands
=
make
(
map
[
string
]
model
.
StandardBrand
)
for
brandId
,
standardBrandId
:=
range
brandMappingArr
{
//普通品牌id=>标品
standardBrandStr
:=
standardBrandArr
[
standardBrandId
]
var
standardBrand
model
.
StandardBrand
if
standardBrandStr
!=
""
{
standardBrand
.
BrandName
=
gjson
.
Get
(
standardBrandStr
,
"brand_name"
)
.
String
()
standardBrand
.
StandardBrandId
=
int
(
gjson
.
Get
(
standardBrandStr
,
"standard_brand_id"
)
.
Int
())
standardBrand
.
BrandLogo
=
gjson
.
Get
(
standardBrandStr
,
"brandLogo"
)
.
String
()
AllStandardBrands
[
brandId
]
=
standardBrand
}
}
}
// 批量获取汇率
func
BatchCurrency
()
{
AllCurrencyRate
=
gredis
.
Hmget
(
"default_r"
,
"erp_rate"
,
[]
string
{
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"10"
,
"11"
,
"12"
,
"13"
})
...
...
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