- 从spec中取美团外卖订单商品的weight

This commit is contained in:
gazebo
2019-05-28 10:20:23 +08:00
parent 281f7b1b55
commit d74c64db83

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net/url"
"regexp"
"time"
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
@@ -39,6 +40,10 @@ const (
callDeliveryDelayGap = 30
)
var (
specPat = regexp.MustCompile(`(\d+)(.+)`)
)
var (
VendorStatus2StatusMap = map[string]int{
mtwmapi.OrderStatusUserCommitted: model.OrderStatusUnknown,
@@ -130,7 +135,6 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
for _, product := range detail {
// product := product2.(map[string]interface{})
skuName := product["food_name"].(string)
_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(skuName)
skuID := utils.Interface2String(product["sku_id"])
sku := &model.OrderSku{
VendorOrderID: order.VendorOrderID,
@@ -139,7 +143,7 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
SkuID: int(utils.Str2Int64WithDefault(skuID, 0)),
VendorSkuID: skuID,
SkuName: skuName,
Weight: jxutils.FormatSkuWeight(specQuality, specUnit), // 订单信息里没有重量,只有名字里尝试找
Weight: getSkuWeight(product),
SalePrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(product["price"])),
// PromotionType: int(utils.MustInterface2Int64(product["promotionType"])),
}
@@ -179,6 +183,18 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
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) {
var err error
if c.isAfsMsg(msg) {