feat: select the range of days for statistics
This commit is contained in:
@@ -3,7 +3,6 @@ package service
|
||||
import (
|
||||
"crm/global"
|
||||
"crm/models"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -11,7 +10,7 @@ type DashboardService struct {
|
||||
}
|
||||
|
||||
// 数据汇总
|
||||
func (d *DashboardService) Summary(uid int64) models.DashboardSum {
|
||||
func (d *DashboardService) Summary(uid int64, days int) models.DashboardSum {
|
||||
var ds models.DashboardSum
|
||||
global.Db.Raw("select count(*) from customer where creator = ?", uid).Scan(&ds.Customers)
|
||||
global.Db.Raw("select count(*) from contract where creator = ?", uid).Scan(&ds.Contracts)
|
||||
@@ -20,10 +19,11 @@ func (d *DashboardService) Summary(uid int64) models.DashboardSum {
|
||||
|
||||
now := time.Now().Unix()
|
||||
con := "created > ? and created < ? and status = 1 and creator = ?"
|
||||
for i, d := 0, 7; i < 7; i++ {
|
||||
ds.Amount = make([]float64, days)
|
||||
ds.Date = make([]string, days)
|
||||
for i, d := 0, days; i < days; i++ {
|
||||
day := now - (int64(d) * 24 * 60 * 60)
|
||||
start, end := dayRange(day)
|
||||
fmt.Println(start, end)
|
||||
global.Db.Table(CONTRACT).Where(con, start, end, uid).Pluck("amount", &ds.Amount[i])
|
||||
ds.Date[i] = time.Unix(day, 0).Format("01-02")
|
||||
d--
|
||||
|
||||
Reference in New Issue
Block a user