Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. DELIMITER ;;
  2. CREATE DEFINER=`root`@`localhost` PROCEDURE `AddUnilevel`(
  3. IN i_subscriber_id VARCHAR(100),
  4. IN i_amount decimal(10,2),
  5. IN i_transaction_type VARCHAR(20),
  6. IN i_trackno VARCHAR(30),
  7. IN i_type VARCHAR(30)
  8. )
  9. BEGIN
  10. DECLARE v_amount INT UNSIGNED;
  11. declare v_price decimal unsigned;
  12. DECLARE v_points DECIMAL UNSIGNED;
  13. declare v_referral_code_price decimal unsigned;
  14. DECLARE v_referral_account_type VARCHAR(30);
  15. DECLARE v_referred_by_id VARCHAR(30);
  16. DECLARE v_statuserror TINYINT(1);
  17. DECLARE done INT DEFAULT FALSE;
  18. DECLARE o_success BOOLEAN;
  19. DECLARE o_message VARCHAR(255);
  20.  
  21. DECLARE EXIT HANDLER FOR SQLEXCEPTION
  22. BEGIN
  23. ROLLBACK;
  24. SELECT o_success AS `status`,o_message AS message, v_statuserror AS error;
  25. END;
  26.  
  27. DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
  28.  
  29. START TRANSACTION;
  30. -- DECLARE EXIT HANDLER FOR SQLEXCEPTION
  31.  
  32. SET o_success = FALSE;
  33. SET o_message = 'Failed 1 Add Unilevel Points';
  34.  
  35. select referred_by into v_referred_by_id from `user_referrals` where subscriber_id = i_subscriber_id;
  36.  
  37. SELECT `subscription_code` INTO v_referral_account_type
  38. FROM user_subscriptions t1
  39. WHERE t1.`created_at` = (SELECT MAX(t2.`created_at`)
  40. FROM user_subscriptions t2
  41. WHERE t2.`subscriber_id` = t1.`subscriber_id`)
  42. AND t1.`subscriber_id` COLLATE utf8mb4_unicode_ci = v_referred_by_id;
  43.  
  44. SET o_message = 'Failed 2 Add Unilevel Points';
  45.  
  46. if v_referral_account_type = 'master' then
  47.  
  48. case
  49. when i_transaction_type = 'dom_air_travel' then set v_amount = 20;
  50. WHEN i_transaction_type = 'int_air_travel' THEN set v_amount = 20;
  51. WHEN i_transaction_type = 'hotel_transaction' THEN set v_amount = i_amount * 0.03;
  52. else set v_amount = 0;
  53. end case ;
  54. end if;
  55.  
  56. if v_referral_account_type = 'mentor' THEN
  57. CASE
  58. WHEN i_transaction_type = 'dom_air_travel' THEN set v_amount = 10;
  59. WHEN i_transaction_type = 'int_air_travel' THEN set v_amount = 10;
  60. WHEN i_transaction_type = 'hotel_transaction' THEN set v_amount = i_amount * 0.02;
  61. ELSE set v_amount = 0;
  62. END case;
  63.  
  64. end if;
  65.  
  66. select `price` into v_referral_code_price from `subscriptions` where `code` = v_referral_account_type;
  67. select `points` into v_points from `user_points` where `subscriber_id` = v_referred_by_id;
  68.  
  69. IF v_referral_code_price < 9990 or v_amount = 0 then
  70.  
  71. SET o_success = TRUE;
  72. SET o_message = 'Successful';
  73. SET v_statuserror = 1;
  74.  
  75. else
  76. INSERT INTO `user_point_transactions` (
  77. `subscriber_id`,
  78. `reference_number`,
  79. `tracking_number`,
  80. `transaction_type`,
  81. `amount`,
  82. `balance_before`,
  83. `balance_after`,
  84. `type`,
  85. `status`,
  86. `created_at`,
  87. `updated_at`
  88. )
  89. VALUES (
  90. v_referred_by_id,
  91. CONCAT('REF-',v_referred_by_id,'-',CHAR( FLOOR(65 + (RAND() * 25))),CHAR( FLOOR(65 + (RAND() * 25))),SUBSTR(UNIX_TIMESTAMP(),4,6)),
  92. i_trackno,
  93. i_transaction_type,
  94. v_amount,
  95. v_points,
  96. v_points + v_amount,
  97. i_type,
  98. 1,
  99. now(),
  100. now()
  101. );
  102.  
  103.  
  104. UPDATE `user_points`
  105. SET `points` = `points` + v_amount
  106. WHERE `subscriber_id` = v_referred_by_id;
  107.  
  108.  
  109. END IF;
  110.  
  111.  
  112. COMMIT;
  113. SET o_success = TRUE;
  114. SET o_message = 'Successful';
  115. SET v_statuserror = 1;
  116. SELECT o_success AS `status`,o_message AS message, v_statuserror AS error;
  117. END;;
  118. DELIMITER ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement