@@ -0,0 +1,140 @@
|
||||
package promoteurlctrl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/constant"
|
||||
"91porn-server/common/constant/redisconst"
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/l/operatorlgmod"
|
||||
"91porn-server/models/v/sourcemod"
|
||||
"91porn-server/web/webg"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// promoteURL doc
|
||||
// @Summary promoteURL 列表查询
|
||||
// @Description
|
||||
// @Tags product
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param status formData integer false "状态"
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /promoteUrl/list [get]
|
||||
func FindMany(ctx *gin.Context) {
|
||||
data := sourcemod.GetPromoteURLList()
|
||||
common.ServeJSON(ctx, stderr.Success, data)
|
||||
}
|
||||
|
||||
// promoteURL doc
|
||||
// @Summary 新增
|
||||
// @Description 新增
|
||||
// @Tags product
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /promoteUrl/insert [post]
|
||||
func Insert(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
s := sourcemod.Source{}
|
||||
if err = ctx.ShouldBind(&s); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
s.Type = sourcemod.PromoteURL
|
||||
s.IsActive = true
|
||||
if err = sourcemod.Insert(&s); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbInsertError, err.Error())
|
||||
return
|
||||
}
|
||||
//落地页域名加入到redis中
|
||||
common.Go(func() {
|
||||
purls := sourcemod.GetPromoteURLArray()
|
||||
_, _ = webg.Redis.Del(redisconst.LandDomainCacheKey)
|
||||
_, _ = webg.Redis.SAdd(redisconst.LandDomainCacheKey, purls)
|
||||
_, _ = webg.Redis.ExpireKey(redisconst.LandDomainCacheKey, redisconst.LandDomainCacheExpire)
|
||||
})
|
||||
log, _ := json.Marshal(s)
|
||||
_ = operatorlgmod.RecordOperation(manager, constant.ProductManagePage, constant.Add, string(log), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, nil)
|
||||
}
|
||||
|
||||
// promoteURL doc
|
||||
// @Summary 修改
|
||||
// @Description 修改
|
||||
// @Tags product
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /promoteUrl/update [post]
|
||||
func Update(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
var p struct {
|
||||
ID primitive.ObjectID `json:"id" form:"id" bson:"id"`
|
||||
sourcemod.SourceEdit
|
||||
}
|
||||
if err = ctx.ShouldBind(&p); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
p.SourceEdit.IsActive = true
|
||||
if err = sourcemod.Update(p.ID, sourcemod.PromoteURL, &p.SourceEdit); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbUpdateError, "")
|
||||
return
|
||||
}
|
||||
common.Go(func() {
|
||||
_, _ = webg.Redis.Del(redisconst.LandDomainCacheKey)
|
||||
})
|
||||
log, _ := json.Marshal(p)
|
||||
_ = operatorlgmod.RecordOperation(manager, constant.ProductManagePage, constant.Modify, string(log), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, nil)
|
||||
}
|
||||
|
||||
// promoteURL doc
|
||||
// @Summary 删除
|
||||
// @Description 删除
|
||||
// @Tags product
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param id formData int true "product等级"
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /promoteUrl/delete [Delete]
|
||||
func Delete(ctx *gin.Context) {
|
||||
manager, err := common.GetAdminAct(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
|
||||
return
|
||||
}
|
||||
var p struct {
|
||||
IDs []primitive.ObjectID `json:"ids" form:"ids"`
|
||||
}
|
||||
if err = ctx.ShouldBind(&p); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
||||
return
|
||||
}
|
||||
if err = sourcemod.Remove(p.IDs); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrDbDeleteError, "")
|
||||
return
|
||||
}
|
||||
common.Go(func() {
|
||||
_, _ = webg.Redis.Del(redisconst.LandDomainCacheKey)
|
||||
})
|
||||
log, _ := json.Marshal(p)
|
||||
_ = operatorlgmod.RecordOperation(manager, constant.ProductManagePage, constant.Delete, string(log), ctx.Request.URL.RequestURI())
|
||||
common.ServeJSON(ctx, stderr.Success, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user