// Code generated by goctl. DO NOT EDIT. package genModel 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 ( serverOrderFieldNames = builder.RawFieldNames(&ServerOrder{}) serverOrderRows = strings.Join(serverOrderFieldNames, ",") serverOrderRowsExpectAutoSet = strings.Join(stringx.Remove(serverOrderFieldNames, "`order_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") serverOrderRowsWithPlaceHolder = strings.Join(stringx.Remove(serverOrderFieldNames, "`order_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" ) type ( serverOrderModel interface { Insert(ctx context.Context, data *ServerOrder) (sql.Result, error) FindOne(ctx context.Context, orderId uint64) (*ServerOrder, error) Update(ctx context.Context, data *ServerOrder) error Delete(ctx context.Context, orderId uint64) error FindByOutBizNo(ctx context.Context, out_biz_no string) (*ServerOrder, error) } defaultServerOrderModel struct { conn sqlx.SqlConn table string } ServerOrder struct { OrderId uint64 `db:"order_id"` PlatformId int64 `db:"platform_id"` // 下游平台id OutBizNo string `db:"out_biz_no"` // 用户侧流水号 VoucherNum string `db:"voucher_num"` // 商户号 OrderNum string `db:"order_num"` // 系统侧订单号 ProductId int64 `db:"product_id"` // 平台提供商品id Num int64 `db:"num"` // 购买数量 LogId sql.NullInt64 `db:"log_id"` // 对应的日志id ReqTime time.Time `db:"req_time"` // 请求时间 CreateTime time.Time `db:"create_time"` UpdateTime time.Time `db:"update_time"` Status int64 `db:"status"` // 状态 } ) func newServerOrderModel(conn sqlx.SqlConn) *defaultServerOrderModel { return &defaultServerOrderModel{ conn: conn, table: "`server_order`", } } func (m *defaultServerOrderModel) Delete(ctx context.Context, orderId uint64) error { query := fmt.Sprintf("delete from %s where `order_id` = ?", m.table) _, err := m.conn.ExecCtx(ctx, query, orderId) return err } func (m *defaultServerOrderModel) FindOne(ctx context.Context, orderId uint64) (*ServerOrder, error) { query := fmt.Sprintf("select %s from %s where `order_id` = ? limit 1", serverOrderRows, m.table) var resp ServerOrder err := m.conn.QueryRowCtx(ctx, &resp, query, orderId) switch err { case nil: return &resp, nil case sqlx.ErrNotFound: return nil, ErrNotFound default: return nil, err } } func (m *defaultServerOrderModel) FindByOutBizNo(ctx context.Context, out_biz_no string) (*ServerOrder, error) { query := fmt.Sprintf("select %s from %s where `out_biz_no` = ? limit 1", serverOrderRows, m.table) var resp ServerOrder err := m.conn.QueryRowCtx(ctx, &resp, query, out_biz_no) switch err { case nil: return &resp, nil case sqlx.ErrNotFound: return nil, ErrNotFound default: return nil, err } } func (m *defaultServerOrderModel) Insert(ctx context.Context, data *ServerOrder) (sql.Result, error) { query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, serverOrderRowsExpectAutoSet) ret, err := m.conn.ExecCtx(ctx, query, data.PlatformId, data.OutBizNo, data.VoucherNum, data.OrderNum, data.ProductId, data.Num, data.LogId, data.ReqTime, data.Status) return ret, err } func (m *defaultServerOrderModel) Update(ctx context.Context, data *ServerOrder) error { query := fmt.Sprintf("update %s set %s where `order_id` = ?", m.table, serverOrderRowsWithPlaceHolder) _, err := m.conn.ExecCtx(ctx, query, data.PlatformId, data.OutBizNo, data.VoucherNum, data.OrderNum, data.ProductId, data.Num, data.LogId, data.ReqTime, data.Status, data.OrderId) return err } func (m *defaultServerOrderModel) tableName() string { return m.table }