@@ -0,0 +1 @@
|
||||
package discount_area_mod
|
||||
@@ -0,0 +1,123 @@
|
||||
package discount_area_mod
|
||||
|
||||
import (
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
var mdb *db.MongoDB
|
||||
|
||||
const (
|
||||
table = models.DiscountArea
|
||||
)
|
||||
|
||||
func coll(t *db.MongoTool) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(table)
|
||||
}
|
||||
return t.Coll(table)
|
||||
}
|
||||
|
||||
func GetNoStatusDiscountAreaByIds(ids []primitive.ObjectID) (list []DiscountArea, err error) {
|
||||
cond := bson.M{}
|
||||
cond["_id"] = bson.M{"$in": ids}
|
||||
if err = coll(nil).Find(&list, cond); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetNoStatusDiscountAreaByIds", table, "Find", err),
|
||||
log.Any("cond", cond),
|
||||
)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetDiscountAreaById 通过id获取上架的折扣区
|
||||
func GetDiscountAreaById(id primitive.ObjectID) (data DiscountArea, err error) {
|
||||
cond := bson.M{}
|
||||
cond["status"] = 1
|
||||
cond["_id"] = id
|
||||
if err = coll(nil).FindOne(&data, cond); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetDiscountAreaById", table, "FindOne", err),
|
||||
log.Any("cond", cond),
|
||||
)
|
||||
return data, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetDiscountAreaByIds 通过ids获取上架的折扣区
|
||||
func GetDiscountAreaByIds(ids []primitive.ObjectID) (list []DiscountArea, err error) {
|
||||
opts := options.FindOptions{}
|
||||
sort := bson.D{{Key: "sortCode", Value: -1}}
|
||||
opts.SetSort(sort)
|
||||
cond := bson.M{}
|
||||
cond["status"] = 1
|
||||
if len(ids) > 0 {
|
||||
cond["_id"] = bson.M{"$in": ids}
|
||||
}
|
||||
if err = coll(nil).Find(&list, cond, &opts); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetDiscountAreaByIds", table, "Find", err),
|
||||
log.Any("cond", cond),
|
||||
log.Any("sort", sort),
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetAllDiscountArea 获取所有上架的折扣区
|
||||
func GetAllDiscountArea() (list []DiscountArea, err error) {
|
||||
opts := options.FindOptions{}
|
||||
sort := bson.D{{Key: "sortCode", Value: -1}}
|
||||
opts.SetSort(sort)
|
||||
cond := bson.M{}
|
||||
cond["status"] = 1
|
||||
if err = coll(nil).Find(&list, cond, &opts); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetAllDiscountArea", table, "Find", err),
|
||||
log.Any("cond", cond),
|
||||
log.Any("sort", sort),
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetAllNoDeleteDiscountArea 获取没有被删除的专区
|
||||
func GetAllNoDeleteDiscountArea() (list []DiscountArea, err error) {
|
||||
opts := options.FindOptions{}
|
||||
sort := bson.D{{Key: "sortCode", Value: -1}}
|
||||
opts.SetSort(sort)
|
||||
cond := bson.M{}
|
||||
cond["status"] = bson.M{"$in": []int{0, 1}}
|
||||
if err = coll(nil).Find(&list, cond, &opts); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetAllNoDeleteDiscountArea", table, "Find", err),
|
||||
log.Any("cond", cond),
|
||||
log.Any("sort", sort),
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// AddDiscountArea 新增折扣专区
|
||||
func AddDiscountArea(model *DiscountArea) (err error) {
|
||||
if _, err = coll(nil).InsertOne(model); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "AddDiscountArea", table, "InsertOne", err))
|
||||
return err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateDiscountArea 修改折扣专区
|
||||
func UpdateDiscountArea(id primitive.ObjectID, update bson.M) (err error) {
|
||||
filter := bson.M{"_id": id}
|
||||
if _, err = coll(nil).UpdateOne(filter, bson.M{"$set": update}); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "UpdateDiscountArea", table, "UpdateOne", err))
|
||||
return err
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package discount_area_mod
|
||||
|
||||
import (
|
||||
"91porn-server/common/db"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DiscountArea 帖子打折专区
|
||||
type DiscountArea struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Title string `json:"title" bson:"title"` // 专区名
|
||||
Desc string `json:"desc" bson:"desc"` //专区描述
|
||||
Discount int `json:"discount" bson:"discount"` // 折扣,1折 10,1.5折 15
|
||||
Status int `json:"status" bson:"status"` // 0-未开启 1-开启 2-删除
|
||||
SortCode int `json:"sortCode" bson:"sortCode"` //排序字段
|
||||
RecommendNum int `json:"recommendNum" bson:"recommendNum"` // 推荐展示个数
|
||||
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
}
|
||||
|
||||
func Init() {
|
||||
mdb = db.Init(table)
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package discount_area_mod
|
||||
|
||||
import (
|
||||
"91porn-server/models/commod"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"time"
|
||||
)
|
||||
|
||||
type WebDiscountAreaListReq struct {
|
||||
}
|
||||
|
||||
type WebDiscountAreaListResp struct {
|
||||
List []DiscountArea `json:"list"`
|
||||
}
|
||||
|
||||
type WebDiscountAreaAddReq struct {
|
||||
Title string `json:"title" form:"title" binding:"required"` // 专区名
|
||||
Desc string `json:"desc" form:"desc"` //专区描述
|
||||
Discount uint `json:"discount" form:"discount" binding:"min=0,max=100"` // 折扣,1折 10,1.5折 15
|
||||
Status uint `json:"status" form:"status,omitempty"` // 0-未开启 1-开启
|
||||
SortCode uint `json:"sortCode" form:"sortCode"` //排序字段
|
||||
RecommendNum uint `json:"recommendNum" form:"recommendNum"` // 推荐展示个数
|
||||
}
|
||||
|
||||
type WebDiscountAreaUpdateReq struct {
|
||||
Id string `json:"id" form:"id" binding:"required"` // 专区名
|
||||
WebDiscountAreaUpdateData
|
||||
}
|
||||
|
||||
type WebDiscountAreaUpdateData struct {
|
||||
Title *string `json:"title" bson:"title,omitempty" form:"title"` // 专区名
|
||||
Desc *string `json:"desc" bson:"desc,omitempty" form:"desc"` //专区描述
|
||||
Discount *uint `json:"discount" bson:"discount,omitempty" form:"discount,omitempty"` // 折扣,1折 10,1.5折 15
|
||||
Status *uint `json:"status" bson:"status,omitempty" form:"status,omitempty"` // 0-未开启 1-开启
|
||||
SortCode *uint `json:"sortCode" bson:"sortCode,omitempty" form:"sortCode"` //排序字段
|
||||
RecommendNum *uint `json:"recommendNum" bson:"recommendNum,omitempty" form:"recommendNum"` // 推荐展示个数
|
||||
}
|
||||
|
||||
type WebDiscountAreaDeleteReq struct {
|
||||
ID string `json:"id" form:"id" binding:"required"`
|
||||
}
|
||||
|
||||
type WebDiscountAreaAddVidReq struct {
|
||||
DiscountAreaId primitive.ObjectID `json:"discountAreaId" form:"discountAreaId" binding:"required"`
|
||||
VIds []primitive.ObjectID `json:"vids" form:"vids" binding:"required"`
|
||||
}
|
||||
|
||||
type WebDiscountAreaDeleteVidReq struct {
|
||||
Ids []primitive.ObjectID `json:"ids" form:"ids" binding:"required"`
|
||||
}
|
||||
|
||||
type WebDiscountAreaVidsReq struct {
|
||||
commod.Page
|
||||
DiscountAreaId string `json:"discountAreaId" form:"discountAreaId"` // 折扣专区id
|
||||
Vid string `json:"vid" form:"vid"` // 视频id
|
||||
}
|
||||
|
||||
type WebDiscountAreaVidsResp struct {
|
||||
List []WebDiscountAreaVideo `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
type WebDiscountAreaVideo struct {
|
||||
Id primitive.ObjectID `json:"id"` // 记录id
|
||||
VideoID primitive.ObjectID `json:"videoID"` // 视频ID
|
||||
Title string `json:"title"` // 标题
|
||||
PublisherID uint64 `json:"publisherID"` // 发布用户ID
|
||||
Cover string `json:"cover"` // 视频封面图
|
||||
DiscountAreaTitle string `json:"discountAreaTitle"` // 折扣专区标题
|
||||
DiscountAreaId primitive.ObjectID `json:"discountAreaId"` // 折扣专区id
|
||||
OriginalPrice int64 `json:"originalPrice"` // 原价
|
||||
DiscountedPrice int64 `json:"discountedPrice"` // 折扣区价格
|
||||
UpdatedAt time.Time `json:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt"` // 创建时间
|
||||
}
|
||||
Reference in New Issue
Block a user