@@ -1,6 +1,7 @@
package ebaiapi
import (
"encoding/json"
"fmt"
"net/http"
"strings"
@@ -375,19 +376,114 @@ type StoreShowWindowSkuList struct {
SkuStatus int ` json:"sku_status" `
}
func ( a * API ) AccessStorePage2 ( subURL string , params map [ string ] interface { } , isPost bool , cookies map [ string ] string ) ( retVal map [ string ] interface { } , err error ) {
type ExianDaSkus struct {
Category string ` json:"category" `
CustomGoodsCode interface { } ` json:"customGoodsCode" `
CustomGoodsID int ` json:"customGoodsId" `
ElemeGoodsCode string ` json:"elemeGoodsCode" `
ElemeGoodsID string ` json:"elemeGoodsId" `
ElemeOwnerCode string ` json:"elemeOwnerCode" `
ElemeOwnerID int ` json:"elemeOwnerId" `
ExtValues struct {
} ` json:"extValues" `
GoodsID int ` json:"goodsId" `
GoodsName string ` json:"goodsName" `
ID int ` json:"id" `
ImageURL string ` json:"imageUrl" `
IsShelflife int ` json:"isShelflife" `
IsWeight int ` json:"isWeight" `
MeasurementUnitID int ` json:"measurementUnitId" `
MeasurementUnitText string ` json:"measurementUnitText" `
OperationType int ` json:"operationType" `
OperationTypeName string ` json:"operationTypeName" `
OwnerID string ` json:"ownerId" `
OwnerName string ` json:"ownerName" `
PurchaseUnitConversionRate string ` json:"purchaseUnitConversionRate" `
PurchaseUnitID int ` json:"purchaseUnitId" `
PurchaseUnitText string ` json:"purchaseUnitText" `
Status int ` json:"status" `
TaxRate string ` json:"taxRate" `
UpcID string ` json:"upcId" `
}
type ExianDaSku struct {
AdventLifeCycle interface { } ` json:"adventLifeCycle" `
CategoryIDFirst int ` json:"categoryIdFirst" `
CategoryIDSecond int ` json:"categoryIdSecond" `
CategoryIDThird int ` json:"categoryIdThird" `
CategoryText string ` json:"categoryText" `
CreatedBy string ` json:"createdBy" `
CustomGoodsCode interface { } ` json:"customGoodsCode" `
CustomGoodsID int ` json:"customGoodsId" `
ElemeGoodsCode string ` json:"elemeGoodsCode" `
ElemeGoodsID string ` json:"elemeGoodsId" `
ElemeOwnerCode string ` json:"elemeOwnerCode" `
ElemeOwnerID int ` json:"elemeOwnerId" `
ExtValues struct {
} ` json:"extValues" `
GoodsID int ` json:"goodsId" `
GoodsName string ` json:"goodsName" `
GoodsType int ` json:"goodsType" `
Height string ` json:"height" `
ImageCOs [ ] struct {
ExtValues struct {
} ` json:"extValues" `
Seq int ` json:"seq" `
URL string ` json:"url" `
} ` json:"imageCOs" `
IsDelete int ` json:"isDelete" `
IsEstimateLifeCycle int ` json:"isEstimateLifeCycle" `
IsShelflife int ` json:"isShelflife" `
IsWeight int ` json:"isWeight" `
Length string ` json:"length" `
LifeCycle int ` json:"lifeCycle" `
LockupLifeCycle interface { } ` json:"lockupLifeCycle" `
MeasurementUnitID int ` json:"measurementUnitId" `
MeasurementUnitText string ` json:"measurementUnitText" `
NetWeight string ` json:"netWeight" `
OperationType int ` json:"operationType" `
OwnerID string ` json:"ownerId" `
OwnerName string ` json:"ownerName" `
PurchaseUnitConversionRate string ` json:"purchaseUnitConversionRate" `
PurchaseUnitID int ` json:"purchaseUnitId" `
PurchaseUnitText string ` json:"purchaseUnitText" `
RejectLifeCycle interface { } ` json:"rejectLifeCycle" `
Status int ` json:"status" `
TaxRate string ` json:"taxRate" `
TemperatureType int ` json:"temperatureType" `
TenantID int ` json:"tenantId" `
UpcIds [ ] string ` json:"upcIds" `
UpdatedBy interface { } ` json:"updatedBy" `
Volume string ` json:"volume" `
Weight string ` json:"weight" `
Width string ` json:"width" `
}
func ( a * API ) AccessStorePage2 ( subURL , storeURL2 string , params map [ string ] interface { } , isPost bool , cookies map [ string ] string ) ( retVal map [ string ] interface { } , err error ) {
if a . GetCookieCount ( ) == 0 {
return nil , fmt . Errorf ( "需要设置Store Cookie才能使用此方法" )
}
err = platformapi . AccessPlatformAPIWithRetry ( a . client ,
func ( ) * http . Request {
var request * http . Request
if ! isPost {
request , _ = http . NewRequest ( http . MethodGet , utils . GenerateGetURL ( storeURL, subURL , params ) , nil )
var url string
if storeURL2 != "" {
url = storeURL2
} else {
request , _ = http . NewRequest ( http . MethodPost , utils . GenerateGetURL ( storeURL , subURL , nil ) , strings . NewReader ( utils . Map2URLValues ( params ) . Encode ( ) ) )
request . Header . Set ( "charset" , "UTF-8" )
request . Header . Set ( "Content-Type" , "application/x-www-form-urlencoded" )
url = storeURL
}
if ! isPost {
request , _ = http . NewRequest ( http . MethodGet , utils . GenerateGetURL ( url , subURL , params ) , nil )
} else {
if storeURL2 != "" {
result , _ := json . MarshalIndent ( params , "" , " " )
request , _ = http . NewRequest ( http . MethodPost , utils . GenerateGetURL ( url , subURL , nil ) , strings . NewReader ( string ( result ) ) )
request . Header . Set ( "Content-Type" , "application/ncp4+json" )
} else {
request , _ = http . NewRequest ( http . MethodPost , utils . GenerateGetURL ( url , subURL , nil ) , strings . NewReader ( utils . Map2URLValues ( params ) . Encode ( ) ) )
request . Header . Set ( "charset" , "UTF-8" )
request . Header . Set ( "Content-Type" , "application/x-www-form-urlencoded" )
}
}
a . FillRequestCookies ( request )
for k , v := range cookies {
@@ -404,15 +500,20 @@ func (a *API) AccessStorePage2(subURL string, params map[string]interface{}, isP
return platformapi . ErrLevelRecoverableErr , fmt . Errorf ( "mapData is nil" )
}
retVal = jsonResult1
if storeURL2 != "" {
return platformapi . ErrLevelSuccess , nil
}
if jsonResult1 [ "errno" ] == nil {
if jsonResult1 [ platformapi . KeyData ] == nil {
baseapi . SugarLogger . Warnf ( "ebai AccessStorePage2, jsonResult1:%s" , utils . Format4Output ( jsonResult1 , true ) )
} else {
return platformapi . ErrLevelRecoverableErr , fmt . Errorf ( "%s return not json" , subURL )
if storeURL2 == "" {
if jsonResult1 [ platformapi . KeyData ] == nil {
baseapi . SugarLogger . Warnf ( "ebai AccessStorePage2, jsonResult1:%s" , utils . Format4Output ( jsonResult1 , true ) )
} else {
return platformapi . ErrLevelRecoverableErr , fmt . Errorf ( "%s return not json" , subURL )
}
}
}
code := int ( utils . MustInterface2Int64 ( jsonResult1 [ "errno" ] ) )
if code == ResponseCodeSuccess {
if code == ResponseCodeSuccess || code == ResponseCodeSuccess2 {
if subURL == swithShopURL {
for _ , v := range response . Cookies ( ) {
if v . Name == "SWITCH_SHOP" {
@@ -435,8 +536,8 @@ func (a *API) AccessStorePage2(subURL string, params map[string]interface{}, isP
return retVal , err
}
func ( a * API ) AccessStorePage ( subURL string , params map [ string ] interface { } , isPost bool ) ( retVal map [ string ] interface { } , err error ) {
return a . AccessStorePage2 ( subURL , params , isPost , nil )
func ( a * API ) AccessStorePage ( subURL , storeURL2 string , params map [ string ] interface { } , isPost bool ) ( retVal map [ string ] interface { } , err error ) {
return a . AccessStorePage2 ( subURL , storeURL2 , params , isPost , nil )
}
func ( a * API ) GetRealMobile4Order ( orderId string ) ( mobile string , err error ) {
@@ -450,7 +551,7 @@ func (a *API) GetRealMobile4Order(orderId string) (mobile string, err error) {
}
func ( a * API ) GetStoreOrderInfo ( orderId string ) ( storeOrderInfo map [ string ] interface { } , err error ) {
retVal , err := a . AccessStorePage ( "crm/orderlist" , map [ string ] interface { } {
retVal , err := a . AccessStorePage ( "crm/orderlist" , "" , map [ string ] interface { } {
"keyword" : orderId ,
} , false )
if err == nil {
@@ -477,7 +578,7 @@ func (a *API) GetStoreOrderInfoList(fromTime, toTime string, shopID string, orde
}
for {
params [ "page" ] = pageNo
retVal , err2 := a . AccessStorePage ( "crm/orderlist" , params , false )
retVal , err2 := a . AccessStorePage ( "crm/orderlist" , "" , params , false )
if err = err2 ; err == nil {
resultList := retVal [ "order_list" ] . ( [ ] interface { } )
storeOrderList = append ( storeOrderList , utils . Slice2MapSlice ( resultList ) ... )
@@ -521,7 +622,7 @@ func (a *API) getCommentList(isElm bool, fromTime, toTime time.Time, shopID, sup
} [ 1 - utils . Bool2Int ( isElm ) ] )
for {
params [ "page_num" ] = pageNo
retVal , err2 := a . AccessStorePage ( fixedURL , params , false )
retVal , err2 := a . AccessStorePage ( fixedURL , "" , params , false )
if err = err2 ; err == nil {
for _ , comment := range retVal [ "comment_list" ] . ( [ ] interface { } ) {
commentMap := comment . ( map [ string ] interface { } )
@@ -562,7 +663,7 @@ func (a *API) PageGetSkuList(baiduShopID int64) (skuList []map[string]interface{
}
for {
params [ "curpage" ] = pageNo
retVal , err2 := a . AccessStorePage ( "commodity/getskulist" , params , false )
retVal , err2 := a . AccessStorePage ( "commodity/getskulist" , "" , params , false )
if err = err2 ; err == nil {
for _ , sku := range retVal [ "sku_list" ] . ( [ ] interface { } ) {
skuList = append ( skuList , sku . ( map [ string ] interface { } ) )
@@ -583,7 +684,7 @@ func (a *API) PageGetCustomSkuList(baiduShopID int64, customCatID int64) (skuLis
"wid" : baiduShopID ,
"custom_cat_id" : customCatID ,
}
retVal , err := a . AccessStorePage ( "commodity/getCustomSkuList" , params , false )
retVal , err := a . AccessStorePage ( "commodity/getCustomSkuList" , "" , params , false )
if err == nil {
return utils . Slice2MapSlice ( retVal [ "sku_list" ] . ( [ ] interface { } ) ) , nil
}
@@ -594,7 +695,7 @@ func (a *API) PageGetCustomCatList(baiduShopID int64) (catList []map[string]inte
params := map [ string ] interface { } {
"wid" : baiduShopID ,
}
retVal , err := a . AccessStorePage ( "commodity/GetCustomCatList" , params , false )
retVal , err := a . AccessStorePage ( "commodity/GetCustomCatList" , "" , params , false )
if err == nil {
return utils . Slice2MapSlice ( retVal [ "cat_list" ] . ( [ ] interface { } ) ) , nil
}
@@ -701,7 +802,7 @@ func (a *API) AccessStorePageNoCookie(subURL string, params map[string]interface
}
func ( a * API ) SwitchShop ( baiduShopID int64 ) ( switchShopCookie string , err error ) {
result , err := a . AccessStorePage ( "crm/manager/switchshop" , map [ string ] interface { } {
result , err := a . AccessStorePage ( "crm/manager/switchshop" , "" , map [ string ] interface { } {
"switch_shop_id" : baiduShopID ,
} , true )
if err == nil {
@@ -711,7 +812,7 @@ func (a *API) SwitchShop(baiduShopID int64) (switchShopCookie string, err error)
}
func ( a * API ) GetShopUserInfo2 ( switchShopCookie string ) ( shopUserInfo * PageShopUserInfo , err error ) {
shopInfo , err := a . AccessStorePage2 ( "crm/account/getshopuserinfo" , nil , true , map [ string ] string {
shopInfo , err := a . AccessStorePage2 ( "crm/account/getshopuserinfo" , "" , nil , true , map [ string ] string {
"SWITCH_SHOP" : switchShopCookie ,
} )
if err == nil {
@@ -733,7 +834,7 @@ func (a *API) GetShopHealthByDetail2(switchShopCookie string) (shopHealthDetail
if err != nil {
return nil , err
}
result , err := a . AccessStorePage2 ( "crm/getshophealthydetail" , map [ string ] interface { } {
result , err := a . AccessStorePage2 ( "crm/getshophealthydetail" , "" , map [ string ] interface { } {
"shop_id" : shopInfo . EleID ,
} , true , map [ string ] string {
"SWITCH_SHOP" : switchShopCookie ,
@@ -764,7 +865,7 @@ func (a *API) GetShopListByPage(status, proxyBusinessState, pageCount, pageNum i
"pageCount" : pageCount ,
"pageNum" : pageNum ,
}
retVal , err := a . AccessStorePage ( "crm/suppliershopstatus" , params , false )
retVal , err := a . AccessStorePage ( "crm/suppliershopstatus" , "" , params , false )
if err == nil {
utils . Map2StructByJson ( retVal [ "shop_list" ] , & shopList , true )
totalCount = int ( utils . MustInterface2Int64 ( retVal [ "total" ] ) )
@@ -782,7 +883,7 @@ func (a *API) ModifyTip4OrderWaybill(orderID, elemeOrderID string, tip, zhongBao
"tip" : tip ,
"zhongbao_ask_price" : zhongBaoAskPrice ,
}
_ , err = a . AccessStorePage ( "crm/modifytip" , params , false )
_ , err = a . AccessStorePage ( "crm/modifytip" , "" , params , false )
return err
}
@@ -791,7 +892,7 @@ func (a *API) GetStoresShowWindowSkus(baiduShopID int64) (storeShowWindowList []
params := map [ string ] interface { } {
"wid" : baiduShopID ,
}
result , err := a . AccessStorePage ( "crm/shop/getcurrshopwindow" , params , true )
result , err := a . AccessStorePage ( "crm/shop/getcurrshopwindow" , "" , params , true )
if err == nil {
err2 := utils . Map2StructByJson ( result [ "sku_list" ] , & storeShowWindowList , false )
if err2 != nil {
@@ -800,3 +901,54 @@ func (a *API) GetStoresShowWindowSkus(baiduShopID int64) (storeShowWindowList []
}
return storeShowWindowList , err
}
//获取饿鲜达商品库
func ( a * API ) GetExianDaSkuDepot ( ) ( results [ ] * ExianDaSkus , err error ) {
var (
pageNum = 1
pageSize = 200
)
params := map [ string ] interface { } {
"metas" : map [ string ] interface { } { } ,
"params" : map [ string ] interface { } {
"goodsListQry" : map [ string ] interface { } {
"pageNum" : pageNum ,
"pageSize" : pageSize ,
} ,
} ,
}
for {
result , err := a . AccessStorePage ( "bwm_newretail.scm_ic/GoodsServiceI/findGoodsList" , "https://ncp.ele.me" , params , true )
if err != nil {
continue
}
if len ( result ) < pageSize {
break
}
if len ( result ) > 0 {
var exianDaSkus [ ] * ExianDaSkus
utils . Map2StructByJson ( result [ "data" ] , & exianDaSkus , false )
results = append ( results , exianDaSkus ... )
}
pageNum ++
}
return results , err
}
//获取饿鲜达单个商品( 主要取分类id)
func ( a * API ) GetExianDaSku ( exdSkuID int64 ) ( results * ExianDaSku , err error ) {
params := map [ string ] interface { } {
"metas" : map [ string ] interface { } { } ,
"params" : map [ string ] interface { } {
"goodsGetQry" : map [ string ] interface { } {
"elemeGoodsId" : exdSkuID ,
} ,
} ,
}
result , err := a . AccessStorePage ( "bwm_newretail.scm_ic/GoodsServiceI/findGoodsById" , "https://ncp.ele.me" , params , true )
if err != nil {
return results , err
}
utils . Map2StructByJson ( result [ "data" ] , & results , false )
return results , err
}