新增查看推文模块
This commit is contained in:
@@ -60,19 +60,27 @@ func (u *TwitterAccountService) OfflineAllAccount() bool {
|
||||
// 获取可用账号
|
||||
func (u *TwitterAccountService) GetAvailableAccount(params *models.TwitterAccount) []models.TwitterAccount {
|
||||
var users []models.TwitterAccount
|
||||
res := u.db.Model(&models.TwitterAccount{}).Where(`status = ? AND (login_status != "账号异常" OR login_status IS NULL)`, params.Status)
|
||||
res := u.db.Model(&models.TwitterAccount{}).Where(`type = ? AND (login_status != "账号异常" OR login_status IS NULL)`, params.Type)
|
||||
// if params.Username != "" {
|
||||
// res.Where("username LIKE ?", "%"+params.Username+"%")
|
||||
// }
|
||||
res.Order("id DESC").Find(&users)
|
||||
|
||||
return users
|
||||
}
|
||||
|
||||
// 获取ID范围内的账号
|
||||
func (u *TwitterAccountService) GetAccountListByIdRange(minId, maxId int64) []models.TwitterAccount {
|
||||
var users []models.TwitterAccount
|
||||
res := u.db.Model(&models.TwitterAccount{}).Where(`id >= ? AND id <= ?`, minId, maxId)
|
||||
res.Order("id DESC").Find(&users)
|
||||
return users
|
||||
}
|
||||
|
||||
// 获取养号未运行或者运行失败的账号
|
||||
// 获取未运行或者运行失败的账号
|
||||
func (u *TwitterAccountService) GetAccountListByStatus(params *models.TwitterAccount) []models.TwitterAccount {
|
||||
var users []models.TwitterAccount
|
||||
res := u.db.Model(&models.TwitterAccount{}).Where(`status = ? AND (login_status != "账号异常" OR login_status IS NULL)`, params.Status)
|
||||
res := u.db.Model(&models.TwitterAccount{}).Where(`type = ? AND (login_status != "账号异常" OR login_status IS NULL) AND (status != ? OR status IS NULL)`, params.Type, params.Status)
|
||||
// if params.Username != "" {
|
||||
// res.Where("username LIKE ?", "%"+params.Username+"%")
|
||||
// }
|
||||
@@ -82,7 +90,13 @@ func (u *TwitterAccountService) GetAccountListByStatus(params *models.TwitterAcc
|
||||
|
||||
// 清空状态字段
|
||||
func (u *TwitterAccountService) ClearAccountStatus(params *models.TwitterAccount) bool {
|
||||
u.db.Model(&models.TwitterAccount{}).Where("status = ?", params.Status).Update("status", nil)
|
||||
u.db.Model(&models.TwitterAccount{}).Where("type = ?", params.Type).Update("status", nil)
|
||||
return true
|
||||
}
|
||||
|
||||
// 清空状态字段
|
||||
func (u *TwitterAccountService) ChangeAccountStatusByStatus(params *models.TwitterAccount, status string) bool {
|
||||
u.db.Model(&models.TwitterAccount{}).Where("status = ?", params.Status).Update("status", status)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -90,3 +104,7 @@ func (u *TwitterAccountService) Update(id int64, params *models.TwitterAccount)
|
||||
params.UpdateTime = time.Now().Unix()
|
||||
u.db.Model(&models.TwitterAccount{}).Where("id = ?", id).Updates(params)
|
||||
}
|
||||
|
||||
func (u *TwitterAccountService) Delete(id int64) {
|
||||
u.db.Delete(&models.TwitterAccount{}, id)
|
||||
}
|
||||
|
||||
25
services/twitter_post_service.go
Normal file
25
services/twitter_post_service.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"go-account-register/models"
|
||||
"go-account-register/utils"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type TwitterPostService struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func InitTwitterPostService() *TwitterPostService {
|
||||
db := utils.GetDB()
|
||||
return &TwitterPostService{db: db}
|
||||
}
|
||||
|
||||
func (s *TwitterPostService) GetAll() []models.TwitterPost {
|
||||
var post []models.TwitterPost
|
||||
res := s.db.Model(&models.TwitterPost{}).Where(`status = ? `, 1)
|
||||
|
||||
res.Order("id DESC").Find(&post)
|
||||
return post
|
||||
}
|
||||
Reference in New Issue
Block a user