v1.0
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
# 设置输出编码为UTF-8
|
||||
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
# 数据库连接信息 - 修改了URL格式
|
||||
$DB_URL = "ycc:5vg67b3UNHu8@(127.0.0.1:21001)/ycc"
|
||||
# 目录配置
|
||||
$OUTPUT_DIR = "./model"
|
||||
$TEMPLATE_DIR = "../template"
|
||||
$TARGET_DIR = "../../app/main/model"
|
||||
|
||||
# 表名列表
|
||||
$tables = @(
|
||||
# ============================================
|
||||
# 新代理系统表
|
||||
# ============================================
|
||||
"agent",
|
||||
# "agent",
|
||||
# "agent_audit",
|
||||
# "agent_wallet",
|
||||
# "agent_relation",
|
||||
@@ -20,9 +19,12 @@ $tables = @(
|
||||
# "agent_rebate",
|
||||
# "agent_upgrade",
|
||||
# "agent_withdrawal",
|
||||
# "agent_config",
|
||||
# "agent_product_config",
|
||||
"agent_real_name"
|
||||
# "agent_config"
|
||||
# "agent_product_config"
|
||||
# "agent_invite_code_usage"
|
||||
# "agent_freeze_task"
|
||||
"agent_short_link"
|
||||
# "agent_real_name"
|
||||
# "agent_withdrawal_tax"
|
||||
# "agent_invite_code"
|
||||
# ============================================
|
||||
@@ -60,5 +62,68 @@ $tables = @(
|
||||
|
||||
# 为每个表生成模型
|
||||
foreach ($table in $tables) {
|
||||
Write-Host "正在生成表: $table" -ForegroundColor Green
|
||||
goctl model mysql datasource -url="ycc:5vg67b3UNHu8@tcp(127.0.0.1:21001)/ycc" -table="$table" -dir="./model" --home="../template" -cache=true --style=goZero
|
||||
|
||||
# 移动生成的文件到目标目录
|
||||
if (Test-Path $OUTPUT_DIR) {
|
||||
$sourceFiles = Get-ChildItem -Path $OUTPUT_DIR -File
|
||||
|
||||
foreach ($file in $sourceFiles) {
|
||||
$fileName = $file.Name
|
||||
$targetPath = Join-Path $TARGET_DIR $fileName
|
||||
$sourcePath = $file.FullName
|
||||
|
||||
# 检查文件类型并决定是否移动
|
||||
$shouldMove = $false
|
||||
$shouldOverwrite = $false
|
||||
|
||||
if ($fileName -eq "vars.go") {
|
||||
# vars.go: 如果目标目录不存在才移动
|
||||
if (-not (Test-Path $targetPath)) {
|
||||
$shouldMove = $true
|
||||
Write-Host " 移动 $fileName (vars.go 不存在于目标目录)" -ForegroundColor Yellow
|
||||
}
|
||||
else {
|
||||
Write-Host " 跳过 $fileName (vars.go 已存在于目标目录,防止覆盖)" -ForegroundColor Cyan
|
||||
}
|
||||
}
|
||||
elseif ($fileName -match "_gen\.go$") {
|
||||
# 带 _gen 后缀的文件: 直接覆盖
|
||||
$shouldMove = $true
|
||||
$shouldOverwrite = $true
|
||||
Write-Host " 移动 $fileName (覆盖 _gen 文件)" -ForegroundColor Yellow
|
||||
}
|
||||
else {
|
||||
# 不带 _gen 后缀的文件: 如果目标目录不存在才移动
|
||||
if (-not (Test-Path $targetPath)) {
|
||||
$shouldMove = $true
|
||||
Write-Host " 移动 $fileName (非 _gen 文件不存在于目标目录)" -ForegroundColor Yellow
|
||||
}
|
||||
else {
|
||||
Write-Host " 跳过 $fileName (非 _gen 文件已存在于目标目录,防止覆盖)" -ForegroundColor Cyan
|
||||
}
|
||||
}
|
||||
|
||||
# 执行移动操作
|
||||
if ($shouldMove) {
|
||||
# 确保目标目录存在
|
||||
if (-not (Test-Path $TARGET_DIR)) {
|
||||
New-Item -ItemType Directory -Path $TARGET_DIR -Force | Out-Null
|
||||
}
|
||||
|
||||
# 如果目标文件存在且需要覆盖,先删除
|
||||
if ($shouldOverwrite -and (Test-Path $targetPath)) {
|
||||
Remove-Item -Path $targetPath -Force
|
||||
}
|
||||
|
||||
# 移动文件
|
||||
Move-Item -Path $sourcePath -Destination $targetPath -Force
|
||||
Write-Host " ✓ 已移动到: $targetPath" -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host '所有模型文件生成并移动完成!' -ForegroundColor Green
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ AgentInviteCodeModel = (*customAgentInviteCodeModel)(nil)
|
||||
|
||||
type (
|
||||
// AgentInviteCodeModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customAgentInviteCodeModel.
|
||||
AgentInviteCodeModel interface {
|
||||
agentInviteCodeModel
|
||||
}
|
||||
|
||||
customAgentInviteCodeModel struct {
|
||||
*defaultAgentInviteCodeModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewAgentInviteCodeModel returns a model for the database table.
|
||||
func NewAgentInviteCodeModel(conn sqlx.SqlConn, c cache.CacheConf) AgentInviteCodeModel {
|
||||
return &customAgentInviteCodeModel{
|
||||
defaultAgentInviteCodeModel: newAgentInviteCodeModel(conn, c),
|
||||
}
|
||||
}
|
||||
@@ -1,414 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT!
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
"ycc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
agentInviteCodeFieldNames = builder.RawFieldNames(&AgentInviteCode{})
|
||||
agentInviteCodeRows = strings.Join(agentInviteCodeFieldNames, ",")
|
||||
agentInviteCodeRowsExpectAutoSet = strings.Join(stringx.Remove(agentInviteCodeFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
agentInviteCodeRowsWithPlaceHolder = strings.Join(stringx.Remove(agentInviteCodeFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheYccAgentInviteCodeIdPrefix = "cache:ycc:agentInviteCode:id:"
|
||||
cacheYccAgentInviteCodeCodePrefix = "cache:ycc:agentInviteCode:code:"
|
||||
)
|
||||
|
||||
type (
|
||||
agentInviteCodeModel interface {
|
||||
Insert(ctx context.Context, session sqlx.Session, data *AgentInviteCode) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*AgentInviteCode, error)
|
||||
FindOneByCode(ctx context.Context, code string) (*AgentInviteCode, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *AgentInviteCode) (sql.Result, error)
|
||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentInviteCode) error
|
||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||
SelectBuilder() squirrel.SelectBuilder
|
||||
DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentInviteCode) error
|
||||
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*AgentInviteCode, error)
|
||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentInviteCode, error)
|
||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentInviteCode, int64, error)
|
||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentInviteCode, error)
|
||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentInviteCode, error)
|
||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
||||
}
|
||||
|
||||
defaultAgentInviteCodeModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
AgentInviteCode struct {
|
||||
Id int64 `db:"id"` // 主键ID
|
||||
Code string `db:"code"` // 邀请码(唯一)
|
||||
AgentId sql.NullInt64 `db:"agent_id"` // 发放代理ID(NULL表示平台发放的钻石邀请码)
|
||||
TargetLevel int64 `db:"target_level"` // 目标等级:1=普通,2=黄金,3=钻石
|
||||
Status int64 `db:"status"` // 状态:0=未使用,1=已使用,2=已失效(所有邀请码只能使用一次,使用后立即失效)
|
||||
UsedUserId sql.NullInt64 `db:"used_user_id"` // 使用用户ID
|
||||
UsedAgentId sql.NullInt64 `db:"used_agent_id"` // 使用代理ID
|
||||
UsedTime sql.NullTime `db:"used_time"` // 使用时间
|
||||
ExpireTime sql.NullTime `db:"expire_time"` // 过期时间(可选)
|
||||
Remark sql.NullString `db:"remark"` // 备注
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态:0=未删除,1=已删除
|
||||
Version int64 `db:"version"` // 版本号(乐观锁)
|
||||
}
|
||||
)
|
||||
|
||||
func newAgentInviteCodeModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentInviteCodeModel {
|
||||
return &defaultAgentInviteCodeModel{
|
||||
CachedConn: sqlc.NewConn(conn, c),
|
||||
table: "`agent_invite_code`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) Insert(ctx context.Context, session sqlx.Session, data *AgentInviteCode) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
yccAgentInviteCodeCodeKey := fmt.Sprintf("%s%v", cacheYccAgentInviteCodeCodePrefix, data.Code)
|
||||
yccAgentInviteCodeIdKey := fmt.Sprintf("%s%v", cacheYccAgentInviteCodeIdPrefix, data.Id)
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, agentInviteCodeRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.Code, data.AgentId, data.TargetLevel, data.Status, data.UsedUserId, data.UsedAgentId, data.UsedTime, data.ExpireTime, data.Remark, data.DeleteTime, data.DelState, data.Version)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.Code, data.AgentId, data.TargetLevel, data.Status, data.UsedUserId, data.UsedAgentId, data.UsedTime, data.ExpireTime, data.Remark, data.DeleteTime, data.DelState, data.Version)
|
||||
}, yccAgentInviteCodeCodeKey, yccAgentInviteCodeIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) FindOne(ctx context.Context, id int64) (*AgentInviteCode, error) {
|
||||
yccAgentInviteCodeIdKey := fmt.Sprintf("%s%v", cacheYccAgentInviteCodeIdPrefix, id)
|
||||
var resp AgentInviteCode
|
||||
err := m.QueryRowCtx(ctx, &resp, yccAgentInviteCodeIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", agentInviteCodeRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) FindOneByCode(ctx context.Context, code string) (*AgentInviteCode, error) {
|
||||
yccAgentInviteCodeCodeKey := fmt.Sprintf("%s%v", cacheYccAgentInviteCodeCodePrefix, code)
|
||||
var resp AgentInviteCode
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, yccAgentInviteCodeCodeKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `code` = ? and del_state = ? limit 1", agentInviteCodeRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, code, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) Update(ctx context.Context, session sqlx.Session, newData *AgentInviteCode) (sql.Result, error) {
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
yccAgentInviteCodeCodeKey := fmt.Sprintf("%s%v", cacheYccAgentInviteCodeCodePrefix, data.Code)
|
||||
yccAgentInviteCodeIdKey := fmt.Sprintf("%s%v", cacheYccAgentInviteCodeIdPrefix, data.Id)
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, agentInviteCodeRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.Code, newData.AgentId, newData.TargetLevel, newData.Status, newData.UsedUserId, newData.UsedAgentId, newData.UsedTime, newData.ExpireTime, newData.Remark, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.Code, newData.AgentId, newData.TargetLevel, newData.Status, newData.UsedUserId, newData.UsedAgentId, newData.UsedTime, newData.ExpireTime, newData.Remark, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
||||
}, yccAgentInviteCodeCodeKey, yccAgentInviteCodeIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *AgentInviteCode) error {
|
||||
|
||||
oldVersion := newData.Version
|
||||
newData.Version += 1
|
||||
|
||||
var sqlResult sql.Result
|
||||
var err error
|
||||
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
yccAgentInviteCodeCodeKey := fmt.Sprintf("%s%v", cacheYccAgentInviteCodeCodePrefix, data.Code)
|
||||
yccAgentInviteCodeIdKey := fmt.Sprintf("%s%v", cacheYccAgentInviteCodeIdPrefix, data.Id)
|
||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, agentInviteCodeRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.Code, newData.AgentId, newData.TargetLevel, newData.Status, newData.UsedUserId, newData.UsedAgentId, newData.UsedTime, newData.ExpireTime, newData.Remark, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.Code, newData.AgentId, newData.TargetLevel, newData.Status, newData.UsedUserId, newData.UsedAgentId, newData.UsedTime, newData.ExpireTime, newData.Remark, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
||||
}, yccAgentInviteCodeCodeKey, yccAgentInviteCodeIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateCount, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentInviteCode) error {
|
||||
data.DelState = globalkey.DelStateYes
|
||||
data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true}
|
||||
if err := m.UpdateWithVersion(ctx, session, data); err != nil {
|
||||
return errors.Wrapf(errors.New("delete soft failed "), "AgentInviteCodeModel delete err : %+v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp float64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("COUNT(" + field + ")")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp int64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*AgentInviteCode, error) {
|
||||
|
||||
builder = builder.Columns(agentInviteCodeRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentInviteCode
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentInviteCode, error) {
|
||||
|
||||
builder = builder.Columns(agentInviteCodeRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentInviteCode
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentInviteCode, int64, error) {
|
||||
|
||||
total, err := m.FindCount(ctx, builder, "id")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
builder = builder.Columns(agentInviteCodeRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, total, err
|
||||
}
|
||||
|
||||
var resp []*AgentInviteCode
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, total, nil
|
||||
default:
|
||||
return nil, total, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentInviteCode, error) {
|
||||
|
||||
builder = builder.Columns(agentInviteCodeRows)
|
||||
|
||||
if preMinId > 0 {
|
||||
builder = builder.Where(" id < ? ", preMinId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentInviteCode
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentInviteCode, error) {
|
||||
|
||||
builder = builder.Columns(agentInviteCodeRows)
|
||||
|
||||
if preMaxId > 0 {
|
||||
builder = builder.Where(" id > ? ", preMaxId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentInviteCode
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||
|
||||
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
return fn(ctx, session)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) SelectBuilder() squirrel.SelectBuilder {
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultAgentInviteCodeModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||
data, err := m.FindOne(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
yccAgentInviteCodeCodeKey := fmt.Sprintf("%s%v", cacheYccAgentInviteCodeCodePrefix, data.Code)
|
||||
yccAgentInviteCodeIdKey := fmt.Sprintf("%s%v", cacheYccAgentInviteCodeIdPrefix, id)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, yccAgentInviteCodeCodeKey, yccAgentInviteCodeIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultAgentInviteCodeModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheYccAgentInviteCodeIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultAgentInviteCodeModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", agentInviteCodeRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
func (m *defaultAgentInviteCodeModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
Reference in New Issue
Block a user