cmb
This commit is contained in:
parent
5d875ea1b0
commit
1d61bd84f4
|
|
@ -0,0 +1,17 @@
|
||||||
|
package bo
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
// ProductBo 领域实体Bo结构,字段和模型字段保持一致
|
||||||
|
type ProductBo struct {
|
||||||
|
ID int32
|
||||||
|
Name string
|
||||||
|
ProductNo string
|
||||||
|
BatchName string
|
||||||
|
BatchNo string
|
||||||
|
AppID string
|
||||||
|
MerchantNo string
|
||||||
|
Channel bool
|
||||||
|
CreateTime time.Time
|
||||||
|
UpdateTime time.Time
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package repo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"voucher/internal/biz/bo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ProductRepo interface {
|
||||||
|
GetByPNO(ctx context.Context, PNO string) (*bo.ProductBo, error)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||||
|
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||||
|
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const TableNameProduct = "product"
|
||||||
|
|
||||||
|
// Product mapped from table <product>
|
||||||
|
type Product struct {
|
||||||
|
ID int32 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||||
|
Name string `gorm:"column:name;not null;comment:商品名称" json:"name"` // 商品名称
|
||||||
|
ProductNo string `gorm:"column:product_no;not null;comment:商品编号" json:"product_no"` // 商品编号
|
||||||
|
BatchName string `gorm:"column:batch_name;not null;comment:批次名称" json:"batch_name"` // 批次名称
|
||||||
|
BatchNo string `gorm:"column:batch_no;not null;comment:立减金批次号" json:"batch_no"` // 立减金批次号
|
||||||
|
AppID string `gorm:"column:app_id;not null;comment:批次所属应用" json:"app_id"` // 批次所属应用
|
||||||
|
MerchantNo string `gorm:"column:merchant_no;not null;comment:商户号,创建批次的商户号" json:"merchant_no"` // 商户号,创建批次的商户号
|
||||||
|
Channel bool `gorm:"column:channel;not null;comment:1:微信 2:支付宝" json:"channel"` // 1:微信 2:支付宝
|
||||||
|
CreateTime time.Time `gorm:"column:create_time;not null" json:"create_time"`
|
||||||
|
UpdateTime time.Time `gorm:"column:update_time" json:"update_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TableName Product's table name
|
||||||
|
func (*Product) TableName() string {
|
||||||
|
return TableNameProduct
|
||||||
|
}
|
||||||
|
|
@ -4,12 +4,14 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"voucher/internal/biz/bo"
|
"voucher/internal/biz/bo"
|
||||||
"voucher/internal/biz/repo"
|
"voucher/internal/biz/repo"
|
||||||
|
"voucher/internal/data"
|
||||||
"voucher/internal/data/model"
|
"voucher/internal/data/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
// OrderWechatRepoImpl .
|
// OrderWechatRepoImpl .
|
||||||
type OrderWechatRepoImpl struct {
|
type OrderWechatRepoImpl struct {
|
||||||
Base[model.OrderWechat, bo.OrderWechatBo]
|
Base[model.OrderWechat, bo.OrderWechatBo]
|
||||||
|
db *data.Db
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOrderWechatRepoImpl .
|
// NewOrderWechatRepoImpl .
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package repoimpl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"voucher/internal/biz/bo"
|
||||||
|
"voucher/internal/biz/repo"
|
||||||
|
"voucher/internal/data"
|
||||||
|
"voucher/internal/data/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProductRepoImpl .
|
||||||
|
type ProductRepoImpl struct {
|
||||||
|
Base[model.Product, bo.ProductBo]
|
||||||
|
db *data.Db
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewProductRepoImpl .
|
||||||
|
func NewProductRepoImpl() repo.ProductRepo {
|
||||||
|
return &ProductRepoImpl{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ProductRepoImpl) DB(ctx context.Context) *gorm.DB {
|
||||||
|
return p.db.DB(ctx).Model(model.Product{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ProductRepoImpl) GetByPNO(ctx context.Context, PNO string) (*bo.ProductBo, error) {
|
||||||
|
var item model.Product
|
||||||
|
|
||||||
|
tx := r.DB(ctx).Where(model.Product{ProductNo: PNO}).Find(&item)
|
||||||
|
|
||||||
|
if tx.Error != nil {
|
||||||
|
return nil, tx.Error
|
||||||
|
}
|
||||||
|
if tx.RowsAffected == 0 {
|
||||||
|
return nil, gorm.ErrRecordNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.ToBo(&item), nil
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue