Commit 713f4a85 by mushishixian

Merge branch 'ysx-魔方统计-20210112'

parents 324698b6 4c2a317b
Showing with 18 additions and 9 deletions
......@@ -94,8 +94,9 @@ func main() {
err = specialDb.Reset().Table(&giftActivityList).Fields("id,start_time,end_time").
Where("end_time", ">", updateTime).Select()
if err != nil {
fmt.Println(err.Error())
logger.Error(err.Error())
fmt.Println(err.Error())
}
fmt.Println(len(giftActivityList))
//统计满赠活动******************
......@@ -117,22 +118,24 @@ func main() {
_, err = specialDb.Reset().Table("lie_activity_statistics").Where("activity_id", activity.Id).Data(data).Update()
if err != nil {
logger.Error(err.Error())
fmt.Println(err.Error())
}
} else {
data["create_time"] = time.Now().Unix()
_, err = specialDb.Reset().Table("lie_activity_statistics").Data(data).Insert()
if err != nil {
logger.Error(err.Error())
fmt.Println(err.Error())
}
}
//将明细写进mongoDB
//先去查找明细是否存在
var orderGifts []model.OrderGift
err = db.Reset().Table(&orderGifts).Where("activity_id", activity.Id).Where("status", "!=", -1).Select()
if err != nil {
fmt.Println(err.Error())
logger.Error(err.Error())
fmt.Println(err.Error())
}
for _, orderGif := range orderGifts {
var giftActivityDetail model.GiftActivityDetail
......@@ -141,6 +144,7 @@ func main() {
One(&giftActivityDetail)
if err != nil && err != mgo.ErrNotFound {
logger.Error(err.Error())
fmt.Println(err.Error())
}
//不存在,则插入
if giftActivityDetail.ActivityId == 0 {
......@@ -149,12 +153,14 @@ func main() {
err = db.Reset().Table(&order).Fields("order_id,status,create_time").Where("order_id", orderGif.OrderId).Select()
if err != nil {
logger.Error(err.Error())
fmt.Println(err.Error())
}
//去找用户信息
var userMain model.UserMain
err = db.Reset().Table(&userMain).Fields("user_id,mobile,is_new").Where("user_id", orderGif.UserId).Select()
if err != nil {
logger.Error(err.Error())
fmt.Println(err.Error())
}
//组装最后的统计结果到mongo
data := model.GiftActivityDetail{
......@@ -172,8 +178,8 @@ func main() {
}
err = mongoConn.DB("ichunt").C("gift_activity_detail").Insert(&data)
if err != nil {
fmt.Println(err.Error())
logger.Error(err.Error())
fmt.Println(err.Error())
}
}
}
......@@ -184,8 +190,9 @@ func main() {
err = specialDb.Reset().Table(&priceActivityList).Fields("id,start_time,end_time").
Where("end_time", ">", updateTime).Select()
if err != nil {
fmt.Println(err.Error())
logger.Error(err.Error())
fmt.Println(err.Error())
}
for _, activity := range priceActivityList {
orderNum, _ := db.Reset().Table("lie_order_activity_count").Where("activity_id", activity.Id).Count("order_id")
......@@ -204,15 +211,15 @@ func main() {
if count > 0 {
_, err = specialDb.Reset().Table("lie_activity_statistics").Where("activity_id", activity.Id).Data(data).Update()
if err != nil {
fmt.Println(err.Error())
logger.Error(err.Error())
fmt.Println(err.Error())
}
} else {
data["create_time"] = time.Now().Unix()
_, err = specialDb.Reset().Table("lie_activity_statistics").Data(data).Insert()
if err != nil {
fmt.Println(err.Error())
logger.Error(err.Error())
fmt.Println(err.Error())
}
}
items, err := db.Reset().
......@@ -223,6 +230,7 @@ func main() {
GroupBy("order_id").Get()
if err != nil {
logger.Error(err.Error())
fmt.Println(err.Error())
}
for _, item := range items {
resultByte, err := json.Marshal(item)
......@@ -234,8 +242,9 @@ func main() {
Find(bson.M{"order_id": gjson.Get(result, "order_id").Int(), "activity_id": gjson.Get(result, "activity_id").Int()}).
One(&priceActivityMongo)
if err != nil && err != mgo.ErrNotFound {
fmt.Println(err.Error())
logger.Error(err.Error())
fmt.Println(err.Error())
}
//存在跳过,不存在才插入
if priceActivityMongo.OrderId == 0 {
......@@ -247,8 +256,8 @@ func main() {
priceActivityMongo.Pf = gjson.Get(result, "create_device").Int()
err = mongoConn.DB("ichunt").C("price_activity_statistics").Insert(&priceActivityMongo)
if err != nil {
fmt.Println(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