xingzai 3 лет назад
Родитель
Сommit
2a4c626934
8 измененных файлов с 456 добавлено и 142 удалено
  1. 205 24
      controllers/activity.go
  2. 2 1
      models/activity.go
  3. 13 0
      models/company.go
  4. 1 1
      models/tactics.go
  5. 43 5
      models/user.go
  6. 5 5
      services/activity.go
  7. 4 0
      services/task.go
  8. 183 106
      services/user.go

+ 205 - 24
controllers/activity.go

@@ -3,8 +3,11 @@ package controllers
 import (
 	"encoding/json"
 	"fmt"
+	"github.com/tealeg/xlsx"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
+	"os"
+	"path/filepath"
 	"rdluck_tools/paging"
 	"strconv"
 	"strings"
@@ -614,6 +617,9 @@ func (this *ActivityCoAntroller) Detail() {
 		if activityInfo.SignupNum > activityInfo.LimitPeopleNum {
 			activityInfo.SignupNum = activityInfo.LimitPeopleNum
 		}
+		if activityInfo.ChartPermissionNames != "" {
+			activityInfo.ChartPermissionName = activityInfo.ChartPermissionNames
+		}
 		resp.Detail = activityInfo
 	}
 	resp.HasPermission = hasPermission
@@ -1540,7 +1546,7 @@ func (this *ActivityCoAntroller) LabelList() {
 		return
 	}
 	pageSize, _ := this.GetInt("PageSize")
-	currentIndex, _ := this.GetInt("CurrentIndex")
+	//currentIndex, _ := this.GetInt("CurrentIndex")
 	chartPermissionIds := this.GetString("ChartPermissionIds")
 	activityTypeIds := this.GetString("ActivityTypeIds")
 	whichDay := this.GetString("WhichDay")
@@ -1610,9 +1616,9 @@ func (this *ActivityCoAntroller) LabelList() {
 	//if pageSize <= 0 {
 	//	pageSize = utils.PageSize20
 	//}
-	currentIndex = 1
+	//currentIndex = 1
 	pageSize = 16
-	startSize = utils.StartIndex(currentIndex, pageSize)
+	//startSize = utils.StartIndex(currentIndex, pageSize)
 	var condition string
 	var pars []interface{}
 	//活动可见限制
@@ -1634,16 +1640,48 @@ func (this *ActivityCoAntroller) LabelList() {
 	}
 	sqlExport += `) `
 
+	condition += ` AND art.publish_status = 1  AND art.label != '' `
+	var conditionOr string
+	if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
+		conditionOr += ` OR (  art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%'	 ` + condition + `) `
+	}
+	if (userType == 5) && strings.Contains(permissionStr, "专家") {
+		conditionOr += ` OR (  art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%'	 ` + condition + `) `
+	}
+	conditionOr += `	OR ( art.is_limit_people = 0 	  ` + condition + `) `
+	condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
+	resp := new(models.GetCygxActivityLabelListRep)
+
 	//主题
 	if label != "" {
-		startSize = 17
-		//sliceLabel := strings.Split(label, ",")
-		//var labelSqlStr string
-		//for _, v := range sliceLabel {
-		//	labelSqlStr += "'" + v + "',"
-		//}
-		//labelSqlStr = strings.TrimRight(labelSqlStr, ",")
-		//condition = `  AND art.label  NOT IN (` + labelSqlStr + `)`
+		listAll, errList := models.GetActivityLabelListAll(condition, pars, startSize, 32)
+		if errList != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + errList.Error()
+			return
+		}
+		list1, errList := models.GetActivityLabelListAll(condition, pars, startSize, 16)
+		if errList != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + errList.Error()
+			return
+		}
+		for _, v := range listAll {
+			var isHAve bool
+			for _, v2 := range list1 {
+				if v2.KeyWord == v.KeyWord {
+					isHAve = true
+				}
+			}
+			if !isHAve {
+				resp.List = append(resp.List, v)
+			}
+		}
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		br.Data = resp
+		return
 	} else {
 		//行业名称
 		if len(chartPermissionIds) > 0 {
@@ -1674,28 +1712,171 @@ func (this *ActivityCoAntroller) LabelList() {
 			condition += ` AND art.active_state  IN (1)`
 		}
 	}
-	condition += ` AND art.publish_status = 1  AND art.label != '' `
-	var conditionOr string
-	if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
-		conditionOr += ` OR (  art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%'	 ` + condition + `) `
-	}
-	if (userType == 5) && strings.Contains(permissionStr, "专家") {
-		conditionOr += ` OR (  art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%'	 ` + condition + `) `
-	}
-	conditionOr += `	OR ( art.is_limit_people = 0 	  ` + condition + `) `
-	condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
-
-	condition += `	GROUP BY art.label ORDER BY art.active_state ASC, art.activity_time DESC  `
 	list, errList := models.GetActivityLabelListAll(condition, pars, startSize, pageSize)
 	if errList != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败,Err:" + errList.Error()
 		return
 	}
-	resp := new(models.GetCygxActivityLabelListRep)
+	//resp := new(models.GetCygxActivityLabelListRep)
 	resp.List = list
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 上传参会表格
+// @Description 上传参会表格数据
+// @Param   File   query   file  true       "文件"
+// @Param   ActivityId   query   int  true     "活动ID"
+// @Success 200 Ret=200 导入成功
+// @router /activityMeet/import [post]
+func (this *ActivityCoAntroller) Import() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.User
+	if sysUser == nil {
+		br.Msg = "请重新登录"
+		return
+	}
+	file, h, err := this.GetFile("File")
+	if err != nil {
+		br.Msg = "获取文件失败"
+		br.ErrMsg = "获取文件失败,Err:" + err.Error()
+		return
+	}
+
+	uploadDir := "static/xls"
+	err = os.MkdirAll(uploadDir, 766)
+	if err != nil {
+		br.Msg = "存储目录创建失败"
+		br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
+		return
+	}
+	path := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
+	defer file.Close()
+	err = this.SaveToFile("File", path)
+	if err != nil {
+		br.Msg = "文件保存失败"
+		br.ErrMsg = "文件保存失败,Err:" + err.Error()
+		return
+	}
+	xlFile, err := xlsx.OpenFile(path)
+	if err != nil {
+		br.Msg = "文件导入失败"
+		br.ErrMsg = "文件导入失败,Err:" + err.Error()
+		return
+	}
+	//允许添加的联系人
+	needAddAttendanc := make([]*models.UserWhiteList, 0)
+
+	// 遍历sheet页读取
+	for _, sheet := range xlFile.Sheets {
+		//遍历行读取
+		maxRow := sheet.MaxRow
+		for i := 0; i < maxRow; i++ {
+			if i >= 1 {
+				row := sheet.Row(i)
+				cells := row.Cells
+				var companyName, permission string
+				for k, cell := range cells {
+					if k == 0 {
+						companyName = cell.String()
+					}
+					if k == 2 {
+						permission = cell.String()
+					}
+
+				}
+				//这些字段都没有的话,系统认为excel到底了
+				if companyName == "" {
+					break
+				}
+				item := new(models.UserWhiteList)
+				item.CompanyName = companyName
+				item.Permission = permission
+				needAddAttendanc = append(needAddAttendanc, item)
+			}
+		}
+	}
+	//var mobileStr string
+	var permissionStr string
+	for k, v := range needAddAttendanc {
+		if k > 0 && v.CompanyName != needAddAttendanc[k-1].CompanyName {
+			permissionStr, err = models.GetCompanyPermissionByName(v.CompanyName)
+			if err != nil {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+				return
+			}
+		}
+		if k == 0 {
+			permissionStr, err = models.GetCompanyPermissionByName(v.CompanyName)
+			if err != nil {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+				return
+			}
+		}
+		needAddAttendanc[k].Permission = permissionStr
+		fmt.Println(permissionStr)
+	}
+
+	defer func() {
+		os.Remove(path)
+	}()
+
+	//创建excel
+	dir, errFile := os.Executable()
+	exPath := filepath.Dir(dir)
+	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	xlsxFile := xlsx.NewFile()
+	if errFile != nil {
+		br.Msg = "生成文件失败Err:" + errFile.Error()
+		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 {
+		br.Msg = "新增Sheet失败,Err:" + err.Error()
+		return
+	}
+	//标头
+	rowTitle := sheet.AddRow()
+	cellA := rowTitle.AddCell()
+	cellA.Value = ""
+	cellB := rowTitle.AddCell()
+	cellB.Value = "公司"
+	cellC := rowTitle.AddCell()
+	cellC.Value = "权限"
+	for _, item := range needAddAttendanc {
+		row := sheet.AddRow()
+		cellA := row.AddCell()
+		cellA.Value = item.CompanyName
+		cellB := row.AddCell()
+		if item.Permission == "" {
+			//item.Permission = "专家/医药/智造/消费/研选/科技/策略/路演服务"
+		}
+		cellB.Value = item.Permission
+	}
+	errFile = xlsxFile.Save(downLoadnFilePath)
+	if errFile != nil {
+		br.Msg = "保存文件失败Err:" + errFile.Error()
+		return
+	}
+
+	br.Msg = "导入成功"
+	br.Ret = 200
+	br.Success = true
+}

+ 2 - 1
models/activity.go

@@ -58,6 +58,7 @@ type ActivityDetail struct {
 	ActivityTypeName        string `description:"活动类型名称"`
 	ChartPermissionId       int    `description:"行业id"`
 	ChartPermissionName     string `description:"行业名称"`
+	ChartPermissionNames    string `description:"行业名称辅助字段,区分研选子分类"`
 	Body                    string `description:"内容"`
 	CreateTime              string `description:"创建时间"`
 	IsLimitPeople           int    `description:"是否限制人数 1是,0否"`
@@ -432,7 +433,7 @@ func GetActivityLabelListAll(condition string, pars []interface{}, startSize, pa
 	if condition != "" {
 		sql += condition
 	}
-	sql += ` LIMIT ?,? `
+	sql += ` GROUP BY art.label ORDER BY  art.activity_time DESC ,art.activity_id DESC  LIMIT ?,? `
 	fmt.Println(sql)
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return

+ 13 - 0
models/company.go

@@ -74,6 +74,19 @@ func GetCompanyPermission(companyId int) (permission string, err error) {
 	return
 }
 
+func GetCompanyPermissionByName(name string) (permission string, err error) {
+	sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name  ORDER BY b.sort ASC SEPARATOR '/') AS permission
+			FROM company_report_permission AS a
+			INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
+			INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id
+			INNER JOIN company AS cm ON cm.company_id=c.company_id 
+			WHERE  cm.company_name=?
+			AND b.product_id = 2 `
+	o := orm.NewOrm()
+	err = o.Raw(sql, name).QueryRow(&permission)
+	return
+}
+
 func GetCompanyDetailAllById(companyId int) (item *CompanyDetail, err error) {
 	sql := ` SELECT a.company_id,a.company_name,b.status,b.seller_id,b.seller_name,c.mobile 
             FROM company AS a

+ 1 - 1
models/tactics.go

@@ -90,7 +90,7 @@ func GetTacticsList2(endDate string) (list []*Tactics2, err error) {
 			INNER JOIN article_content AS b ON a.id=b.article_id
 			INNER JOIN article_category AS c ON a.id=c.article_id
 			INNER JOIN article_categoryinfo AS d ON c.category_id=d.id
-			WHERE a.publish_status=1  AND a.publish_date>=? AND d.id IN (7,9,11,28,32,45,51,52,57,62,64,65,66,67,69,71,72,74,79,80,84,85,86,87,88,89,90,93,95,96,98,100) `
+			WHERE a.publish_status=1  AND a.publish_date>=? AND d.id IN (7,9,11,28,32,45,51,52,57,62,64,65,66,67,69,71,72,74,79,80,84,85,86,87,88,89,90,93,95,96,98,100,102)`
 	//AND a.id NOT IN (3454,3456,3457,3459,2449,2450,2453,2454,2459,2530,2583,2663,2670,2699,2715,2732,2748,2759,2399,2356,2870,3173,2978,2826,3470) `
 	//IN(85,71)
 	_, err = o.Raw(sql, endDate).QueryRows(&list)

+ 43 - 5
models/user.go

@@ -211,9 +211,23 @@ func AddCountryCode(CountryCode string, userId int) (err error) {
 	return
 }
 
-//获取用户白名单
-func GetUserWhiteList(fieldStr, condition string) (items []*ArticleInterviewApplyList, err error) {
+type UserWhiteList struct {
+	Mobile      string `description:"手机号码"`
+	RealName    string `description:"用户实际名称"`
+	CompanyName string `description:"公司名称"`
+	Permission  string `description:"拥有权限分类,多个用英文逗号分隔"`
+	CountryCode string `description:"区号"`
+	SellerName  string `description:"销售姓名"`
+}
+
+type UserWhiteListRep struct {
+	List []*UserWhiteList
+}
+
+//获取正式试用用户白名单
+func GetFormalUserWhiteList(fieldStr, condition string) (items []*UserWhiteList, err error) {
 	sql := `SELECT ` + fieldStr + `
+		(SELECT cp.seller_name FROM company_product  AS cp WHERE cp.company_id = u.company_id ORDER BY cp.product_id DESC  LIMIT 0,1 ) as seller_name,
 		GROUP_CONCAT( DISTINCT b.chart_permission_name SEPARATOR '/' ) AS permission
 		FROM wx_user AS u
 		INNER JOIN company as c ON c.company_id = u.company_id
@@ -222,10 +236,34 @@ func GetUserWhiteList(fieldStr, condition string) (items []*ArticleInterviewAppl
 		INNER JOIN company_product AS cp ON cp.company_id = u.company_id
 		WHERE 1= 1
 		AND p.product_id = 2
-		AND cp.product_id = 2
-		AND u.company_id >1 
-		AND u.mobile = u.outbound_mobile ` + condition + `
+		AND u.company_id >1 ` + condition + `
 		GROUP BY u.user_id`
 	_, err = orm.NewOrm().Raw(sql).QueryRows(&items)
 	return
 }
+
+//获取永续用户白名单
+func GetSustainableUserWhiteList(fieldStr, condition string) (items []*UserWhiteList, err error) {
+	sql := `SELECT ` + fieldStr + `
+			(SELECT cp.seller_name FROM company_product  AS cp WHERE cp.company_id = u.company_id ORDER BY cp.product_id DESC  LIMIT 0,1 ) as seller_name,
+			(SELECT
+				GROUP_CONCAT( DISTINCT b.chart_permission_name SEPARATOR '/' ) 
+			FROM
+				company_report_permission AS p
+				INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id 
+			WHERE
+				p.company_id = u.company_id 
+				AND p.status IN ( '永续' ) 
+				AND p.product_id = 2 
+			) AS permission 
+			FROM wx_user AS u
+			INNER JOIN company AS c ON c.company_id = u.company_id
+			INNER JOIN company_report_permission AS p ON p.company_id = u.company_id
+			INNER JOIN chart_permission AS b ON b.chart_permission_id = p.chart_permission_id
+			INNER JOIN company_product AS cp ON cp.company_id = u.company_id 
+			WHERE 1 = 1
+			AND u.company_id > 1  ` + condition + `
+			GROUP BY u.user_id `
+	_, err = orm.NewOrm().Raw(sql).QueryRows(&items)
+	return
+}

+ 5 - 5
services/activity.go

@@ -229,15 +229,15 @@ func SendEmailFileToExpert(cont context.Context) (err error) {
 		title := activityInfo.ActivityName + "外呼名单"
 		content := "外呼名单详情"
 		fileName := downLoadnFilePath
-		if activityInfo.ChartPermissionName == "科技" {
+		if activityInfo.ChartPermissionName == "科技" || activityInfo.ChartPermissionNames == "研选(科技)" {
 			touser = utils.EmailTechnology
-		} else if activityInfo.ChartPermissionName == "医药" {
+		} else if activityInfo.ChartPermissionName == "医药" || activityInfo.ChartPermissionNames == "研选(医药)" {
 			touser = utils.EmailMedicine
-		} else if activityInfo.ChartPermissionName == "消费" {
+		} else if activityInfo.ChartPermissionName == "消费" || activityInfo.ChartPermissionNames == "研选(消费)" {
 			touser = utils.EmailConsumption
-		} else if activityInfo.ChartPermissionName == "智造" {
+		} else if activityInfo.ChartPermissionName == "智造" || activityInfo.ChartPermissionNames == "研选(智造)" {
 			touser = utils.EmailZhizao
-		} else if activityInfo.ChartPermissionName == "策略" {
+		} else if activityInfo.ChartPermissionName == "策略" || activityInfo.ChartPermissionNames == "研选" {
 			touser = utils.EmailStrategy
 		}
 		go utils.SendEmailHaveFile(title, content, fileName, touser)

+ 4 - 0
services/task.go

@@ -51,6 +51,10 @@ func Task() {
 	sendEmailFileToExpert := task.NewTask("sendEmailFileToExpert", "0 */5 8-22 * * *", SendEmailFileToExpert) //预约外呼名单,会前1小时自动发送邮件给专家组
 	task.AddTask("sendEmailFileToExpert", sendEmailFileToExpert)
 
+	//白名单发送
+	//sendEmailUserWhiteList := task.NewTask("sendEmailUserWhiteList", "0 35 16 * * *", SendEmailUserWhiteList) //预约外呼名单,会前1小时自动发送邮件给专家组
+	//task.AddTask("sendEmailUserWhiteList", sendEmailUserWhiteList)
+
 	//editOutboundMobile := task.NewTask("editOutboundMobile", "0 */1 8-22 * * *", EditOutboundMobile) //同步外呼号码与手机号
 	//task.AddTask("sendEmailFileToExpert", editOutboundMobile)
 	//UpdateActivitySattus()

+ 183 - 106
services/user.go

@@ -1,10 +1,14 @@
 package services
 
 import (
+	"context"
 	"errors"
 	"fmt"
+	"github.com/tealeg/xlsx"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
+	"os"
+	"path/filepath"
 	"strconv"
 	"time"
 )
@@ -397,109 +401,182 @@ func AddUserRecord(openId, unionId, nickName, realName, province, city, country,
 }
 
 //预约外呼名单,会前1小时自动发送邮件给专家组
-//func SendEmailUserInfoTo(cont context.Context) (err error) {
-//	var msg string
-//	//var touser string
-//	defer func() {
-//		if err != nil {
-//			fmt.Println("err:", err)
-//			go utils.SendEmail("发送附件模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
-//			utils.FileLog.Info("发送附件模版消息失败,Err:%s", err.Error())
-//		}
-//		if msg != "" {
-//			fmt.Println(msg)
-//			utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
-//		}
-//	}()
-//	fmt.Println("发送附件")
-//
-//	list, err := models.GetUserFormalTrial()
-//	if err != nil {
-//		msg = "获取失败,Err:" + err.Error()
-//		return
-//	}
-//	//创建excel
-//	dir, errFile := os.Executable()
-//	exPath := filepath.Dir(dir)
-//	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
-//	xlsxFile := xlsx.NewFile()
-//	if errFile != nil {
-//		msg = "生成文件失败Err:" + errFile.Error()
-//		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 {
-//		msg = "新增Sheet失败,Err:" + err.Error()
-//		return
-//	}
-//	//标头
-//	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 = "所属销售"
-//
-//	for _, item := range list {
-//		row := sheet.AddRow()
-//		cellA := row.AddCell()
-//		cellA.Value = item.RealName
-//		cellB := row.AddCell()
-//		cellB.Value = item.OutboundMobile
-//		cellC := row.AddCell()
-//		if item.CountryCode == "" {
-//			cellC.Value = "86"
-//		} else {
-//			cellC.Value = item.CountryCode
-//		}
-//		cellD := row.AddCell()
-//		cellD.Value = item.CompanyName
-//		cellE := row.AddCell()
-//		cellE.Value = item.SellerName
-//	}
-//	errFile = xlsxFile.Save(downLoadnFilePath)
-//	if errFile != nil {
-//		msg = "保存文件失败Err:" + errFile.Error()
-//		return
-//	}
-//	//title := activityInfo.ActivityName + "外呼名单"
-//	//content := "外呼名单详情"
-//	//fileName := downLoadnFilePath
-//	//if activityInfo.ChartPermissionName == "科技" {
-//	//	touser = utils.EmailTechnology
-//	//} else if activityInfo.ChartPermissionName == "医药" {
-//	//	touser = utils.EmailMedicine
-//	//} else if activityInfo.ChartPermissionName == "消费" {
-//	//	touser = utils.EmailConsumption
-//	//} else if activityInfo.ChartPermissionName == "智造" {
-//	//	touser = utils.EmailZhizao
-//	//} else if activityInfo.ChartPermissionName == "策略" {
-//	//	touser = utils.EmailStrategy
-//	//}
-//	//go utils.SendEmailHaveFile(title, content, fileName, touser)
-//	defer func() {
-//		//os.Remove(downLoadnFilePath)
-//	}()
-//	time.Sleep(time.Duration(2) * time.Second) //延迟两秒,避免过多活动的时候邮件发送没有内容
-//	errFile = models.UPdateActivityIdToSendFile(v.ActivityId)
-//	if errFile != nil {
-//		msg = "获取失败,Err:" + errFile.Error()
-//		return
-//	}
-//
-//	fmt.Println("发送附件完成")
-//	return
-//}
+func SendEmailUserWhiteList(cont context.Context) (err error) {
+	var msg string
+	var fieldStr string
+	var condition string
+	//var touser string
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go utils.SendEmail("发送附件模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
+			utils.FileLog.Info("发送附件模版消息失败,Err:%s", err.Error())
+		}
+		if msg != "" {
+			fmt.Println(msg)
+			utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
+		}
+	}()
+	fmt.Println("发送附件")
+	fieldStr = ` u.mobile,u.country_code,u.real_name,c.company_name,u.company_id,cp.seller_name,`
+	condition = ` AND u.mobile = u.outbound_mobile AND cp.status IN ( '正式', '试用' ) AND u.mobile != ''  `
+	list1, err := models.GetFormalUserWhiteList(fieldStr, condition)
+	if err != nil {
+		msg = "获取失败,Err:" + err.Error()
+		return
+	}
+	fieldStr = ` u.outbound_mobile as mobile,u.outbound_country_code as country_code,u.real_name,c.company_name,u.company_id,`
+	condition = ` AND u.mobile != u.outbound_mobile AND cp.status IN ( '正式', '试用' ) AND u.outbound_mobile != ''  `
+	list2, err := models.GetFormalUserWhiteList(fieldStr, condition)
+	if err != nil {
+		msg = "获取失败,Err:" + err.Error()
+		return
+	}
+
+	fieldStr = `u.mobile,u.country_code,u.real_name,c.company_name,u.company_id,`
+	condition = ` AND u.mobile = u.outbound_mobile  AND cp.status IN ( '永续' ) AND u.mobile != '' `
+	list3, err := models.GetSustainableUserWhiteList(fieldStr, condition)
+	if err != nil {
+		msg = "获取失败,Err:" + err.Error()
+		return
+	}
+	fieldStr = ` u.outbound_mobile as mobile,u.outbound_country_code as country_code,u.real_name,c.company_name,u.company_id,`
+	condition = ` AND u.mobile != u.outbound_mobile AND cp.status IN ( '永续') AND u.outbound_mobile != ''  `
+	list4, err := models.GetSustainableUserWhiteList(fieldStr, condition)
+	if err != nil {
+		msg = "获取失败,Err:" + err.Error()
+		return
+	}
+	var rep models.UserWhiteListRep
+	for _, v := range list1 {
+		rep.List = append(rep.List, v)
+	}
+	for _, v := range list2 {
+		rep.List = append(rep.List, v)
+	}
+	for _, v := range list3 {
+		rep.List = append(rep.List, v)
+	}
+	for _, v := range list4 {
+		rep.List = append(rep.List, v)
+	}
+
+	//创建excel
+	dir, errFile := os.Executable()
+	exPath := filepath.Dir(dir)
+	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	xlsxFile := xlsx.NewFile()
+	if errFile != nil {
+		msg = "生成文件失败Err:" + errFile.Error()
+		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 {
+		msg = "新增Sheet失败,Err:" + err.Error()
+		return
+	}
+	//标头
+	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 = "归属部门"
+	cellL := rowTitle.AddCell()
+	cellL.Value = "备注"
+	cellM := rowTitle.AddCell()
+	cellM.Value = "权限(消费,医药,智造,科技,策略)"
+	for _, item := range rep.List {
+		row := sheet.AddRow()
+		cellA := row.AddCell()
+		cellA.Value = item.RealName
+		cellB := row.AddCell()
+		cellB.Value = item.Mobile
+		cellC := row.AddCell()
+		cellC.Value = item.CountryCode
+		if len(item.Mobile) >= 11 && item.CountryCode == "" {
+			cellC.Value = "86"
+		}
+		cellD := row.AddCell()
+		cellD.Value = item.CompanyName
+		cellE := row.AddCell()
+		cellE.Value = ""
+		cellF := row.AddCell()
+		cellF.Value = ""
+		cellG := row.AddCell()
+		cellG.Value = ""
+		cellH := row.AddCell()
+		cellH.Value = item.SellerName
+		cellI := row.AddCell()
+		cellI.Value = ""
+		cellJ := row.AddCell()
+		cellJ.Value = ""
+		cellK := row.AddCell()
+		cellK.Value = ""
+		cellL := row.AddCell()
+		cellL.Value = ""
+		cellM := row.AddCell()
+		if item.Permission == "" {
+			item.Permission = "专家/医药/智造/消费/研选/科技/策略/路演服务"
+		}
+		cellM.Value = item.Permission
+	}
+	errFile = xlsxFile.Save(downLoadnFilePath)
+	if errFile != nil {
+		msg = "保存文件失败Err:" + errFile.Error()
+		return
+	}
+	title := "用户白名单"
+	content := "用户白名单"
+	fileName := downLoadnFilePath
+	//if activityInfo.ChartPermissionName == "科技" {
+	//	touser = utils.EmailTechnology
+	//} else if activityInfo.ChartPermissionName == "医药" {
+	//	touser = utils.EmailMedicine
+	//} else if activityInfo.ChartPermissionName == "消费" {
+	//	touser = utils.EmailConsumption
+	//} else if activityInfo.ChartPermissionName == "智造" {
+	//	touser = utils.EmailZhizao
+	//} else if activityInfo.ChartPermissionName == "策略" {
+	//	touser = utils.EmailStrategy
+	//}
+	go utils.SendEmailHaveFile(title, content, fileName, "cxzhang@hzinsights.com;tshen@hzinsights.com")
+	//go utils.SendEmailHaveFile(title, content, fileName, "cxzhang@hzinsights.com")
+	//go utils.SendEmailHaveFile(title, content, fileName, "tshen@hzinsights.com")
+	time.Sleep(time.Duration(10) * time.Second) //延迟两秒,避免过多活动的时候邮件发送没有内容
+	//errFile = models.UPdateActivityIdToSendFile(v.ActivityId)
+	//if errFile != nil {
+	//	msg = "获取失败,Err:" + errFile.Error()
+	//	return
+	//}
+	defer func() {
+		os.Remove(downLoadnFilePath)
+	}()
+	fmt.Println("发送附件完成", len(rep.List))
+	return
+}