1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package activeUsers
- import (
- "leadGeneration/entity/power"
- "leadGeneration/public"
- "time"
- )
- /*
- ⚠️注意
- user_countbyhour 表只有一个月的数据
- */
- // GetWeekActiveFreeUsers 获取周活无权限用户
- func GetWeekActiveFreeUsers() (rData []string) {
- now := time.Now()
- _, start_m, start_d := now.Date()
- _, end_m, end_d := now.AddDate(0, 0, -7).Date()
- var sql string
- var param []interface{}
- if start_m != end_m {
- //跨月
- sql = "SELECT DISTINCT(user_mongoid) FROM user_countbyhour WHERE day >= ? OR day < ?"
- param = []interface{}{start_d, end_d}
- } else {
- //非跨月
- sql = "SELECT DISTINCT(user_mongoid) FROM user_countbyhour WHERE day >= ? AND day < ?"
- param = []interface{}{start_d, end_d}
- }
- res := public.ActiveMysql.SelectBySql(sql, param...)
- if res == nil || len(*res) == 0 {
- return
- }
- rData = make([]string, 0, len(*res))
- for _, v := range *res {
- if userId, _ := v["user_mongoid"].(string); userId != "" {
- if !power.HasPower(userId) {
- rData = append(rData, userId)
- }
- }
- }
- return rData
- }
- // GetMonthActiveFreeUsers 获取月活用户
- // 有订阅或有搜索词的周活用户+最近7天注册的新用户无条件生
- func GetMonthActiveFreeUsers() (rData []string) {
- //表数据为近一个月,所以直接查询全部
- res := public.ActiveMysql.SelectBySql("SELECT user_mongoid,sum(search) AS total FROM user_countbyhour group by user_mongoid")
- if res == nil || len(*res) == 0 {
- return
- }
- rData = make([]string, 0, len(*res))
- for _, v := range *res {
- userId, _ := v["user_mongoid"].(string)
- if userId == "" {
- continue
- }
- //非会员
- if hasPower := power.HasPower(userId); hasPower {
- continue
- }
- //无搜索记录、无关键词
- if searchTotal, _ := v["total"].(int); searchTotal == 0 {
- //无订阅词
- if !power.HasSubscribe(userId) {
- continue
- }
- }
- rData = append(rData, userId)
- }
- return rData
- }
|