Files
jx-callback/business/model/dao/dao_sim.go
suyl b94de1d201 aa
2021-07-20 16:52:41 +08:00

71 lines
1.9 KiB
Go

package dao
import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
"time"
)
func GetSimFlowExpend(db *DaoDB, iccid string, createdAtBegin, createdAtEnd time.Time) (simFlowExpnd []*model.SimFlowExpend, err error) {
return simFlowExpnd, err
}
func GetSimFlowExpendSum(db *DaoDB, iccid string, createdAtBegin, createdAtEnd time.Time) (simFlowExpnd *model.SimFlowExpend, err error) {
sql := `
SELECT SUM(
IF(flow_unit = 'KB', flow,
IF(flow_unit = 'MB', ROUND(flow * 1024)),
IF(flow_unit = "GB", ROUND(flow * 1024 * 1024), 0)
)
), 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"
err = GetRow(db, &simFlowExpnd, sql, sqlParams)
return simFlowExpnd, err
}
func GetSimFlowIncomeSum(db *DaoDB, iccid string, createdAtBegin, createdAtEnd time.Time) (simFlowIncome *model.SimFlowIncome, err error) {
sql := `
SELECT SUM(
IF(flow_unit = 'KB', flow,
IF(flow_unit = 'MB', ROUND(flow * 1024)),
IF(flow_unit = "GB", ROUND(flow * 1024 * 1024), 0)
)
), 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"
err = GetRow(db, &simFlowIncome, sql, sqlParams)
return simFlowIncome, err
}