From 7a4eb0cce36d4b29b59d3084a94606c804dce644 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 19 Jun 2019 22:45:14 +0800 Subject: [PATCH] =?UTF-8?q?+=20GoodsOrder=E6=B7=BB=E5=8A=A0EarningPrice?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E7=BB=93=E7=AE=97=E7=BB=99=E9=97=A8=E5=BA=97?= =?UTF-8?q?=E7=9A=84=E9=87=91=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/order.go | 33 +++++++++++++++----- business/jxcallback/orderman/orderman_ext.go | 4 +-- business/model/const.go | 4 +++ business/model/order.go | 1 + 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index fb9a9a441..7e7c7faa8 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -349,22 +349,39 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao. func (c *OrderManager) updateOrderOtherInfo(order *model.GoodsOrder, db *dao.DaoDB) (err error) { globals.SugarLogger.Debugf("updateOrderOtherInfo orderID:%s, VendorStoreID:%s", order.VendorOrderID, order.VendorStoreID) - storeMap := &model.StoreMap{ - VendorID: order.VendorID, - VendorStoreID: order.VendorStoreID, - } - storeMap.DeletedAt = utils.DefaultTimeValue - if err = dao.GetEntity(db, storeMap, model.FieldVendorID, model.FieldVendorStoreID, model.FieldDeletedAt); err != nil && err != orm.ErrNoRows { - globals.SugarLogger.Warnf("updateOrderOtherInfo GetEntity orderID:%s, VendorStoreID:%s, error:%v", order.VendorOrderID, order.VendorStoreID, err) + storeDetail, err := dao.GetStoreDetailByVendorStoreID(db, order.VendorStoreID, order.VendorID) + if err != nil { + globals.SugarLogger.Warnf("updateOrderOtherInfo GetStoreDetailByVendorStoreID orderID:%s, VendorStoreID:%s, error:%v", order.VendorOrderID, order.VendorStoreID, err) return err } - order.JxStoreID = storeMap.StoreID + order.JxStoreID = storeDetail.Store.ID if err = c.updateOrderSkuOtherInfo(order, db); err == nil { jxutils.RefreshOrderSkuRelated(order) + + caculateOrderEarningPrice(order, storeDetail.PayPercentage) } return err } +// 计算结算给门店的金额 +func caculateOrderEarningPrice(order *model.GoodsOrder, storePayPercentage int) { + order.EarningPrice = 0 + for _, v := range order.Skus { + skuEarningPrice := v.EarningPrice + if skuEarningPrice == 0 { + basePrice := v.SalePrice + if v.ShopPrice > 0 && v.ShopPrice < basePrice { + basePrice = v.ShopPrice + } + if storePayPercentage <= 0 { + storePayPercentage = model.DefaultEarningPricePercentage + } + skuEarningPrice = basePrice * int64(storePayPercentage) / 100 + } + order.EarningPrice += skuEarningPrice + } +} + func (c *OrderManager) addOrderStatus(orderStatus *model.OrderStatus, db *dao.DaoDB) (isDuplicated bool, order *model.GoodsOrder, err error) { globals.SugarLogger.Debugf("addOrderStatus refOrderID:%s, orderID:%s", orderStatus.RefVendorOrderID, orderStatus.VendorOrderID) if db == nil { diff --git a/business/jxcallback/orderman/orderman_ext.go b/business/jxcallback/orderman/orderman_ext.go index cc9ca007d..078dadfbc 100644 --- a/business/jxcallback/orderman/orderman_ext.go +++ b/business/jxcallback/orderman/orderman_ext.go @@ -283,7 +283,7 @@ func (c *OrderManager) getOrders(ctx *jxcontext.Context, isIncludeSku bool, from } sql := ` SELECT SQL_CALC_FOUND_ROWS t1.*, - CAST(IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, 70) / 100 AS SIGNED) earning_price, + CAST(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, 70) / 100) AS SIGNED) earning_price, t2.status waybill_status, t2.courier_name, t2.courier_mobile, t2.actual_fee, t2.desired_fee, t2.waybill_created_at, t2.waybill_finished_at` if isIncludeSku { @@ -783,7 +783,7 @@ func (c *OrderManager) GetStoresOrderSaleInfo(ctx *jxcontext.Context, storeIDLis sql := ` SELECT IF(t1.jx_store_id > 0, t1.jx_store_id, t1.store_id) store_id, t1.vendor_id, IF(t1.status < ?, 0, t1.status) status, COUNT(*) count, SUM(t1.shop_price) shop_price, SUM(t1.vendor_price) vendor_price, SUM(t1.sale_price) sale_price, SUM(t1.actual_pay_price) actual_pay_price, - CAST(SUM(IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, 70) / 100) AS SIGNED) earning_price + CAST(SUM(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t5.pay_percentage > 0, t5.pay_percentage, 70) / 100)) AS SIGNED) earning_price FROM goods_order t1 LEFT JOIN store t5 ON t5.id = IF(t1.jx_store_id <> 0, t1.jx_store_id, t1.store_id) WHERE t1.order_created_at >= ? AND t1.order_created_at <= ? diff --git a/business/model/const.go b/business/model/const.go index b46de96e6..1b7da9b68 100644 --- a/business/model/const.go +++ b/business/model/const.go @@ -406,3 +406,7 @@ func WaybillVendorID2Mask(vendorID int) (mask int8) { func IsAfsOrderFinalStatus(status int) bool { return status >= AfsOrderStatusFinished && status <= AfsOrderStatusFailed } + +const ( + DefaultEarningPricePercentage = 70 // 门店缺省结算百分比 +) diff --git a/business/model/order.go b/business/model/order.go index 58b85dde2..61c119200 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -22,6 +22,7 @@ type GoodsOrder struct { ActualPayPrice int64 `json:"actualPayPrice"` // 单位为分 顾客实际支付 TotalShopMoney int64 `json:"totalShopMoney"` // 应结金额-第三方平台结算给京西的金额(包括了所有的补贴,扣除) PmSubsidyMoney int64 `json:"pmSubsidyMoney"` // 平台活动补贴(订单主体活动补贴+订单单条sku补贴)1+ + EarningPrice int64 `json:"earningPrice"` // 结算给门店老板的钱(未扣除可能的三方配送费) Weight int `json:"weight"` // 单位为克 ConsigneeName string `orm:"size(32)" json:"consigneeName"` ConsigneeMobile string `orm:"size(32)" json:"consigneeMobile"`