Commit 526a92a4 by mushishixian

活动相关脚本修改

parent 702be50f
......@@ -103,8 +103,6 @@ func main() {
updateTime = 1
}
updateTime = 1
//先去取出所有的正在进行的活动列表
var giftActivityList []model.GiftActivity
err = specialDb.Reset().Table(&giftActivityList).Fields("id,start_time,end_time").
......@@ -124,7 +122,7 @@ func main() {
newUserNum = 0
if orderGiftUserIds != nil {
userIds = orderGiftUserIds.([]interface{})
if len(userIds)>0 {
if len(userIds) > 0 {
//然后根据得到的user_id去In查询所有的用户,并且是要新注册的用户
newUserNum, err = db.Reset().Table("lie_user_main").WhereIn("user_id", userIds).Where("is_new", 1).Count()
if err != nil {
......@@ -132,7 +130,6 @@ func main() {
fmt.Println(err.Error())
}
}
}
//先查询统计是否存在
count, _ := specialDb.Reset().Table("lie_activity_statistics").Where("activity_id", activity.Id).
......@@ -217,7 +214,9 @@ func main() {
}
}
//价格促销活动*****************
updateTime = 1
//价格促销活动统计***********************************************************************************************
var priceActivityList []model.PriceActivity
err = specialDb.Reset().Table(&priceActivityList).Fields("id,start_time,end_time").
Where("end_time", ">", updateTime).Select()
......@@ -227,11 +226,6 @@ func main() {
}
for _, activity := range priceActivityList {
orderNum, _ := db.Reset().Table("lie_order_activity_count").Where("activity_id", activity.Id).Count("order_id")
//newUserNum, _ := db.Reset().Table("lie_order_activity_count").LeftJoin("lie_user_main on lie_order_activity_count.user_id = lie_user_main.user_id").
// Where("lie_order_activity_count.activity_id", activity.Id).Where("lie_user_main.is_new", 1).
// Count("lie_user_main.user_id")
//先找出这个活动对应的所有用户(根据user_id)去重
orderActivityUserIds, _ := orderDb.Reset().Table("lie_order_activity_count").
Where("lie_order_activity_count.activity_id", activity.Id).
......@@ -241,7 +235,7 @@ func main() {
newUserNum = 0
if orderActivityUserIds != nil {
userIds = orderActivityUserIds.([]interface{})
if len(userIds)>0 {
if len(userIds) > 0 {
//然后根据得到的user_id去In查询所有的用户,并且是要新注册的用户
newUserNum, err = db.Reset().Table("lie_user_main").WhereIn("user_id", userIds).Where("is_new", 1).Count()
if err != nil {
......@@ -249,7 +243,6 @@ func main() {
fmt.Println(err.Error())
}
}
}
//先查询统计是否存在
......@@ -278,15 +271,32 @@ func main() {
}
}
items, err := db.Reset().
Fields("activity_id,order_id,lie_user_main.user_id,mobile,create_device,sum(lie_order_activity_count.amount) as total_amount").
Fields("activity_id,user_id,order_id,sum(lie_order_activity_count.amount) as total_amount").
Table("lie_order_activity_count").
LeftJoin("lie_user_main on lie_order_activity_count.user_id = lie_user_main.user_id").
Where("lie_order_activity_count.activity_id", activity.Id).
GroupBy("order_id").Get()
if err != nil {
logger.Error(err.Error())
fmt.Println(err.Error())
}
//找出有用户id,然后去DB里面用IN查找用户数据
var activityUserIds []interface{}
for _, item := range items {
resultByte, _ := json.Marshal(item)
result := string(resultByte)
userId := gjson.Get(result, "user_id").Int()
activityUserIds = append(activityUserIds, int(userId))
}
userMap := make(map[int]model.UserMain)
if len(activityUserIds) > 0 {
var users []model.UserMain
err = db.Reset().Table(&users).Fields("user_id,mobile,is_new,create_device").
WhereIn("user_id", activityUserIds).Select()
for _, user := range users {
userMap[user.UserId] = user
}
}
fmt.Println("用户数据为 : ", userMap)
for _, item := range items {
resultByte, err := json.Marshal(item)
result := string(resultByte)
......@@ -297,7 +307,6 @@ 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 {
logger.Error(err.Error())
fmt.Println(err.Error())
}
......@@ -306,9 +315,12 @@ func main() {
priceActivityMongo.ActivityId = gjson.Get(result, "activity_id").Int()
priceActivityMongo.OrderId = gjson.Get(result, "order_id").Int()
priceActivityMongo.UserId = gjson.Get(result, "user_id").Int()
priceActivityMongo.Mobile = gjson.Get(result, "mobile").String()
priceActivityMongo.OrderAmount = gjson.Get(result, "total_amount").Float()
priceActivityMongo.Pf = gjson.Get(result, "create_device").Int()
//priceActivityMongo.Mobile = gjson.Get(result, "mobile").String()
//priceActivityMongo.Pf = gjson.Get(result, "create_device").Int()
priceActivityMongo.Mobile = userMap[int(priceActivityMongo.UserId)].Mobile
priceActivityMongo.Pf = userMap[int(priceActivityMongo.UserId)].CreateDevice
fmt.Println("mongo数据为 : ", priceActivityMongo)
err = mongoConn.DB("ichunt").C("price_activity_statistics").Insert(&priceActivityMongo)
if err != nil {
logger.Error(err.Error())
......
......@@ -4,6 +4,7 @@ type UserMain struct {
UserId int `gorose:"user_id"`
Mobile string `gorose:"mobile"`
IsNew int `gorose:"is_new"`
CreateDevice int64 `gorose:"create_device"`
RegRemark string `gorose:"reg_remark"`
}
......
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