增加社区列表接口,任务相关接口修改
This commit is contained in:
81
internal/model/nh_promote_bind_model.go
Executable file
81
internal/model/nh_promote_bind_model.go
Executable file
@@ -0,0 +1,81 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/patrickmn/go-cache"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"time"
|
||||
)
|
||||
|
||||
var _ NhPromoteBindModel = (*customNhPromoteBindModel)(nil)
|
||||
|
||||
type (
|
||||
// NhPromoteBindModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customNhPromoteBindModel.
|
||||
NhPromoteBindModel interface {
|
||||
nhPromoteBindModel
|
||||
withSession(session sqlx.Session) NhPromoteBindModel
|
||||
FindRequirePushUser(ctx context.Context, shareUid uint) ([]NhPromoteBind, error)
|
||||
UpdatePushUser(ctx context.Context, id uint) error
|
||||
UpdatePushRole(ctx context.Context, id uint) error
|
||||
UserInviteCount(ctx context.Context, uid uint) (int64, error)
|
||||
}
|
||||
|
||||
customNhPromoteBindModel struct {
|
||||
*defaultNhPromoteBindModel
|
||||
userInviteCountCache *cache.Cache
|
||||
}
|
||||
)
|
||||
|
||||
// NewNhPromoteBindModel returns a model for the database table.
|
||||
func NewNhPromoteBindModel(conn sqlx.SqlConn) NhPromoteBindModel {
|
||||
return &customNhPromoteBindModel{
|
||||
defaultNhPromoteBindModel: newNhPromoteBindModel(conn),
|
||||
userInviteCountCache: cache.New(time.Minute, time.Second*65),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customNhPromoteBindModel) withSession(session sqlx.Session) NhPromoteBindModel {
|
||||
return NewNhPromoteBindModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
||||
|
||||
func (m *customNhPromoteBindModel) FindRequirePushUser(ctx context.Context, shareUid uint) ([]NhPromoteBind, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `share_uid` = ? and `is_push_user` = 0 limit 100", nhPromoteBindRows, m.table)
|
||||
var resp []NhPromoteBind
|
||||
err := m.conn.QueryRowsCtx(ctx, &resp, query, shareUid)
|
||||
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (m *customNhPromoteBindModel) UpdatePushUser(ctx context.Context, id uint) error {
|
||||
update := fmt.Sprintf("update %s set `is_push_user` = 1 where `id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, update, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *customNhPromoteBindModel) UpdatePushRole(ctx context.Context, id uint) error {
|
||||
update := fmt.Sprintf("update %s set `is_push_role` = 1 where `id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, update, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *customNhPromoteBindModel) UserInviteCount(ctx context.Context, uid uint) (int64, error) {
|
||||
key := cast.ToString(uid)
|
||||
v, ok := m.userInviteCountCache.Get(key)
|
||||
if ok {
|
||||
return v.(int64), nil
|
||||
}
|
||||
query := fmt.Sprintf("select count(*) as `count` from %s where `share_uid` = ?", m.table)
|
||||
var count int64
|
||||
err := m.conn.QueryRowCtx(ctx, &count, query, uid)
|
||||
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
||||
return 0, err
|
||||
}
|
||||
m.userInviteCountCache.SetDefault(key, count)
|
||||
return count, nil
|
||||
}
|
||||
104
internal/model/nh_promote_bind_model_gen.go
Executable file
104
internal/model/nh_promote_bind_model_gen.go
Executable file
@@ -0,0 +1,104 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.3
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
nhPromoteBindFieldNames = builder.RawFieldNames(&NhPromoteBind{})
|
||||
nhPromoteBindRows = strings.Join(nhPromoteBindFieldNames, ",")
|
||||
nhPromoteBindRowsExpectAutoSet = strings.Join(stringx.Remove(nhPromoteBindFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
nhPromoteBindRowsWithPlaceHolder = strings.Join(stringx.Remove(nhPromoteBindFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
nhPromoteBindModel interface {
|
||||
Insert(ctx context.Context, data *NhPromoteBind) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id uint) (*NhPromoteBind, error)
|
||||
FindOneByInvitedUid(ctx context.Context, invitedUid uint) (*NhPromoteBind, error)
|
||||
Update(ctx context.Context, data *NhPromoteBind) error
|
||||
Delete(ctx context.Context, id uint) error
|
||||
}
|
||||
|
||||
defaultNhPromoteBindModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
NhPromoteBind struct {
|
||||
Id uint `db:"id"`
|
||||
ShareUid uint `db:"share_uid"` // 分享者uid
|
||||
InvitedUid uint `db:"invited_uid"` // 受邀者uid
|
||||
CreateTime uint `db:"create_time"` // 创建时间
|
||||
IsPushUser int8 `db:"is_push_user"` // 是否已推送用户信息
|
||||
IsPushRole int8 `db:"is_push_role"` // 是否已推送绑定游戏账号
|
||||
}
|
||||
)
|
||||
|
||||
func newNhPromoteBindModel(conn sqlx.SqlConn) *defaultNhPromoteBindModel {
|
||||
return &defaultNhPromoteBindModel{
|
||||
conn: conn,
|
||||
table: "`nh_promote_bind`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhPromoteBindModel) Delete(ctx context.Context, id uint) error {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultNhPromoteBindModel) FindOne(ctx context.Context, id uint) (*NhPromoteBind, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhPromoteBindRows, m.table)
|
||||
var resp NhPromoteBind
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhPromoteBindModel) FindOneByInvitedUid(ctx context.Context, invitedUid uint) (*NhPromoteBind, error) {
|
||||
var resp NhPromoteBind
|
||||
query := fmt.Sprintf("select %s from %s where `invited_uid` = ? limit 1", nhPromoteBindRows, m.table)
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, invitedUid)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhPromoteBindModel) Insert(ctx context.Context, data *NhPromoteBind) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, nhPromoteBindRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.ShareUid, data.InvitedUid, data.IsPushUser, data.IsPushRole)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultNhPromoteBindModel) Update(ctx context.Context, newData *NhPromoteBind) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhPromoteBindRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, newData.ShareUid, newData.InvitedUid, newData.IsPushUser, newData.IsPushRole, newData.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultNhPromoteBindModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
45
internal/model/nh_task_community_model.go
Executable file
45
internal/model/nh_task_community_model.go
Executable file
@@ -0,0 +1,45 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ NhTaskCommunityModel = (*customNhTaskCommunityModel)(nil)
|
||||
|
||||
type (
|
||||
// NhTaskCommunityModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customNhTaskCommunityModel.
|
||||
NhTaskCommunityModel interface {
|
||||
nhTaskCommunityModel
|
||||
withSession(session sqlx.Session) NhTaskCommunityModel
|
||||
All(ctx context.Context) ([]NhTaskCommunity, error)
|
||||
}
|
||||
|
||||
customNhTaskCommunityModel struct {
|
||||
*defaultNhTaskCommunityModel
|
||||
}
|
||||
)
|
||||
|
||||
func (m *customNhTaskCommunityModel) All(ctx context.Context) ([]NhTaskCommunity, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `status` = 1", nhTaskCommunityRows, m.table)
|
||||
var resp []NhTaskCommunity
|
||||
err := m.conn.QueryRowsCtx(ctx, &resp, query)
|
||||
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// NewNhTaskCommunityModel returns a model for the database table.
|
||||
func NewNhTaskCommunityModel(conn sqlx.SqlConn) NhTaskCommunityModel {
|
||||
return &customNhTaskCommunityModel{
|
||||
defaultNhTaskCommunityModel: newNhTaskCommunityModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customNhTaskCommunityModel) withSession(session sqlx.Session) NhTaskCommunityModel {
|
||||
return NewNhTaskCommunityModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
||||
94
internal/model/nh_task_community_model_gen.go
Executable file
94
internal/model/nh_task_community_model_gen.go
Executable file
@@ -0,0 +1,94 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.3
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
nhTaskCommunityFieldNames = builder.RawFieldNames(&NhTaskCommunity{})
|
||||
nhTaskCommunityRows = strings.Join(nhTaskCommunityFieldNames, ",")
|
||||
nhTaskCommunityRowsExpectAutoSet = strings.Join(stringx.Remove(nhTaskCommunityFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
nhTaskCommunityRowsWithPlaceHolder = strings.Join(stringx.Remove(nhTaskCommunityFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
nhTaskCommunityModel interface {
|
||||
Insert(ctx context.Context, data *NhTaskCommunity) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id uint) (*NhTaskCommunity, error)
|
||||
Update(ctx context.Context, data *NhTaskCommunity) error
|
||||
Delete(ctx context.Context, id uint) error
|
||||
}
|
||||
|
||||
defaultNhTaskCommunityModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
NhTaskCommunity struct {
|
||||
Id uint `db:"id"`
|
||||
Title string `db:"title"` // 社区
|
||||
Logo string `db:"logo"` // logo图片链接
|
||||
Description string `db:"description"` // 描述
|
||||
Status int8 `db:"status"` // 0=不启用,1=启用
|
||||
StartAt sql.NullTime `db:"start_at"` // 开始时间
|
||||
EndAt sql.NullTime `db:"end_at"` // 结束时间
|
||||
CreatedAt time.Time `db:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `db:"updated_at"` // 修改时间
|
||||
Sort int `db:"sort"` // 数字越小越靠前
|
||||
}
|
||||
)
|
||||
|
||||
func newNhTaskCommunityModel(conn sqlx.SqlConn) *defaultNhTaskCommunityModel {
|
||||
return &defaultNhTaskCommunityModel{
|
||||
conn: conn,
|
||||
table: "`nh_task_community`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhTaskCommunityModel) Delete(ctx context.Context, id uint) error {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultNhTaskCommunityModel) FindOne(ctx context.Context, id uint) (*NhTaskCommunity, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhTaskCommunityRows, m.table)
|
||||
var resp NhTaskCommunity
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhTaskCommunityModel) Insert(ctx context.Context, data *NhTaskCommunity) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, nhTaskCommunityRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Title, data.Logo, data.Description, data.Status, data.StartAt, data.EndAt, data.Sort)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultNhTaskCommunityModel) Update(ctx context.Context, data *NhTaskCommunity) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhTaskCommunityRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.Title, data.Logo, data.Description, data.Status, data.StartAt, data.EndAt, data.Sort, data.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultNhTaskCommunityModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
@@ -21,6 +21,7 @@ const (
|
||||
TASKTYPE_BIND_DISCORD = 7
|
||||
TASKTYPE_JOIN_TELEGRAM = 8
|
||||
TASKTYPE_DAILY_PAY = 9
|
||||
TASKTYPE_INVITE_USER = 10
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -38,7 +39,7 @@ type (
|
||||
)
|
||||
|
||||
func (m *customNhTaskModel) FindTasksByCommunity(ctx context.Context, communityId uint) ([]*NhTask, error) {
|
||||
query := fmt.Sprintf("select %s from %s where community_id = 0 or community_id = ?", nhTaskRows, m.table)
|
||||
query := fmt.Sprintf("select %s from %s where `status` = 1 and community_id = ? order by `sort`", nhTaskRows, m.table)
|
||||
var tasks []*NhTask
|
||||
err := m.conn.QueryRowsCtx(ctx, &tasks, query, communityId)
|
||||
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
||||
|
||||
@@ -51,6 +51,8 @@ type (
|
||||
EndAt sql.NullTime `db:"end_at"` // 结束时间
|
||||
CreatedAt time.Time `db:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `db:"updated_at"` // 修改时间
|
||||
Param string `db:"param"` // 备用参数,如果是邀请任务,可以填邀请的人数
|
||||
Sort int `db:"sort"` // 数字越小越靠前
|
||||
}
|
||||
)
|
||||
|
||||
@@ -82,14 +84,14 @@ func (m *defaultNhTaskModel) FindOne(ctx context.Context, id uint) (*NhTask, err
|
||||
}
|
||||
|
||||
func (m *defaultNhTaskModel) Insert(ctx context.Context, data *NhTask) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, nhTaskRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.CommunityId, data.Title, data.SubTitle, data.Description, data.Points, data.ButtonText, data.Type, data.Url, data.Status, data.StartAt, data.EndAt)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, nhTaskRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.CommunityId, data.Title, data.SubTitle, data.Description, data.Points, data.ButtonText, data.Type, data.Url, data.Status, data.StartAt, data.EndAt, data.Param, data.Sort)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultNhTaskModel) Update(ctx context.Context, data *NhTask) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhTaskRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.CommunityId, data.Title, data.SubTitle, data.Description, data.Points, data.ButtonText, data.Type, data.Url, data.Status, data.StartAt, data.EndAt, data.Id)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.CommunityId, data.Title, data.SubTitle, data.Description, data.Points, data.ButtonText, data.Type, data.Url, data.Status, data.StartAt, data.EndAt, data.Param, data.Sort, data.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
29
internal/model/nh_tourist_bind_model.go
Executable file
29
internal/model/nh_tourist_bind_model.go
Executable file
@@ -0,0 +1,29 @@
|
||||
package model
|
||||
|
||||
import "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
|
||||
}
|
||||
|
||||
customNhTouristBindModel struct {
|
||||
*defaultNhTouristBindModel
|
||||
}
|
||||
)
|
||||
|
||||
// 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))
|
||||
}
|
||||
87
internal/model/nh_tourist_bind_model_gen.go
Executable file
87
internal/model/nh_tourist_bind_model_gen.go
Executable file
@@ -0,0 +1,87 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.3
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
nhTouristBindFieldNames = builder.RawFieldNames(&NhTouristBind{})
|
||||
nhTouristBindRows = strings.Join(nhTouristBindFieldNames, ",")
|
||||
nhTouristBindRowsExpectAutoSet = strings.Join(stringx.Remove(nhTouristBindFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
nhTouristBindRowsWithPlaceHolder = strings.Join(stringx.Remove(nhTouristBindFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
nhTouristBindModel interface {
|
||||
Insert(ctx context.Context, data *NhTouristBind) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int) (*NhTouristBind, error)
|
||||
Update(ctx context.Context, data *NhTouristBind) error
|
||||
Delete(ctx context.Context, id int) error
|
||||
}
|
||||
|
||||
defaultNhTouristBindModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
NhTouristBind struct {
|
||||
Id int `db:"id"`
|
||||
TouristAccount string `db:"tourist_account"` // 游客账号
|
||||
FormalAccount string `db:"formal_account"` // 正式账号
|
||||
CreateTime int `db:"create_time"` // 创建时间
|
||||
}
|
||||
)
|
||||
|
||||
func newNhTouristBindModel(conn sqlx.SqlConn) *defaultNhTouristBindModel {
|
||||
return &defaultNhTouristBindModel{
|
||||
conn: conn,
|
||||
table: "`nh_tourist_bind`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhTouristBindModel) Delete(ctx context.Context, id int) error {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultNhTouristBindModel) FindOne(ctx context.Context, id int) (*NhTouristBind, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhTouristBindRows, m.table)
|
||||
var resp NhTouristBind
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhTouristBindModel) Insert(ctx context.Context, data *NhTouristBind) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?)", m.table, nhTouristBindRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.TouristAccount, data.FormalAccount)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultNhTouristBindModel) Update(ctx context.Context, data *NhTouristBind) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhTouristBindRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.TouristAccount, data.FormalAccount, data.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultNhTouristBindModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
29
internal/model/nh_user_model.go
Executable file
29
internal/model/nh_user_model.go
Executable file
@@ -0,0 +1,29 @@
|
||||
package model
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var _ NhUserModel = (*customNhUserModel)(nil)
|
||||
|
||||
type (
|
||||
// NhUserModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customNhUserModel.
|
||||
NhUserModel interface {
|
||||
nhUserModel
|
||||
withSession(session sqlx.Session) NhUserModel
|
||||
}
|
||||
|
||||
customNhUserModel struct {
|
||||
*defaultNhUserModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewNhUserModel returns a model for the database table.
|
||||
func NewNhUserModel(conn sqlx.SqlConn) NhUserModel {
|
||||
return &customNhUserModel{
|
||||
defaultNhUserModel: newNhUserModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customNhUserModel) withSession(session sqlx.Session) NhUserModel {
|
||||
return NewNhUserModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
||||
108
internal/model/nh_user_model_gen.go
Executable file
108
internal/model/nh_user_model_gen.go
Executable file
@@ -0,0 +1,108 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.3
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
nhUserFieldNames = builder.RawFieldNames(&NhUser{})
|
||||
nhUserRows = strings.Join(nhUserFieldNames, ",")
|
||||
nhUserRowsExpectAutoSet = strings.Join(stringx.Remove(nhUserFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
nhUserRowsWithPlaceHolder = strings.Join(stringx.Remove(nhUserFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
nhUserModel interface {
|
||||
Insert(ctx context.Context, data *NhUser) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id uint) (*NhUser, error)
|
||||
FindOneByEmail(ctx context.Context, email string) (*NhUser, error)
|
||||
Update(ctx context.Context, data *NhUser) error
|
||||
Delete(ctx context.Context, id uint) error
|
||||
}
|
||||
|
||||
defaultNhUserModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
NhUser struct {
|
||||
Id uint `db:"id"`
|
||||
Email string `db:"email"` // 邮箱
|
||||
Password string `db:"password"` // 密码
|
||||
CreateTime sql.NullInt64 `db:"create_time"` // 创建时间
|
||||
InviteId int `db:"invite_id"` // 邀请码/测试码ID
|
||||
LastLoginTime sql.NullInt64 `db:"last_login_time"` // 最后登陆时间
|
||||
LastLoginIp string `db:"last_login_ip"` // 最后登录IP
|
||||
Remarks sql.NullString `db:"remarks"` // 备注
|
||||
Status uint8 `db:"status"` // 用户状态 1 正常 2 禁止
|
||||
IsOpenSeason int8 `db:"is_open_season"` // 是否已开启赛季
|
||||
}
|
||||
)
|
||||
|
||||
func newNhUserModel(conn sqlx.SqlConn) *defaultNhUserModel {
|
||||
return &defaultNhUserModel{
|
||||
conn: conn,
|
||||
table: "`nh_user`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhUserModel) Delete(ctx context.Context, id uint) error {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultNhUserModel) FindOne(ctx context.Context, id uint) (*NhUser, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhUserRows, m.table)
|
||||
var resp NhUser
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhUserModel) FindOneByEmail(ctx context.Context, email string) (*NhUser, error) {
|
||||
var resp NhUser
|
||||
query := fmt.Sprintf("select %s from %s where `email` = ? limit 1", nhUserRows, m.table)
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, email)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhUserModel) Insert(ctx context.Context, data *NhUser) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, nhUserRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Email, data.Password, data.InviteId, data.LastLoginTime, data.LastLoginIp, data.Remarks, data.Status, data.IsOpenSeason)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultNhUserModel) Update(ctx context.Context, newData *NhUser) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhUserRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, newData.Email, newData.Password, newData.InviteId, newData.LastLoginTime, newData.LastLoginIp, newData.Remarks, newData.Status, newData.IsOpenSeason, newData.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultNhUserModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
Reference in New Issue
Block a user