61 lines
1.7 KiB
Go
Executable File
61 lines
1.7 KiB
Go
Executable File
package model
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
)
|
|
|
|
var _ NhTaskModel = (*customNhTaskModel)(nil)
|
|
|
|
const (
|
|
// 0=follow_twitter,1=bind_twitter,2=cast_twitter,3=publish_twitter,4=repost_twitter,5=watch_youtube,6=follow_youtube,7=bind_discord,8=join_telegram,9=daily_pay
|
|
TASKTYPE_FOLLOW_TWITTER = 0
|
|
TASKTYPE_BIND_TWITTER = 1
|
|
TASKTYPE_CAST_TWITTER = 2
|
|
TASKTYPE_PUBLISH_TWITTER = 3
|
|
TASKTYPE_REPOST_TWITTER = 4
|
|
TASKTYPE_WATCH_YOUTUBE = 5
|
|
TASKTYPE_FOLLOW_YOUTUBE = 6
|
|
TASKTYPE_BIND_DISCORD = 7
|
|
TASKTYPE_JOIN_TELEGRAM = 8
|
|
TASKTYPE_DAILY_PAY = 9
|
|
TASKTYPE_INVITE_USER = 10
|
|
)
|
|
|
|
type (
|
|
// NhTaskModel is an interface to be customized, add more methods here,
|
|
// and implement the added methods in customNhTaskModel.
|
|
NhTaskModel interface {
|
|
nhTaskModel
|
|
withSession(session sqlx.Session) NhTaskModel
|
|
FindTasksByCommunity(ctx context.Context, communityId uint) ([]*NhTask, error)
|
|
}
|
|
|
|
customNhTaskModel struct {
|
|
*defaultNhTaskModel
|
|
}
|
|
)
|
|
|
|
func (m *customNhTaskModel) FindTasksByCommunity(ctx context.Context, communityId uint) ([]*NhTask, error) {
|
|
query := fmt.Sprintf("select %s from %s where `status` = 1 and community_id = ? order by `sort`", nhTaskRows, m.table)
|
|
var tasks []*NhTask
|
|
err := m.conn.QueryRowsCtx(ctx, &tasks, query, communityId)
|
|
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
|
return nil, err
|
|
}
|
|
return tasks, nil
|
|
}
|
|
|
|
// NewNhTaskModel returns a model for the database table.
|
|
func NewNhTaskModel(conn sqlx.SqlConn) NhTaskModel {
|
|
return &customNhTaskModel{
|
|
defaultNhTaskModel: newNhTaskModel(conn),
|
|
}
|
|
}
|
|
|
|
func (m *customNhTaskModel) withSession(session sqlx.Session) NhTaskModel {
|
|
return NewNhTaskModel(sqlx.NewSqlConnFromSession(session))
|
|
}
|