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
86ec1f7f
authored
Mar 12, 2025
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'ysx-魔方价格体系修改-20250306'
parents
1fc9cbab
9c5872de
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
156 additions
and
17 deletions
model/ly_sku.go
service/service_custom_price.go
service/service_ly.go
service/service_ly_common.go
service/service_price.go
model/ly_sku.go
View file @
86ec1f7f
...
...
@@ -86,7 +86,8 @@ type LySku struct {
OriginCurrencySymbol
string
`json:"origin_currency_symbol,omitempty"`
CustomizeRateRMB
float64
CustomizeRateUs
float64
SpuEccn
string
`json:"spu_eccn"`
SpuEccn
string
`json:"spu_eccn"`
CustomPriceList
[]
CustomPrice
`json:"custom_price_list"`
}
type
DiscountRatio
struct
{
...
...
@@ -159,6 +160,11 @@ type SpuExtra struct {
Length
string
`json:"length" bson:"length"`
}
type
CustomPrice
struct
{
PriceName
string
`json:"price_name"`
LadderPrice
[]
LadderPrice
`json:"ladder_price"`
}
// 为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func
InitSkuData
(
sku
string
)
(
data
LySku
)
{
...
...
service/service_custom_price.go
0 → 100644
View file @
86ec1f7f
package
service
import
(
"github.com/gomodule/redigo/redis"
"github.com/tidwall/gjson"
"go_sku_server/model"
c
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
)
type
CustomPrice
struct
{
}
// 加上自定义价格的转换
func
(
sc
*
CustomPrice
)
getCustomPriceList
(
sku
model
.
LySku
)
(
customPriceList
[]
model
.
CustomPrice
,
err
error
)
{
//先根据组织获取对应的自定义价格系数
redisCon
:=
gredis
.
Conn
(
"default_r"
)
defer
redisCon
.
Close
()
customPriceRule
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"cube_custom_price"
,
sku
.
OrgId
))
if
customPriceRule
==
""
{
return
customPriceList
,
nil
}
customPriceRuleArr
:=
gjson
.
Get
(
customPriceRule
,
"price_list"
)
.
Array
()
//这里是价格规则
for
_
,
customPriceRule
:=
range
customPriceRuleArr
{
//每一个自定义价格都有一个系数,比如会员价利润 10%
ratio
:=
customPriceRule
.
Get
(
"ratio"
)
.
Int
()
priceName
:=
customPriceRule
.
Get
(
"price_name"
)
.
String
()
var
customPrice
model
.
CustomPrice
customPrice
.
PriceName
=
priceName
for
_
,
item
:=
range
sku
.
LadderPrice
{
ratioFloat
:=
c
.
DivFloat
(
float64
(
100
+
ratio
),
100
)
customPrice
.
LadderPrice
=
append
(
customPrice
.
LadderPrice
,
model
.
LadderPrice
{
Purchases
:
item
.
Purchases
,
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
item
.
PriceCn
*
ratioFloat
),
2
),
PriceUs
:
c
.
MyRound
(
c
.
MulFloat
(
item
.
PriceUs
*
ratioFloat
),
2
),
PriceAc
:
c
.
MyRound
(
c
.
MulFloat
(
item
.
PriceAc
*
ratioFloat
),
2
),
PriceAcUs
:
c
.
MyRound
(
c
.
MulFloat
(
item
.
PriceAcUs
*
ratioFloat
),
2
),
})
}
customPriceList
=
append
(
customPriceList
,
customPrice
)
}
return
customPriceList
,
nil
}
// 单独处理华云的阶梯价
func
(
sc
*
CustomPrice
)
transformIEdgeLadderPrice
(
sku
model
.
LySku
)
(
ladderPriceList
[]
model
.
LadderPrice
)
{
//华云因为它只有一个阶梯,所以生成的阶梯价只有2个阶梯,为了兼容以前的数据格式
/*
{
"purchases": 1,
"price_us": 0,
"price_cn": 293.13,
"price_name": "标准价"
},
{
"purchases": 2,
"price_us": 0,
"price_cn": 190.59,
"price_name": "企业价"
}
]
*/
if
len
(
sku
.
CustomPriceList
)
!=
0
{
for
index
,
customPrice
:=
range
sku
.
CustomPriceList
{
if
len
(
customPrice
.
LadderPrice
)
>
0
{
//只取最后一个元素价格就行
ladderPrice
:=
customPrice
.
LadderPrice
[
len
(
customPrice
.
LadderPrice
)
-
1
]
ladderPrice
.
PriceName
=
customPrice
.
PriceName
ladderPrice
.
Purchases
=
int64
(
index
+
1
)
ladderPriceList
=
append
(
ladderPriceList
,
ladderPrice
)
}
}
}
return
ladderPriceList
}
service/service_ly.go
View file @
86ec1f7f
...
...
@@ -43,6 +43,8 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
redisConnSpu
.
Close
()
}()
//各种展示条件
//是否快速展示
fast
:=
ctx
.
Request
.
FormValue
(
"power[fast]"
)
//是否展示属性
showAttr
:=
ctx
.
Request
.
FormValue
(
"show_attr"
)
...
...
@@ -69,7 +71,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku
:=
model
.
InitSkuData
(
skuStr
)
sku
.
GoodsId
=
goodsId
spu
:=
spuList
[
sku
.
SpuId
]
//读取包装字段的缓存
//读取包装字段的缓存
(分别是DGK,avnet,mro)
if
sku
.
SupplierId
==
7
||
sku
.
SupplierId
==
13
||
sku
.
SupplierId
==
1688
{
//sku_raw_map哪里写入(成意写的)
packing
,
_
:=
redis
.
String
(
redisConnSpu
.
Do
(
"HGET"
,
"sku_raw_map"
,
goodsId
))
...
...
@@ -96,6 +98,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
brandId
:=
gjson
.
Get
(
spu
,
"brand_id"
)
.
Int
()
brandName
,
_
:=
redis
.
String
(
redisConn
.
Do
(
"HGET"
,
"brand"
,
brandId
))
sku
.
BrandName
=
brandName
sku
.
BrandId
=
brandId
//判断是否要取精简信息
if
fast
!=
"1"
{
...
...
@@ -152,7 +155,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
//处理活动
sku
.
AcType
=
0
sku
.
AllowCoupon
=
1
sku
.
BrandId
=
brandId
//这里获取活动价格和活动类型
sku
=
ls
.
GetActivity
(
sku
)
...
...
@@ -167,20 +169,57 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku
.
Moq
=
purchases
}
}
//这里又有一个判断,如果是非猎芯的,目前只有爱智,通过org_id来判断,如果是爱智,不需要走价格体系
//1是猎芯,3是爱智
switch
sku
.
OrgId
{
//case为0是为了兼容价格体系之前的价格
case
0
:
case
1
:
//如果是寄售的,也不走价格体系
if
sku
.
Source
!=
12
{
//获取系数和价格
sku
=
ls
.
GetCoefficientAndPrice
(
sku
)
//这里还有个特殊判断,要兼容华云改价格体系之前的老数据
//判断组织是3并且阶梯价数量为2的就是老数据
if
sku
.
OrgId
==
3
&&
len
(
sku
.
LadderPrice
)
==
2
{
priceService
:=
PriceService
{}
sku
.
LadderPrice
=
priceService
.
GetIEdgePrice
(
sku
.
LadderPrice
)
}
else
{
//这里猎芯和华云都是走同一套的价格体系了
//获取系数和价格
sku
=
ls
.
GetCoefficientAndPrice
(
sku
)
//获取自定义价格后的阶梯价
customPriceService
:=
CustomPrice
{}
sku
.
CustomPriceList
,
_
=
customPriceService
.
getCustomPriceList
(
sku
)
//这里还要针对华云的阶梯价进行一次转换,因为要兼容目前华云的试用方式
if
sku
.
OrgId
==
3
{
sku
.
LadderPrice
=
customPriceService
.
transformIEdgeLadderPrice
(
sku
)
}
}
}
break
case
3
:
priceService
:=
PriceService
{}
sku
.
LadderPrice
=
priceService
.
GetIEdgePrice
(
sku
.
LadderPrice
)
//如果是寄售的,也不走价格体系
if
sku
.
Source
!=
12
{
//这里还有个特殊判断,要兼容华云改价格体系之前的老数据
//判断组织是3并且阶梯价数量为2的就是老数据
if
sku
.
OrgId
==
3
&&
len
(
sku
.
LadderPrice
)
==
2
{
priceService
:=
PriceService
{}
sku
.
LadderPrice
=
priceService
.
GetIEdgePrice
(
sku
.
LadderPrice
)
}
else
{
//这里猎芯和华云都是走同一套的价格体系了
//获取系数和价格
sku
=
ls
.
GetCoefficientAndPrice
(
sku
)
//获取自定义价格后的阶梯价
customPriceService
:=
CustomPrice
{}
sku
.
CustomPriceList
,
_
=
customPriceService
.
getCustomPriceList
(
sku
)
//这里还要针对华云的阶梯价进行一次转换,因为要兼容目前华云的试用方式
if
sku
.
OrgId
==
3
{
sku
.
LadderPrice
=
customPriceService
.
transformIEdgeLadderPrice
(
sku
)
}
}
}
break
default
:
break
}
...
...
service/service_ly_common.go
View file @
86ec1f7f
...
...
@@ -287,6 +287,8 @@ func (ls *LyService) CombineSup(sku model.LySku, spuStr string) model.LySku {
// 获取系数和总体价格,生成和处理价格的方法,很重要
func
(
ls
*
LyService
)
GetCoefficientAndPrice
(
sku
model
.
LySku
)
model
.
LySku
{
//没有阶梯价格,直接跳过
if
len
(
sku
.
LadderPrice
)
==
0
{
//sku.Original = nil
return
sku
...
...
@@ -299,6 +301,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
//专卖价格获取
if
sku
.
SupplierId
==
17
{
ladderPrice
:=
sku
.
LadderPrice
//这里是存了一些特殊供应商价格的判断,数据库里不是所有供应商都是存的人民币/美金
sku
=
priceService
.
TransformSpecialSupplierPrice
(
sku
)
//判断redis里面是否有成本价,有的话,那就直接去取价格,不需要生成阶梯价
//如果没有成本价字段,就要去生成阶梯价格
...
...
@@ -306,7 +309,6 @@ 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)
}
}
//获取折扣系数
...
...
service/service_price.go
View file @
86ec1f7f
package
service
import
(
"github.com/gogf/gf/util/gconv"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
...
...
@@ -17,6 +18,7 @@ type PriceService struct {
}
// 构建专营的阶梯价,现在专营只会存一个简单的成本价,阶梯数量是1,所以我这边要根据专营的阶梯系数去构建具体的阶梯价
// 还要需要注意的一点是,价格体系改版后华云的sku,也会进入这个判断,毕竟华云的sku也是属于专营的
func
(
ps
*
PriceService
)
GenerateLadderPrice
(
sku
model
.
LySku
)
model
.
LySku
{
//需要展示的价格系数
var
showPriceRatioList
[]
model
.
PriceRatio
...
...
@@ -32,7 +34,13 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
defer
redisCon
.
Close
()
//找一个标志位,因为默认的全局折扣系数的数据格式和非全局的是不一样的
isDefaultPriceRatio
:=
false
priceRatioCache
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"magic_cube_price_rule_v2"
,
sku
.
Canal
))
//这里很关键,因为华云也要兼容到猎芯的价格体系,所以缓存里面也有了华云的售价组,但是猎芯存的哈希对应的key是 供应商编码(L002323)
//而华云(或者以后的新组织),存的哈希对应的key是 供应商编码_组织ID (L00232_3)
ruleKey
:=
sku
.
Canal
if
sku
.
OrgId
!=
1
{
ruleKey
=
sku
.
Canal
+
"_"
+
gconv
.
String
(
sku
.
OrgId
)
}
priceRatioCache
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"magic_cube_price_rule_v2"
,
ruleKey
))
//判断是否是空
checkNullRation
:=
gjson
.
Get
(
priceRatioCache
,
ratioDataKey
)
.
String
()
//如果这个渠道没有对应的折扣系数,那么就去读取全局的
...
...
@@ -73,7 +81,6 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
priceRatio
.
Purchases
=
gjson
.
Get
(
value
.
String
(),
"purchases"
)
.
Int
()
priceRatioList
=
append
(
priceRatioList
,
priceRatio
)
}
//是否满足特定条件的判断
var
hasSpecialCheck
=
false
//判断是否有符合的商品名称
...
...
@@ -185,9 +192,11 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
}
//fmt.Println("最低利润点阶梯数 : ", ladderPriceMiniProfitLevel)
var
generatedLadderPrice
[]
model
.
LadderPrice
//先直接获取成本价原始值,判断第一个阶梯的阶梯数量是否为0,如果是0,那么代表是要走成本价生成,如果不是0,那么就要走阶梯价生成
firstLadderPurchases
:=
sku
.
LadderPrice
[
0
]
.
Purchases
isCostPrice
:=
bool
(
firstLadderPurchases
==
0
)
//判断是否走成本价判断还是走阶梯价判断,因为上传sku的时候,可以设置每个sku的成本价(人民币&&美金),也可以设置每个sku的阶梯价
//如果有阶梯价,就要跳过设置的成本价(假设有设置的话)
if
isCostPrice
{
...
...
@@ -195,8 +204,8 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
costPriceCn
:=
sku
.
LadderPrice
[
0
]
.
PriceCn
costPriceUs
:=
sku
.
LadderPrice
[
0
]
.
PriceUs
//fmt.Println("人民币和美金的成本价分别为 : ", costPriceCn, costPriceUs)
//先去判断起订量,如果起订量小于50,就要走固定配置的阶梯系数
if
sku
.
Moq
<=
50
{
//先去判断起订量,如果起订量小于50,就要走固定配置的阶梯系数
(这里是猎芯的逻辑)
if
sku
.
Moq
<=
50
&&
sku
.
OrgId
==
1
{
moq
:=
int
(
sku
.
Moq
)
fixedRatio
:=
make
(
map
[
int
]
float64
)
//当起订量是小于等于50的时候,阶梯数量和阶梯数是固定的,但是具体的利润还是要去取配置的值,因为固定死的阶梯数量是5,所以这边要直接取魔方配置9个的后5个
...
...
@@ -296,12 +305,10 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//如:库存满足1、2、3层阶梯,最小利润点层级是第5个层级,则利润点取3、4、5层级的
//最小利润点层级 - 库存满足多少个阶梯 + i
costMapIndex
:=
ladderPriceMiniProfitLevel
-
costLadderCount
+
i
//fmt.Println(costMapIndex)
if
costMapIndex
<=
0
{
costMapIndex
=
0
}
priceRatioAndPurchases
=
priceRatioList
[
costMapIndex
]
//fmt.Println("获取到的阶梯系数为 : ", priceRatioAndPurchases)
priceCnRatio
:=
priceRatioAndPurchases
.
Ratio
priceUsRatio
:=
priceRatioAndPurchases
.
RatioUsd
// 阶梯价格系数正序取
...
...
@@ -417,7 +424,12 @@ func (ps *PriceService) GetDiscountRatio(sku model.LySku) model.LySku {
if
sku
.
SupplierId
==
17
{
discountRatioRedisKey
=
"magic_cube_channel_discount_zhuanying"
discountRatioDefaultRedisKey
=
"magic_cube_channel_discount_default_zhuanying"
supplierKey
=
sku
.
Canal
//这里还要判断是否是华云,如果是华云的话,key的格式应该是 L0012323_3
if
sku
.
OrgId
==
1
{
supplierKey
=
sku
.
Canal
}
else
{
supplierKey
=
sku
.
Canal
+
"-_"
+
gconv
.
String
(
sku
.
OrgId
)
}
}
//先去读取成本折扣系数
...
...
@@ -644,6 +656,9 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
// 这里有个前置条件处理美金价,因为element(6)存到美金字段里面的是港币,rs(21)存到美金字段里的是人民币,buerklin(1676)是欧元
// 所以要全部先转成正确的美金价才能显示
func
(
ps
*
PriceService
)
TransformSpecialSupplierPrice
(
sku
model
.
LySku
)
model
.
LySku
{
if
sku
.
OrgId
!=
1
{
return
sku
}
//去redis获取价格
redisCon
:=
gredis
.
Conn
(
"default_r"
)
defer
func
()
{
...
...
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