This commit is contained in:
邹宗楠
2023-09-22 15:09:35 +08:00
parent 76af28b1ba
commit 990ea93f60
3 changed files with 23 additions and 77 deletions

View File

@@ -20,13 +20,13 @@ func init() {
baseapi.Init(sugarLogger)
// 菜市
//api = New("589", "a81eb3df418d83d6a1a4b7c572156d2f", "", "")
api = New("589", "a81eb3df418d83d6a1a4b7c572156d2f", "", "")
// 果园
//api = New("4123", "df2c88338b85f830cebce2a9eab56628", "", "")
//商超
api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_nngsVP37s-HXY86xe85H7Q") //token_n4TwqCntWWuvQwAawzxC0w
//api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_nngsVP37s-HXY86xe85H7Q") //token_n4TwqCntWWuvQwAawzxC0w
//api = New("5873", "41c479790a76f86326f89e8048964739", "", "token_r36FEse6_ywebQI65FNNWA") //token_n4TwqCntWWuvQwAawzxC0w
cookieStr := `
acctId=57396785; token=0bWbK5VbK50E2BmIhIH2zHB-am_y7mB37yXHm6RLZWx4*; wmPoiId=-1;

View File

@@ -125,6 +125,7 @@ type AppFood struct {
Unit string `json:"unit"`
Utime int `json:"utime"`
ZhName string `json:"zh_name"`
CommonAttrValue string `json:"common_attr_value"`
}
type AppFoodResult struct {
@@ -243,18 +244,12 @@ func (a *API) RetailList(poiCode string, offset, limit int) (foodList []*AppFood
return foodList, err
}
func (a *API) RetailListAll(poiCode string) (foodList []*AppFood, err error) {
offset := 0
func (a *API) RetailListAll(poiCode string, offset int) (foodList []*AppFood, err error) {
data := make([]*AppFood, 0, 0)
for {
batchList, err2 := a.RetailList(poiCode, offset, GeneralMaxLimit)
if err = err2; err == nil {
data = append(data, batchList...)
}
if len(batchList) < GeneralMaxLimit {
break
}
offset += GeneralMaxLimit
offset = (offset - 1) * 200
batchList, err2 := a.RetailList(poiCode, offset, GeneralMaxLimit)
if err = err2; err == nil {
data = append(data, batchList...)
}
return data, err
}

View File

@@ -3,12 +3,10 @@ package mtwmapi
import (
"errors"
"fmt"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals"
"strings"
"testing"
"time"
"git.rosy.net.cn/baseapi/utils"
)
// 测试添加分类
@@ -107,31 +105,6 @@ func TestRetailList(t *testing.T) {
t.Log(len(result))
}
func TestRetailListAll(t *testing.T) {
result, err := api.RetailListAll("8967897")
if err != nil {
t.Fatal(err)
}
if len(result) == 0 {
t.Fatal("should have items")
}
t.Log(utils.Format4Output(result, false))
t.Log(len(result))
}
// 删除所有门店商品
func TestReloadStoreSku(t *testing.T) {
result, err := api.RetailListAll("17924337")
if err == nil {
for i := 0; i < len(result); i++ {
err := api.RetailDelete(utils.Int64ToStr(time.Now().Unix()), "17924337", result[i].AppFoodCode)
if err != nil {
fmt.Println(err)
}
}
}
}
func TestRetailGet(t *testing.T) {
result, err := api.RetailGet("18048546", "305011012")
if err != nil {
@@ -205,42 +178,20 @@ func TestErrList(t *testing.T) {
func TestRetailBatchInitData(t *testing.T) {
failedFoods, err := api.RetailBatchInitData(utils.GetUUID(), "19120530", []map[string]interface{}{
map[string]interface{}{
//"app_food_code": "",
//"category_code": "",
//"category_name": "粮油调味",
//"common_attr_value": "[{\"attr_id\":1200000088,\"attr_name\":\"品牌\",\"valueList\":[{\"value_id\":0,\"value\":\"其他\"}]},{\"attr_id\":1200000210,\"attr_name\":\"商品类别\",\"valueList\":[{\"value_id\":1300025227,\"value\":\"萝卜丝\"}]}]",
//"description": "",
//"is_sold_out": 0,
//"min_order_count": 1,
//"name": "吉香居 麻辣萝卜干泡菜 52g/袋",
//"picture": "http://p0.meituan.net/retailsp/f2aec3c090c7ee952f61301848f27c09917081.jpg,http://p0.meituan.net/retailsp/c93074d623f04272b28d7b03fd2b8699852829.jpg,http://p0.meituan.net/retailsp/8d2ef2c6f92b7c48f3673a67fe420fbe111196.jpg",
//"picture_contents": "",
//"price": 4.5,
//"sequence": -117,
//"skus": "[{\"available_times\":{\"friday\":\"\",\"monday\":\"\",\"saturday\":\"\",\"sunday\":\"\",\"thursday\":\"\",\"tuesday\":\"\",\"wednesday\":\"\"},\"box_num\":\"0\",\"box_price\":\"0.0\",\"isSellFlag\":1,\"ladder_box_num\":\"\",\"ladder_box_price\":\"\",\"limit_open_sync_stock_now\":false,\"location_code\":\"\",\"min_order_count\":\"1\",\"price\":\"4.5\",\"sku_id\":\"\",\"spec\":\"52g*1袋\",\"stock\":\"9999\",\"unit\":\"\",\"upc\":\"6926896703303\",\"weight\":\"52\",\"weight_unit\":\"克(g)\"}]",
//"tag_id": 200005035,
//"unit": "g",
"app_food_code": "",
"box_num": 0,
"box_price": 0,
"category_name": "粮油调味",
"description": "",
"is_sold_out": 0,
"min_order_count": 1,
"name": "干腐竹约150g/份",
"picture": "http://image.jxc4.com/5f7fba025fc9348796039423c48ac3f5.jpg",
"price": 1000,
"skus": []map[string]interface{}{
map[string]interface{}{
"price": 1000,
"sku_id": "23841",
"spec": "150g",
"stock": "*",
"upc": "",
},
},
// "tag_id": "200000380",
"unit": "份",
"app_food_code": 1692848899,
"category_name": "调味用品",
"common_attr_value": "[{\"attr_id\":1200000088,\"attr_name\":\"品牌\",\"valueList\":[{\"value_id\":0,\"value\":\"其他\"}]},{\"attr_id\":1200000210,\"attr_name\":\"商品类别\",\"valueList\":[{\"value_id\":1300019511,\"value\":\"寿司萝卜\"}]}]",
"description": "",
"is_sold_out": 0,
"min_order_count": 1,
"name": "吉香居 麻辣萝卜干泡菜 52g/袋",
"picture": "http://p0.meituan.net/retailsp/f2aec3c090c7ee952f61301848f27c09917081.jpg,http://p0.meituan.net/retailsp/c93074d623f04272b28d7b03fd2b8699852829.jpg,http://p0.meituan.net/retailsp/8d2ef2c6f92b7c48f3673a67fe420fbe111196.jpg",
"picture_contents": "",
"price": 4.5,
"sequence": -117,
"skus": "[{\n\t\t\t\"ladder_box_num\": \"\",\n\t\t\t\"ladder_box_price\": \"0.0\",\n\t\t\t\"price\": \"4.5\",\n\t\t\t\"sku_id\": 1692848899,\n\t\t\t\"spec\": \"52g*1袋\",\n\t\t\t\"stock\": \"9999\",\n\t\t\t\"upc\": \"6926896703303\",\n\t\t\t\"weight\": \"52\"\n\t\t}]",
"tag_id": 200005035,
"unit": "",
},
})
if err != nil {