新增了获取问题解锁状态
This commit is contained in:
parent
ddd3f57bdf
commit
9dc506b1c1
@ -135,8 +135,8 @@ func (r *Question) GetQuestion(c *gin.Context) {
|
|||||||
|
|
||||||
// GetQuestionUnlockStatus 获取问题解锁状态
|
// GetQuestionUnlockStatus 获取问题解锁状态
|
||||||
func (r *Question) GetQuestionUnlockStatus(c *gin.Context) {
|
func (r *Question) GetQuestionUnlockStatus(c *gin.Context) {
|
||||||
// 购买状态(0:否 1:是)
|
var g dto.QuestionBuyStatusDto
|
||||||
var status int
|
|
||||||
userId := c.GetInt64("UserId")
|
userId := c.GetInt64("UserId")
|
||||||
|
|
||||||
id := c.Param("question_id")
|
id := c.Param("question_id")
|
||||||
@ -178,24 +178,16 @@ func (r *Question) GetQuestionUnlockStatus(c *gin.Context) {
|
|||||||
isMember := userService.CheckUserMember(user)
|
isMember := userService.CheckUserMember(user)
|
||||||
if isMember == true {
|
if isMember == true {
|
||||||
// 用户为会员,可直接查看
|
// 用户为会员,可直接查看
|
||||||
status = 1
|
g.BuyStatus = 1
|
||||||
responses.OkWithData(status, c)
|
g.BuyMode = 2
|
||||||
return
|
g.ValidDate = time.Time(*user.MemberExpireDate).Format("2006-01-02 15:04:05")
|
||||||
}
|
responses.OkWithData(g, c)
|
||||||
|
|
||||||
// 获取单项配置
|
|
||||||
systemSingleDao := dao.SystemSingleDao{}
|
|
||||||
|
|
||||||
maps := make(map[string]interface{})
|
|
||||||
systemSingle, err := systemSingleDao.GetSystemSingle(maps)
|
|
||||||
if err != nil {
|
|
||||||
responses.FailWithMessage("内部错误", c)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户订单
|
// 获取用户订单
|
||||||
orderSingleDao := dao.OrderSingleDao{}
|
orderSingleDao := dao.OrderSingleDao{}
|
||||||
maps = make(map[string]interface{})
|
maps := make(map[string]interface{})
|
||||||
maps["user_id"] = userId
|
maps["user_id"] = userId
|
||||||
maps["question_id"] = questionId
|
maps["question_id"] = questionId
|
||||||
orderSingles, err := orderSingleDao.GetOrderSingleList(maps)
|
orderSingles, err := orderSingleDao.GetOrderSingleList(maps)
|
||||||
@ -205,7 +197,6 @@ func (r *Question) GetQuestionUnlockStatus(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 是否购买过(0:否 1:是)
|
// 是否购买过(0:否 1:是)
|
||||||
var isBuy int
|
|
||||||
for _, single := range orderSingles {
|
for _, single := range orderSingles {
|
||||||
// 订单状态(1:待支付 2:已完成 3:已取消)
|
// 订单状态(1:待支付 2:已完成 3:已取消)
|
||||||
if single.OrderStatus != 2 {
|
if single.OrderStatus != 2 {
|
||||||
@ -228,24 +219,21 @@ func (r *Question) GetQuestionUnlockStatus(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否还在有效期内
|
// 判断是否还在有效期内
|
||||||
payTime := time.Time(*single.PayTime)
|
t := time.Time(*single.ValidDate)
|
||||||
validTime := payTime.Add(time.Duration(systemSingle.ValidDays) * 24 * time.Hour)
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
if validTime.Before(now) {
|
if t.Before(now) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
isBuy = 1
|
g.BuyStatus = 1
|
||||||
|
g.BuyMode = 2
|
||||||
|
g.ValidDate = time.Time(*single.ValidDate).Format("2006-01-02 15:04:05")
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if isBuy == 1 {
|
responses.OkWithData(g, c)
|
||||||
status = 1
|
return
|
||||||
responses.OkWithData(status, c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
responses.OkWithData(status, c)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PutQuestionClickCount 增加问题点击次数
|
// PutQuestionClickCount 增加问题点击次数
|
||||||
|
|||||||
@ -32,9 +32,9 @@ type QuestionDto struct {
|
|||||||
|
|
||||||
// QuestionBuyStatusDto 获取问题解锁状态
|
// QuestionBuyStatusDto 获取问题解锁状态
|
||||||
type QuestionBuyStatusDto struct {
|
type QuestionBuyStatusDto struct {
|
||||||
QuestionId string `json:"buy_status"` // 解锁状态(0:否 1:是)
|
BuyStatus int `json:"buy_status"` // 解锁状态(0:否 1:是)
|
||||||
QuestionTitle *int `json:"buy_mode"` // 解锁方式(1:单项有效期 2:会员)
|
BuyMode int `json:"buy_mode"` // 解锁方式(1:单项有效期 2:会员)
|
||||||
ValidDate *time.Time `json:"valid_date"` // 到期时间
|
ValidDate string `json:"valid_date"` // 到期时间
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetQuestionDto 详情-问题
|
// GetQuestionDto 详情-问题
|
||||||
@ -60,42 +60,7 @@ func GetQuestionDto(m *model.Question) *QuestionDto {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetQuestionListDto 列表-问题
|
// GetHotQuestionListDto 列表-热榜
|
||||||
func GetQuestionListDto(m []*model.Question) []*QuestionDto {
|
|
||||||
// 处理返回值
|
|
||||||
responses := make([]*QuestionDto, len(m))
|
|
||||||
|
|
||||||
if len(m) > 0 {
|
|
||||||
for i, v := range m {
|
|
||||||
response := &QuestionDto{
|
|
||||||
QuestionId: fmt.Sprintf("%d", v.QuestionId),
|
|
||||||
QuestionTitle: v.QuestionTitle,
|
|
||||||
QuestionSubtitle: v.QuestionSubtitle,
|
|
||||||
QuestionIden: v.QuestionIden,
|
|
||||||
QuestionStatus: v.QuestionStatus,
|
|
||||||
IsHide: v.IsHide,
|
|
||||||
IsRecommend: v.IsRecommend,
|
|
||||||
ClickCount: v.ClickCount,
|
|
||||||
SubmitCount: v.SubmitCount,
|
|
||||||
PayCount: v.PayCount,
|
|
||||||
Price: v.Price,
|
|
||||||
DiscountPrice: v.DiscountPrice,
|
|
||||||
DiscountEndTime: v.DiscountEndTime,
|
|
||||||
QuestionBrief: v.QuestionBrief,
|
|
||||||
QuestionExplain: v.QuestionExplain,
|
|
||||||
CreatedAt: v.CreatedAt,
|
|
||||||
UpdatedAt: v.UpdatedAt,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将转换后的结构体添加到新切片中
|
|
||||||
responses[i] = response
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return responses
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetHotQuestionListDto 列表-热榜问题
|
|
||||||
func GetHotQuestionListDto(m []*model.Question) []*QuestionDto {
|
func GetHotQuestionListDto(m []*model.Question) []*QuestionDto {
|
||||||
// 处理返回值
|
// 处理返回值
|
||||||
responses := make([]*QuestionDto, len(m))
|
responses := make([]*QuestionDto, len(m))
|
||||||
@ -170,7 +135,7 @@ func GetGuessUserLikeListDto(m []*model.Question) []*QuestionDto {
|
|||||||
return responses
|
return responses
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetQuestionPageListDto 列表-分页问题
|
// GetQuestionPageListDto 列表-分页
|
||||||
func GetQuestionPageListDto(m []*model.Question) []*QuestionDto {
|
func GetQuestionPageListDto(m []*model.Question) []*QuestionDto {
|
||||||
// 处理返回值
|
// 处理返回值
|
||||||
responses := make([]*QuestionDto, len(m))
|
responses := make([]*QuestionDto, len(m))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user