diff --git a/internal/biz/bo/product_bo.go b/internal/biz/bo/product_bo.go new file mode 100644 index 0000000..b14b938 --- /dev/null +++ b/internal/biz/bo/product_bo.go @@ -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 +} diff --git a/internal/biz/repo/product.go b/internal/biz/repo/product.go new file mode 100644 index 0000000..8d9f031 --- /dev/null +++ b/internal/biz/repo/product.go @@ -0,0 +1,10 @@ +package repo + +import ( + "context" + "voucher/internal/biz/bo" +) + +type ProductRepo interface { + GetByPNO(ctx context.Context, PNO string) (*bo.ProductBo, error) +} diff --git a/internal/data/model/product.gen.go b/internal/data/model/product.gen.go new file mode 100644 index 0000000..890f74b --- /dev/null +++ b/internal/data/model/product.gen.go @@ -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 +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 +} diff --git a/internal/data/repoimpl/order_wechat.go b/internal/data/repoimpl/order_wechat.go index c8ecccd..8673af3 100644 --- a/internal/data/repoimpl/order_wechat.go +++ b/internal/data/repoimpl/order_wechat.go @@ -4,12 +4,14 @@ import ( "context" "voucher/internal/biz/bo" "voucher/internal/biz/repo" + "voucher/internal/data" "voucher/internal/data/model" ) // OrderWechatRepoImpl . type OrderWechatRepoImpl struct { Base[model.OrderWechat, bo.OrderWechatBo] + db *data.Db } // NewOrderWechatRepoImpl . diff --git a/internal/data/repoimpl/product.go b/internal/data/repoimpl/product.go new file mode 100644 index 0000000..ebb8e18 --- /dev/null +++ b/internal/data/repoimpl/product.go @@ -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 +}