Browse Source

wip:增加注册时间

wangkaiyue 1 year ago
parent
commit
4729cd8e8b
1 changed files with 24 additions and 8 deletions
  1. 24 8
      doFreeClueSign/job/mamager.go

+ 24 - 8
doFreeClueSign/job/mamager.go

@@ -2,6 +2,7 @@ package job
 
 import (
 	"context"
+	"doFreeClueSign/db"
 	"doFreeClueSign/public"
 	"fmt"
 	"github.com/gogf/gf/v2/container/gmap"
@@ -14,8 +15,9 @@ import (
 )
 
 type JobManager struct {
-	payUser *gmap.Map //付费账户
-	lastRun *struct {
+	payUser  *gmap.Map //付费账户
+	register *gmap.Map
+	lastRun  *struct {
 		BindPhone   string `json:"bindPhone"`
 		AgainSub    string `json:"againSub"`
 		NewActivity string `json:"newActivity"`
@@ -129,22 +131,22 @@ func (jm *JobManager) FilterPayUserAndSaveDb(ctx context.Context, value interfac
 			return nil
 		}
 		operationTime = time.Unix(msg.TimeStamp, 0).Format(time.DateTime)
-		sql += `(mogUserId,sub_again_date,create_time)VALUES (?, ?, ?)ON DUPLICATE KEY UPDATE sub_again_date=?`
-		val = append(val, msg.MgoUserID, operationTime, now, operationTime)
+		sql += `(mogUserId,register_time,sub_again_date,create_time)VALUES (?,?,?,?)ON DUPLICATE KEY UPDATE sub_again_date=?`
+		val = append(val, msg.MgoUserID, jm.GetAndCacheRegisterDate(msg.MgoUserID), operationTime, now, operationTime)
 	} else if msg, ok := value.(*public.BindMsg); ok {
 		if jm.payUser.Contains(msg.MgoUserID) {
 			return nil
 		}
 		operationTime = time.Unix(msg.TimeStamp, 0).Format(time.DateTime)
-		sql += `(mogUserId,phone,bind_phone_date,create_time)VALUES (?, ?, ?, ?)ON DUPLICATE KEY UPDATE phone=?, bind_phone_date=?`
-		val = append(val, msg.MgoUserID, msg.Phone, operationTime, now, msg.Phone, operationTime)
+		sql += `(mogUserId,register_time,phone,bind_phone_date,create_time)VALUES (?,?,?,?,?)ON DUPLICATE KEY UPDATE phone=?, bind_phone_date=?`
+		val = append(val, msg.MgoUserID, jm.GetAndCacheRegisterDate(msg.MgoUserID), msg.Phone, operationTime, now, msg.Phone, operationTime)
 	} else if msg, ok := value.(*public.NewActiveMsg); ok {
 		if jm.payUser.Contains(msg.MgoUserID) {
 			return nil
 		}
 		operationTime = time.Unix(msg.TimeStamp, 0).Format(time.DateTime)
-		sql += `(mogUserId,act_again_date,create_time)VALUES (?, ?, ?)ON DUPLICATE KEY UPDATE act_again_date=?`
-		val = append(val, msg.MgoUserID, operationTime, now, operationTime)
+		sql += `(mogUserId,register_time,act_again_date,create_time)VALUES (?,?,?,?)ON DUPLICATE KEY UPDATE act_again_date=?`
+		val = append(val, msg.MgoUserID, jm.GetAndCacheRegisterDate(msg.MgoUserID), operationTime, now, operationTime)
 	} else {
 		return fmt.Errorf("未知类型")
 	}
@@ -154,3 +156,17 @@ func (jm *JobManager) FilterPayUserAndSaveDb(ctx context.Context, value interfac
 	}
 	return nil
 }
+
+// GetAndCacheRegisterDate 获取缓存用户注册时间
+func (jm *JobManager) GetAndCacheRegisterDate(mgoUserId string) string {
+	if registerDate := gconv.String(jm.register.Get(mgoUserId)); registerDate != "" {
+		return registerDate
+	}
+	rMap, _ := db.MG.DB().FindById("user", mgoUserId, `{"l_registedate":1}`)
+	if rMap == nil || len(*rMap) == 0 {
+		return ""
+	}
+	date := time.Unix(gconv.Int64((*rMap)["l_registedate"]), 0).Format(time.DateTime)
+	jm.register.Set(mgoUserId, date)
+	return date
+}