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
ef237a7d
authored
Aug 18, 2023
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'ysx-价格体系修改-20230815' into dev
parents
1c68ef1c
99d38893
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
9 deletions
service/service_ly_common.go
service/service_price.go
service/service_ly_common.go
View file @
ef237a7d
...
...
@@ -2,6 +2,7 @@ package service
import
(
"encoding/json"
"fmt"
"github.com/gomodule/redigo/redis"
_
"github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go"
...
...
@@ -276,6 +277,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if
ladderPrice
[
0
]
.
PriceCostUs
==
0
&&
ladderPrice
[
0
]
.
PriceCostCn
==
0
{
sku
=
priceService
.
GenerateLadderPrice
(
sku
)
ladderPrice
=
sku
.
LadderPrice
fmt
.
Println
(
ladderPrice
)
}
}
//获取折扣系数
...
...
@@ -283,6 +285,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
data
=
make
([]
model
.
LadderPrice
,
len
(
ladderPrice
))
for
key
,
price
:=
range
ladderPrice
{
price
.
PriceUs
=
priceService
.
TransformSpecialSupplierPrice
(
sku
,
price
.
PriceUs
)
if
price
.
Purchases
==
0
{
continue
}
...
...
@@ -385,7 +388,6 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if
!
hasCoefficient
{
coefficient
=
defaultCoefficient
}
//下面是计算价格
//价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
...
...
@@ -393,7 +395,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
for
key
,
price
:=
range
sku
.
LadderPrice
{
//这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
//所以要全部先转成正确的美金价才能显示,目前先写死汇率,因为目前没有地方能获取实时的各种转美金的汇率
price
.
PriceUs
=
priceService
.
TransformSpecialSupplierPrice
(
sku
.
SupplierId
,
price
.
PriceUs
,
coefficient
.
Ratio
)
price
.
PriceUs
=
priceService
.
TransformSpecialSupplierPrice
(
sku
,
price
.
PriceUs
)
originalPrice
=
append
(
originalPrice
,
model
.
OriginPrice
{
PriceUs
:
price
.
PriceUs
,
Purchases
:
price
.
Purchases
,
...
...
service/service_price.go
View file @
ef237a7d
...
...
@@ -19,6 +19,8 @@ type PriceService struct {
// 构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价
func
(
ps
*
PriceService
)
GenerateLadderPrice
(
sku
model
.
LySku
)
model
.
LySku
{
//需要展示的价格系数
var
showPriceRatioList
[]
model
.
PriceRatio
//先去找到对应的价格系数
var
ratioDataKey
string
if
sku
.
Moq
<=
50
{
...
...
@@ -167,14 +169,13 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
}
priceRatioSort
=
-
1
}
sku
.
PriceRatio
=
priceRatioList
sku
.
PriceRatioSort
=
priceRatioSort
//这是用来展示在商品服务的价格系数,专营的系数和代购的不一样,所以要转换一下展示形式
//是否有设置最低利润点阶梯,不足5个阶梯时,最高阶梯对应的最小利润点阶梯
var
ladderPriceMiniProfitLevel
int
fmt
.
Println
(
"是否找到系数"
,
foundRatio
)
fmt
.
Println
(
"系数redis数据为 : "
,
priceRatioCache
)
//
fmt.Println("系数redis数据为 : ", priceRatioCache)
fmt
.
Println
(
"具体系数为 : "
,
priceRatioList
)
if
foundRatio
{
priceRatioSortStr
:=
strconv
.
Itoa
(
priceRatioSort
)
...
...
@@ -213,16 +214,21 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
fixedPurchases
=
[]
int
{
moq
,
200
,
500
,
1000
,
2000
}
break
}
for
index
,
purchase
:=
range
fixedPurchases
{
for
index
,
purchase
s
:=
range
fixedPurchases
{
//costLadderPriceRatio这个redis是字典,下标从0开始的,所以要从第5个开始取
ratio
:=
priceRatioList
[
4
+
index
]
.
Ratio
ratioUsd
:=
priceRatioList
[
4
+
index
]
.
RatioUsd
//同时还要构建价格系数展示在商品服务
generatedLadderPrice
=
append
(
generatedLadderPrice
,
model
.
LadderPrice
{
Purchases
:
int64
(
purchase
),
Purchases
:
int64
(
purchase
s
),
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceCn
,
ratio
),
4
),
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceUs
,
ratioUsd
),
4
),
})
showPriceRatioList
=
append
(
showPriceRatioList
,
model
.
PriceRatio
{
Ratio
:
ratio
,
RatioUsd
:
ratioUsd
,
Purchases
:
int64
(
purchases
),
})
}
}
else
{
...
...
@@ -247,6 +253,11 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceCn
,
ratio
),
4
),
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceUs
,
ratio
),
4
),
})
showPriceRatioList
=
append
(
showPriceRatioList
,
model
.
PriceRatio
{
Ratio
:
ratio
,
RatioUsd
:
ratio
,
Purchases
:
int64
(
purchases
),
})
}
}
...
...
@@ -254,6 +265,8 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
return
generatedLadderPrice
[
i
]
.
Purchases
<
generatedLadderPrice
[
j
]
.
Purchases
})
sku
.
LadderPrice
=
generatedLadderPrice
sku
.
PriceRatio
=
showPriceRatioList
return
sku
}
fmt
.
Println
(
"是成本价"
)
...
...
@@ -296,6 +309,11 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceCn
,
priceCnRatio
),
4
),
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceUs
,
priceUsRatio
),
4
),
})
showPriceRatioList
=
append
(
showPriceRatioList
,
model
.
PriceRatio
{
Ratio
:
priceCnRatio
,
RatioUsd
:
priceUsRatio
,
Purchases
:
int64
(
costPurchases
),
})
}
}
else
{
//价格阶梯数量超过最利润点的层级的情况
...
...
@@ -315,9 +333,15 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceCn
,
priceCnRatio
),
4
),
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
costPriceUs
,
priceUsRatio
),
4
),
})
showPriceRatioList
=
append
(
showPriceRatioList
,
model
.
PriceRatio
{
Ratio
:
priceCnRatio
,
RatioUsd
:
priceUsRatio
,
Purchases
:
int64
(
costPurchases
),
})
}
}
sku
.
LadderPrice
=
generatedLadderPrice
sku
.
PriceRatio
=
showPriceRatioList
return
sku
}
else
{
//fmt.Println(ladderPriceRatio)
...
...
@@ -344,6 +368,11 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
ladder
.
PriceCn
,
priceCnRatio
),
4
),
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
ladder
.
PriceUs
,
priceUsRatio
),
4
),
})
showPriceRatioList
=
append
(
showPriceRatioList
,
model
.
PriceRatio
{
Ratio
:
priceCnRatio
,
RatioUsd
:
priceUsRatio
,
Purchases
:
int64
(
ladder
.
Purchases
),
})
}
}
else
{
...
...
@@ -360,8 +389,14 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
ladder
.
PriceCn
,
priceCnRatio
),
4
),
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
ladder
.
PriceUs
,
priceUsRatio
),
4
),
})
showPriceRatioList
=
append
(
showPriceRatioList
,
model
.
PriceRatio
{
Ratio
:
priceCnRatio
,
RatioUsd
:
priceUsRatio
,
Purchases
:
int64
(
ladder
.
Purchases
),
})
}
}
sku
.
PriceRatio
=
showPriceRatioList
sku
.
LadderPrice
=
generatedLadderPrice
return
sku
}
...
...
@@ -603,19 +638,31 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
return
sku
,
priceRatioList
}
//
TransformSpecialSupplierPrice
这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
// 这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
// 所以要全部先转成正确的美金价才能显示
func
(
ps
*
PriceService
)
TransformSpecialSupplierPrice
(
s
upplierId
int64
,
priceUs
float64
,
usRatio
float64
)
float64
{
func
(
ps
*
PriceService
)
TransformSpecialSupplierPrice
(
s
ku
model
.
LySku
,
priceUs
float64
)
float64
{
//去redis获取价格
redisCon
:=
gredis
.
Conn
(
"default_r"
)
defer
func
()
{
redisCon
.
Close
()
}()
currency
,
_
:=
redis
.
Int
(
redisCon
.
Do
(
"HGET"
,
"magic_cube_supplier_currency"
,
supplierId
))
usRatio
,
_
:=
redis
.
Float64
(
redisCon
.
Do
(
"HGET"
,
"erp_rate"
,
2
))
var
currency
int
//这个供应商把人民币存到美金这个字段了,所以要提前判断和返回
if
sku
.
SupplierId
==
6
{
priceUs
=
c
.
MyRound
(
c
.
DivFloat
(
priceUs
,
usRatio
),
4
)
return
priceUs
}
if
sku
.
SupplierId
!=
17
{
currency
,
_
=
redis
.
Int
(
redisCon
.
Do
(
"HGET"
,
"magic_cube_supplier_currency"
,
sku
.
SupplierId
))
}
else
{
currency
,
_
=
redis
.
Int
(
redisCon
.
Do
(
"HGET"
,
"magic_cube_supplier_currency"
,
sku
.
Canal
))
}
if
currency
>
0
{
//这里进行转换,因为这里都只能取到对应的币种转人民币的比率,我们没有直接各种币种转美金的数据,所以我这边要
//先根据对应币种转人民币,然后根据人民币转美金,才能得到不同币种对应美金的汇率
rmbRatio
,
_
:=
redis
.
Float64
(
redisCon
.
Do
(
"HGET"
,
"erp_rate"
,
currency
))
fmt
.
Println
(
"特殊转换"
,
rmbRatio
)
//人民币汇率转美金汇率
usRatio
=
c
.
MyRound
(
c
.
DivFloat
(
rmbRatio
,
usRatio
),
2
)
priceUs
=
c
.
MyRound
(
c
.
DivFloat
(
priceUs
,
usRatio
),
4
)
...
...
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