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
dd0c2dac
authored
Mar 13, 2023
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
获取各种系数的逻辑
parent
bcd4ffc0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
163 additions
and
3 deletions
model/ly_sku.go
service/service_ly_common.go
service/sorter/int_slice.go
model/ly_sku.go
View file @
dd0c2dac
...
...
@@ -70,6 +70,7 @@ type LySku struct {
StandardBrand
StandardBrand
`json:"standard_brand"`
GoodsTag
GoodsTag
`json:"goods_tag"`
StockInfo
interface
{}
`json:"stock_info"`
Eccn
string
`json:"eccn"`
}
type
PriceActivity
struct
{
...
...
@@ -155,6 +156,9 @@ func InitSkuData(sku string) (data LySku) {
stock
:=
gjson
.
Get
(
sku
,
"stock"
)
.
Int
()
data
.
Stock
=
stock
eccn
:=
gjson
.
Get
(
sku
,
"eccn"
)
.
String
()
data
.
Eccn
=
eccn
isExpire
:=
gjson
.
Get
(
sku
,
"is_expire"
)
.
Int
()
data
.
IsExpire
=
int
(
isExpire
)
...
...
service/service_ly_common.go
View file @
dd0c2dac
...
...
@@ -2,11 +2,14 @@ package service
import
(
"encoding/json"
"fmt"
"go_sku_server/model"
"go_sku_server/pkg/common"
"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"
...
...
@@ -218,11 +221,147 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
}
}
}
else
{
//去获取
系数
//去获取
各种系数(成本折扣系数,售价组系数,供应商系数)
redisCon
:=
gredis
.
Conn
(
"default_r"
)
defer
redisCon
.
Close
()
ratio
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"pool_supplier_ratio"
,
sku
.
SupplierId
))
//先去读取渠道折扣
//找一个标志位,因为默认的全局折扣系数的数据格式和非全局的是不一样的
isDefaultDiscoutRatio
:=
false
discountRatio
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"magic_cube_channel_discount_daigou"
,
sku
.
SupplierId
))
//如果这个渠道没有对应的折扣系数,那么就去读取全局的
if
discountRatio
==
""
{
isDefaultDiscoutRatio
=
true
discountRatio
,
_
=
redis
.
String
(
redisCon
.
Do
(
"GET"
,
"magic_cube_channel_discount_default_zhuanying"
))
}
var
cnDiscountRatio
float64
var
usDiscountRatio
float64
//如果只有默认系数,那么就去找默认系数
if
isDefaultDiscoutRatio
{
cnDiscountRatio
=
gjson
.
Get
(
discountRatio
,
"ration"
)
.
Float
()
usDiscountRatio
=
gjson
.
Get
(
discountRatio
,
"ration_usd"
)
.
Float
()
}
else
{
//拿到系数以后,就要去计算
//拿出里面的所有排序,以人民币系数为准
ration
:=
gjson
.
Get
(
discountRatio
,
"ration"
)
.
Map
()
var
sortNumbers
[]
int
for
sortNumberString
,
_
:=
range
ration
{
sortNumber
,
_
:=
strconv
.
Atoi
(
sortNumberString
)
sortNumbers
=
append
(
sortNumbers
,
sortNumber
)
}
//然后确定排序
sortNumbers
=
sorter
.
IntSliceSortDesc
(
sortNumbers
)
//确定排序以后,就可以进行按排序(从大到小)取系数
for
_
,
sortNumber
:=
range
sortNumbers
{
sortString
:=
strconv
.
Itoa
(
sortNumber
)
cnDiscountRatio
=
gjson
.
Get
(
discountRatio
,
"ration."
+
sortString
)
.
Float
()
usDiscountRatio
=
gjson
.
Get
(
discountRatio
,
"ration_usd."
+
sortString
)
.
Float
()
//判断是否有符合的商品名称
goodsNames
:=
gjson
.
Get
(
discountRatio
,
"goods_name"
)
.
String
()
goodsNameList
:=
strings
.
Split
(
goodsNames
,
"€"
)
//找到有对应的商品名称,那么优先级肯定是最高的了
if
php2go
.
InArray
(
sku
.
GoodsName
,
goodsNameList
)
{
break
}
//判断是否有符合的品牌名称
brandIds
:=
gjson
.
Get
(
discountRatio
,
"brand"
)
.
String
()
standardBrandIdList
:=
strings
.
Split
(
brandIds
,
"€"
)
standardBrandId
:=
strconv
.
Itoa
(
sku
.
StandardBrand
.
StandardBrandId
)
//找到有对应的品牌,那么优先级肯定是最高的了
if
php2go
.
InArray
(
standardBrandId
,
standardBrandIdList
)
{
break
}
//如果没有设置品牌和商品,那么这个优先级高的就会覆盖下面的了,不需要再去判断品牌和型号了
if
len
(
goodsNameList
)
==
0
&&
len
(
standardBrandIdList
)
==
0
{
break
}
}
}
cnDiscountRatio
+=
1
usDiscountRatio
+=
1
//再去找售价组系数
//找一个标志位,因为默认的全局折扣系数的数据格式和非全局的是不一样的
isDefaultPriceRatio
:=
false
priceRatioCache
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"magic_cube_price_rule_channel"
,
sku
.
SupplierId
))
//如果这个渠道没有对应的折扣系数,那么就去读取全局的
if
priceRatioCache
==
""
{
isDefaultPriceRatio
=
true
priceRatioCache
,
_
=
redis
.
String
(
redisCon
.
Do
(
"GET"
,
"magic_cube_price_rule_channel_default"
))
}
type
PriceRatio
struct
{
Ratio
float64
RatioUsd
float64
}
//这个就是最终要获取到的价格系数
var
priceRatioList
[]
PriceRatio
//如果只有默认系数,那么就去找默认系数
if
isDefaultPriceRatio
{
priceRatioArr
:=
gjson
.
Get
(
priceRatioCache
,
"ladder_price"
)
.
Array
()
for
_
,
value
:=
range
priceRatioArr
{
priceRatioList
=
nil
var
priceRatio
PriceRatio
priceRatio
.
Ratio
=
gjson
.
Get
(
value
.
String
(),
"ratio"
)
.
Float
()
priceRatio
.
RatioUsd
=
gjson
.
Get
(
value
.
String
(),
"ratio_usd"
)
.
Float
()
priceRatioList
=
append
(
priceRatioList
,
priceRatio
)
}
}
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
)
//确定排序以后,就可以进行按排序(从大到小)取系数
for
_
,
sortNumber
:=
range
sortNumbers
{
priceRatioList
=
nil
sortString
:=
strconv
.
Itoa
(
sortNumber
)
priceRatioArr
:=
gjson
.
Get
(
priceRatioCache
,
"ladder_price."
+
sortString
)
.
Array
()
for
_
,
value
:=
range
priceRatioArr
{
var
priceRatio
PriceRatio
priceRatio
.
Ratio
=
gjson
.
Get
(
value
.
String
(),
"ratio"
)
.
Float
()
priceRatio
.
RatioUsd
=
gjson
.
Get
(
value
.
String
(),
"ratio_usd"
)
.
Float
()
priceRatioList
=
append
(
priceRatioList
,
priceRatio
)
}
//判断是否有符合的商品名称
goodsNames
:=
gjson
.
Get
(
priceRatioCache
,
"goods_name."
+
sortString
)
.
String
()
goodsNameList
:=
strings
.
Split
(
goodsNames
,
"€"
)
//找到有对应的商品名称,那么优先级肯定是最高的了
if
php2go
.
InArray
(
sku
.
GoodsName
,
goodsNameList
)
{
break
}
//判断是否有符合的标准品牌ID
brandIds
:=
gjson
.
Get
(
priceRatioCache
,
"brand"
+
sortString
)
.
String
()
standardBrandIdList
:=
strings
.
Split
(
brandIds
,
"€"
)
standardBrandId
:=
strconv
.
Itoa
(
sku
.
StandardBrand
.
StandardBrandId
)
//找到有对应的品牌,那么优先级肯定是最高的了
if
php2go
.
InArray
(
standardBrandId
,
standardBrandIdList
)
{
break
}
//判断是否有符合的eccn
eccns
:=
gjson
.
Get
(
priceRatioCache
,
"eccn"
+
sortString
)
.
String
()
eccnList
:=
strings
.
Split
(
eccns
,
"€"
)
//找到有对应的eccn,那么优先级肯定是最高的了
for
_
,
eccn
:=
range
eccnList
{
if
strings
.
Contains
(
sku
.
Eccn
,
eccn
)
{
break
}
}
//如果没有设置品牌和商品,那么这个优先级高的就会覆盖下面的了,不需要再去判断品牌和型号了
if
len
(
goodsNameList
)
==
0
&&
len
(
standardBrandIdList
)
==
0
&&
len
(
eccnList
)
==
0
{
break
}
}
}
fmt
.
Print
(
priceRatioList
)
//这里是供应商系数,先保留这块逻辑
ratio
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"pool_supplier_ratio"
,
sku
.
SupplierId
))
if
ratio
==
""
{
logger
.
Select
(
"sku_query"
)
.
Error
(
"系数获取异常,供应商:"
+
common
.
ToString
(
sku
.
SupplierId
))
return
sku
...
...
@@ -259,7 +398,7 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
}
//存在goods_name的对比吗,为什么,因为系数可以单独针对型号配置,所以要去判断型号
//http://footstone.ichunt.net/web/SavePoolCoefficient?id=1
if
brand
Name
!=
""
&&
strings
.
Contains
(
goodsName
,
sku
.
GoodsName
)
{
if
goods
Name
!=
""
&&
strings
.
Contains
(
goodsName
,
sku
.
GoodsName
)
{
coefficient
=
ratioInfo
hasCoefficient
=
true
break
...
...
@@ -273,6 +412,8 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
if
!
hasCoefficient
{
coefficient
=
defaultCoefficient
}
//下面是计算价格
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
//$tax = config('website.tax');
tax
:=
1.13
...
...
service/sorter/int_slice.go
0 → 100644
View file @
dd0c2dac
package
sorter
import
"sort"
// Define a custom type and methods to implement sort.Interface
type
DescendingInts
[]
int
func
(
d
DescendingInts
)
Len
()
int
{
return
len
(
d
)
}
func
(
d
DescendingInts
)
Swap
(
i
,
j
int
)
{
d
[
i
],
d
[
j
]
=
d
[
j
],
d
[
i
]
}
func
(
d
DescendingInts
)
Less
(
i
,
j
int
)
bool
{
return
d
[
i
]
>
d
[
j
]
}
func
IntSliceSortDesc
(
numbers
[]
int
)
[]
int
{
sort
.
Sort
(
DescendingInts
(
numbers
))
return
numbers
}
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