51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
package cardredeemcookie
|
|
|
|
import (
|
|
"context"
|
|
"github.com/gogf/gf/v2/os/glog"
|
|
"github.com/gogf/gf/v2/os/gtime"
|
|
"kami/internal/consts"
|
|
"kami/internal/dao"
|
|
"kami/internal/model/do"
|
|
"kami/internal/model/entity"
|
|
"kami/utility/config"
|
|
"time"
|
|
|
|
"github.com/duke-git/lancet/v2/pointer"
|
|
"github.com/gogf/gf/errors/gerror"
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
)
|
|
|
|
// ScheduleAccount 调度账号
|
|
func (s *sCardReddemCookie) ScheduleAccount(ctx context.Context, tx gdb.TX) (output *entity.V1CardRedeemCookieInfo, err error) {
|
|
cookie, err := s.GetRandomCookie(ctx, tx)
|
|
if err != nil {
|
|
return nil, gerror.Wrap(err, "获取随机账号失败")
|
|
}
|
|
if pointer.IsNil(cookie) || cookie.Id <= 0 {
|
|
return nil, gerror.New("没有可用的账号")
|
|
}
|
|
return cookie, nil
|
|
}
|
|
|
|
// UnlockAccount 解封临时封禁的账号
|
|
func (s *sCardReddemCookie) UnlockAccount(ctx context.Context, tx gdb.TX) {
|
|
m := dao.V1CardRedeemCookieInfo.Ctx(ctx).DB(config.GetDatabaseV1())
|
|
if tx != nil {
|
|
m = m.TX(tx)
|
|
}
|
|
if _, err := m.Where(dao.V1CardRedeemCookieInfo.Columns().Status, consts.CardRedeemCookieStatusDailyDisable).
|
|
WhereLT(dao.V1CardRedeemCookieInfo.Columns().UpdatedAt, gtime.Now().StartOfDay()).Update(do.V1CardRedeemCookieInfo{
|
|
Status: consts.CardRedeemCookieStatusNormal,
|
|
}); err != nil {
|
|
glog.Error(ctx, "解封今日封禁的账号失败", err)
|
|
}
|
|
if _, err := m.Where(dao.V1CardRedeemCookieInfo.Columns().Status, consts.CardRedeemCookieStatusTmpDisable).
|
|
WhereLT(dao.V1CardRedeemCookieInfo.Columns().UpdatedAt, gtime.Now().Add(-time.Minute*10)).Update(do.V1CardRedeemCookieInfo{
|
|
Status: consts.CardRedeemCookieStatusNormal,
|
|
}); err != nil {
|
|
glog.Error(ctx, "解封临时封禁的账号失败", err)
|
|
}
|
|
return
|
|
}
|