Commit b0188ed3 by 朱继来

调整获取用户下单数

parent 16d40b61
Showing with 6 additions and 7 deletions
......@@ -30,11 +30,14 @@ func main() {
logger.InitLogger("file",logConfig)
logger.Init()
var current_time = time.Now().Unix()
// 獲取前一天零點
t := time.Now()
tm := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
yesterday_time := tm.AddDate(0, 0, -1).Unix()
db := dao.GetLiexinDb()
row, err := db.Queryx("SELECT user_id, FROM_UNIXTIME(create_time, \"%Y%m%d\") AS date, COUNT(*) AS count FROM `lie_order` " +
"WHERE user_id > 0 AND is_type = 0 AND create_time > ? GROUP BY user_id, date ORDER BY create_time", current_time)
"WHERE user_id > 0 AND is_type = 0 AND create_time > ? GROUP BY user_id, date ORDER BY create_time", yesterday_time)
defer db.Close()
if err != nil {
......@@ -46,11 +49,6 @@ func main() {
crm_db := dao.GetDb()
defer crm_db.Close()
if !row.Next() {
fmt.Println("未获取到用户下单数")
return
}
for row.Next() {
var user_order_count model.UserOrderCount
row.StructScan(&user_order_count)
......@@ -62,6 +60,7 @@ func main() {
continue
}
var current_time = time.Now().Unix()
_, err := crm_db.Exec("insert into lie_user_order_count (user_id, date, count, create_time) values (?, ?, ?, ?)", user_order_count.User_Id, user_order_count.Date,
user_order_count.Count, current_time)
......
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