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
576fd30c
authored
Jan 12, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix
parent
bc8f6310
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
295 additions
and
407 deletions
model/ly_sku.go
service/service_activity.go
service/service_ly.go
service/service_zy.go
service/service_zy_common.go
model/ly_sku.go
View file @
576fd30c
...
...
@@ -64,28 +64,29 @@ type LySku struct {
//活动信息
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"`
ActivityInfo
PriceActivity
`json:"activity_info"`
}
type
PriceActivity
struct
{
HasActivity
bool
`json:"-"`
ActivityId
int
`json:"activity_id,omitempty"`
ActivityName
string
`json:"activity_name,omitempty"`
AllowCoupon
int
`json:"-"`
ActivityCommon
Ratio
float64
`json:"ratio"`
}
type
GiftActivity
struct
{
HasActivity
bool
`json:"-"`
ActivityId
int
`json:"activity_id,omitempty"`
ActivityName
int
`json:"activity_name,omitempty"`
AllowCoupon
int
`json:"-"`
ActivityCommon
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存的数据结构不一定正常,可能类型不一致
func
InitSkuData
(
sku
string
)
(
data
LySku
)
{
goodsSn
:=
gjson
.
Get
(
sku
,
"goods_sn"
)
.
String
()
...
...
service/service_activity.go
View file @
576fd30c
...
...
@@ -61,38 +61,52 @@ func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, ac
//如果是整个供应商搞活动,则直接返回系数
if
activity
.
EntireSupplierActivity
{
hasActivity
=
true
giftActivity
.
ItemList
=
activity
.
ItemList
giftActivity
.
ActivityId
=
activity
.
ActivityId
goto
INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if
as
.
CheckExcludeSku
(
checkData
.
GoodsId
,
activity
)
||
as
.
CheckExcludeBrand
(
checkData
.
BrandId
,
activity
)
{
hasActivity
=
false
goto
INFO
}
//判断是否是搞活动的品牌
if
as
.
CheckBrand
(
checkData
.
BrandId
,
activity
)
{
hasActivity
=
true
giftActivity
.
ItemList
=
activity
.
ItemList
giftActivity
.
ActivityId
=
activity
.
ActivityId
goto
INFO
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if
checkData
.
SupplierId
==
17
{
if
as
.
CheckCanal
(
checkData
.
Canal
,
activity
)
{
hasActivity
=
true
giftActivity
.
ItemList
=
activity
.
ItemList
giftActivity
.
ActivityId
=
activity
.
ActivityId
goto
INFO
}
}
else
{
if
as
.
CheckClass
(
checkData
.
ClassId
,
activity
)
{
hasActivity
=
true
giftActivity
.
ItemList
=
activity
.
ItemList
giftActivity
.
ActivityId
=
activity
.
ActivityId
goto
INFO
}
}
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
}
...
...
@@ -108,36 +122,49 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
//如果是整个供应商搞活动,则直接返回系数
if
activity
.
EntireSupplierActivity
{
hasActivity
=
true
priceActivity
.
Ratio
=
activity
.
Ratio
goto
INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if
as
.
CheckExcludeSku
(
checkData
.
GoodsId
,
activity
)
||
as
.
CheckExcludeBrand
(
checkData
.
BrandId
,
activity
)
{
hasActivity
=
false
goto
INFO
}
//判断是否是搞活动的品牌
if
as
.
CheckBrand
(
checkData
.
BrandId
,
activity
)
{
hasActivity
=
true
priceActivity
.
Ratio
=
activity
.
Ratio
goto
INFO
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if
checkData
.
SupplierId
==
17
{
if
as
.
CheckCanal
(
checkData
.
Canal
,
activity
)
{
hasActivity
=
true
priceActivity
.
Ratio
=
activity
.
Ratio
goto
INFO
}
}
else
{
if
as
.
CheckClass
(
checkData
.
ClassId
,
activity
)
{
hasActivity
=
true
priceActivity
.
Ratio
=
activity
.
Ratio
goto
INFO
}
}
INFO
:
if
hasActivity
{
priceActivity
.
AllowCoupon
=
activity
.
AllowCoupon
priceActivity
.
ActivityName
=
activity
.
ActivityName
priceActivity
.
ActivityId
=
activity
.
ActivityId
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
,
},
}
}
}
...
...
service/service_ly.go
View file @
576fd30c
...
...
@@ -188,8 +188,7 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku {
if
priceActivity
.
HasActivity
{
sku
.
AcType
=
10
sku
.
Ratio
=
priceActivity
.
Ratio
sku
.
ActivityInfo
.
ActivityId
=
priceActivity
.
ActivityId
sku
.
ActivityInfo
.
ActivityName
=
priceActivity
.
ActivityName
sku
.
ActivityInfo
=
priceActivity
}
if
giftActivity
.
HasActivity
{
sku
.
HasGiftActivity
=
gconv
.
Int
(
giftActivity
.
HasActivity
)
...
...
service/service_zy.go
View file @
576fd30c
...
...
@@ -31,31 +31,30 @@ type ZiyingService struct {
@param power[special_invoice] 增值税专用发票公司名字,活动价时需要,否则可能导致用户无法享受活动价 : 深圳是猎芯科技有限公司
@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"
)
defer
func
()
{
//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]"
)
GoodsRes
:=
sync
.
Map
{}
for
goods
_id
,
info
:=
range
skuArr
{
for
goods
Id
,
info
:=
range
skuArr
{
if
gjson
.
Get
(
info
,
"goods_name"
)
.
String
()
==
""
{
//fmt.Print("zy goods_name为空-----",goods_id,skuArr)
GoodsRes
.
Store
(
goods
_id
,
false
)
continue
;
GoodsRes
.
Store
(
goods
Id
,
false
)
continue
}
//拼接属性
attrJsonArr
:=
gjson
.
Parse
(
gjson
.
Get
(
info
,
"attrs"
)
.
String
())
.
Array
()
attrs
:=
make
([]
model
.
Attrs
,
0
)
for
_
,
d
:=
range
attrJsonArr
{
attrJsonArr
:=
gjson
.
Parse
(
gjson
.
Get
(
info
,
"attrs"
)
.
String
())
.
Array
()
attrs
:=
make
([]
model
.
Attrs
,
0
)
for
_
,
d
:=
range
attrJsonArr
{
if
d
.
Get
(
"attr_name"
)
.
String
()
==
""
{
continue
;
continue
}
attrs
=
append
(
attrs
,
model
.
Attrs
{
AttrName
:
d
.
Get
(
"attr_name"
)
.
String
(),
...
...
@@ -64,236 +63,234 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string, ch ch
}
//数组
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
A
.
Set
(
"goods_id"
,
common
.
MyInt64
(
goods_i
d
))
A
.
Set
(
"goods_type"
,
gjson
.
Get
(
info
,
"goods_type"
)
.
Int
())
//查询总条数
A
.
Set
(
"supplier_id"
,
gjson
.
Get
(
info
,
"supplier_id"
)
.
Int
())
//查询总条数
A
.
Set
(
"brand_id"
,
gjson
.
Get
(
info
,
"brand_id"
)
.
Int
())
//
other
_attrs
:=
gjson
.
Get
(
info
,
"other_attrs"
)
.
String
()
if
other
_a
ttrs
==
""
{
A
.
Set
(
"other_attrs"
,
""
)
}
else
{
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
A
.
Set
(
"goods_id"
,
common
.
MyInt64
(
goodsI
d
))
A
.
Set
(
"goods_type"
,
gjson
.
Get
(
info
,
"goods_type"
)
.
Int
())
//查询总条数
A
.
Set
(
"supplier_id"
,
gjson
.
Get
(
info
,
"supplier_id"
)
.
Int
())
//查询总条数
A
.
Set
(
"brand_id"
,
gjson
.
Get
(
info
,
"brand_id"
)
.
Int
())
//
other
Attrs
:=
gjson
.
Get
(
info
,
"other_attrs"
)
.
String
()
if
other
A
ttrs
==
""
{
A
.
Set
(
"other_attrs"
,
""
)
}
else
{
B
:=
make
(
map
[
string
]
string
)
pick
_type
:=
gjson
.
Get
(
other_attrs
,
"pick_type"
)
.
String
()
length
:=
gjson
.
Get
(
other
_attrs
,
"length"
)
.
String
()
gross
_wegiht
:=
gjson
.
Get
(
other_attrs
,
"gross_wegiht"
)
.
String
()
if
pick
_t
ype
!=
""
{
B
[
"pick_type"
]
=
pick
_t
ype
pick
Type
:=
gjson
.
Get
(
otherAttrs
,
"pick_type"
)
.
String
()
length
:=
gjson
.
Get
(
other
Attrs
,
"length"
)
.
String
()
gross
Wegiht
:=
gjson
.
Get
(
otherAttrs
,
"gross_wegiht"
)
.
String
()
if
pick
T
ype
!=
""
{
B
[
"pick_type"
]
=
pick
T
ype
}
B
[
"length"
]
=
length
if
gross
_w
egiht
!=
""
{
B
[
"gross_wegiht"
]
=
gross
_w
egiht
if
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
d2
:=
gjson
.
Get
(
info
,
"class_id2"
)
.
Int
()
class
_id1_name
:=
""
;
if
class
_id1
>
0
{
class
_id1_info
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfClassInfo"
,
class_i
d1
))
class
_id1_name
=
gjson
.
Get
(
class_id1_info
,
"class_name"
)
.
String
()
class
I
d1
:=
gjson
.
Get
(
info
,
"class_id1"
)
.
Int
()
class
I
d2
:=
gjson
.
Get
(
info
,
"class_id2"
)
.
Int
()
class
Id1Name
:=
""
if
class
Id1
>
0
{
class
Id1Info
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfClassInfo"
,
classI
d1
))
class
Id1Name
=
gjson
.
Get
(
classId1Info
,
"class_name"
)
.
String
()
}
class
_id2_name
:=
""
;
if
class
_id2
>
0
{
class
_id2_info
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfClassInfo"
,
class_i
d2
))
class
_id2_name
=
gjson
.
Get
(
class_id2_info
,
"class_name"
)
.
String
()
class
Id2Name
:=
""
if
class
Id2
>
0
{
class
Id2Info
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfClassInfo"
,
classI
d2
))
class
Id2Name
=
gjson
.
Get
(
classId2Info
,
"class_name"
)
.
String
()
}
A
.
Set
(
"class_id1"
,
class_id1
)
//
A
.
Set
(
"class_id2"
,
class_id2
)
//
A
.
Set
(
"class_id1_name"
,
class_id1_name
)
//
A
.
Set
(
"class_id2_name"
,
class_id2_name
)
//
A
.
Set
(
"goods_name"
,
gjson
.
Get
(
info
,
"goods_name"
)
.
String
())
//
A
.
Set
(
"status"
,
gjson
.
Get
(
info
,
"status"
)
.
Int
())
//
A
.
Set
(
"encoded"
,
gjson
.
Get
(
info
,
"encoded"
)
.
String
())
//
A
.
Set
(
"encap"
,
gjson
.
Get
(
info
,
"encap"
)
.
String
())
//
A
.
Set
(
"packing"
,
gjson
.
Get
(
info
,
"packing"
)
.
Int
())
//
A
.
Set
(
"goods_unit"
,
gjson
.
Get
(
info
,
"goods_unit"
)
.
Int
())
//
A
.
Set
(
"goods_brief"
,
gjson
.
Get
(
info
,
"goods_brief"
)
.
String
())
//
A
.
Set
(
"moq"
,
gjson
.
Get
(
info
,
"moq"
)
.
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
(
"mpl"
,
gjson
.
Get
(
info
,
"mpl"
)
.
Int
())
//
A
.
Set
(
"class_id1"
,
classId1
)
//
A
.
Set
(
"class_id2"
,
classId2
)
//
A
.
Set
(
"class_id1_name"
,
classId1Name
)
//
A
.
Set
(
"class_id2_name"
,
classId2Name
)
//
A
.
Set
(
"goods_name"
,
gjson
.
Get
(
info
,
"goods_name"
)
.
String
())
//
A
.
Set
(
"status"
,
gjson
.
Get
(
info
,
"status"
)
.
Int
())
//
A
.
Set
(
"encoded"
,
gjson
.
Get
(
info
,
"encoded"
)
.
String
())
//
A
.
Set
(
"encap"
,
gjson
.
Get
(
info
,
"encap"
)
.
String
())
//
A
.
Set
(
"packing"
,
gjson
.
Get
(
info
,
"packing"
)
.
Int
())
//
A
.
Set
(
"goods_unit"
,
gjson
.
Get
(
info
,
"goods_unit"
)
.
Int
())
//
A
.
Set
(
"goods_brief"
,
gjson
.
Get
(
info
,
"goods_brief"
)
.
String
())
//
A
.
Set
(
"moq"
,
gjson
.
Get
(
info
,
"moq"
)
.
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
(
"mpl"
,
gjson
.
Get
(
info
,
"mpl"
)
.
Int
())
//
//处理库存
A
.
Set
(
"stock"
,
0
)
//默认库存为0
dbStock
:=
gjson
.
Get
(
info
,
"stock"
)
.
Int
()
//当前db库存
A
.
Set
(
"stock"
,
0
)
//默认库存为0
dbStock
:=
gjson
.
Get
(
info
,
"stock"
)
.
Int
()
//当前db库存
if
dbStock
>
0
{
lockStock
:=
qs
.
skuLockNum
(
&
redisConn
,
goods_i
d
)
//当前锁库库存
stockG
:=
dbStock
-
lockStock
//当前可购买库存
if
stockG
>
0
{
A
.
Set
(
"actual_stock"
,
gjson
.
Get
(
info
,
"actual_stock"
)
.
Int
())
//锁定库存
A
.
Set
(
"stock"
,
dbStock
)
lockStock
:=
qs
.
skuLockNum
(
&
redisConn
,
goodsI
d
)
//当前锁库库存
stockG
:=
dbStock
-
lockStock
//当前可购买库存
if
stockG
>
0
{
A
.
Set
(
"actual_stock"
,
gjson
.
Get
(
info
,
"actual_stock"
)
.
Int
())
//锁定库存
A
.
Set
(
"stock"
,
dbStock
)
}
A
.
Set
(
"saler_atio"
,
""
)
//
A
.
Set
(
"saler_atio"
,
""
)
//
}
if
len
(
attrs
)
==
0
{
A
.
Set
(
"attrs"
,
""
)
//属性值
}
else
{
A
.
Set
(
"attrs"
,
attrs
)
//
A
.
Set
(
"attrs"
,
""
)
//属性值
}
else
{
A
.
Set
(
"attrs"
,
attrs
)
//
}
A
.
Set
(
"cost"
,
gjson
.
Get
(
info
,
"cost"
)
.
String
())
//
A
.
Set
(
"new_cost"
,
gjson
.
Get
(
info
,
"new_cost"
)
.
String
())
//
A
.
Set
(
"supplier_stock"
,
gjson
.
Get
(
info
,
"supplier_stock"
)
.
Int
())
//
A
.
Set
(
"self_supplier_type"
,
gjson
.
Get
(
info
,
"self_supplier_type"
)
.
Int
())
//
A
.
Set
(
"cost"
,
gjson
.
Get
(
info
,
"cost"
)
.
String
())
//
A
.
Set
(
"new_cost"
,
gjson
.
Get
(
info
,
"new_cost"
)
.
String
())
//
A
.
Set
(
"supplier_stock"
,
gjson
.
Get
(
info
,
"supplier_stock"
)
.
Int
())
//
A
.
Set
(
"self_supplier_type"
,
gjson
.
Get
(
info
,
"self_supplier_type"
)
.
Int
())
//
//处理货期
cn
_delivery_t
ime
:=
gjson
.
Get
(
info
,
"cn_delivery_time"
)
.
String
()
if
cn
_delivery_t
ime
==
""
{
cn
_delivery_time
=
"3-7工作日"
;
cn
DeliveryT
ime
:=
gjson
.
Get
(
info
,
"cn_delivery_time"
)
.
String
()
if
cn
DeliveryT
ime
==
""
{
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_info
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_Brand"
,
brand_id
))
A
.
Set
(
"brand_name"
,
gjson
.
Get
(
brand_info
,
"brand_name"
)
.
String
())
//
brand_info
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_Brand"
,
brand_id
))
A
.
Set
(
"brand_name"
,
gjson
.
Get
(
brand_info
,
"brand_name"
)
.
String
())
//
if
fast
!=
"1"
{
//不是快速查询
// 供应商名称
supplier_id
:=
gjson
.
Get
(
info
,
"supplier_id"
)
.
String
()
supplier_name
:=
""
if
supplier_id
!=
""
{
supplierInfo
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfSupplierInfo"
,
supplier_id
))
supplier_name
=
gjson
.
Get
(
supplierInfo
,
"supplier_name"
)
.
String
()
supplierInfo
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfSupplierInfo"
,
supplier_id
))
supplier_name
=
gjson
.
Get
(
supplierInfo
,
"supplier_name"
)
.
String
()
}
A
.
Set
(
"supplier_name"
,
supplier_name
)
//商品单位
goods
_u
nit
:=
gjson
.
Get
(
info
,
"goods_unit"
)
.
String
()
goods
_unit_n
ame
:=
""
if
goods
_u
nit
!=
""
{
goods
_unit_name
,
_
=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_Unit"
,
goods_u
nit
))
goods
U
nit
:=
gjson
.
Get
(
info
,
"goods_unit"
)
.
String
()
goods
UnitN
ame
:=
""
if
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
_n
ame
:=
""
packing
N
ame
:=
""
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
_unit_n
ame
:=
""
mpq
UnitN
ame
:=
""
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
()
goods
_i
mages
:=
""
goods
I
mages
:=
""
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
()
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
(
"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
))
var
PriceAcXi
float64
=
0
//系数
ratio
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"zy_ratio_sku"
,
goodsI
d
))
var
PriceAcXi
float64
=
0
//系数
if
ratio
!=
""
{
PriceAcXi
=
gjson
.
Get
(
ratio
,
"price_ac"
)
.
Float
()
PriceAcXi
=
gjson
.
Get
(
ratio
,
"price_ac"
)
.
Float
()
//获取立创价格
if
gjson
.
Parse
(
"szlc_price"
)
.
String
()
==
""
{
A
.
Set
(
"szlc_price"
,
nil
)
}
else
{
ladderPriceLc
:=
make
([]
model
.
LadderPriceLc
,
0
)
for
_
,
v
:=
range
gjson
.
Parse
(
"szlc_price"
)
.
Array
()
{
if
gjson
.
Parse
(
"szlc_price"
)
.
String
()
==
""
{
A
.
Set
(
"szlc_price"
,
nil
)
}
else
{
ladderPriceLc
:=
make
([]
model
.
LadderPriceLc
,
0
)
for
_
,
v
:=
range
gjson
.
Parse
(
"szlc_price"
)
.
Array
()
{
ladderPriceLc
=
append
(
ladderPriceLc
,
model
.
LadderPriceLc
{
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_presale"
,
gjson
.
Get
(
ratio
,
"allow_presale"
)
.
String
())
A
.
Set
(
"ac_type"
,
6
)
//系数
A
.
Set
(
"allow_coupon"
,
gjson
.
Get
(
ratio
,
"allow_coupon"
)
.
String
())
A
.
Set
(
"allow_presale"
,
gjson
.
Get
(
ratio
,
"allow_presale"
)
.
String
())
A
.
Set
(
"ac_type"
,
6
)
//系数
}
//拼接梯度价格
ladderPriceArr
:=
gjson
.
Get
(
info
,
"ladder_price"
)
.
Array
()
ladderPrice
:=
make
([]
model
.
LadderPrice
,
0
)
for
_
,
v
:=
range
ladderPriceArr
{
ladderPriceArr
:=
gjson
.
Get
(
info
,
"ladder_price"
)
.
Array
()
ladderPrice
:=
make
([]
model
.
LadderPrice
,
0
)
for
_
,
v
:=
range
ladderPriceArr
{
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
{
ladderPrice
=
append
(
ladderPrice
,
model
.
LadderPrice
{
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
PriceCn
:
price_c
n
,
PriceCn
:
priceC
n
,
})
}
else
{
}
else
{
ladderPrice
=
append
(
ladderPrice
,
model
.
LadderPrice
{
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
PriceCn
:
price_c
n
,
PriceAc
:
PriceAcXi
,
PriceCn
:
priceC
n
,
PriceAc
:
PriceAcXi
,
})
}
}
if
len
(
ladderPrice
)
==
0
{
A
.
Set
(
"ladder_price"
,
""
)
//
}
else
{
A
.
Set
(
"ladder_price"
,
ladderPrice
)
//
A
.
Set
(
"ladder_price"
,
""
)
//
}
else
{
A
.
Set
(
"ladder_price"
,
ladderPrice
)
//
}
//处理限额
goods
_quota
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_goods_quota"
,
goods_i
d
))
if
goods
_q
uota
!=
""
{
A
.
Set
(
"is_quota"
,
1
)
A
.
Set
(
"quota_num"
,
gjson
.
Get
(
goods_quota
,
"num"
)
.
Int
())
goods
Quota
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_goods_quota"
,
goodsI
d
))
if
goods
Q
uota
!=
""
{
A
.
Set
(
"is_quota"
,
1
)
A
.
Set
(
"quota_num"
,
gjson
.
Get
(
goodsQuota
,
"num"
)
.
Int
())
}
//处理是否能购买
if
gjson
.
Get
(
info
,
"status"
)
.
String
()
!=
"1"
||
len
(
ladderPriceArr
)
==
0
{
A
.
Set
(
"is_buy"
,
0
)
}
else
{
A
.
Set
(
"is_buy"
,
1
)
if
gjson
.
Get
(
info
,
"status"
)
.
String
()
!=
"1"
||
len
(
ladderPriceArr
)
==
0
{
A
.
Set
(
"is_buy"
,
0
)
}
else
{
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
{
//没有系数价格才处理活动价
//处理活动价
A
.
Set
(
"ac_type"
,
0
)
A
.
Set
(
"allow_coupon"
,
1
)
Ac
_price
:=
qs
.
ActivityPrice
(
ctx
,
info
,
&
redisConn
)
if
Ac
_p
rice
!=
nil
{
keys
:=
Ac
_p
rice
.
Keys
()
A
.
Set
(
"ac_type"
,
0
)
A
.
Set
(
"allow_coupon"
,
1
)
Ac
Price
:=
qs
.
ActivityPrice
(
ctx
,
info
)
if
Ac
P
rice
!=
nil
{
keys
:=
Ac
P
rice
.
Keys
()
for
_
,
k
:=
range
keys
{
v
,
_
:=
Ac
_p
rice
.
Get
(
k
)
A
.
Set
(
k
,
v
)
//活动价格覆盖
v
,
_
:=
Ac
P
rice
.
Get
(
k
)
A
.
Set
(
k
,
v
)
//活动价格覆盖
}
}
}
//最后写入sync map
(
GoodsRes
)
.
Store
(
goods
_id
,
A
)
(
GoodsRes
)
.
Store
(
goods
Id
,
A
)
}
ch
<-
GoodsRes
}
service/service_zy_common.go
View file @
576fd30c
...
...
@@ -8,28 +8,28 @@ import (
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
)
//自营公共函数类
/*
计算单个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
))
if
err
!=
nil
{
return
0
;
return
0
}
var
albums
[]
int64
if
err
:=
redis
.
ScanSlice
(
reply
,
&
albums
);
err
!=
nil
{
return
0
;
return
0
}
if
len
(
albums
)
==
0
{
return
0
;
}
else
{
return
0
}
else
{
var
all
int64
=
0
for
_
,
n
:=
range
albums
{
all
=
all
+
n
for
_
,
n
:=
range
albums
{
all
=
all
+
n
}
return
all
}
...
...
@@ -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
{
goodsId
:=
gjson
.
Get
(
SkuInfo
,
"goods_id"
)
.
String
()
//团购价
//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
)
func
(
qs
*
ZiyingService
)
ActivityPrice
(
ctx
*
gin
.
Context
,
SkuInfo
string
)
*
orderedmap
.
OrderedMap
{
data
:=
qs
.
HDActivityPrice
(
SkuInfo
)
if
data
!=
nil
{
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
}
//获取活动相关信息
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 类型
限时限量活动 1 自营
活动价 2 自营 and 联营
会员价 3 自营 and 联营
折扣价(废除)4 自营 and 联营
新客价 5 自营 and 联营
自营系数 6 自营
团购价 7 联营
折扣价 8 自营 and 联营
折扣(系数)活动 10 自营/联营
*/
func
(
qs
*
ZiyingService
)
HDActivityPrice
(
ctx
*
gin
.
Context
,
GoodsActivityPrice
string
,
SkuInfo
string
,
Actype
string
)
*
orderedmap
.
OrderedMap
{
visible_roster
:=
gjson
.
Get
(
GoodsActivityPrice
,
"visible_roster"
)
.
String
()
activity_id
:=
gjson
.
Get
(
GoodsActivityPrice
,
"activity_id"
)
.
String
()
is_part
:=
gjson
.
Get
(
GoodsActivityPrice
,
"is_part"
)
.
String
()
activity_type
:=
gjson
.
Get
(
GoodsActivityPrice
,
"activity_type"
)
.
String
()
Ratio
:=
true
//是否符合活动价
if
Actype
==
"5"
{
//新客价
ratio_goods_id
:=
gjson
.
Get
(
GoodsActivityPrice
,
"goods_id"
)
.
String
()
//活动型号id
ratio_brand_id
:=
gjson
.
Get
(
GoodsActivityPrice
,
"brand_id"
)
.
String
()
//活动品牌id
ratio_class_id
:=
gjson
.
Get
(
GoodsActivityPrice
,
"class_id"
)
.
String
()
//活动分类id
//指定参与新客价型号
if
ratio_goods_id
!=
""
{
if
php2go
.
Stripos
(
","
+
ratio_goods_id
+
","
,
","
+
gjson
.
Get
(
SkuInfo
,
"goods_id"
)
.
String
()
+
","
,
0
)
==
-
1
{
Ratio
=
false
;
//不符合新客价
goto
End
}
}
//指定品牌
if
ratio_brand_id
!=
""
{
if
php2go
.
Stripos
(
","
+
ratio_brand_id
+
","
,
","
+
gjson
.
Get
(
SkuInfo
,
"brand_id"
)
.
String
()
+
","
,
0
)
==
-
1
{
Ratio
=
false
;
//不符合新客价
goto
End
}
}
//指定分类
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
// }
//}
}
func
(
qs
*
ZiyingService
)
HDActivityPrice
(
SkuInfo
string
)
*
orderedmap
.
OrderedMap
{
priceActivity
,
giftActivity
:=
qs
.
GetActivity
(
SkuInfo
)
ladderPriceArr
:=
gjson
.
Get
(
SkuInfo
,
"ladder_price"
)
.
Array
()
A
:=
orderedmap
.
New
()
//先去判断价格活动
if
priceActivity
.
HasActivity
&&
len
(
ladderPriceArr
)
>
0
{
ratio
:=
priceActivity
.
Ratio
ladderType
:=
make
([]
model
.
LadderPrice
,
0
)
for
_
,
v
:=
range
ladderPriceArr
{
priceCn
:=
v
.
Get
(
"price_cn"
)
.
Float
()
priceAc
:=
php2go
.
Round
(
priceCn
*
ratio
/
100
*
10000
)
/
10000
ladderType
=
append
(
ladderType
,
model
.
LadderPrice
{
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
PriceUs
:
v
.
Get
(
"price_us"
)
.
Float
(),
PriceCn
:
priceCn
,
PriceAc
:
priceAc
,
})
}
A
.
Set
(
"activity_info"
,
priceActivity
)
A
.
Set
(
"ladder_price"
,
ladderType
)
A
.
Set
(
"ratio"
,
ratio
)
A
.
Set
(
"ac_type"
,
10
)
}
End
:
//最终执行
ladder_price_arr
:=
gjson
.
Get
(
SkuInfo
,
"ladder_price"
)
.
Array
()
if
Ratio
&&
len
(
ladder_price_arr
)
>
0
{
discount_type
:=
gjson
.
Get
(
GoodsActivityPrice
,
"discount_type"
)
.
String
()
ratio
:=
gjson
.
Get
(
GoodsActivityPrice
,
"ratio"
)
.
Float
()
//当前活动折扣
A
:=
orderedmap
.
New
();
ladderType
:=
make
([]
model
.
LadderPrice
,
0
)
for
_
,
v
:=
range
ladder_price_arr
{
if
Actype
!=
"7"
||
(
Actype
==
"7"
&&
discount_type
!=
""
)
||
discount_type
==
"1"
{
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
//再去判断满赠活动
if
giftActivity
.
HasActivity
{
A
.
Set
(
"has_gift_activity"
,
1
)
A
.
Set
(
"gift_activity"
,
giftActivity
)
}
//其中一类活动不允许优惠券,这个商品就不允许使用优惠券
var
allowCoupon
int
if
priceActivity
.
HasActivity
&&
priceActivity
.
AllowCoupon
==
0
{
allowCoupon
=
0
A
.
Set
(
"allow_coupon"
,
allowCoupon
)
}
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
))
if
GoodsLimit
==
""
{
return
nil
}
start_time
:=
gjson
.
Get
(
GoodsLimit
,
"start_time"
)
.
Int
()
end_time
:=
gjson
.
Get
(
GoodsLimit
,
"end_time"
)
.
Int
()
buy_stock
:=
gjson
.
Get
(
GoodsLimit
,
"buy_stock"
)
.
Float
()
ac_stock
:=
gjson
.
Get
(
GoodsLimit
,
"ac_stock"
)
.
Float
()
schedule
:=
gjson
.
Get
(
GoodsLimit
,
"schedule"
)
.
Float
()
allow_coupon
:=
gjson
.
Get
(
GoodsLimit
,
"allow_coupon"
)
.
Int
()
if
start_time
<
php2go
.
Time
()
&&
end_time
>
php2go
.
Time
()
{
buy
:=
buy_stock
/
ac_stock
*
100
schedule
:=
common
.
MyRound
(
buy
+
schedule
,
2
)
start_time
:=
gjson
.
Get
(
GoodsLimit
,
"start_time"
)
.
Int
()
end_time
:=
gjson
.
Get
(
GoodsLimit
,
"end_time"
)
.
Int
()
buy_stock
:=
gjson
.
Get
(
GoodsLimit
,
"buy_stock"
)
.
Float
()
ac_stock
:=
gjson
.
Get
(
GoodsLimit
,
"ac_stock"
)
.
Float
()
schedule
:=
gjson
.
Get
(
GoodsLimit
,
"schedule"
)
.
Float
()
allow_coupon
:=
gjson
.
Get
(
GoodsLimit
,
"allow_coupon"
)
.
Int
()
if
start_time
<
php2go
.
Time
()
&&
end_time
>
php2go
.
Time
()
{
buy
:=
buy_stock
/
ac_stock
*
100
schedule
:=
common
.
MyRound
(
buy
+
schedule
,
2
)
if
schedule
<
100
{
A
:=
orderedmap
.
New
()
;
//拼接梯度价格
ladder_price_arr
:=
gjson
.
Get
(
GoodsLimit
,
"ac_price"
)
.
Array
()
ladderType
:=
make
([]
model
.
LadderPrice
,
0
)
for
_
,
v
:=
range
ladder_price_arr
{
A
:=
orderedmap
.
New
()
//拼接梯度价格
ladder_price_arr
:=
gjson
.
Get
(
GoodsLimit
,
"ac_price"
)
.
Array
()
ladderType
:=
make
([]
model
.
LadderPrice
,
0
)
for
_
,
v
:=
range
ladder_price_arr
{
ladderType
=
append
(
ladderType
,
model
.
LadderPrice
{
Purchases
:
v
.
Get
(
"purchases"
)
.
Int
(),
PriceCn
:
v
.
Get
(
"price_cn"
)
.
Float
(),
PriceAc
:
v
.
Get
(
"price_ac"
)
.
Float
(),
PriceCn
:
v
.
Get
(
"price_cn"
)
.
Float
(),
PriceAc
:
v
.
Get
(
"price_ac"
)
.
Float
(),
})
}
now_stock
:=
ac_stock
*
((
100
-
schedule
)
/
100
)
A
.
Set
(
"ac_type"
,
1
)
A
.
Set
(
"ac_id"
,
gjson
.
Get
(
GoodsLimit
,
"id"
)
.
Int
())
A
.
Set
(
"ladder_price"
,
ladderType
)
A
.
Set
(
"ac_stock"
,
ac_stock
)
A
.
Set
(
"stock"
,
now_stock
)
A
.
Set
(
"schedule"
,
schedule
)
A
.
Set
(
"activity_end_time"
,
end_time
)
if
allow_coupon
>
0
{
A
.
Set
(
"allow_coupon"
,
allow_coupon
)
}
else
{
A
.
Set
(
"allow_coupon"
,
1
)
now_stock
:=
ac_stock
*
((
100
-
schedule
)
/
100
)
A
.
Set
(
"ac_type"
,
1
)
A
.
Set
(
"ac_id"
,
gjson
.
Get
(
GoodsLimit
,
"id"
)
.
Int
())
A
.
Set
(
"ladder_price"
,
ladderType
)
A
.
Set
(
"ac_stock"
,
ac_stock
)
A
.
Set
(
"stock"
,
now_stock
)
A
.
Set
(
"schedule"
,
schedule
)
A
.
Set
(
"activity_end_time"
,
end_time
)
if
allow_coupon
>
0
{
A
.
Set
(
"allow_coupon"
,
allow_coupon
)
}
else
{
A
.
Set
(
"allow_coupon"
,
1
)
}
//活动库存大于当前可售库存,强制结束活动
if
now_stock
>
common
.
MyFloat64
(
Stock
)
||
now_stock
==
0
{
return
nil
return
nil
}
return
A
return
A
}
}
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