feat: 积分质押功能
This commit is contained in:
@@ -22,32 +22,7 @@ import (
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
|
||||
TaskModel model.NhTaskModel
|
||||
taskAssetModel model.NhTaskAssetModel
|
||||
taskAssetRecordModel model.NhTaskAssetRecordModel
|
||||
TaskProgressModel model.NhTaskProgressModel
|
||||
TwitterModel model.NhTwitterModel
|
||||
PromoteBindModel model.NhPromoteBindModel
|
||||
TouristBindModel model.NhTouristBindModel
|
||||
CommunityModel model.NhTaskCommunityModel
|
||||
UserModel model.NhUserModel
|
||||
WalletModel model.NhWalletModel
|
||||
ConfigModel model.NhSystemConfigModel
|
||||
NftHolderModel model.NhNftHolderModel
|
||||
NftHolderChangeLogModel model.NhNftHolderChangeLogModel
|
||||
StakeNftModel model.NhTaskNftStakeModel
|
||||
OldStakeNftModel model.NhNftStakeModel
|
||||
StakeNftLogModel model.NhTaskNftStakeLogModel
|
||||
StakeRewardModel model.NhTaskNftStakeRewardModel
|
||||
GamePitModel model.NhGamePitModel
|
||||
StakePropertyModel model.NhNftStakePropertyModel
|
||||
EmailRewardModel model.NhEmailRewardModel
|
||||
AmbassadorModel model.NhTaskAmbassadorModel
|
||||
GameReportModel model.NhGameReportModel
|
||||
RoleModel model.NhRoleModel
|
||||
GamesPropertyModel model.NhGamesPropertyLogsModel
|
||||
AirdropModel model.NhAirdropLogModel
|
||||
PioneerRewardsModel model.NhPioneerRewardsModel
|
||||
*dbModel
|
||||
|
||||
ApiKeyCheck rest.Middleware
|
||||
AdminSecretCheck rest.Middleware
|
||||
@@ -61,44 +36,18 @@ type ServiceContext struct {
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
dbConn := c.MySql.Conn()
|
||||
gameConn := c.GameDB.Conn()
|
||||
configModel := model.NewNhSystemConfigModel(dbConn, c.Cache)
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
|
||||
TaskModel: model.NewNhTaskModel(dbConn),
|
||||
taskAssetModel: model.NewNhTaskAssetModel(dbConn),
|
||||
taskAssetRecordModel: model.NewNhTaskAssetRecordModel(dbConn),
|
||||
TaskProgressModel: model.NewNhTaskProgressModel(dbConn),
|
||||
TwitterModel: model.NewNhTwitterModel(dbConn),
|
||||
PromoteBindModel: model.NewNhPromoteBindModel(dbConn),
|
||||
CommunityModel: model.NewNhTaskCommunityModel(dbConn),
|
||||
UserModel: model.NewNhUserModel(dbConn),
|
||||
TouristBindModel: model.NewNhTouristBindModel(dbConn),
|
||||
WalletModel: model.NewNhWalletModel(dbConn),
|
||||
ConfigModel: configModel,
|
||||
NftHolderModel: model.NewNhNftHolderModel(dbConn),
|
||||
NftHolderChangeLogModel: model.NewNhNftHolderChangeLogModel(dbConn),
|
||||
StakeNftModel: model.NewNhTaskNftStakeModel(dbConn),
|
||||
OldStakeNftModel: model.NewNhNftStakeModel(dbConn),
|
||||
StakeRewardModel: model.NewNhTaskNftStakeRewardModel(dbConn),
|
||||
GamePitModel: model.NewNhGamePitModel(dbConn),
|
||||
StakePropertyModel: model.NewNhNftStakePropertyModel(dbConn),
|
||||
EmailRewardModel: model.NewNhEmailRewardModel(dbConn),
|
||||
AmbassadorModel: model.NewNhTaskAmbassadorModel(dbConn),
|
||||
GameReportModel: model.NewNhGameReportModel(dbConn),
|
||||
RoleModel: model.NewNhRoleModel(dbConn),
|
||||
GamesPropertyModel: model.NewNhGamesPropertyLogsModel(dbConn),
|
||||
AirdropModel: model.NewNhAirdropLogModel(dbConn),
|
||||
PioneerRewardsModel: model.NewNhPioneerRewardsModel(dbConn),
|
||||
|
||||
Config: c,
|
||||
dbModel: newDBModel(dbConn, gameConn, configModel),
|
||||
ApiKeyCheck: middleware.NewApiKeyCheckMiddleware(configModel).Handle,
|
||||
AdminSecretCheck: middleware.NewAdminSecretCheckMiddleware(configModel).Handle,
|
||||
Game7ApiKeyCheck: middleware.NewGame7ApiKeyCheckMiddleware(configModel).Handle,
|
||||
KGeNApiKeyCheck: middleware.NewKGeNApiKeyCheckMiddleware(configModel).Handle,
|
||||
|
||||
Earn: c.Earn.BuildEarnClient(),
|
||||
DBConn: dbConn,
|
||||
Redis: redis.MustNewRedis(c.Redis),
|
||||
DBConn: dbConn,
|
||||
Earn: c.Earn.BuildEarnClient(),
|
||||
Redis: redis.MustNewRedis(c.Redis),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,6 +122,35 @@ func (s *ServiceContext) AddUserAssetWithSession(ctx context.Context, session sq
|
||||
recordModel = s.taskAssetRecordModel
|
||||
gamesPropertyModel = s.GamesPropertyModel
|
||||
}
|
||||
if amount.LessThan(decimal.Zero) {
|
||||
uAsset, err := assetModel.FindOneByUid(ctx, int(uid))
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
return errs.New(errs.ErrInsufficientPoints, "insufficient point")
|
||||
}
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
switch asset {
|
||||
case consts.AssetType_Points:
|
||||
if uAsset.Points.LessThan(amount.Abs()) {
|
||||
return errs.New(errs.ErrInsufficientPoints, "insufficient point")
|
||||
}
|
||||
case consts.AssetType_Castile:
|
||||
if uAsset.Castile.LessThan(amount.Abs()) {
|
||||
return errs.New(errs.ErrInsufficientCastile, "insufficient castile")
|
||||
}
|
||||
case consts.AssetType_Elite_Points:
|
||||
if uAsset.ElitePoints.LessThan(amount.Abs()) {
|
||||
return errs.New(errs.ErrInsufficientElitePoints, "insufficient elite points")
|
||||
}
|
||||
case consts.AssetType_Keys:
|
||||
if uAsset.Keys < int(amount.IntPart()) {
|
||||
return errs.New(errs.ErrInsufficientKeys, "insufficient keys")
|
||||
}
|
||||
default:
|
||||
return errors.New("unknown asset type")
|
||||
}
|
||||
}
|
||||
var err error
|
||||
switch asset {
|
||||
case consts.AssetType_Points:
|
||||
@@ -186,7 +164,7 @@ func (s *ServiceContext) AddUserAssetWithSession(ctx context.Context, session sq
|
||||
case consts.AssetType_Property:
|
||||
_, err = gamesPropertyModel.Insert(ctx, &model.NhGamesPropertyLogs{
|
||||
Uid: uid,
|
||||
RoleId: int64(role),
|
||||
RoleId: role,
|
||||
PropertyId: assetId,
|
||||
PropertyNum: uint(amount.IntPart()),
|
||||
})
|
||||
@@ -234,6 +212,7 @@ func (s *ServiceContext) AddUserAssetWithSession(ctx context.Context, session sq
|
||||
return s.AddUserAssetWithSession(ctx, session, pb.ShareUid, 0, asset, assetId, rewardAmount, fmt.Sprintf("分享返利,比例%s", rated.String()), 7, uid, false)
|
||||
}
|
||||
|
||||
// AddUserAsset 增加用户资产
|
||||
func (s *ServiceContext) AddUserAsset(ctx context.Context, uid uint, role int64, asset consts.AssetType, assetId string, amount decimal.Decimal, remark string, eventId uint64, provideUid uint, referralReward bool) error {
|
||||
return s.AddUserAssetWithSession(ctx, nil, uid, role, asset, assetId, amount, remark, eventId, provideUid, referralReward)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user