Merge branch 'su'
This commit is contained in:
@@ -1,38 +1,76 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"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
|
||||
type StatisticsForOrdersExists struct {
|
||||
StoreID int `orm:"column(storeID)" json:"storeID"`
|
||||
}
|
||||
|
||||
func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate string, toDate string) (statisticsReportForOrdersList []*StatisticsReportForOrdersList, err error) {
|
||||
type StatisticsReportForOrdersList struct {
|
||||
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"` //京西
|
||||
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 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)
|
||||
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,
|
||||
@@ -52,16 +90,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 += `
|
||||
@@ -69,7 +105,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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user