diff --git a/platformapi/ebaiapi/shop_sku_test.go b/platformapi/ebaiapi/shop_sku_test.go index 28756fc3..6ae6c19b 100644 --- a/platformapi/ebaiapi/shop_sku_test.go +++ b/platformapi/ebaiapi/shop_sku_test.go @@ -72,7 +72,7 @@ func TestSkuCreate(t *testing.T) { "photos": []map[string]interface{}{ map[string]interface{}{ "is_master": true, - "url": "http://image.jx.scaqda.com/8536c76779333f53517006f88ea7174c.jpg?imageView2/1/w/80/h/80", + "url": "http://image.jxc4.com/8536c76779333f53517006f88ea7174c.jpg?imageView2/1/w/80/h/80", }, }, }) diff --git a/platformapi/jdapi/jdapi_test.go b/platformapi/jdapi/jdapi_test.go index 637041ff..dbcb2272 100644 --- a/platformapi/jdapi/jdapi_test.go +++ b/platformapi/jdapi/jdapi_test.go @@ -21,9 +21,9 @@ func init() { baseapi.Init(sugarLogger) // sandbox - //jdapi = New("c8854ef2-f80a-45ee-aceb-dc8014d646f8", "06692746f7224695ad4788ce340bc854", "d6b42a35a7414a5490d811654d745c84") + jdapi = New("c8854ef2-f80a-45ee-aceb-dc8014d646f8", "06692746f7224695ad4788ce340bc854", "d6b42a35a7414a5490d811654d745c84") // prod - jdapi = New("91633f2a-c5f5-4982-a925-a220d19095c3", "1dba76d40cac446ca500c0391a0b6c9d", "a88d031a1e7b462cb1579f12e97fe7f4") + // jdapi = New("91633f2a-c5f5-4982-a925-a220d19095c3", "1dba76d40cac446ca500c0391a0b6c9d", "a88d031a1e7b462cb1579f12e97fe7f4") } func TestTest(t *testing.T) { diff --git a/platformapi/jdapi/promotion.go b/platformapi/jdapi/promotion.go new file mode 100644 index 00000000..ecbd5f44 --- /dev/null +++ b/platformapi/jdapi/promotion.go @@ -0,0 +1,157 @@ +package jdapi + +import ( + "crypto/md5" + "fmt" + "time" + + "git.rosy.net.cn/baseapi/utils" +) + +const ( + KeyStationNo = "stationNo" + KeyOutStationNo = "outStationNo" + KeyPromotionPrice = "promotionPrice" + KeyLimitSkuCount = "limitSkuCount" + + KeyInfoId = "infoId" + KeyOutInfoId = "outInfoId" +) + +const ( + MaxPromotionSkuCount = 200 +) + +// 单品直降添加主活动信息接口 +// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=178&apiid=ee8685c9be9b4aa5bdc41468c5ebc33b +func (a *API) CreatePromotionInfosSingle(name string, beginDate, endDate time.Time, outInfoId, advertising string) (infoId int64, err error) { + return a.createPromotionInfos(PromotionTypeDirectDown, name, beginDate, endDate, outInfoId, advertising) +} + +// 单品直降添加活动商品信息接口 +// 最多200条 +// 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) { + return a.createPromotionSku(PromotionTypeDirectDown, infoId, outInfoId, skus) +} + +// 单品直降活动提交保存接口 +// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=178&apiid=b84e14eb341e470db8ed9b60f78edb16 +func (a *API) ConfirmPromotionSingle(infoId int64, outInfoId string) (err error) { + return a.confirmPromotion(PromotionTypeDirectDown, infoId, outInfoId) +} + +// 限时抢添加活动主信息接口 +// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=184&apiid=7d8b7ff86c9e457bb8a46963cb575769 +func (a *API) CreatePromotionInfosLimitTime(name string, beginDate, endDate time.Time, outInfoId, advertising string) (infoId int64, err error) { + return a.createPromotionInfos(PromotionTypeLimitedTime, name, beginDate, endDate, outInfoId, advertising) +} + +// 限时抢添加活动规则信息接口(直降也是调用此接口) +// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=184&apiid=e80674791d3542f0a87502753c0d0592 +func (a *API) CreatePromotionRules(infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int) (err error) { + jdParams := map[string]interface{}{ + "limitDevice": limitDevice, + "limitPin": limitPin, + "limitCount": limitCount, + "limitDaily": limitDaily, + "timeStamp": utils.GetCurTimeStr(), + } + if infoId != 0 { + jdParams[KeyInfoId] = infoId + } else { + jdParams[KeyOutInfoId] = outInfoId + } + _, err = a.AccessAPINoPage("limitTime/createPromotionRules", jdParams, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "data", "0")) + return err +} + +// 限时抢添加活动商品信息接口 +// 最多200条 +// 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) { + return a.createPromotionSku(PromotionTypeLimitedTime, infoId, outInfoId, skus) +} + +// 限时抢活动提交保存接口 +// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=184&apiid=3991063e2f0d435094e9fe44754f3490 +func (a *API) ConfirmPromotionLimitTime(infoId int64, outInfoId string) (err error) { + return a.confirmPromotion(PromotionTypeLimitedTime, infoId, outInfoId) +} + +func (a *API) createPromotionInfos(promotionType int, name string, beginDate, endDate time.Time, outInfoId, advertising string) (infoId int64, err error) { + if outInfoId == "" { + outInfoId = fmt.Sprintf("%X", md5.Sum([]byte(name))) + } + jdParams := map[string]interface{}{ + "promotionName": name, + "beginDate": utils.Time2Str(beginDate), + "endDate": utils.Time2Str(endDate), + "advertising": advertising, + "promotionType": promotionType, + "timeStamp": utils.GetCurTimeStr(), + KeyOutInfoId: outInfoId, + } + cmd := "" + if promotionType == PromotionTypeDirectDown { + cmd = "singlePromote/createPromotionInfos" + } else if promotionType == PromotionTypeLimitedTime { + cmd = "limitTime/createPromotionInfos" + } else { + panic("unknow promotionType!") + } + result, err := a.AccessAPINoPage(cmd, jdParams, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "data", "0")) + if err == nil { + return utils.MustInterface2Int64(result), nil + } + return 0, err +} + +func (a *API) createPromotionSku(promotionType int, infoId int64, outInfoId string, skus []map[string]interface{}) (skusResult []map[string]interface{}, err error) { + jdParams := map[string]interface{}{ + "skus": skus, + "timeStamp": utils.GetCurTimeStr(), + } + if infoId != 0 { + jdParams[KeyInfoId] = infoId + } else { + jdParams[KeyOutInfoId] = outInfoId + } + cmd := "" + if promotionType == PromotionTypeDirectDown { + cmd = "singlePromote/createPromotionSku" + } else if promotionType == PromotionTypeLimitedTime { + cmd = "limitTime/createPromotionSku" + } else { + panic("unknow promotionType!") + } + result, err := a.AccessAPINoPage(cmd, jdParams, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "data", "0")) + if err == nil { + if result != nil { + return utils.Slice2MapSlice(result.([]interface{})), nil + } + return nil, nil + } + return nil, err +} + +func (a *API) confirmPromotion(promotionType int, infoId int64, outInfoId string) (err error) { + jdParams := map[string]interface{}{ + "timeStamp": utils.GetCurTimeStr(), + } + if infoId != 0 { + jdParams[KeyInfoId] = infoId + } else { + jdParams[KeyOutInfoId] = outInfoId + } + cmd := "" + if promotionType == PromotionTypeDirectDown { + cmd = "singlePromote/confirmPromotion" + } else if promotionType == PromotionTypeLimitedTime { + cmd = "limitTime/confirmPromotion" + } else { + panic("unknow promotionType!") + } + _, err = a.AccessAPINoPage(cmd, jdParams, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "data", "0")) + return err +} diff --git a/platformapi/jdapi/promotion_test.go b/platformapi/jdapi/promotion_test.go new file mode 100644 index 00000000..c8a53a09 --- /dev/null +++ b/platformapi/jdapi/promotion_test.go @@ -0,0 +1,62 @@ +package jdapi + +import ( + "testing" + "time" +) + +func TestCreatePromotionSingle(t *testing.T) { + infoId, err := jdapi.CreatePromotionInfosSingle("测试1", time.Now(), time.Now().Add(24*time.Hour), "", "") + if err != nil { + t.Fatal(err) + } + t.Log(infoId) + err = jdapi.CreatePromotionRules(infoId, "", 1, 1, 1, 1) + if err != nil { + t.Fatal(err) + } + skuInfos, err := jdapi.CreatePromotionSkuSingle(infoId, "", []map[string]interface{}{ + { + KeyOutSkuId: "2216", + KeyStationNo: 11682042, + KeyPromotionPrice: 500, + KeyLimitSkuCount: 2, + }, + }) + if err != nil { + t.Fatal(err) + } + t.Log(skuInfos) + err = jdapi.ConfirmPromotionSingle(infoId, "") + if err != nil { + t.Fatal(err) + } +} + +func TestCreatePromotionLimitTime(t *testing.T) { + infoId, err := jdapi.CreatePromotionInfosLimitTime("测试1", time.Now(), time.Now().Add(24*time.Hour), "", "") + if err != nil { + t.Fatal(err) + } + t.Log(infoId) + err = jdapi.CreatePromotionRules(infoId, "", 1, 1, 5, 1) + if err != nil { + t.Fatal(err) + } + skuInfos, err := jdapi.CreatePromotionSkuLimitTime(infoId, "", []map[string]interface{}{ + { + KeyOutSkuId: "2216", + KeyStationNo: 11682042, + KeyPromotionPrice: 300, + KeyLimitSkuCount: 2, + }, + }) + if err != nil { + t.Fatal(err) + } + t.Log(skuInfos) + err = jdapi.ConfirmPromotionLimitTime(infoId, "") + if err != nil { + t.Fatal(err) + } +}