Merge branch 'su'
This commit is contained in:
@@ -1,12 +1,71 @@
|
||||
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"
|
||||
)
|
||||
|
||||
var (
|
||||
storeIDsExist []int
|
||||
storeIDsNotExist []int
|
||||
StatisticsForOrdersExists *dao.StatisticsForOrdersExists
|
||||
StatisticsForOrdersExistsStore *dao.StatisticsForOrdersExists
|
||||
)
|
||||
|
||||
func GetStatisticsReportForOrders(ctx *jxcontext.Context, storeIDs []int, fromDate string, toDate string) (statisticsReportForOrdersList []*dao.StatisticsReportForOrdersList, err error) {
|
||||
storeIDsExist = storeIDsExist[0:0]
|
||||
storeIDsNotExist = storeIDsNotExist[0:0]
|
||||
db := dao.GetDB()
|
||||
statisticsReportForOrdersList, err = dao.GetStatisticsReportForOrders(db, storeIDs, fromDate, toDate)
|
||||
fromDateParm := utils.Str2Time(fromDate)
|
||||
toDateParm := utils.Str2Time(toDate)
|
||||
//若时间间隔大于3个月则不允许查询
|
||||
if math.Ceil(toDateParm.Sub(fromDateParm).Hours()/24) > 92 {
|
||||
return nil, errors.New(fmt.Sprintf("查询间隔时间不允许大于3个月!: 时间范围:[%v] 至 [%v]", fromDate, toDate))
|
||||
}
|
||||
//若入参中,不存在的店则不显示,存在的店但无订单的显示0
|
||||
for _, id := range storeIDs {
|
||||
StatisticsForOrdersExistsStore, err = dao.IsStoreExist(db, id)
|
||||
if StatisticsForOrdersExistsStore == nil {
|
||||
continue
|
||||
}
|
||||
StatisticsForOrdersExists, err = dao.GetStatisticsForOrdersExist(db, id)
|
||||
//若该门店存在此查询条件范围内的订单
|
||||
if StatisticsForOrdersExists != nil {
|
||||
storeIDsExist = append(storeIDsExist, id)
|
||||
} else {
|
||||
storeIDsNotExist = append(storeIDsNotExist, id)
|
||||
}
|
||||
}
|
||||
statisticsReportForOrdersList, err = dao.GetStatisticsReportForOrders(db, storeIDsExist, fromDateParm, toDateParm)
|
||||
if storeIDsNotExist != nil {
|
||||
for _, v := range storeIDsNotExist {
|
||||
tempStruct1 := &dao.StatisticsForOrdersExists{
|
||||
StoreID: v,
|
||||
}
|
||||
tempStruct2 := &dao.StatisticsReportForOrdersList{
|
||||
StatisticsForOrdersExists: *tempStruct1,
|
||||
OrderCounts: 0,
|
||||
SalePrice: 0,
|
||||
ActualPayPrice: 0,
|
||||
ShopPrice: 0,
|
||||
DiscountMoney: 0,
|
||||
DesiredFee: 0,
|
||||
DistanceFreightMoney: 0,
|
||||
WaybillTipMoney: 0,
|
||||
TotalShopMoney: 0,
|
||||
PmSubsidyMoney: 0,
|
||||
EarningPrice: 0,
|
||||
TotalGrossProfit: 0,
|
||||
ComGrossProfit: 0,
|
||||
CityManagerGrossProfit: 0,
|
||||
}
|
||||
statisticsReportForOrdersList = append(statisticsReportForOrdersList, tempStruct2)
|
||||
}
|
||||
}
|
||||
return statisticsReportForOrdersList, err
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user