|
@@ -52,7 +52,8 @@ func init() {
|
|
|
}
|
|
|
|
|
|
func sm() {
|
|
|
- sendmail("", -1, 1, "")
|
|
|
+ //bforce要是0,不发送已经发过的信息
|
|
|
+ sendmail("", -1, 0, "", true)
|
|
|
}
|
|
|
|
|
|
//调用url地址发送邮件
|
|
@@ -68,7 +69,7 @@ func SendMailByAppid(w http.ResponseWriter, r *http.Request) {
|
|
|
day = qu.IntAll(days)
|
|
|
}
|
|
|
force1 := qu.IntAll(force)
|
|
|
- sendmail(appid, day, force1, fn)
|
|
|
+ sendmail(appid, day, force1, fn, false)
|
|
|
w.Write([]byte("ok"))
|
|
|
} else {
|
|
|
w.Write([]byte("param error"))
|
|
@@ -80,8 +81,9 @@ func SendMailByAppid(w http.ResponseWriter, r *http.Request) {
|
|
|
appid 用户身份
|
|
|
days -1发送昨天数据 -3发送前三天数据
|
|
|
force 1不判断bget 0判断bget为1的不发送
|
|
|
+bcron 只能,取用户表cronday的值是0 或 -1
|
|
|
**/
|
|
|
-func sendmail(appid string, days int, force int, fn string) {
|
|
|
+func sendmail(appid string, days int, force int, fn string, bcron bool) {
|
|
|
query := map[string]interface{}{
|
|
|
"mails": map[string]interface{}{
|
|
|
"$exists": 1,
|
|
@@ -110,6 +112,7 @@ func sendmail(appid string, days int, force int, fn string) {
|
|
|
}
|
|
|
appfields, _ := v["fields"].(string)
|
|
|
mails, _ := v["mails"].(map[string]interface{})
|
|
|
+ cronday := qu.IntAllDef(v["cronday"], 0)
|
|
|
if len(mails) > 0 && appid != "" && len(planname) > 1 {
|
|
|
GetDataMapLock.Lock()
|
|
|
appidLock := GetDataMap[appid]
|
|
@@ -141,6 +144,13 @@ func sendmail(appid string, days int, force int, fn string) {
|
|
|
}
|
|
|
st, _ := GetDayMinMax(time.Now())
|
|
|
st1 := st + int64(days*86400)
|
|
|
+ if bcron { //如果是定时任务取cronday的值只能为0或-1,-1只发昨天的数据,0发最近两天的bget不为1的数据
|
|
|
+ st1 = st - 86400 //昨天0点
|
|
|
+ if cronday == 0 {
|
|
|
+ st = time.Now().Unix() //当前时间
|
|
|
+ }
|
|
|
+ fn = time.Now().Format("2006-01-02-15")
|
|
|
+ }
|
|
|
dataQuery["createtime"] = map[string]interface{}{
|
|
|
"$gte": st1,
|
|
|
"$lt": st,
|
|
@@ -184,7 +194,7 @@ func sendmail(appid string, days int, force int, fn string) {
|
|
|
}
|
|
|
}
|
|
|
fields2["item"] = 1
|
|
|
- log.Info(fields2)
|
|
|
+ log.Info(fields2, dataQuery)
|
|
|
data, bdata := Mgo.Find("usermail", dataQuery, `{"_id":1}`, fields2, false, -1, -1)
|
|
|
firstId, lastId := "", ""
|
|
|
if bdata && data != nil && *data != nil && len(*data) > 0 {
|
|
@@ -323,7 +333,7 @@ func GetBidInfoXlsx(appid string, fn string, mails map[string]interface{}, field
|
|
|
log.Println("mkdir err", dir)
|
|
|
}
|
|
|
}
|
|
|
- fname := key + "_" + fn + qu.GetRandom(4) + ".xlsx"
|
|
|
+ fname := key + "_" + fn + "_N" + qu.GetRandom(4) + ".xlsx"
|
|
|
err := fx.Save(dir + fname)
|
|
|
if err != nil {
|
|
|
log.Info("xls error", appid, fname)
|