init
This commit is contained in:
50
model/config_api/configapimodel.go
Normal file
50
model/config_api/configapimodel.go
Normal file
@ -0,0 +1,50 @@
|
||||
package config_api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ ConfigApiModel = (*customConfigApiModel)(nil)
|
||||
|
||||
type (
|
||||
// ConfigApiModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customConfigApiModel.
|
||||
ConfigApiModel interface {
|
||||
configApiModel
|
||||
withSession(session sqlx.Session) ConfigApiModel
|
||||
FindList(ctx context.Context) ([]ConfigApi, error)
|
||||
}
|
||||
|
||||
customConfigApiModel struct {
|
||||
*defaultConfigApiModel
|
||||
}
|
||||
)
|
||||
|
||||
func (m *customConfigApiModel) FindList(ctx context.Context) ([]ConfigApi, error) {
|
||||
|
||||
query := fmt.Sprintf("select %s from %s", configApiRows, m.table)
|
||||
var resp []ConfigApi
|
||||
err := m.conn.QueryRowsCtx(ctx, &resp, query)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// NewConfigApiModel returns a model for the database table.
|
||||
func NewConfigApiModel(conn sqlx.SqlConn) ConfigApiModel {
|
||||
return &customConfigApiModel{
|
||||
defaultConfigApiModel: newConfigApiModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customConfigApiModel) withSession(session sqlx.Session) ConfigApiModel {
|
||||
return NewConfigApiModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
87
model/config_api/configapimodel_gen.go
Normal file
87
model/config_api/configapimodel_gen.go
Normal file
@ -0,0 +1,87 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.6
|
||||
|
||||
package config_api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
configApiFieldNames = builder.RawFieldNames(&ConfigApi{})
|
||||
configApiRows = strings.Join(configApiFieldNames, ",")
|
||||
configApiRowsExpectAutoSet = strings.Join(stringx.Remove(configApiFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
configApiRowsWithPlaceHolder = strings.Join(stringx.Remove(configApiFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
configApiModel interface {
|
||||
Insert(ctx context.Context, data *ConfigApi) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*ConfigApi, error)
|
||||
Update(ctx context.Context, data *ConfigApi) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultConfigApiModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
ConfigApi struct {
|
||||
Id int64 `db:"id"` // 主键ID
|
||||
Type string `db:"type"` // 接口类型 0:172
|
||||
Key sql.NullString `db:"key"` // key
|
||||
Secret sql.NullString `db:"secret"` // 密钥
|
||||
}
|
||||
)
|
||||
|
||||
func newConfigApiModel(conn sqlx.SqlConn) *defaultConfigApiModel {
|
||||
return &defaultConfigApiModel{
|
||||
conn: conn,
|
||||
table: "`config_api`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultConfigApiModel) 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 *defaultConfigApiModel) FindOne(ctx context.Context, id int64) (*ConfigApi, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", configApiRows, m.table)
|
||||
var resp ConfigApi
|
||||
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 *defaultConfigApiModel) Insert(ctx context.Context, data *ConfigApi) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, configApiRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Type, data.Key, data.Secret)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultConfigApiModel) Update(ctx context.Context, data *ConfigApi) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, configApiRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.Type, data.Key, data.Secret, data.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultConfigApiModel) tableName() string {
|
||||
return m.table
|
||||
}
|
5
model/config_api/vars.go
Normal file
5
model/config_api/vars.go
Normal file
@ -0,0 +1,5 @@
|
||||
package config_api
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var ErrNotFound = sqlx.ErrNotFound
|
54
model/goods_info/goodsinfomodel.go
Normal file
54
model/goods_info/goodsinfomodel.go
Normal file
@ -0,0 +1,54 @@
|
||||
package goods_info
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ GoodsInfoModel = (*customGoodsInfoModel)(nil)
|
||||
|
||||
type (
|
||||
// GoodsInfoModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customGoodsInfoModel.
|
||||
GoodsInfoModel interface {
|
||||
goodsInfoModel
|
||||
withSession(session sqlx.Session) GoodsInfoModel
|
||||
GetGoodsIndex(ctx context.Context, value string) ([]GoodsInfo, error)
|
||||
}
|
||||
|
||||
customGoodsInfoModel struct {
|
||||
*defaultGoodsInfoModel
|
||||
}
|
||||
)
|
||||
|
||||
func (m *customGoodsInfoModel) GetGoodsIndex(ctx context.Context, value string) ([]GoodsInfo, error) {
|
||||
var resp []GoodsInfo
|
||||
var err error
|
||||
if len(value) > 1 || value != "0" {
|
||||
query := fmt.Sprintf("select %s from %s where status = 1 and type = ? order by id desc", goodsInfoRows, m.table)
|
||||
err = m.conn.QueryRowsCtx(ctx, &resp, query, value)
|
||||
} else {
|
||||
query := fmt.Sprintf("select %s from %s where status = 1 order by id desc", goodsInfoRows, m.table)
|
||||
err = m.conn.QueryRowsCtx(ctx, &resp, query)
|
||||
}
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// NewGoodsInfoModel returns a model for the database table.
|
||||
func NewGoodsInfoModel(conn sqlx.SqlConn) GoodsInfoModel {
|
||||
return &customGoodsInfoModel{
|
||||
defaultGoodsInfoModel: newGoodsInfoModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customGoodsInfoModel) withSession(session sqlx.Session) GoodsInfoModel {
|
||||
return NewGoodsInfoModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
105
model/goods_info/goodsinfomodel_gen.go
Normal file
105
model/goods_info/goodsinfomodel_gen.go
Normal file
@ -0,0 +1,105 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.6
|
||||
|
||||
package goods_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 (
|
||||
goodsInfoFieldNames = builder.RawFieldNames(&GoodsInfo{})
|
||||
goodsInfoRows = strings.Join(goodsInfoFieldNames, ",")
|
||||
goodsInfoRowsExpectAutoSet = strings.Join(stringx.Remove(goodsInfoFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
goodsInfoRowsWithPlaceHolder = strings.Join(stringx.Remove(goodsInfoFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
goodsInfoModel interface {
|
||||
Insert(ctx context.Context, data *GoodsInfo) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*GoodsInfo, error)
|
||||
Update(ctx context.Context, data *GoodsInfo) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultGoodsInfoModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
GoodsInfo struct {
|
||||
Id int64 `db:"id"` // 主键ID
|
||||
Type string `db:"type"` // 运营商 0:未标注 1:电信 2:联通 3:移动 4:光电
|
||||
Name string `db:"name"` // 商品名
|
||||
MainPic string `db:"main_pic"` // 主图
|
||||
LittlePicture string `db:"little_picture"` // 详情图
|
||||
NetAddr string `db:"netAddr"` // 商品套餐资料介绍地址
|
||||
Area string `db:"area"` // 归属地
|
||||
UniFlow string `db:"uni_flow"` // 通用流量
|
||||
DirFlow string `db:"dir_flow"` // 定向流量
|
||||
TalkTime string `db:"talk_time"` // 通话时间
|
||||
DisableArea string `db:"disable_area"` // 禁发地区
|
||||
DisableAge string `db:"disable_age"` // 年龄限制
|
||||
DisableContract string `db:"disable_contract"` // 合约期
|
||||
Notes sql.NullString `db:"notes"` // 商品说明
|
||||
ApiId sql.NullInt64 `db:"api_id"` // 三方接口
|
||||
ApiProductId sql.NullInt64 `db:"api_product_id"` // 三方商品id
|
||||
NumberSel string `db:"number_sel"` // 是否选号 0:不支持 1:收货地不是归属地 2:收货地是归属地
|
||||
Status string `db:"status"` // 状态 0:上架 1:下架
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
Remarks sql.NullString `db:"remarks"` // 备注
|
||||
}
|
||||
)
|
||||
|
||||
func newGoodsInfoModel(conn sqlx.SqlConn) *defaultGoodsInfoModel {
|
||||
return &defaultGoodsInfoModel{
|
||||
conn: conn,
|
||||
table: "`goods_info`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultGoodsInfoModel) 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 *defaultGoodsInfoModel) FindOne(ctx context.Context, id int64) (*GoodsInfo, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", goodsInfoRows, m.table)
|
||||
var resp GoodsInfo
|
||||
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 *defaultGoodsInfoModel) Insert(ctx context.Context, data *GoodsInfo) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, goodsInfoRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Type, data.Name, data.MainPic, data.LittlePicture, data.NetAddr, data.Area, data.UniFlow, data.DirFlow, data.TalkTime, data.DisableArea, data.DisableAge, data.DisableContract, data.Notes, data.ApiId, data.ApiProductId, data.NumberSel, data.Status, data.Remarks)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultGoodsInfoModel) Update(ctx context.Context, data *GoodsInfo) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, goodsInfoRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.Type, data.Name, data.MainPic, data.LittlePicture, data.NetAddr, data.Area, data.UniFlow, data.DirFlow, data.TalkTime, data.DisableArea, data.DisableAge, data.DisableContract, data.Notes, data.ApiId, data.ApiProductId, data.NumberSel, data.Status, data.Remarks, data.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultGoodsInfoModel) tableName() string {
|
||||
return m.table
|
||||
}
|
5
model/goods_info/vars.go
Normal file
5
model/goods_info/vars.go
Normal file
@ -0,0 +1,5 @@
|
||||
package goods_info
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var ErrNotFound = sqlx.ErrNotFound
|
92
model/goods_status/goodsstatusmodel.go
Normal file
92
model/goods_status/goodsstatusmodel.go
Normal file
@ -0,0 +1,92 @@
|
||||
package goods_status
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var _ GoodsStatusModel = (*customGoodsStatusModel)(nil)
|
||||
|
||||
type (
|
||||
// GoodsStatusModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customGoodsStatusModel.
|
||||
GoodsStatusModel interface {
|
||||
goodsStatusModel
|
||||
withSession(session sqlx.Session) GoodsStatusModel
|
||||
DeleteByApiId(ctx context.Context, id int64) error
|
||||
FindUpList(ctx context.Context, apiId int64) ([]int64, error)
|
||||
UpdateDownByIds(ctx context.Context, ids []int64) error
|
||||
FindNotIdOne(ctx context.Context, apiId int64) (int64, error)
|
||||
}
|
||||
|
||||
customGoodsStatusModel struct {
|
||||
*defaultGoodsStatusModel
|
||||
}
|
||||
)
|
||||
|
||||
func (m *customGoodsStatusModel) FindNotIdOne(ctx context.Context, apiId int64) (int64, error) {
|
||||
query := fmt.Sprintf("select gs.`api_product_id` from %s gs left join `goods_info` gi on gs.`api_id` = gi.`api_id` where gs.`api_id` = ? and gs.`api_product_id` not in (select gs.api_product_id from `goods_status` gs join `goods_info` gi on gs.`api_id` = gi.`api_id` and gi.api_product_id = gs.api_product_id where gs.`api_id` = ?) limit 1", m.table)
|
||||
var resp int64
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, apiId, apiId)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return 0, ErrNotFound
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customGoodsStatusModel) UpdateDownByIds(ctx context.Context, ids []int64) error {
|
||||
// 动态构造 IN 子句中的占位符
|
||||
placeholders := make([]string, len(ids))
|
||||
for i := range ids {
|
||||
placeholders[i] = "?"
|
||||
}
|
||||
query := fmt.Sprintf("update %s set `status` = 0 where `id` in (%s)", m.table, strings.Join(placeholders, ","))
|
||||
_, err := m.conn.ExecCtx(ctx, query, convertToInterface(ids)...)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *customGoodsStatusModel) FindUpList(ctx context.Context, apiId int64) ([]int64, error) {
|
||||
query := fmt.Sprintf("select g.`id` from %s g join `config_api` c on g.`api_id` = c.id where g.status = 0 and c.id = ?", m.table)
|
||||
var resp []int64
|
||||
err := m.conn.QueryRowsCtx(ctx, &resp, query, apiId)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customGoodsStatusModel) DeleteByApiId(ctx context.Context, id int64) error {
|
||||
query := fmt.Sprintf("delete from %s where `api_id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
// NewGoodsStatusModel returns a model for the database table.
|
||||
func NewGoodsStatusModel(conn sqlx.SqlConn) GoodsStatusModel {
|
||||
return &customGoodsStatusModel{
|
||||
defaultGoodsStatusModel: newGoodsStatusModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customGoodsStatusModel) withSession(session sqlx.Session) GoodsStatusModel {
|
||||
return NewGoodsStatusModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
||||
|
||||
// convertToInterface 将 int64 切片转换为接口切片
|
||||
func convertToInterface(ids []int64) []interface{} {
|
||||
result := make([]interface{}, len(ids))
|
||||
for i, id := range ids {
|
||||
result[i] = id
|
||||
}
|
||||
return result
|
||||
}
|
87
model/goods_status/goodsstatusmodel_gen.go
Normal file
87
model/goods_status/goodsstatusmodel_gen.go
Normal file
@ -0,0 +1,87 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.6
|
||||
|
||||
package goods_status
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
goodsStatusFieldNames = builder.RawFieldNames(&GoodsStatus{})
|
||||
goodsStatusRows = strings.Join(goodsStatusFieldNames, ",")
|
||||
goodsStatusRowsExpectAutoSet = strings.Join(stringx.Remove(goodsStatusFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
goodsStatusRowsWithPlaceHolder = strings.Join(stringx.Remove(goodsStatusFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
goodsStatusModel interface {
|
||||
Insert(ctx context.Context, data *GoodsStatus) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*GoodsStatus, error)
|
||||
Update(ctx context.Context, data *GoodsStatus) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultGoodsStatusModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
GoodsStatus struct {
|
||||
Id int64 `db:"id"` // id
|
||||
ApiId sql.NullInt64 `db:"api_id"` // 三方接口
|
||||
ApiProductId sql.NullInt64 `db:"api_product_id"` // 三方商品id
|
||||
Status sql.NullInt64 `db:"status"` // 商品状态 0=上架 1=下架
|
||||
}
|
||||
)
|
||||
|
||||
func newGoodsStatusModel(conn sqlx.SqlConn) *defaultGoodsStatusModel {
|
||||
return &defaultGoodsStatusModel{
|
||||
conn: conn,
|
||||
table: "`goods_status`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultGoodsStatusModel) 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 *defaultGoodsStatusModel) FindOne(ctx context.Context, id int64) (*GoodsStatus, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", goodsStatusRows, m.table)
|
||||
var resp GoodsStatus
|
||||
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 *defaultGoodsStatusModel) Insert(ctx context.Context, data *GoodsStatus) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, goodsStatusRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.ApiId, data.ApiProductId, data.Status)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultGoodsStatusModel) Update(ctx context.Context, data *GoodsStatus) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, goodsStatusRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.ApiId, data.ApiProductId, data.Status, data.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultGoodsStatusModel) tableName() string {
|
||||
return m.table
|
||||
}
|
5
model/goods_status/vars.go
Normal file
5
model/goods_status/vars.go
Normal file
@ -0,0 +1,5 @@
|
||||
package goods_status
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var ErrNotFound = sqlx.ErrNotFound
|
29
model/order_info/oderinfomodel.go
Normal file
29
model/order_info/oderinfomodel.go
Normal file
@ -0,0 +1,29 @@
|
||||
package order_info
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var _ OderInfoModel = (*customOderInfoModel)(nil)
|
||||
|
||||
type (
|
||||
// OderInfoModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customOderInfoModel.
|
||||
OderInfoModel interface {
|
||||
oderInfoModel
|
||||
withSession(session sqlx.Session) OderInfoModel
|
||||
}
|
||||
|
||||
customOderInfoModel struct {
|
||||
*defaultOderInfoModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewOderInfoModel returns a model for the database table.
|
||||
func NewOderInfoModel(conn sqlx.SqlConn) OderInfoModel {
|
||||
return &customOderInfoModel{
|
||||
defaultOderInfoModel: newOderInfoModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customOderInfoModel) withSession(session sqlx.Session) OderInfoModel {
|
||||
return NewOderInfoModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
102
model/order_info/oderinfomodel_gen.go
Normal file
102
model/order_info/oderinfomodel_gen.go
Normal file
@ -0,0 +1,102 @@
|
||||
// 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
|
||||
}
|
5
model/order_info/vars.go
Normal file
5
model/order_info/vars.go
Normal file
@ -0,0 +1,5 @@
|
||||
package order_info
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var ErrNotFound = sqlx.ErrNotFound
|
Reference in New Issue
Block a user