- 美团外卖满减,直降,运费活动API完成
This commit is contained in:
@@ -7,23 +7,39 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ActTypeStoreMoneyOff = 0
|
||||
ActTypeSkuMoneyOff = 1
|
||||
ActTypeStoreFullDiscount = 0
|
||||
ActTypeSkuFullDiscount = 1
|
||||
)
|
||||
|
||||
const (
|
||||
// 指定商品满减活动状态
|
||||
SkuMoneyOffStatusNew = 2 // 待生效
|
||||
SkuMoneyOffStatusValid = 1 // 生效
|
||||
SkuMoneyOffStatusExpired = 0 // 过期
|
||||
SkuFullDiscountStatusExpired = 0 // 过期
|
||||
SkuFullDiscountStatusValid = 1 // 生效
|
||||
SkuFullDiscountStatusNew = 2 // 待生效
|
||||
|
||||
// 全店满减活动状态
|
||||
StoreMoneyOffStatusNew = 0 // 待生效
|
||||
StoreMoneyOffStatusValid = 1 // 生效
|
||||
StoreMoneyOffStatusExpired = 2 // 过期
|
||||
StoreFullDiscountStatusNew = 0 // 待生效
|
||||
StoreFullDiscountStatusValid = 1 // 生效
|
||||
StoreFullDiscountStatusExpired = 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 FullDiscountActInfo 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 FullDiscountActDetail 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 *FullDiscountActInfo `json:"act_info"`
|
||||
ActRemark string `json:"act_remark"`
|
||||
AppPoiCode string `json:"app_poi_code"`
|
||||
|
||||
ActDetails []*ActDetail `json:"act_details"`
|
||||
ActDetails []*FullDiscountActDetail `json:"act_details"`
|
||||
}
|
||||
|
||||
type ActFoodsInfo struct {
|
||||
ActInfo *ActInfo `json:"act_info"`
|
||||
ActRemark string `json:"act_remark"`
|
||||
AppPoiCode string `json:"app_poi_code"`
|
||||
type FullDiscountFoodsInfo struct {
|
||||
ActInfo *FullDiscountActInfo `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 ActData struct {
|
||||
ItemID int64 `json:"item_id"` // 活动ID,为什么这里又是int64
|
||||
DayLimit int `json:"day_limit"` // 当日活动库存,只能为正整数或-1,-1表示无限库存
|
||||
type ShippingFeeActDetail struct {
|
||||
LimitPrice float64 `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, &FullDiscountActDetail{
|
||||
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{}) *FullDiscountActInfo {
|
||||
actInfoMap := actInfo.(map[string]interface{})
|
||||
return &ActInfo{
|
||||
return &FullDiscountActInfo{
|
||||
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 *ActFoodsInfo, err error) {
|
||||
pageSize := 200
|
||||
func (a *API) FullDiscountFoodsList(poiCode, actID string) (actFoodsInfo *FullDiscountFoodsInfo, 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 = &ActFoodsInfo{
|
||||
actFoodsInfo = &FullDiscountFoodsInfo{
|
||||
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
|
||||
}
|
||||
|
||||
@@ -8,14 +8,14 @@ import (
|
||||
)
|
||||
|
||||
func TestFullDiscountBatchSave(t *testing.T) {
|
||||
err := api.FullDiscountBatchSave("6693359", &ActInfo{
|
||||
result, err := api.FullDiscountBatchSave("6693359", &FullDiscountActInfo{
|
||||
// ActIDs: "12345678",
|
||||
ActName: "测试活动0402",
|
||||
StartTime: time.Now().Unix(),
|
||||
EndTime: time.Now().Add(24 * time.Hour).Unix(),
|
||||
ActType: ActTypeStoreMoneyOff,
|
||||
}, []*ActDetail{
|
||||
&ActDetail{
|
||||
ActType: ActTypeStoreFullDiscount,
|
||||
}, []*FullDiscountActDetail{
|
||||
&FullDiscountActDetail{
|
||||
OriginalPrice: 10000,
|
||||
ActPrice: 1,
|
||||
},
|
||||
@@ -29,11 +29,11 @@ func TestFullDiscountBatchSave(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// 30902
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
t.Log(result)
|
||||
}
|
||||
|
||||
func TestFullDiscountList(t *testing.T) {
|
||||
result, err := api.FullDiscountList("6737142", ActTypeStoreMoneyOff)
|
||||
result, err := api.FullDiscountList("6737142", ActTypeStoreFullDiscount)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -47,3 +47,50 @@ func TestFullDiscountFoodsList(t *testing.T) {
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestFulllDiscountShippingFeeBatchSave(t *testing.T) {
|
||||
err := api.FulllDiscountShippingFeeBatchSave("6737142", []*ShippingFeeActData{&ShippingFeeActData{}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFulllDiscountShippingFeeList(t *testing.T) {
|
||||
result, err := api.FulllDiscountShippingFeeList("6737142")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestRetailDiscountBatchSave(t *testing.T) {
|
||||
result, err := api.RetailDiscountBatchSave("6737142", []*RetailActData{&RetailActData{
|
||||
AppFoodCode: "24785",
|
||||
UserType: UserTypeAll,
|
||||
StartTime: time.Now().Unix(),
|
||||
EndTime: time.Now().Add(24 * time.Hour).Unix(),
|
||||
OrderLimit: 1,
|
||||
DayLimit: 1,
|
||||
SettingType: SettingTypeAsDiscount,
|
||||
DiscountCoefficient: 9.7,
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestRetailDiscountList(t *testing.T) {
|
||||
result, err := api.RetailDiscountList("6737142")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestRetailDiscountDelete(t *testing.T) {
|
||||
err := api.RetailDiscountDelete("6737142", []string{"329187452"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ const (
|
||||
KeyOrderID = "order_id"
|
||||
)
|
||||
|
||||
const (
|
||||
resultKeyData = "data"
|
||||
resultKeyMsg = "success_msg"
|
||||
)
|
||||
const (
|
||||
GeneralMaxLimit = 200 // 大多数的API的批处理最大条数
|
||||
)
|
||||
@@ -82,7 +86,7 @@ func (a *API) signParams(signURL string, params map[string]interface{}) string {
|
||||
return fmt.Sprintf("%x", md5.Sum([]byte(finalStr)))
|
||||
}
|
||||
|
||||
func (a *API) AccessAPI(cmd string, isGet bool, bizParams map[string]interface{}) (retVal interface{}, err error) {
|
||||
func (a *API) AccessAPI2(cmd string, isGet bool, bizParams map[string]interface{}, resultKey string) (retVal interface{}, err error) {
|
||||
params := make(map[string]interface{})
|
||||
params["timestamp"] = time.Now().Unix()
|
||||
params["app_id"] = a.appID
|
||||
@@ -136,7 +140,7 @@ func (a *API) AccessAPI(cmd string, isGet bool, bizParams map[string]interface{}
|
||||
newErr := utils.NewErrorIntCode(errorInfo["msg"].(string), int(utils.MustInterface2Int64(errorInfo["code"])))
|
||||
return platformapi.ErrLevelCodeIsNotOK, newErr
|
||||
}
|
||||
retVal = jsonResult1["data"]
|
||||
retVal = jsonResult1[resultKey]
|
||||
return platformapi.ErrLevelSuccess, nil
|
||||
})
|
||||
err = platformapi.RebuildError(err, bizParams, []string{
|
||||
@@ -146,3 +150,7 @@ func (a *API) AccessAPI(cmd string, isGet bool, bizParams map[string]interface{}
|
||||
})
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
func (a *API) AccessAPI(cmd string, isGet bool, bizParams map[string]interface{}) (retVal interface{}, err error) {
|
||||
return a.AccessAPI2(cmd, isGet, bizParams, resultKeyData)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user