修改新增修改时票数判断
This commit is contained in:
parent
d0bb374414
commit
61d27b2f02
@ -142,9 +142,11 @@ func (r *Article) PutArticle(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if req.VoteNum < 0 {
|
||||
responses.FailWithMessage("票数需大于0", c)
|
||||
return
|
||||
if req.VoteNum != nil {
|
||||
if *req.VoteNum < 0 {
|
||||
responses.FailWithMessage("票数需大于0", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 获取订单数据
|
||||
@ -182,8 +184,10 @@ func (r *Article) PutArticle(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 票数
|
||||
if article.VoteNum != req.VoteNum {
|
||||
articleData["vote_num"] = req.VoteNum
|
||||
if req.VoteNum != nil {
|
||||
if article.VoteNum != *req.VoteNum {
|
||||
articleData["vote_num"] = *req.VoteNum
|
||||
}
|
||||
}
|
||||
|
||||
// 修改
|
||||
@ -269,9 +273,11 @@ func (r *Article) AddArticle(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if req.VoteNum < 0 {
|
||||
responses.FailWithMessage("票数需大于0", c)
|
||||
return
|
||||
if req.VoteNum != nil {
|
||||
if *req.VoteNum < 0 {
|
||||
responses.FailWithMessage("票数需大于0", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
@ -287,10 +293,13 @@ func (r *Article) AddArticle(c *gin.Context) {
|
||||
article := &model.Article{
|
||||
ArticleTitle: req.ArticleTitle,
|
||||
ArticleStatus: req.ArticleStatus,
|
||||
VoteNum: req.VoteNum,
|
||||
ArticleContent: req.ArticleContent,
|
||||
}
|
||||
|
||||
if req.VoteNum != nil {
|
||||
article.VoteNum = *req.VoteNum
|
||||
}
|
||||
|
||||
articleDao := dao.ArticleDao{}
|
||||
article, err := articleDao.AddArticle(tx, article)
|
||||
if err != nil {
|
||||
@ -346,3 +355,77 @@ func (r *Article) AddArticle(c *gin.Context) {
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutArticleStatus 操作图文状态
|
||||
func (b *Article) PutArticleStatus(c *gin.Context) {
|
||||
//orderSingleRequest := requests.OrderSingleRequest{}
|
||||
//req := orderSingleRequest.PutOrderSingleDeleteStatus
|
||||
//if err := c.ShouldBind(&req); err != nil {
|
||||
// responses.FailWithMessage(err.Error(), c)
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//// 参数验证
|
||||
//if err := global.Validate.Struct(req); err != nil {
|
||||
// responses.FailWithMessage(utils.Translate(err), c)
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//if req.IsDelete != 0 && req.IsDelete != 1 {
|
||||
// responses.FailWithMessage("参数错误", c)
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//id := c.Param("order_id")
|
||||
//if id == "" {
|
||||
// responses.FailWithMessage("缺少参数", c)
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//// 将 id 转换为 int64 类型
|
||||
//orderId, err := strconv.ParseInt(id, 10, 64)
|
||||
//if err != nil {
|
||||
// responses.Fail(c)
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//// 获取订单数据
|
||||
//orderSingleDao := dao.OrderSingleDao{}
|
||||
//orderSingle, err := orderSingleDao.GetOrderSingleById(orderId)
|
||||
//if err != nil {
|
||||
// responses.FailWithMessage("订单异常", c)
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//// 检测订单状态
|
||||
//if orderSingle.OrderStatus == 2 {
|
||||
// responses.FailWithMessage("订单不允许删除", c)
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//// 检测订单删除状态
|
||||
//if orderSingle.IsDelete == req.IsDelete {
|
||||
// responses.Ok(c)
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//// 开始事务
|
||||
//tx := global.Db.Begin()
|
||||
//defer func() {
|
||||
// if r := recover(); r != nil {
|
||||
// tx.Rollback()
|
||||
// }
|
||||
//}()
|
||||
//
|
||||
//orderSingleData := make(map[string]interface{})
|
||||
//orderSingleData["is_delete"] = 1
|
||||
//err = orderSingleDao.EditOrderSingleById(tx, orderId, orderSingleData)
|
||||
//if err != nil {
|
||||
// tx.Rollback()
|
||||
// responses.FailWithMessage("删除失败", c)
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
@ -142,9 +142,11 @@ func (r *Video) PutVideo(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if req.VoteNum < 0 {
|
||||
responses.FailWithMessage("票数需大于0", c)
|
||||
return
|
||||
if req.VoteNum != nil {
|
||||
if *req.VoteNum < 0 {
|
||||
responses.FailWithMessage("票数需大于0", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 获取订单数据
|
||||
@ -176,9 +178,10 @@ func (r *Video) PutVideo(c *gin.Context) {
|
||||
videoData["video_status"] = req.VideoStatus
|
||||
}
|
||||
|
||||
// 总票数
|
||||
if video.VoteNum != req.VoteNum {
|
||||
videoData["vote_num"] = req.VoteNum
|
||||
if req.VoteNum != nil {
|
||||
if video.VoteNum != *req.VoteNum {
|
||||
videoData["vote_num"] = *req.VoteNum
|
||||
}
|
||||
}
|
||||
|
||||
// 视频编号
|
||||
@ -274,9 +277,11 @@ func (r *Video) AddVideo(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if req.VoteNum < 0 {
|
||||
responses.FailWithMessage("票数需大于0", c)
|
||||
return
|
||||
if req.VoteNum != nil {
|
||||
if *req.VoteNum < 0 {
|
||||
responses.FailWithMessage("票数需大于0", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
@ -293,10 +298,13 @@ func (r *Video) AddVideo(c *gin.Context) {
|
||||
VideoTitle: req.VideoTitle,
|
||||
VideoStatus: req.VideoStatus,
|
||||
VideoNo: req.VideoNo,
|
||||
VoteNum: req.VoteNum,
|
||||
VideoContent: req.VideoContent,
|
||||
}
|
||||
|
||||
if req.VoteNum != nil {
|
||||
video.VoteNum = *req.VoteNum
|
||||
}
|
||||
|
||||
videoDao := dao.VideoDao{}
|
||||
video, err := videoDao.AddVideo(tx, video)
|
||||
if err != nil {
|
||||
|
||||
@ -24,7 +24,7 @@ type GetArticlePageOrder struct {
|
||||
type PutArticle struct {
|
||||
ArticleTitle string `json:"article_title" form:"article_title" label:"文章标题" validate:"required"`
|
||||
ArticleStatus int `json:"article_status" form:"article_status" label:"文章状态" validate:"required,oneof=1 2"` // (1:正常 2:禁用)
|
||||
VoteNum uint `json:"vote_num" form:"vote_num" label:"票数" validate:"required"`
|
||||
VoteNum *uint `json:"vote_num" form:"vote_num" label:"票数"`
|
||||
ArticleContent string `json:"article_content" form:"article_content" label:"文章内容" validate:"required"`
|
||||
ArticleAuthor []*PutArticleAuthor `json:"article_author" form:"article_author" label:"作者" validate:"required"`
|
||||
}
|
||||
@ -39,7 +39,7 @@ type PutArticleAuthor struct {
|
||||
type AddArticle struct {
|
||||
ArticleTitle string `json:"article_title" form:"article_title" label:"文章标题" validate:"required"`
|
||||
ArticleStatus int `json:"article_status" form:"article_status" label:"文章状态" validate:"required,oneof=1 2"` // (1:正常 2:禁用)
|
||||
VoteNum uint `json:"vote_num" form:"vote_num" label:"票数" validate:"required"`
|
||||
VoteNum *uint `json:"vote_num" form:"vote_num" label:"票数"`
|
||||
ArticleContent string `json:"article_content" form:"article_content" label:"文章内容" validate:"required"`
|
||||
ArticleAuthor []*PutArticleAuthor `json:"article_author" form:"article_author" label:"作者" validate:"required"`
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ type GetVideoPageOrder struct {
|
||||
type PutVideo struct {
|
||||
VideoTitle string `json:"video_title" form:"video_title" label:"视频标题" validate:"required"`
|
||||
VideoStatus int `json:"video_status" form:"video_status" label:"视频状态" validate:"required,oneof=1 2"` // (1:正常 2:禁用)
|
||||
VoteNum uint `json:"vote_num" form:"vote_num" label:"总票数" validate:"required"`
|
||||
VoteNum *uint `json:"vote_num" form:"vote_num" label:"总票数"`
|
||||
VideoNo string `json:"video_no" form:"video_no" label:"视频编号" validate:"required"` // (保利)
|
||||
VideoContent string `json:"video_content" form:"video_content" label:"视频内容" validate:"required"`
|
||||
VideoAuthor []*PutVideoAuthor `json:"video_author" form:"video_author" label:"作者" validate:"required"`
|
||||
@ -41,7 +41,7 @@ type PutVideoAuthor struct {
|
||||
type AddVideo struct {
|
||||
VideoTitle string `json:"video_title" form:"video_title" label:"视频标题" validate:"required"`
|
||||
VideoStatus int `json:"video_status" form:"video_status" label:"视频状态" validate:"required,oneof=1 2"` // (1:正常 2:禁用)
|
||||
VoteNum uint `json:"vote_num" form:"vote_num" label:"总票数" validate:"required"`
|
||||
VoteNum *uint `json:"vote_num" form:"vote_num" label:"总票数"`
|
||||
VideoNo string `json:"video_no" form:"video_no" label:"视频编号" validate:"required"` // (保利)
|
||||
VideoContent string `json:"video_content" form:"video_content" label:"视频内容" validate:"required"`
|
||||
VideoAuthor []*PutVideoAuthor `json:"video_author" form:"video_author" label:"作者" validate:"required"`
|
||||
|
||||
@ -120,6 +120,9 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
// 新增图文详情
|
||||
articleGroup.POST("", api.Article.AddArticle)
|
||||
|
||||
// 操作图文状态
|
||||
articleGroup.PUT("/status/:article_id", api.Article.PutArticleStatus)
|
||||
|
||||
// 投票记录列表-图文-分页
|
||||
articleGroup.GET("/vote/page", api.UserVoteDay.GetArticleVotePage)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user