Initial commit
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
package landingPage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
"stat/common/utils"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// 初始化model
|
||||
func Init() {
|
||||
// 获取数据库表
|
||||
db = mongos.New(mongos.MgoManager, CollLandingPage)
|
||||
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{{Key: "appId", Value: 1}},
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
|
||||
panic(fmt.Sprintf("%s model set index err ==>[%+v]", CollLandingPage, err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FindLandingPageList 获取渠道转账列表
|
||||
func FindLandingPageList(ctx context.Context, appid int32, skip, limit int64) (count int64, data []LandingPage, err error) {
|
||||
filter := bson.M{"appId": appid}
|
||||
|
||||
sort := bson.D{{Key: "status", Value: -1}, {Key: "createdAt", Value: -1}}
|
||||
|
||||
opts := options.Find().SetSort(sort).SetSkip(skip).SetLimit(limit)
|
||||
|
||||
if err = db.Find(ctx, &data, filter, opts); err != nil {
|
||||
log.Error("LandingPage FindLandingPageList Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
if count, err = db.Count(ctx, filter); err != nil {
|
||||
log.Error("LandingPage FindLandingPageList Count err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// AddLandingPage 添加落地页请求
|
||||
func AddLandingPage(ctx context.Context, doc *LandingPage) (id string, err error) {
|
||||
if id, err = db.InsertOne(ctx, doc); err != nil {
|
||||
log.Error("LandingPage AddLandingPage InsertOne err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FindLandingPage 查询订单
|
||||
func FindLandingPage(ctx context.Context, id int64) (w LandingPage, err error) {
|
||||
var filter = bson.M{"_id": id}
|
||||
|
||||
if err = db.FindOne(ctx, &w, filter); err != nil {
|
||||
log.Error("LandingPage FindLandingPage FindOne err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateLandingPage 更新落地页成功
|
||||
func UpdateLandingPage(ctx context.Context, id int64, doc UpdateDoc) (err error) {
|
||||
|
||||
var filter = bson.M{"_id": id}
|
||||
|
||||
update, _ := utils.ToBsonM(doc)
|
||||
|
||||
if _, err = db.UpdateOne(ctx, filter, bson.M{"$set": update}); err != nil {
|
||||
log.Error("LandingPage UpdateLandingPageSuccess UpdateOne err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DelLandingPage 删除落地页
|
||||
func DelLandingPage(ctx context.Context, id int64) (err error) {
|
||||
filter := bson.M{"_id": id}
|
||||
|
||||
if _, err = db.DeleteOne(ctx, filter); err != nil {
|
||||
log.Error("LandingPage DelLandingpage DeleteOne err", log.E(err))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// FindChannelCodeLandingPage 根据 app 获取落地页
|
||||
func FindChannelCodeLandingPage(ctx context.Context, appIds []int32) (data []LandingPage, err error) {
|
||||
if len(appIds) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
filter := bson.M{"appId": bson.M{"$in": appIds}, "status": true, "type": 1}
|
||||
|
||||
if err = db.Find(ctx, &data, filter); err != nil {
|
||||
log.Error("LandingPage FindLandingPageByAppsId Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// FindShareLandingPage 根据 app 获取落地页
|
||||
func FindShareLandingPage(ctx context.Context, appId int32) (data []LandingPage, err error) {
|
||||
|
||||
filter := bson.M{"appId": appId, "status": true, "type": 2}
|
||||
|
||||
if err = db.Find(ctx, &data, filter); err != nil {
|
||||
log.Error("LandingPage FindLandingPageByAppsId Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// FindAllLandingPage 获取所有落地页
|
||||
func FindAllLandingPage(ctx context.Context) (data []LandingPage, err error) {
|
||||
filter := bson.M{"status": true}
|
||||
|
||||
sort := bson.D{{Key: "createdAt", Value: -1}}
|
||||
|
||||
opts := options.Find().SetSort(sort)
|
||||
|
||||
if err = db.Find(ctx, &data, filter, opts); err != nil {
|
||||
log.Error("LandingPage FindAllLandingPage Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FindChannelLandingPage 获取配置渠道的落地页
|
||||
func FindChannelLandingPage(ctx context.Context) (data []LandingPage, err error) {
|
||||
filter := bson.M{"channelCode": bson.M{"$gt": ""}}
|
||||
|
||||
sort := bson.D{{Key: "createdAt", Value: -1}}
|
||||
|
||||
opts := options.Find().SetSort(sort)
|
||||
|
||||
if err = db.Find(ctx, &data, filter, opts); err != nil {
|
||||
log.Error("LandingPage FindChannelLandingPage Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user