103 lines
4.0 KiB
Go
103 lines
4.0 KiB
Go
![]() |
// Code generated by goctl. DO NOT EDIT.
|
|||
|
// versions:
|
|||
|
// goctl version: 1.7.6
|
|||
|
|
|||
|
package order_info
|
|||
|
|
|||
|
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 (
|
|||
|
oderInfoFieldNames = builder.RawFieldNames(&OderInfo{})
|
|||
|
oderInfoRows = strings.Join(oderInfoFieldNames, ",")
|
|||
|
oderInfoRowsExpectAutoSet = strings.Join(stringx.Remove(oderInfoFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|||
|
oderInfoRowsWithPlaceHolder = strings.Join(stringx.Remove(oderInfoFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|||
|
)
|
|||
|
|
|||
|
type (
|
|||
|
oderInfoModel interface {
|
|||
|
Insert(ctx context.Context, data *OderInfo) (sql.Result, error)
|
|||
|
FindOne(ctx context.Context, id int64) (*OderInfo, error)
|
|||
|
Update(ctx context.Context, data *OderInfo) error
|
|||
|
Delete(ctx context.Context, id int64) error
|
|||
|
}
|
|||
|
|
|||
|
defaultOderInfoModel struct {
|
|||
|
conn sqlx.SqlConn
|
|||
|
table string
|
|||
|
}
|
|||
|
|
|||
|
OderInfo struct {
|
|||
|
Id int64 `db:"id"` // 订单id
|
|||
|
OderId string `db:"oder_id"` // 订单id
|
|||
|
GoodsId string `db:"goods_id"` // 下单产品ID
|
|||
|
Name string `db:"name"` // 姓名
|
|||
|
IdCard string `db:"id_card"` // 身份证号
|
|||
|
Phone string `db:"phone"` // 手机号码
|
|||
|
Province string `db:"province"` // 省
|
|||
|
City string `db:"city"` // 城市
|
|||
|
Area string `db:"area"` // 区/县/镇
|
|||
|
Address string `db:"address"` // 详细地址
|
|||
|
Status string `db:"status"` // 发货处理状态:0=未处理,1=已下单 2=已发货 3已完成 4失败
|
|||
|
ApiId sql.NullString `db:"api_id"` // 接口来源
|
|||
|
ApiOderId sql.NullString `db:"api_oder_id"` // 第三方订单
|
|||
|
ThirdPhone sql.NullString `db:"third_phone"` // 用户办理的号码
|
|||
|
CardStatus string `db:"card_status"` // 号码状态
|
|||
|
CreateTime time.Time `db:"create_time"` // 创建时间
|
|||
|
UpdateTime time.Time `db:"update_time"` // 更新时间
|
|||
|
Remarks sql.NullString `db:"remarks"` // 备注
|
|||
|
}
|
|||
|
)
|
|||
|
|
|||
|
func newOderInfoModel(conn sqlx.SqlConn) *defaultOderInfoModel {
|
|||
|
return &defaultOderInfoModel{
|
|||
|
conn: conn,
|
|||
|
table: "`oder_info`",
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
func (m *defaultOderInfoModel) 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 *defaultOderInfoModel) FindOne(ctx context.Context, id int64) (*OderInfo, error) {
|
|||
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", oderInfoRows, m.table)
|
|||
|
var resp OderInfo
|
|||
|
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 *defaultOderInfoModel) Insert(ctx context.Context, data *OderInfo) (sql.Result, error) {
|
|||
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, oderInfoRowsExpectAutoSet)
|
|||
|
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.OderId, data.GoodsId, data.Name, data.IdCard, data.Phone, data.Province, data.City, data.Area, data.Address, data.Status, data.ApiId, data.ApiOderId, data.ThirdPhone, data.CardStatus, data.Remarks)
|
|||
|
return ret, err
|
|||
|
}
|
|||
|
|
|||
|
func (m *defaultOderInfoModel) Update(ctx context.Context, data *OderInfo) error {
|
|||
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, oderInfoRowsWithPlaceHolder)
|
|||
|
_, err := m.conn.ExecCtx(ctx, query, data.OderId, data.GoodsId, data.Name, data.IdCard, data.Phone, data.Province, data.City, data.Area, data.Address, data.Status, data.ApiId, data.ApiOderId, data.ThirdPhone, data.CardStatus, data.Remarks, data.Id)
|
|||
|
return err
|
|||
|
}
|
|||
|
|
|||
|
func (m *defaultOderInfoModel) tableName() string {
|
|||
|
return m.table
|
|||
|
}
|