Browse Source

Merge branch 'master' of http://8.136.199.33:3000/hongze/hongze_cygx into cygx_4.6

xingzai 3 years ago
parent
commit
708ae4d28e
8 changed files with 126 additions and 132 deletions
  1. 17 20
      controllers/activity.go
  2. 9 0
      controllers/article.go
  3. 1 1
      controllers/report.go
  4. 32 109
      services/activity.go
  5. 55 0
      services/article.go
  6. 5 0
      services/user.go
  7. 2 2
      utils/config.go
  8. 5 0
      utils/constants.go

+ 17 - 20
controllers/activity.go

@@ -2059,18 +2059,6 @@ func (this *ActivityCoAntroller) AskAdd() {
 		br.ErrMsg = "操作失败,Err:" + errInfo.Error()
 		return
 	}
-	//resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
-	//if activityInfo.ActivityTypeId == 1 && activityInfo.ChartPermissionId != 31 {
-	//	if time.Now().After(resultTime.Add(-time.Minute * 15)) {
-	//		br.Msg = "活动开始前15分钟内无法提交问题"
-	//		return
-	//	}
-	//} else {
-	//	if time.Now().After(resultTime.Add(-time.Minute * 60)) {
-	//		br.Msg = "活动开始前1小时内无法提交问题"
-	//		return
-	//	}
-	//}
 	companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
 	if err != nil {
 		br.Msg = "提交失败!"
@@ -2125,21 +2113,30 @@ func (this *ActivityCoAntroller) AskAdd() {
 		if activityInfo.ChartPermissionId == 31 {
 			sendMobile = utils.ActSendMsgMobile
 		}
+
+		//获取销售信息
+		sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "提交失败"
+			br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
+			return
+		}
+		//给研究员发送消息
 		if sendMobile != "" {
 			openIpItem, _ := models.GetUserRecordByMobile(4, sendMobile)
 			if openIpItem != nil && openIpItem.OpenId != "" {
-				//获取销售信息
-				sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
-				if err != nil && err.Error() != utils.ErrNoRow() {
-					br.Msg = "提交失败"
-					br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
-					return
-				}
 				if sellerItem != nil {
-					services.SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RoleName+")", time.Now().Format(utils.FormatDateTime), req.Content, activityInfo.ActivityName, openIpItem.OpenId, activityInfo.ActivityId)
+					services.SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RealName+")", time.Now().Format(utils.FormatDateTime), req.Content, activityInfo.ActivityName, openIpItem.OpenId, activityInfo.ActivityId)
 				}
 			}
 		}
+		// 给所属销售发送消息
+		if sellerItem != nil {
+			openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
+			if openIpItem != nil && openIpItem.OpenId != "" {
+				services.SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RealName+")", time.Now().Format(utils.FormatDateTime), req.Content, activityInfo.ActivityName, openIpItem.OpenId, activityInfo.ActivityId)
+			}
+		}
 	}
 
 	br.Ret = 200

+ 9 - 0
controllers/article.go

@@ -689,6 +689,15 @@ func (this *ArticleController) AddStopTime() {
 					if !utils.Rc.IsExist(key) || outType != 2 {
 						//新增浏览记录
 						go models.AddCygxArticleViewRecordNewpv(record)
+						recordRedis := new(services.ReportViewRecord)
+						recordRedis.UserId = user.UserId
+						recordRedis.ReportId = articleId
+						recordRedis.Mobile = user.Mobile
+						recordRedis.Email = user.Email
+						recordRedis.RealName = user.RealName
+						recordRedis.CompanyName = user.CompanyName
+						recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
+						go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
 					} else {
 						go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
 					}

+ 1 - 1
controllers/report.go

@@ -1717,7 +1717,7 @@ func (this *ReportController) RoadshowDetail() {
 			return
 		}
 		detail.Body = html.UnescapeString(detail.Body)
-		detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
+		detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
 		detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
 		detail.VideoPlaySeconds = utils.Mp3Time(detail.VideoPlaySeconds)
 		if detail.ReportLink == "0" {

+ 32 - 109
services/activity.go

@@ -452,15 +452,23 @@ func SendEmailFileForAskMsgResearch(cont context.Context) (err error) {
 			if err != nil && err.Error() != utils.ErrNoRow() {
 				return err
 			}
-			openIpItem, _ := models.GetUserRecordByMobile(4, utils.ActSendMsgMobile)
-			if openIpItem != nil && openIpItem.OpenId != "" {
-				//获取销售信息
-				sellerItem, err := models.GetSellerByCompanyIdCheckFicc(v2.CompanyId, 2)
-				if err != nil && err.Error() != utils.ErrNoRow() {
-					return err
+			//获取销售信息
+			sellerItem, err := models.GetSellerByCompanyIdCheckFicc(v2.CompanyId, 2)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				return err
+			}
+			//给研究员推送消息
+			if sellerItem != nil {
+				openIpItem, _ := models.GetUserRecordByMobile(4, utils.ActSendMsgMobile)
+				if openIpItem != nil && openIpItem.OpenId != "" {
+					SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RealName+")", v2.CreateTime, v2.Content, activityInfo.ActivityName, openIpItem.OpenId, activityInfo.ActivityId)
 				}
-				if sellerItem != nil {
-					SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RoleName+")", time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem.OpenId, activityInfo.ActivityId)
+			}
+			//给所属销售推送消息
+			if sellerItem != nil {
+				openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
+				if openIpItem != nil && openIpItem.OpenId != "" {
+					SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RealName+")", v2.CreateTime, v2.Content, activityInfo.ActivityName, openIpItem.OpenId, activityInfo.ActivityId)
 				}
 			}
 		}
@@ -507,99 +515,6 @@ func SendEmailFileForAskMsg(cont context.Context) (err error) {
 		msg = "获取失败,Err:" + errEmail.Error()
 		return
 	}
-	//for _, v := range listActivity {
-	//	activityInfo, _ := models.GetAddActivityInfoById(v.ActivityId)
-	//	if activityInfo == nil {
-	//		msg = "活动不存在,Err:activityId:" + strconv.Itoa(v.ActivityId)
-	//		return
-	//	}
-	//	list, errFile := models.GetActivityMsgExport(v.ActivityId)
-	//	if errFile != nil {
-	//		msg = "获取失败,Err:" + errFile.Error()
-	//		return
-	//	}
-	//	for _, v := range listEmail {
-	//		if strings.Index(activityInfo.Host, v.Name) > 0 {
-	//			touser += v.Email + ";"
-	//		}
-	//	}
-	//	if touser == "" {
-	//		msg = "没有对应的邮箱"
-	//		return
-	//	}
-	//	if utils.RunMode == "release" {
-	//		touser += "tshen@hzinsights.com;cxzhang@hzinsights.com"
-	//	} else {
-	//		touser = "tshen@hzinsights.com;cxzhang@hzinsights.com"
-	//	}
-	//
-	//	//创建excel
-	//	dir, errFile := os.Executable()
-	//	exPath := filepath.Dir(dir)
-	//	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + utils.GetRandDigit(5) + ".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, errFile := xlsxFile.AddSheet("外呼名单")
-	//	if errFile != nil {
-	//		msg = "新增Sheet失败,Err:" + errFile.Error()
-	//		return
-	//	}
-	//	//设置宽度
-	//	_ = sheet.SetColWidth(1, 1, 30)
-	//	_ = sheet.SetColWidth(2, 2, 60)
-	//	//标头
-	//	rowTitle := sheet.AddRow()
-	//	cellA := rowTitle.AddCell()
-	//	cellA.Value = "姓名"
-	//	cellB := rowTitle.AddCell()
-	//	cellB.Value = "公司名称"
-	//	cellC := rowTitle.AddCell()
-	//	cellC.Value = "问题"
-	//	cellD := rowTitle.AddCell()
-	//	cellD.Value = "提交时间"
-	//	for _, item := range list {
-	//		row := sheet.AddRow()
-	//		cellA := row.AddCell()
-	//		cellA.Value = item.RealName
-	//		cellB := row.AddCell()
-	//		cellB.Value = item.CompanyName
-	//		cellC := row.AddCell()
-	//		cellC.Value = item.Content
-	//		cellD := row.AddCell()
-	//		cellD.Value = item.CreateTime
-	//	}
-	//	errFile = xlsxFile.Save(downLoadnFilePath)
-	//	if errFile != nil {
-	//		msg = "保存文件失败Err:" + errFile.Error()
-	//		return
-	//	}
-	//	title := activityInfo.ActivityName + "-活动带问"
-	//	content := "活动带问详情"
-	//	fileName := downLoadnFilePath
-	//	sendResult := utils.SendEmailByHongze(title, content, touser, fileName, title+".xlsx")
-	//	if sendResult {
-	//		errFile = models.UPdateActivityMsgToSendFile(v.ActivityId)
-	//		if errFile != nil {
-	//			msg = "获取失败,Err:" + errFile.Error()
-	//			return
-	//		}
-	//		os.Remove(downLoadnFilePath)
-	//	} else {
-	//		go utils.SendEmail("发送附件模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format(utils.FormatDateTime), msg+";Err:"+activityInfo.ActivityName, utils.EmailSendToUsers)
-	//		utils.FileLog.Info("发送附件模版消息失败,Err:%s", activityInfo.ActivityName)
-	//	}
-	//}
 
 	for _, v := range listActivity {
 		activityInfo, _ := models.GetAddActivityInfoById(v.ActivityId)
@@ -624,15 +539,23 @@ func SendEmailFileForAskMsg(cont context.Context) (err error) {
 					sendMobile = vEmail.Mobile
 				}
 			}
-			openIpItem, _ := models.GetUserRecordByMobile(4, sendMobile)
-			if openIpItem != nil && openIpItem.OpenId != "" {
-				//获取销售信息
-				sellerItem, err := models.GetSellerByCompanyIdCheckFicc(v2.CompanyId, 2)
-				if err != nil && err.Error() != utils.ErrNoRow() {
-					return err
+			//获取销售信息
+			sellerItem, err := models.GetSellerByCompanyIdCheckFicc(v2.CompanyId, 2)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				return err
+			}
+			//给研究员推送模板消息
+			if sellerItem != nil {
+				openIpItem, _ := models.GetUserRecordByMobile(4, sendMobile)
+				if openIpItem != nil && openIpItem.OpenId != "" {
+					SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RealName+")", v2.CreateTime, v2.Content, activityInfo.ActivityName, openIpItem.OpenId, activityInfo.ActivityId)
 				}
-				if sellerItem != nil {
-					SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RoleName+")", time.Now().Format(utils.FormatDateTime), v2.Content, activityInfo.ActivityName, openIpItem.OpenId, activityInfo.ActivityId)
+			}
+			//给销售推送模板消息
+			if sellerItem != nil {
+				openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
+				if openIpItem != nil && openIpItem.OpenId != "" {
+					SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RealName+")", v2.CreateTime, v2.Content, activityInfo.ActivityName, openIpItem.OpenId, activityInfo.ActivityId)
 				}
 			}
 		}

+ 55 - 0
services/article.go

@@ -56,6 +56,18 @@ func GetReportContentTextSub(content string) (contentSub string, err error) {
 	return
 }
 
+func GetReportContentTextSubNew(content string) (contentSub string, err error) {
+	content = html.UnescapeString(content)
+	doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
+	docText := doc.Text()
+	bodyRune := []rune(docText)
+	bodyRuneLen := len(bodyRune)
+	body := string(bodyRune[:bodyRuneLen])
+	contentSub = body
+	contentSub = strings.Replace(body, "Powered by Froala Editor", "", -1)
+	return
+}
+
 //解析文章内容
 func GetArticleAll() {
 	var err error
@@ -726,3 +738,46 @@ func StatisticalReport() {
 	return
 
 }
+
+// UserViewRedisData 阅读数据
+type UserViewRedisData struct {
+	Mobile      string `json:"mobile"`
+	Email       string `json:"email"`
+	RealName    string `json:"real_name"`
+	CompanyName string `json:"company_name"`
+	ViewTime    string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
+	ProductId   int    `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
+	CompanyId   int    `json:"company_id" description:"客户id"`
+}
+
+type ReportViewRecord struct {
+	Id          int       `orm:"column(id);pk"`
+	UserId      int       `description:"用户id"`
+	ReportId    int       `description:"报告id"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	RealName    string    `description:"用户实际姓名"`
+	CompanyName string    `description:"公司名称"`
+	CreateTime  time.Time `description:"创建时间"`
+}
+
+// PushViewRecordNewRedisData 阅读数据加入到redis
+func PushViewRecordNewRedisData(reportViewRecord *ReportViewRecord, companyId int) bool {
+	data := &UserViewRedisData{
+		Mobile:      reportViewRecord.Mobile,
+		Email:       reportViewRecord.Email,
+		RealName:    reportViewRecord.RealName,
+		CompanyName: reportViewRecord.CompanyName,
+		ViewTime:    reportViewRecord.CreateTime.Format(utils.FormatDateTime),
+		ProductId:   2,
+		CompanyId:   companyId,
+	}
+	if utils.Re == nil {
+		err := utils.Rc.LPush(utils.CACHE_KEY_USER_VIEW, data)
+		if err != nil {
+			fmt.Println("PushViewRecordNewRedisData LPush Err:" + err.Error())
+		}
+		return true
+	}
+	return false
+}

+ 5 - 0
services/user.go

@@ -613,6 +613,7 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 	if mobileStr == "" {
 		mobileStr = "1"
 	}
+	mobileStr = strings.Replace(mobileStr, " ", "", -1)
 	//手机号新增
 	fieldStr = ` u.mobile,u.country_code,u.real_name,c.company_name,u.company_id,cp.seller_name,cp.status,`
 	condition = `  AND cp.status IN ( '正式', '试用' ) AND u.mobile IN (` + mobileStr + `) `
@@ -626,6 +627,7 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 	if outboundMobileStr == "" {
 		outboundMobileStr = "1"
 	}
+	outboundMobileStr = strings.Replace(outboundMobileStr, " ", "", -1)
 	fieldStr = ` u.outbound_mobile as mobile,u.outbound_country_code as country_code,u.real_name,c.company_name,u.company_id,cp.status,`
 	condition = `  AND cp.status IN ( '正式', '试用' ) AND u.outbound_mobile IN (` + outboundMobileStr + `) `
 	listOutboundMobile, err := models.GetFormalUserWhiteList(fieldStr, condition)
@@ -1161,6 +1163,9 @@ func SendEmailAllUserWithCompany() (err error) {
 			if item.CountryCode != "" && item.Mobile != "" {
 				cellC.Value = "+" + item.CountryCode
 			}
+			if item.CountryCode == "" && item.Mobile != "" {
+				cellC.Value = "+86"
+			}
 			cellD := row.AddCell()
 			cellD.Value = ""
 			cellE := row.AddCell()

+ 2 - 2
utils/config.go

@@ -121,14 +121,14 @@ func init() {
 		WxPublicAppId = "wx4a844c734d8c8e56"
 		WxPublicAppSecret = "26c586e7ccb3c575433f0f37797b3eeb"
 		WxPublicId = "gh_b67e0049fb8c"
-		IndexName = "cygx_article_v0125"
+		IndexName = "cygx_article_v0225"
 
 		//接收附件邮箱
 		EmailTechnology = "mlluo@hzinsights.com;jxu@hzinsights.com;tshen@hzinsights.com;cxzhang@hzinsights.com;jhwang@hzinsights.com"    //科技行业专家邮箱
 		EmailMedicine = "xlzheng@hzinsights.com;tshen@hzinsights.com;cxzhang@hzinsights.com;jhwang@hzinsights.com"                       //医药行业专家邮箱
 		EmailConsumption = "yrhuang@hzinsights.com;tshen@hzinsights.com;cxzhang@hzinsights.com;jhwang@hzinsights.com;jxu@hzinsights.com" //消费行业专家邮箱
 		EmailZhizao = "xfma@hzinsights.com;agne@hzinsights.com;tshen@hzinsights.com;cxzhang@hzinsights.com;jhwang@hzinsights.com"        //智造行业专家邮箱
-		EmailStrategy = "xfma@hzinsights.com;tshen@hzinsights.com;cxzhang@hzinsights.com;jhwang@hzinsights.com"                          //策略行业专家邮箱
+		EmailStrategy = "experts@hzinsights.com;tshen@hzinsights.com;cxzhang@hzinsights.com;jhwang@hzinsights.com"                       //策略行业专家邮箱
 		EmailExpert = "experts@hzinsights.com;tshen@hzinsights.com;cxzhang@hzinsights.com;jhwang@hzinsights.com"                         //研选行业专家邮箱
 		EmaiWhiteUserList = "tshen@hzinsights.com;cxzhang@hzinsights.com;yyli@hzinsights.com"                                            //白名单邮箱
 		WxMsgTemplateIdAskMsg = "PaoDanHGlt1kFw5q-4_ipJSwO3FyZpxSSNg4rwB7YCk"

+ 5 - 0
utils/constants.go

@@ -55,3 +55,8 @@ var (
 	AccessKeyId     string = "LTAIFMZYQhS2BTvW"
 	AccessKeySecret string = "12kk1ptCHoGWedhBnKRVW5hRJzq9Fq"
 )
+
+//缓存key
+const (
+	CACHE_KEY_USER_VIEW = "user_view_record" //用户阅读数据
+)