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
bc8f6310
authored
Jan 08, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
联营商品服务
parent
756df35c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
48 deletions
model/activity.go
model/ly_sku.go
service/service_activity.go
service/service_ly.go
service/service_price.go
model/activity.go
View file @
bc8f6310
...
...
@@ -35,6 +35,7 @@ type Activity struct {
AdminName
string
`json:"admin_name"`
ActivityId
int
`json:"activity_id"`
ItemList
[]
ActivityItem
`json:"item_list"`
EntireSupplierActivity
bool
`json:"entire_supplier_activity"`
}
type
ActivityItem
struct
{
...
...
model/ly_sku.go
View file @
bc8f6310
...
...
@@ -32,7 +32,6 @@ type LySku struct {
SupplierName
string
`json:"supplier_name"`
Attrs
interface
{}
`json:"attrs"`
ScmBrand
interface
{}
`json:"scm_brand"`
AcType
int
`json:"ac_type"`
AllowCoupon
int
`json:"allow_coupon"`
BrandId
int64
`json:"brand_id"`
//系数相关
...
...
@@ -61,24 +60,32 @@ type LySku struct {
Ratio
float64
`json:"ratio,omitempty"`
SpuDetail
string
`json:"spu_detail,omitempty"`
AcType
int
`json:"ac_type"`
//活动信息
HasGiftActivity
int
`json:"has_gift_activity"`
GiftActivity
GiftActivity
`json:"gift_activity"`
HasGiftActivity
int
`json:"has_gift_activity"`
GiftActivity
GiftActivity
`json:"gift_activity"`
ActivityInfo
struct
{
ActivityId
int
`json:"activity_id,omitempty"`
ActivityName
string
`json:"activity_name,omitempty"`
}
`json:"activity_info"`
}
type
PriceActivity
struct
{
HasActivity
bool
`json:"-"`
ActivityId
int
`json:"activity_id,omitempty"`
Ratio
float64
`json:"ratio"`
HasActivity
bool
`json:"-"`
ActivityId
int
`json:"activity_id,omitempty"`
ActivityName
string
`json:"activity_name,omitempty"`
AllowCoupon
int
`json:"-"`
Ratio
float64
`json:"ratio"`
}
type
GiftActivity
struct
{
HasActivity
bool
`json:"-"`
ActivityId
int
`json:"activity_id,omitempty"`
ItemList
[]
ActivityItem
`json:"items,omitempty"`
HasActivity
bool
`json:"-"`
ActivityId
int
`json:"activity_id,omitempty"`
ActivityName
int
`json:"activity_name,omitempty"`
AllowCoupon
int
`json:"-"`
ItemList
[]
ActivityItem
`json:"items,omitempty"`
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func
InitSkuData
(
sku
string
)
(
data
LySku
)
{
goodsSn
:=
gjson
.
Get
(
sku
,
"goods_sn"
)
.
String
()
...
...
service/service_activity.go
View file @
bc8f6310
...
...
@@ -9,6 +9,7 @@ import (
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"strings"
"time"
)
type
ActivityService
struct
{
...
...
@@ -49,7 +50,21 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p
//获取满赠活动信息
func
(
as
*
ActivityService
)
GetGiftActivity
(
checkData
model
.
ActivityCheckData
,
activities
[]
model
.
Activity
)
(
giftActivity
model
.
GiftActivity
)
{
var
hasActivity
bool
nowTimestamp
:=
int
(
time
.
Now
()
.
Unix
())
for
_
,
activity
:=
range
activities
{
//判断时间是否过期
if
activity
.
StartTime
>
nowTimestamp
||
activity
.
EndTime
<
nowTimestamp
{
return
}
//如果是整个供应商搞活动,则直接返回系数
if
activity
.
EntireSupplierActivity
{
hasActivity
=
true
giftActivity
.
ItemList
=
activity
.
ItemList
giftActivity
.
ActivityId
=
activity
.
ActivityId
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if
as
.
CheckExcludeSku
(
checkData
.
GoodsId
,
activity
)
||
as
.
CheckExcludeBrand
(
checkData
.
BrandId
,
activity
)
{
hasActivity
=
false
...
...
@@ -77,14 +92,25 @@ func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, ac
}
}
}
giftActivity
.
HasActivity
=
hasActivity
return
}
func
(
as
*
ActivityService
)
GetPriceActivity
(
checkData
model
.
ActivityCheckData
,
activities
[]
model
.
Activity
)
(
priceActivity
model
.
PriceActivity
)
{
var
hasActivity
bool
nowTimestamp
:=
int
(
time
.
Now
()
.
Unix
())
for
_
,
activity
:=
range
activities
{
//判断时间是否过期
if
activity
.
StartTime
>
nowTimestamp
||
activity
.
EndTime
<
nowTimestamp
{
return
}
//如果是整个供应商搞活动,则直接返回系数
if
activity
.
EntireSupplierActivity
{
hasActivity
=
true
priceActivity
.
Ratio
=
activity
.
Ratio
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if
as
.
CheckExcludeSku
(
checkData
.
GoodsId
,
activity
)
||
as
.
CheckExcludeBrand
(
checkData
.
BrandId
,
activity
)
{
hasActivity
=
false
...
...
@@ -108,13 +134,13 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
priceActivity
.
Ratio
=
activity
.
Ratio
}
}
//判断是否是搞活动的品牌
if
as
.
CheckSkuId
(
checkData
.
GoodsId
,
activity
)
{
hasActivity
=
true
priceActivity
.
Ratio
=
activity
.
Ratio
if
hasActivity
{
priceActivity
.
AllowCoupon
=
activity
.
AllowCoupon
priceActivity
.
ActivityName
=
activity
.
ActivityName
priceActivity
.
ActivityId
=
activity
.
ActivityId
}
}
priceActivity
.
HasActivity
=
hasActivity
return
}
...
...
@@ -191,18 +217,3 @@ func (as *ActivityService) CheckCanal(canal string, activity model.Activity) boo
}
return
false
}
//检查是否属于活动sku_id
func
(
as
*
ActivityService
)
CheckSkuId
(
skuId
string
,
activity
model
.
Activity
)
bool
{
if
skuId
==
""
{
return
false
}
//先去判断品牌
activity
.
SkuIdList
=
strings
.
Split
(
activity
.
SkuIds
,
","
)
skuIdStr
:=
gconv
.
String
(
skuId
)
//如果存在于有活动价的品牌,就是有折扣活动了
if
php2go
.
InArray
(
skuIdStr
,
activity
.
SkuIdList
)
{
return
true
}
return
false
}
service/service_ly.go
View file @
bc8f6310
...
...
@@ -118,23 +118,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku
.
AllowCoupon
=
1
sku
.
BrandId
=
brandId
//去判断是否有活动(促销打折活动和满赠活动)
checkData
:=
model
.
ActivityCheckData
{
SupplierId
:
int
(
sku
.
SupplierId
),
BrandId
:
int
(
sku
.
BrandId
),
GoodsId
:
sku
.
GoodsId
,
Canal
:
sku
.
Canal
,
ClassId
:
sku
.
ClassID2
,
}
var
activityService
ActivityService
priceActivity
,
giftActivity
:=
activityService
.
GetActivityData
(
checkData
)
if
priceActivity
.
HasActivity
{
sku
.
AcType
=
9
}
if
giftActivity
.
HasActivity
{
sku
.
HasGiftActivity
=
gconv
.
Int
(
giftActivity
.
HasActivity
)
sku
.
GiftActivity
=
giftActivity
}
sku
=
ls
.
GetActivity
(
sku
)
//处理阶梯价数据
if
len
(
sku
.
LadderPrice
)
>
0
{
...
...
@@ -188,3 +172,33 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
}
ch
<-
GoodsRes
}
//获取活动
func
(
ls
*
LyService
)
GetActivity
(
sku
model
.
LySku
)
model
.
LySku
{
//去判断是否有活动(促销打折活动和满赠活动)
checkData
:=
model
.
ActivityCheckData
{
SupplierId
:
int
(
sku
.
SupplierId
),
BrandId
:
int
(
sku
.
BrandId
),
GoodsId
:
sku
.
GoodsId
,
Canal
:
sku
.
Canal
,
ClassId
:
sku
.
ClassID2
,
}
var
activityService
ActivityService
priceActivity
,
giftActivity
:=
activityService
.
GetActivityData
(
checkData
)
if
priceActivity
.
HasActivity
{
sku
.
AcType
=
10
sku
.
Ratio
=
priceActivity
.
Ratio
sku
.
ActivityInfo
.
ActivityId
=
priceActivity
.
ActivityId
sku
.
ActivityInfo
.
ActivityName
=
priceActivity
.
ActivityName
}
if
giftActivity
.
HasActivity
{
sku
.
HasGiftActivity
=
gconv
.
Int
(
giftActivity
.
HasActivity
)
sku
.
GiftActivity
=
giftActivity
}
//获取是否能使用优惠券
if
giftActivity
.
AllowCoupon
!=
1
||
priceActivity
.
AllowCoupon
!=
1
{
sku
.
AllowCoupon
=
0
}
return
sku
}
service/service_price.go
View file @
bc8f6310
...
...
@@ -11,6 +11,9 @@ import (
"time"
)
type
PriceService
struct
{
}
//获取联营活动价
func
(
ls
*
LyService
)
GetActivityPrice
(
sku
model
.
LySku
,
suffix
string
,
power
Power
)
model
.
LySku
{
//没价格,直接返回
...
...
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