- 重构京东活动API
This commit is contained in:
158
platformapi/jdapi/promotion_audit.go
Normal file
158
platformapi/jdapi/promotion_audit.go
Normal file
@@ -0,0 +1,158 @@
|
||||
package jdapi
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
AuditPromotionStateNew = 101 // 待开始
|
||||
AuditPromotionStateOnGoing = 102 // 进行中
|
||||
AuditPromotionStateEnded = 103 // 结束
|
||||
AuditPromotionStateCanceled = 104 // 取消
|
||||
AuditPromotionStateAll = 105 // 全部
|
||||
)
|
||||
|
||||
type OpenPlatActivityQResponse struct {
|
||||
AddLadderList []struct {
|
||||
BenefitMaxCount int `json:"benefitMaxCount"`
|
||||
DiscountAmount int `json:"discountAmount"`
|
||||
DiscountRate float32 `json:"discountRate"`
|
||||
LowMoney int `json:"lowMoney"`
|
||||
LowerLimitCount int `json:"lowerLimitCount"`
|
||||
OrderLadder string `json:"orderLadder"`
|
||||
} `json:"addLadderList"`
|
||||
Awords string `json:"awords"`
|
||||
BeginDate *utils.JavaDate `json:"beginDate"`
|
||||
CostRadios int `json:"costRadios"`
|
||||
EndDate *utils.JavaDate `json:"endDate"`
|
||||
ID int `json:"id"`
|
||||
IsMerchant int `json:"isMerchant"`
|
||||
OrderLadder string `json:"orderLadder"`
|
||||
OrgCode string `json:"orgCode"`
|
||||
OutActivityID string `json:"outActivityId"`
|
||||
PromotionName string `json:"promotionName"`
|
||||
SkuBeanList []struct {
|
||||
SkuID int64 `json:"skuId"`
|
||||
SkuName int64 `json:"skuName"`
|
||||
} `json:"skuBeanList"`
|
||||
State int `json:"state"`
|
||||
StationBeanList []struct {
|
||||
OrgCode interface{} `json:"orgCode"`
|
||||
OrgName string `json:"orgName"`
|
||||
OutStationNo string `json:"outStationNo"`
|
||||
StationName string `json:"stationName"`
|
||||
StationNo int `json:"stationNo"`
|
||||
} `json:"stationBeanList"`
|
||||
}
|
||||
|
||||
type PromotionSkuResult 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"`
|
||||
EndTime *utils.JavaDate `json:"endTime"`
|
||||
LimitDaily int `json:"limitDaily"`
|
||||
LimitDevice int `json:"limitDevice"`
|
||||
LimitPin int `json:"limitPin"`
|
||||
PlatformRatio int `json:"platformRatio"`
|
||||
PromotionPrice int `json:"promotionPrice"`
|
||||
PromotionState int `json:"promotionState"`
|
||||
PromotionType int `json:"promotionType"`
|
||||
SkuId int64 `json:"skuId"`
|
||||
Source string `json:"source"`
|
||||
StationNo int64 `json:"stationNo"`
|
||||
StoreRatio int `json:"storeRatio"`
|
||||
} `json:"skuResultList"`
|
||||
Source string `json:"source"`
|
||||
}
|
||||
|
||||
func (a *API) OrderDiscountQueryActivityInfoById(activityID int64, promotionType, state int, operator string) (response *OpenPlatActivityQResponse, err error) {
|
||||
params := map[string]interface{}{
|
||||
"activityId": activityID,
|
||||
"type": promotionType,
|
||||
"traceId": utils.GetUUID(),
|
||||
"operator": operator,
|
||||
"requestTime": time.Now().UnixNano() / 1000000,
|
||||
}
|
||||
if state > 0 {
|
||||
params["state"] = state
|
||||
}
|
||||
result, err := a.AccessAPINoPage("orderdiscount/queryActivityInfoById", params, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "data", "10000"))
|
||||
if err == nil {
|
||||
err = utils.Map2StructByJson(result, &response, false)
|
||||
}
|
||||
return response, err
|
||||
}
|
||||
|
||||
func (a *API) QueryPromotionInfo(promotionInfoId int64) (promotionInfo *PromotionInfo, 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{}{
|
||||
"promotionInfoId": promotionInfoId,
|
||||
}
|
||||
result, err := a.AccessAPINoPage("singlePromote/queryPromotionInfo", jdParams, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "data", "0"))
|
||||
if err == nil {
|
||||
err = utils.Map2StructByJson(result, &promotionInfo, false)
|
||||
}
|
||||
return promotionInfo, err
|
||||
}
|
||||
Reference in New Issue
Block a user