|
@@ -966,3 +966,215 @@ func GetUserhasPermission(user *models.WxUserItem) (hasPermission int, err error
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+//每周五发送当前所有的权益用户
|
|
|
+func SendEmailAllUserWithRAI() (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("err:", err, time.Now())
|
|
|
+ go utils.SendEmail("发送权益用户邮件失败"+"【"+utils.APPNAME+"】"+time.Now().Format(utils.FormatDateTime), ";Err:"+err.Error(), utils.EmailSendToUsers)
|
|
|
+ utils.FileLog.Info("发送权益用户邮件失败,Err:%s", err.Error())
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ list, err := models.GetSendEmailAllUserWithRAI()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //创建excel
|
|
|
+ dir, err := os.Executable()
|
|
|
+ exPath := filepath.Dir(dir)
|
|
|
+ downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandDigit(5) + ".xlsx"
|
|
|
+ xlsxFile := xlsx.NewFile()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ style := xlsx.NewStyle()
|
|
|
+ alignment := xlsx.Alignment{
|
|
|
+ Horizontal: "center",
|
|
|
+ Vertical: "center",
|
|
|
+ WrapText: true,
|
|
|
+ }
|
|
|
+ style.Alignment = alignment
|
|
|
+ style.ApplyAlignment = true
|
|
|
+ sheet, err := xlsxFile.AddSheet("权益用户名单")
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //设置宽度
|
|
|
+ _ = sheet.SetColWidth(0, 0, 30)
|
|
|
+ _ = sheet.SetColWidth(1, 1, 22)
|
|
|
+ _ = sheet.SetColWidth(3, 3, 18)
|
|
|
+ _ = sheet.SetColWidth(5, 5, 15)
|
|
|
+ _ = sheet.SetColWidth(7, 8, 12)
|
|
|
+ _ = sheet.SetColWidth(9, 9, 17)
|
|
|
+ _ = sheet.SetColWidth(10, 10, 35)
|
|
|
+ //标头
|
|
|
+ rowTitle := sheet.AddRow()
|
|
|
+ cellA := rowTitle.AddCell()
|
|
|
+ cellA.Value = "客户名称"
|
|
|
+ cellB := rowTitle.AddCell()
|
|
|
+ cellB.Value = "社会信用码"
|
|
|
+ cellC := rowTitle.AddCell()
|
|
|
+ cellC.Value = "客户类型"
|
|
|
+ cellD := rowTitle.AddCell()
|
|
|
+ cellD.Value = "行业"
|
|
|
+ cellE := rowTitle.AddCell()
|
|
|
+ cellE.Value = "所属销售"
|
|
|
+ cellF := rowTitle.AddCell()
|
|
|
+ cellF.Value = "销售手机号"
|
|
|
+ cellG := rowTitle.AddCell()
|
|
|
+ cellG.Value = "状态"
|
|
|
+ cellH := rowTitle.AddCell()
|
|
|
+ cellH.Value = "服务起始期限"
|
|
|
+ cellI := rowTitle.AddCell()
|
|
|
+ cellI.Value = "服务结束期限"
|
|
|
+ cellJ := rowTitle.AddCell()
|
|
|
+ cellJ.Value = "创建时间"
|
|
|
+ cellK := rowTitle.AddCell()
|
|
|
+ cellK.Value = "权限"
|
|
|
+ if len(list) > 0 {
|
|
|
+ for _, item := range list {
|
|
|
+ row := sheet.AddRow()
|
|
|
+ cellA := row.AddCell()
|
|
|
+ cellA.Value = item.CompanyName
|
|
|
+ cellB := row.AddCell()
|
|
|
+ cellB.Value = item.CreditCode
|
|
|
+ cellC := row.AddCell()
|
|
|
+ cellC.Value = item.ProductName
|
|
|
+ cellD := row.AddCell()
|
|
|
+ cellD.Value = item.IndustryName
|
|
|
+ cellE := row.AddCell()
|
|
|
+ cellE.Value = item.RealName
|
|
|
+ cellF := row.AddCell()
|
|
|
+ cellF.Value = item.Mobile
|
|
|
+ cellG := row.AddCell()
|
|
|
+ cellG.Value = item.Status
|
|
|
+ cellH := row.AddCell()
|
|
|
+ cellH.Value = item.StartDate
|
|
|
+ cellI := row.AddCell()
|
|
|
+ cellI.Value = item.EndDate
|
|
|
+ cellJ := row.AddCell()
|
|
|
+ cellJ.Value = item.CreatedTime
|
|
|
+ cellK := row.AddCell()
|
|
|
+ cellK.Value = item.Permission
|
|
|
+ }
|
|
|
+ }
|
|
|
+ err = xlsxFile.Save(downLoadnFilePath)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ title := time.Now().Format(utils.FormatDate) + "权益用户名单"
|
|
|
+ content := time.Now().Format(utils.FormatDate) + "权益用户名单"
|
|
|
+ fileName := downLoadnFilePath
|
|
|
+ if len(list) > 0 {
|
|
|
+ utils.SendEmailByHongze(title, content, "cxzhang@hzinsights.com;tshen@hzinsights.com", fileName, title+".xlsx")
|
|
|
+ }
|
|
|
+ os.Remove(downLoadnFilePath)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//每周五发送发送这些公司下的用户
|
|
|
+func SendEmailAllUserWithCompany() (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("err:", err, time.Now())
|
|
|
+ go utils.SendEmail("发送权益用户邮件失败"+"【"+utils.APPNAME+"】"+time.Now().Format(utils.FormatDateTime), ";Err:"+err.Error(), utils.EmailSendToUsers)
|
|
|
+ utils.FileLog.Info("发送权益用户邮件失败,Err:%s", err.Error())
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ list, err := models.GetSendEmailAllUserWithRAI()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //创建excel
|
|
|
+ dir, err := os.Executable()
|
|
|
+ exPath := filepath.Dir(dir)
|
|
|
+ downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandDigit(5) + ".xlsx"
|
|
|
+ xlsxFile := xlsx.NewFile()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ style := xlsx.NewStyle()
|
|
|
+ alignment := xlsx.Alignment{
|
|
|
+ Horizontal: "center",
|
|
|
+ Vertical: "center",
|
|
|
+ WrapText: true,
|
|
|
+ }
|
|
|
+ style.Alignment = alignment
|
|
|
+ style.ApplyAlignment = true
|
|
|
+ sheet, err := xlsxFile.AddSheet("权益用户名单")
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //设置宽度
|
|
|
+ _ = sheet.SetColWidth(0, 0, 30)
|
|
|
+ _ = sheet.SetColWidth(1, 1, 22)
|
|
|
+ _ = sheet.SetColWidth(3, 3, 18)
|
|
|
+ _ = sheet.SetColWidth(5, 5, 15)
|
|
|
+ _ = sheet.SetColWidth(7, 8, 12)
|
|
|
+ _ = sheet.SetColWidth(9, 9, 17)
|
|
|
+ _ = sheet.SetColWidth(10, 10, 35)
|
|
|
+ //标头
|
|
|
+ rowTitle := sheet.AddRow()
|
|
|
+ cellA := rowTitle.AddCell()
|
|
|
+ cellA.Value = "客户名称"
|
|
|
+ cellB := rowTitle.AddCell()
|
|
|
+ cellB.Value = "社会信用码"
|
|
|
+ cellC := rowTitle.AddCell()
|
|
|
+ cellC.Value = "客户类型"
|
|
|
+ cellD := rowTitle.AddCell()
|
|
|
+ cellD.Value = "行业"
|
|
|
+ cellE := rowTitle.AddCell()
|
|
|
+ cellE.Value = "所属销售"
|
|
|
+ cellF := rowTitle.AddCell()
|
|
|
+ cellF.Value = "销售手机号"
|
|
|
+ cellG := rowTitle.AddCell()
|
|
|
+ cellG.Value = "状态"
|
|
|
+ cellH := rowTitle.AddCell()
|
|
|
+ cellH.Value = "服务起始期限"
|
|
|
+ cellI := rowTitle.AddCell()
|
|
|
+ cellI.Value = "服务结束期限"
|
|
|
+ cellJ := rowTitle.AddCell()
|
|
|
+ cellJ.Value = "创建时间"
|
|
|
+ cellK := rowTitle.AddCell()
|
|
|
+ cellK.Value = "权限"
|
|
|
+ if len(list) > 0 {
|
|
|
+ for _, item := range list {
|
|
|
+ row := sheet.AddRow()
|
|
|
+ cellA := row.AddCell()
|
|
|
+ cellA.Value = item.CompanyName
|
|
|
+ cellB := row.AddCell()
|
|
|
+ cellB.Value = item.CreditCode
|
|
|
+ cellC := row.AddCell()
|
|
|
+ cellC.Value = item.ProductName
|
|
|
+ cellD := row.AddCell()
|
|
|
+ cellD.Value = item.IndustryName
|
|
|
+ cellE := row.AddCell()
|
|
|
+ cellE.Value = item.RealName
|
|
|
+ cellF := row.AddCell()
|
|
|
+ cellF.Value = item.Mobile
|
|
|
+ cellG := row.AddCell()
|
|
|
+ cellG.Value = item.Status
|
|
|
+ cellH := row.AddCell()
|
|
|
+ cellH.Value = item.StartDate
|
|
|
+ cellI := row.AddCell()
|
|
|
+ cellI.Value = item.EndDate
|
|
|
+ cellJ := row.AddCell()
|
|
|
+ cellJ.Value = item.CreatedTime
|
|
|
+ cellK := row.AddCell()
|
|
|
+ cellK.Value = item.Permission
|
|
|
+ }
|
|
|
+ }
|
|
|
+ err = xlsxFile.Save(downLoadnFilePath)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ title := time.Now().Format(utils.FormatDate) + "权益用户名单"
|
|
|
+ content := time.Now().Format(utils.FormatDate) + "权益用户名单"
|
|
|
+ fileName := downLoadnFilePath
|
|
|
+ if len(list) > 0 {
|
|
|
+ utils.SendEmailByHongze(title, content, "cxzhang@hzinsights.com;tshen@hzinsights.com", fileName, title+".xlsx")
|
|
|
+ }
|
|
|
+ os.Remove(downLoadnFilePath)
|
|
|
+ return
|
|
|
+}
|