diff --git a/platformapi/ebaiapi/activity.go b/platformapi/ebaiapi/activity.go index 4bf6591a..b7329002 100644 --- a/platformapi/ebaiapi/activity.go +++ b/platformapi/ebaiapi/activity.go @@ -21,6 +21,9 @@ const ( // 下面两个是做什么用的? // ActivityShowStatusEnabled = 2 // ActivityShowStatusDisabled = 4 + + MaxActivityNameLength = 30 // 活动名称为空或者长度大于30个字符 + MaxActivityDescLength = 15 // 优惠描述限15个字符 ) type ActivityRule struct { diff --git a/platformapi/jdapi/promotion_sku.go b/platformapi/jdapi/promotion_sku.go index bb60dd4a..4f6f039b 100644 --- a/platformapi/jdapi/promotion_sku.go +++ b/platformapi/jdapi/promotion_sku.go @@ -202,7 +202,7 @@ func (a *API) confirmPromotion(promotionType int, infoId int64, outInfoId, trace return err } -// 与createPromotionSku不同的是,此接口在活动确认后可以合适,实时生效 +// 与createPromotionSku不同的是,此接口在活动确认后可以调用,实时生效 func (a *API) cancelPromotionSku(promotionType int, infoId int64, outInfoId string, cancelSkus []*PromotionSku, traceId string) (err error) { jdParams := getCommonSkuPromotionParams(infoId, outInfoId, traceId) jdParams["cancelSkus"] = cancelSkus @@ -210,6 +210,7 @@ func (a *API) cancelPromotionSku(promotionType int, infoId int64, outInfoId stri return err } +// 取消一个不存在的活动,不会报错 func (a *API) cancelPromotion(promotionType int, infoId int64, outInfoId, traceId string) (err error) { jdParams := getCommonSkuPromotionParams(infoId, outInfoId, traceId) _, err = a.AccessAPINoPage(getPromotionCmd("cancelPromotion", promotionType), jdParams, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "", "0")) diff --git a/platformapi/mtwmapi/act.go b/platformapi/mtwmapi/act.go index 1eb8c1cc..f6b62ff3 100644 --- a/platformapi/mtwmapi/act.go +++ b/platformapi/mtwmapi/act.go @@ -111,11 +111,11 @@ type RetailDiscountActData struct { EndTime int64 `json:"end_time"` // 活动结束时间,单位秒 OrderLimit int `json:"order_limit"` // 每单限购:1)只能是正整数或-1。2)最大为10。 DayLimit int `json:"day_limit"` // 当日活动库存:只能是正整数或-1。 - Period string `json:"period"` - WeeksTime string `json:"weeks_time"` + Period string `json:"period,omitempty"` + WeeksTime string `json:"weeks_time,omitempty"` SettingType int `json:"setting_type"` - ActPrice float64 `json:"act_price"` // 折扣价格(单位元):必须为大于0的数字,且不能超过2位小数。 - DiscountCoefficient float64 `json:"discount_coefficient"` // 折扣系数:必须大于0小于9.8,最多支持两位小数。如输入3,即为3折 + ActPrice float64 `json:"act_price,omitempty"` // 折扣价格(单位元):必须为大于0的数字,且不能超过2位小数。 + DiscountCoefficient float64 `json:"discount_coefficient,omitempty"` // 折扣系数:必须大于0小于9.8,最多支持两位小数。如输入3,即为3折 Sequence int `json:"sequence,omitempty"` ItemID int64 `json:"item_id,omitempty"` // 活动ID,为什么这里又是int64 @@ -357,14 +357,28 @@ func (a *API) RetailDiscountBatchSave2(poiCode string, actType int, actData []*R "act_data": string(utils.MustMarshal(actData)), "act_type": actType, }, "", "") + var msg string if err == nil { resultMap := result.(map[string]interface{}) err = utils.UnmarshalUseNumber([]byte(resultMap[resultKeySuccessMsg].(string)), &actResult) if err == nil { - failedList, err = handleRetailBatchResult(resultMap[resultKeyMsg]) + msg = utils.Interface2String(resultMap[resultKeyMsg]) + } + } else { + msg = getMsgFromError(err) + } + failedList = parseErr4ErrList(msg) + return actResult, failedList, err +} + +func parseErr4ErrList(msg string) (failedList []*AppFoodResult) { + if msg != "" { + var mapData map[string]interface{} + if err := utils.UnmarshalUseNumber([]byte(msg), &mapData); err == nil { + utils.Map2StructByJson(mapData["error_list"], &failedList, false) } } - return actResult, failedList, err + return failedList } // 查询门店零售折扣商品 @@ -401,29 +415,62 @@ func (a *API) RetailDiscountList(poiCode string, actType int) (actList []*Retail // 批量删除零售折扣商品 // http://developer.waimai.meituan.com/home/docDetail/289 -// TODO 部分成功未处理 -func (a *API) RetailDiscountDelete(poiCode string, actType int, actIDList []string) (err error) { +func (a *API) RetailDiscountDelete2(poiCode string, actType int, actIDList []string) (failedList []*ActItemErrMsg, err error) { if actType == 0 { actType = RetailActTypeDirectDown } - _, err = a.AccessAPI("act/retail/discount/batchdelete", false, map[string]interface{}{ + result, err := a.AccessAPI("act/retail/discount/batchdelete", false, map[string]interface{}{ KeyAppPoiCode: poiCode, "act_type": actType, "item_ids": strings.Join(actIDList, ","), }) + var msg string + if err == nil { + msg = getMsgFromResult(result) + } else { + msg = getMsgFromError(err) + } + failedList = parseErr4RetailDiscountDelete(msg) + return failedList, err +} + +func (a *API) RetailDiscountDelete(poiCode string, actType int, actIDList []string) (err error) { + _, err = a.RetailDiscountDelete2(poiCode, actType, actIDList) return err } -func ParseErr4RetailDiscountDelete(err error) (failedList []*ActItemErrMsg) { +func getMsgFromResult(result interface{}) (msg string) { + if resultMap, ok := result.(map[string]interface{}); ok { + msg = utils.Interface2String(resultMap[resultKeyMsg]) + } + return msg +} + +func getMsgFromError(err error) (msg string) { if errExt, ok := err.(*utils.ErrorWithCode); ok { + msg = errExt.ErrMsg() + } + return msg +} + +func parseErr4RetailDiscountDelete(msg string) (failedList []*ActItemErrMsg) { + if msg != "" { var mapData map[string]interface{} - if err := utils.UnmarshalUseNumber([]byte(errExt.ErrMsg()), &mapData); err == nil { + if err := utils.UnmarshalUseNumber([]byte(msg), &mapData); err == nil { utils.Map2StructByJson(mapData["error_list"], &failedList, false) } } return failedList } +func ParseErr4RetailDiscountDelete(err error) (failedList []*ActItemErrMsg) { + return parseErr4RetailDiscountDelete(getMsgFromError(err)) +} + +func CanDeleteActErrMsgIgnore(errMsg string) bool { + return errMsg == "" || errMsg == "活动ID不存在" +} + // 批量修改零售折扣商品当日活动库存 // http://developer.waimai.meituan.com/home/docDetail/290 func (a *API) RetailDiscountBatchStock(poiCode, actDataList []*RetailDiscountActDataLimit) (err error) {