Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 5.66 KB | None | 0 0
  1. CREATE Procedure [dbo].[Player_InsertPlayer](
  2.                                         @Nickname               nvarchar(50),
  3.                                         @GameNickname           nvarchar(50),
  4.                                         @Password               nvarchar(50),
  5.                                         @EmailAddress           nvarchar(100),
  6.                                         @EmailStatus            int,
  7.                                         @FirstName              nvarchar(50),
  8.                                         @LastName               nvarchar(50),
  9.                                         @Gender                 int,
  10.                                         @BirthDate              datetime,
  11.                                         @Address1               nvarchar(100),
  12.                                         @Address2               nvarchar(100),
  13.                                         @City                   nvarchar(50),
  14.                                         @State                  nvarchar(50),
  15.                                         @Country                nvarchar(2),
  16.                                         @ZipCode                nvarchar(10),
  17.                                         @Phone                  nvarchar(30),
  18.                                         @Mobile                 nvarchar(30),
  19.                                         @Fax                    nvarchar(30),
  20.                                         @Comments               nvarchar(2000),
  21.                                         @OperatorID             int,
  22.                                         @AffiliateID            int,
  23.                                         @AgentID                int,
  24.                                         @PlayerStatus           int,
  25.                                         @AudienceType           int = 2,
  26.                                         @MadeDeposit            bit,
  27.                                         @MustChangePassword     bit,
  28.                                         @IsLock                 bit,
  29.                                         @ChargeBack             bit,
  30.                                         @ChargeBackDesc         nvarchar(500),
  31.                                         @TechComments           nvarchar(500),
  32.                                         @VisitedDepositPage     bit,
  33.                                         @CurrencyID             int,
  34.                                         @ExternalPlayerID       int,
  35.                                         @ExternalHirParentID    int,
  36.                                         @SecretQuestion         nvarchar(100),
  37.                                         @SecretAnswer           nvarchar(50),
  38.                                         @ChatStatus             int,
  39.                                         @IsExternalWallet       bit = null,
  40.                                         @GroupLimitID           int = 0) As
  41. Begin
  42. begin tran
  43. BEGIN TRY
  44.  
  45.     Declare @playerID int
  46.     DECLARE @LockOperatorID int, @IsPlayerExist int
  47.    
  48.     IF(@EmailAddress = '')
  49.     BEGIN              
  50.         set @EmailAddress = @Nickname + '@fakeemail.com' ;
  51.     END
  52.    
  53.     IF(@CurrencyID = -1)
  54.     BEGIN
  55.         SET @CurrencyID = 1
  56.     END
  57.        
  58.         -- if there is a config with id 4 set for an operator it means it is set up with external wallet
  59.         DECLARE @IsExternalWalletOperator bit =
  60.             case when exists(SELECT OPERATOR_VALUE FROM TO_OPERATOR_CONFIG_VALUES where CONFIG_ID = 4 and OPERATOR_ID = @OperatorID)
  61.             then 1 else 0 end
  62.  
  63.             INSERT INTO [TP_PLAYERS]
  64.                    ([nickname]
  65.                    ,[game_nickname]
  66.                    ,[password]
  67.                    ,[email_address]
  68.                    ,[email_status]
  69.                    ,[first_name]
  70.                    ,[last_name]
  71.                    ,[gender]
  72.                    ,[birth_date]
  73.                    ,[address1]
  74.                    ,[address2]
  75.                    ,[city]
  76.                    ,[state]
  77.                    ,[country]
  78.                    ,[zip_code]
  79.                    ,[phone]
  80.                    ,[mobile]
  81.                    ,[fax]
  82.                    ,[comments]
  83.                    ,[join_date]
  84.                    ,[operator_id]
  85.                    ,[affiliate_id]
  86.                    ,[agent_id]
  87.                    ,[player_status]
  88.                    ,[audience_type]
  89.                    ,[made_deposit]
  90.                    ,[status_date]
  91.                    ,[must_change_password]
  92.                    ,[is_lock]
  93.                    ,[charge_back]
  94.                    ,[charge_back_desc]
  95.                    ,[tech_comments]
  96.                    ,[visited_deposit_page]
  97.                    ,[currency_id]
  98.                    ,[external_player_id]
  99.                    ,[external_hierarchy_parent_id]
  100.                    ,[security_question]
  101.                    ,[security_answer]
  102.                    ,[CHAT_STATUS]
  103.                    ,is_external_wallet)
  104.                    
  105.              VALUES
  106.                    (@Nickname  
  107.                     ,@GameNickname         
  108.                     ,@Password             
  109.                     ,@EmailAddress         
  110.                     ,@EmailStatus          
  111.                     ,@FirstName            
  112.                     ,@LastName             
  113.                     ,@Gender                   
  114.                     ,@BirthDate            
  115.                     ,@Address1             
  116.                     ,@Address2             
  117.                     ,@City                 
  118.                     ,@State                
  119.                     ,@Country              
  120.                     ,@ZipCode              
  121.                     ,@Phone                
  122.                     ,@Mobile                   
  123.                     ,@Fax                  
  124.                     ,@Comments             
  125.                     ,getDate()             
  126.                     ,@OperatorID               
  127.                     ,@AffiliateID          
  128.                     ,@AgentID              
  129.                     ,@PlayerStatus         
  130.                     ,@AudienceType         
  131.                     ,@MadeDeposit          
  132.                     ,getDate()             
  133.                     ,@MustChangePassword    
  134.                     ,@IsLock                   
  135.                     ,@ChargeBack               
  136.                     ,@ChargeBackDesc           
  137.                     ,@TechComments         
  138.                     ,@VisitedDepositPage       
  139.                     ,@CurrencyID
  140.                     ,@ExternalPlayerID
  141.                     ,@ExternalHirParentID
  142.                     ,@SecretQuestion
  143.                     ,@SecretAnswer
  144.                     ,@ChatStatus
  145.                     ,@IsExternalWalletOperator)
  146.            
  147.            
  148.             Set @PlayerID = SCOPE_IDENTITY()
  149.            
  150.             IF @AffiliateID <> -1
  151.                 BEGIN
  152.                     INSERT INTO T_AFFILIATE_PLAYERS
  153.                     VALUES(@AffiliateID, @playerID, SYSDATETIME());
  154.                 END;
  155.                
  156.             IF @GroupLimitID <> 0
  157.                 BEGIN
  158.                     -- on Api level the group limit is taken from cache and then validated
  159.                     -- needs to validate on DB level too as the cache could not be update on the Api request
  160.                     DECLARE @AssignedOnOperator bit;
  161.                     SELECT @AssignedOnOperator = COUNT(*) FROM TG_VIP_GROUPS_LEVELS
  162.                     WHERE OPERATOR_ID = @OperatorID
  163.                          AND GROUP_ID = @GroupLimitID
  164.                                  
  165.                     IF @assignedOnOperator = 1
  166.                         BEGIN                      
  167.                             INSERT TG_VIP_GROUPS_LEVELS(PLAYER_ID, GROUP_ID) VALUES(@PlayerID, @GroupLimitID)  
  168.                         END;
  169.                 END;
  170.            
  171.             exec dbo.Player_GetPlayerByParam @OperatorID, @playerID, -1, '', ''
  172.     commit tran
  173.     END TRY
  174.     BEGIN CATCH
  175.          Declare @ErrorMsg NVarChar(1000),
  176.                   @ErrorLine NVarChar(100),
  177.                   @ErrorMessage NVarChar(1000),
  178.                   @ErrorSeverity Int,
  179.                   @ErrorState Int,
  180.                   @DatabaseID Int,
  181.                   @DatabaseName NVarChar(100);
  182.  
  183.           Select @ErrorLine = Convert(NVarChar, ERROR_NUMBER()),
  184.                  @ErrorMessage = ERROR_MESSAGE(),
  185.                  @ErrorSeverity = ERROR_SEVERITY(),
  186.                  @ErrorState = ERROR_STATE(),
  187.                  @DatabaseID = DB_ID(),
  188.                  @DatabaseName = DB_NAME();
  189.          
  190.           if (@@TRANCOUNT > 0)
  191.             rollback transaction;
  192.        
  193.           Set @ErrorMsg = 'DB:Player_InsertPlayer (Error=' + @ErrorMessage;
  194.  
  195.           IF @ErrorMessage like '%Violation of UNIQUE KEY constraint%'
  196.           BEGIN
  197.                 EXEC dbo.General_WriteLog @MessageText = @ErrorMsg, @Level = 2
  198.           END
  199.           ELSE
  200.           BEGIN
  201.                 Exec dbo.General_WriteGeneralError '0.0.0.0', @ErrorMsg;
  202.           END
  203.  
  204.           Raiserror (@ErrorMessage, @ErrorSeverity, @ErrorState, @DatabaseID, @DatabaseName);
  205.     END CATCH
  206. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement