package model import ( "context" "fmt" "strings" "github.com/zeromicro/go-zero/core/stores/sqlc" "github.com/zeromicro/go-zero/core/stores/sqlx" "github.com/zeromicro/go-zero/core/stringx" ) var _ FsAddressModel = (*customFsAddressModel)(nil) type ( // FsAddressModel is an interface to be customized, add more methods here, // and implement the added methods in customFsAddressModel. FsAddressModel interface { fsAddressModel FindDataAddressList(ctx context.Context, userid int64) (*DataAddressList, error) } customFsAddressModel struct { *defaultFsAddressModel } DataAddressList struct { Id int64 `db:"id" json:"id"` UserId int64 `db:"user_id" json:"user_id"` // 用户ID Name string `db:"name" json:"name"` // 地址名称 FirstName string `db:"first_name" json:"first_name"` // FirstName LastName string `db:"last_name" json:"last_name"` // LastName Mobile string `db:"mobile" json:"mobile"` // 手机号码 Street string `db:"street" json:"street"` // 街道 Suite string `db:"suite" json:"suite"` // 房号 City string `db:"city" json:"city"` // 城市 State string `db:"state" json:"state"` // 州名 ZipCode string `db:"zip_code" json:"zip_code"` // 邮编 IsDefault int64 `db:"is_default" json:"is_default"` // 1默认地址,0非默认地址 } ) var ( // DataAddressList 结构需要的字段 fsDataAddressListRows = strings.Join(stringx.Remove(fsAddressFieldNames, "`status`", "`country`"), ",") ) // NewFsAddressModel returns a model for the database table. func NewFsAddressModel(conn sqlx.SqlConn) FsAddressModel { return &customFsAddressModel{ defaultFsAddressModel: newFsAddressModel(conn), } } func (m *defaultFsAddressModel) FindDataAddressList(ctx context.Context, userid int64) (*DataAddressList, error) { query := fmt.Sprintf("select %s from %s where `user_id` = ? ", fsDataAddressListRows, m.table) var resp DataAddressList err := m.conn.QueryRowCtx(ctx, &resp, query, userid) switch err { case nil: return &resp, nil case sqlc.ErrNotFound: return nil, ErrNotFound default: return nil, err } }