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
5e4bd169
authored
Jan 12, 2026
by
hcy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
控制商品购买按钮
parent
465ee58b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
153 additions
and
1 deletions
cmd/http_server.go
model/ly_sku.go
model/supplier.go
pkg/common/function.go
service/service_activity.go
service/service_ly.go
service/service_zy.go
service/supplier.go
cmd/http_server.go
View file @
5e4bd169
...
...
@@ -7,6 +7,7 @@ import (
"go_sku_server/boot"
"go_sku_server/pkg/config"
"go_sku_server/routes"
service2
"go_sku_server/service"
)
func
main
()
{
...
...
@@ -26,11 +27,20 @@ func main() {
web
.
Handler
(
r
),
web
.
Address
(
":"
+
port
),
)
service2
.
Supplier
.
GetSupplierForbidMap
()
////初始化禁用规则
//go func() {
// for true {
// service2.Supplier.GetSupplierForbidMap()
// time.Sleep(3600 * time.Second)
// }
//}()
if
err
:=
service
.
Init
();
err
!=
nil
{
panic
(
err
)
}
if
err
:=
service
.
Run
();
err
!=
nil
{
panic
(
err
)
}
}
model/ly_sku.go
View file @
5e4bd169
...
...
@@ -92,6 +92,7 @@ type LySku struct {
Tariff
float64
`json:"tariff"`
TariffFormat
string
`json:"tariff_format"`
AbilityLevel
int
`json:"ability_level"`
LabelOp
int
`json:"label_op"`
BrandPack
string
`json:"brand_pack"`
OnwayStock
int
`json:"onway_stock"`
}
...
...
model/supplier.go
0 → 100644
View file @
5e4bd169
package
model
// 供应商禁用信息map
type
SupplierForbidMap
map
[
string
]
ForbidInfo
// 供应商禁止信息,会转换一次
type
ForbidInfo
struct
{
SupplierId
int
`json:"supplier_id"`
// 供应商id
StandardBrandIds
[]
int
// 禁止标准品牌列表
Eccns
[]
string
// 禁止eccn列表
GoodsNames
[]
string
// 禁止型号列表
SkuIds
[]
string
// 禁止sku_ids
SpuIds
[]
string
// 禁止spu_ids
ClassId1
[]
string
//
ClassId2
[]
string
//
EccnNo
[]
string
// 白名单 eccn
}
// 供应商禁止信息, redis中存储的
type
RedisForbidInfo
struct
{
SupplierId
int
`json:"supplier_id"`
// 供应商id
StandardBrandId
string
`json:"standard_brand_id"`
// 禁止标准品牌,多个用,分割 8,130
Eccn
string
`json:"eccn"`
// 禁止eccn ,多个用,分割 %3A001%,%3A292%
GoodsName
string
`json:"goods_name"`
// 禁止型号,多个用 € 分割
SkuId
string
`json:"sku_id"`
// 禁止sku_id多个用 € 分割
SpuId
string
`json:"spu_id"`
// 禁止spu_id多个用 € 分割
ClassId1
string
`json:"class_id1"`
ClassId2
string
`json:"class_id2"`
EccnNo
string
`json:"eccn_no"`
// 白名单 eccn
}
pkg/common/function.go
View file @
5e4bd169
...
...
@@ -27,6 +27,49 @@ import (
"github.com/tidwall/gjson"
)
func
GetMd5KeyUpper
(
str
string
)
string
{
lowerStr
:=
strings
.
ToUpper
(
str
)
// 创建 MD5 散列对象
hash
:=
md5
.
New
()
// 计算字符串的 MD5 散列值
hash
.
Write
([]
byte
(
lowerStr
))
// 获取计算后的 MD5 散列值
hashed
:=
hash
.
Sum
(
nil
)
// 将散列值转换为十六进制字符串表示
md5Str
:=
hex
.
EncodeToString
(
hashed
)
return
md5Str
}
// 判断是否在字符串数组切片中
func
InStringArray
(
needle
string
,
haystack
[]
string
)
bool
{
for
_
,
item
:=
range
haystack
{
if
item
==
needle
{
return
true
}
}
return
false
}
func
InIntArray
(
target
int
,
arr
[]
int
)
bool
{
sort
.
Ints
(
arr
)
index
:=
sort
.
SearchInts
(
arr
,
target
)
return
index
<
len
(
arr
)
&&
arr
[
index
]
==
target
}
// ReplaceSpecialCharts 替换特殊字符
func
ReplaceSpecialCharts
(
str
string
)
string
{
reg
:=
regexp
.
MustCompile
(
`[^A-Za-z0-9]+`
)
return
reg
.
ReplaceAllString
(
str
,
""
)
}
func
GetUpperAndTrimStr
(
str
string
)
string
{
// 使用 Fields 方法将字符串拆分为单词,并重新组合
words
:=
strings
.
Fields
(
str
)
filteredStr
:=
strings
.
Join
(
words
,
""
)
upperStr
:=
strings
.
ToUpper
(
filteredStr
)
return
upperStr
}
/*
gjson 判断某值是否存在 map
@param json string 分析json字符串
...
...
service/service_activity.go
View file @
5e4bd169
...
...
@@ -19,6 +19,51 @@ import (
type
ActivityService
struct
{
}
/*
控制前端3.0购买 加入购物车 联系销售等按钮
https://www.tapd.cn/tapd_fe/20225591/story/detail/1120225591001012052
todo 1 加入购物车、立即购买 :
6项条件须同时满足
是否属于网站屏蔽范围:不属于
商品状态:上架
商品是否过期:否
库存数量:不为空,且,>0,且,≥起订量
商品价格:不为空,且,>0(人民币、美金价格至少有一个满足)
履约程度:强履约
todo 2 加入询价池、立即询价
6项条件须同时满足
是否属于网站屏蔽范围:不属于
商品状态:上架
商品是否过期:否
库存数量:不为空,且,>0,且,≥起订量
商品价格:不为空,且,>0(人民币、美金价格至少有一个满足)
履约程度:强履约
todo 3 联系销售
规则1 且 规则2 不符合
*/
func
(
as
*
ActivityService
)
GetLabelOp
(
sku
model
.
LySku
)
(
op
int
)
{
var
taxCheck
map
[
string
]
map
[
string
]
string
if
sku
.
SupplierId
==
7
{
taxCheck
=
Supplier
.
GetTaxMap
([]
string
{
sku
.
GoodsName
},
"3C目录内"
)
}
forbidStatus
,
_
:=
Supplier
.
GetSkuForbidStatus
(
sku
.
SupplierId
,
sku
.
StandardBrand
.
StandardBrandId
,
sku
.
GoodsName
,
sku
.
GoodsId
,
sku
.
Eccn
,
sku
.
SpuId
,
sku
.
Canal
,
gconv
.
String
(
sku
.
ClassID1
),
gconv
.
String
(
sku
.
ClassID2
),
taxCheck
)
if
sku
.
GoodsStatus
==
1
&&
sku
.
IsExpire
==
0
&&
forbidStatus
==
0
&&
sku
.
Stock
>
0
&&
sku
.
LadderPrice
!=
nil
{
if
sku
.
AbilityLevel
==
2
{
return
1
//可购买
}
else
{
return
2
//立即询价
}
}
else
{
return
3
//联系销售
}
}
// 获取活动信息,目前是包括促销活动(系数打折)以及满赠活动
func
(
as
*
ActivityService
)
GetActivityData
(
checkData
model
.
ActivityCheckData
)
(
priceActivity
model
.
PriceActivity
,
giftActivity
model
.
GiftActivity
)
{
supplierId
:=
checkData
.
SupplierId
...
...
service/service_ly.go
View file @
5e4bd169
...
...
@@ -73,6 +73,7 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, go
skuArr
:=
gredis
.
Hmget
(
"default_r"
,
"sku"
,
goodsIds
)
//为了性能着想,这边也先去批量获取spu的信息
var
spuService
SpuService
var
activityService
ActivityService
spuList
:=
spuService
.
getSpuList
(
skuArr
)
GoodsRes
:=
sync
.
Map
{}
...
...
@@ -327,6 +328,8 @@ func (ls *LyService) LyGoodsDetail(ctx context.Context, params RequestParams, go
if
has
{
sku
.
Stock
=
int64
(
limitStock
)
}
//计算按钮
sku
.
LabelOp
=
activityService
.
GetLabelOp
(
sku
)
//最后一步,将sku的全部信息放到有序map里面
GoodsRes
.
Store
(
goodsId
,
sku
)
//(*goodsRes)[goodsId] = A
...
...
service/service_zy.go
View file @
5e4bd169
...
...
@@ -2,6 +2,7 @@ package service
import
(
"context"
"github.com/gogf/gf/util/gconv"
"go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
...
...
@@ -126,10 +127,15 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx context.Context, params RequestParams
spuId
:=
gjson
.
Get
(
info
,
"spu_id"
)
.
Int
()
var
standardBrand
model
.
StandardBrand
var
brandId
int64
var
spuClassId1
int64
var
spuClassId2
int64
var
brandName
string
var
activityService
ActivityService
if
spuId
!=
0
{
spuStr
,
_
:=
gredis
.
String
(
redisConnSpu
.
Do
(
"HGET"
,
"spu"
,
spuId
))
brandId
=
gjson
.
Get
(
spuStr
,
"brand_id"
)
.
Int
()
spuClassId1
=
gjson
.
Get
(
spuStr
,
"class_id1"
)
.
Int
()
spuClassId2
=
gjson
.
Get
(
spuStr
,
"class_id2"
)
.
Int
()
brandName
,
_
=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"brand"
,
brandId
))
var
ly
LyService
standardBrand
=
ly
.
GetStandardBrand
(
brandId
)
...
...
@@ -353,6 +359,20 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx context.Context, params RequestParams
A
.
Set
(
"canal"
,
"L0003270"
)
//自营写死编码
//todo 计算购买按钮
nowstock
,
_
:=
A
.
Get
(
"stock"
)
var
lySku
=
model
.
LySku
{
GoodsId
:
goodsId
,
Stock
:
gconv
.
Int64
(
nowstock
),
AbilityLevel
:
2
,
StandardBrand
:
standardBrand
,
GoodsName
:
gjson
.
Get
(
info
,
"goods_name"
)
.
String
(),
SpuId
:
gconv
.
String
(
spuId
),
ClassID1
:
gconv
.
Int
(
spuClassId1
),
ClassID2
:
gconv
.
Int
(
spuClassId2
),
}
A
.
Set
(
"label_op"
,
activityService
.
GetLabelOp
(
lySku
))
//最后写入sync map
(
GoodsRes
)
.
Store
(
goodsId
,
A
)
}
...
...
service/supplier.go
0 → 100644
View file @
5e4bd169
This diff is collapsed.
Click to expand it.
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