From 061e906d17e91aec9eec49912077e7db8d4a8adf Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 18 Jul 2019 18:35:59 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E6=AD=A3=E5=90=84=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E4=B8=8E=E6=8B=89=E5=8F=96=E8=AE=A2=E5=8D=95=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84API=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/order.go | 2 +- platformapi/ebaiapi/order_test.go | 9 ++ platformapi/jdapi/order.go | 162 ++++++++++++++++++++++++++---- platformapi/jdapi/order_test.go | 1 + platformapi/mtwmapi/mtwmapi.go | 3 +- platformapi/mtwmapi/order.go | 42 ++++++++ platformapi/mtwmapi/order_test.go | 9 ++ utils/typeconv.go | 5 + 8 files changed, 210 insertions(+), 23 deletions(-) diff --git a/platformapi/ebaiapi/order.go b/platformapi/ebaiapi/order.go index b0cc9926..bd596118 100644 --- a/platformapi/ebaiapi/order.go +++ b/platformapi/ebaiapi/order.go @@ -476,7 +476,7 @@ func (a *API) OrderListAll(shopID string, baiduShopID int64, startTime, endTime return nil, err } listOrder = append(listOrder, result.List...) - if result.Page == result.Pages { + if result.Page >= result.Pages { break } page++ diff --git a/platformapi/ebaiapi/order_test.go b/platformapi/ebaiapi/order_test.go index 16142693..6bd2c3b6 100644 --- a/platformapi/ebaiapi/order_test.go +++ b/platformapi/ebaiapi/order_test.go @@ -33,6 +33,15 @@ func TestOrderList(t *testing.T) { } } +func TestOrderListAll(t *testing.T) { + result, err := api.OrderListAll("", 32267089397, 1563379200, 1563465599, 0) + if err != nil { + t.Fatal(err) + } else { + t.Log(utils.Format4Output(result, false)) + } +} + func TestOrderPartRefundGet(t *testing.T) { result, err := api.OrderPartRefundGet("1557459492221457830") if err != nil { diff --git a/platformapi/jdapi/order.go b/platformapi/jdapi/order.go index 318a7813..ce56763f 100644 --- a/platformapi/jdapi/order.go +++ b/platformapi/jdapi/order.go @@ -177,6 +177,139 @@ type OrderSettlementInfo struct { VenderSkuGoodsDiscountMoney int64 `json:"venderSkuGoodsDiscountMoney"` } +type OrderProductInfo struct { + AdjustMode int `json:"adjustMode"` + CanteenMoney int `json:"canteenMoney"` + CategoryID string `json:"categoryId"` + FirstCategoryName string `json:"firstCategoryName"` + IsGift bool `json:"isGift"` + PromotionType int `json:"promotionType"` + SkuCount int `json:"skuCount"` + SkuID int `json:"skuId"` + SkuJdPrice int `json:"skuJdPrice"` + SkuName string `json:"skuName"` + SkuSpuID int `json:"skuSpuId"` + SkuStockOwner int `json:"skuStockOwner"` + SkuStorePrice int `json:"skuStorePrice"` + SkuWeight float64 `json:"skuWeight"` + UpcCode string `json:"upcCode,omitempty"` + SpecialServiceTag string `json:"specialServiceTag,omitempty"` +} + +type OrderInfo struct { + AdjustCount int `json:"adjustCount"` + AdjustID int `json:"adjustId"` + AdjustIsExists bool `json:"adjustIsExists"` + AppVersion string `json:"appVersion"` + ArtificerPortraitURL string `json:"artificerPortraitUrl"` + BusinessTag string `json:"businessTag"` + BusinessType int `json:"businessType"` + BuyerCity string `json:"buyerCity"` + BuyerCityName string `json:"buyerCityName"` + BuyerCoordType int `json:"buyerCoordType"` + BuyerCountry string `json:"buyerCountry"` + BuyerCountryName string `json:"buyerCountryName"` + BuyerFullAddress string `json:"buyerFullAddress"` + BuyerFullName string `json:"buyerFullName"` + BuyerIP int `json:"buyerIp"` + BuyerLat float64 `json:"buyerLat"` + BuyerLng float64 `json:"buyerLng"` + BuyerMobile string `json:"buyerMobile"` + BuyerPin string `json:"buyerPin"` + BuyerPinType int `json:"buyerPinType"` + BuyerPoi string `json:"buyerPoi"` + BuyerProvince string `json:"buyerProvince"` + CancelDeadline string `json:"cancelDeadline"` + CancelOperator string `json:"cancelOperator"` + CancelOrderIsReadable bool `json:"cancelOrderIsReadable"` + CancelRequestTime string `json:"cancelRequestTime"` + ClientOrderPreStartDeliveryTime string `json:"clientOrderPreStartDeliveryTime"` + DeliveryBillNo string `json:"deliveryBillNo"` + DeliveryCarrierName string `json:"deliveryCarrierName"` + DeliveryCarrierNo string `json:"deliveryCarrierNo"` + DeliveryDelayAgreed int `json:"deliveryDelayAgreed"` + DeliveryPackageVolume float64 `json:"deliveryPackageVolume"` + DeliveryPackageWeight float64 `json:"deliveryPackageWeight"` + DeliveryStationName string `json:"deliveryStationName"` + DeliveryStationNo string `json:"deliveryStationNo"` + DeliveryStationNoIsv string `json:"deliveryStationNoIsv"` + DeliveryType int `json:"deliveryType"` + EquipmentID string `json:"equipmentId"` + GrabMark int `json:"grabMark"` + IndustryTag int `json:"industryTag"` + IsDeleted bool `json:"isDeleted"` + IsGroupon bool `json:"isGroupon"` + IsJDGetCash bool `json:"isJDGetCash"` + LastFourDigitsOfBuyerMobile string `json:"lastFourDigitsOfBuyerMobile"` + LocalDeliveryMoney int `json:"localDeliveryMoney"` + MerchantPaymentDistanceFreightMoney int `json:"merchantPaymentDistanceFreightMoney"` + OrderAcceptTime string `json:"orderAcceptTime"` + OrderAdditionFreightMoney int `json:"orderAdditionFreightMoney"` + OrderAgingType int `json:"orderAgingType"` + OrderBalanceUsed int `json:"orderBalanceUsed"` + OrderBaseFreightMoney int `json:"orderBaseFreightMoney"` + OrderBaseReceivableFreight int `json:"orderBaseReceivableFreight"` + OrderBuyerPayableMoney int `json:"orderBuyerPayableMoney"` + OrderBuyerRemark string `json:"orderBuyerRemark"` + OrderCancelRemark string `json:"orderCancelRemark"` + OrderCancelTime string `json:"orderCancelTime"` + OrderDiscountMoney int `json:"orderDiscountMoney"` + OrderDistanceStepFreight int `json:"orderDistanceStepFreight"` + OrderFinanceOrgCode int `json:"orderFinanceOrgCode"` + OrderFreightMoney int `json:"orderFreightMoney"` + OrderGoodsMoney int `json:"orderGoodsMoney"` + OrderID int64 `json:"orderId"` + OrderInvoiceOpenMark int `json:"orderInvoiceOpenMark"` + OrderIsClosed bool `json:"orderIsClosed"` + OrderJingdouMoney int `json:"orderJingdouMoney"` + OrderLadderFreightMoney int `json:"orderLadderFreightMoney"` + OrderNum int `json:"orderNum"` + OrderPayType int `json:"orderPayType"` + OrderPreDeliveryTime string `json:"orderPreDeliveryTime"` + OrderPreEndDeliveryTime string `json:"orderPreEndDeliveryTime"` + OrderPreStartDeliveryTime string `json:"orderPreStartDeliveryTime"` + OrderPurchaseTime string `json:"orderPurchaseTime"` + OrderReceivableFreight int `json:"orderReceivableFreight"` + OrderSkuType int `json:"orderSkuType"` + OrderStartTime string `json:"orderStartTime"` + OrderStatus int `json:"orderStatus"` + OrderStatusTime string `json:"orderStatusTime"` + OrderStockOwner int `json:"orderStockOwner"` + OrderTakeSelfCode string `json:"orderTakeSelfCode"` + OrderTotalMoney int `json:"orderTotalMoney"` + OrderType int `json:"orderType"` + OrderVenderChargeMoney int `json:"orderVenderChargeMoney"` + OrgCode string `json:"orgCode"` + PackagingMoney int `json:"packagingMoney"` + PayChannel int `json:"payChannel"` + PickDeadline string `json:"pickDeadline"` + PickMark int `json:"pickMark"` + PlatformPointsDeductionMoney int `json:"platformPointsDeductionMoney"` + PrescriptionDTO struct { + IsRigorous bool `json:"isRigorous"` + } `json:"prescriptionDTO"` + PrintMark int `json:"printMark"` + ProduceStationName string `json:"produceStationName"` + ProduceStationNo string `json:"produceStationNo"` + ProduceStationNoIsv string `json:"produceStationNoIsv"` + Product []*OrderProductInfo `json:"product"` + SrcInnerOrderID int `json:"srcInnerOrderId"` + SrcInnerType int `json:"srcInnerType"` + SrcOrderID string `json:"srcOrderId"` + SrcOrderType int `json:"srcOrderType"` + SrcPlatID int `json:"srcPlatId"` + StoreLat float64 `json:"storeLat"` + StoreLng float64 `json:"storeLng"` + Tips int `json:"tips"` + Ts string `json:"ts"` + UpdatePin string `json:"updatePin"` + UserTip int `json:"userTip"` + VenderBalanceDeductMoney int `json:"venderBalanceDeductMoney"` + VenderIntegralDeductMoney int `json:"venderIntegralDeductMoney"` + VenderProcessResult string `json:"venderProcessResult"` + Yn bool `json:"yn"` +} + var ( ErrCanNotFindOrder = errors.New("can not find order") ) @@ -203,6 +336,14 @@ 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 取件服务费(开票)(正向单展示远距离运费;售后单则展示达达售后运费) @@ -220,27 +361,6 @@ func (a *API) QuerySingleOrder(orderId string) (map[string]interface{}, error) { return result[0].(map[string]interface{}), nil } -func (a *API) LegacyQuerySingleOrder(orderId string) (map[string]interface{}, error) { - jdParams := make(map[string]interface{}) - jdParams["orderId"] = orderId - - result, err := a.AccessAPI("order/es/query", jdParams) - if err != nil { - return nil, err - } - - dataStr, _ := result["data"].(string) - var data map[string]interface{} - utils.UnmarshalUseNumber([]byte(dataStr), &data) - result["data"] = data - - var dataResult map[string]interface{} - utils.UnmarshalUseNumber([]byte(data["result"].(string)), &dataResult) - data["result"] = dataResult - - return result, nil -} - // 商家确认接单接口 // 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 88de4ba8..18e65ff6 100644 --- a/platformapi/jdapi/order_test.go +++ b/platformapi/jdapi/order_test.go @@ -31,6 +31,7 @@ func TestOrderQuery(t *testing.T) { if err != nil { t.Fatalf("OrderQuery return error:%v", err) } + t.Log(utils.Format4Output(result, false)) if len(result) == 0 || totalCount == 0 { t.Fatal("OrderQuery return empty data") diff --git a/platformapi/mtwmapi/mtwmapi.go b/platformapi/mtwmapi/mtwmapi.go index 15f50f18..95aecb1b 100644 --- a/platformapi/mtwmapi/mtwmapi.go +++ b/platformapi/mtwmapi/mtwmapi.go @@ -45,6 +45,7 @@ const ( ErrCodeAccessLimited = 711 // 接口调用过于频繁,触发流控,请降低调用频率 ErrCodeNoAppFood = 805 // 不存在此菜品 + ErrCodeNoSuchOrder = 808 // 不存在此订单 ErrCodeSkuCategoryNotExist = 1021 // 菜品分类不存在 ErrCodeSkuCategoryExist = 1037 // 菜品分类已存在 ) @@ -159,6 +160,7 @@ func (a *API) AccessAPI2(cmd string, isGet bool, bizParams map[string]interface{ if jsonResult1 == nil { return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil") } + retVal = jsonResult1[resultKey] if errObj, ok := jsonResult1["error"]; ok { baseapi.SugarLogger.Debugf("mtwm AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true)) errorInfo := errObj.(map[string]interface{}) @@ -168,7 +170,6 @@ func (a *API) AccessAPI2(cmd string, isGet bool, bizParams map[string]interface{ } return platformapi.ErrLevelCodeIsNotOK, newErr } - retVal = jsonResult1[resultKey] return platformapi.ErrLevelSuccess, nil }) err = platformapi.RebuildError(err, bizParams, []string{ diff --git a/platformapi/mtwmapi/order.go b/platformapi/mtwmapi/order.go index a9c5ffad..c866efff 100644 --- a/platformapi/mtwmapi/order.go +++ b/platformapi/mtwmapi/order.go @@ -1,6 +1,8 @@ package mtwmapi import ( + "time" + "git.rosy.net.cn/baseapi/utils" ) @@ -84,6 +86,10 @@ const ( ExtrasPromotionTypeShanGouBaoPin = 56 // 闪购爆品 ) +const ( + MaxGap4GetOrderIdByDaySeq = 100 +) + type RefundSku struct { AppFoodCode string `json:"app_food_code"` SkuID string `json:"sku_id,omitempty"` @@ -297,6 +303,11 @@ type OrderActInfo struct { } `json:"act_detail_list"` } +type GetOrderIdByDaySeqResult struct { + Result string `json:"result"` + OrderIDs []int64 `json:"order_ids"` +} + func (a *API) OrderReceived(orderID int64) (err error) { _, err = a.AccessAPI("order/poi_received", true, map[string]interface{}{ KeyOrderID: orderID, @@ -508,3 +519,34 @@ func (a *API) GetOrderActDetail(queryData []*GetOrderActDetailParam) (orderActLi } return orderActList, err } + +func (a *API) GetOrderDaySeq(poiCode string) (daySeq int, err error) { + params := map[string]interface{}{ + KeyAppPoiCode: poiCode, + } + result, err := a.AccessAPI("order/getOrderDaySeq", true, params) + if err == nil { + daySeq = int(utils.MustInterface2Int64(result.(map[string]interface{})["day_seq"])) + } + return daySeq, err +} + +// 订单流水号的开始序号,门店内每日的订单流水号都是从1开始。 +// 订单流水号的结束序号,注意开始流水号与结束流水号的跨度需小于100,即差值最大为99 +// 这个函数在给定的区间范围全部没有订单时,返回错误808,但如果有部分订单,返回的错误是0 +func (a *API) GetOrderIdByDaySeq(poiCode string, dateTime time.Time, seqStart, seqEnd int) (vendorOrderIDs []int64, err error) { + params := map[string]interface{}{ + KeyAppPoiCode: poiCode, + "date_time": dateTime.Format("20060102"), + "day_seq_start": seqStart, + "day_seq_end": seqEnd, + } + result, err := a.AccessAPI("ecommerce/order/getOrderIdByDaySeq", true, params) + if extErr, ok := err.(*utils.ErrorWithCode); (ok && extErr.IntCode() == 0) || err == nil { + var data GetOrderIdByDaySeqResult + if err2 := utils.UnmarshalUseNumber([]byte(utils.Interface2String(result)), &data); err2 == nil { + vendorOrderIDs = data.OrderIDs + } + } + return vendorOrderIDs, err +} diff --git a/platformapi/mtwmapi/order_test.go b/platformapi/mtwmapi/order_test.go index fda51cf5..838ac1d5 100644 --- a/platformapi/mtwmapi/order_test.go +++ b/platformapi/mtwmapi/order_test.go @@ -2,6 +2,7 @@ package mtwmapi import ( "testing" + "time" "git.rosy.net.cn/baseapi/utils" ) @@ -113,3 +114,11 @@ func TestGetOrderActDetaill(t *testing.T) { } t.Log(utils.Format4Output(result, false)) } + +func TestGetOrderIdByDaySeq(t *testing.T) { + result, err := api.GetOrderIdByDaySeq("7111597", utils.Time2Date(time.Now()), 1, 100) + t.Log(utils.Format4Output(result, false)) + if err != nil { + t.Fatal(err) + } +} diff --git a/utils/typeconv.go b/utils/typeconv.go index 67459739..b0cbabba 100644 --- a/utils/typeconv.go +++ b/utils/typeconv.go @@ -281,6 +281,11 @@ func Time2TimeStr(t time.Time) string { return t.Format("15:04:05") } +func Time2Date(t time.Time) time.Time { + year, month, day := t.Date() + return time.Date(year, month, day, 0, 0, 0, 0, t.Location()) +} + func Time2DateStr(t time.Time) string { return t.Format("2006-01-02") }