Commit 8315156d by mushishixian

修复冲突

parents 2f883c30 823df656
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
2021-10-11 15:31:43.514 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:43.624 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:43.739 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:43.848 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:43.957 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:44.073 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:44.182 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:44.29 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:44.398 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:44.482 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:44.574 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:44.674 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:44.774 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:44.875 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:44.982 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:31:45.092 ERROR (main.go:main.main:279) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:06.788 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:06.896 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:07.005 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:07.122 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:07.239 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:07.338 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:07.439 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:07.54 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:07.647 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:07.755 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:07.906 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:08.006 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:08.116 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:08.223 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:08.331 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:34:08.432 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:35:34.113 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:35:34.229 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:35:34.313 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:35:34.396 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:35:34.481 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:35:34.566 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:35:34.656 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:35:34.74 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:35:34.823 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:35:34.907 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:35:35.008 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
2021-10-11 15:35:35.107 ERROR (main.go:main.main:280) Error 1146: Table 'liexin.lie_order_activity_count' doesn't exist
......@@ -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,31 +95,47 @@ 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()
......@@ -116,7 +143,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())
......@@ -187,20 +214,35 @@ func main() {
}
}
//价格促销活动*****************
//价格促销活动统计***********************************************************************************************
var priceActivityList []model.PriceActivity
err = specialDb.Reset().Table(&priceActivityList).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 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")
orderNum, _ := orderDb.Reset().Table("lie_order_activity_count").Where("activity_id", activity.Id).Count("order_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()
......@@ -211,7 +253,8 @@ 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).
fmt.Println(data)
_, 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())
......@@ -225,16 +268,33 @@ func main() {
fmt.Println(err.Error())
}
}
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").
items, err := orderDb.Reset().
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)
......@@ -245,7 +305,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())
}
......@@ -254,9 +313,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())
......
package model
type UserMain struct {
UserId int `gorose:"user_id"`
Mobile string `gorose:"mobile"`
IsNew int `gorose:"is_new"`
RegRemark string `gorose:"reg_remark"`
UserId int `gorose:"user_id"`
Mobile string `gorose:"mobile"`
IsNew int `gorose:"is_new"`
CreateDevice int64 `gorose:"create_device"`
RegRemark string `gorose:"reg_remark"`
}
func (um *UserMain) TableName() string {
......
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