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
5003b2fe
authored
Jan 12, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'ysx-价格体系修改-20210106' into dev
parents
07aab597
76b494a9
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
384 additions
and
442 deletions
model/activity.go
model/ly_sku.go
service/service_activity.go
service/service_ly.go
service/service_price.go
service/service_zy.go
service/service_zy_common.go
model/activity.go
View file @
5003b2fe
...
@@ -35,6 +35,7 @@ type Activity struct {
...
@@ -35,6 +35,7 @@ type Activity struct {
AdminName
string
`json:"admin_name"`
AdminName
string
`json:"admin_name"`
ActivityId
int
`json:"activity_id"`
ActivityId
int
`json:"activity_id"`
ItemList
[]
ActivityItem
`json:"item_list"`
ItemList
[]
ActivityItem
`json:"item_list"`
EntireSupplierActivity
bool
`json:"entire_supplier_activity"`
}
}
type
ActivityItem
struct
{
type
ActivityItem
struct
{
...
...
model/ly_sku.go
View file @
5003b2fe
...
@@ -32,7 +32,6 @@ type LySku struct {
...
@@ -32,7 +32,6 @@ type LySku struct {
SupplierName
string
`json:"supplier_name"`
SupplierName
string
`json:"supplier_name"`
Attrs
interface
{}
`json:"attrs"`
Attrs
interface
{}
`json:"attrs"`
ScmBrand
interface
{}
`json:"scm_brand"`
ScmBrand
interface
{}
`json:"scm_brand"`
AcType
int
`json:"ac_type"`
AllowCoupon
int
`json:"allow_coupon"`
AllowCoupon
int
`json:"allow_coupon"`
BrandId
int64
`json:"brand_id"`
BrandId
int64
`json:"brand_id"`
//系数相关
//系数相关
...
@@ -61,23 +60,32 @@ type LySku struct {
...
@@ -61,23 +60,32 @@ type LySku struct {
Ratio
float64
`json:"ratio,omitempty"`
Ratio
float64
`json:"ratio,omitempty"`
SpuDetail
string
`json:"spu_detail,omitempty"`
SpuDetail
string
`json:"spu_detail,omitempty"`
AcType
int
`json:"ac_type"`
//活动信息
//活动信息
HasGiftActivity
int
`json:"has_gift_activity"`
HasGiftActivity
int
`json:"has_gift_activity"`
GiftActivity
GiftActivity
`json:"gift_activity"`
GiftActivity
GiftActivity
`json:"gift_activity"`
ActivityInfo
PriceActivity
`json:"activity_info"`
}
}
type
PriceActivity
struct
{
type
PriceActivity
struct
{
HasActivity
bool
`json:"-"`
ActivityCommon
ActivityId
int
`json:"activity_id,omitempty"`
Ratio
float64
`json:"ratio"`
Ratio
float64
`json:"ratio"`
}
}
type
GiftActivity
struct
{
type
GiftActivity
struct
{
HasActivity
bool
`json:"-"`
ActivityCommon
ActivityId
int
`json:"activity_id,omitempty"`
ItemList
[]
ActivityItem
`json:"items,omitempty"`
ItemList
[]
ActivityItem
`json:"items,omitempty"`
}
}
type
ActivityCommon
struct
{
HasActivity
bool
`json:"-"`
ActivityId
int
`json:"activity_id,omitempty"`
ActivityName
string
`json:"activity_name,omitempty"`
AllowCoupon
int
`json:"-"`
SignText
string
`json:"sign_text"`
Sign
string
`json:"sign"`
ShowName
string
`json:"show_name"`
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func
InitSkuData
(
sku
string
)
(
data
LySku
)
{
func
InitSkuData
(
sku
string
)
(
data
LySku
)
{
...
...
service/service_activity.go
View file @
5003b2fe
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"go_sku_server/model"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/gredis"
"strings"
"strings"
"time"
)
)
type
ActivityService
struct
{
type
ActivityService
struct
{
...
@@ -49,72 +50,142 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p
...
@@ -49,72 +50,142 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p
//获取满赠活动信息
//获取满赠活动信息
func
(
as
*
ActivityService
)
GetGiftActivity
(
checkData
model
.
ActivityCheckData
,
activities
[]
model
.
Activity
)
(
giftActivity
model
.
GiftActivity
)
{
func
(
as
*
ActivityService
)
GetGiftActivity
(
checkData
model
.
ActivityCheckData
,
activities
[]
model
.
Activity
)
(
giftActivity
model
.
GiftActivity
)
{
var
hasActivity
bool
var
hasActivity
bool
nowTimestamp
:=
int
(
time
.
Now
()
.
Unix
())
for
_
,
activity
:=
range
activities
{
for
_
,
activity
:=
range
activities
{
//判断时间是否过期
if
activity
.
StartTime
>
nowTimestamp
||
activity
.
EndTime
<
nowTimestamp
{
return
}
//如果是整个供应商搞活动,则直接返回系数
if
activity
.
EntireSupplierActivity
{
hasActivity
=
true
goto
INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if
as
.
CheckExcludeSku
(
checkData
.
GoodsId
,
activity
)
||
as
.
CheckExcludeBrand
(
checkData
.
BrandId
,
activity
)
{
if
as
.
CheckExcludeSku
(
checkData
.
GoodsId
,
activity
)
||
as
.
CheckExcludeBrand
(
checkData
.
BrandId
,
activity
)
{
hasActivity
=
false
hasActivity
=
false
goto
INFO
}
}
//判断是否是搞活动的品牌
//判断是否是搞活动的品牌
if
as
.
CheckBrand
(
checkData
.
BrandId
,
activity
)
{
if
as
.
CheckBrand
(
checkData
.
BrandId
,
activity
)
{
hasActivity
=
true
hasActivity
=
true
giftActivity
.
ItemList
=
activity
.
ItemList
goto
INFO
giftActivity
.
ActivityId
=
activity
.
ActivityId
}
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if
checkData
.
SupplierId
==
17
{
if
checkData
.
SupplierId
==
17
{
if
as
.
CheckCanal
(
checkData
.
Canal
,
activity
)
{
if
as
.
CheckCanal
(
checkData
.
Canal
,
activity
)
{
hasActivity
=
true
hasActivity
=
true
giftActivity
.
ItemList
=
activity
.
ItemList
goto
INFO
giftActivity
.
ActivityId
=
activity
.
ActivityId
}
}
}
else
{
}
else
{
if
as
.
CheckClass
(
checkData
.
ClassId
,
activity
)
{
if
as
.
CheckClass
(
checkData
.
ClassId
,
activity
)
{
hasActivity
=
true
hasActivity
=
true
giftActivity
.
ItemList
=
activity
.
ItemList
goto
INFO
giftActivity
.
ActivityId
=
activity
.
ActivityId
}
}
INFO
:
if
hasActivity
{
giftActivity
.
ActivityName
=
activity
.
ActivityName
giftActivity
.
ActivityId
=
activity
.
ActivityId
giftActivity
=
model
.
GiftActivity
{
ItemList
:
activity
.
ItemList
,
ActivityCommon
:
model
.
ActivityCommon
{
HasActivity
:
hasActivity
,
ActivityId
:
activity
.
ActivityId
,
ActivityName
:
activity
.
ActivityName
,
AllowCoupon
:
activity
.
AllowCoupon
,
SignText
:
activity
.
SignText
,
Sign
:
activity
.
Sign
,
ShowName
:
activity
.
ShowName
,
},
}
}
}
}
}
}
giftActivity
.
HasActivity
=
hasActivity
return
return
}
}
func
(
as
*
ActivityService
)
GetPriceActivity
(
checkData
model
.
ActivityCheckData
,
activities
[]
model
.
Activity
)
(
priceActivity
model
.
PriceActivity
)
{
func
(
as
*
ActivityService
)
GetPriceActivity
(
checkData
model
.
ActivityCheckData
,
activities
[]
model
.
Activity
)
(
priceActivity
model
.
PriceActivity
)
{
var
hasActivity
bool
var
hasActivity
bool
nowTimestamp
:=
int
(
time
.
Now
()
.
Unix
())
for
_
,
activity
:=
range
activities
{
for
_
,
activity
:=
range
activities
{
//判断时间是否过期
if
activity
.
StartTime
>
nowTimestamp
||
activity
.
EndTime
<
nowTimestamp
{
return
}
//如果是整个供应商搞活动,则直接返回系数
if
activity
.
EntireSupplierActivity
{
hasActivity
=
true
goto
INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if
as
.
CheckExcludeSku
(
checkData
.
GoodsId
,
activity
)
||
as
.
CheckExcludeBrand
(
checkData
.
BrandId
,
activity
)
{
if
as
.
CheckExcludeSku
(
checkData
.
GoodsId
,
activity
)
||
as
.
CheckExcludeBrand
(
checkData
.
BrandId
,
activity
)
{
hasActivity
=
false
hasActivity
=
false
}
goto
INFO
//判断是否是搞活动的品牌
if
as
.
CheckBrand
(
checkData
.
BrandId
,
activity
)
{
hasActivity
=
true
priceActivity
.
Ratio
=
activity
.
Ratio
}
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if
checkData
.
SupplierId
==
17
{
if
checkData
.
SupplierId
==
17
{
if
as
.
CheckCanal
(
checkData
.
Canal
,
activity
)
{
if
as
.
CheckCanal
(
checkData
.
Canal
,
activity
)
{
hasActivity
=
true
//品牌不为空,还要去判断品牌,是同时满足的关系
priceActivity
.
Ratio
=
activity
.
Ratio
if
activity
.
BrandIds
!=
""
{
//判断是否是搞活动的品牌
if
as
.
CheckBrand
(
checkData
.
BrandId
,
activity
)
{
hasActivity
=
true
goto
INFO
}
}
else
{
hasActivity
=
true
goto
INFO
}
}
}
}
else
{
}
else
if
checkData
.
SupplierId
==
10000
{
if
as
.
CheckClass
(
checkData
.
ClassId
,
activity
)
{
if
as
.
CheckClass
(
checkData
.
ClassId
,
activity
)
{
//品牌不为空,还要去判断品牌,是同时满足的关系
if
activity
.
BrandIds
!=
""
{
//判断是否是搞活动的品牌
if
as
.
CheckBrand
(
checkData
.
BrandId
,
activity
)
{
hasActivity
=
true
goto
INFO
}
}
else
{
hasActivity
=
true
goto
INFO
}
}
}
else
{
//判断是否是搞活动的品牌
if
as
.
CheckBrand
(
checkData
.
BrandId
,
activity
)
{
hasActivity
=
true
hasActivity
=
true
priceActivity
.
Ratio
=
activity
.
Ratio
goto
INFO
}
}
}
}
INFO
:
//判断是否是搞活动的品牌
if
hasActivity
{
if
as
.
CheckSkuId
(
checkData
.
GoodsId
,
activity
)
{
priceActivity
.
ActivityName
=
activity
.
ActivityName
hasActivity
=
true
priceActivity
.
ActivityId
=
activity
.
ActivityId
priceActivity
.
Ratio
=
activity
.
Ratio
priceActivity
=
model
.
PriceActivity
{
Ratio
:
activity
.
Ratio
,
ActivityCommon
:
model
.
ActivityCommon
{
HasActivity
:
hasActivity
,
ActivityId
:
activity
.
ActivityId
,
ActivityName
:
activity
.
ActivityName
,
AllowCoupon
:
activity
.
AllowCoupon
,
SignText
:
activity
.
SignText
,
Sign
:
activity
.
Sign
,
ShowName
:
activity
.
ShowName
,
},
}
}
}
}
}
priceActivity
.
HasActivity
=
hasActivity
priceActivity
.
HasActivity
=
hasActivity
return
return
}
}
...
@@ -191,18 +262,3 @@ func (as *ActivityService) CheckCanal(canal string, activity model.Activity) boo
...
@@ -191,18 +262,3 @@ func (as *ActivityService) CheckCanal(canal string, activity model.Activity) boo
}
}
return
false
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 @
5003b2fe
...
@@ -118,23 +118,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
...
@@ -118,23 +118,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku
.
AllowCoupon
=
1
sku
.
AllowCoupon
=
1
sku
.
BrandId
=
brandId
sku
.
BrandId
=
brandId
//去判断是否有活动(促销打折活动和满赠活动)
sku
=
ls
.
GetActivity
(
sku
)
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
}
//处理阶梯价数据
//处理阶梯价数据
if
len
(
sku
.
LadderPrice
)
>
0
{
if
len
(
sku
.
LadderPrice
)
>
0
{
...
@@ -188,3 +172,32 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
...
@@ -188,3 +172,32 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
}
}
ch
<-
GoodsRes
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
=
priceActivity
}
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 @
5003b2fe
...
@@ -11,6 +11,9 @@ import (
...
@@ -11,6 +11,9 @@ import (
"time"
"time"
)
)
type
PriceService
struct
{
}
//获取联营活动价
//获取联营活动价
func
(
ls
*
LyService
)
GetActivityPrice
(
sku
model
.
LySku
,
suffix
string
,
power
Power
)
model
.
LySku
{
func
(
ls
*
LyService
)
GetActivityPrice
(
sku
model
.
LySku
,
suffix
string
,
power
Power
)
model
.
LySku
{
//没价格,直接返回
//没价格,直接返回
...
...
service/service_zy.go
View file @
5003b2fe
...
@@ -31,31 +31,30 @@ type ZiyingService struct {
...
@@ -31,31 +31,30 @@ type ZiyingService struct {
@param power[special_invoice] 增值税专用发票公司名字,活动价时需要,否则可能导致用户无法享受活动价 : 深圳是猎芯科技有限公司
@param power[special_invoice] 增值税专用发票公司名字,活动价时需要,否则可能导致用户无法享受活动价 : 深圳是猎芯科技有限公司
@param power[verify_blacklist] 是否验证黑名单,用于折扣活动提交订单页面与后台下单 :true
@param power[verify_blacklist] 是否验证黑名单,用于折扣活动提交订单页面与后台下单 :true
*/
*/
func
(
qs
*
ZiyingService
)
ZyGoodsDetail
(
ctx
*
gin
.
Context
,
goodsIds
[]
string
,
ch
chan
sync
.
Map
)
{
func
(
qs
*
ZiyingService
)
ZyGoodsDetail
(
ctx
*
gin
.
Context
,
goodsIds
[]
string
,
ch
chan
sync
.
Map
)
{
redisConn
:=
gredis
.
Conn
(
"search_r"
)
redisConn
:=
gredis
.
Conn
(
"search_r"
)
defer
func
()
{
defer
func
()
{
//wg.Done();
//wg.Done();
redisConn
.
Close
()
;
redisConn
.
Close
()
}()
}()
skuArr
:=
gredis
.
Hmget
(
"search_r"
,
"Self_SelfGoods"
,
goodsIds
)
//批量获取商品详情
skuArr
:=
gredis
.
Hmget
(
"search_r"
,
"Self_SelfGoods"
,
goodsIds
)
//批量获取商品详情
fast
:=
ctx
.
Request
.
FormValue
(
"power[fast]"
)
fast
:=
ctx
.
Request
.
FormValue
(
"power[fast]"
)
GoodsRes
:=
sync
.
Map
{}
GoodsRes
:=
sync
.
Map
{}
for
goods
_id
,
info
:=
range
skuArr
{
for
goods
Id
,
info
:=
range
skuArr
{
if
gjson
.
Get
(
info
,
"goods_name"
)
.
String
()
==
""
{
if
gjson
.
Get
(
info
,
"goods_name"
)
.
String
()
==
""
{
//fmt.Print("zy goods_name为空-----",goods_id,skuArr)
//fmt.Print("zy goods_name为空-----",goods_id,skuArr)
GoodsRes
.
Store
(
goods
_id
,
false
)
GoodsRes
.
Store
(
goods
Id
,
false
)
continue
;
continue
}
}
//拼接属性
//拼接属性
attrJsonArr
:=
gjson
.
Parse
(
gjson
.
Get
(
info
,
"attrs"
)
.
String
())
.
Array
()
attrJsonArr
:=
gjson
.
Parse
(
gjson
.
Get
(
info
,
"attrs"
)
.
String
())
.
Array
()
attrs
:=
make
([]
model
.
Attrs
,
0
)
attrs
:=
make
([]
model
.
Attrs
,
0
)
for
_
,
d
:=
range
attrJsonArr
{
for
_
,
d
:=
range
attrJsonArr
{
if
d
.
Get
(
"attr_name"
)
.
String
()
==
""
{
if
d
.
Get
(
"attr_name"
)
.
String
()
==
""
{
continue
;
continue
}
}
attrs
=
append
(
attrs
,
model
.
Attrs
{
attrs
=
append
(
attrs
,
model
.
Attrs
{
AttrName
:
d
.
Get
(
"attr_name"
)
.
String
(),
AttrName
:
d
.
Get
(
"attr_name"
)
.
String
(),
...
@@ -64,236 +63,234 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string, ch ch
...
@@ -64,236 +63,234 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string, ch ch
}
}
//数组
//数组
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
A
.
Set
(
"goods_id"
,
common
.
MyInt64
(
goods_i
d
))
A
.
Set
(
"goods_id"
,
common
.
MyInt64
(
goodsI
d
))
A
.
Set
(
"goods_type"
,
gjson
.
Get
(
info
,
"goods_type"
)
.
Int
())
//查询总条数
A
.
Set
(
"goods_type"
,
gjson
.
Get
(
info
,
"goods_type"
)
.
Int
())
//查询总条数
A
.
Set
(
"supplier_id"
,
gjson
.
Get
(
info
,
"supplier_id"
)
.
Int
())
//查询总条数
A
.
Set
(
"supplier_id"
,
gjson
.
Get
(
info
,
"supplier_id"
)
.
Int
())
//查询总条数
A
.
Set
(
"brand_id"
,
gjson
.
Get
(
info
,
"brand_id"
)
.
Int
())
//
A
.
Set
(
"brand_id"
,
gjson
.
Get
(
info
,
"brand_id"
)
.
Int
())
//
other
_attrs
:=
gjson
.
Get
(
info
,
"other_attrs"
)
.
String
()
other
Attrs
:=
gjson
.
Get
(
info
,
"other_attrs"
)
.
String
()
if
other
_a
ttrs
==
""
{
if
other
A
ttrs
==
""
{
A
.
Set
(
"other_attrs"
,
""
)
A
.
Set
(
"other_attrs"
,
""
)
}
else
{
}
else
{
B
:=
make
(
map
[
string
]
string
)
B
:=
make
(
map
[
string
]
string
)
pick
_type
:=
gjson
.
Get
(
other_attrs
,
"pick_type"
)
.
String
()
pick
Type
:=
gjson
.
Get
(
otherAttrs
,
"pick_type"
)
.
String
()
length
:=
gjson
.
Get
(
other
_attrs
,
"length"
)
.
String
()
length
:=
gjson
.
Get
(
other
Attrs
,
"length"
)
.
String
()
gross
_wegiht
:=
gjson
.
Get
(
other_attrs
,
"gross_wegiht"
)
.
String
()
gross
Wegiht
:=
gjson
.
Get
(
otherAttrs
,
"gross_wegiht"
)
.
String
()
if
pick
_t
ype
!=
""
{
if
pick
T
ype
!=
""
{
B
[
"pick_type"
]
=
pick
_t
ype
B
[
"pick_type"
]
=
pick
T
ype
}
}
B
[
"length"
]
=
length
B
[
"length"
]
=
length
if
gross
_w
egiht
!=
""
{
if
gross
W
egiht
!=
""
{
B
[
"gross_wegiht"
]
=
gross
_w
egiht
B
[
"gross_wegiht"
]
=
gross
W
egiht
}
}
A
.
Set
(
"other_attrs"
,
B
)
A
.
Set
(
"other_attrs"
,
B
)
}
}
class
_i
d1
:=
gjson
.
Get
(
info
,
"class_id1"
)
.
Int
()
class
I
d1
:=
gjson
.
Get
(
info
,
"class_id1"
)
.
Int
()
class
_i
d2
:=
gjson
.
Get
(
info
,
"class_id2"
)
.
Int
()
class
I
d2
:=
gjson
.
Get
(
info
,
"class_id2"
)
.
Int
()
class
_id1_name
:=
""
;
class
Id1Name
:=
""
if
class
_id1
>
0
{
if
class
Id1
>
0
{
class
_id1_info
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfClassInfo"
,
class_i
d1
))
class
Id1Info
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfClassInfo"
,
classI
d1
))
class
_id1_name
=
gjson
.
Get
(
class_id1_info
,
"class_name"
)
.
String
()
class
Id1Name
=
gjson
.
Get
(
classId1Info
,
"class_name"
)
.
String
()
}
}
class
_id2_name
:=
""
;
class
Id2Name
:=
""
if
class
_id2
>
0
{
if
class
Id2
>
0
{
class
_id2_info
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfClassInfo"
,
class_i
d2
))
class
Id2Info
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfClassInfo"
,
classI
d2
))
class
_id2_name
=
gjson
.
Get
(
class_id2_info
,
"class_name"
)
.
String
()
class
Id2Name
=
gjson
.
Get
(
classId2Info
,
"class_name"
)
.
String
()
}
}
A
.
Set
(
"class_id1"
,
class_id1
)
//
A
.
Set
(
"class_id1"
,
classId1
)
//
A
.
Set
(
"class_id2"
,
class_id2
)
//
A
.
Set
(
"class_id2"
,
classId2
)
//
A
.
Set
(
"class_id1_name"
,
class_id1_name
)
//
A
.
Set
(
"class_id1_name"
,
classId1Name
)
//
A
.
Set
(
"class_id2_name"
,
class_id2_name
)
//
A
.
Set
(
"class_id2_name"
,
classId2Name
)
//
A
.
Set
(
"goods_name"
,
gjson
.
Get
(
info
,
"goods_name"
)
.
String
())
//
A
.
Set
(
"goods_name"
,
gjson
.
Get
(
info
,
"goods_name"
)
.
String
())
//
A
.
Set
(
"status"
,
gjson
.
Get
(
info
,
"status"
)
.
Int
())
//
A
.
Set
(
"status"
,
gjson
.
Get
(
info
,
"status"
)
.
Int
())
//
A
.
Set
(
"encoded"
,
gjson
.
Get
(
info
,
"encoded"
)
.
String
())
//
A
.
Set
(
"encoded"
,
gjson
.
Get
(
info
,
"encoded"
)
.
String
())
//
A
.
Set
(
"encap"
,
gjson
.
Get
(
info
,
"encap"
)
.
String
())
//
A
.
Set
(
"encap"
,
gjson
.
Get
(
info
,
"encap"
)
.
String
())
//
A
.
Set
(
"packing"
,
gjson
.
Get
(
info
,
"packing"
)
.
Int
())
//
A
.
Set
(
"packing"
,
gjson
.
Get
(
info
,
"packing"
)
.
Int
())
//
A
.
Set
(
"goods_unit"
,
gjson
.
Get
(
info
,
"goods_unit"
)
.
Int
())
//
A
.
Set
(
"goods_unit"
,
gjson
.
Get
(
info
,
"goods_unit"
)
.
Int
())
//
A
.
Set
(
"goods_brief"
,
gjson
.
Get
(
info
,
"goods_brief"
)
.
String
())
//
A
.
Set
(
"goods_brief"
,
gjson
.
Get
(
info
,
"goods_brief"
)
.
String
())
//
A
.
Set
(
"moq"
,
gjson
.
Get
(
info
,
"moq"
)
.
Int
())
//
A
.
Set
(
"moq"
,
gjson
.
Get
(
info
,
"moq"
)
.
Int
())
//
A
.
Set
(
"mpq"
,
gjson
.
Get
(
info
,
"mpq"
)
.
Int
())
//
A
.
Set
(
"mpq"
,
gjson
.
Get
(
info
,
"mpq"
)
.
Int
())
//
A
.
Set
(
"update_time"
,
gjson
.
Get
(
info
,
"update_time"
)
.
Int
())
//
A
.
Set
(
"sku_name"
,
strings
.
Trim
(
gjson
.
Get
(
info
,
"sku_name"
)
.
String
(),
" "
))
//
A
.
Set
(
"update_time"
,
gjson
.
Get
(
info
,
"update_time"
)
.
Int
())
//
A
.
Set
(
"mpl"
,
gjson
.
Get
(
info
,
"mpl"
)
.
Int
())
//
A
.
Set
(
"sku_name"
,
strings
.
Trim
(
gjson
.
Get
(
info
,
"sku_name"
)
.
String
(),
" "
))
//
A
.
Set
(
"mpl"
,
gjson
.
Get
(
info
,
"mpl"
)
.
Int
())
//
//处理库存
//处理库存
A
.
Set
(
"stock"
,
0
)
//默认库存为0
A
.
Set
(
"stock"
,
0
)
//默认库存为0
dbStock
:=
gjson
.
Get
(
info
,
"stock"
)
.
Int
()
//当前db库存
dbStock
:=
gjson
.
Get
(
info
,
"stock"
)
.
Int
()
//当前db库存
if
dbStock
>
0
{
if
dbStock
>
0
{
lockStock
:=
qs
.
skuLockNum
(
&
redisConn
,
goods_i
d
)
//当前锁库库存
lockStock
:=
qs
.
skuLockNum
(
&
redisConn
,
goodsI
d
)
//当前锁库库存
stockG
:=
dbStock
-
lockStock
//当前可购买库存
stockG
:=
dbStock
-
lockStock
//当前可购买库存
if
stockG
>
0
{
if
stockG
>
0
{
A
.
Set
(
"actual_stock"
,
gjson
.
Get
(
info
,
"actual_stock"
)
.
Int
())
//锁定库存
A
.
Set
(
"actual_stock"
,
gjson
.
Get
(
info
,
"actual_stock"
)
.
Int
())
//锁定库存
A
.
Set
(
"stock"
,
dbStock
)
A
.
Set
(
"stock"
,
dbStock
)
}
}
A
.
Set
(
"saler_atio"
,
""
)
//
A
.
Set
(
"saler_atio"
,
""
)
//
}
}
if
len
(
attrs
)
==
0
{
if
len
(
attrs
)
==
0
{
A
.
Set
(
"attrs"
,
""
)
//属性值
A
.
Set
(
"attrs"
,
""
)
//属性值
}
else
{
}
else
{
A
.
Set
(
"attrs"
,
attrs
)
//
A
.
Set
(
"attrs"
,
attrs
)
//
}
}
A
.
Set
(
"cost"
,
gjson
.
Get
(
info
,
"cost"
)
.
String
())
//
A
.
Set
(
"cost"
,
gjson
.
Get
(
info
,
"cost"
)
.
String
())
//
A
.
Set
(
"new_cost"
,
gjson
.
Get
(
info
,
"new_cost"
)
.
String
())
//
A
.
Set
(
"new_cost"
,
gjson
.
Get
(
info
,
"new_cost"
)
.
String
())
//
A
.
Set
(
"supplier_stock"
,
gjson
.
Get
(
info
,
"supplier_stock"
)
.
Int
())
//
A
.
Set
(
"supplier_stock"
,
gjson
.
Get
(
info
,
"supplier_stock"
)
.
Int
())
//
A
.
Set
(
"self_supplier_type"
,
gjson
.
Get
(
info
,
"self_supplier_type"
)
.
Int
())
//
A
.
Set
(
"self_supplier_type"
,
gjson
.
Get
(
info
,
"self_supplier_type"
)
.
Int
())
//
//处理货期
//处理货期
cn
_delivery_t
ime
:=
gjson
.
Get
(
info
,
"cn_delivery_time"
)
.
String
()
cn
DeliveryT
ime
:=
gjson
.
Get
(
info
,
"cn_delivery_time"
)
.
String
()
if
cn
_delivery_t
ime
==
""
{
if
cn
DeliveryT
ime
==
""
{
cn
_delivery_time
=
"3-7工作日"
;
cn
DeliveryTime
=
"3-7工作日"
}
}
A
.
Set
(
"cn_delivery_time"
,
cn
_delivery_time
)
// 货期
A
.
Set
(
"cn_delivery_time"
,
cn
DeliveryTime
)
// 货期
//查询品牌名称
//查询品牌名称
brand_id
:=
gjson
.
Get
(
info
,
"brand_id"
)
.
Int
()
brand_id
:=
gjson
.
Get
(
info
,
"brand_id"
)
.
Int
()
brand_info
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_Brand"
,
brand_id
))
brand_info
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_Brand"
,
brand_id
))
A
.
Set
(
"brand_name"
,
gjson
.
Get
(
brand_info
,
"brand_name"
)
.
String
())
//
A
.
Set
(
"brand_name"
,
gjson
.
Get
(
brand_info
,
"brand_name"
)
.
String
())
//
if
fast
!=
"1"
{
//不是快速查询
if
fast
!=
"1"
{
//不是快速查询
// 供应商名称
// 供应商名称
supplier_id
:=
gjson
.
Get
(
info
,
"supplier_id"
)
.
String
()
supplier_id
:=
gjson
.
Get
(
info
,
"supplier_id"
)
.
String
()
supplier_name
:=
""
supplier_name
:=
""
if
supplier_id
!=
""
{
if
supplier_id
!=
""
{
supplierInfo
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfSupplierInfo"
,
supplier_id
))
supplierInfo
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfSupplierInfo"
,
supplier_id
))
supplier_name
=
gjson
.
Get
(
supplierInfo
,
"supplier_name"
)
.
String
()
supplier_name
=
gjson
.
Get
(
supplierInfo
,
"supplier_name"
)
.
String
()
}
}
A
.
Set
(
"supplier_name"
,
supplier_name
)
A
.
Set
(
"supplier_name"
,
supplier_name
)
//商品单位
//商品单位
goods
_u
nit
:=
gjson
.
Get
(
info
,
"goods_unit"
)
.
String
()
goods
U
nit
:=
gjson
.
Get
(
info
,
"goods_unit"
)
.
String
()
goods
_unit_n
ame
:=
""
goods
UnitN
ame
:=
""
if
goods
_u
nit
!=
""
{
if
goods
U
nit
!=
""
{
goods
_unit_name
,
_
=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_Unit"
,
goods_u
nit
))
goods
UnitName
,
_
=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_Unit"
,
goodsU
nit
))
}
}
A
.
Set
(
"goods_unit_name"
,
goods
_unit_n
ame
)
A
.
Set
(
"goods_unit_name"
,
goods
UnitN
ame
)
//包装名称
//包装名称
packing
:=
gjson
.
Get
(
info
,
"packing"
)
.
String
()
packing
:=
gjson
.
Get
(
info
,
"packing"
)
.
String
()
packing
_n
ame
:=
""
packing
N
ame
:=
""
if
packing
!=
""
{
if
packing
!=
""
{
packing
_name
,
_
=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_Unit"
,
packing
))
packing
Name
,
_
=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_Unit"
,
packing
))
}
}
A
.
Set
(
"packing_name"
,
packing_name
)
//
A
.
Set
(
"packing_name"
,
packingName
)
//
//mpq包装名称
//mpq包装名称
mpq
_unit_n
ame
:=
""
mpq
UnitN
ame
:=
""
if
packing
!=
""
{
if
packing
!=
""
{
mpq
_unit_name
,
_
=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_UnitAlias"
,
packing
))
mpq
UnitName
,
_
=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_UnitAlias"
,
packing
))
}
}
A
.
Set
(
"mpq_unit_name"
,
mpq_unit_name
)
//
A
.
Set
(
"mpq_unit_name"
,
mpqUnitName
)
//
//图片
//图片
img
:=
gjson
.
Get
(
info
,
"goods_images"
)
.
String
()
img
:=
gjson
.
Get
(
info
,
"goods_images"
)
.
String
()
goods
_i
mages
:=
""
goods
I
mages
:=
""
if
img
!=
""
{
if
img
!=
""
{
goods
_images
,
_
=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfGoodsSource"
,
img
))
goods
Images
,
_
=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfGoodsSource"
,
img
))
}
}
A
.
Set
(
"goods_images"
,
gjson
.
Get
(
goods
_images
,
"url"
)
.
String
())
A
.
Set
(
"goods_images"
,
gjson
.
Get
(
goods
Images
,
"url"
)
.
String
())
pdf
:=
gjson
.
Get
(
info
,
"pdf"
)
.
String
()
pdf
:=
gjson
.
Get
(
info
,
"pdf"
)
.
String
()
if
pdf
!=
""
{
if
pdf
!=
""
{
pdf
,
_
=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfGoodsSource"
,
pdf
))
pdf
,
_
=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfGoodsSource"
,
pdf
))
}
}
A
.
Set
(
"pdf"
,
gjson
.
Get
(
pdf
,
"url"
)
.
String
())
A
.
Set
(
"pdf"
,
gjson
.
Get
(
pdf
,
"url"
)
.
String
())
}
}
A
.
Set
(
"scm_brand_name"
,
gjson
.
Get
(
info
,
"scm_brand_name"
)
.
String
())
//
A
.
Set
(
"scm_brand_name"
,
gjson
.
Get
(
info
,
"scm_brand_name"
)
.
String
())
//
//处理系数
//处理系数
ratio
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"zy_ratio_sku"
,
goods_i
d
))
ratio
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"zy_ratio_sku"
,
goodsI
d
))
var
PriceAcXi
float64
=
0
//系数
var
PriceAcXi
float64
=
0
//系数
if
ratio
!=
""
{
if
ratio
!=
""
{
PriceAcXi
=
gjson
.
Get
(
ratio
,
"price_ac"
)
.
Float
()
PriceAcXi
=
gjson
.
Get
(
ratio
,
"price_ac"
)
.
Float
()
//获取立创价格
//获取立创价格
if
gjson
.
Parse
(
"szlc_price"
)
.
String
()
==
""
{
if
gjson
.
Parse
(
"szlc_price"
)
.
String
()
==
""
{
A
.
Set
(
"szlc_price"
,
nil
)
A
.
Set
(
"szlc_price"
,
nil
)
}
else
{
}
else
{
ladderPriceLc
:=
make
([]
model
.
LadderPriceLc
,
0
)
ladderPriceLc
:=
make
([]
model
.
LadderPriceLc
,
0
)
for
_
,
v
:=
range
gjson
.
Parse
(
"szlc_price"
)
.
Array
()
{
for
_
,
v
:=
range
gjson
.
Parse
(
"szlc_price"
)
.
Array
()
{
ladderPriceLc
=
append
(
ladderPriceLc
,
model
.
LadderPriceLc
{
ladderPriceLc
=
append
(
ladderPriceLc
,
model
.
LadderPriceLc
{
Purchases
:
v
.
Get
(
"Purchases"
)
.
Int
(),
Purchases
:
v
.
Get
(
"Purchases"
)
.
Int
(),
Price
:
v
.
Get
(
"price"
)
.
Float
(),
Price
:
v
.
Get
(
"price"
)
.
Float
(),
})
})
}
}
A
.
Set
(
"szlc_price"
,
ladderPriceLc
)
A
.
Set
(
"szlc_price"
,
ladderPriceLc
)
}
}
A
.
Set
(
"allow_coupon"
,
gjson
.
Get
(
ratio
,
"allow_coupon"
)
.
String
())
A
.
Set
(
"allow_coupon"
,
gjson
.
Get
(
ratio
,
"allow_coupon"
)
.
String
())
A
.
Set
(
"allow_presale"
,
gjson
.
Get
(
ratio
,
"allow_presale"
)
.
String
())
A
.
Set
(
"allow_presale"
,
gjson
.
Get
(
ratio
,
"allow_presale"
)
.
String
())
A
.
Set
(
"ac_type"
,
6
)
//系数
A
.
Set
(
"ac_type"
,
6
)
//系数
}
}
//拼接梯度价格
//拼接梯度价格
ladderPriceArr
:=
gjson
.
Get
(
info
,
"ladder_price"
)
.
Array
()
ladderPriceArr
:=
gjson
.
Get
(
info
,
"ladder_price"
)
.
Array
()
ladderPrice
:=
make
([]
model
.
LadderPrice
,
0
)
ladderPrice
:=
make
([]
model
.
LadderPrice
,
0
)
for
_
,
v
:=
range
ladderPriceArr
{
for
_
,
v
:=
range
ladderPriceArr
{
if
v
.
Get
(
"purchases"
)
.
String
()
==
""
{
if
v
.
Get
(
"purchases"
)
.
String
()
==
""
{
continue
;
continue
}
}
price
_cn
:=
php2go
.
Round
(
v
.
Get
(
"price_cn"
)
.
Float
()
*
10000
)
/
10000
price
Cn
:=
php2go
.
Round
(
v
.
Get
(
"price_cn"
)
.
Float
()
*
10000
)
/
10000
if
PriceAcXi
==
0
{
if
PriceAcXi
==
0
{
ladderPrice
=
append
(
ladderPrice
,
model
.
LadderPrice
{
ladderPrice
=
append
(
ladderPrice
,
model
.
LadderPrice
{
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
PriceCn
:
price_c
n
,
PriceCn
:
priceC
n
,
})
})
}
else
{
}
else
{
ladderPrice
=
append
(
ladderPrice
,
model
.
LadderPrice
{
ladderPrice
=
append
(
ladderPrice
,
model
.
LadderPrice
{
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
PriceCn
:
price_c
n
,
PriceCn
:
priceC
n
,
PriceAc
:
PriceAcXi
,
PriceAc
:
PriceAcXi
,
})
})
}
}
}
}
if
len
(
ladderPrice
)
==
0
{
if
len
(
ladderPrice
)
==
0
{
A
.
Set
(
"ladder_price"
,
""
)
//
A
.
Set
(
"ladder_price"
,
""
)
//
}
else
{
}
else
{
A
.
Set
(
"ladder_price"
,
ladderPrice
)
//
A
.
Set
(
"ladder_price"
,
ladderPrice
)
//
}
}
//处理限额
//处理限额
goods
_quota
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_goods_quota"
,
goods_i
d
))
goods
Quota
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_goods_quota"
,
goodsI
d
))
if
goods
_q
uota
!=
""
{
if
goods
Q
uota
!=
""
{
A
.
Set
(
"is_quota"
,
1
)
A
.
Set
(
"is_quota"
,
1
)
A
.
Set
(
"quota_num"
,
gjson
.
Get
(
goods_quota
,
"num"
)
.
Int
())
A
.
Set
(
"quota_num"
,
gjson
.
Get
(
goodsQuota
,
"num"
)
.
Int
())
}
}
//处理是否能购买
//处理是否能购买
if
gjson
.
Get
(
info
,
"status"
)
.
String
()
!=
"1"
||
len
(
ladderPriceArr
)
==
0
{
if
gjson
.
Get
(
info
,
"status"
)
.
String
()
!=
"1"
||
len
(
ladderPriceArr
)
==
0
{
A
.
Set
(
"is_buy"
,
0
)
A
.
Set
(
"is_buy"
,
0
)
}
else
{
}
else
{
A
.
Set
(
"is_buy"
,
1
)
A
.
Set
(
"is_buy"
,
1
)
}
}
//提前设置活动信息的默认值
A
.
Set
(
"activity_info"
,
map
[
string
]
interface
{}{})
A
.
Set
(
"has_gift_activity"
,
0
)
A
.
Set
(
"gift_activity"
,
map
[
string
]
interface
{}{})
if
PriceAcXi
==
0
{
//没有系数价格才处理活动价
if
PriceAcXi
==
0
{
//没有系数价格才处理活动价
//处理活动价
//处理活动价
A
.
Set
(
"ac_type"
,
0
)
A
.
Set
(
"ac_type"
,
0
)
A
.
Set
(
"allow_coupon"
,
1
)
A
.
Set
(
"allow_coupon"
,
1
)
Ac
_price
:=
qs
.
ActivityPrice
(
ctx
,
info
,
&
redisConn
)
Ac
Price
:=
qs
.
ActivityPrice
(
ctx
,
info
)
if
Ac
_p
rice
!=
nil
{
if
Ac
P
rice
!=
nil
{
keys
:=
Ac
_p
rice
.
Keys
()
keys
:=
Ac
P
rice
.
Keys
()
for
_
,
k
:=
range
keys
{
for
_
,
k
:=
range
keys
{
v
,
_
:=
Ac
_p
rice
.
Get
(
k
)
v
,
_
:=
Ac
P
rice
.
Get
(
k
)
A
.
Set
(
k
,
v
)
//活动价格覆盖
A
.
Set
(
k
,
v
)
//活动价格覆盖
}
}
}
}
}
}
//最后写入sync map
//最后写入sync map
(
GoodsRes
)
.
Store
(
goods
_id
,
A
)
(
GoodsRes
)
.
Store
(
goods
Id
,
A
)
}
}
ch
<-
GoodsRes
ch
<-
GoodsRes
}
}
service/service_zy_common.go
View file @
5003b2fe
...
@@ -8,28 +8,28 @@ import (
...
@@ -8,28 +8,28 @@ import (
"github.com/tidwall/gjson"
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
)
)
//自营公共函数类
//自营公共函数类
/*
/*
计算单个sku总锁库数量
计算单个sku总锁库数量
*/
*/
func
(
qs
*
ZiyingService
)
skuLockNum
(
c
*
redis
.
Conn
,
goodsId
string
)
int64
{
func
(
qs
*
ZiyingService
)
skuLockNum
(
c
*
redis
.
Conn
,
goodsId
string
)
int64
{
reply
,
err
:=
redis
.
Values
((
*
c
)
.
Do
(
"hvals"
,
"Self_StockLock"
+
goodsId
))
reply
,
err
:=
redis
.
Values
((
*
c
)
.
Do
(
"hvals"
,
"Self_StockLock"
+
goodsId
))
if
err
!=
nil
{
if
err
!=
nil
{
return
0
;
return
0
}
}
var
albums
[]
int64
var
albums
[]
int64
if
err
:=
redis
.
ScanSlice
(
reply
,
&
albums
);
err
!=
nil
{
if
err
:=
redis
.
ScanSlice
(
reply
,
&
albums
);
err
!=
nil
{
return
0
;
return
0
}
}
if
len
(
albums
)
==
0
{
if
len
(
albums
)
==
0
{
return
0
;
return
0
}
else
{
}
else
{
var
all
int64
=
0
var
all
int64
=
0
for
_
,
n
:=
range
albums
{
for
_
,
n
:=
range
albums
{
all
=
all
+
n
all
=
all
+
n
}
}
return
all
return
all
}
}
...
@@ -38,269 +38,133 @@ func (qs *ZiyingService) skuLockNum(c *redis.Conn,goodsId string) int64{
...
@@ -38,269 +38,133 @@ func (qs *ZiyingService) skuLockNum(c *redis.Conn,goodsId string) int64{
/*
/*
获取自营活动价
获取自营活动价
*/
*/
func
(
qs
*
ZiyingService
)
ActivityPrice
(
ctx
*
gin
.
Context
,
SkuInfo
string
,
c
*
redis
.
Conn
)
*
orderedmap
.
OrderedMap
{
func
(
qs
*
ZiyingService
)
ActivityPrice
(
ctx
*
gin
.
Context
,
SkuInfo
string
)
*
orderedmap
.
OrderedMap
{
goodsId
:=
gjson
.
Get
(
SkuInfo
,
"goods_id"
)
.
String
()
data
:=
qs
.
HDActivityPrice
(
SkuInfo
)
//团购价
//assemble := ctx.Request.FormValue("power[assemble]")
//if php2go.InArray(assemble,[]string{"true","1",""}) {
// teamAc,_ := gredis.String((*c).Do("get","Self_activity_assemble_list"))
// if teamAc != "" && goodsId == gjson.Get(teamAc,"goods_id").String() {
// data := qs.HDActivityPrice(ctx,teamAc,SkuInfo,"7")
// if data != nil {
// return data
// }
// }
//}
//新客价处理
if
ctx
.
Request
.
FormValue
(
"power[newCustomer]"
)
==
"true"
||
ctx
.
Request
.
FormValue
(
"power[newCustomer]"
)
==
"1"
{
goodsActivityPrice
,
_
:=
gredis
.
String
((
*
c
)
.
Do
(
"get"
,
"Self_ActivityPrice_10000_NewCustomer"
))
if
goodsActivityPrice
!=
""
{
data
:=
qs
.
HDActivityPrice
(
ctx
,
goodsActivityPrice
,
SkuInfo
,
"5"
)
if
data
!=
nil
{
return
data
}
}
}
//团购限制
data
:=
qs
.
HDGoodsLimit
(
goodsId
,
gjson
.
Get
(
SkuInfo
,
"stock"
)
.
String
(),
c
)
common
.
PrintDebugHtml
(
ctx
,
data
)
if
data
!=
nil
{
if
data
!=
nil
{
return
data
return
data
}
}
//活动价
GoodsActivityPrice
,
_
:=
gredis
.
String
((
*
c
)
.
Do
(
"get"
,
"Self_ActivityPrice_10000"
))
if
GoodsActivityPrice
!=
""
{
data
:=
qs
.
HDActivityPrice
(
ctx
,
GoodsActivityPrice
,
SkuInfo
,
"2"
)
if
data
!=
nil
{
return
data
}
}
//会员价
GoodsActivityPrice
,
_
=
gredis
.
String
((
*
c
)
.
Do
(
"get"
,
"Self_ActivityPrice_10000_Member"
))
if
GoodsActivityPrice
!=
""
{
data
:=
qs
.
HDActivityPrice
(
ctx
,
GoodsActivityPrice
,
SkuInfo
,
"3"
)
if
data
!=
nil
{
return
data
}
}
return
nil
return
nil
}
}
//获取活动相关信息
func
(
qs
*
ZiyingService
)
GetActivity
(
skuInfo
string
)
(
priceActivity
model
.
PriceActivity
,
giftActivity
model
.
GiftActivity
)
{
//去判断是否有活动(促销打折活动和满赠活动)
checkData
:=
model
.
ActivityCheckData
{
SupplierId
:
10000
,
BrandId
:
int
(
gjson
.
Get
(
skuInfo
,
"brand_id"
)
.
Int
()),
ClassId
:
int
(
gjson
.
Get
(
skuInfo
,
"class_id2"
)
.
Int
()),
}
var
activityService
ActivityService
priceActivity
,
giftActivity
=
activityService
.
GetActivityData
(
checkData
)
return
}
/*
/*
计算活动价
计算活动价
ac_type说明: 0 没有活动
ac_type说明: 0 没有活动
活动名称 ac_type 类型
活动名称 ac_type 类型
限时限量活动 1 自营
活动价 2 自营 and 联营
会员价 3 自营 and 联营
折扣价(废除)4 自营 and 联营
新客价 5 自营 and 联营
自营系数 6 自营
自营系数 6 自营
团购价 7 联营
折扣(系数)活动 10 自营/联营
折扣价 8 自营 and 联营
*/
*/
func
(
qs
*
ZiyingService
)
HDActivityPrice
(
ctx
*
gin
.
Context
,
GoodsActivityPrice
string
,
SkuInfo
string
,
Actype
string
)
*
orderedmap
.
OrderedMap
{
func
(
qs
*
ZiyingService
)
HDActivityPrice
(
SkuInfo
string
)
*
orderedmap
.
OrderedMap
{
visible_roster
:=
gjson
.
Get
(
GoodsActivityPrice
,
"visible_roster"
)
.
String
()
priceActivity
,
giftActivity
:=
qs
.
GetActivity
(
SkuInfo
)
activity_id
:=
gjson
.
Get
(
GoodsActivityPrice
,
"activity_id"
)
.
String
()
ladderPriceArr
:=
gjson
.
Get
(
SkuInfo
,
"ladder_price"
)
.
Array
()
is_part
:=
gjson
.
Get
(
GoodsActivityPrice
,
"is_part"
)
.
String
()
A
:=
orderedmap
.
New
()
activity_type
:=
gjson
.
Get
(
GoodsActivityPrice
,
"activity_type"
)
.
String
()
//先去判断价格活动
if
priceActivity
.
HasActivity
&&
len
(
ladderPriceArr
)
>
0
{
Ratio
:=
true
//是否符合活动价
ratio
:=
priceActivity
.
Ratio
if
Actype
==
"5"
{
//新客价
ladderType
:=
make
([]
model
.
LadderPrice
,
0
)
ratio_goods_id
:=
gjson
.
Get
(
GoodsActivityPrice
,
"goods_id"
)
.
String
()
//活动型号id
for
_
,
v
:=
range
ladderPriceArr
{
ratio_brand_id
:=
gjson
.
Get
(
GoodsActivityPrice
,
"brand_id"
)
.
String
()
//活动品牌id
priceCn
:=
v
.
Get
(
"price_cn"
)
.
Float
()
ratio_class_id
:=
gjson
.
Get
(
GoodsActivityPrice
,
"class_id"
)
.
String
()
//活动分类id
priceAc
:=
php2go
.
Round
(
priceCn
*
ratio
/
100
*
10000
)
/
10000
ladderType
=
append
(
ladderType
,
model
.
LadderPrice
{
//指定参与新客价型号
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
if
ratio_goods_id
!=
""
{
PriceUs
:
v
.
Get
(
"price_us"
)
.
Float
(),
if
php2go
.
Stripos
(
","
+
ratio_goods_id
+
","
,
","
+
gjson
.
Get
(
SkuInfo
,
"goods_id"
)
.
String
()
+
","
,
0
)
==
-
1
{
PriceCn
:
priceCn
,
Ratio
=
false
;
//不符合新客价
PriceAc
:
priceAc
,
goto
End
})
}
}
}
//指定品牌
A
.
Set
(
"activity_info"
,
priceActivity
)
if
ratio_brand_id
!=
""
{
if
php2go
.
Stripos
(
","
+
ratio_brand_id
+
","
,
","
+
gjson
.
Get
(
SkuInfo
,
"brand_id"
)
.
String
()
+
","
,
0
)
==
-
1
{
A
.
Set
(
"ladder_price"
,
ladderType
)
Ratio
=
false
;
//不符合新客价
A
.
Set
(
"ratio"
,
ratio
)
goto
End
A
.
Set
(
"ac_type"
,
10
)
}
}
//指定分类
if
ratio_class_id
!=
""
{
if
php2go
.
Stripos
(
","
+
ratio_class_id
+
","
,
","
+
gjson
.
Get
(
SkuInfo
,
"class_id2"
)
.
String
()
+
","
,
0
)
==
-
1
{
Ratio
=
false
;
//不符合新客价
goto
End
}
}
}
else
{
//fmt.Println(GoodsActivityPrice,SkuInfo)
brand_id
:=
gjson
.
Get
(
GoodsActivityPrice
,
"brand_id"
)
.
String
()
class_id
:=
gjson
.
Get
(
GoodsActivityPrice
,
"class_id"
)
.
String
()
if
brand_id
!=
""
{
if
!
common
.
GInArray
(
GoodsActivityPrice
,
"brand_id"
,
gjson
.
Get
(
SkuInfo
,
"brand_id"
)
.
String
())
{
Ratio
=
false
;
//不符合活动价
//fmt.Println("不符合活动价1")
goto
End
}
}
if
class_id
!=
""
{
if
!
common
.
GInArray
(
GoodsActivityPrice
,
"class_id"
,
gjson
.
Get
(
SkuInfo
,
"class_id2"
)
.
String
())
{
Ratio
=
false
;
//不符合活动价
//fmt.Println("不符合活动价2")
goto
End
}
}
//会员价处理
if
Actype
==
"3"
&&
is_part
==
"1"
&&
visible_roster
!=
""
{
Ratio
=
false
;
//
visible_roster
=
","
+
visible_roster
+
","
if
php2go
.
Stripos
(
visible_roster
,
","
+
ctx
.
Request
.
FormValue
(
"power[user_id]"
)
+
","
,
0
)
!=
-
1
{
Ratio
=
true
;
}
if
php2go
.
Stripos
(
visible_roster
,
","
+
ctx
.
Request
.
FormValue
(
"power[mobile]"
)
+
","
,
0
)
!=
-
1
{
Ratio
=
true
;
}
if
php2go
.
Stripos
(
visible_roster
,
","
+
ctx
.
Request
.
FormValue
(
"power[email]"
)
+
","
,
0
)
!=
-
1
{
Ratio
=
true
;
}
//fmt.Println("不符合活动价3")
}
//处理黑名单,只有折扣活动才有黑名单,并且是下单页面,debug
if
Ratio
==
true
&&
Actype
==
"2"
&&
activity_id
!=
""
&&
activity_type
==
"2"
&&
ctx
.
Request
.
FormValue
(
"power[verify_blacklist]"
)
==
"true"
{
//redisConn := gredis.Conn("search_r")
//defer redisConn.Close();
//
//blacklist, _ := redis.String(redisConn.Do("hget", "activity_roster",activity_id+"_1"))
//blacklist_type := config.Cfg.Section("blacklist_type").KeysHash()
//
//blacklistArr := php2go.Explode(",",blacklist)
//for p,d := range blacklist_type {
//
// //backval,ok := blacklist_type[d]
//
// if php2go.Stripos(visible_roster,","+middleware.REQUEST["power[user_id]"]+",",0) == -1 {
// Ratio = false; //不符合新客价
// goto End
// }
//}
}
}
}
End
:
//最终执行
//再去判断满赠活动
ladder_price_arr
:=
gjson
.
Get
(
SkuInfo
,
"ladder_price"
)
.
Array
()
if
giftActivity
.
HasActivity
{
if
Ratio
&&
len
(
ladder_price_arr
)
>
0
{
A
.
Set
(
"has_gift_activity"
,
1
)
discount_type
:=
gjson
.
Get
(
GoodsActivityPrice
,
"discount_type"
)
.
String
()
A
.
Set
(
"gift_activity"
,
giftActivity
)
ratio
:=
gjson
.
Get
(
GoodsActivityPrice
,
"ratio"
)
.
Float
()
//当前活动折扣
}
//其中一类活动不允许优惠券,这个商品就不允许使用优惠券
A
:=
orderedmap
.
New
();
var
allowCoupon
int
ladderType
:=
make
([]
model
.
LadderPrice
,
0
)
if
priceActivity
.
HasActivity
&&
priceActivity
.
AllowCoupon
==
0
{
for
_
,
v
:=
range
ladder_price_arr
{
allowCoupon
=
0
if
Actype
!=
"7"
||
(
Actype
==
"7"
&&
discount_type
!=
""
)
||
discount_type
==
"1"
{
A
.
Set
(
"allow_coupon"
,
allowCoupon
)
price_cn
:=
v
.
Get
(
"price_cn"
)
.
Float
()
price_ac
:=
php2go
.
Round
(
price_cn
*
ratio
/
100
*
10000
)
/
10000
ladderType
=
append
(
ladderType
,
model
.
LadderPrice
{
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
PriceUs
:
v
.
Get
(
"price_us"
)
.
Float
(),
PriceCn
:
price_cn
,
PriceAc
:
price_ac
,
})
}
}
allow_not_login
:=
gjson
.
Get
(
GoodsActivityPrice
,
"allow_not_login"
)
.
Int
()
if
allow_not_login
==
0
{
allow_not_login
=
2
}
A
.
Set
(
"activity_info"
,
map
[
string
]
interface
{}{
"activity_ad"
:
gjson
.
Get
(
GoodsActivityPrice
,
"activity_ad"
)
.
String
(),
"sign_name"
:
gjson
.
Get
(
GoodsActivityPrice
,
"sign_name"
)
.
String
(),
"allow_not_login"
:
allow_not_login
,
})
A
.
Set
(
"ladder_price"
,
ladderType
)
A
.
Set
(
"ratio"
,
ratio
)
A
.
Set
(
"ac_type"
,
Actype
)
if
gjson
.
Get
(
GoodsActivityPrice
,
"activity_type"
)
.
Int
()
==
2
{
A
.
Set
(
"ac_type"
,
8
)
}
allow_coupon
:=
gjson
.
Get
(
GoodsActivityPrice
,
"allow_coupon"
)
.
Int
()
if
gjson
.
Get
(
GoodsActivityPrice
,
"allow_coupon"
)
.
Int
()
==
0
{
allow_coupon
=
1
}
A
.
Set
(
"allow_coupon"
,
allow_coupon
)
A
.
Set
(
"activity_end_time"
,
gjson
.
Get
(
GoodsActivityPrice
,
"end_time"
)
.
Int
())
return
A
}
}
return
nil
if
giftActivity
.
HasActivity
&&
giftActivity
.
AllowCoupon
==
0
{
allowCoupon
=
0
A
.
Set
(
"allow_coupon"
,
allowCoupon
)
}
return
A
}
}
/*
/*
获取当前锁住的库存
获取当前锁住的库存
*/
*/
func
(
qs
*
ZiyingService
)
HDGoodsLimit
(
SkuID
string
,
Stock
string
,
c
*
redis
.
Conn
)
*
orderedmap
.
OrderedMap
{
func
(
qs
*
ZiyingService
)
HDGoodsLimit
(
SkuID
string
,
Stock
string
,
c
*
redis
.
Conn
)
*
orderedmap
.
OrderedMap
{
GoodsLimit
,
_
:=
redis
.
String
((
*
c
)
.
Do
(
"get"
,
"Self_GoodsLimit_"
+
SkuID
))
GoodsLimit
,
_
:=
redis
.
String
((
*
c
)
.
Do
(
"get"
,
"Self_GoodsLimit_"
+
SkuID
))
if
GoodsLimit
==
""
{
if
GoodsLimit
==
""
{
return
nil
return
nil
}
}
start_time
:=
gjson
.
Get
(
GoodsLimit
,
"start_time"
)
.
Int
()
start_time
:=
gjson
.
Get
(
GoodsLimit
,
"start_time"
)
.
Int
()
end_time
:=
gjson
.
Get
(
GoodsLimit
,
"end_time"
)
.
Int
()
end_time
:=
gjson
.
Get
(
GoodsLimit
,
"end_time"
)
.
Int
()
buy_stock
:=
gjson
.
Get
(
GoodsLimit
,
"buy_stock"
)
.
Float
()
buy_stock
:=
gjson
.
Get
(
GoodsLimit
,
"buy_stock"
)
.
Float
()
ac_stock
:=
gjson
.
Get
(
GoodsLimit
,
"ac_stock"
)
.
Float
()
ac_stock
:=
gjson
.
Get
(
GoodsLimit
,
"ac_stock"
)
.
Float
()
schedule
:=
gjson
.
Get
(
GoodsLimit
,
"schedule"
)
.
Float
()
schedule
:=
gjson
.
Get
(
GoodsLimit
,
"schedule"
)
.
Float
()
allow_coupon
:=
gjson
.
Get
(
GoodsLimit
,
"allow_coupon"
)
.
Int
()
allow_coupon
:=
gjson
.
Get
(
GoodsLimit
,
"allow_coupon"
)
.
Int
()
if
start_time
<
php2go
.
Time
()
&&
end_time
>
php2go
.
Time
()
{
if
start_time
<
php2go
.
Time
()
&&
end_time
>
php2go
.
Time
()
{
buy
:=
buy_stock
/
ac_stock
*
100
buy
:=
buy_stock
/
ac_stock
*
100
schedule
:=
common
.
MyRound
(
buy
+
schedule
,
2
)
schedule
:=
common
.
MyRound
(
buy
+
schedule
,
2
)
if
schedule
<
100
{
if
schedule
<
100
{
A
:=
orderedmap
.
New
()
;
A
:=
orderedmap
.
New
()
//拼接梯度价格
//拼接梯度价格
ladder_price_arr
:=
gjson
.
Get
(
GoodsLimit
,
"ac_price"
)
.
Array
()
ladder_price_arr
:=
gjson
.
Get
(
GoodsLimit
,
"ac_price"
)
.
Array
()
ladderType
:=
make
([]
model
.
LadderPrice
,
0
)
ladderType
:=
make
([]
model
.
LadderPrice
,
0
)
for
_
,
v
:=
range
ladder_price_arr
{
for
_
,
v
:=
range
ladder_price_arr
{
ladderType
=
append
(
ladderType
,
model
.
LadderPrice
{
ladderType
=
append
(
ladderType
,
model
.
LadderPrice
{
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
PriceCn
:
v
.
Get
(
"price_cn"
)
.
Float
(),
PriceCn
:
v
.
Get
(
"price_cn"
)
.
Float
(),
PriceAc
:
v
.
Get
(
"price_ac"
)
.
Float
(),
PriceAc
:
v
.
Get
(
"price_ac"
)
.
Float
(),
})
})
}
}
now_stock
:=
ac_stock
*
((
100
-
schedule
)
/
100
)
now_stock
:=
ac_stock
*
((
100
-
schedule
)
/
100
)
A
.
Set
(
"ac_type"
,
1
)
A
.
Set
(
"ac_type"
,
1
)
A
.
Set
(
"ac_id"
,
gjson
.
Get
(
GoodsLimit
,
"id"
)
.
Int
())
A
.
Set
(
"ac_id"
,
gjson
.
Get
(
GoodsLimit
,
"id"
)
.
Int
())
A
.
Set
(
"ladder_price"
,
ladderType
)
A
.
Set
(
"ladder_price"
,
ladderType
)
A
.
Set
(
"ac_stock"
,
ac_stock
)
A
.
Set
(
"ac_stock"
,
ac_stock
)
A
.
Set
(
"stock"
,
now_stock
)
A
.
Set
(
"stock"
,
now_stock
)
A
.
Set
(
"schedule"
,
schedule
)
A
.
Set
(
"schedule"
,
schedule
)
A
.
Set
(
"activity_end_time"
,
end_time
)
A
.
Set
(
"activity_end_time"
,
end_time
)
if
allow_coupon
>
0
{
if
allow_coupon
>
0
{
A
.
Set
(
"allow_coupon"
,
allow_coupon
)
A
.
Set
(
"allow_coupon"
,
allow_coupon
)
}
else
{
}
else
{
A
.
Set
(
"allow_coupon"
,
1
)
A
.
Set
(
"allow_coupon"
,
1
)
}
}
//活动库存大于当前可售库存,强制结束活动
//活动库存大于当前可售库存,强制结束活动
if
now_stock
>
common
.
MyFloat64
(
Stock
)
||
now_stock
==
0
{
if
now_stock
>
common
.
MyFloat64
(
Stock
)
||
now_stock
==
0
{
return
nil
return
nil
}
}
return
A
return
A
}
}
}
}
return
nil
return
nil
}
}
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