135 lines
6.7 KiB
Go
135 lines
6.7 KiB
Go
|
// Code generated by goctl. DO NOT EDIT.
|
|||
|
|
|||
|
package marketReseller
|
|||
|
|
|||
|
import (
|
|||
|
"context"
|
|||
|
"database/sql"
|
|||
|
"fmt"
|
|||
|
"strings"
|
|||
|
"time"
|
|||
|
|
|||
|
"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"
|
|||
|
)
|
|||
|
|
|||
|
var (
|
|||
|
resellerFieldNames = builder.RawFieldNames(&Reseller{})
|
|||
|
resellerRows = strings.Join(resellerFieldNames, ",")
|
|||
|
resellerRowsExpectAutoSet = strings.Join(stringx.Remove(resellerFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|||
|
resellerRowsWithPlaceHolder = strings.Join(stringx.Remove(resellerFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|||
|
|
|||
|
cacheResellerResellerIdPrefix = "cache:reseller:reseller:id:"
|
|||
|
)
|
|||
|
|
|||
|
type (
|
|||
|
resellerModel interface {
|
|||
|
Insert(ctx context.Context, data *Reseller) (sql.Result, error)
|
|||
|
FindOne(ctx context.Context, id uint64) (*Reseller, error)
|
|||
|
Update(ctx context.Context, data *Reseller) error
|
|||
|
Delete(ctx context.Context, id uint64) error
|
|||
|
}
|
|||
|
|
|||
|
defaultResellerModel struct {
|
|||
|
sqlc.CachedConn
|
|||
|
table string
|
|||
|
}
|
|||
|
|
|||
|
Reseller struct {
|
|||
|
Id uint64 `db:"id"` // 主键
|
|||
|
Creator int64 `db:"creator"` // 操作人员
|
|||
|
Code string `db:"code"` // 分销商编号
|
|||
|
Name string `db:"name"` // 分销商名称
|
|||
|
Subject string `db:"subject"` // 分销商主体
|
|||
|
Account string `db:"account"` // 登录账号
|
|||
|
Password string `db:"password"` // 登录密码
|
|||
|
Status uint64 `db:"status"` // 分销商账号状态
|
|||
|
HeadImg string `db:"head_img"` // 头像
|
|||
|
SalesmanId uint64 `db:"salesman_id"` // 销售人员ID,后台用户表ID
|
|||
|
SalesmanName string `db:"salesman_name"` // 销售人员名称
|
|||
|
CompanyId uint64 `db:"company_id"` // 所属公司,公司表ID
|
|||
|
CompanyName string `db:"company_name"` // 公司名称
|
|||
|
IdentityType uint64 `db:"identity_type"` // 身份类型
|
|||
|
Balance float64 `db:"balance"` // 分销商余额
|
|||
|
BalanceWarning float64 `db:"balance_warning"` // 余额预警
|
|||
|
FrozenAmount float64 `db:"frozen_amount"` // 冻结金额
|
|||
|
CreditAmount float64 `db:"credit_amount"` // 授信金额
|
|||
|
TotalConsumption float64 `db:"total_consumption"` // 累计消费
|
|||
|
ContactName string `db:"contact_name"` // 联系人名称
|
|||
|
ContactPhone string `db:"contact_phone"` // 联系人电话
|
|||
|
ContactEmail string `db:"contact_email"` // 联系人Email,多个逗号(,)用逗号分开
|
|||
|
CreateTime time.Time `db:"create_time"` // 创建时间
|
|||
|
UpdateTime sql.NullTime `db:"update_time"` // 编辑时间
|
|||
|
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
|||
|
DirectResellerId uint64 `db:"direct_reseller_id"` // 直连天下分销商映射ID
|
|||
|
MapTime sql.NullTime `db:"map_time"` // 映射时间
|
|||
|
}
|
|||
|
)
|
|||
|
|
|||
|
func newResellerModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultResellerModel {
|
|||
|
return &defaultResellerModel{
|
|||
|
CachedConn: sqlc.NewConn(conn, c, opts...),
|
|||
|
table: "`reseller`",
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
func (m *defaultResellerModel) Delete(ctx context.Context, id uint64) error {
|
|||
|
resellerResellerIdKey := fmt.Sprintf("%s%v", cacheResellerResellerIdPrefix, 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)
|
|||
|
return conn.ExecCtx(ctx, query, id)
|
|||
|
}, resellerResellerIdKey)
|
|||
|
return err
|
|||
|
}
|
|||
|
|
|||
|
func (m *defaultResellerModel) FindOne(ctx context.Context, id uint64) (*Reseller, error) {
|
|||
|
resellerResellerIdKey := fmt.Sprintf("%s%v", cacheResellerResellerIdPrefix, id)
|
|||
|
var resp Reseller
|
|||
|
err := m.QueryRowCtx(ctx, &resp, resellerResellerIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
|||
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", resellerRows, m.table)
|
|||
|
return conn.QueryRowCtx(ctx, v, query, id)
|
|||
|
})
|
|||
|
switch err {
|
|||
|
case nil:
|
|||
|
return &resp, nil
|
|||
|
case sqlc.ErrNotFound:
|
|||
|
return nil, ErrNotFound
|
|||
|
default:
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
func (m *defaultResellerModel) Insert(ctx context.Context, data *Reseller) (sql.Result, error) {
|
|||
|
resellerResellerIdKey := fmt.Sprintf("%s%v", cacheResellerResellerIdPrefix, data.Id)
|
|||
|
ret, err := 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, resellerRowsExpectAutoSet)
|
|||
|
return conn.ExecCtx(ctx, query, data.Creator, data.Code, data.Name, data.Subject, data.Account, data.Password, data.Status, data.HeadImg, data.SalesmanId, data.SalesmanName, data.CompanyId, data.CompanyName, data.IdentityType, data.Balance, data.BalanceWarning, data.FrozenAmount, data.CreditAmount, data.TotalConsumption, data.ContactName, data.ContactPhone, data.ContactEmail, data.DeleteTime, data.DirectResellerId, data.MapTime)
|
|||
|
}, resellerResellerIdKey)
|
|||
|
return ret, err
|
|||
|
}
|
|||
|
|
|||
|
func (m *defaultResellerModel) Update(ctx context.Context, data *Reseller) error {
|
|||
|
resellerResellerIdKey := fmt.Sprintf("%s%v", cacheResellerResellerIdPrefix, data.Id)
|
|||
|
_, 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` = ?", m.table, resellerRowsWithPlaceHolder)
|
|||
|
return conn.ExecCtx(ctx, query, data.Creator, data.Code, data.Name, data.Subject, data.Account, data.Password, data.Status, data.HeadImg, data.SalesmanId, data.SalesmanName, data.CompanyId, data.CompanyName, data.IdentityType, data.Balance, data.BalanceWarning, data.FrozenAmount, data.CreditAmount, data.TotalConsumption, data.ContactName, data.ContactPhone, data.ContactEmail, data.DeleteTime, data.DirectResellerId, data.MapTime, data.Id)
|
|||
|
}, resellerResellerIdKey)
|
|||
|
return err
|
|||
|
}
|
|||
|
|
|||
|
func (m *defaultResellerModel) formatPrimary(primary any) string {
|
|||
|
return fmt.Sprintf("%s%v", cacheResellerResellerIdPrefix, primary)
|
|||
|
}
|
|||
|
|
|||
|
func (m *defaultResellerModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
|||
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", resellerRows, m.table)
|
|||
|
return conn.QueryRowCtx(ctx, v, query, primary)
|
|||
|
}
|
|||
|
|
|||
|
func (m *defaultResellerModel) tableName() string {
|
|||
|
return m.table
|
|||
|
}
|