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
8e8a68f6
authored
Aug 23, 2023
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'ysx-商品活动价逻辑修改-20230823' into dev
parents
91d78a1e
77976452
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
32 deletions
model/activity.go
service/service_activity.go
service/service_ly.go
service/service_ly_common.go
service/service_price.go
service/service_zy_common.go
model/activity.go
View file @
8e8a68f6
...
...
@@ -44,6 +44,7 @@ type Activity struct {
ExcludeStandardBrandIdList
[]
string
CurrencyRmb
int
`json:"currency_rmb"`
CurrencyUs
int
`json:"currency_us"`
UseType
int
`json:"use_type"`
}
type
ActivityItem
struct
{
...
...
@@ -58,9 +59,10 @@ type ActivityItem struct {
AddTime
int
`json:"add_time"`
}
//用于检查是否有活动情况的结构体
//
用于检查是否有活动情况的结构体
type
ActivityCheckData
struct
{
SupplierId
int
GoodsName
string
BrandId
int
StandardBrandId
int
GoodsId
string
...
...
service/service_activity.go
View file @
8e8a68f6
...
...
@@ -5,6 +5,7 @@ import (
"fmt"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"strconv"
"strings"
"time"
...
...
@@ -16,7 +17,7 @@ import (
type
ActivityService
struct
{
}
//
获取活动信息,目前是包括促销活动(系数打折)以及满赠活动
//
获取活动信息,目前是包括促销活动(系数打折)以及满赠活动
func
(
as
*
ActivityService
)
GetActivityData
(
checkData
model
.
ActivityCheckData
)
(
priceActivity
model
.
PriceActivity
,
giftActivity
model
.
GiftActivity
)
{
supplierId
:=
checkData
.
SupplierId
redisCon
:=
gredis
.
Conn
(
"default_r"
)
...
...
@@ -36,7 +37,7 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p
return
}
//
获取满赠活动信息
//
获取满赠活动信息
func
(
as
*
ActivityService
)
GetGiftActivity
(
checkData
model
.
ActivityCheckData
,
activities
[]
model
.
Activity
)
(
giftActivity
model
.
GiftActivity
)
{
var
hasActivity
bool
nowTimestamp
:=
int
(
time
.
Now
()
.
Unix
())
...
...
@@ -105,6 +106,8 @@ func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, ac
}
func
(
as
*
ActivityService
)
GetPriceActivity
(
checkData
model
.
ActivityCheckData
,
activities
[]
model
.
Activity
)
(
priceActivity
model
.
PriceActivity
)
{
redisConn
:=
gredis
.
Conn
(
"default_r"
)
defer
redisConn
.
Close
()
var
hasActivity
bool
nowTimestamp
:=
int
(
time
.
Now
()
.
Unix
())
for
_
,
activity
:=
range
activities
{
...
...
@@ -128,7 +131,21 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if
checkData
.
SupplierId
==
17
{
if
as
.
CheckCanal
(
checkData
.
Canal
,
activity
)
{
if
checkData
.
Canal
!=
""
{
if
!
as
.
CheckCanal
(
checkData
.
Canal
,
activity
)
{
continue
}
}
if
activity
.
UseType
==
2
{
//判断商品名称是否在redis
redisKey
:=
"lie_activity_and_coupon_sku_"
+
strconv
.
Itoa
(
activity
.
ActivityId
)
exists
,
_
:=
redis
.
Bool
(
redisConn
.
Do
(
"hexists"
,
redisKey
,
checkData
.
GoodsName
))
if
exists
{
hasActivity
=
true
goto
INFO
}
}
else
{
//不等于2都是根据品牌来,因为老数据以前也只有品牌,0和1都是品牌
//品牌不为空,还要去判断品牌,是同时满足的关系
if
activity
.
StandardBrandIds
!=
""
{
//判断是否是搞活动的品牌
...
...
@@ -141,6 +158,7 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
goto
INFO
}
}
}
else
if
checkData
.
SupplierId
==
10000
{
//自营活动特殊判断
//判断活动指定的渠道编码,品牌,分类id,如果都为空,那么这个活动可以理解为整个供应商了,上面的排除已经会提前去判断了
...
...
@@ -162,11 +180,30 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
}
}
}
else
{
//这是针对代购的
//判断是否是搞活动的品牌
if
activity
.
UseType
==
2
{
//判断商品名称是否在redis
redisKey
:=
"lie_activity_and_coupon_sku_"
+
strconv
.
Itoa
(
activity
.
ActivityId
)
exists
,
_
:=
redis
.
Bool
(
redisConn
.
Do
(
"hexists"
,
redisKey
,
checkData
.
GoodsName
))
if
exists
{
hasActivity
=
true
goto
INFO
}
}
else
{
//不等于2都是根据品牌来,因为老数据以前也只有品牌,0和1都是品牌
//品牌不为空,还要去判断品牌,是同时满足的关系
if
activity
.
StandardBrandIds
!=
""
{
//判断是否是搞活动的品牌
if
as
.
CheckStandardBrand
(
checkData
.
StandardBrandId
,
activity
)
{
hasActivity
=
true
goto
INFO
}
}
else
{
hasActivity
=
true
goto
INFO
}
}
}
INFO
:
if
hasActivity
{
...
...
@@ -203,7 +240,7 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
return
}
//
检查是否属于被排除的品牌
//
检查是否属于被排除的品牌
func
(
as
*
ActivityService
)
CheckExcludeBrand
(
brandId
int
,
activity
model
.
Activity
)
bool
{
if
brandId
==
0
{
return
false
...
...
@@ -218,7 +255,7 @@ func (as *ActivityService) CheckExcludeBrand(brandId int, activity model.Activit
return
false
}
//
检查是否属于被排除的标准品牌
//
检查是否属于被排除的标准品牌
func
(
as
*
ActivityService
)
CheckExcludeStandardBrand
(
standardBrandId
int
,
activity
model
.
Activity
)
bool
{
if
standardBrandId
==
0
{
return
false
...
...
@@ -233,7 +270,7 @@ func (as *ActivityService) CheckExcludeStandardBrand(standardBrandId int, activi
return
false
}
//
检查是否属于被排除的sku
//
检查是否属于被排除的sku
func
(
as
*
ActivityService
)
CheckExcludeSku
(
skuId
string
,
activity
model
.
Activity
)
bool
{
if
skuId
==
""
{
return
false
...
...
@@ -247,7 +284,7 @@ func (as *ActivityService) CheckExcludeSku(skuId string, activity model.Activity
return
false
}
//
检查是否属于活动分类(只有自营需要判断)
//
检查是否属于活动分类(只有自营需要判断)
func
(
as
*
ActivityService
)
CheckClass
(
classId
int
,
activity
model
.
Activity
)
bool
{
if
classId
==
0
{
return
false
...
...
@@ -262,7 +299,7 @@ func (as *ActivityService) CheckClass(classId int, activity model.Activity) bool
return
false
}
//
检查是否属于活动品牌
//
检查是否属于活动品牌
func
(
as
*
ActivityService
)
CheckBrand
(
brandId
int
,
activity
model
.
Activity
)
bool
{
if
brandId
==
0
{
return
false
...
...
@@ -277,7 +314,7 @@ func (as *ActivityService) CheckBrand(brandId int, activity model.Activity) bool
return
false
}
//
检测是否属于活动标准品牌
//
检测是否属于活动标准品牌
func
(
as
*
ActivityService
)
CheckStandardBrand
(
standardBrandId
int
,
activity
model
.
Activity
)
bool
{
if
standardBrandId
==
0
{
return
false
...
...
@@ -292,7 +329,7 @@ func (as *ActivityService) CheckStandardBrand(standardBrandId int, activity mode
return
false
}
//
检查是否属于供应商渠道
//
检查是否属于供应商渠道
func
(
as
*
ActivityService
)
CheckCanal
(
canal
string
,
activity
model
.
Activity
)
bool
{
if
canal
==
""
{
return
false
...
...
service/service_ly.go
View file @
8e8a68f6
...
...
@@ -58,7 +58,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku
.
GoodsId
=
goodsId
spu
:=
spuList
[
sku
.
SpuId
]
//读取包装字段的缓存
if
sku
.
SupplierId
==
7
||
sku
.
SupplierId
==
13
{
if
sku
.
SupplierId
==
7
||
sku
.
SupplierId
==
13
||
sku
.
SupplierId
==
1688
{
//sku_raw_map哪里写入(成意写的)
packing
,
_
:=
redis
.
String
(
redisConnSpu
.
Do
(
"HGET"
,
"sku_raw_map"
,
goodsId
))
sku
.
Packing
=
gjson
.
Get
(
packing
,
"pack"
)
.
String
()
...
...
@@ -211,6 +211,7 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku {
GoodsId
:
sku
.
GoodsId
,
Canal
:
sku
.
Canal
,
ClassId
:
sku
.
ClassID2
,
GoodsName
:
sku
.
GoodsName
,
}
var
activityService
ActivityService
priceActivity
,
giftActivity
:=
activityService
.
GetActivityData
(
checkData
)
...
...
service/service_ly_common.go
View file @
8e8a68f6
...
...
@@ -2,7 +2,6 @@ package service
import
(
"encoding/json"
"fmt"
"github.com/gomodule/redigo/redis"
_
"github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go"
...
...
@@ -277,7 +276,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
)
//
fmt.Println(ladderPrice)
}
}
//获取折扣系数
...
...
@@ -433,7 +432,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
priceCostUs
:=
c
.
MulFloat
(
price
.
PriceUs
,
sku
.
DiscountRatio
.
RatioUsd
)
priceCostUs
=
c
.
MyRound
(
priceCostUs
,
4
)
//美金售价
fmt
.
Println
(
"计算美金价的系数"
,
priceRatio
.
RatioUsd
)
//
fmt.Println("计算美金价的系数", priceRatio.RatioUsd)
priceUs
:=
c
.
MulFloat
(
priceCostUs
,
priceRatio
.
RatioUsd
)
//人民币成本价,mro只有人民币,所以人民币价格不是从美金来的,而且人民币是含税的.就它要特殊处理
var
priceCostCn
float64
...
...
@@ -503,7 +502,7 @@ func (ls *LyService) GetCoefficientAndPrice(sku model.LySku) model.LySku {
sku
.
LadderPrice
=
data
}
fmt
.
Println
(
sku
.
PriceRatio
,
sku
.
PriceRatioSort
)
//
fmt.Println(sku.PriceRatio, sku.PriceRatioSort)
return
sku
}
service/service_price.go
View file @
8e8a68f6
...
...
@@ -94,6 +94,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
if
brandIds
!=
""
{
hasSpecialCheck
=
true
standardBrandIdList
:=
strings
.
Split
(
brandIds
,
","
)
fmt
.
Println
(
standardBrandIdList
)
standardBrandId
:=
strconv
.
Itoa
(
sku
.
StandardBrand
.
StandardBrandId
)
//找到有对应的品牌,那么优先级肯定是最高的了
if
php2go
.
InArray
(
standardBrandId
,
standardBrandIdList
)
{
...
...
@@ -156,7 +157,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
}
//找不到特定的系数,那就去找全局的
if
!
foundRatio
{
fmt
.
Println
(
"去找默认系数"
)
//
fmt.Println("去找默认系数")
priceRatioCache
,
_
=
redis
.
String
(
redisCon
.
Do
(
"GET"
,
"magic_cube_price_rule_v2_default"
))
priceRatioArr
:=
gjson
.
Get
(
priceRatioCache
,
ratioDataKey
)
.
Array
()
priceRatioList
=
nil
...
...
@@ -174,16 +175,16 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//这是用来展示在商品服务的价格系数,专营的系数和代购的不一样,所以要转换一下展示形式
//是否有设置最低利润点阶梯,不足5个阶梯时,最高阶梯对应的最小利润点阶梯
var
ladderPriceMiniProfitLevel
int
fmt
.
Println
(
"是否找到系数"
,
foundRatio
)
//
fmt.Println("是否找到系数", foundRatio)
//fmt.Println("系数redis数据为 : ", priceRatioCache)
fmt
.
Println
(
"具体系数为 : "
,
priceRatioList
)
//
fmt.Println("具体系数为 : ", priceRatioList)
if
foundRatio
{
priceRatioSortStr
:=
strconv
.
Itoa
(
priceRatioSort
)
ladderPriceMiniProfitLevel
=
int
(
gjson
.
Get
(
priceRatioCache
,
"ladder_price_mini_profit_level."
+
priceRatioSortStr
)
.
Int
())
}
else
{
ladderPriceMiniProfitLevel
=
int
(
gjson
.
Get
(
priceRatioCache
,
"ladder_price_mini_profit_level"
)
.
Int
())
}
fmt
.
Println
(
"最低利润点阶梯数 : "
,
ladderPriceMiniProfitLevel
)
//
fmt.Println("最低利润点阶梯数 : ", ladderPriceMiniProfitLevel)
var
generatedLadderPrice
[]
model
.
LadderPrice
//先直接获取成本价原始值,判断第一个阶梯的阶梯数量是否为0,如果是0,那么代表是要走成本价生成,如果不是0,那么就要走阶梯价生成
firstLadderPurchases
:=
sku
.
LadderPrice
[
0
]
.
Purchases
...
...
@@ -191,7 +192,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//判断是否走成本价判断还是走阶梯价判断,因为上传sku的时候,可以设置每个sku的成本价(人民币&&美金),也可以设置每个sku的阶梯价
//如果有阶梯价,就要跳过设置的成本价(假设有设置的话)
if
isCostPrice
{
fmt
.
Println
(
"成本价"
)
//
fmt.Println("成本价")
costPriceCn
:=
sku
.
LadderPrice
[
0
]
.
PriceCn
costPriceUs
:=
sku
.
LadderPrice
[
0
]
.
PriceUs
//fmt.Println("人民币和美金的成本价分别为 : ", costPriceCn, costPriceUs)
...
...
@@ -279,8 +280,8 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
}
costLadderCount
++
}
fmt
.
Println
(
"阶梯数量为 : "
,
costLadderCount
)
fmt
.
Println
(
"设置的利润阶梯为 : "
,
ladderPriceMiniProfitLevel
)
//
fmt.Println("阶梯数量为 : ", costLadderCount)
//
fmt.Println("设置的利润阶梯为 : ", ladderPriceMiniProfitLevel)
if
costLadderCount
<=
ladderPriceMiniProfitLevel
{
for
i
:=
0
;
i
<
costLadderCount
;
i
++
{
priceRatioAndPurchases
:=
priceRatioList
[
i
]
...
...
@@ -296,7 +297,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//如:库存满足1、2、3层阶梯,最小利润点层级是第5个层级,则利润点取3、4、5层级的
//最小利润点层级 - 库存满足多少个阶梯 + i
costMapIndex
:=
ladderPriceMiniProfitLevel
-
costLadderCount
+
i
fmt
.
Println
(
costMapIndex
)
//
fmt.Println(costMapIndex)
if
costMapIndex
<=
0
{
costMapIndex
=
0
}
...
...
@@ -363,7 +364,7 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
priceCnRatio
:=
priceRatio
.
Ratio
priceUsRatio
:=
priceRatio
.
RatioUsd
// 阶梯价格系数正序取
fmt
.
Println
(
"价格:"
,
c
.
MulFloat
(
ladder
.
PriceCn
,
priceCnRatio
))
//
fmt.Println("价格:",c.MulFloat(ladder.PriceCn, priceCnRatio))
generatedLadderPrice
=
append
(
generatedLadderPrice
,
model
.
LadderPrice
{
Purchases
:
ladder
.
Purchases
,
PriceCn
:
c
.
MyRound
(
c
.
MulFloat
(
ladder
.
PriceCn
,
priceCnRatio
),
5
),
...
...
@@ -653,13 +654,13 @@ func (ps *PriceService) TransformSpecialSupplierPrice(sku model.LySku, priceUs f
}
else
{
currency
,
_
=
redis
.
Int
(
redisCon
.
Do
(
"HGET"
,
"magic_cube_supplier_currency"
,
sku
.
Canal
))
}
fmt
.
Println
(
"进来的美金价格:"
,
priceUs
)
//
fmt.Println("进来的美金价格:", priceUs)
if
currency
>
0
{
//这里进行转换,因为这里都只能取到对应的币种转人民币的比率,我们没有直接各种币种转美金的数据,所以我这边要
//先根据对应币种转人民币,然后根据人民币转美金,才能得到不同币种对应美金的汇率
rmbRatio
,
_
:=
redis
.
Float64
(
redisCon
.
Do
(
"HGET"
,
"erp_rate"
,
currency
))
fmt
.
Println
(
"特殊转换"
,
rmbRatio
)
fmt
.
Println
(
rmbRatio
,
usRatio
)
//
fmt.Println("特殊转换", rmbRatio)
//
fmt.Println(rmbRatio, usRatio)
//人民币汇率转美金汇率
usRatio
=
c
.
MyRound
(
c
.
DivFloat
(
rmbRatio
,
usRatio
),
6
)
...
...
service/service_zy_common.go
View file @
8e8a68f6
...
...
@@ -38,7 +38,7 @@ func (qs *ZiyingService) skuLockNum(c *redis.Conn, goodsId string) int64 {
}
/*
获取自营活动价
获取自营活动价
*/
func
(
qs
*
ZiyingService
)
ActivityPrice
(
ctx
*
gin
.
Context
,
SkuInfo
string
)
*
orderedmap
.
OrderedMap
{
data
:=
qs
.
HDActivityPrice
(
SkuInfo
)
...
...
@@ -48,7 +48,7 @@ func (qs *ZiyingService) ActivityPrice(ctx *gin.Context, SkuInfo string) *ordere
return
nil
}
//获取活动相关信息
//
获取活动相关信息
func
(
qs
*
ZiyingService
)
GetActivity
(
skuInfo
string
)
(
priceActivity
model
.
PriceActivity
,
giftActivity
model
.
GiftActivity
)
{
//去判断是否有活动(促销打折活动和满赠活动)
var
standardBrandId
int
...
...
@@ -72,6 +72,7 @@ func (qs *ZiyingService) GetActivity(skuInfo string) (priceActivity model.PriceA
StandardBrandId
:
standardBrandId
,
GoodsId
:
gjson
.
Get
(
skuInfo
,
"goods_id"
)
.
String
(),
ClassId
:
int
(
gjson
.
Get
(
skuInfo
,
"class_id2"
)
.
Int
()),
GoodsName
:
gjson
.
Get
(
skuInfo
,
"goods_name"
)
.
String
(),
}
var
activityService
ActivityService
priceActivity
,
giftActivity
=
activityService
.
GetActivityData
(
checkData
)
...
...
@@ -85,7 +86,6 @@ ac_type说明: 0 没有活动
活动名称 ac_type 类型
自营系数 6 自营
折扣(系数)活动 10 自营/联营
*/
func
(
qs
*
ZiyingService
)
HDActivityPrice
(
SkuInfo
string
)
*
orderedmap
.
OrderedMap
{
priceActivity
,
giftActivity
:=
qs
.
GetActivity
(
SkuInfo
)
...
...
@@ -132,7 +132,7 @@ func (qs *ZiyingService) HDActivityPrice(SkuInfo string) *orderedmap.OrderedMap
}
/*
获取当前锁住的库存
获取当前锁住的库存
*/
func
(
qs
*
ZiyingService
)
HDGoodsLimit
(
SkuID
string
,
Stock
string
,
c
*
redis
.
Conn
)
*
orderedmap
.
OrderedMap
{
...
...
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