|
|
@@ -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 |
|
|
|