- 修复饿百调整单消息没有正确更新订单信息的BUG
This commit is contained in:
@@ -421,3 +421,17 @@ func HandleUserWXRemark(db *dao.DaoDB, mobile string) (err error) {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func RefreshOrderSkuRelated(order *model.GoodsOrder) *model.GoodsOrder {
|
||||
order.SkuCount = 0
|
||||
order.GoodsCount = 0
|
||||
order.SalePrice = 0
|
||||
order.Weight = 0
|
||||
for _, sku := range order.Skus {
|
||||
order.SkuCount++
|
||||
order.GoodsCount += sku.Count
|
||||
order.SalePrice += sku.SalePrice * int64(sku.Count)
|
||||
order.Weight += sku.Weight * sku.Count
|
||||
}
|
||||
return order
|
||||
}
|
||||
|
||||
@@ -88,15 +88,15 @@ type OrderSku struct {
|
||||
StoreSubID int `orm:"column(store_sub_id)" json:"storeSubID"`
|
||||
StoreSubName string `orm:"size(64)" json:"storeSubName"`
|
||||
Count int `json:"count"`
|
||||
VendorSkuID string `orm:"column(vendor_sku_id);size(48)" json:"-"`
|
||||
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"` // 门店标价
|
||||
SalePrice int64 `json:"salePrice"` // 售卖价
|
||||
Weight int `json:"-"` // 单位为克
|
||||
SkuType int `json:"-"` // 当前如果为gift就为1,否则缺省为0
|
||||
PromotionType int `json:"-"` // todo 当前是用于记录京东的PromotionType(生成jxorder用),没有做转换
|
||||
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:"-"` // 分区考虑
|
||||
SkuPmSubsidy int64 `json:"-"` //平台商品活动补贴
|
||||
SkuPmFee int64 `json:"-"` //门店商品活动支出
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/autonavi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
@@ -68,6 +70,63 @@ func (p *PurchaseHandler) getOrder(vendorOrderID string) (order *model.GoodsOrde
|
||||
return order, result, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetOrder4PartRefund(vendorOrderID string) (order *model.GoodsOrder, err error) {
|
||||
taskIDs := []int{1, 2}
|
||||
var (
|
||||
err1, err2 error
|
||||
result1, result2 map[string]interface{}
|
||||
)
|
||||
task := tasksch.NewParallelTask("GetOrder4PartRefund", nil, jxcontext.AdminCtx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
taskID := batchItemList[0].(int)
|
||||
if taskID == 1 {
|
||||
result1, err1 = api.EbaiAPI.OrderGet(vendorOrderID)
|
||||
} else if taskID == 2 {
|
||||
result2, err2 = api.EbaiAPI.OrderPartrefundGet(vendorOrderID)
|
||||
}
|
||||
return nil, nil
|
||||
}, taskIDs)
|
||||
task.Run()
|
||||
task.GetResult(0)
|
||||
if err1 == nil {
|
||||
order = p.Map2Order(result1)
|
||||
if err2 == nil {
|
||||
order.Skus = p.partRefund2OrderDetailSkuList(utils.Interface2String(result2["order_id"]), result2["order_detail"])
|
||||
jxutils.RefreshOrderSkuRelated(order)
|
||||
} else if err2Ext, ok := err2.(*utils.ErrorWithCode); !ok || err2Ext.IntCode() != ebaiapi.ErrOrderIsNotPartRefund {
|
||||
err = err2
|
||||
}
|
||||
} else {
|
||||
err = err1
|
||||
}
|
||||
return order, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) partRefund2OrderDetailSkuList(orderID string, orderDetail2 interface{}) (skuList []*model.OrderSku) {
|
||||
orderDetail := orderDetail2.([]interface{})
|
||||
for _, product2 := range orderDetail {
|
||||
product := product2.(map[string]interface{})
|
||||
skuName := product["name"].(string)
|
||||
_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(skuName)
|
||||
number := int(utils.MustInterface2Int64(product["number"]))
|
||||
sku := &model.OrderSku{
|
||||
VendorOrderID: orderID,
|
||||
VendorID: model.VendorIDEBAI,
|
||||
Count: number,
|
||||
SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product[ebaiapi.KeyCustomSkuID]), 0)),
|
||||
VendorSkuID: utils.Interface2String(product[ebaiapi.KeySkuID]),
|
||||
SkuName: skuName,
|
||||
// Weight: int(utils.Interface2Int64WithDefault(product["total_weight"], 0)) / number, // 退单这里的total_weight有BUG,这里的total_weight还是没有退单时的值
|
||||
SalePrice: utils.MustInterface2Int64(product["product_price"]),
|
||||
}
|
||||
if sku.Weight == 0 {
|
||||
sku.Weight = jxutils.FormatSkuWeight(specQuality, specUnit) // 订单信息里没有重量,只有名字里尝试找
|
||||
}
|
||||
skuList = append(skuList, sku)
|
||||
}
|
||||
return skuList
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *model.GoodsOrder) {
|
||||
result := orderData
|
||||
shopMap := result["shop"].(map[string]interface{})
|
||||
@@ -134,29 +193,27 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
||||
product := product2.(map[string]interface{})
|
||||
skuName := product["product_name"].(string)
|
||||
_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(skuName)
|
||||
productAmount := int(utils.MustInterface2Int64(product["product_amount"]))
|
||||
sku := &model.OrderSku{
|
||||
VendorOrderID: order.VendorOrderID,
|
||||
VendorID: model.VendorIDEBAI,
|
||||
Count: int(utils.MustInterface2Int64(product["product_amount"])),
|
||||
Count: productAmount,
|
||||
SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product[ebaiapi.KeyCustomSkuID]), 0)),
|
||||
VendorSkuID: utils.Interface2String(product["baidu_product_id"]),
|
||||
SkuName: skuName,
|
||||
Weight: jxutils.FormatSkuWeight(specQuality, specUnit), // 订单信息里没有重量,只有名字里尝试找
|
||||
Weight: int(utils.Interface2Int64WithDefault(product["total_weight"], 0)) / productAmount,
|
||||
SalePrice: utils.MustInterface2Int64(product["product_price"]),
|
||||
// PromotionType: int(utils.MustInterface2Int64(product["promotionType"])),
|
||||
}
|
||||
if sku.Weight == 0 {
|
||||
sku.Weight = 222 // 如果名字里找不到缺省给半斤左右的一个特别值
|
||||
sku.Weight = jxutils.FormatSkuWeight(specQuality, specUnit) // 订单信息里没有重量,只有名字里尝试找
|
||||
}
|
||||
// if product["isGift"].(bool) {
|
||||
// sku.SkuType = 1
|
||||
// }
|
||||
order.Skus = append(order.Skus, sku)
|
||||
order.SkuCount++
|
||||
order.GoodsCount += sku.Count
|
||||
order.SalePrice += sku.SalePrice * int64(sku.Count)
|
||||
order.Weight += sku.Weight * sku.Count
|
||||
}
|
||||
jxutils.RefreshOrderSkuRelated(order)
|
||||
// setOrederDetailFee(result, order)
|
||||
return order
|
||||
}
|
||||
@@ -245,7 +302,14 @@ func (c *PurchaseHandler) onOrderMsg(msg *ebaiapi.CallbackMsg) (retVal *ebaiapi.
|
||||
status := c.callbackMsg2Status(msg)
|
||||
var err error
|
||||
if status != nil {
|
||||
err = partner.CurOrderManager.OnOrderStatusChanged(status)
|
||||
if status.Status == model.OrderStatusAdjust {
|
||||
var order *model.GoodsOrder
|
||||
if order, err = c.GetOrder4PartRefund(GetOrderIDFromMsg(msg)); err == nil {
|
||||
err = partner.CurOrderManager.OnOrderAdjust(order, status.VendorStatus)
|
||||
}
|
||||
} else {
|
||||
err = partner.CurOrderManager.OnOrderStatusChanged(status)
|
||||
}
|
||||
}
|
||||
retVal = api.EbaiAPI.Err2CallbackResponse(msg.Cmd, err, nil)
|
||||
}
|
||||
|
||||
16
business/partner/purchase/ebai/order_test.go
Normal file
16
business/partner/purchase/ebai/order_test.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package ebai
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
func TestGetOrder4PartRefund(t *testing.T) {
|
||||
order, err := new(PurchaseHandler).GetOrder4PartRefund("1556530656022029520")
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
} else {
|
||||
t.Log(utils.Format4Output(order, false))
|
||||
}
|
||||
}
|
||||
@@ -190,12 +190,9 @@ func (c *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
||||
sku.VendorSkuID = utils.Int64ToStr(utils.MustInterface2Int64(product["id"])) // 2018-09-28日,饿了么迁移到饿百后,这个字段发生了变化
|
||||
}
|
||||
order.Skus = append(order.Skus, sku)
|
||||
order.SkuCount++
|
||||
order.GoodsCount += sku.Count
|
||||
order.SalePrice += sku.SalePrice * int64(sku.Count)
|
||||
order.Weight += sku.Weight * sku.Count
|
||||
}
|
||||
}
|
||||
jxutils.RefreshOrderSkuRelated(order)
|
||||
setOrederDetailFee(result, order)
|
||||
return order
|
||||
}
|
||||
|
||||
@@ -153,11 +153,8 @@ func (c *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
||||
sku.SkuType = 1
|
||||
}
|
||||
order.Skus = append(order.Skus, sku)
|
||||
order.SkuCount++
|
||||
order.GoodsCount += sku.Count
|
||||
order.SalePrice += sku.SalePrice * int64(sku.Count)
|
||||
order.Weight += sku.Weight * sku.Count
|
||||
}
|
||||
jxutils.RefreshOrderSkuRelated(order)
|
||||
setOrederDetailFee(result, order)
|
||||
return order
|
||||
}
|
||||
|
||||
@@ -146,11 +146,8 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
||||
// sku.SkuType = 1
|
||||
// }
|
||||
order.Skus = append(order.Skus, sku)
|
||||
order.SkuCount++
|
||||
order.GoodsCount += sku.Count
|
||||
order.SalePrice += sku.SalePrice * int64(sku.Count)
|
||||
order.Weight += sku.Weight * sku.Count
|
||||
}
|
||||
jxutils.RefreshOrderSkuRelated(order)
|
||||
// setOrederDetailFee(result, order)
|
||||
return order
|
||||
}
|
||||
|
||||
@@ -158,11 +158,8 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
||||
SalePrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(item["price"])),
|
||||
}
|
||||
order.Skus = append(order.Skus, sku)
|
||||
order.SkuCount++
|
||||
order.GoodsCount += sku.Count
|
||||
order.SalePrice += sku.SalePrice * int64(sku.Count)
|
||||
order.Weight += sku.Weight * sku.Count
|
||||
}
|
||||
jxutils.RefreshOrderSkuRelated(order)
|
||||
p.arrangeSaleStore(order, utils.Interface2String(logisticsDeliveryDetail["receiverCity"]), utils.Interface2String(logisticsDeliveryDetail["receiverProvince"]))
|
||||
p.setStoreOrderSeq(order)
|
||||
return order
|
||||
|
||||
Reference in New Issue
Block a user