新增了操作图文视频状态
This commit is contained in:
+58
-70
@@ -357,75 +357,63 @@ func (r *Article) AddArticle(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 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()
|
||||
func (r *Article) PutArticleStatus(c *gin.Context) {
|
||||
articleRequest := requests.ArticleRequest{}
|
||||
req := articleRequest.PutArticleStatus
|
||||
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
|
||||
}
|
||||
|
||||
id := c.Param("article_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
articleId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取订单数据
|
||||
articleDao := dao.ArticleDao{}
|
||||
article, err := articleDao.GetArticleById(articleId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("图文异常", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
articleData := make(map[string]interface{})
|
||||
if req.ArticleStatus != article.ArticleStatus {
|
||||
articleData["article_status"] = req.ArticleStatus
|
||||
}
|
||||
|
||||
if len(articleData) > 0 {
|
||||
err = articleDao.EditArticleById(tx, articleId, articleData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("修改失败", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
@@ -360,3 +360,65 @@ func (r *Video) AddVideo(c *gin.Context) {
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutVideoStatus 操作视频状态
|
||||
func (r *Video) PutVideoStatus(c *gin.Context) {
|
||||
videoRequest := requests.VideoRequest{}
|
||||
req := videoRequest.PutVideoStatus
|
||||
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
|
||||
}
|
||||
|
||||
id := c.Param("video_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
videoId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取订单数据
|
||||
videoDao := dao.VideoDao{}
|
||||
video, err := videoDao.GetVideoById(videoId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("视频异常", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
videoData := make(map[string]interface{})
|
||||
if req.VideoStatus != video.VideoStatus {
|
||||
videoData["video_status"] = req.VideoStatus
|
||||
}
|
||||
|
||||
if len(videoData) > 0 {
|
||||
err = videoDao.EditVideoById(tx, videoId, videoData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("修改失败", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user