+74
@@ -0,0 +1,74 @@
|
||||
package nakedchatdata
|
||||
|
||||
import (
|
||||
"91porn-server/models/v/nakedchatmod"
|
||||
)
|
||||
|
||||
// FormatAppDataList 格式化app列表数据
|
||||
func FormatAppDataList(origin []nakedchatmod.NakedChat) (res []*nakedchatmod.NakedChatSimple) {
|
||||
res = make([]*nakedchatmod.NakedChatSimple, len(origin))
|
||||
if len(origin) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// 组装返回数据
|
||||
for i, item := range origin {
|
||||
res[i] = FormatAppSimpleData(item)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FormatAppSimpleData 格式化app数据
|
||||
func FormatAppSimpleData(item nakedchatmod.NakedChat) (res *nakedchatmod.NakedChatSimple) {
|
||||
if item.ID.IsZero() {
|
||||
return
|
||||
}
|
||||
|
||||
// 组装返回数据
|
||||
res = &nakedchatmod.NakedChatSimple{
|
||||
ID: item.ID,
|
||||
Title: item.Title,
|
||||
Cover: item.Cover,
|
||||
Price: item.Price,
|
||||
Age: item.Age,
|
||||
Weight: item.Weight,
|
||||
Height: item.Height,
|
||||
Cup: item.Cup,
|
||||
SaleNum: item.SaleNum + item.FakeSaleNum,
|
||||
CreatedAt: item.CreatedAt,
|
||||
UpdatedAt: item.UpdatedAt,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FormatAppData 格式化app数据
|
||||
func FormatAppData(item nakedchatmod.NakedChat) (res *nakedchatmod.NakedChatInfo) {
|
||||
if item.ID.IsZero() {
|
||||
return
|
||||
}
|
||||
|
||||
// 组装返回数据
|
||||
res = &nakedchatmod.NakedChatInfo{
|
||||
ID: item.ID,
|
||||
Title: item.Title,
|
||||
Cover: item.Cover,
|
||||
Price: item.Price,
|
||||
Options: item.Options,
|
||||
Images: item.Images,
|
||||
Video: item.Video,
|
||||
Contact: item.Contact,
|
||||
Age: item.Age,
|
||||
Weight: item.Weight,
|
||||
Height: item.Height,
|
||||
Cup: item.Cup,
|
||||
SaleNum: item.SaleNum + item.FakeSaleNum,
|
||||
BusinessHours: item.BusinessHours,
|
||||
Summary: item.Summary,
|
||||
CreatedAt: item.CreatedAt,
|
||||
UpdatedAt: item.UpdatedAt,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
package nakedchatdata
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/common/cachev2"
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/models"
|
||||
"91porn-server/models/v/nakedchatmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type ListRes struct {
|
||||
List []nakedchatmod.NakedChat
|
||||
Count int64
|
||||
HasNext bool
|
||||
}
|
||||
|
||||
// GetListFromCache 从缓存获取列表数据
|
||||
func GetListFromCache(cond bson.M, skip, limit int64, sort bson.D) ([]nakedchatmod.NakedChat, int64, bool, error) {
|
||||
var data ListRes
|
||||
_, err := cachev2.Classes().CacheTime(10*time.Minute).AutoListKey(models.NakedChat).ResBind(&data).Cache(GetListData, cond, skip, limit, sort)
|
||||
return data.List, data.Count, data.HasNext, err
|
||||
}
|
||||
|
||||
// GetListData 获取列表数据并组装适合缓存格式返回
|
||||
func GetListData(cond bson.M, skip, limit int64, sort bson.D) (res ListRes, err error) {
|
||||
res.List, res.Count, res.HasNext, err = nakedchatmod.GetList(cond, skip, limit, sort)
|
||||
return
|
||||
}
|
||||
|
||||
// GetInfoFromCache 获取数据详情
|
||||
func GetInfoFromCache(id primitive.ObjectID) (res nakedchatmod.NakedChat, err error) {
|
||||
_, err = cachev2.Classes().CacheTime(30*time.Minute).AutoInfoKey(models.NakedChat, id.Hex()).ResBind(&res).Cache(nakedchatmod.GetInfo, id)
|
||||
return
|
||||
}
|
||||
|
||||
// GetAllFromCache 获取所有数据
|
||||
func GetAllFromCache(cond bson.M, sort bson.D) (res []nakedchatmod.NakedChat, err error) {
|
||||
_, err = cachev2.Classes().CacheTime(30*time.Minute).AutoListKey(models.NakedChat+"-all").ResBind(&res).Cache(nakedchatmod.GetAll, cond, sort)
|
||||
return
|
||||
}
|
||||
|
||||
// InsertData 插入数据
|
||||
func InsertData(t *db.MongoTool, data nakedchatmod.NakedChat) (primitive.ObjectID, error) {
|
||||
newID, err := nakedchatmod.Insert(t, data)
|
||||
if err != nil {
|
||||
return newID, err
|
||||
}
|
||||
// 清除缓存数据
|
||||
_, err = cachev2.Classes().Table(models.NakedChat).AutoClear(true, nil)
|
||||
if err != nil {
|
||||
return newID, err
|
||||
}
|
||||
return newID, nil
|
||||
}
|
||||
|
||||
// UpdateData 更新数据
|
||||
func UpdateData(t *db.MongoTool, id string, data map[string]interface{}) (int64, error) {
|
||||
objID, err := primitive.ObjectIDFromHex(id)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
affect, err := nakedchatmod.UpdateByID(t, objID, data)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 清理缓存
|
||||
_, _ = cachev2.Classes().Table(models.NakedChat).AutoClear(true, &id)
|
||||
|
||||
return affect, err
|
||||
}
|
||||
|
||||
// DeleteData 删除数据
|
||||
func DeleteData(t *db.MongoTool, id primitive.ObjectID) (err error) {
|
||||
err = nakedchatmod.DeleteByID(t, id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 清理缓存
|
||||
all := "*"
|
||||
_, _ = cachev2.Classes().Table(models.NakedChat).AutoClear(true, &all)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user