aa
This commit is contained in:
@@ -158,3 +158,10 @@ func GetPayStatistics(ctx *jxcontext.Context, userID string, pop int, cityCodes
|
|||||||
)
|
)
|
||||||
return dao.GetPayStatistics(db, userID, pop, cityCodes, mobile, utils.Str2Time(fromTime), utils.Str2Time(toTime), consumeTypes)
|
return dao.GetPayStatistics(db, userID, pop, cityCodes, mobile, utils.Str2Time(fromTime), utils.Str2Time(toTime), consumeTypes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetIncomeStatistics(ctx *jxcontext.Context, userID string, pop int, cityCodes []int, mobile, fromTime, toTime string) (getIncomeStatisticsResult *dao.GetIncomeStatisticsResult, err error) {
|
||||||
|
var (
|
||||||
|
db = dao.GetDB()
|
||||||
|
)
|
||||||
|
return dao.GetIncomeStatistics(db, userID, pop, cityCodes, mobile, utils.Str2Time(fromTime), utils.Str2Time(toTime))
|
||||||
|
}
|
||||||
|
|||||||
@@ -184,17 +184,37 @@ type GetPayStatisticsResult struct {
|
|||||||
AccountBalance int `json:"accountBalance"` //未提现(含保证金)
|
AccountBalance int `json:"accountBalance"` //未提现(含保证金)
|
||||||
SubmitCash int `json:"submitCash"` //申请提现
|
SubmitCash int `json:"submitCash"` //申请提现
|
||||||
Cashed int `json:"cashed"` //已经体现
|
Cashed int `json:"cashed"` //已经体现
|
||||||
TotalIncome int `json:"totalIncome"` //收益总额
|
|
||||||
MemberIncome int `json:"memberIncome"` //会员收益
|
|
||||||
CashIncome int `json:"cashIncome"` //提现收益
|
CashIncome int `json:"cashIncome"` //提现收益
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPayStatistics(db *DaoDB, userID string, pop int, cityCodes []int, mobile string, fromTime, toTime time.Time, orderTypes []int) (getPayStatisticsResult *GetPayStatisticsResult, err error) {
|
func GetPayStatistics(db *DaoDB, userID string, pop int, cityCodes []int, mobile string, fromTime, toTime time.Time, orderTypes []int) (getPayStatisticsResult *GetPayStatisticsResult, err error) {
|
||||||
sqlParams := []interface{}{}
|
sqlParams := []interface{}{}
|
||||||
|
getWhereSql := func(fromTime, toTime time.Time, orderTypes []int) (sql string) {
|
||||||
|
if len(orderTypes) > 0 {
|
||||||
|
sql += ` AND order_type IN ` + GenQuestionMarks(len(orderTypes)) + `)`
|
||||||
|
sqlParams = append(sqlParams, orderTypes)
|
||||||
|
}
|
||||||
|
if fromTime != utils.ZeroTimeValue {
|
||||||
|
sql += ` AND created_at > ?`
|
||||||
|
sqlParams = append(sqlParams, fromTime)
|
||||||
|
}
|
||||||
|
if toTime != utils.ZeroTimeValue {
|
||||||
|
sql += ` AND created_at < ?`
|
||||||
|
sqlParams = append(sqlParams, toTime)
|
||||||
|
}
|
||||||
|
return sql
|
||||||
|
}
|
||||||
sql := `
|
sql := `
|
||||||
SELECT a.*
|
SELECT t1.total_pay, t2.submit_cash + t3.account_balance can_cash, t3.account_balance, t4.cashed, t4.cashed / 10 cash_income
|
||||||
FROM user a
|
FROM user a
|
||||||
|
LEFT JOIN (SELECT SUM(pay_price) total_pay, user_id FROM order WHERE type = ? AND status = ? ` + getWhereSql(fromTime, toTime, orderTypes) + ` GROUP BY 2) t1 ON t1.user_id = a.user_id
|
||||||
|
LEFT JOIN (SELECT SUM(pay_price) submit_cash, user_id FROM order WHERE type = ? AND status = ?` + getWhereSql(fromTime, toTime, orderTypes) + ` GROUP BY 2) t2 ON t2.user_id = a.user_id
|
||||||
|
LEFT JOIN user_bill t3 ON t3.user_id = a.user_id
|
||||||
|
LEFT JOIN (SELECT SUM(pay_price) cashed, user_id FROM order WHERE type = ? AND status = ?` + getWhereSql(fromTime, toTime, orderTypes) + ` GROUP BY 2) t4 ON t4.user_id = a.user_id
|
||||||
`
|
`
|
||||||
|
sqlParams = append(sqlParams, model.OrderTypePay, model.OrderStatusFinished)
|
||||||
|
sqlParams = append(sqlParams, model.OrderTypeCash, model.OrderStatusWait4Pay)
|
||||||
|
sqlParams = append(sqlParams, model.OrderTypeCash, model.OrderStatusFinished)
|
||||||
if mobile != "" {
|
if mobile != "" {
|
||||||
if pop == 1 {
|
if pop == 1 {
|
||||||
sql += " JOIN user e ON e.moblie = ? AND a.pop_user = e.user_id"
|
sql += " JOIN user e ON e.moblie = ? AND a.pop_user = e.user_id"
|
||||||
@@ -226,3 +246,47 @@ func GetPayStatistics(db *DaoDB, userID string, pop int, cityCodes []int, mobile
|
|||||||
err = GetRow(db, &getPayStatisticsResult, sql, sqlParams)
|
err = GetRow(db, &getPayStatisticsResult, sql, sqlParams)
|
||||||
return getPayStatisticsResult, err
|
return getPayStatisticsResult, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetIncomeStatisticsResult struct {
|
||||||
|
TotalIncome int `json:"totalIncome"` //收益总额
|
||||||
|
MemberIncome int `json:"memberIncome"` //会员收益
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetIncomeStatistics(db *DaoDB, userID string, pop int, cityCodes []int, mobile string, fromTime, toTime time.Time) (getIncomeStatisticsResult *GetIncomeStatisticsResult, err error) {
|
||||||
|
sqlParams := []interface{}{}
|
||||||
|
sql := `
|
||||||
|
SELECT
|
||||||
|
FROM user a
|
||||||
|
JOIN
|
||||||
|
`
|
||||||
|
if mobile != "" {
|
||||||
|
if pop == 1 {
|
||||||
|
sql += " JOIN user e ON e.moblie = ? AND a.pop_user = e.user_id"
|
||||||
|
sqlParams = append(sqlParams, mobile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sql += `
|
||||||
|
WHERE 1 = 1
|
||||||
|
`
|
||||||
|
if userID != "" {
|
||||||
|
if pop == 1 {
|
||||||
|
sql += " AND a.pop_user = ?"
|
||||||
|
sqlParams = append(sqlParams, userID)
|
||||||
|
} else {
|
||||||
|
sql += " AND a.user_id = ?"
|
||||||
|
sqlParams = append(sqlParams, userID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if mobile != "" {
|
||||||
|
if pop == 0 {
|
||||||
|
sql += " AND a.mobile = ?"
|
||||||
|
sqlParams = append(sqlParams, mobile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(cityCodes) > 0 {
|
||||||
|
sql += ` AND a.city_code IN ` + GenQuestionMarks(len(cityCodes)) + `)`
|
||||||
|
sqlParams = append(sqlParams, cityCodes)
|
||||||
|
}
|
||||||
|
err = GetRow(db, &getIncomeStatisticsResult, sql, sqlParams)
|
||||||
|
return getIncomeStatisticsResult, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -125,3 +125,25 @@ func (c *OrderController) GetPayStatistics() {
|
|||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 收益统计
|
||||||
|
// @Description 收益统计
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param userID query string false "用户id"
|
||||||
|
// @Param pop query int false "1为你邀请的,0为全部"
|
||||||
|
// @Param cityCodes query string false "城市id列表"
|
||||||
|
// @Param mobile query string false "用户手机,必须全匹配"
|
||||||
|
// @Param fromTime query string false "消费开始时间"
|
||||||
|
// @Param toTime query string false "消费结束时间"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /GetIncomeStatistics [get]
|
||||||
|
func (c *OrderController) GetIncomeStatistics() {
|
||||||
|
c.callGetIncomeStatistics(func(params *tOrderGetIncomeStatisticsParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
var cityCodes []int
|
||||||
|
if err = jxutils.Strings2Objs(params.CityCodes, &cityCodes); err == nil {
|
||||||
|
retVal, err = cms.GetIncomeStatistics(params.Ctx, params.UserID, params.Pop, cityCodes, params.Mobile, params.FromTime, params.ToTime)
|
||||||
|
}
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -628,6 +628,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "GetIncomeStatistics",
|
||||||
|
Router: `/GetIncomeStatistics`,
|
||||||
|
AllowHTTPMethods: []string{"get"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "GetOrders",
|
Method: "GetOrders",
|
||||||
|
|||||||
Reference in New Issue
Block a user