Commit 05cfc816 by mushishixian

temp

parent 9d828ec5
2021-09-28 16:54:05.462 ERROR (main.go:main.main:130) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:54:05.574 ERROR (main.go:main.main:130) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:54:05.698 ERROR (main.go:main.main:130) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:54:05.815 ERROR (main.go:main.main:130) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:54:05.94 ERROR (main.go:main.main:130) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:54:06.079 ERROR (main.go:main.main:130) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:54:06.19 ERROR (main.go:main.main:130) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:54:06.296 ERROR (main.go:main.main:130) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:54:06.413 ERROR (main.go:main.main:130) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:54:06.529 ERROR (main.go:main.main:130) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:54:06.654 ERROR (main.go:main.main:130) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:54:07.098 ERROR (main.go:main.main:130) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:58:37.394 ERROR (main.go:main.main:133) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:58:37.519 ERROR (main.go:main.main:133) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:58:37.761 ERROR (main.go:main.main:133) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:58:37.884 ERROR (main.go:main.main:133) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:58:38.018 ERROR (main.go:main.main:133) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:58:38.152 ERROR (main.go:main.main:133) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:58:38.261 ERROR (main.go:main.main:133) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:58:38.362 ERROR (main.go:main.main:133) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:58:38.462 ERROR (main.go:main.main:133) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:58:38.587 ERROR (main.go:main.main:133) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:58:38.695 ERROR (main.go:main.main:133) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:58:38.795 ERROR (main.go:main.main:133) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
2021-09-28 16:58:39.231 ERROR (main.go:main.main:133) Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') and is_new = ? LIMIT 1' at line 1
......@@ -20,6 +20,7 @@ var ConfigDir string
var LogDir string
var err error
var engine *gorose.Engin
var orderEngine *gorose.Engin
var specialEngine *gorose.Engin
var mongoConn *mgo.Session
......@@ -52,12 +53,17 @@ func initLog() {
//初始化数据库
func initDB() {
dsn := util.Configs.Liexin_databases.Dns
orderDsn := util.Configs.Liexin_order_databases.Dns
specialDsn := util.Configs.Special_databases.Dns
//engine.GetLogger().
engine, err = gorose.Open(&gorose.Config{Driver: "mysql", Dsn: dsn})
if err != nil {
panic(err)
}
orderEngine, err = gorose.Open(&gorose.Config{Driver: "mysql", Dsn: orderDsn})
if err != nil {
panic(err)
}
specialEngine, err = gorose.Open(&gorose.Config{Driver: "mysql", Dsn: specialDsn})
if err != nil {
panic(err)
......@@ -72,11 +78,16 @@ func SpecialDB() gorose.IOrm {
return specialEngine.NewOrm()
}
func OrderDB() gorose.IOrm {
return orderEngine.NewOrm()
}
//有货提醒
func main() {
//先去遍历数据库,全部过一遍
db := DB()
specialDb := SpecialDB()
orderDb := OrderDB()
mongoConn, err = model.GetMongoConn(util.Configs.Mongo_config)
defer func() {
db.Close()
......@@ -84,30 +95,48 @@ func main() {
mongoConn.Close()
}()
fmt.Println("开始")
//首先去找最后的更新时间,一般来说找统计表最后一条记录的时间就对了
updateTime, _ := specialDb.Reset().Table("lie_activity_statistics").OrderBy("id desc").Value("update_time")
if updateTime == nil {
updateTime = 1
}
updateTime = 1
//先去取出所有的正在进行的活动列表
var giftActivityList []model.GiftActivity
err = specialDb.Reset().Table(&giftActivityList).Fields("id,start_time,end_time").
Where("end_time", ">", updateTime).Select()
if err != nil {
logger.Error(err.Error())
fmt.Println(err.Error())
}
//统计满赠活动******************
for _, activity := range giftActivityList {
orderNum, _ := db.Reset().Table("lie_order_gift").Where("activity_id", activity.Id).Where("status", "!=", -1).Count()
newUserNum, _ := db.Reset().Table("lie_order_gift").LeftJoin("lie_user_main on lie_order_gift.user_id = lie_user_main.user_id").
Where("lie_order_gift.activity_id", activity.Id).Where("lie_user_main.is_new", 1).Where("lie_order_gift.status", "!=", -1).Count()
orderNum, _ := orderDb.Reset().Table("lie_order_gift").Where("activity_id", activity.Id).Where("status", "!=", -1).Count()
//先找出这个活动对应的所有非取消的满赠礼物(根据user_id)去重
orderGiftUserIds, _ := orderDb.Reset().Table("lie_order_gift").Where("lie_order_gift.activity_id", activity.Id).
Where("lie_order_gift.status", "!=", -1).GroupBy("user_id").Pluck("user_id")
var newUserNum int64
var userIds []interface{}
newUserNum = 0
if orderGiftUserIds != nil {
userIds = orderGiftUserIds.([]interface{})
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 {
logger.Error(err.Error())
fmt.Println(err.Error())
}
}
}
//先查询统计是否存在
count, _ := specialDb.Reset().Table("lie_activity_statistics").Where("activity_id", activity.Id).
Where("type", 2).Count()
data := make(map[string]interface{})
fmt.Println("活动iD : " + strconv.Itoa(activity.Id) + ",订单数量 : " + strconv.Itoa(int(orderNum)))
fmt.Println("活动iD : " + strconv.Itoa(activity.Id) + ",订单数量 : " + strconv.Itoa(int(orderNum)) + ",新用户数量 : " + strconv.Itoa(int(newUserNum)))
data["order_num"] = orderNum
data["new_user_num"] = newUserNum
data["update_time"] = time.Now().Unix()
......@@ -115,7 +144,7 @@ func main() {
data["type"] = 2
if count > 0 {
_, err = specialDb.Reset().Table("lie_activity_statistics").Where("activity_id", activity.Id).
Where("type",2).Data(data).Update()
Where("type", 2).Data(data).Update()
fmt.Println(specialDb.LastSql())
if err != nil {
logger.Error(err.Error())
......@@ -197,9 +226,31 @@ 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")
//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).
GroupBy("user_id").Pluck("user_id")
var newUserNum int64
var userIds []interface{}
newUserNum = 0
if orderActivityUserIds != nil {
userIds = orderActivityUserIds.([]interface{})
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 {
logger.Error(err.Error())
fmt.Println(err.Error())
}
}
}
//先查询统计是否存在
count, _ := specialDb.Reset().Table("lie_activity_statistics").Where("activity_id", activity.Id).
Where("type", 1).Count()
......@@ -210,7 +261,7 @@ func main() {
data["activity_id"] = activity.Id
data["type"] = 1
if count > 0 {
_, err = specialDb.Reset().Table("lie_activity_statistics").Where("activity_id", activity.Id).Where("type",1).
_, err = specialDb.Reset().Table("lie_activity_statistics").Where("activity_id", activity.Id).Where("type", 1).
Data(data).Update()
if err != nil {
logger.Error(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