196 lines
6.9 KiB
Go
196 lines
6.9 KiB
Go
package tonectrl
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"91porn-server/common"
|
|
"91porn-server/common/constant"
|
|
"91porn-server/common/stderr"
|
|
"91porn-server/models/commod"
|
|
"91porn-server/models/l/operatorlgmod"
|
|
"91porn-server/models/v/tonemod"
|
|
"91porn-server/models/v/tonerecomod"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
// List doc
|
|
// @Summary 获取音色最热列表
|
|
// @Description 获取音色最热列表
|
|
// @Tags web-视频管理-音色最热
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param pageNumber query int true "当前页"
|
|
// @Param pageSize query int true "每页条数"
|
|
// @Success 200 {string} json "{"msg": "操作成功", "date": { "total":10, "list":[] }}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /web/vid/tone/list [get]
|
|
func List(c *gin.Context) {
|
|
var arg struct {
|
|
commod.Page
|
|
}
|
|
if err := c.ShouldBind(&arg); err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, "tone List arg error "+err.Error())
|
|
return
|
|
}
|
|
sort := bson.D{{Key: "createdAt", Value: -1}}
|
|
skip := int64((arg.PageNumber - 1) * arg.PageSize)
|
|
limit := int64(arg.PageSize)
|
|
page, err := tonemod.TonePages(sort, skip, limit)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.Failure, "tone List error: "+err.Error())
|
|
return
|
|
}
|
|
common.ServeJSON(c, stderr.Success, page)
|
|
}
|
|
|
|
// Update doc
|
|
// @Summary 编辑音色最热
|
|
// @Description 编辑音色最热
|
|
// @Tags web-视频管理-音色最热
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param targetID formData string true "目标文档ID"
|
|
// @Param name formData string false "名字"
|
|
// @Param cover formData string false "封面"
|
|
// @Param sortKey formData int false "排序键"
|
|
// @Param enable formData bool false "使能"
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /web/vid/tone/update [post]
|
|
func Update(c *gin.Context) {
|
|
manager, err := common.GetAdminAct(c)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.AdminIDErr, err.Error())
|
|
return
|
|
}
|
|
var arg struct {
|
|
TargetID string `form:"targetID" json:"targetID,omitempty" binding:"required"`
|
|
Name *string `form:"name" json:"name,omitempty" binding:""`
|
|
Cover *string `form:"cover" json:"cover,omitempty" binding:""`
|
|
SortKey *int `form:"sortKey" json:"sortKey,omitempty" binding:""`
|
|
Enable *bool `form:"enable" json:"enable,omitempty" binding:""`
|
|
}
|
|
if err := c.ShouldBind(&arg); err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, "tone Update arg error "+err.Error())
|
|
return
|
|
}
|
|
doc := tonemod.ToneDoc{
|
|
Name: arg.Name,
|
|
Cover: arg.Cover,
|
|
SortKey: arg.SortKey,
|
|
Enable: arg.Enable,
|
|
}
|
|
targetID, err := primitive.ObjectIDFromHex(arg.TargetID)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, err)
|
|
return
|
|
}
|
|
if err := tonemod.UpdateTo(targetID, doc); err != nil {
|
|
common.ServeJSON(c, stderr.ErrDbUpdateError, err)
|
|
return
|
|
}
|
|
log, _ := json.Marshal(arg)
|
|
_ = operatorlgmod.RecordOperation(manager, constant.VideoManageTone, constant.Modify, string(log), c.Request.URL.RequestURI())
|
|
common.ServeJSON(c, stderr.Success, "")
|
|
}
|
|
|
|
// OffiRecomAdd doc
|
|
// @Summary 音色最热-官方推荐视屏批量添加
|
|
// @Description 音色最热-官方推荐视屏批量添加
|
|
// @Tags web-视频管理-音色最热
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param vidArray formData array true "视屏ID数组"
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /web/vid/tone/offi_recom/add [post]
|
|
func OffiRecomAdd(c *gin.Context) {
|
|
var arg struct {
|
|
VIDArray []string `form:"vidArray" json:"vidArray" binding:"required"`
|
|
}
|
|
if err := c.ShouldBind(&arg); err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, "tone OffiRecomAdd arg error "+err.Error())
|
|
return
|
|
}
|
|
vidArray, err := common.IDArray(arg.VIDArray)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, err)
|
|
return
|
|
}
|
|
offiRecoms := make([]tonerecomod.OffiRecomDoc, len(vidArray))
|
|
for i, _id := range vidArray {
|
|
offiRecoms[i] = tonerecomod.OffiRecomDoc{
|
|
VID: _id,
|
|
}
|
|
}
|
|
if err := tonerecomod.InsertMany(offiRecoms); err != nil {
|
|
common.ServeJSON(c, stderr.ErrDbInsertError, err)
|
|
return
|
|
}
|
|
common.ServeJSON(c, stderr.Success, "")
|
|
}
|
|
|
|
// OffiRecomList doc
|
|
// @Summary 音色最热-官方推荐视屏列表
|
|
// @Description 音色最热-官方推荐视屏列表
|
|
// @Tags web-视频管理-音色最热
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param pageNumber query int true "当前页"
|
|
// @Param pageSize query int true "每页条数"
|
|
// @Success 200 {string} json "{"msg": "操作成功", "date": { "total":10, "list":[] }}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /web/vid/tone/offi_recom/list [get]
|
|
func OffiRecomList(c *gin.Context) {
|
|
var arg struct {
|
|
commod.Page
|
|
commod.OrderBy
|
|
}
|
|
if err := c.ShouldBind(&arg); err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, "tone OffiRecomAList arg error "+err.Error())
|
|
return
|
|
}
|
|
sort := tonemod.D{{Key: "createdAt", Value: -1}}
|
|
skip := int64((arg.PageNumber - 1) * arg.PageSize)
|
|
limit := int64(arg.PageSize)
|
|
page, err := tonerecomod.OffiRecomPages(sort, skip, limit)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.Failure, "tone OffiRecomAList error: "+err.Error())
|
|
return
|
|
}
|
|
common.ServeJSON(c, stderr.Success, page)
|
|
}
|
|
|
|
// OffiRecomDelete doc
|
|
// @Summary 音色最热-官方推荐视屏批量删除
|
|
// @Description 音色最热-官方推荐视屏批量删除
|
|
// @Tags web-视频管理-音色最热
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param idArray formData array true "ID数组"
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /web/vid/tone/offi_recom/delete [delete]
|
|
func OffiRecomDelete(c *gin.Context) {
|
|
var arg struct {
|
|
IDArray []string `form:"idArray" json:"idArray" binding:"required"`
|
|
}
|
|
if err := c.ShouldBind(&arg); err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, "tone OffiRecomDelete arg error "+err.Error())
|
|
return
|
|
}
|
|
idArray, err := common.IDArray(arg.IDArray)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, err)
|
|
return
|
|
}
|
|
if err = tonerecomod.DeleteMany(idArray); err != nil {
|
|
common.ServeJSON(c, stderr.ErrDbDeleteError, err)
|
|
return
|
|
}
|
|
common.ServeJSON(c, stderr.Success, "")
|
|
}
|