|
@@ -0,0 +1,60 @@
|
|
|
+package lunarActivity
|
|
|
+
|
|
|
+import (
|
|
|
+ "context"
|
|
|
+ "fmt"
|
|
|
+ "github.com/gogf/gf/v2/frame/g"
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+ "workTasks/userSign/match"
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ ctx = context.TODO()
|
|
|
+ ActiveCodeMap map[string]interface{}
|
|
|
+)
|
|
|
+
|
|
|
+func init() {
|
|
|
+ ActiveCodeMap = g.Cfg().MustGet(ctx, "activeCode.pcCode").Map()
|
|
|
+}
|
|
|
+
|
|
|
+func Active() {
|
|
|
+ var sqlIds, delCode, pcBaseId, wxBaseId, appBaseId []string
|
|
|
+ rPc, err := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT(baseUserId) as baseUserId FROM user_log_byHour WHERE create_time >'%s' AND s_source ='pc';`, time.Now().AddDate(0, 0, -30).Format(time.DateTime)))
|
|
|
+ if err == nil && !rPc.IsEmpty() {
|
|
|
+ for _, m := range rPc.List() {
|
|
|
+ // 插入pc30天活跃用户
|
|
|
+ pcBaseId = append(pcBaseId, gconv.String(m["baseUserId"]))
|
|
|
+ }
|
|
|
+ if len(pcBaseId) > 0 {
|
|
|
+ delCode = append(delCode, gconv.String(ActiveCodeMap["pcCode"]))
|
|
|
+ sqlIds = append(sqlIds, fmt.Sprintf(`('%s', 'name_value1', bitmapBuild([toUInt64(%s)]), groupid_value1, 'created_at_value1', 'created_by_value1', bit_num_value1) `, ActiveCodeMap["pcCode"], strings.Join(pcBaseId, ",")))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rWx, err1 := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT(baseUserId) as baseUserId FROM user_log_byHour WHERE create_time >'%s' AND s_source ='wx';`, time.Now().AddDate(0, 0, -30).Format(time.DateTime)))
|
|
|
+ if err1 == nil && !rWx.IsEmpty() {
|
|
|
+ for _, m := range rWx.List() {
|
|
|
+ // 插入wx30天活跃用户
|
|
|
+ wxBaseId = append(wxBaseId, gconv.String(m["baseUserId"]))
|
|
|
+ }
|
|
|
+ if len(wxBaseId) > 0 {
|
|
|
+ delCode = append(delCode, gconv.String(ActiveCodeMap["wxCode"]))
|
|
|
+ sqlIds = append(sqlIds, fmt.Sprintf(`('%s', 'name_value1', bitmapBuild([toUInt64(%s)]), groupid_value1, 'created_at_value1', 'created_by_value1', bit_num_value1) `, ActiveCodeMap["wxCode"], strings.Join(wxBaseId, ",")))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rApp, err2 := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT(baseUserId) as baseUserId FROM user_log_byHour WHERE create_time >'%s' AND s_source ='app';`, time.Now().AddDate(0, 0, -30).Format(time.DateTime)))
|
|
|
+ if err2 == nil && !rApp.IsEmpty() {
|
|
|
+ for _, m := range rApp.List() {
|
|
|
+ // 插入app30天活跃用户
|
|
|
+ appBaseId = append(appBaseId, gconv.String(m["baseUserId"]))
|
|
|
+ }
|
|
|
+ if len(appBaseId) > 0 {
|
|
|
+ delCode = append(delCode, gconv.String(ActiveCodeMap["appCode"]))
|
|
|
+ sqlIds = append(sqlIds, fmt.Sprintf(`('%s', 'name_value1', bitmapBuild([toUInt64(%s)]), groupid_value1, 'created_at_value1', 'created_by_value1', bit_num_value1) `, ActiveCodeMap["appCode"], strings.Join(appBaseId, ",")))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(sqlIds) > 0 {
|
|
|
+ match.SetUserTag(delCode, sqlIds)
|
|
|
+ }
|
|
|
+}
|