domain

package
v0.0.0-...-654a53c Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

模型的行为动作,可见不支持泛型写这些东西是多么的啰嗦

模型结构

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvPayStateToString

func ConvPayStateToString(state PayState) string

Types

type Account

type Account struct {
	BaseModel
	Username  string `json:"username" binding:"required"`
	Name      string `json:"name" binding:"required"`
	Password  string `json:"password,omitempty" binding:"required"`
	Avatar    string `json:"avatar"`
	Telephone string `json:"telephone" binding:"required,numeric,startswith=1,len=11"`
	Email     string `json:"email" binding:"required,email"`
	Location  string `json:"location"`
}

用户

func NewAccount

func NewAccount(db *db.Database) *Account

用户行为

func (*Account) Create

func (s *Account) Create() (int64, error)

func (*Account) FindByNameOrEmailOrTelephone

func (s *Account) FindByNameOrEmailOrTelephone(name, email, telephone string) (r []Account, err error)

func (*Account) GetByName

func (s *Account) GetByName(username string) (*Account, error)

func (*Account) Update

func (s *Account) Update() (int64, error)
type Advertisement struct {
	BaseModel
	ProductId uint   `json:"productId"`
	Image     string `json:"image"`
}

广告实体

func NewAdvertisement

func NewAdvertisement(db *db.Database) *Advertisement

广告行为

func (*Advertisement) FindAll

func (s *Advertisement) FindAll() (r []Advertisement, err error)

type BaseModel

type BaseModel struct {
	ID           uint `json:"id" gorm:"primaryKey;autoIncrement;notNull"`
	*db.Database `json:"-" gorm:"-" binding:"-"`
}

func (*BaseModel) IsNew

func (s *BaseModel) IsNew() bool

type Item

type Item struct {
	ID     uint `json:"id"`
	Amount int  `json:"amount"`
}

结算单中要购买的商品

type PayState

type PayState int
const (
	Waiting PayState = iota
	Cancel
	Payed
	Timeout
)

func ConvStringToPayState

func ConvStringToPayState(state string) (PayState, error)

type Payment

type Payment struct {
	BaseModel
	CreateTime  time.Time `json:"createTime"`
	PayId       string    `json:"payId"`
	TotalPrice  float64   `json:"totalPrice"`
	Expires     int64     `json:"expires"`
	PaymentLink string    `json:"paymentLink" gorm:"-"`
	PayState    PayState  `json:"payState"`
}

支付单模型 就是传到客户端让用户给扫码或者其他别的方式付钱的对象

func NewPayment

func NewPayment(db *db.Database) *Payment

支付单行为

func NewPaymentWithInfo

func NewPaymentWithInfo(db *db.Database, user string, total float64, expires int64) *Payment

func (*Payment) Create

func (s *Payment) Create() (int64, error)

func (*Payment) Get

func (s *Payment) Get(id uint) (*Payment, error)

func (*Payment) GetByPayID

func (s *Payment) GetByPayID(payId string) (*Payment, error)

func (*Payment) Update

func (s *Payment) Update() (int64, error)

type Product

type Product struct {
	BaseModel
	Title          string          `json:"title"`
	Price          float64         `json:"price"` // 用浮点数来表示金额是很不好的行为,这里只是方便演示
	Rate           float32         `json:"rate"`
	Description    string          `json:"description"`
	Cover          string          `json:"cover"`
	Detail         string          `json:"detail"`
	Specifications []Specification `json:"specifications" gorm:"foreignKey:ProductId"`
}

产品实例

func NewProduct

func NewProduct(db *db.Database) *Product

产品行为

func (*Product) Create

func (s *Product) Create() (int64, error)

func (*Product) Delete

func (s *Product) Delete(id ...uint) (int64, error)

func (*Product) FindAll

func (s *Product) FindAll() (r []Product, err error)

func (*Product) FindByIDs

func (s *Product) FindByIDs(ids []uint) (r []Product, err error)

func (*Product) Get

func (s *Product) Get(id uint) (*Product, error)

func (*Product) Update

func (s *Product) Update() (int64, error)

type Purchase

type Purchase struct {
	Delivery  bool   `json:"delivery"`
	Pay       string `json:"pay"`
	Name      string `json:"name" binding:"required"`
	Telephone string `json:"telephone" binding:"required,numeric,startswith=1,len=11"`
	Location  string `json:"location"`
}

结算单中的配送信息

type Settlement

type Settlement struct {
	Items      []Item            `json:"items"`
	Purchase   Purchase          `json:"purchase"`
	ProductMap map[uint]*Product `json:"productMap"`
}

支付结算单模型

type Specification

type Specification struct {
	BaseModel
	Item      string `json:"item"`
	Value     string `json:"value"`
	ProductId uint   `json:"productId"`
}

产品规格

type Stockpile

type Stockpile struct {
	BaseModel
	Amount    int  `json:"amount"`
	Frozen    int  `json:"frozen"`
	ProductId uint `json:"productId"`
}

商品库存

func NewStockpile

func NewStockpile(db *db.Database) *Stockpile

库存行为

func (*Stockpile) Get

func (s *Stockpile) Get(id uint) (*Stockpile, error)

func (*Stockpile) GetByProductId

func (s *Stockpile) GetByProductId(id uint) (*Stockpile, error)

func (*Stockpile) Update

func (s *Stockpile) Update() (int64, error)

func (*Stockpile) UpdateAmount

func (s *Stockpile) UpdateAmount(id uint, amount uint) (int64, error)

type Wallet

type Wallet struct {
	BaseModel
	Money     float64 `json:"money"`
	AccountId uint    `json:"accountId"`
}

用户钱包

func NewWallet

func NewWallet(db *db.Database) *Wallet

用户钱包行为

func (*Wallet) GetByAccountId

func (s *Wallet) GetByAccountId(id uint) (*Wallet, error)

func (*Wallet) Update

func (s *Wallet) Update() (int64, error)

Jump to

Keyboard shortcuts

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