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]