Commit 4c2a317b by mushishixian

统计日志

parent f713e05d
Showing with 18 additions and 9 deletions
...@@ -91,8 +91,9 @@ func main() { ...@@ -91,8 +91,9 @@ func main() {
err = specialDb.Reset().Table(&giftActivityList).Fields("id,start_time,end_time"). err = specialDb.Reset().Table(&giftActivityList).Fields("id,start_time,end_time").
Where("end_time", ">", updateTime).Select() Where("end_time", ">", updateTime).Select()
if err != nil { if err != nil {
fmt.Println(err.Error())
logger.Error(err.Error()) logger.Error(err.Error())
fmt.Println(err.Error())
} }
fmt.Println(len(giftActivityList)) fmt.Println(len(giftActivityList))
//统计满赠活动****************** //统计满赠活动******************
...@@ -114,22 +115,24 @@ func main() { ...@@ -114,22 +115,24 @@ func main() {
_, err = specialDb.Reset().Table("lie_activity_statistics").Where("activity_id", activity.Id).Data(data).Update() _, err = specialDb.Reset().Table("lie_activity_statistics").Where("activity_id", activity.Id).Data(data).Update()
if err != nil { if err != nil {
logger.Error(err.Error()) logger.Error(err.Error())
fmt.Println(err.Error())
} }
} else { } else {
data["create_time"] = time.Now().Unix() data["create_time"] = time.Now().Unix()
_, err = specialDb.Reset().Table("lie_activity_statistics").Data(data).Insert() _, err = specialDb.Reset().Table("lie_activity_statistics").Data(data).Insert()
if err != nil { if err != nil {
logger.Error(err.Error()) logger.Error(err.Error())
fmt.Println(err.Error())
} }
} }
//将明细写进mongoDB //将明细写进mongoDB
//先去查找明细是否存在 //先去查找明细是否存在
var orderGifts []model.OrderGift var orderGifts []model.OrderGift
err = db.Reset().Table(&orderGifts).Where("activity_id", activity.Id).Where("status", "!=", -1).Select() err = db.Reset().Table(&orderGifts).Where("activity_id", activity.Id).Where("status", "!=", -1).Select()
if err != nil { if err != nil {
fmt.Println(err.Error())
logger.Error(err.Error()) logger.Error(err.Error())
fmt.Println(err.Error())
} }
for _, orderGif := range orderGifts { for _, orderGif := range orderGifts {
var giftActivityDetail model.GiftActivityDetail var giftActivityDetail model.GiftActivityDetail
...@@ -138,6 +141,7 @@ func main() { ...@@ -138,6 +141,7 @@ func main() {
One(&giftActivityDetail) One(&giftActivityDetail)
if err != nil && err != mgo.ErrNotFound { if err != nil && err != mgo.ErrNotFound {
logger.Error(err.Error()) logger.Error(err.Error())
fmt.Println(err.Error())
} }
//不存在,则插入 //不存在,则插入
if giftActivityDetail.ActivityId == 0 { if giftActivityDetail.ActivityId == 0 {
...@@ -146,12 +150,14 @@ func main() { ...@@ -146,12 +150,14 @@ func main() {
err = db.Reset().Table(&order).Fields("order_id,status,create_time").Where("order_id", orderGif.OrderId).Select() err = db.Reset().Table(&order).Fields("order_id,status,create_time").Where("order_id", orderGif.OrderId).Select()
if err != nil { if err != nil {
logger.Error(err.Error()) logger.Error(err.Error())
fmt.Println(err.Error())
} }
//去找用户信息 //去找用户信息
var userMain model.UserMain var userMain model.UserMain
err = db.Reset().Table(&userMain).Fields("user_id,mobile,is_new").Where("user_id", orderGif.UserId).Select() err = db.Reset().Table(&userMain).Fields("user_id,mobile,is_new").Where("user_id", orderGif.UserId).Select()
if err != nil { if err != nil {
logger.Error(err.Error()) logger.Error(err.Error())
fmt.Println(err.Error())
} }
//组装最后的统计结果到mongo //组装最后的统计结果到mongo
data := model.GiftActivityDetail{ data := model.GiftActivityDetail{
...@@ -169,8 +175,8 @@ func main() { ...@@ -169,8 +175,8 @@ func main() {
} }
err = mongoConn.DB("ichunt").C("gift_activity_detail").Insert(&data) err = mongoConn.DB("ichunt").C("gift_activity_detail").Insert(&data)
if err != nil { if err != nil {
fmt.Println(err.Error())
logger.Error(err.Error()) logger.Error(err.Error())
fmt.Println(err.Error())
} }
} }
} }
...@@ -181,8 +187,9 @@ func main() { ...@@ -181,8 +187,9 @@ func main() {
err = specialDb.Reset().Table(&priceActivityList).Fields("id,start_time,end_time"). err = specialDb.Reset().Table(&priceActivityList).Fields("id,start_time,end_time").
Where("end_time", ">", updateTime).Select() Where("end_time", ">", updateTime).Select()
if err != nil { if err != nil {
fmt.Println(err.Error())
logger.Error(err.Error()) logger.Error(err.Error())
fmt.Println(err.Error())
} }
for _, activity := range priceActivityList { for _, activity := range priceActivityList {
orderNum, _ := db.Reset().Table("lie_order_activity_count").Where("activity_id", activity.Id).Count("order_id") orderNum, _ := db.Reset().Table("lie_order_activity_count").Where("activity_id", activity.Id).Count("order_id")
...@@ -201,15 +208,15 @@ func main() { ...@@ -201,15 +208,15 @@ func main() {
if count > 0 { if count > 0 {
_, err = specialDb.Reset().Table("lie_activity_statistics").Where("activity_id", activity.Id).Data(data).Update() _, err = specialDb.Reset().Table("lie_activity_statistics").Where("activity_id", activity.Id).Data(data).Update()
if err != nil { if err != nil {
fmt.Println(err.Error())
logger.Error(err.Error()) logger.Error(err.Error())
fmt.Println(err.Error())
} }
} else { } else {
data["create_time"] = time.Now().Unix() data["create_time"] = time.Now().Unix()
_, err = specialDb.Reset().Table("lie_activity_statistics").Data(data).Insert() _, err = specialDb.Reset().Table("lie_activity_statistics").Data(data).Insert()
if err != nil { if err != nil {
fmt.Println(err.Error())
logger.Error(err.Error()) logger.Error(err.Error())
fmt.Println(err.Error())
} }
} }
items, err := db.Reset(). items, err := db.Reset().
...@@ -220,6 +227,7 @@ func main() { ...@@ -220,6 +227,7 @@ func main() {
GroupBy("order_id").Get() GroupBy("order_id").Get()
if err != nil { if err != nil {
logger.Error(err.Error()) logger.Error(err.Error())
fmt.Println(err.Error())
} }
for _, item := range items { for _, item := range items {
resultByte, err := json.Marshal(item) resultByte, err := json.Marshal(item)
...@@ -231,8 +239,9 @@ func main() { ...@@ -231,8 +239,9 @@ func main() {
Find(bson.M{"order_id": gjson.Get(result, "order_id").Int(), "activity_id": gjson.Get(result, "activity_id").Int()}). Find(bson.M{"order_id": gjson.Get(result, "order_id").Int(), "activity_id": gjson.Get(result, "activity_id").Int()}).
One(&priceActivityMongo) One(&priceActivityMongo)
if err != nil && err != mgo.ErrNotFound { if err != nil && err != mgo.ErrNotFound {
fmt.Println(err.Error())
logger.Error(err.Error()) logger.Error(err.Error())
fmt.Println(err.Error())
} }
//存在跳过,不存在才插入 //存在跳过,不存在才插入
if priceActivityMongo.OrderId == 0 { if priceActivityMongo.OrderId == 0 {
...@@ -244,8 +253,8 @@ func main() { ...@@ -244,8 +253,8 @@ func main() {
priceActivityMongo.Pf = gjson.Get(result, "create_device").Int() priceActivityMongo.Pf = gjson.Get(result, "create_device").Int()
err = mongoConn.DB("ichunt").C("price_activity_statistics").Insert(&priceActivityMongo) err = mongoConn.DB("ichunt").C("price_activity_statistics").Insert(&priceActivityMongo)
if err != nil { if err != nil {
fmt.Println(err.Error())
logger.Error(err.Error()) logger.Error(err.Error())
fmt.Println(err.Error())
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment