diff --git a/call/pay.go b/call/pay.go index 0f99734..1ba61ec 100644 --- a/call/pay.go +++ b/call/pay.go @@ -511,9 +511,8 @@ func PayActivity(r *common.RechargeOrder, notCharge bool, user *common.PlayerDBI // 更新loginrecord if notCharge { InsertLoginRecord(r.UID, r.ChannelID, user.IP, user.Birth, user.Platform) - CheckShare(r) } - + CheckShare(r) return nil } diff --git a/call/share.go b/call/share.go index 23b72ae..d8206e9 100644 --- a/call/share.go +++ b/call/share.go @@ -82,20 +82,77 @@ func ShareBind(share string, isOld bool, uid, cid int) { // 判断分享,发放有效用户奖励 func CheckShare(r *common.RechargeOrder) { + shareInfo := GetShareInfo(r.UID) reward := GetConfigShareSys().ShareReward - if r.Amount < GetConfigShareSys().ShareRecharge { + // 付费分享 + // CheckShareTask(shareInfo.UP1, 1, common.TaskTypePayShare) + // 发放奖励 + update := map[string]interface{}{ + "recharge_amount": gorm.Expr("recharge_amount + ?", r.Amount), + } + if shareInfo.BetAmount != -1 { + update["bet_amount"] = gorm.Expr("bet_amount + ?", r.Amount) + } + db.Mysql().Update(&common.ShareInfo{UID: r.UID}, update) + betAmount := shareInfo.BetAmount + if betAmount == -1 { + betAmount = 0 + } + if shareInfo.RechargeAmount+r.Amount < GetConfigShareSys().ShareRecharge { return } - share := GetShareInfo(r.UID) - if share.UP1 == 0 { + if shareInfo.UP1 == 0 { return } - // 发放奖励 - db.Mysql().Update(&common.ShareInfo{UID: share.UP1}, map[string]interface{}{ - "invalid_invites": gorm.Expr("invalid_invites + 1"), - "invite_reward": gorm.Expr("invite_reward + ?", reward), - "available_reward": gorm.Expr("available_reward + ?", reward), - }) + if shareInfo.BetAmount >= 0 { + db.Mysql().Update(&common.ShareInfo{UID: r.UID}, map[string]interface{}{ + "bet_amount": -1, + }) + update = map[string]interface{}{ + "invalid_invites": gorm.Expr("invalid_invites + 1"), + "invite_reward": gorm.Expr("invite_reward + ?", reward), + "available_reward": gorm.Expr("available_reward + ?", reward), + } + db.Mysql().Update(&common.ShareInfo{UID: shareInfo.UP1}, update) + } + ShareRecharge(r.UID, r.Amount+betAmount) +} + +func ShareRecharge(uid int, amount int64) { + shareInfo := &common.ShareInfo{UID: uid} + db.Mysql().Get(shareInfo) + if shareInfo.UP1 == 0 { + return + } + ref := reflect.ValueOf(shareInfo).Elem() + // 循环查询上级 + for i := 1; i <= 3; i++ { + upUid := int(ref.FieldByName(fmt.Sprintf("UP%d", i)).Int()) + if upUid == 0 { + break + } + con := GetConfigShareByLevel(i) + if con == nil { + log.Error("unknown config share level:%v", i) + continue + } + // 发奖 + reward := amount * con.Per / 1000 + if reward <= 0 { + continue + } + db.Mysql().Update(&common.ShareInfo{UID: upUid}, map[string]interface{}{ + "bet_reward": gorm.Expr("bet_reward + ?", reward), + "available_reward": gorm.Expr("available_reward + ?", reward), + }) + db.Mysql().Create(&common.ShareDetail{ + UID: uid, + Up: upUid, + RechargeAmount: amount, + Reward: reward, + Time: time.Now().Unix(), + }) + } } // 投注奖励结算 diff --git a/cmd/build.sh b/cmd/build.sh index a34264c..037ba5e 100644 --- a/cmd/build.sh +++ b/cmd/build.sh @@ -8,5 +8,5 @@ cd pb/proto # go generate cd ../.. #go build main.go -#CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o indiaprovider main.go -CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gameserver main.go \ No newline at end of file +CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o indiaprovider main.go +#CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gameserver main.go \ No newline at end of file diff --git a/common/activity.go b/common/activity.go index a778638..3b2f277 100644 --- a/common/activity.go +++ b/common/activity.go @@ -307,8 +307,8 @@ func (c *ConfigActivityBreakGift) TableName() string { type ConfigActivityWeekCard struct { ID int `gorm:"primarykey"` - DayOneReward int64 `gorm:"column:day_one_reward;type:bigint(20);default:0;comment:第一天奖励" web:"day_one_reward"` // 下限 - MiniLimit int64 `gorm:"column:mini_limit;type:bigint(20);default:0;comment:下限" web:"mini_limit"` // 下限 + DayOneReward int64 `gorm:"column:day_one_reward;type:bigint(20);default:0;comment:第一天奖励" web:"day_one_reward"` // 下限 + MiniLimit int64 `gorm:"column:mini_limit;type:bigint(20);default:0;comment:下限" web:"mini_limit"` // 下限 RewardAmount int64 `gorm:"column:reward_amount;type:bigint(20);default:0;comment:第二到第6天奖励金额" web:"reward_amount"` // 第二到第6天奖励金额 Discount int64 `gorm:"column:discount;type:bigint(20);default:0;comment:第二到第6天奖励金额" web:"discount"` // 满减券折扣 } diff --git a/common/share.go b/common/share.go index bcf06a4..6025cef 100644 --- a/common/share.go +++ b/common/share.go @@ -43,6 +43,25 @@ type ShareInfo struct { AvailableReward int64 `gorm:"column:available_reward;type:bigint(20);default:0;comment:可支配佣金"` Time int64 `gorm:"column:time;type:bigint(20);default:0;comment:加入的时间"` ActivityId int `gorm:"column:activity_id;type:int(11);default:0;comment:来自于哪个分享活动"` + RechargeAmount int64 `gorm:"column:recharge_amount;type:bigint(20);default:0;comment:充值金额"` + BetAmount int64 `gorm:"column:bet_amount;type:bigint(20);default:0;comment:下注金额"` +} + +func (a *ShareInfo) TableName() string { + return "share_info" +} + +type ShareDetail struct { + ID int `gorm:"primarykey"` + UID int `gorm:"column:uid;not null;type:int(11);"` + Up int `gorm:"column:up;type:int(11);default:0;comment:上级"` + Reward int64 `gorm:"column:reward;type:bigint(20);default:0;comment:获取奖励"` + RechargeAmount int64 `gorm:"column:recharge_amount;type:bigint(20);default:0;comment:充值金额"` + Time int64 `gorm:"column:time;type:bigint(20);default:0;comment:时间"` +} + +func (m *ShareDetail) TableName() string { + return "share_detail" } // 绑定关系 @@ -75,10 +94,6 @@ type ShareInfo struct { // Time int64 `gorm:"column:time;type:bigint(20);default:0;comment:加入的时间"` // } -func (a *ShareInfo) TableName() string { - return "share_info" -} - type ShareActivityCode struct { Id int `gorm:"column:id;type:int(11) AUTO_INCREMENT;primary_key;" json:"id"` UID int `gorm:"column:uid;type:int(11);index:idx_share;comment:玩家ID" json:"uid"` diff --git a/modules/backend/migrate.go b/modules/backend/migrate.go index 3ea94ab..e904fd8 100644 --- a/modules/backend/migrate.go +++ b/modules/backend/migrate.go @@ -119,6 +119,7 @@ func MigrateDB() { new(common.ConfigDiscountTicket), new(common.ConfigRtp), new(common.PlayerRtpData), + new(common.ShareDetail), ) if err != nil { panic("Migrate db fail") diff --git a/modules/common/nats.go b/modules/common/nats.go index 85387e3..9599016 100644 --- a/modules/common/nats.go +++ b/modules/common/nats.go @@ -33,7 +33,7 @@ type Player struct { func afterSettle(d *pb.InnerAfterSettle) { log.Debug("afterSettle:%+v", *d) UpdateGameData(d) - call.ShareSettle(d) + // call.ShareSettle(d) // p := &Player{uid: int(d.UID), gid: int(d.GameID), settleData: d} // p.ActivityFirstRechargeBack() } diff --git a/modules/web/handler/activity.go b/modules/web/handler/activity.go index 70b2e34..de8331a 100644 --- a/modules/web/handler/activity.go +++ b/modules/web/handler/activity.go @@ -2198,3 +2198,15 @@ func DiscountTicketInfo(c *gin.Context) { } resp.ChannelList = call.GetConfigPayChannelsByID(common.CurrencyINR) } + +func InviteRankInfo(c *gin.Context) { + a := app.NewApp(c) + defer func() { + a.Response() + }() + if !a.CheckActivityExpire(common.ActivityIDBetDraw) { + return + } + resp := new(values.InviteInfoResp) + a.Data = resp +} diff --git a/modules/web/handler/share.go b/modules/web/handler/share.go index 8e38b21..768e9e1 100644 --- a/modules/web/handler/share.go +++ b/modules/web/handler/share.go @@ -84,13 +84,6 @@ func ShareInfo(c *gin.Context) { } channel := call.GetChannelByID(a.Channel) if channel != nil { - // resp.ShareLink += channel.URL + "?code=" + "xxxxxx" - // if a.Prefix != "" { - // resp.ShareLink = a.Prefix + "." + resp.ShareLink - // } else { - // resp.ShareLink = "www." + resp.ShareLink - // } - // resp.ShareLink = "https://" + resp.ShareLink resp.ShareLink = channel.ShareUrl } a.GetUID() @@ -107,20 +100,7 @@ func ShareInfo(c *gin.Context) { resp.RechargeCount = call.GetUserShareRecharges(a.UID, 1) resp.TotalRecharge = call.GetUserShareRechargeAmount(a.UID, 1) resp.ShareCode = shareInfo.Share - // if channel != nil { - // num := 10000 - // channelId := channel.ChannelID - // if channel.ChannelID < num { - // channelId += num - // } - // resp.ShareLink = channel.URL + "?code=" + shareInfo.Share + "&ch=" + fmt.Sprintf("%d", channelId) - // if a.Prefix != "" { - // resp.ShareLink = a.Prefix + "." + resp.ShareLink - // } else { - // resp.ShareLink = "www." + resp.ShareLink - // } - // resp.ShareLink = "https://" + resp.ShareLink - // } + num := 0 if resp.AvailableReward > 0 { num = 1 @@ -130,6 +110,73 @@ func ShareInfo(c *gin.Context) { } } +func ShareList(c *gin.Context) { + a := app.NewApp(c) + defer func() { + a.Response() + }() + req := new(values.ShareListReq) + if !a.S(req) { + return + } + resp := &values.ShareListResp{} + a.Data = resp + type TempData struct { + Uid int `gorm:"column:UID"` + Amount int64 `gorm:"column:total_reward"` + RechargeAmount int64 `gorm:"column:total_recharge"` + } + var ret []TempData + if req.Type == 1 { + err := db.Mysql().QueryCountBySql(fmt.Sprintf("SELECT count(*) FROM share_detail WHERE FROM_UNIXTIME(Time, '%%Y-%%m-%%d') = CURDATE() and up = %d GROUP BY UID ORDER BY total_reward DESC", a.UID), &resp.Count) + if err != nil { + log.Error("err:%v", err) + } + err = db.Mysql().QueryBySql(fmt.Sprintf("SELECT UID, SUM(reward) AS total_reward, SUM(recharge_amount) AS total_recharge FROM share_detail WHERE up = %d and FROM_UNIXTIME(Time, '%%Y-%%m-%%d') = CURDATE() GROUP BY UID ORDER BY total_reward DESC limit %d,%d", a.UID, req.Page, req.Size), &ret) + if err != nil { + log.Error("err:%v", err) + } + for _, item := range ret { + resp.TodayRewardList = append(resp.TodayRewardList, values.RewardInfo{ + UID: item.Uid, + Amount: item.Amount, + }) + } + } else if req.Type == 2 { + err := db.Mysql().QueryCountBySql(fmt.Sprintf("SELECT count(*) FROM share_detail where up = %d GROUP BY UID ORDER BY total_reward DESC", a.UID), &resp.Count) + if err != nil { + log.Error("err:%v", err) + } + err = db.Mysql().QueryBySql(fmt.Sprintf("SELECT UID, SUM(reward) AS total_reward, SUM(recharge_amount) AS total_recharge FROM share_detail where up = %d GROUP BY UID ORDER BY total_reward DESC limit %d,%d", a.UID, req.Page, req.Size), &ret) + if err != nil { + log.Error("err:%v", err) + } + for _, item := range ret { + resp.RewardList = append(resp.RewardList, values.RewardInfo{ + UID: item.Uid, + Amount: item.Amount, + }) + } + } else if req.Type == 3 { + err := db.Mysql().QueryCountBySql(fmt.Sprintf("SELECT count(*) FROM share_detail where up = %d GROUP BY UID ORDER BY total_reward DESC", a.UID), &resp.Count) + if err != nil { + log.Error("err:%v", err) + } + err = db.Mysql().QueryBySql(fmt.Sprintf("SELECT UID, SUM(reward) AS total_reward, SUM(recharge_amount) AS total_recharge FROM share_detail where up = %d GROUP BY UID ORDER BY total_recharge DESC limit %d,%d", a.UID, req.Page, req.Size), &ret) + if err != nil { + log.Error("err:%v", err) + } + for _, item := range ret { + user, _ := call.GetUserXInfo(item.Uid, "birth") + resp.InviteList = append(resp.InviteList, values.InviteInfo{ + UID: item.Uid, + RechargeAmount: item.RechargeAmount, + RegisterTime: user.Birth, + }) + } + } +} + func GetActivityCode(c *gin.Context) { a := app.NewApp(c) defer func() { diff --git a/modules/web/routers/routers_activity.go b/modules/web/routers/routers_activity.go index 3331cc5..36a9c6a 100644 --- a/modules/web/routers/routers_activity.go +++ b/modules/web/routers/routers_activity.go @@ -48,4 +48,6 @@ func activity(e *gin.RouterGroup) { e.POST("/activity/weekCard/draw", handler.ActivityWeekCardDraw) // 优惠券 e.POST("/activity/discountTicket/info", handler.DiscountTicketInfo) + // 好友冲冲冲 + e.POST("/activity/inviteRank/info", handler.InviteRankInfo) } diff --git a/modules/web/routers/routers_share.go b/modules/web/routers/routers_share.go index 245bfcb..d4b61a3 100644 --- a/modules/web/routers/routers_share.go +++ b/modules/web/routers/routers_share.go @@ -11,6 +11,7 @@ func share(e *gin.RouterGroup) { e.POST("/share/platform", handler.SharePlatformInfo) e.POST("/share/withdraw", handler.ShareWithdraw) e.POST("/share/activity_code", handler.GetActivityCode) + e.POST("/share/list", handler.ShareList) // e.POST("/share/reference", handler.ShareReference) // e.POST("/share/report", handler.ShareReport) // e.POST("/share/transfer", handler.ShareTransfer) diff --git a/modules/web/values/activity.go b/modules/web/values/activity.go index 1da9614..550d93c 100644 --- a/modules/web/values/activity.go +++ b/modules/web/values/activity.go @@ -325,3 +325,21 @@ type DiscountTicketResp struct { Ticket *DiscountTicketInfo ChannelList []*common.ConfigPayChannels } + +type RewardRankConfig struct { + RankMin int64 + RankMax int64 + Reward int64 +} + +type RankInfo struct { + Rank int `json:"Rank"` + Reward int `json:"Reward"` + UserName string `json:"UserName"` +} + +type InviteInfoResp struct { + RewardRankConfig []RewardRankConfig + RankInfoList []RankInfo + MyRank RankInfo +} diff --git a/modules/web/values/share.go b/modules/web/values/share.go index 084c609..b9e723f 100644 --- a/modules/web/values/share.go +++ b/modules/web/values/share.go @@ -207,3 +207,26 @@ type GetActivityCodeResp struct { type ShareCodeBindReq struct { Code string } + +type ShareListReq struct { + Type int // 1 今日贡献 2 总贡献 3 邀请列表 + Page int + Size int +} + +type ShareListResp struct { + TodayRewardList []RewardInfo + RewardList []RewardInfo + InviteList []InviteInfo + Count int // 总数 +} +type RewardInfo struct { + UID int // UID + Amount int64 // 总额 +} + +type InviteInfo struct { + UID int // UID + RechargeAmount int64 // 充值总额 + RegisterTime int64 // 注册时间 +}