Jelajahi Sumber

Merge branch 'feature/v4.9.33' of https://jygit.jydev.jianyu360.cn/qmx/jy into feature/v4.9.33

wangchuanjin 1 tahun lalu
induk
melakukan
d5e9d154a6
1 mengubah file dengan 220 tambahan dan 173 penghapusan
  1. 220 173
      src/jfw/modules/subscribepay/src/util/pdfSendEmail.go

+ 220 - 173
src/jfw/modules/subscribepay/src/util/pdfSendEmail.go

@@ -1,50 +1,50 @@
 package util
 
 import (
-	qutil "app.yhyue.com/moapp/jybase/common"
-	"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
-	"encoding/json"
-	"fmt"
-	. "jy/src/jfw/modules/subscribepay/src/config"
-	"log"
-	"strings"
-	"time"
+    qutil "app.yhyue.com/moapp/jybase/common"
+    "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
+    "encoding/json"
+    "fmt"
+    . "jy/src/jfw/modules/subscribepay/src/config"
+    "log"
+    "strings"
+    "time"
 )
 
 type MarketAnalysisEntity struct {
-	FormatParam AnalysisRequestFormat
+    FormatParam AnalysisRequestFormat
 }
 
 // AnalysisRequestFormat 格式化后参数
 type AnalysisRequestFormat struct {
-	KeysItems    []keyWordGroup
-	Area, City   []string //省份城市
-	STime, ETime int64    //开始结束时间
-	Industry     []string //行业
-	BuyerClass   []string //采购单位类型
-	Buyer        string   //采购单位
-	Winner       string   //中标单位
-	Sort         int      //排序:默认0:成交时间倒序;1:项目金额倒序
-	PageSize     int      //默认每页10条
-	PageNum      int      //默认当前第一页
+    KeysItems    []keyWordGroup
+    Area, City   []string //省份城市
+    STime, ETime int64    //开始结束时间
+    Industry     []string //行业
+    BuyerClass   []string //采购单位类型
+    Buyer        string   //采购单位
+    Winner       string   //中标单位
+    Sort         int      //排序:默认0:成交时间倒序;1:项目金额倒序
+    PageSize     int      //默认每页10条
+    PageNum      int      //默认当前第一页
 }
 
 // keyWordGroup 订阅词结构体
 type keyWordGroup struct {
-	A_Key      []viewKeyWord `json:"a_key"`
-	ItemName   string        `json:"s_item"`
-	UpdateTime int64         `json:"updatetime"`
+    A_Key      []viewKeyWord `json:"a_key"`
+    ItemName   string        `json:"s_item"`
+    UpdateTime int64         `json:"updatetime"`
 }
 
 type viewKeyWord struct {
-	Keyword  []string `json:"key"`       //关键词
-	Appended []string `json:"appendkey"` //附加词
-	Exclude  []string `json:"notkey"`    //排除词
-	MatchWay int      `json:"matchway"`  //匹配模式
+    Keyword  []string `json:"key"`       //关键词
+    Appended []string `json:"appendkey"` //附加词
+    Exclude  []string `json:"notkey"`    //排除词
+    MatchWay int      `json:"matchway"`  //匹配模式
 }
 
 var (
-	PdfEmailContent = `<div style="width:1200px;background-color:#F5F4FA;padding:15px;">
+    AnalyzePdfEmailContent = `<div style="width:1200px;background-color:#F5F4FA;padding:15px;">
   <div style="padding:5px 50px 50px 50px;background-color:#fff;width:1000px;margin:auto;border-top: 5px solid #2cb7ca;">
     <img src="https://www.jianyu360.com/images/swordfish/sf_01.png" style="display:block;width:150px;margin: 10px auto 30px auto;">
     <div style="padding-bottom: 30px;margin-bottom: 30px;border-bottom: 1px dashed #ddd;">尊敬的剑鱼标讯用户:
@@ -55,167 +55,214 @@ var (
       <div style="height: 35px; line-height: 35px; background: rgb(245, 245, 251); font-size: 14px; color: rgb(29, 29, 29); padding-left: 30px;">报告详情</div>
       <div style="padding: 18px 0px; overflow: hidden;">
         <div style="box-sizing: border-box; padding-left: 30px; float: left; width: %s;">
-            %s
           <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">分析内容:%s</p>
           <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">匹配方式:%s</p>
           <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">成交时间:%s</p>
           <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">项目地区:%s</p>
           <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">行业:%s</p>
-            %s
+          <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">采购单位类型:%s</p>
+        </div>
+      </div>
+    </div>
+  </div>
+</div>`
+    BuyerPdfEmailContent = `<div style="width:1200px;background-color:#F5F4FA;padding:15px;">
+  <div style="padding:5px 50px 50px 50px;background-color:#fff;width:1000px;margin:auto;border-top: 5px solid #2cb7ca;">
+    <img src="https://www.jianyu360.com/images/swordfish/sf_01.png" style="display:block;width:150px;margin: 10px auto 30px auto;">
+    <div style="padding-bottom: 30px;margin-bottom: 30px;border-bottom: 1px dashed #ddd;">尊敬的剑鱼标讯用户:
+      <div style="font-size:14px;text-indent: 32px;margin-top: 5px;">您好,感谢您购买剑鱼标讯%s,您的报告已发送到您的邮箱,请查收!如有问题,可拨打客服热线:400-108-6670。</div>
+    </div>
+    <a href="%s" download="%s" style="margin: 0 auto;display: block;width: 150px;height: 30px;line-height: 30px;background: #2cb7ca;text-decoration: none;text-align: center;color: #fff;border-radius: 5px;margin-bottom: 25px;">%s下载</a>
+    <div style="box-sizing: border-box; border-width: 2px 1px 1px; border-style: solid; border-color: rgb(204, 204, 204); margin-bottom: 20px; font-family: 'Microsoft YaHei'; orphans: 2; widows: 2;">
+      <div style="height: 35px; line-height: 35px; background: rgb(245, 245, 251); font-size: 14px; color: rgb(29, 29, 29); padding-left: 30px;">报告详情</div>
+      <div style="padding: 18px 0px; overflow: hidden;">
+        <div style="box-sizing: border-box; padding-left: 30px; float: left; width: %s;">
+          <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">目标业主:%s</p>
+          <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">成交时间:%s</p>
+          <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">关键词:%s</p>
+          <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">搜索范围:%s</p>
+          <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">项目地区:%s</p>
+          <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">行业:%s</p>
+        </div>
+      </div>
+    </div>
+  </div>
+</div>`
+    EndPdfEmailContent = `<div style="width:1200px;background-color:#F5F4FA;padding:15px;">
+  <div style="padding:5px 50px 50px 50px;background-color:#fff;width:1000px;margin:auto;border-top: 5px solid #2cb7ca;">
+    <img src="https://www.jianyu360.com/images/swordfish/sf_01.png" style="display:block;width:150px;margin: 10px auto 30px auto;">
+    <div style="padding-bottom: 30px;margin-bottom: 30px;border-bottom: 1px dashed #ddd;">尊敬的剑鱼标讯用户:
+      <div style="font-size:14px;text-indent: 32px;margin-top: 5px;">您好,感谢您购买剑鱼标讯%s,您的报告已发送到您的邮箱,请查收!如有问题,可拨打客服热线:400-108-6670。</div>
+    </div>
+    <a href="%s" download="%s" style="margin: 0 auto;display: block;width: 150px;height: 30px;line-height: 30px;background: #2cb7ca;text-decoration: none;text-align: center;color: #fff;border-radius: 5px;margin-bottom: 25px;">%s下载</a>
+    <div style="box-sizing: border-box; border-width: 2px 1px 1px; border-style: solid; border-color: rgb(204, 204, 204); margin-bottom: 20px; font-family: 'Microsoft YaHei'; orphans: 2; widows: 2;">
+      <div style="height: 35px; line-height: 35px; background: rgb(245, 245, 251); font-size: 14px; color: rgb(29, 29, 29); padding-left: 30px;">报告详情</div>
+      <div style="padding: 18px 0px; overflow: hidden;">
+        <div style="box-sizing: border-box; padding-left: 30px; float: left; width: %s;">
+          <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">目标企业:%s</p>
+          <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">成交时间:%s</p>
+          <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">关键词:%s</p>
+          <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">搜索范围:%s</p>
+          <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">项目地区:%s</p>
+          <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">行业:%s</p>
+          <p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">采购单位类型:%s</p>
         </div>
       </div>
     </div>
   </div>
 </div>`
-	entBuyerName = `<p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">目标企业:%s</p>`
-	buyerStr     = `<p style="margin: 0px 0px 1px; font-size: 14px; color: rgb(29, 29, 29);">采购单位类型:%s</p>`
 )
 
 // GetPdfDetail 生成pdf文件程序查询接口
 func PdfSendEmail(rData map[string]interface{}) error {
-	sEmail := qutil.InterfaceToStr(rData["s_email"])
-	pdfUrl := qutil.InterfaceToStr(rData["s_pdfUrl"])
-	sType := qutil.InterfaceToStr(rData["type"])
-	if !jy.IsEmail(sEmail) {
-		return fmt.Errorf("邮箱格式不正确")
-	}
-	if pdfUrl == "" {
-		return fmt.Errorf("无效下载地址")
-	}
-	pdfUrl = fmt.Sprintf("%s%s", Config.WebDomain, pdfUrl)
-	var (
-		keyWords                                                                             []string
-		targetEnt, packageName, matchingMode, rangeTime, area, industry, buyerClass, entName string
-	)
-	switch sType {
-	case "3":
-		packageName = "市场分析定制报告"
-		//格式化订阅词
-		var (
-			mae MarketAnalysisEntity
-		)
-		if err := json.Unmarshal([]byte(qutil.InterfaceToStr(rData["s_keysItems"])), &mae.FormatParam.KeysItems); err == nil {
-			for _, item := range mae.FormatParam.KeysItems {
-				var keyGroup []string
-				for _, word := range item.A_Key {
-					matchWayStr := "(精准)"
-					if word.MatchWay == 1 {
-						matchWayStr = "(模糊)"
-					}
-					keyGroup = append(keyGroup, word.Keyword...)
-					keyGroup = append(keyGroup, word.Appended...)
-					keyGroup = append(keyGroup, matchWayStr)
-				}
-				keyWords = append(keyWords, strings.Join(keyGroup, " "))
-			}
-		}
-		matchingMode = qutil.If(qutil.InterfaceToStr(rData["s_matchingMode"]) == "title", "【按标题匹配】", "【按全文匹配】").(string)
-		sRangeTime := strings.Split(qutil.InterfaceToStr(rData["s_rangeTime"]), "-")
-		var (
-			sTime, eTime string
-		)
-		if sRangeTime[0] != "" && sRangeTime[0] != "0" {
-			sTime = time.Unix(qutil.Int64All(sRangeTime[0]), 0).Format("2006-01-02")
-		}
-		if sRangeTime[1] != "" && sRangeTime[1] != "0" {
-			eTime = time.Unix(qutil.Int64All(sRangeTime[1]), 0).Format("2006-01-02")
-		}
-		rangeTime = fmt.Sprintf("%s至%s", sTime, eTime)
-		if areaStr := strings.TrimSpace(qutil.InterfaceToStr(rData["s_area"])); areaStr != "" {
-			imap := map[string][]string{}
-			if err := json.Unmarshal([]byte(qutil.InterfaceToStr(rData["s_area"])), &imap); err == nil {
-				var areas []string
-				for name, v := range imap {
-					if len(v) == 0 {
-						areas = append(areas, name)
-					} else {
-						areas = append(areas, fmt.Sprintf("%s:%s", name, strings.Join(v, ",")))
-					}
-				}
-				area = strings.Join(areas, ",")
-			}
-		}
-		if area == "" {
-			area = "全国"
-		}
-		sIndustry, _ := rData["s_industry"].(string)
-		industryMap := qutil.ObjToMap(sIndustry)
+    sEmail := qutil.InterfaceToStr(rData["s_email"])
+    pdfUrl := qutil.InterfaceToStr(rData["s_pdfUrl"])
+    sType := qutil.InterfaceToStr(rData["type"])
+    if !jy.IsEmail(sEmail) {
+        return fmt.Errorf("邮箱格式不正确")
+    }
+    if pdfUrl == "" {
+        return fmt.Errorf("无效下载地址")
+    }
+    pdfUrl = fmt.Sprintf("%s%s", Config.WebDomain, pdfUrl)
+    var (
+        keyWords                                                                               []string
+        mailContent, packageName, matchingMode, rangeTime, area, industry, buyerClass, entName string
+    )
+    switch sType {
+    case "3":
+        packageName = "市场分析定制报告"
+        //格式化订阅词
+        var (
+            mae MarketAnalysisEntity
+        )
+        if err := json.Unmarshal([]byte(qutil.InterfaceToStr(rData["s_keysItems"])), &mae.FormatParam.KeysItems); err == nil {
+            for _, item := range mae.FormatParam.KeysItems {
+                var keyGroup []string
+                for _, word := range item.A_Key {
+                    matchWayStr := "(精准)"
+                    if word.MatchWay == 1 {
+                        matchWayStr = "(模糊)"
+                    }
+                    keyGroup = append(keyGroup, word.Keyword...)
+                    keyGroup = append(keyGroup, word.Appended...)
+                    keyGroup = append(keyGroup, matchWayStr)
+                }
+                keyWords = append(keyWords, strings.Join(keyGroup, " "))
+            }
+        }
+        if keyWords == nil {
+            keyWords = append(keyWords, "-")
+        }
+        matchingMode = qutil.If(qutil.InterfaceToStr(rData["s_matchingMode"]) == "title", "【按标题匹配】", "【按全文匹配】").(string)
+        sRangeTime := strings.Split(qutil.InterfaceToStr(rData["s_rangeTime"]), "-")
+        var (
+            sTime, eTime string
+        )
+        if sRangeTime[0] != "" && sRangeTime[0] != "0" {
+            sTime = time.Unix(qutil.Int64All(sRangeTime[0]), 0).Format("2006-01-02")
+        }
+        if sRangeTime[1] != "" && sRangeTime[1] != "0" {
+            eTime = time.Unix(qutil.Int64All(sRangeTime[1]), 0).Format("2006-01-02")
+        }
+        rangeTime = fmt.Sprintf("%s至%s", sTime, eTime)
+        if areaStr := strings.TrimSpace(qutil.InterfaceToStr(rData["s_area"])); areaStr != "" {
+            imap := map[string][]string{}
+            if err := json.Unmarshal([]byte(qutil.InterfaceToStr(rData["s_area"])), &imap); err == nil {
+                var areas []string
+                for name, v := range imap {
+                    if len(v) == 0 {
+                        areas = append(areas, name)
+                    } else {
+                        areas = append(areas, fmt.Sprintf("%s:%s", name, strings.Join(v, ",")))
+                    }
+                }
+                area = strings.Join(areas, ",")
+            }
+        }
+        if area == "" {
+            area = "全国"
+        }
+        sIndustry, _ := rData["s_industry"].(string)
+        industryMap := qutil.ObjToMap(sIndustry)
 
-		if industryMap == nil {
-			industry = "全行业"
-		} else {
-			var industryArr []string
-			for key := range *industryMap {
-				//is, _ := i.([]interface{})
-				industryArr = append(industryArr, key)
-			}
-			industry = strings.Join(industryArr, ",")
-		}
-		if industry == "" {
-			industry = "全行业"
-		}
-		sBuyerClass, _ := rData["s_buyerClass"].(string)
-		if sBuyerClass == "" {
-			sBuyerClass = "全部"
-		}
-		buyerClass = fmt.Sprintf(buyerStr, sBuyerClass)
-	case "2", "1":
-		entName = qutil.InterfaceToStr(rData["entName"])
-		targetEnt = fmt.Sprintf(entBuyerName, entName)
-		packageName = "业主采购分析报告"
-		match, _ := rData["match"].(string)
-		matching := "(模糊)"
-		if qutil.InterfaceToStr(rData["exactMatch"]) == "1" {
-			matching = "(精准)"
-		}
-		if match != "" {
-			keyWords = append(keyWords, fmt.Sprintf("%s %s", match, matching))
-		}
+        if industryMap == nil {
+            industry = "全行业"
+        } else {
+            var industryArr []string
+            for key := range *industryMap {
+                //is, _ := i.([]interface{})
+                industryArr = append(industryArr, key)
+            }
+            industry = strings.Join(industryArr, ",")
+        }
+        if industry == "" {
+            industry = "全行业"
+        }
+        sBuyerClass, _ := rData["s_buyerClass"].(string)
+        if sBuyerClass == "" {
+            sBuyerClass = "全部"
+        }
+        mailContent = fmt.Sprintf(AnalyzePdfEmailContent, packageName, pdfUrl,
+            fmt.Sprintf("剑鱼标讯-%s-%s.pdf", packageName, time.Unix(qutil.Int64All(rData["l_createTime"]), 0).Format("20060102")),
+            packageName, `97%`, strings.Join(keyWords, ","), matchingMode, rangeTime, area, industry, buyerClass)
+    case "2", "1":
+        entName = qutil.InterfaceToStr(rData["entName"])
+        packageName = "业主采购分析报告"
+        match, _ := rData["match"].(string)
+        matching := "(模糊)"
+        if qutil.InterfaceToStr(rData["exactMatch"]) == "1" {
+            matching = "(精准)"
+        }
+        if match != "" {
+            keyWords = append(keyWords, fmt.Sprintf("%s %s", match, matching))
+        } else {
+            keyWords = append(keyWords, "-")
+        }
 
-		matchRange, _ := rData["matchRange"].(string)
-		var matchingModes []string
-		if strings.Contains(matchRange, "purchasing") {
-			matchingModes = append(matchingModes, "项目名称/标的物")
-		}
-		if strings.Contains(matchRange, "agency") {
-			matchingModes = append(matchingModes, "招标代理机构")
-		}
-		if strings.Contains(matchRange, "winner") {
-			matchingModes = append(matchingModes, "中标企业")
-		}
-		if strings.Contains(matchRange, "buyer") {
-			matchingModes = append(matchingModes, "采购单位")
-		}
-		matchingMode = strings.Join(matchingModes, ",")
-		timeRange, _ := rData["timeRange"].(string)
-		rangeTime = strings.ReplaceAll(timeRange, "_", "至")
-		area, _ = rData["area"].(string)
-		if area == "" {
-			area = "全国"
-		}
-		industry, _ = rData["scopeClass"].(string)
-		if industry == "" {
-			industry = "全行业"
-		}
+        matchRange, _ := rData["matchRange"].(string)
+        var matchingModes []string
+        if strings.Contains(matchRange, "purchasing") {
+            matchingModes = append(matchingModes, "项目名称/标的物")
+        }
+        if strings.Contains(matchRange, "agency") {
+            matchingModes = append(matchingModes, "招标代理机构")
+        }
+        if strings.Contains(matchRange, "winner") {
+            matchingModes = append(matchingModes, "中标企业")
+        }
+        if strings.Contains(matchRange, "buyer") {
+            matchingModes = append(matchingModes, "采购单位")
+        }
+        matchingMode = strings.Join(matchingModes, ",")
+        timeRange, _ := rData["timeRange"].(string)
+        rangeTime = strings.ReplaceAll(timeRange, "_", "至")
+        area, _ = rData["area"].(string)
+        if area == "" {
+            area = "全国"
+        }
+        industry, _ = rData["scopeClass"].(string)
+        if industry == "" {
+            industry = "全行业"
+        }
 
-		if sType == "1" { //中标企业分析有采购单位类型筛选
-			packageName = "企业中标分析报告"
-			sBuyerClass, _ := rData["s_buyerClass"].(string)
-			if sBuyerClass == "" {
-				sBuyerClass = "全部"
-			}
-			buyerClass = fmt.Sprintf(buyerStr, sBuyerClass)
-		}
-	}
-	if keyWords == nil {
-		keyWords = append(keyWords, "-")
-	}
-	//拼接正文
-	mailContent := fmt.Sprintf(PdfEmailContent, packageName, pdfUrl,
-		fmt.Sprintf("剑鱼标讯-%s-%s.pdf", packageName, time.Unix(qutil.Int64All(rData["l_createTime"]), 0).Format("20060102")),
-		packageName, `97%`, targetEnt, strings.Join(keyWords, ","), matchingMode, rangeTime, area, industry, buyerClass)
-	if SendRetryMail(3, sEmail, qutil.If(entName != "", fmt.Sprintf("%s(%s)", packageName, entName), packageName).(string), mailContent, "", nil, GmailAuth) {
-		log.Printf("PdfSendEmail SendMailToPayUser %s 邮件%s发送成功!", packageName, sEmail)
-	}
-	return nil
+        if sType == "1" { //中标企业分析有采购单位类型筛选
+            packageName = "企业中标分析报告"
+            sBuyerClass, _ := rData["s_buyerClass"].(string)
+            if sBuyerClass == "" {
+                sBuyerClass = "全部"
+            }
+            mailContent = fmt.Sprintf(EndPdfEmailContent, packageName, pdfUrl,
+                fmt.Sprintf("剑鱼标讯-%s-%s.pdf", packageName, time.Unix(qutil.Int64All(rData["l_createTime"]), 0).Format("20060102")),
+                packageName, `97%`, entName, rangeTime, strings.Join(keyWords, ","), matchingMode, area, industry, sBuyerClass)
+        } else {
+            mailContent = fmt.Sprintf(BuyerPdfEmailContent, packageName, pdfUrl,
+                fmt.Sprintf("剑鱼标讯-%s-%s.pdf", packageName, time.Unix(qutil.Int64All(rData["l_createTime"]), 0).Format("20060102")),
+                packageName, `97%`, entName, rangeTime, strings.Join(keyWords, ","), matchingMode, area, industry)
+        }
+    }
+    if SendRetryMail(3, sEmail, qutil.If(entName != "", fmt.Sprintf("%s(%s)", packageName, entName), packageName).(string), mailContent, "", nil, GmailAuth) {
+        log.Printf("PdfSendEmail SendMailToPayUser %s 邮件%s发送成功!", packageName, sEmail)
+    }
+    return nil
 }