فهرست منبع

Merge branch 'master' into cygx_12.0

ziwen 1 سال پیش
والد
کامیت
26cbe43a0d

+ 17 - 0
controllers/report_selection.go

@@ -63,6 +63,21 @@ func (this *ReportSelectionController) Detail() {
 		br.ErrMsg = "报告ID错误" + strconv.Itoa(articleId)
 		return
 	}
+
+	PermissionNameMap, err := services.GetPermissionNameMap()
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败 GetPermissionNameMap,Err:" + err.Error()
+		return
+	}
+
+	PermissionIcoMap, err := services.GetPermissionNameIcoMap()
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败 GetPermissionNameMap,Err:" + err.Error()
+		return
+	}
+
 	resp := new(models.ReportSelectionLetailResp)
 	//判断用户权限
 	hasPermission, err := services.GetUserhasPermission(user)
@@ -154,6 +169,8 @@ func (this *ReportSelectionController) Detail() {
 			}
 			item.BodyChartSummary = mapChartLog[v.PermissionName]
 			item.List = listSonLog
+			item.PermissionName = PermissionNameMap[v.ChartPermissionId]
+			item.IcoLink = PermissionIcoMap[v.ChartPermissionId]
 			items = append(items, item)
 			itemsSubject = append(itemsSubject, itemSubject)
 			//itemLogs = make([]*models.CygxReportSelectionLogDetail, 0)

+ 9 - 8
models/activity.go

@@ -730,6 +730,7 @@ func GetActivityIdToSendFile(endDate string) (items []*ActivityIdRep, err error)
 type SignupExportRep struct {
 	Mobile         string `description:"手机号"`
 	CompanyName    string `description:"公司名称"`
+	CompanyId      int    `description:"公司Id"`
 	RealName       string `description:"姓名"`
 	CountryCode    string `description:"区号"`
 	OutboundMobile string `description:"外呼手机号"`
@@ -748,17 +749,17 @@ type ActivityMsgExportRep struct {
 
 func GetSignupExport(activityId int) (item []*SignupExportRep, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT  s.outbound_mobile,
+	sql := `SELECT
+			s.outbound_mobile,
 			s.country_code,
 			a.is_limit_people,
-			u.real_name,
-			( SELECT p.seller_name FROM company_product AS p WHERE p.company_id = u.company_id AND p.product_id = 2 ) AS seller_name,
-			( SELECT c.company_name FROM company AS c WHERE c.company_id = u.company_id  ) AS company_name
-			FROM
+			s.real_name,
+			s.seller_name,
+			s.company_id,
+			s.company_name 
+		FROM
 			cygx_activity_signup AS s
-			LEFT JOIN wx_user AS u ON u.user_id = s.user_id
-			LEFT JOIN cygx_activity AS a ON a.activity_id = s.activity_id
-			LEFT JOIN company_product AS p ON p.company_id = u.company_id 
+			JOIN cygx_activity AS a ON a.activity_id = s.activity_id 
 			WHERE a.activity_id = ?  AND s.do_fail_type = 0 AND s.signup_type = 1  GROUP BY s.id `
 	_, err = o.Raw(sql, activityId).QueryRows(&item)
 	return

+ 1 - 1
models/activity_special_trip.go

@@ -71,7 +71,7 @@ func GetUserActivitySpecialTripCount(uid, activityId int) (count int, err error)
 
 // 获取某一活动的报名的数量
 func GetActivitySpecialTripCountByActivityId(condition string, pars []interface{}) (count int, err error) {
-	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip as t   INNER JOIN wx_user as  u on u.user_id = t.user_id WHERE    1 = 1 ` + condition
+	sqlCount := `SELECT COUNT(1) AS count FROM cygx_activity_special_trip as t  WHERE    1 = 1 ` + condition
 	o := orm.NewOrm()
 	err = o.Raw(sqlCount, pars).QueryRow(&count)
 	return

+ 5 - 8
models/activity_special_trip_bill.go

@@ -70,11 +70,9 @@ type CygxActivitySpecialTripBillList struct {
 func GetCygxActivitySpecialTripBillList(condition string, pars []interface{}) (item []*CygxActivitySpecialTripBillList, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
-			b.*,
-			c.chart_permission_name 
+			b.*
 		FROM
 			cygx_activity_special_trip_bill AS b
-			LEFT JOIN chart_permission AS c ON c.chart_permission_id = b.chart_permission_id 
 		WHERE
 			1 = 1` + condition
 	_, err = o.Raw(sql, pars).QueryRows(&item)
@@ -146,9 +144,9 @@ func AddCygxActivitySpecialTripBillMulti(items []*CygxActivitySpecialTripBill) (
 }
 
 type SpecialBillInitReduce struct {
-	CreateTime       time.Time
-	CompanyId          int
-	CompanyName        string
+	CreateTime  time.Time
+	CompanyId   int
+	CompanyName string
 }
 
 func GetActivitySecialTirpBillForReduce() (item []*SpecialBillInitReduce, err error) {
@@ -182,10 +180,9 @@ func GetCygxActivitySpecialTripBillByCompanyIdForInit(companyId int) (item []*Cy
 	return
 }
 
-
 func UpdateCygxActivitySpecialTripBillByCompanyIdForInit(total string, id int) (err error) {
 	o := orm.NewOrm()
 	sql := ` UPDATE cygx_activity_special_trip_bill SET total=? WHERE id = ?  `
-	_, err = o.Raw(sql,total, id).Exec()
+	_, err = o.Raw(sql, total, id).Exec()
 	return
 }

+ 8 - 0
models/chart_permission.go

@@ -9,6 +9,7 @@ type ChartPermission struct {
 	ChartPermissionId int    `description:"权限id"`
 	PermissionName    string `description:"权限名称"`
 	IsShowSustainable bool   `description:"是否展示限免标签"`
+	ImageUrlM         string `description:"图片地址"`
 }
 
 type ActivityChartPermission struct {
@@ -28,6 +29,13 @@ func GetChartPermissionAll(condition string) (items []*ChartPermission, err erro
 	return
 }
 
+func GetChartPermissionListRai() (items []*ChartPermission, err error) {
+	o := orm.NewOrmUsingDB("weekly_report")
+	sql := `SELECT * FROM chart_permission WHERE product_id=2  ORDER BY sort ASC `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
 func GetCategoryId(chartPermissionId int) (category_id string, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT GROUP_CONCAT(a.category_id) AS category_id 

+ 0 - 31
models/product_interior.go

@@ -36,37 +36,6 @@ type ProductInteriorIdReq struct {
 	ProductInteriorId int `description:"ID"`
 }
 
-// 添加
-func AddProductInterior(item *CygxProductInterior) (err error) {
-	o := orm.NewOrm()
-	_, err = o.Insert(item)
-	return
-}
-
-// 修改
-func UpdateProductInterior(item *CygxProductInterior) (err error) {
-	to := orm.NewOrm()
-	updateParams := make(map[string]interface{})
-	updateParams["PublishTime"] = item.PublishTime
-	updateParams["ModifyTime"] = item.ModifyTime
-	updateParams["ColumnName"] = item.ColumnName
-	updateParams["Title"] = item.Title
-	updateParams["Status"] = item.Status
-	updateParams["Body"] = item.Body
-	updateParams["IsCancel"] = item.IsCancel
-	updateParams["VisibleRange"] = item.VisibleRange
-	updateParams["Abstract"] = item.Abstract
-	updateParams["Department"] = item.Department
-	ptrStructOrTableName := "cygx_product_interior"
-	whereParam := map[string]interface{}{"product_interior_id": item.ProductInteriorId}
-	qs := to.QueryTable(ptrStructOrTableName)
-	for expr, exprV := range whereParam {
-		qs = qs.Filter(expr, exprV)
-	}
-	_, err = qs.Update(updateParams)
-	return
-}
-
 type GetCygxProductInteriorResp struct {
 	Paging *paging.PagingItem `description:"分页数据"`
 	List   []*CygxProductInteriorResp

+ 2 - 4
models/report_selection.go

@@ -170,10 +170,9 @@ func GetReportSelectionListHome(condition, tbdb string, pars []interface{}, star
 // 列表
 func GetReportSelectionlogListAll(articleId int) (items []*CygxReportSelectionLog, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT c.permission_name ,c.image_url,s.subject_name , l.*  ,l.company_label as label
+	sql := `SELECT s.subject_name , l.*  ,l.company_label as label
 			FROM
 			cygx_report_selection_log AS l
-			INNER JOIN chart_permission AS c ON c.chart_permission_id = l.chart_permission_id 
 			INNER JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = l.industrial_subject_id 
 			WHERE l.article_id = ? `
 	_, err = o.Raw(sql, articleId).QueryRows(&items)
@@ -183,10 +182,9 @@ func GetReportSelectionlogListAll(articleId int) (items []*CygxReportSelectionLo
 // 列表
 func GetReportSelectionlogSonListAll(articleId, chartPermissionId int) (items []*CygxReportSelectionLogDetail, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT c.permission_name , l.* ,l.company_label as label
+	sql := `SELECT  l.* ,l.company_label as label
 			FROM
 			cygx_report_selection_log AS l
-			INNER JOIN chart_permission AS c ON c.chart_permission_id = l.chart_permission_id 
 			LEFT JOIN cygx_industrial_subject AS s ON s.industrial_subject_id = l.industrial_subject_id 
 			WHERE l.article_id = ? AND l.chart_permission_id =?`
 	_, err = o.Raw(sql, articleId, chartPermissionId).QueryRows(&items)

+ 1 - 2
models/report_selection_chart_log.go

@@ -27,9 +27,8 @@ type AddCygxReportSelectionChartLog struct {
 
 func GetCygxReportSelectionChartLogRepList(articleId int) (items []*CygxReportSelectionChartLogRep, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT l.*,c.chart_permission_name
+	sql := `SELECT l.*
 			FROM cygx_report_selection_chart_log AS l
-			LEFT JOIN chart_permission as c  ON c.chart_permission_id = l.chart_permission_id
 			WHERE  1= 1 AND article_id=?  `
 	_, err = o.Raw(sql, articleId).QueryRows(&items)
 	return

+ 1 - 1
models/wx_user.go

@@ -54,7 +54,7 @@ type WxUser struct {
 
 // 添加用户信息
 func AddWxUser(item *WxUser) (lastId int64, err error) {
-	o := orm.NewOrm()
+	o := orm.NewOrmUsingDB("weekly_report")
 	lastId, err = o.Insert(item)
 	return
 }

+ 27 - 22
services/activity.go

@@ -172,23 +172,26 @@ func SendEmailFileToExpert(cont context.Context) (err error) {
 	defer func() {
 		if err != nil {
 			fmt.Println("err:", err)
-			go utils.SendAlarmMsg("预约外呼名单,会前1小时自动发送邮件给专家组失败"+msg, 2)
+			go utils.SendAlarmMsg("预约外呼名单,会前1小时自动发送邮件给专家组失败"+err.Error()+msg, 2)
 		}
 	}()
 	endDate := time.Now().Add(+time.Minute * 60).Format(utils.FormatDateTime)
-	total, err := models.GetCountActivityIdToSendFile(endDate)
-
+	total, e := models.GetCountActivityIdToSendFile(endDate)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCountActivityIdToSendFile" + e.Error())
+		return
+	}
 	if total == 0 {
 		fmt.Println("发送附件完成0")
 		return nil
 	}
-	if err != nil {
-		msg = "发送附件模版消息失败 Err:" + err.Error()
+
+	listActivity, e := models.GetActivityIdToSendFile(endDate)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetActivityIdToSendFile" + e.Error())
 		return
 	}
-	listActivity, err := models.GetActivityIdToSendFile(endDate)
-	if err != nil {
-		msg = "发送附件模版消息失败 Err:" + err.Error()
+	if len(listActivity) == 0 {
 		return
 	}
 	var activityIds []int
@@ -196,22 +199,23 @@ func SendEmailFileToExpert(cont context.Context) (err error) {
 		activityIds = append(activityIds, v.ActivityId)
 	}
 
-	//{
-	//	utils.SendAlarmMsg("预约外呼名单,会前1小时自动发送邮件给专家组 监控日志,监控使用无需处理,活动ID:"+fmt.Sprint(activityIds), 2)
-	//}
-
 	for _, v := range listActivity {
 		//time.Sleep(30 * time.Second) //延时30秒,避免邮件发送不成功
-		activityInfo, _ := models.GetAddActivityInfoById(v.ActivityId)
-		if activityInfo == nil {
-			msg = "活动不存在,Err:activityId:" + strconv.Itoa(v.ActivityId)
+		activityInfo, e := models.GetAddActivityInfoById(v.ActivityId)
+		if e != nil {
+			err = errors.New("GetAddActivityInfoById" + e.Error())
 			return
 		}
-		list, errFile := models.GetSignupExport(v.ActivityId)
-		if errFile != nil {
-			msg = "获取失败,Err:" + errFile.Error()
+		list, e := models.GetSignupExport(v.ActivityId)
+		if e != nil {
+			err = errors.New("GetSignupExport" + e.Error())
 			return
 		}
+		var companyIds []int
+		for _, vSin := range list {
+			companyIds = append(companyIds, vSin.CompanyId)
+		}
+		sellNameMap := GetSellNameMapByCompanyIds(companyIds)
 		//创建excel
 		dir, errFile := os.Executable()
 		exPath := filepath.Dir(dir)
@@ -265,8 +269,9 @@ func SendEmailFileToExpert(cont context.Context) (err error) {
 			cellD := row.AddCell()
 			cellD.Value = item.CompanyName
 			cellE := row.AddCell()
-			cellE.Value = item.SellerName
+			cellE.Value = sellNameMap[item.CompanyId]
 		}
+
 		errFile = xlsxFile.Save(downLoadnFilePath)
 		if errFile != nil {
 			msg = "保存文件失败Err:" + errFile.Error()
@@ -297,9 +302,9 @@ func SendEmailFileToExpert(cont context.Context) (err error) {
 			}
 		}
 		os.Remove(downLoadnFilePath)
-		err = models.UPdateActivityIdToSendFile(v.ActivityId)
-		if err != nil {
-			go utils.SendAlarmMsg("UPdateActivityIdToSendFile err"+msg, 2)
+		e = models.UPdateActivityIdToSendFile(v.ActivityId)
+		if e != nil {
+			go utils.SendAlarmMsg("UPdateActivityIdToSendFile err"+e.Error(), 2)
 		}
 
 		//sendResult := utils.SendEmailByHongze(title, content, touser, fileName, title+".xlsx")

+ 9 - 0
services/activity_special.go

@@ -1337,6 +1337,15 @@ func GetChartPermissionSpecialSurplusByCompany(companyId int) (userType int, tri
 			err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
 			return
 		}
+
+		PermissionNameMap, e := GetPermissionNameMap()
+		if e != nil {
+			err = errors.New("GetPermissionNameMap, Err: " + e.Error())
+			return
+		}
+		for k, v := range listTripBill {
+			listTripBill[k].ChartPermissionName = PermissionNameMap[v.ChartPermissionId]
+		}
 		// 获取继承点数
 		inheritList, e := models.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
 		if e != nil && e.Error() != utils.ErrNoRow() {

+ 29 - 0
services/company_permission.go

@@ -286,3 +286,32 @@ func GetUserHasPermissionSimple(user *models.WxUserItem) (hasPermission int, err
 	}
 	return
 }
+
+// GetPermissionNameMap 权限名称与权限ID的map
+func GetPermissionNameMap() (mapItem map[int]string, err error) {
+	list, e := models.GetChartPermissionListRai()
+	if e != nil {
+		err = e
+		return
+	}
+	mapPermissionName := make(map[int]string)
+	for _, v := range list {
+		mapPermissionName[v.ChartPermissionId] = v.PermissionName
+	}
+	mapItem = mapPermissionName
+	return
+}
+
+func GetPermissionNameIcoMap() (mapItem map[int]string, err error) {
+	list, e := models.GetChartPermissionListRai()
+	if e != nil {
+		err = e
+		return
+	}
+	mapPermissionName := make(map[int]string)
+	for _, v := range list {
+		mapPermissionName[v.ChartPermissionId] = v.ImageUrlM
+	}
+	mapItem = mapPermissionName
+	return
+}

+ 8 - 8
utils/email.go

@@ -13,7 +13,7 @@ var (
 	AlarmMsgUrl = "http://127.0.0.1:8606/api/alarm/send"
 )
 
-//发送邮件
+// 发送邮件
 func SendEmail(title, content string, touser string) bool {
 	if RunMode == "debug" {
 		return false
@@ -40,10 +40,10 @@ func SendEmail(title, content string, touser string) bool {
 	return true
 }
 
-//projectName-项目名称
-//runMode-运行模式
-//msgBody-消息内容
-//level:消息基本,1:提示消息,2:警告消息,3:严重错误信息,默认为1 提示消息
+// projectName-项目名称
+// runMode-运行模式
+// msgBody-消息内容
+// level:消息基本,1:提示消息,2:警告消息,3:严重错误信息,默认为1 提示消息
 func SendAlarmMsg(msgBody string, level int) {
 	params := make(map[string]interface{})
 	params["ProjectName"] = APPNAME
@@ -58,7 +58,7 @@ func SendAlarmMsg(msgBody string, level int) {
 	http.Post(AlarmMsgUrl, string(param))
 }
 
-//发送邮件
+// 发送邮件
 func SendEmailByHz(title, content string, touser string) (result bool, err error) {
 	//if RunMode == "debug" {
 	//	result = false
@@ -88,7 +88,7 @@ func SendEmailByHz(title, content string, touser string) (result bool, err error
 	return
 }
 
-//发送带有文件的邮件
+// 发送带有文件的邮件
 func SendEmailHaveFile(title, content string, fileName, touser string) bool {
 	var arr []string
 	sub := strings.Index(touser, ";")
@@ -113,7 +113,7 @@ func SendEmailHaveFile(title, content string, fileName, touser string) bool {
 	return true
 }
 
-//发送邮件
+// 发送邮件
 func SendEmailByHongze(title, content string, touser, attachPath, attachName string) bool {
 	var arr []string
 	sub := strings.Index(touser, ";")