51 lines
1.5 KiB
Go
Executable File
51 lines
1.5 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)
|
|
}
|
|
|
|
customNhTouristBindModel struct {
|
|
*defaultNhTouristBindModel
|
|
}
|
|
|
|
NhTouristBindUser struct {
|
|
Id uint `db:"id"`
|
|
Uid uint `db:"uid"`
|
|
}
|
|
)
|
|
|
|
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))
|
|
}
|