|
@@ -3,13 +3,14 @@ package utils
|
|
|
import (
|
|
|
. "config"
|
|
|
"fmt"
|
|
|
- "github.com/robfig/cron"
|
|
|
- log "github.com/sirupsen/logrus"
|
|
|
- b "gopkg.in/mgo.v2/bson"
|
|
|
"net/http"
|
|
|
qu "qfw/util"
|
|
|
"qfw/util/redis"
|
|
|
"time"
|
|
|
+
|
|
|
+ "github.com/robfig/cron"
|
|
|
+ log "github.com/sirupsen/logrus"
|
|
|
+ b "gopkg.in/mgo.v2/bson"
|
|
|
)
|
|
|
|
|
|
//定时任务,邮件服务
|
|
@@ -22,17 +23,17 @@ var (
|
|
|
func tj() {
|
|
|
sess := Mgo.GetMgoConn()
|
|
|
defer Mgo.DestoryMongoConn(sess)
|
|
|
- var res []b.M
|
|
|
+ var res []map[string]interface{}
|
|
|
now := time.Now()
|
|
|
d1970 := time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)
|
|
|
nowZero := time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, time.Local).Unix()
|
|
|
befor := nowZero - 86400*60
|
|
|
//b.M{"$add": []interface{}{"$createtime", 28800}}
|
|
|
//b.M{"$subtract": []interface{}{"$createtime", 28800}}
|
|
|
- sess.DB(Mgo.DbName).C("usermail").Pipe([]b.M{
|
|
|
- b.M{"$match": b.M{"createtime": b.M{"$gte": befor, "$lt": nowZero}}},
|
|
|
- b.M{"$group": b.M{"_id": b.M{"appid": "$appid", "M": b.M{"$dateToString": b.M{"format": "%Y-%m-%d", "date": b.M{"$add": []interface{}{d1970, b.M{"$multiply": []interface{}{1000, b.M{"$add": []interface{}{"$createtime", 28800}}}}}}}}}, "sum": b.M{"$sum": int(1)}, "bget": b.M{"$sum": "$bget"}}},
|
|
|
- b.M{"$project": b.M{"day": "$_id.M", "appid": "$_id.appid", "sum": "$sum", "_id": 0, "bget": "$bget"}},
|
|
|
+ sess.DB(Mgo.DbName).C("usermail").Pipe([]map[string]interface{}{
|
|
|
+ map[string]interface{}{"$match": map[string]interface{}{"createtime": map[string]interface{}{"$gte": befor, "$lt": nowZero}}},
|
|
|
+ map[string]interface{}{"$group": map[string]interface{}{"_id": map[string]interface{}{"appid": "$appid", "M": map[string]interface{}{"$dateToString": map[string]interface{}{"format": "%Y-%m-%d", "date": map[string]interface{}{"$add": []interface{}{d1970, map[string]interface{}{"$multiply": []interface{}{1000, map[string]interface{}{"$add": []interface{}{"$createtime", 28800}}}}}}}}}, "sum": map[string]interface{}{"$sum": int(1)}, "bget": map[string]interface{}{"$sum": "$bget"}}},
|
|
|
+ map[string]interface{}{"$project": map[string]interface{}{"day": "$_id.M", "appid": "$_id.appid", "sum": "$sum", "_id": 0, "bget": "$bget"}},
|
|
|
}).All(&res)
|
|
|
if res != nil && len(res) > 0 {
|
|
|
update := [][]map[string]interface{}{}
|