Initial commit
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package rechargechannelmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func Init() {
|
||||
db = mongos.New(mongos.MgoManager, CollRechargeChannel)
|
||||
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{{Key: "sumDate", Value: 1}},
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
|
||||
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollRechargeChannel, err))
|
||||
}
|
||||
}
|
||||
|
||||
// UpsertOneUserRechargeStat 更新或插入一条支付渠道统计
|
||||
func UpsertOneUserRechargeStat(ctx context.Context, channelName string, appId int32, sumDate time.Time, blocDeduction bool, money, paymoney, channelMoney int64) (err error) {
|
||||
filter := bson.M{"channelName": channelName, "appId": appId, "sumDate": sumDate}
|
||||
|
||||
update := bson.M{}
|
||||
|
||||
update["orderCount"] = 1
|
||||
update["totalOrderMoney"] = money
|
||||
update["TotalOrderPayMoney"] = paymoney
|
||||
update["channelMoney"] = channelMoney
|
||||
if !blocDeduction {
|
||||
update["blocOrderCount"] = 1
|
||||
update["blocOrderMoney"] = money
|
||||
update["blocOrderPayMoney"] = paymoney
|
||||
update["blocChannelMoney"] = channelMoney
|
||||
}
|
||||
|
||||
exists, err := db.Exists(ctx, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if exists {
|
||||
_, err = db.UpdateOne(ctx, filter, bson.M{"$inc": update})
|
||||
} else {
|
||||
insertDoc := update
|
||||
insertDoc["sumDate"] = sumDate
|
||||
insertDoc["appId"] = appId
|
||||
insertDoc["channelName"] = channelName
|
||||
|
||||
_, err = db.InsertOne(ctx, insertDoc)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// 后台获取统计信息
|
||||
func GetRechargeChannelStatList(ctx context.Context, appId *int32, channelName *string, start, end *time.Time, skip, limit int64) (count int64, data []RechargeChannelMod, err error) {
|
||||
filter := bson.M{}
|
||||
|
||||
if appId != nil {
|
||||
filter["appId"] = appId
|
||||
}
|
||||
|
||||
if channelName != nil {
|
||||
filter["channelName"] = channelName
|
||||
}
|
||||
|
||||
if start != nil && end != nil {
|
||||
filter["sumDate"] = bson.M{"$gte": start, "$lt": end}
|
||||
} else if start != nil {
|
||||
filter["sumDate"] = bson.M{"$gte": start}
|
||||
} else if end != nil {
|
||||
filter["sumDate"] = bson.M{"$lt": end}
|
||||
}
|
||||
|
||||
sort := bson.D{{Key: "sumDate", Value: -1}, {Key: "appId", Value: 1}}
|
||||
|
||||
opts := options.Find().SetSort(sort).SetSkip(skip).SetLimit(limit)
|
||||
|
||||
if err = db.Find(ctx, &data, filter, opts); err != nil {
|
||||
log.Error("channelCodeStat GetRechargeChannelStatList Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
if count, err = db.Count(ctx, filter); err != nil {
|
||||
log.Error("channelCodeStat GetRechargeChannelStatList Count err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package rechargechannelmod
|
||||
|
||||
import (
|
||||
"stat/common/mongos"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 表名
|
||||
const CollRechargeChannel = "log_recharge_channel"
|
||||
|
||||
var db *mongos.MongoTool
|
||||
|
||||
// RechargeChannelMod 充值渠道信息
|
||||
type RechargeChannelMod struct {
|
||||
SumDate time.Time `bson:"sumDate"` // 记录时间 按天对齐
|
||||
AppId int32 `bson:"appId"` // appId
|
||||
ChannelName string `bson:"channelName"` // 支付渠道名称
|
||||
TotalOrderCount int64 `bson:"orderCount"` // 订单数量
|
||||
BlocOrderCount int64 `bson:"blocOrderCount"` // 集团订单数量
|
||||
TotalOrderMoney int64 `bson:"totalOrderMoney"` // 订单金额
|
||||
BlocOrderMoney int64 `bson:"blocOrderMoney"` // 集团订单金额
|
||||
TotalOrderPayMoney int64 `bson:"totalOrderPayMoney"` // 订单实际支付金额
|
||||
BlocOrderPayMoney int64 `bson:"blocOrderPayMoney"` // 集团订单实际支付金额
|
||||
ChannelMoney int64 `bson:"channelMoney"` // 渠道费用
|
||||
BlocChannelMoney int64 `bson:"blocChannelMoney"` // 集团渠道费用
|
||||
CreatedAt time.Time `bson:"createdAt"` // 创建时间
|
||||
}
|
||||
Reference in New Issue
Block a user