This commit is contained in:
suyl
2021-07-20 16:52:41 +08:00
parent 59cc2d4ffd
commit b94de1d201
5 changed files with 112 additions and 22 deletions

View File

@@ -39,3 +39,32 @@ func GetSimFlowExpendSum(db *DaoDB, iccid string, createdAtBegin, createdAtEnd t
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
}

View File

@@ -70,9 +70,10 @@ func (v *SimFlowExpend) TableIndex() [][]string {
type SimFlowIncome struct {
ModelIDCUL
IccID string `orm:"column(icc_id)" json:"iccID"` //sim卡iccid
Flow float64 `json:"flow"` //流量数
FlowUnit string `json:"flowUnit"` //流量单位
IccID string `orm:"column(icc_id)" json:"iccID"` //sim卡iccid
Flow float64 `json:"flow"` //流量数
FlowUnit string `json:"flowUnit"` //流量单位
IncomeType int `json:"incomeType"` //1 表示系统每月自动划转2 表示商户自己冲的
}
func (v *SimFlowIncome) TableIndex() [][]string {