Files
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

147 lines
5.3 KiB
Go

package userctrl
import (
"91porn-server/common"
"91porn-server/common/stderr"
"91porn-server/models/commod"
"91porn-server/models/v/faqmod"
"91porn-server/web/service/userser"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// FaqList doc
// @Summary 用户常见问题
// @Description 用户常见问题列表
// @Tags web-用户管理
// @Accept mpfd,json
// @Produce json,html
// @Param category query string false "问题类型"
// @Param keywords query string false "查找关键字"
// @Param pageNumber query integer true "当前页"
// @Param pageSize query integer true "每页条数"
// @Success 200 {string} json "{"msg": "操作成功", "date": { "total":10, "list":[] }}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /web/user/faq/list [get]
func FaqList(c *gin.Context) {
var args struct {
Category string `form:"category" json:"category"`
Keywords string `form:"keywords" json:"keywords"`
commod.Page
}
if err := c.ShouldBind(&args); err != nil {
common.ServeJSON(c, stderr.ErrParamError, "web user FaqList arg error "+err.Error())
return
}
pageBy := commod.PageBy{Num: args.PageNumber, Size: args.PageSize}
page, err := userser.FaqList(args.Category, args.Keywords, commod.StdQuery{Page: &pageBy})
if err != nil {
common.ServeJSON(c, stderr.Failure, "web user FaqList error: "+err.Error())
return
}
common.ServeJSON(c, stderr.Success, page)
}
// FaqAdd doc
// @Summary 用户常见问题
// @Description 新增用户常见问题
// @Tags web-用户管理
// @Accept mpfd,json
// @Produce json,html
// @Param category formData string true "问题类型"
// @Param query formData string true "问题"
// @Param answer formData string true "问题答案"
// @Param status formData boolean true "状态 ture为开启 false为关闭"
// @Param sortCode formData string false "排序号""
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /web/user/faq/add [post]
func FaqAdd(ctx *gin.Context) {
f := faqmod.Faq{}
if err := ctx.ShouldBind(&f); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
return
}
code, err := faqmod.FaqInsert(f)
if err != nil {
common.ServeJSON(ctx, code, err.Error())
return
}
common.ServeJSON(ctx, stderr.Success, nil)
}
// FaqDelete doc
// @Summary 用户常见问题
// @Description 批量删除用户常见问题
// @Tags web-用户管理
// @Accept mpfd,json
// @Produce json,html
// @Param ids formData array true "id数组 字符串数组"
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /web/user/faq/del [delete]
func FaqDelete(ctx *gin.Context) {
var args struct {
IDs []primitive.ObjectID `form:"ids" json:"ids"`
}
if err := ctx.ShouldBind(&args); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
return
}
if err := faqmod.FaqDelete(args.IDs); err != nil {
common.ServeJSON(ctx, stderr.ErrDbDeleteError, err.Error())
return
}
common.ServeJSON(ctx, stderr.Success, nil)
}
// FaqUpdate doc
// @Summary 用户常见问题
// @Description 编辑常见问题
// @Tags web-用户管理
// @Accept mpfd,json
// @Produce json,html
// @Param id formData array true "id字符串"
// @Param category formData string false "问题类型"
// @Param query formData string false "问题"
// @Param answer formData string false "问题答案"
// @Param status formData boolean false "状态 ture为开启 false为关闭"
// @Param sortCode formData string false "排序号""
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /web/user/faq/update [post]
func FaqUpdate(ctx *gin.Context) {
var args struct {
ID primitive.ObjectID `form:"id" json:"id" binding:"required"`
faqmod.FaqUpdateDoc
}
if err := ctx.ShouldBind(&args); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, nil)
return
}
if err := faqmod.FaqUpdate(args.ID, args.FaqUpdateDoc); err != nil {
common.ServeJSON(ctx, stderr.ErrDbUpdateError, err.Error())
return
}
common.ServeJSON(ctx, stderr.Success, nil)
}
// FaqCateList doc
// @Summary 用户常见问题
// @Description 用户常见问题分类列表
// @Tags web-用户管理
// @Accept mpfd,json
// @Produce json,html
// @Success 200 {string} json "{"msg": "操作成功", "date": {}}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /web/user/faq/cate/list [get]
func FaqCateList(c *gin.Context) {
page, err := faqmod.FaqCateList()
if err != nil {
common.ServeJSON(c, stderr.Failure, "web user FaqCateList error: "+err.Error())
return
}
common.ServeJSON(c, stderr.Success, page)
}