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
2a5fcbf0
authored
Mar 03, 2025
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'ysx-tme重量需求-20250228' into dev
# Conflicts: # model/ly_sku.go
parents
eacff7c5
1fc9cbab
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
6 deletions
model/ly_sku.go
pkg/common/function.go
model/ly_sku.go
View file @
2a5fcbf0
...
...
@@ -154,10 +154,9 @@ type SpuExtra struct {
SpuId
string
`bson:"spu_id" json:"spu_id"`
Height
string
`json:"height" bson:"height"`
Weight
string
`json:"-" bson:"weight"`
TransformedWeight
int
`json:"weight"`
TransformedWeight
float64
`json:"weight"`
Width
string
`json:"width" bson:"width"`
Length
string
`json:"length" bson:"length"`
EnPdfUrl
string
`bson:"en_pdf_url" json:"en_pdf_url"`
}
// 为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
...
...
pkg/common/function.go
View file @
2a5fcbf0
...
...
@@ -627,7 +627,7 @@ func DivFloat(first float64, second float64) float64 {
}
// 将重量单位统一转换为克,同时清洗数据
func
ConvertToGrams
(
input
string
)
(
int
,
error
)
{
func
ConvertToGrams
(
input
string
)
(
float64
,
error
)
{
// 清洗数据:去除左右空格,去除中间空格
input
=
strings
.
ReplaceAll
(
strings
.
TrimSpace
(
input
),
" "
,
""
)
...
...
@@ -654,11 +654,13 @@ func ConvertToGrams(input string) (int, error) {
// 根据单位返回对应的克数
switch
unit
{
case
"kg"
,
"千克"
:
return
int
(
num
*
1000
),
nil
return
float64
(
num
*
1000
),
nil
case
"g"
,
"克"
:
return
int
(
num
),
nil
return
float64
(
num
),
nil
case
"t"
,
"吨"
:
return
int
(
num
*
1000000
),
nil
return
float64
(
num
*
1000000
),
nil
case
"mg"
,
"毫克"
:
return
float64
(
num
/
1000
),
nil
default
:
return
0
,
fmt
.
Errorf
(
"未知的重量单位: %s"
,
unit
)
}
...
...
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