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
03c6a0b0
authored
Jun 19, 2023
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'ysx-专营商品构建阶梯价-20230612' into dev
parents
b675f9a6
d1c73493
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
14 deletions
service/service_ly_common.go
service/service_price.go
service/service_ly_common.go
View file @
03c6a0b0
...
...
@@ -198,8 +198,11 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if
len
(
ladderPrice
)
>
0
{
if
ladderPrice
[
0
]
.
PriceCostUs
==
0
&&
ladderPrice
[
0
]
.
PriceCostCn
==
0
{
var
priceService
PriceService
ladderPrice
=
priceService
.
GenerateLadderPrice
(
sku
)
generatedLadderPrice
,
priceRatio
:=
priceService
.
GenerateLadderPrice
(
sku
)
ladderPrice
=
generatedLadderPrice
//sku.Original = ladderPrice
sku
.
PriceRatio
=
priceRatio
sku
.
PriceRatioSort
=
-
1
}
else
{
fmt
.
Println
(
"不走成本价生成"
)
}
...
...
service/service_price.go
View file @
03c6a0b0
...
...
@@ -40,7 +40,7 @@ func (ls *LyService) TransformSpecialSupplierPrice(supplierId int64, priceUs flo
}
//构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价
func
(
ps
*
PriceService
)
GenerateLadderPrice
(
sku
model
.
LySku
)
(
generatedLadderPrice
[]
model
.
LadderPrice
)
{
func
(
ps
*
PriceService
)
GenerateLadderPrice
(
sku
model
.
LySku
)
(
generatedLadderPrice
[]
model
.
LadderPrice
,
showPriceRatio
[]
model
.
PriceRatio
)
{
//先直接获取成本价原始值,判断第一个阶梯的阶梯数量是否为0,如果是0,那么代表是要走成本价生成,如果不是0,那么就要走阶梯价生成
firstLadderPurchases
:=
sku
.
LadderPrice
[
0
]
.
Purchases
isCostPrice
:=
bool
(
firstLadderPurchases
==
0
)
...
...
@@ -51,9 +51,9 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
priceRatio
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"magic_cube_price_rule_v2"
,
sku
.
Canal
))
//拿不到就直接返回空价格,防止低价售卖
if
priceRatio
==
""
{
return
nil
return
nil
,
nil
}
//这是用来展示在商品服务的价格系数,专营的系数和代购的不一样,所以要转换一下展示形式
//是否有设置最低利润点阶梯,不足5个阶梯时,最高阶梯对应的最小利润点阶梯
ladderPriceMiniProfitLevel
:=
int
(
gjson
.
Get
(
priceRatio
,
"ladder_price_mini_profit_level"
)
.
Int
())
//判断是否走成本价判断还是走阶梯价判断,因为上传sku的时候,可以设置每个sku的成本价(人民币&&美金),也可以设置每个sku的阶梯价
...
...
@@ -81,16 +81,20 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
//然后根据一开始只有一个的阶梯价去生成阶梯价格
for
purchases
,
ratio
:=
range
fixedRatio
{
//同时还要构建价格系数展示在商品服务
showPriceRatio
=
append
(
showPriceRatio
,
model
.
PriceRatio
{
Ratio
:
ratio
,
RatioUsd
:
ratio
})
generatedLadderPrice
=
append
(
generatedLadderPrice
,
model
.
LadderPrice
{
Purchases
:
int64
(
purchases
),
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceCn
,
ratio
),
4
),
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceUs
,
ratio
),
4
),
})
}
sku
.
PriceRatio
=
showPriceRatio
sort
.
Slice
(
generatedLadderPrice
,
func
(
i
,
j
int
)
bool
{
return
generatedLadderPrice
[
i
]
.
Purchases
<
generatedLadderPrice
[
j
]
.
Purchases
})
return
generatedLadderPrice
return
generatedLadderPrice
,
showPriceRatio
}
//判断最小起订量是属于哪个范围
ratioKey
:=
""
...
...
@@ -131,12 +135,16 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
}
priceRatioAndPurchases
=
costLadderPriceRatio
[
strconv
.
Itoa
(
costMapIndex
)]
fmt
.
Println
(
"获取到的阶梯系数为 : "
,
priceRatioAndPurchases
)
priceCnRatio
:=
priceRatioAndPurchases
.
Get
(
"price"
)
.
Float
()
priceUsRatio
:=
priceRatioAndPurchases
.
Get
(
"price_usd"
)
.
Float
()
// 阶梯价格系数正序取
showPriceRatio
=
append
(
showPriceRatio
,
model
.
PriceRatio
{
Ratio
:
priceCnRatio
,
RatioUsd
:
priceUsRatio
})
generatedLadderPrice
=
append
(
generatedLadderPrice
,
model
.
LadderPrice
{
Purchases
:
costPurchases
,
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceCn
,
price
RatioAndPurchases
.
Get
(
"price"
)
.
Float
()
),
4
),
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceUs
,
price
RatioAndPurchases
.
Get
(
"price_usd"
)
.
Float
()
),
4
),
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceCn
,
price
CnRatio
),
4
),
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceUs
,
price
UsRatio
),
4
),
})
sku
.
PriceRatio
=
showPriceRatio
}
}
else
{
//价格阶梯数量超过最利润点的层级的情况
...
...
@@ -148,16 +156,19 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
if
costPurchases
>
sku
.
Stock
{
break
}
fmt
.
Println
(
costPriceCn
)
priceCnRatio
:=
priceRatioAndPurchases
.
Get
(
"price"
)
.
Float
()
priceUsRatio
:=
priceRatioAndPurchases
.
Get
(
"price_usd"
)
.
Float
()
showPriceRatio
=
append
(
showPriceRatio
,
model
.
PriceRatio
{
Ratio
:
priceCnRatio
,
RatioUsd
:
priceUsRatio
})
// 阶梯价格系数正序取
generatedLadderPrice
=
append
(
generatedLadderPrice
,
model
.
LadderPrice
{
Purchases
:
sku
.
Moq
*
priceRatioAndPurchases
.
Get
(
"purchases"
)
.
Int
(),
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceCn
,
price
RatioAndPurchases
.
Get
(
"price"
)
.
Float
()
),
4
),
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceUs
,
price
RatioAndPurchases
.
Get
(
"price_usd"
)
.
Float
()
),
4
),
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceCn
,
price
CnRatio
),
4
),
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceUs
,
price
UsRatio
),
4
),
})
}
sku
.
PriceRatio
=
showPriceRatio
}
return
generatedLadderPrice
return
generatedLadderPrice
,
showPriceRatio
}
else
{
ladderPriceRatio
:=
gjson
.
Get
(
priceRatio
,
"ladder_price_egt50_lt200"
)
.
Map
()
fmt
.
Println
(
ladderPriceRatio
)
...
...
@@ -176,19 +187,27 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
fmt
.
Println
(
costMapIndex
)
priceRatio
:=
ladderPriceRatio
[
strconv
.
Itoa
(
costMapIndex
)]
fmt
.
Println
(
"获取到的阶梯系数为 : "
,
priceRatio
)
priceCnRatio
:=
priceRatio
.
Get
(
"ratio"
)
.
Float
()
priceUsRatio
:=
priceRatio
.
Get
(
"ratio_usd"
)
.
Float
()
showPriceRatio
=
append
(
showPriceRatio
,
model
.
PriceRatio
{
Ratio
:
priceCnRatio
,
RatioUsd
:
priceUsRatio
})
// 阶梯价格系数正序取
generatedLadderPrice
=
append
(
generatedLadderPrice
,
model
.
LadderPrice
{
Purchases
:
ladder
.
Purchases
,
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
ladder
.
PriceCn
,
price
Ratio
.
Get
(
"ratio"
)
.
Float
()
),
4
),
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
ladder
.
PriceUs
,
price
Ratio
.
Get
(
"ratio_usd"
)
.
Float
()
),
4
),
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
ladder
.
PriceCn
,
price
CnRatio
),
4
),
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
ladder
.
PriceUs
,
price
UsRatio
),
4
),
})
}
sku
.
PriceRatio
=
showPriceRatio
}
else
{
//价格阶梯数量超过最利润点的层级的情况
for
i
:=
1
;
i
<=
9
;
i
++
{
ladder
:=
sku
.
LadderPrice
[
i
-
1
]
// 阶梯数量系数正序取
priceRatio
:=
ladderPriceRatio
[
strconv
.
Itoa
(
i
)]
priceCnRatio
:=
priceRatio
.
Get
(
"ratio"
)
.
Float
()
priceUsRatio
:=
priceRatio
.
Get
(
"ratio_usd"
)
.
Float
()
showPriceRatio
=
append
(
showPriceRatio
,
model
.
PriceRatio
{
Ratio
:
priceCnRatio
,
RatioUsd
:
priceUsRatio
})
// 阶梯价格系数正序取
generatedLadderPrice
=
append
(
generatedLadderPrice
,
model
.
LadderPrice
{
Purchases
:
int64
(
ladder
.
Purchases
),
...
...
@@ -196,7 +215,8 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) (generatedLadderPri
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
ladder
.
PriceUs
,
priceRatio
.
Get
(
"ratio_usd"
)
.
Float
()),
4
),
})
}
sku
.
PriceRatio
=
showPriceRatio
}
return
generatedLadderPrice
return
generatedLadderPrice
,
showPriceRatio
}
}
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