From b61d677ceaa893bf9cbb4fedcafa04aea1a61ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 30 Oct 2019 18:23:01 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/dao/report.go | 30 +++++++++++++++--------------- controllers/jx_report.go | 4 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/business/model/dao/report.go b/business/model/dao/report.go index 8e253a4f9..5d0e9ecfa 100644 --- a/business/model/dao/report.go +++ b/business/model/dao/report.go @@ -9,21 +9,21 @@ import ( ) type StatisticsReportForOrdersList struct { - StoreID int - orderCounts int - salePrice int64 - actualPayPrice int64 - shopPrice int64 - discountMoney int64 - desiredFee int64 - distanceFreightMoney int64 - waybillTipMoney int64 - totalShopMoney int64 - pmSubsidyMoney int64 - EarningPrice int64 - totalGrossProfit int64 - comGrossProfit float32 - cityManagerGrossProfit float32 + storeID int `json:"storeID"` + orderCounts int `json:"orderCounts"` + salePrice int64 `json:"salePrice"` + actualPayPrice int64 `json:"actualPayPrice"` + shopPrice int64 `json:"shopPrice"` + discountMoney int64 `json:"discountMoney"` + desiredFee int64 `json:"desiredFee"` + distanceFreightMoney int64 `json:"distanceFreightMoney"` + waybillTipMoney int64 `json:"waybillTipMoney"` + totalShopMoney int64 `json:"totalShopMoney"` + pmSubsidyMoney int64 `json:"pmSubsidyMoney"` + earningPrice int64 `json:"earningPrice"` + totalGrossProfit int64 `json:"totalGrossProfit"` + comGrossProfit float32 `json:"comGrossProfit"` + cityManagerGrossProfit float32 `json:"cityManagerGrossProfit"` } func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate string, toDate string) (statisticsReportForOrdersList []*StatisticsReportForOrdersList, err error) { diff --git a/controllers/jx_report.go b/controllers/jx_report.go index 6ed9d9ef7..4bad3821e 100644 --- a/controllers/jx_report.go +++ b/controllers/jx_report.go @@ -15,8 +15,8 @@ type ReportController struct { // @Description 根据门店idlist和时间范围查询 // @Param token header string true "认证token" // @Param storeIDs formData string true "京西门店ID列表[1,2,3]" -// @Param FromDate formData string false "开始日期(包含),格式(2006-01-02 00:00:00)" -// @Param ToDate formData string false "结束日期(包含),格式(2006-01-02 00:00:00)" +// @Param fromDate formData string false "开始日期(包含),格式(2006-01-02 00:00:00)" +// @Param toDate formData string false "结束日期(包含),格式(2006-01-02 00:00:00)" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /StatisticsReportForOrders [post] From 5c4a52636790812d559e6bc116e269d0010c0499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 30 Oct 2019 18:27:34 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/dao/report.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/business/model/dao/report.go b/business/model/dao/report.go index 5d0e9ecfa..a51920457 100644 --- a/business/model/dao/report.go +++ b/business/model/dao/report.go @@ -9,21 +9,21 @@ import ( ) type StatisticsReportForOrdersList struct { - storeID int `json:"storeID"` - orderCounts int `json:"orderCounts"` - salePrice int64 `json:"salePrice"` - actualPayPrice int64 `json:"actualPayPrice"` - shopPrice int64 `json:"shopPrice"` - discountMoney int64 `json:"discountMoney"` - desiredFee int64 `json:"desiredFee"` - distanceFreightMoney int64 `json:"distanceFreightMoney"` - waybillTipMoney int64 `json:"waybillTipMoney"` - totalShopMoney int64 `json:"totalShopMoney"` - pmSubsidyMoney int64 `json:"pmSubsidyMoney"` - earningPrice int64 `json:"earningPrice"` - totalGrossProfit int64 `json:"totalGrossProfit"` - comGrossProfit float32 `json:"comGrossProfit"` - cityManagerGrossProfit float32 `json:"cityManagerGrossProfit"` + storeID int `orm:"size(255)" json:"storeID"` + orderCounts int `orm:"size(255)" json:"orderCounts"` + salePrice int64 `orm:"size(255)" json:"salePrice"` + actualPayPrice int64 `orm:"size(255)" json:"actualPayPrice"` + shopPrice int64 `orm:"size(255)" json:"shopPrice"` + discountMoney int64 `orm:"size(255)" json:"discountMoney"` + desiredFee int64 `orm:"size(255)" json:"desiredFee"` + distanceFreightMoney int64 `orm:"size(255)" json:"distanceFreightMoney"` + waybillTipMoney int64 `orm:"size(255)" json:"waybillTipMoney"` + totalShopMoney int64 `orm:"size(255)" json:"totalShopMoney"` + pmSubsidyMoney int64 `orm:"size(255)" json:"pmSubsidyMoney"` + earningPrice int64 `orm:"size(255)" json:"earningPrice"` + totalGrossProfit int64 `orm:"size(255)" json:"totalGrossProfit"` + comGrossProfit float32 `orm:"size(255)" json:"comGrossProfit"` + cityManagerGrossProfit float32 `orm:"size(255)" json:"cityManagerGrossProfit"` } func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate string, toDate string) (statisticsReportForOrdersList []*StatisticsReportForOrdersList, err error) { From ceb35801a5cae0282a2186f22656278b31386dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 31 Oct 2019 08:54:09 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/dao/report.go | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/business/model/dao/report.go b/business/model/dao/report.go index a51920457..a1747140f 100644 --- a/business/model/dao/report.go +++ b/business/model/dao/report.go @@ -1,7 +1,6 @@ package dao import ( - "fmt" "strconv" "git.rosy.net.cn/baseapi/utils" @@ -9,21 +8,21 @@ import ( ) type StatisticsReportForOrdersList struct { - storeID int `orm:"size(255)" json:"storeID"` - orderCounts int `orm:"size(255)" json:"orderCounts"` - salePrice int64 `orm:"size(255)" json:"salePrice"` - actualPayPrice int64 `orm:"size(255)" json:"actualPayPrice"` - shopPrice int64 `orm:"size(255)" json:"shopPrice"` - discountMoney int64 `orm:"size(255)" json:"discountMoney"` - desiredFee int64 `orm:"size(255)" json:"desiredFee"` - distanceFreightMoney int64 `orm:"size(255)" json:"distanceFreightMoney"` - waybillTipMoney int64 `orm:"size(255)" json:"waybillTipMoney"` - totalShopMoney int64 `orm:"size(255)" json:"totalShopMoney"` - pmSubsidyMoney int64 `orm:"size(255)" json:"pmSubsidyMoney"` - earningPrice int64 `orm:"size(255)" json:"earningPrice"` - totalGrossProfit int64 `orm:"size(255)" json:"totalGrossProfit"` - comGrossProfit float32 `orm:"size(255)" json:"comGrossProfit"` - cityManagerGrossProfit float32 `orm:"size(255)" json:"cityManagerGrossProfit"` + StoreID int `orm:"column(storeID)" json:"storeID"` + OrderCounts int `orm:"column(orderCounts)" json:"orderCounts"` + SalePrice int `orm:"column(salePrice)" json:"salePrice"` + ActualPayPrice int `orm:"column(actualPayPrice)" json:"actualPayPrice"` + ShopPrice int `orm:"column(shopPrice)" json:"shopPrice"` + DiscountMoney int `orm:"column(discountMoney)" json:"discountMoney"` + DesiredFee int `orm:"column(desiredFee)" json:"desiredFee"` + DistanceFreightMoney int `orm:"column(distanceFreightMoney)" json:"distanceFreightMoney"` + WaybillTipMoney int `orm:"column(waybillTipMoney)" json:"waybillTipMoney"` + TotalShopMoney int `orm:"column(totalShopMoney)" json:"totalShopMoney"` + PmSubsidyMoney int `orm:"column(pmSubsidyMoney)" json:"pmSubsidyMoney"` + EarningPrice int `orm:"column(earningPrice)" json:"earningPrice"` + TotalGrossProfit int `orm:"column(totalGrossProfit)" json:"totalGrossProfit"` + ComGrossProfit float32 `orm:"column(comGrossProfit)" json:"comGrossProfit"` + CityManagerGrossProfit float32 `orm:"column(cityManagerGrossProfit)" json:"cityManagerGrossProfit"` } func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate string, toDate string) (statisticsReportForOrdersList []*StatisticsReportForOrdersList, err error) { @@ -69,7 +68,6 @@ func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate string, to )s WHERE s.storeID = c.id ` - fmt.Println(sql) if err = GetRows(db, &statisticsReportForOrdersList, sql, sqlParams...); err == nil { return statisticsReportForOrdersList, nil } From 5284267133ddb7fda8702bb791024cc5190dc902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 31 Oct 2019 09:08:39 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/dao/report.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/business/model/dao/report.go b/business/model/dao/report.go index a1747140f..d01737169 100644 --- a/business/model/dao/report.go +++ b/business/model/dao/report.go @@ -30,8 +30,8 @@ func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate string, to status := strconv.Itoa(model.OrderStatusCanceled) sql := ` SELECT s.*, - (totalGrossProfit*c.jx_brand_fee_factor)/(c.jx_brand_fee_factor+market_add_fee_factor) comGrossProfit, - (totalGrossProfit*c.market_add_fee_factor)/(c.jx_brand_fee_factor+market_add_fee_factor) cityManagerGrossProfit + if(c.jx_brand_fee_factor = 0 AND c.market_add_fee_factor = 0,totalGrossProfit,(totalGrossProfit*c.jx_brand_fee_factor)/(c.jx_brand_fee_factor+market_add_fee_factor)) comGrossProfit, + if(c.jx_brand_fee_factor = 0 AND c.market_add_fee_factor = 0,0,(totalGrossProfit*c.market_add_fee_factor)/(c.jx_brand_fee_factor+market_add_fee_factor)) cityManagerGrossProfit FROM store c,( SELECT a.store_id storeID, From 8ed5172f35bf4cf9fc2d34e5406c98433fe71ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 31 Oct 2019 10:25:21 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/report/report.go | 12 ++++++++++- business/model/dao/report.go | 33 +++++++++++++++---------------- controllers/jx_report.go | 6 +++--- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/business/jxstore/report/report.go b/business/jxstore/report/report.go index 5fe22d54b..324bd7320 100644 --- a/business/jxstore/report/report.go +++ b/business/jxstore/report/report.go @@ -1,12 +1,22 @@ package report import ( + "errors" + "fmt" + "math" + + "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/business/model/dao" ) func GetStatisticsReportForOrders(ctx *jxcontext.Context, storeIDs []int, fromDate string, toDate string) (statisticsReportForOrdersList []*dao.StatisticsReportForOrdersList, err error) { db := dao.GetDB() - statisticsReportForOrdersList, err = dao.GetStatisticsReportForOrders(db, storeIDs, fromDate, toDate) + fromDateParm := utils.Str2Time(fromDate) + toDateParm := utils.Str2Time(toDate) + if math.Ceil(toDateParm.Sub(fromDateParm).Hours()/24) > 92 { + return nil, errors.New(fmt.Sprintf("查询间隔时间不允许大于3个月!: 时间范围:[%v] 至 [%v]", fromDate, toDate)) + } + statisticsReportForOrdersList, err = dao.GetStatisticsReportForOrders(db, storeIDs, fromDateParm, toDateParm) return statisticsReportForOrdersList, err } diff --git a/business/model/dao/report.go b/business/model/dao/report.go index d01737169..22386fcdf 100644 --- a/business/model/dao/report.go +++ b/business/model/dao/report.go @@ -2,6 +2,7 @@ package dao import ( "strconv" + "time" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/model" @@ -9,14 +10,14 @@ import ( type StatisticsReportForOrdersList struct { StoreID int `orm:"column(storeID)" json:"storeID"` - OrderCounts int `orm:"column(orderCounts)" json:"orderCounts"` - SalePrice int `orm:"column(salePrice)" json:"salePrice"` - ActualPayPrice int `orm:"column(actualPayPrice)" json:"actualPayPrice"` - ShopPrice int `orm:"column(shopPrice)" json:"shopPrice"` - DiscountMoney int `orm:"column(discountMoney)" json:"discountMoney"` - DesiredFee int `orm:"column(desiredFee)" json:"desiredFee"` - DistanceFreightMoney int `orm:"column(distanceFreightMoney)" json:"distanceFreightMoney"` - WaybillTipMoney int `orm:"column(waybillTipMoney)" json:"waybillTipMoney"` + OrderCounts int `orm:"column(orderCounts)" json:"orderCounts"` //定单数 + SalePrice int `orm:"column(salePrice)" json:"salePrice"` //GMV(售卖价) + ActualPayPrice int `orm:"column(actualPayPrice)" json:"actualPayPrice"` //实付 + ShopPrice int `orm:"column(shopPrice)" json:"shopPrice"` //京西 + DiscountMoney int `orm:"column(discountMoney)" json:"discountMoney"` //优惠 + DesiredFee int `orm:"column(desiredFee)" json:"desiredFee"` //配送费 + DistanceFreightMoney int `orm:"column(distanceFreightMoney)" json:"distanceFreightMoney"` //远距离 + WaybillTipMoney int `orm:"column(waybillTipMoney)" json:"waybillTipMoney"` // TotalShopMoney int `orm:"column(totalShopMoney)" json:"totalShopMoney"` PmSubsidyMoney int `orm:"column(pmSubsidyMoney)" json:"pmSubsidyMoney"` EarningPrice int `orm:"column(earningPrice)" json:"earningPrice"` @@ -25,7 +26,7 @@ type StatisticsReportForOrdersList struct { CityManagerGrossProfit float32 `orm:"column(cityManagerGrossProfit)" json:"cityManagerGrossProfit"` } -func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate string, toDate string) (statisticsReportForOrdersList []*StatisticsReportForOrdersList, err error) { +func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate time.Time, toDate time.Time) (statisticsReportForOrdersList []*StatisticsReportForOrdersList, err error) { //排除已取消的订单 status := strconv.Itoa(model.OrderStatusCanceled) sql := ` @@ -51,16 +52,14 @@ func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate string, to WHERE a.status != ` + status + ` ` sqlParams := []interface{}{} - if fromDate != "" { - sql += "AND a.order_created_at >= date_format(?,'YYYY-MM-DD HH:MM:SS')" - sqlParams = append(sqlParams, utils.Str2Time(fromDate)) - } - if toDate != "" { - sql += "AND a.order_created_at <= date_format(?,'YYYY-MM-DD HH:MM:SS')" - sqlParams = append(sqlParams, utils.Str2Time(toDate)) + if !utils.IsTimeZero(fromDate) && !utils.IsTimeZero(toDate) { + sql += `AND a.order_created_at BETWEEN ? and ? + ` + sqlParams = append(sqlParams, fromDate, toDate) } if len(storeIDs) > 0 { - sql += "AND a.store_id in(" + GenQuestionMarks(len(storeIDs)) + ")" + sql += `AND a.store_id in(` + GenQuestionMarks(len(storeIDs)) + `) + ` sqlParams = append(sqlParams, storeIDs) } sql += ` diff --git a/controllers/jx_report.go b/controllers/jx_report.go index 4bad3821e..9450f576e 100644 --- a/controllers/jx_report.go +++ b/controllers/jx_report.go @@ -13,10 +13,10 @@ type ReportController struct { // @Title 查询订单统计信息 // @Description 根据门店idlist和时间范围查询 -// @Param token header string true "认证token" +// @Param token header string true "认证token" // @Param storeIDs formData string true "京西门店ID列表[1,2,3]" -// @Param fromDate formData string false "开始日期(包含),格式(2006-01-02 00:00:00)" -// @Param toDate formData string false "结束日期(包含),格式(2006-01-02 00:00:00)" +// @Param fromDate formData string true "开始日期(包含),格式(2006-01-02 00:00:00)" +// @Param toDate formData string true "结束日期(包含),格式(2006-01-02 00:00:00)" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /StatisticsReportForOrders [post] From d066a13b65bc2534a874620d8cb91eb994219ff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 31 Oct 2019 13:33:38 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/report/report.go | 51 ++++++++++++++++++++++++++++++- business/model/dao/report.go | 42 +++++++++++++++++++++++-- 2 files changed, 90 insertions(+), 3 deletions(-) diff --git a/business/jxstore/report/report.go b/business/jxstore/report/report.go index 324bd7320..1258a6f21 100644 --- a/business/jxstore/report/report.go +++ b/business/jxstore/report/report.go @@ -10,13 +10,62 @@ import ( "git.rosy.net.cn/jx-callback/business/model/dao" ) +var ( + storeIDsExist []int + storeIDsNotExist []int + StatisticsForOrdersExists *dao.StatisticsForOrdersExists + StatisticsForOrdersExistsStore *dao.StatisticsForOrdersExists +) + func GetStatisticsReportForOrders(ctx *jxcontext.Context, storeIDs []int, fromDate string, toDate string) (statisticsReportForOrdersList []*dao.StatisticsReportForOrdersList, err error) { + storeIDsExist = storeIDsExist[0:0] + storeIDsNotExist = storeIDsNotExist[0:0] db := dao.GetDB() fromDateParm := utils.Str2Time(fromDate) toDateParm := utils.Str2Time(toDate) + //若时间间隔大于3个月则不允许查询 if math.Ceil(toDateParm.Sub(fromDateParm).Hours()/24) > 92 { return nil, errors.New(fmt.Sprintf("查询间隔时间不允许大于3个月!: 时间范围:[%v] 至 [%v]", fromDate, toDate)) } - statisticsReportForOrdersList, err = dao.GetStatisticsReportForOrders(db, storeIDs, fromDateParm, toDateParm) + //若入参中,不存在的店则不显示,存在的店但无订单的显示0 + for _, id := range storeIDs { + StatisticsForOrdersExistsStore, err = dao.IsStoreExist(db, id) + if StatisticsForOrdersExistsStore == nil { + continue + } + StatisticsForOrdersExists, err = dao.GetStatisticsForOrdersExist(db, id) + //若该门店存在此查询条件范围内的订单 + if StatisticsForOrdersExists != nil { + storeIDsExist = append(storeIDsExist, id) + } else { + storeIDsNotExist = append(storeIDsNotExist, id) + } + } + statisticsReportForOrdersList, err = dao.GetStatisticsReportForOrders(db, storeIDsExist, fromDateParm, toDateParm) + if storeIDsNotExist != nil { + for _, v := range storeIDsNotExist { + tempStruct1 := &dao.StatisticsForOrdersExists{ + StoreID: v, + } + tempStruct2 := &dao.StatisticsReportForOrdersList{ + StatisticsForOrdersExists: *tempStruct1, + OrderCounts: 0, + SalePrice: 0, + ActualPayPrice: 0, + ShopPrice: 0, + DiscountMoney: 0, + DesiredFee: 0, + DistanceFreightMoney: 0, + WaybillTipMoney: 0, + TotalShopMoney: 0, + PmSubsidyMoney: 0, + EarningPrice: 0, + TotalGrossProfit: 0, + ComGrossProfit: 0, + CityManagerGrossProfit: 0, + } + statisticsReportForOrdersList = append(statisticsReportForOrdersList, tempStruct2) + } + } return statisticsReportForOrdersList, err } diff --git a/business/model/dao/report.go b/business/model/dao/report.go index 22386fcdf..17617df38 100644 --- a/business/model/dao/report.go +++ b/business/model/dao/report.go @@ -8,9 +8,13 @@ import ( "git.rosy.net.cn/jx-callback/business/model" ) +type StatisticsForOrdersExists struct { + StoreID int `orm:"column(storeID)" json:"storeID"` +} + type StatisticsReportForOrdersList struct { - StoreID int `orm:"column(storeID)" json:"storeID"` - OrderCounts int `orm:"column(orderCounts)" json:"orderCounts"` //定单数 + StatisticsForOrdersExists + OrderCounts int `orm:"column(orderCounts)" json:"orderCounts"` //订单数 SalePrice int `orm:"column(salePrice)" json:"salePrice"` //GMV(售卖价) ActualPayPrice int `orm:"column(actualPayPrice)" json:"actualPayPrice"` //实付 ShopPrice int `orm:"column(shopPrice)" json:"shopPrice"` //京西 @@ -26,6 +30,40 @@ type StatisticsReportForOrdersList struct { CityManagerGrossProfit float32 `orm:"column(cityManagerGrossProfit)" json:"cityManagerGrossProfit"` } +//是否存在这个门店 +func IsStoreExist(db *DaoDB, storeID int) (StatisticsForOrdersExists *StatisticsForOrdersExists, err error) { + sql := ` + SELECT * + FROM store + WHERE id = ? + ` + sqlParams := []interface{}{} + sqlParams = append(sqlParams, storeID) + + if err = GetRow(db, &StatisticsForOrdersExists, sql, sqlParams...); err == nil { + return StatisticsForOrdersExists, nil + } + return nil, err +} + +//查询条件内是否存在订单 +func GetStatisticsForOrdersExist(db *DaoDB, storeID int) (StatisticsForOrdersExists *StatisticsForOrdersExists, err error) { + sql := ` + SELECT store_id + FROM goods_order a LEFT JOIN waybill b ON IF(a.waybill_vendor_id = -1,a.vendor_order_id,a.vendor_waybill_id) = b.vendor_waybill_id + WHERE a.store_id = ? + GROUP BY a.store_id + ` + sqlParams := []interface{}{} + sqlParams = append(sqlParams, storeID) + + if err = GetRow(db, &StatisticsForOrdersExists, sql, sqlParams...); err == nil { + return StatisticsForOrdersExists, nil + } + return nil, err +} + +//查询统计订单信息 func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate time.Time, toDate time.Time) (statisticsReportForOrdersList []*StatisticsReportForOrdersList, err error) { //排除已取消的订单 status := strconv.Itoa(model.OrderStatusCanceled)