parent
6acb097d44
commit
702c98ce05
26 changed files with 2221 additions and 562 deletions
@ -0,0 +1,113 @@ |
|||||||
|
package call |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"encoding/json" |
||||||
|
"server/db" |
||||||
|
"server/natsClient" |
||||||
|
"server/pb" |
||||||
|
"server/util" |
||||||
|
"time" |
||||||
|
|
||||||
|
"github.com/liangdas/mqant/log" |
||||||
|
"github.com/olivere/elastic/v7" |
||||||
|
) |
||||||
|
|
||||||
|
func InsertToESGO(index string, params interface{}, id ...string) { |
||||||
|
if GetTopicName() == "common" { |
||||||
|
data := &WriteData{Index: index, Data: params} |
||||||
|
if id != nil { |
||||||
|
data.ID = id[0] |
||||||
|
} |
||||||
|
Go(func() { |
||||||
|
AddBulk(data) |
||||||
|
}) |
||||||
|
} else { |
||||||
|
byt, _ := json.Marshal(params) |
||||||
|
data := &pb.InnerESBulk{Index: index, Data: string(byt)} |
||||||
|
if id != nil { |
||||||
|
data.ID = id[0] |
||||||
|
} |
||||||
|
Go(func() { Publish(natsClient.TopicInnerESBulk, data) }) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
var ( |
||||||
|
Bulk *elastic.BulkService |
||||||
|
WriteChan = make(chan *WriteData, 20000) |
||||||
|
ESCloseChan = make(chan struct{}) |
||||||
|
ESFinishChan = make(chan struct{}) // 完成信号
|
||||||
|
MaxSize int64 = 50 * 1024 * 1024 // bulk最大长度
|
||||||
|
) |
||||||
|
|
||||||
|
type WriteData struct { |
||||||
|
ID string |
||||||
|
Index string |
||||||
|
Data interface{} |
||||||
|
} |
||||||
|
|
||||||
|
func InitBulkQueue() { |
||||||
|
es := db.ES().C() |
||||||
|
Bulk = es.Bulk() |
||||||
|
util.Go(func() { |
||||||
|
t := time.NewTimer(time.Second) |
||||||
|
for { |
||||||
|
select { |
||||||
|
case <-t.C: |
||||||
|
t.Reset(time.Second) |
||||||
|
Flush() |
||||||
|
case one := <-WriteChan: |
||||||
|
e := elastic.NewBulkCreateRequest().Index(one.Index) |
||||||
|
if one.ID != "" { |
||||||
|
e.Id(one.ID) |
||||||
|
} |
||||||
|
e.Doc(one.Data) |
||||||
|
Bulk.Add(e) |
||||||
|
if Bulk.EstimatedSizeInBytes() >= MaxSize { |
||||||
|
Flush() |
||||||
|
} |
||||||
|
case <-ESCloseChan: |
||||||
|
log.Debug("module closing") |
||||||
|
Flush() |
||||||
|
ESFinishChan <- struct{}{} |
||||||
|
} |
||||||
|
// fmt.Println(total)
|
||||||
|
} |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
func AddBulk(w *WriteData) { |
||||||
|
WriteChan <- w |
||||||
|
} |
||||||
|
|
||||||
|
func Flush() { |
||||||
|
if Bulk.EstimatedSizeInBytes() <= 0 { |
||||||
|
return |
||||||
|
} |
||||||
|
bulk := Bulk |
||||||
|
// util.IndexTry(func() error {
|
||||||
|
util.Go(func() { |
||||||
|
_, err := bulk.Do(context.Background()) |
||||||
|
if err != nil { |
||||||
|
log.Error("err:%v", err) |
||||||
|
// return err
|
||||||
|
} |
||||||
|
}) |
||||||
|
// return nil
|
||||||
|
// })
|
||||||
|
Bulk = db.ES().C().Bulk() |
||||||
|
} |
||||||
|
|
||||||
|
// 滚动设置新的索引
|
||||||
|
func Rollover(aliasName, indexName string) { |
||||||
|
if db.ES().IndexExist(indexName) { |
||||||
|
return |
||||||
|
} |
||||||
|
// 不存在创建
|
||||||
|
if !db.ES().IndexExist(aliasName) { |
||||||
|
db.ES().CreateExist(indexName) |
||||||
|
db.ES().AddAlias(aliasName, indexName) |
||||||
|
} else { |
||||||
|
db.ES().Rollover(aliasName, indexName, nil) |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,87 @@ |
|||||||
|
package call |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"runtime" |
||||||
|
"server/common" |
||||||
|
"time" |
||||||
|
|
||||||
|
"github.com/liangdas/mqant/log" |
||||||
|
) |
||||||
|
|
||||||
|
// Go 用协程处理f
|
||||||
|
func Go(f func()) { |
||||||
|
go func() { |
||||||
|
defer Recover() |
||||||
|
f() |
||||||
|
}() |
||||||
|
} |
||||||
|
|
||||||
|
func IndexTryCallback(f func() error, cb func()) { |
||||||
|
Go(func() { |
||||||
|
for i := 0; i <= 6; i++ { |
||||||
|
if i > 0 { |
||||||
|
next := time.Duration(i*i) * time.Minute |
||||||
|
time.Sleep(next) |
||||||
|
} |
||||||
|
err := f() |
||||||
|
if err == nil { |
||||||
|
break |
||||||
|
} |
||||||
|
log.Error("err:%v next:%v", err, i) |
||||||
|
if i == 6 { |
||||||
|
cb() |
||||||
|
} |
||||||
|
} |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
func IndexTry(f func() error) { |
||||||
|
Go(func() { |
||||||
|
for i := 0; i <= 6; i++ { |
||||||
|
if i > 0 { |
||||||
|
next := time.Duration(i*i) * time.Minute |
||||||
|
time.Sleep(next) |
||||||
|
} |
||||||
|
err := f() |
||||||
|
if err == nil { |
||||||
|
break |
||||||
|
} |
||||||
|
log.Error("err:%v next:%v", err, i) |
||||||
|
} |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
func IndexTryS(f func() error) { |
||||||
|
Go(func() { |
||||||
|
for i := 0; i <= 6; i++ { |
||||||
|
if i > 0 { |
||||||
|
next := time.Duration(i*i) * time.Second |
||||||
|
time.Sleep(next) |
||||||
|
} |
||||||
|
err := f() |
||||||
|
if err == nil { |
||||||
|
break |
||||||
|
} |
||||||
|
log.Error("err:%v next:%v", err, i) |
||||||
|
} |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
// 捕获异常并打日志
|
||||||
|
// Usage: defer Recover()
|
||||||
|
func Recover() { |
||||||
|
if err := recover(); err != nil { |
||||||
|
buf := make([]byte, 1024) |
||||||
|
runtime.Stack(buf, false) |
||||||
|
str := fmt.Sprintf("%+v", err) |
||||||
|
log.Error("panic(%s), stack:\n%s", str, string(buf)) |
||||||
|
name := GetCaller().GetType() |
||||||
|
InsertToESGO(common.ESIndexBackPanic, common.ESPanic{ |
||||||
|
Module: name, |
||||||
|
Func: str, |
||||||
|
Time: time.Now().Unix(), |
||||||
|
Error: string(buf), |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,10 @@ |
|||||||
|
package common |
||||||
|
|
||||||
|
import ( |
||||||
|
"server/call" |
||||||
|
"server/pb" |
||||||
|
) |
||||||
|
|
||||||
|
func esBulk(d *pb.InnerESBulk) { |
||||||
|
call.AddBulk(&call.WriteData{Index: d.Index, Data: d.Data, ID: d.ID}) |
||||||
|
} |
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,233 @@ |
|||||||
|
package values |
||||||
|
|
||||||
|
import "server/common" |
||||||
|
|
||||||
|
// Balance 总余额
|
||||||
|
// TotalCommission 可退出
|
||||||
|
// TotalWithdrawals 已退出
|
||||||
|
// Banners banner图
|
||||||
|
// TotalReferrals 总分享
|
||||||
|
// ShareLink 分享地址
|
||||||
|
// PopNewTask 是否弹出新手任务
|
||||||
|
// PopWithdraw 可退出弹窗
|
||||||
|
// PopWithdrawAmount 弹出退出金额
|
||||||
|
// NewReward 新手奖励金额
|
||||||
|
// LastReward 昨天收益
|
||||||
|
// LevelUpInfo 升级提示,如果升级了,该字段会有值
|
||||||
|
type ShareNewInfoResp struct { |
||||||
|
Balance int64 |
||||||
|
TotalCommission int64 |
||||||
|
TotalWithdrawals int64 |
||||||
|
TotalReferrals int64 |
||||||
|
Banners []string |
||||||
|
ShareLink string |
||||||
|
PopNewTask bool |
||||||
|
PopWithdraw bool |
||||||
|
PopWithdrawAmount int64 |
||||||
|
NewReward int64 |
||||||
|
LastReward struct { |
||||||
|
Total int64 |
||||||
|
Invitation int64 |
||||||
|
Recharge int64 |
||||||
|
Affiliate int64 |
||||||
|
Other int64 |
||||||
|
} |
||||||
|
LevelUpInfo common.LevelUpInfo |
||||||
|
NowLevel int |
||||||
|
NowExp int64 |
||||||
|
NextExp int64 |
||||||
|
Avatar string |
||||||
|
} |
||||||
|
|
||||||
|
type ShareNewTaskInfoResp struct { |
||||||
|
TaskList []OneShareNewTask |
||||||
|
} |
||||||
|
|
||||||
|
type ShareNewTaskDrawReq struct { |
||||||
|
TaskID int |
||||||
|
} |
||||||
|
|
||||||
|
type ShareNewTaskDrawResp struct { |
||||||
|
Reward int64 |
||||||
|
} |
||||||
|
|
||||||
|
// TaskID 任务id
|
||||||
|
// Desc 任务描述
|
||||||
|
// Type 任务类型
|
||||||
|
// Progress 任务进度
|
||||||
|
// Target 任务目标
|
||||||
|
// Reward 任务奖励
|
||||||
|
// Status 任务状态,0进行中,1可领取,2已领取
|
||||||
|
type OneShareNewTask struct { |
||||||
|
TaskID int |
||||||
|
Desc string |
||||||
|
Type int |
||||||
|
Progess int64 |
||||||
|
Target int64 |
||||||
|
Reward int64 |
||||||
|
Status int |
||||||
|
} |
||||||
|
|
||||||
|
// Page 页码
|
||||||
|
// Num 一页个数,最大50
|
||||||
|
// Level int
|
||||||
|
type ShareNewAffiliateReq struct { |
||||||
|
Page int |
||||||
|
Num int |
||||||
|
Level int |
||||||
|
} |
||||||
|
|
||||||
|
// Level1 每个等级人数
|
||||||
|
type ShareNewAffiliateResp struct { |
||||||
|
Level1 int64 |
||||||
|
Level2 int64 |
||||||
|
Level3 int64 |
||||||
|
Level4 int64 |
||||||
|
Level5 int64 |
||||||
|
Count int64 |
||||||
|
AffiliateList []OneShareNewAffiliate |
||||||
|
} |
||||||
|
|
||||||
|
// AffiliateCount 下级数量
|
||||||
|
type OneShareNewAffiliate struct { |
||||||
|
UID int |
||||||
|
Nick string |
||||||
|
AffiliateCount int64 |
||||||
|
LastLogin int64 |
||||||
|
} |
||||||
|
|
||||||
|
// Page 页码
|
||||||
|
// Num 一页个数,最大50
|
||||||
|
type ShareNewCommissionReq struct { |
||||||
|
Page int |
||||||
|
Num int |
||||||
|
} |
||||||
|
|
||||||
|
// All 总收益
|
||||||
|
// Invitation 总邀请收益
|
||||||
|
// Recharge 总充值收益
|
||||||
|
// Affiliate 总客损收益
|
||||||
|
// Other 总其他收益
|
||||||
|
type ShareNewCommissionResp struct { |
||||||
|
All int64 |
||||||
|
Invitation int64 |
||||||
|
Recharge int64 |
||||||
|
Affiliate int64 |
||||||
|
Other int64 |
||||||
|
List []OneShareNewCommission |
||||||
|
Count int64 |
||||||
|
} |
||||||
|
|
||||||
|
type OneShareNewCommission struct { |
||||||
|
Date string |
||||||
|
Invitation int64 |
||||||
|
Recharge int64 |
||||||
|
Affiliate int64 |
||||||
|
Other int64 |
||||||
|
} |
||||||
|
|
||||||
|
// Page 页码
|
||||||
|
// Num 一页个数,最大50
|
||||||
|
// Type 类型 0日榜 1周榜 2月榜
|
||||||
|
// Time 查询时间,0当前周期,1上一周期,以此类推
|
||||||
|
type ShareNewRankReq struct { |
||||||
|
Page int |
||||||
|
Num int |
||||||
|
Type int |
||||||
|
Time int |
||||||
|
} |
||||||
|
|
||||||
|
type ShareNewRankResp struct { |
||||||
|
List []*common.ShareRank |
||||||
|
Self *common.ShareRank |
||||||
|
Days []string |
||||||
|
Weeks []string |
||||||
|
Months []string |
||||||
|
} |
||||||
|
|
||||||
|
// 如果参数都是零代表当前没有任务或任务已超时
|
||||||
|
// NowLevel 当前等级
|
||||||
|
// NextLevel 下一等级
|
||||||
|
// Exp 当前经验
|
||||||
|
// LevelUpExp 升级所需经验
|
||||||
|
// TimeLeft 剩余时间,单位秒
|
||||||
|
// CanDraw 是否能领取
|
||||||
|
type ShareLimitTaskInfoResp struct { |
||||||
|
NowLevel common.LevelUpInfo |
||||||
|
NextLevel common.LevelUpInfo |
||||||
|
Exp int64 |
||||||
|
LevelUpExp int64 |
||||||
|
TimeLeft int64 |
||||||
|
CanDraw bool |
||||||
|
Reward int64 |
||||||
|
} |
||||||
|
|
||||||
|
// NowLevel 领取任务的等级
|
||||||
|
type ShareLimitTaskDrawReq struct { |
||||||
|
NowLevel int |
||||||
|
} |
||||||
|
|
||||||
|
type ShareLimitTaskDrawResp struct { |
||||||
|
Reward int64 |
||||||
|
} |
||||||
|
|
||||||
|
type ShareNewWithdrawInfoResp struct { |
||||||
|
TotalBalance int64 |
||||||
|
Withdrawable int64 |
||||||
|
Method int |
||||||
|
List []*WithdrawProduct |
||||||
|
WithDrawCount int |
||||||
|
TotalWithdrawCount int |
||||||
|
Tips string |
||||||
|
Accounts []*common.PayInfo |
||||||
|
NewList []*common.ConfigWithdrawChannels |
||||||
|
} |
||||||
|
|
||||||
|
// Type 类型 1转移到游戏账户 2退出
|
||||||
|
// PayAccount 退出信息,Type为2是不能为空
|
||||||
|
type ShareNewWithdrawReq struct { |
||||||
|
Type int `json:"Type" binding:"required"` |
||||||
|
AmountID int |
||||||
|
// 可能对应多种结构
|
||||||
|
PayAccount map[string]interface{} `json:"PayAccount"` |
||||||
|
} |
||||||
|
|
||||||
|
type ShareNewWithdrawResp struct { |
||||||
|
TotalBalance int64 |
||||||
|
Withdrawable int64 |
||||||
|
} |
||||||
|
|
||||||
|
type ShareNewWithdrawHisReq struct { |
||||||
|
Page int |
||||||
|
Num int |
||||||
|
} |
||||||
|
|
||||||
|
type ShareNewWithdrawHisResp struct { |
||||||
|
Count int64 |
||||||
|
List []OneShareNewWithdrawHis |
||||||
|
} |
||||||
|
|
||||||
|
type OneShareNewWithdrawHis struct { |
||||||
|
CreatedAt string |
||||||
|
OrderID string |
||||||
|
PayAccount string |
||||||
|
UID int |
||||||
|
Amount int64 |
||||||
|
Event int |
||||||
|
ProductID int |
||||||
|
Status uint8 |
||||||
|
FailReason string |
||||||
|
ChannelID int |
||||||
|
UPI int |
||||||
|
Scene int |
||||||
|
WithdrawCash int64 `json:"withdraw_cash"` |
||||||
|
} |
||||||
|
|
||||||
|
type ShareNewBroadcastReq struct { |
||||||
|
Page int |
||||||
|
Num int |
||||||
|
} |
||||||
|
|
||||||
|
type ShareNewBroadcastResp struct { |
||||||
|
List []string |
||||||
|
} |
||||||
@ -1,10 +1,31 @@ |
|||||||
package values |
package values |
||||||
|
|
||||||
import "server/common" |
import ( |
||||||
|
"server/call" |
||||||
|
"server/common" |
||||||
|
"server/util" |
||||||
|
"time" |
||||||
|
) |
||||||
|
|
||||||
var ( |
var ( |
||||||
ShareTotalInviteReward int64 |
ShareTotalInviteReward int64 |
||||||
ShareTotalBetReward int64 |
ShareTotalBetReward int64 |
||||||
ShareRank []*OneShareRank |
ShareRank []*OneShareRank |
||||||
ActivitySlotsRank []*common.ActivitySlotsData |
ActivitySlotsRank []*common.ActivitySlotsData |
||||||
|
|
||||||
|
// 分享排行榜
|
||||||
|
ShareRankDaily []*common.ShareRank |
||||||
|
ShareRankWeekly []*common.ShareRank |
||||||
|
ShareRankMonthly []*common.ShareRank |
||||||
|
ShareWithdrawBroadcast []string |
||||||
) |
) |
||||||
|
|
||||||
|
func LoadShareRankData() { |
||||||
|
now := time.Now() |
||||||
|
dayZero := util.GetZeroTime(now).Unix() |
||||||
|
ShareRankDaily = call.GetShareRank(common.ShareRankTypeDaily, dayZero) |
||||||
|
weekZero := util.GetWeekZeroTime(now).Unix() |
||||||
|
ShareRankWeekly = call.GetShareRank(common.ShareRankTypeWeekly, weekZero) |
||||||
|
monthZero := util.GetFirstDateOfMonth(now).Unix() |
||||||
|
ShareRankMonthly = call.GetShareRank(common.ShareRankTypeMonthly, monthZero) |
||||||
|
} |
||||||
|
|||||||
Loading…
Reference in new issue