email reward
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
@@ -15,14 +16,15 @@ type (
|
||||
NhTaskNftStakeModel interface {
|
||||
nhTaskNftStakeModel
|
||||
withSession(session sqlx.Session) NhTaskNftStakeModel
|
||||
StakeNft(ctx context.Context, uid uint, roleId uint64, tokens []string) error
|
||||
UnStakeNft(ctx context.Context, uid uint, token string) error
|
||||
StakeNft(ctx context.Context, uid uint, roleId uint64, tokenId string) error
|
||||
UnStakeNft(ctx context.Context, uid uint, token string, isTransferOut bool) error
|
||||
FindByUid(ctx context.Context, uid uint) ([]NhTaskNftStake, error)
|
||||
AllStakeNft(ctx context.Context) ([]NhTaskNftStake, error)
|
||||
}
|
||||
|
||||
customNhTaskNftStakeModel struct {
|
||||
*defaultNhTaskNftStakeModel
|
||||
log NhTaskNftStakeLogModel
|
||||
}
|
||||
)
|
||||
|
||||
@@ -46,19 +48,46 @@ func (m *customNhTaskNftStakeModel) FindByUid(ctx context.Context, uid uint) ([]
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (m *customNhTaskNftStakeModel) UnStakeNft(ctx context.Context, uid uint, token string) error {
|
||||
func (m *customNhTaskNftStakeModel) UnStakeNft(ctx context.Context, uid uint, token string, isTransferOut bool) error {
|
||||
update := fmt.Sprintf("UPDATE %s SET `state` = 0 WHERE `uid` = ? AND `token_id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, update, uid, token)
|
||||
result, err := m.conn.ExecCtx(ctx, update, uid, token)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
row, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if row > 0 {
|
||||
var operate int8
|
||||
if isTransferOut {
|
||||
operate = 3
|
||||
} else {
|
||||
operate = 2
|
||||
}
|
||||
_, err = m.log.Insert(ctx, &NhTaskNftStakeLog{
|
||||
Uid: uid,
|
||||
TokenId: token,
|
||||
Operate: operate,
|
||||
})
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *customNhTaskNftStakeModel) StakeNft(ctx context.Context, uid uint, roleId uint64, tokens []string) error {
|
||||
func (m *customNhTaskNftStakeModel) StakeNft(ctx context.Context, uid uint, roleId uint64, tokenId string) error {
|
||||
insertOrUpdate := fmt.Sprintf("INSERT INTO %s (`uid`, `token_id`, `role_id`, `state`) VALUES (?, ?, ?, 1) ON DUPLICATE KEY UPDATE `role_id` = ?, `state` = 1", m.table)
|
||||
for _, token := range tokens {
|
||||
_, err := m.conn.ExecCtx(ctx, insertOrUpdate, uid, token, roleId, roleId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := m.conn.ExecCtx(ctx, insertOrUpdate, uid, tokenId, roleId, roleId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = m.log.Insert(ctx, &NhTaskNftStakeLog{
|
||||
Uid: uid,
|
||||
RoleId: roleId,
|
||||
TokenId: tokenId,
|
||||
Operate: 1,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorw("insert stake log failed", logx.Field("err", err), logx.Field("uid", uid), logx.Field("tokenId", token), logx.Field("role", roleId))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -67,6 +96,7 @@ func (m *customNhTaskNftStakeModel) StakeNft(ctx context.Context, uid uint, role
|
||||
func NewNhTaskNftStakeModel(conn sqlx.SqlConn) NhTaskNftStakeModel {
|
||||
return &customNhTaskNftStakeModel{
|
||||
defaultNhTaskNftStakeModel: newNhTaskNftStakeModel(conn),
|
||||
log: NewNhTaskNftStakeLogModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user