3
This commit is contained in:
parent
73e41552e4
commit
5a94972228
@ -246,3 +246,99 @@ func (r *Question) GetQuestionBuyStatus(c *gin.Context) {
|
|||||||
|
|
||||||
responses.OkWithData(status, c)
|
responses.OkWithData(status, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PutQuestionClickCount 增加问题点击次数
|
||||||
|
func (r *Question) PutQuestionClickCount(c *gin.Context) {
|
||||||
|
id := c.Param("question_id")
|
||||||
|
if id == "" {
|
||||||
|
responses.FailWithMessage("缺少参数", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将 id 转换为 int64 类型
|
||||||
|
questionId, err := strconv.ParseInt(id, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
responses.Fail(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取题目数据
|
||||||
|
questionDao := dao.QuestionDao{}
|
||||||
|
question, err := questionDao.GetQuestionById(questionId)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage("题目错误", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if question.QuestionStatus != 1 {
|
||||||
|
responses.FailWithMessage("题目错误", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始事务
|
||||||
|
tx := global.Db.Begin()
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
err = questionDao.Inc(tx, questionId, "click_count", 1)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
responses.FailWithMessage("内部错误", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.Commit()
|
||||||
|
|
||||||
|
responses.Ok(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutQuestionSubmitCount 增加问题提交次数
|
||||||
|
func (r *Question) PutQuestionSubmitCount(c *gin.Context) {
|
||||||
|
id := c.Param("question_id")
|
||||||
|
if id == "" {
|
||||||
|
responses.FailWithMessage("缺少参数", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将 id 转换为 int64 类型
|
||||||
|
questionId, err := strconv.ParseInt(id, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
responses.Fail(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取题目数据
|
||||||
|
questionDao := dao.QuestionDao{}
|
||||||
|
question, err := questionDao.GetQuestionById(questionId)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage("题目错误", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if question.QuestionStatus != 1 {
|
||||||
|
responses.FailWithMessage("题目错误", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始事务
|
||||||
|
tx := global.Db.Begin()
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
err = questionDao.Inc(tx, questionId, "submit_count", 1)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
responses.FailWithMessage("内部错误", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.Commit()
|
||||||
|
|
||||||
|
responses.Ok(c)
|
||||||
|
}
|
||||||
|
|||||||
@ -251,3 +251,21 @@ func (r *QuestionDao) GetQuestionPageSearch(req requests.GetQuestionPage, page,
|
|||||||
}
|
}
|
||||||
return m, totalRecords, nil
|
return m, totalRecords, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inc 自增
|
||||||
|
func (r *QuestionDao) Inc(tx *gorm.DB, questionId int64, field string, numeral int) error {
|
||||||
|
err := tx.Model(&model.Question{}).Where("question_id = ?", questionId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dec 自减
|
||||||
|
func (r *QuestionDao) Dec(tx *gorm.DB, questionId int64, field string, numeral int) error {
|
||||||
|
err := tx.Model(&model.Question{}).Where("question_id = ?", questionId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ type UserDto struct {
|
|||||||
RegisterSource int `json:"register_source"` // 注册来源(1:app注册 2:公众号注册)
|
RegisterSource int `json:"register_source"` // 注册来源(1:app注册 2:公众号注册)
|
||||||
OpenId string `json:"open_id"` // 用户微信标识
|
OpenId string `json:"open_id"` // 用户微信标识
|
||||||
UnionId string `json:"union_id"` // 微信开放平台标识
|
UnionId string `json:"union_id"` // 微信开放平台标识
|
||||||
Age uint `json:"age"` // 年龄
|
Age *uint `json:"age"` // 年龄
|
||||||
Sex uint `json:"sex"` // 性别(0:未知 1:男 2:女)
|
Sex uint `json:"sex"` // 性别(0:未知 1:男 2:女)
|
||||||
Avatar string `json:"avatar"` // 头像
|
Avatar string `json:"avatar"` // 头像
|
||||||
IsMember int `json:"is_member"` // 是否会员(0:否 1:是)
|
IsMember int `json:"is_member"` // 是否会员(0:否 1:是)
|
||||||
@ -35,7 +35,7 @@ func GetUserDto(m *model.User) *UserDto {
|
|||||||
Mobile: m.Mobile,
|
Mobile: m.Mobile,
|
||||||
UserStatus: m.UserStatus,
|
UserStatus: m.UserStatus,
|
||||||
RegisterSource: m.RegisterSource,
|
RegisterSource: m.RegisterSource,
|
||||||
Age: *m.Age,
|
Age: m.Age,
|
||||||
Sex: uint(m.Sex),
|
Sex: uint(m.Sex),
|
||||||
Avatar: utils.AddOssDomain(m.Avatar),
|
Avatar: utils.AddOssDomain(m.Avatar),
|
||||||
IsMember: m.IsMember,
|
IsMember: m.IsMember,
|
||||||
|
|||||||
@ -16,7 +16,7 @@ type GetQuestionPage struct {
|
|||||||
IsRecommend *int `json:"is_recommend" form:"is_recommend" label:"是否推荐"`
|
IsRecommend *int `json:"is_recommend" form:"is_recommend" label:"是否推荐"`
|
||||||
QuestionBrief string `json:"question_brief" form:"question_brief" label:"问题介绍"`
|
QuestionBrief string `json:"question_brief" form:"question_brief" label:"问题介绍"`
|
||||||
QuestionExplain string `json:"question_explain" form:"question_explain" label:"问题解释/科普"`
|
QuestionExplain string `json:"question_explain" form:"question_explain" label:"问题解释/科普"`
|
||||||
ClassId string `json:"class_id" form:"question_explain" label:"分类标识"`
|
ClassId string `json:"class_id" form:"class_id" label:"分类标识"`
|
||||||
Order *GetQuestionPageOrder `json:"order" form:"order" label:"排序"`
|
Order *GetQuestionPageOrder `json:"order" form:"order" label:"排序"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,11 +22,11 @@ type GetUserCouponPage struct {
|
|||||||
// GetUserUsableQuestionCoupon 获取患者可使用优惠卷-单项
|
// GetUserUsableQuestionCoupon 获取患者可使用优惠卷-单项
|
||||||
type GetUserUsableQuestionCoupon struct {
|
type GetUserUsableQuestionCoupon struct {
|
||||||
QuestionId string `json:"question_id" form:"question_id" label:"问题" validate:"required"`
|
QuestionId string `json:"question_id" form:"question_id" label:"问题" validate:"required"`
|
||||||
AmountTotal float64 `json:"amount_total" form:"amount_total" label:"价格1" validate:"required"`
|
AmountTotal float64 `json:"amount_total" form:"amount_total" label:"价格" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserUsableMemberCoupon 获取患者可使用优惠卷-会员
|
// GetUserUsableMemberCoupon 获取患者可使用优惠卷-会员
|
||||||
type GetUserUsableMemberCoupon struct {
|
type GetUserUsableMemberCoupon struct {
|
||||||
SystemMemberId string `json:"system_member_id" form:"system_member_id" label:"会员" validate:"required"`
|
SystemMemberId string `json:"system_member_id" form:"system_member_id" label:"会员" validate:"required"`
|
||||||
AmountTotal float64 `json:"amount_total" form:"amount_total" label:"价格1" validate:"required"`
|
AmountTotal float64 `json:"amount_total" form:"amount_total" label:"价格" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -143,6 +143,17 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
|||||||
|
|
||||||
// 获取问题购买状态
|
// 获取问题购买状态
|
||||||
questionGroup.GET("/buy/status/:question_id", api.Question.GetQuestionBuyStatus)
|
questionGroup.GET("/buy/status/:question_id", api.Question.GetQuestionBuyStatus)
|
||||||
|
|
||||||
|
// 点击次数
|
||||||
|
clickGroup := questionGroup.Group("/click")
|
||||||
|
{
|
||||||
|
// 增加问题点击次数(点击进入详情页的人次)
|
||||||
|
clickGroup.PUT("/:question_id", api.Question.PutQuestionClickCount)
|
||||||
|
|
||||||
|
// 增加问题提交次数(提交个人信息进行了算算的人次)
|
||||||
|
clickGroup.PUT("/submit/:question_id", api.Question.PutQuestionSubmitCount)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用户
|
// 用户
|
||||||
@ -161,11 +172,14 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
|||||||
// 获取还未弹窗的优惠卷
|
// 获取还未弹窗的优惠卷
|
||||||
couponGroup.GET("/unnotified", api.UserCoupon.GetUserCouponUnnotified)
|
couponGroup.GET("/unnotified", api.UserCoupon.GetUserCouponUnnotified)
|
||||||
|
|
||||||
|
usableGroup := couponGroup.Group("/usable")
|
||||||
|
{
|
||||||
// 获取患者可使用优惠卷-单项
|
// 获取患者可使用优惠卷-单项
|
||||||
couponGroup.GET("/question", api.UserCoupon.GetUserUsableQuestionCoupon)
|
usableGroup.GET("/question", api.UserCoupon.GetUserUsableQuestionCoupon)
|
||||||
|
|
||||||
// 获取患者可使用优惠卷-会员
|
// 获取患者可使用优惠卷-会员
|
||||||
couponGroup.GET("/member", api.UserCoupon.GetUserUsableMemberCoupon)
|
usableGroup.GET("/member", api.UserCoupon.GetUserUsableMemberCoupon)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 收藏
|
// 收藏
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user