银豹api增加分类
This commit is contained in:
@@ -20,7 +20,7 @@ func init() {
|
||||
logger, _ := zap.NewDevelopment()
|
||||
sugarLogger = logger.Sugar()
|
||||
baseapi.Init(sugarLogger)
|
||||
api = New("7e9c1a5fe4ac4ea48c3c572d488e60b8hnwz", "0D397F05CF11C51BCDCC81744680EBC3", "f16a5e57ff4f4f428b702c40d2d4b933")
|
||||
api = New("bcb6201b5b3c45a0976dcda5e2dea8aejiwm", "0D397F05CF11C51BCDCC81744680EBC3", "f16a5e57ff4f4f428b702c40d2d4b933")
|
||||
}
|
||||
|
||||
func TestQuerySpSource(t *testing.T) {
|
||||
|
||||
184
platformapi/yinbaoapi/store_page.go
Normal file
184
platformapi/yinbaoapi/store_page.go
Normal file
@@ -0,0 +1,184 @@
|
||||
package yinbaoapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
pageUrl = "https://beta27.pospal.cn"
|
||||
|
||||
MainStoreVendorOrgCode = "3933189"
|
||||
)
|
||||
|
||||
func (a *API) AccessStorePage(action string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
|
||||
fullURL := utils.GenerateGetURL(pageUrl, action, nil)
|
||||
// result, _ := json.MarshalIndent(bizParams, "", " ")
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
request, _ := http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(bizParams).Encode()))
|
||||
request.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
|
||||
a.FillRequestCookies(request)
|
||||
return request
|
||||
},
|
||||
a.config,
|
||||
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
|
||||
if jsonResult1 == nil {
|
||||
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
||||
}
|
||||
if err == nil {
|
||||
if !jsonResult1["successed"].(bool) {
|
||||
errLevel = platformapi.ErrLevelGeneralFail
|
||||
err = utils.NewErrorCode(jsonResult1["msg"].(string), "-1", 0)
|
||||
baseapi.SugarLogger.Debugf("yinbao AccessStorePageAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
||||
}
|
||||
retVal = jsonResult1
|
||||
}
|
||||
return errLevel, err
|
||||
})
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
type LoadSubStoresByUserIdDDLJsonResult struct {
|
||||
Balance float64 `json:"balance"`
|
||||
Storewebsite interface{} `json:"storewebsite"`
|
||||
Version interface{} `json:"version"`
|
||||
IsParent int `json:"isParent"`
|
||||
SortNo int `json:"sortNo"`
|
||||
UserLocation interface{} `json:"userLocation"`
|
||||
StoreDomain interface{} `json:"storeDomain"`
|
||||
ParentAccount interface{} `json:"parentAccount"`
|
||||
ParentUserID interface{} `json:"parentUserId"`
|
||||
AreaID string `json:"areaId"`
|
||||
SubUsers interface{} `json:"subUsers"`
|
||||
CamerasSettings interface{} `json:"camerasSettings"`
|
||||
ImageRecognitionRemainingTimes string `json:"imageRecognitionRemainingTimes"`
|
||||
CrmVipNum interface{} `json:"crmVipNum"`
|
||||
ID int `json:"id"`
|
||||
Account string `json:"account"`
|
||||
Email interface{} `json:"email"`
|
||||
Address string `json:"address"`
|
||||
Tel string `json:"tel"`
|
||||
Company string `json:"company"`
|
||||
Industry string `json:"industry"`
|
||||
IP interface{} `json:"ip"`
|
||||
Vip interface{} `json:"vip"`
|
||||
CreatedDatetime interface{} `json:"createdDatetime"`
|
||||
Enable interface{} `json:"enable"`
|
||||
IsOldRev interface{} `json:"isOldRev"`
|
||||
EnterpriseID interface{} `json:"enterpriseId"`
|
||||
Source interface{} `json:"source"`
|
||||
AppID interface{} `json:"appId"`
|
||||
AppKey interface{} `json:"appKey"`
|
||||
UserType int `json:"userType"`
|
||||
IsFranchise int `json:"isFranchise"`
|
||||
SecondIndustry interface{} `json:"secondIndustry"`
|
||||
Number interface{} `json:"number"`
|
||||
TimeZoneID interface{} `json:"timeZoneId"`
|
||||
}
|
||||
|
||||
//获取所有门店的userID
|
||||
//https://beta27.pospal.cn/Account/LoadSubStoresByUserIdDDLJson
|
||||
func (a *API) LoadSubStoresByUserIdDDLJson() (results []*LoadSubStoresByUserIdDDLJsonResult, err error) {
|
||||
result, err := a.AccessStorePage("Account/LoadSubStoresByUserIdDDLJson", map[string]interface{}{
|
||||
"userId": MainStoreVendorOrgCode,
|
||||
"withSelf": false,
|
||||
})
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["stores"], &results, false)
|
||||
}
|
||||
return results, err
|
||||
}
|
||||
|
||||
//获得分类ID
|
||||
//https://beta27.pospal.cn/Category/CreateCategoryUid
|
||||
func (a *API) CreateCategoryUid() (categoryID string, err error) {
|
||||
result, err := a.AccessStorePage("Category/CreateCategoryUid", nil)
|
||||
if err == nil {
|
||||
categoryID = result["uid"].(string)
|
||||
}
|
||||
return categoryID, err
|
||||
}
|
||||
|
||||
//添加分类
|
||||
//经测试,parentCategoryName为空或者平台上不存在都是默认建成1级分类
|
||||
//https://beta27.pospal.cn/Category/AddNewCategory
|
||||
func (a *API) AddNewCategory(userId, categoryName, parentCategoryName string) (catID string, err error) {
|
||||
uid, err := a.CreateCategoryUid()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
_, err = a.AccessStorePage("Category/AddNewCategory", map[string]interface{}{
|
||||
"userId": userId,
|
||||
"uid": uid,
|
||||
"parentCategoryName": parentCategoryName,
|
||||
"categoryName": categoryName,
|
||||
"categoryType": 0,
|
||||
})
|
||||
return uid, err
|
||||
}
|
||||
|
||||
func IsErrCategoryExist(err error) (isExist bool) {
|
||||
return utils.IsErrMatch(err, "1", []string{"您输入的商品分类名称已存在"})
|
||||
}
|
||||
|
||||
//修改分类
|
||||
//经测试,如果parentCategoryName为空或在平台上不存在,则此分类会单独从之前的分类中移出重建成一级分类,0_0||
|
||||
//https://beta27.pospal.cn/Category/Update
|
||||
func (a *API) UpdateCategory(userId, categoryUid, newCategoryName, parentCategoryName string) (err error) {
|
||||
_, err = a.AccessStorePage("Category/Update", map[string]interface{}{
|
||||
"userId": userId,
|
||||
"categoryUid": categoryUid,
|
||||
"parentCategoryName": parentCategoryName,
|
||||
"newCategoryName": newCategoryName,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
//删除分类
|
||||
// https://beta27.pospal.cn/Category/Delete
|
||||
func (a *API) DeleteCategory(userId string, categoryUidsJson []string) (err error) {
|
||||
_, err = a.AccessStorePage("Category/Delete", map[string]interface{}{
|
||||
"userId": userId,
|
||||
"categoryUidsJson": categoryUidsJson,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
type LoadCategorysWithOptionResult struct {
|
||||
ID int `json:"id"`
|
||||
UserID int `json:"userId"`
|
||||
UID int64 `json:"uid"`
|
||||
ParentUID int `json:"parentUid"`
|
||||
Name string `json:"name"`
|
||||
Enable int `json:"enable"`
|
||||
CreatedDatetime string `json:"createdDatetime"`
|
||||
UpdatedDatetime string `json:"updatedDatetime"`
|
||||
CategoryType int `json:"categoryType"`
|
||||
Categoryoption struct {
|
||||
ID int `json:"id"`
|
||||
UserID int `json:"userId"`
|
||||
CategoryOrder int `json:"categoryOrder"`
|
||||
CategoryUID int64 `json:"categoryUid"`
|
||||
HideFromClient int `json:"hideFromClient"`
|
||||
} `json:"categoryoption"`
|
||||
TxtUID string `json:"txtUid"`
|
||||
TxtParentUID string `json:"txtParentUid"`
|
||||
}
|
||||
|
||||
//获取所有分类
|
||||
//https://beta27.pospal.cn/Category/LoadCategorysWithOption
|
||||
func (a *API) LoadCategorysWithOption(userId string) (loadCategorysWithOptionResult []*LoadCategorysWithOptionResult, err error) {
|
||||
result, err := a.AccessStorePage("Category/LoadCategorysWithOption", map[string]interface{}{
|
||||
"userId": userId,
|
||||
})
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["categorys"], &loadCategorysWithOptionResult, false)
|
||||
}
|
||||
return loadCategorysWithOptionResult, err
|
||||
}
|
||||
55
platformapi/yinbaoapi/store_page_test.go
Normal file
55
platformapi/yinbaoapi/store_page_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package yinbaoapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
func TestCreateCategoryUid(t *testing.T) {
|
||||
result, err := api.CreateCategoryUid()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestLoadSubStoresByUserIdDDLJson(t *testing.T) {
|
||||
result, err := api.LoadSubStoresByUserIdDDLJson()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestAddNewCategory(t *testing.T) {
|
||||
_, err := api.AddNewCategory(MainStoreVendorOrgCode, "测试2", "测试分类2")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestUpdateCategory(t *testing.T) {
|
||||
err := api.UpdateCategory(MainStoreVendorOrgCode, "1585030864115972859", "叶菜3", "蔬菜")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestDeleteCategory(t *testing.T) {
|
||||
err := api.DeleteCategory(MainStoreVendorOrgCode, []string{"1585030864115972859"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestLoadCategorysWithOption(t *testing.T) {
|
||||
result, err := api.LoadCategorysWithOption(MainStoreVendorOrgCode)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
@@ -29,6 +29,8 @@ const (
|
||||
)
|
||||
|
||||
type API struct {
|
||||
platformapi.APICookie
|
||||
|
||||
appKey string
|
||||
appID string
|
||||
client *http.Client
|
||||
|
||||
@@ -18,6 +18,7 @@ func init() {
|
||||
sugarLogger = logger.Sugar()
|
||||
baseapi.Init(sugarLogger)
|
||||
api = New("682628966212343269", "18C0E0867E467DBC26EFF5E957B02EC4") //总店
|
||||
api.SetCookie(".POSPALAUTH30220", "0102B128D1E568D0D708FEB190954771D0D708000833003900330033003100380039003A0000012F00FF27DD332FACE5011FCB641B9C049B0882ED228F18")
|
||||
}
|
||||
|
||||
func TestAddProductInfo(t *testing.T) {
|
||||
@@ -42,14 +43,14 @@ func TestAddProductInfo(t *testing.T) {
|
||||
|
||||
func TestUpdateProductInfo(t *testing.T) {
|
||||
var (
|
||||
sellPrice = float64(50)
|
||||
sellPrice = float64(-1)
|
||||
)
|
||||
err := api.UpdateProductInfo(&ProductInfoParam{
|
||||
ProductInfo: &ProductInfo{
|
||||
UID: 285305464077105187,
|
||||
Stock: &sellPrice,
|
||||
err := api.UpdateProductInfo(
|
||||
&ProductInfo{
|
||||
UID: 285305464077105187,
|
||||
SellPrice: &sellPrice,
|
||||
},
|
||||
})
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user