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 //中标单位
Buyerclass string //采购单位行业
Hasbuyertel string //是否有采购电话
Haswinnertel string //是否有中标电话
SelectIds string //选择单条信息id
Notkey string //排除词
FileExists string //是否有附件
City string //城市
BidField string // 领域化数据: 0101 医疗
}
func (this *BidSearchExport) PassBidSearchExport(Sysconfig map[string]interface{}) (returnData map[string]interface{}) {
defer util.Catch()
areaSave, industrySave, citySave := []string{}, []string{}, []string{}
winnerSave, buyerclassSave := []string{}, []string{}
publishtimeSave := this.Publishtime
if len(this.Area) > 0 {
areaSave = strings.Split(this.Area, ",")
}
if this.City != "" {
citySave = strings.Split(this.City, ",")
}
if len(this.Industry) > 0 {
industrySave = strings.Split(this.Industry, ",")
}
if len(this.Buyerclass) > 0 {
buyerclassSave = strings.Split(this.Buyerclass, ",")
}
if len(this.Winner) > 0 {
winnerSave = strings.Split(this.Winner, ",")
}
KeyWordSave := []dataexport.KeyWord{}
if len(this.Keywords) > 0 {
_, _, keywords := jy.InterceptSearchKW(this.Keywords, util.IntAllDef(Sysconfig["keywordsLimit"], 35), len(this.Industry) == 0)
keywords = strings.Replace(keywords, "+", " ", -1)
excludes := []string{}
if this.Notkey != "" && len(strings.Split(this.Notkey, " ")) > 0 {
excludes = strings.Split(this.Notkey, " ")
}
KeyWordSave = append(KeyWordSave, dataexport.KeyWord{Keyword: keywords, Exclude: excludes})
}
//时间
now := time.Now()
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_%d", starttime, now.Unix())
} 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_%d", starttime, now.Unix())
} 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,
"subtype": this.Subtype,
"minprice": this.Minprice,
"maxprice": this.Maxprice,
"industry": industrySave,
"selectType": this.SelectType,
"buyerclass": buyerclassSave,
"winner": winnerSave,
"hasBuyertel": this.Hasbuyertel,
"hasWinnertel": this.Haswinnertel,
"fileExists": this.FileExists,
"comeintime": now.Unix(),
"bid_field": this.BidField,
}
//选择信息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
}