Initial commit: web_hghl_server
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package srv_contactus
|
||||
|
||||
import (
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/models/contactusmod"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func GetContactusList(ctx *gin.Context, req *GetContactusListReq) (resp *GetContactusListResp, err *srvdef.SrvErr) {
|
||||
filter := bson.M{}
|
||||
if req.CategoryName != nil && len(*req.CategoryName) > 0 {
|
||||
filter[contactusmod.FN.ContactUsModel.CategoryName] = *req.CategoryName
|
||||
}
|
||||
if req.Ip != nil && len(*req.Ip) > 0 {
|
||||
filter[contactusmod.FN.ContactUsModel.Ip] = *req.Ip
|
||||
}
|
||||
if req.Name != nil && len(*req.Name) > 0 {
|
||||
filter[contactusmod.FN.ContactUsModel.Name] = *req.Name
|
||||
}
|
||||
if req.Email != nil && len(*req.Email) > 0 {
|
||||
filter[contactusmod.FN.ContactUsModel.Email] = *req.Email
|
||||
}
|
||||
var total int64
|
||||
total, err = contactusmod.CountContactUsModels(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("GetContactusList.CountContactUsModels", log.Any("filter", filter), log.E(err))
|
||||
return
|
||||
}
|
||||
resp = &GetContactusListResp{
|
||||
Total: 0,
|
||||
List: make(contactusmod.ContactUsModelList, 0),
|
||||
}
|
||||
if total == 0 {
|
||||
return resp, nil
|
||||
}
|
||||
opts := &options.FindOptions{}
|
||||
opts.SetSort(bson.M{contactusmod.FN.ContactUsModel.CreatedAt: -1})
|
||||
opts.SetLimit(req.PageSize).SetSkip((req.PageNum - 1) * req.PageSize)
|
||||
list, err := contactusmod.FindManyContactUsModel(ctx, filter, opts)
|
||||
if err != nil {
|
||||
log.Warn("GetContactusList.FindManyContactUsModels", log.Any("filter", filter), log.E(err))
|
||||
return
|
||||
}
|
||||
resp.List = list
|
||||
return resp, nil
|
||||
}
|
||||
func DelContactus(ctx *gin.Context, id primitive.ObjectID) *srvdef.SrvErr {
|
||||
if id.IsZero() {
|
||||
return srvdef.New(srvdef.ErrParamError)
|
||||
}
|
||||
_, err := contactusmod.DelOneContactUsModel(ctx, bson.M{contactusmod.FN.ContactUsModel.Id: id})
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateContactus(ctx *gin.Context, id primitive.ObjectID, status int64) *srvdef.SrvErr {
|
||||
if id.IsZero() {
|
||||
return srvdef.New(srvdef.ErrParamError)
|
||||
}
|
||||
err := contactusmod.UpdateOneContactUsModel(ctx, bson.M{contactusmod.FN.ContactUsModel.Id: id}, bson.M{
|
||||
"$set": bson.M{contactusmod.FN.ContactUsModel.Status: status},
|
||||
})
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package srv_contactus
|
||||
|
||||
import (
|
||||
"videoweb/pub/models/contactusmod"
|
||||
"videoweb/pub/pubdef"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type GetContactusListReq struct {
|
||||
pubdef.Page
|
||||
Ip *string `form:"ip" json:"ip"` // ip
|
||||
Name *string `form:"name" json:"name"` // 姓名
|
||||
Email *string `form:"email" json:"email"` // 邮箱
|
||||
CategoryName *string `form:"categoryName" json:"categoryName"` // 分类
|
||||
}
|
||||
|
||||
type GetContactusListResp struct {
|
||||
Total int64 `json:"total"`
|
||||
List contactusmod.ContactUsModelList `json:"list"`
|
||||
}
|
||||
|
||||
type DelOneContactusReq struct {
|
||||
Id primitive.ObjectID `form:"id" json:"id"`
|
||||
}
|
||||
|
||||
type UpdateContactusReq struct {
|
||||
Id primitive.ObjectID `form:"id" json:"id"`
|
||||
Status int64 `form:"status" json:"status"`
|
||||
}
|
||||
Reference in New Issue
Block a user