- 京东活动API重构
This commit is contained in:
@@ -47,34 +47,7 @@ type OpenPlatActivityQResponse struct {
|
|||||||
} `json:"stationBeanList"`
|
} `json:"stationBeanList"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PromotionSkuResult struct {
|
type PromotionLspQuerySkuResult struct {
|
||||||
LimitDaily int
|
|
||||||
LimitDevice int
|
|
||||||
LimitPin int
|
|
||||||
PlatformRatio int
|
|
||||||
PromotionPrice int
|
|
||||||
SkuId int64
|
|
||||||
StationNo int64
|
|
||||||
StoreRatio int
|
|
||||||
}
|
|
||||||
|
|
||||||
type PromotionInfo struct {
|
|
||||||
BeginTime time.Time
|
|
||||||
EndTime time.Time
|
|
||||||
PromotionInfoId int64
|
|
||||||
PromotionState int
|
|
||||||
PromotionType int
|
|
||||||
Source string
|
|
||||||
SkuResultList []*PromotionSkuResult
|
|
||||||
}
|
|
||||||
|
|
||||||
type PromotionLspQueryInfoResult struct {
|
|
||||||
BeginTime *utils.JavaDate `json:"beginTime"`
|
|
||||||
EndTime *utils.JavaDate `json:"endTime"`
|
|
||||||
PromotionInfoID int `json:"promotionInfoId"`
|
|
||||||
PromotionState int `json:"promotionState"`
|
|
||||||
PromotionType int `json:"promotionType"`
|
|
||||||
SkuResultList []struct {
|
|
||||||
BeginTime *utils.JavaDate `json:"beginTime"`
|
BeginTime *utils.JavaDate `json:"beginTime"`
|
||||||
EndTime *utils.JavaDate `json:"endTime"`
|
EndTime *utils.JavaDate `json:"endTime"`
|
||||||
LimitDaily int `json:"limitDaily"`
|
LimitDaily int `json:"limitDaily"`
|
||||||
@@ -84,11 +57,19 @@ type PromotionLspQueryInfoResult struct {
|
|||||||
PromotionPrice int `json:"promotionPrice"`
|
PromotionPrice int `json:"promotionPrice"`
|
||||||
PromotionState int `json:"promotionState"`
|
PromotionState int `json:"promotionState"`
|
||||||
PromotionType int `json:"promotionType"`
|
PromotionType int `json:"promotionType"`
|
||||||
SkuId int64 `json:"skuId"`
|
SkuID int64 `json:"skuId"`
|
||||||
Source string `json:"source"`
|
Source string `json:"source"`
|
||||||
StationNo int64 `json:"stationNo"`
|
StationNo int64 `json:"stationNo"`
|
||||||
StoreRatio int `json:"storeRatio"`
|
StoreRatio int `json:"storeRatio"`
|
||||||
} `json:"skuResultList"`
|
}
|
||||||
|
|
||||||
|
type PromotionLspQueryInfoResult struct {
|
||||||
|
BeginTime *utils.JavaDate `json:"beginTime"`
|
||||||
|
EndTime *utils.JavaDate `json:"endTime"`
|
||||||
|
PromotionInfoID int64 `json:"promotionInfoId"`
|
||||||
|
PromotionState int `json:"promotionState"`
|
||||||
|
PromotionType int `json:"promotionType"`
|
||||||
|
SkuResultList []*PromotionLspQuerySkuResult `json:"skuResultList"`
|
||||||
Source string `json:"source"`
|
Source string `json:"source"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,43 +91,7 @@ func (a *API) OrderDiscountQueryActivityInfoById(activityID int64, promotionType
|
|||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) QueryPromotionInfo(promotionInfoId int64) (promotionInfo *PromotionInfo, err error) {
|
func (a *API) QueryPromotionInfo(promotionInfoId int64) (promotionInfo *PromotionLspQueryInfoResult, err error) {
|
||||||
jdParams := map[string]interface{}{
|
|
||||||
"promotionInfoId": promotionInfoId,
|
|
||||||
}
|
|
||||||
result, err := a.AccessAPINoPage("singlePromote/queryPromotionInfo", jdParams, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "data", "0"))
|
|
||||||
if err == nil {
|
|
||||||
data := result.(map[string]interface{})
|
|
||||||
// baseapi.SugarLogger.Debug(utils.Format4Output(data, false))
|
|
||||||
promotionInfo = &PromotionInfo{
|
|
||||||
BeginTime: utils.Timestamp2Time(utils.MustInterface2Int64(data["beginTime"].(map[string]interface{})["time"]) / 1000),
|
|
||||||
EndTime: utils.Timestamp2Time(utils.MustInterface2Int64(data["endTime"].(map[string]interface{})["time"]) / 1000),
|
|
||||||
PromotionInfoId: utils.MustInterface2Int64(data["promotionInfoId"]),
|
|
||||||
PromotionState: int(utils.MustInterface2Int64(data["promotionState"])),
|
|
||||||
PromotionType: int(utils.MustInterface2Int64(data["promotionType"])),
|
|
||||||
Source: utils.Interface2String(data["source"]),
|
|
||||||
}
|
|
||||||
skuResultList := data["skuResultList"].([]interface{})
|
|
||||||
promotionInfo.SkuResultList = make([]*PromotionSkuResult, len(skuResultList))
|
|
||||||
for k, v := range skuResultList {
|
|
||||||
skuResult := v.(map[string]interface{})
|
|
||||||
promotionInfo.SkuResultList[k] = &PromotionSkuResult{
|
|
||||||
LimitDaily: int(utils.MustInterface2Int64(skuResult["limitDaily"])),
|
|
||||||
LimitDevice: int(utils.MustInterface2Int64(skuResult["limitDevice"])),
|
|
||||||
LimitPin: int(utils.MustInterface2Int64(skuResult["limitPin"])),
|
|
||||||
PlatformRatio: int(utils.MustInterface2Int64(skuResult["platformRatio"])),
|
|
||||||
PromotionPrice: int(utils.MustInterface2Int64(skuResult["promotionPrice"])),
|
|
||||||
SkuId: utils.MustInterface2Int64(skuResult["skuId"]),
|
|
||||||
StationNo: utils.MustInterface2Int64(skuResult["stationNo"]),
|
|
||||||
StoreRatio: int(utils.MustInterface2Int64(skuResult["storeRatio"])),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return promotionInfo, nil
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *API) QueryPromotionInfo2(promotionInfoId int64) (promotionInfo *PromotionLspQueryInfoResult, err error) {
|
|
||||||
jdParams := map[string]interface{}{
|
jdParams := map[string]interface{}{
|
||||||
"promotionInfoId": promotionInfoId,
|
"promotionInfoId": promotionInfoId,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,16 @@ const (
|
|||||||
PromotionStateEnded = 9
|
PromotionStateEnded = 9
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type PromotionSku struct {
|
||||||
|
SkuID int64 `json:"skuId,omitempty"`
|
||||||
|
OutSkuID string `json:"outSkuId,omitempty"`
|
||||||
|
StationNo int64 `json:"stationNo,omitempty"`
|
||||||
|
OutStationNo string `json:"outStationNo,omitempty"`
|
||||||
|
PromotionPrice int64 `json:"promotionPrice"`
|
||||||
|
LimitSkuCount int `json:"limitSkuCount,omitempty"`
|
||||||
|
FailReason string `json:"failReason,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
func getPromotionCmd(inCmd string, promotionType int) (outCmd string) {
|
func getPromotionCmd(inCmd string, promotionType int) (outCmd string) {
|
||||||
if promotionType == PromotionTypeDirectDown {
|
if promotionType == PromotionTypeDirectDown {
|
||||||
outCmd = "singlePromote/" + inCmd
|
outCmd = "singlePromote/" + inCmd
|
||||||
@@ -49,7 +59,7 @@ func (a *API) CreatePromotionInfosSingle(name string, beginDate, endDate time.Ti
|
|||||||
// 单品直降添加活动商品信息接口
|
// 单品直降添加活动商品信息接口
|
||||||
// 最多200条
|
// 最多200条
|
||||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=178&apiid=0ad0715e0aaa42489cbeac36398e916d
|
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=178&apiid=0ad0715e0aaa42489cbeac36398e916d
|
||||||
func (a *API) CreatePromotionSkuSingle(infoId int64, outInfoId string, skus []map[string]interface{}) (skusResult []map[string]interface{}, err error) {
|
func (a *API) CreatePromotionSkuSingle(infoId int64, outInfoId string, skus []*PromotionSku) (skusResult []*PromotionSku, err error) {
|
||||||
return a.createPromotionSku(PromotionTypeDirectDown, infoId, outInfoId, skus)
|
return a.createPromotionSku(PromotionTypeDirectDown, infoId, outInfoId, skus)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +103,7 @@ func (a *API) CreatePromotionRules(infoId int64, outInfoId string, limitDevice,
|
|||||||
// 限时抢添加活动商品信息接口
|
// 限时抢添加活动商品信息接口
|
||||||
// 最多200条
|
// 最多200条
|
||||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=184&apiid=65fecef4883c40c6b23bbdb6123f5d80
|
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=184&apiid=65fecef4883c40c6b23bbdb6123f5d80
|
||||||
func (a *API) CreatePromotionSkuLimitTime(infoId int64, outInfoId string, skus []map[string]interface{}) (skusResult []map[string]interface{}, err error) {
|
func (a *API) CreatePromotionSkuLimitTime(infoId int64, outInfoId string, skus []*PromotionSku) (skusResult []*PromotionSku, err error) {
|
||||||
return a.createPromotionSku(PromotionTypeLimitedTime, infoId, outInfoId, skus)
|
return a.createPromotionSku(PromotionTypeLimitedTime, infoId, outInfoId, skus)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +140,7 @@ func (a *API) createPromotionInfos(promotionType int, name string, beginDate, en
|
|||||||
}
|
}
|
||||||
|
|
||||||
// todo skusResult 返回值没有意义,为了兼容暂时保留
|
// todo skusResult 返回值没有意义,为了兼容暂时保留
|
||||||
func (a *API) createPromotionSku(promotionType int, infoId int64, outInfoId string, skus []map[string]interface{}) (skusResult []map[string]interface{}, err error) {
|
func (a *API) createPromotionSku(promotionType int, infoId int64, outInfoId string, skus []*PromotionSku) (skusResult []*PromotionSku, err error) {
|
||||||
jdParams := map[string]interface{}{
|
jdParams := map[string]interface{}{
|
||||||
"skus": skus,
|
"skus": skus,
|
||||||
"timeStamp": utils.GetCurTimeStr(),
|
"timeStamp": utils.GetCurTimeStr(),
|
||||||
@@ -140,8 +150,11 @@ func (a *API) createPromotionSku(promotionType int, infoId int64, outInfoId stri
|
|||||||
} else {
|
} else {
|
||||||
jdParams[KeyOutInfoId] = outInfoId
|
jdParams[KeyOutInfoId] = outInfoId
|
||||||
}
|
}
|
||||||
_, err = a.AccessAPINoPage(getPromotionCmd("createPromotionSku", promotionType), jdParams, nil, nil, genNoPageResultParser("errorCode", "data", "", "0"))
|
result, err := a.AccessAPINoPage(getPromotionCmd("createPromotionSku", promotionType), jdParams, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "data", "0"))
|
||||||
return nil, err
|
if err == nil {
|
||||||
|
err = utils.Map2StructByJson(result, &skusResult, false)
|
||||||
|
}
|
||||||
|
return skusResult, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) confirmPromotion(promotionType int, infoId int64, outInfoId string) (err error) {
|
func (a *API) confirmPromotion(promotionType int, infoId int64, outInfoId string) (err error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user