aa
This commit is contained in:
81
dao/sim_dao.go
Normal file
81
dao/sim_dao.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetSimFlowExpend(db *sqlx.DB, iccid string, createdAtBegin, createdAtEnd time.Time) (simFlowExpnd []*model.SimFlowExpend, err error) {
|
||||
|
||||
return simFlowExpnd, err
|
||||
}
|
||||
|
||||
func GetSimFlowExpendSum(db *sqlx.DB, iccid string, createdAtBegin, createdAtEnd time.Time) (simFlowExpnd *model.SimFlowExpend, err error) {
|
||||
var (
|
||||
simFlowExpnds []*model.SimFlowExpend
|
||||
)
|
||||
sql := `
|
||||
SELECT SUM(
|
||||
IF(flow_unit = 'KB', flow,
|
||||
IF(flow_unit = 'MB', ROUND(flow * 1024)),
|
||||
IF(flow_unit = "GB", ROUND(flow * 1024 * 1024), 0)
|
||||
)
|
||||
) flow, icc_id, 'KB' flow_unit
|
||||
FROM sim_flow_expend
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if iccid != "" {
|
||||
sql += " AND icc_id = ?"
|
||||
sqlParams = append(sqlParams, iccid)
|
||||
}
|
||||
if !utils.IsTimeZero(createdAtBegin) {
|
||||
sql += " AND created_at > ?"
|
||||
sqlParams = append(sqlParams, createdAtBegin)
|
||||
}
|
||||
if !utils.IsTimeZero(createdAtEnd) {
|
||||
sql += " AND created_at < ?"
|
||||
sqlParams = append(sqlParams, createdAtEnd)
|
||||
}
|
||||
sql += " GROUP BY 2, 3"
|
||||
if err = db.Select(&simFlowExpnds, sql, sqlParams); err == nil && len(simFlowExpnds) > 0 {
|
||||
return simFlowExpnds[0], err
|
||||
}
|
||||
return simFlowExpnd, err
|
||||
}
|
||||
|
||||
func GetSimFlowIncomeSum(db *sqlx.DB, iccid string, createdAtBegin, createdAtEnd time.Time) (simFlowIncome *model.SimFlowIncome, err error) {
|
||||
var (
|
||||
simFlowIncomes []*model.SimFlowIncome
|
||||
)
|
||||
sql := `
|
||||
SELECT SUM(
|
||||
IF(flow_unit = 'KB', flow,
|
||||
IF(flow_unit = 'MB', ROUND(flow * 1024)),
|
||||
IF(flow_unit = "GB", ROUND(flow * 1024 * 1024), 0)
|
||||
)
|
||||
) flow, icc_id, 'KB' flow_unit
|
||||
FROM sim_flow_income
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if iccid != "" {
|
||||
sql += " AND icc_id = ?"
|
||||
sqlParams = append(sqlParams, iccid)
|
||||
}
|
||||
if !utils.IsTimeZero(createdAtBegin) {
|
||||
sql += " AND created_at > ?"
|
||||
sqlParams = append(sqlParams, createdAtBegin)
|
||||
}
|
||||
if !utils.IsTimeZero(createdAtEnd) {
|
||||
sql += " AND created_at < ?"
|
||||
sqlParams = append(sqlParams, createdAtEnd)
|
||||
}
|
||||
sql += " GROUP BY 2, 3"
|
||||
if err = db.Select(&simFlowIncomes, sql, sqlParams); err == nil && len(simFlowIncomes) > 0 {
|
||||
return simFlowIncomes[0], err
|
||||
}
|
||||
return simFlowIncome, err
|
||||
}
|
||||
Reference in New Issue
Block a user