From 73f7b027fa2d43dbe72c5f05aa6a0c894af11625 Mon Sep 17 00:00:00 2001 From: liangjies <1139629972@qq.com> Date: Tue, 16 Apr 2024 16:47:30 +0800 Subject: [PATCH 1/2] fix: open quest did --- internal/app/dao/quest.go | 12 +++++++++++- internal/app/service/badge_v2.go | 4 ++-- internal/app/service/quest.go | 2 +- internal/app/service/zcloak.go | 16 ++++++++++++---- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/internal/app/dao/quest.go b/internal/app/dao/quest.go index 2e0735f..9f072c4 100644 --- a/internal/app/dao/quest.go +++ b/internal/app/dao/quest.go @@ -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 @@ -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 diff --git a/internal/app/service/badge_v2.go b/internal/app/service/badge_v2.go index 6c4fa90..c7e7481 100644 --- a/internal/app/service/badge_v2.go +++ b/internal/app/service/badge_v2.go @@ -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") @@ -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") diff --git a/internal/app/service/quest.go b/internal/app/service/quest.go index b5d1fc3..aa0d2c7 100644 --- a/internal/app/service/quest.go +++ b/internal/app/service/quest.go @@ -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" { diff --git a/internal/app/service/zcloak.go b/internal/app/service/zcloak.go index 797c3a8..6ace0f2 100644 --- a/internal/app/service/zcloak.go +++ b/internal/app/service/zcloak.go @@ -87,9 +87,17 @@ 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 { @@ -97,7 +105,7 @@ func (s *Service) GenerateCardInfo(address string, score int64, req request.Gene } 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") From 32b940cbbfb561a954e34baf16c1ea2acbaee2bb Mon Sep 17 00:00:00 2001 From: liangjies <1139629972@qq.com> Date: Tue, 7 May 2024 10:50:49 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E7=BC=BA=E5=B0=91commit=5Ftime?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/app/initialize/gorm.go | 2 +- internal/app/model/user_open_quest.go | 5 +++-- internal/app/service/challenge.go | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/app/initialize/gorm.go b/internal/app/initialize/gorm.go index 9606678..6adec30 100644 --- a/internal/app/initialize/gorm.go +++ b/internal/app/initialize/gorm.go @@ -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") } diff --git a/internal/app/model/user_open_quest.go b/internal/app/model/user_open_quest.go index e0ab00e..708ec76 100644 --- a/internal/app/model/user_open_quest.go +++ b/internal/app/model/user_open_quest.go @@ -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"` // 分数 } diff --git a/internal/app/service/challenge.go b/internal/app/service/challenge.go index 85c76c8..95b6cb7 100644 --- a/internal/app/service/challenge.go +++ b/internal/app/service/challenge.go @@ -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) { @@ -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")