added logic for update privilege gigachat count
This commit is contained in:
parent
056d15094b
commit
130304d8ae
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gitea.pena/PenaSide/hlog"
|
||||
"gitea.pena/SQuiz/common/dal"
|
||||
"gitea.pena/SQuiz/worker/internal/answerwc"
|
||||
@ -18,7 +19,6 @@ import (
|
||||
"github.com/go-resty/resty/v2"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var zapOptions = []zap.Option{
|
||||
@ -115,7 +115,7 @@ func New(ctx context.Context, cfg initialize.Config, build Build) error {
|
||||
|
||||
checkWorker := privilegewc.NewCheckWorker(privilegewc.Deps{
|
||||
PrivilegeIDsDays: []string{"quizUnlimTime", "squizHideBadge"},
|
||||
PrivilegeIDsCount: []string{"quizCnt", "quizManual"},
|
||||
PrivilegeIDsCount: []string{"quizCnt", "quizManual", "quizGigaChat"},
|
||||
TickerInterval: time.Minute,
|
||||
PrivilegeDAL: pgdal,
|
||||
CustomerClient: clients.CustomerClient,
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"gitea.pena/SQuiz/common/dal"
|
||||
"gitea.pena/SQuiz/common/model"
|
||||
"gitea.pena/SQuiz/worker/internal/clients/gigachat"
|
||||
"gitea.pena/SQuiz/worker/internal/wctools"
|
||||
"github.com/twmb/franz-go/pkg/kgo"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
@ -55,6 +56,7 @@ type MessageGigaChat struct {
|
||||
QuizID int64 `json:"quiz_id"`
|
||||
Sex int32 `json:"sex"` // 0 - female, 1 - male, 2 - not sex
|
||||
Age string `json:"age"`
|
||||
AccountID string `json:"account_id"`
|
||||
}
|
||||
|
||||
type UpdJsonQuestionData struct {
|
||||
@ -146,5 +148,21 @@ func (r *GigaChatTaskScheduler) handleMessage(ctx context.Context, msg MessageGi
|
||||
r.logger.Error("failed to create updated question", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
|
||||
_, privileges, err := r.dal.AccountRepo.GetAccAndPrivilegeByEmail(ctx, msg.AccountID)
|
||||
if err != nil {
|
||||
r.logger.Error("failed to get acc/privilege", zap.Error(err))
|
||||
}
|
||||
|
||||
privilege := wctools.HasQuizGigaChatPrivilege(privileges)
|
||||
if privilege != nil {
|
||||
privilege.Amount--
|
||||
err = r.dal.AccountRepo.UpdatePrivilegeAmount(ctx, privilege.ID, privilege.Amount)
|
||||
if err != nil {
|
||||
r.logger.Error("failed to update privilege", zap.Error(err))
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -136,6 +136,15 @@ func HasQuizCntPrivilege(privileges []model.ShortPrivilege) *model.ShortPrivileg
|
||||
return nil
|
||||
}
|
||||
|
||||
func HasQuizGigaChatPrivilege(privileges []model.ShortPrivilege) *model.ShortPrivilege {
|
||||
for _, privilege := range privileges {
|
||||
if privilege.PrivilegeID == "quizGigaChat" && privilege.Amount > 0 {
|
||||
return &privilege
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ToJSON(data interface{}) (string, error) {
|
||||
result, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user