- 调整了一些与活动相关的API,三个平台都有
This commit is contained in:
@@ -17,6 +17,7 @@ const (
|
||||
ActivityConflictShare = 0 // 与全店满减等其他活动同享
|
||||
ActivityConfilictExclude = 1 // 与全店满减等其他活动互斥
|
||||
|
||||
MaxActivitySkuBatchSize = 100 // 使用商品id的活动商品,与商品自定义id互斥。一批最多100个
|
||||
// 下面两个是做什么用的?
|
||||
// ActivityShowStatusEnabled = 2
|
||||
// ActivityShowStatusDisabled = 4
|
||||
|
||||
@@ -42,7 +42,11 @@ type PromotionSku struct {
|
||||
|
||||
func getPromotionCmd(inCmd string, promotionType int) (outCmd string) {
|
||||
if promotionType == PromotionTypeDirectDown {
|
||||
outCmd = "singlePromote/" + inCmd
|
||||
if inCmd == "adjustPromotionSku" || inCmd == "adjustPromotionTime" {
|
||||
outCmd = "promotesku/" + inCmd
|
||||
} else {
|
||||
outCmd = "singlePromote/" + inCmd
|
||||
}
|
||||
} else if promotionType == PromotionTypeLimitedTime {
|
||||
outCmd = "limitTime/" + inCmd
|
||||
} else {
|
||||
@@ -88,6 +92,18 @@ func (a *API) CancelPromotionSingle(infoId int64, outInfoId, traceId string) (er
|
||||
return a.cancelPromotion(PromotionTypeDirectDown, infoId, outInfoId, traceId)
|
||||
}
|
||||
|
||||
// 单品实时促销活动结束时间调整接口
|
||||
// https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=178&apiid=0abab0c4b81d45e5bc555cc7dfbeb1ad
|
||||
func (a *API) AdjustPromotionTimeSingle(infoId int64, outInfoId string, endDate time.Time, traceId string) (err error) {
|
||||
return a.adjustPromotionTime(PromotionTypeDirectDown, infoId, outInfoId, endDate, traceId)
|
||||
}
|
||||
|
||||
// 单品实时促销商品促销数量调整接口
|
||||
// https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=178&apiid=82964e5e0f9c448db072a54ed20e00c4
|
||||
func (a *API) AdjustPromotionSkuSingle(infoId int64, outInfoId string, skus []*PromotionSku, traceId string) (skusResult []*PromotionSku, err error) {
|
||||
return a.adjustPromotionSku(PromotionTypeDirectDown, infoId, outInfoId, skus, traceId)
|
||||
}
|
||||
|
||||
// 以下为限时抢
|
||||
|
||||
// 限时抢添加活动主信息接口
|
||||
@@ -127,6 +143,18 @@ func (a *API) CancelPromotionLimitTime(infoId int64, outInfoId, traceId string)
|
||||
return a.cancelPromotion(PromotionTypeLimitedTime, infoId, outInfoId, traceId)
|
||||
}
|
||||
|
||||
// 限时抢活动结束时间调整接口
|
||||
// https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=184&apiid=f91035295cd54a9bbd2db9dfc800484c
|
||||
func (a *API) AdjustPromotionTimeLimitTime(infoId int64, outInfoId string, endDate time.Time, traceId string) (err error) {
|
||||
return a.adjustPromotionTime(PromotionTypeLimitedTime, infoId, outInfoId, endDate, traceId)
|
||||
}
|
||||
|
||||
// 限时抢商品促销数量调整接口
|
||||
// https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=184&apiid=aa878a000dfb4a248634ee755af1f1d3
|
||||
func (a *API) AdjustPromotionSkuLimitTime(infoId int64, outInfoId string, skus []*PromotionSku, traceId string) (skusResult []*PromotionSku, err error) {
|
||||
return a.adjustPromotionSku(PromotionTypeLimitedTime, infoId, outInfoId, skus, traceId)
|
||||
}
|
||||
|
||||
func (a *API) createPromotionInfos(promotionType int, name string, beginDate, endDate time.Time, outInfoId, advertising, traceId string) (infoId int64, err error) {
|
||||
if outInfoId == "" {
|
||||
outInfoId = fmt.Sprintf("%X", md5.Sum([]byte(name)))
|
||||
@@ -186,6 +214,22 @@ func (a *API) cancelPromotion(promotionType int, infoId int64, outInfoId, traceI
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) adjustPromotionTime(promotionType int, infoId int64, outInfoId string, endDate time.Time, traceId string) (err error) {
|
||||
jdParams := getCommonSkuPromotionParams(infoId, outInfoId, traceId)
|
||||
_, err = a.AccessAPINoPage(getPromotionCmd("adjustPromotionTime", promotionType), jdParams, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "", "0"))
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) adjustPromotionSku(promotionType int, infoId int64, outInfoId string, skus []*PromotionSku, traceId string) (skusResult []*PromotionSku, err error) {
|
||||
jdParams := getCommonSkuPromotionParams(infoId, outInfoId, traceId)
|
||||
jdParams["skus"] = skus
|
||||
result, err := a.AccessAPINoPage(getPromotionCmd("adjustPromotionSku", promotionType), jdParams, nil, nil, genNoPageResultParser("errorCode", "data", "", "0"))
|
||||
if err == nil && result != nil {
|
||||
err = utils.Map2StructByJson(result, &skusResult, false)
|
||||
}
|
||||
return skusResult, err
|
||||
}
|
||||
|
||||
func getCommonSkuPromotionParams(infoId int64, outInfoId, traceId string) map[string]interface{} {
|
||||
jdParams := map[string]interface{}{
|
||||
"timeStamp": utils.GetCurTimeStr(),
|
||||
|
||||
@@ -79,8 +79,9 @@ type ShippingFeeActDetail struct {
|
||||
LimitPrice float64 `json:"limit_price"`
|
||||
DiscountPrice float64 `json:"discount_price"`
|
||||
|
||||
PoiCharge float64 `json:"-"`
|
||||
MtCharge float64 `json:"-"`
|
||||
// list时用
|
||||
PoiCharge float64 `json:"poi_charge,omitempty"`
|
||||
MtCharge float64 `json:"mt_charge,omitempty"`
|
||||
}
|
||||
|
||||
type ShippingFeeActData struct {
|
||||
@@ -91,34 +92,44 @@ type ShippingFeeActData struct {
|
||||
ActDetail []*ShippingFeeActDetail `json:"act_detail"`
|
||||
MaxPrice float64 `json:"max_price,omitempty"`
|
||||
|
||||
AppPoiCode string `json:"-"`
|
||||
ActID string `json:"-"`
|
||||
ActStatus string `json:"-"`
|
||||
// list时用
|
||||
AppPoiCode string `json:"app_poi_code,omitempty"`
|
||||
ActID int64 `json:"act_id,omitempty"`
|
||||
ActStatus string `json:"actStatus,omitempty"`
|
||||
}
|
||||
|
||||
type RetailActData struct {
|
||||
type RetailDiscountActData struct {
|
||||
AppFoodCode string `json:"app_food_code"`
|
||||
UserType int `json:"user_type"`
|
||||
StartTime int64 `json:"start_time"` // 活动开始时间,单位秒
|
||||
EndTime int64 `json:"end_time"` // 活动结束时间,单位秒
|
||||
OrderLimit int `json:"order_limit"`
|
||||
DayLimit int `json:"day_limit"`
|
||||
WeeksTime string `json:"weeks_time"`
|
||||
Period string `json:"period"`
|
||||
WeeksTime string `json:"weeks_time"`
|
||||
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,omitempty"`
|
||||
ItemID int64 `json:"item_id,omitempty"` // 活动ID,为什么这里又是int64
|
||||
|
||||
// 以下参数只有查询时用到
|
||||
OriginalPrice float64 `json:"-"` // 商品原价,单位元
|
||||
Stock int `json:"-"` // 当日剩余活动商品数量。只有当发起查询时间处于活动生效时段内时(start_time、end_time、period、weeks_time均需满足),该字段才代表实际剩余活动商品数量,否则显示的是创建活动时规定的当日活动库存
|
||||
Status int `json:"-"` // 活动状态,0:已过期,1:已生效,2:待生效。
|
||||
Name string `json:"-"`
|
||||
// list时用
|
||||
OriginalPrice float64 `json:"origin_price,omitempty"` // 商品原价,单位元
|
||||
Stock int `json:"stock,omitempty"` // 当日剩余活动商品数量。只有当发起查询时间处于活动生效时段内时(start_time、end_time、period、weeks_time均需满足),该字段才代表实际剩余活动商品数量,否则显示的是创建活动时规定的当日活动库存
|
||||
Status int `json:"status,omitempty"` // 活动状态,0:已过期,1:已生效,2:待生效。
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type RetailActDataLimit struct {
|
||||
type RetailDiscountActResult struct {
|
||||
AppFoodCode string `json:"app_food_code"`
|
||||
StartTime int64 `json:"start_time"` // 活动开始时间,单位秒
|
||||
EndTime int64 `json:"end_time"` // 活动结束时间,单位秒
|
||||
ActID int64 `json:"act_id,omitempty"`
|
||||
Period string `json:"period"`
|
||||
WeeksTime string `json:"weeks_time"`
|
||||
}
|
||||
|
||||
type RetailDiscountActDataLimit struct {
|
||||
ItemID int64 `json:"item_id"` // 活动ID,为什么这里又是int64
|
||||
DayLimit int `json:"day_limit,omitempty"` // 当日活动库存,只能为正整数或-1,-1表示无限库存
|
||||
OrderLimit int `json:"order_limit,omitempty"` // 每单可购买的折扣商品数量
|
||||
@@ -137,6 +148,12 @@ type CouponInfo struct {
|
||||
Stock int `json:"stock"`
|
||||
}
|
||||
|
||||
type CouponResult struct {
|
||||
StartTime int64 `json:"start_time"` // 活动开始时间,单位秒
|
||||
EndTime int64 `json:"end_time"` // 活动结束时间,单位秒
|
||||
ActID int64 `json:"act_id,omitempty"`
|
||||
}
|
||||
|
||||
type CouponData struct {
|
||||
LimitPrice float64 `json:"limit_price"` //使用门槛,单位元
|
||||
CouponPrice float64 `json:"coupon_price"` // 优惠券金额,单位元
|
||||
@@ -160,7 +177,7 @@ type CouponActInfo struct {
|
||||
|
||||
// 批量创建指定商品满减活动或创建店内满减活动
|
||||
// http://developer.waimai.meituan.com/home/docDetail/255
|
||||
func (a *API) FullDiscountBatchSave(poiCode string, actInfo *FullDiscountActInfo, actList []*FullDiscountActDetail, actSkuList []*FullDiscountSku) (actID int64, err error) {
|
||||
func (a *API) FullDiscountBatchSave(poiCode string, actInfo *FullDiscountActInfo, actList []*FullDiscountActDetail, actSkuList []*FullDiscountSku) (actIDList []int64, err error) {
|
||||
params := map[string]interface{}{
|
||||
KeyAppPoiCode: poiCode,
|
||||
"act_info": string(utils.MustMarshal(actInfo)),
|
||||
@@ -171,9 +188,9 @@ func (a *API) FullDiscountBatchSave(poiCode string, actInfo *FullDiscountActInfo
|
||||
}
|
||||
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
|
||||
err = utils.UnmarshalUseNumber([]byte(result.(string)), &actIDList)
|
||||
}
|
||||
return 0, err
|
||||
return actIDList, err
|
||||
}
|
||||
|
||||
// 批量查询指定商品满减活动或店内满减活动
|
||||
@@ -301,20 +318,20 @@ func (a *API) FulllDiscountShippingFeeBatchDelete(poiCode string, actIDList []st
|
||||
|
||||
// 批量创建或更新零售折扣商品
|
||||
// http://developer.waimai.meituan.com/home/docDetail/287
|
||||
func (a *API) RetailDiscountBatchSave(poiCode string, actData []*RetailActData) (actID int64, err error) {
|
||||
func (a *API) RetailDiscountBatchSave(poiCode string, actData []*RetailDiscountActData) (actResult []*RetailDiscountActResult, err error) {
|
||||
result, err := a.AccessAPI2("act/retail/discount/batchsave", false, map[string]interface{}{
|
||||
KeyAppPoiCode: poiCode,
|
||||
"act_data": string(utils.MustMarshal(actData)),
|
||||
}, resultKeyMsg)
|
||||
if err == nil {
|
||||
return utils.MustInterface2Int64(result.([]interface{})[0].(map[string]interface{})["act_id"]), nil
|
||||
err = utils.UnmarshalUseNumber([]byte(result.(string)), &actResult)
|
||||
}
|
||||
return 0, err
|
||||
return actResult, err
|
||||
}
|
||||
|
||||
// 查询门店零售折扣商品
|
||||
// http://developer.waimai.meituan.com/home/docDetail/288
|
||||
func (a *API) RetailDiscountList(poiCode string) (actList []*RetailActData, err error) {
|
||||
func (a *API) RetailDiscountList(poiCode string) (actList []*RetailDiscountActData, err error) {
|
||||
limit := 200
|
||||
offset := 0
|
||||
for {
|
||||
@@ -324,7 +341,7 @@ func (a *API) RetailDiscountList(poiCode string) (actList []*RetailActData, err
|
||||
"offset": offset,
|
||||
})
|
||||
if err == nil {
|
||||
var tmpActList []*RetailActData
|
||||
var tmpActList []*RetailDiscountActData
|
||||
if err = utils.Map2StructByJson(result, &tmpActList, false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -352,7 +369,7 @@ func (a *API) RetailDiscountDelete(poiCode string, actIDList []string) (err erro
|
||||
|
||||
// 批量修改零售折扣商品当日活动库存
|
||||
// http://developer.waimai.meituan.com/home/docDetail/290
|
||||
func (a *API) RetailDiscountBatchStock(poiCode, actDataList []*RetailActDataLimit) (err error) {
|
||||
func (a *API) RetailDiscountBatchStock(poiCode, actDataList []*RetailDiscountActDataLimit) (err error) {
|
||||
_, err = a.AccessAPI("act/retail/discount/batchstock", false, map[string]interface{}{
|
||||
KeyAppPoiCode: poiCode,
|
||||
"act_data": string(utils.MustMarshal(actDataList)),
|
||||
@@ -362,7 +379,7 @@ func (a *API) RetailDiscountBatchStock(poiCode, actDataList []*RetailActDataLimi
|
||||
|
||||
// 批量修改零售折扣商品每单限购数量
|
||||
// http://developer.waimai.meituan.com/home/docDetail/291
|
||||
func (a *API) RetailDiscountBatchLimit(poiCode, actDataList []*RetailActDataLimit) (err error) {
|
||||
func (a *API) RetailDiscountBatchLimit(poiCode, actDataList []*RetailDiscountActDataLimit) (err error) {
|
||||
_, err = a.AccessAPI("act/retail/discount/batchlimit", false, map[string]interface{}{
|
||||
KeyAppPoiCode: poiCode,
|
||||
"act_data": string(utils.MustMarshal(actDataList)),
|
||||
@@ -372,16 +389,16 @@ func (a *API) RetailDiscountBatchLimit(poiCode, actDataList []*RetailActDataLimi
|
||||
|
||||
// 批量新增商家券(店内发券)活动
|
||||
// http://developer.waimai.meituan.com/home/docDetail/312
|
||||
func (a *API) InStoreCouponBatchSave(poiCode string, limitTime *LimitTime, couponInfoList []*CouponInfo) (actID int64, err error) {
|
||||
func (a *API) InStoreCouponBatchSave(poiCode string, limitTime *LimitTime, couponInfoList []*CouponInfo) (couponResultList []*CouponResult, err error) {
|
||||
result, err := a.AccessAPI2("act/instore/coupon/batchsave", false, map[string]interface{}{
|
||||
KeyAppPoiCode: poiCode,
|
||||
"limit_time": string(utils.MustMarshal(limitTime)),
|
||||
"act_data": string(utils.MustMarshal(couponInfoList)),
|
||||
}, resultKeyMsg)
|
||||
if err == nil {
|
||||
actID = utils.MustInterface2Int64(result.([]interface{})[0].(map[string]interface{})["act_id"])
|
||||
err = utils.UnmarshalUseNumber([]byte(result.(string)), &couponResultList)
|
||||
}
|
||||
return actID, err
|
||||
return couponResultList, err
|
||||
}
|
||||
|
||||
// 批量删除商家券(店内发券)活动
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestFullDiscountBatchSave(t *testing.T) {
|
||||
result, err := api.FullDiscountBatchSave("6693359", &FullDiscountActInfo{
|
||||
result, err := api.FullDiscountBatchSave(testPoiCode, &FullDiscountActInfo{
|
||||
// ActIDs: "12345678",
|
||||
ActName: "测试活动0402",
|
||||
StartTime: time.Now().Unix(),
|
||||
@@ -33,7 +33,7 @@ func TestFullDiscountBatchSave(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFullDiscountList(t *testing.T) {
|
||||
result, err := api.FullDiscountList("6737142", ActTypeStoreFullDiscount)
|
||||
result, err := api.FullDiscountList(testPoiCode, ActTypeStoreFullDiscount)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func TestFullDiscountList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFullDiscountFoodsList(t *testing.T) {
|
||||
result, err := api.FullDiscountFoodsList("6737142", "497726932")
|
||||
result, err := api.FullDiscountFoodsList(testPoiCode, "497726932")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -49,14 +49,14 @@ func TestFullDiscountFoodsList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFulllDiscountShippingFeeBatchSave(t *testing.T) {
|
||||
err := api.FulllDiscountShippingFeeBatchSave("6737142", []*ShippingFeeActData{&ShippingFeeActData{}})
|
||||
err := api.FulllDiscountShippingFeeBatchSave(testPoiCode, []*ShippingFeeActData{&ShippingFeeActData{}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFulllDiscountShippingFeeList(t *testing.T) {
|
||||
result, err := api.FulllDiscountShippingFeeList("6737142")
|
||||
result, err := api.FulllDiscountShippingFeeList(testPoiCode)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -64,8 +64,8 @@ func TestFulllDiscountShippingFeeList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRetailDiscountBatchSave(t *testing.T) {
|
||||
result, err := api.RetailDiscountBatchSave("6737142", []*RetailActData{&RetailActData{
|
||||
AppFoodCode: "24785",
|
||||
result, err := api.RetailDiscountBatchSave(testPoiCode, []*RetailDiscountActData{&RetailDiscountActData{
|
||||
AppFoodCode: "5246",
|
||||
UserType: UserTypeAll,
|
||||
StartTime: time.Now().Unix(),
|
||||
EndTime: time.Now().Add(24 * time.Hour).Unix(),
|
||||
@@ -81,7 +81,7 @@ func TestRetailDiscountBatchSave(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRetailDiscountList(t *testing.T) {
|
||||
result, err := api.RetailDiscountList("6737142")
|
||||
result, err := api.RetailDiscountList(testPoiCode)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -89,14 +89,14 @@ func TestRetailDiscountList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRetailDiscountDelete(t *testing.T) {
|
||||
err := api.RetailDiscountDelete("6737142", []string{"329187452"})
|
||||
err := api.RetailDiscountDelete(testPoiCode, []string{"329187452"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInStoreCouponList(t *testing.T) {
|
||||
result, err := api.InStoreCouponList("6783616", 1, 100)
|
||||
result, err := api.InStoreCouponList(testPoiCode, 1, 100)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user