软质押增加奖励发放记录
This commit is contained in:
@@ -19,6 +19,8 @@ type (
|
||||
withSession(session sqlx.Session) NhTaskNftStakeRewardModel
|
||||
GetRandomCoefficientByUid(ctx context.Context, uid uint, awardSeq int, min, max float64) (float64, error)
|
||||
SetReward(ctx context.Context, uid uint, awardSeq, occupyPercent int, pledgeOutput, reward decimal.Decimal) error
|
||||
CountReward(ctx context.Context, uid uint) (float64, error)
|
||||
FindRewardsByUid(ctx context.Context, uid uint) ([]*NhTaskNftStakeReward, error)
|
||||
}
|
||||
|
||||
customNhTaskNftStakeRewardModel struct {
|
||||
@@ -26,6 +28,23 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (m *customNhTaskNftStakeRewardModel) CountReward(ctx context.Context, uid uint) (float64, error) {
|
||||
query := fmt.Sprintf("SELECT SUM(`reward`) FROM %s WHERE `uid` = ? AND `sent` = 1", m.table)
|
||||
var reward float64
|
||||
err := m.conn.QueryRowCtx(ctx, &reward, query, uid)
|
||||
return reward, err
|
||||
}
|
||||
|
||||
func (m *customNhTaskNftStakeRewardModel) FindRewardsByUid(ctx context.Context, uid uint) ([]*NhTaskNftStakeReward, error) {
|
||||
query := fmt.Sprintf("SELECT * FROM %s WHERE `uid` = ? AND `sent` = 1", m.table)
|
||||
var list []*NhTaskNftStakeReward
|
||||
err := m.conn.QueryRowsCtx(ctx, &list, query, uid)
|
||||
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// SetReward 对未发送奖励的用户发送奖励,支持并发,且不会重发
|
||||
func (m *customNhTaskNftStakeRewardModel) SetReward(ctx context.Context, uid uint, awardSeq, occupyPercent int, pledgeOutput, reward decimal.Decimal) error {
|
||||
update := fmt.Sprintf("UPDATE %s SET `occupy_percent` = ?, `pledge_output` = ?, `reward` = ?, `sent` = 1 WHERE `uid` = ? AND `award_seq` = ? AND `sent` = 0", m.table)
|
||||
|
||||
Reference in New Issue
Block a user