forked from all_user/stat_center
Initial commit
This commit is contained in:
Executable
+58
@@ -0,0 +1,58 @@
|
||||
package syncvip
|
||||
|
||||
type TagSyncVip struct {
|
||||
Amount string
|
||||
AppId string
|
||||
BlocDeduction string
|
||||
BuyVIPType string
|
||||
CreatedAt string
|
||||
DeviceType string
|
||||
DistrictCode string
|
||||
ID string
|
||||
IsDeduction string
|
||||
IsDirect string
|
||||
Money string
|
||||
Name string
|
||||
OID string
|
||||
PlatformId string
|
||||
PromCode string
|
||||
Rate string
|
||||
RegisterTime string
|
||||
Repeat string
|
||||
Status string
|
||||
SuccessAt string
|
||||
UID string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
SyncVip TagSyncVip
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
SyncVip string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.SyncVip.Amount = "amount"
|
||||
FN.SyncVip.AppId = "appId"
|
||||
FN.SyncVip.BlocDeduction = "blocDeduction"
|
||||
FN.SyncVip.BuyVIPType = "buyVIPType"
|
||||
FN.SyncVip.CreatedAt = "createdAt"
|
||||
FN.SyncVip.DeviceType = "deviceType"
|
||||
FN.SyncVip.DistrictCode = "districtCode"
|
||||
FN.SyncVip.ID = "_id"
|
||||
FN.SyncVip.IsDeduction = "isDeduction"
|
||||
FN.SyncVip.IsDirect = "isDirect"
|
||||
FN.SyncVip.Money = "money"
|
||||
FN.SyncVip.Name = "name"
|
||||
FN.SyncVip.OID = "oid"
|
||||
FN.SyncVip.PlatformId = "platformId"
|
||||
FN.SyncVip.PromCode = "promCode"
|
||||
FN.SyncVip.Rate = "rate"
|
||||
FN.SyncVip.RegisterTime = "registerTime"
|
||||
FN.SyncVip.Repeat = "repeat"
|
||||
FN.SyncVip.Status = "status"
|
||||
FN.SyncVip.SuccessAt = "successAt"
|
||||
FN.SyncVip.UID = "uid"
|
||||
TN.SyncVip = "sync_vip"
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package syncvip
|
||||
|
||||
import (
|
||||
"stat/common/topicmessage"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// 帖子模型,数据库中的
|
||||
// @table:sync_vip
|
||||
type SyncVip struct {
|
||||
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // ID
|
||||
PlatformId string `json:"platformId" bson:"platformId"` // 原始平台订单Id
|
||||
AppId int32 `json:"appId" bson:"appId"` //appID
|
||||
UID uint64 `json:"uid" bson:"uid"` //用户id
|
||||
Name string `json:"name" bson:"name"` //用户名
|
||||
Money int64 `json:"money" bson:"money"` //提现金额
|
||||
Amount int64 `json:"amount" bson:"amount"` //提现金额
|
||||
BuyVIPType topicmessage.BuyVIPType `json:"buyVIPType" bson:"buyVIPType"` //支付方式
|
||||
OID string `json:"oid" bson:"oid"` //第三方支付平台id
|
||||
DeviceType string `json:"deviceType" bson:"deviceType"` //设备类型
|
||||
Status int `json:"status" bson:"status"` //1未审核 5提现成功
|
||||
SuccessAt time.Time `json:"successAt" bson:"successAt"` //回调成功时间
|
||||
BlocDeduction bool `json:"blocDeduction" bson:"blocDeduction"` // 集团扣量(特定渠道扣量)
|
||||
PromCode string `json:"promCode,omitempty" bson:"promCode"` // 用户推广序列
|
||||
RegisterTime time.Time `json:"registerTime,omitempty" bson:"registerTime"` // 操作时间
|
||||
IsDirect bool `json:"isDirect" bson:"isDirect"` // true:是直推用户
|
||||
DistrictCode string `json:"districtCode" bson:"districtCode"` // 渠道码
|
||||
Rate string `json:"rate" bson:"rate"` // 渠道费率
|
||||
IsDeduction bool `json:"isDeduction" bson:"isDeduction"` // true:CPS扣量用户
|
||||
IsFormalUser bool `json:"isFormalUser" bson:"isFormalUser"` // 是否正式用户
|
||||
Repeat bool `bson:"repeat" json:"repeat"` // 复冲: true 重复充值 false 第一次
|
||||
CreatedAt time.Time `bson:"createdAt"` // 创建时间
|
||||
}
|
||||
type SyncVipList []*SyncVip
|
||||
@@ -0,0 +1,128 @@
|
||||
package syncvip
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
var db *mongos.MongoTool
|
||||
|
||||
func Init(ctx context.Context) {
|
||||
// 获取数据库表
|
||||
db = mongos.New(mongos.MgoManager, TN.SyncVip)
|
||||
// 初始化索引
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.SyncVip.UID, Value: 1},
|
||||
{Key: FN.SyncVip.AppId, Value: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(SyncVip:initSyncVipIndex) Create SyncVip Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
//InsertOneSyncVip 插入一个VIP购买记录
|
||||
func InsertOneSyncVip(ctx context.Context, SyncVip *SyncVip) error {
|
||||
if _, err := db.InsertOne(ctx, SyncVip); err != nil {
|
||||
log.Warn("SyncVip:InsertOneSyncVip db.InsertOne failed", log.E(err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//FindOneSyncVip 查找一个VIP购买记录
|
||||
func FindOneSyncVip(ctx context.Context, filter bson.M) (
|
||||
*SyncVip, error) {
|
||||
var SyncVip SyncVip
|
||||
if err := db.FindOne(ctx, &SyncVip, filter); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SyncVip, nil
|
||||
}
|
||||
|
||||
//DelOneSyncVip 删除一个VIP购买记录
|
||||
func DelOneSyncVip(ctx context.Context, filter bson.M) (
|
||||
int64, error) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("SyncVip:DelOneSyncVip db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
//UpdateOneSyncVip 更新一个VIP购买记录
|
||||
func UpdateOneSyncVip(ctx context.Context, filter bson.M, update bson.M) error {
|
||||
_, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("user:UpdateOneSyncVip db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//CountSyncVips 统计VIP购买记录数量
|
||||
func CountSyncVips(ctx context.Context, filter bson.M) (
|
||||
int64, error) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("SyncVip:CountSyncVips db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
//UpdateManySyncVip 更新满足条件的VIP购买记录
|
||||
func UpdateManySyncVip(ctx context.Context, filter bson.M, update bson.M) error {
|
||||
_, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("user:UpdateManySyncVip db.UpdateMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//FindManySyncVip 查找一批VIP购买记录数据
|
||||
func FindManySyncVip(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (SyncVipList, error) {
|
||||
data := make(SyncVipList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("SyncVip:FindManySyncVip db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
//FindManySyncVipWithBind 用自己定义结构查找一批VIP购买记录数据
|
||||
func FindManySyncVipWithBind(ctx context.Context, bind interface{}, filter bson.M,
|
||||
opts ...*options.FindOptions) error {
|
||||
if err := db.Find(ctx, bind, filter, opts...); err != nil {
|
||||
log.Warn("SyncVip:FindManySyncVipWithBind db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//AggregateSyncVips 聚合查找一批VIP购买记录信息
|
||||
func AggregateSyncVips(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) error {
|
||||
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("feedback:AggregateSyncVips db.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user