package jdeclpapi import ( "fmt" "math" "regexp" "testing" "time" "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("bcb6201b5b3c45a0976dcda5e2dea8aejiwm", "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("EMG4418113943423") if err != nil { t.Fatal(err) } t.Log(utils.Format4Output(result, false)) } func TestQueryStock(t *testing.T) { result, err := api.QueryStock("EMG4418113943423") if err != nil { t.Fatal(err) } t.Log(utils.Format4Output(result, false)) } func TestWaybillReceive(t *testing.T) { err := api.WaybillReceive(&WaybillReceiveParam{ SalePlat: SalePlatSourceDelivery, CustomerCode: CustomerCode, OrderID: utils.GetUUID(), SenderName: "测试", SenderAddress: "测试地址1", ReceiveName: "测试", ReceiveAddress: "测试地址1", PackageCount: 1, Weight: 1, Vloumn: 10000, }) if err != nil { t.Fatal(err) } // t.Log(utils.Format4Output(result, false)) } func TestCancelWayBill(t *testing.T) { err := api.CancelWayBill(&CancelWayBillParam{ WaybillCode: "11", CustomerCode: CustomerCode, Source: "JOS", CancelReason: "测试", OperatorName: "jxadmin", }) 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: 6039507, Weight: 2620, Count: 1, } 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)) }