package jdeclpapi import ( "fmt" "regexp" "testing" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi" "go.uber.org/zap" ) var ( api *API sugarLogger *zap.SugaredLogger ) func init() { logger, _ := zap.NewDevelopment() sugarLogger = logger.Sugar() baseapi.Init(sugarLogger) api = New("7e9c1a5fe4ac4ea48c3c572d488e60b8hnwz", "0D397F05CF11C51BCDCC81744680EBC3", "f16a5e57ff4f4f428b702c40d2d4b933") } func TestQuerySpSource(t *testing.T) { result, err := api.QuerySpSource() if err != nil { t.Fatal(err) } t.Log(utils.Format4Output(result, false)) } func TestAddOrder(t *testing.T) { result, err := api.AddOrder(&AddOrderParam{ IsvUUID: "88321464273509", IsvSource: IsvSource, ShopNo: ShopNo, DepartmentNo: DepartmentNo, WarehouseNo: WarehouseNo, SalePlatformSource: SalePlatformSource, SalesPlatformOrderNo: "88321464273509", ConsigneeName: "测试用户", ConsigneeMobile: "18160030913", ConsigneeAddress: "成都市金牛区", OrderMark: OrderMark, // IsvGoodsNo: "JX10012,JX10011", Price: "0,0", Quantity: "1,2", GoodsNo: "EMG4418111927871,EMG4418111927871", }) if err != nil { t.Fatal(err) } t.Log(utils.Format4Output(result, false)) } func TestCancelOrder(t *testing.T) { result, err := api.CancelOrder("ESL96778168766975") if err != nil { t.Fatal(err) } t.Log(utils.Format4Output(result, false)) } func TestQueryOrderStatus(t *testing.T) { result, err := api.QueryOrderStatus("ESL96778164878526") if err != nil { t.Fatal(err) } t.Log(utils.Format4Output(result, false)) } func TestGetTrackMessagePlusByOrder(t *testing.T) { result, err := api.GetTrackMessagePlusByOrder("46304726013148") if err != nil { t.Fatal(err) } t.Log(utils.Format4Output(result, false)) } func TestSearchShopStock(t *testing.T) { result, err := api.SearchShopStock("") if err != nil { t.Fatal(err) } t.Log(utils.Format4Output(result, false)) } func TestQueryStock(t *testing.T) { result, err := api.QueryStock("") if err != nil { t.Fatal(err) } 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: 6039387, Weight: 1400, Count: 2, } 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: 6039381, Weight: 280, Count: 4, } 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 loop(weightList []*JxSkuInfo2, jxOrder *JxOrderInfo, flag bool) (outOrder *JxOrderInfo) { outOrder = &JxOrderInfo{} outOrder.StoreID = jxOrder.StoreID sum5 := 0 sum3 := 0 for i := 0; i < len(weightList); i++ { if flag { if weightList[i].Weight+sum5 <= 5000 { sum5 += weightList[i].Weight weightList[i].GroupSign = true if len(outOrder.Skus) > 0 { for _, v := range outOrder.Skus { if v.SkuID == weightList[i].SkuID { v.Count++ } else { outOrder.Skus = append(outOrder.Skus, jxOrderChange(weightList[i])) } } } else { outOrder.Skus = append(outOrder.Skus, jxOrderChange(weightList[i])) } } else { if sum5 >= 5000 { break } continue } } else { if weightList[i].Weight+sum3 <= 3000 { sum3 += weightList[i].Weight weightList[i].GroupSign = true if len(outOrder.Skus) > 0 { for _, v := range outOrder.Skus { if v.SkuID == weightList[i].SkuID { v.Count++ } else { 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 } 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 <= 5000 { 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 }