统计订单信息接口
This commit is contained in:
12
business/jxstore/report/report.go
Normal file
12
business/jxstore/report/report.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
77
business/model/dao/report.go
Normal file
77
business/model/dao/report.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
31
controllers/jx_report.go
Normal file
31
controllers/jx_report.go
Normal file
@@ -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
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1934,5 +1934,13 @@ func init() {
|
|||||||
MethodParams: param.Make(),
|
MethodParams: param.Make(),
|
||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: 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})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,6 +121,11 @@ func init() {
|
|||||||
&controllers.FoodRecipeController{},
|
&controllers.FoodRecipeController{},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
beego.NSNamespace("/report",
|
||||||
|
beego.NSInclude(
|
||||||
|
&controllers.ReportController{},
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
beego.AddNamespace(ns)
|
beego.AddNamespace(ns)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user