美团配送状态,京东商城

This commit is contained in:
苏尹岚
2020-05-08 09:40:51 +08:00
parent f1d789b724
commit 221e8cf45f
6 changed files with 285 additions and 70 deletions

View File

@@ -2,8 +2,10 @@ package jdeclpapi
import (
"fmt"
"math"
"regexp"
"testing"
"time"
"git.rosy.net.cn/baseapi/utils"
@@ -91,6 +93,39 @@ func TestQueryStock(t *testing.T) {
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"`
@@ -137,9 +172,9 @@ func TestAA(t *testing.T) {
var skus []*JxSkuInfo
weight := 0
sku1 := &JxSkuInfo{
SkuID: 6039387,
Weight: 1400,
Count: 2,
SkuID: 6039507,
Weight: 2620,
Count: 1,
}
skus = append(skus, sku1)
weight += sku1.Count * sku1.Weight
@@ -151,9 +186,9 @@ func TestAA(t *testing.T) {
skus = append(skus, sku2)
weight += sku2.Count * sku2.Weight
sku3 := &JxSkuInfo{
SkuID: 6039381,
Weight: 280,
Count: 4,
SkuID: 6039393,
Weight: 2540,
Count: 1,
}
skus = append(skus, sku3)
weight += sku3.Count * sku3.Weight
@@ -214,59 +249,6 @@ func tryToSplitMatterOrder(jxOrder *JxOrderInfo) (outOrders []*JxOrderInfo, frei
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
@@ -291,7 +273,7 @@ func loop2(weightList []*JxSkuInfo2, storeID int, weight *int) (outOrder *JxOrde
outOrder = &JxOrderInfo{}
outOrder.StoreID = storeID
sum3 := 0
if *weight <= 5000 {
if *weight <= 4500 {
for i := 0; i < len(weightList); i++ {
weightList[i].GroupSign = true
outOrder.Weight += weightList[i].Weight
@@ -341,3 +323,92 @@ func loop2(weightList []*JxSkuInfo2, storeID int, weight *int) (outOrder *JxOrde
}
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))
}