accounts

package
v0.0.0-...-6d8854b Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAccountDomain

func NewAccountDomain() *accountDomain

Types

type Account

type Account struct {
	// db tag 自定义结构体字段映射数据库表字段名称
	// 账户id omitempty标识在insert update操作时忽略该字段
	Id int64 `db:"id,omitempty"`
	// 账户编号 unique 该字段是唯一索引
	AccountNo string `db:"account_no,unique"`
	// 账户名称
	AccountName string `db:"account_name"`
	// 账户类型
	AccountType int `db:"account_type"`
	// 货币类型编码
	CurrencyCode string `db:"currency_code"`
	// 用户编号
	UserId string `db:"user_id"`
	// 用户编号
	Username sql.NullString `db:"username"`
	// TODO:NOTICE 账户可用余额 避免Go的float32 float64在计算中丢失数据精度
	Balance decimal.Decimal `db:"balance"`
	// 账户状态
	Status int `db:"status"`
	// 账户创建时间
	CreatedAt time.Time `db:"created_at,omitempty"`
	// 账户更新时间
	UpdatedAt time.Time `db:"updated_at,omitempty"`
}

账户持久化对象

func (*Account) FromDTO

func (po *Account) FromDTO(dto *services.AccountDTO)

func (*Account) ToDTO

func (po *Account) ToDTO() *services.AccountDTO

type AccountDao

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

查询数据库持久化对象的单实例 数据库访问层的每个方法 代表1个原子性操作 不建议把多个数据库操作写到1个方法中 数据库操作的事务放到各个方法外部,多个方法对应的数据库操作组成1个事务

func (*AccountDao) GetByUserId

func (dao *AccountDao) GetByUserId(userId string, accountType int) *Account

资金账户Account 依赖用户User 1个user可以有多个account通过账户类型区分 通过用户Id和账户类型来查询账户信息

func (*AccountDao) GetOne

func (dao *AccountDao) GetOne(accountNo string) *Account

获取一行数据

func (*AccountDao) Insert

func (dao *AccountDao) Insert(data *Account) (int64, error)

账户数据插入 返回账户id

func (*AccountDao) UpdateBalance

func (dao *AccountDao) UpdateBalance(accountNo string, amount decimal.Decimal) (rows int64, err error)

TODO:NOTICE 账户余额更新 [乐观锁] 机制 账户余额更新 amount > 0 收入 amount < 0 扣减 入参 account 变化的金额 负为扣减 正为增加 返回受影响行数 成功返回1 失败返回<=0的值

func (*AccountDao) UpdateStatus

func (dao *AccountDao) UpdateStatus(accountNo string, status int) (rows int64, err error)

账户状态更新 账户数据不做物理删除通过status字段标识账户的 启用 停用 状态

type AccountLog

type AccountLog struct {
	Id              int64               `db:"id,omitempty"`
	LogNo           string              `db:"log_no,unique"`
	TradeNo         string              `db:"trade_no"`
	AccountNo       string              `db:"account_no"`
	UserId          string              `db:"user_id"`
	Username        string              `db:"username"`
	TargetAccountNo string              `db:"target_account_no"`
	TargetUserId    string              `db:"target_user_id"`
	TargetUsername  string              `db:"target_username"`
	Amount          decimal.Decimal     `db:"amount"`
	Balance         decimal.Decimal     `db:"balance"`
	ChangeType      services.ChangeType `db:"change_type"`
	ChangeFlag      services.ChangeFlag `db:"change_flag"`
	Status          int                 `db:"status"`
	Desc            string              `db:"desc"`
	// 创建时间系统自动生成 该字段无需手动赋值
	CreatedAt time.Time `db:"created_at,omitempty"`
}

账户流水表持久化对象

func (*AccountLog) FromTransferDTO

func (po *AccountLog) FromTransferDTO(dto *services.AccountTransferDTO)

func (*AccountLog) ToDTO

func (po *AccountLog) ToDTO() *services.AccountLogDTO

type AccountLogDao

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

func (*AccountLogDao) GetByTradeNo

func (dao *AccountLogDao) GetByTradeNo(tradeNo string) *AccountLog

通过交易编号查询流水记录

func (*AccountLogDao) GetOne

func (dao *AccountLogDao) GetOne(logNo string) *AccountLog

通过流水编号查询流水记录

func (*AccountLogDao) Insert

func (dao *AccountLogDao) Insert(data *AccountLog) (id int64, err error)

流水记录的写入

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL