Merge branch 'master' of e.coding.net:rosydev/baseapi
This commit is contained in:
@@ -21,6 +21,9 @@ const (
|
|||||||
// 下面两个是做什么用的?
|
// 下面两个是做什么用的?
|
||||||
// ActivityShowStatusEnabled = 2
|
// ActivityShowStatusEnabled = 2
|
||||||
// ActivityShowStatusDisabled = 4
|
// ActivityShowStatusDisabled = 4
|
||||||
|
|
||||||
|
MaxActivityNameLength = 30 // 活动名称为空或者长度大于30个字符
|
||||||
|
MaxActivityDescLength = 15 // 优惠描述限15个字符
|
||||||
)
|
)
|
||||||
|
|
||||||
type ActivityRule struct {
|
type ActivityRule struct {
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ func (a *API) confirmPromotion(promotionType int, infoId int64, outInfoId, trace
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 与createPromotionSku不同的是,此接口在活动确认后可以合适,实时生效
|
// 与createPromotionSku不同的是,此接口在活动确认后可以调用,实时生效
|
||||||
func (a *API) cancelPromotionSku(promotionType int, infoId int64, outInfoId string, cancelSkus []*PromotionSku, traceId string) (err error) {
|
func (a *API) cancelPromotionSku(promotionType int, infoId int64, outInfoId string, cancelSkus []*PromotionSku, traceId string) (err error) {
|
||||||
jdParams := getCommonSkuPromotionParams(infoId, outInfoId, traceId)
|
jdParams := getCommonSkuPromotionParams(infoId, outInfoId, traceId)
|
||||||
jdParams["cancelSkus"] = cancelSkus
|
jdParams["cancelSkus"] = cancelSkus
|
||||||
@@ -210,6 +210,7 @@ func (a *API) cancelPromotionSku(promotionType int, infoId int64, outInfoId stri
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 取消一个不存在的活动,不会报错
|
||||||
func (a *API) cancelPromotion(promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
func (a *API) cancelPromotion(promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
||||||
jdParams := getCommonSkuPromotionParams(infoId, outInfoId, traceId)
|
jdParams := getCommonSkuPromotionParams(infoId, outInfoId, traceId)
|
||||||
_, err = a.AccessAPINoPage(getPromotionCmd("cancelPromotion", promotionType), jdParams, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "", "0"))
|
_, err = a.AccessAPINoPage(getPromotionCmd("cancelPromotion", promotionType), jdParams, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "", "0"))
|
||||||
|
|||||||
@@ -111,11 +111,11 @@ type RetailDiscountActData struct {
|
|||||||
EndTime int64 `json:"end_time"` // 活动结束时间,单位秒
|
EndTime int64 `json:"end_time"` // 活动结束时间,单位秒
|
||||||
OrderLimit int `json:"order_limit"` // 每单限购:1)只能是正整数或-1。2)最大为10。
|
OrderLimit int `json:"order_limit"` // 每单限购:1)只能是正整数或-1。2)最大为10。
|
||||||
DayLimit int `json:"day_limit"` // 当日活动库存:只能是正整数或-1。
|
DayLimit int `json:"day_limit"` // 当日活动库存:只能是正整数或-1。
|
||||||
Period string `json:"period"`
|
Period string `json:"period,omitempty"`
|
||||||
WeeksTime string `json:"weeks_time"`
|
WeeksTime string `json:"weeks_time,omitempty"`
|
||||||
SettingType int `json:"setting_type"`
|
SettingType int `json:"setting_type"`
|
||||||
ActPrice float64 `json:"act_price"` // 折扣价格(单位元):必须为大于0的数字,且不能超过2位小数。
|
ActPrice float64 `json:"act_price,omitempty"` // 折扣价格(单位元):必须为大于0的数字,且不能超过2位小数。
|
||||||
DiscountCoefficient float64 `json:"discount_coefficient"` // 折扣系数:必须大于0小于9.8,最多支持两位小数。如输入3,即为3折
|
DiscountCoefficient float64 `json:"discount_coefficient,omitempty"` // 折扣系数:必须大于0小于9.8,最多支持两位小数。如输入3,即为3折
|
||||||
Sequence int `json:"sequence,omitempty"`
|
Sequence int `json:"sequence,omitempty"`
|
||||||
ItemID int64 `json:"item_id,omitempty"` // 活动ID,为什么这里又是int64
|
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_data": string(utils.MustMarshal(actData)),
|
||||||
"act_type": actType,
|
"act_type": actType,
|
||||||
}, "", "")
|
}, "", "")
|
||||||
|
var msg string
|
||||||
if err == nil {
|
if err == nil {
|
||||||
resultMap := result.(map[string]interface{})
|
resultMap := result.(map[string]interface{})
|
||||||
err = utils.UnmarshalUseNumber([]byte(resultMap[resultKeySuccessMsg].(string)), &actResult)
|
err = utils.UnmarshalUseNumber([]byte(resultMap[resultKeySuccessMsg].(string)), &actResult)
|
||||||
if err == nil {
|
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
|
// http://developer.waimai.meituan.com/home/docDetail/289
|
||||||
// TODO 部分成功未处理
|
func (a *API) RetailDiscountDelete2(poiCode string, actType int, actIDList []string) (failedList []*ActItemErrMsg, err error) {
|
||||||
func (a *API) RetailDiscountDelete(poiCode string, actType int, actIDList []string) (err error) {
|
|
||||||
if actType == 0 {
|
if actType == 0 {
|
||||||
actType = RetailActTypeDirectDown
|
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,
|
KeyAppPoiCode: poiCode,
|
||||||
"act_type": actType,
|
"act_type": actType,
|
||||||
"item_ids": strings.Join(actIDList, ","),
|
"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
|
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 {
|
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{}
|
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)
|
utils.Map2StructByJson(mapData["error_list"], &failedList, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return failedList
|
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
|
// http://developer.waimai.meituan.com/home/docDetail/290
|
||||||
func (a *API) RetailDiscountBatchStock(poiCode, actDataList []*RetailDiscountActDataLimit) (err error) {
|
func (a *API) RetailDiscountBatchStock(poiCode, actDataList []*RetailDiscountActDataLimit) (err error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user