代码提交
This commit is contained in:
@@ -603,6 +603,27 @@ func InsertOneChannelStatYestoday(ctx context.Context, media *ChannelStatYesterd
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpsertOneChannelStatYestoday 按 (channel, appId, sumDate) 覆盖写入一条同时段对比数据。
|
||||
// 用 ReplaceOne 而不是 InsertOne: 整点任务可能因服务重启或重试在同一小时内跑第二次,
|
||||
// 而该表有 (channel, appId, sumDate) 唯一索引,InsertOne 第二次必然冲突失败。
|
||||
// 整条替换也保证快照不会残留上一次的旧值。
|
||||
// 注意不可改用 UpsertMOne: 它内部用 Struct2Map 走 JSON 序列化,time.Time 会被写成字符串,
|
||||
// sumDate 将不再是 BSON Date,按时间范围的查询会全部失效。
|
||||
func UpsertOneChannelStatYestoday(ctx context.Context, doc *ChannelStatYesterday) error {
|
||||
filter := bson.M{
|
||||
FN.ChannelStatYestoday.Channel: doc.Channel,
|
||||
FN.ChannelStatYestoday.AppId: doc.AppId,
|
||||
FN.ChannelStatYestoday.SumDate: doc.SumDate,
|
||||
}
|
||||
opt := options.Replace().SetUpsert(true)
|
||||
if _, err := dbStatYestoday.GetCollection().ReplaceOne(ctx, filter, doc, opt); err != nil {
|
||||
log.Warn("ChannelStatYestoday:UpsertOneChannelStatYestoday ReplaceOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CountChannelStatYestoday 统计渠道扣量规则数量
|
||||
func CountChannelStatYestoday(ctx context.Context, filter bson.M) (int64, error) {
|
||||
count, err := dbStatYestoday.Count(ctx, filter)
|
||||
|
||||
@@ -27,6 +27,8 @@ func Init(ctx context.Context) {
|
||||
SetPartialFilterExpression(bson.M{FN.RefundOrder.OrderId: bson.M{"$gt": ""}}),
|
||||
},
|
||||
{Keys: bson.D{{Key: FN.RefundOrder.CID, Value: 1}}},
|
||||
{Keys: bson.D{{Key: FN.RefundOrder.TransNo, Value: 1}}},
|
||||
{Keys: bson.D{{Key: FN.RefundOrder.IP, Value: 1}}},
|
||||
{Keys: bson.D{{Key: FN.RefundOrder.UserId, Value: 1}}},
|
||||
{Keys: bson.D{{Key: FN.RefundOrder.ChannelName, Value: 1}}},
|
||||
{Keys: bson.D{{Key: FN.RefundOrder.DistrictCode, Value: 1}}},
|
||||
|
||||
@@ -4,6 +4,8 @@ type TagRefundOrder struct {
|
||||
ID string
|
||||
AppId string
|
||||
CID string
|
||||
TransNo string
|
||||
IP string
|
||||
DistrictCode string
|
||||
Money string
|
||||
OrderId string
|
||||
@@ -25,6 +27,8 @@ func init() {
|
||||
FN.RefundOrder.ID = "_id"
|
||||
FN.RefundOrder.AppId = "appId"
|
||||
FN.RefundOrder.CID = "cid"
|
||||
FN.RefundOrder.TransNo = "transNo"
|
||||
FN.RefundOrder.IP = "ip"
|
||||
FN.RefundOrder.DistrictCode = "districtCode"
|
||||
FN.RefundOrder.Money = "money"
|
||||
FN.RefundOrder.OrderId = "orderId"
|
||||
|
||||
@@ -18,7 +18,9 @@ var db *mongos.MongoTool
|
||||
type RefundOrder struct {
|
||||
ID primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
|
||||
AppId int32 `json:"appId" bson:"appId"` // appId
|
||||
CID string `json:"cid" bson:"cid"` // 渠道id
|
||||
CID string `json:"cid" bson:"cid"` // 订单id(来自 log_recharge.cid)
|
||||
TransNo string `json:"transNo" bson:"transNo"` // 请求订单号(pay_server 的 transNo,由前端换取 cid 时一并传入)
|
||||
IP string `json:"ip" bson:"ip"` // 下单用户IP(来自 pay_server 的 recharge_order.userIP,log_recharge 无此字段)
|
||||
DistrictCode string `json:"districtCode" bson:"districtCode"` // 渠道码
|
||||
Money int64 `json:"money" bson:"money"` // 订单金额
|
||||
OrderId string `json:"orderId" bson:"orderId"` // 流水id
|
||||
|
||||
Reference in New Issue
Block a user