This commit is contained in:
苏尹岚
2021-02-04 15:49:13 +08:00
parent dbeeab48ab
commit 48f4a7179c
6 changed files with 326 additions and 28 deletions

View File

@@ -12,8 +12,37 @@ type CityInfo struct {
Level int `json:"level"`
}
type CatInfo struct {
ID int `json:"category_id"`
Name string `json:"category_name"`
}
func (a *API) CommonShopCities(parentID int) (cityList []*CityInfo, err error) {
result, err := a.AccessAPI("common.shopcities", utils.Params2Map("pid", parentID))
result, err := a.AccessAPI("common.shopcities", utils.Params2Map("pid", parentID, "level", 2))
if err == nil {
err = utils.Map2StructByJson(result.Data, &cityList, true)
}
return cityList, err
}
func (a *API) CommonShopCategoriesGet() (cityList []*CatInfo, err error) {
result, err := a.AccessAPI("common.shop.category.get", nil)
if err == nil {
err = utils.Map2StructByJson(result.Data, &cityList, true)
}
return cityList, err
}
func (a *API) CommonShopCategories(parentID, level int) (cityList []*CatInfo, err error) {
result, err := a.AccessAPI("common.shopcategories", utils.Params2Map("category_id", parentID, "level", level))
if err == nil {
err = utils.Map2StructByJson(result.Data, &cityList, true)
}
return cityList, err
}
func (a *API) CommonBusinessCategories(parentID int) (cityList []*CatInfo, err error) {
result, err := a.AccessAPI("common.businesscategories", utils.Params2Map("category_id", parentID))
if err == nil {
err = utils.Map2StructByJson(result.Data, &cityList, true)
}

View File

@@ -7,7 +7,34 @@ import (
)
func TestCommonShopCities(t *testing.T) {
result, err := api.CommonShopCities(0)
result, err := api.CommonShopCities(75)
if err != nil {
t.Fatal(err)
} else {
t.Log(utils.Format4Output(result, false))
}
}
func TestCommonShopCategoriesGet(t *testing.T) {
result, err := api.CommonShopCategoriesGet()
if err != nil {
t.Fatal(err)
} else {
t.Log(utils.Format4Output(result, false))
}
}
func TestCommonShopCategories(t *testing.T) {
result, err := api.CommonShopCategories(166, 2)
if err != nil {
t.Fatal(err)
} else {
t.Log(utils.Format4Output(result, false))
}
}
func TestCommonBusinessCategories(t *testing.T) {
result, err := api.CommonBusinessCategories(166)
if err != nil {
t.Fatal(err)
} else {

View File

@@ -31,6 +31,9 @@ func init() {
// 京西菜市
// api = New("34665", "c3db75b754ea2d89")
//菜市测试
// api = New("62923", "aa4cdc6c1108486b")
// 京西果园
api = New("35957", "10013fbb7c2ddad7")
api.SetCookie("PASSPORT_DELIMONT_TOKEN", "PBE_2.0_5cd1c6141c127d4188f026ac01fc93656266683e8dfb3127c2fdf894259e9034125ff3bdd2a997a385802ee3ef1802ba93a04acea34fde2d2b6e802c5dcd4ec6e3f4ad909a1d806e3ceeb349ed726b03d60ed1fe7010d4140aa338d9c5f05e3fec172c78d3d7f0ca579d61b7015af1bf99aa46b04d2b8a64aa50646dc09afe94b6b60e0ba9a933635db5e8b2a035e9b6d693b289acf1b256d5b9a3f8478c87b0b009115bfd1394f20bb5a0dc2c07b8d013a25f286ec6bf7f2d86010d65507e31358834b7a6b58fbd88cb3f1a12cf71c997b91c1527f6f3c10693f7c2bd6073da8633a98cd2dc1114dfa5be5ee0e60b02cf7e4a94d0fb563a8c01717e7c050f02249117219c07a2eb211577c208ba77f4d536fa25139bc249be93b38d6fc495ef67a32aa206835d177db402bc534de1d29caf4f6b4fbcd912c13f167d00d1732222744c336a5189728f72fb5e153c4b1164171cfb0c811f34f4c2fedd43f721b8706b43f8d631251c")

View File

@@ -1,6 +1,8 @@
package ebaiapi
import (
"fmt"
"git.rosy.net.cn/baseapi/utils"
)
@@ -185,7 +187,11 @@ func (a *API) ShopList( /*orderPush, orderStatusPush, status, */ sysStatus int)
func (a *API) ShopCreate(params map[string]interface{}) (baiduShopID int64, err error) {
result, err := a.AccessAPI("shop.create", params)
if err == nil {
return utils.MustInterface2Int64(result.Data.(map[string]interface{})[KeyBaiduShopID]), nil
if result.Data != nil {
return utils.MustInterface2Int64(result.Data.(map[string]interface{})[KeyBaiduShopID]), nil
} else {
return 0, fmt.Errorf(result.Error)
}
}
return 0, err
}
@@ -296,3 +302,12 @@ func (a *API) ShopAnnouncementSet(shopID string, baiduShopID int64, content stri
}
return err
}
func (a *API) ShopAptitudeUpload(shopID string, baiduShopID int64, params map[string]interface{}) (err error) {
params2 := a.genShopIDParams(shopID, baiduShopID, 0)
_, err = a.AccessAPI("shop.aptitude.upload", utils.MergeMaps(params, params2))
if err == nil {
return nil
}
return err
}

View File

@@ -17,17 +17,33 @@ func TestShopList(t *testing.T) {
func TestShopCreate(t *testing.T) {
result, err := api.ShopCreate(map[string]interface{}{
"shop_id": "123123123",
"business_form_id": "179",
"service_phone": "1111111",
"invoice_support": "2",
"package_box_price": "0",
"encrypt": "",
"category1": "",
"category2": "",
"category3": "",
"name": "测试",
"supplier_id": "2233065879",
"shop_id": "667550",
"name": "互利超市(金牛店)",
"supplier_id": "1486975681715",
"province": 32,
"city": 75,
"county": 698,
"address": "成都市金牛区二环路北一段8号",
"phone": 18980429231,
"service_phone": 18980429231,
"ivr_phone": 18048531223,
"longitude": 104.043677,
"latitude": 30.692361,
"shop_logo": "http://image.jxc4.com/image/4573e7789c647d4961f8955e3733dbd6.tem.jpg",
"coord_type": "amap",
"categorys": []map[string]int{
map[string]int{
"category1": 166,
"category2": 222,
},
},
"business_time": []map[string]string{
map[string]string{
"start": "7:00",
"end": "19:00",
},
},
"business_form_id": 1672214913,
})
if err != nil {
t.Fatal(err)
@@ -37,7 +53,7 @@ func TestShopCreate(t *testing.T) {
}
func TestShopGet(t *testing.T) {
result, err := api.ShopGet("", 32267697558) //2233065879
result, err := api.ShopGet("", 335768207) //2233065879
if err != nil {
t.Fatal(err)
} else {
@@ -53,7 +69,7 @@ func TestShopGet(t *testing.T) {
}
func TestShopAptitudeGet(t *testing.T) {
result, err := api.ShopAptitudeGet("", testShopBaiduID)
result, err := api.ShopAptitudeGet("", 335768207)
if err != nil {
t.Fatal(err)
} else {
@@ -83,7 +99,7 @@ func TestShopUpdate(t *testing.T) {
}
func TestShopBusStatusGet(t *testing.T) {
result, err := api.ShopBusStatusGet("", testShopBaiduID, PlatformFlagElm)
result, err := api.ShopBusStatusGet("", 335768207, PlatformFlagElm)
if err != nil {
t.Fatal(err)
} else {
@@ -92,7 +108,7 @@ func TestShopBusStatusGet(t *testing.T) {
}
func TestShopStatusGet(t *testing.T) {
result, err := api.ShopStatusGet("", testShopBaiduID)
result, err := api.ShopStatusGet("", 335768207)
if err != nil {
t.Fatal(err)
} else {
@@ -121,7 +137,7 @@ func TestSupplierList(t *testing.T) {
}
func TestShopOpen(t *testing.T) {
err := api.ShopOpen("", testShopBaiduID)
err := api.ShopOpen("", 335768207)
if err != nil {
t.Fatal(err)
}
@@ -147,3 +163,81 @@ func TestShopAnnouncementSet(t *testing.T) {
t.Fatal(err)
}
}
func TestShopAptitudeUpload(t *testing.T) {
err := api.ShopAptitudeUpload("", 335768207, map[string]interface{}{
"aptitude": []map[string]interface{}{
map[string]interface{}{
"type_1": 1,
"type_2": 101,
"license_number": "92510106L597085088",
"license_address": "金牛区二环路北一段8号1A-2、A-3、A-4楼",
"long_term_valid": 1,
"legal_representative_name": "张应友",
"license_name": "营业执照",
"photos": []map[string]interface{}{
map[string]interface{}{
"photo_url": "http://image.jxc4.com/image/c436338a2af4d87e30b770cfc1bb8041.jpg",
"waterprinter_url": "http://image.jxc4.com/image/c436338a2af4d87e30b770cfc1bb8041.jpg",
},
},
},
map[string]interface{}{
"type_1": 2,
"type_2": 202,
"license_number": "JY151010601049471-1",
"license_validdate": "2023-10-09",
"license_name": "食品经营许可证",
"license_address": "金牛区二环路北一段8号1A-2、A-3、A-4楼",
"legal_representative_name": "张应友",
"photos": []map[string]interface{}{
map[string]interface{}{
"photo_url": "http://image.jxc4.com/image/93d2126adfd28350385b5067e2770edf.jpg",
"waterprinter_url": "http://image.jxc4.com/image/93d2126adfd28350385b5067e2770edf.jpg",
},
},
},
map[string]interface{}{
"type_1": 3,
"type_2": 301,
"license_number": "510921196608255211",
"long_term_valid": 1,
"license_name": "身份证",
"legal_representative_name": "张应友",
"photos": []map[string]interface{}{
map[string]interface{}{
"photo_url": "http://image.jxc4.com/image/ebdaf32e771a6c050e397624c3fae369.jpg",
"waterprinter_url": "http://image.jxc4.com/image/ebdaf32e771a6c050e397624c3fae369.jpg",
},
map[string]interface{}{
"photo_url": "http://image.jxc4.com/image/75fad719d61326cedd73f17b1af6338b.jpg",
"waterprinter_url": "http://image.jxc4.com/image/75fad719d61326cedd73f17b1af6338b.jpg",
},
},
},
map[string]interface{}{
"type_1": 5,
"type_2": 501,
"photos": []map[string]interface{}{
map[string]interface{}{
"photo_url": "http://image.jxc4.com/image/53bd1275a8a9cd5898912fa78857f284.jpg",
"waterprinter_url": "http://image.jxc4.com/image/53bd1275a8a9cd5898912fa78857f284.jpg",
},
},
},
map[string]interface{}{
"type_1": 5,
"type_2": 502,
"photos": []map[string]interface{}{
map[string]interface{}{
"photo_url": "http://image.jxc4.com/image/74c371be5bf39d795cf6c02507e7ca84.jpg",
"waterprinter_url": "http://image.jxc4.com/image/74c371be5bf39d795cf6c02507e7ca84.jpg",
},
},
},
},
})
if err != nil {
t.Fatal(err)
}
}