diff --git a/app/db/db_new_acquisition.go b/app/db/db_new_acquisition.go index 975d1de..180010f 100644 --- a/app/db/db_new_acquisition.go +++ b/app/db/db_new_acquisition.go @@ -17,7 +17,15 @@ func GetNewAcquisitionRewardLog(Db *xorm.Engine, condition *model.NewAcquisition } func GetNewAcquisitionRewardLogWhere(Db *xorm.Engine, uid, toUid, lv int) (*model.NewAcquisitionRewardLog, bool, error) { var data model.NewAcquisitionRewardLog - has, err := Db.Where("uid=? and to_uid=? and lv=?", uid, toUid, lv).Get(&data) + has, err := Db.Where("uid=? and to_uid=? and lv=? ", uid, toUid, lv).Get(&data) + if err != nil { + return nil, false, err + } + return &data, has, nil +} +func GetNewAcquisitionRewardLogWhereCoinId(Db *xorm.Engine, uid, toUid, lv, coin_id int) (*model.NewAcquisitionRewardLog, bool, error) { + var data model.NewAcquisitionRewardLog + has, err := Db.Where("uid=? and to_uid=? and lv=? and coin_id=?", uid, toUid, lv, coin_id).Get(&data) if err != nil { return nil, false, err } diff --git a/consume/md/md.go b/consume/md/md.go index ac6ae13..61a9acd 100644 --- a/consume/md/md.go +++ b/consume/md/md.go @@ -58,6 +58,7 @@ type AcquisitionCfg struct { InvitedRewardMax string `json:"invited_reward_max"` RewardType string `json:"reward_type"` RewardCoinId string `json:"reward_coin_id"` + NewRewardCoinId string `json:"new_reward_coin_id"` LvRewardList []LvRewardList `json:"lv_reward_list"` } `json:"reward_rule"` ExtraRewardSetting struct { @@ -83,16 +84,25 @@ type AcquisitionCfg struct { RankData string `json:"rank_data"` } type LvRewardList struct { - Id string `json:"id"` + Id string `json:"id"` + DirectSuccess string `json:"direct_success"` + IndirectSuccess string `json:"indirect_success"` + Name string `json:"name"` + InvitedReward string `json:"invited_reward"` + DirectSuccessMax string `json:"direct_success_max"` + IndirectSuccessMax string `json:"indirect_success_max"` + InvitedRewardMax string `json:"invited_reward_max"` + CoinList []RewardRuleCoinList `json:"coin_list"` +} +type RewardRuleCoinList struct { + CoinId string `json:"coin_id"` DirectSuccess string `json:"direct_success"` IndirectSuccess string `json:"indirect_success"` - Name string `json:"name"` InvitedReward string `json:"invited_reward"` DirectSuccessMax string `json:"direct_success_max"` IndirectSuccessMax string `json:"indirect_success_max"` InvitedRewardMax string `json:"invited_reward_max"` } - type User struct { Info *model.User Profile *model.UserProfile diff --git a/consume/zhios_acquisition_condition.go b/consume/zhios_acquisition_condition.go index 72cf81f..b62404f 100644 --- a/consume/zhios_acquisition_condition.go +++ b/consume/zhios_acquisition_condition.go @@ -11,6 +11,7 @@ import ( "errors" "fmt" "github.com/streadway/amqp" + "strings" "time" "xorm.io/xorm" ) @@ -122,79 +123,181 @@ func handleZhiosAcquisition(msg []byte) error { isEnd = 1 } lv = utils.StrToInt(v.Id) - InvitedReward := v.InvitedReward - if cfg.RewardRule.RewardType == "1" { - InvitedReward = Rands(v.InvitedReward, v.InvitedRewardMax) - } - //直推 - DirectSuccess := v.DirectSuccess - if cfg.RewardRule.RewardType == "1" { - DirectSuccess = Rands(v.DirectSuccess, v.DirectSuccessMax) - } - //间推 - IndirectSuccess := v.IndirectSuccess - if cfg.RewardRule.RewardType == "1" { - IndirectSuccess = Rands(v.IndirectSuccess, v.IndirectSuccessMax) - } - InvitedSource := 0 - DirectSource := 1 - IndirectSource := 2 - InvitedSourceStr := "注册奖励" - DirectSourceStr := "直推好友" - IndirectSourceStr := "间推好友" - if k > 0 { - InvitedSource = 3 - DirectSource = 4 - IndirectSource = 5 - InvitedSourceStr = "升级" + v.Name + "奖励" - DirectSourceStr = "直推好友升级" + v.Name + "奖励" - IndirectSourceStr = "间推好友升级" + v.Name + "奖励" - } - if utils.StrToFloat64(InvitedReward) > 0 { - ownRewardLog, ownhas, _ := db.GetNewAcquisitionRewardLogWhere(eg, userProfile.Uid, user.Profile.Uid, lv) - if !ownhas { - ownRewardLog = &model.NewAcquisitionRewardLog{ - Uid: user.Profile.Uid, - ToUid: user.Profile.Uid, - Title: user.Info.Nickname, - Source: InvitedSource, - SourceText: InvitedSourceStr, - Money: InvitedReward, - CreatedAt: int(time.Now().Unix()), - State: 0, - CoinId: utils.StrToInt(cfg.RewardRule.RewardCoinId), - RewardType: utils.StrToInt(cfg.RewardRule.RewardType), - InviteTime: int(userInfo.CreateAt.Unix()), - Lv: lv, - } + if cfg.RewardRule.NewRewardCoinId != "" { + ex := strings.Split(cfg.RewardRule.NewRewardCoinId, ",") + for _, v1 := range v.CoinList { + if utils.InArr(v1.CoinId, ex) { + InvitedReward := v1.InvitedReward + if cfg.RewardRule.RewardType == "1" { + InvitedReward = Rands(v1.InvitedReward, v1.InvitedRewardMax) + } + //直推 + DirectSuccess := v1.DirectSuccess + if cfg.RewardRule.RewardType == "1" { + DirectSuccess = Rands(v1.DirectSuccess, v1.DirectSuccessMax) + } + //间推 + IndirectSuccess := v1.IndirectSuccess + if cfg.RewardRule.RewardType == "1" { + IndirectSuccess = Rands(v1.IndirectSuccess, v1.IndirectSuccessMax) + } + InvitedSource := 0 + DirectSource := 1 + IndirectSource := 2 + InvitedSourceStr := "注册奖励" + DirectSourceStr := "直推好友" + IndirectSourceStr := "间推好友" + if k > 0 { + InvitedSource = 3 + DirectSource = 4 + IndirectSource = 5 + InvitedSourceStr = "升级" + v.Name + "奖励" + DirectSourceStr = "直推好友升级" + v.Name + "奖励" + IndirectSourceStr = "间推好友升级" + v.Name + "奖励" + } + if utils.StrToFloat64(InvitedReward) > 0 { + ownRewardLog, ownhas, _ := db.GetNewAcquisitionRewardLogWhereCoinId(eg, userProfile.Uid, user.Profile.Uid, lv, utils.StrToInt(v1.CoinId)) + if !ownhas { + ownRewardLog = &model.NewAcquisitionRewardLog{ + Uid: user.Profile.Uid, + ToUid: user.Profile.Uid, + Title: user.Info.Nickname, + Source: InvitedSource, + SourceText: InvitedSourceStr, + Money: InvitedReward, + CreatedAt: int(time.Now().Unix()), + State: 0, + CoinId: utils.StrToInt(v1.CoinId), + RewardType: utils.StrToInt(cfg.RewardRule.RewardType), + InviteTime: int(userInfo.CreateAt.Unix()), + Lv: lv, + } - db.InsertNewRewardLog(eg, ownRewardLog) - } - if ownRewardLog.GivenAt == 0 { + db.InsertNewRewardLog(eg, ownRewardLog) + } + if ownRewardLog.GivenAt == 0 { - ownRewardLog.CompleteCon = str - ownRewardLog.IsFull = isFull - if ownRewardLog.FullTime == 0 { - ownRewardLog.FullTime = fullTime - } - if ownRewardLog.ToRewardTime == 0 { - ownRewardLog.ToRewardTime = toRewardTime + ownRewardLog.CompleteCon = str + ownRewardLog.IsFull = isFull + if ownRewardLog.FullTime == 0 { + ownRewardLog.FullTime = fullTime + } + if ownRewardLog.ToRewardTime == 0 { + ownRewardLog.ToRewardTime = toRewardTime + } + eg.Where("id=?", ownRewardLog.Id).Update(ownRewardLog) + } + } + if utils.StrToFloat64(DirectSuccess) > 0 { + if userProfile.ParentUid > 0 { + //写入奖励记录 + extendRewardLog, extendHas, _ := db.GetNewAcquisitionRewardLogWhereCoinId(eg, userProfile.ParentUid, userProfile.Uid, lv, utils.StrToInt(v1.CoinId)) + if !extendHas { + extendRewardLog = &model.NewAcquisitionRewardLog{ + Uid: user.Profile.ParentUid, + ToUid: user.Profile.Uid, + Title: user.Info.Nickname, + Source: DirectSource, + SourceText: DirectSourceStr, + Money: DirectSuccess, + CreatedAt: int(time.Now().Unix()), + State: 0, + CoinId: utils.StrToInt(v1.CoinId), + RewardType: utils.StrToInt(cfg.RewardRule.RewardType), + InviteTime: int(userInfo.CreateAt.Unix()), + Lv: lv, + } + db.InsertNewRewardLog(eg, extendRewardLog) + } + if extendRewardLog.GivenAt == 0 { + + extendRewardLog.CompleteCon = str + extendRewardLog.IsFull = isFull + if extendRewardLog.FullTime == 0 { + extendRewardLog.FullTime = fullTime + } + if extendRewardLog.ToRewardTime == 0 { + extendRewardLog.ToRewardTime = toRewardTime + } + eg.Where("id=?", extendRewardLog.Id).Update(extendRewardLog) + } + } + } + if utils.StrToFloat64(IndirectSuccess) > 0 { + if nextUserProfile != nil && nextUserProfile.ParentUid > 0 { + IndirectRewardLog, IndirectHas, _ := db.GetNewAcquisitionRewardLogWhereCoinId(eg, nextUserProfile.ParentUid, userProfile.Uid, lv, utils.StrToInt(v1.CoinId)) + if !IndirectHas { + IndirectRewardLog = &model.NewAcquisitionRewardLog{ + Uid: nextUserProfile.ParentUid, + ToUid: user.Profile.Uid, + Title: user.Info.Nickname, + Source: IndirectSource, + SourceText: IndirectSourceStr, + Money: IndirectSuccess, + CreatedAt: int(time.Now().Unix()), + State: 0, + CoinId: utils.StrToInt(v1.CoinId), + RewardType: utils.StrToInt(cfg.RewardRule.RewardType), + InviteTime: int(userInfo.CreateAt.Unix()), + Lv: lv, + } + db.InsertNewRewardLog(eg, IndirectRewardLog) + } + if IndirectRewardLog.GivenAt == 0 { + IndirectRewardLog.CompleteCon = str + IndirectRewardLog.IsFull = isFull + if IndirectRewardLog.FullTime == 0 { + IndirectRewardLog.FullTime = fullTime + } + if IndirectRewardLog.ToRewardTime == 0 { + IndirectRewardLog.ToRewardTime = toRewardTime + } + eg.Where("id=?", IndirectRewardLog.Id).Update(IndirectRewardLog) + } + } + } } - eg.Where("id=?", ownRewardLog.Id).Update(ownRewardLog) } - } - if utils.StrToFloat64(DirectSuccess) > 0 { - if userProfile.ParentUid > 0 { - //写入奖励记录 - extendRewardLog, extendHas, _ := db.GetNewAcquisitionRewardLogWhere(eg, userProfile.ParentUid, userProfile.Uid, lv) - if !extendHas { - extendRewardLog = &model.NewAcquisitionRewardLog{ - Uid: user.Profile.ParentUid, + + } else { + InvitedReward := v.InvitedReward + if cfg.RewardRule.RewardType == "1" { + InvitedReward = Rands(v.InvitedReward, v.InvitedRewardMax) + } + //直推 + DirectSuccess := v.DirectSuccess + if cfg.RewardRule.RewardType == "1" { + DirectSuccess = Rands(v.DirectSuccess, v.DirectSuccessMax) + } + //间推 + IndirectSuccess := v.IndirectSuccess + if cfg.RewardRule.RewardType == "1" { + IndirectSuccess = Rands(v.IndirectSuccess, v.IndirectSuccessMax) + } + InvitedSource := 0 + DirectSource := 1 + IndirectSource := 2 + InvitedSourceStr := "注册奖励" + DirectSourceStr := "直推好友" + IndirectSourceStr := "间推好友" + if k > 0 { + InvitedSource = 3 + DirectSource = 4 + IndirectSource = 5 + InvitedSourceStr = "升级" + v.Name + "奖励" + DirectSourceStr = "直推好友升级" + v.Name + "奖励" + IndirectSourceStr = "间推好友升级" + v.Name + "奖励" + } + if utils.StrToFloat64(InvitedReward) > 0 { + ownRewardLog, ownhas, _ := db.GetNewAcquisitionRewardLogWhere(eg, userProfile.Uid, user.Profile.Uid, lv) + if !ownhas { + ownRewardLog = &model.NewAcquisitionRewardLog{ + Uid: user.Profile.Uid, ToUid: user.Profile.Uid, Title: user.Info.Nickname, - Source: DirectSource, - SourceText: DirectSourceStr, - Money: DirectSuccess, + Source: InvitedSource, + SourceText: InvitedSourceStr, + Money: InvitedReward, CreatedAt: int(time.Now().Unix()), State: 0, CoinId: utils.StrToInt(cfg.RewardRule.RewardCoinId), @@ -202,55 +305,92 @@ func handleZhiosAcquisition(msg []byte) error { InviteTime: int(userInfo.CreateAt.Unix()), Lv: lv, } - db.InsertNewRewardLog(eg, extendRewardLog) + + db.InsertNewRewardLog(eg, ownRewardLog) } - if extendRewardLog.GivenAt == 0 { + if ownRewardLog.GivenAt == 0 { - extendRewardLog.CompleteCon = str - extendRewardLog.IsFull = isFull - if extendRewardLog.FullTime == 0 { - extendRewardLog.FullTime = fullTime + ownRewardLog.CompleteCon = str + ownRewardLog.IsFull = isFull + if ownRewardLog.FullTime == 0 { + ownRewardLog.FullTime = fullTime } - if extendRewardLog.ToRewardTime == 0 { - extendRewardLog.ToRewardTime = toRewardTime + if ownRewardLog.ToRewardTime == 0 { + ownRewardLog.ToRewardTime = toRewardTime } - eg.Where("id=?", extendRewardLog.Id).Update(extendRewardLog) + eg.Where("id=?", ownRewardLog.Id).Update(ownRewardLog) } } - } - if utils.StrToFloat64(IndirectSuccess) > 0 { - if nextUserProfile != nil && nextUserProfile.ParentUid > 0 { - IndirectRewardLog, IndirectHas, _ := db.GetNewAcquisitionRewardLogWhere(eg, nextUserProfile.ParentUid, userProfile.Uid, lv) - if !IndirectHas { - IndirectRewardLog = &model.NewAcquisitionRewardLog{ - Uid: nextUserProfile.ParentUid, - ToUid: user.Profile.Uid, - Title: user.Info.Nickname, - Source: IndirectSource, - SourceText: IndirectSourceStr, - Money: IndirectSuccess, - CreatedAt: int(time.Now().Unix()), - State: 0, - CoinId: utils.StrToInt(cfg.RewardRule.RewardCoinId), - RewardType: utils.StrToInt(cfg.RewardRule.RewardType), - InviteTime: int(userInfo.CreateAt.Unix()), - Lv: lv, + if utils.StrToFloat64(DirectSuccess) > 0 { + if userProfile.ParentUid > 0 { + //写入奖励记录 + extendRewardLog, extendHas, _ := db.GetNewAcquisitionRewardLogWhere(eg, userProfile.ParentUid, userProfile.Uid, lv) + if !extendHas { + extendRewardLog = &model.NewAcquisitionRewardLog{ + Uid: user.Profile.ParentUid, + ToUid: user.Profile.Uid, + Title: user.Info.Nickname, + Source: DirectSource, + SourceText: DirectSourceStr, + Money: DirectSuccess, + CreatedAt: int(time.Now().Unix()), + State: 0, + CoinId: utils.StrToInt(cfg.RewardRule.RewardCoinId), + RewardType: utils.StrToInt(cfg.RewardRule.RewardType), + InviteTime: int(userInfo.CreateAt.Unix()), + Lv: lv, + } + db.InsertNewRewardLog(eg, extendRewardLog) + } + if extendRewardLog.GivenAt == 0 { + + extendRewardLog.CompleteCon = str + extendRewardLog.IsFull = isFull + if extendRewardLog.FullTime == 0 { + extendRewardLog.FullTime = fullTime + } + if extendRewardLog.ToRewardTime == 0 { + extendRewardLog.ToRewardTime = toRewardTime + } + eg.Where("id=?", extendRewardLog.Id).Update(extendRewardLog) } - db.InsertNewRewardLog(eg, IndirectRewardLog) } - if IndirectRewardLog.GivenAt == 0 { - IndirectRewardLog.CompleteCon = str - IndirectRewardLog.IsFull = isFull - if IndirectRewardLog.FullTime == 0 { - IndirectRewardLog.FullTime = fullTime + } + if utils.StrToFloat64(IndirectSuccess) > 0 { + if nextUserProfile != nil && nextUserProfile.ParentUid > 0 { + IndirectRewardLog, IndirectHas, _ := db.GetNewAcquisitionRewardLogWhere(eg, nextUserProfile.ParentUid, userProfile.Uid, lv) + if !IndirectHas { + IndirectRewardLog = &model.NewAcquisitionRewardLog{ + Uid: nextUserProfile.ParentUid, + ToUid: user.Profile.Uid, + Title: user.Info.Nickname, + Source: IndirectSource, + SourceText: IndirectSourceStr, + Money: IndirectSuccess, + CreatedAt: int(time.Now().Unix()), + State: 0, + CoinId: utils.StrToInt(cfg.RewardRule.RewardCoinId), + RewardType: utils.StrToInt(cfg.RewardRule.RewardType), + InviteTime: int(userInfo.CreateAt.Unix()), + Lv: lv, + } + db.InsertNewRewardLog(eg, IndirectRewardLog) } - if IndirectRewardLog.ToRewardTime == 0 { - IndirectRewardLog.ToRewardTime = toRewardTime + if IndirectRewardLog.GivenAt == 0 { + IndirectRewardLog.CompleteCon = str + IndirectRewardLog.IsFull = isFull + if IndirectRewardLog.FullTime == 0 { + IndirectRewardLog.FullTime = fullTime + } + if IndirectRewardLog.ToRewardTime == 0 { + IndirectRewardLog.ToRewardTime = toRewardTime + } + eg.Where("id=?", IndirectRewardLog.Id).Update(IndirectRewardLog) } - eg.Where("id=?", IndirectRewardLog.Id).Update(IndirectRewardLog) } } } + } } else { InvitedReward := cfg.RewardRule.InvitedReward