users.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package services
  2. import (
  3. "fmt"
  4. "github.com/tealeg/xlsx"
  5. "hongze/hongze_task/models"
  6. "hongze/hongze_task/utils"
  7. "os"
  8. "time"
  9. )
  10. //用户权限统计
  11. func HongzeUsers() (err error) {
  12. defer func() {
  13. if err != nil {
  14. fmt.Println("crete HongzeUsers err:", err.Error())
  15. utils.FileLog.Info("crete HongzeUsers err: %s", err.Error())
  16. }
  17. }()
  18. items,err:=models.GetHongzeUsers()
  19. if err!=nil {
  20. return
  21. }
  22. title:="用户权限统计"
  23. //创建excel
  24. file := xlsx.NewFile()
  25. sheet, err := file.AddSheet(title)
  26. if err != nil {
  27. return err
  28. }
  29. //标头
  30. rowTitle := sheet.AddRow()
  31. cellA := rowTitle.AddCell()
  32. cellA.Value = "用户名称"
  33. cellB := rowTitle.AddCell()
  34. cellB.Value = "公司名称"
  35. cellC := rowTitle.AddCell()
  36. cellC.Value = "手机号"
  37. cellD := rowTitle.AddCell()
  38. cellD.Value = "是否使用"
  39. cellE := rowTitle.AddCell()
  40. cellE.Value = "是否付费用户"
  41. for _, item := range items {
  42. row := sheet.AddRow()
  43. cellA := row.AddCell()
  44. cellA.Value = item.RealName
  45. cellB := row.AddCell()
  46. cellB.Value = item.CompanyName
  47. cellC := row.AddCell()
  48. cellC.Value=item.Mobile
  49. cellD := row.AddCell()
  50. cellD.Value = item.IsRegister
  51. cellE := row.AddCell()
  52. cellE.Value = item.UserType
  53. }
  54. savePath := "hongze_user"+ time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  55. err = file.Save("./" + savePath)
  56. if err != nil {
  57. return
  58. }
  59. //发送邮件
  60. fmt.Println("start send email")
  61. sendResult := utils.SendEmailByHongze(title, "用户权限统计',\"你好,用户权限统计见附件。", utils.EmailSendToHzUsers, savePath,title+".xlsx")
  62. if sendResult {
  63. os.Remove(savePath)
  64. }
  65. fmt.Println("send result:", sendResult)
  66. fmt.Println("end send email")
  67. return nil
  68. }
  69. func FixReportLasterViewTime() {
  70. items,err:=models.GetPotentialUser()
  71. if err!=nil {
  72. fmt.Println("Err:"+err.Error())
  73. return
  74. }
  75. for k,v:=range items{
  76. maxTime,err:=models.GetMaxReviewTime(int(v.UserId))
  77. if err!=nil {
  78. fmt.Println("GetMaxReviewTime Err:"+err.Error())
  79. return
  80. }
  81. err=models.ModifyUserLastViewTime(int(v.UserId),maxTime)
  82. if err!=nil {
  83. fmt.Println("ModifyUserLastViewTime Err:"+err.Error())
  84. return
  85. }
  86. fmt.Println(k,v.UserId,v.Mobile)
  87. }
  88. }