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
c8399857
authored
Aug 16, 2023
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
价格逻辑修改
parent
acacf9fb
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
149 deletions
model/ly_sku.go
service/service_ly_common.go
service/service_price.go
model/ly_sku.go
View file @
c8399857
...
...
@@ -88,6 +88,7 @@ type DiscountRatio struct {
type
PriceRatio
struct
{
Ratio
float64
`json:"ratio"`
RatioUsd
float64
`json:"ratio_usd"`
Purchases
int64
`json:"purchases,omitempty"`
}
type
PriceActivity
struct
{
...
...
service/service_ly_common.go
View file @
c8399857
...
...
@@ -7,8 +7,6 @@ import (
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/logger"
_
"go_sku_server/pkg/mongo"
"go_sku_server/service/sorter"
"strconv"
"strings"
"github.com/gomodule/redigo/redis"
...
...
@@ -211,10 +209,8 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
//如果没有成本价字段,就要去生成阶梯价格
if
len
(
ladderPrice
)
>
0
{
if
ladderPrice
[
0
]
.
PriceCostUs
==
0
&&
ladderPrice
[
0
]
.
PriceCostCn
==
0
{
generatedLadderPrice
,
priceRatio
:=
priceService
.
GenerateLadderPrice
(
sku
)
ladderPrice
=
generatedLadderPrice
sku
.
PriceRatio
=
priceRatio
sku
.
PriceRatioSort
=
-
1
sku
=
priceService
.
GenerateLadderPrice
(
sku
)
ladderPrice
=
sku
.
LadderPrice
}
}
data
=
make
([]
model
.
LadderPrice
,
len
(
ladderPrice
))
...
...
@@ -259,154 +255,14 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
redisCon
:=
gredis
.
Conn
(
"default_r"
)
defer
redisCon
.
Close
()
/**
**/
sku
=
priceService
.
GetDiscountRatio
(
sku
)
/**
再去找售价组系数
**/
sku
,
priceRatioList
:=
priceService
.
GetPriceRatio
(
sku
)
//找一个标志位,因为默认的全局折扣系数的数据格式和非全局的是不一样的
isDefaultPriceRatio
:=
false
priceRatioCache
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"magic_cube_price_rule_channel"
,
sku
.
SupplierId
))
checkNullRation
:=
gjson
.
Get
(
priceRatioCache
,
"ladder_price"
)
.
String
()
//如果这个渠道没有对应的折扣系数,那么就去读取全局的
if
priceRatioCache
==
""
||
checkNullRation
==
"{}"
{
isDefaultPriceRatio
=
true
priceRatioCache
,
_
=
redis
.
String
(
redisCon
.
Do
(
"GET"
,
"magic_cube_price_rule_channel_default"
))
}
var
priceRatioSort
int
//这个就是最终要获取到的价格系数
var
priceRatioList
[]
model
.
PriceRatio
//是否找到系数的标志位
foundRatio
:=
false
//如果只有默认系数,那么就去找默认系数
if
isDefaultPriceRatio
{
}
else
{
//拿到系数以后,就要去计算
//拿出里面的所有排序
priceRatioSortMap
:=
gjson
.
Get
(
priceRatioCache
,
"ladder_price"
)
.
Map
()
var
sortNumbers
[]
int
for
sortNumberString
,
_
:=
range
priceRatioSortMap
{
sortNumber
,
_
:=
strconv
.
Atoi
(
sortNumberString
)
sortNumbers
=
append
(
sortNumbers
,
sortNumber
)
}
//然后确定排序
sortNumbers
=
sorter
.
IntSliceSortDesc
(
sortNumbers
)
//确定排序以后,就可以进行按排序(从大到小)取系数
outerLoop
:
for
_
,
sortNumber
:=
range
sortNumbers
{
priceRatioSort
=
sortNumber
priceRatioList
=
nil
sortString
:=
strconv
.
Itoa
(
sortNumber
)
priceRatioArr
:=
gjson
.
Get
(
priceRatioCache
,
"ladder_price."
+
sortString
)
.
Array
()
for
_
,
value
:=
range
priceRatioArr
{
var
priceRatio
model
.
PriceRatio
priceRatio
.
Ratio
=
gjson
.
Get
(
value
.
String
(),
"ratio"
)
.
Float
()
priceRatio
.
RatioUsd
=
gjson
.
Get
(
value
.
String
(),
"ratio_usd"
)
.
Float
()
priceRatioList
=
append
(
priceRatioList
,
priceRatio
)
}
var
hasSpecialCheck
=
false
//判断是否有符合的商品名称
goodsNames
:=
gjson
.
Get
(
priceRatioCache
,
"goods_name."
+
sortString
)
.
String
()
if
goodsNames
!=
""
{
hasSpecialCheck
=
true
goodsNameList
:=
strings
.
Split
(
goodsNames
,
"@€@"
)
//找到有对应的商品名称,那么优先级肯定是最高的了
if
php2go
.
InArray
(
sku
.
GoodsName
,
goodsNameList
)
{
foundRatio
=
true
break
}
}
//判断是否有符合的标准品牌ID
brandIds
:=
gjson
.
Get
(
priceRatioCache
,
"brand."
+
sortString
)
.
String
()
if
brandIds
!=
""
{
hasSpecialCheck
=
true
standardBrandIdList
:=
strings
.
Split
(
brandIds
,
","
)
standardBrandId
:=
strconv
.
Itoa
(
sku
.
StandardBrand
.
StandardBrandId
)
//找到有对应的品牌,那么优先级肯定是最高的了
if
php2go
.
InArray
(
standardBrandId
,
standardBrandIdList
)
{
foundRatio
=
true
break
}
}
//判断是否有符合的eccn
eccns
:=
gjson
.
Get
(
priceRatioCache
,
"eccn."
+
sortString
)
.
String
()
if
eccns
!=
""
{
hasSpecialCheck
=
true
eccnList
:=
strings
.
Split
(
eccns
,
","
)
//找到有对应的eccn,那么优先级肯定是最高的了
for
_
,
eccn
:=
range
eccnList
{
//判断是否有百分号匹配
//如果是纯%,那就是不对的,要跳过
if
strings
.
Replace
(
eccn
,
"%"
,
""
,
10
)
==
""
{
continue
}
if
strings
.
Contains
(
eccn
,
"%"
)
{
hasPrefix
:=
strings
.
HasPrefix
(
eccn
,
"%"
)
hasSuffix
:=
strings
.
HasSuffix
(
eccn
,
"%"
)
if
hasPrefix
&&
hasSuffix
{
eccn
=
strings
.
Replace
(
eccn
,
"%"
,
""
,
10
)
if
strings
.
Contains
(
sku
.
Eccn
,
eccn
)
{
foundRatio
=
true
break
outerLoop
}
}
if
hasPrefix
&&
!
hasSuffix
{
eccn
=
strings
.
Replace
(
eccn
,
"%"
,
""
,
10
)
if
strings
.
HasSuffix
(
sku
.
Eccn
,
eccn
)
{
foundRatio
=
true
break
outerLoop
}
}
if
!
hasPrefix
&&
hasSuffix
{
eccn
=
strings
.
Replace
(
eccn
,
"%"
,
""
,
10
)
if
strings
.
HasPrefix
(
sku
.
Eccn
,
eccn
)
{
foundRatio
=
true
break
outerLoop
}
}
}
else
{
if
sku
.
Eccn
==
eccn
{
foundRatio
=
true
break
outerLoop
}
}
}
}
//如果没有设置品牌和商品,那么这个优先级高的就会覆盖下面的了,不需要再去判断品牌和型号了
if
hasSpecialCheck
{
continue
}
foundRatio
=
true
break
}
}
//找不到特定的系数,那就去找全局的
if
!
foundRatio
{
priceRatioCache
,
_
=
redis
.
String
(
redisCon
.
Do
(
"GET"
,
"magic_cube_price_rule_channel_default"
))
priceRatioArr
:=
gjson
.
Get
(
priceRatioCache
,
"ladder_price"
)
.
Array
()
priceRatioList
=
nil
for
_
,
value
:=
range
priceRatioArr
{
var
priceRatio
model
.
PriceRatio
priceRatio
.
Ratio
=
gjson
.
Get
(
value
.
String
(),
"ratio"
)
.
Float
()
priceRatio
.
RatioUsd
=
gjson
.
Get
(
value
.
String
(),
"ratio_usd"
)
.
Float
()
priceRatioList
=
append
(
priceRatioList
,
priceRatio
)
}
priceRatioSort
=
-
1
}
sku
.
PriceRatio
=
priceRatioList
sku
.
PriceRatioSort
=
priceRatioSort
//这里是供应商系数,先保留这块逻辑
/** 这里是供应商系数,先保留这块逻辑 **/
ratio
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"pool_supplier_ratio"
,
sku
.
SupplierId
))
if
ratio
==
""
{
logger
.
Select
(
"sku_query"
)
.
Error
(
"系数获取异常,供应商:"
+
c
.
ToString
(
sku
.
SupplierId
))
...
...
@@ -456,6 +312,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
if
!
hasCoefficient
{
coefficient
=
defaultCoefficient
}
//下面是计算价格
//价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
...
...
@@ -473,7 +330,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
continue
}
data
[
key
]
.
Purchases
=
price
.
Purchases
//找出对应的阶梯,从
$
priceRatioList找到对应的售价组系数
//找出对应的阶梯,从priceRatioList找到对应的售价组系数
//这个是为了怕后台存的数据格式不对导致无法获取到对应的系数
//这里去取对应的售价利润阶梯的时候,是往下匹配的,比如 阶梯价是 1,2,3 售价组利润是 1,2,3,4,5,那么123对应的是售价组利润的345
//而且当原始阶梯价为10个的时候,超过了售价利润组的9个,就要去取第9个售价利润组
...
...
service/service_price.go
View file @
c8399857
This diff is collapsed.
Click to expand it.
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