89 lines
2.5 KiB
Go
89 lines
2.5 KiB
Go
package annouser
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"91porn-server/common/log"
|
|
"91porn-server/common/stderr"
|
|
"91porn-server/models/v/annoumod"
|
|
"91porn-server/web/vidhelp"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
// GetAnnounceList 获取会员中心跑马灯列表
|
|
func GetAnnounceListApi() (code stderr.Code, announce string) {
|
|
aInfos, err := annoumod.GetAnnounceApi("createdAt", -1)
|
|
if err != nil && err != mongo.ErrNoDocuments {
|
|
return stderr.ErrDbQueryError, ""
|
|
}
|
|
if err == mongo.ErrNoDocuments || len(aInfos) <= 0 {
|
|
return stderr.Success, ""
|
|
}
|
|
return stderr.Success, aInfos[0].Content
|
|
}
|
|
|
|
// GetAnnounceList 获取会员中心跑马灯列表
|
|
func GetAnnounceList() (code stderr.Code, data []annoumod.Announce) {
|
|
aInfos, err := annoumod.GetAnnounce("createdAt", -1)
|
|
if err != nil && err != mongo.ErrNoDocuments {
|
|
return stderr.ErrDbQueryError, nil
|
|
}
|
|
if err == mongo.ErrNoDocuments || len(aInfos) <= 0 {
|
|
return stderr.Success, nil
|
|
}
|
|
return stderr.Success, aInfos
|
|
}
|
|
|
|
// UpdateAnnounce 更新会员中心跑马灯信息
|
|
func UpdateAnnounce(req annoumod.EditAnnounceReq) (code stderr.Code, data interface{}) {
|
|
oid, err := primitive.ObjectIDFromHex(req.ID)
|
|
if err != nil {
|
|
log.Error(fmt.Sprintf("exchange string(%s) to objectID error.", req.ID))
|
|
return stderr.ErrParamError, nil
|
|
}
|
|
m := vidhelp.Struct2Map(req.EditAnnounceInfo)
|
|
cnt, err := annoumod.UpdateAnnounce(oid, m)
|
|
if err != nil {
|
|
return stderr.ErrDbUpdateError, nil
|
|
}
|
|
return stderr.Success, annoumod.OpeResp{Count: cnt}
|
|
}
|
|
|
|
// DeleteAnnounce 删除会员中心跑马灯
|
|
func DeleteAnnounce(ids []string) (code stderr.Code, data interface{}) {
|
|
oids := make([]primitive.ObjectID, 0, len(ids))
|
|
for _, id := range ids {
|
|
oid, err := primitive.ObjectIDFromHex(id)
|
|
if err != nil {
|
|
log.Error(fmt.Sprintf("exchange string(%s) to objectID error.", id))
|
|
continue
|
|
}
|
|
oids = append(oids, oid)
|
|
}
|
|
cnt, err := annoumod.DeleteAnnounce(oids)
|
|
if err != nil {
|
|
return stderr.ErrDbUpdateError, nil
|
|
}
|
|
return stderr.Success, annoumod.OpeResp{Count: cnt}
|
|
}
|
|
|
|
// AddAnnounce 添加会员中心跑马灯
|
|
func AddAnnounce(req annoumod.AddAnnounceReq) (code stderr.Code) {
|
|
infos := []annoumod.Announce{annoumod.Announce{
|
|
ID: primitive.NewObjectID(),
|
|
Content: req.Content,
|
|
Url: req.Url,
|
|
Type: annoumod.UserCenter,
|
|
Active: req.Active,
|
|
CreatedAt: time.Now(),
|
|
UpdatedAt: time.Now(),
|
|
}}
|
|
if err := annoumod.AddAnnounce(infos); err != nil {
|
|
return stderr.ErrDbInsertError
|
|
}
|
|
return stderr.Success
|
|
}
|