From 14e3594455f70d90ca8f6ce7dc84564dfae3c3d9 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 16 Aug 2019 11:08:09 +0800 Subject: [PATCH] =?UTF-8?q?-=20GetStoresOrderSaleInfo=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=94=AE=E5=90=8E=E5=8D=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/order.go | 30 ++++++------- business/jxcallback/orderman/orderman_ext.go | 2 +- business/jxutils/jxutils.go | 2 + business/model/dao/dao_order.go | 44 ++++++++++++++++---- business/model/order.go | 4 +- business/model/order_financial.go | 7 ++++ 6 files changed, 62 insertions(+), 27 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index ce452d802..df4209051 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -236,7 +236,7 @@ func (c *OrderManager) SaveOrder(order *model.GoodsOrder, isAdjust bool, db *dao return isDuplicated, err } -func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.DaoDB) (err error) { +func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.DaoDB, storePayPercentage int) (err error) { globals.SugarLogger.Debugf("updateOrderSkuOtherInfo orderID:%s, VendorStoreID:%s", order.VendorOrderID, order.VendorStoreID) jxStoreID := jxutils.GetShowStoreIDFromOrder(order) var opNumStr string @@ -316,10 +316,10 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao. v.JxSkuID = skuBindInfo.SkuID v.ShopPrice = int64(skuBindInfo.Price) v.Weight = skuBindInfo.Weight // 以本地信息中的WEIGHT为准 - order.ShopPrice += v.ShopPrice * int64(v.Count) if skuBindInfo.Price == 0 { globals.SugarLogger.Infof("updateOrderSkuOtherInfo [运营%s]%s订单sku门店价格为零(一般原因为没有门店价格信息),orderID:%s, StoreID:%d, SkuID:%d, sku:%v", opNumStr, model.VendorChineseNames[order.VendorID], order.VendorOrderID, jxStoreID, v.JxSkuID, v) } + v.EarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage) } } @@ -335,7 +335,7 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao. if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 { if actStoreSku := actStoreSkuMap.GetActStoreSku(jxStoreID, skuID, order.VendorID); actStoreSku != nil { v.EarningPrice = actStoreSku.EarningPrice - if v.StoreSubName != "" { + if true { //v.StoreSubName != "" { // 之前这里为什么要加判断? v.StoreSubID = actStoreSku.ActID } } @@ -361,24 +361,24 @@ func (c *OrderManager) updateOrderOtherInfo(order *model.GoodsOrder, db *dao.Dao order.JxStoreID = storeDetail.Store.ID payPercentage = storeDetail.PayPercentage } - if err = c.updateOrderSkuOtherInfo(order, db); err == nil { + if err = c.updateOrderSkuOtherInfo(order, db, payPercentage); err == nil { jxutils.RefreshOrderSkuRelated(order) - caculateOrderEarningPrice(order, payPercentage) + // caculateOrderEarningPrice(order, payPercentage) } return err } // 计算结算给门店的金额 -func caculateOrderEarningPrice(order *model.GoodsOrder, storePayPercentage int) { - order.EarningPrice = 0 - for _, v := range order.Skus { - skuEarningPrice := v.EarningPrice - if skuEarningPrice == 0 { - skuEarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage) - } - order.EarningPrice += skuEarningPrice * int64(v.Count) - } -} +// func caculateOrderEarningPrice(order *model.GoodsOrder, storePayPercentage int) { +// order.EarningPrice = 0 +// for _, v := range order.Skus { +// skuEarningPrice := v.EarningPrice +// if skuEarningPrice == 0 { +// skuEarningPrice = jxutils.CaculateSkuEarningPrice(v.ShopPrice, v.SalePrice, storePayPercentage) +// } +// order.EarningPrice += skuEarningPrice * int64(v.Count) +// } +// } 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) diff --git a/business/jxcallback/orderman/orderman_ext.go b/business/jxcallback/orderman/orderman_ext.go index 5c33c44e4..3b2ace132 100644 --- a/business/jxcallback/orderman/orderman_ext.go +++ b/business/jxcallback/orderman/orderman_ext.go @@ -907,7 +907,7 @@ func (c *OrderManager) getAfsOrderSkuInfo4ExportOrders(ctx *jxcontext.Context, f SELECT t2.* FROM afs_order t1 JOIN order_sku_financial t2 ON t2.vendor_order_id = t1.vendor_order_id AND t2.vendor_id = t1.vendor_id AND t2.is_afs_order = 1 - WHERE t1.afs_created_at >= ? AND t1.afs_created_at <= ? AND t1.status = ? + WHERE t1.afs_finished_at >= ? AND t1.afs_finished_at <= ? AND t1.status = ? ` sqlParams := []interface{}{ fromDate, diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index 2a15f0379..5c20f947c 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -479,6 +479,7 @@ func RefreshOrderSkuRelated(order *model.GoodsOrder) *model.GoodsOrder { order.GoodsCount = 0 order.SalePrice = 0 order.VendorPrice = 0 + order.ShopPrice = 0 order.Weight = 0 for _, sku := range order.Skus { if sku.SkuID > math.MaxInt32 { @@ -489,6 +490,7 @@ func RefreshOrderSkuRelated(order *model.GoodsOrder) *model.GoodsOrder { order.GoodsCount += sku.Count order.SalePrice += sku.SalePrice * int64(sku.Count) order.VendorPrice += sku.VendorPrice * int64(sku.Count) + order.ShopPrice += sku.ShopPrice * int64(sku.Count) order.Weight += sku.Weight * sku.Count } return order diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index ccb41cc44..f85b62587 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -8,6 +8,10 @@ import ( "git.rosy.net.cn/jx-callback/business/model" ) +const ( + AfsOrderStatus = -1 +) + type StoresOrderSaleInfo struct { StoreID int `orm:"column(store_id)" json:"storeID"` VendorID int `orm:"column(vendor_id)" json:"vendorID"` @@ -122,6 +126,7 @@ func GetAfsOrders(db *DaoDB, vendorID int, vendorOrderID, afsOrderID string) (af return afsOrderList, err } +// 时间范围是订单完成时间 func GetStoresOrderSaleInfo(db *DaoDB, storeIDList []int, fromTime time.Time, toTime time.Time, statusList []int) (saleInfoList []*StoresOrderSaleInfo, err error) { if utils.IsTimeZero(fromTime) { return nil, fmt.Errorf("查询订单信息必须指定起始时间") @@ -135,13 +140,13 @@ func GetStoresOrderSaleInfo(db *DaoDB, storeIDList []int, fromTime time.Time, to // 用int64类型去取float型的数据库返回值,会取不到 sql := fmt.Sprintf(` - 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.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, %d) / 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_finished_at >= ? AND t1.order_finished_at <= ? - `, model.DefaultEarningPricePercentage) + 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.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, %d) / 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_finished_at >= ? AND t1.order_finished_at <= ? + `, model.DefaultEarningPricePercentage) sqlParams := []interface{}{ model.OrderStatusEndBegin, fromTime, @@ -156,8 +161,29 @@ func GetStoresOrderSaleInfo(db *DaoDB, storeIDList []int, fromTime time.Time, to sqlParams = append(sqlParams, statusList) } sql += ` - GROUP BY 1,2,3 - ORDER BY 1,2,3` + GROUP BY 1,2,3` + sql += fmt.Sprintf(` + UNION + SELECT IF(t0.jx_store_id > 0, t0.jx_store_id, t0.store_id) store_id, t0.vendor_id, -1 status, + COUNT(*) count, SUM(t1.shop_price) shop_price, SUM(t1.vendor_price) vendor_price, SUM(t1.sale_price) sale_price, 0 actual_pay_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, %d) / 100)) AS SIGNED) earning_price + FROM afs_order t0 + JOIN order_sku_financial t2 ON t2.afs_order_id = t0.afs_order_id AND t2.vendor_id = t0.vendor_id AND t2.is_afs_order = 1 + JOIN order_sku t1 ON t1.vendor_order_id = t2.vendor_order_id AND t1.vendor_id = t2.vendor_id AND t1.sku_id = t2.sku_id + LEFT JOIN store t5 ON t5.id = IF(t0.jx_store_id <> 0, t0.jx_store_id, t0.store_id) + WHERE t0.afs_finished_at >= ? AND t0.afs_finished_at <= ?`, model.DefaultEarningPricePercentage) + sqlParams = append(sqlParams, []interface{}{ + fromTime, + toTime, + }) + if len(storeIDList) > 0 { + sql += " AND IF(t0.jx_store_id > 0, t0.jx_store_id, t0.store_id) IN (" + GenQuestionMarks(len(storeIDList)) + ")" + sqlParams = append(sqlParams, storeIDList) + } + sql += ` + GROUP BY 1,2,3` + + sql += " ORDER BY 1,2,3" err = GetRows(db, &saleInfoList, sql, sqlParams...) return saleInfoList, err } diff --git a/business/model/order.go b/business/model/order.go index b3dbcbdb6..861757d15 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -84,7 +84,7 @@ type OrderSku struct { ID int64 `orm:"column(id)" json:"-"` VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` VendorID int `orm:"column(vendor_id)" json:"vendorID"` - StoreSubID int `orm:"column(store_sub_id)" json:"storeSubID"` // 当前这个字段被当成活动ID用 + StoreSubID int `orm:"column(store_sub_id)" json:"storeSubID"` // 当前这个字段被当成结算活动ID用 StoreSubName string `orm:"size(64)" json:"storeSubName"` // 当前这个字段被用作vendorActType Count int `json:"count"` VendorSkuID string `orm:"column(vendor_sku_id);size(48)" json:"vendorSkuID"` @@ -94,7 +94,7 @@ type OrderSku struct { ShopPrice int64 `json:"shopPrice"` // 京西价 VendorPrice int64 `json:"vendorPrice"` // 平台价 SalePrice int64 `json:"salePrice"` // 售卖价 - EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱 + EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱,如果结算活动ID为0,是按结算比例算的,否则就是结算表中的值 Weight int `json:"weight"` // 单位为克 SkuType int `json:"skuType"` // 当前如果为gift就为1,否则缺省为0 PromotionType int `json:"promotionType"` // todo 当前是用于记录京东的PromotionType(生成jxorder用),没有做转换 diff --git a/business/model/order_financial.go b/business/model/order_financial.go index 8b2b6b6b0..ea883e033 100644 --- a/business/model/order_financial.go +++ b/business/model/order_financial.go @@ -155,6 +155,13 @@ type OrderSkuFinancial struct { StoreSubName string `orm:"size(64)" json:"storeSubName"` // 当前这个字段被用作vendorActType } +// todo +// func (o *OrderSkuFinancial) TableUnique() [][]string { +// return [][]string{ +// []string{"AfsOrderID", "VendorSkuID", "VendorID", "IsAfsOrder"}, +// } +// } + func (o *OrderSkuFinancial) TableIndex() [][]string { return [][]string{ []string{"VendorOrderID", "VendorSkuID"},