transfer_yl/genModel/merchantWechatModel_gen.go

103 lines
3.9 KiB
Go
Raw Permalink Normal View History

2024-07-16 16:51:39 +08:00
// Code generated by goctl. DO NOT EDIT.
package genModel
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 (
merchantWechatFieldNames = builder.RawFieldNames(&MerchantWechat{})
merchantWechatRows = strings.Join(merchantWechatFieldNames, ",")
merchantWechatRowsExpectAutoSet = strings.Join(stringx.Remove(merchantWechatFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
merchantWechatRowsWithPlaceHolder = strings.Join(stringx.Remove(merchantWechatFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
merchantWechatModel interface {
Insert(ctx context.Context, data *MerchantWechat) (sql.Result, error)
FindOne(ctx context.Context, id uint64) (*MerchantWechat, error)
Update(ctx context.Context, data *MerchantWechat) error
Delete(ctx context.Context, id uint64) error
FindOneByMerchantId(ctx context.Context, merchant_id string) (*MerchantWechat, error)
}
defaultMerchantWechatModel struct {
conn sqlx.SqlConn
table string
}
MerchantWechat struct {
Id uint64 `db:"id"`
MerchantId sql.NullString `db:"merchant_id"` // 商户号
WechatMerchantId sql.NullString `db:"wechat_merchant_id"` // sip的微信商户号
WechatAppId sql.NullString `db:"wechat_app_id"` // sip的微信app_id [{"appid" :"xxxxx", "default": "1"}]支持设置多个appid 但是只能设置一个default = 1 代码当前商户正在用的appid。 如果需要使用其他appid发券 那么需要商户侧通过接口传入appid
NotifyUrl sql.NullString `db:"notify_url"` // 回调通知地址[{"coupon_grant_order":"xxxx"},{"wechat_coupon_status":"xxxxx"}]
CreateTime sql.NullTime `db:"create_time"`
}
)
func newMerchantWechatModel(conn sqlx.SqlConn) *defaultMerchantWechatModel {
return &defaultMerchantWechatModel{
conn: conn,
table: "`merchant_wechat`",
}
}
func (m *defaultMerchantWechatModel) Delete(ctx context.Context, id uint64) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultMerchantWechatModel) FindOne(ctx context.Context, id uint64) (*MerchantWechat, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", merchantWechatRows, m.table)
var resp MerchantWechat
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 *defaultMerchantWechatModel) FindOneByMerchantId(ctx context.Context, merchant_id string) (*MerchantWechat, error) {
query := fmt.Sprintf("select %s from %s where `merchant_id` = ? limit 1", merchantWechatRows, m.table)
var resp MerchantWechat
err := m.conn.QueryRowCtx(ctx, &resp, query, merchant_id)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultMerchantWechatModel) Insert(ctx context.Context, data *MerchantWechat) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, merchantWechatRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.MerchantId, data.WechatMerchantId, data.WechatAppId, data.NotifyUrl)
return ret, err
}
func (m *defaultMerchantWechatModel) Update(ctx context.Context, data *MerchantWechat) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, merchantWechatRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.MerchantId, data.WechatMerchantId, data.WechatAppId, data.NotifyUrl, data.Id)
return err
}
func (m *defaultMerchantWechatModel) tableName() string {
return m.table
}