66 lines
2.0 KiB
Go
Executable File
66 lines
2.0 KiB
Go
Executable File
package model
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
)
|
|
|
|
var _ NhTouristBindModel = (*customNhTouristBindModel)(nil)
|
|
|
|
type (
|
|
// NhTouristBindModel is an interface to be customized, add more methods here,
|
|
// and implement the added methods in customNhTouristBindModel.
|
|
NhTouristBindModel interface {
|
|
nhTouristBindModel
|
|
withSession(session sqlx.Session) NhTouristBindModel
|
|
FindRequirePushUser(ctx context.Context, shareUid uint) ([]NhTouristBindUser, error)
|
|
FindOneByEmail(ctx context.Context, email string) (*NhTouristBind, error)
|
|
}
|
|
|
|
customNhTouristBindModel struct {
|
|
*defaultNhTouristBindModel
|
|
}
|
|
|
|
NhTouristBindUser struct {
|
|
Id uint `db:"id"`
|
|
Uid uint `db:"uid"`
|
|
}
|
|
)
|
|
|
|
func (m *customNhTouristBindModel) FindOneByEmail(ctx context.Context, email string) (*NhTouristBind, error) {
|
|
query := fmt.Sprintf("select %s from %s where `email` = ? limit 1", nhTouristBindRows, m.table)
|
|
var resp NhTouristBind
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, email)
|
|
switch {
|
|
case err == nil:
|
|
return &resp, nil
|
|
case errors.Is(err, sqlx.ErrNotFound):
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *customNhTouristBindModel) FindRequirePushUser(ctx context.Context, shareUid uint) ([]NhTouristBindUser, error) {
|
|
query := fmt.Sprintf("SELECT t2.id, t1.uid FROM nh_tourist_bind t1 JOIN nh_promote_bind t2 ON t1.uid = t2.invited_uid WHERE t2.share_uid = ? AND t2.is_push_role = 0;")
|
|
var resp []NhTouristBindUser
|
|
err := m.conn.QueryRowsCtx(ctx, &resp, query, shareUid)
|
|
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
|
return nil, err
|
|
}
|
|
return resp, nil
|
|
}
|
|
|
|
// NewNhTouristBindModel returns a model for the database table.
|
|
func NewNhTouristBindModel(conn sqlx.SqlConn) NhTouristBindModel {
|
|
return &customNhTouristBindModel{
|
|
defaultNhTouristBindModel: newNhTouristBindModel(conn),
|
|
}
|
|
}
|
|
|
|
func (m *customNhTouristBindModel) withSession(session sqlx.Session) NhTouristBindModel {
|
|
return NewNhTouristBindModel(sqlx.NewSqlConnFromSession(session))
|
|
}
|