Initial commit

This commit is contained in:
2026-05-20 16:13:58 +08:00
commit ceffbe382e
500 changed files with 157469 additions and 0 deletions
+215
View File
@@ -0,0 +1,215 @@
package channelsettlementrecord
import (
"context"
"fmt"
"go.mongodb.org/mongo-driver/mongo"
"stat/common/log"
"stat/common/mongos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
)
var (
dbRecord *mongos.MongoTool
dbDeleted *mongos.MongoTool
)
func Init(ctx context.Context) {
initDbRecord(ctx)
initDbDeleted(ctx)
}
func initDbRecord(ctx context.Context) {
// 获取数据库表
dbRecord = mongos.New(mongos.MgoManager, TN.ChannelSettlementRecord)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.ChannelSettlementRecord.Channel, Value: 1},
{Key: FN.ChannelSettlementRecord.AppId, Value: 1},
},
},
{
Keys: bson.D{{Key: FN.ChannelSettlementRecord.SettleIds, Value: 1}},
},
{
Keys: bson.D{{Key: FN.ChannelSettlementRecord.Applicant, Value: 1}},
},
}
if _, err := dbRecord.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(ChannelSettlementRecord:initChannelSettlementRecordIndex) Create ChannelSettlementRecord Index failed! err:%+v:", err))
}
}
func initDbDeleted(ctx context.Context) {
// 获取数据库表
dbDeleted = mongos.New(mongos.MgoManager, TN.ChannelSettlementDeleted)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.ChannelSettlementDeleted.Channel, Value: 1},
{Key: FN.ChannelSettlementDeleted.AppId, Value: 1},
},
},
{
Keys: bson.D{{Key: FN.ChannelSettlementDeleted.SettleIds, Value: 1}},
},
}
if _, err := dbDeleted.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(ChannelSettlementDeleted:initChannelSettlementDeletedIndex) Create ChannelSettlementDeleted Index failed! err:%+v:", err))
}
}
//InsertOneChannelSettlementRecord 插入一个结算记录
func InsertOneChannelSettlementRecord(ctx context.Context, ChannelSettlementRecord *ChannelSettlementRecord) error {
if _, err := dbRecord.InsertOne(ctx, ChannelSettlementRecord); err != nil {
log.Warn("ChannelSettlementRecord:InsertOneChannelSettlementRecord dbRecord.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneChannelSettlementRecord 查找一个结算记录
func FindOneChannelSettlementRecord(ctx context.Context, filter bson.M) (
*ChannelSettlementRecord, error) {
var ChannelSettlementRecord ChannelSettlementRecord
if err := dbRecord.FindOne(ctx, &ChannelSettlementRecord, filter); err != nil {
return nil, err
}
return &ChannelSettlementRecord, nil
}
//FindOneChannelSettlementRecordEx 查找一个结算记录
func FindOneChannelSettlementRecordEx(ctx context.Context, filter bson.M) (
*ChannelSettlementRecord, error) {
var ChannelSettlementRecord ChannelSettlementRecord
if err := dbRecord.FindOneEx(ctx, &ChannelSettlementRecord, filter); err != nil {
return nil, err
}
return &ChannelSettlementRecord, nil
}
//DelOneChannelSettlementRecord 删除一个结算记录
func DelOneChannelSettlementRecord(ctx context.Context, filter bson.M) (
int64, error) {
count, err := dbRecord.DeleteOne(ctx, filter)
if err != nil {
log.Warn("ChannelSettlementRecord:DelOneChannelSettlementRecord dbRecord.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateOneChannelSettlementRecord 更新一个结算记录
func UpdateOneChannelSettlementRecord(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbRecord.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateOneChannelSettlementRecord dbRecord.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//CountChannelSettlementRecords 统计结算记录数量
func CountChannelSettlementRecords(ctx context.Context, filter bson.M) (
int64, error) {
count, err := dbRecord.Count(ctx, filter)
if err != nil {
log.Warn("ChannelSettlementRecord:CountChannelSettlementRecords dbRecord.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateManyChannelSettlementRecord 更新满足条件的结算记录
func UpdateManyChannelSettlementRecord(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbRecord.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyChannelSettlementRecord dbRecord.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//FindManyChannelSettlementRecord 查找一批结算记录数据
func FindManyChannelSettlementRecord(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (ChannelSettlementRecordList, error) {
data := make(ChannelSettlementRecordList, 0)
if err := dbRecord.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("ChannelSettlementRecord:FindManyChannelSettlementRecord dbRecord.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
//FindManyChannelSettlementRecordWithBind 用自己定义结构查找一批结算记录数据
func FindManyChannelSettlementRecordWithBind(ctx context.Context, bind interface{}, filter bson.M,
opts ...*options.FindOptions) error {
if err := dbRecord.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("ChannelSettlementRecord:FindManyChannelSettlementRecordWithBind dbRecord.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//AggregateChannelSettlementRecords 聚合查找一批结算记录信息
func AggregateChannelSettlementRecords(ctx context.Context,
bind interface{}, pipeline []bson.M) error {
if err := dbRecord.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("feedback:AggregateChannelSettlementRecords dbRecord.Aggregate failed",
log.E(err), log.Any("pipeline", pipeline))
return err
}
return nil
}
// ----------------------------------------
//CountChannelSettlementRecords 统计结算记录数量
func CountChannelSettlementDeletes(ctx context.Context, filter bson.M) (
int64, error) {
count, err := dbDeleted.Count(ctx, filter)
if err != nil {
log.Warn("ChannelSettlementRecord:CountChannelSettlementDeletes dbDeleted.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//InsertOneChannelSettlementDeleted 插入一个结算删除记录
func InsertOneChannelSettlementDeleted(ctx context.Context, ChannelSettlementRecord *ChannelSettlementRecord) error {
if _, err := dbDeleted.InsertOne(ctx, ChannelSettlementRecord); err != nil {
log.Warn("ChannelSettlementRecord:InsertOneChannelSettlementDeleted dbDeleted.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneChannelSettlementDeletedEx 查找一个结算删除记录
func FindOneChannelSettlementDeletedEx(ctx context.Context, filter bson.M) (
*ChannelSettlementRecord, error) {
var ChannelSettlementRecord ChannelSettlementRecord
if err := dbDeleted.FindOneEx(ctx, &ChannelSettlementRecord, filter); err != nil {
return nil, err
}
return &ChannelSettlementRecord, nil
}
//FindManyChannelSettlementDeleted 查找一批结算记录数据
func FindManyChannelSettlementDeleted(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (ChannelSettlementRecordList, error) {
data := make(ChannelSettlementRecordList, 0)
if err := dbDeleted.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("ChannelSettlementRecord:FindManyChannelSettlementDeleted dbDeleted.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
+81
View File
@@ -0,0 +1,81 @@
package channelsettlementrecord
type TagChannelSettlementRecord struct {
AppId string
BeginTime string
CPAPrice string
CPSRate string
Channel string
CreatedAt string
UpdatedAt string
EndTime string
ID string
NewDeductionCount string
NewFissionCount string
NewDirectCount string
PayMoney string
RechargeAmount string
Remark string
Settlement string
Status string
TotalMoney string
SettleMoney string
Usdt string
VipPayMoney string
VipPayCoin string
VipPayDeduction string
SettleIds string
OperateHistory string
Applicant string
Wallet struct {
Addr1 string
Addr2 string
}
IncludeChild string
}
var FN struct {
ChannelSettlementRecord TagChannelSettlementRecord
ChannelSettlementDeleted TagChannelSettlementRecord
}
var TN struct {
ChannelSettlementRecord string
ChannelSettlementDeleted string
}
func init() {
FN.ChannelSettlementRecord.AppId = "appId"
FN.ChannelSettlementRecord.BeginTime = "beginTime"
FN.ChannelSettlementRecord.CPAPrice = "cpaPrice"
FN.ChannelSettlementRecord.CPSRate = "cpsRate"
FN.ChannelSettlementRecord.Channel = "channel"
FN.ChannelSettlementRecord.CreatedAt = "createdAt"
FN.ChannelSettlementRecord.UpdatedAt = "updatedAt"
FN.ChannelSettlementRecord.EndTime = "endTime"
FN.ChannelSettlementRecord.ID = "_id"
FN.ChannelSettlementRecord.NewDeductionCount = "newDeductionCount"
FN.ChannelSettlementRecord.NewFissionCount = "newFissionCount"
FN.ChannelSettlementRecord.NewDirectCount = "newDirectCount"
FN.ChannelSettlementRecord.PayMoney = "payMoney"
FN.ChannelSettlementRecord.RechargeAmount = "rechargeAmount"
FN.ChannelSettlementRecord.Remark = "remark"
FN.ChannelSettlementRecord.Settlement = "settlement"
FN.ChannelSettlementRecord.Status = "status"
FN.ChannelSettlementRecord.TotalMoney = "totalMoney"
FN.ChannelSettlementRecord.SettleMoney = "settleMoney"
FN.ChannelSettlementRecord.Usdt = "usdt"
FN.ChannelSettlementRecord.VipPayMoney = "vipPayMoney"
FN.ChannelSettlementRecord.VipPayCoin = "vipPayCoin"
FN.ChannelSettlementRecord.VipPayDeduction = "vipPayDeduction"
FN.ChannelSettlementRecord.SettleIds = "settleIds"
FN.ChannelSettlementRecord.OperateHistory = "operateHistory"
FN.ChannelSettlementRecord.Applicant = "applicant"
FN.ChannelSettlementRecord.Wallet.Addr1 = "wallet.addr1"
FN.ChannelSettlementRecord.Wallet.Addr2 = "wallet.addr2"
FN.ChannelSettlementRecord.IncludeChild = "includeChild"
FN.ChannelSettlementDeleted = FN.ChannelSettlementRecord
TN.ChannelSettlementRecord = "channel_settlement_record"
TN.ChannelSettlementDeleted = "channel_settlement_deleted"
}
+90
View File
@@ -0,0 +1,90 @@
package channelsettlementrecord
import (
"stat/middleware/define"
"stat/models/channelmod"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// 结算方式
type SettlementStatus int64
const (
SettlementInit SettlementStatus = 0 // 发起
SettlementSuccess SettlementStatus = 1 // 成功
SettlementFailed SettlementStatus = 2 // 失败
SettlementDeleted SettlementStatus = 3 // 已删除
)
func (status SettlementStatus) String() string {
return GetSettStatus(status)
}
func GetSettStatus(status SettlementStatus) string {
switch status {
case SettlementInit:
return "发起"
case SettlementSuccess:
return "成功"
case SettlementFailed:
return "失败"
case SettlementDeleted:
return "已删除"
default:
return "未知状态"
}
}
type SettlementOperateItem struct {
OperateTime time.Time `bson:"operateTime" json:"operateTime"` // 操作时间
BeforeStatus SettlementStatus `bson:"beforeStatus" json:"beforeStatus"` // 操作前状态
AfterStatus SettlementStatus `bson:"afterStatus" json:"afterStatus"` // 操作后状态
OperatorAccount string `bson:"operatorAccount" json:"operatorAccount"` // 操作者账号
OperatorAccountType define.ActType `bson:"operatorAccountType" json:"operatorAccountType"` // 操作者账号类型
OperatorAccountName string `bson:"operatorAccountName" json:"operatorAccountName"` // 操作者账号名字
Content string `bson:"content" json:"content"` // 操作的内容
Pictures []string `bson:"pictures" json:"pictures"` // 上传的图片
Remark string `bson:"remark" json:"remark"` // 操作备注
}
// 帖子模型,数据库中的
// @table:channel_settlement_record
type ChannelSettlementRecord struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // ID
Channel string `bson:"channel" json:"channel"` // 渠道
AppId int32 `bson:"appId" json:"appId"` // appId
AppType channelmod.AppType `bson:"appType" json:"appType"` // 应用类型
PromoteMode channelmod.PromoteMode `bson:"promoteMode" json:"promoteMode"` // 推广类型
BeginTime time.Time `bson:"beginTime" json:"beginTime"` // 开始时间
EndTime time.Time `bson:"endTime" json:"endTime"` // 结束时间
TotalMoney int64 `bson:"totalMoney" json:"totalMoney"` // 计算出的总金额
SettleMoney int64 `bson:"settleMoney" json:"settleMoney"` // 手动输入的要结算的真实金额()
Settlement channelmod.SettlementWay `bson:"settlement" json:"settlement"` // 结算方式 cps/cpa/cpt/cpc
CPAPrice int64 `bson:"cpaPrice" json:"cpaPrice"` // 单价
CPSRate int64 `bson:"cpsRate" json:"cpsRate"` // CPS 分成比列 0-100
NewDirectCount int64 `bson:"newDirectCount" json:"newDirectCount"` // 新增直推
NewFissionCount int64 `bson:"newFissionCount" json:"newFissionCount"` // 新增裂变
NewDeductionCount int64 `bson:"newDeductionCount" json:"newDeductionCount"` // 新增扣量
RechargeAmount int64 `bson:"rechargeAmount" json:"rechargeAmount"` // 充值金额
VipPayMoney int64 `bson:"vipPayMoney" json:"vipPayMoney"` // 购买会员金额(CPS扣量后)
VipPayCoin int64 `bson:"vipPayCoin,omitempty" json:"vipPayCoin"` // 购买会员金币
VipPayDeduction int64 `bson:"vipPayDeduction,omitempty" json:"vipPayDeduction"` // 购买会员金额(CPS扣量)
ValidDirectCount int64 `bson:"validDirectCount,omitempty" json:"validDirectCount"` // 有效直推总数
ValidDeductionCount int64 `bson:"validDeductionCount,omitempty" json:"validDeductionCount"` // 有效扣量总数
ValidPayMoney int64 `bson:"validPayMoney,omitempty" json:"validPayMoney"` // 有效收益会员金额
ValidPayCoin int64 `bson:"validPayCoin,omitempty" json:"validPayCoin"` // 有效收益金币金额
Wallet channelmod.Wallet `bson:"wallet" json:"wallet"` // 钱包地址
PayMoney int64 `bson:"payMoney" json:"payMoney"` // 打款金额
Usdt int64 `bson:"usdt" json:"usdt"` // 打款Usdt 还是分
Status SettlementStatus `bson:"status" json:"status"` // 状态
OperateHistory []SettlementOperateItem `bson:"operateHistory" json:"operateHistory"` // 操作历史[最后一项是当前操作记录]
Remark string `bson:"remark" json:"remark"` // 备注
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` // 更新时间
CreatedAt time.Time `bson:"createdAt" json:"createdAt"` // 创建时间
SettleIds []primitive.ObjectID `bson:"settleIds" json:"settleIds"` // 本次结算的天统计记录id列表
Applicant string `bson:"applicant" json:"applicant"` // 结算申请人
IncludeChild bool `bson:"includeChild" json:"includeChild"` // 结算是否包含子渠道
}
type ChannelSettlementRecordList []*ChannelSettlementRecord