package crons import ( "designs/global" "fmt" "os" "time" ) func ActiveDelete() { //读取前一日数据 now := time.Now() for i := 30; i <= 40; i++ { last := now.AddDate(0, 0, -i).Format("2006-01-02") path := "storage" + "/" + last //删除前一天的文件夹 err := os.RemoveAll(path) if err != nil { fmt.Println("删除文件夹失败:"+path, err) } else { fmt.Println("删除文件夹完成:" + path) } } } func OnlineDatabaseDelete() { //获取到表名 now := time.Now() date := now.AddDate(0, 0, -29).Format("20060102") tableName := "user_online_" + date var tableList []string sql := "SELECT table_name FROM information_schema.tables WHERE table_schema = 'chunhao' AND table_name LIKE '" + tableName + "%'" err := global.App.DB.Raw(sql).Pluck("table_name", &tableList).Error if err != nil { global.App.Log.Error("查询", date, "user_online数据表失败", err.Error()) return } //批量删除数据表 for _, table := range tableList { sql := "drop table IF EXISTS " + table err := global.App.DB.Exec(sql).Error if err != nil { global.App.Log.Error("删除", table, "数据表失败", err.Error()) return } } global.App.Log.Info(date, "数据表清理完成", tableList) } // 对日活数据进行汇算 func RemainDataSummary() { //计算每日的留存 } //对广告数据进行汇算 //对打点数据进行汇算