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
c83cbe27
authored
Mar 13, 2023
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'ysx-魔方改版-20230313' into dev
parents
2e918fed
434aa3a2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
225 additions
and
30 deletions
model/activity.go
model/goods.go
model/ly_sku.go
service/service_activity.go
service/service_ly.go
service/service_ly_common.go
service/sorter/int_slice.go
model/activity.go
View file @
c83cbe27
...
...
@@ -4,17 +4,18 @@ type Activity struct {
Id
int64
`json:"id"`
SupplierIds
string
`json:"supplier_ids"`
SupplierIdList
[]
string
SupplierType
int
`json:"supplier_type"`
UserScope
int
`json:"user_scope"`
CanAdminOrder
interface
{}
`json:"can_admin_order"`
SignText
string
`json:"sign_text"`
BrandIds
string
`json:"brand_ids"`
SupplierType
int
`json:"supplier_type"`
UserScope
int
`json:"user_scope"`
CanAdminOrder
interface
{}
`json:"can_admin_order"`
SignText
string
`json:"sign_text"`
BrandIds
string
`json:"brand_ids"`
BrandIdList
[]
string
ClassIds
string
`json:"class_ids"`
ClassIdList
[]
string
Canals
string
`json:"canals"`
CanalList
[]
string
Ratio
float64
`json:"ratio"`
RatioUs
float64
`json:"ratio_us"`
StartTime
int
`json:"start_time"`
EndTime
int
`json:"end_time"`
AddTime
int
`json:"add_time"`
...
...
model/goods.go
View file @
c83cbe27
...
...
@@ -2,21 +2,25 @@ package model
//联营统一返回格式
type
LyResponse
struct
{
ErrorCode
int
`json:"error_code"`
ErrorMsg
string
`json:"error_msg"`
Data
interface
{}
`json:"data"`
ErrorCode
int
`json:"error_code"`
ErrorMsg
string
`json:"error_msg"`
Data
interface
{}
`json:"data"`
}
//原始sku梯度
type
LadderPrice
struct
{
Purchases
int64
`json:"purchases"`
//购买数量
PriceUs
float64
`json:"price_us,omitempty"`
//数量对应的英文价格
PriceCn
float64
`json:"price_cn"`
//数量对应的中文价格
PriceAc
float64
`json:"price_ac,omitempty"`
CostPrice
float64
`json:"-"`
Purchases
int64
`json:"purchases"`
//购买数量
PriceUs
float64
`json:"price_us,omitempty"`
//数量对应的英文价格
PriceCn
float64
`json:"price_cn"`
//数量对应的中文价格
PriceCostUs
float64
`json:"price_cost_us"`
//成本价美金
PriceCostCn
float64
`json:"price_cost_cn"`
//成本价人民币
PriceAc
float64
`json:"price_ac,omitempty"`
//活动价人民币
PriceAcUs
float64
`json:"price_ac_us"`
//活动价美金
CostPrice
float64
`json:"-"`
}
type
OriginPrice
struct
{
Purchases
int64
`json:"purchases"`
//购买数量
Purchases
int64
`json:"purchases"`
//购买数量
PriceUs
float64
`json:"price_us"`
//数量对应的英文价格
PriceCn
float64
`json:"price_cn"`
//数量对应的中文价格
PriceAc
float64
`json:"price_ac,omitempty"`
...
...
@@ -25,12 +29,12 @@ type OriginPrice struct {
//立创价格梯度
type
LadderPriceLc
struct
{
Purchases
int64
`json:"purchases"`
//购买数量
Price
float64
`json:"price"`
//立创价格,人民币
Purchases
int64
`json:"purchases"`
//购买数量
Price
float64
`json:"price"`
//立创价格,人民币
}
//自营属性列表
type
Attrs
struct
{
AttrName
string
`json:"attr_name"`
//属性名称
AttrValue
string
`json:"attr_value"`
//属性值
}
\ No newline at end of file
AttrName
string
`json:"attr_name"`
//属性名称
AttrValue
string
`json:"attr_value"`
//属性值
}
model/ly_sku.go
View file @
c83cbe27
...
...
@@ -60,6 +60,7 @@ type LySku struct {
ClassName2
string
`json:"class_name2,omitempty"`
ClassName3
string
`json:"class_name3,omitempty"`
Ratio
float64
`json:"ratio,omitempty"`
RatioUs
float64
`json:"ratio_us,omitempty"`
SpuDetail
string
`json:"spu_detail,omitempty"`
AcType
int
`json:"ac_type"`
...
...
@@ -70,11 +71,13 @@ 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
{
ActivityCommon
Ratio
float64
`json:"ratio,omitempty"`
RatioUs
float64
`json:"ratio_us,omitempty"`
SignText
string
`json:"sign_text,omitempty"`
Sign
string
`json:"sign,omitempty"`
ShowName
string
`json:"show_name,omitempty"`
...
...
@@ -155,6 +158,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_activity.go
View file @
c83cbe27
...
...
@@ -198,6 +198,11 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
UserScope
:
activity
.
UserScope
,
},
}
if
activity
.
RatioUs
>
0
{
priceActivity
.
RatioUs
=
activity
.
RatioUs
}
else
{
priceActivity
.
RatioUs
=
1
}
break
}
}
...
...
service/service_ly.go
View file @
c83cbe27
...
...
@@ -133,6 +133,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku
.
AllowCoupon
=
1
sku
.
BrandId
=
brandId
//这里获取活动价格和活动类型
sku
=
ls
.
GetActivity
(
sku
)
//处理阶梯价数据
...
...
@@ -146,7 +147,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
}
}
//获取系数
sku
=
ls
.
GetCoefficient
(
sku
)
sku
=
ls
.
GetCoefficient
AndPrice
(
sku
)
//仅提供价格和库存
if
fast
!=
"1"
{
...
...
@@ -215,6 +216,8 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku {
if
priceActivity
.
HasActivity
{
sku
.
AcType
=
10
sku
.
Ratio
=
priceActivity
.
Ratio
sku
.
RatioUs
=
priceActivity
.
RatioUs
sku
.
ActivityInfo
=
priceActivity
}
if
giftActivity
.
HasActivity
{
...
...
service/service_ly_common.go
View file @
c83cbe27
...
...
@@ -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"
...
...
@@ -179,7 +182,7 @@ func (ls *LyService) GetExtendFee(supplierId int64, canal string) interface{} {
}
//获取系数
func
(
ls
*
LyService
)
GetCoefficient
(
sku
model
.
LySku
)
model
.
LySku
{
func
(
ls
*
LyService
)
GetCoefficient
AndPrice
(
sku
model
.
LySku
)
model
.
LySku
{
if
len
(
sku
.
LadderPrice
)
==
0
{
sku
.
Original
=
nil
return
sku
...
...
@@ -218,16 +221,150 @@ 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
}
}
}
//这里是供应商系数,先保留这块逻辑
ratio
,
_
:=
redis
.
String
(
redisCon
.
Do
(
"HGET"
,
"pool_supplier_ratio"
,
sku
.
SupplierId
))
if
ratio
==
""
{
logger
.
Select
(
"sku_query"
)
.
Error
(
"系数获取异常,供应商:"
+
common
.
ToString
(
sku
.
SupplierId
))
return
sku
}
ratios
:=
gjson
.
Parse
(
ratio
)
.
Array
()
var
defaultCoefficient
,
coefficient
model
.
Coefficient
var
hasDefault
,
hasCoefficient
bool
...
...
@@ -259,7 +396,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
...
...
@@ -269,10 +406,12 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
logger
.
Select
(
"sku_query"
)
.
Error
(
"系数获取异常,供应商:"
+
common
.
ToString
(
sku
.
SupplierId
))
return
sku
}
if
!
hasCoefficient
{
coefficient
=
defaultCoefficient
}
//下面是计算价格
//价格计算文档 https://docs.qq.com/doc/DR3RJcnNPeUNkWHRk
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
//$tax = config('website.tax');
tax
:=
1.13
...
...
@@ -281,10 +420,31 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
continue
}
data
[
key
]
.
Purchases
=
price
.
Purchases
//根据系数处理美金
data
[
key
]
.
PriceUs
=
common
.
MyRound
(
price
.
PriceUs
*
coefficient
.
ExtraRatio
*
coefficient
.
Hk
,
4
)
//找出对应的阶梯,从$priceRatioList找到对应的售价组系数
//这个是为了怕后台存的数据格式不对导致无法获取到对应的系数
var
priceRatio
PriceRatio
if
len
(
priceRatioList
)
>
key
{
priceRatio
=
priceRatioList
[
key
]
}
else
{
priceRatio
=
PriceRatio
{
Ratio
:
1
,
RatioUsd
:
1
,
}
}
//美金成本价
priceCostUs
:=
price
.
PriceUs
*
usDiscountRatio
//美金售价
priceUs
:=
priceCostUs
*
priceRatio
.
RatioUsd
//人民币成本价
priceCostCn
:=
price
.
PriceUs
*
coefficient
.
Ratio
*
cnDiscountRatio
//人民币售价
priceCn
:=
priceCostCn
*
priceRatio
.
Ratio
*
tax
data
[
key
]
.
PriceUs
=
common
.
MyRound
(
priceUs
,
4
)
data
[
key
]
.
PriceCostUs
=
common
.
MyRound
(
priceCostUs
,
4
)
//处理人民币
data
[
key
]
.
PriceCn
=
common
.
MyRound
(
price
.
PriceUs
*
coefficient
.
ExtraRatio
*
coefficient
.
Cn
*
coefficient
.
Ratio
*
tax
,
4
)
data
[
key
]
.
PriceCn
=
common
.
MyRound
(
priceCn
,
4
)
data
[
key
]
.
PriceCostCn
=
common
.
MyRound
(
priceCostCn
,
4
)
fmt
.
Println
(
data
[
key
])
//处理mouser的成本价
//mouser成本价是什么,斌哥同步过来的成本价
//sku.LadderPrice[key].CostPrice是专门针对贸泽(mouser)的
...
...
@@ -302,6 +462,8 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
if
(
sku
.
GoodsType
==
1
||
sku
.
GoodsType
==
2
)
&&
sku
.
AcType
>
1
&&
sku
.
Ratio
>
0
{
priceAc
:=
common
.
MyRound
(
data
[
key
]
.
PriceCn
*
(
sku
.
Ratio
/
100
),
4
)
data
[
key
]
.
PriceAc
=
priceAc
priceAcUs
:=
common
.
MyRound
(
data
[
key
]
.
PriceCn
*
(
sku
.
RatioUs
/
100
),
4
)
data
[
key
]
.
PriceAcUs
=
priceAcUs
if
priceAc
<=
0
{
sku
.
AcType
=
0
...
...
service/sorter/int_slice.go
0 → 100644
View file @
c83cbe27
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