187 lines
6.4 KiB
Go
187 lines
6.4 KiB
Go
package locationctrl
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"91porn-server/common"
|
|
"91porn-server/common/constant"
|
|
"91porn-server/common/pageopt"
|
|
"91porn-server/common/stderr"
|
|
"91porn-server/models/commod"
|
|
"91porn-server/models/l/operatorlgmod"
|
|
"91porn-server/models/v/locmod"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
// HotCityList doc
|
|
// @Summary 获取热门城市列表
|
|
// @Description 获取热门城市列表
|
|
// @Tags web-视频管理-HotCity
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param pageNumber query int true "当前页"
|
|
// @Param pageSize query int true "每页条数"
|
|
// @Param city query string false "过滤条件:城市"
|
|
// @Success 200 {string} json "{"msg": "操作成功", "date": { "total":10, "list":[] }}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /web/vid/location/hotCity/list [get]
|
|
func HotCityList(c *gin.Context) {
|
|
type Query struct {
|
|
City *string `form:"city" json:"city" bson:"city,omitempty"` //角色类型
|
|
}
|
|
var arg struct {
|
|
commod.Page
|
|
Query
|
|
}
|
|
if err := c.ShouldBind(&arg); err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, "hotCity List arg error "+err.Error())
|
|
return
|
|
}
|
|
match := &pageopt.AssignMatch{
|
|
Key: "city",
|
|
Val: arg.City,
|
|
}
|
|
sort := bson.D{{Key: "createdAt", Value: -1}}
|
|
skip := int64((arg.PageNumber - 1) * arg.PageSize)
|
|
limit := int64(arg.PageSize)
|
|
page, err := locmod.HotCityPages(sort, skip, limit, match)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.Failure, "hotCity List error: "+err.Error())
|
|
return
|
|
}
|
|
common.ServeJSON(c, stderr.Success, page)
|
|
}
|
|
|
|
// HotCityUpdate doc
|
|
// @Summary 编辑热门城市
|
|
// @Description 编辑热门城市
|
|
// @Tags web-视频管理-HotCity
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param targetID formData string true "目标文档ID"
|
|
// @Param sortKey formData int false "排序键"
|
|
// @Param enable formData bool false "使能"
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /web/vid/location/hotCity/update [post]
|
|
func HotCityUpdate(c *gin.Context) {
|
|
manager, err := common.GetAdminAct(c)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.AdminIDErr, err.Error())
|
|
return
|
|
}
|
|
type Update struct {
|
|
SortKey *int `form:"sortKey" json:"sortKey" binding:""`
|
|
Enable *bool `form:"enable" json:"enable" binding:""`
|
|
Province *string `form:"province" json:"province" binding:""`
|
|
}
|
|
var arg struct {
|
|
TargetID string `form:"targetID" json:"targetID,omitempty" binding:"required"`
|
|
Update
|
|
}
|
|
if err = c.ShouldBind(&arg); err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, "hotCity Update arg error "+err.Error())
|
|
return
|
|
}
|
|
cityDoc := locmod.HotCityDoc{
|
|
SortKey: arg.SortKey,
|
|
Enable: arg.Enable,
|
|
Province: arg.Province,
|
|
}
|
|
targetID, err := primitive.ObjectIDFromHex(arg.TargetID)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, err)
|
|
return
|
|
}
|
|
if err = locmod.UpdateTo(targetID, cityDoc); err != nil {
|
|
common.ServeJSON(c, stderr.ErrDbUpdateError, err)
|
|
return
|
|
}
|
|
log, _ := json.Marshal(arg)
|
|
_ = operatorlgmod.RecordOperation(manager, constant.VideoManageHotCity, constant.Modify, string(log), c.Request.URL.RequestURI())
|
|
common.ServeJSON(c, stderr.Success, "")
|
|
}
|
|
|
|
// HotCityAdd doc
|
|
// @Summary 新增热门城市
|
|
// @Description 新增热门城市
|
|
// @Tags web-视频管理-HotCity
|
|
// @Accept mpfd,json
|
|
// @Produce json,html
|
|
// @Param city formData string true "城市"
|
|
// @Param sortKey formData int true "排序"
|
|
// @Param enable formData bool true "使能"
|
|
// @Success 200 {string} json "{"msg": "操作成功"}"
|
|
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
|
// @Router /web/vid/location/hotCity/add [post]
|
|
func HotCityAdd(c *gin.Context) {
|
|
manager, err := common.GetAdminAct(c)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.AdminIDErr, err.Error())
|
|
return
|
|
}
|
|
var arg struct {
|
|
City *string `form:"city" json:"city" binding:"required"` //城市
|
|
Province *string `form:"province" json:"province" binding:"required"` //省份
|
|
SortKey *int `form:"sortKey" json:"sortKey" binding:"required"` //排序
|
|
Enable *bool `form:"enable" json:"enable" binding:"required"` //使能
|
|
}
|
|
if err := c.ShouldBind(&arg); err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, "tone Add arg error "+err.Error())
|
|
return
|
|
}
|
|
doc := locmod.HotCityDoc{
|
|
City: arg.City,
|
|
Province: arg.Province,
|
|
SortKey: arg.SortKey,
|
|
Enable: arg.Enable,
|
|
}
|
|
if err = locmod.Insert(doc); err != nil {
|
|
common.ServeJSON(c, stderr.ErrDbInsertError, err)
|
|
return
|
|
}
|
|
log, _ := json.Marshal(arg)
|
|
_ = operatorlgmod.RecordOperation(manager, constant.VideoManageHotCity, constant.Add, string(log), c.Request.URL.RequestURI())
|
|
common.ServeJSON(c, stderr.Success, "")
|
|
}
|
|
|
|
// HotCityDelete doc
|
|
// @Summary 批量删除热门城市
|
|
// @Description 批量删除热门城市
|
|
// @Tags web-视频管理-HotCity
|
|
// @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/location/hotCity/delete [delete]
|
|
func HotCityDelete(c *gin.Context) {
|
|
manager, err := common.GetAdminAct(c)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.AdminIDErr, err.Error())
|
|
return
|
|
}
|
|
var arg struct {
|
|
IDArray []string `form:"idArray" json:"idArray" binding:"required"`
|
|
}
|
|
if err = c.ShouldBind(&arg); err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, "hotCity Delete arg error "+err.Error())
|
|
return
|
|
}
|
|
idArray, err := common.IDArray(arg.IDArray)
|
|
if err != nil {
|
|
common.ServeJSON(c, stderr.ErrParamError, err)
|
|
return
|
|
}
|
|
if err = locmod.DeleteMany(idArray); err != nil {
|
|
common.ServeJSON(c, stderr.ErrDbDeleteError, err)
|
|
return
|
|
}
|
|
log, _ := json.Marshal(arg)
|
|
_ = operatorlgmod.RecordOperation(manager, constant.VideoManageHotCity, constant.Delete, string(log), c.Request.URL.RequestURI())
|
|
common.ServeJSON(c, stderr.Success, "")
|
|
}
|