Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 修复开放题 did 证书不发放 #136

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion internal/app/dao/quest.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (d *Dao) GetQuestList(req *request.GetQuestListRequest) (questList []respon
return questList, total, err
}

func (d *Dao) GetQuestByTokenIDWithLang(language string, tokenID string) (quest response.GetQuestRes, err error) {
func (d *Dao) GetQuestDetailByTokenIDWithLang(language string, tokenID string) (quest response.GetQuestRes, err error) {
err = d.db.Model(&model.Quest{}).Select("quest.*,COALESCE(tr.title,quest.title) as title,COALESCE(tr.description,quest.description) as description,"+
"COALESCE(tr.meta_data,quest.meta_data) as meta_data,COALESCE(tr.quest_data,quest.quest_data) as quest_data").
Joins("LEFT JOIN quest_translated tr ON quest.token_id = tr.token_id AND tr.language = ?", language).Where("quest.token_id", tokenID).First(&quest.Quest).Error
Expand All @@ -124,6 +124,16 @@ func (d *Dao) GetQuestByTokenIDWithLang(language string, tokenID string) (quest
return
}

func (d *Dao) GetQuestByTokenIDWithLang(language string, tokenID string) (quest model.Quest, err error) {
err = d.db.Model(&model.Quest{}).Select("quest.*,COALESCE(tr.title,quest.title) as title,COALESCE(tr.description,quest.description) as description,"+
"COALESCE(tr.meta_data,quest.meta_data) as meta_data,COALESCE(tr.quest_data,quest.quest_data) as quest_data").
Joins("LEFT JOIN quest_translated tr ON quest.token_id = tr.token_id AND tr.language = ?", language).Where("quest.token_id", tokenID).First(&quest).Error
if err != nil {
return quest, err
}
return
}

func (d *Dao) GetQuestByTokenID(tokenID string) (quest model.Quest, err error) {
err = d.db.Model(&model.Quest{}).Where("token_id", tokenID).First(&quest).Error
return
Expand Down
2 changes: 1 addition & 1 deletion internal/app/initialize/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func RegisterTables(db *gorm.DB) {
func initMultiChainV2(db *gorm.DB) {
// 查询是否存在链ID
var chainID int64
err := db.Model(&model.Collection{}).Select("max(chain_id)").Scan(&chainID).Error
err := db.Model(&model.Collection{}).Select("COALESCE(max(chain_id), 0)").Scan(&chainID).Error
if err != nil && err != gorm.ErrRecordNotFound {
panic("initMultiChainV2 failed")
}
Expand Down
5 changes: 3 additions & 2 deletions internal/app/model/user_open_quest.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type UserOpenQuest struct {
OpenQuestScore int64 `gorm:"column:open_quest_score;default:0;comment:开放题分数" json:"open_quest_score" form:"open_quest_score"` // 开放题分数
OpenQuestReviewStatus uint8 `gorm:"column:open_quest_review_status;default:0;comment:评阅开放题状态 1 未审核 2 已审核" json:"open_quest_review_status" form:"open_quest_review_status"` // // 评阅开放题状态 1 未审核 2 已审核
OpenQuestReviewTime time.Time `gorm:"column:open_quest_review_time;comment:评阅开放题时间" json:"open_quest_review_time" form:"open_quest_review_time"`
Pass bool `gorm:"column:pass;default:false;comment:挑战通过状态" json:"pass" form:"pass"` // 状态 false 挑战未通过 true 挑战通过
UserScore int64 `gorm:"column:user_score" form:"user_score" json:"user_score"` // 分数
CommitTime time.Time `gorm:"column:commit_time;comment:提交时间" json:"commit_time" form:"commit_time"` // 提交时间
Pass bool `gorm:"column:pass;default:false;comment:挑战通过状态" json:"pass" form:"pass"` // 状态 false 挑战未通过 true 挑战通过
UserScore int64 `gorm:"column:user_score" form:"user_score" json:"user_score"` // 分数
}
4 changes: 2 additions & 2 deletions internal/app/service/badge_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *Service) SubmitClaimShareV2(address string, req request.SubmitClaimShar
if req.Uri != "" && req.Uri != quest.Uri {
return res, errors.New("QuestUpdate")
}
_, pass, err := s.AnswerCheck(s.c.Quest.EncryptKey, req.Answer, address, req.Score, &quest.Quest, true)
_, pass, err := s.AnswerCheck(s.c.Quest.EncryptKey, req.Answer, address, req.Score, &quest, true)
if err != nil {
log.Errorv("AnswerCheck error", zap.Error(err))
return res, errors.New("UnexpectedError")
Expand All @@ -82,7 +82,7 @@ func (s *Service) SubmitClaimShareV2(address string, req request.SubmitClaimShar
app = "decert_solana"
}
// 解析用户答案
answer, err := s.AnswerParse(s.c.Quest.EncryptKey, req.Answer, address, &quest.Quest)
answer, err := s.AnswerParse(s.c.Quest.EncryptKey, req.Answer, address, &quest)
if err != nil {
log.Errorv("AnswerParse error", zap.Error(err))
return res, errors.New("UnexpectedError")
Expand Down
2 changes: 2 additions & 0 deletions internal/app/service/challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"github.com/tidwall/gjson"
"go.uber.org/zap"
"time"
)

func (s *Service) GetUserChallengeList(req request.GetChallengeListRequest) (res []response.GetChallengeListRes, total int64, err error) {
Expand Down Expand Up @@ -86,6 +87,7 @@ func (s *Service) CreateChallengeLog(req request.SaveChallengeLogRequest, lang s
TokenId: req.TokenId,
Answer: []byte(gjson.Parse(req.Answer).Raw),
OpenQuestReviewStatus: 1,
CommitTime: time.Now(),
})
if err != nil {
return errors.New("OperationFailed")
Expand Down
2 changes: 1 addition & 1 deletion internal/app/service/quest.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *Service) GetQuest(language, id string, address, original string) (quest
quest, err = s.dao.GetQuestWithClaimStatusByUUID(language, id, address)
} else {
if address == "" {
quest, err = s.dao.GetQuestByTokenIDWithLang(language, id)
quest, err = s.dao.GetQuestDetailByTokenIDWithLang(language, id)
return
}
if original == "true" {
Expand Down
16 changes: 12 additions & 4 deletions internal/app/service/zcloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,25 @@ func (s *Service) GenerateCardInfo(address string, score int64, req request.Gene
return errors.New("DIDNotFound")
}
// 校验分数正确性
quest, err := s.dao.GetQuestByTokenIDWithLang(req.Lang, req.TokenId)
if err != nil {
return errors.New("TokenIDInvalid")
var quest model.Quest
if req.Lang == "" {
quest, err = s.dao.GetQuestByTokenID(req.TokenId)
if err != nil {
return errors.New("TokenIDInvalid")
}
} else {
quest, err = s.dao.GetQuestByTokenIDWithLang(req.Lang, req.TokenId)
if err != nil {
return errors.New("TokenIDInvalid")
}
}
// 校验题目
if req.Uri != "" && req.Uri != quest.Uri {
return errors.New("QuestUpdate")
}
pass := true
if score == 0 {
score, pass, err = s.AnswerCheck(s.c.Quest.EncryptKey, req.Answer, address, 0, &quest.Quest, true)
score, pass, err = s.AnswerCheck(s.c.Quest.EncryptKey, req.Answer, address, 0, &quest, true)
if err != nil {
log.Errorv("AnswerCheck error", zap.Error(err))
return errors.New("UnexpectedError")
Expand Down