- 从spec中取美团外卖订单商品的weight
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||||
@@ -39,6 +40,10 @@ const (
|
|||||||
callDeliveryDelayGap = 30
|
callDeliveryDelayGap = 30
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
specPat = regexp.MustCompile(`(\d+)(.+)`)
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
VendorStatus2StatusMap = map[string]int{
|
VendorStatus2StatusMap = map[string]int{
|
||||||
mtwmapi.OrderStatusUserCommitted: model.OrderStatusUnknown,
|
mtwmapi.OrderStatusUserCommitted: model.OrderStatusUnknown,
|
||||||
@@ -130,7 +135,6 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
|||||||
for _, product := range detail {
|
for _, product := range detail {
|
||||||
// product := product2.(map[string]interface{})
|
// product := product2.(map[string]interface{})
|
||||||
skuName := product["food_name"].(string)
|
skuName := product["food_name"].(string)
|
||||||
_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(skuName)
|
|
||||||
skuID := utils.Interface2String(product["sku_id"])
|
skuID := utils.Interface2String(product["sku_id"])
|
||||||
sku := &model.OrderSku{
|
sku := &model.OrderSku{
|
||||||
VendorOrderID: order.VendorOrderID,
|
VendorOrderID: order.VendorOrderID,
|
||||||
@@ -139,7 +143,7 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
|||||||
SkuID: int(utils.Str2Int64WithDefault(skuID, 0)),
|
SkuID: int(utils.Str2Int64WithDefault(skuID, 0)),
|
||||||
VendorSkuID: skuID,
|
VendorSkuID: skuID,
|
||||||
SkuName: skuName,
|
SkuName: skuName,
|
||||||
Weight: jxutils.FormatSkuWeight(specQuality, specUnit), // 订单信息里没有重量,只有名字里尝试找
|
Weight: getSkuWeight(product),
|
||||||
SalePrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(product["price"])),
|
SalePrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(product["price"])),
|
||||||
// PromotionType: int(utils.MustInterface2Int64(product["promotionType"])),
|
// PromotionType: int(utils.MustInterface2Int64(product["promotionType"])),
|
||||||
}
|
}
|
||||||
@@ -179,6 +183,18 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
|||||||
return order
|
return order
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getSkuWeight(product map[string]interface{}) (weight int) {
|
||||||
|
searchResult := specPat.FindStringSubmatch(product["spec"].(string))
|
||||||
|
if len(searchResult) == 3 {
|
||||||
|
weight = jxutils.FormatSkuWeight(float32(utils.Str2Float64WithDefault(searchResult[1], 0)), utils.TrimBlankChar(searchResult[2]))
|
||||||
|
}
|
||||||
|
if weight == 0 {
|
||||||
|
_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(product["food_name"].(string))
|
||||||
|
weight = jxutils.FormatSkuWeight(specQuality, specUnit)
|
||||||
|
}
|
||||||
|
return weight
|
||||||
|
}
|
||||||
|
|
||||||
func (c *PurchaseHandler) onOrderMsg(msg *mtwmapi.CallbackMsg) (response *mtwmapi.CallbackResponse) {
|
func (c *PurchaseHandler) onOrderMsg(msg *mtwmapi.CallbackMsg) (response *mtwmapi.CallbackResponse) {
|
||||||
var err error
|
var err error
|
||||||
if c.isAfsMsg(msg) {
|
if c.isAfsMsg(msg) {
|
||||||
|
|||||||
Reference in New Issue
Block a user