Advertisement
umonkey

coins_history view

Aug 26th, 2020 (edited)
1,747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.24 KB | None | 0 0
  1. DROP VIEW IF EXISTS coins_history;
  2.  
  3. CREATE VIEW `coins_history` AS
  4.  
  5. SELECT
  6.   t1.datum_request AS `date`,
  7.   t1.user_details AS `user_id`,
  8.   'charge' AS `scope`,
  9.   t2.coins AS `coins`,
  10.   t1.id
  11. FROM
  12.   cam_charge t1
  13.   INNER JOIN cam_chargeamounts t2
  14.     ON t2.id = t1.chargeamount
  15.  
  16. UNION SELECT
  17.   t1.datum_request,
  18.   t1.user_details,
  19.   'charge bounce',
  20.   - t2.coins,
  21.   t1.id
  22. FROM
  23.   cam_charge t1
  24.   INNER JOIN cam_chargeamounts t2
  25.     ON t2.id = t1.chargeamount
  26. WHERE
  27.   t1.bounced = 1
  28.  
  29. UNION SELECT
  30.   start,
  31.   user_details,
  32.   'visit-x chat',
  33.   - (coins_per_minute * videotime / 60),
  34.   id
  35. FROM
  36.   cam_call
  37. WHERE
  38.   videotime > 0
  39.   AND bill = 1
  40.  
  41.  
  42. UNION SELECT
  43.   t2.start AS date,
  44.   t1.user_details AS user_id,
  45.   'visit-x private chat' AS scope,
  46.   - (t2.duration / 60 * t2.coins_per_minute) AS coins,
  47.   t2.id AS id
  48.  
  49. FROM
  50.   cam_call t1
  51.   INNER JOIN cam_private_call t2
  52.     ON t2.paid_chat_id = t1.id
  53.  
  54. WHERE
  55.   t2.duration > 0
  56.  
  57.  
  58. UNION SELECT
  59.   start,
  60.   user_details,
  61.   'imlive chat',
  62.   - (videotime * coins_per_minute / 60),
  63.   id
  64. FROM
  65.   tbl_imlive_chat
  66. WHERE
  67.   videotime > 0
  68.  
  69. UNION SELECT
  70.   `date`,
  71.   user_id,
  72.   'video unlock',
  73.   - coinsprice,
  74.   id
  75. FROM
  76.   tbl_bought_video
  77. WHERE
  78.   coinsprice <> 0
  79.  
  80. UNION SELECT
  81.   `date`,
  82.   user_id,
  83.   'gallery unlock',
  84.   - coinsprice,
  85.   id
  86. FROM
  87.   tbl_bought_galleries
  88. WHERE
  89.   coinsprice <> 0
  90.  
  91. UNION SELECT
  92.   `date`,
  93.   user_id,
  94.   'camera mail',
  95.   - coins,
  96.   id
  97. FROM
  98.   cam_mails
  99. WHERE
  100.   coins <> 0
  101.  
  102. UNION SELECT
  103.   t1.`date`,
  104.   t1.user_id,
  105.   'tips',
  106.   - t1.coins,
  107.   t1.id
  108. FROM
  109.   tbl_playdate_tips t1
  110.   INNER JOIN tbl_playdate_poll_vote t2
  111.     ON t2.tip_id = t1.id
  112.   INNER JOIN tbl_playdate_poll_option t3
  113.     ON t3.id = t2.option_id
  114. WHERE
  115.   t3.is_winner = 1
  116.   AND t1.coins <> 0
  117.  
  118. UNION
  119. SELECT
  120.   purchase_date AS date,
  121.   user_id,
  122.   'playdate ticket',
  123.   - coins,
  124.   id
  125. FROM
  126.   tbl_playdate_ticket
  127.  
  128. UNION
  129. SELECT
  130.   bounced_date AS date,
  131.   user_id,
  132.   'playdate ticket bounce',
  133.   coins,
  134.   id
  135. FROM
  136.   tbl_playdate_ticket
  137. WHERE
  138.   bounced_date IS NOT NULL
  139.  
  140. UNION SELECT
  141.   t1.`date`,
  142.   t1.user_id,
  143.   'playdate tips',
  144.   - t1.coins,
  145.   id
  146. FROM
  147.   tbl_playdate_tips t1
  148. WHERE
  149.   t1.entity_type <> 'ErstiesPlaydate\\Models\\Poll'
  150.   AND t1.coins <> 0
  151.  
  152. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement