增加 记录问答题库打开次数
This commit is contained in:
parent
c7daf18830
commit
f91fb16996
@ -8,6 +8,7 @@ import (
|
|||||||
"knowledge/api/model"
|
"knowledge/api/model"
|
||||||
"knowledge/api/requests"
|
"knowledge/api/requests"
|
||||||
"knowledge/api/responses"
|
"knowledge/api/responses"
|
||||||
|
"knowledge/api/service"
|
||||||
"knowledge/consts"
|
"knowledge/consts"
|
||||||
"knowledge/global"
|
"knowledge/global"
|
||||||
"knowledge/utils"
|
"knowledge/utils"
|
||||||
@ -300,5 +301,10 @@ func (r *Share) GetQuestion(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 记录问答题库打开次数
|
||||||
|
questionQaService := service.QuestionQaService{}
|
||||||
|
_ = questionQaService.RecordQuestionQaOpenNum(global.Db, questionQa.QaId)
|
||||||
|
|
||||||
|
// 返回
|
||||||
responses.OkWithData(g, c)
|
responses.OkWithData(g, c)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -188,3 +188,21 @@ func (r *QuestionQaDao) GetQuestionQaPageSearch(req requests.GetQuestionQaPage,
|
|||||||
}
|
}
|
||||||
return m, totalRecords, nil
|
return m, totalRecords, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inc 自增
|
||||||
|
func (r *QuestionQaDao) Inc(tx *gorm.DB, qaId int64, field string, numeral int) error {
|
||||||
|
err := tx.Model(&model.QuestionQa{}).Where("qa_id = ?", qaId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dec 自减
|
||||||
|
func (r *QuestionQaDao) Dec(tx *gorm.DB, qaId int64, field string, numeral int) error {
|
||||||
|
err := tx.Model(&model.QuestionQa{}).Where("qa_id = ?", qaId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
|
"gorm.io/gorm"
|
||||||
"knowledge/api/dao"
|
"knowledge/api/dao"
|
||||||
"knowledge/api/model"
|
"knowledge/api/model"
|
||||||
"knowledge/api/requests"
|
"knowledge/api/requests"
|
||||||
@ -556,3 +557,14 @@ func (r *QuestionQaService) PutQuestionQaRule(qaId int64, req requests.PutQuesti
|
|||||||
tx.Commit()
|
tx.Commit()
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RecordQuestionQaOpenNum 记录问答题库打开次数
|
||||||
|
func (r *QuestionQaService) RecordQuestionQaOpenNum(tx *gorm.DB, qaId int64) error {
|
||||||
|
questionQaDao := dao.QuestionQaDao{}
|
||||||
|
err := questionQaDao.Inc(tx, qaId, "open_number", 1)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user