eclp增加仓库查询接口,增加银豹api
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package jdeclpapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
@@ -80,3 +82,262 @@ func TestSearchShopStock(t *testing.T) {
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestQueryStock(t *testing.T) {
|
||||
result, err := api.QueryStock("JX10001")
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user