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
eacff7c5
authored
Feb 28, 2025
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'ysx-tme重量需求-20250228' into dev
# Conflicts: # model/ly_sku.go
parents
6f9c359b
a68834bb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
10 deletions
model/ly_sku.go
pkg/common/function.go
service/service_ly.go
model/ly_sku.go
View file @
eacff7c5
...
@@ -150,8 +150,13 @@ type SpuExtra struct {
...
@@ -150,8 +150,13 @@ type SpuExtra struct {
Thumbnail
string
`bson:"thumbnail" json:"thumbnail"`
Thumbnail
string
`bson:"thumbnail" json:"thumbnail"`
}
`bson:"image_list" json:"image_list"`
}
`bson:"image_list" json:"image_list"`
SpuDetail
string
`bson:"spu_detail" json:"spu_detail"`
SpuDetail
string
`bson:"spu_detail" json:"spu_detail"`
SpuId
string
`bson:"spu_id" json:"spu_id"`
SpuId
string
`bson:"spu_id" json:"spu_id"`
Height
string
`json:"height" bson:"height"`
Weight
string
`json:"-" bson:"weight"`
TransformedWeight
int
`json:"weight"`
Width
string
`json:"width" bson:"width"`
Length
string
`json:"length" bson:"length"`
EnPdfUrl
string
`bson:"en_pdf_url" json:"en_pdf_url"`
EnPdfUrl
string
`bson:"en_pdf_url" json:"en_pdf_url"`
}
}
...
...
pkg/common/function.go
View file @
eacff7c5
...
@@ -625,3 +625,41 @@ func MulFloat(first float64, args ...float64) float64 {
...
@@ -625,3 +625,41 @@ func MulFloat(first float64, args ...float64) float64 {
func
DivFloat
(
first
float64
,
second
float64
)
float64
{
func
DivFloat
(
first
float64
,
second
float64
)
float64
{
return
((
first
*
1000000000
)
/
(
second
*
1000000000
))
return
((
first
*
1000000000
)
/
(
second
*
1000000000
))
}
}
// 将重量单位统一转换为克,同时清洗数据
func
ConvertToGrams
(
input
string
)
(
int
,
error
)
{
// 清洗数据:去除左右空格,去除中间空格
input
=
strings
.
ReplaceAll
(
strings
.
TrimSpace
(
input
),
" "
,
""
)
// 分离数字和单位
var
numStr
,
unit
string
for
i
,
char
:=
range
input
{
if
char
>=
'0'
&&
char
<=
'9'
||
char
==
'.'
{
numStr
+=
string
(
char
)
}
else
{
unit
=
input
[
i
:
]
break
}
}
// 将数字部分转换为浮点数
num
,
err
:=
strconv
.
ParseFloat
(
numStr
,
64
)
if
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"无效的数字: %s"
,
numStr
)
}
// 将单位转换为小写,方便匹配
unit
=
strings
.
ToLower
(
unit
)
// 根据单位返回对应的克数
switch
unit
{
case
"kg"
,
"千克"
:
return
int
(
num
*
1000
),
nil
case
"g"
,
"克"
:
return
int
(
num
),
nil
case
"t"
,
"吨"
:
return
int
(
num
*
1000000
),
nil
default
:
return
0
,
fmt
.
Errorf
(
"未知的重量单位: %s"
,
unit
)
}
}
\ No newline at end of file
service/service_ly.go
View file @
eacff7c5
package
service
package
service
import
(
import
(
"fmt"
"go_sku_server/model"
"go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/logger"
"go_sku_server/pkg/logger"
"go_sku_server/pkg/mongo"
"go_sku_server/pkg/mongo"
...
@@ -83,7 +85,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
...
@@ -83,7 +85,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
//获取商品名称
//获取商品名称
//1688就是mro的sku spuName和GoodsName不是一个东西,不能公用
//1688就是mro的sku spuName和GoodsName不是一个东西,不能公用
if
sku
.
GoodsName
!=
""
&&
(
sku
.
SupplierId
==
1688
||
sku
.
Canal
==
"L0015730"
)
{
if
sku
.
GoodsName
!=
""
&&
(
sku
.
SupplierId
==
1688
||
sku
.
OrgId
==
3
)
{
sku
.
GoodsName
=
gjson
.
Get
(
spu
,
"spu_name"
)
.
String
()
sku
.
GoodsName
=
gjson
.
Get
(
spu
,
"spu_name"
)
.
String
()
}
}
if
sku
.
GoodsName
==
""
{
if
sku
.
GoodsName
==
""
{
...
@@ -170,8 +172,11 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
...
@@ -170,8 +172,11 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
//1是猎芯,3是爱智
//1是猎芯,3是爱智
switch
sku
.
OrgId
{
switch
sku
.
OrgId
{
case
1
:
case
1
:
//获取系数和价格
//如果是寄售的,也不走价格体系
sku
=
ls
.
GetCoefficientAndPrice
(
sku
)
if
sku
.
Source
!=
12
{
//获取系数和价格
sku
=
ls
.
GetCoefficientAndPrice
(
sku
)
}
break
break
case
3
:
case
3
:
priceService
:=
PriceService
{}
priceService
:=
PriceService
{}
...
@@ -287,6 +292,10 @@ func (ls *LyService) GetSpuExtra(spuId string) (spuExtra model.SpuExtra) {
...
@@ -287,6 +292,10 @@ func (ls *LyService) GetSpuExtra(spuId string) (spuExtra model.SpuExtra) {
if
err
!=
nil
&&
err
!=
mgo
.
ErrNotFound
{
if
err
!=
nil
&&
err
!=
mgo
.
ErrNotFound
{
logger
.
Select
(
"sku_query"
)
.
Error
(
err
.
Error
())
logger
.
Select
(
"sku_query"
)
.
Error
(
err
.
Error
())
}
}
fmt
.
Println
(
spuExtra
.
Weight
)
if
spuExtra
.
Weight
!=
""
{
spuExtra
.
TransformedWeight
,
_
=
common
.
ConvertToGrams
(
spuExtra
.
Weight
)
}
//兼容老版本数据
//兼容老版本数据
if
len
(
spuExtra
.
ImageList
)
==
0
{
if
len
(
spuExtra
.
ImageList
)
==
0
{
...
@@ -299,15 +308,12 @@ func (ls *LyService) GetSpuExtra(spuId string) (spuExtra model.SpuExtra) {
...
@@ -299,15 +308,12 @@ func (ls *LyService) GetSpuExtra(spuId string) (spuExtra model.SpuExtra) {
var
oldSpuExtra
OldSpuExtra
var
oldSpuExtra
OldSpuExtra
err
=
mongodb
.
DB
(
"ichunt"
)
.
C
(
"spu_extra"
)
.
Find
(
bson
.
M
{
"spu_id"
:
spuId
})
.
One
(
&
oldSpuExtra
)
err
=
mongodb
.
DB
(
"ichunt"
)
.
C
(
"spu_extra"
)
.
Find
(
bson
.
M
{
"spu_id"
:
spuId
})
.
One
(
&
oldSpuExtra
)
for
_
,
image
:=
range
oldSpuExtra
.
OldImageList
{
for
_
,
image
:=
range
oldSpuExtra
.
OldImageList
{
spuExtra
.
ImageList
=
append
(
spuExtra
.
ImageList
,
struct
{
spuExtra
.
ImageList
=
append
(
spuExtra
.
ImageList
,
struct
{
Name
string
`bson:"name" json:"name"`
Name
string
`bson:"name" json:"name"`
Thumbnail
string
`bson:"thumbnail" json:"thumbnail"`
Thumbnail
string
`bson:"thumbnail" json:"thumbnail"`
}{
}{
Name
:
image
.
Name
,
Name
:
image
.
Name
,
Thumbnail
:
image
.
Thumbnail
,
Thumbnail
:
image
.
Thumbnail
,
})
})
}
}
...
...
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