models

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const FROM_API int8 = 1
View Source
const FROM_CACHE int8 = 2
View Source
const IN_LAND = 1 // 国内快递
View Source
const OUT_LAND = 2 // 国际快递
View Source
const REQUEST_FAIL int8 = 2
View Source
const REQUEST_SUCCESS int8 = 1
View Source
const STATUS_FAIL = 2 // 异常状态
View Source
const STATUS_OK = 1 // 正常状态

Variables

View Source
var DB *gorm.DB

Functions

func CheckExpressCode

func CheckExpressCode(code string) bool

检测code是否存在

func CreateSearchLog

func CreateSearchLog(log *SearchLog) error

func CreateUser

func CreateUser(user *User) (int, error)

func InitDatabase

func InitDatabase() *gorm.DB

func ModifyUser

func ModifyUser(user *User) error

func StatusOK

func StatusOK(db *gorm.DB) *gorm.DB

定义通用scope作用域查询

Types

type ExpressCompany

type ExpressCompany struct {
	// 通过制定json字段 能控制返回给前段的属性名,比如这里使用小写
	// 注意不同字符串直接的空格
	// `json:"id" gorm:"primaryKey; notNull; autoIncrement; comment:主键;"`
	ID            int16  `gorm:"primaryKey; notNull; autoIncrement; comment:主键;"`
	Name          string `gorm:"notNull; size:64; default:''; comment:快递公司名"`
	Code          string `gorm:"notNull; size:24; default:''; comment:快递公司编码"`
	FirstCode     string `gorm:"notNull; size:1; default:''; comment:快递公司编码的首字母"`
	FirstNameCode string `gorm:"notNull; size:1; default:''; comment:快递公司名的首字母"`
	Icon          string `gorm:"notNull; size:256; default:''; comment:快递公司名的图标"`
	Tel           string `gorm:"notNull; size:256; default:''; comment:快递公司名的联系电话"`
	Type          int8   `gorm:"notNull; default:1; comment:快递公司类型 1=国内快递 2=国际快递"`
	Status        int8   `gorm:"notNULL; default: 1; comment: 快递状态 1=正常 2=异常"`
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

func ExpressCompanyAll

func ExpressCompanyAll(land int8) []ExpressCompany

获取所有的快递公司列表

func GetExpressByCode

func GetExpressByCode(code string) (ExpressCompany, error)

根据code查询快递公司

type PaginationDefaultParams

type PaginationDefaultParams struct {
	Page     int16 `json:"page"`
	PageSize int16 `json:"page_size"`
}

type PaginationParams

type PaginationParams struct {
	PaginationDefaultParams
}

type SearchLog

type SearchLog struct {
	ID           int16  `gorm:"primaryKey; notNull; autoIncrement; comment:主键;"`
	UserID       int    `gorm:"notNull; size:64; default:0; comment:所属用户"`
	ShipperCode  string `gorm:"notNull; size:24; default:''; comment:查询的快递公司编码"`
	LogisticCode string `gorm:"notNull; size:24; default:''; comment:查询的快递单号"`
	IsCache      int8   `gorm:"notNull; size:1; default:1; comment:结果是否来自缓存,1=来自第三方接口 2=来自缓存"`
	IsSuccess    int8   `gorm:"notNull; size:1; default:1; comment:查询是否成功,1=成功 2=失败"`
	// 这里可以通过gorm的tags来改变数据库的映射字段类型
	Result    string `gorm:"type:text; notNull; comment:接口返回结果"`
	ErrorMsg  string `gorm:"notNull; size:256; default:''; comment:接口失败返回信息"`
	Ip        string `gorm:"notNULL; size:32; default: ''; comment: 用户的ip地址"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

快递查询日志表

type User

type User struct {
	ID          int       `gorm:"primaryKey; notNull; autoIncrement; comment:主键"`
	Openid      string    `gorm:"unique; size:64; notNull; comment: 用户的openid"`
	Unionid     string    `gorm:"notNULL; size:64; default: ''; comment: 用户的unionid"`
	Platform    string    `gorm:"notNULL; size:64; default: 'wechat-mini'; comment: 用户的来源平台"`
	NickName    string    `gorm:"notNULL; size:128; default: ''; comment: 用户的昵称"`
	HeadImg     string    `gorm:"notNULL; default: ''; comment: 用户的头像地址"`
	Status      int8      `gorm:"notNULL; default: 1; comment: 用户的状态 1=正常 2=异常"`
	Ip          string    `gorm:"notNULL; size:32; default: ''; comment: 用户的ip地址"`
	LastLoginAt time.Time `gorm:"notNULL; comment: 用户最后一次登录时间"`
	SessionKey  string    `gorm:"notNULL; default:''; comment: 小程序秘钥"`
	CreatedAt   time.Time
	UpdatedAt   time.Time
	// 定义和快递查询日志的1对多关系
	SearchLogs []SearchLog
}

func UserByOpenid

func UserByOpenid(openid string) (User, error)

Jump to

Keyboard shortcuts

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