dataexport.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. package public
  2. import (
  3. "fmt"
  4. "log"
  5. "strings"
  6. "sync"
  7. "time"
  8. . "app.yhyue.com/moapp/jybase/encrypt"
  9. "app.yhyue.com/moapp/jypkg/common/src/qfw/util/dataexport"
  10. "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
  11. util "app.yhyue.com/moapp/jybase/common"
  12. "app.yhyue.com/moapp/jybase/mail"
  13. )
  14. var ExConf *DataexportConfig
  15. //价格配置文件
  16. type DataexportConfig struct {
  17. MsgMaxCount int `json:"msgMaxCount"`
  18. Font Font `json:"font"`
  19. }
  20. type Font struct {
  21. Enabled bool `json:"enabled"`
  22. ConvertVersionDefault string `json:"convertVersionDefault"`
  23. UnConvertVersionDefault string `json:"unConvertVersionDefault"`
  24. MappingFileExt string `json:"mappingFileExt"`
  25. MappingFilePath string `json:"mappingFilePath"`
  26. RedisPool string `json:"redisPool"`
  27. RedisKey string `json:"redisKey"`
  28. }
  29. func init() {
  30. util.ReadConfig("./dataexport.json", &ExConf)
  31. }
  32. //发送邮箱验证码
  33. func SendMailIdentCode(to, code string, auth []*mail.GmailAuth) bool {
  34. html := fmt.Sprintf(`<div>
  35. <div>
  36. %s,您好!
  37. </div>
  38. <div style="padding: 20px 70px 10px 70px;">
  39. <p>您正在进行导出邮箱地址验证,请在邮件验证码输入框输入下方验证码:</p>
  40. <span style="font-weight: bold;font-size: x-large;">%s</span>
  41. <p>请勿向任何人泄露您收到的验证码。</p>
  42. <p>如果您没有使用剑鱼标讯,请忽略此邮件。</p>
  43. <p>此为系统邮件,请勿回复。</p>
  44. <p>如有疑问,请联系客服 400-108-6670。</p>
  45. </div>
  46. <div>
  47. <p>此致</p>
  48. <p>剑鱼标讯</p>
  49. </div>
  50. </div>`, to, code)
  51. for k, v := range auth {
  52. if mail.GSendMail("剑鱼标讯", to, "", "", "剑鱼标讯邮箱校验", html, "", "", v) {
  53. log.Println(to, fmt.Sprintf("使用%s发送邮件成功", v.User))
  54. return true
  55. }
  56. if k < len(auth)-1 {
  57. log.Println(to, fmt.Sprintf("使用%s发送邮件失败!3s后使用其他邮箱尝试", v.User))
  58. } else {
  59. log.Println(to, fmt.Sprintf("使用%s发送邮件失败!", v.User))
  60. }
  61. time.Sleep(time.Second * 3)
  62. }
  63. return false
  64. }
  65. var finaceLock *sync.Mutex = &sync.Mutex{}
  66. func GetWaitPayToken(orderid int64, order_money int, ordercode, payway, userid string) string {
  67. return util.GetMd5String(fmt.Sprintf("%d_%d_%s_%s_%s", orderid, order_money, ordercode, payway, userid))
  68. }
  69. /*
  70. 获取-筛选条件-金额
  71. */
  72. func GetPriceDes_SieveCondition(minPrice, maxPrice string) string {
  73. des := ""
  74. unit := "万元"
  75. if minPrice != "" && maxPrice != "" {
  76. des = minPrice + unit + "-" + maxPrice + unit
  77. } else if minPrice != "" {
  78. des = "大于" + minPrice + unit
  79. } else if maxPrice != "" {
  80. des = "小于" + maxPrice + unit
  81. }
  82. return des
  83. }
  84. //招标数据导出筛选
  85. type BidSearchExport struct {
  86. Keywords string //搜索词
  87. Publishtime string //发布时间
  88. Area string //地区
  89. Subtype string //信息类型
  90. Minprice string //最低价格
  91. Maxprice string //最高价格
  92. Industry string //选中的行业
  93. SelectType string //标题 or 全文
  94. Winner string //中标单位
  95. Buyerclass string //采购单位行业
  96. Hasbuyertel string //是否有采购电话
  97. Haswinnertel string //是否有中标电话
  98. SelectIds string //选择单条信息id
  99. Notkey string //排除词
  100. FileExists string //是否有附件
  101. City string //城市
  102. BidField string // 领域化数据: 0101 医疗
  103. }
  104. func (this *BidSearchExport) PassBidSearchExport(Sysconfig map[string]interface{}) (returnData map[string]interface{}) {
  105. defer util.Catch()
  106. areaSave, industrySave, citySave := []string{}, []string{}, []string{}
  107. winnerSave, buyerclassSave := []string{}, []string{}
  108. publishtimeSave := this.Publishtime
  109. if len(this.Area) > 0 {
  110. areaSave = strings.Split(this.Area, ",")
  111. }
  112. if this.City != "" {
  113. citySave = strings.Split(this.City, ",")
  114. }
  115. if len(this.Industry) > 0 {
  116. industrySave = strings.Split(this.Industry, ",")
  117. }
  118. if len(this.Buyerclass) > 0 {
  119. buyerclassSave = strings.Split(this.Buyerclass, ",")
  120. }
  121. if len(this.Winner) > 0 {
  122. winnerSave = strings.Split(this.Winner, ",")
  123. }
  124. KeyWordSave := []dataexport.KeyWord{}
  125. if len(this.Keywords) > 0 {
  126. _, _, keywords := jy.InterceptSearchKW(this.Keywords, util.IntAllDef(Sysconfig["keywordsLimit"], 35), len(this.Industry) == 0)
  127. keywords = strings.Replace(keywords, "+", " ", -1)
  128. excludes := []string{}
  129. if this.Notkey != "" && len(strings.Split(this.Notkey, " ")) > 0 {
  130. excludes = strings.Split(this.Notkey, " ")
  131. }
  132. KeyWordSave = append(KeyWordSave, dataexport.KeyWord{Keyword: keywords, Exclude: excludes})
  133. }
  134. //时间
  135. now := time.Now()
  136. if this.Publishtime == "lately-7" { //最近7天
  137. starttime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
  138. publishtimeSave = fmt.Sprintf("%s_%d", starttime, now.Unix())
  139. } else if this.Publishtime == "lately-30" { //最近30天
  140. starttime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
  141. publishtimeSave = fmt.Sprintf("%s_%d", starttime, now.Unix())
  142. } else if this.Publishtime == "thisyear" { //去年
  143. starttime := fmt.Sprint(time.Date(now.Year()-1, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
  144. endtime := fmt.Sprint(now.Unix())
  145. publishtimeSave = fmt.Sprintf("%s_%s", starttime, endtime)
  146. } else if this.Publishtime == "threeyear" { //近三年
  147. starttime := fmt.Sprint(time.Date(now.Year()-3, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
  148. endtime := fmt.Sprint(now.Unix())
  149. publishtimeSave = fmt.Sprintf("%s_%s", starttime, endtime)
  150. } else if this.Publishtime == "fiveyear" { //近五年
  151. starttime := fmt.Sprint(time.Date(now.Year()-5, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
  152. endtime := fmt.Sprint(now.Unix())
  153. publishtimeSave = fmt.Sprintf("%s_%s", starttime, endtime)
  154. }
  155. returnData = map[string]interface{}{
  156. "keywords": KeyWordSave,
  157. "publishtime": publishtimeSave,
  158. "area": areaSave,
  159. "city": citySave,
  160. "subtype": this.Subtype,
  161. "minprice": this.Minprice,
  162. "maxprice": this.Maxprice,
  163. "industry": industrySave,
  164. "selectType": this.SelectType,
  165. "buyerclass": buyerclassSave,
  166. "winner": winnerSave,
  167. "hasBuyertel": this.Hasbuyertel,
  168. "hasWinnertel": this.Haswinnertel,
  169. "fileExists": this.FileExists,
  170. "comeintime": now.Unix(),
  171. "bid_field": this.BidField,
  172. }
  173. //选择信息id
  174. if this.SelectIds != "" {
  175. ids := []string{}
  176. for _, encodeId := range strings.Split(this.SelectIds, ",") {
  177. if tmp := CommonDecodeArticle("content", encodeId); len(tmp) > 0 {
  178. if id := tmp[0]; id != "" {
  179. ids = append(ids, id)
  180. }
  181. }
  182. }
  183. if len(ids) > 0 {
  184. returnData["selectIds"] = ids
  185. }
  186. }
  187. return returnData
  188. }