free_viewer.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package services
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/tealeg/xlsx"
  6. "hongze/hongze_task/models"
  7. "hongze/hongze_task/utils"
  8. "os"
  9. "time"
  10. )
  11. //潜在客户回访记录
  12. func FreeViewerDetail(cont context.Context) (err error) {
  13. defer func() {
  14. if err != nil {
  15. fmt.Println("crete FreeViewerDetail err:", err.Error())
  16. utils.FileLog.Info("crete FreeViewerDetail err: %s", err.Error())
  17. }
  18. }()
  19. //endTime := time.Now().Format(utils.FormatDateTime)
  20. startTime := time.Now().AddDate(0, 0, -7).Format(utils.FormatDateTime)
  21. endTime := time.Now().Format(utils.FormatDateTime)
  22. items, err := models.GetFreeViewerDetails(startTime, endTime)
  23. if err != nil {
  24. return
  25. }
  26. title := "潜在客户回访记录"
  27. //创建excel
  28. file := xlsx.NewFile()
  29. sheet, err := file.AddSheet(title)
  30. if err != nil {
  31. return err
  32. }
  33. //标头
  34. rowTitle := sheet.AddRow()
  35. cellA := rowTitle.AddCell()
  36. cellA.Value = "姓名"
  37. cellB := rowTitle.AddCell()
  38. cellB.Value = "手机号"
  39. cellC := rowTitle.AddCell()
  40. cellC.Value = "客户公司"
  41. cellD := rowTitle.AddCell()
  42. cellD.Value = "注册时间"
  43. cellE := rowTitle.AddCell()
  44. cellE.Value = "邮箱"
  45. for _, item := range items {
  46. row := sheet.AddRow()
  47. cellA := row.AddCell()
  48. cellA.Value = item.RealName
  49. cellB := row.AddCell()
  50. cellB.Value = item.Mobile
  51. cellC := row.AddCell()
  52. cellC.Value = item.Note
  53. cellD := row.AddCell()
  54. cellD.Value = item.CreatedTime
  55. cellE := row.AddCell()
  56. cellE.Value = item.Email
  57. models.DealWxUser(item.UserId)
  58. }
  59. savePath := "free_viewer_details" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  60. err = file.Save("./" + savePath)
  61. if err != nil {
  62. return
  63. }
  64. //发送邮件
  65. fmt.Println("start send email")
  66. sendResult := utils.SendEmailByHongze(title, "潜在客户回访记录',\"你好,上周潜在客户回访记录见附件。", utils.EmailSendToHzUsers, savePath, title+".xlsx")
  67. //sendResult:=utils.SendEmailByHongze(title,"你好,上周研报阅读统计见附件。",utils.EmailSendToMe,savePath)
  68. if sendResult {
  69. os.Remove(savePath)
  70. }
  71. //fmt.Println("send result:", sendResult)
  72. fmt.Println("end send email")
  73. return nil
  74. }