@@ -0,0 +1,108 @@
|
||||
package lotterylgmod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/common/timeutil/timerange"
|
||||
"91porn-server/models"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
const table = models.LotteryLog
|
||||
|
||||
var mdb *db.MongoDB
|
||||
|
||||
func coll(t *db.MongoTool) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(table)
|
||||
}
|
||||
return t.Coll(table)
|
||||
}
|
||||
|
||||
// initIndexAds 初始化索引
|
||||
func initIndex() {
|
||||
many := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{{Key: "uid", Value: 1}, {Key: "createdAt", Value: 1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "code", Value: 1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "createdAt", Value: 1}},
|
||||
},
|
||||
}
|
||||
if _, err := coll(nil).CreateIndex(many); err != nil {
|
||||
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertLog 记录一个抽奖号行为
|
||||
func InsertLog(uid uint64, code int, gateName string) error {
|
||||
ll := LotteryLog{
|
||||
UID: uid,
|
||||
Code: code,
|
||||
GateName: gateName,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
if _, err := coll(nil).InsertOne(ll); err != nil {
|
||||
log.Error("InsertClickLog error", log.Any("ll", ll), log.E(err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UserTodayChances 获取用户当日抽奖号数量
|
||||
func UserTodayChances(uid uint64) (int, error) {
|
||||
sumDate := timerange.LocDayRange(time.Now()).Head
|
||||
ll := []LotteryLog{}
|
||||
cond := bson.M{"uid": uid, "createdAt": bson.M{"$gte": sumDate}}
|
||||
if err := coll(nil).Find(&ll, cond); err != nil {
|
||||
log.Error("UserTodayChances error", log.Any("uid", uid), log.E(err))
|
||||
return 0, err
|
||||
}
|
||||
return len(ll), nil
|
||||
}
|
||||
|
||||
// LottnumList 获取摇号列表
|
||||
func LottnumList(page, size uint64, start *time.Time, end *time.Time, uid *uint64, code *int) ([]LotteryLog, int64, error) {
|
||||
back := []LotteryLog{}
|
||||
cond := bson.M{}
|
||||
if uid != nil {
|
||||
cond["uid"] = *uid
|
||||
}
|
||||
if code != nil {
|
||||
cond["code"] = *code
|
||||
}
|
||||
if start != nil && end != nil {
|
||||
cond["createdAt"] = bson.M{"$gte": *start, "$lt": *end}
|
||||
}
|
||||
sort := bson.D{{Key: "createdAt", Value: -1}}
|
||||
skip := (page - 1) * size
|
||||
opts := options.FindOptions{}
|
||||
opts.SetSort(sort).SetSkip(int64(skip)).SetLimit(int64(size))
|
||||
if err := coll(nil).Find(&back, bson.M(cond), &opts); err != nil {
|
||||
log.Error("LottnumList error", log.Any("page", page), log.Any("size", size), log.Any("cond", cond), log.E(err))
|
||||
return back, 0, err
|
||||
}
|
||||
total, _ := coll(nil).Count(cond)
|
||||
return back, total, nil
|
||||
}
|
||||
|
||||
// UserTodayNum 获取用户当日抽奖号
|
||||
func UserTodayNum(uid uint64) ([]LotteryLog, error) {
|
||||
sumDate := timerange.LocDayRange(time.Now()).Head
|
||||
ll := []LotteryLog{}
|
||||
cond := bson.M{"uid": uid, "createdAt": bson.M{"$gte": sumDate}}
|
||||
if err := coll(nil).Find(&ll, cond); err != nil {
|
||||
log.Error("UserTodayChances error", log.Any("uid", uid), log.E(err))
|
||||
return ll, err
|
||||
}
|
||||
return ll, nil
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package lotterylgmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/common/db"
|
||||
)
|
||||
|
||||
// LotteryLog 活动摇号日志
|
||||
type LotteryLog struct {
|
||||
UID uint64 `json:"uid" bson:"uid"`
|
||||
Code int `json:"code" bson:"code"`
|
||||
GateName string `json:"gateName" bson:"gateName"`
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
|
||||
}
|
||||
|
||||
func Init() {
|
||||
mdb = db.Init(table)
|
||||
initIndex()
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package lotterylgmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/models/commod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// AdsClickResp 广告点击日志应答
|
||||
type AdsClickResp struct {
|
||||
Logs int `json:"logs"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
// AdsCountResp 广告点击统计应答
|
||||
type AdsCountResp struct {
|
||||
ID string `json:"id"`
|
||||
TodayCnt int64 `json:"todayCnt"`
|
||||
YesterdayCnt int64 `json:"yesterdayCnt"`
|
||||
WeekCnt int64 `json:"weekCnt"`
|
||||
MonthCnt int64 `json:"monthCnt"`
|
||||
TotalCnt int64 `json:"totalCnt"`
|
||||
}
|
||||
|
||||
type AdsClickReq struct {
|
||||
UID uint64 `form:"uid" json:"uid"`
|
||||
Start time.Time `form:"start" json:"start"`
|
||||
End time.Time `form:"end" json:"end"`
|
||||
Sort string `form:"sort" json:"sort"`
|
||||
Desc int `form:"desc" json:"desc"`
|
||||
commod.Page
|
||||
}
|
||||
|
||||
// AdsClickInfo
|
||||
type AdsClickInfo struct {
|
||||
AID primitive.ObjectID `json:"aid"` //广告id
|
||||
TodayCount int64 `json:"todayCount"` //今日点击数
|
||||
YesterdayCount int64 `json:"yesterdayCount"` //昨日点击数
|
||||
WeekCount int64 `json:"weekCount"` //本周点击数
|
||||
MonthCount int64 `json:"monthCount"` //本月点击数
|
||||
TotalCount int64 `json:"totalCount"` //总点击数
|
||||
}
|
||||
|
||||
// AdsStatisticResp 广告点击统计应答
|
||||
type AdsStatisticResp struct {
|
||||
Logs []AdsClickInfo `json:"logs"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
Reference in New Issue
Block a user