updated contributors

This commit is contained in:
marvzhang
2020-03-19 11:13:25 +08:00
parent e0d953d18f
commit daef59be07
22 changed files with 211 additions and 31 deletions

View File

@@ -1,6 +1,7 @@
package model
import (
"crawlab/constants"
"crawlab/database"
"github.com/apex/log"
"github.com/globalsign/mgo/bson"
@@ -82,6 +83,52 @@ func GetActionListTotal(filter interface{}) (int, error) {
return result, nil
}
func GetVisitDays(uid bson.ObjectId) (int, error) {
type ResData struct {
Days int `json:"days" bson:"days"`
}
s, c := database.GetCol("actions")
defer s.Close()
pipeline := []bson.M{
{
"$match": bson.M{
"user_id": uid,
"type": constants.ActionTypeVisit,
},
},
{
"$addFields": bson.M{
"date": bson.M{
"$dateToString": bson.M{
"format": "%Y%m%d",
"date": "$create_ts",
"timezone": "Asia/Shanghai",
},
},
},
},
{
"$group": bson.M{
"_id": "$date",
},
},
{
"_id": nil,
"days": bson.M{"$sum": 1},
},
}
var resData []ResData
if err := c.Pipe(pipeline).All(&resData); err != nil {
log.Errorf(err.Error())
debug.PrintStack()
return 0, err
}
return resData[0].Days, nil
}
func UpdateAction(id bson.ObjectId, item Action) error {
s, c := database.GetCol("actions")
defer s.Close()