From eb906260d82d2d07f7945767695b42a37175c593 Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 29 Jul 2019 15:27:56 +0800 Subject: [PATCH 01/71] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8DAfsSubmit=E4=B8=8EO?= =?UTF-8?q?rderAddTips=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/jdapi_test.go | 2 +- platformapi/jdapi/order.go | 9 +++++---- platformapi/jdapi/order_test.go | 10 +++++++++- platformapi/mtpsapi/mtpsapi_test.go | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/platformapi/jdapi/jdapi_test.go b/platformapi/jdapi/jdapi_test.go index b6bd0372..40b459f9 100644 --- a/platformapi/jdapi/jdapi_test.go +++ b/platformapi/jdapi/jdapi_test.go @@ -23,7 +23,7 @@ func init() { // sandbox api = New("df97f334-f7d8-4b36-9664-5784d8ae0baf", "06692746f7224695ad4788ce340bc854", "d6b42a35a7414a5490d811654d745c84") // prod - // api = New("ccb10daf-e6f5-4a58-ada5-b97f9073a137", "1dba76d40cac446ca500c0391a0b6c9d", "a88d031a1e7b462cb1579f12e97fe7f4") + // api = New("77e703b7-7997-441b-a12a-2e522efb117a", "1dba76d40cac446ca500c0391a0b6c9d", "a88d031a1e7b462cb1579f12e97fe7f4") // 天天果园 // api = New("84541069-fbe2-424b-b625-9b2ba1d4c9e6", "5d5577a2506f41b8b4ec520ba83490f5", "0b01b9eeb15b41dab1c3d05d95c17a26") diff --git a/platformapi/jdapi/order.go b/platformapi/jdapi/order.go index ee15e905..d329a41b 100644 --- a/platformapi/jdapi/order.go +++ b/platformapi/jdapi/order.go @@ -588,6 +588,7 @@ func (a *API) AfsSubmit(OrderID, pin, questionTypeCode, questionDesc, questionPi "orderId": OrderID, "pin": utils.GetAPIOperator(pin), "questionTypeCode": questionTypeCode, + "skuList": skuList, } if questionDesc != "" { jdParams["questionDesc"] = questionDesc @@ -625,11 +626,11 @@ func ProcessQuestionPic(questionPic string) (outQuestionPic string) { // 订单商家加小费接口 // https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=169&apiid=ed9e3ca7325c4d4d8ceaf959ed0e7a62 -func (a *API) OrderAddTips(OrderID string, tips int, pin string) (err error) { +func (a *API) OrderAddTips(orderID string, tips int, operator string) (err error) { jdParams := map[string]interface{}{ - "orderId": OrderID, - "tips": tips, - "pin": utils.GetAPIOperator(pin), + "orderId": orderID, + "tips": tips, + "operator": utils.GetAPIOperator(operator), } _, err = a.AccessAPINoPage("order/addTips", jdParams, nil, nil, nullResultParser) return err diff --git a/platformapi/jdapi/order_test.go b/platformapi/jdapi/order_test.go index 18e65ff6..b64008ab 100644 --- a/platformapi/jdapi/order_test.go +++ b/platformapi/jdapi/order_test.go @@ -10,7 +10,8 @@ import ( ) func TestQuerySingleOrder(t *testing.T) { - retVal, err := api.QuerySingleOrder("815536199000222") + retVal, err := api.QuerySingleOrder("918092290000042") + t.Log(utils.Format4Output(retVal, false)) if err != nil { t.Error(err) } @@ -218,3 +219,10 @@ func TestOrderShoudSettlementService2(t *testing.T) { } sugarLogger.Debug(utils.Format4Output(result, false)) } + +func TestOrderAddTips(t *testing.T) { + err := api.OrderAddTips("918092290000042", 50, "xjh") + if err != nil { + t.Fatal(err.Error()) + } +} diff --git a/platformapi/mtpsapi/mtpsapi_test.go b/platformapi/mtpsapi/mtpsapi_test.go index d053345c..ee9fbde6 100644 --- a/platformapi/mtpsapi/mtpsapi_test.go +++ b/platformapi/mtpsapi/mtpsapi_test.go @@ -25,7 +25,7 @@ func init() { // prod // api = New("3c0a05d464c247c19d7ec13accc78605", "b1M}9?:sTbsB[OF2gNORnN(|(iy9rB8(`7]|[wGLnbmt`evfM>E:A90DjHAW:UPE") - api.SetCookie("token", "0seqGSJnhbr4XJ0EaIQL6CoOpnaV1ErgS42uOlzNXYIX7PeuLuyCFQQZKKWGExJ7IMTQQQDe5H6YMmVFnxjCkw") + api.SetCookie("token", "jWQx6ao1-BFeuFg1iOHX207ocrPXlJPY-f41EaF1769C13Gw-irr5QnfQzmZOvOqt99cdN4XdQW0n8wvy-Hl_A") } func handleError(t *testing.T, err error) { From 00cb0a7b33c45dbec00cb9d08cdd4864e4585719 Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 29 Jul 2019 17:16:42 +0800 Subject: [PATCH 02/71] + jdapi.CarrierNoCrowdSourcing, CarrierNoSelfDelivery --- platformapi/jdapi/store.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platformapi/jdapi/store.go b/platformapi/jdapi/store.go index 71cb7629..7cf8798b 100644 --- a/platformapi/jdapi/store.go +++ b/platformapi/jdapi/store.go @@ -44,6 +44,11 @@ type CityInfo struct { Yn int `json:"yn"` } +const ( + CarrierNoCrowdSourcing = 9966 // 众包 + CarrierNoSelfDelivery = 2938 // 自送 +) + func (a *API) GetAllCities() (cities []*CityInfo, err error) { result, err := a.AccessAPINoPage("address/allcities", nil, nil, nil, genNoPageResultParser("code", "msg", "result", "0")) if err == nil { From 4f31e53b23450a7af383a94b0e572a9f57cad503 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 30 Jul 2019 09:46:53 +0800 Subject: [PATCH 03/71] - comment on jdapi.OrderAddTips --- platformapi/jdapi/order.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/platformapi/jdapi/order.go b/platformapi/jdapi/order.go index d329a41b..12fe9fef 100644 --- a/platformapi/jdapi/order.go +++ b/platformapi/jdapi/order.go @@ -625,6 +625,8 @@ func ProcessQuestionPic(questionPic string) (outQuestionPic string) { } // 订单商家加小费接口 +// tips必须是100的倍数,另外必须要等到家下发运单后才能调用,否则会报“订单号srcOrderNo的订单不存在”错 +// 这个tips是累计增的,比如第一次调用tips为100,再一次调用tips为200,则总共的tips就是300 // https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=169&apiid=ed9e3ca7325c4d4d8ceaf959ed0e7a62 func (a *API) OrderAddTips(orderID string, tips int, operator string) (err error) { jdParams := map[string]interface{}{ From 2e3dc64609d304444904d2b7b818a8fabc0525e7 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 30 Jul 2019 14:39:27 +0800 Subject: [PATCH 04/71] =?UTF-8?q?-=20=E6=94=B9jdapi.OrderQuery2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=8F=82=E6=95=B0=E7=B1=BB=E5=9E=8B=20+=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9Ejdapi.QuerySingleOrder2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/order.go | 43 +++++++++++++++++++++++++++------ platformapi/jdapi/order_test.go | 10 ++++++++ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/platformapi/jdapi/order.go b/platformapi/jdapi/order.go index 12fe9fef..f1b82e83 100644 --- a/platformapi/jdapi/order.go +++ b/platformapi/jdapi/order.go @@ -310,6 +310,19 @@ type OrderInfo struct { Yn bool `json:"yn"` } +type OrderQueryParam struct { + PageNo int64 `json:"pageNo,omitempty"` // 当前页数,默认:1 + PageSize int `json:"pageSize,omitempty"` // 每页条数,默认:20,最大值100 + OrderID int64 `json:"orderId,omitempty"` + + OrderPurchaseTimeBegin string `json:"orderPurchaseTime_begin,omitempty"` // 购买成交时间-支付(开始) + OrderPurchaseTimeEnd string `json:"orderPurchaseTime_end,omitempty"` // 购买成交时间-支付(结束) + OrderStatus int `json:"orderStatus,omitempty"` + + DeliveryStationNo string `json:"deliveryStationNo,omitempty"` // 到家门店编码 + DeliveryStationNoIsv string `json:"deliveryStationNoIsv,omitempty"` // 商家门店编码 +} + var ( ErrCanNotFindOrder = errors.New("can not find order") ) @@ -336,14 +349,6 @@ func (a *API) OrderQuery(jdParams map[string]interface{}) (retVal []interface{}, return retVal, totalCount, err } -func (a *API) OrderQuery2(jdParams map[string]interface{}) (retVal []*OrderInfo, totalCount int, err error) { - orderList, totalCount, err := a.OrderQuery(jdParams) - if err == nil { - err = utils.Map2StructByJson(orderList, &retVal, true) - } - return retVal, totalCount, err -} - // orderFreightMoney 基础运费 // tips 商家承担小费 // merchantPaymentDistanceFreightMoney 取件服务费(开票)(正向单展示远距离运费;售后单则展示达达售后运费) @@ -361,6 +366,28 @@ func (a *API) QuerySingleOrder(orderId string) (map[string]interface{}, error) { return result[0].(map[string]interface{}), nil } +func (a *API) OrderQuery2(queryParam *OrderQueryParam) (retVal []*OrderInfo, totalCount int, err error) { + orderList, totalCount, err := a.OrderQuery(utils.Struct2MapByJson(queryParam)) + if err == nil { + err = utils.Map2StructByJson(orderList, &retVal, true) + } + return retVal, totalCount, err +} + +func (a *API) QuerySingleOrder2(orderID string) (orderInfo *OrderInfo, err error) { + orderList, _, err := a.OrderQuery2(&OrderQueryParam{ + OrderID: utils.Str2Int64(orderID), + }) + if err == nil { + if len(orderList) > 0 { + orderInfo = orderList[0] + } else { + err = ErrCanNotFindOrder + } + } + return orderInfo, err +} + // 商家确认接单接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=169&apiid=c1a15129d1374e9da7fa35487f878604 func (a *API) OrderAcceptOperate(orderId string, isAgreed bool, userName string) error { diff --git a/platformapi/jdapi/order_test.go b/platformapi/jdapi/order_test.go index b64008ab..89d94372 100644 --- a/platformapi/jdapi/order_test.go +++ b/platformapi/jdapi/order_test.go @@ -226,3 +226,13 @@ func TestOrderAddTips(t *testing.T) { t.Fatal(err.Error()) } } + +func TestOrderQuery2(t *testing.T) { + orderList, _, err := api.OrderQuery2(&OrderQueryParam{ + OrderID: 918092290000042, + }) + t.Log(utils.Format4Output(orderList, false)) + if err != nil { + t.Fatal(err.Error()) + } +} From 58bd31a996c5446d98a630a5c74c0c5ae2b19044 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 30 Jul 2019 18:12:43 +0800 Subject: [PATCH 05/71] =?UTF-8?q?-=20HTTP=E8=AF=B7=E6=B1=82=E4=B8=AD?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E6=AC=A1=E8=AE=BF=E9=97=AEtrackInfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/platformapi.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/platformapi/platformapi.go b/platformapi/platformapi.go index 63e04287..f0558a28 100644 --- a/platformapi/platformapi.go +++ b/platformapi/platformapi.go @@ -101,12 +101,10 @@ func AccessPlatformAPIWithRetry(client *http.Client, handleRequest func() *http. } beginTime := time.Now() trackInfo := request.Header.Get(KeyTrackInfo) - if trackInfo == "" { - trackInfo = utils.GetUUID() - // request.Header.Set(KeyTrackInfo, trackID) - } else { + if trackInfo != "" { request.Header.Del(KeyTrackInfo) } + trackInfo += ", " + utils.GetUUID() baseapi.SugarLogger.Debugf("begin AccessPlatformAPIWithRetry:%s do:%s url:%v", trackInfo, request.Method, request.URL) response, err := client.Do(request) baseapi.SugarLogger.Debugf("end AccessPlatformAPIWithRetry:%s do url:%v, request:%s", trackInfo, request.URL, getClonedData(request.URL, savedBuf)) From d28c352b3e85713898034968cf55dcedc7fb3592 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 31 Jul 2019 18:11:04 +0800 Subject: [PATCH 06/71] =?UTF-8?q?-=20=E6=A0=87=E5=87=86=E5=8C=96jdapi.Quer?= =?UTF-8?q?ySkuInfos=E5=92=8CQueryListBySkuIds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/sku.go | 96 +++++++++++++++++++++++------------ platformapi/jdapi/sku_test.go | 11 +++- 2 files changed, 73 insertions(+), 34 deletions(-) diff --git a/platformapi/jdapi/sku.go b/platformapi/jdapi/sku.go index 9c5239db..14311f7c 100644 --- a/platformapi/jdapi/sku.go +++ b/platformapi/jdapi/sku.go @@ -68,9 +68,9 @@ const ( ) const ( - SkuFixedStatusOnline = 1 - SkuFixedStatusOffline = 2 - SkuFixedStatusDeleted = 4 + SkuFixedStatusOnline = 1 // 上架 + SkuFixedStatusOffline = 2 // 下架 + SkuFixedStatusDeleted = 4 // 删除 ) const ( @@ -79,6 +79,10 @@ const ( CreateSpuResultFailed = 3 ) +const ( + IsFilterDelTrue = "0" // 0代表不查已删除商品 +) + const ( MaxSkuNameCharCount = 45 // skuname最长字符数 SaleAttrIDBase = 1001 @@ -131,13 +135,57 @@ type CreateByUpcPair struct { SkuId int64 } +type QuerySkuParam struct { + SkuName string `json:"skuName,omitempty"` + UpcCode string `json:"upcCode,omitempty"` + SkuID int64 `json:"skuId,omitempty"` + IsFilterDel string `json:"isFilterDel,omitempty"` // 是否查询出已删除的上传商品(0代表不查已删除商品,不填则查出全部商品) + PageNo int `json:"pageNo,omitempty"` + PageSize int `json:"pageSize,omitempty"` +} + +type SkuMain struct { + SuperID int64 `json:"superId"` + SkuID int64 `json:"skuId"` + OutSkuID string `json:"outSkuId"` + CategoryID int64 `json:"categoryId"` + BrandID int64 `json:"brandId"` + ShopCategories []int64 `json:"shopCategories"` + SkuName string `json:"skuName"` + FixedStatus int `json:"fixedStatus"` // 商家商品上下架状态(1:上架;2:下架;4:删除;) + FixedUpTime string `json:"fixedUpTime"` + OrgCode int `json:"orgCode"` + SellCities []int64 `json:"sellCities"` + SkuPrice int `json:"skuPrice"` + Weight float64 `json:"weight"` +} + +type QueryListBySkuIdsParam struct { + SkuIDs []int64 `json:"skuIds"` + ImgType int `json:"imgType,omitempty"` + HandleStatus []int `json:"handleStatus,omitempty"` +} + +type ImgHandleQueryResult struct { + ID string `json:"id"` + SkuID int64 `json:"skuId"` + IsMain int `json:"isMain"` + ImgType int `json:"imgType"` + SourceImgURL string `json:"sourceImgUrl"` + SkuImgSort int `json:"skuImgSort"` + HandleStatus int `json:"handleStatus"` + HandleStatusStr string `json:"handleStatusStr"` + HandleRemark string `json:"handleRemark"` + HandleErrLog string `json:"handleErrLog"` +} + var ( skuExistReg = regexp.MustCompile(`商家skuId已存在:(\d+)`) ) // 分页查询商品品牌信息接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=180&apiid=1ca07a3e767649a7a44fc6ea7e9ed8dd -func (a *API) QueryPageBrandInfo(pageNo, pageSize, brandId int, brandName string) (brandList []*BrandInfo, totalCount int, err error) { +func (a *API) QueryPageBrandInfo(pageNo, pageSize int, brandId int64, brandName string) (brandList []*BrandInfo, totalCount int, err error) { if pageNo <= 0 { pageNo = 1 } @@ -320,44 +368,28 @@ func (a *API) BatchUpdateOutSkuId(skuInfoList []*SkuIDPair) (retVal interface{}, // 查询商家已上传商品信息列表接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=180&apiid=e433b95f74524dab91718432c0358977 // pageNo 从1开始 -func (a *API) QuerySkuInfos(skuName string, skuId int64, pageNo, pageSize int, isFilterDel bool) (retVal []map[string]interface{}, totalCount int, err error) { - if pageNo <= 0 { - pageNo = 1 +func (a *API) QuerySkuInfos(queryParam *QuerySkuParam) (skuList []*SkuMain, totalCount int, err error) { + if queryParam.PageNo <= 0 { + queryParam.PageNo = 1 } - if pageSize == 0 { - pageSize = 50 + if queryParam.PageSize == 0 { + queryParam.PageSize = 50 } - params := map[string]interface{}{ - KeyPageNo: pageNo, // pageNo好像必须要有值,否则一直不返回 - KeyPageSize: pageSize, - } - if skuName != "" { - params[KeySkuName] = skuName - } - if skuId != 0 { - params[KeySkuId] = skuId - } - if isFilterDel { - params[KeyIsFilterDel] = "1" - } else { - params[KeyIsFilterDel] = "0" - } - result, totalCount, err := a.AccessAPIHavePage("pms/querySkuInfos", params, nil, nil, nil) + result, totalCount, err := a.AccessAPIHavePage("pms/querySkuInfos", utils.Struct2MapByJson(queryParam), nil, nil, nil) if err == nil { - return utils.Slice2MapSlice(result), totalCount, nil + err = utils.Map2StructByJson(result, &skuList, false) } - return nil, 0, err + return skuList, totalCount, err } // 查询商品图片处理结果接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=180&apiid=17506653e03542f9a49023711780c30d -func (a *API) QueryListBySkuIds(skuIds []int64, addParams map[string]interface{}) (retVal []map[string]interface{}, err error) { - result, err := a.AccessAPINoPage("order/queryListBySkuIds", utils.MergeMaps(addParams, utils.Params2Map("skuIds", skuIds)), nil, nil, nil) +func (a *API) QueryListBySkuIds(queryParam *QueryListBySkuIdsParam) (imgList []*ImgHandleQueryResult, err error) { + result, err := a.AccessAPINoPage("order/queryListBySkuIds", utils.Struct2MapByJson(queryParam), nil, nil, nil) if err == nil { - return utils.Slice2MapSlice(result.([]interface{})), nil + err = utils.Map2StructByJson(result, &imgList, false) } - return nil, err - + return imgList, err } // 分页查询京东到家商品前缀库接口 diff --git a/platformapi/jdapi/sku_test.go b/platformapi/jdapi/sku_test.go index 950dcbbf..b15f7043 100644 --- a/platformapi/jdapi/sku_test.go +++ b/platformapi/jdapi/sku_test.go @@ -58,7 +58,11 @@ func TestBatchUpdateOutSkuId(t *testing.T) { func TestQuerySkuInfos(t *testing.T) { pageSize := 20 - result, totalCount, err := api.QuerySkuInfos("一个高级商品", 0, 0, pageSize, true) + result, totalCount, err := api.QuerySkuInfos(&QuerySkuParam{ + IsFilterDel: IsFilterDelTrue, + }) + t.Log(utils.Format4Output(result, false)) + t.Log(totalCount) if err != nil { t.Fatal(err) } @@ -73,7 +77,10 @@ func TestQueryListBySkuIds(t *testing.T) { 2018806493, 2018805873, } - result, err := api.QueryListBySkuIds(ids, nil) + result, err := api.QueryListBySkuIds(&QueryListBySkuIdsParam{ + SkuIDs: ids, + }) + t.Log(utils.Format4Output(result, false)) if err != nil { t.Fatal(err) } From 9c1182bd7f79b68b771364c44fcca1e36f3acbc9 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 1 Aug 2019 10:14:39 +0800 Subject: [PATCH 07/71] + jdapi.MaxPageSize4QuerySku, MaxSkuIDsCount4QueryListBySkuIds --- platformapi/jdapi/sku.go | 31 ++++++++++------------------- platformapi/jdapi/sku_test.go | 8 ++++---- platformapi/mtpsapi/mtpsapi_test.go | 2 +- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/platformapi/jdapi/sku.go b/platformapi/jdapi/sku.go index 14311f7c..06d9be00 100644 --- a/platformapi/jdapi/sku.go +++ b/platformapi/jdapi/sku.go @@ -1,12 +1,10 @@ package jdapi import ( - "fmt" "regexp" "strings" "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/globals" ) const ( @@ -65,6 +63,8 @@ const ( const ( MaxBatchSize4BatchUpdateOutSkuId = 50 + MaxPageSize4QuerySku = 50 + MaxSkuIDsCount4QueryListBySkuIds = 25 ) const ( @@ -123,11 +123,11 @@ type CategoryInfo struct { } type CreateByUpcParam struct { - Upc string - OutSkuId string - Price int // 单位为分 - ShopCategoryId int64 - IsSale bool + UniqueUpc string `json:"uniqueCode"` // 商品UPC码 + OutSku string `json:"outSku"` // 商家商品编码,商家系统中唯一编码,限1-35字符,与到家商品编码一对一对应 + JdPrice string `json:"jdPrice"` // 商家商品价格(单位:元),用于初始商品门店价格,所有的商品门店价格都会初始化成该值。后续修改商品门店价格需要通过价格类接口修改。 + ShopCategoryID int64 `json:"shopCategoryId"` // 商家店内分类编码,店内分类编码通过查询商家店内分类信息接口获取 + IsSale bool `json:"isSale"` // 门店商品可售状态,true为可售,false为不可售,默认为可售。 } type CreateByUpcPair struct { @@ -152,6 +152,7 @@ type SkuMain struct { BrandID int64 `json:"brandId"` ShopCategories []int64 `json:"shopCategories"` SkuName string `json:"skuName"` + Slogan string `json:"slogan"` FixedStatus int `json:"fixedStatus"` // 商家商品上下架状态(1:上架;2:下架;4:删除;) FixedUpTime string `json:"fixedUpTime"` OrgCode int `json:"orgCode"` @@ -373,7 +374,7 @@ func (a *API) QuerySkuInfos(queryParam *QuerySkuParam) (skuList []*SkuMain, tota queryParam.PageNo = 1 } if queryParam.PageSize == 0 { - queryParam.PageSize = 50 + queryParam.PageSize = MaxPageSize4QuerySku } result, totalCount, err := a.AccessAPIHavePage("pms/querySkuInfos", utils.Struct2MapByJson(queryParam), nil, nil, nil) if err == nil { @@ -575,22 +576,12 @@ func (a *API) GetSpuSaleAttr(outSpuId string) (attrList []map[string]interface{} return nil, err } -func (a *API) BatchAddSku(paramList []*CreateByUpcParam) (pairs []*CreateByUpcPair, err error) { - batchSkuRequestList := make([]map[string]interface{}, len(paramList)) - for k, v := range paramList { - batchSkuRequestList[k] = map[string]interface{}{ - "uniqueCode": v.Upc, - "outSku": v.OutSkuId, - "jdPrice": fmt.Sprintf("%.2f", float32(v.Price)/100), - "shopCategoryId": v.ShopCategoryId, - "isSale": v.IsSale, - } - } +func (a *API) BatchAddSku(batchSkuRequestList []*CreateByUpcParam) (pairs []*CreateByUpcPair, err error) { result, err := a.AccessAPINoPage("PmsSkuMainService/batchAddSku", map[string]interface{}{ "batchSkuRequestList": batchSkuRequestList, }, nil, nil, genNoPageResultParser("code", "result", "detail", "0")) if err == nil { - globals.SugarLogger.Debug(utils.Format4Output(result, false)) + // globals.SugarLogger.Debug(utils.Format4Output(result, false)) // todo 这个API在找不到UPC创建失败时,code也是0,底层不能判断失败 if result2, ok := result.([]interface{}); ok && len(result2) > 0 { detail := utils.Slice2MapSlice(result2) diff --git a/platformapi/jdapi/sku_test.go b/platformapi/jdapi/sku_test.go index b15f7043..b44cb514 100644 --- a/platformapi/jdapi/sku_test.go +++ b/platformapi/jdapi/sku_test.go @@ -159,10 +159,10 @@ func TestGetSpuSaleAttr(t *testing.T) { func TestBatchAddSku(t *testing.T) { paramList := []*CreateByUpcParam{ &CreateByUpcParam{ - Upc: "6948939649102", - OutSkuId: "50001", - Price: 213, - ShopCategoryId: 4247719, + UniqueUpc: "6948939649102", + OutSku: "50001", + JdPrice: "2.13", + ShopCategoryID: 4247719, IsSale: true, }, } diff --git a/platformapi/mtpsapi/mtpsapi_test.go b/platformapi/mtpsapi/mtpsapi_test.go index ee9fbde6..c8731a7f 100644 --- a/platformapi/mtpsapi/mtpsapi_test.go +++ b/platformapi/mtpsapi/mtpsapi_test.go @@ -25,7 +25,7 @@ func init() { // prod // api = New("3c0a05d464c247c19d7ec13accc78605", "b1M}9?:sTbsB[OF2gNORnN(|(iy9rB8(`7]|[wGLnbmt`evfM>E:A90DjHAW:UPE") - api.SetCookie("token", "jWQx6ao1-BFeuFg1iOHX207ocrPXlJPY-f41EaF1769C13Gw-irr5QnfQzmZOvOqt99cdN4XdQW0n8wvy-Hl_A") + api.SetCookie("token", "M0p9VatZSeSHfrosD5IViAVl73IcA8mlcuHIV5sG6Zpv83a7JE0wY3t26aEhrrs_MR5gtLSFF1UIkt8HAjaXow") } func handleError(t *testing.T, err error) { From fbe921605b5632b6abcc752757fcb710b0c58278 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 1 Aug 2019 16:46:43 +0800 Subject: [PATCH 08/71] =?UTF-8?q?-=20=E7=BC=BA=E7=9C=81=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E8=AE=BE=E4=B8=BA30=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/platformapi.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformapi/platformapi.go b/platformapi/platformapi.go index f0558a28..4e51acd5 100644 --- a/platformapi/platformapi.go +++ b/platformapi/platformapi.go @@ -17,7 +17,7 @@ import ( ) const ( - DefClientTimeout = 15 * time.Second + DefClientTimeout = 30 * time.Second DefSleepSecondWhenExceedLimit = 3 * time.Second DefMaxRecoverableRetryCount = 1 DefMaxExceedLimitRetryCount = 25 From e2185bf02e302bf68dbe7078c96501cfa15ab85c Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 2 Aug 2019 11:00:29 +0800 Subject: [PATCH 09/71] - jdapi.ImgType const --- platformapi/jdapi/sku.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platformapi/jdapi/sku.go b/platformapi/jdapi/sku.go index 06d9be00..abb122b4 100644 --- a/platformapi/jdapi/sku.go +++ b/platformapi/jdapi/sku.go @@ -89,6 +89,11 @@ const ( SaleAttrValueIDBase = 10 ) +const ( + ImgTypeMain = 1 // 商品图片 + ImgTypeDetail = 2 // 详情图片 +) + type SkuIDPair struct { SkuId int64 `json:"skuId"` OutSkuId string `json:"outSkuId"` From a9f5e5595cc10b1a0190f6eaf9aab4e56e45b0ef Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 2 Aug 2019 13:10:02 +0800 Subject: [PATCH 10/71] + mtwmapi.ErrCodeOpFailed --- platformapi/mtwmapi/mtwmapi.go | 3 ++- platformapi/mtwmapi/poi_test.go | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/platformapi/mtwmapi/mtwmapi.go b/platformapi/mtwmapi/mtwmapi.go index 3aa53dff..50120383 100644 --- a/platformapi/mtwmapi/mtwmapi.go +++ b/platformapi/mtwmapi/mtwmapi.go @@ -46,7 +46,8 @@ const ( ErrCodeAccessLimited = 711 // 接口调用过于频繁,触发流控,请降低调用频率 ErrCodeNoAppFood = 805 // 不存在此菜品 - ErrCodeNoSuchOrder = 808 // 不存在此订单 + ErrCodeNoSuchOrder = 806 // 不存在此订单 + ErrCodeOpFailed = 808 // 操作失败(如订单在操作时,状态已变更等情况) ErrCodeSkuCategoryNotExist = 1021 // 菜品分类不存在 ErrCodeSkuCategoryExist = 1037 // 菜品分类已存在 ) diff --git a/platformapi/mtwmapi/poi_test.go b/platformapi/mtwmapi/poi_test.go index e8874199..84307467 100644 --- a/platformapi/mtwmapi/poi_test.go +++ b/platformapi/mtwmapi/poi_test.go @@ -22,7 +22,8 @@ func TestPoiGetIDs(t *testing.T) { } func TestPoiMGet(t *testing.T) { - result, err := api.PoiMGet([]string{testPoiCode}) + result, err := api.PoiMGet([]string{"2461723"}) + t.Log(utils.Format4Output(result, false)) if err != nil { t.Fatal(err) } @@ -32,7 +33,6 @@ func TestPoiMGet(t *testing.T) { if result[0].AppPoiCode != testPoiCode { t.Fatal("test_poi_01 is not equal") } - t.Log(utils.Format4Output(result, false)) } func TestPoiSave(t *testing.T) { @@ -80,3 +80,14 @@ func TestPoiStatus(t *testing.T) { t.Fatal(err) } } + +func TestPoiShipTimeUpdate(t *testing.T) { + err := api.PoiShipTimeUpdate("7174130", "00:00-23:00") + if err != nil { + t.Fatal(err) + } + err = api.PoiOpen("6741258") + if err != nil { + t.Fatal(err) + } +} From df1c2c52a1a103e97e31b0949bb76897d792517d Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 6 Aug 2019 16:00:34 +0800 Subject: [PATCH 11/71] - up --- platformapi/jdapi/promotion_sku_test.go | 67 +++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/platformapi/jdapi/promotion_sku_test.go b/platformapi/jdapi/promotion_sku_test.go index de1865b1..44eb1135 100644 --- a/platformapi/jdapi/promotion_sku_test.go +++ b/platformapi/jdapi/promotion_sku_test.go @@ -76,3 +76,70 @@ func TestCreatePromotionSkuLimitTime(t *testing.T) { t.Fatal(err) } } + +func TestCancelPromotion(t *testing.T) { + promotionIDs := []int64{ + 24636389, + 24753178, + 24754087, + 24970355, + 24970383, + 24970389, + 25439508, + 25444342, + 25869363, + 25871946, + 26291079, + 27036663, + 27407558, + 27407649, + 27424152, + 27424181, + 27424247, + 27424568, + 27508490, + 27555133, + 27674289, + 30969372, + 41809699, + 41810076, + 41810296, + 41811111, + 44179379, + 54080816, + 54080829, + 54080842, + 55346987, + 55347123, + 55347340, + 55348499, + 55348706, + 55348999, + 55349177, + 56723852, + 56724283, + 56725840, + 56725955, + 56726053, + 60713479, + 60714768, + 60719242, + 68818338, + } + + for _, v := range promotionIDs { + promotionInfo, err := api.QueryPromotionInfo(v) + if err != nil { + t.Fatal(err) + } + // t.Log(promotionInfo.PromotionType) + if promotionInfo.PromotionType == PromotionTypeLimitedTime { + err = api.CancelPromotionLimitTime(v, "", utils.GetUUID()) + } else { + err = api.CancelPromotionSingle(v, "", utils.GetUUID()) + } + if err != nil { + t.Fatal(err) + } + } +} From d0f16a33dade20d20fa45755f032a3fb274aebb1 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 6 Aug 2019 20:22:44 +0800 Subject: [PATCH 12/71] =?UTF-8?q?-=20=E7=BE=8E=E5=9B=A2=E5=A4=96=E5=8D=96?= =?UTF-8?q?=E7=9A=84ErrCodeSysErr=E5=BD=93=E6=88=90=E5=8F=AF=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E9=94=99=E8=AF=AF=EF=BC=88=E8=80=8C=E4=B8=8D=E6=98=AF?= =?UTF-8?q?=E8=B6=85=E8=AE=BF=E9=97=AE=E9=A2=91=E7=8E=87=E9=94=99=E8=AF=AF?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/mtwmapi/mtwmapi.go | 6 +++++- platformapi/mtwmapi/poi_test.go | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/platformapi/mtwmapi/mtwmapi.go b/platformapi/mtwmapi/mtwmapi.go index 50120383..0a1adc1a 100644 --- a/platformapi/mtwmapi/mtwmapi.go +++ b/platformapi/mtwmapi/mtwmapi.go @@ -67,9 +67,11 @@ type API struct { var ( canRetryCodes = map[int]int{ - ErrCodeSysErr: 1, ErrCodeAccessLimited: 1, } + canRecoverCodes = map[int]int{ + ErrCodeSysErr: 1, + } ) func New(appID, secret, callbackURL string, config ...*platformapi.APIConfig) *API { @@ -174,6 +176,8 @@ func (a *API) AccessAPI2(cmd string, isGet bool, bizParams map[string]interface{ newErr := utils.NewErrorIntCode(errorInfo["msg"].(string), int(utils.MustInterface2Int64(errorInfo["code"]))) if canRetryCodes[newErr.IntCode()] == 1 { return platformapi.ErrLevelExceedLimit, newErr + } else if canRecoverCodes[newErr.IntCode()] == 1 { + return platformapi.ErrLevelRecoverableErr, newErr } return platformapi.ErrLevelCodeIsNotOK, newErr } diff --git a/platformapi/mtwmapi/poi_test.go b/platformapi/mtwmapi/poi_test.go index 84307467..a089a5d9 100644 --- a/platformapi/mtwmapi/poi_test.go +++ b/platformapi/mtwmapi/poi_test.go @@ -91,3 +91,10 @@ func TestPoiShipTimeUpdate(t *testing.T) { t.Fatal(err) } } + +func TestPoiOpen(t *testing.T) { + err := api.PoiOpen("6735933") + if err != nil { + t.Fatal(err) + } +} From 8a9ec5dc91f3cd442eec8c8272f8c2357e406ee7 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 7 Aug 2019 10:15:44 +0800 Subject: [PATCH 13/71] =?UTF-8?q?-=20=E5=8E=BB=E9=99=A4=E9=A5=BF=E7=99=BE?= =?UTF-8?q?=E6=89=B9=E5=A4=84=E7=90=86API=E9=94=99=E8=AF=AF=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E4=B8=AD=E7=9A=84=E6=88=90=E5=8A=9F=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/shop_sku.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platformapi/ebaiapi/shop_sku.go b/platformapi/ebaiapi/shop_sku.go index fd282197..2a09db57 100644 --- a/platformapi/ebaiapi/shop_sku.go +++ b/platformapi/ebaiapi/shop_sku.go @@ -367,8 +367,8 @@ func handleShopSkuBatchErr(err error) (opResult *BatchOpResult, outErr error) { var data interface{} if err2 := utils.UnmarshalUseNumber([]byte(errExt.ErrMsg()), &data); err2 == nil { if err2 = utils.Map2StructByJson(data, &opResult, true); err2 == nil { - // 将以\u表示的字符串标准化 - errExt.SetErrMsg(string(utils.MustMarshal(opResult))) + // 将以\u表示的字符串标准化,并去掉成功的 + errExt.SetErrMsg(string(utils.MustMarshal(opResult.FailedList))) outErr = errExt } } From 6840508339c281792c5845df9d6da63c787bfc6a Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 7 Aug 2019 18:18:14 +0800 Subject: [PATCH 14/71] + Struct2Map --- utils/typeconv.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/utils/typeconv.go b/utils/typeconv.go index 9e75380a..df233bca 100644 --- a/utils/typeconv.go +++ b/utils/typeconv.go @@ -443,12 +443,19 @@ func MergeMaps(firstMap map[string]interface{}, otherMaps ...map[string]interfac return retVal } -func Struct2MapByJson(obj interface{}) (mapData map[string]interface{}) { +func Struct2Map(obj interface{}, tagName string) (mapData map[string]interface{}) { + if tagName == "" { + tagName = "json" + } structsObj := structs.New(obj) - structsObj.TagName = "json" + structsObj.TagName = tagName return structsObj.Map() } +func Struct2MapByJson(obj interface{}) (mapData map[string]interface{}) { + return Struct2Map(obj, "") +} + // 此函数将MAP中所有的子MAP中的数据提升到最上层,相同字段会覆盖父MAP的 func FlatMap(in map[string]interface{}) map[string]interface{} { keys := []string{} From c81c9110bbf3eb922b6d103a415d1dab3c1a083d Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 8 Aug 2019 22:03:28 +0800 Subject: [PATCH 15/71] + QueryPromotionSku --- platformapi/jdapi/jdapi.go | 83 ++++++++++--------- platformapi/jdapi/promotion_audit.go | 15 ++++ platformapi/jdapi/promotion_audit_test.go | 21 +++++ platformapi/yilianyunapi/yilianyunapi_test.go | 10 +-- 4 files changed, 83 insertions(+), 46 deletions(-) diff --git a/platformapi/jdapi/jdapi.go b/platformapi/jdapi/jdapi.go index 7c1b5e64..d6f5c82c 100644 --- a/platformapi/jdapi/jdapi.go +++ b/platformapi/jdapi/jdapi.go @@ -267,59 +267,60 @@ func (a *API) AccessAPINoPage2(apiStr string, jdParams map[string]interface{}, k func (a *API) AccessAPINoPage(apiStr string, jdParams map[string]interface{}, keyToRemove, keyToKeep []string, resultParser func(data map[string]interface{}) (interface{}, error)) (interface{}, error) { return a.AccessAPINoPage2(apiStr, jdParams, keyToRemove, keyToKeep, resultParser, "") } +func genNormalHavePageResultParser(dataKey string) (handler PageResultParser) { + return func(data map[string]interface{}, totalCount int) ([]interface{}, int, error) { + var result map[string]interface{} + var retVal []interface{} -func normalHavePageResultParser(data map[string]interface{}, totalCount int) ([]interface{}, int, error) { - var result map[string]interface{} - var retVal []interface{} - - tempResult := data["result"] - if resultStr, ok := tempResult.(string); ok { - if err := utils.UnmarshalUseNumber([]byte(resultStr), &tempResult); err != nil { - return nil, 0, platformapi.ErrResponseDataFormatWrong - } - } - - result = tempResult.(map[string]interface{}) - - if totalCount == 0 { - for _, totalCountKey := range havePageTotalCountKeys { - if totalCount2, ok := result[totalCountKey]; ok { - totalCountInt64, _ := totalCount2.(json.Number).Int64() - totalCount = int(totalCountInt64) - if totalCount == 0 { - return make([]interface{}, 0), 0, nil - } - break + tempResult := data[dataKey] + if resultStr, ok := tempResult.(string); ok { + if err := utils.UnmarshalUseNumber([]byte(resultStr), &tempResult); err != nil { + return nil, 0, platformapi.ErrResponseDataFormatWrong } } + + result = tempResult.(map[string]interface{}) + if totalCount == 0 { - baseapi.SugarLogger.Errorf("can not find totalCount key, data:%v", result) - return nil, 0, platformapi.ErrResponseDataFormatWrong - } - } - - for _, inner2ResultKey := range havePageInner2DataKeys { - if inner2Result, ok := result[inner2ResultKey]; ok { - if inner2Result == nil { - retVal = nil - } else if inner2ResultStr, ok := inner2Result.(string); ok { - err := utils.UnmarshalUseNumber([]byte(inner2ResultStr), &retVal) - if err != nil { - return nil, 0, platformapi.ErrResponseDataFormatWrong + for _, totalCountKey := range havePageTotalCountKeys { + if totalCount2, ok := result[totalCountKey]; ok { + totalCountInt64, _ := totalCount2.(json.Number).Int64() + totalCount = int(totalCountInt64) + if totalCount == 0 { + return make([]interface{}, 0), 0, nil + } + break } - } else { - retVal = inner2Result.([]interface{}) } - return retVal, totalCount, nil + if totalCount == 0 { + baseapi.SugarLogger.Errorf("can not find totalCount key, data:%v", result) + return nil, 0, platformapi.ErrResponseDataFormatWrong + } } + + for _, inner2ResultKey := range havePageInner2DataKeys { + if inner2Result, ok := result[inner2ResultKey]; ok { + if inner2Result == nil { + retVal = nil + } else if inner2ResultStr, ok := inner2Result.(string); ok { + err := utils.UnmarshalUseNumber([]byte(inner2ResultStr), &retVal) + if err != nil { + return nil, 0, platformapi.ErrResponseDataFormatWrong + } + } else { + retVal = inner2Result.([]interface{}) + } + return retVal, totalCount, nil + } + } + baseapi.SugarLogger.Errorf("can not find result key, data:%v", result) + return nil, 0, platformapi.ErrResponseDataFormatWrong } - baseapi.SugarLogger.Errorf("can not find result key, data:%v", result) - return nil, 0, platformapi.ErrResponseDataFormatWrong } func (a *API) AccessAPIHavePage(apiStr string, jdParams map[string]interface{}, keyToRemove, keyToKeep []string, pageResultParser PageResultParser) ([]interface{}, int, error) { if pageResultParser == nil { - pageResultParser = normalHavePageResultParser + pageResultParser = genNormalHavePageResultParser("result") } localJdParams := make(map[string]interface{}) diff --git a/platformapi/jdapi/promotion_audit.go b/platformapi/jdapi/promotion_audit.go index e993891f..a0c9d2a2 100644 --- a/platformapi/jdapi/promotion_audit.go +++ b/platformapi/jdapi/promotion_audit.go @@ -106,3 +106,18 @@ func (a *API) QueryPromotionInfo(promotionInfoId int64) (promotionInfo *Promotio } return promotionInfo, err } + +// 根据到家商品ID查询单品级优惠活动列表接口 +// https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=196&apiid=d73baba02c484109a3c3c1b1236ca13d +func (a *API) QueryPromotionSku(promotionType int, skuID int64, promotionState int /*, pageNo int64, pageSize int*/) (skuResultList []*PromotionLspQuerySkuResult, err error) { + jdParams := map[string]interface{}{ + "promotionType": promotionType, + "skuId": skuID, + "promotionState": promotionState, + } + result, _, err := a.AccessAPIHavePage("singlePromote/queryPromotionSku", jdParams, nil, nil, genNormalHavePageResultParser("data")) + if err != nil { + err = utils.Map2StructByJson(result, &skuResultList, false) + } + return skuResultList, err +} diff --git a/platformapi/jdapi/promotion_audit_test.go b/platformapi/jdapi/promotion_audit_test.go index b1b670f9..70ec955a 100644 --- a/platformapi/jdapi/promotion_audit_test.go +++ b/platformapi/jdapi/promotion_audit_test.go @@ -21,3 +21,24 @@ func TestQueryPromotionInfo(t *testing.T) { } t.Log(utils.Format4Output(result, false)) } + +func TestQueryPromotionSku(t *testing.T) { + skuIDs := []int64{ + 2023335105, + // 2023335104, + // 2023335088, + // 2023335057, + // 2023335098, + // 2023335020, + } + for _, skuID := range skuIDs { + list, err := api.QueryPromotionSku(PromotionTypeDirectDown, skuID, PromotionStateConfirmed) + t.Log(utils.Format4Output(list, false)) + if err != nil { + t.Fatal(err) + } + // for _, v := range list { + // CancelPromotionSkuSingle() + // } + } +} diff --git a/platformapi/yilianyunapi/yilianyunapi_test.go b/platformapi/yilianyunapi/yilianyunapi_test.go index 3e3f79f1..b2728edf 100644 --- a/platformapi/yilianyunapi/yilianyunapi_test.go +++ b/platformapi/yilianyunapi/yilianyunapi_test.go @@ -42,19 +42,19 @@ func TestRetrieveToken(t *testing.T) { func TestAddPrinter(t *testing.T) { // err := api.AddPrinter("4004600675", "fem2ukwvduik", "公司测试打印机1") - // 4004617180 公司测试打印机2 - err := api.AddPrinter("4004600675", "fem2ukwvduik", "测试打印机1") + // 4004617180, 381870509796 公司测试打印机2 + err := api.AddPrinter("4004615546", "7nxsw668yqtk", "测试打印机1") handleError(t, err) } func TestDeletePrinter(t *testing.T) { - err := api.DeletePrinter("4004611945") + err := api.DeletePrinter("4004615546") handleError(t, err) } func TestPrintMsg(t *testing.T) { // 4004606481 - err := api.PrintMsg("4004600675", utils.GetUUID(), "饿百取货码") + err := api.PrintMsg("4004615546", utils.GetUUID(), "饿百取货码") handleError(t, err) } @@ -65,7 +65,7 @@ func TestPrintMsgWithToken(t *testing.T) { } func TestGetPrintStatus(t *testing.T) { - state, err := api.GetPrintStatus("4004617180") + state, err := api.GetPrintStatus("4004615546") handleError(t, err) baseapi.SugarLogger.Debug(state) } From 4fb34af13df44b39fc0551973b54e5c0045ff803 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 13 Aug 2019 17:03:35 +0800 Subject: [PATCH 16/71] =?UTF-8?q?-=20=E4=BA=AC=E4=B8=9C=EF=BC=8C=E7=BE=8E?= =?UTF-8?q?=E5=9B=A2=E5=92=8C=E9=A5=BF=E7=99=BEAPI=E4=B8=AD=EF=BC=8C?= =?UTF-8?q?=E5=9B=A0=E4=B8=BA=E5=B7=B2=E7=BB=8F=E5=AF=B9=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E5=81=9A=E4=BA=86=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/ebaiapi.go | 4 ++-- platformapi/jdapi/jdapi.go | 3 ++- platformapi/mtwmapi/mtwmapi.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/platformapi/ebaiapi/ebaiapi.go b/platformapi/ebaiapi/ebaiapi.go index b3b5f50b..de4aa419 100644 --- a/platformapi/ebaiapi/ebaiapi.go +++ b/platformapi/ebaiapi/ebaiapi.go @@ -144,8 +144,8 @@ func (a *API) AccessAPI2(cmd string, body map[string]interface{}, trackInfo stri err = platformapi.RebuildError(err, body, []string{ KeyBaiduShopID, KeyShopID, - KeySkuID, - KeyCustomSkuID, + // KeySkuID, + // KeyCustomSkuID, }) return retVal, err } diff --git a/platformapi/jdapi/jdapi.go b/platformapi/jdapi/jdapi.go index d6f5c82c..60102ff3 100644 --- a/platformapi/jdapi/jdapi.go +++ b/platformapi/jdapi/jdapi.go @@ -105,7 +105,8 @@ var ( KeyOutStationNo, KeyStationNo, "StoreNo", - "outSkuId", + // KeyOutSkuId, + // KeySkuId, } ) diff --git a/platformapi/mtwmapi/mtwmapi.go b/platformapi/mtwmapi/mtwmapi.go index 0a1adc1a..91db3b45 100644 --- a/platformapi/mtwmapi/mtwmapi.go +++ b/platformapi/mtwmapi/mtwmapi.go @@ -186,7 +186,7 @@ func (a *API) AccessAPI2(cmd string, isGet bool, bizParams map[string]interface{ err = platformapi.RebuildError(err, bizParams, []string{ KeyAppPoiCode, KeyAppPoiCodes, - KeyAppFoodCode, + // KeyAppFoodCode, }) return retVal, err } From 2580d1a8c31cbf7bd939092ac63ded74e3e5a77b Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 13 Aug 2019 17:43:00 +0800 Subject: [PATCH 17/71] =?UTF-8?q?-=20=E4=BA=AC=E4=B8=9C=EF=BC=8C=E7=BE=8E?= =?UTF-8?q?=E5=9B=A2=E5=92=8C=E9=A5=BF=E7=99=BEAPI=E4=B8=AD=EF=BC=8C?= =?UTF-8?q?=E8=BF=98=E6=98=AF=E4=BF=9D=E7=95=99=E5=87=BA=E9=94=99=E6=98=AF?= =?UTF-8?q?=E7=BB=99=E5=87=BA=E9=97=A8=E5=BA=97=E5=92=8C=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=9A=84=E4=BF=A1=E6=81=AF=EF=BC=88RebuildError=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/ebaiapi.go | 4 ++-- platformapi/jdapi/jdapi.go | 4 ++-- platformapi/mtwmapi/mtwmapi.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/platformapi/ebaiapi/ebaiapi.go b/platformapi/ebaiapi/ebaiapi.go index de4aa419..b3b5f50b 100644 --- a/platformapi/ebaiapi/ebaiapi.go +++ b/platformapi/ebaiapi/ebaiapi.go @@ -144,8 +144,8 @@ func (a *API) AccessAPI2(cmd string, body map[string]interface{}, trackInfo stri err = platformapi.RebuildError(err, body, []string{ KeyBaiduShopID, KeyShopID, - // KeySkuID, - // KeyCustomSkuID, + KeySkuID, + KeyCustomSkuID, }) return retVal, err } diff --git a/platformapi/jdapi/jdapi.go b/platformapi/jdapi/jdapi.go index 60102ff3..6228f09b 100644 --- a/platformapi/jdapi/jdapi.go +++ b/platformapi/jdapi/jdapi.go @@ -105,8 +105,8 @@ var ( KeyOutStationNo, KeyStationNo, "StoreNo", - // KeyOutSkuId, - // KeySkuId, + KeyOutSkuId, + KeySkuId, } ) diff --git a/platformapi/mtwmapi/mtwmapi.go b/platformapi/mtwmapi/mtwmapi.go index 91db3b45..0a1adc1a 100644 --- a/platformapi/mtwmapi/mtwmapi.go +++ b/platformapi/mtwmapi/mtwmapi.go @@ -186,7 +186,7 @@ func (a *API) AccessAPI2(cmd string, isGet bool, bizParams map[string]interface{ err = platformapi.RebuildError(err, bizParams, []string{ KeyAppPoiCode, KeyAppPoiCodes, - // KeyAppFoodCode, + KeyAppFoodCode, }) return retVal, err } From b338b87a025a1f51df2f4dbcf7c991a432fd78ff Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 08:54:02 +0800 Subject: [PATCH 18/71] =?UTF-8?q?-=20=E8=B6=85=E9=A2=91=E9=87=8D=E8=A7=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E6=94=B9=E4=B8=BA=E6=8C=89=E5=B9=82=E5=A2=9E?= =?UTF-8?q?=E9=95=BF=20+=20jdapi.NewPageOnly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/jdapi.go | 7 +++++++ platformapi/platformapi.go | 32 +++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/platformapi/jdapi/jdapi.go b/platformapi/jdapi/jdapi.go index 6228f09b..c6cbe5e4 100644 --- a/platformapi/jdapi/jdapi.go +++ b/platformapi/jdapi/jdapi.go @@ -144,6 +144,13 @@ func New(token, appKey, appSecret string, config ...*platformapi.APIConfig) *API } } +func NewPageOnly(cookie string, config ...*platformapi.APIConfig) *API { + api := New("", "", "", config...) + api.SetCookie(accessStorePageCookieName, cookie) + api.SetCookie(accessStorePageCookieName2, cookie) + return api +} + func (a *API) AccessAPI2(apiStr string, jdParams map[string]interface{}, traceInfo string) (retVal map[string]interface{}, err error) { params := make(map[string]interface{}) params["v"] = "1.0" diff --git a/platformapi/platformapi.go b/platformapi/platformapi.go index 4e51acd5..7b313a73 100644 --- a/platformapi/platformapi.go +++ b/platformapi/platformapi.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "io/ioutil" + "math" "net" "net/http" "net/url" @@ -17,18 +18,18 @@ import ( ) const ( - DefClientTimeout = 30 * time.Second - DefSleepSecondWhenExceedLimit = 3 * time.Second - DefMaxRecoverableRetryCount = 1 - DefMaxExceedLimitRetryCount = 25 + DefClientTimeout = 30 * time.Second + DefMaxSleepSecondWhenExceedLimit = 62 // 超频类错误最大重试间隙(秒) + DefMaxExceedLimitRetryCount = 25 // 超频类错误最大重试次数 + DefMaxRecoverableRetryCount = 1 // 可恢复类错误(一般指网络错),最大重试次数 KeyTrackInfo = "TrackInfo" ) type APIRetryConfig struct { - MaxExceedLimitRetryCount int - MaxRecoverableRetryCount int - SleepSecondWhenExceedLimit time.Duration + MaxExceedLimitRetryCount int + MaxRecoverableRetryCount int + MaxSleepSecondWhenExceedLimit int } type APIConfig struct { @@ -45,9 +46,9 @@ type AccessPlatformAPIWithRetryParam struct { var ( DefAPIConfig = APIConfig{ APIRetryConfig: APIRetryConfig{ - MaxExceedLimitRetryCount: DefMaxExceedLimitRetryCount, - MaxRecoverableRetryCount: DefMaxRecoverableRetryCount, - SleepSecondWhenExceedLimit: DefSleepSecondWhenExceedLimit, + MaxExceedLimitRetryCount: DefMaxExceedLimitRetryCount, + MaxRecoverableRetryCount: DefMaxRecoverableRetryCount, + MaxSleepSecondWhenExceedLimit: DefMaxSleepSecondWhenExceedLimit, }, ClientTimeout: DefClientTimeout, } @@ -90,6 +91,11 @@ func getClonedData(requestURL *url.URL, r *bytes.Buffer) string { return retVal } +func NewDefAPIConfig() (conf *APIConfig) { + obj := DefAPIConfig + return &obj +} + func AccessPlatformAPIWithRetry(client *http.Client, handleRequest func() *http.Request, config *APIConfig, handleResponse func(response *http.Response, bodyStr string, bodyMap map[string]interface{}) (string, error)) error { exceedLimitRetryCount := 0 recoverableErrorRetryCount := 0 @@ -172,7 +178,11 @@ func AccessPlatformAPIWithRetry(client *http.Client, handleRequest func() *http. } else if errLevel == ErrLevelExceedLimit { exceedLimitRetryCount++ if exceedLimitRetryCount <= config.MaxExceedLimitRetryCount { - time.Sleep(config.SleepSecondWhenExceedLimit) + sleepSeconds := int(math.Exp2(float64(exceedLimitRetryCount))) + if sleepSeconds > config.MaxSleepSecondWhenExceedLimit { + sleepSeconds = config.MaxSleepSecondWhenExceedLimit + } + time.Sleep(time.Duration(sleepSeconds) * time.Second) continue } } else if errLevel == ErrLevelRecoverableErr { From da1ee8f496f37175aa8e06c6cc814c4ce829cee1 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 12:22:01 +0800 Subject: [PATCH 19/71] + jdapi.SaveQualify --- platformapi/jdapi/store_page.go | 135 +++++++++++++++++++++++++-- platformapi/jdapi/store_page_test.go | 90 +++++++++++++++++- 2 files changed, 217 insertions(+), 8 deletions(-) diff --git a/platformapi/jdapi/store_page.go b/platformapi/jdapi/store_page.go index c4e56f73..9b7d7526 100644 --- a/platformapi/jdapi/store_page.go +++ b/platformapi/jdapi/store_page.go @@ -1,9 +1,13 @@ package jdapi import ( + "bytes" "crypto/md5" "fmt" + "io/ioutil" + "mime/multipart" "net/http" + "net/url" "regexp" "strings" @@ -136,14 +140,56 @@ type PageShopInfo struct { StoreShareURL string `json:"storeShareUrl"` } -var ( - monthSaleNumReg = regexp.MustCompile(`(\d+)([千|万])`) +const ( + LincenceEconKindPerson = "个体工商户" + + QualifyTypePerson = "25" // 营业执照 + QualifyTypeCompany = "22" // 身份证,个体工商户要求填 + QualifyTypeAddInfo = "31" // 附加信息,如果身份证是长期有效,要求身份证背面信息 + + SaveQualifyActionTypeCommit = 0 // 提交 + SaveQualifyActionTypeSave = 1 // 暂时保存 ) -func (a *API) AccessStorePage(fullURL string, params map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) { +type QualifyItem struct { + QualifyURL string `json:"qualifyUrl"` + QualifyType string `json:"qualifyType"` + QualifyExpireForever int `json:"qualifyExpireForever"` // 0:永久有性,1:非永久有效(需要填QualifyExpireEnd) + QualifyExpireStart string `json:"qualifyExpireStart"` + QualifyExpireEnd string `json:"qualifyExpireEnd,omitempty"` + QualifyName string `json:"qualifyName,omitempty"` + QualifyOwner string `json:"qualifyOwner,omitempty"` + LicenceType string `json:"licenceType,omitempty"` // -1 + QualifyNumber string `json:"qualifyNumber,omitempty"` + QualifyAddress string `json:"qualifyAddress,omitempty"` + LicenceName string `json:"licenceName,omitempty"` + EconKind string `json:"econKind,omitempty"` + Scope string `json:"scope,omitempty"` +} + +var ( + monthSaleNumReg = regexp.MustCompile(`(\d+)([千|万])`) + pageExceedLimitCodes = map[string]int{ + "403": 1, + } +) + +const ( + KeyImgData = "imgData" + KeyImgName = "imgName" + + ResultKeyData = "data" + ResultKeyResult = "result" +) + +func (a *API) AccessStorePage2(fullURL string, params map[string]interface{}, isPost bool, resultKey string) (retVal interface{}, err error) { if a.GetCookieCount() == 0 { return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法") } + imgData := params[KeyImgData] + if imgData != nil { + delete(params, KeyImgData) + } err = platformapi.AccessPlatformAPIWithRetry(a.client, func() *http.Request { var request *http.Request @@ -151,8 +197,26 @@ func (a *API) AccessStorePage(fullURL string, params map[string]interface{}, isP request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(fullURL, "", params), nil) } else { request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(params).Encode())) + if params[KeyImgName] == nil { + request.Header.Set("Content-Type", "application/x-www-form-urlencoded") + } else { + var b bytes.Buffer + w := multipart.NewWriter(&b) + if fw, err := w.CreateFormFile("uploadFile", params[KeyImgName].(string)); err != nil { + panic(err.Error()) + } else { + fw.Write(imgData.([]byte)) + } + for k, v := range params { + fmt.Println(k, " ", v) + w.WriteField(k, url.QueryEscape(fmt.Sprint(v))) + } + w.Close() + // b.WriteString(utils.Map2URLValues(params).Encode()) + request, _ = http.NewRequest(http.MethodPost, fullURL, &b) + request.Header.Set("Content-Type", w.FormDataContentType()) + } request.Header.Set("charset", "UTF-8") - request.Header.Set("Content-Type", "application/x-www-form-urlencoded") } if err != nil { return nil @@ -166,13 +230,18 @@ func (a *API) AccessStorePage(fullURL string, params map[string]interface{}, isP return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil") } retVal = jsonResult1 - code := jsonResult1["code"].(string) + code, ok := jsonResult1["code"].(string) + if !ok { + return platformapi.ErrLevelGeneralFail, utils.NewErrorCode(utils.Format4Output(jsonResult1, true), "999") + } if code == ResponseCodeSuccess { - retVal, _ = jsonResult1["result"].(map[string]interface{}) + if resultKey != "" { + retVal = jsonResult1[resultKey] + } return platformapi.ErrLevelSuccess, nil } newErr := utils.NewErrorCode(jsonResult1["msg"].(string), code) - if _, ok := exceedLimitCodes[code]; ok { + if _, ok := pageExceedLimitCodes[code]; ok { return platformapi.ErrLevelExceedLimit, newErr } else if _, ok := canRetryCodes[code]; ok { return platformapi.ErrLevelRecoverableErr, newErr @@ -184,6 +253,14 @@ func (a *API) AccessStorePage(fullURL string, params map[string]interface{}, isP return retVal, err } +func (a *API) AccessStorePage(fullURL string, params map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) { + result, err := a.AccessStorePage2(fullURL, params, isPost, ResultKeyResult) + if err == nil { + retVal = result.(map[string]interface{}) + } + return retVal, err +} + func (a *API) GetRealMobile4Order(orderId, stationNo string) (mobile string, err error) { retVal, err := a.GetStoreOrderInfo(orderId, stationNo) if err == nil { @@ -346,3 +423,47 @@ func MonthSaleNum2Int(monthSaleNumStr string) (monthSaleNum int) { } return monthSaleNum } + +func (a *API) StoreUploadImg(imgFileName string, imgBin []byte) (imgURL string, err error) { + result, err := a.AccessStorePage2("https://sta-store.jddj.com/store/uploadImg.json", map[string]interface{}{ + KeyImgData: imgBin, + KeyImgName: imgFileName, + }, true, ResultKeyData) + if err == nil { + imgURL = result.(string) + } + return imgURL, err +} + +func (a *API) StoreUploadImgByURL(inImgURL string) (imgURL string, err error) { + response, err := http.Get(inImgURL) + if err == nil { + defer func() { + response.Body.Close() + }() + if response.StatusCode == http.StatusOK { + bodyData, err2 := ioutil.ReadAll(response.Body) + if err = err2; err == nil { + imgName := utils.GetUUID() + if lastSlashIndex := strings.LastIndex(inImgURL, "/"); lastSlashIndex >= 0 { + imgName = inImgURL[lastSlashIndex+1:] + } + return a.StoreUploadImg(imgName, bodyData) + } + } else { + err = platformapi.ErrHTTPCodeIsNot200 + } + } + return "", err +} + +func (a *API) SaveQualify(stationNo string, actionType int, qualifyList []*QualifyItem) (err error) { + _, err = a.AccessStorePage2("https://sta-store.jddj.com/store/saveQualify.o2o", map[string]interface{}{ + "stationNo": stationNo, + "actionType": actionType, + "qualifyList": qualifyList, + "type": 1, + "degrade": "no", + }, true, "") + return err +} diff --git a/platformapi/jdapi/store_page_test.go b/platformapi/jdapi/store_page_test.go index 5e773b19..c137ee02 100644 --- a/platformapi/jdapi/store_page_test.go +++ b/platformapi/jdapi/store_page_test.go @@ -56,7 +56,7 @@ func TestGetSkuPageImageInfo(t *testing.T) { } func TestGetCorporationInfo(t *testing.T) { - imgList, err := api.GetCorporationInfo("", "915101003431062533") + imgList, err := api.GetCorporationInfo("", "92330104MA28XPXH5G") if err != nil { t.Fatal(err) } @@ -101,3 +101,91 @@ func TestMonthSaleNum2Int(t *testing.T) { t.Fatalf("num3:%d", num3) } } + +func TestStoreUploadImgByURL(t *testing.T) { + outImgURL, err := api.StoreUploadImgByURL("http://image.jxc4.com/940c151db7e396f2ceaec0304597836f.jpg") + t.Log(outImgURL) + if err != nil { + t.Fatal(err) + } +} + +func TestSaveQualify(t *testing.T) { + jsonStr := ` + [ + { + "qualifyUrl":"http://img30.360buyimg.com/vendersettle/jfs/t1/69834/24/6602/68812/5d4d35fdEaaf373c6/5c1c50e7bb6330e4.jpg", + "qualifyType":"25", + "qualifyExpireForever":0, + "qualifyExpireStart":"2017-09-07 00:00:00", + "qualifyName":"刘男", + "licenceType":"-1", + "qualifyNumber":"92330104MA28XPXH5G", + "qualifyAddress":"浙江省杭州市江干区八堡家园5排10号一楼102", + "licenceName":"杭州市江干区刘男便利店", + "econKind":"个体工商户", + "scope":"食品经营(凭有效许可证经营);零售:卷烟、雪茄烟(凭有效许可证经营);批发、零售:日用百货,五金。(依法须经批准的项目,经相关部门批准后方可开展经营活动)" + }, + { + "qualifyUrl":"http://img30.360buyimg.com/vendersettle/jfs/t1/58554/26/7134/19343/5d4d3639E57b14138/bcce25e1eac11be8.jpg", + "qualifyType":"22", + "qualifyExpireForever":1, + "qualifyExpireStart":"2013-07-22 16:59:38", + "qualifyExpireEnd":"2033-07-22 16:59:50", + "qualifyOwner":"刘男", + "qualifyNumber":"420621198110303336" + }, + { + "qualifyUrl":"", + "qualifyType":"33", + "qualifyExpireForever":1, + "qualifyExpireStart":"", + "qualifyExpireEnd":"" + }, + { + "qualifyUrl":"", + "qualifyType":"8", + "qualifyExpireForever":1, + "qualifyExpireStart":"", + "qualifyExpireEnd":"" + }, + { + "qualifyUrl":"", + "qualifyType":"9", + "qualifyExpireForever":1, + "qualifyExpireStart":"", + "qualifyExpireEnd":"" + }, + { + "qualifyUrl":"", + "qualifyType":"10", + "qualifyExpireForever":1, + "qualifyExpireStart":"", + "qualifyExpireEnd":"" + }, + { + "qualifyUrl":"", + "qualifyType":"29", + "qualifyExpireForever":1, + "qualifyExpireStart":"", + "qualifyExpireEnd":"" + }, + { + "qualifyUrl":"", + "qualifyType":"31", + "qualifyExpireForever":1, + "qualifyExpireStart":"", + "qualifyExpireEnd":"" + } + ] + ` + var qualityList []*QualifyItem + err := utils.UnmarshalUseNumber([]byte(jsonStr), &qualityList) + if err != nil { + t.Fatal(err) + } + err = api.SaveQualify("11902261", SaveQualifyActionTypeSave, qualityList) + if err != nil { + t.Fatal(err) + } +} From 15c818a3dcef30bc0e87015eb290d1336c6ac5e9 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 15:49:27 +0800 Subject: [PATCH 20/71] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8Djdapi.SaveQualify?= =?UTF-8?q?=E4=B8=AD=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/store_page.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformapi/jdapi/store_page.go b/platformapi/jdapi/store_page.go index 9b7d7526..b58c7aa3 100644 --- a/platformapi/jdapi/store_page.go +++ b/platformapi/jdapi/store_page.go @@ -461,7 +461,7 @@ func (a *API) SaveQualify(stationNo string, actionType int, qualifyList []*Quali _, err = a.AccessStorePage2("https://sta-store.jddj.com/store/saveQualify.o2o", map[string]interface{}{ "stationNo": stationNo, "actionType": actionType, - "qualifyList": qualifyList, + "qualifyList": utils.Format4Output(qualifyList, true), "type": 1, "degrade": "no", }, true, "") From 46e56d3f493d0021257227556f2403ac8a03645b Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 16:28:45 +0800 Subject: [PATCH 21/71] - up --- platformapi/jdapi/store_page.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/platformapi/jdapi/store_page.go b/platformapi/jdapi/store_page.go index b58c7aa3..774cd8ac 100644 --- a/platformapi/jdapi/store_page.go +++ b/platformapi/jdapi/store_page.go @@ -143,8 +143,8 @@ type PageShopInfo struct { const ( LincenceEconKindPerson = "个体工商户" - QualifyTypePerson = "25" // 营业执照 - QualifyTypeCompany = "22" // 身份证,个体工商户要求填 + QualifyTypeCompany = "25" // 营业执照 + QualifyTypePerson = "22" // 身份证,个体工商户要求填 QualifyTypeAddInfo = "31" // 附加信息,如果身份证是长期有效,要求身份证背面信息 SaveQualifyActionTypeCommit = 0 // 提交 @@ -172,6 +172,7 @@ var ( pageExceedLimitCodes = map[string]int{ "403": 1, } + pageCanRetryCodes = map[string]int{} ) const ( @@ -243,7 +244,7 @@ func (a *API) AccessStorePage2(fullURL string, params map[string]interface{}, is newErr := utils.NewErrorCode(jsonResult1["msg"].(string), code) if _, ok := pageExceedLimitCodes[code]; ok { return platformapi.ErrLevelExceedLimit, newErr - } else if _, ok := canRetryCodes[code]; ok { + } else if _, ok := pageCanRetryCodes[code]; ok { return platformapi.ErrLevelRecoverableErr, newErr } else { baseapi.SugarLogger.Debugf("jd AccessStorePage failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true)) From bfbe247f20b74a38825712fa4b032eb53fe8a5e1 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 15 Aug 2019 16:40:34 +0800 Subject: [PATCH 22/71] - up --- platformapi/jdapi/store_page.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/platformapi/jdapi/store_page.go b/platformapi/jdapi/store_page.go index 774cd8ac..01b4a5ad 100644 --- a/platformapi/jdapi/store_page.go +++ b/platformapi/jdapi/store_page.go @@ -141,8 +141,6 @@ type PageShopInfo struct { } const ( - LincenceEconKindPerson = "个体工商户" - QualifyTypeCompany = "25" // 营业执照 QualifyTypePerson = "22" // 身份证,个体工商户要求填 QualifyTypeAddInfo = "31" // 附加信息,如果身份证是长期有效,要求身份证背面信息 From c91dfdeb21123bf412b41e077e456827bcb002d5 Mon Sep 17 00:00:00 2001 From: gazebo Date: Sun, 18 Aug 2019 14:02:09 +0800 Subject: [PATCH 23/71] =?UTF-8?q?-=20=E4=BA=AC=E4=B8=9C=E7=BD=91=E9=A1=B5?= =?UTF-8?q?=E5=8F=96=E7=94=B5=E8=AF=9D=E5=8F=B7=E7=A0=81=E7=9A=84=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E5=8F=98=E5=8A=A8=E4=B8=BA:http://order.jddj.com/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/store_page.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platformapi/jdapi/store_page.go b/platformapi/jdapi/store_page.go index 01b4a5ad..9268f9af 100644 --- a/platformapi/jdapi/store_page.go +++ b/platformapi/jdapi/store_page.go @@ -278,7 +278,7 @@ func (a *API) GetStoreOrderInfo(orderId, stationNo string) (storeOrderInfo map[s if stationNo != "" { params["stationNo"] = stationNo } - retVal, err := a.AccessStorePage("http://store.jddj.com/order/newManager/search", params, false) + retVal, err := a.AccessStorePage("http://order.jddj.com/order/newManager/search", params, false) // baseapi.SugarLogger.Debug(utils.Format4Output(retVal, false)) if err == nil { newOrderinfoMains := retVal["newOrderinfoMains"].(map[string]interface{}) @@ -305,7 +305,7 @@ func (a *API) GetStoreOrderInfoList(fromTime, toTime string) (storeOrderList []m for { params["pageNo"] = pageNo - retVal, err := a.AccessStorePage("http://store.jddj.com/order/newManager/tabQuery/all", params, false) + retVal, err := a.AccessStorePage("http://order.jddj.com/order/newManager/tabQuery/all", params, false) // baseapi.SugarLogger.Debug(utils.Format4Output(retVal, false)) if err == nil { newOrderinfoMains := retVal["newOrderinfoMains"].(map[string]interface{}) From 6b1f4d6aef9c3e48fa3b04c11f30f9c44a5c7db5 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 21 Aug 2019 21:27:55 +0800 Subject: [PATCH 24/71] + BatchCoordinateConvert --- platformapi/autonavi/autonavi.go | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/platformapi/autonavi/autonavi.go b/platformapi/autonavi/autonavi.go index a81ddaaa..5a75f3f3 100644 --- a/platformapi/autonavi/autonavi.go +++ b/platformapi/autonavi/autonavi.go @@ -43,6 +43,7 @@ const ( const ( FakeDistrictPadding = 9000000 + MaxConvertCount = 40 ) var ( @@ -89,6 +90,11 @@ type District struct { Districts []*District `json:"districts"` } +type Coordinate struct { + Lng float64 `json:"lng"` + Lat float64 `json:"lat"` +} + type ResponseResult map[string]interface{} type API struct { @@ -161,6 +167,15 @@ func (a *API) AccessAPI(apiStr string, params map[string]interface{}) (retVal Re // 为了方便调用者编码,如果失败,也会返回未转换的原始值 func (a *API) CoordinateConvert(lng, lat float64, coordsys string) (retLng, retLat float64, err error) { + // outCoords, err := a.BatchCoordinateConvert([]*Coordinate{ + // &Coordinate{ + // Lng: lng, + // Lat: lat, + // }, + // }, coordsys) + // if err == nil { + // retLng, retLat = outCoords[0].Lng, outCoords[0].Lat + // } if coordsys == "" || coordsys == CoordSysAutonavi { return lng, lat, nil } @@ -180,6 +195,33 @@ func (a *API) CoordinateConvert(lng, lat float64, coordsys string) (retLng, retL return lng, lat, err } +func (a *API) BatchCoordinateConvert(coords []*Coordinate, coordsys string) (outCoords []*Coordinate, err error) { + if coordsys == "" || coordsys == CoordSysAutonavi { + return coords, nil + } + var coordsStrList []string + for _, v := range coords { + coordsStrList = append(coordsStrList, fmt.Sprintf("%.6f,%.6f", v.Lng, v.Lat)) + } + params := map[string]interface{}{ + "locations": strings.Join(coordsStrList, "|"), + "coordsys": coordsys, + } + result, err := a.AccessAPI("assistant/coordinate/convert", params) + if err == nil { + coordinate := result["locations"].(string) + retCoordsStrList := strings.Split(coordinate, ";") + for _, v := range retCoordsStrList { + pair := strings.Split(v, ",") + outCoords = append(outCoords, &Coordinate{ + Lng: utils.Str2Float64(pair[0]), + Lat: utils.Str2Float64(pair[1]), + }) + } + } + return outCoords, err +} + func (a *API) GetCoordinateFromAddress(address string, cityInfo string) (lng, lat float64, districtCode int) { params := map[string]interface{}{ "address": address, From 75c327e08df2b9dba307b47b5a063edb4c5fc48f Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 26 Aug 2019 18:51:00 +0800 Subject: [PATCH 25/71] + baidunavi --- platformapi/baidunavi/baidunavi.go | 168 ++++++++++++++++++++++++ platformapi/baidunavi/baidunavi_test.go | 41 ++++++ 2 files changed, 209 insertions(+) create mode 100644 platformapi/baidunavi/baidunavi.go create mode 100644 platformapi/baidunavi/baidunavi_test.go diff --git a/platformapi/baidunavi/baidunavi.go b/platformapi/baidunavi/baidunavi.go new file mode 100644 index 00000000..20fde070 --- /dev/null +++ b/platformapi/baidunavi/baidunavi.go @@ -0,0 +1,168 @@ +package baidunavi + +import ( + "crypto/md5" + "fmt" + "net/http" + "net/url" + "sort" + "strings" + + "git.rosy.net.cn/baseapi/platformapi" + "git.rosy.net.cn/baseapi/utils" +) + +const ( + signKey = "sn" + resultKey = "result" + prodURL = "http://api.map.baidu.com" +) + +const ( + StatusCodeSuccess = 0 + StatusCodeInternalErr = 1 // 服务器内部错误 + StatusCodeExceedDailyQuota = 301 // 永久配额超限,限制访问 + StatusCodeExceedQuota = 302 // 天配额超限,限制访问 + StatusCodeExceedDailyConcurrentQuota = 401 // 当前并发量已经超过约定并发配额,限制访问 + StatusCodeExceedConcurrentQuota = 402 // 当前并发量已经超过约定并发配额,并且服务总并发量也已经超过设定的总并发配额,限制访问 +) + +const ( + CoordSysWGS84 = 1 // GPS设备获取的角度坐标,WGS84坐标 + CoordSysGCJ02 = 3 // google地图、soso地图、aliyun地图、mapabc地图和amap地图所用坐标,国测局(GCJ02)坐标 + CoordSysBaiDu = 5 // 百度地图采用的经纬度坐标 +) + +const ( + MaxCoordsConvBatchSize = 100 +) + +var ( + exceedLimitCodes = map[int]int{ + StatusCodeExceedDailyQuota: 1, + StatusCodeExceedQuota: 1, + StatusCodeExceedDailyConcurrentQuota: 1, + StatusCodeExceedConcurrentQuota: 1, + } + + canRetryCodes = map[int]int{ + StatusCodeInternalErr: 1, + } +) + +type Coordinate struct { + Lng float64 `json:"x"` + Lat float64 `json:"y"` +} + +type API struct { + client *http.Client + config *platformapi.APIConfig + ak string + sk string +} + +func New(ak, sk string, config ...*platformapi.APIConfig) *API { + curConfig := platformapi.DefAPIConfig + if len(config) > 0 { + curConfig = *config[0] + } + return &API{ + ak: ak, + sk: sk, + client: &http.Client{Timeout: curConfig.ClientTimeout}, + config: &curConfig, + } +} + +func (a *API) signParams(apiStr string, mapData map[string]interface{}) string { + keys := make([]string, 0) + for k := range mapData { + if k != signKey { + keys = append(keys, k) + } + } + sort.Strings(keys) + + strList := []string{} + for _, k := range keys { + strList = append(strList, k+"="+url.QueryEscape(fmt.Sprint(mapData[k]))) + } + finalStr := "/" + apiStr + "?" + strings.Join(strList, "&") + a.sk + // baseapi.SugarLogger.Debugf("sign str:%v", finalStr) + finalStr = url.QueryEscape(finalStr) + return fmt.Sprintf("%x", md5.Sum([]byte(finalStr))) +} + +func genGetURL(baseURL, apiStr string, params map[string]interface{}) string { + keys := make([]string, 0) + for k := range params { + if k != signKey { + keys = append(keys, k) + } + } + sort.Strings(keys) + + strList := []string{} + for _, k := range keys { + strList = append(strList, k+"="+url.QueryEscape(fmt.Sprint(params[k]))) + } + strList = append(strList, signKey+"="+url.QueryEscape(fmt.Sprint(params[signKey]))) + queryString := "?" + strings.Join(strList, "&") + if apiStr != "" { + return baseURL + "/" + apiStr + queryString + } + return baseURL + queryString +} + +func (a *API) AccessAPI(apiStr string, params map[string]interface{}) (retVal interface{}, err error) { + apiStr += "/" + params2 := utils.MergeMaps(utils.Params2Map("ak", a.ak, "output", "json"), params) + params2[signKey] = a.signParams(apiStr, params2) + + err = platformapi.AccessPlatformAPIWithRetry(a.client, + func() *http.Request { + request, _ := http.NewRequest(http.MethodGet, genGetURL(prodURL, apiStr, params2), nil) + 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") + } + status := int(utils.MustInterface2Int64(jsonResult1["status"])) + if status == StatusCodeSuccess { + retVal = jsonResult1[resultKey] + return platformapi.ErrLevelSuccess, nil + } + newErr := utils.NewErrorIntCode(utils.Interface2String(jsonResult1["message"]), status) + if _, ok := exceedLimitCodes[status]; ok { + return platformapi.ErrLevelExceedLimit, newErr + } else if _, ok := canRetryCodes[status]; ok { + return platformapi.ErrLevelRecoverableErr, newErr + } else { + return platformapi.ErrLevelCodeIsNotOK, newErr + } + }) + return retVal, err +} + +func (a *API) BatchCoordinateConvert(coords []*Coordinate, fromCoordSys, toCoordSys int) (outCoords []*Coordinate, err error) { + if fromCoordSys == toCoordSys { + return coords, nil + } + var coordsStrList []string + for _, v := range coords { + coordsStrList = append(coordsStrList, fmt.Sprintf("%.6f,%.6f", v.Lng, v.Lat)) + } + params := map[string]interface{}{ + "coords": strings.Join(coordsStrList, ";"), + "from": fromCoordSys, + "to": toCoordSys, + } + result, err := a.AccessAPI("geoconv/v1", params) + if err == nil { + err = utils.Map2StructByJson(result, &outCoords, false) + } + return outCoords, err +} diff --git a/platformapi/baidunavi/baidunavi_test.go b/platformapi/baidunavi/baidunavi_test.go new file mode 100644 index 00000000..3b11f2f4 --- /dev/null +++ b/platformapi/baidunavi/baidunavi_test.go @@ -0,0 +1,41 @@ +package baidunavi + +import ( + "testing" + + "git.rosy.net.cn/baseapi" + "git.rosy.net.cn/baseapi/utils" + + "go.uber.org/zap" +) + +var ( + api *API + sugarLogger *zap.SugaredLogger +) + +func init() { + logger, _ := zap.NewDevelopment() + sugarLogger = logger.Sugar() + baseapi.Init(sugarLogger) + + api = New("eL94zToVOdGDTkNQxV8dnEQ1ZRcB2UKb", "ZG0OOpOsOVURUwAkkmoHQFKRCbzn0zGb") +} + +func TestBatchCoordinateConvert(t *testing.T) { + result, err := api.BatchCoordinateConvert([]*Coordinate{ + &Coordinate{ + Lng: 104.057367, + Lat: 30.694686, + }, + &Coordinate{ + Lng: 104.057367, + Lat: 30.694686, + }, + }, CoordSysGCJ02, CoordSysBaiDu) + if err != nil { + t.Fatalf("TestCoordinateConvert failed with error:%v", err) + } else { + t.Log(utils.Format4Output(result, false)) + } +} From 53a2aa46f2356816a97f6e7a4ba8d430dc792b3d Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 27 Aug 2019 13:50:05 +0800 Subject: [PATCH 26/71] =?UTF-8?q?-=20=E9=A5=BF=E7=99=BE=E6=B4=BB=E5=8A=A8A?= =?UTF-8?q?PI=E5=85=B6=E4=B8=AD=E4=B8=80=E4=BA=9B=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC=E6=98=AF=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/activity.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platformapi/ebaiapi/activity.go b/platformapi/ebaiapi/activity.go index 27b8f5b0..4bf6591a 100644 --- a/platformapi/ebaiapi/activity.go +++ b/platformapi/ebaiapi/activity.go @@ -145,7 +145,7 @@ func (a *API) ActivitySkuAddBatch(activityID int64, shopID string, baiduShopID i params[skusKey] = skuList2Str(activityType, skuList, isSkuIDCustom) result, err := a.AccessAPI("activity.sku.add.batch", params) if err == nil { - return strings.Split(result.Data.(string), ","), nil + return strings.Split(utils.Interface2String(result.Data), ","), nil } return nil, err } @@ -180,7 +180,7 @@ func (a *API) ActivitySkuDeleteBatch(activityID int64, shopID string, baiduShopI params[skusKey] = strings.Join(skuIDs, ",") result, err := a.AccessAPI("activity.sku.delete.batch", params) if err == nil { - return strings.Split(result.Data.(string), ","), nil + return strings.Split(utils.Interface2String(result.Data), ","), nil } return nil, err } @@ -236,7 +236,7 @@ func (a *API) ActivitySkuUpdateBatch(activityID int64, actSkuInfoList []*Activit "act_sku_info": actSkuInfoList, }) if err == nil { - return strings.Split(result.Data.(string), ";"), nil + return strings.Split(utils.Interface2String(result.Data), ";"), nil } return nil, err } From 4170b5903fde014372d2e0182a6077cc9a6b2adb Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 27 Aug 2019 16:15:37 +0800 Subject: [PATCH 27/71] =?UTF-8?q?-=20=E6=A0=B9=E6=8D=AE=E2=80=9C=E6=82=A8?= =?UTF-8?q?=E5=A5=BD=EF=BC=8C=E8=BF=91=E6=9C=9F=E9=A5=BF=E7=99=BE=E9=9B=B6?= =?UTF-8?q?=E5=94=AE=E5=BC=80=E6=94=BE=E5=B9=B3=E5=8F=B0=E5=AF=B9=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E4=B8=AD=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=AD=97=E6=AE=B5=E8=BF=9B=E8=A1=8C=E8=B0=83=E6=95=B4?= =?UTF-8?q?=EF=BC=8C=E5=B9=B3=E5=8F=B0=E5=B0=86=E4=BB=8E8=E6=9C=8829?= =?UTF-8?q?=E6=97=A5=E8=B5=B7=E6=A0=B9=E6=8D=AE=E9=97=A8=E5=BA=97=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E9=80=90=E6=AD=A5=E7=81=B0=E5=BA=A6=EF=BC=8C=E9=A2=84?= =?UTF-8?q?=E8=AE=A19=E6=9C=88=E5=BA=95=E5=85=A8=E9=87=8F=E3=80=82?= =?UTF-8?q?=E8=AF=B7=E5=BC=80=E5=8F=91=E8=80=85=E5=85=B3=E6=B3=A8=E2=80=9D?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/order.go | 61 ++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/platformapi/ebaiapi/order.go b/platformapi/ebaiapi/order.go index bd596118..d39c4a55 100644 --- a/platformapi/ebaiapi/order.go +++ b/platformapi/ebaiapi/order.go @@ -41,6 +41,7 @@ const ( WaybillStatusSelfDelivery = "18" // 自行配送 WaybillStatusDontDeliver = "19" // 不再配送 WaybillStatusDeliveryRejected = "20" // 配送拒单 + WaybillStatusCourierArrived = "21" // 骑士到店 ) const ( @@ -188,31 +189,31 @@ type OrderDetailInfo struct { Ext struct { TaoxiFlag int `json:"taoxi_flag"` } `json:"ext"` - FinishedTime string `json:"finished_time"` - InvoiceTitle string `json:"invoice_title"` - IsColdBoxOrder int `json:"is_cold_box_order"` - IsPrivate int `json:"is_private"` - LatestSendTime int `json:"latest_send_time"` - MealNum string `json:"meal_num"` - NeedInvoice int `json:"need_invoice"` - OrderFlag int `json:"order_flag"` - OrderFrom string `json:"order_from"` - OrderID string `json:"order_id"` - OrderIndex string `json:"order_index"` - PackageFee int `json:"package_fee"` - PayStatus int `json:"pay_status"` - PayType int `json:"pay_type"` - PickupTime int `json:"pickup_time"` - Remark string `json:"remark"` - ResponsibleParty string `json:"responsible_party"` - SendFee int `json:"send_fee"` - SendImmediately int `json:"send_immediately"` - SendTime int `json:"send_time"` - ShopFee int `json:"shop_fee"` - Status int `json:"status"` - TaxerID string `json:"taxer_id"` - TotalFee int `json:"total_fee"` - UserFee int `json:"user_fee"` + FinishedTime string `json:"finished_time"` + InvoiceTitle string `json:"invoice_title"` + IsColdBoxOrder int `json:"is_cold_box_order"` + IsPrivate int `json:"is_private"` + LatestSendTime int `json:"latest_send_time"` + MealNum string `json:"meal_num"` + NeedInvoice int `json:"need_invoice"` + OrderFlag int `json:"order_flag"` + OrderFrom string `json:"order_from"` + OrderID string `json:"order_id"` + OrderIndex string `json:"order_index"` + PackageFee int `json:"package_fee"` + PayStatus int `json:"pay_status"` + PayType int `json:"pay_type"` + PickupTime int `json:"pickup_time"` + Remark string `json:"remark"` + // ResponsibleParty string `json:"responsible_party"` + SendFee int `json:"send_fee"` + SendImmediately int `json:"send_immediately"` + SendTime int `json:"send_time"` + ShopFee int `json:"shop_fee"` + Status int `json:"status"` + TaxerID string `json:"taxer_id"` + TotalFee int `json:"total_fee"` + UserFee int `json:"user_fee"` } `json:"order"` Products [][]*OrderProductInfo `json:"products"` Shop *struct { @@ -223,8 +224,8 @@ type OrderDetailInfo struct { Source string `json:"source"` User *struct { Address string `json:"address"` - City string `json:"city"` - Coord *struct { + // City string `json:"city"` + Coord *struct { Latitude string `json:"latitude"` Longitude string `json:"longitude"` } `json:"coord"` @@ -232,13 +233,13 @@ type OrderDetailInfo struct { Latitude string `json:"latitude"` Longitude string `json:"longitude"` } `json:"coord_amap"` - District string `json:"district"` + // District string `json:"district"` Gender string `json:"gender"` Name string `json:"name"` Phone string `json:"phone"` PrivacyPhone string `json:"privacy_phone"` - Province string `json:"province"` - UserID string `json:"user_id"` + // Province string `json:"province"` + UserID string `json:"user_id"` } `json:"user"` } From d7cd7461c0c8802f9d2585a3bc9b5dd3230ef249 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 27 Aug 2019 16:41:05 +0800 Subject: [PATCH 28/71] =?UTF-8?q?-=20=E9=A5=BF=E7=99=BE=E7=9A=84=E6=B6=88?= =?UTF-8?q?=E6=81=AF=EF=BC=8C=E5=85=88QueryUnescape=E5=86=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/callback.go | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/platformapi/ebaiapi/callback.go b/platformapi/ebaiapi/callback.go index 497400f2..c7be08be 100644 --- a/platformapi/ebaiapi/callback.go +++ b/platformapi/ebaiapi/callback.go @@ -113,16 +113,12 @@ func (a *API) unmarshalData(cmd string, data []byte, msg interface{}) (callbackR return nil } -func (a *API) CheckCallbackValidation(request *http.Request) (callbackResponse *CallbackResponse) { - params := make(url.Values) - for k, v := range request.PostForm { - params[k] = v - } +func (a *API) CheckCallbackValidation(cmd string, params url.Values) (callbackResponse *CallbackResponse) { sign := a.signParams(params) - if sign != request.FormValue(signKey) { - msg := fmt.Sprintf("Signature is not ok, mine:%v, get:%v", sign, request.FormValue(signKey)) + if sign != params.Get(signKey) { + msg := fmt.Sprintf("Signature is not ok, mine:%v, get:%v", sign, params.Get(signKey)) baseapi.SugarLogger.Info(msg) - return a.Err2CallbackResponse(GetCmd(request), errors.New(msg), nil) + return a.Err2CallbackResponse(cmd, errors.New(msg), nil) } return nil } @@ -130,15 +126,20 @@ func (a *API) CheckCallbackValidation(request *http.Request) (callbackResponse * func (a *API) GetCallbackMsg(request *http.Request) (msg *CallbackMsg, callbackResponse *CallbackResponse) { err := request.ParseForm() if err == nil { - if callbackResponse = a.CheckCallbackValidation(request); callbackResponse != nil { - return nil, callbackResponse + params := make(url.Values) + for k := range request.PostForm { + decodedValue, _ := url.QueryUnescape(request.PostFormValue(k)) + params.Set(k, decodedValue) } msg = new(CallbackMsg) - if callbackResponse = a.unmarshalData(GetCmd(request), []byte(request.FormValue("body")), &msg.Body); callbackResponse != nil { + msg.Cmd = GetCmd(request) + if callbackResponse = a.CheckCallbackValidation(msg.Cmd, params); callbackResponse != nil { return nil, callbackResponse } - msg.Cmd = GetCmd(request) - msg.Timestamp = utils.Str2Int64(utils.Interface2String(request.FormValue("timestamp"))) + if callbackResponse = a.unmarshalData(msg.Cmd, []byte(params.Get("body")), &msg.Body); callbackResponse != nil { + return nil, callbackResponse + } + msg.Timestamp = utils.Str2Int64(utils.Interface2String(params.Get("timestamp"))) var tmpObj interface{} switch msg.Cmd { case CmdOrderPartRefund: @@ -158,6 +159,7 @@ func (a *API) GetCallbackMsg(request *http.Request) (msg *CallbackMsg, callbackR return nil, a.Err2CallbackResponse("", err, nil) } -func GetCmd(request *http.Request) string { - return request.FormValue("cmd") +func GetCmd(request *http.Request) (cmd string) { + cmd, _ = url.QueryUnescape(request.FormValue("cmd")) + return cmd } From 645da0403832fad0237a9f906db717a41204905e Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 27 Aug 2019 17:09:57 +0800 Subject: [PATCH 29/71] - fk --- platformapi/jdapi/order.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/platformapi/jdapi/order.go b/platformapi/jdapi/order.go index f1b82e83..d994cb5d 100644 --- a/platformapi/jdapi/order.go +++ b/platformapi/jdapi/order.go @@ -59,16 +59,17 @@ const ( ) const ( - AfsReasonTypeGoodsQuality = 201 // 商品质量问题/做工粗糙/有瑕疵 - AfsReasonTypeWrongGoods = 202 // 发错货 - AfsReasonTypeMissingGoods = 203 // 部分商品未收到 - AfsReasonTypeNoGoods = 501 // 全部商品未收到 - AfsReasonTypeDamagedGoods = 208 // 外表损伤(压坏,磕坏等) - AfsReasonTypeGoodsQuantity = 207 // 缺斤少两 - AfsReasonTypeAgreedByMerchant = 209 // 与商家协商一致 + AfsReasonTypeGoodsQuality = 201 // 商品质量问题 + AfsReasonTypeWrongGoods = 202 // 送错货 + AfsReasonTypeMissingGoods = 203 // 缺件少件 + AfsReasonTypeNoGoods = 501 // 全部商品未收到 + AfsReasonTypeDamagedGoods = 208 // 包装脏污有破损 + AfsReasonTypeGoodsQuantity = 207 // 缺斤少两 + // AfsReasonTypeAgreedByMerchant = 209 // 与商家协商一致,2019/09/01取消 + AfsReasonTypeGoodsAbsent = 210 // 商家通知我缺货 AfsReasonTypeGoodsSizeNoSame = 302 // 大小尺寸与商品描述不符 - AfsReasonTypeGoodsColorNoSame = 303 // 颜色/款式/图案与描述不符 - AfsReasonWrongPurchase = 402 // 误购 + AfsReasonTypeGoodsColorNoSame = 303 // 实物与原图不符 + AfsReasonWrongPurchase = 402 // 不想要了 AfsReasonNotReceivedIntime = 502 // 未在时效内送达 ) From afad69e0ab03e145fcf3e1448ad421416811c214 Mon Sep 17 00:00:00 2001 From: gazebo Date: Sat, 31 Aug 2019 11:25:45 +0800 Subject: [PATCH 30/71] =?UTF-8?q?-=20=E6=98=93=E8=81=94=E5=8E=BBGetPrinter?= =?UTF-8?q?Token=E6=88=90=E5=8A=9F=E5=90=8E=EF=BC=8C=E4=B8=8D=E5=BA=94?= =?UTF-8?q?=E8=AF=A5=E8=B0=83=E7=94=A8SetToken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/yilianyunapi/yilianyunapi.go | 1 - platformapi/yilianyunapi/yilianyunapi_test.go | 14 ++++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/platformapi/yilianyunapi/yilianyunapi.go b/platformapi/yilianyunapi/yilianyunapi.go index 5019fd25..2f562bf0 100644 --- a/platformapi/yilianyunapi/yilianyunapi.go +++ b/platformapi/yilianyunapi/yilianyunapi.go @@ -238,7 +238,6 @@ func (a *API) GetPrinterToken(machineCode, qrKey string) (tokenInfo *TokenInfo, }, "") if err == nil { err = utils.Map2StructByJson(result, &tokenInfo, false) - a.SetToken(tokenInfo.AccessToken) } return tokenInfo, err } diff --git a/platformapi/yilianyunapi/yilianyunapi_test.go b/platformapi/yilianyunapi/yilianyunapi_test.go index b2728edf..0117898c 100644 --- a/platformapi/yilianyunapi/yilianyunapi_test.go +++ b/platformapi/yilianyunapi/yilianyunapi_test.go @@ -20,11 +20,11 @@ func init() { baseapi.Init(sugarLogger) // 自有应用 - api = New("1039586024", "4885d07c2997b661102e4b6099c0bf3b") - api.SetToken("7884617f9eeb4c28933569f94a95b5c3") + // api = New("1039586024", "4885d07c2997b661102e4b6099c0bf3b") + // api.SetToken("7884617f9eeb4c28933569f94a95b5c3") // 开放应用 - // api = New("1098307169", "d5eedb40c99e6691b1ca2ba82a363d6a") + api = New("1098307169", "d5eedb40c99e6691b1ca2ba82a363d6a") } func handleError(t *testing.T, err error) { @@ -71,7 +71,7 @@ func TestGetPrintStatus(t *testing.T) { } func TestGetPrintStatusWithToken(t *testing.T) { - state, err := api.GetPrintStatusWithToken("4004600675", "b1a36aa8de5647d2b08af49db11a9c9d") + state, err := api.GetPrintStatusWithToken("4004617242", "88de89a384714436a5d1ca23e8991e15") handleError(t, err) baseapi.SugarLogger.Debug(state) } @@ -91,3 +91,9 @@ func TestPlayText(t *testing.T) { err := api.PlayText("4004617180", utils.GetUUID(), "我们已安排%s配送员%s负责配送。^_^", "") handleError(t, err) } + +func TestRefreshToken(t *testing.T) { + tokenInfo, err := api.RefreshToken("c565a8983887488eb2a708ca118ce43c") + handleError(t, err) + t.Log(utils.Format4Output(tokenInfo, true)) +} From e653f099f09b1a8965e9f7db5b35fd36c9f9e5db Mon Sep 17 00:00:00 2001 From: gazebo Date: Sun, 1 Sep 2019 10:35:40 +0800 Subject: [PATCH 31/71] =?UTF-8?q?-=20jdapi.handleBatchOpResult=E5=8F=AA?= =?UTF-8?q?=E6=9C=89=E5=9C=A8=E6=9C=89=E9=94=99=E8=AF=AF=E6=97=B6=E6=89=8D?= =?UTF-8?q?=E4=BC=9A=E5=B0=9D=E8=AF=95=E8=A7=A3=E6=9E=90=E8=AF=A6=E7=BB=86?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E4=BF=A1=E6=81=AF=EF=BC=88=E5=8D=B3=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E4=B8=8D=E8=A7=A3=E6=9E=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/store_sku.go | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/platformapi/jdapi/store_sku.go b/platformapi/jdapi/store_sku.go index 08ae1886..25e12752 100644 --- a/platformapi/jdapi/store_sku.go +++ b/platformapi/jdapi/store_sku.go @@ -109,7 +109,7 @@ func (a *API) UpdateVendorStationPrice(trackInfo string, outStationNo, stationNo result, err := a.AccessAPINoPage2("venderprice/updateStationPrice", jdParams, nil, nil, genNoPageResultParser("code", "msg", "result", "0"), trackInfo) if result != nil { var err2 error - if responseList, err2 = a.handleBatchOpResult(len(skuPriceInfoList), result, "json2"); err2 != nil && err == nil { + if responseList, err2 = a.handleBatchOpResult(len(skuPriceInfoList), err, result, "json2"); err2 != nil && err == nil { err = err2 } } @@ -146,18 +146,20 @@ func (a *API) GetStationInfoList(stationNo string, skuIds []int64) (priceInfo [] return priceInfo, err } -func (a *API) handleBatchOpResult(batchCount int, result interface{}, tagName string) (responseList []*StoreSkuBatchUpdateResponse, err error) { - if err = utils.Map2Struct(result, &responseList, true, tagName); err == nil { - var failedList []*StoreSkuBatchUpdateResponse - for _, v := range responseList { - if v.Code != 0 { - failedList = append(failedList, v) +func (a *API) handleBatchOpResult(batchCount int, inErr error, result interface{}, tagName string) (responseList []*StoreSkuBatchUpdateResponse, err error) { + if inErr != nil { + if err = utils.Map2Struct(result, &responseList, true, tagName); err == nil { + var failedList []*StoreSkuBatchUpdateResponse + for _, v := range responseList { + if v.Code != 0 { + failedList = append(failedList, v) + } + } + if len(failedList) >= batchCount { + err = utils.NewErrorCode(string(utils.MustMarshal(failedList)), ResponseCodeAccessFailed, 1) // 此错误基本用不到 + } else if len(failedList) > 0 { // 部分失败 + err = utils.NewErrorCode(string(utils.MustMarshal(failedList)), ResponseInnerCodePartialFailed, 1) } - } - if len(failedList) >= batchCount { - err = utils.NewErrorCode(string(utils.MustMarshal(failedList)), ResponseCodeAccessFailed, 1) // 此错误基本用不到 - } else if len(failedList) > 0 { // 部分失败 - err = utils.NewErrorCode(string(utils.MustMarshal(failedList)), ResponseInnerCodePartialFailed, 1) } } return responseList, err @@ -181,7 +183,7 @@ func (a *API) BatchUpdateCurrentQtys(trackInfo, outStationNo, stationNo string, result, err := a.AccessAPINoPage2("stock/batchUpdateCurrentQtys", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"), trackInfo) if result != nil { var err2 error - if responseList, err2 = a.handleBatchOpResult(len(skuStockList), result, ""); err2 != nil && err == nil { + if responseList, err2 = a.handleBatchOpResult(len(skuStockList), err, result, ""); err2 != nil && err == nil { err = err2 } } @@ -231,7 +233,7 @@ func (a *API) UpdateVendibility(trackInfo string, listBaseStockCenterRequest []* result, err := a.AccessAPINoPage2("stock/updateVendibility", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"), trackInfo) if result != nil { var err2 error - if responseList, err2 = a.handleBatchOpResult(len(listBaseStockCenterRequest), result, ""); err2 != nil && err == nil { + if responseList, err2 = a.handleBatchOpResult(len(listBaseStockCenterRequest), err, result, ""); err2 != nil && err == nil { err = err2 } } @@ -256,7 +258,7 @@ func (a *API) BatchUpdateVendibility(trackInfo, outStationNo, stationNo string, result, err := a.AccessAPINoPage2("stock/batchUpdateVendibility", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"), trackInfo) if result != nil { var err2 error - if responseList, err2 = a.handleBatchOpResult(len(stockVendibilityList), result, ""); err2 != nil && err == nil { + if responseList, err2 = a.handleBatchOpResult(len(stockVendibilityList), err, result, ""); err2 != nil && err == nil { err = err2 } } From 2c67316c0f6ec749441cd553e0ce2f10f0e8dc44 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 3 Sep 2019 15:38:08 +0800 Subject: [PATCH 32/71] + utils_type.go --- utils/utils_type.go | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 utils/utils_type.go diff --git a/utils/utils_type.go b/utils/utils_type.go new file mode 100644 index 00000000..0bf1a678 --- /dev/null +++ b/utils/utils_type.go @@ -0,0 +1,56 @@ +package utils + +func String2Pointer(value string) *string { + return &value +} + +func Pointer2String(ptr *string) (value string) { + if ptr != nil { + value = *ptr + } + return value +} + +func Int2Pointer(value int) *int { + return &value +} + +func Pointer2Int(ptr *int) (value int) { + if ptr != nil { + value = *ptr + } + return value +} + +func Int64ToPointer(value int64) *int64 { + return &value +} + +func Pointer2Int64(ptr *int64) (value int64) { + if ptr != nil { + value = *ptr + } + return value +} + +func Float32ToPointer(value float32) *float32 { + return &value +} + +func Pointer2Float32(ptr *float32) (value float32) { + if ptr != nil { + value = *ptr + } + return value +} + +func Float64ToPointer(value float64) *float64 { + return &value +} + +func Pointer2Float64(ptr *float64) (value float64) { + if ptr != nil { + value = *ptr + } + return value +} From 188abb987a5380b7cd76bd230abac45a4c858f61 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 3 Sep 2019 18:15:07 +0800 Subject: [PATCH 33/71] + GetByOrderNoForOaos and CheckSelfPickCode. --- platformapi/jdapi/order.go | 63 ++++++++++++++++++++++++++++++--- platformapi/jdapi/order_test.go | 10 +++++- platformapi/jdapi/store.go | 1 + 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/platformapi/jdapi/order.go b/platformapi/jdapi/order.go index d994cb5d..8a75d2a7 100644 --- a/platformapi/jdapi/order.go +++ b/platformapi/jdapi/order.go @@ -37,11 +37,10 @@ const ( ) const ( - FreightDiscountTypeByShop = 8 // 8:商家满免运费 - FreightDiscountTypeByVip = 7 // 7:VIP免运费 - FreightDiscountTypeByActivity = 12 // 12:首单地推满免运费 - FreightDiscountTypeByCoupons = 15 // 15:运费券 - SelfDeliveryCarrierNo = "2938" // 京东配送方式=商家自送 + FreightDiscountTypeByShop = 8 // 8:商家满免运费 + FreightDiscountTypeByVip = 7 // 7:VIP免运费 + FreightDiscountTypeByActivity = 12 // 12:首单地推满免运费 + FreightDiscountTypeByCoupons = 15 // 15:运费券 ) const ( @@ -324,6 +323,35 @@ type OrderQueryParam struct { DeliveryStationNoIsv string `json:"deliveryStationNoIsv,omitempty"` // 商家门店编码 } +type SonTag struct { + MqProcessTime string `json:"mqProcessTime"` + OperTime string `json:"operTime"` + TagCode int `json:"tagCode"` + CodeName string `json:"codeName"` + OperPin string `json:"operPin"` + OperName int `json:"operName"` + MsgContent string `json:"msgContent"` +} + +type OrderTrack struct { + SonTagList []*SonTag `json:"sonTagList"` + IsThirdCarry int `json:"isThirdCarry"` + OperFrom string `json:"operFrom"` + MqProcessTime string `json:"mqProcessTime"` + TagIcon string `json:"tagIcon"` + OperTime string `json:"operTime"` + ThirdCarry int `json:"thirdCarry"` + TagTitle string `json:"tagTitle"` + CodeName string `json:"codeName"` + TagCode int `json:"tagCode"` + OperPin string `json:"operPin"` + OperName string `json:"operName"` + Care bool `json:"care"` + MsgContent string `json:"msgContent"` + MsgContentApp string `json:"msgContentApp"` + DoNotCareReason string `json:"doNotCareReason"` +} + var ( ErrCanNotFindOrder = errors.New("can not find order") ) @@ -665,3 +693,28 @@ func (a *API) OrderAddTips(orderID string, tips int, operator string) (err error _, err = a.AccessAPINoPage("order/addTips", jdParams, nil, nil, nullResultParser) return err } + +// 根据订单号查询订单跟踪接口 +// https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=169&apiid=d9d4fd73fba14fd8851a4c054d2ee42e +func (a *API) GetByOrderNoForOaos(orderNo string) (orderTrackList []*OrderTrack, err error) { + jdParams := map[string]interface{}{ + "orderNo": orderNo, + } + result, err := a.AccessAPINoPage("orderTrace/getByOrderNoForOaos", jdParams, nil, nil, genNoPageResultParser("code", "msg", "orderTrackList", "0")) + if err == nil { + err = utils.Map2StructByJson(result, &orderTrackList, false) + } + return orderTrackList, err +} + +// 订单自提码核验接口 +// https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=169&apiid=428fa2cb66784b64a85db36ec2972ff9 +func (a *API) CheckSelfPickCode(selfPickCode, orderID, operPin string) (err error) { + jdParams := map[string]interface{}{ + "selfPickCode": selfPickCode, + "orderId": orderID, + "operPin": operPin, + } + _, err = a.AccessAPINoPage("ocs/checkSelfPickCode", jdParams, nil, nil, nullResultParser) + return err +} diff --git a/platformapi/jdapi/order_test.go b/platformapi/jdapi/order_test.go index 89d94372..c9a33b52 100644 --- a/platformapi/jdapi/order_test.go +++ b/platformapi/jdapi/order_test.go @@ -10,7 +10,7 @@ import ( ) func TestQuerySingleOrder(t *testing.T) { - retVal, err := api.QuerySingleOrder("918092290000042") + retVal, err := api.QuerySingleOrder("921160248000222") t.Log(utils.Format4Output(retVal, false)) if err != nil { t.Error(err) @@ -236,3 +236,11 @@ func TestOrderQuery2(t *testing.T) { t.Fatal(err.Error()) } } + +func TestGetByOrderNoForOaos(t *testing.T) { + orderList, err := api.GetByOrderNoForOaos("921160248000222") + t.Log(utils.Format4Output(orderList, false)) + if err != nil { + t.Fatal(err.Error()) + } +} diff --git a/platformapi/jdapi/store.go b/platformapi/jdapi/store.go index 7cf8798b..91812604 100644 --- a/platformapi/jdapi/store.go +++ b/platformapi/jdapi/store.go @@ -47,6 +47,7 @@ type CityInfo struct { const ( CarrierNoCrowdSourcing = 9966 // 众包 CarrierNoSelfDelivery = 2938 // 自送 + CarrierNoSelfTake = 9999 // 到店自提 ) func (a *API) GetAllCities() (cities []*CityInfo, err error) { From 975305a32de10ada81edd609a839e77114af91bd Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 4 Sep 2019 11:44:31 +0800 Subject: [PATCH 34/71] + jdapi.AddByStoreAndSkus --- platformapi/jdapi/order_test.go | 7 +++++++ platformapi/jdapi/store_sku.go | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/platformapi/jdapi/order_test.go b/platformapi/jdapi/order_test.go index c9a33b52..2513f0ee 100644 --- a/platformapi/jdapi/order_test.go +++ b/platformapi/jdapi/order_test.go @@ -244,3 +244,10 @@ func TestGetByOrderNoForOaos(t *testing.T) { t.Fatal(err.Error()) } } + +func TestCheckSelfPickCode(t *testing.T) { + err := api.CheckSelfPickCode("", "921241806000842", "test") + if err != nil { + t.Fatal(err.Error()) + } +} diff --git a/platformapi/jdapi/store_sku.go b/platformapi/jdapi/store_sku.go index 25e12752..45dd44e9 100644 --- a/platformapi/jdapi/store_sku.go +++ b/platformapi/jdapi/store_sku.go @@ -9,6 +9,8 @@ import ( const ( MaxStoreSkuBatchSize = 50 MaxStockQty = 100000000 + + MaxAddByStoreAndSkusCount = 30 // 批量置顶商品排序接口的最大个数 ) type SkuPriceInfo struct { @@ -293,3 +295,14 @@ func (a *API) QueryStockCenter(outStationNo string, skuIds []*SkuIdEntity, userP } return vendibilityResponse, err } + +// 批量置顶商品排序接口 +// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=180&apiid=a7677f1a75984ed3a6ea3d4827f5a6b4 +func (a *API) AddByStoreAndSkus(stationNo int64, skuIDs []int64) (err error) { + jdParams := map[string]interface{}{ + "storeId": stationNo, + "skuIds": skuIDs, + } + _, err = a.AccessAPINoPage("OrgSortService/addByStoreAndSkus", jdParams, nil, nil, genNoPageResultParser("status", "message", "", "200")) + return err +} From 2e8b7538234179da7d4056cb69faaf500c5358f8 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 4 Sep 2019 15:11:38 +0800 Subject: [PATCH 35/71] =?UTF-8?q?+=20=E6=B7=BB=E5=8A=A0mtwmapi.OrderGetRid?= =?UTF-8?q?erInfoPhoneNumber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/mtwmapi/order.go | 43 ++++++++++++++++++++++++++++--- platformapi/mtwmapi/order_test.go | 13 +++++++--- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/platformapi/mtwmapi/order.go b/platformapi/mtwmapi/order.go index c3498b0e..03066c16 100644 --- a/platformapi/mtwmapi/order.go +++ b/platformapi/mtwmapi/order.go @@ -308,6 +308,23 @@ type GetOrderIdByDaySeqResult struct { OrderIDs []int64 `json:"order_ids"` } +type UserRealPhoneNumberInfo struct { + OrderID int64 `json:"order_id"` + AppPoiCode string `json:"app_poi_code"` + WmOrderIDView string `json:"wm_order_id_view"` + DaySeq int `json:"day_seq"` + RealPhoneNumber string `json:"real_phone_number"` // 订单收货人的真实手机号码 + RealOrderPhoneNumber string `json:"real_order_phone_number"` // 鲜花绿植类订单预订人的真实手机号码,如无则返回空。 +} + +type RiderRealPhoneNumberInfo struct { + OrderID int64 `json:"order_id"` + AppPoiCode string `json:"app_poi_code"` + WmOrderIDView string `json:"wm_order_id_view"` + RiderName string `json:"rider_name"` + RiderRealPhoneNumber string `json:"rider_real_phone_number"` // 骑手真实手机号 +} + func (a *API) OrderReceived(orderID int64) (err error) { _, err = a.AccessAPI("order/poi_received", true, map[string]interface{}{ KeyOrderID: orderID, @@ -462,8 +479,10 @@ func (a *API) OrderLogisticsStatus(orderID int64) (status map[string]interface{} return nil, err } +// 拉取用户真实手机号(必接) +// https://developer.waimai.meituan.com/home/docDetail/222 // limit最大为MaxBatchPullPhoneNumberLimit = 1000 -func (a *API) OrderBatchPullPhoneNumber(poiCode string, offset, limit int) (realNumberList []map[string]interface{}, err error) { +func (a *API) OrderBatchPullPhoneNumber(poiCode string, offset, limit int) (realNumberList []*UserRealPhoneNumberInfo, err error) { params := map[string]interface{}{ "offset": offset, "limit": limit, @@ -473,9 +492,27 @@ func (a *API) OrderBatchPullPhoneNumber(poiCode string, offset, limit int) (real } result, err := a.AccessAPI("order/batchPullPhoneNumber", false, params) if err == nil { - return utils.Slice2MapSlice(result.([]interface{})), nil + err = utils.Map2StructByJson(result, &realNumberList, false) } - return nil, err + return realNumberList, err +} + +// 拉取骑手真实手机号(必接),美团2019-09-17才开始灰度上线 +// https://developer.waimai.meituan.com/home/docDetail/388 +// limit最大为MaxBatchPullPhoneNumberLimit = 1000 +func (a *API) OrderGetRiderInfoPhoneNumber(poiCode string, offset, limit int) (realNumberList []*RiderRealPhoneNumberInfo, err error) { + params := map[string]interface{}{ + "offset": offset, + "limit": limit, + } + if poiCode != "" { + params[KeyAppPoiCode] = poiCode + } + result, err := a.AccessAPI("order/getRiderInfoPhoneNumber", false, params) + if err == nil { + err = utils.Map2StructByJson(result, &realNumberList, false) + } + return realNumberList, err } // 专快混配送转为商家自配送 diff --git a/platformapi/mtwmapi/order_test.go b/platformapi/mtwmapi/order_test.go index 838ac1d5..444d3130 100644 --- a/platformapi/mtwmapi/order_test.go +++ b/platformapi/mtwmapi/order_test.go @@ -80,14 +80,19 @@ func TestOrderLogisticsStatus(t *testing.T) { } func TestOrderBatchPullPhoneNumber(t *testing.T) { - result, err := api.OrderBatchPullPhoneNumber(testPoiCode, 0, 10) + result, err := api.OrderBatchPullPhoneNumber(testPoiCode, 0, MaxBatchPullPhoneNumberLimit) + t.Log(utils.Format4Output(result, false)) if err != nil { t.Fatal(err) } - if len(result) == 0 { - t.Fatal("result should have value") +} + +func TestOrderGetRiderInfoPhoneNumber(t *testing.T) { + result, err := api.OrderGetRiderInfoPhoneNumber(testPoiCode, 0, MaxBatchPullPhoneNumberLimit) + t.Log(utils.Format4Output(result, false)) + if err != nil { + t.Fatal(err) } - // t.Log(utils.Format4Output(result, false)) } func TestGetOrderRefundDetail(t *testing.T) { From cd08000879e6391834690b1ac7501dd3d3df8bd7 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 4 Sep 2019 16:31:56 +0800 Subject: [PATCH 36/71] =?UTF-8?q?-=20jdapi.handleBatchOpResult=E4=B8=AD?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E5=88=A4=E6=96=ADinErr=E5=B0=B1=E8=A7=A3?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/store_sku.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platformapi/jdapi/store_sku.go b/platformapi/jdapi/store_sku.go index 45dd44e9..cee2f4cf 100644 --- a/platformapi/jdapi/store_sku.go +++ b/platformapi/jdapi/store_sku.go @@ -149,7 +149,7 @@ func (a *API) GetStationInfoList(stationNo string, skuIds []int64) (priceInfo [] } func (a *API) handleBatchOpResult(batchCount int, inErr error, result interface{}, tagName string) (responseList []*StoreSkuBatchUpdateResponse, err error) { - if inErr != nil { + if result != nil { if err = utils.Map2Struct(result, &responseList, true, tagName); err == nil { var failedList []*StoreSkuBatchUpdateResponse for _, v := range responseList { @@ -257,6 +257,7 @@ func (a *API) BatchUpdateVendibility(trackInfo, outStationNo, stationNo string, } else { jdParams["stationNo"] = stationNo } + // 此函数在全部失败时,err仍然返回成功 result, err := a.AccessAPINoPage2("stock/batchUpdateVendibility", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"), trackInfo) if result != nil { var err2 error From a464da447650bebac44969352d523fa80b704698 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 5 Sep 2019 18:22:28 +0800 Subject: [PATCH 37/71] + GetByOrderNoForOaosNew --- platformapi/jdapi/order.go | 13 +++++++++++++ platformapi/jdapi/order_test.go | 12 ++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/platformapi/jdapi/order.go b/platformapi/jdapi/order.go index 8a75d2a7..f1b62f5b 100644 --- a/platformapi/jdapi/order.go +++ b/platformapi/jdapi/order.go @@ -707,6 +707,19 @@ func (a *API) GetByOrderNoForOaos(orderNo string) (orderTrackList []*OrderTrack, return orderTrackList, err } +// 新版根据订单号查询订单跟踪接口 +// https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=169&apiid=6450cd91dd5b4dc0bb6a6cd17af6d0a4 +func (a *API) GetByOrderNoForOaosNew(orderID string) (orderTrackList []*OrderTrack, err error) { + jdParams := map[string]interface{}{ + "orderId": orderID, + } + result, err := a.AccessAPINoPage("orderTrace/getByOrderNoForOaosNew", jdParams, nil, nil, genNoPageResultParser("code", "detail", "result", "0")) + if err == nil { + err = utils.Map2StructByJson(result.(map[string]interface{})["orderTrackList"], &orderTrackList, false) + } + return orderTrackList, err +} + // 订单自提码核验接口 // https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=169&apiid=428fa2cb66784b64a85db36ec2972ff9 func (a *API) CheckSelfPickCode(selfPickCode, orderID, operPin string) (err error) { diff --git a/platformapi/jdapi/order_test.go b/platformapi/jdapi/order_test.go index 2513f0ee..b95119c4 100644 --- a/platformapi/jdapi/order_test.go +++ b/platformapi/jdapi/order_test.go @@ -238,7 +238,15 @@ func TestOrderQuery2(t *testing.T) { } func TestGetByOrderNoForOaos(t *testing.T) { - orderList, err := api.GetByOrderNoForOaos("921160248000222") + orderList, err := api.GetByOrderNoForOaos("921235438000341") + t.Log(utils.Format4Output(orderList, false)) + if err != nil { + t.Fatal(err.Error()) + } +} + +func TestGetByOrderNoForOaosNew(t *testing.T) { + orderList, err := api.GetByOrderNoForOaosNew("921235438000341") t.Log(utils.Format4Output(orderList, false)) if err != nil { t.Fatal(err.Error()) @@ -246,7 +254,7 @@ func TestGetByOrderNoForOaos(t *testing.T) { } func TestCheckSelfPickCode(t *testing.T) { - err := api.CheckSelfPickCode("", "921241806000842", "test") + err := api.CheckSelfPickCode("020606", "921235438000341", "test") if err != nil { t.Fatal(err.Error()) } From 5bbde530b0458e2d97f6634846641b8830e48cc3 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 6 Sep 2019 17:28:05 +0800 Subject: [PATCH 38/71] - up --- platformapi/ebaiapi/shop_sku.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformapi/ebaiapi/shop_sku.go b/platformapi/ebaiapi/shop_sku.go index 2a09db57..c5af6b31 100644 --- a/platformapi/ebaiapi/shop_sku.go +++ b/platformapi/ebaiapi/shop_sku.go @@ -237,7 +237,7 @@ func (a *API) ShopCategoryCreate(shopID string, parentID int64, name string, ran func (a *API) ShopCategoryGet(shopID string) (cats []*CategoryInfo, err error) { result, err := a.AccessAPI("sku.shop.category.get", utils.Params2Map(KeyShopID, shopID)) if err == nil { - if inMap, ok := result.Data.(map[string]interface{}); ok { // fuck it + if inMap, ok := result.Data.(map[string]interface{}); ok { cats := interface2CatList(inMap["categorys"], 1) return cats, nil } From 882c4ff53154f3591f5c06552dbc0f899b89e9c9 Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 9 Sep 2019 13:52:40 +0800 Subject: [PATCH 39/71] =?UTF-8?q?-=20ShopCategoryUpdate=E4=B8=AD=E4=B8=8D?= =?UTF-8?q?=E5=BF=BD=E7=95=A5=E5=90=8C=E5=90=8D=E9=94=99=E8=AF=AF.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/shop_sku.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/platformapi/ebaiapi/shop_sku.go b/platformapi/ebaiapi/shop_sku.go index c5af6b31..5018704f 100644 --- a/platformapi/ebaiapi/shop_sku.go +++ b/platformapi/ebaiapi/shop_sku.go @@ -252,11 +252,13 @@ func (a *API) ShopCategoryUpdate(shopID string, categoryID int64, name string, r "name": name, "rank": rank, }) - if errWithCode, ok := err.(*utils.ErrorWithCode); ok { - if errWithCode.Level() == 0 && errWithCode.IntCode() == 1 { //忽略同名错误 - err = nil - } - } + + // todo, 之前为什么要忽略同名错误? + // if errWithCode, ok := err.(*utils.ErrorWithCode); ok { + // if errWithCode.Level() == 0 && errWithCode.IntCode() == 1 { //忽略同名错误 + // err = nil + // } + // } return err } From a1c5ec77ff68f69d990d3593fb04a47842fc4e76 Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 9 Sep 2019 14:24:05 +0800 Subject: [PATCH 40/71] - fk --- platformapi/ebaiapi/shop_sku.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/platformapi/ebaiapi/shop_sku.go b/platformapi/ebaiapi/shop_sku.go index 5018704f..f4caaf28 100644 --- a/platformapi/ebaiapi/shop_sku.go +++ b/platformapi/ebaiapi/shop_sku.go @@ -252,13 +252,6 @@ func (a *API) ShopCategoryUpdate(shopID string, categoryID int64, name string, r "name": name, "rank": rank, }) - - // todo, 之前为什么要忽略同名错误? - // if errWithCode, ok := err.(*utils.ErrorWithCode); ok { - // if errWithCode.Level() == 0 && errWithCode.IntCode() == 1 { //忽略同名错误 - // err = nil - // } - // } return err } From 938b28e5a83f5522e0014f843f8233491a8a59e6 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 10 Sep 2019 14:22:49 +0800 Subject: [PATCH 41/71] =?UTF-8?q?-=20=E5=86=85=E5=B5=8CAPICookie=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E5=88=A0=E9=99=A4=E4=B8=80=E4=BA=9B=E5=86=97=E4=BD=99?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E6=88=90=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/ebaiapi.go | 13 ++++--------- platformapi/ebaiapi/shop_sku_test.go | 4 ++-- platformapi/jdapi/jdapi.go | 4 ---- platformapi/jdapi/jdapi_test.go | 2 +- platformapi/jdapi/store_page_test.go | 10 +++++----- platformapi/mtwmapi/mtwmapi.go | 6 ------ platformapi/platformapi_cookie.go | 18 +++++++++--------- 7 files changed, 21 insertions(+), 36 deletions(-) diff --git a/platformapi/ebaiapi/ebaiapi.go b/platformapi/ebaiapi/ebaiapi.go index b3b5f50b..78bdfe8a 100644 --- a/platformapi/ebaiapi/ebaiapi.go +++ b/platformapi/ebaiapi/ebaiapi.go @@ -7,7 +7,6 @@ import ( "net/url" "sort" "strings" - "sync" "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/platformapi" @@ -43,9 +42,6 @@ type API struct { config *platformapi.APIConfig speedLimiter *platformapi.Limiter supplierID int64 - - locker sync.RWMutex - storeCookies map[string]string } func New(source, secret string, config ...*platformapi.APIConfig) *API { @@ -60,7 +56,6 @@ func New(source, secret string, config ...*platformapi.APIConfig) *API { client: &http.Client{Timeout: curConfig.ClientTimeout}, config: &curConfig, speedLimiter: platformapi.New(apiLimitConfigs, nil), //defaultAPILimitConfig), - storeCookies: make(map[string]string), supplierID: -1, } @@ -155,12 +150,12 @@ func (a *API) AccessAPI(cmd string, body map[string]interface{}) (retVal *Respon } func (a *API) GetSupplierID() (supplierID int64) { - a.locker.RLock() + a.RLock() supplierID = a.supplierID - a.locker.RUnlock() + a.RUnlock() if supplierID < 0 { - a.locker.Lock() - defer a.locker.Unlock() + a.Lock() + defer a.Unlock() a.supplierID = 0 if shopList, err := a.ShopList(SysStatusAll); err == nil { diff --git a/platformapi/ebaiapi/shop_sku_test.go b/platformapi/ebaiapi/shop_sku_test.go index d55f5e58..c9649afa 100644 --- a/platformapi/ebaiapi/shop_sku_test.go +++ b/platformapi/ebaiapi/shop_sku_test.go @@ -16,7 +16,7 @@ func TestShopCategoryCreate(t *testing.T) { } func TestShopCategoryGet(t *testing.T) { - result, err := api.ShopCategoryGet("102493") + result, err := api.ShopCategoryGet("300034") if err != nil { t.Fatal(err) } else { @@ -69,7 +69,7 @@ func TestSkuUploadRTF(t *testing.T) { } func TestSkuCreate(t *testing.T) { - result, err := api.SkuCreate(testShopID, 17, map[string]interface{}{ + result, err := api.SkuCreate("", testShopID, 17, map[string]interface{}{ "name": "测试商品", "status": SkuStatusOnline, "left_num": MaxLeftNum, diff --git a/platformapi/jdapi/jdapi.go b/platformapi/jdapi/jdapi.go index c6cbe5e4..a2afb720 100644 --- a/platformapi/jdapi/jdapi.go +++ b/platformapi/jdapi/jdapi.go @@ -7,7 +7,6 @@ import ( "net/http" "sort" "strings" - "sync" "git.rosy.net.cn/baseapi" @@ -66,9 +65,6 @@ type API struct { appSecret string client *http.Client config *platformapi.APIConfig - - locker sync.RWMutex - storeCookie string } var ( diff --git a/platformapi/jdapi/jdapi_test.go b/platformapi/jdapi/jdapi_test.go index 40b459f9..957260c2 100644 --- a/platformapi/jdapi/jdapi_test.go +++ b/platformapi/jdapi/jdapi_test.go @@ -27,7 +27,7 @@ func init() { // 天天果园 // api = New("84541069-fbe2-424b-b625-9b2ba1d4c9e6", "5d5577a2506f41b8b4ec520ba83490f5", "0b01b9eeb15b41dab1c3d05d95c17a26") - const cookieValue = "YYJV3NHVBPHLD36FWP6F3EM5PTXJ2XZQS7U4HWRIDPP4IWGUKUIB4XG5N26CZRDLDF7PKOXBPD6BNTUAJLETLZOIWMCVFI3K6MYZIY4QBIXIMXYDJNUKFGJVQTN5356SAD6WPCIHWNQAG7DDMF7L7S3SHDYZP7PPVMRGO4VWG2JRBMKFTOGIWZ5L2XHXC3SXQ4OLX7EL4RKUPZQT6GOH63KE3EVK37L5LG7TGSDGXFQP4377YK72UB5YZG6IJH6PY25YLLCJYPMDSHKPGYBUFJ4MMMKGN6MWB37CP7XVDBBZJ3U462ENTEXH744AWCQCIG2AAE2PKYVHC" + const cookieValue = "YYJV3NHVBPHLD36FWP6F3EM5PTXJ2XZQS7U4HWRIDPP4IWGUKUIB4XG5N26CZRDLDF7PKOXBPD6BNTUAJLETLZOIWMCVFI3K6MYZIY4QBIXIMXYDJNUKFGJVQTN5356SAD6WPCIHWNQAG7DDMF7L7S3SHCT3RM3CQG7IJIPUQ3THS5UIUYWMKINM7ETUOQB7OBPOPZVCT3ZJY55243TDVXLO25PP4UYSPTTPMNQ7HPMWOJKJ3BJWGVHD243MXH7NZWW264TKN5UOCJBSSSOKD2QQII" api.SetCookie(accessStorePageCookieName, cookieValue) api.SetCookie(accessStorePageCookieName2, cookieValue) } diff --git a/platformapi/jdapi/store_page_test.go b/platformapi/jdapi/store_page_test.go index c137ee02..cc2f4045 100644 --- a/platformapi/jdapi/store_page_test.go +++ b/platformapi/jdapi/store_page_test.go @@ -8,9 +8,9 @@ import ( ) func TestGetRealMobileNumber4Order(t *testing.T) { - orderId := "910170516000941" - desiredMobile := "13398196274" - mobile, err := api.GetRealMobile4Order(orderId, "") + orderId := "921823424000122" + desiredMobile := "13722455105" + mobile, err := api.GetRealMobile4Order(orderId, "11893205") if err != nil { t.Fatal(err) } @@ -21,8 +21,8 @@ func TestGetRealMobileNumber4Order(t *testing.T) { } func TestGetStoreOrderInfo(t *testing.T) { - orderId := "910170516000941" - orderInfo, err := api.GetStoreOrderInfo(orderId, "") + orderId := "921823424000122" + orderInfo, err := api.GetStoreOrderInfo(orderId, "11893205") if err != nil { t.Fatal(err) } diff --git a/platformapi/mtwmapi/mtwmapi.go b/platformapi/mtwmapi/mtwmapi.go index 0a1adc1a..972f3261 100644 --- a/platformapi/mtwmapi/mtwmapi.go +++ b/platformapi/mtwmapi/mtwmapi.go @@ -9,7 +9,6 @@ import ( "net/url" "sort" "strings" - "sync" "time" "git.rosy.net.cn/baseapi" @@ -60,9 +59,6 @@ type API struct { callbackURL string client *http.Client config *platformapi.APIConfig - - locker sync.RWMutex - userCookies map[string]string } var ( @@ -85,8 +81,6 @@ func New(appID, secret, callbackURL string, config ...*platformapi.APIConfig) *A callbackURL: callbackURL, client: &http.Client{Timeout: curConfig.ClientTimeout}, config: &curConfig, - - userCookies: make(map[string]string), } } diff --git a/platformapi/platformapi_cookie.go b/platformapi/platformapi_cookie.go index 90a7bd9b..e6dd8998 100644 --- a/platformapi/platformapi_cookie.go +++ b/platformapi/platformapi_cookie.go @@ -11,7 +11,7 @@ import ( ) type APICookie struct { - locker sync.RWMutex + sync.RWMutex storeCookies map[string]string } @@ -44,28 +44,28 @@ func (a *APICookie) SetCookieWithStr(cookieStr string) { } func (a *APICookie) SetCookie(key, value string) { - a.locker.Lock() - defer a.locker.Unlock() + a.Lock() + defer a.Unlock() a.createMapIfNeeded() a.storeCookies[key] = value } func (a *APICookie) GetCookie(key string) string { - a.locker.RLock() - defer a.locker.RUnlock() + a.RLock() + defer a.RUnlock() a.createMapIfNeeded() return a.storeCookies[key] } func (a *APICookie) GetCookieCount() int { - a.locker.RLock() - defer a.locker.RUnlock() + a.RLock() + defer a.RUnlock() return len(a.storeCookies) } func (a *APICookie) FillRequestCookies(r *http.Request) *http.Request { - a.locker.RLock() - defer a.locker.RUnlock() + a.RLock() + defer a.RUnlock() for k, v := range a.storeCookies { r.AddCookie(&http.Cookie{ Name: k, From 77c80f18d7a05e4bc427a6869d027f1d46ce5510 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 10 Sep 2019 17:58:19 +0800 Subject: [PATCH 42/71] =?UTF-8?q?-=20=E7=BE=8E=E5=9B=A2=E5=A4=96=E5=8D=96p?= =?UTF-8?q?ick=5Ftype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/mtwmapi/order.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platformapi/mtwmapi/order.go b/platformapi/mtwmapi/order.go index 03066c16..803ee838 100644 --- a/platformapi/mtwmapi/order.go +++ b/platformapi/mtwmapi/order.go @@ -67,6 +67,11 @@ const ( NotifyTypeCancelRefundComplaint = "cancelRefundComplaint" // 用户取消退款申诉 ) +const ( + OrderPickTypeNormal = 0 // 普通(配送) + OrderPickTypeSelf = 1 // 用户到店自取 +) + const ( UserApplyCancelWaitMinute = 30 // 用户申请退款后,商家未在30分钟内(大连锁商家为3小时内)处理退款请求,系统将自动同意退款 ) From 7e2dfd070b48ad778d115e75d60a849d0a5c2901 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 11 Sep 2019 10:41:53 +0800 Subject: [PATCH 43/71] =?UTF-8?q?-=20jdapi=20store=20page=E4=B8=ADAccessSt?= =?UTF-8?q?orePage=E7=A9=BA=E6=8C=87=E9=92=88bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/autonavi/autonavi_test.go | 2 +- platformapi/jdapi/store_page.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platformapi/autonavi/autonavi_test.go b/platformapi/autonavi/autonavi_test.go index 81c2d857..4e21dd05 100644 --- a/platformapi/autonavi/autonavi_test.go +++ b/platformapi/autonavi/autonavi_test.go @@ -19,7 +19,7 @@ func init() { sugarLogger = logger.Sugar() baseapi.Init(sugarLogger) - autonaviAPI = New("4427170f870af2110becb8852d36ab08") + autonaviAPI = New("ef64f638f31e05cb7bde28790f7309fe") } func TestCoordinateConvert(t *testing.T) { diff --git a/platformapi/jdapi/store_page.go b/platformapi/jdapi/store_page.go index 9268f9af..f5337ea2 100644 --- a/platformapi/jdapi/store_page.go +++ b/platformapi/jdapi/store_page.go @@ -255,7 +255,7 @@ func (a *API) AccessStorePage2(fullURL string, params map[string]interface{}, is func (a *API) AccessStorePage(fullURL string, params map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) { result, err := a.AccessStorePage2(fullURL, params, isPost, ResultKeyResult) if err == nil { - retVal = result.(map[string]interface{}) + retVal, _ = result.(map[string]interface{}) } return retVal, err } From e4fc1901b5d0fe1a01d2444085fcc8cb5431f768 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 11 Sep 2019 14:45:29 +0800 Subject: [PATCH 44/71] =?UTF-8?q?-=20=E9=A5=BF=E7=99=BE=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=8B=89=E5=8F=96=E6=96=B9=E6=B3=95=E8=B0=83=E6=95=B4GetStoreL?= =?UTF-8?q?ist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/store_page.go | 39 ++++++++++++++++++++------ platformapi/ebaiapi/store_page_test.go | 4 +-- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/platformapi/ebaiapi/store_page.go b/platformapi/ebaiapi/store_page.go index e3ddfa4f..6743c2db 100644 --- a/platformapi/ebaiapi/store_page.go +++ b/platformapi/ebaiapi/store_page.go @@ -515,22 +515,45 @@ func (a *API) PageGetCustomCatList(baiduShopID int64) (catList []map[string]inte return nil, err } -func (a *API) GetStoreList(lng string, lat string) (retVal map[string]interface{}, err error) { +func (a *API) GetStoreList(lng string, lat string, pageNo, pageSize int) (shopListInfo *PageListInfo, err error) { + if pageNo <= 0 { + pageNo = 1 + } + if pageSize > 20 || pageSize <= 0 { + pageSize = 20 + } params := map[string]interface{}{ "channel": "kitchen", - "pn": 1, - "rn": 999, + "rn": pageSize, + "pn": pageNo, "lng": lng, "lat": lat, } - retVal, err = a.AccessStorePageNoCookie("/newretail/main/shoplist", params) - return retVal, err + result, err := a.AccessStorePageNoCookie("newretail/main/shoplist", params) + if err == nil && result != nil { + err = utils.Map2StructByJson(result, &shopListInfo, true) + } + return shopListInfo, err } func (a *API) GetStoreList2(lng float64, lat float64) (shopListInfo *PageListInfo, err error) { - retVal, err := a.GetStoreList(fmt.Sprintf("%.6f", lng), fmt.Sprintf("%.6f", lat)) - if err == nil { - err = utils.Map2StructByJson(retVal, &shopListInfo, true) + pageSize := 20 + pageNo := 1 + for { + retVal, err2 := a.GetStoreList(fmt.Sprintf("%.6f", lng), fmt.Sprintf("%.6f", lat), pageNo, pageSize) + if err = err2; err == nil { + if shopListInfo == nil { + shopListInfo = retVal + } else { + shopListInfo.ShopList = append(shopListInfo.ShopList, retVal.ShopList...) + if len(retVal.ShopList) < pageSize { + break + } + } + pageNo++ + } else { + break + } } return shopListInfo, err } diff --git a/platformapi/ebaiapi/store_page_test.go b/platformapi/ebaiapi/store_page_test.go index ca6bc4b4..7537fe8f 100644 --- a/platformapi/ebaiapi/store_page_test.go +++ b/platformapi/ebaiapi/store_page_test.go @@ -107,7 +107,7 @@ func TestGetShopHealthByDetail(t *testing.T) { } func TestGetStoreList(t *testing.T) { - result, err := api.GetStoreList("104.057218", "30.6949") + result, err := api.GetStoreList("104.057218", "30.6949", 0, 0) if err != nil { t.Fatal(err) } @@ -115,7 +115,7 @@ func TestGetStoreList(t *testing.T) { } func TestGetStoreList2(t *testing.T) { - result, err := api.GetStoreList2(120.074911, 29.306863) + result, err := api.GetStoreList2(104.010554, 30.637072) if err != nil { t.Fatal(err) } From 6fb31375cb5d4d3c764d828ca55fcf50804660d0 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 11 Sep 2019 16:27:58 +0800 Subject: [PATCH 45/71] + ebaiapi.PageShopInfo.MedicineQualification --- platformapi/ebaiapi/store_page.go | 71 +++++++++++++++++-------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/platformapi/ebaiapi/store_page.go b/platformapi/ebaiapi/store_page.go index 6743c2db..2cc075f3 100644 --- a/platformapi/ebaiapi/store_page.go +++ b/platformapi/ebaiapi/store_page.go @@ -263,39 +263,44 @@ type PageShopInfo struct { Tag []interface{} `json:"tag"` Text string `json:"text"` } `json:"delivery_mode"` - Description string `json:"description"` - DisplayRefundLabel int `json:"display_refund_label"` - Distance int `json:"distance"` - EleBusinessState int `json:"ele_business_state"` - EleID string `json:"ele_id"` - FirstOpenTime *BussinessTimeInfo `json:"first_open_time"` - HitGod int `json:"hit_god"` - ImagePath string `json:"image_path"` - IsColdChain int `json:"is_cold_chain"` - IsDoubleTwelve int `json:"is_double_twelve"` - IsMedicineShop int `json:"is_medicine_shop"` - IsOwnTheme int `json:"is_own_theme"` - Latitude float64 `json:"latitude"` - Longitude float64 `json:"longitude"` - MedicineQualification []interface{} `json:"medicine_qualification"` - Name string `json:"name"` - NewStyle bool `json:"new_style"` - OTakoutCost int `json:"o_takout_cost"` - OTakoutPrice int `json:"o_takout_price"` - OrderLeadTime interface{} `json:"order_lead_time"` - Phone string `json:"phone"` - PromotionInfo string `json:"promotion_info"` - Qualification string `json:"qualification"` - RecentOrderNum int `json:"recent_order_num"` - ShopID string `json:"shop_id"` - ShopScore float64 `json:"shop_score"` - ShopSourceFrom int `json:"shop_source_from"` - SkuCount int `json:"sku_count"` - TakeoutCost int `json:"takeout_cost"` - TakeoutInvoice int `json:"takeout_invoice"` - TakeoutInvoiceMinPrice string `json:"takeout_invoice_min_price"` - TakeoutOpenTime string `json:"takeout_open_time"` - TakeoutPrice int `json:"takeout_price"` + Description string `json:"description"` + DisplayRefundLabel int `json:"display_refund_label"` + Distance int `json:"distance"` + EleBusinessState int `json:"ele_business_state"` + EleID string `json:"ele_id"` + FirstOpenTime *BussinessTimeInfo `json:"first_open_time"` + HitGod int `json:"hit_god"` + ImagePath string `json:"image_path"` + IsColdChain int `json:"is_cold_chain"` + IsDoubleTwelve int `json:"is_double_twelve"` + IsMedicineShop int `json:"is_medicine_shop"` + IsOwnTheme int `json:"is_own_theme"` + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + MedicineQualification []*struct { + AptitudeName string `json:"aptitude_name"` + AptitudePhoto []string `json:"aptitude_photo"` + AptitudeType string `json:"aptitude_type"` + LicenseNumber string `json:"license_number"` + } `json:"medicine_qualification"` + Name string `json:"name"` + NewStyle bool `json:"new_style"` + OTakoutCost int `json:"o_takout_cost"` + OTakoutPrice int `json:"o_takout_price"` + OrderLeadTime interface{} `json:"order_lead_time"` + Phone string `json:"phone"` + PromotionInfo string `json:"promotion_info"` + Qualification string `json:"qualification"` + RecentOrderNum int `json:"recent_order_num"` + ShopID string `json:"shop_id"` + ShopScore float64 `json:"shop_score"` + ShopSourceFrom int `json:"shop_source_from"` + SkuCount int `json:"sku_count"` + TakeoutCost int `json:"takeout_cost"` + TakeoutInvoice int `json:"takeout_invoice"` + TakeoutInvoiceMinPrice string `json:"takeout_invoice_min_price"` + TakeoutOpenTime string `json:"takeout_open_time"` + TakeoutPrice int `json:"takeout_price"` } func (a *API) AccessStorePage2(subURL string, params map[string]interface{}, isPost bool, cookies map[string]string) (retVal map[string]interface{}, err error) { From 9b1e3dfc2f5e115587cee0f8406c843525659ddc Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 11 Sep 2019 20:45:11 +0800 Subject: [PATCH 46/71] - up --- platformapi/ebaiapi/store_page.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platformapi/ebaiapi/store_page.go b/platformapi/ebaiapi/store_page.go index 2cc075f3..bd29b938 100644 --- a/platformapi/ebaiapi/store_page.go +++ b/platformapi/ebaiapi/store_page.go @@ -551,9 +551,9 @@ func (a *API) GetStoreList2(lng float64, lat float64) (shopListInfo *PageListInf shopListInfo = retVal } else { shopListInfo.ShopList = append(shopListInfo.ShopList, retVal.ShopList...) - if len(retVal.ShopList) < pageSize { - break - } + } + if len(retVal.ShopList) < pageSize { + break } pageNo++ } else { From 48265441e2df681f8b4e8f8d112c3c183e0f2f00 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 12 Sep 2019 11:04:57 +0800 Subject: [PATCH 47/71] =?UTF-8?q?-=20TryInterface2Int64=E5=92=8CTryInterfa?= =?UTF-8?q?ce2Float64=E5=85=BC=E5=AE=B9string?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/typeconv.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/utils/typeconv.go b/utils/typeconv.go index df233bca..123a6b9c 100644 --- a/utils/typeconv.go +++ b/utils/typeconv.go @@ -7,6 +7,7 @@ import ( "fmt" "math" "net/url" + "reflect" "strconv" "strings" "time" @@ -70,15 +71,13 @@ func TryInterface2Int64(data interface{}) (num int64, err error) { if dataNumber, ok := data.(int); ok { return int64(dataNumber), nil } - dataNumber, ok := data.(json.Number) - if !ok { - return 0, fmt.Errorf("data is not json.Number:%v to int64", data) + if dataNumber, ok := data.(json.Number); ok { + return dataNumber.Int64() } - retVal, err := dataNumber.Int64() - if err != nil { - return num, err + if str, ok := data.(string); ok { + return Str2Int64(str), nil } - return retVal, nil + return 0, fmt.Errorf("data is not json.Number, it's %s, value:%v", reflect.TypeOf(data).String(), data) } func MustInterface2Int64(data interface{}) int64 { @@ -114,15 +113,13 @@ func TryInterface2Float64(data interface{}) (num float64, err error) { if dataNumber, ok := data.(float32); ok { return float64(dataNumber), nil } - dataNumber, ok := data.(json.Number) - if !ok { - return num, fmt.Errorf("data is not json.Number:%v", data) + if dataNumber, ok := data.(json.Number); ok { + return dataNumber.Float64() } - retVal, err := dataNumber.Float64() - if err != nil { - return num, err + if str, ok := data.(string); ok { + return Str2Float64(str), nil } - return retVal, nil + return 0, fmt.Errorf("data is not json.Number, it's %s, value:%v", reflect.TypeOf(data).String(), data) } func MustInterface2Float64(data interface{}) float64 { From a4768603db9d003c79e9dc587057943516d22d90 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 12 Sep 2019 15:16:15 +0800 Subject: [PATCH 48/71] - CommonShopCities --- platformapi/ebaiapi/common.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/platformapi/ebaiapi/common.go b/platformapi/ebaiapi/common.go index 49de80ec..4bdf8573 100644 --- a/platformapi/ebaiapi/common.go +++ b/platformapi/ebaiapi/common.go @@ -15,18 +15,7 @@ type CityInfo struct { func (a *API) CommonShopCities(parentID int) (cityList []*CityInfo, err error) { result, err := a.AccessAPI("common.shopcities", utils.Params2Map("pid", parentID)) if err == nil { - cityMapList := utils.Slice2MapSlice(result.Data.([]interface{})) - // baseapi.SugarLogger.Debug(utils.Format4Output(cityMapList, false)) - cityList = make([]*CityInfo, len(cityMapList)) - for k, v := range cityMapList { - cityList[k] = &CityInfo{ - ID: int(utils.Str2Int64(utils.Interface2String(v["city_id"]))), - Name: utils.Interface2String(v["city_name"]), - ParentID: int(utils.Str2Int64(utils.Interface2String(v["parent_id"]))), - IsOpen: int(utils.Str2Int64(utils.Interface2String(v["is_open"]))), - } - } - return cityList, nil + err = utils.Map2StructByJson(result.Data, &cityList, true) } - return nil, err + return cityList, err } From 09c9d49a45b1a38a0713ab98cd4cacd732b82431 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 13 Sep 2019 10:56:54 +0800 Subject: [PATCH 49/71] =?UTF-8?q?-=20TryInterface2Int64=E4=B8=8ETryInterfa?= =?UTF-8?q?ce2Float64=EF=BC=8C=E5=9C=A8=E8=BD=AC=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E4=B8=BA=E6=95=B0=E5=AD=97=E4=B8=8D=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E4=B8=8D=E6=8A=A5=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/typeconv.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/typeconv.go b/utils/typeconv.go index 123a6b9c..bf562356 100644 --- a/utils/typeconv.go +++ b/utils/typeconv.go @@ -75,7 +75,7 @@ func TryInterface2Int64(data interface{}) (num int64, err error) { return dataNumber.Int64() } if str, ok := data.(string); ok { - return Str2Int64(str), nil + return Str2Int64WithDefault(str, 0), nil } return 0, fmt.Errorf("data is not json.Number, it's %s, value:%v", reflect.TypeOf(data).String(), data) } @@ -117,7 +117,7 @@ func TryInterface2Float64(data interface{}) (num float64, err error) { return dataNumber.Float64() } if str, ok := data.(string); ok { - return Str2Float64(str), nil + return Str2Float64WithDefault(str, 0), nil } return 0, fmt.Errorf("data is not json.Number, it's %s, value:%v", reflect.TypeOf(data).String(), data) } From 4732ba5b46fe057bd2cc7e6f065b3e9e20c99c6d Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 13 Sep 2019 16:50:08 +0800 Subject: [PATCH 50/71] =?UTF-8?q?-=20ebaiapi,=20TakeoutPrice,=20TakeoutInv?= =?UTF-8?q?oice=E5=92=8CTakeoutCost=E6=94=B9=E4=B8=BA=E4=BB=8Eint=E6=94=B9?= =?UTF-8?q?=E4=B8=BAfloat64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/store_page.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/platformapi/ebaiapi/store_page.go b/platformapi/ebaiapi/store_page.go index bd29b938..c8349d90 100644 --- a/platformapi/ebaiapi/store_page.go +++ b/platformapi/ebaiapi/store_page.go @@ -197,7 +197,7 @@ type PageListInnerShopInfo struct { ShopLabels string `json:"shop_labels"` ShopName string `json:"shop_name"` TakeoutCost float64 `json:"takeout_cost"` - TakeoutPrice int `json:"takeout_price"` + TakeoutPrice float64 `json:"takeout_price"` Type interface{} `json:"type"` WelfareInfo []struct { IconColor struct { @@ -296,11 +296,11 @@ type PageShopInfo struct { ShopScore float64 `json:"shop_score"` ShopSourceFrom int `json:"shop_source_from"` SkuCount int `json:"sku_count"` - TakeoutCost int `json:"takeout_cost"` - TakeoutInvoice int `json:"takeout_invoice"` + TakeoutCost float64 `json:"takeout_cost"` + TakeoutInvoice float64 `json:"takeout_invoice"` TakeoutInvoiceMinPrice string `json:"takeout_invoice_min_price"` TakeoutOpenTime string `json:"takeout_open_time"` - TakeoutPrice int `json:"takeout_price"` + TakeoutPrice float64 `json:"takeout_price"` } func (a *API) AccessStorePage2(subURL string, params map[string]interface{}, isPost bool, cookies map[string]string) (retVal map[string]interface{}, err error) { From 3764e05b14d33d40ecfd8441021d6820affe2034 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 18 Sep 2019 17:21:40 +0800 Subject: [PATCH 51/71] - up --- platformapi/mtwmapi/retail.go | 1 + 1 file changed, 1 insertion(+) diff --git a/platformapi/mtwmapi/retail.go b/platformapi/mtwmapi/retail.go index 856c2cef..fe3249ff 100644 --- a/platformapi/mtwmapi/retail.go +++ b/platformapi/mtwmapi/retail.go @@ -113,6 +113,7 @@ type AppFoodResult struct { // 创建二级分类,secondaryName为二级分类名, // (如果originName为空,同时创建一级分类,所以如果只是创建二级分类,originName与name要填一样的,此时sequence指的二级分类的sequence,一级分类的sequence为缺省值) // 修改二级分类,originName为二级分类名,name为二级分类新名,secondaryName为空 +// https://developer.waimai.meituan.com/home/questionDetail/4669 func (a *API) RetailCatUpdate(poiCode, originName, name, secondaryName string, sequence int) (err error) { params := map[string]interface{}{ KeyAppPoiCode: poiCode, From 0d10f7897af58ef8915019e54bafd2e9173763c0 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 19 Sep 2019 14:56:57 +0800 Subject: [PATCH 52/71] =?UTF-8?q?-=20=E6=A0=87=E5=87=86=E5=8C=96=E4=BA=AC?= =?UTF-8?q?=E4=B8=9C=E5=88=B0=E5=AE=B6=E9=97=A8=E5=BA=97=E7=9B=B8=E5=85=B3?= =?UTF-8?q?API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/store.go | 223 ++++++++++++++++++++++++++++---- platformapi/jdapi/store_test.go | 78 ++++++----- 2 files changed, 239 insertions(+), 62 deletions(-) diff --git a/platformapi/jdapi/store.go b/platformapi/jdapi/store.go index 91812604..a6c42796 100644 --- a/platformapi/jdapi/store.go +++ b/platformapi/jdapi/store.go @@ -29,6 +29,12 @@ const ( KeyStandByPhone = "standByPhone" ) +const ( + CarrierNoCrowdSourcing = 9966 // 众包 + CarrierNoSelfDelivery = 2938 // 自送 + CarrierNoSelfTake = 9999 // 到店自提 +) + type CreateShopResult struct { DeliveryRangeType int `json:"deliveryRangeType"` CoordinatePoints string `json:"coordinatePoints"` @@ -44,11 +50,164 @@ type CityInfo struct { Yn int `json:"yn"` } -const ( - CarrierNoCrowdSourcing = 9966 // 众包 - CarrierNoSelfDelivery = 2938 // 自送 - CarrierNoSelfTake = 9999 // 到店自提 -) +type OpStoreParams struct { + // 以下可用于修改(及查询) + StationNo string `json:"stationNo"` // 强制参数,主键 + StationName string `json:"stationName,omitempty"` + OutSystemID string `json:"outSystemId,omitempty"` + Mobile string `json:"mobile,omitempty"` + Phone string `json:"phone,omitempty"` + Lat float64 `json:"lat,omitempty"` + Lng float64 `json:"lng,omitempty"` + City int `json:"city,omitempty"` + County int `json:"county,omitempty"` + StationAddress string `json:"stationAddress,omitempty"` + Operator string `json:"operator"` // 返回值无 + ServiceTimeEnd1 int `json:"serviceTimeEnd1,omitempty"` + ServiceTimeStart1 int `json:"serviceTimeStart1,omitempty"` + ServiceTimeEnd2 int `json:"serviceTimeEnd2,omitempty"` + ServiceTimeStart2 int `json:"serviceTimeStart2,omitempty"` + DeliveryRangeType int8 `json:"deliveryRangeType,omitempty"` // 返回值无,划分配送服务范围的类型(3、圆心半径、2、不规则多边形(手动画范围))。若更新此字段需传完整值。 + CoordinateType int `json:"coordinateType,omitempty"` // 返回值无,使用的地图类型(1,谷歌), (2,百度), (3,高德), (4,腾讯) + DeliveryRangeRadius int `json:"deliveryRangeRadius,omitempty"` // 返回值无,时效服务范围半径(单位:米)(如果服务范围为类型3的话,该字段有值) + CoordinatePoints string `json:"coordinatePoints,omitempty"` // 返回值无,坐标点集合(如果服务范围为类型2的话,该字段有值),每个点以:经度,纬度 的格式表示,用“;”隔开多个点;对于腾讯地图、谷歌地图和高德地图,整个coordinatePoints的长度必须小于2k;对于百度地图,整个coordinatePoints的长度必须小于1k + CloseStatus int `json:"closeStatus,omitempty"` + StoreNotice string `json:"storeNotice,omitempty"` + StandByPhone string `json:"standByPhone,omitempty"` +} + +type StoreDetail struct { + // 以下可用于修改(及查询) + StationNo string `json:"stationNo"` // 强制参数,主键 + StationName string `json:"stationName,omitempty"` + OutSystemID string `json:"outSystemId,omitempty"` + Mobile string `json:"mobile,omitempty"` + Phone string `json:"phone,omitempty"` + Lat float64 `json:"lat,omitempty"` + Lng float64 `json:"lng,omitempty"` + City int `json:"city,omitempty"` + County int `json:"county,omitempty"` + StationAddress string `json:"stationAddress,omitempty"` + // Operator string `json:"operator"` // 返回值无 + ServiceTimeEnd1 int `json:"serviceTimeEnd1,omitempty"` + ServiceTimeStart1 int `json:"serviceTimeStart1,omitempty"` + ServiceTimeEnd2 int `json:"serviceTimeEnd2,omitempty"` + ServiceTimeStart2 int `json:"serviceTimeStart2,omitempty"` + // DeliveryRangeType int8 `json:"deliveryRangeType,omitempty"` // 返回值无,划分配送服务范围的类型(3、圆心半径、2、不规则多边形(手动画范围))。若更新此字段需传完整值。 + // CoordinateType int `json:"coordinateType,omitempty"` // 返回值无,使用的地图类型(1,谷歌), (2,百度), (3,高德), (4,腾讯) + // DeliveryRangeRadius int `json:"deliveryRangeRadius,omitempty"` // 返回值无,时效服务范围半径(单位:米)(如果服务范围为类型3的话,该字段有值) + // CoordinatePoints string `json:"coordinatePoints,omitempty"` // 返回值无,坐标点集合(如果服务范围为类型2的话,该字段有值),每个点以:经度,纬度 的格式表示,用“;”隔开多个点;对于腾讯地图、谷歌地图和高德地图,整个coordinatePoints的长度必须小于2k;对于百度地图,整个coordinatePoints的长度必须小于1k + CloseStatus int `json:"closeStatus,omitempty"` + StoreNotice string `json:"storeNotice,omitempty"` + StandByPhone string `json:"standByPhone,omitempty"` + + // 以下仅用于查询 + AllowRangeOptimized int `json:"allowRangeOptimized,omitempty"` + CacheKey4StoreList string `json:"cacheKey4StoreList,omitempty"` + CarrierNo int `json:"carrierNo,omitempty"` + CityName string `json:"cityName,omitempty"` + Coordinate string `json:"coordinate,omitempty"` + CoordinateAddress string `json:"coordinateAddress,omitempty"` + CountyName string `json:"countyName,omitempty"` + CreatePin string `json:"createPin,omitempty"` + CreateTime *utils.JavaDate `json:"createTime,omitempty"` + ID int64 `json:"id,omitempty"` + IndustryTag int `json:"industryTag,omitempty"` + InnerNoStatus int `json:"innerNoStatus,omitempty"` + IsAutoOrder int `json:"isAutoOrder,omitempty"` // 是否自动接单,0:是1:否 + IsMembership int `json:"isMembership,omitempty"` + IsNoPaper int `json:"isNoPaper,omitempty"` + OnlineTime *utils.JavaDate `json:"onlineTime,omitempty"` + OrderAging int `json:"orderAging,omitempty"` + OrderNoticeType int `json:"orderNoticeType,omitempty"` + PreWarehouse int `json:"preWarehouse,omitempty"` + Province int `json:"province,omitempty"` + ProvinceName string `json:"provinceName,omitempty"` + QualifyStatus int `json:"qualifyStatus,omitempty"` + RegularFlag int `json:"regularFlag,omitempty"` + StationDeliveryStatus int `json:"stationDeliveryStatus,omitempty"` + SupportInvoice int `json:"supportInvoice,omitempty"` + SupportOfflinePurchase int `json:"supportOfflinePurchase,omitempty"` + TestMark int `json:"testMark,omitempty"` + TimeAmType int `json:"timeAmType,omitempty"` + TimePmType int `json:"timePmType,omitempty"` + Ts *utils.JavaDate `json:"ts,omitempty"` + UpdatePin string `json:"updatePin,omitempty"` + UpdateTime *utils.JavaDate `json:"updateTime,omitempty"` + VenderID string `json:"venderId,omitempty"` + VenderName string `json:"venderName,omitempty"` + WareType int `json:"wareType,omitempty"` + WhiteDelivery bool `json:"whiteDelivery,omitempty"` + Yn int8 `json:"yn,omitempty"` // 门店状态,0启用,1禁用 +} + +type OrderProdCommentVo struct { + CreatePin string `json:"createPin"` + CreateTime *utils.JavaDate `json:"createTime"` + ID int64 `json:"id"` + IsPraise int `json:"isPraise"` + Score int `json:"score"` + ScoreLevel int `json:"scoreLevel"` + SkuID int64 `json:"skuId"` + SkuName string `json:"skuName"` + UpdatePin string `json:"updatePin"` + UpdateTime *utils.JavaDate `json:"updateTime"` + Yn int8 `json:"yn"` +} + +type OrderCommentInfo struct { + AppVersion string `json:"appVersion"` + CreatePin string `json:"createPin"` + CreateTime *utils.JavaDate `json:"createTime"` + DeliveryCarrierNo string `json:"deliveryCarrierNo"` + DeliveryConfirmTime *utils.JavaDate `json:"deliveryConfirmTime"` + DeliveryConfirmTime2 *utils.JavaDate `json:"deliveryConfirmTime2"` + DeliveryDifTime int `json:"deliveryDifTime"` + DeliveryDifTime2 int `json:"deliveryDifTime2"` + DeliveryManNo string `json:"deliveryManNo"` + DocID interface{} `json:"docId"` + ID int64 `json:"id"` + IsUpdate int `json:"isUpdate"` + OrderID int64 `json:"orderId"` + OrderProdCommentVoList []*OrderProdCommentVo `json:"orderProdCommentVoList"` + OrderType int `json:"orderType"` + OrgCode int `json:"orgCode"` + OrgCommentContent string `json:"orgCommentContent"` + OrgCommentStatus int `json:"orgCommentStatus"` + OrgCommentTime *utils.JavaDate `json:"orgCommentTime"` + OrgName string `json:"orgName"` + Score3 int `json:"score3"` + Score3Content string `json:"score3Content"` + Score4 int `json:"score4"` + Score4Content string `json:"score4Content"` + ScoreLevel int `json:"scoreLevel"` + StoreID int `json:"storeId"` + StoreName string `json:"storeName"` + Tags []string `json:"tags"` + TagsKey []string `json:"tagsKey"` + UpdatePin string `json:"updatePin"` + UpdateTime *utils.JavaDate `json:"updateTime"` + VenderTageKey []string `json:"venderTageKey"` + VenderTags []string `json:"venderTags"` + Yn int8 `json:"yn"` +} + +type StoreDeliveryRange struct { + Adresses string `json:"adresses"` + CreatePin string `json:"createPin"` + CreateTime *utils.JavaDate `json:"createTime"` + DeliveryRange string `json:"deliveryRange"` + DeliveryRangeRadius int `json:"deliveryRangeRadius"` + DeliveryRangeType int `json:"deliveryRangeType"` + DeliveryServiceType int `json:"deliveryServiceType"` + ID int `json:"id"` + StationNo string `json:"stationNo"` + Ts *utils.JavaDate `json:"ts"` + UpdatePin string `json:"updatePin"` + UpdateTime *utils.JavaDate `json:"updateTime"` + VenderID string `json:"venderId"` + Yn int8 `json:"yn"` +} func (a *API) GetAllCities() (cities []*CityInfo, err error) { result, err := a.AccessAPINoPage("address/allcities", nil, nil, nil, genNoPageResultParser("code", "msg", "result", "0")) @@ -75,23 +234,8 @@ func (a *API) GetStationsByVenderId() ([]string, error) { // 新增不带资质的门店信息接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=93acef27c3aa4d8286d5c8c26b493629 -func (a *API) CreateStore(stationName, phone string, city, county int, stationAddress, userName string, serviceTimeStart1, serviceTimeEnd1 int, lng, lat float64, deliveryRangeType, coordinateType int, standByPhone string, addParams map[string]interface{}) (*CreateShopResult, error) { - params := map[string]interface{}{ - KeyStationName: stationName, - KeyPhone: phone, - KeyCity: city, - KeyCounty: county, - KeyStationAddress: stationAddress, - KeyOperator: utils.GetAPIOperator(userName), - KeyServiceTimeStart1: serviceTimeStart1, - KeyServiceTimeEnd2: serviceTimeEnd1, - KeyLng: lng, - KeyLat: lat, - KeyDeliveryRangeType: deliveryRangeType, - KeyCoordinateType: coordinateType, - KeyStandByPhone: standByPhone, - } - result, err := a.AccessAPINoPage("store/createStore", utils.MergeMaps(params, addParams), nil, nil, func(data map[string]interface{}) (interface{}, error) { +func (a *API) CreateStore(createParams *OpStoreParams) (*CreateShopResult, error) { + result, err := a.AccessAPINoPage("store/createStore", utils.Struct2MapByJson(createParams), nil, nil, func(data map[string]interface{}) (interface{}, error) { innerCode := data["code"].(string) if data["code"] == "0" { mapData := data["data"].(map[string]interface{}) @@ -116,6 +260,14 @@ func (a *API) GetStoreInfoByStationNo(storeNo string) (map[string]interface{}, e return nil, err } +func (a *API) GetStoreInfoByStationNo2(storeNo string) (storeDetail *StoreDetail, err error) { + result, err := a.AccessAPINoPage("storeapi/getStoreInfoByStationNo", utils.Params2Map("StoreNo", storeNo), nil, nil, nil) + if err == nil { + err = utils.Map2StructByJson(result, &storeDetail, false) + } + return storeDetail, err +} + // 修改门店基础信息接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=2600369a456446f0921e918f3d15e96a func (a *API) UpdateStoreInfo4Open(storeNo, userName string, addParams map[string]interface{}) error { @@ -128,6 +280,11 @@ func (a *API) UpdateStoreInfo4Open(storeNo, userName string, addParams map[strin return err } +func (a *API) UpdateStoreInfo4Open2(updateParams *OpStoreParams) (err error) { + _, err = a.AccessAPINoPage("store/updateStoreInfo4Open", utils.Struct2MapByJson(updateParams), nil, nil, nullResultParser) + return err +} + // 根据订单号查询商家门店评价信息接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=bd23397725bb4e74b69e2f2fa1c88d43 func (a *API) GetCommentByOrderId(orderId int64) (map[string]interface{}, error) { @@ -141,6 +298,17 @@ func (a *API) GetCommentByOrderId(orderId int64) (map[string]interface{}, error) return nil, err } +func (a *API) GetCommentByOrderId2(orderId int64) (orderComment *OrderCommentInfo, err error) { + jdParams := map[string]interface{}{ + "orderId": orderId, + } + result, err := a.AccessAPINoPage("commentOutApi/getCommentByOrderId", jdParams, nil, nil, genNoPageResultParser("code", "msg", "result", "200")) + if err == nil { + err = utils.Map2StructByJson(result, &orderComment, false) + } + return orderComment, err +} + // 商家门店评价信息回复接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=ea0b466a7fa8489b813e8b197efca2d4 func (a *API) OrgReplyComment(orderID int64, storeID, content, replayPin string) error { @@ -186,6 +354,17 @@ func (a *API) GetDeliveryRangeByStationNo(stationNo string) (map[string]interfac return nil, err } +func (a *API) GetDeliveryRangeByStationNo2(stationNo string) (deliveryRange *StoreDeliveryRange, err error) { + jdParams := map[string]interface{}{ + "stationNo": stationNo, + } + result, err := a.AccessAPINoPage("store/getDeliveryRangeByStationNo", jdParams, nil, nil, nil) + if err == nil { + err = utils.Map2StructByJson(result, &deliveryRange, false) + } + return deliveryRange, err +} + // 私有函数 func interface2CreateShopResult(data interface{}) (retVal *CreateShopResult) { if result, ok := data.(map[string]interface{}); ok { diff --git a/platformapi/jdapi/store_test.go b/platformapi/jdapi/store_test.go index 2b62eeab..6676e86a 100644 --- a/platformapi/jdapi/store_test.go +++ b/platformapi/jdapi/store_test.go @@ -11,6 +11,9 @@ import ( const ( mustExistStoreID = "11053496" mustExistStoreJXID = "2" + + // mustExistStoreID = "11734851" + // mustExistStoreJXID = "100118" ) func TestGetAllCities(t *testing.T) { @@ -39,56 +42,51 @@ func TestGetStationsByVenderId(t *testing.T) { } func TestGetStoreInfoByStationNo(t *testing.T) { - result, err := api.GetStoreInfoByStationNo(mustExistStoreID) + result, err := api.GetStoreInfoByStationNo2(mustExistStoreID) if err != nil { t.Fatal(err) } - outSystemId := result["outSystemId"].(string) - if outSystemId != "100285" { - baseapi.SugarLogger.Fatalf("outSystemId is not correct, its:%s", outSystemId) + t.Log(utils.Format4Output(result, false)) + if result.OutSystemID != mustExistStoreJXID { + baseapi.SugarLogger.Fatalf("outSystemId is not correct, its:%s", result.OutSystemID) } } func TestUpdateStoreInfo4Open(t *testing.T) { - result, err := api.GetStoreInfoByStationNo(mustExistStoreID) + result, err := api.GetStoreInfoByStationNo2(mustExistStoreID) if err != nil { t.Fatal(err) } - oldAddress := result["stationAddress"].(string) - testAddress := oldAddress + "T" - addParams := map[string]interface{}{ - "stationAddress": testAddress, + oldAddress := result.StationAddress + params := &OpStoreParams{ + StationNo: mustExistStoreID, + Operator: "test", + StationAddress: oldAddress + "T", } - err = api.UpdateStoreInfo4Open(mustExistStoreID, "test", addParams) + err = api.UpdateStoreInfo4Open2(params) if err != nil { t.Fatal(err) } - result, err = api.GetStoreInfoByStationNo(mustExistStoreID) - newAddress := result["stationAddress"].(string) - if newAddress != testAddress { + result, err = api.GetStoreInfoByStationNo2(mustExistStoreID) + newAddress := result.StationAddress + if newAddress != params.StationAddress { t.Fatalf("address not match, newAddress:%s, oldAddress:%s", newAddress, oldAddress) } - addParams = map[string]interface{}{ - "stationAddress": oldAddress, - } - api.UpdateStoreInfo4Open(mustExistStoreID, "test", addParams) + params.StationAddress = oldAddress + api.UpdateStoreInfo4Open2(params) if err != nil { t.Fatal(err) } - } + func TestGetCommentByOrderId(t *testing.T) { - testOrderID := int64(822347450000922) - result, err := api.GetCommentByOrderId(testOrderID) + testOrderID := int64(922520919000622) + result, err := api.GetCommentByOrderId2(testOrderID) if err != nil { t.Fatal(err.Error()) } - gotOrderID := utils.MustInterface2Int64(result["orderId"]) - if gotOrderID != testOrderID { - t.Fatalf("GetCommentByOrderId wrong, gotOrderID:%d", gotOrderID) - } t.Log(utils.Format4Output(result, false)) } @@ -115,27 +113,27 @@ func TestUpdateStoreConfig4Open(t *testing.T) { } func TestGetDeliveryRangeByStationNo(t *testing.T) { - const testStoreID = "11738152" - result, err := api.GetDeliveryRangeByStationNo(testStoreID) - if err != nil { - t.Fatal(err) - } - result2, err := api.GetStoreInfoByStationNo(testStoreID) + const testStoreID = "11734851" + result, err := api.GetDeliveryRangeByStationNo2(testStoreID) if err != nil { t.Fatal(err) } baseapi.SugarLogger.Debug(utils.Format4Output(result, false)) - baseapi.SugarLogger.Debug(utils.Format4Output(result2, false)) - deliveryRange := result["deliveryRange"].(string) - params := map[string]interface{}{ - "lng": result2["lng"], - "lat": result2["lat"], - "coordinateType": 3, - "deliveryRangeType": 2, - "coordinatePoints": deliveryRange, - } - err = api.UpdateStoreInfo4Open(testStoreID, "test", params) +} + +func TestDisableAutoOrder4AllStores(t *testing.T) { + storeIDs, err := api.GetStationsByVenderId() if err != nil { t.Fatal(err) } + for _, storeID := range storeIDs { + if storeInfo, err := api.GetStoreInfoByStationNo2(storeID); err == nil { + if storeInfo.Yn == 0 && storeInfo.IsAutoOrder == 0 { + t.Log(storeID) + api.UpdateStoreConfig4Open(storeID, false) + } + t.Log(utils.Format4Output(storeInfo, false)) + } + break + } } From 23f548047a25437666e11dd7ebfb3f53288e9c84 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 19 Sep 2019 15:56:26 +0800 Subject: [PATCH 53/71] - up --- platformapi/jdapi/store.go | 9 ++++++++- platformapi/jdapi/store_test.go | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/platformapi/jdapi/store.go b/platformapi/jdapi/store.go index a6c42796..336d531d 100644 --- a/platformapi/jdapi/store.go +++ b/platformapi/jdapi/store.go @@ -35,6 +35,13 @@ const ( CarrierNoSelfTake = 9999 // 到店自提 ) +const ( + CoordinateTypeGoogle = 1 // 谷歌 + CoordinateTypeBaidu = 2 // 百度 + CoordinateTypeAutonavi = 3 // 高德 + CoordinateTypeTencent = 4 // 腾讯 +) + type CreateShopResult struct { DeliveryRangeType int `json:"deliveryRangeType"` CoordinatePoints string `json:"coordinatePoints"` @@ -181,7 +188,7 @@ type OrderCommentInfo struct { Score4 int `json:"score4"` Score4Content string `json:"score4Content"` ScoreLevel int `json:"scoreLevel"` - StoreID int `json:"storeId"` + StoreID int64 `json:"storeId"` StoreName string `json:"storeName"` Tags []string `json:"tags"` TagsKey []string `json:"tagsKey"` diff --git a/platformapi/jdapi/store_test.go b/platformapi/jdapi/store_test.go index 6676e86a..27e6f385 100644 --- a/platformapi/jdapi/store_test.go +++ b/platformapi/jdapi/store_test.go @@ -102,11 +102,11 @@ func TestUpdateStoreConfig4Open(t *testing.T) { t.Fatal(result) } time.Sleep(2 * time.Second) - result2, err := api.GetStoreInfoByStationNo(testStationNo) + result2, err := api.GetStoreInfoByStationNo2(testStationNo) if err != nil { t.Fatal(err.Error()) } - isAutoOrder := int(utils.MustInterface2Int64(result2["isAutoOrder"])) + isAutoOrder := result2.IsAutoOrder if isAutoOrder != 0 && desiredValue || isAutoOrder == 0 && !desiredValue { t.Fatalf("UpdateStoreConfig4Open failed, isAutoOrder:%d", isAutoOrder) } From 521a6f0661303de0c86458ace484d1ff4c7aa419 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 19 Sep 2019 17:25:47 +0800 Subject: [PATCH 54/71] =?UTF-8?q?-=20CloseStatus=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0omitempty=E6=A0=87=E5=BF=97=EF=BC=8C=E5=9B=A0?= =?UTF-8?q?=E4=B8=BA0=E6=98=AF=E6=9C=89=E6=84=8F=E4=B9=89=E7=9A=84?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/store.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/platformapi/jdapi/store.go b/platformapi/jdapi/store.go index 336d531d..2281249a 100644 --- a/platformapi/jdapi/store.go +++ b/platformapi/jdapi/store.go @@ -78,7 +78,7 @@ type OpStoreParams struct { CoordinateType int `json:"coordinateType,omitempty"` // 返回值无,使用的地图类型(1,谷歌), (2,百度), (3,高德), (4,腾讯) DeliveryRangeRadius int `json:"deliveryRangeRadius,omitempty"` // 返回值无,时效服务范围半径(单位:米)(如果服务范围为类型3的话,该字段有值) CoordinatePoints string `json:"coordinatePoints,omitempty"` // 返回值无,坐标点集合(如果服务范围为类型2的话,该字段有值),每个点以:经度,纬度 的格式表示,用“;”隔开多个点;对于腾讯地图、谷歌地图和高德地图,整个coordinatePoints的长度必须小于2k;对于百度地图,整个coordinatePoints的长度必须小于1k - CloseStatus int `json:"closeStatus,omitempty"` + CloseStatus int `json:"closeStatus"` StoreNotice string `json:"storeNotice,omitempty"` StandByPhone string `json:"standByPhone,omitempty"` } @@ -287,8 +287,12 @@ func (a *API) UpdateStoreInfo4Open(storeNo, userName string, addParams map[strin return err } -func (a *API) UpdateStoreInfo4Open2(updateParams *OpStoreParams) (err error) { - _, err = a.AccessAPINoPage("store/updateStoreInfo4Open", utils.Struct2MapByJson(updateParams), nil, nil, nullResultParser) +func (a *API) UpdateStoreInfo4Open2(updateParams *OpStoreParams, modifyCloseStatus bool) (err error) { + mapData := utils.Struct2MapByJson(updateParams) + if !modifyCloseStatus { + delete(mapData, "closeStatus") + } + _, err = a.AccessAPINoPage("store/updateStoreInfo4Open", mapData, nil, nil, nullResultParser) return err } From e0f9d2da6915b276695cc6efeec9e52683c5950d Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 19 Sep 2019 17:28:29 +0800 Subject: [PATCH 55/71] - up --- platformapi/jdapi/store.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platformapi/jdapi/store.go b/platformapi/jdapi/store.go index 2281249a..bf92f542 100644 --- a/platformapi/jdapi/store.go +++ b/platformapi/jdapi/store.go @@ -78,7 +78,7 @@ type OpStoreParams struct { CoordinateType int `json:"coordinateType,omitempty"` // 返回值无,使用的地图类型(1,谷歌), (2,百度), (3,高德), (4,腾讯) DeliveryRangeRadius int `json:"deliveryRangeRadius,omitempty"` // 返回值无,时效服务范围半径(单位:米)(如果服务范围为类型3的话,该字段有值) CoordinatePoints string `json:"coordinatePoints,omitempty"` // 返回值无,坐标点集合(如果服务范围为类型2的话,该字段有值),每个点以:经度,纬度 的格式表示,用“;”隔开多个点;对于腾讯地图、谷歌地图和高德地图,整个coordinatePoints的长度必须小于2k;对于百度地图,整个coordinatePoints的长度必须小于1k - CloseStatus int `json:"closeStatus"` + CloseStatus int `json:"closeStatus"` // 0是有意义的值,所以不能是omitempty StoreNotice string `json:"storeNotice,omitempty"` StandByPhone string `json:"standByPhone,omitempty"` } @@ -104,7 +104,7 @@ type StoreDetail struct { // CoordinateType int `json:"coordinateType,omitempty"` // 返回值无,使用的地图类型(1,谷歌), (2,百度), (3,高德), (4,腾讯) // DeliveryRangeRadius int `json:"deliveryRangeRadius,omitempty"` // 返回值无,时效服务范围半径(单位:米)(如果服务范围为类型3的话,该字段有值) // CoordinatePoints string `json:"coordinatePoints,omitempty"` // 返回值无,坐标点集合(如果服务范围为类型2的话,该字段有值),每个点以:经度,纬度 的格式表示,用“;”隔开多个点;对于腾讯地图、谷歌地图和高德地图,整个coordinatePoints的长度必须小于2k;对于百度地图,整个coordinatePoints的长度必须小于1k - CloseStatus int `json:"closeStatus,omitempty"` + CloseStatus int `json:"closeStatus"` // 0是有意义的值,所以不能是omitempty StoreNotice string `json:"storeNotice,omitempty"` StandByPhone string `json:"standByPhone,omitempty"` From 926a9533b22780164b29e8142a741b3a89a0a0d6 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 19 Sep 2019 17:31:31 +0800 Subject: [PATCH 56/71] =?UTF-8?q?-=20StoreDetail=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E5=A4=A7=E5=A4=9A=E6=95=B0=E5=AD=97=E6=AE=B5=E5=8E=BB=E6=8E=89?= =?UTF-8?q?omitempty=EF=BC=8C=E5=9B=A0=E4=B8=BA=E4=B8=8D=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=EF=BC=8C=E4=B8=94=E6=9C=89=E8=BE=83=E5=A4=9A?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E7=9A=840=E5=80=BC=E6=98=AF=E6=9C=89?= =?UTF-8?q?=E6=84=8F=E4=B9=89=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/store.go | 74 +++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/platformapi/jdapi/store.go b/platformapi/jdapi/store.go index bf92f542..b7170e59 100644 --- a/platformapi/jdapi/store.go +++ b/platformapi/jdapi/store.go @@ -109,43 +109,43 @@ type StoreDetail struct { StandByPhone string `json:"standByPhone,omitempty"` // 以下仅用于查询 - AllowRangeOptimized int `json:"allowRangeOptimized,omitempty"` - CacheKey4StoreList string `json:"cacheKey4StoreList,omitempty"` - CarrierNo int `json:"carrierNo,omitempty"` - CityName string `json:"cityName,omitempty"` - Coordinate string `json:"coordinate,omitempty"` - CoordinateAddress string `json:"coordinateAddress,omitempty"` - CountyName string `json:"countyName,omitempty"` - CreatePin string `json:"createPin,omitempty"` - CreateTime *utils.JavaDate `json:"createTime,omitempty"` - ID int64 `json:"id,omitempty"` - IndustryTag int `json:"industryTag,omitempty"` - InnerNoStatus int `json:"innerNoStatus,omitempty"` - IsAutoOrder int `json:"isAutoOrder,omitempty"` // 是否自动接单,0:是1:否 - IsMembership int `json:"isMembership,omitempty"` - IsNoPaper int `json:"isNoPaper,omitempty"` - OnlineTime *utils.JavaDate `json:"onlineTime,omitempty"` - OrderAging int `json:"orderAging,omitempty"` - OrderNoticeType int `json:"orderNoticeType,omitempty"` - PreWarehouse int `json:"preWarehouse,omitempty"` - Province int `json:"province,omitempty"` - ProvinceName string `json:"provinceName,omitempty"` - QualifyStatus int `json:"qualifyStatus,omitempty"` - RegularFlag int `json:"regularFlag,omitempty"` - StationDeliveryStatus int `json:"stationDeliveryStatus,omitempty"` - SupportInvoice int `json:"supportInvoice,omitempty"` - SupportOfflinePurchase int `json:"supportOfflinePurchase,omitempty"` - TestMark int `json:"testMark,omitempty"` - TimeAmType int `json:"timeAmType,omitempty"` - TimePmType int `json:"timePmType,omitempty"` - Ts *utils.JavaDate `json:"ts,omitempty"` - UpdatePin string `json:"updatePin,omitempty"` - UpdateTime *utils.JavaDate `json:"updateTime,omitempty"` - VenderID string `json:"venderId,omitempty"` - VenderName string `json:"venderName,omitempty"` - WareType int `json:"wareType,omitempty"` - WhiteDelivery bool `json:"whiteDelivery,omitempty"` - Yn int8 `json:"yn,omitempty"` // 门店状态,0启用,1禁用 + AllowRangeOptimized int `json:"allowRangeOptimized"` + CacheKey4StoreList string `json:"cacheKey4StoreList"` + CarrierNo int `json:"carrierNo"` + CityName string `json:"cityName"` + Coordinate string `json:"coordinate"` + CoordinateAddress string `json:"coordinateAddress"` + CountyName string `json:"countyName"` + CreatePin string `json:"createPin"` + CreateTime *utils.JavaDate `json:"createTime"` + ID int64 `json:"id"` + IndustryTag int `json:"industryTag"` + InnerNoStatus int `json:"innerNoStatus"` + IsAutoOrder int `json:"isAutoOrder"` // 是否自动接单,0:是1:否 + IsMembership int `json:"isMembership"` + IsNoPaper int `json:"isNoPaper"` + OnlineTime *utils.JavaDate `json:"onlineTime"` + OrderAging int `json:"orderAging"` + OrderNoticeType int `json:"orderNoticeType"` + PreWarehouse int `json:"preWarehouse"` + Province int `json:"province"` + ProvinceName string `json:"provinceName"` + QualifyStatus int `json:"qualifyStatus"` + RegularFlag int `json:"regularFlag"` + StationDeliveryStatus int `json:"stationDeliveryStatus"` + SupportInvoice int `json:"supportInvoice"` + SupportOfflinePurchase int `json:"supportOfflinePurchase"` + TestMark int `json:"testMark"` + TimeAmType int `json:"timeAmType"` + TimePmType int `json:"timePmType"` + Ts *utils.JavaDate `json:"ts"` + UpdatePin string `json:"updatePin"` + UpdateTime *utils.JavaDate `json:"updateTime"` + VenderID string `json:"venderId"` + VenderName string `json:"venderName"` + WareType int `json:"wareType"` + WhiteDelivery bool `json:"whiteDelivery"` + Yn int8 `json:"yn"` // 门店状态,0启用,1禁用 } type OrderProdCommentVo struct { From 8bbfc555255c4f425ed8e66940992e89b576af6c Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 20 Sep 2019 11:22:15 +0800 Subject: [PATCH 57/71] =?UTF-8?q?-=20=E9=A5=BF=E7=99=BEdeliveryParty?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84=E5=B8=B8=E9=87=8F=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/order.go | 2 -- platformapi/ebaiapi/shop.go | 12 ++++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/platformapi/ebaiapi/order.go b/platformapi/ebaiapi/order.go index d39c4a55..bfd410e6 100644 --- a/platformapi/ebaiapi/order.go +++ b/platformapi/ebaiapi/order.go @@ -67,8 +67,6 @@ const ( OrderUserCancelTypeBeforeSale = 1 // 表示订单完成前用户全单取消申请流程 OrderUserCancelTypeAfterSale = 2 // 表示订单完成后用户全单退款申请流程 - - SendImmediatelySelf = 6 // 饿百商家自送的配送状态 ) const ( diff --git a/platformapi/ebaiapi/shop.go b/platformapi/ebaiapi/shop.go index d4a8e4e6..7f2249d2 100644 --- a/platformapi/ebaiapi/shop.go +++ b/platformapi/ebaiapi/shop.go @@ -68,6 +68,18 @@ const ( DeliveryTypeElmXingHuoZBKA = 18 // 星火众包KA ) +// https://open-be.ele.me/dev/api/doc/v3/#api-Order_Up-order_get +const ( + DeliveryPartyFengNiao = 1 // 蜂鸟 + DeliveryPartyFengNiaoSelf = 2 // 蜂鸟自配送 + DeliveryPartyFengNiaoZB = 3 // 蜂鸟众包 + DeliveryPartyFengElmZB = 4 // 饿了么众包 + DeliveryPartyFengNiaoPS = 5 // 蜂鸟配送 + DeliveryPartyFengElmSelf = 6 // 饿了么自配送,商家自送? + DeliveryPartyFullCity = 7 // 全城送 + DeliveryPartyKuaiDiPS = 8 // 快递配送 +) + type ShopInfo struct { ShopID string `json:"shop_id"` BaiduShopID int64 `json:"baidu_shop_id"` From f97d7d47c5155ffc718fbe16434dd2be16631b4f Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 20 Sep 2019 14:36:39 +0800 Subject: [PATCH 58/71] + mtwmapi.ErrCodeCanNotModifyStoreDeliveryInfo --- platformapi/mtwmapi/mtwmapi.go | 11 ++++++----- platformapi/mtwmapi/poi.go | 3 +++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/platformapi/mtwmapi/mtwmapi.go b/platformapi/mtwmapi/mtwmapi.go index 972f3261..1d00454d 100644 --- a/platformapi/mtwmapi/mtwmapi.go +++ b/platformapi/mtwmapi/mtwmapi.go @@ -44,11 +44,12 @@ const ( ErrCodeSysErr = 700 // 系统错误,按美团外卖技术支持的说法,可当成需重试的错误 ErrCodeAccessLimited = 711 // 接口调用过于频繁,触发流控,请降低调用频率 - ErrCodeNoAppFood = 805 // 不存在此菜品 - ErrCodeNoSuchOrder = 806 // 不存在此订单 - ErrCodeOpFailed = 808 // 操作失败(如订单在操作时,状态已变更等情况) - ErrCodeSkuCategoryNotExist = 1021 // 菜品分类不存在 - ErrCodeSkuCategoryExist = 1037 // 菜品分类已存在 + ErrCodeNoAppFood = 805 // 不存在此菜品 + ErrCodeNoSuchOrder = 806 // 不存在此订单 + ErrCodeOpFailed = 808 // 操作失败(如订单在操作时,状态已变更等情况) + ErrCodeSkuCategoryNotExist = 1021 // 菜品分类不存在 + ErrCodeSkuCategoryExist = 1037 // 菜品分类已存在 + ErrCodeCanNotModifyStoreDeliveryInfo = 3018 // 商家已接入美团配送,不可修改门店配送相关信息 ) type API struct { diff --git a/platformapi/mtwmapi/poi.go b/platformapi/mtwmapi/poi.go index bc407d74..c956848c 100644 --- a/platformapi/mtwmapi/poi.go +++ b/platformapi/mtwmapi/poi.go @@ -47,6 +47,9 @@ type PoiInfo struct { Utime int64 `json:"utime,omitempt"` } +// todo 此函数在open_level与is_online开店,由于一些原因并没有成功时,好像并不会报错 +// 经常会奇怪的报错:商家已接入美团配送,不可修改门店配送相关信息,但实际并没有修改任何与配送相关的东西 +// 参见:https://developer.waimai.meituan.com/home/myquestionDetail/6194 func (a *API) PoiSave(poiCode string, poiParams map[string]interface{}) (err error) { _, err = a.AccessAPI("poi/save", false, utils.MergeMaps(utils.Params2Map(KeyAppPoiCode, poiCode), poiParams)) return err From 3ae979e48b724418f2d2aa19df547e07a6657aa5 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 24 Sep 2019 08:59:36 +0800 Subject: [PATCH 59/71] =?UTF-8?q?-=20TryInterface2Int64=E6=B7=BB=E5=8A=A0i?= =?UTF-8?q?n32,int16,int8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/typeconv.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/utils/typeconv.go b/utils/typeconv.go index bf562356..f528da43 100644 --- a/utils/typeconv.go +++ b/utils/typeconv.go @@ -71,6 +71,15 @@ func TryInterface2Int64(data interface{}) (num int64, err error) { if dataNumber, ok := data.(int); ok { return int64(dataNumber), nil } + if dataNumber, ok := data.(int32); ok { + return int64(dataNumber), nil + } + if dataNumber, ok := data.(int16); ok { + return int64(dataNumber), nil + } + if dataNumber, ok := data.(int8); ok { + return int64(dataNumber), nil + } if dataNumber, ok := data.(json.Number); ok { return dataNumber.Int64() } From b02230ec2dc0a11957f874c21c5ca761acd95852 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 24 Sep 2019 15:23:27 +0800 Subject: [PATCH 60/71] =?UTF-8?q?-=20=E9=87=8D=E6=96=B0=E5=AE=9E=E7=8E=B0u?= =?UTF-8?q?tils.Struct2FlatMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/typeconv.go | 31 +++++-------------------------- utils/typeconv_test.go | 37 +++++++++++++++++++++++++++++++++++++ utils/utils_test.go | 11 ----------- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/utils/typeconv.go b/utils/typeconv.go index f528da43..c1b76479 100644 --- a/utils/typeconv.go +++ b/utils/typeconv.go @@ -13,7 +13,7 @@ import ( "time" "git.rosy.net.cn/baseapi" - "github.com/fatih/structs" + "github.com/gazeboxu/structs" "github.com/mitchellh/mapstructure" ) @@ -449,43 +449,22 @@ func MergeMaps(firstMap map[string]interface{}, otherMaps ...map[string]interfac return retVal } -func Struct2Map(obj interface{}, tagName string) (mapData map[string]interface{}) { +func Struct2Map(obj interface{}, tagName string, isFlattenAnonymous bool) (mapData map[string]interface{}) { if tagName == "" { tagName = "json" } structsObj := structs.New(obj) structsObj.TagName = tagName + structsObj.IsFlattenAnonymous = true return structsObj.Map() } func Struct2MapByJson(obj interface{}) (mapData map[string]interface{}) { - return Struct2Map(obj, "") -} - -// 此函数将MAP中所有的子MAP中的数据提升到最上层,相同字段会覆盖父MAP的 -func FlatMap(in map[string]interface{}) map[string]interface{} { - keys := []string{} - maps := []map[string]interface{}{} - for k, v := range in { - if vMap, ok := v.(map[string]interface{}); ok { - vMap = FlatMap(vMap) - maps = append(maps, vMap) - keys = append(keys, k) - } - } - if len(maps) > 0 { - retVal := MergeMaps(in, maps...) - for _, v := range keys { - delete(retVal, v) - } - return retVal - } - return in + return Struct2Map(obj, "", false) } func Struct2FlatMap(obj interface{}) map[string]interface{} { - m := Struct2MapByJson(obj) - return FlatMap(m) + return Struct2Map(obj, "", true) } // !!! 此函数好像不支持struct是内嵌结构的 diff --git a/utils/typeconv_test.go b/utils/typeconv_test.go index d49f2122..081503e3 100644 --- a/utils/typeconv_test.go +++ b/utils/typeconv_test.go @@ -84,3 +84,40 @@ func TestTime(t *testing.T) { } } } + +func TestStruct2MapByJson(t *testing.T) { + type InnerKK struct { + IntData int + StrData string + ObjData time.Time + } + type KK struct { + IntData int + A int + B string + C time.Time + InnerKK + InnerKK2 InnerKK + } + kk := &KK{ + InnerKK: InnerKK{ + IntData: 1, + StrData: "hello", + }, + } + mapData := Struct2MapByJson(kk) + t.Log(Format4Output(mapData, false)) + // t.Log(mapData) + // t.Log(kk) +} + +// func TestStruct2MapByJson(t *testing.T) { +// mapData := Struct2MapByJson(&struct { +// IntData int `structs:"dataInt"` +// StrData string `json:"-"` +// }{ +// IntData: 1, +// StrData: "2", +// }) +// t.Log(mapData) +// } diff --git a/utils/utils_test.go b/utils/utils_test.go index ffdab708..79fb4b29 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -175,17 +175,6 @@ func TestTrimBlanChar(t *testing.T) { } } -func TestStruct2MapByJson(t *testing.T) { - mapData := Struct2MapByJson(&struct { - IntData int `structs:"dataInt"` - StrData string `json:"-"` - }{ - IntData: 1, - StrData: "2", - }) - t.Log(mapData) -} - func TestLimitUTF8StringLen(t *testing.T) { for _, v := range [][]interface{}{ []interface{}{ From 84d5bbe79855a818047c42df1a9915493754c196 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 24 Sep 2019 15:50:31 +0800 Subject: [PATCH 61/71] - up --- platformapi/jdapi/store.go | 74 +++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/platformapi/jdapi/store.go b/platformapi/jdapi/store.go index b7170e59..e5811e31 100644 --- a/platformapi/jdapi/store.go +++ b/platformapi/jdapi/store.go @@ -242,6 +242,7 @@ func (a *API) GetStationsByVenderId() ([]string, error) { // 新增不带资质的门店信息接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=93acef27c3aa4d8286d5c8c26b493629 func (a *API) CreateStore(createParams *OpStoreParams) (*CreateShopResult, error) { + createParams.Operator = utils.GetAPIOperator(createParams.Operator) result, err := a.AccessAPINoPage("store/createStore", utils.Struct2MapByJson(createParams), nil, nil, func(data map[string]interface{}) (interface{}, error) { innerCode := data["code"].(string) if data["code"] == "0" { @@ -259,13 +260,13 @@ func (a *API) CreateStore(createParams *OpStoreParams) (*CreateShopResult, error // 根据到家门店编码查询门店基本信息接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=4c48e347027146d5a103e851055cb1a7 -func (a *API) GetStoreInfoByStationNo(storeNo string) (map[string]interface{}, error) { - result, err := a.AccessAPINoPage("storeapi/getStoreInfoByStationNo", utils.Params2Map("StoreNo", storeNo), nil, nil, nil) - if err == nil { - return result.(map[string]interface{}), nil - } - return nil, err -} +// func (a *API) GetStoreInfoByStationNo(storeNo string) (map[string]interface{}, error) { +// result, err := a.AccessAPINoPage("storeapi/getStoreInfoByStationNo", utils.Params2Map("StoreNo", storeNo), nil, nil, nil) +// if err == nil { +// return result.(map[string]interface{}), nil +// } +// return nil, err +// } func (a *API) GetStoreInfoByStationNo2(storeNo string) (storeDetail *StoreDetail, err error) { result, err := a.AccessAPINoPage("storeapi/getStoreInfoByStationNo", utils.Params2Map("StoreNo", storeNo), nil, nil, nil) @@ -277,17 +278,18 @@ func (a *API) GetStoreInfoByStationNo2(storeNo string) (storeDetail *StoreDetail // 修改门店基础信息接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=2600369a456446f0921e918f3d15e96a -func (a *API) UpdateStoreInfo4Open(storeNo, userName string, addParams map[string]interface{}) error { - jdParams := map[string]interface{}{ - "stationNo": storeNo, - "operator": utils.GetAPIOperator(userName), - } - jdParams = utils.MergeMaps(jdParams, addParams) - _, err := a.AccessAPINoPage("store/updateStoreInfo4Open", jdParams, nil, nil, nullResultParser) - return err -} +// func (a *API) UpdateStoreInfo4Open(storeNo, userName string, addParams map[string]interface{}) error { +// jdParams := map[string]interface{}{ +// "stationNo": storeNo, +// "operator": utils.GetAPIOperator(userName), +// } +// jdParams = utils.MergeMaps(jdParams, addParams) +// _, err := a.AccessAPINoPage("store/updateStoreInfo4Open", jdParams, nil, nil, nullResultParser) +// return err +// } func (a *API) UpdateStoreInfo4Open2(updateParams *OpStoreParams, modifyCloseStatus bool) (err error) { + updateParams.Operator = utils.GetAPIOperator(updateParams.Operator) mapData := utils.Struct2MapByJson(updateParams) if !modifyCloseStatus { delete(mapData, "closeStatus") @@ -298,16 +300,16 @@ func (a *API) UpdateStoreInfo4Open2(updateParams *OpStoreParams, modifyCloseStat // 根据订单号查询商家门店评价信息接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=bd23397725bb4e74b69e2f2fa1c88d43 -func (a *API) GetCommentByOrderId(orderId int64) (map[string]interface{}, error) { - jdParams := map[string]interface{}{ - "orderId": orderId, - } - result, err := a.AccessAPINoPage("commentOutApi/getCommentByOrderId", jdParams, nil, nil, genNoPageResultParser("code", "msg", "result", "200")) - if err == nil { - return result.(map[string]interface{}), nil - } - return nil, err -} +// func (a *API) GetCommentByOrderId(orderId int64) (map[string]interface{}, error) { +// jdParams := map[string]interface{}{ +// "orderId": orderId, +// } +// result, err := a.AccessAPINoPage("commentOutApi/getCommentByOrderId", jdParams, nil, nil, genNoPageResultParser("code", "msg", "result", "200")) +// if err == nil { +// return result.(map[string]interface{}), nil +// } +// return nil, err +// } func (a *API) GetCommentByOrderId2(orderId int64) (orderComment *OrderCommentInfo, err error) { jdParams := map[string]interface{}{ @@ -354,16 +356,16 @@ func (a *API) UpdateStoreConfig4Open(stationNo string, isAutoOrder bool) (bool, // 获取门店配送范围接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=8f6d0ac75d734c68bf5bd2a09f376a78 -func (a *API) GetDeliveryRangeByStationNo(stationNo string) (map[string]interface{}, error) { - jdParams := map[string]interface{}{ - "stationNo": stationNo, - } - result, err := a.AccessAPINoPage("store/getDeliveryRangeByStationNo", jdParams, nil, nil, nil) - if err == nil { - return result.(map[string]interface{}), nil - } - return nil, err -} +// func (a *API) GetDeliveryRangeByStationNo(stationNo string) (map[string]interface{}, error) { +// jdParams := map[string]interface{}{ +// "stationNo": stationNo, +// } +// result, err := a.AccessAPINoPage("store/getDeliveryRangeByStationNo", jdParams, nil, nil, nil) +// if err == nil { +// return result.(map[string]interface{}), nil +// } +// return nil, err +// } func (a *API) GetDeliveryRangeByStationNo2(stationNo string) (deliveryRange *StoreDeliveryRange, err error) { jdParams := map[string]interface{}{ From afeb66b2d36a3e206dd4f8e6da889d8b00362c60 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 24 Sep 2019 18:10:32 +0800 Subject: [PATCH 62/71] + Time2Pointer --- utils/utils_type.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/utils/utils_type.go b/utils/utils_type.go index 0bf1a678..1e9e7f91 100644 --- a/utils/utils_type.go +++ b/utils/utils_type.go @@ -1,5 +1,7 @@ package utils +import "time" + func String2Pointer(value string) *string { return &value } @@ -54,3 +56,14 @@ func Pointer2Float64(ptr *float64) (value float64) { } return value } + +func Time2Pointer(value time.Time) *time.Time { + return &value +} + +func Pointer2Time(ptr *time.Time) (value time.Time) { + if ptr != nil { + value = *ptr + } + return value +} From 0b44ea74e1483eb60b3b2d26265a0f0844b26f3d Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 25 Sep 2019 09:17:06 +0800 Subject: [PATCH 63/71] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96jdapi.signParams?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/jdapi.go | 12 +++++++----- platformapi/jdapi/store_test.go | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/platformapi/jdapi/jdapi.go b/platformapi/jdapi/jdapi.go index a2afb720..2c78e6c8 100644 --- a/platformapi/jdapi/jdapi.go +++ b/platformapi/jdapi/jdapi.go @@ -1,6 +1,7 @@ package jdapi import ( + "bytes" "crypto/md5" "encoding/json" "fmt" @@ -117,13 +118,14 @@ func (a *API) signParams(jdParams map[string]interface{}) string { } sort.Strings(keys) - allStr := a.appSecret + buf := &bytes.Buffer{} + buf.WriteString(a.appSecret) for _, k := range keys { - allStr += k + fmt.Sprint(jdParams[k]) + buf.WriteString(k) + buf.WriteString(fmt.Sprint(jdParams[k])) } - allStr = allStr + a.appSecret - - return fmt.Sprintf("%X", md5.Sum([]byte(allStr))) + buf.WriteString(a.appSecret) + return fmt.Sprintf("%X", md5.Sum(buf.Bytes())) } func New(token, appKey, appSecret string, config ...*platformapi.APIConfig) *API { diff --git a/platformapi/jdapi/store_test.go b/platformapi/jdapi/store_test.go index 27e6f385..47f5d5f6 100644 --- a/platformapi/jdapi/store_test.go +++ b/platformapi/jdapi/store_test.go @@ -63,7 +63,7 @@ func TestUpdateStoreInfo4Open(t *testing.T) { Operator: "test", StationAddress: oldAddress + "T", } - err = api.UpdateStoreInfo4Open2(params) + err = api.UpdateStoreInfo4Open2(params, false) if err != nil { t.Fatal(err) } @@ -75,7 +75,7 @@ func TestUpdateStoreInfo4Open(t *testing.T) { } params.StationAddress = oldAddress - api.UpdateStoreInfo4Open2(params) + api.UpdateStoreInfo4Open2(params, false) if err != nil { t.Fatal(err) } From 37de9f6f7ed70f3fc8e53e40bfdfc58a7d62e0ca Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 25 Sep 2019 18:08:47 +0800 Subject: [PATCH 64/71] up --- platformapi/mtwmapi/poi.go | 1 + 1 file changed, 1 insertion(+) diff --git a/platformapi/mtwmapi/poi.go b/platformapi/mtwmapi/poi.go index c956848c..3915bf0c 100644 --- a/platformapi/mtwmapi/poi.go +++ b/platformapi/mtwmapi/poi.go @@ -153,6 +153,7 @@ func (a *API) PoiShipTimeUpdate(poiCode, shippingTime string) (err error) { } // 美团要求必须是jpg|jpeg图片格式,且imgName必须以jpg或jpeg结尾 +// 此接口虽然要求poiCode参数,但经过测试,发现上传的图片可以跨门店使用 func (a *API) ImageUpload(poiCode, imgName string, imgData []byte) (imgID string, err error) { result, err := a.AccessAPI("image/upload", false, map[string]interface{}{ KeyAppPoiCode: poiCode, From d93cc097302e796ac3f5c8ab5a4918a1722cb2ef Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 25 Sep 2019 22:55:21 +0800 Subject: [PATCH 65/71] comment --- platformapi/mtwmapi/poi.go | 1 + 1 file changed, 1 insertion(+) diff --git a/platformapi/mtwmapi/poi.go b/platformapi/mtwmapi/poi.go index 3915bf0c..a2263a19 100644 --- a/platformapi/mtwmapi/poi.go +++ b/platformapi/mtwmapi/poi.go @@ -154,6 +154,7 @@ func (a *API) PoiShipTimeUpdate(poiCode, shippingTime string) (err error) { // 美团要求必须是jpg|jpeg图片格式,且imgName必须以jpg或jpeg结尾 // 此接口虽然要求poiCode参数,但经过测试,发现上传的图片可以跨门店使用 +// imgName好像不支持中文,否则会报签名错 func (a *API) ImageUpload(poiCode, imgName string, imgData []byte) (imgID string, err error) { result, err := a.AccessAPI("image/upload", false, map[string]interface{}{ KeyAppPoiCode: poiCode, From 349e9ad088558d50714e14512b442bec08a0e1d8 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 26 Sep 2019 11:13:43 +0800 Subject: [PATCH 66/71] =?UTF-8?q?=E5=8E=BB=E6=8E=89fmt.Println?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/store_page.go | 2 +- platformapi/mtwmapi/mtwmapi.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platformapi/jdapi/store_page.go b/platformapi/jdapi/store_page.go index f5337ea2..c4184570 100644 --- a/platformapi/jdapi/store_page.go +++ b/platformapi/jdapi/store_page.go @@ -207,7 +207,7 @@ func (a *API) AccessStorePage2(fullURL string, params map[string]interface{}, is fw.Write(imgData.([]byte)) } for k, v := range params { - fmt.Println(k, " ", v) + // baseapi.SugarLogger.Debug(k, " ", v) w.WriteField(k, url.QueryEscape(fmt.Sprint(v))) } w.Close() diff --git a/platformapi/mtwmapi/mtwmapi.go b/platformapi/mtwmapi/mtwmapi.go index 1d00454d..e6aa16be 100644 --- a/platformapi/mtwmapi/mtwmapi.go +++ b/platformapi/mtwmapi/mtwmapi.go @@ -143,7 +143,7 @@ func (a *API) AccessAPI2(cmd string, isGet bool, bizParams map[string]interface{ fw.Write(imgData.([]byte)) } for k, v := range params { - fmt.Println(k, " ", v) + // baseapi.SugarLogger.Debug(k, " ", v) w.WriteField(k, url.QueryEscape(fmt.Sprint(v))) } w.Close() From 949bca2c1c1026a40df363b130ec283eae6e629a Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 26 Sep 2019 15:43:55 +0800 Subject: [PATCH 67/71] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=A4=E7=82=B9?= =?UTF-8?q?=E9=97=B4=E6=AD=A5=E8=A1=8C=E8=B7=9D=E7=A6=BB=E5=87=BD=E6=95=B0?= =?UTF-8?q?=EF=BC=9AWalkingDistance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/autonavi/autonavi.go | 25 ++++++++++++++++++++++--- platformapi/autonavi/autonavi_test.go | 5 +++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/platformapi/autonavi/autonavi.go b/platformapi/autonavi/autonavi.go index 5a75f3f3..9ff7e07c 100644 --- a/platformapi/autonavi/autonavi.go +++ b/platformapi/autonavi/autonavi.go @@ -133,6 +133,10 @@ func (a *API) signParams(mapData map[string]interface{}) string { return fmt.Sprintf("%X", md5.Sum([]byte(finalStr))) } +func coordinate2String(lng, lat float64) (str string) { + return fmt.Sprintf("%.6f,%.6f", lng, lat) +} + func (a *API) AccessAPI(apiStr string, params map[string]interface{}) (retVal ResponseResult, err error) { params2 := utils.MergeMaps(utils.Params2Map("key", a.key, "output", "json"), params) params2[signKey] = a.signParams(params2) @@ -183,7 +187,7 @@ func (a *API) CoordinateConvert(lng, lat float64, coordsys string) (retLng, retL return 0.0, 0.0, nil } params := map[string]interface{}{ - "locations": fmt.Sprintf("%.6f,%.6f", lng, lat), + "locations": coordinate2String(lng, lat), "coordsys": coordsys, } result, err := a.AccessAPI("assistant/coordinate/convert", params) @@ -201,7 +205,7 @@ func (a *API) BatchCoordinateConvert(coords []*Coordinate, coordsys string) (out } var coordsStrList []string for _, v := range coords { - coordsStrList = append(coordsStrList, fmt.Sprintf("%.6f,%.6f", v.Lng, v.Lat)) + coordsStrList = append(coordsStrList, coordinate2String(v.Lng, v.Lat)) } params := map[string]interface{}{ "locations": strings.Join(coordsStrList, "|"), @@ -260,7 +264,7 @@ func (a *API) GetCoordinateDistrictCode(lng, lat float64) (districtCode int) { func (a *API) GetCoordinateAreaInfo(lng, lat float64) (areaInfo map[string]interface{}, err error) { params := map[string]interface{}{ - "location": fmt.Sprintf("%.6f,%.6f", lng, lat), + "location": coordinate2String(lng, lat), } result, err := a.AccessAPI("geocode/regeo", params) return result, err @@ -325,3 +329,18 @@ func (a *API) getDistrictsFromInterface(districts interface{}) (districtList []* func GetDistrictLevel(levelName string) (level int) { return levelStr2IntMap[levelName] } + +// 两点之间的步行距离,单位为米 +func (a *API) WalkingDistance(lng1, lat1, lng2, lat2 float64) (distance float64) { + params := map[string]interface{}{ + "origin": coordinate2String(lng1, lat1), + "destination": coordinate2String(lng2, lat2), + } + result, err := a.AccessAPI("direction/walking", params) + if err == nil { + if paths, _ := result["route"].(map[string]interface{})["paths"].([]interface{}); len(paths) > 0 { + distance = utils.Interface2Float64WithDefault(paths[0].(map[string]interface{})["distance"], 0) + } + } + return distance +} diff --git a/platformapi/autonavi/autonavi_test.go b/platformapi/autonavi/autonavi_test.go index 4e21dd05..26fd32a1 100644 --- a/platformapi/autonavi/autonavi_test.go +++ b/platformapi/autonavi/autonavi_test.go @@ -88,3 +88,8 @@ func TestGetCoordinateFromAddress(t *testing.T) { lng, lat, districtCode := autonaviAPI.GetCoordinateFromAddress("天府广场", "成都市") t.Logf("lng:%f, lat:%f, districtCode:%d", lng, lat, districtCode) } + +func TestWalkingDistance(t *testing.T) { + distance := autonaviAPI.WalkingDistance(104.057289, 30.694798, 104.066289, 30.695598) + t.Logf("distance:%f", distance) +} From 34d95a4f46d23cc795e5418cc907174b404b5794 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 27 Sep 2019 15:36:00 +0800 Subject: [PATCH 68/71] =?UTF-8?q?jdapi.GetSkuPageInfo=E4=B8=8D=E7=94=A8map?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/store_page.go | 62 +++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/platformapi/jdapi/store_page.go b/platformapi/jdapi/store_page.go index c4184570..6b8c7a07 100644 --- a/platformapi/jdapi/store_page.go +++ b/platformapi/jdapi/store_page.go @@ -140,6 +140,59 @@ type PageShopInfo struct { StoreShareURL string `json:"storeShareUrl"` } +type PageSku struct { + ButtonEnable bool `json:"buttonEnable"` + CatID string `json:"catId"` + FixedStatus bool `json:"fixedStatus"` + FuncIndicatins string `json:"funcIndicatins"` + H5SwichItem struct { + IsLeadApp bool `json:"isLeadApp"` + } `json:"h5SwichItem"` + HasSaleAttr bool `json:"hasSaleAttr"` + IconType int `json:"iconType"` + Image []*SkuPageImg `json:"image"` + InCartCount int `json:"inCartCount"` + IsInScope bool `json:"isInScope"` + IsRemind bool `json:"isRemind"` + MarkingPrice string `json:"markingPrice"` + Name string `json:"name"` + OrgCode string `json:"orgCode"` + Prescription bool `json:"prescription"` + PriceUnit string `json:"priceUnit"` + ProductComment struct { + CommentNum string `json:"commentNum"` + GoodRate float64 `json:"goodRate"` + GoodRating string `json:"goodRating"` + HasMore bool `json:"hasMore"` + TotalScore string `json:"totalScore"` + } `json:"productComment"` + ProductInfoType int `json:"productInfoType"` + ProductType int `json:"productType"` + ProductTypeEnum string `json:"productTypeEnum"` + ShareProductURL string `json:"shareProductUrl"` + ShowState int `json:"showState"` + ShowStateEnum string `json:"showStateEnum"` + ShowStateName string `json:"showStateName"` + ShowTimLine bool `json:"showTimLine"` + SkuID int64 `json:"skuId"` + SkuPriceVO struct { + BasicPrice string `json:"basicPrice"` + MkPrice string `json:"mkPrice"` + Promotion int `json:"promotion"` + RealTimePrice string `json:"realTimePrice"` + SkuID string `json:"skuId"` + } `json:"skuPriceVO"` + Standard string `json:"standard"` + StoreInfo struct { + Show bool `json:"show"` + StoreID string `json:"storeId"` + } `json:"storeInfo"` + Subtitle string `json:"subtitle"` + Tags []string `json:"tags"` + UserActionSku string `json:"userActionSku"` + VenderID string `json:"venderId"` +} + const ( QualifyTypeCompany = "25" // 营业执照 QualifyTypePerson = "22" // 身份证,个体工商户要求填 @@ -322,7 +375,7 @@ func (a *API) GetStoreOrderInfoList(fromTime, toTime string) (storeOrderList []m return nil, err } -func (a *API) GetSkuPageInfo(skuId int64) (skuPageInfo map[string]interface{}, err error) { +func (a *API) GetSkuPageInfo(skuId int64) (skuPageInfo *PageSku, err error) { skuIDMap := map[string]interface{}{ "skuId": utils.Int64ToStr(skuId), "storeId": "0", @@ -334,14 +387,17 @@ func (a *API) GetSkuPageInfo(skuId int64) (skuPageInfo map[string]interface{}, e "body": utils.Format4Output(skuIDMap, true), } - skuPageInfo, err = a.AccessStorePage("https://daojia.jd.com/client", params, false) + result, err := a.AccessStorePage("https://daojia.jd.com/client", params, false) + if err == nil { + err = utils.Map2StructByJson(result, &skuPageInfo, false) + } return skuPageInfo, err } func (a *API) GetSkuPageImageInfo(skuId int64) (imgList []*SkuPageImg, err error) { skuPageInfo, err := a.GetSkuPageInfo(skuId) if err == nil { - err = utils.Map2StructByJson(skuPageInfo["image"], &imgList, false) + imgList = skuPageInfo.Image } return imgList, err } From 9e46a9195d188efe49bba30c2677f570817c4028 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 27 Sep 2019 18:37:14 +0800 Subject: [PATCH 69/71] =?UTF-8?q?=E6=98=93=E8=81=94=E4=BA=91=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E6=9C=BA=E6=B7=BB=E5=8A=A0GetOrderPagingList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/yilianyunapi/yilianyunapi.go | 22 +++++++++++++++++++ platformapi/yilianyunapi/yilianyunapi_test.go | 12 +++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/platformapi/yilianyunapi/yilianyunapi.go b/platformapi/yilianyunapi/yilianyunapi.go index 2f562bf0..ef08c085 100644 --- a/platformapi/yilianyunapi/yilianyunapi.go +++ b/platformapi/yilianyunapi/yilianyunapi.go @@ -56,6 +56,15 @@ type TokenInfo struct { MachineCode string `json:"machine_code"` } +type PrinterOrderResult struct { + Content string `json:"content"` + ID string `json:"id"` + OriginID string `json:"origin_id"` + PrintTime string `json:"print_time"` + ReceivingTime string `json:"receiving_time"` + Status int `json:"status"` +} + func New(clientID, clientSecret string, config ...*platformapi.APIConfig) *API { curConfig := platformapi.DefAPIConfig if len(config) > 0 { @@ -256,3 +265,16 @@ func (a *API) CancelAll(machineCode, token string) (err error) { func (a *API) PlayText(machineCode, orderID, text, token string) (err error) { return a.printMsg(machineCode, orderID, fmt.Sprintf("", strings.Replace(text, ",", ".", -1)), token) } + +// pageIndex从1开始,pageSize最大为100 +func (a *API) GetOrderPagingList(machineCode, token string, pageIndex, pageSize int) (orderResultList []*PrinterOrderResult, err error) { + result, err := a.AccessAPI("printer/getorderpaginglist", map[string]interface{}{ + "machine_code": machineCode, + "page_index": pageIndex, + "page_size": pageSize, + }, token) + if err != nil { + err = utils.Map2StructByJson(result, &orderResultList, false) + } + return orderResultList, err +} diff --git a/platformapi/yilianyunapi/yilianyunapi_test.go b/platformapi/yilianyunapi/yilianyunapi_test.go index 0117898c..f39b0601 100644 --- a/platformapi/yilianyunapi/yilianyunapi_test.go +++ b/platformapi/yilianyunapi/yilianyunapi_test.go @@ -20,11 +20,11 @@ func init() { baseapi.Init(sugarLogger) // 自有应用 - // api = New("1039586024", "4885d07c2997b661102e4b6099c0bf3b") - // api.SetToken("7884617f9eeb4c28933569f94a95b5c3") + api = New("1039586024", "4885d07c2997b661102e4b6099c0bf3b") + api.SetToken("3a38e3cec7974b459a6f0a381c9b0312") // 开放应用 - api = New("1098307169", "d5eedb40c99e6691b1ca2ba82a363d6a") + // api = New("1098307169", "d5eedb40c99e6691b1ca2ba82a363d6a") } func handleError(t *testing.T, err error) { @@ -97,3 +97,9 @@ func TestRefreshToken(t *testing.T) { handleError(t, err) t.Log(utils.Format4Output(tokenInfo, true)) } + +func TestGetOrderPagingList(t *testing.T) { + result, err := api.GetOrderPagingList("4004613792", "", 1, 50) + handleError(t, err) + t.Log(utils.Format4Output(result, true)) +} From 6a20301c9ee44b1a128072f43160740c68ea69fa Mon Sep 17 00:00:00 2001 From: gazebo Date: Sun, 29 Sep 2019 17:10:54 +0800 Subject: [PATCH 70/71] =?UTF-8?q?=E6=B7=BB=E5=8A=A0utils.IsPtrTimeZero?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/typeconv.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils/typeconv.go b/utils/typeconv.go index c1b76479..e81d978d 100644 --- a/utils/typeconv.go +++ b/utils/typeconv.go @@ -335,6 +335,10 @@ func IsTimeZero(timeValue time.Time) bool { return timeValue == DefaultTimeValue || timeValue == ZeroTimeValue } +func IsPtrTimeZero(timePtr *time.Time) bool { + return timePtr == nil || *timePtr == DefaultTimeValue || *timePtr == ZeroTimeValue +} + func HTTPBody2Values(data []byte, needDecode bool) (url.Values, error) { bodyStr := string(data) if needDecode { From 38076317aa31184069ce319815e732e6328aac91 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 8 Oct 2019 11:24:19 +0800 Subject: [PATCH 71/71] =?UTF-8?q?CorporationInfo=E4=B8=AD=E5=8E=BB?= =?UTF-8?q?=E6=8E=89NeedID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/store_page.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platformapi/jdapi/store_page.go b/platformapi/jdapi/store_page.go index 6b8c7a07..b162c194 100644 --- a/platformapi/jdapi/store_page.go +++ b/platformapi/jdapi/store_page.go @@ -40,9 +40,9 @@ type CorporationInfo struct { EconKind string `json:"econ_kind"` EndDate string `json:"end_date"` TermEnd string `json:"term_end"` - NeedID bool `json:"needID"` - Address string `json:"address"` - Partners []struct { + // NeedID bool `json:"needID"` + Address string `json:"address"` + Partners []struct { IdentifyType string `json:"identify_type"` ShouldCapiItems []interface{} `json:"should_capi_items"` StockType string `json:"stock_type"`