! GoodsOrder与OrderSku添加VendorPrice表示平台价,而SalePrice表示单品优惠之后的价格

This commit is contained in:
gazebo
2019-06-11 23:49:21 +08:00
parent 07f8b120f8
commit 7f939333df
6 changed files with 76 additions and 35 deletions

View File

@@ -333,11 +333,7 @@ func (c *OrderManager) updateOrderOtherInfo(order *model.GoodsOrder, db *dao.Dao
}
order.JxStoreID = storeMap.StoreID
if err = c.updateOrderSkuOtherInfo(order, db); err == nil {
if order.Weight == 0 {
for _, v := range order.Skus {
order.Weight += v.Weight
}
}
jxutils.RefreshOrderSkuRelated(order)
}
return err
}

View File

@@ -447,11 +447,13 @@ func RefreshOrderSkuRelated(order *model.GoodsOrder) *model.GoodsOrder {
order.SkuCount = 0
order.GoodsCount = 0
order.SalePrice = 0
order.VendorPrice = 0
order.Weight = 0
for _, sku := range order.Skus {
order.SkuCount++
order.GoodsCount += sku.Count
order.SalePrice += sku.SalePrice * int64(sku.Count)
order.VendorPrice += sku.VendorPrice * int64(sku.Count)
order.Weight += sku.Weight * sku.Count
}
return order

View File

@@ -16,8 +16,9 @@ type GoodsOrder struct {
StoreID int `orm:"column(store_id)" json:"storeID"` // 外部系统里记录的 jxstoreid
JxStoreID int `orm:"column(jx_store_id)" json:"jxStoreID"` // 根据VendorStoreID在本地系统里查询出来的 jxstoreid
StoreName string `orm:"size(64)" json:"storeName"`
ShopPrice int64 `json:"shopPrice"` // 单位为分 门店标
SalePrice int64 `json:"salePrice"` // 单位为分 售卖
ShopPrice int64 `json:"shopPrice"` // 京西
VendorPrice int64 `json:"vendorPrice"` // 平台
SalePrice int64 `json:"salePrice"` // 售卖价
ActualPayPrice int64 `json:"actualPayPrice"` // 单位为分 顾客实际支付
Weight int `json:"weight"` // 单位为克
ConsigneeName string `orm:"size(32)" json:"consigneeName"`
@@ -85,7 +86,8 @@ type OrderSku struct {
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"` // 门店标
ShopPrice int64 `json:"shopPrice"` // 京西
VendorPrice int64 `json:"vendorPrice"` // 平台价
SalePrice int64 `json:"salePrice"` // 售卖价
Weight int `json:"weight"` // 单位为克
SkuType int `json:"skuType"` // 当前如果为gift就为1否则缺省为0

View File

@@ -119,7 +119,8 @@ func (p *PurchaseHandler) partRefund2OrderDetailSkuList(orderID string, orderDet
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"]),
VendorPrice: utils.MustInterface2Int64(product["product_price"]),
SalePrice: getSkuSalePrice(product),
}
if sku.Weight == 0 {
sku.Weight = jxutils.FormatSkuWeight(specQuality, specUnit) // 订单信息里没有重量,只有名字里尝试找
@@ -204,7 +205,8 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
VendorSkuID: utils.Interface2String(product["baidu_product_id"]),
SkuName: skuName,
Weight: int(utils.Interface2Int64WithDefault(product["total_weight"], 0)) / productAmount,
SalePrice: utils.MustInterface2Int64(product["product_price"]),
VendorPrice: utils.MustInterface2Int64(product["product_price"]),
SalePrice: getSkuSalePrice(product),
// PromotionType: int(utils.MustInterface2Int64(product["promotionType"])),
}
if sku.Weight == 0 {
@@ -219,6 +221,26 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
return order
}
func getSkuSalePrice(product map[string]interface{}) (salePrice int64) {
var product2 *ebaiapi.OrderProductInfo
if err := utils.Map2StructByJson(product, &product2, true); err != nil {
return utils.MustInterface2Int64(product["product_price"])
}
return int64(getSkuSalePrice2(product2))
}
func getSkuSalePrice2(product *ebaiapi.OrderProductInfo) (salePrice int) {
salePrice = product.ProductPrice
if product.ProductSubsidy != nil {
for _, v := range product.ProductSubsidy.DiscountDetail {
if v.Type == ebaiapi.OrderSkuDiscountTypeZhe {
salePrice -= v.BaiduRate + v.ShopRate
}
}
}
return salePrice
}
func (p *PurchaseHandler) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool, userName string) (err error) {
globals.SugarLogger.Debugf("ebai AcceptOrRefuseOrder orderID:%s, isAcceptIt:%t", order.VendorOrderID, isAcceptIt)
if isAcceptIt {

View File

@@ -160,6 +160,7 @@ func (c *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(product["skuId"])),
SkuName: product["skuName"].(string),
Weight: jxutils.FloatWeight2Int(float32(utils.MustInterface2Float64(product["skuWeight"]))),
VendorPrice: utils.MustInterface2Int64(product["skuStorePrice"]),
SalePrice: utils.MustInterface2Int64(product["skuJdPrice"]),
PromotionType: int(utils.MustInterface2Int64(product["promotionType"])),
}

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"net/url"
"regexp"
"strings"
"time"
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
@@ -62,6 +63,12 @@ var (
fakeUserUndoApplyCancel: model.OrderStatusUndoApplyCancel,
fakeMerchantAgreeApplyCancel: model.OrderStatusCanceled,
}
skuActTypeMap = map[int]int{
mtwmapi.ExtrasPromotionTypeTeJiaCai: 1,
mtwmapi.ExtrasPromotionTypeZheKouCai: 1,
mtwmapi.ExtrasPromotionTypeSecondHalfPrice: 1,
}
)
func (p *PurchaseHandler) GetStatusFromVendorStatus(vendorStatus string) int {
@@ -132,34 +139,10 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
if err := utils.UnmarshalUseNumber([]byte(result["detail"].(string)), &detail); err != nil {
panic(fmt.Sprintf("mtwm Map2Order vendorID:%s failed with error:%v", vendorOrderID, err))
}
// detail := result["detail"].([]interface{})
for _, product := range detail {
// product := product2.(map[string]interface{})
skuName := product["food_name"].(string)
skuID := utils.Interface2String(product["sku_id"])
sku := &model.OrderSku{
VendorOrderID: order.VendorOrderID,
VendorID: model.VendorIDMTWM,
Count: int(utils.MustInterface2Float64(product["quantity"])),
SkuID: int(utils.Str2Int64WithDefault(skuID, 0)),
VendorSkuID: skuID,
SkuName: skuName,
Weight: getSkuWeight(product),
SalePrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(product["price"])),
// PromotionType: int(utils.MustInterface2Int64(product["promotionType"])),
}
if sku.Weight == 0 {
sku.Weight = 222 // 如果名字里找不到缺省给半斤左右的一个特别值
}
// if product["isGift"].(bool) {
// sku.SkuType = 1
// }
order.Skus = append(order.Skus, sku)
}
// 添加需要赠送的东西
var extraList []*mtwmapi.OrderExtraInfo
if result["extras"] != nil {
var extraList []*mtwmapi.OrderExtraInfo
if err := utils.UnmarshalUseNumber([]byte(result["extras"].(string)), &extraList); err != nil {
panic(fmt.Sprintf("mtwm Map2Order vendorID:%s failed with error:%v", vendorOrderID, err))
}
@@ -180,6 +163,41 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
}
}
ignoreSkuMap := make(map[int]int)
// detail := result["detail"].([]interface{})
for _, product := range detail {
// product := product2.(map[string]interface{})
skuName := product["food_name"].(string)
skuID := utils.Interface2String(product["sku_id"])
sku := &model.OrderSku{
VendorOrderID: order.VendorOrderID,
VendorID: model.VendorIDMTWM,
Count: int(utils.MustInterface2Float64(product["quantity"])),
SkuID: int(utils.Str2Int64WithDefault(skuID, 0)),
VendorSkuID: skuID,
SkuName: skuName,
Weight: getSkuWeight(product),
VendorPrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(product["price"])),
SalePrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(product["price"])),
// PromotionType: int(utils.MustInterface2Int64(product["promotionType"])),
}
if sku.Weight == 0 {
sku.Weight = 222 // 如果名字里找不到缺省给半斤左右的一个特别值
}
if ignoreSkuMap[sku.SkuID] == 0 && sku.Count == 1 {
for _, v := range extraList {
if skuActTypeMap[v.Type] == 1 && strings.Index(v.Remark, skuName) >= 0 {
ignoreSkuMap[sku.SkuID] = 1
sku.SalePrice -= jxutils.StandardPrice2Int(v.ReduceFee)
}
}
}
// if product["isGift"].(bool) {
// sku.SkuType = 1
// }
order.Skus = append(order.Skus, sku)
}
jxutils.RefreshOrderSkuRelated(order)
return order
}