From 186a543ce07b2d39d76394ded388b1b361d9588e 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 17:56:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E8=AE=A2=E5=8D=95=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=8E=A5=E5=8F=A3?= 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 | 77 +++++++++++++++++++++++++++ controllers/jx_report.go | 31 +++++++++++ routers/commentsRouter_controllers.go | 10 +++- routers/router.go | 5 ++ 5 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 business/jxstore/report/report.go create mode 100644 business/model/dao/report.go create mode 100644 controllers/jx_report.go diff --git a/business/jxstore/report/report.go b/business/jxstore/report/report.go new file mode 100644 index 000000000..5fe22d54b --- /dev/null +++ b/business/jxstore/report/report.go @@ -0,0 +1,12 @@ +package report + +import ( + "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) + return statisticsReportForOrdersList, err +} diff --git a/business/model/dao/report.go b/business/model/dao/report.go new file mode 100644 index 000000000..8e253a4f9 --- /dev/null +++ b/business/model/dao/report.go @@ -0,0 +1,77 @@ +package dao + +import ( + "fmt" + "strconv" + + "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/model" +) + +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 +} + +func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate string, toDate string) (statisticsReportForOrdersList []*StatisticsReportForOrdersList, err error) { + //排除已取消的订单 + 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 + FROM store c,( + SELECT + a.store_id storeID, + count(*) orderCounts, + sum(sale_price) salePrice, + sum(actual_pay_price) actualPayPrice, + sum(shop_price) shopPrice, + sum(discount_money) discountMoney, + sum(desired_fee) desiredFee, + sum(distance_freight_money) distanceFreightMoney, + sum(waybill_tip_money) waybillTipMoney, + sum(total_shop_money) totalShopMoney, + sum(pm_subsidy_money) pmSubsidyMoney, + sum(earning_price) EarningPrice, + sum(total_shop_money-earning_price-desired_fee-distance_freight_money-waybill_tip_money-80) totalGrossProfit + 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.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 len(storeIDs) > 0 { + sql += "AND a.store_id in(" + GenQuestionMarks(len(storeIDs)) + ")" + sqlParams = append(sqlParams, storeIDs) + } + sql += ` + GROUP BY a.store_id + )s + WHERE s.storeID = c.id + ` + fmt.Println(sql) + if err = GetRows(db, &statisticsReportForOrdersList, sql, sqlParams...); err == nil { + return statisticsReportForOrdersList, nil + } + return nil, err +} diff --git a/controllers/jx_report.go b/controllers/jx_report.go new file mode 100644 index 000000000..6ed9d9ef7 --- /dev/null +++ b/controllers/jx_report.go @@ -0,0 +1,31 @@ +package controllers + +import ( + "git.rosy.net.cn/jx-callback/business/jxstore/report" + "git.rosy.net.cn/jx-callback/business/jxutils" + "github.com/astaxie/beego" +) + +// 统计相关API +type ReportController struct { + beego.Controller +} + +// @Title 查询订单统计信息 +// @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)" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /StatisticsReportForOrders [post] +func (c *ReportController) StatisticsReportForOrders() { + c.callStatisticsReportForOrders(func(params *tReportStatisticsReportForOrdersParams) (retVal interface{}, errCode string, err error) { + var storeIDList []int + if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil { + retVal, err = report.GetStatisticsReportForOrders(params.Ctx, storeIDList, params.FromDate, params.ToDate) + } + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 9345a8936..ea54ac96e 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1934,5 +1934,13 @@ func init() { MethodParams: param.Make(), Filters: nil, Params: nil}) - + + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"], + beego.ControllerComments{ + Method: "StatisticsReportForOrders", + Router: `/StatisticsReportForOrders`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) } diff --git a/routers/router.go b/routers/router.go index 9e0979e45..f6453d568 100644 --- a/routers/router.go +++ b/routers/router.go @@ -121,6 +121,11 @@ func init() { &controllers.FoodRecipeController{}, ), ), + beego.NSNamespace("/report", + beego.NSInclude( + &controllers.ReportController{}, + ), + ), ) beego.AddNamespace(ns)