package public
import (
"fmt"
"log"
"strings"
"sync"
"time"
. "app.yhyue.com/moapp/jybase/encrypt"
"app.yhyue.com/moapp/jypkg/common/src/qfw/util/dataexport"
"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
util "app.yhyue.com/moapp/jybase/common"
"app.yhyue.com/moapp/jybase/mail"
)
var ExConf *DataexportConfig
// 价格配置文件
type DataexportConfig struct {
MsgMaxCount int `json:"msgMaxCount"`
Font Font `json:"font"`
}
type Font struct {
Enabled bool `json:"enabled"`
ConvertVersionDefault string `json:"convertVersionDefault"`
UnConvertVersionDefault string `json:"unConvertVersionDefault"`
MappingFileExt string `json:"mappingFileExt"`
MappingFilePath string `json:"mappingFilePath"`
RedisPool string `json:"redisPool"`
RedisKey string `json:"redisKey"`
}
func init() {
util.ReadConfig("./dataexport.json", &ExConf)
}
// 发送邮箱验证码
func SendMailIdentCode(to, code string, auth []*mail.GmailAuth) bool {
html := fmt.Sprintf(`
%s,您好!
您正在进行导出邮箱地址验证,请在邮件验证码输入框输入下方验证码:
%s
请勿向任何人泄露您收到的验证码。
如果您没有使用剑鱼标讯,请忽略此邮件。
此为系统邮件,请勿回复。
如有疑问,请联系客服 400-108-6670。
`, to, code)
for k, v := range auth {
if mail.GSendMail("剑鱼标讯", to, "", "", "剑鱼标讯邮箱校验", html, "", "", v) {
log.Println(to, fmt.Sprintf("使用%s发送邮件成功", v.User))
return true
}
if k < len(auth)-1 {
log.Println(to, fmt.Sprintf("使用%s发送邮件失败!3s后使用其他邮箱尝试", v.User))
} else {
log.Println(to, fmt.Sprintf("使用%s发送邮件失败!", v.User))
}
time.Sleep(time.Second * 3)
}
return false
}
var finaceLock *sync.Mutex = &sync.Mutex{}
func GetWaitPayToken(orderid int64, order_money int, ordercode, payway, userid string) string {
return util.GetMd5String(fmt.Sprintf("%d_%d_%s_%s_%s", orderid, order_money, ordercode, payway, userid))
}
/*
获取-筛选条件-金额
*/
func GetPriceDes_SieveCondition(minPrice, maxPrice string) string {
des := ""
unit := "万元"
if minPrice != "" && maxPrice != "" {
des = minPrice + unit + "-" + maxPrice + unit
} else if minPrice != "" {
des = "大于" + minPrice + unit
} else if maxPrice != "" {
des = "小于" + maxPrice + unit
}
return des
}
// 招标数据导出筛选
type BidSearchExport struct {
Keywords string //搜索词
Publishtime string //发布时间
Area string //地区
Subtype string //信息类型
Minprice string //最低价格
Maxprice string //最高价格
Industry string //选中的行业
SelectType string //标题 or 全文
Winner string //中标单位
Buyer string `json:"buyer"` //招标单位(采购单位)
Agency string `json:"agency"` //招标代理机构(采购单位)
Buyerclass string //采购单位行业
Hasbuyertel string //是否有采购电话
Haswinnertel string //是否有中标电话
SelectIds string //选择单条信息id
Notkey string //排除词 排除词(副:五组,每组最多15个字符)
FileExists string //是否有附件
City string //城市
BidField string // 领域化数据: 0101 医疗
SearchGroup int // 搜索分组:默认0:全部;1:招标采购公告;2:超前项目
SearchMode int // 搜索模式:0:精准搜索;1:模糊搜索
WordsMode int // 搜索关键词模式;默认0:包含所有,1:包含任意
AdditionalWords string // 关键词:附加关键词(副:五组,每组最多15个字符)
District string //地区
RegionMap string
}
func (this *BidSearchExport) PassBidSearchExport(Sysconfig map[string]interface{}) (returnData map[string]interface{}) {
defer util.Catch()
var (
areaSave, industrySave, citySave, districtSave = []string{}, []string{}, []string{}, []string{}
winnerSave, buyerSave, agencySave, buyerclassSave = []string{}, []string{}, []string{}, []string{}
)
publishtimeSave := this.Publishtime
if len(this.Area) > 0 {
areaSave = strings.Split(this.Area, ",")
}
if this.City != "" {
citySave = strings.Split(this.City, ",")
}
if this.District != "" {
districtSave = strings.Split(this.District, ",")
}
if this.Industry = strings.TrimSpace(this.Industry); this.Industry != "" {
industrySave = strings.Split(this.Industry, ",")
//P510 行业:其它
if qt := jy.IndustryHandle(this.Industry); len(qt) > 0 {
industrySave = append(industrySave, qt...)
}
}
if len(this.Buyerclass) > 0 {
buyerclassSave = strings.Split(this.Buyerclass, ",")
}
if len(this.Winner) > 0 {
winnerSave = strings.Split(this.Winner, ",")
}
if len(this.Buyer) > 0 {
buyerSave = strings.Split(this.Buyer, ",")
}
if len(this.Agency) > 0 {
agencySave = strings.Split(this.Agency, ",")
}
KeyWordSave := []dataexport.KeyWord{}
if len(this.Keywords) > 0 || len(this.AdditionalWords) > 0 {
_, _, keywords := jy.InterceptSearchKW(this.Keywords, util.IntAllDef(Sysconfig["keywordsLimit"], 35), len(this.Industry) == 0)
keywords = strings.Replace(keywords, "+", " ", -1)
excludes := []string{} // 排除词
appendWords := []string{} // 附加词
//排除词 每组排除词不能超过15个字符
if this.Notkey != "" && len(strings.Split(this.Notkey, ",")) > 0 {
for _, ak := range strings.Split(this.Notkey, ",") {
if len([]rune(ak)) > 15 {
excludes = append(excludes, string([]rune(ak)[:15]))
} else {
excludes = append(excludes, ak)
}
}
}
//附加词 每组附加词不能超过15个字符
if this.AdditionalWords != "" && len(strings.Split(this.AdditionalWords, ",")) > 0 {
for _, ak := range strings.Split(this.AdditionalWords, ",") {
if len([]rune(ak)) > 15 {
appendWords = append(appendWords, string([]rune(ak)[:15]))
} else {
appendWords = append(appendWords, ak)
}
}
}
KeyWordSave = append(KeyWordSave, dataexport.KeyWord{Keyword: keywords, Exclude: excludes, Appended: appendWords})
}
//时间
now := time.Now()
endTime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, time.Local).Unix())
if this.Publishtime == "lately-7" { //最近7天
starttime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-7, 0, 0, 0, 0, time.Local).Unix())
publishtimeSave = fmt.Sprintf("%s_%s", starttime, endTime)
} else if this.Publishtime == "lately-30" { //最近30天
starttime := fmt.Sprint(time.Date(now.Year(), now.Month(), now.Day()-30, 0, 0, 0, 0, time.Local).Unix())
publishtimeSave = fmt.Sprintf("%s_%s", starttime, endTime)
} else if this.Publishtime == "thisyear" { //去年
starttime := fmt.Sprint(time.Date(now.Year()-1, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
//endtime := fmt.Sprint(now.Unix())
publishtimeSave = fmt.Sprintf("%s_%s", starttime, endTime)
} else if this.Publishtime == "threeyear" { //近三年
starttime := fmt.Sprint(time.Date(now.Year()-3, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
//endtime := fmt.Sprint(now.Unix())
publishtimeSave = fmt.Sprintf("%s_%s", starttime, endTime)
} else if this.Publishtime == "fiveyear" { //近五年
starttime := fmt.Sprint(time.Date(now.Year()-5, now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), 0, time.Local).Unix())
//endtime := fmt.Sprint(now.Unix())
publishtimeSave = fmt.Sprintf("%s_%s", starttime, endTime)
}
returnData = map[string]interface{}{
"keywords": KeyWordSave,
"publishtime": publishtimeSave,
"area": areaSave,
"city": citySave,
"district": districtSave,
"subtype": this.Subtype,
"minprice": this.Minprice,
"maxprice": this.Maxprice,
"industry": industrySave,
"selectType": this.SelectType,
"buyerclass": buyerclassSave,
"winner": winnerSave,
"buyer": buyerSave,
"agency": agencySave,
"hasBuyertel": this.Hasbuyertel,
"hasWinnertel": this.Haswinnertel,
"fileExists": this.FileExists,
"comeintime": now.Unix(),
"bid_field": this.BidField,
"searchGroup": this.SearchGroup,
"searchMode": this.SearchMode,
"wordsMode": this.WordsMode,
}
//选择信息id
if this.SelectIds != "" {
ids := []string{}
for _, encodeId := range strings.Split(this.SelectIds, ",") {
if tmp := CommonDecodeArticle("content", encodeId); len(tmp) > 0 {
if id := tmp[0]; id != "" {
ids = append(ids, id)
}
}
}
if len(ids) > 0 {
returnData["selectIds"] = ids
}
}
return returnData
}