新增了获取问题解锁状态
This commit is contained in:
+15
-27
@@ -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 增加问题点击次数
|
||||
|
||||
Reference in New Issue
Block a user