affiliate

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 41 Imported by: 0

README

Arandu

Arandu Affiliate

An affiliate program for an Arandu application: a referral link per affiliate, a referral tree that is for life, commission plans of one to four levels, commissions paid into an arandu-wallet wallet the moment a referred user pays, and withdrawals an operator pays by PIX with the receipt attached.

How it works

  1. The link. Every affiliate has a code, and /r/{code} records the click, sets a cookie that carries the code for the plan's cookie days (30 by default), and lands the visitor — on ?to= when it is a path of the same site. A link opened later replaces the cookie.
  2. The sign-up. The application's sign-up reads the cookie (module.CodeFrom(r)) and calls Attribute. The user is then linked to that affiliate for life: no later cookie moves them. An affiliate cannot refer themselves, and one person — by user or by CPF/CNPJ — cannot appear twice in a tree.
  3. The payment. The application reports every payment of a user — the first purchase and every renewal — with RecordConversion. The package walks up the tree from the buyer and pays each level the rate of the plan in force: level one is the buyer's referrer, level two the referrer's referrer, up to four. A blocked affiliate's level is skipped; the levels above still earn. The commission is deposited at once — no waiting period — and stays in the wallet until withdrawn.
  4. The refund. RecordRefund reverses every commission of the payment. The money leaves the wallet even past zero: a commission already withdrawn leaves the balance negative, which closes withdrawals until later commissions cover it, or the admin forgives the rest with a recorded write-off.
  5. The withdrawal. The affiliate declares a payout account — PIX, bank, crypto or another kind — always in the name and document of their registration, and asks for any amount between the plan's minimum and maximum (R$ 100,00 minimum by default), at most once a day. arandu-wallet holds the amount; the operator takes the request, pays it outside the system and attaches the end-to-end identifier and the receipt, or rejects it with a reason, which frees the day.

Money is int64 centavos and rates are basis points (150 = 1,5%).

Install

It needs arandu-wallet v0.13.0 or newer, whose wallets take withdrawal requests only through the package that manages them:

go get github.com/hyz-is/arandu-wallet@v0.13.0
go get github.com/hyz-is/arandu-affiliate

Wire it

An Arandu application registers a module explicitly, in bootstrap/app.go.

import (
	affiliate "github.com/hyz-is/arandu-affiliate"
)

In Build, after the session store and the wallet module exist:

	affiliateModule, err := affiliate.New(affiliate.Config{
		Tenant:       "acme",                   // the customer a visitor with no session is read as
		Wallet:       walletModule.Service(),   // the one arandu-wallet instance
		SecureCookie: cfg.App.Env == "production",
	}, db, sessions)
	if err != nil {
		return App{}, err
	}

and affiliateModule, inside k.Register(...). Then, once:

aru migrate

The package owns eight tables; arandu.mod.toml says migrations = true.

In the sign-up
	referral, err := affiliateModule.Service().Attribute(ctx, security.Guest(tenant), affiliate.AttributeRequest{
		UserID:   newUser.ID,
		Code:     affiliateModule.CodeFrom(r),
		Document: newUser.Document, // optional; guards the tree by CPF/CNPJ too
	})

A refusal is a validation.Errors the sign-up may ignore: the user is created either way, without a referrer.

Where payments are confirmed
	_, _, err := affiliateModule.Service().RecordConversion(ctx, operator, affiliate.ConversionRequest{
		OrderRef: "mp:" + payment.ID, BuyerUserID: payment.UserID, ProductID: "placaflow",
		Amount: 19900, Renewal: payment.IsRenewal, OccurredAt: payment.ApprovedAt,
	})
	// and when it is given back:
	_, err = affiliateModule.Service().RecordRefund(ctx, operator, "mp:"+payment.ID, "chargeback")

Both are idempotent by the order reference. operator is a subject with the roles below.

Give people access

Roles reach the policy through the Subject, which arandu-permission fills:

role what it opens
affiliate.admin plans, affiliates, the tree, blocking, commissions and their reversal, write-offs, the withdrawal queue, recording payments
wallet.operator arandu-wallet's operator actions; whoever records payments or pays withdrawals needs it too

An affiliate needs no role: the user whose user_id is on an affiliate's registration reads that panel and nobody else's. A visitor may only record a click and a referral. The tenant of every statement is the Grant's.

Screens

Six, in pt-BR and English, on Kyse components and components.DataTable: the affiliate's panel — link with a copy button, the plan in force, the period's clicks, sign-ups, sales and commissions, the balance, the withdrawal form, the payout account, the commissions filtered by level and status and paged on the server, the withdrawals with their receipts — and the admin's plans, affiliates (paged, searched, filtered on the server), one affiliate with the tree and the write-off, the commissions with manual reversal, and the withdrawal queue. Every GET answers the screen to a browser and JSON to a client that asks for it.

Publish the views

aru vendor:publish --tag=view --apply
aru view:build

and import the two directories aru view:build writes:

	_ "your/module/path/storage/framework/views/modules/affiliate"
	_ "your/module/path/storage/framework/views/modules/affiliate/admin"

The module refuses to boot until they are linked. The sentences come from resources/lang/<locale>/affiliate.json; the application's own catalogue, passed as Config.Translator, is asked first, key by key.

Configuration

field required meaning
Tenant yes the customer a visitor with no session is read as on /r/{code}.
Wallet yes arandu-wallet's service. The package keeps no balance of its own.
Prefix no where the panels are mounted. Defaults to /affiliate.
ReferralPath no where the link answers. Defaults to /r.
LandingPath no where the link lands without ?to=. Defaults to /.
CookieName no the referral cookie. Defaults to affiliate_ref.
SecureCookie no marks the cookie Secure; on in production.
PageSize no rows per page. Defaults to 25, refused above 200.
Location no the timezone days are counted in. Defaults to America/Sao_Paulo.
Translator no the application's catalogue, asked first.

Routes

GET /r/{code} is public. Every other route sits behind RequireAuth: a visitor with no session is sent to /auth/login, and a handler reads who is asking with ctx.User().

method path what
GET /r/{code} the referral link
GET /affiliate/me the affiliate's panel
POST /affiliate/me/payout-accounts declare a payout account
POST /affiliate/me/withdrawals ask for a withdrawal
GET /affiliate/withdrawals/{id}/receipt the receipt of a paid withdrawal
GET, POST /affiliate/admin/plans the plans, define one
POST /affiliate/admin/plans/{id}/activation make a plan the one in force
GET, POST /affiliate/admin/affiliates the affiliates, register one
GET /affiliate/admin/affiliates/{id} one affiliate, with the tree
POST, DELETE /affiliate/admin/affiliates/{id}/block block, unblock
POST /affiliate/admin/affiliates/{id}/write-off forgive a negative balance
GET /affiliate/admin/commissions every commission
POST /affiliate/admin/commissions/{id}/reversal reverse a commission
POST /affiliate/admin/conversions record a payment
POST /affiliate/admin/refunds record a refund
GET /affiliate/admin/withdrawals the withdrawal queue
POST /affiliate/admin/withdrawals/{id}/processing, /payment, /rejection take, pay (multipart, with the receipt), reject

The data path

Each entity embeds model.Model and declares its table beside it. aru model:build generates the queries — AffiliateQuery.go with Affiliates(db), and one per entity — committed and never edited by hand; aru model:build --check fails when one is out of date.

AffiliateService owns *data.DB and follows validate -> security.Authorize -> Grant -> Model terminal in every exported method, which the unit suite audits. Every query reads the tenant from the Grant through data.Tenant(g).

Tests

GOWORK=off go test ./... -race

The unit suite audits the data path, holds the policy and the calculation, and builds every published view with the view compiler an application uses — then renders each screen with sample data. The feature suite runs the link, the lifelong referral, renewals, every level, refunds below zero, the write-off, one withdrawal a day under eight concurrent requests, the limits, and tenant isolation against SQLite with arandu-wallet beside it.

Licence

MIT. See LICENSE.md.

Documentation

Overview

Package affiliate is an Arandu module for an affiliate program: referral links, a referral tree that is for life, commission plans of one to four levels, commissions paid into arandu-wallet the moment a referred user pays, and withdrawals by request.

The files are laid out by role rather than by layer, so the whole package reads top to bottom:

module.go               -> registration, routes, handlers and migrations
config.go               -> what the application passes in
model.go                -> the entities
policy.go               -> who may do what
service.go              -> the affiliates
plan_service.go         -> the commission plans
referral_service.go     -> the link, the referral and the tree
commission_service.go   -> payments, commissions, reversals
withdrawal_service.go   -> balance, payout accounts and withdrawals
screens.go, views.go    -> what the screens show, and the files published

An application registers it explicitly. There is no service provider, no container and no discovery.

Index

Constants

View Source
const (
	// DefaultPrefix is where the panels are mounted when Config leaves Prefix
	// empty.
	DefaultPrefix = "/affiliate"
	// DefaultReferralPath is where the referral link answers: /r/{code}.
	DefaultReferralPath = "/r"
	// DefaultCookieName is the cookie the link sets and the sign-up reads.
	DefaultCookieName = "affiliate_ref"
	// DefaultCookieDays is how long the cookie lives when no plan is active.
	DefaultCookieDays = 30
	// DefaultMinWithdrawal is the smallest withdrawal, in centavos, when no
	// plan is active: R$ 100,00.
	DefaultMinWithdrawal = 10000
	// DefaultPageSize is how many rows one page answers with.
	DefaultPageSize = 25
	// MaxPageSize is the most a page may be configured to answer with.
	MaxPageSize = 200
)
View Source
const (
	// DashboardView is an affiliate reading their own panel: the link, the
	// plan, the numbers, the commissions, the balance and the withdrawals --
	// and asking for a withdrawal or declaring a payout account of their own.
	DashboardView security.Action = "affiliate.dashboard.view"
	// PlansManage is defining the commission plans.
	PlansManage security.Action = "affiliate.plans.manage"
	// AffiliatesManage is the admin's side of the program: the affiliates, the
	// tree, blocking, the commissions and their reversal, the write-off of a
	// negative balance, the queue of withdrawals, and recording the payments
	// the commissions are paid on.
	AffiliatesManage security.Action = "affiliate.affiliates.manage"
	// ReferralRecord is recording what a visitor did with a referral link: the
	// click on /r/{code}, and the referral of the user who signed up with it.
	// The visitor has no session; the application's sign-up is the caller.
	ReferralRecord security.Action = "affiliate.referrals.record"
)

The actions of the affiliate program. Constants rather than strings at the call site: a typo in an action name would silently authorize nothing, or worse, everything.

View Source
const (
	// TranslationGroup is the file every key of this package lives in, and the
	// prefix of every key: "affiliate.screen.dashboard_title".
	TranslationGroup = "affiliate"
	// FallbackLocale answers a request that negotiated no locale. The package
	// is Brazilian first.
	FallbackLocale = "pt-BR"
)
View Source
const (
	ViewDashboard        = "modules.affiliate.dashboard"
	ViewAdminPlans       = "modules.affiliate.admin.plans"
	ViewAdminAffiliates  = "modules.affiliate.admin.affiliates"
	ViewAdminAffiliate   = "modules.affiliate.admin.affiliate"
	ViewAdminCommissions = "modules.affiliate.admin.commissions"
	ViewAdminWithdrawals = "modules.affiliate.admin.withdrawals"
)

The screens this package renders, by the name their path gives them.

View Source
const AdminRole = "affiliate.admin"

AdminRole is the role that runs the program in its tenant. The application gives it through arandu-permission, which fills the Subject's roles.

View Source
const DayLayout = "2006-01-02"

DayLayout is how a Day is written.

View Source
const DefaultLocation = "America/Sao_Paulo"

DefaultLocation is the timezone days are counted in when Config leaves Location nil.

View Source
const MaxLevels = 4

MaxLevels is the deepest level a plan pays.

View Source
const PayoutVia = "affiliate"

PayoutVia is the name this package asks for its affiliates' withdrawals under, and the one their wallets are opened with: arandu-wallet refuses a request for those wallets that does not carry it, so the minimum, the maximum and one request a day cannot be stepped around.

View Source
const PublishCommand = "aru vendor:publish --apply"

PublishCommand is what an application runs to take ownership of the views.

View Source
const WalletSlug = "affiliate"

WalletSlug is the slug of the affiliate's wallet in arandu-wallet.

Variables

View Source
var (
	// ErrSelfReferral is an affiliate signing up with their own code.
	ErrSelfReferral = validation.Errors{"code": {"an affiliate cannot refer themselves"}}
	// ErrSameTree is a document, or a user, already in the referrer's tree.
	ErrSameTree = validation.Errors{"document": {"this person is already in the referrer's tree"}}
	// ErrDocumentReferred is a document another referral already carries.
	ErrDocumentReferred = validation.Errors{"document": {"this document was already referred"}}
)

The refusals of a referral, each a reason the sign-up keeps going without one. They are validation errors: the application decides whether to tell the person.

View Source
var (
	// ErrOnePerDay is a second withdrawal on a day that already has one.
	ErrOnePerDay = validation.Errors{"amount": {"one withdrawal a day; ask again tomorrow"}}
	// ErrNegativeBalance is a withdrawal while a reversed commission left the
	// balance below zero.
	ErrNegativeBalance = validation.Errors{"amount": {"the balance is below zero after a reversed commission; withdrawals open again once it is covered"}}
	// ErrBlocked is a blocked affiliate asking for money.
	ErrBlocked = forbidden("affiliate: a blocked affiliate cannot withdraw")
)

The refusals of a withdrawal.

View Source
var ErrNotFound = fmt.Errorf("affiliate: record not found: %w", model.ErrModelNotFound)

ErrNotFound is a record the caller may not see or that does not exist. It wraps model.ErrModelNotFound, which the router answers with 404.

View Source
var ErrTaken = validation.Errors{"code": {"the user, the document or the code is already an affiliate's"}}

ErrTaken is a user, a document or a code that already belongs to an affiliate of the tenant.

View Source
var PayoutKindNames = []string{"pix", "bank", "crypto", "other"}

PayoutKindNames are PayoutKinds' keys in the order a form lists them.

View Source
var PayoutKinds = map[string][]string{
	"pix":    {"key_type", "key"},
	"bank":   {"bank", "agency", "account", "account_type"},
	"crypto": {"network", "address"},
	"other":  {"description"},
}

PayoutKinds are the kinds of account an affiliate can be paid into, and the details each one takes.

Functions

func CommissionOf

func CommissionOf(amount, rateBps int64) int64

CommissionOf is what a rate in basis points pays on an amount in centavos, rounded half up to the centavo.

func Locales

func Locales() []string

Locales are the languages the package ships.

func PublishedPaths

func PublishedPaths() []string

PublishedPaths are the files in the archive, each relative to the root of the application, sorted.

func ViewNames

func ViewNames() []string

ViewNames are the names the published views are rendered by, sorted.

The name is the path under the view root with its separators turned into dots, which is what the view compiler writes into the registration call. It is derived from the same archive the publication carries, so a view that was renamed cannot keep an old name here.

func ViewPackages

func ViewPackages() []string

ViewPackages are the directories the compiled views land in, each relative to the root of the application, sorted and without repeats.

Importing one is what puts its views in the binary: a compiled view calls the registry from init(), and a package nothing imports is not linked at all. The import is named rather than written into bootstrap/app.go, because one line somebody reads beats a file that changed while they were not looking.

Types

type AccountOption

type AccountOption struct{ ID, Label string }

AccountOption is one payout account a withdrawal can be paid into.

type AccountRequest

type AccountRequest struct {
	Kind    string
	Label   string
	Details map[string]string
}

AccountRequest is a payout account an affiliate declares.

type AdminAffiliatePageData

type AdminAffiliatePageData struct {
	Screen
	Affiliate                             AffiliateRow
	Link                                  string
	Balance, Held, Available              string
	Negative                              bool
	Clicks, Signups, Sales                int64
	Commissions                           string
	Tree                                  []TreeRow
	BlockURL, WriteOffURL, CommissionsURL string
}

AdminAffiliatePageData is one affiliate, for the admin.

type AdminAffiliatesPageData

type AdminAffiliatesPageData struct {
	Screen
	Rows     []AffiliateRow
	Status   string
	Table    TableState
	StoreURL string
}

AdminAffiliatesPageData is the admin's list of affiliates.

type AdminCommissionsPageData

type AdminCommissionsPageData struct {
	Screen
	Rows          []CommissionRow
	Level, Status string
	AffiliateID   string
	Table         TableState
}

AdminCommissionsPageData is every commission, for the admin.

type AdminPlansPageData

type AdminPlansPageData struct {
	Screen
	Plans    []PlanRow
	StoreURL string
}

AdminPlansPageData is the plans, for the admin.

type AdminWithdrawalsPageData

type AdminWithdrawalsPageData struct {
	Screen
	Rows   []WithdrawalRow
	Status string
	URL    string
}

AdminWithdrawalsPageData is the queue of affiliates' withdrawals.

type Affiliate

type Affiliate struct {
	model.Model

	ID       string `db:"id"`
	TenantID string `db:"tenant_id"`

	// UserID is the login user who signs in to the panel, unique per tenant.
	UserID string `db:"user_id"`

	// Code is what the referral link carries, unique per tenant.
	Code string `db:"code"`

	// Document is the CPF or the CNPJ, digits only, unique per tenant.
	Document string `db:"document"`

	// Name is how the affiliate is called on the screens and on a payout.
	Name string `db:"name"`

	// Status is whether the affiliate earns and withdraws. A blocked
	// affiliate keeps their history and their place in the tree; their level
	// is skipped when a commission is paid, and the levels above them still
	// earn.
	Status AffiliateStatus `db:"status"`

	CreatedBy string    `db:"created_by"`
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

Affiliate is somebody who refers people to the application and earns a commission on every payment those people make, and on the payments of the people they referred in turn, up to the levels the plan pays.

An affiliate is a login user with a code. The code is what the referral link carries -- /r/{code} -- and it is unique in its tenant. The document is the affiliate's CPF or CNPJ: it is what keeps one person from appearing twice in a referral tree, and the name every payout account of theirs has to be in.

func (*Affiliate) Fresh

func (row *Affiliate) Fresh(ctx context.Context, g auth.Grant, with ...string) (*Affiliate, error)

Fresh reads the row again, as a new Affiliate; it shadows the untyped one the embedded model promotes.

func (Affiliate) IsActive

func (a Affiliate) IsActive() bool

IsActive reports whether the affiliate earns and withdraws.

func (*Affiliate) Replicate

func (row *Affiliate) Replicate(except ...string) (*Affiliate, error)

Replicate returns an unsaved copy of the row without its key; it shadows the untyped one the embedded model promotes.

type AffiliateCollection

type AffiliateCollection []*Affiliate

AffiliateCollection is rows of Affiliate, as a query returns them.

func AffiliateCollectionOf

func AffiliateCollectionOf(rows model.Rows) AffiliateCollection

AffiliateCollectionOf converts rows of the table of Affiliate. A nil input is a nil collection.

func (AffiliateCollection) Contains

func (c AffiliateCollection) Contains(key any) bool

func (AffiliateCollection) Except

func (c AffiliateCollection) Except(keys ...any) AffiliateCollection

func (AffiliateCollection) Find

func (c AffiliateCollection) Find(key any) *Affiliate

func (AffiliateCollection) FindOrFail

func (c AffiliateCollection) FindOrFail(key any) (*Affiliate, error)

func (AffiliateCollection) Fresh

func (AffiliateCollection) Load

func (c AffiliateCollection) Load(ctx context.Context, g auth.Grant, relations ...string) error

func (AffiliateCollection) LoadCount

func (c AffiliateCollection) LoadCount(ctx context.Context, g auth.Grant, relations ...string) error

func (AffiliateCollection) LoadMissing

func (c AffiliateCollection) LoadMissing(ctx context.Context, g auth.Grant, relations ...string) error

func (AffiliateCollection) ModelKeys

func (c AffiliateCollection) ModelKeys() []any

func (AffiliateCollection) Only

func (AffiliateCollection) Pluck

func (c AffiliateCollection) Pluck(column string) []any

func (AffiliateCollection) Rows

func (c AffiliateCollection) Rows() model.Rows

Rows converts the collection back to the core's rows.

func (AffiliateCollection) ToArray

func (c AffiliateCollection) ToArray() []map[string]any

func (AffiliateCollection) Unique

type AffiliatePolicy

type AffiliatePolicy struct{}

AffiliatePolicy is the only authority over who does what in the program.

It denies unless a rule below allows. The admin role manages the program in its own tenant; an affiliate reads only their own row; a visitor -- with or without a session -- may record a click and a referral and nothing else.

func (AffiliatePolicy) Can

Can decides whether the subject may perform the action on the record.

It is the only place that decides. The service reaches the Model only after Authorize turns this method's nil result into a Grant.

type AffiliateQuery

type AffiliateQuery struct {
	// contains filtered or unexported fields
}

AffiliateQuery is a query on the table of Affiliate.

The methods that build return the query, so they chain. The methods that run take a context and an auth.Grant, and return Affiliate rows or a value; there is no way to run one without a Grant.

func Affiliates

func Affiliates(db model.DB) *AffiliateQuery

Affiliates starts a query on the table of Affiliate, through db.

Global scopes are on and, unless the table is Global, every statement is filtered by the tenant of the Grant its terminal takes.

func (*AffiliateQuery) AddSelect

func (q *AffiliateQuery) AddSelect(columns ...any) *AffiliateQuery

func (*AffiliateQuery) Avg

func (q *AffiliateQuery) Avg(ctx context.Context, g auth.Grant, column any) (any, error)

func (*AffiliateQuery) Base

func (q *AffiliateQuery) Base() *model.Builder

Base returns the core builder the query forwards to. It is for code in this package -- a local scope in the custom block of model.go -- and for the factory, which builds rows through it.

func (*AffiliateQuery) Chunk

func (q *AffiliateQuery) Chunk(ctx context.Context, g auth.Grant, count int, callback func(AffiliateCollection, int) (bool, error)) error

func (*AffiliateQuery) Clone

func (q *AffiliateQuery) Clone() *AffiliateQuery

Clone returns an independent copy of the query.

func (*AffiliateQuery) Count

func (q *AffiliateQuery) Count(ctx context.Context, g auth.Grant, columns ...any) (int64, error)

func (*AffiliateQuery) Create

func (q *AffiliateQuery) Create(ctx context.Context, g auth.Grant, attributes map[string]any) (*Affiliate, error)

func (*AffiliateQuery) Cursor

func (*AffiliateQuery) CursorPaginate

func (q *AffiliateQuery) CursorPaginate(ctx context.Context, g auth.Grant, perPage int, cursor *pagination.Cursor, opts pagination.Options, columns ...any) (AffiliateCollection, *pagination.CursorPage, error)

func (*AffiliateQuery) Decrement

func (q *AffiliateQuery) Decrement(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*AffiliateQuery) Delete

func (q *AffiliateQuery) Delete(ctx context.Context, g auth.Grant) (int64, error)

func (*AffiliateQuery) DoesntExist

func (q *AffiliateQuery) DoesntExist(ctx context.Context, g auth.Grant) (bool, error)

func (*AffiliateQuery) DoesntHave

func (q *AffiliateQuery) DoesntHave(relation, boolean string, callback func(*query.Builder)) *AffiliateQuery

func (*AffiliateQuery) Each

func (q *AffiliateQuery) Each(ctx context.Context, g auth.Grant, count int, callback func(*Affiliate, int) (bool, error)) error

func (*AffiliateQuery) Exists

func (q *AffiliateQuery) Exists(ctx context.Context, g auth.Grant) (bool, error)

func (*AffiliateQuery) Find

func (q *AffiliateQuery) Find(ctx context.Context, g auth.Grant, id any, columns ...any) (*Affiliate, error)

func (*AffiliateQuery) FindMany

func (q *AffiliateQuery) FindMany(ctx context.Context, g auth.Grant, ids []any, columns ...any) (AffiliateCollection, error)

func (*AffiliateQuery) FindOrFail

func (q *AffiliateQuery) FindOrFail(ctx context.Context, g auth.Grant, id any, columns ...any) (*Affiliate, error)

func (*AffiliateQuery) FindOrNew

func (q *AffiliateQuery) FindOrNew(ctx context.Context, g auth.Grant, id any, columns ...any) (*Affiliate, error)

func (*AffiliateQuery) First

func (q *AffiliateQuery) First(ctx context.Context, g auth.Grant, columns ...any) (*Affiliate, error)

First returns the first row, or nil and no error when there is none.

func (*AffiliateQuery) FirstOrCreate

func (q *AffiliateQuery) FirstOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Affiliate, error)

func (*AffiliateQuery) FirstOrFail

func (q *AffiliateQuery) FirstOrFail(ctx context.Context, g auth.Grant, columns ...any) (*Affiliate, error)

func (*AffiliateQuery) FirstOrNew

func (q *AffiliateQuery) FirstOrNew(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Affiliate, error)

func (*AffiliateQuery) FirstWhere

func (q *AffiliateQuery) FirstWhere(ctx context.Context, g auth.Grant, column any, args ...any) (*Affiliate, error)

func (*AffiliateQuery) ForPage

func (q *AffiliateQuery) ForPage(page, perPage int) *AffiliateQuery

func (*AffiliateQuery) ForceCreate

func (q *AffiliateQuery) ForceCreate(ctx context.Context, g auth.Grant, attributes map[string]any) (*Affiliate, error)

func (*AffiliateQuery) Get

func (q *AffiliateQuery) Get(ctx context.Context, g auth.Grant, columns ...any) (AffiliateCollection, error)

Get runs the query and returns the rows.

func (*AffiliateQuery) GroupBy

func (q *AffiliateQuery) GroupBy(groups ...any) *AffiliateQuery

func (*AffiliateQuery) Has

func (q *AffiliateQuery) Has(relation, operator string, count int, boolean string, callback func(*query.Builder)) *AffiliateQuery

func (*AffiliateQuery) Increment

func (q *AffiliateQuery) Increment(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*AffiliateQuery) Insert

func (q *AffiliateQuery) Insert(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*AffiliateQuery) InsertOrIgnore

func (q *AffiliateQuery) InsertOrIgnore(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*AffiliateQuery) Join

func (q *AffiliateQuery) Join(table any, first any, args ...any) *AffiliateQuery

func (*AffiliateQuery) Latest

func (q *AffiliateQuery) Latest(column ...string) *AffiliateQuery

func (*AffiliateQuery) Limit

func (q *AffiliateQuery) Limit(value int) *AffiliateQuery

func (*AffiliateQuery) Max

func (q *AffiliateQuery) Max(ctx context.Context, g auth.Grant, column any) (any, error)

func (*AffiliateQuery) Min

func (q *AffiliateQuery) Min(ctx context.Context, g auth.Grant, column any) (any, error)

func (*AffiliateQuery) New

func (q *AffiliateQuery) New() (*Affiliate, error)

New returns an empty Affiliate on the query's connection, not yet saved, filled with what WithAttributes recorded on the query.

func (*AffiliateQuery) Offset

func (q *AffiliateQuery) Offset(value int) *AffiliateQuery

func (*AffiliateQuery) Oldest

func (q *AffiliateQuery) Oldest(column ...string) *AffiliateQuery

func (*AffiliateQuery) OrDoesntHave

func (q *AffiliateQuery) OrDoesntHave(relation string) *AffiliateQuery

func (*AffiliateQuery) OrHas

func (q *AffiliateQuery) OrHas(relation, operator string, count int) *AffiliateQuery

func (*AffiliateQuery) OrWhere

func (q *AffiliateQuery) OrWhere(column any, args ...any) *AffiliateQuery

OrWhere adds an or-where clause; a func(*AffiliateQuery) in place of the column adds a group.

func (*AffiliateQuery) OrWhereDoesntHave

func (q *AffiliateQuery) OrWhereDoesntHave(relation string, callback func(*query.Builder)) *AffiliateQuery

func (*AffiliateQuery) OrWhereHas

func (q *AffiliateQuery) OrWhereHas(relation string, callback func(*query.Builder)) *AffiliateQuery

func (*AffiliateQuery) OrWhereNot

func (q *AffiliateQuery) OrWhereNot(column any, args ...any) *AffiliateQuery

OrWhereNot adds an or-joined negated where clause, or a negated group.

func (*AffiliateQuery) OrWhereRelation

func (q *AffiliateQuery) OrWhereRelation(relation string, column any, args ...any) *AffiliateQuery

func (*AffiliateQuery) OrderBy

func (q *AffiliateQuery) OrderBy(column any, direction ...string) *AffiliateQuery

func (*AffiliateQuery) OrderByDesc

func (q *AffiliateQuery) OrderByDesc(column any) *AffiliateQuery

func (*AffiliateQuery) Paginate

func (q *AffiliateQuery) Paginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (AffiliateCollection, *pagination.LengthAwarePage, error)

func (*AffiliateQuery) Pluck

func (q *AffiliateQuery) Pluck(ctx context.Context, g auth.Grant, column string) ([]any, error)

func (*AffiliateQuery) Select

func (q *AffiliateQuery) Select(columns ...any) *AffiliateQuery

func (*AffiliateQuery) SelectRaw

func (q *AffiliateQuery) SelectRaw(expression string, bindings ...any) *AffiliateQuery

func (*AffiliateQuery) SimplePaginate

func (q *AffiliateQuery) SimplePaginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (AffiliateCollection, *pagination.Page, error)

func (*AffiliateQuery) Sole

func (q *AffiliateQuery) Sole(ctx context.Context, g auth.Grant, columns ...any) (*Affiliate, error)

func (*AffiliateQuery) SoleValue

func (q *AffiliateQuery) SoleValue(ctx context.Context, g auth.Grant, column string) (any, error)

func (*AffiliateQuery) Sum

func (q *AffiliateQuery) Sum(ctx context.Context, g auth.Grant, column any) (any, error)

func (*AffiliateQuery) Touch

func (q *AffiliateQuery) Touch(ctx context.Context, g auth.Grant, column ...string) (int64, error)

func (*AffiliateQuery) Update

func (q *AffiliateQuery) Update(ctx context.Context, g auth.Grant, values map[string]any) (int64, error)

func (*AffiliateQuery) UpdateOrCreate

func (q *AffiliateQuery) UpdateOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Affiliate, error)

func (*AffiliateQuery) Upsert

func (q *AffiliateQuery) Upsert(ctx context.Context, g auth.Grant, values []map[string]any, uniqueBy, update []string) (int64, error)

func (*AffiliateQuery) Value

func (q *AffiliateQuery) Value(ctx context.Context, g auth.Grant, column string) (any, error)

func (*AffiliateQuery) ValueOrFail

func (q *AffiliateQuery) ValueOrFail(ctx context.Context, g auth.Grant, column string) (any, error)

func (*AffiliateQuery) Where

func (q *AffiliateQuery) Where(column any, args ...any) *AffiliateQuery

Where adds a where clause; a func(*AffiliateQuery) in place of the column adds a group.

func (*AffiliateQuery) WhereBelongsTo

func (q *AffiliateQuery) WhereBelongsTo(relationshipName string, related ...model.Entity) *AffiliateQuery

func (*AffiliateQuery) WhereBetween

func (q *AffiliateQuery) WhereBetween(column any, from, to any) *AffiliateQuery

func (*AffiliateQuery) WhereColumn

func (q *AffiliateQuery) WhereColumn(first any, args ...any) *AffiliateQuery

func (*AffiliateQuery) WhereDoesntHave

func (q *AffiliateQuery) WhereDoesntHave(relation string, callback func(*query.Builder)) *AffiliateQuery

func (*AffiliateQuery) WhereExists

func (q *AffiliateQuery) WhereExists(callback func(*query.Builder)) *AffiliateQuery

func (*AffiliateQuery) WhereHas

func (q *AffiliateQuery) WhereHas(relation string, callback func(*query.Builder)) *AffiliateQuery

func (*AffiliateQuery) WhereHasCount

func (q *AffiliateQuery) WhereHasCount(relation string, callback func(*query.Builder), operator string, count int) *AffiliateQuery

func (*AffiliateQuery) WhereIn

func (q *AffiliateQuery) WhereIn(column any, values []any) *AffiliateQuery

func (*AffiliateQuery) WhereKey

func (q *AffiliateQuery) WhereKey(id any) *AffiliateQuery

func (*AffiliateQuery) WhereNot

func (q *AffiliateQuery) WhereNot(column any, args ...any) *AffiliateQuery

WhereNot adds a negated where clause, or a negated group.

func (*AffiliateQuery) WhereNotExists

func (q *AffiliateQuery) WhereNotExists(callback func(*query.Builder)) *AffiliateQuery

func (*AffiliateQuery) WhereNotIn

func (q *AffiliateQuery) WhereNotIn(column any, values []any) *AffiliateQuery

func (*AffiliateQuery) WhereNotNull

func (q *AffiliateQuery) WhereNotNull(columns ...any) *AffiliateQuery

func (*AffiliateQuery) WhereNull

func (q *AffiliateQuery) WhereNull(columns ...any) *AffiliateQuery

func (*AffiliateQuery) WhereRelation

func (q *AffiliateQuery) WhereRelation(relation string, column any, args ...any) *AffiliateQuery

func (*AffiliateQuery) With

func (q *AffiliateQuery) With(relations ...string) *AffiliateQuery

func (*AffiliateQuery) WithAvg

func (q *AffiliateQuery) WithAvg(relation, column string) *AffiliateQuery

func (*AffiliateQuery) WithCount

func (q *AffiliateQuery) WithCount(relations ...string) *AffiliateQuery

func (*AffiliateQuery) WithExists

func (q *AffiliateQuery) WithExists(relation string) *AffiliateQuery

func (*AffiliateQuery) WithMax

func (q *AffiliateQuery) WithMax(relation, column string) *AffiliateQuery

func (*AffiliateQuery) WithMin

func (q *AffiliateQuery) WithMin(relation, column string) *AffiliateQuery

func (*AffiliateQuery) WithSum

func (q *AffiliateQuery) WithSum(relation, column string) *AffiliateQuery

func (*AffiliateQuery) Without

func (q *AffiliateQuery) Without(relations ...string) *AffiliateQuery

func (*AffiliateQuery) WithoutGlobalScope

func (q *AffiliateQuery) WithoutGlobalScope(identifier string) *AffiliateQuery

func (*AffiliateQuery) WithoutGlobalScopes

func (q *AffiliateQuery) WithoutGlobalScopes(identifiers ...string) *AffiliateQuery

type AffiliateRow

type AffiliateRow struct {
	ID, Name, Code, Document, User, Status, StatusKey, Created, URL string
	Active                                                          bool
}

AffiliateRow is one affiliate in the admin's list.

type AffiliateService

type AffiliateService struct {
	// contains filtered or unexported fields
}

AffiliateService is the program's use cases. It owns the database handle; every exported method asks the policy before it reads or writes, and every statement carries the tenant of the Grant the policy issued.

func NewAffiliateService

func NewAffiliateService(db *data.DB) *AffiliateService

NewAffiliateService returns the use cases over a database handle. New wires the rest; a test may build one directly.

func (*AffiliateService) ActivatePlan

func (s *AffiliateService) ActivatePlan(ctx context.Context, actor security.Subject, id string) (*PlanView, error)

ActivatePlan makes a plan the one new conversions are paid by.

func (*AffiliateService) ActivePlan

func (s *AffiliateService) ActivePlan(ctx context.Context, actor security.Subject) (*PlanView, error)

ActivePlan is the plan in force, for anybody who reads a panel: an affiliate consults it, never changes it. Nil when no plan is active.

func (*AffiliateService) AddPayoutAccount

func (s *AffiliateService) AddPayoutAccount(ctx context.Context, actor security.Subject, in AccountRequest) (*wallet.PayoutAccount, error)

AddPayoutAccount declares an account the asking affiliate is paid into, in the name and the document of their registration: an affiliate is paid into an account of their own, never a third party's.

func (*AffiliateService) AffiliatesPage

func (s *AffiliateService) AffiliatesPage(ctx context.Context, actor security.Subject, q AffiliatesQuery) ([]*Affiliate, int, error)

AffiliatesPage is a page of the admin's list and how many rows it has.

func (*AffiliateService) Attribute

Attribute links a user who signed up with a referral code to the affiliate who owns it, for life. It is called by the application's sign-up, with whatever subject it signs up as -- a guest of the tenant included.

A user who already has a referrer keeps them: the answer is the existing referral, unchanged. An empty code records nothing and answers nil. A code that is no active affiliate's, an affiliate's own code, or a person already in the referrer's tree is refused, and the sign-up goes on without a referrer.

func (*AffiliateService) BalanceOf

func (s *AffiliateService) BalanceOf(ctx context.Context, actor security.Subject, affiliateID string) (Balance, error)

BalanceOf is an affiliate's balance, for themselves and for the admin.

func (*AffiliateService) CommissionsPage

func (s *AffiliateService) CommissionsPage(ctx context.Context, actor security.Subject, q CommissionsQuery) ([]CommissionView, int, error)

CommissionsPage is a page of commissions and how many the list has: an affiliate's own, or, for the admin, anybody's.

func (*AffiliateService) Create

Create registers an affiliate.

func (*AffiliateService) CreatePlan

func (s *AffiliateService) CreatePlan(ctx context.Context, actor security.Subject, in PlanRequest, activate bool) (*PlanView, error)

CreatePlan defines a plan, and makes it the active one when activate is set. A plan is never edited: a new one is defined and activated, and every commission keeps the plan that paid it.

func (*AffiliateService) Find

func (s *AffiliateService) Find(ctx context.Context, actor security.Subject, id string) (*Affiliate, error)

Find answers one affiliate, for the admin.

func (*AffiliateService) Mine

Mine answers the affiliate whose login user is asking.

func (*AffiliateService) MyWithdrawals

func (s *AffiliateService) MyWithdrawals(ctx context.Context, actor security.Subject) ([]*wallet.WithdrawalRequest, error)

MyWithdrawals are the asking affiliate's withdrawal requests, newest first.

func (*AffiliateService) PayWithdrawal

func (s *AffiliateService) PayWithdrawal(ctx context.Context, actor security.Subject, in wallet.PaymentInput, receipt io.Reader) (*wallet.WithdrawalRequest, error)

PayWithdrawal records that the operator paid an affiliate's withdrawal, with the end-to-end identifier and the receipt.

func (*AffiliateService) PayoutAccounts

func (s *AffiliateService) PayoutAccounts(ctx context.Context, actor security.Subject, affiliateID string) ([]*wallet.PayoutAccount, error)

PayoutAccounts are an affiliate's accounts, for themselves and the admin.

func (*AffiliateService) Plans

func (s *AffiliateService) Plans(ctx context.Context, actor security.Subject) ([]PlanView, error)

Plans lists every plan, the active one first, then the newest.

func (*AffiliateService) RecordClick

func (s *AffiliateService) RecordClick(ctx context.Context, actor security.Subject, in ClickRequest) (*Affiliate, int, error)

RecordClick records that a referral link was opened and answers the affiliate it belongs to and how many days the cookie lives. A code that is no active affiliate's records nothing and answers no affiliate: the link still lands, and sets no cookie.

func (*AffiliateService) RecordConversion

func (s *AffiliateService) RecordConversion(ctx context.Context, actor security.Subject, in ConversionRequest) (*Conversion, []*Commission, error)

RecordConversion records a payment of a user and pays every level of the tree above them, by the plan active now: the buyer's referrer is level one, the referrer's referrer level two, and so on. A blocked affiliate's level is skipped and the levels above still earn. Each commission is deposited in the affiliate's wallet at once.

It is idempotent by OrderRef: a payment reported again answers what the first report recorded. A buyer with no referrer, or a payment with no plan active, is recorded and pays nothing.

func (*AffiliateService) RecordRefund

func (s *AffiliateService) RecordRefund(ctx context.Context, actor security.Subject, orderRef, reason string) (*Conversion, error)

RecordRefund records that a payment was given back, and reverses every commission it paid. The money leaves each wallet whatever its balance: a commission already withdrawn leaves the balance below zero, which blocks withdrawals until later commissions, or the admin's write-off, cover it. Refunding twice changes nothing.

func (*AffiliateService) RejectWithdrawal

func (s *AffiliateService) RejectWithdrawal(ctx context.Context, actor security.Subject, requestID, reason string) (*wallet.WithdrawalRequest, error)

RejectWithdrawal refuses an affiliate's withdrawal with the reason they read. The amount goes back to the balance, and the day is free again.

func (*AffiliateService) RequestWithdrawal

RequestWithdrawal asks for an affiliate's money: any amount between the plan's minimum and maximum, up to what is available, at most once a day, never while the balance is below zero. arandu-wallet holds the amount until the operator pays it or refuses it; a refused or cancelled request frees the day.

func (*AffiliateService) ReverseCommission

func (s *AffiliateService) ReverseCommission(ctx context.Context, actor security.Subject, commissionID, reason string) (*Commission, error)

ReverseCommission takes one commission back, by the admin's hand, with the reason the affiliate reads.

func (*AffiliateService) SetBlocked

func (s *AffiliateService) SetBlocked(ctx context.Context, actor security.Subject, id string, blocked bool) (*Affiliate, error)

SetBlocked blocks an affiliate, or unblocks one. A blocked affiliate earns nothing new and cannot withdraw; their history and their place in the tree stay.

func (*AffiliateService) StartPaying

func (s *AffiliateService) StartPaying(ctx context.Context, actor security.Subject, requestID string) (*wallet.WithdrawalRequest, error)

StartPaying is the operator taking an affiliate's withdrawal to pay it.

func (*AffiliateService) StatsOf

func (s *AffiliateService) StatsOf(ctx context.Context, actor security.Subject, affiliateID string, from, to Day) (Stats, error)

StatsOf counts an affiliate's clicks, sign-ups and sales in [from, to], and sums the commissions they earned in it.

func (*AffiliateService) Tree

func (s *AffiliateService) Tree(ctx context.Context, actor security.Subject, affiliateID string) ([]TreeNode, error)

Tree is an affiliate's tree, down to MaxLevels: the users they referred, and, for those who are affiliates themselves, the users those referred.

func (*AffiliateService) Upline

func (s *AffiliateService) Upline(ctx context.Context, actor security.Subject, userID string) ([]*Affiliate, error)

Upline is who earns on a user's payments: the user's referrer first, then the referrer's, up to MaxLevels. Empty for a user nobody referred.

func (*AffiliateService) WithdrawalReceipt

func (s *AffiliateService) WithdrawalReceipt(ctx context.Context, actor security.Subject, requestID string) (*wallet.WithdrawalRequest, filesystem.File, error)

WithdrawalReceipt opens the receipt of a paid withdrawal, for the affiliate it paid and for the admin. The caller closes the body.

func (*AffiliateService) Withdrawals

Withdrawals is the operator's queue of affiliates' withdrawals: the requests arandu-wallet holds that this package asked for.

func (*AffiliateService) WriteOff

func (s *AffiliateService) WriteOff(ctx context.Context, actor security.Subject, affiliateID, reason string) (int64, error)

WriteOff forgives an affiliate's negative balance: a deposit of what is missing, recorded in the ledger with the admin's reason. It answers the centavos written off, zero when the balance was not negative.

type AffiliateStatus

type AffiliateStatus string

AffiliateStatus is whether an affiliate earns and withdraws.

const (
	// AffiliateActive earns commissions and withdraws them.
	AffiliateActive AffiliateStatus = "active"
	// AffiliateBlocked earns nothing new and cannot withdraw.
	AffiliateBlocked AffiliateStatus = "blocked"
)

type AffiliateWithdrawal

type AffiliateWithdrawal struct {
	Request   *wallet.WithdrawalRequest
	Affiliate *Affiliate
}

AffiliateWithdrawal is one affiliate's withdrawal request in the operator's queue.

type AffiliatesQuery

type AffiliatesQuery struct {
	Search  string
	Status  AffiliateStatus
	Sort    string
	Dir     string
	Page    int
	PerPage int
}

AffiliatesQuery narrows the admin's list. Page counts from one.

type AttributeRequest

type AttributeRequest struct {
	// UserID is the user who just signed up.
	UserID string
	// Code is the referral code, from the cookie the link set (CodeFrom).
	Code string
	// Document is the user's CPF or CNPJ, when the application has it.
	// Without it, the tree is guarded by the user alone.
	Document string
}

AttributeRequest is what a sign-up with a referral code records.

type Balance

type Balance struct {
	// Balance is what the wallet holds, negative after a reversal of money
	// already withdrawn.
	Balance int64
	// Held is what open withdrawal requests set aside.
	Held int64
	// Available is what can be asked for now.
	Available int64
}

Balance is an affiliate's money as the panel shows it, in centavos.

type CellInput

type CellInput struct {
	Name, Type, Placeholder, Value, Label string
	Required                              bool
}

CellInput is one field of a form drawn inside a table cell.

type Click

type Click struct {
	model.Model

	ID          string    `db:"id"`
	TenantID    string    `db:"tenant_id"`
	AffiliateID string    `db:"affiliate_id"`
	At          time.Time `db:"at"`
	LandingURL  string    `db:"landing_url"`
	IPHash      string    `db:"ip_hash"`
	CreatedAt   time.Time `db:"created_at"`
	UpdatedAt   time.Time `db:"updated_at"`
}

Click is one opening of a referral link. The address is kept only as a hash, with the tenant in it, so a click can be told apart from another and nobody's address is stored.

func (*Click) Fresh

func (row *Click) Fresh(ctx context.Context, g auth.Grant, with ...string) (*Click, error)

Fresh reads the row again, as a new Click; it shadows the untyped one the embedded model promotes.

func (*Click) Replicate

func (row *Click) Replicate(except ...string) (*Click, error)

Replicate returns an unsaved copy of the row without its key; it shadows the untyped one the embedded model promotes.

type ClickCollection

type ClickCollection []*Click

ClickCollection is rows of Click, as a query returns them.

func ClickCollectionOf

func ClickCollectionOf(rows model.Rows) ClickCollection

ClickCollectionOf converts rows of the table of Click. A nil input is a nil collection.

func (ClickCollection) Contains

func (c ClickCollection) Contains(key any) bool

func (ClickCollection) Except

func (c ClickCollection) Except(keys ...any) ClickCollection

func (ClickCollection) Find

func (c ClickCollection) Find(key any) *Click

func (ClickCollection) FindOrFail

func (c ClickCollection) FindOrFail(key any) (*Click, error)

func (ClickCollection) Fresh

func (c ClickCollection) Fresh(ctx context.Context, g auth.Grant, with ...string) (ClickCollection, error)

func (ClickCollection) Load

func (c ClickCollection) Load(ctx context.Context, g auth.Grant, relations ...string) error

func (ClickCollection) LoadCount

func (c ClickCollection) LoadCount(ctx context.Context, g auth.Grant, relations ...string) error

func (ClickCollection) LoadMissing

func (c ClickCollection) LoadMissing(ctx context.Context, g auth.Grant, relations ...string) error

func (ClickCollection) ModelKeys

func (c ClickCollection) ModelKeys() []any

func (ClickCollection) Only

func (c ClickCollection) Only(keys ...any) ClickCollection

func (ClickCollection) Pluck

func (c ClickCollection) Pluck(column string) []any

func (ClickCollection) Rows

func (c ClickCollection) Rows() model.Rows

Rows converts the collection back to the core's rows.

func (ClickCollection) ToArray

func (c ClickCollection) ToArray() []map[string]any

func (ClickCollection) Unique

func (c ClickCollection) Unique() ClickCollection

type ClickQuery

type ClickQuery struct {
	// contains filtered or unexported fields
}

ClickQuery is a query on the table of Click.

The methods that build return the query, so they chain. The methods that run take a context and an auth.Grant, and return Click rows or a value; there is no way to run one without a Grant.

func Clicks

func Clicks(db model.DB) *ClickQuery

Clicks starts a query on the table of Click, through db.

Global scopes are on and, unless the table is Global, every statement is filtered by the tenant of the Grant its terminal takes.

func (*ClickQuery) AddSelect

func (q *ClickQuery) AddSelect(columns ...any) *ClickQuery

func (*ClickQuery) Avg

func (q *ClickQuery) Avg(ctx context.Context, g auth.Grant, column any) (any, error)

func (*ClickQuery) Base

func (q *ClickQuery) Base() *model.Builder

Base returns the core builder the query forwards to. It is for code in this package -- a local scope in the custom block of referral.go -- and for the factory, which builds rows through it.

func (*ClickQuery) Chunk

func (q *ClickQuery) Chunk(ctx context.Context, g auth.Grant, count int, callback func(ClickCollection, int) (bool, error)) error

func (*ClickQuery) Clone

func (q *ClickQuery) Clone() *ClickQuery

Clone returns an independent copy of the query.

func (*ClickQuery) Count

func (q *ClickQuery) Count(ctx context.Context, g auth.Grant, columns ...any) (int64, error)

func (*ClickQuery) Create

func (q *ClickQuery) Create(ctx context.Context, g auth.Grant, attributes map[string]any) (*Click, error)

func (*ClickQuery) Cursor

func (q *ClickQuery) Cursor(ctx context.Context, g auth.Grant) iter.Seq2[*Click, error]

func (*ClickQuery) CursorPaginate

func (q *ClickQuery) CursorPaginate(ctx context.Context, g auth.Grant, perPage int, cursor *pagination.Cursor, opts pagination.Options, columns ...any) (ClickCollection, *pagination.CursorPage, error)

func (*ClickQuery) Decrement

func (q *ClickQuery) Decrement(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*ClickQuery) Delete

func (q *ClickQuery) Delete(ctx context.Context, g auth.Grant) (int64, error)

func (*ClickQuery) DoesntExist

func (q *ClickQuery) DoesntExist(ctx context.Context, g auth.Grant) (bool, error)

func (*ClickQuery) DoesntHave

func (q *ClickQuery) DoesntHave(relation, boolean string, callback func(*query.Builder)) *ClickQuery

func (*ClickQuery) Each

func (q *ClickQuery) Each(ctx context.Context, g auth.Grant, count int, callback func(*Click, int) (bool, error)) error

func (*ClickQuery) Exists

func (q *ClickQuery) Exists(ctx context.Context, g auth.Grant) (bool, error)

func (*ClickQuery) Find

func (q *ClickQuery) Find(ctx context.Context, g auth.Grant, id any, columns ...any) (*Click, error)

func (*ClickQuery) FindMany

func (q *ClickQuery) FindMany(ctx context.Context, g auth.Grant, ids []any, columns ...any) (ClickCollection, error)

func (*ClickQuery) FindOrFail

func (q *ClickQuery) FindOrFail(ctx context.Context, g auth.Grant, id any, columns ...any) (*Click, error)

func (*ClickQuery) FindOrNew

func (q *ClickQuery) FindOrNew(ctx context.Context, g auth.Grant, id any, columns ...any) (*Click, error)

func (*ClickQuery) First

func (q *ClickQuery) First(ctx context.Context, g auth.Grant, columns ...any) (*Click, error)

First returns the first row, or nil and no error when there is none.

func (*ClickQuery) FirstOrCreate

func (q *ClickQuery) FirstOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Click, error)

func (*ClickQuery) FirstOrFail

func (q *ClickQuery) FirstOrFail(ctx context.Context, g auth.Grant, columns ...any) (*Click, error)

func (*ClickQuery) FirstOrNew

func (q *ClickQuery) FirstOrNew(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Click, error)

func (*ClickQuery) FirstWhere

func (q *ClickQuery) FirstWhere(ctx context.Context, g auth.Grant, column any, args ...any) (*Click, error)

func (*ClickQuery) ForPage

func (q *ClickQuery) ForPage(page, perPage int) *ClickQuery

func (*ClickQuery) ForceCreate

func (q *ClickQuery) ForceCreate(ctx context.Context, g auth.Grant, attributes map[string]any) (*Click, error)

func (*ClickQuery) Get

func (q *ClickQuery) Get(ctx context.Context, g auth.Grant, columns ...any) (ClickCollection, error)

Get runs the query and returns the rows.

func (*ClickQuery) GroupBy

func (q *ClickQuery) GroupBy(groups ...any) *ClickQuery

func (*ClickQuery) Has

func (q *ClickQuery) Has(relation, operator string, count int, boolean string, callback func(*query.Builder)) *ClickQuery

func (*ClickQuery) Increment

func (q *ClickQuery) Increment(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*ClickQuery) Insert

func (q *ClickQuery) Insert(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*ClickQuery) InsertOrIgnore

func (q *ClickQuery) InsertOrIgnore(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*ClickQuery) Join

func (q *ClickQuery) Join(table any, first any, args ...any) *ClickQuery

func (*ClickQuery) Latest

func (q *ClickQuery) Latest(column ...string) *ClickQuery

func (*ClickQuery) Limit

func (q *ClickQuery) Limit(value int) *ClickQuery

func (*ClickQuery) Max

func (q *ClickQuery) Max(ctx context.Context, g auth.Grant, column any) (any, error)

func (*ClickQuery) Min

func (q *ClickQuery) Min(ctx context.Context, g auth.Grant, column any) (any, error)

func (*ClickQuery) New

func (q *ClickQuery) New() (*Click, error)

New returns an empty Click on the query's connection, not yet saved, filled with what WithAttributes recorded on the query.

func (*ClickQuery) Offset

func (q *ClickQuery) Offset(value int) *ClickQuery

func (*ClickQuery) Oldest

func (q *ClickQuery) Oldest(column ...string) *ClickQuery

func (*ClickQuery) OrDoesntHave

func (q *ClickQuery) OrDoesntHave(relation string) *ClickQuery

func (*ClickQuery) OrHas

func (q *ClickQuery) OrHas(relation, operator string, count int) *ClickQuery

func (*ClickQuery) OrWhere

func (q *ClickQuery) OrWhere(column any, args ...any) *ClickQuery

OrWhere adds an or-where clause; a func(*ClickQuery) in place of the column adds a group.

func (*ClickQuery) OrWhereDoesntHave

func (q *ClickQuery) OrWhereDoesntHave(relation string, callback func(*query.Builder)) *ClickQuery

func (*ClickQuery) OrWhereHas

func (q *ClickQuery) OrWhereHas(relation string, callback func(*query.Builder)) *ClickQuery

func (*ClickQuery) OrWhereNot

func (q *ClickQuery) OrWhereNot(column any, args ...any) *ClickQuery

OrWhereNot adds an or-joined negated where clause, or a negated group.

func (*ClickQuery) OrWhereRelation

func (q *ClickQuery) OrWhereRelation(relation string, column any, args ...any) *ClickQuery

func (*ClickQuery) OrderBy

func (q *ClickQuery) OrderBy(column any, direction ...string) *ClickQuery

func (*ClickQuery) OrderByDesc

func (q *ClickQuery) OrderByDesc(column any) *ClickQuery

func (*ClickQuery) Paginate

func (q *ClickQuery) Paginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (ClickCollection, *pagination.LengthAwarePage, error)

func (*ClickQuery) Pluck

func (q *ClickQuery) Pluck(ctx context.Context, g auth.Grant, column string) ([]any, error)

func (*ClickQuery) Select

func (q *ClickQuery) Select(columns ...any) *ClickQuery

func (*ClickQuery) SelectRaw

func (q *ClickQuery) SelectRaw(expression string, bindings ...any) *ClickQuery

func (*ClickQuery) SimplePaginate

func (q *ClickQuery) SimplePaginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (ClickCollection, *pagination.Page, error)

func (*ClickQuery) Sole

func (q *ClickQuery) Sole(ctx context.Context, g auth.Grant, columns ...any) (*Click, error)

func (*ClickQuery) SoleValue

func (q *ClickQuery) SoleValue(ctx context.Context, g auth.Grant, column string) (any, error)

func (*ClickQuery) Sum

func (q *ClickQuery) Sum(ctx context.Context, g auth.Grant, column any) (any, error)

func (*ClickQuery) Touch

func (q *ClickQuery) Touch(ctx context.Context, g auth.Grant, column ...string) (int64, error)

func (*ClickQuery) Update

func (q *ClickQuery) Update(ctx context.Context, g auth.Grant, values map[string]any) (int64, error)

func (*ClickQuery) UpdateOrCreate

func (q *ClickQuery) UpdateOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Click, error)

func (*ClickQuery) Upsert

func (q *ClickQuery) Upsert(ctx context.Context, g auth.Grant, values []map[string]any, uniqueBy, update []string) (int64, error)

func (*ClickQuery) Value

func (q *ClickQuery) Value(ctx context.Context, g auth.Grant, column string) (any, error)

func (*ClickQuery) ValueOrFail

func (q *ClickQuery) ValueOrFail(ctx context.Context, g auth.Grant, column string) (any, error)

func (*ClickQuery) Where

func (q *ClickQuery) Where(column any, args ...any) *ClickQuery

Where adds a where clause; a func(*ClickQuery) in place of the column adds a group.

func (*ClickQuery) WhereBelongsTo

func (q *ClickQuery) WhereBelongsTo(relationshipName string, related ...model.Entity) *ClickQuery

func (*ClickQuery) WhereBetween

func (q *ClickQuery) WhereBetween(column any, from, to any) *ClickQuery

func (*ClickQuery) WhereColumn

func (q *ClickQuery) WhereColumn(first any, args ...any) *ClickQuery

func (*ClickQuery) WhereDoesntHave

func (q *ClickQuery) WhereDoesntHave(relation string, callback func(*query.Builder)) *ClickQuery

func (*ClickQuery) WhereExists

func (q *ClickQuery) WhereExists(callback func(*query.Builder)) *ClickQuery

func (*ClickQuery) WhereHas

func (q *ClickQuery) WhereHas(relation string, callback func(*query.Builder)) *ClickQuery

func (*ClickQuery) WhereHasCount

func (q *ClickQuery) WhereHasCount(relation string, callback func(*query.Builder), operator string, count int) *ClickQuery

func (*ClickQuery) WhereIn

func (q *ClickQuery) WhereIn(column any, values []any) *ClickQuery

func (*ClickQuery) WhereKey

func (q *ClickQuery) WhereKey(id any) *ClickQuery

func (*ClickQuery) WhereNot

func (q *ClickQuery) WhereNot(column any, args ...any) *ClickQuery

WhereNot adds a negated where clause, or a negated group.

func (*ClickQuery) WhereNotExists

func (q *ClickQuery) WhereNotExists(callback func(*query.Builder)) *ClickQuery

func (*ClickQuery) WhereNotIn

func (q *ClickQuery) WhereNotIn(column any, values []any) *ClickQuery

func (*ClickQuery) WhereNotNull

func (q *ClickQuery) WhereNotNull(columns ...any) *ClickQuery

func (*ClickQuery) WhereNull

func (q *ClickQuery) WhereNull(columns ...any) *ClickQuery

func (*ClickQuery) WhereRelation

func (q *ClickQuery) WhereRelation(relation string, column any, args ...any) *ClickQuery

func (*ClickQuery) With

func (q *ClickQuery) With(relations ...string) *ClickQuery

func (*ClickQuery) WithAvg

func (q *ClickQuery) WithAvg(relation, column string) *ClickQuery

func (*ClickQuery) WithCount

func (q *ClickQuery) WithCount(relations ...string) *ClickQuery

func (*ClickQuery) WithExists

func (q *ClickQuery) WithExists(relation string) *ClickQuery

func (*ClickQuery) WithMax

func (q *ClickQuery) WithMax(relation, column string) *ClickQuery

func (*ClickQuery) WithMin

func (q *ClickQuery) WithMin(relation, column string) *ClickQuery

func (*ClickQuery) WithSum

func (q *ClickQuery) WithSum(relation, column string) *ClickQuery

func (*ClickQuery) Without

func (q *ClickQuery) Without(relations ...string) *ClickQuery

func (*ClickQuery) WithoutGlobalScope

func (q *ClickQuery) WithoutGlobalScope(identifier string) *ClickQuery

func (*ClickQuery) WithoutGlobalScopes

func (q *ClickQuery) WithoutGlobalScopes(identifiers ...string) *ClickQuery

type ClickRequest

type ClickRequest struct {
	Code       string
	LandingURL string
	// Address is the visitor's address. Only its hash, with the tenant in it,
	// is stored.
	Address string
}

ClickRequest is what opening a referral link records.

type Commission

type Commission struct {
	model.Model

	ID           string `db:"id"`
	TenantID     string `db:"tenant_id"`
	ConversionID string `db:"conversion_id"`
	AffiliateID  string `db:"affiliate_id"`

	Level   int   `db:"level"`
	RateBps int64 `db:"rate_bps"`
	Amount  int64 `db:"amount"`

	Status CommissionStatus `db:"status"`

	// WalletOperationID is the deposit; ReversalOperationID the withdrawal
	// that undid it.
	WalletOperationID   string `db:"wallet_operation_id"`
	ReversalOperationID string `db:"reversal_operation_id"`
	ReversedReason      string `db:"reversed_reason"`

	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

Commission is what one level of the tree earned on one conversion. It is deposited in the affiliate's wallet the moment it is created -- no waiting period -- and stays there until they withdraw it. A refund, or the admin, reverses it: the same amount leaves the wallet again, and the balance may go below zero, which blocks withdrawals until later commissions, or the admin, bring it back.

func (*Commission) Fresh

func (row *Commission) Fresh(ctx context.Context, g auth.Grant, with ...string) (*Commission, error)

Fresh reads the row again, as a new Commission; it shadows the untyped one the embedded model promotes.

func (*Commission) Replicate

func (row *Commission) Replicate(except ...string) (*Commission, error)

Replicate returns an unsaved copy of the row without its key; it shadows the untyped one the embedded model promotes.

type CommissionCollection

type CommissionCollection []*Commission

CommissionCollection is rows of Commission, as a query returns them.

func CommissionCollectionOf

func CommissionCollectionOf(rows model.Rows) CommissionCollection

CommissionCollectionOf converts rows of the table of Commission. A nil input is a nil collection.

func (CommissionCollection) Contains

func (c CommissionCollection) Contains(key any) bool

func (CommissionCollection) Except

func (c CommissionCollection) Except(keys ...any) CommissionCollection

func (CommissionCollection) Find

func (c CommissionCollection) Find(key any) *Commission

func (CommissionCollection) FindOrFail

func (c CommissionCollection) FindOrFail(key any) (*Commission, error)

func (CommissionCollection) Fresh

func (CommissionCollection) Load

func (c CommissionCollection) Load(ctx context.Context, g auth.Grant, relations ...string) error

func (CommissionCollection) LoadCount

func (c CommissionCollection) LoadCount(ctx context.Context, g auth.Grant, relations ...string) error

func (CommissionCollection) LoadMissing

func (c CommissionCollection) LoadMissing(ctx context.Context, g auth.Grant, relations ...string) error

func (CommissionCollection) ModelKeys

func (c CommissionCollection) ModelKeys() []any

func (CommissionCollection) Only

func (CommissionCollection) Pluck

func (c CommissionCollection) Pluck(column string) []any

func (CommissionCollection) Rows

func (c CommissionCollection) Rows() model.Rows

Rows converts the collection back to the core's rows.

func (CommissionCollection) ToArray

func (c CommissionCollection) ToArray() []map[string]any

func (CommissionCollection) Unique

type CommissionQuery

type CommissionQuery struct {
	// contains filtered or unexported fields
}

CommissionQuery is a query on the table of Commission.

The methods that build return the query, so they chain. The methods that run take a context and an auth.Grant, and return Commission rows or a value; there is no way to run one without a Grant.

func Commissions

func Commissions(db model.DB) *CommissionQuery

Commissions starts a query on the table of Commission, through db.

Global scopes are on and, unless the table is Global, every statement is filtered by the tenant of the Grant its terminal takes.

func (*CommissionQuery) AddSelect

func (q *CommissionQuery) AddSelect(columns ...any) *CommissionQuery

func (*CommissionQuery) Avg

func (q *CommissionQuery) Avg(ctx context.Context, g auth.Grant, column any) (any, error)

func (*CommissionQuery) Base

func (q *CommissionQuery) Base() *model.Builder

Base returns the core builder the query forwards to. It is for code in this package -- a local scope in the custom block of ledger.go -- and for the factory, which builds rows through it.

func (*CommissionQuery) Chunk

func (q *CommissionQuery) Chunk(ctx context.Context, g auth.Grant, count int, callback func(CommissionCollection, int) (bool, error)) error

func (*CommissionQuery) Clone

func (q *CommissionQuery) Clone() *CommissionQuery

Clone returns an independent copy of the query.

func (*CommissionQuery) Count

func (q *CommissionQuery) Count(ctx context.Context, g auth.Grant, columns ...any) (int64, error)

func (*CommissionQuery) Create

func (q *CommissionQuery) Create(ctx context.Context, g auth.Grant, attributes map[string]any) (*Commission, error)

func (*CommissionQuery) Cursor

func (*CommissionQuery) CursorPaginate

func (q *CommissionQuery) CursorPaginate(ctx context.Context, g auth.Grant, perPage int, cursor *pagination.Cursor, opts pagination.Options, columns ...any) (CommissionCollection, *pagination.CursorPage, error)

func (*CommissionQuery) Decrement

func (q *CommissionQuery) Decrement(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*CommissionQuery) Delete

func (q *CommissionQuery) Delete(ctx context.Context, g auth.Grant) (int64, error)

func (*CommissionQuery) DoesntExist

func (q *CommissionQuery) DoesntExist(ctx context.Context, g auth.Grant) (bool, error)

func (*CommissionQuery) DoesntHave

func (q *CommissionQuery) DoesntHave(relation, boolean string, callback func(*query.Builder)) *CommissionQuery

func (*CommissionQuery) Each

func (q *CommissionQuery) Each(ctx context.Context, g auth.Grant, count int, callback func(*Commission, int) (bool, error)) error

func (*CommissionQuery) Exists

func (q *CommissionQuery) Exists(ctx context.Context, g auth.Grant) (bool, error)

func (*CommissionQuery) Find

func (q *CommissionQuery) Find(ctx context.Context, g auth.Grant, id any, columns ...any) (*Commission, error)

func (*CommissionQuery) FindMany

func (q *CommissionQuery) FindMany(ctx context.Context, g auth.Grant, ids []any, columns ...any) (CommissionCollection, error)

func (*CommissionQuery) FindOrFail

func (q *CommissionQuery) FindOrFail(ctx context.Context, g auth.Grant, id any, columns ...any) (*Commission, error)

func (*CommissionQuery) FindOrNew

func (q *CommissionQuery) FindOrNew(ctx context.Context, g auth.Grant, id any, columns ...any) (*Commission, error)

func (*CommissionQuery) First

func (q *CommissionQuery) First(ctx context.Context, g auth.Grant, columns ...any) (*Commission, error)

First returns the first row, or nil and no error when there is none.

func (*CommissionQuery) FirstOrCreate

func (q *CommissionQuery) FirstOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Commission, error)

func (*CommissionQuery) FirstOrFail

func (q *CommissionQuery) FirstOrFail(ctx context.Context, g auth.Grant, columns ...any) (*Commission, error)

func (*CommissionQuery) FirstOrNew

func (q *CommissionQuery) FirstOrNew(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Commission, error)

func (*CommissionQuery) FirstWhere

func (q *CommissionQuery) FirstWhere(ctx context.Context, g auth.Grant, column any, args ...any) (*Commission, error)

func (*CommissionQuery) ForPage

func (q *CommissionQuery) ForPage(page, perPage int) *CommissionQuery

func (*CommissionQuery) ForceCreate

func (q *CommissionQuery) ForceCreate(ctx context.Context, g auth.Grant, attributes map[string]any) (*Commission, error)

func (*CommissionQuery) Get

func (q *CommissionQuery) Get(ctx context.Context, g auth.Grant, columns ...any) (CommissionCollection, error)

Get runs the query and returns the rows.

func (*CommissionQuery) GroupBy

func (q *CommissionQuery) GroupBy(groups ...any) *CommissionQuery

func (*CommissionQuery) Has

func (q *CommissionQuery) Has(relation, operator string, count int, boolean string, callback func(*query.Builder)) *CommissionQuery

func (*CommissionQuery) Increment

func (q *CommissionQuery) Increment(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*CommissionQuery) Insert

func (q *CommissionQuery) Insert(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*CommissionQuery) InsertOrIgnore

func (q *CommissionQuery) InsertOrIgnore(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*CommissionQuery) Join

func (q *CommissionQuery) Join(table any, first any, args ...any) *CommissionQuery

func (*CommissionQuery) Latest

func (q *CommissionQuery) Latest(column ...string) *CommissionQuery

func (*CommissionQuery) Limit

func (q *CommissionQuery) Limit(value int) *CommissionQuery

func (*CommissionQuery) Max

func (q *CommissionQuery) Max(ctx context.Context, g auth.Grant, column any) (any, error)

func (*CommissionQuery) Min

func (q *CommissionQuery) Min(ctx context.Context, g auth.Grant, column any) (any, error)

func (*CommissionQuery) New

func (q *CommissionQuery) New() (*Commission, error)

New returns an empty Commission on the query's connection, not yet saved, filled with what WithAttributes recorded on the query.

func (*CommissionQuery) Offset

func (q *CommissionQuery) Offset(value int) *CommissionQuery

func (*CommissionQuery) Oldest

func (q *CommissionQuery) Oldest(column ...string) *CommissionQuery

func (*CommissionQuery) OrDoesntHave

func (q *CommissionQuery) OrDoesntHave(relation string) *CommissionQuery

func (*CommissionQuery) OrHas

func (q *CommissionQuery) OrHas(relation, operator string, count int) *CommissionQuery

func (*CommissionQuery) OrWhere

func (q *CommissionQuery) OrWhere(column any, args ...any) *CommissionQuery

OrWhere adds an or-where clause; a func(*CommissionQuery) in place of the column adds a group.

func (*CommissionQuery) OrWhereDoesntHave

func (q *CommissionQuery) OrWhereDoesntHave(relation string, callback func(*query.Builder)) *CommissionQuery

func (*CommissionQuery) OrWhereHas

func (q *CommissionQuery) OrWhereHas(relation string, callback func(*query.Builder)) *CommissionQuery

func (*CommissionQuery) OrWhereNot

func (q *CommissionQuery) OrWhereNot(column any, args ...any) *CommissionQuery

OrWhereNot adds an or-joined negated where clause, or a negated group.

func (*CommissionQuery) OrWhereRelation

func (q *CommissionQuery) OrWhereRelation(relation string, column any, args ...any) *CommissionQuery

func (*CommissionQuery) OrderBy

func (q *CommissionQuery) OrderBy(column any, direction ...string) *CommissionQuery

func (*CommissionQuery) OrderByDesc

func (q *CommissionQuery) OrderByDesc(column any) *CommissionQuery

func (*CommissionQuery) Paginate

func (q *CommissionQuery) Paginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (CommissionCollection, *pagination.LengthAwarePage, error)

func (*CommissionQuery) Pluck

func (q *CommissionQuery) Pluck(ctx context.Context, g auth.Grant, column string) ([]any, error)

func (*CommissionQuery) Select

func (q *CommissionQuery) Select(columns ...any) *CommissionQuery

func (*CommissionQuery) SelectRaw

func (q *CommissionQuery) SelectRaw(expression string, bindings ...any) *CommissionQuery

func (*CommissionQuery) SimplePaginate

func (q *CommissionQuery) SimplePaginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (CommissionCollection, *pagination.Page, error)

func (*CommissionQuery) Sole

func (q *CommissionQuery) Sole(ctx context.Context, g auth.Grant, columns ...any) (*Commission, error)

func (*CommissionQuery) SoleValue

func (q *CommissionQuery) SoleValue(ctx context.Context, g auth.Grant, column string) (any, error)

func (*CommissionQuery) Sum

func (q *CommissionQuery) Sum(ctx context.Context, g auth.Grant, column any) (any, error)

func (*CommissionQuery) Touch

func (q *CommissionQuery) Touch(ctx context.Context, g auth.Grant, column ...string) (int64, error)

func (*CommissionQuery) Update

func (q *CommissionQuery) Update(ctx context.Context, g auth.Grant, values map[string]any) (int64, error)

func (*CommissionQuery) UpdateOrCreate

func (q *CommissionQuery) UpdateOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Commission, error)

func (*CommissionQuery) Upsert

func (q *CommissionQuery) Upsert(ctx context.Context, g auth.Grant, values []map[string]any, uniqueBy, update []string) (int64, error)

func (*CommissionQuery) Value

func (q *CommissionQuery) Value(ctx context.Context, g auth.Grant, column string) (any, error)

func (*CommissionQuery) ValueOrFail

func (q *CommissionQuery) ValueOrFail(ctx context.Context, g auth.Grant, column string) (any, error)

func (*CommissionQuery) Where

func (q *CommissionQuery) Where(column any, args ...any) *CommissionQuery

Where adds a where clause; a func(*CommissionQuery) in place of the column adds a group.

func (*CommissionQuery) WhereBelongsTo

func (q *CommissionQuery) WhereBelongsTo(relationshipName string, related ...model.Entity) *CommissionQuery

func (*CommissionQuery) WhereBetween

func (q *CommissionQuery) WhereBetween(column any, from, to any) *CommissionQuery

func (*CommissionQuery) WhereColumn

func (q *CommissionQuery) WhereColumn(first any, args ...any) *CommissionQuery

func (*CommissionQuery) WhereDoesntHave

func (q *CommissionQuery) WhereDoesntHave(relation string, callback func(*query.Builder)) *CommissionQuery

func (*CommissionQuery) WhereExists

func (q *CommissionQuery) WhereExists(callback func(*query.Builder)) *CommissionQuery

func (*CommissionQuery) WhereHas

func (q *CommissionQuery) WhereHas(relation string, callback func(*query.Builder)) *CommissionQuery

func (*CommissionQuery) WhereHasCount

func (q *CommissionQuery) WhereHasCount(relation string, callback func(*query.Builder), operator string, count int) *CommissionQuery

func (*CommissionQuery) WhereIn

func (q *CommissionQuery) WhereIn(column any, values []any) *CommissionQuery

func (*CommissionQuery) WhereKey

func (q *CommissionQuery) WhereKey(id any) *CommissionQuery

func (*CommissionQuery) WhereNot

func (q *CommissionQuery) WhereNot(column any, args ...any) *CommissionQuery

WhereNot adds a negated where clause, or a negated group.

func (*CommissionQuery) WhereNotExists

func (q *CommissionQuery) WhereNotExists(callback func(*query.Builder)) *CommissionQuery

func (*CommissionQuery) WhereNotIn

func (q *CommissionQuery) WhereNotIn(column any, values []any) *CommissionQuery

func (*CommissionQuery) WhereNotNull

func (q *CommissionQuery) WhereNotNull(columns ...any) *CommissionQuery

func (*CommissionQuery) WhereNull

func (q *CommissionQuery) WhereNull(columns ...any) *CommissionQuery

func (*CommissionQuery) WhereRelation

func (q *CommissionQuery) WhereRelation(relation string, column any, args ...any) *CommissionQuery

func (*CommissionQuery) With

func (q *CommissionQuery) With(relations ...string) *CommissionQuery

func (*CommissionQuery) WithAvg

func (q *CommissionQuery) WithAvg(relation, column string) *CommissionQuery

func (*CommissionQuery) WithCount

func (q *CommissionQuery) WithCount(relations ...string) *CommissionQuery

func (*CommissionQuery) WithExists

func (q *CommissionQuery) WithExists(relation string) *CommissionQuery

func (*CommissionQuery) WithMax

func (q *CommissionQuery) WithMax(relation, column string) *CommissionQuery

func (*CommissionQuery) WithMin

func (q *CommissionQuery) WithMin(relation, column string) *CommissionQuery

func (*CommissionQuery) WithSum

func (q *CommissionQuery) WithSum(relation, column string) *CommissionQuery

func (*CommissionQuery) Without

func (q *CommissionQuery) Without(relations ...string) *CommissionQuery

func (*CommissionQuery) WithoutGlobalScope

func (q *CommissionQuery) WithoutGlobalScope(identifier string) *CommissionQuery

func (*CommissionQuery) WithoutGlobalScopes

func (q *CommissionQuery) WithoutGlobalScopes(identifiers ...string) *CommissionQuery

type CommissionRow

type CommissionRow struct {
	ID, Date, Rate, Amount, AmountSort, Status, StatusKey string
	Order, Buyer, Product, Affiliate, AffiliateURL        string
	Reason, ReverseURL                                    string
	Level                                                 int
	Reversible                                            bool
}

CommissionRow is one commission as a screen shows it.

type CommissionStatus

type CommissionStatus string

CommissionStatus is where a commission stands.

const (
	// CommissionAvailable is in the wallet.
	CommissionAvailable CommissionStatus = "available"
	// CommissionReversed was taken back out.
	CommissionReversed CommissionStatus = "reversed"
)

type CommissionView

type CommissionView struct {
	Commission Commission
	Conversion *Conversion
	Affiliate  *Affiliate
}

CommissionView is a commission with the payment it was paid on and the affiliate who earned it.

type CommissionsQuery

type CommissionsQuery struct {
	AffiliateID string
	Level       int
	Status      CommissionStatus
	From, To    Day
	Sort        string
	Dir         string
	Page        int
	PerPage     int
}

CommissionsQuery narrows a list of commissions. Page counts from one.

type Config

type Config struct {
	// Prefix is the path the panels are mounted under. Empty means
	// DefaultPrefix.
	Prefix string

	// ReferralPath is the path the referral link answers under, outside the
	// prefix and outside the sign-in guard: /r/{code}. Empty means
	// DefaultReferralPath.
	ReferralPath string

	// Tenant is the customer a visitor with no session is read as when they
	// open a referral link. Required: the click has to belong to some tenant,
	// and it cannot be one the request names.
	Tenant string

	// LandingPath is where the referral link sends the visitor after setting
	// the cookie, unless the link carries ?to= with a path of the same site.
	// Empty means "/".
	LandingPath string

	// CookieName is the cookie the link sets and CodeFrom reads. Empty means
	// DefaultCookieName.
	CookieName string

	// SecureCookie marks the cookie Secure. Leave it on in production; a
	// development server over plain HTTP turns it off.
	SecureCookie bool

	// PageSize is how many rows one page answers with. Zero means
	// DefaultPageSize; anything above MaxPageSize is refused.
	PageSize int

	// Location is the timezone a day is counted in: the day of a withdrawal,
	// the period of the panel's numbers. Nil means DefaultLocation.
	Location *time.Location

	// Wallet is arandu-wallet's service, the application's one instance
	// (walletModule.Service()). Required: the commissions are deposited in the
	// affiliate's wallet and withdrawn from it, and this package keeps no
	// balance of its own.
	Wallet *wallet.WalletService

	// Translator is the application's own catalogue, asked before the one this
	// package ships, key by key: "affiliate.screen.dashboard_title". Optional.
	Translator *translation.Translator
}

Config is everything the module needs from the application, checked by New before the module exists.

func (Config) Validate

func (c Config) Validate() error

Validate reports the first setting that cannot work.

type Conversion

type Conversion struct {
	model.Model

	ID       string `db:"id"`
	TenantID string `db:"tenant_id"`

	// OrderRef is the application's identifier of the payment, unique per
	// tenant: reporting the same payment twice records it once.
	OrderRef string `db:"order_ref"`

	BuyerUserID string `db:"buyer_user_id"`
	ProductID   string `db:"product_id"`

	// Amount is the payment in centavos, what the rates apply to.
	Amount  int64 `db:"amount"`
	Renewal Flag  `db:"renewal"`

	// AffiliateID is the buyer's referrer, the first level, empty when the
	// buyer was referred by nobody. PlanID is the plan that paid it, empty
	// when no plan was active.
	AffiliateID string `db:"affiliate_id"`
	PlanID      string `db:"plan_id"`

	Status     ConversionStatus `db:"status"`
	OccurredAt time.Time        `db:"occurred_at"`

	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

Conversion is one payment of a referred user -- a first purchase or a renewal -- as the application reported it. It is recorded once per order reference, and it is what the commissions of every level point at.

func (*Conversion) Fresh

func (row *Conversion) Fresh(ctx context.Context, g auth.Grant, with ...string) (*Conversion, error)

Fresh reads the row again, as a new Conversion; it shadows the untyped one the embedded model promotes.

func (*Conversion) Replicate

func (row *Conversion) Replicate(except ...string) (*Conversion, error)

Replicate returns an unsaved copy of the row without its key; it shadows the untyped one the embedded model promotes.

type ConversionCollection

type ConversionCollection []*Conversion

ConversionCollection is rows of Conversion, as a query returns them.

func ConversionCollectionOf

func ConversionCollectionOf(rows model.Rows) ConversionCollection

ConversionCollectionOf converts rows of the table of Conversion. A nil input is a nil collection.

func (ConversionCollection) Contains

func (c ConversionCollection) Contains(key any) bool

func (ConversionCollection) Except

func (c ConversionCollection) Except(keys ...any) ConversionCollection

func (ConversionCollection) Find

func (c ConversionCollection) Find(key any) *Conversion

func (ConversionCollection) FindOrFail

func (c ConversionCollection) FindOrFail(key any) (*Conversion, error)

func (ConversionCollection) Fresh

func (ConversionCollection) Load

func (c ConversionCollection) Load(ctx context.Context, g auth.Grant, relations ...string) error

func (ConversionCollection) LoadCount

func (c ConversionCollection) LoadCount(ctx context.Context, g auth.Grant, relations ...string) error

func (ConversionCollection) LoadMissing

func (c ConversionCollection) LoadMissing(ctx context.Context, g auth.Grant, relations ...string) error

func (ConversionCollection) ModelKeys

func (c ConversionCollection) ModelKeys() []any

func (ConversionCollection) Only

func (ConversionCollection) Pluck

func (c ConversionCollection) Pluck(column string) []any

func (ConversionCollection) Rows

func (c ConversionCollection) Rows() model.Rows

Rows converts the collection back to the core's rows.

func (ConversionCollection) ToArray

func (c ConversionCollection) ToArray() []map[string]any

func (ConversionCollection) Unique

type ConversionQuery

type ConversionQuery struct {
	// contains filtered or unexported fields
}

ConversionQuery is a query on the table of Conversion.

The methods that build return the query, so they chain. The methods that run take a context and an auth.Grant, and return Conversion rows or a value; there is no way to run one without a Grant.

func Conversions

func Conversions(db model.DB) *ConversionQuery

Conversions starts a query on the table of Conversion, through db.

Global scopes are on and, unless the table is Global, every statement is filtered by the tenant of the Grant its terminal takes.

func (*ConversionQuery) AddSelect

func (q *ConversionQuery) AddSelect(columns ...any) *ConversionQuery

func (*ConversionQuery) Avg

func (q *ConversionQuery) Avg(ctx context.Context, g auth.Grant, column any) (any, error)

func (*ConversionQuery) Base

func (q *ConversionQuery) Base() *model.Builder

Base returns the core builder the query forwards to. It is for code in this package -- a local scope in the custom block of ledger.go -- and for the factory, which builds rows through it.

func (*ConversionQuery) Chunk

func (q *ConversionQuery) Chunk(ctx context.Context, g auth.Grant, count int, callback func(ConversionCollection, int) (bool, error)) error

func (*ConversionQuery) Clone

func (q *ConversionQuery) Clone() *ConversionQuery

Clone returns an independent copy of the query.

func (*ConversionQuery) Count

func (q *ConversionQuery) Count(ctx context.Context, g auth.Grant, columns ...any) (int64, error)

func (*ConversionQuery) Create

func (q *ConversionQuery) Create(ctx context.Context, g auth.Grant, attributes map[string]any) (*Conversion, error)

func (*ConversionQuery) Cursor

func (*ConversionQuery) CursorPaginate

func (q *ConversionQuery) CursorPaginate(ctx context.Context, g auth.Grant, perPage int, cursor *pagination.Cursor, opts pagination.Options, columns ...any) (ConversionCollection, *pagination.CursorPage, error)

func (*ConversionQuery) Decrement

func (q *ConversionQuery) Decrement(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*ConversionQuery) Delete

func (q *ConversionQuery) Delete(ctx context.Context, g auth.Grant) (int64, error)

func (*ConversionQuery) DoesntExist

func (q *ConversionQuery) DoesntExist(ctx context.Context, g auth.Grant) (bool, error)

func (*ConversionQuery) DoesntHave

func (q *ConversionQuery) DoesntHave(relation, boolean string, callback func(*query.Builder)) *ConversionQuery

func (*ConversionQuery) Each

func (q *ConversionQuery) Each(ctx context.Context, g auth.Grant, count int, callback func(*Conversion, int) (bool, error)) error

func (*ConversionQuery) Exists

func (q *ConversionQuery) Exists(ctx context.Context, g auth.Grant) (bool, error)

func (*ConversionQuery) Find

func (q *ConversionQuery) Find(ctx context.Context, g auth.Grant, id any, columns ...any) (*Conversion, error)

func (*ConversionQuery) FindMany

func (q *ConversionQuery) FindMany(ctx context.Context, g auth.Grant, ids []any, columns ...any) (ConversionCollection, error)

func (*ConversionQuery) FindOrFail

func (q *ConversionQuery) FindOrFail(ctx context.Context, g auth.Grant, id any, columns ...any) (*Conversion, error)

func (*ConversionQuery) FindOrNew

func (q *ConversionQuery) FindOrNew(ctx context.Context, g auth.Grant, id any, columns ...any) (*Conversion, error)

func (*ConversionQuery) First

func (q *ConversionQuery) First(ctx context.Context, g auth.Grant, columns ...any) (*Conversion, error)

First returns the first row, or nil and no error when there is none.

func (*ConversionQuery) FirstOrCreate

func (q *ConversionQuery) FirstOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Conversion, error)

func (*ConversionQuery) FirstOrFail

func (q *ConversionQuery) FirstOrFail(ctx context.Context, g auth.Grant, columns ...any) (*Conversion, error)

func (*ConversionQuery) FirstOrNew

func (q *ConversionQuery) FirstOrNew(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Conversion, error)

func (*ConversionQuery) FirstWhere

func (q *ConversionQuery) FirstWhere(ctx context.Context, g auth.Grant, column any, args ...any) (*Conversion, error)

func (*ConversionQuery) ForPage

func (q *ConversionQuery) ForPage(page, perPage int) *ConversionQuery

func (*ConversionQuery) ForceCreate

func (q *ConversionQuery) ForceCreate(ctx context.Context, g auth.Grant, attributes map[string]any) (*Conversion, error)

func (*ConversionQuery) Get

func (q *ConversionQuery) Get(ctx context.Context, g auth.Grant, columns ...any) (ConversionCollection, error)

Get runs the query and returns the rows.

func (*ConversionQuery) GroupBy

func (q *ConversionQuery) GroupBy(groups ...any) *ConversionQuery

func (*ConversionQuery) Has

func (q *ConversionQuery) Has(relation, operator string, count int, boolean string, callback func(*query.Builder)) *ConversionQuery

func (*ConversionQuery) Increment

func (q *ConversionQuery) Increment(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*ConversionQuery) Insert

func (q *ConversionQuery) Insert(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*ConversionQuery) InsertOrIgnore

func (q *ConversionQuery) InsertOrIgnore(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*ConversionQuery) Join

func (q *ConversionQuery) Join(table any, first any, args ...any) *ConversionQuery

func (*ConversionQuery) Latest

func (q *ConversionQuery) Latest(column ...string) *ConversionQuery

func (*ConversionQuery) Limit

func (q *ConversionQuery) Limit(value int) *ConversionQuery

func (*ConversionQuery) Max

func (q *ConversionQuery) Max(ctx context.Context, g auth.Grant, column any) (any, error)

func (*ConversionQuery) Min

func (q *ConversionQuery) Min(ctx context.Context, g auth.Grant, column any) (any, error)

func (*ConversionQuery) New

func (q *ConversionQuery) New() (*Conversion, error)

New returns an empty Conversion on the query's connection, not yet saved, filled with what WithAttributes recorded on the query.

func (*ConversionQuery) Offset

func (q *ConversionQuery) Offset(value int) *ConversionQuery

func (*ConversionQuery) Oldest

func (q *ConversionQuery) Oldest(column ...string) *ConversionQuery

func (*ConversionQuery) OrDoesntHave

func (q *ConversionQuery) OrDoesntHave(relation string) *ConversionQuery

func (*ConversionQuery) OrHas

func (q *ConversionQuery) OrHas(relation, operator string, count int) *ConversionQuery

func (*ConversionQuery) OrWhere

func (q *ConversionQuery) OrWhere(column any, args ...any) *ConversionQuery

OrWhere adds an or-where clause; a func(*ConversionQuery) in place of the column adds a group.

func (*ConversionQuery) OrWhereDoesntHave

func (q *ConversionQuery) OrWhereDoesntHave(relation string, callback func(*query.Builder)) *ConversionQuery

func (*ConversionQuery) OrWhereHas

func (q *ConversionQuery) OrWhereHas(relation string, callback func(*query.Builder)) *ConversionQuery

func (*ConversionQuery) OrWhereNot

func (q *ConversionQuery) OrWhereNot(column any, args ...any) *ConversionQuery

OrWhereNot adds an or-joined negated where clause, or a negated group.

func (*ConversionQuery) OrWhereRelation

func (q *ConversionQuery) OrWhereRelation(relation string, column any, args ...any) *ConversionQuery

func (*ConversionQuery) OrderBy

func (q *ConversionQuery) OrderBy(column any, direction ...string) *ConversionQuery

func (*ConversionQuery) OrderByDesc

func (q *ConversionQuery) OrderByDesc(column any) *ConversionQuery

func (*ConversionQuery) Paginate

func (q *ConversionQuery) Paginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (ConversionCollection, *pagination.LengthAwarePage, error)

func (*ConversionQuery) Pluck

func (q *ConversionQuery) Pluck(ctx context.Context, g auth.Grant, column string) ([]any, error)

func (*ConversionQuery) Select

func (q *ConversionQuery) Select(columns ...any) *ConversionQuery

func (*ConversionQuery) SelectRaw

func (q *ConversionQuery) SelectRaw(expression string, bindings ...any) *ConversionQuery

func (*ConversionQuery) SimplePaginate

func (q *ConversionQuery) SimplePaginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (ConversionCollection, *pagination.Page, error)

func (*ConversionQuery) Sole

func (q *ConversionQuery) Sole(ctx context.Context, g auth.Grant, columns ...any) (*Conversion, error)

func (*ConversionQuery) SoleValue

func (q *ConversionQuery) SoleValue(ctx context.Context, g auth.Grant, column string) (any, error)

func (*ConversionQuery) Sum

func (q *ConversionQuery) Sum(ctx context.Context, g auth.Grant, column any) (any, error)

func (*ConversionQuery) Touch

func (q *ConversionQuery) Touch(ctx context.Context, g auth.Grant, column ...string) (int64, error)

func (*ConversionQuery) Update

func (q *ConversionQuery) Update(ctx context.Context, g auth.Grant, values map[string]any) (int64, error)

func (*ConversionQuery) UpdateOrCreate

func (q *ConversionQuery) UpdateOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Conversion, error)

func (*ConversionQuery) Upsert

func (q *ConversionQuery) Upsert(ctx context.Context, g auth.Grant, values []map[string]any, uniqueBy, update []string) (int64, error)

func (*ConversionQuery) Value

func (q *ConversionQuery) Value(ctx context.Context, g auth.Grant, column string) (any, error)

func (*ConversionQuery) ValueOrFail

func (q *ConversionQuery) ValueOrFail(ctx context.Context, g auth.Grant, column string) (any, error)

func (*ConversionQuery) Where

func (q *ConversionQuery) Where(column any, args ...any) *ConversionQuery

Where adds a where clause; a func(*ConversionQuery) in place of the column adds a group.

func (*ConversionQuery) WhereBelongsTo

func (q *ConversionQuery) WhereBelongsTo(relationshipName string, related ...model.Entity) *ConversionQuery

func (*ConversionQuery) WhereBetween

func (q *ConversionQuery) WhereBetween(column any, from, to any) *ConversionQuery

func (*ConversionQuery) WhereColumn

func (q *ConversionQuery) WhereColumn(first any, args ...any) *ConversionQuery

func (*ConversionQuery) WhereDoesntHave

func (q *ConversionQuery) WhereDoesntHave(relation string, callback func(*query.Builder)) *ConversionQuery

func (*ConversionQuery) WhereExists

func (q *ConversionQuery) WhereExists(callback func(*query.Builder)) *ConversionQuery

func (*ConversionQuery) WhereHas

func (q *ConversionQuery) WhereHas(relation string, callback func(*query.Builder)) *ConversionQuery

func (*ConversionQuery) WhereHasCount

func (q *ConversionQuery) WhereHasCount(relation string, callback func(*query.Builder), operator string, count int) *ConversionQuery

func (*ConversionQuery) WhereIn

func (q *ConversionQuery) WhereIn(column any, values []any) *ConversionQuery

func (*ConversionQuery) WhereKey

func (q *ConversionQuery) WhereKey(id any) *ConversionQuery

func (*ConversionQuery) WhereNot

func (q *ConversionQuery) WhereNot(column any, args ...any) *ConversionQuery

WhereNot adds a negated where clause, or a negated group.

func (*ConversionQuery) WhereNotExists

func (q *ConversionQuery) WhereNotExists(callback func(*query.Builder)) *ConversionQuery

func (*ConversionQuery) WhereNotIn

func (q *ConversionQuery) WhereNotIn(column any, values []any) *ConversionQuery

func (*ConversionQuery) WhereNotNull

func (q *ConversionQuery) WhereNotNull(columns ...any) *ConversionQuery

func (*ConversionQuery) WhereNull

func (q *ConversionQuery) WhereNull(columns ...any) *ConversionQuery

func (*ConversionQuery) WhereRelation

func (q *ConversionQuery) WhereRelation(relation string, column any, args ...any) *ConversionQuery

func (*ConversionQuery) With

func (q *ConversionQuery) With(relations ...string) *ConversionQuery

func (*ConversionQuery) WithAvg

func (q *ConversionQuery) WithAvg(relation, column string) *ConversionQuery

func (*ConversionQuery) WithCount

func (q *ConversionQuery) WithCount(relations ...string) *ConversionQuery

func (*ConversionQuery) WithExists

func (q *ConversionQuery) WithExists(relation string) *ConversionQuery

func (*ConversionQuery) WithMax

func (q *ConversionQuery) WithMax(relation, column string) *ConversionQuery

func (*ConversionQuery) WithMin

func (q *ConversionQuery) WithMin(relation, column string) *ConversionQuery

func (*ConversionQuery) WithSum

func (q *ConversionQuery) WithSum(relation, column string) *ConversionQuery

func (*ConversionQuery) Without

func (q *ConversionQuery) Without(relations ...string) *ConversionQuery

func (*ConversionQuery) WithoutGlobalScope

func (q *ConversionQuery) WithoutGlobalScope(identifier string) *ConversionQuery

func (*ConversionQuery) WithoutGlobalScopes

func (q *ConversionQuery) WithoutGlobalScopes(identifiers ...string) *ConversionQuery

type ConversionRequest

type ConversionRequest struct {
	// OrderRef is the application's identifier of the payment, unique per
	// tenant: reporting it twice records it once.
	OrderRef    string
	BuyerUserID string
	ProductID   string
	// Amount is the payment in centavos.
	Amount int64
	// Renewal is a payment of something the buyer already had. It pays
	// commissions like a first purchase: they are for life.
	Renewal    bool
	OccurredAt time.Time
}

ConversionRequest is a payment of a user, as the application reports it.

func (ConversionRequest) Validate

func (r ConversionRequest) Validate() validation.Errors

Validate reports the errors per field.

type ConversionStatus

type ConversionStatus string

ConversionStatus is whether a payment still stands.

const (
	// ConversionCounted stands, and its commissions with it.
	ConversionCounted ConversionStatus = "counted"
	// ConversionRefunded was given back, and its commissions reversed.
	ConversionRefunded ConversionStatus = "refunded"
)

type CreateRequest

type CreateRequest struct {
	// UserID is the login user who will sign in to the panel.
	UserID string
	// Name is how the affiliate is called.
	Name string
	// Document is the CPF or the CNPJ.
	Document string
	// Code is the referral code. Empty draws one.
	Code string
}

CreateRequest is what registering an affiliate takes.

func (CreateRequest) Validate

func (r CreateRequest) Validate() validation.Errors

Validate reports the errors per field.

type DashboardPageData

type DashboardPageData struct {
	Screen
	Name, Code, Link, Document string
	Blocked                    bool
	Plan                       *PlanRow
	From, To                   string
	Clicks, Signups, Sales     int64
	Commissions                string
	Balance, Held, Available   string
	Negative                   bool
	Min, Max                   string
	Rows                       []CommissionRow
	Level, Status              string
	Table                      TableState
	Accounts                   []AccountOption
	Withdrawals                []WithdrawalRow
	WithdrawURL, AccountURL    string
}

DashboardPageData is the affiliate's own panel.

type Day

type Day string

Day is a calendar day, as YYYY-MM-DD, in the application's timezone.

func DayOf

func DayOf(t time.Time, loc *time.Location) Day

DayOf is the calendar day of an instant in a timezone.

func ParseDay

func ParseDay(s string) (Day, error)

ParseDay reads a day, and the empty string as no day.

func (Day) IsZero

func (d Day) IsZero() bool

IsZero reports the empty day.

func (Day) Time

func (d Day) Time() time.Time

Time is midnight of the day, in UTC.

type Flag

type Flag bool

Flag is a yes-or-no stored as 0 or 1, which every engine reads the same.

func (*Flag) Scan

func (f *Flag) Scan(value any) error

Scan reads a flag from whatever the engine answers.

func (Flag) Value

func (f Flag) Value() (driver.Value, error)

Value writes the flag as 0 or 1.

type FormState

type FormState struct{ view.Page }

FormState is what a form field reads from the page it is drawn on: what was typed before a refusal, and the message for each field.

func (FormState) FieldError

func (f FormState) FieldError(name string) string

FieldError is the first message for one field, empty when it was accepted.

type Labels

type Labels struct {
	Locale string
	// contains filtered or unexported fields
}

Labels are the sentences of this package's screens in one locale.

func (Labels) Status

func (l Labels) Status(s string) string

Status is the label of a status of this package: an affiliate's, a commission's or a conversion's.

func (Labels) T

func (l Labels) T(key string) string

T reads a key of this package: "screen.dashboard_title".

type LevelRow

type LevelRow struct {
	Level int
	Rate  string
}

LevelRow is one level of a plan.

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module is what the application registers.

func New

func New(cfg Config, db *data.DB, sessions *security.SessionStore) (*Module, error)

New returns the module, or the reason it cannot be built.

func (*Module) Boot

func (m *Module) Boot(context.Context) error

Boot refuses to start until every view this package renders is linked.

func (*Module) CodeFrom

func (m *Module) CodeFrom(r *stdhttp.Request) string

CodeFrom is the referral code the visitor's cookie carries, for the application's sign-up to pass to Attribute. Empty when there is none.

func (*Module) Labels

func (m *Module) Labels(locale string) Labels

Labels answers the sentences in a locale, the shipped one when empty.

func (*Module) Migrations

func (m *Module) Migrations() []foundation.Migration

Migrations declares the schema this module owns, in the order the names sort in.

func (*Module) Name

func (m *Module) Name() string

Name is the module identifier.

func (*Module) Publishes

func (m *Module) Publishes() []foundation.Publication

Publishes declares the files this package offers, each at the path it takes relative to the root of the project.

One tree, under one tag. A publication may carry a page, a component, a configuration file, a migration, a catalogue of sentences or an asset, and this package offers the first of those and nothing else. Each absence is a decision rather than an omission:

  • configuration is the Config struct New is handed, checked by the compiler and validated before the module exists. A file copied into the project beside it would be a second place to say the same thing, and only one of the two could be the one the code reads.
  • a stylesheet, a script or any other asset is registered with the view layer and served from an address derived from its own bytes. Copying one into the project would put a second copy of those bytes under a second address, and a page can only reference one of them.
  • translations are overridden by writing the lines the application wants into its own override tree, which the catalogue loader already reads. A copy of every line this package ships is a copy that goes stale, and it goes stale without saying so.
  • migrations are declared and collected, never copied. A copy in the project's own migration directory is found by the runner as well, so one schema change applies twice under two names.

What is left is the markup, and it is here for the reason the others are not: it is the one thing the project is expected to edit. A package cannot know what a screen should say in a product it has never seen.

func (*Module) Routes

func (m *Module) Routes(r *fhttp.Router)

Routes registers the module's routes.

The referral link is the one route a visitor with no session reaches, and it is registered on the router the application handed in, outside the prefix: /r/{code}. Every other route is registered on the guarded group, which is mounted before the first registration.

func (*Module) Service

func (m *Module) Service() *AffiliateService

Service is the use cases, for an application that calls them from its own code: the sign-up that attributes a referral, the place payments are confirmed. Every method asks the policy, so handing it out opens nothing.

type OptionalText

type OptionalText string

OptionalText is a text column that is NULL when empty, so a unique index over it holds among the rows that have a value and lets every row without one through: two users whose document nobody knows are not the same person.

func (*OptionalText) Scan

func (t *OptionalText) Scan(value any) error

Scan reads NULL as the empty text.

func (OptionalText) Value

func (t OptionalText) Value() (driver.Value, error)

Value writes the empty text as NULL.

type Plan

type Plan struct {
	model.Model

	ID       string `db:"id"`
	TenantID string `db:"tenant_id"`

	Name string   `db:"name"`
	Kind PlanKind `db:"kind"`

	// CookieDays is how long the referral cookie set by /r/{code} lives.
	CookieDays int `db:"cookie_days"`

	// MinWithdrawal and MaxWithdrawal are centavos. A max of zero is no max.
	MinWithdrawal int64 `db:"min_withdrawal"`
	MaxWithdrawal int64 `db:"max_withdrawal"`

	Active Flag `db:"active"`

	CreatedBy string    `db:"created_by"`
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

Plan is how commissions are paid: how many levels up the tree, at which rate each, how long a referral cookie lives, and the limits of a withdrawal. The admin defines plans; one is active at a time, and a conversion is paid by the plan active when it arrived.

func (*Plan) Fresh

func (row *Plan) Fresh(ctx context.Context, g auth.Grant, with ...string) (*Plan, error)

Fresh reads the row again, as a new Plan; it shadows the untyped one the embedded model promotes.

func (*Plan) Replicate

func (row *Plan) Replicate(except ...string) (*Plan, error)

Replicate returns an unsaved copy of the row without its key; it shadows the untyped one the embedded model promotes.

type PlanCollection

type PlanCollection []*Plan

PlanCollection is rows of Plan, as a query returns them.

func PlanCollectionOf

func PlanCollectionOf(rows model.Rows) PlanCollection

PlanCollectionOf converts rows of the table of Plan. A nil input is a nil collection.

func (PlanCollection) Contains

func (c PlanCollection) Contains(key any) bool

func (PlanCollection) Except

func (c PlanCollection) Except(keys ...any) PlanCollection

func (PlanCollection) Find

func (c PlanCollection) Find(key any) *Plan

func (PlanCollection) FindOrFail

func (c PlanCollection) FindOrFail(key any) (*Plan, error)

func (PlanCollection) Fresh

func (c PlanCollection) Fresh(ctx context.Context, g auth.Grant, with ...string) (PlanCollection, error)

func (PlanCollection) Load

func (c PlanCollection) Load(ctx context.Context, g auth.Grant, relations ...string) error

func (PlanCollection) LoadCount

func (c PlanCollection) LoadCount(ctx context.Context, g auth.Grant, relations ...string) error

func (PlanCollection) LoadMissing

func (c PlanCollection) LoadMissing(ctx context.Context, g auth.Grant, relations ...string) error

func (PlanCollection) ModelKeys

func (c PlanCollection) ModelKeys() []any

func (PlanCollection) Only

func (c PlanCollection) Only(keys ...any) PlanCollection

func (PlanCollection) Pluck

func (c PlanCollection) Pluck(column string) []any

func (PlanCollection) Rows

func (c PlanCollection) Rows() model.Rows

Rows converts the collection back to the core's rows.

func (PlanCollection) ToArray

func (c PlanCollection) ToArray() []map[string]any

func (PlanCollection) Unique

func (c PlanCollection) Unique() PlanCollection

type PlanKind

type PlanKind string

PlanKind is how far up the tree a plan pays.

const (
	// Linear pays the referrer alone: one level.
	Linear PlanKind = "linear"
	// Multilevel pays up to MaxLevels levels up the tree.
	Multilevel PlanKind = "multilevel"
)

type PlanLevel

type PlanLevel struct {
	model.Model

	ID        string    `db:"id"`
	TenantID  string    `db:"tenant_id"`
	PlanID    string    `db:"plan_id"`
	Level     int       `db:"level"`
	RateBps   int64     `db:"rate_bps"`
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

PlanLevel is the rate one level of a plan pays, in basis points of the payment: 150 is 1,5%.

func (*PlanLevel) Fresh

func (row *PlanLevel) Fresh(ctx context.Context, g auth.Grant, with ...string) (*PlanLevel, error)

Fresh reads the row again, as a new PlanLevel; it shadows the untyped one the embedded model promotes.

func (*PlanLevel) Replicate

func (row *PlanLevel) Replicate(except ...string) (*PlanLevel, error)

Replicate returns an unsaved copy of the row without its key; it shadows the untyped one the embedded model promotes.

type PlanLevelCollection

type PlanLevelCollection []*PlanLevel

PlanLevelCollection is rows of PlanLevel, as a query returns them.

func PlanLevelCollectionOf

func PlanLevelCollectionOf(rows model.Rows) PlanLevelCollection

PlanLevelCollectionOf converts rows of the table of PlanLevel. A nil input is a nil collection.

func (PlanLevelCollection) Contains

func (c PlanLevelCollection) Contains(key any) bool

func (PlanLevelCollection) Except

func (c PlanLevelCollection) Except(keys ...any) PlanLevelCollection

func (PlanLevelCollection) Find

func (c PlanLevelCollection) Find(key any) *PlanLevel

func (PlanLevelCollection) FindOrFail

func (c PlanLevelCollection) FindOrFail(key any) (*PlanLevel, error)

func (PlanLevelCollection) Fresh

func (PlanLevelCollection) Load

func (c PlanLevelCollection) Load(ctx context.Context, g auth.Grant, relations ...string) error

func (PlanLevelCollection) LoadCount

func (c PlanLevelCollection) LoadCount(ctx context.Context, g auth.Grant, relations ...string) error

func (PlanLevelCollection) LoadMissing

func (c PlanLevelCollection) LoadMissing(ctx context.Context, g auth.Grant, relations ...string) error

func (PlanLevelCollection) ModelKeys

func (c PlanLevelCollection) ModelKeys() []any

func (PlanLevelCollection) Only

func (PlanLevelCollection) Pluck

func (c PlanLevelCollection) Pluck(column string) []any

func (PlanLevelCollection) Rows

func (c PlanLevelCollection) Rows() model.Rows

Rows converts the collection back to the core's rows.

func (PlanLevelCollection) ToArray

func (c PlanLevelCollection) ToArray() []map[string]any

func (PlanLevelCollection) Unique

type PlanLevelQuery

type PlanLevelQuery struct {
	// contains filtered or unexported fields
}

PlanLevelQuery is a query on the table of PlanLevel.

The methods that build return the query, so they chain. The methods that run take a context and an auth.Grant, and return PlanLevel rows or a value; there is no way to run one without a Grant.

func PlanLevels

func PlanLevels(db model.DB) *PlanLevelQuery

PlanLevels starts a query on the table of PlanLevel, through db.

Global scopes are on and, unless the table is Global, every statement is filtered by the tenant of the Grant its terminal takes.

func (*PlanLevelQuery) AddSelect

func (q *PlanLevelQuery) AddSelect(columns ...any) *PlanLevelQuery

func (*PlanLevelQuery) Avg

func (q *PlanLevelQuery) Avg(ctx context.Context, g auth.Grant, column any) (any, error)

func (*PlanLevelQuery) Base

func (q *PlanLevelQuery) Base() *model.Builder

Base returns the core builder the query forwards to. It is for code in this package -- a local scope in the custom block of plan.go -- and for the factory, which builds rows through it.

func (*PlanLevelQuery) Chunk

func (q *PlanLevelQuery) Chunk(ctx context.Context, g auth.Grant, count int, callback func(PlanLevelCollection, int) (bool, error)) error

func (*PlanLevelQuery) Clone

func (q *PlanLevelQuery) Clone() *PlanLevelQuery

Clone returns an independent copy of the query.

func (*PlanLevelQuery) Count

func (q *PlanLevelQuery) Count(ctx context.Context, g auth.Grant, columns ...any) (int64, error)

func (*PlanLevelQuery) Create

func (q *PlanLevelQuery) Create(ctx context.Context, g auth.Grant, attributes map[string]any) (*PlanLevel, error)

func (*PlanLevelQuery) Cursor

func (*PlanLevelQuery) CursorPaginate

func (q *PlanLevelQuery) CursorPaginate(ctx context.Context, g auth.Grant, perPage int, cursor *pagination.Cursor, opts pagination.Options, columns ...any) (PlanLevelCollection, *pagination.CursorPage, error)

func (*PlanLevelQuery) Decrement

func (q *PlanLevelQuery) Decrement(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*PlanLevelQuery) Delete

func (q *PlanLevelQuery) Delete(ctx context.Context, g auth.Grant) (int64, error)

func (*PlanLevelQuery) DoesntExist

func (q *PlanLevelQuery) DoesntExist(ctx context.Context, g auth.Grant) (bool, error)

func (*PlanLevelQuery) DoesntHave

func (q *PlanLevelQuery) DoesntHave(relation, boolean string, callback func(*query.Builder)) *PlanLevelQuery

func (*PlanLevelQuery) Each

func (q *PlanLevelQuery) Each(ctx context.Context, g auth.Grant, count int, callback func(*PlanLevel, int) (bool, error)) error

func (*PlanLevelQuery) Exists

func (q *PlanLevelQuery) Exists(ctx context.Context, g auth.Grant) (bool, error)

func (*PlanLevelQuery) Find

func (q *PlanLevelQuery) Find(ctx context.Context, g auth.Grant, id any, columns ...any) (*PlanLevel, error)

func (*PlanLevelQuery) FindMany

func (q *PlanLevelQuery) FindMany(ctx context.Context, g auth.Grant, ids []any, columns ...any) (PlanLevelCollection, error)

func (*PlanLevelQuery) FindOrFail

func (q *PlanLevelQuery) FindOrFail(ctx context.Context, g auth.Grant, id any, columns ...any) (*PlanLevel, error)

func (*PlanLevelQuery) FindOrNew

func (q *PlanLevelQuery) FindOrNew(ctx context.Context, g auth.Grant, id any, columns ...any) (*PlanLevel, error)

func (*PlanLevelQuery) First

func (q *PlanLevelQuery) First(ctx context.Context, g auth.Grant, columns ...any) (*PlanLevel, error)

First returns the first row, or nil and no error when there is none.

func (*PlanLevelQuery) FirstOrCreate

func (q *PlanLevelQuery) FirstOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*PlanLevel, error)

func (*PlanLevelQuery) FirstOrFail

func (q *PlanLevelQuery) FirstOrFail(ctx context.Context, g auth.Grant, columns ...any) (*PlanLevel, error)

func (*PlanLevelQuery) FirstOrNew

func (q *PlanLevelQuery) FirstOrNew(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*PlanLevel, error)

func (*PlanLevelQuery) FirstWhere

func (q *PlanLevelQuery) FirstWhere(ctx context.Context, g auth.Grant, column any, args ...any) (*PlanLevel, error)

func (*PlanLevelQuery) ForPage

func (q *PlanLevelQuery) ForPage(page, perPage int) *PlanLevelQuery

func (*PlanLevelQuery) ForceCreate

func (q *PlanLevelQuery) ForceCreate(ctx context.Context, g auth.Grant, attributes map[string]any) (*PlanLevel, error)

func (*PlanLevelQuery) Get

func (q *PlanLevelQuery) Get(ctx context.Context, g auth.Grant, columns ...any) (PlanLevelCollection, error)

Get runs the query and returns the rows.

func (*PlanLevelQuery) GroupBy

func (q *PlanLevelQuery) GroupBy(groups ...any) *PlanLevelQuery

func (*PlanLevelQuery) Has

func (q *PlanLevelQuery) Has(relation, operator string, count int, boolean string, callback func(*query.Builder)) *PlanLevelQuery

func (*PlanLevelQuery) Increment

func (q *PlanLevelQuery) Increment(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*PlanLevelQuery) Insert

func (q *PlanLevelQuery) Insert(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*PlanLevelQuery) InsertOrIgnore

func (q *PlanLevelQuery) InsertOrIgnore(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*PlanLevelQuery) Join

func (q *PlanLevelQuery) Join(table any, first any, args ...any) *PlanLevelQuery

func (*PlanLevelQuery) Latest

func (q *PlanLevelQuery) Latest(column ...string) *PlanLevelQuery

func (*PlanLevelQuery) Limit

func (q *PlanLevelQuery) Limit(value int) *PlanLevelQuery

func (*PlanLevelQuery) Max

func (q *PlanLevelQuery) Max(ctx context.Context, g auth.Grant, column any) (any, error)

func (*PlanLevelQuery) Min

func (q *PlanLevelQuery) Min(ctx context.Context, g auth.Grant, column any) (any, error)

func (*PlanLevelQuery) New

func (q *PlanLevelQuery) New() (*PlanLevel, error)

New returns an empty PlanLevel on the query's connection, not yet saved, filled with what WithAttributes recorded on the query.

func (*PlanLevelQuery) Offset

func (q *PlanLevelQuery) Offset(value int) *PlanLevelQuery

func (*PlanLevelQuery) Oldest

func (q *PlanLevelQuery) Oldest(column ...string) *PlanLevelQuery

func (*PlanLevelQuery) OrDoesntHave

func (q *PlanLevelQuery) OrDoesntHave(relation string) *PlanLevelQuery

func (*PlanLevelQuery) OrHas

func (q *PlanLevelQuery) OrHas(relation, operator string, count int) *PlanLevelQuery

func (*PlanLevelQuery) OrWhere

func (q *PlanLevelQuery) OrWhere(column any, args ...any) *PlanLevelQuery

OrWhere adds an or-where clause; a func(*PlanLevelQuery) in place of the column adds a group.

func (*PlanLevelQuery) OrWhereDoesntHave

func (q *PlanLevelQuery) OrWhereDoesntHave(relation string, callback func(*query.Builder)) *PlanLevelQuery

func (*PlanLevelQuery) OrWhereHas

func (q *PlanLevelQuery) OrWhereHas(relation string, callback func(*query.Builder)) *PlanLevelQuery

func (*PlanLevelQuery) OrWhereNot

func (q *PlanLevelQuery) OrWhereNot(column any, args ...any) *PlanLevelQuery

OrWhereNot adds an or-joined negated where clause, or a negated group.

func (*PlanLevelQuery) OrWhereRelation

func (q *PlanLevelQuery) OrWhereRelation(relation string, column any, args ...any) *PlanLevelQuery

func (*PlanLevelQuery) OrderBy

func (q *PlanLevelQuery) OrderBy(column any, direction ...string) *PlanLevelQuery

func (*PlanLevelQuery) OrderByDesc

func (q *PlanLevelQuery) OrderByDesc(column any) *PlanLevelQuery

func (*PlanLevelQuery) Paginate

func (q *PlanLevelQuery) Paginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (PlanLevelCollection, *pagination.LengthAwarePage, error)

func (*PlanLevelQuery) Pluck

func (q *PlanLevelQuery) Pluck(ctx context.Context, g auth.Grant, column string) ([]any, error)

func (*PlanLevelQuery) Select

func (q *PlanLevelQuery) Select(columns ...any) *PlanLevelQuery

func (*PlanLevelQuery) SelectRaw

func (q *PlanLevelQuery) SelectRaw(expression string, bindings ...any) *PlanLevelQuery

func (*PlanLevelQuery) SimplePaginate

func (q *PlanLevelQuery) SimplePaginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (PlanLevelCollection, *pagination.Page, error)

func (*PlanLevelQuery) Sole

func (q *PlanLevelQuery) Sole(ctx context.Context, g auth.Grant, columns ...any) (*PlanLevel, error)

func (*PlanLevelQuery) SoleValue

func (q *PlanLevelQuery) SoleValue(ctx context.Context, g auth.Grant, column string) (any, error)

func (*PlanLevelQuery) Sum

func (q *PlanLevelQuery) Sum(ctx context.Context, g auth.Grant, column any) (any, error)

func (*PlanLevelQuery) Touch

func (q *PlanLevelQuery) Touch(ctx context.Context, g auth.Grant, column ...string) (int64, error)

func (*PlanLevelQuery) Update

func (q *PlanLevelQuery) Update(ctx context.Context, g auth.Grant, values map[string]any) (int64, error)

func (*PlanLevelQuery) UpdateOrCreate

func (q *PlanLevelQuery) UpdateOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*PlanLevel, error)

func (*PlanLevelQuery) Upsert

func (q *PlanLevelQuery) Upsert(ctx context.Context, g auth.Grant, values []map[string]any, uniqueBy, update []string) (int64, error)

func (*PlanLevelQuery) Value

func (q *PlanLevelQuery) Value(ctx context.Context, g auth.Grant, column string) (any, error)

func (*PlanLevelQuery) ValueOrFail

func (q *PlanLevelQuery) ValueOrFail(ctx context.Context, g auth.Grant, column string) (any, error)

func (*PlanLevelQuery) Where

func (q *PlanLevelQuery) Where(column any, args ...any) *PlanLevelQuery

Where adds a where clause; a func(*PlanLevelQuery) in place of the column adds a group.

func (*PlanLevelQuery) WhereBelongsTo

func (q *PlanLevelQuery) WhereBelongsTo(relationshipName string, related ...model.Entity) *PlanLevelQuery

func (*PlanLevelQuery) WhereBetween

func (q *PlanLevelQuery) WhereBetween(column any, from, to any) *PlanLevelQuery

func (*PlanLevelQuery) WhereColumn

func (q *PlanLevelQuery) WhereColumn(first any, args ...any) *PlanLevelQuery

func (*PlanLevelQuery) WhereDoesntHave

func (q *PlanLevelQuery) WhereDoesntHave(relation string, callback func(*query.Builder)) *PlanLevelQuery

func (*PlanLevelQuery) WhereExists

func (q *PlanLevelQuery) WhereExists(callback func(*query.Builder)) *PlanLevelQuery

func (*PlanLevelQuery) WhereHas

func (q *PlanLevelQuery) WhereHas(relation string, callback func(*query.Builder)) *PlanLevelQuery

func (*PlanLevelQuery) WhereHasCount

func (q *PlanLevelQuery) WhereHasCount(relation string, callback func(*query.Builder), operator string, count int) *PlanLevelQuery

func (*PlanLevelQuery) WhereIn

func (q *PlanLevelQuery) WhereIn(column any, values []any) *PlanLevelQuery

func (*PlanLevelQuery) WhereKey

func (q *PlanLevelQuery) WhereKey(id any) *PlanLevelQuery

func (*PlanLevelQuery) WhereNot

func (q *PlanLevelQuery) WhereNot(column any, args ...any) *PlanLevelQuery

WhereNot adds a negated where clause, or a negated group.

func (*PlanLevelQuery) WhereNotExists

func (q *PlanLevelQuery) WhereNotExists(callback func(*query.Builder)) *PlanLevelQuery

func (*PlanLevelQuery) WhereNotIn

func (q *PlanLevelQuery) WhereNotIn(column any, values []any) *PlanLevelQuery

func (*PlanLevelQuery) WhereNotNull

func (q *PlanLevelQuery) WhereNotNull(columns ...any) *PlanLevelQuery

func (*PlanLevelQuery) WhereNull

func (q *PlanLevelQuery) WhereNull(columns ...any) *PlanLevelQuery

func (*PlanLevelQuery) WhereRelation

func (q *PlanLevelQuery) WhereRelation(relation string, column any, args ...any) *PlanLevelQuery

func (*PlanLevelQuery) With

func (q *PlanLevelQuery) With(relations ...string) *PlanLevelQuery

func (*PlanLevelQuery) WithAvg

func (q *PlanLevelQuery) WithAvg(relation, column string) *PlanLevelQuery

func (*PlanLevelQuery) WithCount

func (q *PlanLevelQuery) WithCount(relations ...string) *PlanLevelQuery

func (*PlanLevelQuery) WithExists

func (q *PlanLevelQuery) WithExists(relation string) *PlanLevelQuery

func (*PlanLevelQuery) WithMax

func (q *PlanLevelQuery) WithMax(relation, column string) *PlanLevelQuery

func (*PlanLevelQuery) WithMin

func (q *PlanLevelQuery) WithMin(relation, column string) *PlanLevelQuery

func (*PlanLevelQuery) WithSum

func (q *PlanLevelQuery) WithSum(relation, column string) *PlanLevelQuery

func (*PlanLevelQuery) Without

func (q *PlanLevelQuery) Without(relations ...string) *PlanLevelQuery

func (*PlanLevelQuery) WithoutGlobalScope

func (q *PlanLevelQuery) WithoutGlobalScope(identifier string) *PlanLevelQuery

func (*PlanLevelQuery) WithoutGlobalScopes

func (q *PlanLevelQuery) WithoutGlobalScopes(identifiers ...string) *PlanLevelQuery

type PlanQuery

type PlanQuery struct {
	// contains filtered or unexported fields
}

PlanQuery is a query on the table of Plan.

The methods that build return the query, so they chain. The methods that run take a context and an auth.Grant, and return Plan rows or a value; there is no way to run one without a Grant.

func Plans

func Plans(db model.DB) *PlanQuery

Plans starts a query on the table of Plan, through db.

Global scopes are on and, unless the table is Global, every statement is filtered by the tenant of the Grant its terminal takes.

func (*PlanQuery) AddSelect

func (q *PlanQuery) AddSelect(columns ...any) *PlanQuery

func (*PlanQuery) Avg

func (q *PlanQuery) Avg(ctx context.Context, g auth.Grant, column any) (any, error)

func (*PlanQuery) Base

func (q *PlanQuery) Base() *model.Builder

Base returns the core builder the query forwards to. It is for code in this package -- a local scope in the custom block of plan.go -- and for the factory, which builds rows through it.

func (*PlanQuery) Chunk

func (q *PlanQuery) Chunk(ctx context.Context, g auth.Grant, count int, callback func(PlanCollection, int) (bool, error)) error

func (*PlanQuery) Clone

func (q *PlanQuery) Clone() *PlanQuery

Clone returns an independent copy of the query.

func (*PlanQuery) Count

func (q *PlanQuery) Count(ctx context.Context, g auth.Grant, columns ...any) (int64, error)

func (*PlanQuery) Create

func (q *PlanQuery) Create(ctx context.Context, g auth.Grant, attributes map[string]any) (*Plan, error)

func (*PlanQuery) Cursor

func (q *PlanQuery) Cursor(ctx context.Context, g auth.Grant) iter.Seq2[*Plan, error]

func (*PlanQuery) CursorPaginate

func (q *PlanQuery) CursorPaginate(ctx context.Context, g auth.Grant, perPage int, cursor *pagination.Cursor, opts pagination.Options, columns ...any) (PlanCollection, *pagination.CursorPage, error)

func (*PlanQuery) Decrement

func (q *PlanQuery) Decrement(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*PlanQuery) Delete

func (q *PlanQuery) Delete(ctx context.Context, g auth.Grant) (int64, error)

func (*PlanQuery) DoesntExist

func (q *PlanQuery) DoesntExist(ctx context.Context, g auth.Grant) (bool, error)

func (*PlanQuery) DoesntHave

func (q *PlanQuery) DoesntHave(relation, boolean string, callback func(*query.Builder)) *PlanQuery

func (*PlanQuery) Each

func (q *PlanQuery) Each(ctx context.Context, g auth.Grant, count int, callback func(*Plan, int) (bool, error)) error

func (*PlanQuery) Exists

func (q *PlanQuery) Exists(ctx context.Context, g auth.Grant) (bool, error)

func (*PlanQuery) Find

func (q *PlanQuery) Find(ctx context.Context, g auth.Grant, id any, columns ...any) (*Plan, error)

func (*PlanQuery) FindMany

func (q *PlanQuery) FindMany(ctx context.Context, g auth.Grant, ids []any, columns ...any) (PlanCollection, error)

func (*PlanQuery) FindOrFail

func (q *PlanQuery) FindOrFail(ctx context.Context, g auth.Grant, id any, columns ...any) (*Plan, error)

func (*PlanQuery) FindOrNew

func (q *PlanQuery) FindOrNew(ctx context.Context, g auth.Grant, id any, columns ...any) (*Plan, error)

func (*PlanQuery) First

func (q *PlanQuery) First(ctx context.Context, g auth.Grant, columns ...any) (*Plan, error)

First returns the first row, or nil and no error when there is none.

func (*PlanQuery) FirstOrCreate

func (q *PlanQuery) FirstOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Plan, error)

func (*PlanQuery) FirstOrFail

func (q *PlanQuery) FirstOrFail(ctx context.Context, g auth.Grant, columns ...any) (*Plan, error)

func (*PlanQuery) FirstOrNew

func (q *PlanQuery) FirstOrNew(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Plan, error)

func (*PlanQuery) FirstWhere

func (q *PlanQuery) FirstWhere(ctx context.Context, g auth.Grant, column any, args ...any) (*Plan, error)

func (*PlanQuery) ForPage

func (q *PlanQuery) ForPage(page, perPage int) *PlanQuery

func (*PlanQuery) ForceCreate

func (q *PlanQuery) ForceCreate(ctx context.Context, g auth.Grant, attributes map[string]any) (*Plan, error)

func (*PlanQuery) Get

func (q *PlanQuery) Get(ctx context.Context, g auth.Grant, columns ...any) (PlanCollection, error)

Get runs the query and returns the rows.

func (*PlanQuery) GroupBy

func (q *PlanQuery) GroupBy(groups ...any) *PlanQuery

func (*PlanQuery) Has

func (q *PlanQuery) Has(relation, operator string, count int, boolean string, callback func(*query.Builder)) *PlanQuery

func (*PlanQuery) Increment

func (q *PlanQuery) Increment(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*PlanQuery) Insert

func (q *PlanQuery) Insert(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*PlanQuery) InsertOrIgnore

func (q *PlanQuery) InsertOrIgnore(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*PlanQuery) Join

func (q *PlanQuery) Join(table any, first any, args ...any) *PlanQuery

func (*PlanQuery) Latest

func (q *PlanQuery) Latest(column ...string) *PlanQuery

func (*PlanQuery) Limit

func (q *PlanQuery) Limit(value int) *PlanQuery

func (*PlanQuery) Max

func (q *PlanQuery) Max(ctx context.Context, g auth.Grant, column any) (any, error)

func (*PlanQuery) Min

func (q *PlanQuery) Min(ctx context.Context, g auth.Grant, column any) (any, error)

func (*PlanQuery) New

func (q *PlanQuery) New() (*Plan, error)

New returns an empty Plan on the query's connection, not yet saved, filled with what WithAttributes recorded on the query.

func (*PlanQuery) Offset

func (q *PlanQuery) Offset(value int) *PlanQuery

func (*PlanQuery) Oldest

func (q *PlanQuery) Oldest(column ...string) *PlanQuery

func (*PlanQuery) OrDoesntHave

func (q *PlanQuery) OrDoesntHave(relation string) *PlanQuery

func (*PlanQuery) OrHas

func (q *PlanQuery) OrHas(relation, operator string, count int) *PlanQuery

func (*PlanQuery) OrWhere

func (q *PlanQuery) OrWhere(column any, args ...any) *PlanQuery

OrWhere adds an or-where clause; a func(*PlanQuery) in place of the column adds a group.

func (*PlanQuery) OrWhereDoesntHave

func (q *PlanQuery) OrWhereDoesntHave(relation string, callback func(*query.Builder)) *PlanQuery

func (*PlanQuery) OrWhereHas

func (q *PlanQuery) OrWhereHas(relation string, callback func(*query.Builder)) *PlanQuery

func (*PlanQuery) OrWhereNot

func (q *PlanQuery) OrWhereNot(column any, args ...any) *PlanQuery

OrWhereNot adds an or-joined negated where clause, or a negated group.

func (*PlanQuery) OrWhereRelation

func (q *PlanQuery) OrWhereRelation(relation string, column any, args ...any) *PlanQuery

func (*PlanQuery) OrderBy

func (q *PlanQuery) OrderBy(column any, direction ...string) *PlanQuery

func (*PlanQuery) OrderByDesc

func (q *PlanQuery) OrderByDesc(column any) *PlanQuery

func (*PlanQuery) Paginate

func (q *PlanQuery) Paginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (PlanCollection, *pagination.LengthAwarePage, error)

func (*PlanQuery) Pluck

func (q *PlanQuery) Pluck(ctx context.Context, g auth.Grant, column string) ([]any, error)

func (*PlanQuery) Select

func (q *PlanQuery) Select(columns ...any) *PlanQuery

func (*PlanQuery) SelectRaw

func (q *PlanQuery) SelectRaw(expression string, bindings ...any) *PlanQuery

func (*PlanQuery) SimplePaginate

func (q *PlanQuery) SimplePaginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (PlanCollection, *pagination.Page, error)

func (*PlanQuery) Sole

func (q *PlanQuery) Sole(ctx context.Context, g auth.Grant, columns ...any) (*Plan, error)

func (*PlanQuery) SoleValue

func (q *PlanQuery) SoleValue(ctx context.Context, g auth.Grant, column string) (any, error)

func (*PlanQuery) Sum

func (q *PlanQuery) Sum(ctx context.Context, g auth.Grant, column any) (any, error)

func (*PlanQuery) Touch

func (q *PlanQuery) Touch(ctx context.Context, g auth.Grant, column ...string) (int64, error)

func (*PlanQuery) Update

func (q *PlanQuery) Update(ctx context.Context, g auth.Grant, values map[string]any) (int64, error)

func (*PlanQuery) UpdateOrCreate

func (q *PlanQuery) UpdateOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Plan, error)

func (*PlanQuery) Upsert

func (q *PlanQuery) Upsert(ctx context.Context, g auth.Grant, values []map[string]any, uniqueBy, update []string) (int64, error)

func (*PlanQuery) Value

func (q *PlanQuery) Value(ctx context.Context, g auth.Grant, column string) (any, error)

func (*PlanQuery) ValueOrFail

func (q *PlanQuery) ValueOrFail(ctx context.Context, g auth.Grant, column string) (any, error)

func (*PlanQuery) Where

func (q *PlanQuery) Where(column any, args ...any) *PlanQuery

Where adds a where clause; a func(*PlanQuery) in place of the column adds a group.

func (*PlanQuery) WhereBelongsTo

func (q *PlanQuery) WhereBelongsTo(relationshipName string, related ...model.Entity) *PlanQuery

func (*PlanQuery) WhereBetween

func (q *PlanQuery) WhereBetween(column any, from, to any) *PlanQuery

func (*PlanQuery) WhereColumn

func (q *PlanQuery) WhereColumn(first any, args ...any) *PlanQuery

func (*PlanQuery) WhereDoesntHave

func (q *PlanQuery) WhereDoesntHave(relation string, callback func(*query.Builder)) *PlanQuery

func (*PlanQuery) WhereExists

func (q *PlanQuery) WhereExists(callback func(*query.Builder)) *PlanQuery

func (*PlanQuery) WhereHas

func (q *PlanQuery) WhereHas(relation string, callback func(*query.Builder)) *PlanQuery

func (*PlanQuery) WhereHasCount

func (q *PlanQuery) WhereHasCount(relation string, callback func(*query.Builder), operator string, count int) *PlanQuery

func (*PlanQuery) WhereIn

func (q *PlanQuery) WhereIn(column any, values []any) *PlanQuery

func (*PlanQuery) WhereKey

func (q *PlanQuery) WhereKey(id any) *PlanQuery

func (*PlanQuery) WhereNot

func (q *PlanQuery) WhereNot(column any, args ...any) *PlanQuery

WhereNot adds a negated where clause, or a negated group.

func (*PlanQuery) WhereNotExists

func (q *PlanQuery) WhereNotExists(callback func(*query.Builder)) *PlanQuery

func (*PlanQuery) WhereNotIn

func (q *PlanQuery) WhereNotIn(column any, values []any) *PlanQuery

func (*PlanQuery) WhereNotNull

func (q *PlanQuery) WhereNotNull(columns ...any) *PlanQuery

func (*PlanQuery) WhereNull

func (q *PlanQuery) WhereNull(columns ...any) *PlanQuery

func (*PlanQuery) WhereRelation

func (q *PlanQuery) WhereRelation(relation string, column any, args ...any) *PlanQuery

func (*PlanQuery) With

func (q *PlanQuery) With(relations ...string) *PlanQuery

func (*PlanQuery) WithAvg

func (q *PlanQuery) WithAvg(relation, column string) *PlanQuery

func (*PlanQuery) WithCount

func (q *PlanQuery) WithCount(relations ...string) *PlanQuery

func (*PlanQuery) WithExists

func (q *PlanQuery) WithExists(relation string) *PlanQuery

func (*PlanQuery) WithMax

func (q *PlanQuery) WithMax(relation, column string) *PlanQuery

func (*PlanQuery) WithMin

func (q *PlanQuery) WithMin(relation, column string) *PlanQuery

func (*PlanQuery) WithSum

func (q *PlanQuery) WithSum(relation, column string) *PlanQuery

func (*PlanQuery) Without

func (q *PlanQuery) Without(relations ...string) *PlanQuery

func (*PlanQuery) WithoutGlobalScope

func (q *PlanQuery) WithoutGlobalScope(identifier string) *PlanQuery

func (*PlanQuery) WithoutGlobalScopes

func (q *PlanQuery) WithoutGlobalScopes(identifiers ...string) *PlanQuery

type PlanRequest

type PlanRequest struct {
	Name string
	Kind PlanKind
	// Rates are the basis points of each level, the first level first: one
	// for a linear plan, one to MaxLevels for a multilevel one.
	Rates []int64
	// CookieDays is how long the referral cookie lives. Zero means
	// DefaultCookieDays.
	CookieDays int
	// MinWithdrawal and MaxWithdrawal are centavos; a max of zero is no max.
	MinWithdrawal int64
	MaxWithdrawal int64
}

PlanRequest is what defining a commission plan takes.

func (PlanRequest) Validate

func (r PlanRequest) Validate() validation.Errors

Validate reports the errors per field.

type PlanRow

type PlanRow struct {
	ID, Name, Kind, KindKey, Min, Max, Created, ActivateURL string
	CookieDays                                              int
	Levels                                                  []LevelRow
	Active                                                  bool
}

PlanRow is a plan as a screen shows it.

type PlanView

type PlanView struct {
	Plan   Plan
	Levels []PlanLevel
}

PlanView is a plan with its levels, the first level first.

func (PlanView) Rate

func (p PlanView) Rate(level int) int64

Rate is the basis points a level pays, zero for a level the plan does not pay.

type Referral

type Referral struct {
	model.Model

	ID       string `db:"id"`
	TenantID string `db:"tenant_id"`

	// UserID is the user who was referred, unique per tenant: a user has one
	// referrer, for life.
	UserID string `db:"user_id"`

	// AffiliateID is the affiliate who referred them.
	AffiliateID string `db:"affiliate_id"`

	// Document is the user's CPF or CNPJ when the application knows it, digits
	// only and unique per tenant when present, so one person is not referred
	// twice under two accounts.
	Document OptionalText `db:"document"`

	// Code is the code the user signed up with.
	Code string `db:"code"`

	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

Referral is the lifelong link of a user to the affiliate who referred them.

It is written once, when the user signs up with a referral code, and never changes: the cookie that carried the code only decides who the referrer is at that moment. Every payment of the user afterwards -- the first purchase and every renewal -- pays a commission up the tree that starts here.

func (*Referral) Fresh

func (row *Referral) Fresh(ctx context.Context, g auth.Grant, with ...string) (*Referral, error)

Fresh reads the row again, as a new Referral; it shadows the untyped one the embedded model promotes.

func (*Referral) Replicate

func (row *Referral) Replicate(except ...string) (*Referral, error)

Replicate returns an unsaved copy of the row without its key; it shadows the untyped one the embedded model promotes.

type ReferralCollection

type ReferralCollection []*Referral

ReferralCollection is rows of Referral, as a query returns them.

func ReferralCollectionOf

func ReferralCollectionOf(rows model.Rows) ReferralCollection

ReferralCollectionOf converts rows of the table of Referral. A nil input is a nil collection.

func (ReferralCollection) Contains

func (c ReferralCollection) Contains(key any) bool

func (ReferralCollection) Except

func (c ReferralCollection) Except(keys ...any) ReferralCollection

func (ReferralCollection) Find

func (c ReferralCollection) Find(key any) *Referral

func (ReferralCollection) FindOrFail

func (c ReferralCollection) FindOrFail(key any) (*Referral, error)

func (ReferralCollection) Fresh

func (ReferralCollection) Load

func (c ReferralCollection) Load(ctx context.Context, g auth.Grant, relations ...string) error

func (ReferralCollection) LoadCount

func (c ReferralCollection) LoadCount(ctx context.Context, g auth.Grant, relations ...string) error

func (ReferralCollection) LoadMissing

func (c ReferralCollection) LoadMissing(ctx context.Context, g auth.Grant, relations ...string) error

func (ReferralCollection) ModelKeys

func (c ReferralCollection) ModelKeys() []any

func (ReferralCollection) Only

func (c ReferralCollection) Only(keys ...any) ReferralCollection

func (ReferralCollection) Pluck

func (c ReferralCollection) Pluck(column string) []any

func (ReferralCollection) Rows

func (c ReferralCollection) Rows() model.Rows

Rows converts the collection back to the core's rows.

func (ReferralCollection) ToArray

func (c ReferralCollection) ToArray() []map[string]any

func (ReferralCollection) Unique

type ReferralQuery

type ReferralQuery struct {
	// contains filtered or unexported fields
}

ReferralQuery is a query on the table of Referral.

The methods that build return the query, so they chain. The methods that run take a context and an auth.Grant, and return Referral rows or a value; there is no way to run one without a Grant.

func Referrals

func Referrals(db model.DB) *ReferralQuery

Referrals starts a query on the table of Referral, through db.

Global scopes are on and, unless the table is Global, every statement is filtered by the tenant of the Grant its terminal takes.

func (*ReferralQuery) AddSelect

func (q *ReferralQuery) AddSelect(columns ...any) *ReferralQuery

func (*ReferralQuery) Avg

func (q *ReferralQuery) Avg(ctx context.Context, g auth.Grant, column any) (any, error)

func (*ReferralQuery) Base

func (q *ReferralQuery) Base() *model.Builder

Base returns the core builder the query forwards to. It is for code in this package -- a local scope in the custom block of referral.go -- and for the factory, which builds rows through it.

func (*ReferralQuery) Chunk

func (q *ReferralQuery) Chunk(ctx context.Context, g auth.Grant, count int, callback func(ReferralCollection, int) (bool, error)) error

func (*ReferralQuery) Clone

func (q *ReferralQuery) Clone() *ReferralQuery

Clone returns an independent copy of the query.

func (*ReferralQuery) Count

func (q *ReferralQuery) Count(ctx context.Context, g auth.Grant, columns ...any) (int64, error)

func (*ReferralQuery) Create

func (q *ReferralQuery) Create(ctx context.Context, g auth.Grant, attributes map[string]any) (*Referral, error)

func (*ReferralQuery) Cursor

func (q *ReferralQuery) Cursor(ctx context.Context, g auth.Grant) iter.Seq2[*Referral, error]

func (*ReferralQuery) CursorPaginate

func (q *ReferralQuery) CursorPaginate(ctx context.Context, g auth.Grant, perPage int, cursor *pagination.Cursor, opts pagination.Options, columns ...any) (ReferralCollection, *pagination.CursorPage, error)

func (*ReferralQuery) Decrement

func (q *ReferralQuery) Decrement(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*ReferralQuery) Delete

func (q *ReferralQuery) Delete(ctx context.Context, g auth.Grant) (int64, error)

func (*ReferralQuery) DoesntExist

func (q *ReferralQuery) DoesntExist(ctx context.Context, g auth.Grant) (bool, error)

func (*ReferralQuery) DoesntHave

func (q *ReferralQuery) DoesntHave(relation, boolean string, callback func(*query.Builder)) *ReferralQuery

func (*ReferralQuery) Each

func (q *ReferralQuery) Each(ctx context.Context, g auth.Grant, count int, callback func(*Referral, int) (bool, error)) error

func (*ReferralQuery) Exists

func (q *ReferralQuery) Exists(ctx context.Context, g auth.Grant) (bool, error)

func (*ReferralQuery) Find

func (q *ReferralQuery) Find(ctx context.Context, g auth.Grant, id any, columns ...any) (*Referral, error)

func (*ReferralQuery) FindMany

func (q *ReferralQuery) FindMany(ctx context.Context, g auth.Grant, ids []any, columns ...any) (ReferralCollection, error)

func (*ReferralQuery) FindOrFail

func (q *ReferralQuery) FindOrFail(ctx context.Context, g auth.Grant, id any, columns ...any) (*Referral, error)

func (*ReferralQuery) FindOrNew

func (q *ReferralQuery) FindOrNew(ctx context.Context, g auth.Grant, id any, columns ...any) (*Referral, error)

func (*ReferralQuery) First

func (q *ReferralQuery) First(ctx context.Context, g auth.Grant, columns ...any) (*Referral, error)

First returns the first row, or nil and no error when there is none.

func (*ReferralQuery) FirstOrCreate

func (q *ReferralQuery) FirstOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Referral, error)

func (*ReferralQuery) FirstOrFail

func (q *ReferralQuery) FirstOrFail(ctx context.Context, g auth.Grant, columns ...any) (*Referral, error)

func (*ReferralQuery) FirstOrNew

func (q *ReferralQuery) FirstOrNew(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Referral, error)

func (*ReferralQuery) FirstWhere

func (q *ReferralQuery) FirstWhere(ctx context.Context, g auth.Grant, column any, args ...any) (*Referral, error)

func (*ReferralQuery) ForPage

func (q *ReferralQuery) ForPage(page, perPage int) *ReferralQuery

func (*ReferralQuery) ForceCreate

func (q *ReferralQuery) ForceCreate(ctx context.Context, g auth.Grant, attributes map[string]any) (*Referral, error)

func (*ReferralQuery) Get

func (q *ReferralQuery) Get(ctx context.Context, g auth.Grant, columns ...any) (ReferralCollection, error)

Get runs the query and returns the rows.

func (*ReferralQuery) GroupBy

func (q *ReferralQuery) GroupBy(groups ...any) *ReferralQuery

func (*ReferralQuery) Has

func (q *ReferralQuery) Has(relation, operator string, count int, boolean string, callback func(*query.Builder)) *ReferralQuery

func (*ReferralQuery) Increment

func (q *ReferralQuery) Increment(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*ReferralQuery) Insert

func (q *ReferralQuery) Insert(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*ReferralQuery) InsertOrIgnore

func (q *ReferralQuery) InsertOrIgnore(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*ReferralQuery) Join

func (q *ReferralQuery) Join(table any, first any, args ...any) *ReferralQuery

func (*ReferralQuery) Latest

func (q *ReferralQuery) Latest(column ...string) *ReferralQuery

func (*ReferralQuery) Limit

func (q *ReferralQuery) Limit(value int) *ReferralQuery

func (*ReferralQuery) Max

func (q *ReferralQuery) Max(ctx context.Context, g auth.Grant, column any) (any, error)

func (*ReferralQuery) Min

func (q *ReferralQuery) Min(ctx context.Context, g auth.Grant, column any) (any, error)

func (*ReferralQuery) New

func (q *ReferralQuery) New() (*Referral, error)

New returns an empty Referral on the query's connection, not yet saved, filled with what WithAttributes recorded on the query.

func (*ReferralQuery) Offset

func (q *ReferralQuery) Offset(value int) *ReferralQuery

func (*ReferralQuery) Oldest

func (q *ReferralQuery) Oldest(column ...string) *ReferralQuery

func (*ReferralQuery) OrDoesntHave

func (q *ReferralQuery) OrDoesntHave(relation string) *ReferralQuery

func (*ReferralQuery) OrHas

func (q *ReferralQuery) OrHas(relation, operator string, count int) *ReferralQuery

func (*ReferralQuery) OrWhere

func (q *ReferralQuery) OrWhere(column any, args ...any) *ReferralQuery

OrWhere adds an or-where clause; a func(*ReferralQuery) in place of the column adds a group.

func (*ReferralQuery) OrWhereDoesntHave

func (q *ReferralQuery) OrWhereDoesntHave(relation string, callback func(*query.Builder)) *ReferralQuery

func (*ReferralQuery) OrWhereHas

func (q *ReferralQuery) OrWhereHas(relation string, callback func(*query.Builder)) *ReferralQuery

func (*ReferralQuery) OrWhereNot

func (q *ReferralQuery) OrWhereNot(column any, args ...any) *ReferralQuery

OrWhereNot adds an or-joined negated where clause, or a negated group.

func (*ReferralQuery) OrWhereRelation

func (q *ReferralQuery) OrWhereRelation(relation string, column any, args ...any) *ReferralQuery

func (*ReferralQuery) OrderBy

func (q *ReferralQuery) OrderBy(column any, direction ...string) *ReferralQuery

func (*ReferralQuery) OrderByDesc

func (q *ReferralQuery) OrderByDesc(column any) *ReferralQuery

func (*ReferralQuery) Paginate

func (q *ReferralQuery) Paginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (ReferralCollection, *pagination.LengthAwarePage, error)

func (*ReferralQuery) Pluck

func (q *ReferralQuery) Pluck(ctx context.Context, g auth.Grant, column string) ([]any, error)

func (*ReferralQuery) Select

func (q *ReferralQuery) Select(columns ...any) *ReferralQuery

func (*ReferralQuery) SelectRaw

func (q *ReferralQuery) SelectRaw(expression string, bindings ...any) *ReferralQuery

func (*ReferralQuery) SimplePaginate

func (q *ReferralQuery) SimplePaginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (ReferralCollection, *pagination.Page, error)

func (*ReferralQuery) Sole

func (q *ReferralQuery) Sole(ctx context.Context, g auth.Grant, columns ...any) (*Referral, error)

func (*ReferralQuery) SoleValue

func (q *ReferralQuery) SoleValue(ctx context.Context, g auth.Grant, column string) (any, error)

func (*ReferralQuery) Sum

func (q *ReferralQuery) Sum(ctx context.Context, g auth.Grant, column any) (any, error)

func (*ReferralQuery) Touch

func (q *ReferralQuery) Touch(ctx context.Context, g auth.Grant, column ...string) (int64, error)

func (*ReferralQuery) Update

func (q *ReferralQuery) Update(ctx context.Context, g auth.Grant, values map[string]any) (int64, error)

func (*ReferralQuery) UpdateOrCreate

func (q *ReferralQuery) UpdateOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*Referral, error)

func (*ReferralQuery) Upsert

func (q *ReferralQuery) Upsert(ctx context.Context, g auth.Grant, values []map[string]any, uniqueBy, update []string) (int64, error)

func (*ReferralQuery) Value

func (q *ReferralQuery) Value(ctx context.Context, g auth.Grant, column string) (any, error)

func (*ReferralQuery) ValueOrFail

func (q *ReferralQuery) ValueOrFail(ctx context.Context, g auth.Grant, column string) (any, error)

func (*ReferralQuery) Where

func (q *ReferralQuery) Where(column any, args ...any) *ReferralQuery

Where adds a where clause; a func(*ReferralQuery) in place of the column adds a group.

func (*ReferralQuery) WhereBelongsTo

func (q *ReferralQuery) WhereBelongsTo(relationshipName string, related ...model.Entity) *ReferralQuery

func (*ReferralQuery) WhereBetween

func (q *ReferralQuery) WhereBetween(column any, from, to any) *ReferralQuery

func (*ReferralQuery) WhereColumn

func (q *ReferralQuery) WhereColumn(first any, args ...any) *ReferralQuery

func (*ReferralQuery) WhereDoesntHave

func (q *ReferralQuery) WhereDoesntHave(relation string, callback func(*query.Builder)) *ReferralQuery

func (*ReferralQuery) WhereExists

func (q *ReferralQuery) WhereExists(callback func(*query.Builder)) *ReferralQuery

func (*ReferralQuery) WhereHas

func (q *ReferralQuery) WhereHas(relation string, callback func(*query.Builder)) *ReferralQuery

func (*ReferralQuery) WhereHasCount

func (q *ReferralQuery) WhereHasCount(relation string, callback func(*query.Builder), operator string, count int) *ReferralQuery

func (*ReferralQuery) WhereIn

func (q *ReferralQuery) WhereIn(column any, values []any) *ReferralQuery

func (*ReferralQuery) WhereKey

func (q *ReferralQuery) WhereKey(id any) *ReferralQuery

func (*ReferralQuery) WhereNot

func (q *ReferralQuery) WhereNot(column any, args ...any) *ReferralQuery

WhereNot adds a negated where clause, or a negated group.

func (*ReferralQuery) WhereNotExists

func (q *ReferralQuery) WhereNotExists(callback func(*query.Builder)) *ReferralQuery

func (*ReferralQuery) WhereNotIn

func (q *ReferralQuery) WhereNotIn(column any, values []any) *ReferralQuery

func (*ReferralQuery) WhereNotNull

func (q *ReferralQuery) WhereNotNull(columns ...any) *ReferralQuery

func (*ReferralQuery) WhereNull

func (q *ReferralQuery) WhereNull(columns ...any) *ReferralQuery

func (*ReferralQuery) WhereRelation

func (q *ReferralQuery) WhereRelation(relation string, column any, args ...any) *ReferralQuery

func (*ReferralQuery) With

func (q *ReferralQuery) With(relations ...string) *ReferralQuery

func (*ReferralQuery) WithAvg

func (q *ReferralQuery) WithAvg(relation, column string) *ReferralQuery

func (*ReferralQuery) WithCount

func (q *ReferralQuery) WithCount(relations ...string) *ReferralQuery

func (*ReferralQuery) WithExists

func (q *ReferralQuery) WithExists(relation string) *ReferralQuery

func (*ReferralQuery) WithMax

func (q *ReferralQuery) WithMax(relation, column string) *ReferralQuery

func (*ReferralQuery) WithMin

func (q *ReferralQuery) WithMin(relation, column string) *ReferralQuery

func (*ReferralQuery) WithSum

func (q *ReferralQuery) WithSum(relation, column string) *ReferralQuery

func (*ReferralQuery) Without

func (q *ReferralQuery) Without(relations ...string) *ReferralQuery

func (*ReferralQuery) WithoutGlobalScope

func (q *ReferralQuery) WithoutGlobalScope(identifier string) *ReferralQuery

func (*ReferralQuery) WithoutGlobalScopes

func (q *ReferralQuery) WithoutGlobalScopes(identifiers ...string) *ReferralQuery

type Screen

type Screen struct {
	view.Page
	Labels Labels
	Prefix string
}

Screen is what every page of this package carries: the application's chrome, the sentences, and where the package is mounted.

func (Screen) AdminNav

func (s Screen) AdminNav(current string) template.HTML

AdminNav is the bar on top of every admin screen, the current list marked.

func (Screen) AffiliateStatusOptions

func (s Screen) AffiliateStatusOptions() []components.SelectOption

AffiliateStatusOptions are where an affiliate can stand.

func (Screen) CellForm

func (s Screen) CellForm(action, label, variant string, inputs ...CellInput) template.HTML

CellForm is a small form posted from a table cell: the CSRF token of the page, the fields given, and one button. Every value is escaped.

func (Screen) CommissionStatusOptions

func (s Screen) CommissionStatusOptions() []components.SelectOption

CommissionStatusOptions are where a commission can stand.

func (Screen) Form

func (s Screen) Form() FormState

Form is the form state of the page.

func (Screen) LevelOptions

func (s Screen) LevelOptions() []components.SelectOption

LevelOptions are the levels a commission can be of.

func (Screen) PayoutKindOptions

func (s Screen) PayoutKindOptions() []components.SelectOption

PayoutKindOptions are the kinds of payout account.

func (Screen) PixKeyOptions

func (s Screen) PixKeyOptions() []components.SelectOption

PixKeyOptions are the kinds of PIX key.

func (Screen) PlanKindOptions

func (s Screen) PlanKindOptions() []components.SelectOption

PlanKindOptions are the kinds of plan.

func (Screen) TableLines

func (s Screen) TableLines() components.DataTableLines

TableLines are the sentences a data table on these screens says.

func (Screen) WithdrawalStatusOptions

func (s Screen) WithdrawalStatusOptions() []components.SelectOption

WithdrawalStatusOptions are where a withdrawal request can stand.

type Stats

type Stats struct {
	Clicks, Signups, Sales int64
	Commissions            int64
}

Stats are an affiliate's numbers over a period.

type TableState

type TableState struct {
	URL, Query, Sort, Dir     string
	CurrentPage, Pages, Total int
}

TableState is a server-paged list: the filters in force and where the page is.

type TreeNode

type TreeNode struct {
	Level       int
	UserID      string
	ParentID    string
	AffiliateID string
	Name        string
	Code        string
	Status      AffiliateStatus
	JoinedAt    time.Time
}

TreeNode is one person in an affiliate's tree.

type TreeRow

type TreeRow struct {
	Level                                 int
	User, Name, Code, Status, Joined, URL string
}

TreeRow is one person in an affiliate's tree.

type WithdrawalDay

type WithdrawalDay struct {
	model.Model

	ID                  string    `db:"id"`
	TenantID            string    `db:"tenant_id"`
	AffiliateID         string    `db:"affiliate_id"`
	Day                 Day       `db:"day"`
	WithdrawalRequestID string    `db:"withdrawal_request_id"`
	Attempt             int       `db:"attempt"`
	CreatedAt           time.Time `db:"created_at"`
	UpdatedAt           time.Time `db:"updated_at"`
}

WithdrawalDay is the one withdrawal an affiliate asked for on a day. Its unique index is what holds the rule of one a day under two requests sent at once; a request of the day that was rejected or cancelled frees the day.

func (*WithdrawalDay) Fresh

func (row *WithdrawalDay) Fresh(ctx context.Context, g auth.Grant, with ...string) (*WithdrawalDay, error)

Fresh reads the row again, as a new WithdrawalDay; it shadows the untyped one the embedded model promotes.

func (*WithdrawalDay) Replicate

func (row *WithdrawalDay) Replicate(except ...string) (*WithdrawalDay, error)

Replicate returns an unsaved copy of the row without its key; it shadows the untyped one the embedded model promotes.

type WithdrawalDayCollection

type WithdrawalDayCollection []*WithdrawalDay

WithdrawalDayCollection is rows of WithdrawalDay, as a query returns them.

func WithdrawalDayCollectionOf

func WithdrawalDayCollectionOf(rows model.Rows) WithdrawalDayCollection

WithdrawalDayCollectionOf converts rows of the table of WithdrawalDay. A nil input is a nil collection.

func (WithdrawalDayCollection) Contains

func (c WithdrawalDayCollection) Contains(key any) bool

func (WithdrawalDayCollection) Except

func (WithdrawalDayCollection) Find

func (WithdrawalDayCollection) FindOrFail

func (c WithdrawalDayCollection) FindOrFail(key any) (*WithdrawalDay, error)

func (WithdrawalDayCollection) Fresh

func (WithdrawalDayCollection) Load

func (c WithdrawalDayCollection) Load(ctx context.Context, g auth.Grant, relations ...string) error

func (WithdrawalDayCollection) LoadCount

func (c WithdrawalDayCollection) LoadCount(ctx context.Context, g auth.Grant, relations ...string) error

func (WithdrawalDayCollection) LoadMissing

func (c WithdrawalDayCollection) LoadMissing(ctx context.Context, g auth.Grant, relations ...string) error

func (WithdrawalDayCollection) ModelKeys

func (c WithdrawalDayCollection) ModelKeys() []any

func (WithdrawalDayCollection) Only

func (WithdrawalDayCollection) Pluck

func (c WithdrawalDayCollection) Pluck(column string) []any

func (WithdrawalDayCollection) Rows

Rows converts the collection back to the core's rows.

func (WithdrawalDayCollection) ToArray

func (c WithdrawalDayCollection) ToArray() []map[string]any

func (WithdrawalDayCollection) Unique

type WithdrawalDayQuery

type WithdrawalDayQuery struct {
	// contains filtered or unexported fields
}

WithdrawalDayQuery is a query on the table of WithdrawalDay.

The methods that build return the query, so they chain. The methods that run take a context and an auth.Grant, and return WithdrawalDay rows or a value; there is no way to run one without a Grant.

func WithdrawalDays

func WithdrawalDays(db model.DB) *WithdrawalDayQuery

WithdrawalDays starts a query on the table of WithdrawalDay, through db.

Global scopes are on and, unless the table is Global, every statement is filtered by the tenant of the Grant its terminal takes.

func (*WithdrawalDayQuery) AddSelect

func (q *WithdrawalDayQuery) AddSelect(columns ...any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) Avg

func (q *WithdrawalDayQuery) Avg(ctx context.Context, g auth.Grant, column any) (any, error)

func (*WithdrawalDayQuery) Base

func (q *WithdrawalDayQuery) Base() *model.Builder

Base returns the core builder the query forwards to. It is for code in this package -- a local scope in the custom block of ledger.go -- and for the factory, which builds rows through it.

func (*WithdrawalDayQuery) Chunk

func (q *WithdrawalDayQuery) Chunk(ctx context.Context, g auth.Grant, count int, callback func(WithdrawalDayCollection, int) (bool, error)) error

func (*WithdrawalDayQuery) Clone

Clone returns an independent copy of the query.

func (*WithdrawalDayQuery) Count

func (q *WithdrawalDayQuery) Count(ctx context.Context, g auth.Grant, columns ...any) (int64, error)

func (*WithdrawalDayQuery) Create

func (q *WithdrawalDayQuery) Create(ctx context.Context, g auth.Grant, attributes map[string]any) (*WithdrawalDay, error)

func (*WithdrawalDayQuery) Cursor

func (*WithdrawalDayQuery) CursorPaginate

func (q *WithdrawalDayQuery) CursorPaginate(ctx context.Context, g auth.Grant, perPage int, cursor *pagination.Cursor, opts pagination.Options, columns ...any) (WithdrawalDayCollection, *pagination.CursorPage, error)

func (*WithdrawalDayQuery) Decrement

func (q *WithdrawalDayQuery) Decrement(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*WithdrawalDayQuery) Delete

func (q *WithdrawalDayQuery) Delete(ctx context.Context, g auth.Grant) (int64, error)

func (*WithdrawalDayQuery) DoesntExist

func (q *WithdrawalDayQuery) DoesntExist(ctx context.Context, g auth.Grant) (bool, error)

func (*WithdrawalDayQuery) DoesntHave

func (q *WithdrawalDayQuery) DoesntHave(relation, boolean string, callback func(*query.Builder)) *WithdrawalDayQuery

func (*WithdrawalDayQuery) Each

func (q *WithdrawalDayQuery) Each(ctx context.Context, g auth.Grant, count int, callback func(*WithdrawalDay, int) (bool, error)) error

func (*WithdrawalDayQuery) Exists

func (q *WithdrawalDayQuery) Exists(ctx context.Context, g auth.Grant) (bool, error)

func (*WithdrawalDayQuery) Find

func (q *WithdrawalDayQuery) Find(ctx context.Context, g auth.Grant, id any, columns ...any) (*WithdrawalDay, error)

func (*WithdrawalDayQuery) FindMany

func (q *WithdrawalDayQuery) FindMany(ctx context.Context, g auth.Grant, ids []any, columns ...any) (WithdrawalDayCollection, error)

func (*WithdrawalDayQuery) FindOrFail

func (q *WithdrawalDayQuery) FindOrFail(ctx context.Context, g auth.Grant, id any, columns ...any) (*WithdrawalDay, error)

func (*WithdrawalDayQuery) FindOrNew

func (q *WithdrawalDayQuery) FindOrNew(ctx context.Context, g auth.Grant, id any, columns ...any) (*WithdrawalDay, error)

func (*WithdrawalDayQuery) First

func (q *WithdrawalDayQuery) First(ctx context.Context, g auth.Grant, columns ...any) (*WithdrawalDay, error)

First returns the first row, or nil and no error when there is none.

func (*WithdrawalDayQuery) FirstOrCreate

func (q *WithdrawalDayQuery) FirstOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*WithdrawalDay, error)

func (*WithdrawalDayQuery) FirstOrFail

func (q *WithdrawalDayQuery) FirstOrFail(ctx context.Context, g auth.Grant, columns ...any) (*WithdrawalDay, error)

func (*WithdrawalDayQuery) FirstOrNew

func (q *WithdrawalDayQuery) FirstOrNew(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*WithdrawalDay, error)

func (*WithdrawalDayQuery) FirstWhere

func (q *WithdrawalDayQuery) FirstWhere(ctx context.Context, g auth.Grant, column any, args ...any) (*WithdrawalDay, error)

func (*WithdrawalDayQuery) ForPage

func (q *WithdrawalDayQuery) ForPage(page, perPage int) *WithdrawalDayQuery

func (*WithdrawalDayQuery) ForceCreate

func (q *WithdrawalDayQuery) ForceCreate(ctx context.Context, g auth.Grant, attributes map[string]any) (*WithdrawalDay, error)

func (*WithdrawalDayQuery) Get

Get runs the query and returns the rows.

func (*WithdrawalDayQuery) GroupBy

func (q *WithdrawalDayQuery) GroupBy(groups ...any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) Has

func (q *WithdrawalDayQuery) Has(relation, operator string, count int, boolean string, callback func(*query.Builder)) *WithdrawalDayQuery

func (*WithdrawalDayQuery) Increment

func (q *WithdrawalDayQuery) Increment(ctx context.Context, g auth.Grant, column string, amount any, extra map[string]any) (int64, error)

func (*WithdrawalDayQuery) Insert

func (q *WithdrawalDayQuery) Insert(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*WithdrawalDayQuery) InsertOrIgnore

func (q *WithdrawalDayQuery) InsertOrIgnore(ctx context.Context, g auth.Grant, values ...map[string]any) (bool, error)

func (*WithdrawalDayQuery) Join

func (q *WithdrawalDayQuery) Join(table any, first any, args ...any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) Latest

func (q *WithdrawalDayQuery) Latest(column ...string) *WithdrawalDayQuery

func (*WithdrawalDayQuery) Limit

func (q *WithdrawalDayQuery) Limit(value int) *WithdrawalDayQuery

func (*WithdrawalDayQuery) Max

func (q *WithdrawalDayQuery) Max(ctx context.Context, g auth.Grant, column any) (any, error)

func (*WithdrawalDayQuery) Min

func (q *WithdrawalDayQuery) Min(ctx context.Context, g auth.Grant, column any) (any, error)

func (*WithdrawalDayQuery) New

func (q *WithdrawalDayQuery) New() (*WithdrawalDay, error)

New returns an empty WithdrawalDay on the query's connection, not yet saved, filled with what WithAttributes recorded on the query.

func (*WithdrawalDayQuery) Offset

func (q *WithdrawalDayQuery) Offset(value int) *WithdrawalDayQuery

func (*WithdrawalDayQuery) Oldest

func (q *WithdrawalDayQuery) Oldest(column ...string) *WithdrawalDayQuery

func (*WithdrawalDayQuery) OrDoesntHave

func (q *WithdrawalDayQuery) OrDoesntHave(relation string) *WithdrawalDayQuery

func (*WithdrawalDayQuery) OrHas

func (q *WithdrawalDayQuery) OrHas(relation, operator string, count int) *WithdrawalDayQuery

func (*WithdrawalDayQuery) OrWhere

func (q *WithdrawalDayQuery) OrWhere(column any, args ...any) *WithdrawalDayQuery

OrWhere adds an or-where clause; a func(*WithdrawalDayQuery) in place of the column adds a group.

func (*WithdrawalDayQuery) OrWhereDoesntHave

func (q *WithdrawalDayQuery) OrWhereDoesntHave(relation string, callback func(*query.Builder)) *WithdrawalDayQuery

func (*WithdrawalDayQuery) OrWhereHas

func (q *WithdrawalDayQuery) OrWhereHas(relation string, callback func(*query.Builder)) *WithdrawalDayQuery

func (*WithdrawalDayQuery) OrWhereNot

func (q *WithdrawalDayQuery) OrWhereNot(column any, args ...any) *WithdrawalDayQuery

OrWhereNot adds an or-joined negated where clause, or a negated group.

func (*WithdrawalDayQuery) OrWhereRelation

func (q *WithdrawalDayQuery) OrWhereRelation(relation string, column any, args ...any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) OrderBy

func (q *WithdrawalDayQuery) OrderBy(column any, direction ...string) *WithdrawalDayQuery

func (*WithdrawalDayQuery) OrderByDesc

func (q *WithdrawalDayQuery) OrderByDesc(column any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) Paginate

func (q *WithdrawalDayQuery) Paginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (WithdrawalDayCollection, *pagination.LengthAwarePage, error)

func (*WithdrawalDayQuery) Pluck

func (q *WithdrawalDayQuery) Pluck(ctx context.Context, g auth.Grant, column string) ([]any, error)

func (*WithdrawalDayQuery) Select

func (q *WithdrawalDayQuery) Select(columns ...any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) SelectRaw

func (q *WithdrawalDayQuery) SelectRaw(expression string, bindings ...any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) SimplePaginate

func (q *WithdrawalDayQuery) SimplePaginate(ctx context.Context, g auth.Grant, perPage, page int, opts pagination.Options, columns ...any) (WithdrawalDayCollection, *pagination.Page, error)

func (*WithdrawalDayQuery) Sole

func (q *WithdrawalDayQuery) Sole(ctx context.Context, g auth.Grant, columns ...any) (*WithdrawalDay, error)

func (*WithdrawalDayQuery) SoleValue

func (q *WithdrawalDayQuery) SoleValue(ctx context.Context, g auth.Grant, column string) (any, error)

func (*WithdrawalDayQuery) Sum

func (q *WithdrawalDayQuery) Sum(ctx context.Context, g auth.Grant, column any) (any, error)

func (*WithdrawalDayQuery) Touch

func (q *WithdrawalDayQuery) Touch(ctx context.Context, g auth.Grant, column ...string) (int64, error)

func (*WithdrawalDayQuery) Update

func (q *WithdrawalDayQuery) Update(ctx context.Context, g auth.Grant, values map[string]any) (int64, error)

func (*WithdrawalDayQuery) UpdateOrCreate

func (q *WithdrawalDayQuery) UpdateOrCreate(ctx context.Context, g auth.Grant, attributes, values map[string]any) (*WithdrawalDay, error)

func (*WithdrawalDayQuery) Upsert

func (q *WithdrawalDayQuery) Upsert(ctx context.Context, g auth.Grant, values []map[string]any, uniqueBy, update []string) (int64, error)

func (*WithdrawalDayQuery) Value

func (q *WithdrawalDayQuery) Value(ctx context.Context, g auth.Grant, column string) (any, error)

func (*WithdrawalDayQuery) ValueOrFail

func (q *WithdrawalDayQuery) ValueOrFail(ctx context.Context, g auth.Grant, column string) (any, error)

func (*WithdrawalDayQuery) Where

func (q *WithdrawalDayQuery) Where(column any, args ...any) *WithdrawalDayQuery

Where adds a where clause; a func(*WithdrawalDayQuery) in place of the column adds a group.

func (*WithdrawalDayQuery) WhereBelongsTo

func (q *WithdrawalDayQuery) WhereBelongsTo(relationshipName string, related ...model.Entity) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WhereBetween

func (q *WithdrawalDayQuery) WhereBetween(column any, from, to any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WhereColumn

func (q *WithdrawalDayQuery) WhereColumn(first any, args ...any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WhereDoesntHave

func (q *WithdrawalDayQuery) WhereDoesntHave(relation string, callback func(*query.Builder)) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WhereExists

func (q *WithdrawalDayQuery) WhereExists(callback func(*query.Builder)) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WhereHas

func (q *WithdrawalDayQuery) WhereHas(relation string, callback func(*query.Builder)) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WhereHasCount

func (q *WithdrawalDayQuery) WhereHasCount(relation string, callback func(*query.Builder), operator string, count int) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WhereIn

func (q *WithdrawalDayQuery) WhereIn(column any, values []any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WhereKey

func (q *WithdrawalDayQuery) WhereKey(id any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WhereNot

func (q *WithdrawalDayQuery) WhereNot(column any, args ...any) *WithdrawalDayQuery

WhereNot adds a negated where clause, or a negated group.

func (*WithdrawalDayQuery) WhereNotExists

func (q *WithdrawalDayQuery) WhereNotExists(callback func(*query.Builder)) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WhereNotIn

func (q *WithdrawalDayQuery) WhereNotIn(column any, values []any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WhereNotNull

func (q *WithdrawalDayQuery) WhereNotNull(columns ...any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WhereNull

func (q *WithdrawalDayQuery) WhereNull(columns ...any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WhereRelation

func (q *WithdrawalDayQuery) WhereRelation(relation string, column any, args ...any) *WithdrawalDayQuery

func (*WithdrawalDayQuery) With

func (q *WithdrawalDayQuery) With(relations ...string) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WithAvg

func (q *WithdrawalDayQuery) WithAvg(relation, column string) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WithCount

func (q *WithdrawalDayQuery) WithCount(relations ...string) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WithExists

func (q *WithdrawalDayQuery) WithExists(relation string) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WithMax

func (q *WithdrawalDayQuery) WithMax(relation, column string) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WithMin

func (q *WithdrawalDayQuery) WithMin(relation, column string) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WithSum

func (q *WithdrawalDayQuery) WithSum(relation, column string) *WithdrawalDayQuery

func (*WithdrawalDayQuery) Without

func (q *WithdrawalDayQuery) Without(relations ...string) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WithoutGlobalScope

func (q *WithdrawalDayQuery) WithoutGlobalScope(identifier string) *WithdrawalDayQuery

func (*WithdrawalDayQuery) WithoutGlobalScopes

func (q *WithdrawalDayQuery) WithoutGlobalScopes(identifiers ...string) *WithdrawalDayQuery

type WithdrawalRequest

type WithdrawalRequest struct {
	// Amount is centavos; zero asks for everything available.
	Amount    int64
	AccountID string
}

WithdrawalRequest is what an affiliate asks for.

type WithdrawalRow

type WithdrawalRow struct {
	ID, Affiliate, AffiliateURL, Amount, Account, Status, StatusKey, RequestedAt, Reason string
	Open, Processing, Paid                                                               bool
	ProcessURL, PayURL, RejectURL, ReceiptURL                                            string
}

WithdrawalRow is one withdrawal request as a screen shows it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL