From 9eefd9a7298cfaceb83ef0477181ec315123533e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 28 Oct 2020 09:36:13 +0800 Subject: [PATCH] =?UTF-8?q?jd=20=E6=9F=A5=E8=AF=A2=E7=89=A9=E6=B5=81?= =?UTF-8?q?=E9=87=8D=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdeclpapi/jdeclpapi.go | 19 ++ platformapi/jdeclpapi/jdeclpapi_test.go | 293 +----------------------- platformapi/weixinapi/weixinapi_test.go | 28 +-- 3 files changed, 38 insertions(+), 302 deletions(-) diff --git a/platformapi/jdeclpapi/jdeclpapi.go b/platformapi/jdeclpapi/jdeclpapi.go index 66e5fae2..d37e52c9 100644 --- a/platformapi/jdeclpapi/jdeclpapi.go +++ b/platformapi/jdeclpapi/jdeclpapi.go @@ -437,3 +437,22 @@ func (a *API) QueryDynamicTraceInfo(waybillCode string) (err error) { }) return err } + +type WaybillQueryResult struct { + Weight float64 `json:"weight"` + DeliveryID string `json:"deliveryId"` + GoodNumber int `json:"goodNumber"` +} + +//京东物流运单查询 +//https://open.jd.com/home/home#/doc/api?apiCateId=64&apiId=2189&apiName=jingdong.ldop.waybill.query +func (a *API) WaybillQuery(deliveryId string) (waybill *WaybillQueryResult, err error) { + result, err := a.AccessAPI("jingdong.ldop.waybill.query", prodURL, map[string]interface{}{ + "deliveryId": deliveryId, + "customerCode": CustomerCode, + }) + if err == nil { + utils.Map2StructByJson(result["jingdong_ldop_waybill_query_responce"].(map[string]interface{})["resultInfo"].(map[string]interface{})["data"], &waybill, false) + } + return waybill, err +} diff --git a/platformapi/jdeclpapi/jdeclpapi_test.go b/platformapi/jdeclpapi/jdeclpapi_test.go index 6a6163a0..1cd87cb9 100644 --- a/platformapi/jdeclpapi/jdeclpapi_test.go +++ b/platformapi/jdeclpapi/jdeclpapi_test.go @@ -1,11 +1,7 @@ package jdeclpapi import ( - "fmt" - "math" - "regexp" "testing" - "time" "git.rosy.net.cn/baseapi/utils" @@ -130,289 +126,10 @@ func TestCancelWayBill(t *testing.T) { // t.Log(utils.Format4Output(result, false)) } -type JxOrderInfo struct { - BuyerComment string `json:"buyerComment"` - StoreID int `json:"storeID"` - Skus []*JxSkuInfo `json:"skus"` - - ExpectedDeliveredTimestamp int64 `json:"expectedDeliveredTimestamp"` // 预期送达时间 - - TotalPrice int64 `json:"totalPrice"` // 单位为分 订单总价 - FreightPrice int64 `json:"freightPrice"` // 单位为分 订单配送费 - OrderPrice int64 `json:"orderPrice"` // 单位为分 订单商品价格 - ActualPayPrice int64 `json:"actualPayPrice"` // 单位为分 顾客实际支付 - - OrderID int64 `json:"orderID"` - StoreName string `json:"storeName"` - Weight int `json:"weight"` - FromStoreID int `json:"fromStoreID"` -} - -type JxSkuInfo struct { - SkuID int `json:"skuID"` - Count int `json:"count"` - - Price int64 `json:"price,omitempty"` // 原价 - SalePrice int64 `json:"salePrice,omitempty"` // 售卖价 - - Name string `json:"name"` - Weight int `json:"weight"` - GroupSign bool `json:"groupSign"` -} - -type JxSkuInfo2 struct { - SkuID int `json:"skuID"` - Count int `json:"count"` - - Price int64 `json:"price,omitempty"` // 原价 - SalePrice int64 `json:"salePrice,omitempty"` // 售卖价 - - Name string `json:"name"` - Weight int `json:"weight"` - GroupSign bool `json:"groupSign"` -} - -func TestAA(t *testing.T) { - var skus []*JxSkuInfo - weight := 0 - sku1 := &JxSkuInfo{ - SkuID: 6039507, - Weight: 2620, - Count: 1, +func TestWaybillQuery(t *testing.T) { + result, err := api.WaybillQuery("JDVD01093075824") + if err != nil { + t.Fatal(err) } - skus = append(skus, sku1) - weight += sku1.Count * sku1.Weight - sku2 := &JxSkuInfo{ - SkuID: 6039382, - Weight: 1460, - Count: 1, - } - skus = append(skus, sku2) - weight += sku2.Count * sku2.Weight - sku3 := &JxSkuInfo{ - SkuID: 6039393, - Weight: 2540, - Count: 1, - } - skus = append(skus, sku3) - weight += sku3.Count * sku3.Weight - jxOrderInfo := &JxOrderInfo{ - StoreID: 666666, - Skus: skus, - FromStoreID: 100118, - Weight: weight, - } - _, _, _ = tryToSplitMatterOrder(jxOrderInfo) - // t.Log(utils.Format4Output(result1, false)) -} - -func tryToSplitMatterOrder(jxOrder *JxOrderInfo) (outOrders []*JxOrderInfo, freightPrice int, err error) { - var ( - skus = jxOrder.Skus - weightList []*JxSkuInfo2 - // flag = true - ) - for _, v := range skus { - for i := 0; i < v.Count; i++ { - var sku2 = &JxSkuInfo2{} - sku2.Count = v.Count - sku2.Name = v.Name - sku2.Price = v.Price - sku2.SalePrice = v.SalePrice - sku2.Weight = v.Weight - sku2.SkuID = v.SkuID - weightList = append(weightList, sku2) - } - } - for i := 0; i < len(weightList)-1; i++ { - for j := 0; j < len(weightList)-i-1; j++ { - if weightList[j].Weight < weightList[j+1].Weight { - tmp := weightList[j] - weightList[j] = weightList[j+1] - weightList[j+1] = tmp - } - } - } - weight := jxOrder.Weight - for { - outOrders = append(outOrders, loop2(weightList, jxOrder.StoreID, &weight)) - for i := 0; i < len(weightList); { - if weightList[i].GroupSign { - var weightList3 []*JxSkuInfo2 - weightList3 = append(weightList[:i], weightList[i+1:]...) - weightList = weightList3 - } else { - i++ - } - } - if len(weightList) == 0 { - break - } - } - fmt.Println(utils.Format4Output(outOrders, false)) - return outOrders, freightPrice, err -} - -func jxOrderChange(sku2 *JxSkuInfo2) *JxSkuInfo { - sku := &JxSkuInfo{} - sku.Count = 1 - sku.Name = sku2.Name - sku.Price = sku2.Price - sku.SalePrice = sku2.SalePrice - sku.SkuID = sku2.SkuID - sku.Weight = sku2.Weight - return sku -} - -func TestBB(t *testing.T) { - regexpCnameAndCmobile := regexp.MustCompile(`配送员,(.*),手机号,(.*)`) - s := "配送员开始配送,请您准备收货,配送员,彭林,手机号,18008096393" - result := regexpCnameAndCmobile.FindAllStringSubmatch(s, -1) - cName := result[0][1] - cMobile := result[0][2] - fmt.Println(cName, cMobile) -} - -func loop2(weightList []*JxSkuInfo2, storeID int, weight *int) (outOrder *JxOrderInfo) { - outOrder = &JxOrderInfo{} - outOrder.StoreID = storeID - sum3 := 0 - if *weight <= 4500 { - for i := 0; i < len(weightList); i++ { - weightList[i].GroupSign = true - outOrder.Weight += weightList[i].Weight - if len(outOrder.Skus) > 0 { - var flag = false - for _, v := range outOrder.Skus { - if v.SkuID == weightList[i].SkuID { - v.Count++ - flag = true - } - } - if !flag { - outOrder.Skus = append(outOrder.Skus, jxOrderChange(weightList[i])) - } - } else { - outOrder.Skus = append(outOrder.Skus, jxOrderChange(weightList[i])) - } - } - } else { - for i := 0; i < len(weightList); i++ { - if weightList[i].Weight+sum3 <= 3000 { - sum3 += weightList[i].Weight - weightList[i].GroupSign = true - outOrder.Weight += weightList[i].Weight - *weight -= weightList[i].Weight - if len(outOrder.Skus) > 0 { - var flag = false - for _, v := range outOrder.Skus { - if v.SkuID == weightList[i].SkuID { - v.Count++ - flag = true - } - } - if !flag { - outOrder.Skus = append(outOrder.Skus, jxOrderChange(weightList[i])) - } - } else { - outOrder.Skus = append(outOrder.Skus, jxOrderChange(weightList[i])) - } - } else { - if sum3 >= 3000 { - break - } - continue - } - } - } - return outOrder -} - -type OrderSku struct { - ID int64 `orm:"column(id)" json:"-"` - VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` - VendorID int `orm:"column(vendor_id)" json:"vendorID"` - StoreSubID int `orm:"column(store_sub_id)" json:"storeSubID"` // EarningActID,当前这个字段被当成结算活动ID用 - StoreSubName string `orm:"size(64)" json:"storeSubName"` // 当前这个字段被用作vendorActType - Count int `json:"count"` - VendorSkuID string `orm:"column(vendor_sku_id);size(48)" json:"vendorSkuID"` - SkuID int `orm:"column(sku_id)" json:"skuID"` // 外部系统里记录的 jxskuid - JxSkuID int `orm:"column(jx_sku_id)" json:"jxSkuID"` // 根据VendorSkuID在本地系统里查询出来的 jxskuid - SkuName string `orm:"size(255)" json:"skuName"` - ShopPrice int64 `json:"shopPrice"` // 京西价 - VendorPrice int64 `json:"vendorPrice"` // 平台价 - SalePrice int64 `json:"salePrice"` // 售卖价 - EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱,如果结算活动ID为0,是按结算比例算的,否则就是结算表中的值 - Weight int `json:"weight"` // 单位为克 - SkuType int `json:"skuType"` // 当前如果为gift就为1,否则缺省为0 - PromotionType int `json:"promotionType"` // todo 当前是用于记录京东的PromotionType(生成jxorder用),没有做转换 - OrderCreatedAt time.Time `orm:"type(datetime);index" json:"-"` // 分区考虑 -} - -type tSkuCountPrice struct { - Count int `json:"count"` - SalePrice int64 `json:"salePrice"` -} - -func TestCC(t *testing.T) { - var orderSkus = []*OrderSku{ - &OrderSku{ - SkuID: 30783, - Count: 1, - ShopPrice: 438, - SalePrice: 390, - EarningPrice: 312, - }, - &OrderSku{ - SkuID: 30783, - Count: 2, - ShopPrice: 438, - SalePrice: 490, - EarningPrice: 312, - }, - &OrderSku{ - SkuID: 32914, - Count: 2, - ShopPrice: 400, - SalePrice: 660, - EarningPrice: 320, - }, - &OrderSku{ - SkuID: 32914, - Count: 1, - ShopPrice: 400, - SalePrice: 650, - EarningPrice: 320, - }, - } - var skuMultiCountMap = make(map[int][]*tSkuCountPrice) - for _, v := range orderSkus { - skuMultiCountMap[v.SkuID] = append(skuMultiCountMap[v.SkuID], &tSkuCountPrice{ - Count: v.Count, - SalePrice: v.SalePrice, - }) - } - var storePayPercentage int = 70 - for _, v := range orderSkus { - if v.EarningPrice > 0 { - if len(skuMultiCountMap[v.SkuID]) > 1 { - var price = 0 - for _, vv := range skuMultiCountMap[v.SkuID] { - if int(vv.SalePrice) > price { - price = int(vv.SalePrice) - } - } - if price == int(v.SalePrice) { - var earningPrice = 0 - if v.ShopPrice < v.SalePrice { - earningPrice = int(utils.Float64TwoInt64(math.Round(utils.Int2Float64(int(v.ShopPrice)) * utils.Int2Float64(storePayPercentage) / 100))) - } else { - earningPrice = int(utils.Float64TwoInt64(math.Round(utils.Int2Float64(int(v.SalePrice)) * utils.Int2Float64(storePayPercentage) / 100))) - } - v.EarningPrice = int64(earningPrice) - } - } - } - } - fmt.Println(utils.Format4Output(orderSkus, false)) + t.Log(utils.Format4Output(result, false)) } diff --git a/platformapi/weixinapi/weixinapi_test.go b/platformapi/weixinapi/weixinapi_test.go index 40368bfb..5979fdd3 100644 --- a/platformapi/weixinapi/weixinapi_test.go +++ b/platformapi/weixinapi/weixinapi_test.go @@ -2,8 +2,6 @@ package weixinapi import ( "fmt" - "regexp" - "strings" "testing" "git.rosy.net.cn/baseapi" @@ -24,9 +22,12 @@ func init() { // sandbox // api = New("wxbf235770edaabc5c", "ba32b269a068a5b72486a0beafd171e8") - // prod - api = New("wx2bb99eb5d2c9b82c", "6bbbed1443cc062c20a015a64c07a531") - api.CBSetToken("36_un9YOYENTdiNi4TVoDfrb2oiiU9XSugSgbm0B-uJ4TbhVk543aOi5UcBgYcujsCZ1gyCIMDbaKCON7oWMHtHRLCg1P2KzjRhxU3KoVbNZ04PPzdDOXStnigkoSLTxv-y9pbenFP0kHYHUeRHQEUeAHAJXN") + // // prod + // api = New("wx2bb99eb5d2c9b82c", "6bbbed1443cc062c20a015a64c07a531") + + //weixinapp + api = New("wx18111a41fd17f24f", "c79ac6e1b2d6d7968e72a9658a8b6715") + // api.CBSetToken("36_un9YOYENTdiNi4TVoDfrb2oiiU9XSugSgbm0B-uJ4TbhVk543aOi5UcBgYcujsCZ1gyCIMDbaKCON7oWMHtHRLCg1P2KzjRhxU3KoVbNZ04PPzdDOXStnigkoSLTxv-y9pbenFP0kHYHUeRHQEUeAHAJXN") } func handleError(t *testing.T, err error) { @@ -35,13 +36,12 @@ func handleError(t *testing.T, err error) { t.Fatal(err.Error()) } } -func TestTest(t *testing.T) { - sensitiveWordRegexp := regexp.MustCompile(`包含敏感词:(\[.*\])`) - subSensitiveWordRegexp := regexp.MustCompile(`[^\[\]\"\}]`) - findResult := sensitiveWordRegexp.FindStringSubmatch("商品[山鸡蛋约500g/份]包含敏感词:[商品名称]不得包含[山鸡];") - fmt.Println(findResult) - if findResult != nil && len(findResult) > 1 { - findSubResult := subSensitiveWordRegexp.FindAllString(findResult[1], -1) - fmt.Println(strings.Join(findSubResult, "")) - } + +func aa() { + fmt.Println("hello") +} + +func TestTest(t *testing.T) { + go aa() + fmt.Println("world") }