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