122 lines
6.0 KiB
Go
Executable File
122 lines
6.0 KiB
Go
Executable File
// Code generated by goctl. DO NOT EDIT.
|
|
|
|
package model
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
"github.com/zeromicro/go-zero/core/stringx"
|
|
)
|
|
|
|
var (
|
|
fsOrderDetailFieldNames = builder.RawFieldNames(&FsOrderDetail{})
|
|
fsOrderDetailRows = strings.Join(fsOrderDetailFieldNames, ",")
|
|
fsOrderDetailRowsExpectAutoSet = strings.Join(stringx.Remove(fsOrderDetailFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
fsOrderDetailRowsWithPlaceHolder = strings.Join(stringx.Remove(fsOrderDetailFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
fsOrderDetailModel interface {
|
|
Insert(ctx context.Context, data *FsOrderDetail) (sql.Result, error)
|
|
FindOne(ctx context.Context, id int64) (*FsOrderDetail, error)
|
|
FindOneBySn(ctx context.Context, sn string) (*FsOrderDetail, error)
|
|
Update(ctx context.Context, data *FsOrderDetail) error
|
|
Delete(ctx context.Context, id int64) error
|
|
}
|
|
|
|
defaultFsOrderDetailModel struct {
|
|
conn sqlx.SqlConn
|
|
table string
|
|
}
|
|
|
|
FsOrderDetail struct {
|
|
Id int64 `db:"id"`
|
|
Sn string `db:"sn"` // 唯一编码
|
|
OrderId int64 `db:"order_id"` // 订单ID
|
|
UserId sql.NullInt64 `db:"user_id"` // 用户ID
|
|
FactoryId int64 `db:"factory_id"` // 工厂ID
|
|
OrderDetailTemplateId int64 `db:"order_detail_template_id"` // 详情templateID
|
|
ProductId int64 `db:"product_id"` // 产品ID
|
|
BuyNum int64 `db:"buy_num"` // 购买数量
|
|
PushNum int64 `db:"push_num"` // 已发数量
|
|
Amount int64 `db:"amount"` // 单价
|
|
Cover string `db:"cover"` // 截图
|
|
Ctime int64 `db:"ctime"` // 添加时间
|
|
Status int64 `db:"status"` // 状态位 是否推送到厂家 是否生产完成 是否发货完成
|
|
OptionalId int64 `db:"optional_id"` // 选项ID
|
|
OptionalTitle string `db:"optional_title"` // 选项名称
|
|
OptionPrice int64 `db:"option_price"` // 配件价格
|
|
IsTofactory int64 `db:"is_tofactory"` // 是否推送到工厂
|
|
IsProduct int64 `db:"is_product"` // 是否生产中
|
|
IsProductCompletion int64 `db:"is_product_completion"` // 是否生产完成
|
|
IsCloud int64 `db:"is_cloud"` // 是否是云仓订单
|
|
IsTocloud int64 `db:"is_tocloud"` // 是否已发云仓(云仓单要发货到云仓,直接发到用户的不需要发到云仓)
|
|
IsDeliver int64 `db:"is_deliver"` // 是否已发货
|
|
IsEnd int64 `db:"is_end"` // 是否完成订单(签收)
|
|
CartId int64 `db:"cart_id"` // 购物车编号
|
|
}
|
|
)
|
|
|
|
func newFsOrderDetailModel(conn sqlx.SqlConn) *defaultFsOrderDetailModel {
|
|
return &defaultFsOrderDetailModel{
|
|
conn: conn,
|
|
table: "`fs_order_detail`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultFsOrderDetailModel) Delete(ctx context.Context, id int64) error {
|
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
|
_, err := m.conn.ExecCtx(ctx, query, id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultFsOrderDetailModel) FindOne(ctx context.Context, id int64) (*FsOrderDetail, error) {
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsOrderDetailRows, m.table)
|
|
var resp FsOrderDetail
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlc.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultFsOrderDetailModel) FindOneBySn(ctx context.Context, sn string) (*FsOrderDetail, error) {
|
|
var resp FsOrderDetail
|
|
query := fmt.Sprintf("select %s from %s where `sn` = ? limit 1", fsOrderDetailRows, m.table)
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, sn)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlc.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultFsOrderDetailModel) Insert(ctx context.Context, data *FsOrderDetail) (sql.Result, error) {
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsOrderDetailRowsExpectAutoSet)
|
|
ret, err := m.conn.ExecCtx(ctx, query, data.Sn, data.OrderId, data.UserId, data.FactoryId, data.OrderDetailTemplateId, data.ProductId, data.BuyNum, data.PushNum, data.Amount, data.Cover, data.Ctime, data.Status, data.OptionalId, data.OptionalTitle, data.OptionPrice, data.IsTofactory, data.IsProduct, data.IsProductCompletion, data.IsCloud, data.IsTocloud, data.IsDeliver, data.IsEnd, data.CartId)
|
|
return ret, err
|
|
}
|
|
|
|
func (m *defaultFsOrderDetailModel) Update(ctx context.Context, newData *FsOrderDetail) error {
|
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsOrderDetailRowsWithPlaceHolder)
|
|
_, err := m.conn.ExecCtx(ctx, query, newData.Sn, newData.OrderId, newData.UserId, newData.FactoryId, newData.OrderDetailTemplateId, newData.ProductId, newData.BuyNum, newData.PushNum, newData.Amount, newData.Cover, newData.Ctime, newData.Status, newData.OptionalId, newData.OptionalTitle, newData.OptionPrice, newData.IsTofactory, newData.IsProduct, newData.IsProductCompletion, newData.IsCloud, newData.IsTocloud, newData.IsDeliver, newData.IsEnd, newData.CartId, newData.Id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultFsOrderDetailModel) tableName() string {
|
|
return m.table
|
|
}
|