accounts.hrl 3.8 KB

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