aa
This commit is contained in:
@@ -191,32 +191,33 @@ type GetPayStatisticsResult struct {
|
||||
}
|
||||
|
||||
func getWhereSql(sqlP []interface{}, fromTime, toTime time.Time, orderTypes []int) (sql string) {
|
||||
if len(orderTypes) > 0 {
|
||||
sql += ` AND b.order_type IN ` + GenQuestionMarks(len(orderTypes)) + `)`
|
||||
sqlP = append(sqlP, orderTypes)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND b.created_at > ?`
|
||||
sqlP = append(sqlP, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND b.created_at < ?`
|
||||
sqlP = append(sqlP, toTime)
|
||||
}
|
||||
|
||||
return sql
|
||||
}
|
||||
|
||||
func getFromSql(sqlP []interface{}, orderType, status int, alies string, userID string, pop int, cityCodes []int, mobile string, fromTime, toTime time.Time, orderTypes []int) (sql string) {
|
||||
func getFromSql(orderType, status int, alies string, userID string, pop int, cityCodes []int, mobile string, fromTime, toTime time.Time, orderTypes []int) (sql string, sqlParams []interface{}) {
|
||||
sql += `
|
||||
(SELECT SUM(IFNULL(b.pay_price,0)) total_pay
|
||||
FROM user a
|
||||
JOIN ` + "`order` b " + `ON b.user_id = a.user_id AND b.type = ? AND b.status = ? ` + getWhereSql(sqlP, fromTime, toTime, orderTypes) + `
|
||||
`
|
||||
sqlP = append(sqlP, orderType, status)
|
||||
JOIN ` + "`order` b " + `ON b.user_id = a.user_id AND b.type = ? AND b.status = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, orderType, status)
|
||||
if len(orderTypes) > 0 {
|
||||
sql += ` AND b.order_type IN ` + GenQuestionMarks(len(orderTypes)) + `)`
|
||||
sqlParams = append(sqlParams, orderTypes)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += ` AND b.created_at > ?`
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += ` AND b.created_at < ?`
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
if mobile != "" {
|
||||
if pop == 1 {
|
||||
sql += " JOIN user e ON e.moblie = ? AND a.pop_user = e.user_id"
|
||||
sqlP = append(sqlP, mobile)
|
||||
sqlParams = append(sqlParams, mobile)
|
||||
}
|
||||
}
|
||||
sql += `
|
||||
@@ -225,33 +226,39 @@ func getFromSql(sqlP []interface{}, orderType, status int, alies string, userID
|
||||
if userID != "" {
|
||||
if pop == 1 {
|
||||
sql += " AND a.pop_user = ?"
|
||||
sqlP = append(sqlP, userID)
|
||||
sqlParams = append(sqlParams, userID)
|
||||
} else {
|
||||
sql += " AND a.user_id = ?"
|
||||
sqlP = append(sqlP, userID)
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
}
|
||||
if mobile != "" {
|
||||
if pop == 0 {
|
||||
sql += " AND a.mobile = ?"
|
||||
sqlP = append(sqlP, mobile)
|
||||
sqlParams = append(sqlParams, mobile)
|
||||
}
|
||||
}
|
||||
if len(cityCodes) > 0 {
|
||||
sql += ` AND a.city_code IN ` + GenQuestionMarks(len(cityCodes)) + `)`
|
||||
sqlP = append(sqlP, cityCodes)
|
||||
sqlParams = append(sqlParams, cityCodes)
|
||||
}
|
||||
sql += `) ` + alies
|
||||
return sql
|
||||
return sql, sqlParams
|
||||
}
|
||||
|
||||
func GetPayStatistics(db *DaoDB, userID string, pop int, cityCodes []int, mobile string, fromTime, toTime time.Time, orderTypes []int) (getPayStatisticsResult *GetPayStatisticsResult, err error) {
|
||||
var sqlParams []interface{}
|
||||
sqlParams := []interface{}{}
|
||||
sql := `SELECT t1.total_pay, t2.total_pay submit_cash, t3.total_pay cashed, t4.account_balance, t4.account_balance + t2.total_pay can_cash, t3.total_pay / 10 cash_income
|
||||
FROM `
|
||||
sql += getFromSql(sqlParams, model.OrderTypePay, model.OrderStatusFinished, "t1", userID, pop, cityCodes, mobile, fromTime, toTime, orderTypes) + ","
|
||||
sql += getFromSql(sqlParams, model.OrderTypeCash, model.OrderStatusWait4Pay, "t2", userID, pop, cityCodes, mobile, fromTime, toTime, orderTypes) + ","
|
||||
sql += getFromSql(sqlParams, model.OrderTypeCash, model.OrderStatusFinished, "t3", userID, pop, cityCodes, mobile, fromTime, toTime, orderTypes) + ","
|
||||
rSQL1, rSQLParams1 := getFromSql(model.OrderTypePay, model.OrderStatusFinished, "t1", userID, pop, cityCodes, mobile, fromTime, toTime, orderTypes)
|
||||
sql += rSQL1 + ","
|
||||
sqlParams = append(sqlParams, rSQLParams1...)
|
||||
rSQL2, rSQLParams2 := getFromSql(model.OrderTypeCash, model.OrderStatusWait4Pay, "t2", userID, pop, cityCodes, mobile, fromTime, toTime, orderTypes)
|
||||
sql += rSQL2 + ","
|
||||
sqlParams = append(sqlParams, rSQLParams2...)
|
||||
rSQL3, rSQLParams3 := getFromSql(model.OrderTypeCash, model.OrderStatusFinished, "t3", userID, pop, cityCodes, mobile, fromTime, toTime, orderTypes)
|
||||
sql += rSQL3 + ","
|
||||
sqlParams = append(sqlParams, rSQLParams3...)
|
||||
sql += `(SELECT SUM(IFNULL(b.account_balance,0)) account_balacne
|
||||
FROM user a
|
||||
JOIN user_bill b ON a.user_id = b.user_id
|
||||
|
||||
Reference in New Issue
Block a user