accounts.hrl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. %%----------------------------------------------------------------------
  2. %% @author Vladimir Baranov <vladimir.b.n.b@gmail.com>
  3. %% @copyright Paynet Internet ve Bilisim Hizmetleri A.S. All Rights Reserved.
  4. %% @doc
  5. %% Definitions file for accounts and transactions related records and macroses
  6. %% @end
  7. %%--------------------------------------------------------------------
  8. -ifndef(ACCOUNTS_HRL).
  9. -define(ACCOUNTS_HRL, "accounts_hrl").
  10. -include_lib("kvs/include/kvs.hrl").
  11. -type currency() :: kakaush | quota | game_point | money.
  12. %% game events when points affected
  13. -type game_event_type() :: round_start | round_end | game_start | game_end | tour_start.
  14. -type tournament_type() :: standalone | elimination | pointing | lucky. %% FIXME: Copypasted from game_okey.hrl
  15. -type game_name() :: okey | tavla. %% TODO: add other game names
  16. -type game_mode() :: standard | evenodd | color | countdown | feellucky |
  17. esli | kakara. %% TODO: add other game types
  18. -type account_id() :: {string(), currency()}. %% {username, currency}.
  19. -type transaction_id() :: string().
  20. -define(SYSTEM_ACCOUNT_ID, system).
  21. %% common fields for all accounts
  22. -record(account, {
  23. ?ITERATOR(feed),
  24. account_id :: account_id(),
  25. debet :: integer(),
  26. credit :: integer(),
  27. %% can be negative. Store last change
  28. %% to resolve conflicts just by applying
  29. %% all changes to one of the conflicting
  30. last_change :: integer()
  31. }).
  32. -define(ACC_ID(Account, Currency), {Account, Currency}). %% account id helper
  33. -record(pointing_rule,
  34. {
  35. ?ITERATOR(feed),
  36. pointing_rule_id, %% {Game, GameType, Rounds} | {Game, GameType}
  37. game,
  38. game_type,
  39. rounds, %% rounds | points | undefined
  40. kakush_winner, %% kakush points will be assigned for the winner of the game.
  41. kakush_other, %% kakush points will be assigned for the rest of the
  42. %% players other then winner, per player.
  43. %% quota, no of quota will be charged to players.
  44. quota,
  45. %% game points will be assigned at the end of the game
  46. %% to winner player
  47. game_points
  48. }
  49. ).
  50. %% Transaction info definitions. This records should be used as
  51. %% values in #transaction.info. 'ti' prefix = 'transaction info'.
  52. -record(ti_game_event,
  53. {
  54. id :: integer(), %% GameId
  55. type :: game_event_type(),
  56. game_name :: game_name(),
  57. game_mode :: game_mode(),
  58. double_points :: integer(),
  59. tournament_type = standalone :: tournament_type()
  60. }
  61. ).
  62. -record(ti_payment,
  63. {
  64. id :: integer()
  65. }).
  66. -record(ti_admin_change,
  67. {
  68. reason :: binary()
  69. }
  70. ).
  71. -record(ti_default_assignment,
  72. {
  73. }).
  74. -type transaction_info() :: #ti_game_event{} | #ti_payment{} | #ti_admin_change{} | #ti_default_assignment{}.
  75. -record(user_transaction, {user,top}).
  76. -record(transaction,
  77. {
  78. id :: transaction_id(),
  79. commit_time :: erlang:now(),
  80. amount :: integer(), %% amount to move between accounts
  81. remitter :: account_id(), %% accout that gives money/points
  82. acceptor :: account_id(), %% account receive money/points
  83. currency :: currency(), %% some of the points or money
  84. info :: transaction_info(),
  85. next,
  86. prev
  87. }).
  88. %% Currencies
  89. -define(CURRENCY_KAKUSH, kakush).
  90. -define(CURRENCY_KAKUSH_CURRENCY, kakush_currency). %% used for gifts section, charged only when user buy package
  91. -define(CURRENCY_MONEY, money).
  92. -define(CURRENCY_GAME_POINTS, game_point).
  93. -define(CURRENCY_QUOTA, quota).
  94. -endif.