统计订单信息接口
This commit is contained in:
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
|
||||
}
|
||||
Reference in New Issue
Block a user