Browse Source

策略权限修改

xingzai 3 years ago
parent
commit
1cb07abc9b
3 changed files with 21 additions and 19 deletions
  1. 10 4
      models/company.go
  2. 1 1
      services/activity.go
  3. 10 14
      services/user.go

+ 10 - 4
models/company.go

@@ -35,10 +35,14 @@ func GetCompanyDetailByIdGroup(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
 			INNER JOIN company_product AS b ON a.company_id=b.company_id
+			INNER JOIN company_report_permission AS p ON p.company_id = a.company_id
+			INNER JOIN chart_permission AS cp ON cp.chart_permission_id = p.chart_permission_id
 			LEFT JOIN admin AS c ON b.seller_id=c.admin_id
-			WHERE a.company_id=? AND b.product_id = 2  GROUP BY b.company_id `
+			WHERE a.company_id=? AND b.product_id = 2 
+			OR (a.company_id = ? AND  cp.permission_name = '策略' ) 
+			GROUP BY b.company_id `
 	o := orm.NewOrm()
-	err = o.Raw(sql, companyId).QueryRow(&item)
+	err = o.Raw(sql, companyId, companyId).QueryRow(&item)
 	return
 }
 
@@ -46,10 +50,12 @@ func GetCountCompanyDetailByIdGroup(companyId int) (count int, err error) {
 	sql := ` SELECT COUNT(1) AS count
             FROM company AS a
 			INNER JOIN company_product AS b ON a.company_id=b.company_id
+			INNER JOIN company_report_permission AS p ON p.company_id = a.company_id
+			INNER JOIN chart_permission AS cp ON cp.chart_permission_id = p.chart_permission_id
 			LEFT JOIN admin AS c ON b.seller_id=c.admin_id
-			WHERE a.company_id=? AND b.product_id = 2  `
+			WHERE a.company_id=? AND b.product_id = 2     `
 	o := orm.NewOrm()
-	err = o.Raw(sql, companyId).QueryRow(&count)
+	err = o.Raw(sql, companyId, companyId).QueryRow(&count)
 	return
 }
 

+ 1 - 1
services/activity.go

@@ -172,7 +172,7 @@ func SendEmailFileToExpert(cont context.Context) (err error) {
 		//创建excel
 		dir, errFile := os.Executable()
 		exPath := filepath.Dir(dir)
-		downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+		downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandDigit(5) + ".xlsx"
 		xlsxFile := xlsx.NewFile()
 		if errFile != nil {
 			msg = "生成文件失败Err:" + errFile.Error()

+ 10 - 14
services/user.go

@@ -406,7 +406,7 @@ func AddUserRecord(openId, unionId, nickName, realName, province, city, country,
 	return
 }
 
-//预约外呼名单,会前1小时自动发送邮件给专家组
+//每天新增,删除的白名单(弃用)
 func SendEmailUserWhiteList(cont context.Context) (err error) {
 	var msg string
 	var fieldStr string
@@ -589,13 +589,11 @@ func SendEmailUserWhiteList(cont context.Context) (err error) {
 	return
 }
 
-//预约外呼名单,会前1小时自动发送邮件给专家组
+//每天新增,删除的白名单
 func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 	var msg string
 	var fieldStr string
 	var condition string
-	//var mobileStr string
-	//var touser string
 	defer func() {
 		if err != nil {
 			fmt.Println("err:", err, time.Now())
@@ -636,7 +634,6 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 		msg = "获取失败,Err:" + err.Error()
 		return
 	}
-
 	var rep models.UserWhiteListRep
 	for _, v := range list2 {
 		list1 = append(list1, v)
@@ -645,7 +642,7 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 	//创建excel
 	dir, errFile := os.Executable()
 	exPath := filepath.Dir(dir)
-	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDate) + "新增白名单" + ".xlsx"
 	xlsxFile := xlsx.NewFile()
 	if errFile != nil {
 		msg = "生成文件失败Err:" + errFile.Error()
@@ -743,14 +740,13 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 	}
 	//go utils.SendEmailHaveFile(title, content, fileName, "cxzhang@hzinsights.com")
 	//go utils.SendEmailHaveFile(title, content, fileName, "tshen@hzinsights.com")
-	time.Sleep(time.Duration(2) * time.Second) //延迟两秒,避免过多活动的时候邮件发送没有内容
-	defer func() {
-		os.Remove(downLoadnFilePath)
-	}()
+	//defer func() {
+	os.Remove(downLoadnFilePath)
+	//}()
 	//创建冻结excel
 	dir, errFile = os.Executable()
 	exPath = filepath.Dir(dir)
-	downLoadnFilePaths := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	downLoadnFilePaths := exPath + "/" + time.Now().Format(utils.FormatDate) + "删除白名单" + ".xlsx"
 	xlsxFile = xlsx.NewFile()
 	if errFile != nil {
 		msg = "生成文件失败Err:" + errFile.Error()
@@ -862,9 +858,9 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 
 	//go utils.SendEmailHaveFile(title, content, fileName, "cxzhang@hzinsights.com")
 	time.Sleep(time.Duration(2) * time.Second) //延迟两秒,避免过多活动的时候邮件发送没有内容
-	defer func() {
-		os.Remove(downLoadnFilePaths)
-	}()
+	//defer func() {
+	os.Remove(downLoadnFilePaths)
+	//}()
 	if len(list1) > 0 {
 		for _, v := range list1 {
 			item := new(models.WxUserWhite)