Commit c5675226 authored by 贾浩@五瓣科技's avatar 贾浩@五瓣科技

update telegram bind action

parent 668e385d
...@@ -35,6 +35,7 @@ func IsValidPlatform(platform string) bool { ...@@ -35,6 +35,7 @@ func IsValidPlatform(platform string) bool {
} }
const ( const (
TaskActionBind = "bind"
TaskActionJoin = "join" TaskActionJoin = "join"
TaskActionActive = "active" TaskActionActive = "active"
TaskActionFollow = "follow" TaskActionFollow = "follow"
...@@ -45,6 +46,7 @@ const ( ...@@ -45,6 +46,7 @@ const (
) )
var validActions = map[string]bool{ var validActions = map[string]bool{
TaskActionBind: true,
TaskActionJoin: true, TaskActionJoin: true,
TaskActionActive: true, TaskActionActive: true,
TaskActionFollow: true, TaskActionFollow: true,
...@@ -61,7 +63,7 @@ func IsValidAction(action string) bool { ...@@ -61,7 +63,7 @@ func IsValidAction(action string) bool {
var TaskAction = map[string][]string{ var TaskAction = map[string][]string{
TaskPlatformApp: {TaskActionActive, TaskActionInvite}, TaskPlatformApp: {TaskActionActive, TaskActionInvite},
TaskPlatformTelegram: {TaskActionJoin, TaskActionActive}, TaskPlatformTelegram: {TaskActionJoin, TaskActionActive, TaskActionBind},
TaskPlatformTwitter: {TaskActionFollow, TaskActionLike, TaskActionReply, TaskActionRetweet}, TaskPlatformTwitter: {TaskActionFollow, TaskActionLike, TaskActionReply, TaskActionRetweet},
} }
......
...@@ -7,6 +7,8 @@ import ( ...@@ -7,6 +7,8 @@ import (
"io" "io"
"net/http" "net/http"
"strings" "strings"
"taskcenter/constant"
dbModel "taskcenter/model/db"
"time" "time"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
...@@ -90,3 +92,12 @@ func httpPost(url string, body io.Reader) ([]byte, error) { ...@@ -90,3 +92,12 @@ func httpPost(url string, body io.Reader) ([]byte, error) {
defer resp.Body.Close() defer resp.Body.Close()
return io.ReadAll(resp.Body) return io.ReadAll(resp.Body)
} }
func (d *Dao) CheckTGBind(userId string) (ok bool, err error) {
// 任务完成表中是否存在该用户
sql := `SELECT COUNT(1) FROM %s AS T JOIN %s AS TH ON T.id = TH.task_id WHERE TH.user_id = ? AND T.platform = ? AND T.action = ? AND T.start >= ? AND T.end <= ? AND T.deleted_at IS NULL AND TH.deleted_at IS NULL`
sql = fmt.Sprintf(sql, (&dbModel.Task{}).TableName(), (&dbModel.TaskHistory{}).TableName())
var ct int64
err = d.db.Raw(sql, userId, constant.TaskPlatformTelegram, constant.TaskActionBind, time.Now().Unix(), time.Now().Unix()).Count(&ct).Error
return ct > 0, err
}
...@@ -78,6 +78,13 @@ func (s *Sync) SyncTask(taskId int, userId string) (ok bool, err error) { ...@@ -78,6 +78,13 @@ func (s *Sync) SyncTask(taskId int, userId string) (ok bool, err error) {
return false, err return false, err
} }
return taskDone, nil return taskDone, nil
case constant.TaskActionBind:
alreadyDone, err := s.d.CheckTGBind(userId)
if err != nil {
log.WithError(err).Error("check tg bind error")
return false, err
}
return !alreadyDone, nil
default: default:
return false, fmt.Errorf("unknown task action: %s", task.Action) return false, fmt.Errorf("unknown task action: %s", task.Action)
} }
......
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 to comment