userAction.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package crons
  2. import (
  3. "designs/global"
  4. "designs/service"
  5. "fmt"
  6. "os"
  7. "time"
  8. )
  9. func ActiveDelete() {
  10. //读取前一日数据
  11. now := time.Now()
  12. for i := 30; i <= 40; i++ {
  13. last := now.AddDate(0, 0, -i).Format("2006-01-02")
  14. path := "storage" + "/" + last
  15. //删除前一天的文件夹
  16. err := os.RemoveAll(path)
  17. if err != nil {
  18. fmt.Println("删除文件夹失败:"+path, err)
  19. } else {
  20. fmt.Println("删除文件夹完成:" + path)
  21. }
  22. }
  23. }
  24. func OnlineDatabaseDelete() {
  25. //获取到表名
  26. now := time.Now()
  27. date := now.AddDate(0, 0, -29).Format("20060102")
  28. tableName := "user_online_" + date
  29. var tableList []string
  30. sql := "SELECT table_name FROM information_schema.tables WHERE table_schema = 'chunhao' AND table_name LIKE '" + tableName + "%'"
  31. err := global.App.DB.Raw(sql).Pluck("table_name", &tableList).Error
  32. if err != nil {
  33. global.App.Log.Error("查询", date, "user_online数据表失败", err.Error())
  34. return
  35. }
  36. //批量删除数据表
  37. for _, table := range tableList {
  38. sql := "drop table IF EXISTS " + table
  39. err := global.App.DB.Exec(sql).Error
  40. if err != nil {
  41. global.App.Log.Error("删除", table, "数据表失败", err.Error())
  42. return
  43. }
  44. }
  45. global.App.Log.Info(date, "数据表清理完成", tableList)
  46. }
  47. //对广告数据进行汇算
  48. func AdsDataSummary() {
  49. lastDay := time.Now().AddDate(0, 0, -1).Format("20060102")
  50. service.SeeAdsSummary(lastDay)
  51. return
  52. }
  53. //
  54. //// 对打点数据进行汇算
  55. //func ActionDataSummary() {
  56. // lastDay := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
  57. //
  58. // //获取
  59. //}