|
@@ -6,10 +6,13 @@
|
|
|
%% @end
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
|
|
--ifndef(NSM_ACCOUNTS).
|
|
|
--define(NSM_ACCOUNTS, true).
|
|
|
+-ifndef(ACCOUNTS_HRL).
|
|
|
+-define(ACCOUNTS_HRL, "accounts_hrl").
|
|
|
+
|
|
|
+-include_lib("kvs/include/kvs.hrl").
|
|
|
|
|
|
-type currency() :: kakaush | quota | game_point | money.
|
|
|
+
|
|
|
%% game events when points affected
|
|
|
-type game_event_type() :: round_start | round_end | game_start | game_end | tour_start.
|
|
|
-type tournament_type() :: standalone | elimination | pointing | lucky. %% FIXME: Copypasted from game_okey.hrl
|
|
@@ -23,80 +26,91 @@
|
|
|
|
|
|
%% common fields for all accounts
|
|
|
|
|
|
--record(account, {id :: account_id(),
|
|
|
- debet :: integer(),
|
|
|
- credit :: integer(),
|
|
|
- last_change :: integer() %% can be negative. Store last change
|
|
|
- %% to resolve conflicts just by applying
|
|
|
- %% all changes to one of the conflicting
|
|
|
-
|
|
|
- }).
|
|
|
+-record(account, {
|
|
|
+ ?ITERATOR(feed),
|
|
|
+ account_id :: account_id(),
|
|
|
+ debet :: integer(),
|
|
|
+ credit :: integer(),
|
|
|
+
|
|
|
+ %% can be negative. Store last change
|
|
|
+ %% to resolve conflicts just by applying
|
|
|
+ %% all changes to one of the conflicting
|
|
|
+ last_change :: integer()
|
|
|
+ }).
|
|
|
|
|
|
-define(ACC_ID(Account, Currency), {Account, Currency}). %% account id helper
|
|
|
|
|
|
-record(pointing_rule,
|
|
|
{
|
|
|
- id, %% {Game, GameType, Rounds} | {Game, GameType}
|
|
|
- game,
|
|
|
- game_type,
|
|
|
- rounds, %% rounds | points | undefined
|
|
|
- kakush_winner, %% kakush points will be assigned for the winner of the game.
|
|
|
- kakush_other, %% kakush points will be assigned for the rest of the
|
|
|
- %% players other then winner, per player.
|
|
|
- quota, %% quota, no of quota will be charged to players.
|
|
|
- game_points %% game points will be assigned at the end of the game
|
|
|
- %% to winner player
|
|
|
- }).
|
|
|
+ ?ITERATOR(feed),
|
|
|
+ pointing_rule_id, %% {Game, GameType, Rounds} | {Game, GameType}
|
|
|
+ game,
|
|
|
+ game_type,
|
|
|
+ rounds, %% rounds | points | undefined
|
|
|
+ kakush_winner, %% kakush points will be assigned for the winner of the game.
|
|
|
+ kakush_other, %% kakush points will be assigned for the rest of the
|
|
|
+
|
|
|
+ %% players other then winner, per player.
|
|
|
+ %% quota, no of quota will be charged to players.
|
|
|
+ quota,
|
|
|
+
|
|
|
+ %% game points will be assigned at the end of the game
|
|
|
+ %% to winner player
|
|
|
+ game_points
|
|
|
+ }
|
|
|
+ ).
|
|
|
|
|
|
%% Transaction info definitions. This records should be used as
|
|
|
%% values in #transaction.info. 'ti' prefix = 'transaction info'.
|
|
|
|
|
|
-record(ti_game_event,
|
|
|
{
|
|
|
- id :: integer(), %% GameId
|
|
|
- type :: game_event_type(),
|
|
|
- game_name :: game_name(),
|
|
|
- game_mode :: game_mode(),
|
|
|
- double_points :: integer(),
|
|
|
- tournament_type = standalone :: tournament_type()
|
|
|
- }).
|
|
|
+ id :: integer(), %% GameId
|
|
|
+ type :: game_event_type(),
|
|
|
+ game_name :: game_name(),
|
|
|
+ game_mode :: game_mode(),
|
|
|
+ double_points :: integer(),
|
|
|
+ tournament_type = standalone :: tournament_type()
|
|
|
+ }
|
|
|
+ ).
|
|
|
|
|
|
-record(ti_payment,
|
|
|
{
|
|
|
- id :: integer()
|
|
|
+ id :: integer()
|
|
|
}).
|
|
|
|
|
|
-record(ti_admin_change,
|
|
|
{
|
|
|
- reason :: binary()
|
|
|
- }).
|
|
|
+ reason :: binary()
|
|
|
+ }
|
|
|
+ ).
|
|
|
|
|
|
-record(ti_default_assignment,
|
|
|
{
|
|
|
|
|
|
- }).
|
|
|
+ }).
|
|
|
|
|
|
--type transaction_info() :: #ti_game_event{} | #ti_payment{} | #ti_admin_change{}|#ti_default_assignment{}.
|
|
|
+-type transaction_info() :: #ti_game_event{} | #ti_payment{} | #ti_admin_change{} | #ti_default_assignment{}.
|
|
|
|
|
|
-record(user_transaction, {user,top}).
|
|
|
|
|
|
-record(transaction,
|
|
|
{
|
|
|
- id :: transaction_id(),
|
|
|
- commit_time :: erlang:now(),
|
|
|
- amount :: integer(), %% amount to move between accounts
|
|
|
- remitter :: account_id(), %% accout that gives money/points
|
|
|
- acceptor :: account_id(), %% account receive money/points
|
|
|
- currency :: currency(), %% some of the points or money
|
|
|
- info :: transaction_info(),
|
|
|
- next,
|
|
|
- prev
|
|
|
- }).
|
|
|
+ id :: transaction_id(),
|
|
|
+ commit_time :: erlang:now(),
|
|
|
+ amount :: integer(), %% amount to move between accounts
|
|
|
+ remitter :: account_id(), %% accout that gives money/points
|
|
|
+ acceptor :: account_id(), %% account receive money/points
|
|
|
+ currency :: currency(), %% some of the points or money
|
|
|
+ info :: transaction_info(),
|
|
|
+ next,
|
|
|
+ prev
|
|
|
+ }).
|
|
|
|
|
|
%% Currencies
|
|
|
|
|
|
-define(CURRENCY_KAKUSH, kakush).
|
|
|
--define(CURRENCY_KAKUSH_CURRENCY, kakush_currency). % used for gifts section, charged only when user buy package
|
|
|
+-define(CURRENCY_KAKUSH_CURRENCY, kakush_currency). %% used for gifts section, charged only when user buy package
|
|
|
-define(CURRENCY_MONEY, money).
|
|
|
-define(CURRENCY_GAME_POINTS, game_point).
|
|
|
-define(CURRENCY_QUOTA, quota).
|