统计订单接口修改
This commit is contained in:
@@ -10,16 +10,7 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"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) {
|
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()
|
db := dao.GetDB()
|
||||||
fromDateParm := utils.Str2Time(fromDate)
|
fromDateParm := utils.Str2Time(fromDate)
|
||||||
toDateParm := utils.Str2Time(toDate)
|
toDateParm := utils.Str2Time(toDate)
|
||||||
@@ -27,45 +18,6 @@ func GetStatisticsReportForOrders(ctx *jxcontext.Context, storeIDs []int, fromDa
|
|||||||
if math.Ceil(toDateParm.Sub(fromDateParm).Hours()/24) > 92 {
|
if math.Ceil(toDateParm.Sub(fromDateParm).Hours()/24) > 92 {
|
||||||
return nil, errors.New(fmt.Sprintf("查询间隔时间不允许大于3个月!: 时间范围:[%v] 至 [%v]", fromDate, toDate))
|
return nil, errors.New(fmt.Sprintf("查询间隔时间不允许大于3个月!: 时间范围:[%v] 至 [%v]", fromDate, toDate))
|
||||||
}
|
}
|
||||||
//若入参中,不存在的店则不显示,存在的店但无订单的显示0
|
statisticsReportForOrdersList, err = dao.GetStatisticsReportForOrders(db, storeIDs, fromDateParm, toDateParm)
|
||||||
for _, id := range storeIDs {
|
|
||||||
StatisticsForOrdersExistsStore, err = dao.IsStoreExist(db, id)
|
|
||||||
if StatisticsForOrdersExistsStore == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
StatisticsForOrdersExists, err = dao.GetStatisticsForOrdersExist(db, id, fromDateParm, toDateParm)
|
|
||||||
//若该门店存在此查询条件范围内的订单
|
|
||||||
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
|
return statisticsReportForOrdersList, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,65 +9,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type StatisticsForOrdersExists struct {
|
type StatisticsForOrdersExists struct {
|
||||||
StoreID int `orm:"column(storeID)" json:"storeID"`
|
StoreID int `orm:"column(store_id)" json:"storeId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatisticsReportForOrdersList struct {
|
type StatisticsReportForOrdersList struct {
|
||||||
StatisticsForOrdersExists
|
StatisticsForOrdersExists
|
||||||
OrderCounts int `orm:"column(orderCounts)" json:"orderCounts"` //订单数
|
StoreName string `json:"name"` //门店名
|
||||||
SalePrice int `orm:"column(salePrice)" json:"salePrice"` //GMV(售卖价)
|
OrderCounts int `json:"orderCounts"` //订单数
|
||||||
ActualPayPrice int `orm:"column(actualPayPrice)" json:"actualPayPrice"` //实付
|
SalePrice int `json:"salePrice"` //GMV(售卖价)
|
||||||
ShopPrice int `orm:"column(shopPrice)" json:"shopPrice"` //京西
|
ActualPayPrice int `json:"actualPayPrice"` //实付
|
||||||
DiscountMoney int `orm:"column(discountMoney)" json:"discountMoney"` //优惠
|
ShopPrice int `json:"shopPrice"` //京西
|
||||||
DesiredFee int `orm:"column(desiredFee)" json:"desiredFee"` //配送费
|
DiscountMoney int `json:"discountMoney"` //优惠
|
||||||
DistanceFreightMoney int `orm:"column(distanceFreightMoney)" json:"distanceFreightMoney"` //远距离
|
DesiredFee int `json:"desiredFee"` //配送费
|
||||||
WaybillTipMoney int `orm:"column(waybillTipMoney)" json:"waybillTipMoney"` //小费
|
DistanceFreightMoney int `json:"distanceFreightMoney"` //远距离
|
||||||
TotalShopMoney int `orm:"column(totalShopMoney)" json:"totalShopMoney"` //平台结算
|
WaybillTipMoney int `json:"waybillTipMoney"` //小费
|
||||||
PmSubsidyMoney int `orm:"column(pmSubsidyMoney)" json:"pmSubsidyMoney"` //平台补贴
|
TotalShopMoney int `json:"totalShopMoney"` //平台结算
|
||||||
EarningPrice int `orm:"column(earningPrice)" json:"earningPrice"` //门店收益(预计收益)
|
PmSubsidyMoney int `json:"pmSubsidyMoney"` //平台补贴
|
||||||
TotalGrossProfit int `orm:"column(totalGrossProfit)" json:"totalGrossProfit"` //总毛利
|
EarningPrice int `json:"earningPrice"` //门店收益(预计收益)
|
||||||
ComGrossProfit float32 `orm:"column(comGrossProfit)" json:"comGrossProfit"` //公司毛利
|
TotalGrossProfit int `json:"totalGrossProfit"` //总毛利
|
||||||
CityManagerGrossProfit float32 `orm:"column(cityManagerGrossProfit)" json:"cityManagerGrossProfit"` //城市经理毛利
|
ComGrossProfit float32 `json:"comGrossProfit"` //公司毛利
|
||||||
}
|
CityManagerGrossProfit float32 `json:"cityManagerGrossProfit"` //城市经理毛利
|
||||||
|
MarketManName string `json:"marketManName"` //市场负责人
|
||||||
//是否存在这个门店
|
OperatorName string `json:"operatorName"` //运营负责人
|
||||||
func IsStoreExist(db *DaoDB, storeID int) (StatisticsForOrdersExists *StatisticsForOrdersExists, err error) {
|
OperatorName2 string `json:"operatorName2"`
|
||||||
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, fromDate time.Time, toDate time.Time) (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 = ?
|
|
||||||
`
|
|
||||||
sqlParams := []interface{}{}
|
|
||||||
sqlParams = append(sqlParams, storeID)
|
|
||||||
if !utils.IsTimeZero(fromDate) && !utils.IsTimeZero(toDate) {
|
|
||||||
sql += `AND a.order_created_at BETWEEN ? and ?
|
|
||||||
`
|
|
||||||
sqlParams = append(sqlParams, fromDate, toDate)
|
|
||||||
}
|
|
||||||
sql += `
|
|
||||||
GROUP BY a.store_id
|
|
||||||
`
|
|
||||||
|
|
||||||
if err = GetRow(db, &StatisticsForOrdersExists, sql, sqlParams...); err == nil {
|
|
||||||
return StatisticsForOrdersExists, nil
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//查询统计订单信息
|
//查询统计订单信息
|
||||||
@@ -75,25 +39,48 @@ func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate time.Time,
|
|||||||
//排除已取消的订单
|
//排除已取消的订单
|
||||||
status := strconv.Itoa(model.OrderStatusCanceled)
|
status := strconv.Itoa(model.OrderStatusCanceled)
|
||||||
sql := `
|
sql := `
|
||||||
SELECT s.*,
|
SELECT
|
||||||
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,
|
c.id store_id,
|
||||||
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
|
c.name store_name,
|
||||||
FROM store c,(
|
s.orderCounts order_counts,
|
||||||
|
s.salePrice sale_price,
|
||||||
|
s.actualPayPrice actual_pay_price,
|
||||||
|
s.shopPrice shop_price,
|
||||||
|
s.discountMoney discount_money,
|
||||||
|
s.desiredFee desired_fee,
|
||||||
|
s.distanceFreightMoney distance_freight_money,
|
||||||
|
s.waybillTipMoney waybill_tip_money,
|
||||||
|
s.totalShopMoney total_shop_money,
|
||||||
|
s.pmSubsidyMoney pm_subsidy_money,
|
||||||
|
s.EarningPrice earning_price,
|
||||||
|
s.totalGrossProfit total_gross_profit,
|
||||||
|
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)) com_grossProfit,
|
||||||
|
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)) city_manager_gross_profit,
|
||||||
|
IF(mm.name <> '', mm.name, mm.user_id2) market_man_name,
|
||||||
|
IF(om.name <> '', om.name, om.user_id2) operator_name,
|
||||||
|
IF(om2.name <> '', om2.name, om2.user_id2) operator_name2
|
||||||
|
FROM store c
|
||||||
|
LEFT JOIN user mm ON mm.mobile <> '' AND mm.mobile = c.market_man_phone
|
||||||
|
LEFT JOIN user om ON om.mobile <> '' AND om.mobile = c.operator_phone
|
||||||
|
LEFT JOIN user om2 ON om2.mobile <> '' AND om2.mobile = c.operator_phone2
|
||||||
|
LEFT JOIN
|
||||||
|
(
|
||||||
SELECT
|
SELECT
|
||||||
a.store_id storeID,
|
a.store_id storeID,
|
||||||
count(*) orderCounts,
|
COUNT(*) orderCounts,
|
||||||
sum(sale_price) salePrice,
|
SUM(sale_price) salePrice,
|
||||||
sum(actual_pay_price) actualPayPrice,
|
SUM(actual_pay_price) actualPayPrice,
|
||||||
sum(shop_price) shopPrice,
|
SUM(shop_price) shopPrice,
|
||||||
sum(discount_money) discountMoney,
|
SUM(discount_money) discountMoney,
|
||||||
sum(desired_fee) desiredFee,
|
SUM(desired_fee) desiredFee,
|
||||||
sum(distance_freight_money) distanceFreightMoney,
|
SUM(distance_freight_money) distanceFreightMoney,
|
||||||
sum(waybill_tip_money) waybillTipMoney,
|
SUM(waybill_tip_money) waybillTipMoney,
|
||||||
sum(total_shop_money) totalShopMoney,
|
SUM(total_shop_money) totalShopMoney,
|
||||||
sum(pm_subsidy_money) pmSubsidyMoney,
|
SUM(pm_subsidy_money) pmSubsidyMoney,
|
||||||
sum(earning_price) EarningPrice,
|
SUM(earning_price) EarningPrice,
|
||||||
sum(total_shop_money-earning_price-desired_fee-distance_freight_money-waybill_tip_money-80) totalGrossProfit
|
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
|
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 + `
|
WHERE a.status != ` + status + `
|
||||||
`
|
`
|
||||||
sqlParams := []interface{}{}
|
sqlParams := []interface{}{}
|
||||||
@@ -110,8 +97,13 @@ func GetStatisticsReportForOrders(db *DaoDB, storeIDs []int, fromDate time.Time,
|
|||||||
sql += `
|
sql += `
|
||||||
GROUP BY a.store_id
|
GROUP BY a.store_id
|
||||||
)s
|
)s
|
||||||
WHERE s.storeID = c.id
|
ON s.storeID = c.id
|
||||||
`
|
`
|
||||||
|
if len(storeIDs) > 0 {
|
||||||
|
sql += `WHERE c.id IN (` + GenQuestionMarks(len(storeIDs)) + `)
|
||||||
|
`
|
||||||
|
sqlParams = append(sqlParams, storeIDs)
|
||||||
|
}
|
||||||
if err = GetRows(db, &statisticsReportForOrdersList, sql, sqlParams...); err == nil {
|
if err = GetRows(db, &statisticsReportForOrdersList, sql, sqlParams...); err == nil {
|
||||||
return statisticsReportForOrdersList, nil
|
return statisticsReportForOrdersList, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,3 +29,18 @@ func (c *ReportController) StatisticsReportForOrders() {
|
|||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 查询售后单统计信息
|
||||||
|
// @Description 根据门店idlist和时间范围查询
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param storeIDs formData string true "京西门店ID列表[1,2,3]"
|
||||||
|
// @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 /StatisticsReportForAfsOrders [post]
|
||||||
|
func (c *ReportController) StatisticsReportForAfsOrders() {
|
||||||
|
c.callStatisticsReportForAfsOrders(func(params *tReportStatisticsReportForAfsOrdersParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user