@@ -7,23 +7,39 @@ import (
)
const (
ActTypeStoreMoneyOff = 0
ActTypeSkuMoneyOff = 1
ActTypeStoreFullDiscount = 0
ActTypeSkuFullDiscount = 1
)
const (
// 指定商品满减活动状态
SkuMoneyOffStatusNew = 2 // 待生效
SkuMoneyOff StatusValid = 1 // 生效
SkuMoneyOffStatusExpired = 0 // 过期
SkuFullDiscountStatusExpired = 0 // 过期
SkuFullDiscount StatusValid = 1 // 生效
SkuFullDiscountStatusNew = 2 // 待生效
// 全店满减活动状态
StoreMoneyOff StatusNew = 0 // 待生效
StoreMoneyOff StatusValid = 1 // 生效
StoreMoneyOff StatusExpired = 2 // 过期
StoreFullDiscount StatusNew = 0 // 待生效
StoreFullDiscount StatusValid = 1 // 生效
StoreFullDiscount StatusExpired = 2 // 过期
ShippingFeeStatusNotStart = "NOT_START" // 待生效
ShippingFeeStatusInProgress = "IN_PROGRESS" // 已生效
ShippingFeeStatusExpired = "EXPIRED" // 已过期
ShippingFeeStatusApprove = "APPROVE" // 待审批
ShippingFeeStatusFreeze = "FREEZE" // 冻结中
RetailDiscountStatusExpired = 0 // 已过期
RetailDiscountStatusValid = 1 // 已生效
RetailDiscountStatusNew = 2 // 待生效
UserTypeAll = 0 // 不限
UserTypeNewCommer = 1 // 门店新客
SettingTypeAsDiscount = 0 // 按折扣系数开展活动
SettingTypeAsPrice = 0 // 按折扣价格开展活动s
)
type ActInfo struct {
type FullDiscount ActInfo struct {
ActIDs string ` json:"act_ids" `
ActName string ` json:"act_name" `
StartTime int64 ` json:"start_time" ` // 活动开始时间,单s位秒
@@ -32,52 +48,105 @@ type ActInfo struct {
Status int ` json:"-" `
}
type ActDetail struct {
OriginalPrice float32 ` json:"origin_price" ` // 满
ActPrice float32 ` json:"act_price" ` // 减
type FullDiscount ActDetail struct {
OriginalPrice float64 ` json:"origin_price" ` // 满
ActPrice float64 ` json:"act_price" ` // 减
}
type ActSkuInfo struct {
type FullDiscountSku struct {
AppFoodCode string ` json:"app_food_code" `
DayLimit int ` json:"day_limit" `
Name string ` json:"-" ` // 设置操作时无用
}
type ActWholeInfo struct {
ActInfo * ActInfo ` json:"act_info" `
ActRemark string ` json:"act_remark" `
AppPoiCode string ` json:"app_poi_code" `
type FullDiscountActData struct {
ActInfo * FullDiscount ActInfo ` json:"act_info" `
ActRemark string ` json:"act_remark" `
AppPoiCode string ` json:"app_poi_code" `
ActDetails [ ] * ActDetail ` json:"act_details" `
ActDetails [ ] * FullDiscount ActDetail ` json:"act_details" `
}
type Ac tFoodsInfo struct {
ActInfo * ActInfo ` json:"act_info" `
ActRemark string ` json:"act_remark" `
AppPoiCode string ` json:"app_poi_code" `
type FullDiscoun tFoodsInfo struct {
ActInfo * FullDiscount ActInfo ` json:"act_info" `
ActRemark string ` json:"act_remark" `
AppPoiCode string ` json:"app_poi_code" `
AppFoods [ ] * ActSkuInfo ` json:"app_foods" `
AppFoods [ ] * FullDiscountSku ` json:"app_foods" `
}
type ActDa ta struct {
ItemID in t64 ` json:"item_id" ` // 活动ID, 为什么这里又是int64
DayLimit int ` json:"day_limit" ` // 当日活动库存,只能为正整数或-1, -1表示无限库存
type ShippingFee ActDe tail struct {
LimitPrice floa t64 ` json:"limit_price" `
DiscountPrice float64 ` json:"discount_price" `
PoiCharge float64 ` json:"-" `
MtCharge float64 ` json:"-" `
}
func ( a * API ) FullDiscountBatchSave ( poiCode string , actInfo * ActInfo , actList [ ] * ActDetail , actSkuList [ ] * ActSkuInfo ) ( err error ) {
type ShippingFeeActData struct {
StartTime int64 ` json:"start_time" ` // 活动开始时间,单s位秒
EndTime int64 ` json:"end_time" ` // 活动结束时间,单位秒
WeeksTime string ` json:"weeks_time" `
Period string ` json:"period" `
ActDetail [ ] * ShippingFeeActDetail ` json:"act_detail" `
MaxPrice float64 ` json:"max_price" `
AppPoiCode string ` json:"-" `
ActID string ` json:"-" `
ActStatus string ` json:"-" `
}
type RetailActData struct {
AppFoodCode string ` json:"app_food_code" `
UserType int ` json:"user_type" `
StartTime int64 ` json:"start_time" ` // 活动开始时间,单s位秒
EndTime int64 ` json:"end_time" ` // 活动结束时间,单位秒
OrderLimit int ` json:"order_limit" `
DayLimit int ` json:"day_limit" `
WeeksTime string ` json:"weeks_time" `
Period string ` json:"period" `
SettingType int ` json:"setting_type" `
ActPrice float64 ` json:"act_price" ` // 折扣价格(单位元): 必须为大于0的数字, 且不能超过2位小数。
DiscountCoefficient float64 ` json:"discount_coefficient" ` // 折扣系数: 必须大于0小于9.8, 最多支持两位小数。如输入3, 即为3折
Sequence int ` json:"sequence" `
ItemID int64 ` json:"item_id" ` // 活动ID, 为什么这里又是int64
// 以下参数只有查询时用到
OriginalPrice float64 ` json:"-" ` // 商品原价,单位元
Stock int ` json:"-" ` // 当日剩余活动商品数量。只有当发起查询时间处于活动生效时段内时(start_time、end_time、period、weeks_time均需满足),该字段才代表实际剩余活动商品数量,否则显示的是创建活动时规定的当日活动库存
Status int ` json:"-" ` // 活动状态, 0:已过期, 1:已生效, 2:待生效。
Name string ` json:"-" `
}
type RetailActDataLimit struct {
ItemID int64 ` json:"item_id" ` // 活动ID, 为什么这里又是int64
DayLimit int ` json:"day_limit" ` // 当日活动库存,只能为正整数或-1, -1表示无限库存
OrderLimit int ` json:"order_limit" ` // 每单可购买的折扣商品数量
}
var (
ignoreShippingFeeActData = ShippingFeeActData { }
ignoreRetailActData = & RetailActData { }
ignoreRetailActDataLimit = & RetailActDataLimit { }
)
func ( a * API ) FullDiscountBatchSave ( poiCode string , actInfo * FullDiscountActInfo , actList [ ] * FullDiscountActDetail , actSkuList [ ] * FullDiscountSku ) ( actID int64 , err error ) {
params := map [ string ] interface { } {
KeyAppPoiCode : poiCode ,
"act_info" : string ( utils . MustMarshal ( actInfo ) ) ,
"act_details" : string ( utils . MustMarshal ( actList ) ) ,
}
if actInfo . ActType == ActTypeSkuMoneyOff {
if actInfo . ActType == ActTypeSkuFullDiscount {
params [ "app_foods" ] = string ( utils . MustMarshal ( actSkuList ) )
}
_ , err = a . AccessAPI ( "act/full/discount/batchsave" , false , params )
return err
result , err : = a . AccessAPI2 ( "act/full/discount/batchsave" , false , params , resultKeyMsg )
if err == nil {
return utils . MustInterface2Int64 ( result . ( [ ] interface { } ) [ 0 ] . ( map [ string ] interface { } ) [ "act_id" ] ) , nil
}
return 0 , err
}
func ( a * API ) FullDiscountList ( poiCode string , actType int ) ( actInfoList [ ] * ActWholeInfo , err error ) {
func ( a * API ) FullDiscountList ( poiCode string , actType int ) ( actInfoList [ ] * FullDiscountActData , err error ) {
result , err := a . AccessAPI ( "act/full/discount/list" , false , map [ string ] interface { } {
KeyAppPoiCode : poiCode ,
"act_type" : actType ,
@@ -85,7 +154,7 @@ func (a *API) FullDiscountList(poiCode string, actType int) (actInfoList []*ActW
if err == nil && result != nil {
for _ , v := range result . ( [ ] interface { } ) {
actMap := v . ( map [ string ] interface { } )
actWholeInfo := & ActWholeInfo {
actWholeInfo := & FullDiscountActData {
ActInfo : interface2ActInfo ( actMap [ "act_info" ] ) ,
ActRemark : utils . Interface2String ( actMap [ "act_remark" ] ) ,
AppPoiCode : utils . Interface2String ( actMap [ "app_poi_code" ] ) ,
@@ -93,9 +162,9 @@ func (a *API) FullDiscountList(poiCode string, actType int) (actInfoList []*ActW
actInfoList = append ( actInfoList , actWholeInfo )
for _ , v := range actMap [ "act_details" ] . ( [ ] interface { } ) {
vMap := v . ( map [ string ] interface { } )
actWholeInfo . ActDetails = append ( actWholeInfo . ActDetails , & ActDetail {
OriginalPrice : float32 ( utils . MustInterface2Float64 ( vMap [ "origin_price" ] ) ) ,
ActPrice : float32 ( utils . MustInterface2Float64 ( vMap [ "act_price" ] ) ) ,
actWholeInfo . ActDetails = append ( actWholeInfo . ActDetails , & FullDiscount ActDetail{
OriginalPrice : float64 ( utils . MustInterface2Float64 ( vMap [ "origin_price" ] ) ) ,
ActPrice : float64 ( utils . MustInterface2Float64 ( vMap [ "act_price" ] ) ) ,
} )
}
}
@@ -104,9 +173,9 @@ func (a *API) FullDiscountList(poiCode string, actType int) (actInfoList []*ActW
return nil , err
}
func interface2ActInfo ( actInfo interface { } ) * ActInfo {
func interface2ActInfo ( actInfo interface { } ) * FullDiscount ActInfo {
actInfoMap := actInfo . ( map [ string ] interface { } )
return & ActInfo {
return & FullDiscount ActInfo{
ActIDs : utils . Interface2String ( actInfoMap [ "act_ids" ] ) ,
StartTime : utils . MustInterface2Int64 ( actInfoMap [ "start_time" ] ) ,
EndTime : utils . MustInterface2Int64 ( actInfoMap [ "end_time" ] ) ,
@@ -123,7 +192,7 @@ func (a *API) FullDiscountDelete(poiCode string, actIDList []string, actType int
return err
}
func ( a * API ) FullDiscountFoodsBatchSave ( poiCode , actID string , appFoodList [ ] * ActSkuInfo ) ( err error ) {
func ( a * API ) FullDiscountFoodsBatchSave ( poiCode , actID string , appFoodList [ ] * FullDiscountSku ) ( err error ) {
_ , err = a . AccessAPI ( "act/full/discount/foods/batchsave" , false , map [ string ] interface { } {
KeyAppPoiCode : poiCode ,
"act_id" : actID ,
@@ -132,21 +201,21 @@ func (a *API) FullDiscountFoodsBatchSave(poiCode, actID string, appFoodList []*A
return err
}
func ( a * API ) FullDiscountFoodsList ( poiCode , actID string ) ( actFoodsInfo * Ac tFoodsInfo, err error ) {
pageSize := 200
func ( a * API ) FullDiscountFoodsList ( poiCode , actID string ) ( actFoodsInfo * FullDiscoun tFoodsInfo, err error ) {
limit := 200
for {
var result interface { }
offset := 0
result , err = a . AccessAPI ( "act/full/discount/foods/list" , false , map [ string ] interface { } {
KeyAppPoiCode : poiCode ,
"act_id" : actID ,
"limit" : pageSize ,
"limit" : limit ,
"offset" : offset ,
} )
if err == nil && result != nil {
resultMap := result . ( map [ string ] interface { } )
if actFoodsInfo == nil {
actFoodsInfo = & Ac tFoodsInfo{
actFoodsInfo = & FullDiscoun tFoodsInfo{
ActInfo : interface2ActInfo ( resultMap [ "act_info" ] ) ,
ActRemark : utils . Interface2String ( resultMap [ "act_remark" ] ) ,
AppPoiCode : utils . Interface2String ( resultMap [ "app_poi_code" ] ) ,
@@ -162,10 +231,10 @@ func (a *API) FullDiscountFoodsList(poiCode, actID string) (actFoodsInfo *ActFoo
return nil , err
}
func interface2SkuInfoList ( value interface { } ) ( actSkuList [ ] * ActSkuInfo ) {
func interface2SkuInfoList ( value interface { } ) ( actSkuList [ ] * FullDiscountSku ) {
for _ , v := range value . ( [ ] interface { } ) {
vMap := v . ( map [ string ] interface { } )
actSkuList = append ( actSkuList , & ActSkuInfo {
actSkuList = append ( actSkuList , & FullDiscountSku {
AppFoodCode : utils . Interface2String ( vMap [ "app_food_code" ] ) ,
DayLimit : int ( utils . Interface2Int64WithDefault ( vMap [ "day_limit" ] , 0 ) ) ,
Name : utils . Interface2String ( vMap [ "name" ] ) ,
@@ -186,7 +255,7 @@ func (a *API) FullDiscountFoodsDelete(poiCode, actID string, appFoodCodeList []s
}
// 批量修改指定商品满减活动中商品的当日活动库存
func ( a * API ) FullDiscountFoodsDayLimit ( poiCode , actID string , appFoodList [ ] * ActSkuInfo ) ( err error ) {
func ( a * API ) FullDiscountFoodsDayLimit ( poiCode , actID string , appFoodList [ ] * FullDiscountSku ) ( err error ) {
_ , err = a . AccessAPI ( "act/full/discount/foods/daylimit" , false , map [ string ] interface { } {
KeyAppPoiCode : poiCode ,
"act_id" : actID ,
@@ -195,11 +264,142 @@ func (a *API) FullDiscountFoodsDayLimit(poiCode, actID string, appFoodList []*Ac
return err
}
// 批量修改零售折扣商品当日活动库存
func ( a * API ) RetailDiscountBatchStock ( poiCode , actDataList [ ] * ActData ) ( err error ) {
_ , err = a . AccessAPI ( "act/retail/discount/batchstock" , false , map [ string ] interface { } {
// 阶梯满减配送费活动一个门店只可能有一个活动, 所以不涉及actID的概念
// 批量创建阶梯满减配送费活动
func ( a * API ) FulllDiscountShippingFeeBatchSave ( poiCode string , actData [ ] * ShippingFeeActData ) ( err error ) {
_ , err = a . AccessAPI ( "act/full/discount/shippingfee/batchsave" , false , map [ string ] interface { } {
KeyAppPoiCode : poiCode ,
"act_data" : string ( utils . MustMarshal ( actDataList ) ) ,
"act_data" : string ( utils . MustMarshal ( utils . StructList2MapListWithIgnore ( actData , map [ string ] interface { } {
"weeks_time" : ignoreShippingFeeActData . WeeksTime ,
"period" : ignoreShippingFeeActData . Period ,
"max_price" : ignoreShippingFeeActData . MaxPrice ,
} ) ) ) ,
} )
return err
}
// 查询阶梯满减配送费活动
func ( a * API ) FulllDiscountShippingFeeList ( poiCode string ) ( actList [ ] * ShippingFeeActData , err error ) {
result , err := a . AccessAPI ( "act/full/discount/shippingfee/list" , true , map [ string ] interface { } {
KeyAppPoiCode : poiCode ,
} )
if err == nil {
for _ , v := range result . ( [ ] interface { } ) {
vMap := v . ( map [ string ] interface { } )
act := & ShippingFeeActData {
AppPoiCode : utils . Interface2String ( vMap [ "app_poi_code" ] ) ,
ActID : utils . Interface2String ( vMap [ "act_id" ] ) ,
StartTime : utils . MustInterface2Int64 ( vMap [ "start_time" ] ) ,
EndTime : utils . MustInterface2Int64 ( vMap [ "end_time" ] ) ,
WeeksTime : utils . Interface2String ( vMap [ "weeks_time" ] ) ,
Period : utils . Interface2String ( vMap [ "period" ] ) ,
MaxPrice : utils . Interface2Float64WithDefault ( vMap [ "max_price" ] , 0 ) ,
ActStatus : utils . Interface2String ( vMap [ "actStatus" ] ) ,
}
actList = append ( actList , act )
for _ , v := range vMap [ "act_detail" ] . ( [ ] interface { } ) {
vMap := v . ( map [ string ] interface { } )
act . ActDetail = append ( act . ActDetail , & ShippingFeeActDetail {
LimitPrice : utils . Interface2Float64WithDefault ( vMap [ "limit_price" ] , 0 ) ,
DiscountPrice : utils . Interface2Float64WithDefault ( vMap [ "discount_price" ] , 0 ) ,
PoiCharge : utils . Interface2Float64WithDefault ( vMap [ "poi_charge" ] , 0 ) ,
MtCharge : utils . Interface2Float64WithDefault ( vMap [ "mt_charge" ] , 0 ) ,
} )
}
}
}
return actList , err
}
// 批量创建或更新零售折扣商品
func ( a * API ) RetailDiscountBatchSave ( poiCode string , actData [ ] * RetailActData ) ( actID int64 , err error ) {
result , err := a . AccessAPI2 ( "act/retail/discount/batchsave" , false , map [ string ] interface { } {
KeyAppPoiCode : poiCode ,
"act_data" : string ( utils . MustMarshal ( utils . StructList2MapListWithIgnore ( actData , map [ string ] interface { } {
"sequence" : ignoreRetailActData . Sequence ,
"item_id" : ignoreRetailActData . ItemID ,
} ) ) ) ,
} , resultKeyMsg )
if err == nil {
return utils . MustInterface2Int64 ( result . ( [ ] interface { } ) [ 0 ] . ( map [ string ] interface { } ) [ "act_id" ] ) , nil
}
return 0 , err
}
// 查询门店零售折扣商品
func ( a * API ) RetailDiscountList ( poiCode string ) ( actList [ ] * RetailActData , err error ) {
limit := 200
offset := 0
for {
result , err := a . AccessAPI ( "act/retail/discount/list" , true , map [ string ] interface { } {
KeyAppPoiCode : poiCode ,
"limit" : limit ,
"offset" : offset ,
} )
if err == nil {
resultList := result . ( [ ] interface { } )
for _ , v := range resultList {
vMap := v . ( map [ string ] interface { } )
act := & RetailActData {
AppFoodCode : utils . Interface2String ( vMap [ "app_food_code" ] ) ,
UserType : int ( utils . MustInterface2Int64 ( vMap [ "user_type" ] ) ) ,
StartTime : utils . MustInterface2Int64 ( vMap [ "start_time" ] ) ,
EndTime : utils . MustInterface2Int64 ( vMap [ "end_time" ] ) ,
OrderLimit : int ( utils . MustInterface2Int64 ( vMap [ "order_limit" ] ) ) ,
DayLimit : int ( utils . MustInterface2Int64 ( vMap [ "day_limit" ] ) ) ,
WeeksTime : utils . Interface2String ( vMap [ "weeks_time" ] ) ,
Period : utils . Interface2String ( vMap [ "period" ] ) ,
SettingType : int ( utils . MustInterface2Int64 ( vMap [ "setting_type" ] ) ) ,
ActPrice : utils . Interface2Float64WithDefault ( vMap [ "act_price" ] , 0 ) ,
DiscountCoefficient : utils . Interface2Float64WithDefault ( vMap [ "discount_coefficient" ] , 0 ) ,
ItemID : utils . MustInterface2Int64 ( vMap [ "item_id" ] ) ,
OriginalPrice : utils . Interface2Float64WithDefault ( vMap [ "origin_price" ] , 0 ) ,
Stock : int ( utils . MustInterface2Int64 ( vMap [ "stock" ] ) ) ,
Status : int ( utils . MustInterface2Int64 ( vMap [ "status" ] ) ) ,
Name : utils . Interface2String ( vMap [ "name" ] ) ,
Sequence : int ( utils . MustInterface2Int64 ( vMap [ "sequence" ] ) ) ,
}
actList = append ( actList , act )
}
if len ( resultList ) < limit {
break
}
offset ++
} else {
return nil , err
}
}
return actList , err
}
// 批量删除零售折扣商品
func ( a * API ) RetailDiscountDelete ( poiCode string , actIDList [ ] string ) ( err error ) {
_ , err = a . AccessAPI ( "act/retail/discount/batchdelete" , false , map [ string ] interface { } {
KeyAppPoiCode : poiCode ,
"item_ids" : strings . Join ( actIDList , "," ) ,
} )
return err
}
// 批量修改零售折扣商品当日活动库存
func ( a * API ) RetailDiscountBatchStock ( poiCode , actDataList [ ] * RetailActDataLimit ) ( err error ) {
_ , err = a . AccessAPI ( "act/retail/discount/batchstock" , false , map [ string ] interface { } {
KeyAppPoiCode : poiCode ,
"act_data" : string ( utils . MustMarshalJSONIgnoreValues ( actDataList , map [ string ] interface { } {
"order_limit" : ignoreRetailActDataLimit . OrderLimit ,
} ) ) ,
} )
return err
}
// 批量修改零售折扣商品每单限购数量
func ( a * API ) RetailDiscountBatchLimit ( poiCode , actDataList [ ] * RetailActDataLimit ) ( err error ) {
_ , err = a . AccessAPI ( "act/retail/discount/batchlimit" , false , map [ string ] interface { } {
KeyAppPoiCode : poiCode ,
"act_data" : string ( utils . MustMarshalJSONIgnoreValues ( actDataList , map [ string ] interface { } {
"day_limit" : ignoreRetailActDataLimit . DayLimit ,
} ) ) ,
} )
return err
}