Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrMemberRequired = errors.New("bursary: require member") ErrMemberNotFound = errors.New("bursary: member not found") ErrUpstreamNotFound = errors.New("bursary: upstream not found") )
View Source
var DefaultRule = Rule{
Commission: 0.0,
Share: 0.0,
ReturnedShare: 0.0,
}
View Source
var (
ErrLedgerNotFound = errors.New("bursary: ledger not found")
)
Functions ¶
This section is empty.
Types ¶
type Bursary ¶
type Bursary interface {
RelationManager() RelationManager
LedgerManager() LedgerManager
GeneralLedger() Ledger
GetLevels(memberId string) ([]*Member, error)
CalculateRewards(t *Ticket) ([]*LedgerEntry, error)
WriteTicket(t *Ticket) error
WriteEntry(le *LedgerEntry) error
WriteEntries(ledgerName string, entries []*LedgerEntry) error
Close() error
}
func NewBursary ¶
type Condition ¶
type Condition struct {
Page int `json:"page"`
Limit int `json:"limit"`
TimeRange *TimeRange `json:"timeRange,omitempty"`
Sort []*SortField `json:"sort,omitempty"`
}
func NewCondition ¶
func NewCondition() *Condition
type Ledger ¶
type Ledger interface {
WriteRecords(entries []*LedgerEntry) error
ReadRecordsByMemberID(memberID string, cond *Condition) ([]*LedgerEntry, error)
}
func NewLedgerMemory ¶
func NewLedgerMemory() Ledger
type LedgerEntry ¶
type LedgerEntry struct {
ID string `json:"id"`
Channel string `json:"channel"`
Upstream string `json:"upstream"`
MemberID string `json:"member_id"`
Contributor string `json:"contributor"`
Expense int64 `json:"expense"`
Income int64 `json:"income"`
Amount int64 `json:"amount"` // income - expense
Fee int64 `json:"fee"` // original fee
Gain int64 `json:"gain"` // amount * (share + returned share by downstream)
Commissions int64 `json:"commissions"` // fee * commission share
Contributions int64 `json:"contributions"`
Total int64 `json:"total"` // profit + commissions
Desc string `json:"desc"`
Info map[string]interface{} `json:"info"`
PrimaryID string `json:"primary_id"`
IsPrimary bool `json:"is_primary"`
CreatedAt time.Time `json:"created_at"`
}
type LedgerManager ¶
type LedgerManager interface {
Add(name string, l Ledger) error
Get(name string) (Ledger, error)
Delete(name string) error
}
func NewLedgerManager ¶
func NewLedgerManager() LedgerManager
type Member ¶
type Member struct {
ID string `json:"id"`
ChannelRules map[string]*Rule `json:"channel_rules"`
RelationPath []string `json:"relation_path"`
Upstream string `json:"upstream"`
}
func (*Member) GetChannelRule ¶
type MemberEntry ¶
type MemberEntry struct {
ID string `json:"id"`
ChannelRules map[string]*Rule `json:"channel_rules"`
}
func NewMemberEntry ¶
func NewMemberEntry() *MemberEntry
type Opt ¶
type Opt func(*bursary)
func WithGeneralLedger ¶
func WithLedgerManager ¶
func WithLedgerManager(lm LedgerManager) Opt
func WithRelationManager ¶
func WithRelationManager(rm RelationManager) Opt
type RelationManager ¶
type RelationManager interface {
AddMembers(members []*MemberEntry, upstream string) error
ChangePath(mid string, newPath []string) error
DeleteMembers(mids []string) error
GetPath(mid string) ([]string, error)
GetMember(mid string) (*Member, error)
GetUpstreams(mid string) ([]*Member, error)
MoveMembers(mids []string, upstream string) error
ListMembers(upstream string, cond *Condition) ([]*Member, error)
UpdateChannelRule(mid string, channel string, rule *Rule) error
RemoveChannelRule(mid string, channel string) error
RemoveChannel(channel string) error
Close() error
}
func NewRelationManagerMemory ¶
func NewRelationManagerMemory() RelationManager
type Ticket ¶
type Ticket struct {
ID string `json:"id"`
Channel string `json:"channel"`
MemberID string `json:"member_id"`
Expense int64 `json:"expense"`
Income int64 `json:"income"`
Amount int64 `json:"amount"` // Amount = Income - Expense
Fee int64 `json:"fee"`
Total int64 `json:"total"` // Amount + Fee
Desc string `json:"desc"`
Info map[string]interface{} `json:"info"`
CreatedAt time.Time `json:"created_at"`
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.