|
@@ -262,7 +262,6 @@ func CountMaxVisit() {
|
|
|
// @Description 日期相差天数
|
|
|
// @Date 2024/8/22
|
|
|
func VerifyDate(d1, d2 string) int {
|
|
|
- log.Println("d1: ", d1, "d2: ", d2)
|
|
|
if d1 == d2 {
|
|
|
return 0
|
|
|
}
|
|
@@ -284,13 +283,15 @@ var (
|
|
|
firstLoad2, firstLoad3 = true, true
|
|
|
|
|
|
mSearchMap = make(map[string]int)
|
|
|
+ mDetailMap = make(map[string]int)
|
|
|
)
|
|
|
|
|
|
func Count3DaysSearch() {
|
|
|
var (
|
|
|
- sql string
|
|
|
- count int
|
|
|
- total int64
|
|
|
+ sql string
|
|
|
+ countSql string
|
|
|
+ count int
|
|
|
+ total int64
|
|
|
)
|
|
|
|
|
|
// 判断当日第一次执行
|
|
@@ -306,13 +307,15 @@ func Count3DaysSearch() {
|
|
|
if firstLoad2 {
|
|
|
// 当日首次执行 1、全部归0 search_count
|
|
|
config.JianyuSubjectdb.ExecBySql("UPDATE dwd_f_crm_attribute_label SET search_count = 0")
|
|
|
- sql = "SELECT v.userid, b.uid, v.date, v.searchnum FROM dwd_f_userbase_visit_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.base_user_id WHERE DATE(date) BETWEEN DATE(NOW() - INTERVAL 3 DAY) AND DATE(NOW()) ORDER BY date ASC"
|
|
|
+ sql = "SELECT v.userid, b.uid, v.date, v.searchnum FROM dwd_f_userbase_visit_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.userid WHERE DATE(v.date) BETWEEN DATE(NOW() - INTERVAL 3 DAY) AND DATE(NOW()) ORDER BY v.date ASC"
|
|
|
+ countSql = "SELECT COUNT(v.id) FROM dwd_f_userbase_visit_info v WHERE DATE(date) BETWEEN DATE(NOW() - INTERVAL 3 DAY) AND DATE(NOW())"
|
|
|
} else {
|
|
|
aTime := time.Now().Add(-1 * time.Hour)
|
|
|
- sql = "SELECT v.userid, b.uid, v.date, v.searchnum FROM dwd_f_userbase_visit_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.base_user_id WHERE date >= " + aTime.Format(time.DateTime) + " ORDER BY date ASC"
|
|
|
+ sql = "SELECT v.userid, b.uid, v.date, v.searchnum FROM dwd_f_userbase_visit_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.userid WHERE v.date >= " + aTime.Format(time.DateTime) + " ORDER BY v.date ASC"
|
|
|
+ countSql = "SELECT COUNT(v.id) FROM dwd_f_userbase_visit_info v WHERE v.date >= " + aTime.Format(time.DateTime)
|
|
|
}
|
|
|
- total = config.JianyuSubjectdb.CountBySql(sql)
|
|
|
- log.Println("Count3DaysSearch getRecord---", total)
|
|
|
+ total = config.JianyuSubjectdb.CountBySql(countSql)
|
|
|
+ log.Println("Count3DaysSearch total---", total)
|
|
|
if total <= 0 {
|
|
|
return
|
|
|
}
|
|
@@ -320,26 +323,40 @@ func Count3DaysSearch() {
|
|
|
if err != nil {
|
|
|
log.Println("Count3DaysSearch---", err)
|
|
|
}
|
|
|
+ columns, err := rows.Columns()
|
|
|
for rows.Next() {
|
|
|
+ scanArgs := make([]interface{}, len(columns))
|
|
|
+ values := make([]interface{}, len(columns))
|
|
|
+ ret := make(map[string]interface{})
|
|
|
+ for k := range values {
|
|
|
+ scanArgs[k] = &values[k]
|
|
|
+ }
|
|
|
+ err = rows.Scan(scanArgs...)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("CountMaxVisit---", err)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ for i, col := range values {
|
|
|
+ if v, ok := col.([]uint8); ok {
|
|
|
+ ret[columns[i]] = string(v)
|
|
|
+ } else {
|
|
|
+ ret[columns[i]] = col
|
|
|
+ }
|
|
|
+ }
|
|
|
count++
|
|
|
if count%2000 == 0 {
|
|
|
log.Println("Count3DaysSearch current-------", count)
|
|
|
}
|
|
|
- var (
|
|
|
- userId string
|
|
|
- uid string
|
|
|
- mDate time.Time
|
|
|
- searchNum int
|
|
|
- )
|
|
|
- if err = rows.Scan(&userId, &uid, &mDate, &searchNum); err != nil {
|
|
|
- log.Fatal(err)
|
|
|
- }
|
|
|
- mSearchMap[uid] += searchNum
|
|
|
+ uid := common.ObjToString(ret["uid"])
|
|
|
+ num := common.IntAll(ret["searchnum"])
|
|
|
+ mSearchMap[uid] += num
|
|
|
}
|
|
|
_ = rows.Close()
|
|
|
|
|
|
for k, v := range mSearchMap {
|
|
|
- if b := config.JianyuSubjectdb.Update("dwd_f_crm_attribute_label", bson.M{"uid": k}, bson.M{"search_count": v}); !b {
|
|
|
+ if config.JianyuSubjectdb.CountBySql("SELECT COUNT(uid) FROM dwd_f_crm_attribute_label WHERE uid = ?", k) > 0 {
|
|
|
+ config.JianyuSubjectdb.ExecBySql("UPDATE dwd_f_crm_attribute_label SET search_count = search_count + ? WHERE uid = ?", v, k)
|
|
|
+ } else {
|
|
|
config.JianyuSubjectdb.Insert("dwd_f_crm_attribute_label", map[string]interface{}{
|
|
|
"uid": k,
|
|
|
"members_info": "昨日未浏览",
|
|
@@ -352,9 +369,10 @@ func Count3DaysSearch() {
|
|
|
|
|
|
func Count3DaysDetail() {
|
|
|
var (
|
|
|
- sql string
|
|
|
- count int
|
|
|
- total int64
|
|
|
+ sql string
|
|
|
+ countSql string
|
|
|
+ count int
|
|
|
+ total int64
|
|
|
)
|
|
|
|
|
|
// 判断当日第一次执行
|
|
@@ -370,13 +388,15 @@ func Count3DaysDetail() {
|
|
|
if firstLoad3 {
|
|
|
// 当日首次执行 1、全部归0 click_detail_count
|
|
|
config.JianyuSubjectdb.ExecBySql("UPDATE dwd_f_crm_attribute_label SET click_detail_count = 0")
|
|
|
- sql = "SELECT v.userid, b.uid, v.date, v.contentnum FROM dwd_f_userbase_visit_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.base_user_id WHERE DATE(date) BETWEEN DATE(NOW() - INTERVAL 3 DAY) AND DATE(NOW()) ORDER BY date ASC"
|
|
|
+ sql = "SELECT v.userid, b.uid, v.date, v.contentnum FROM dwd_f_userbase_visit_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.userid WHERE DATE(v.date) BETWEEN DATE(NOW() - INTERVAL 3 DAY) AND DATE(NOW()) ORDER BY v.date ASC"
|
|
|
+ countSql = "SELECT COUNT(v.id) FROM dwd_f_userbase_visit_info v WHERE DATE(date) BETWEEN DATE(NOW() - INTERVAL 3 DAY) AND DATE(NOW())"
|
|
|
} else {
|
|
|
aTime := time.Now().Add(-1 * time.Hour)
|
|
|
- sql = "SELECT v.userid, b.uid, v.date, v.contentnum FROM dwd_f_userbase_visit_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.base_user_id WHERE date >= " + aTime.Format(time.DateTime) + " ORDER BY date ASC"
|
|
|
+ sql = "SELECT v.userid, b.uid, v.date, v.contentnum FROM dwd_f_userbase_visit_info v LEFT JOIN dwd_f_userbase_baseinfo b ON v.userid = b.userid WHERE v.date >= " + aTime.Format(time.DateTime) + " ORDER BY v.date ASC"
|
|
|
+ countSql = "SELECT COUNT(v.id) FROM dwd_f_userbase_visit_info v WHERE v.date >= " + aTime.Format(time.DateTime)
|
|
|
}
|
|
|
- total = config.JianyuSubjectdb.CountBySql(sql)
|
|
|
- log.Println("Count3DaysDetail getRecord---", total)
|
|
|
+ total = config.JianyuSubjectdb.CountBySql(countSql)
|
|
|
+ log.Println("Count3DaysDetail total---", total)
|
|
|
if total <= 0 {
|
|
|
return
|
|
|
}
|
|
@@ -384,26 +404,40 @@ func Count3DaysDetail() {
|
|
|
if err != nil {
|
|
|
log.Println("Count3DaysDetail---", err)
|
|
|
}
|
|
|
+ columns, err := rows.Columns()
|
|
|
for rows.Next() {
|
|
|
+ scanArgs := make([]interface{}, len(columns))
|
|
|
+ values := make([]interface{}, len(columns))
|
|
|
+ ret := make(map[string]interface{})
|
|
|
+ for k := range values {
|
|
|
+ scanArgs[k] = &values[k]
|
|
|
+ }
|
|
|
+ err = rows.Scan(scanArgs...)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("CountMaxVisit---", err)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ for i, col := range values {
|
|
|
+ if v, ok := col.([]uint8); ok {
|
|
|
+ ret[columns[i]] = string(v)
|
|
|
+ } else {
|
|
|
+ ret[columns[i]] = col
|
|
|
+ }
|
|
|
+ }
|
|
|
count++
|
|
|
if count%2000 == 0 {
|
|
|
log.Println("Count3DaysDetail current-------", count)
|
|
|
}
|
|
|
- var (
|
|
|
- userId string
|
|
|
- uid string
|
|
|
- mDate time.Time
|
|
|
- contentNum int
|
|
|
- )
|
|
|
- if err = rows.Scan(&userId, &uid, &mDate, &contentNum); err != nil {
|
|
|
- log.Fatal(err)
|
|
|
- }
|
|
|
- mSearchMap[uid] += contentNum
|
|
|
+ uid := common.ObjToString(ret["uid"])
|
|
|
+ num := common.IntAll(ret["contentnum"])
|
|
|
+ mDetailMap[uid] += num
|
|
|
}
|
|
|
_ = rows.Close()
|
|
|
|
|
|
- for k, v := range mSearchMap {
|
|
|
- if b := config.JianyuSubjectdb.Update("dwd_f_crm_attribute_label", bson.M{"uid": k}, bson.M{"click_detail_count": v}); !b {
|
|
|
+ for k, v := range mDetailMap {
|
|
|
+ if config.JianyuSubjectdb.CountBySql("SELECT COUNT(uid) FROM dwd_f_crm_attribute_label WHERE uid = ?", k) > 0 {
|
|
|
+ config.JianyuSubjectdb.ExecBySql("UPDATE dwd_f_crm_attribute_label SET click_detail_count = click_detail_count + ? WHERE uid = ?", v, k)
|
|
|
+ } else {
|
|
|
config.JianyuSubjectdb.Insert("dwd_f_crm_attribute_label", map[string]interface{}{
|
|
|
"uid": k,
|
|
|
"members_info": "昨日未浏览",
|
|
@@ -415,9 +449,71 @@ func Count3DaysDetail() {
|
|
|
}
|
|
|
|
|
|
func VipExpire() {
|
|
|
+
|
|
|
+ var (
|
|
|
+ sql string
|
|
|
+ countSql string
|
|
|
+ total int64
|
|
|
+ count int
|
|
|
+ )
|
|
|
+
|
|
|
now := time.Now()
|
|
|
config.JianyuSubjectdb.ExecBySql("update dwd_f_crm_attribute_label set supersub = 0 where supersub = 1")
|
|
|
- config.JianyuSubjectdb.ExecBySql("UPDATE dwd_f_crm_attribute_label SET supersub = 1 WHERE product_type = '超级订阅' AND endtime > ?", now.Format(date.Date_Short_Layout))
|
|
|
config.JianyuSubjectdb.ExecBySql("update dwd_f_crm_attribute_label set areasubpkg = 0 where areasubpkg = 1")
|
|
|
- config.JianyuSubjectdb.ExecBySql("UPDATE dwd_f_crm_attribute_label SET areasubpkg = 1 WHERE product_type = '省份订阅包' AND endtime > ?", now.Format(date.Date_Short_Layout))
|
|
|
+
|
|
|
+ sql = fmt.Sprintf("select uid, product_type from dwd_f_data_equity_info WHERE product_type = '省份订阅包' or product_type = '超级订阅' AND endtime > %s", now.Format(date.Date_Short_Layout))
|
|
|
+ countSql = fmt.Sprintf("select count(id) from dwd_f_data_equity_info WHERE product_type = '省份订阅包' or product_type = '超级订阅' AND endtime > %s", now.Format(date.Date_Short_Layout))
|
|
|
+
|
|
|
+ total = config.JianyuSubjectdb.CountBySql(countSql)
|
|
|
+ log.Println("VipExpire total---", total)
|
|
|
+ if total <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ rows, err := config.JianyuSubjectdb.DB.Query(sql)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("VipExpire---", err)
|
|
|
+ }
|
|
|
+ columns, err := rows.Columns()
|
|
|
+ for rows.Next() {
|
|
|
+ scanArgs := make([]interface{}, len(columns))
|
|
|
+ values := make([]interface{}, len(columns))
|
|
|
+ ret := make(map[string]interface{})
|
|
|
+ for k := range values {
|
|
|
+ scanArgs[k] = &values[k]
|
|
|
+ }
|
|
|
+ err = rows.Scan(scanArgs...)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("VipExpire---", err)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ for i, col := range values {
|
|
|
+ if v, ok := col.([]uint8); ok {
|
|
|
+ ret[columns[i]] = string(v)
|
|
|
+ } else {
|
|
|
+ ret[columns[i]] = col
|
|
|
+ }
|
|
|
+ }
|
|
|
+ count++
|
|
|
+ if count%2000 == 0 {
|
|
|
+ log.Println("VipExpire current-------", count)
|
|
|
+ }
|
|
|
+
|
|
|
+ uid := common.ObjToString(ret["uid"])
|
|
|
+ ptype := common.ObjToString(ret["product_type"])
|
|
|
+ if config.JianyuSubjectdb.CountBySql("SELECT COUNT(uid) FROM dwd_f_crm_attribute_label WHERE uid = ?", uid) > 0 {
|
|
|
+ if ptype == "省份订阅包" {
|
|
|
+ config.JianyuSubjectdb.ExecBySql("UPDATE dwd_f_crm_attribute_label SET areasubpkg = 1 WHERE uid = ?", uid)
|
|
|
+ } else {
|
|
|
+ config.JianyuSubjectdb.ExecBySql("UPDATE dwd_f_crm_attribute_label SET supersub = 1 WHERE uid = ?", uid)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ config.JianyuSubjectdb.Insert("dwd_f_crm_attribute_label", map[string]interface{}{
|
|
|
+ "uid": uid,
|
|
|
+ "members_info": "昨日未浏览",
|
|
|
+ "updatetime": time.Now(),
|
|
|
+ common.ObjToString(common.If(ptype == "省份订阅包", "areasubpkg", "supersub")): 1,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _ = rows.Close()
|
|
|
}
|