This commit is contained in:
李子铭 2025-03-07 11:25:53 +08:00
parent a3852ede6e
commit 50c6f1f995
7 changed files with 224 additions and 16 deletions

View File

@ -0,0 +1,15 @@
package bo
import "time"
// WechatNotifyRegisterTagBo 领域实体Bo结构字段和模型字段保持一致
type WechatNotifyRegisterTagBo struct {
ID int32
StockID string
StockCreatorMchID string
Tag string
Status uint8
Remark string
CreateTime *time.Time
UpdateTime *time.Time
}

View File

@ -13,6 +13,7 @@ type Cmb struct {
OrderWechatRepo repo.OrderWechatRepo
ProductRepo repo.ProductRepo
OrderNotifyRepo repo.OrderNotifyRepo
WechatNotifyRegisterTagRepo repo.WechatNotifyRegisterTagRepo
WechatCpnRepo wechatrepo.WechatCpnRepo
GenerateMixRepo mixrepos.GenerateMixRepo
CmbMixRepo mixrepos.CmbMixRepo
@ -24,6 +25,7 @@ func NewCmb(
OrderWechatRepo repo.OrderWechatRepo,
ProductRepo repo.ProductRepo,
OrderNotifyRepo repo.OrderNotifyRepo,
WechatNotifyRegisterTagRepo repo.WechatNotifyRegisterTagRepo,
WechatCpnRepo wechatrepo.WechatCpnRepo,
GenerateMixRepo mixrepos.GenerateMixRepo,
CmbMixRepo mixrepos.CmbMixRepo,
@ -34,6 +36,7 @@ func NewCmb(
OrderWechatRepo: OrderWechatRepo,
ProductRepo: ProductRepo,
OrderNotifyRepo: OrderNotifyRepo,
WechatNotifyRegisterTagRepo: WechatNotifyRegisterTagRepo,
WechatCpnRepo: WechatCpnRepo,
GenerateMixRepo: GenerateMixRepo,
CmbMixRepo: CmbMixRepo,

View File

@ -0,0 +1,13 @@
package repo
import (
"context"
"voucher/internal/biz/bo"
)
type WechatNotifyRegisterTagRepo interface {
GetByStockIdAndMchId(ctx context.Context, stockId, stockCreatorMchID string) (*bo.WechatNotifyRegisterTagBo, error)
Create(ctx context.Context, req *bo.WechatNotifyRegisterTagBo) (*bo.WechatNotifyRegisterTagBo, error)
Success(ctx context.Context, id int32) error
Fail(ctx context.Context, id int32, remark string) error
}

View File

@ -0,0 +1,38 @@
package vo
type WechatNotifyRegisterTagStatus uint8
const (
WechatNotifyRegisterTagStatusWait WechatNotifyRegisterTagStatus = iota + 1
WechatNotifyRegisterTagStatusSuccess
WechatNotifyRegisterTagStatusFail
)
var WechatNotifyRegisterTagStatusMap = map[WechatNotifyRegisterTagStatus]string{
WechatNotifyRegisterTagStatusWait: "待请求",
WechatNotifyRegisterTagStatusSuccess: "请求成功",
WechatNotifyRegisterTagStatusFail: "请求失败",
}
func (s WechatNotifyRegisterTagStatus) GetText() string {
if t, ok := WechatNotifyRegisterTagStatusMap[s]; ok {
return t
}
return "未知请求状态"
}
func (s WechatNotifyRegisterTagStatus) GetValue() uint8 {
return uint8(s)
}
func (s WechatNotifyRegisterTagStatus) IsWait() bool {
return s == WechatNotifyRegisterTagStatusWait
}
func (s WechatNotifyRegisterTagStatus) IsSuccess() bool {
return s == WechatNotifyRegisterTagStatusSuccess
}
func (s WechatNotifyRegisterTagStatus) IsFail() bool {
return s == WechatNotifyRegisterTagStatusFail
}

View File

@ -0,0 +1,28 @@
// 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 TableNameWechatNotifyRegisterTag = "wechat_notify_register_tag"
// WechatNotifyRegisterTag mapped from table <wechat_notify_register_tag>
type WechatNotifyRegisterTag struct {
ID int32 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
StockID string `gorm:"column:stock_id;not null" json:"stock_id"`
StockCreatorMchID string `gorm:"column:stock_creator_mch_id;not null" json:"stock_creator_mch_id"`
Tag string `gorm:"column:tag;not null" json:"tag"`
Status uint8 `gorm:"column:status;not null" json:"status"`
Remark string `gorm:"column:remark;not null" json:"remark"`
CreateTime *time.Time `gorm:"column:create_time;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time" json:"update_time"`
}
// TableName WechatNotifyRegisterTag's table name
func (*WechatNotifyRegisterTag) TableName() string {
return TableNameWechatNotifyRegisterTag
}

View File

@ -10,4 +10,5 @@ var ProviderRepoImplSet = wire.NewSet(
NewOrderWechatRepoImpl,
NewProductRepoImpl,
NewOrderNotifyRepoImpl,
NewWechatNotifyRegisterTagRepoImpl,
)

View File

@ -0,0 +1,110 @@
package repoimpl
import (
"context"
"gorm.io/gorm"
"time"
"unicode/utf8"
"voucher/internal/biz/bo"
"voucher/internal/biz/repo"
"voucher/internal/biz/vo"
"voucher/internal/data"
"voucher/internal/data/model"
)
// WechatNotifyRegisterTagRepoImpl .
type WechatNotifyRegisterTagRepoImpl struct {
Base[model.WechatNotifyRegisterTag, bo.WechatNotifyRegisterTagBo]
db *data.Db
}
// NewWechatNotifyRegisterTagRepoImpl .
func NewWechatNotifyRegisterTagRepoImpl() repo.WechatNotifyRegisterTagRepo {
return &WechatNotifyRegisterTagRepoImpl{}
}
func (p *WechatNotifyRegisterTagRepoImpl) DB(ctx context.Context) *gorm.DB {
return p.db.DB(ctx).Model(model.WechatNotifyRegisterTag{})
}
func (p *WechatNotifyRegisterTagRepoImpl) GetByStockIdAndMchId(ctx context.Context, stockId, stockCreatorMchID string) (*bo.WechatNotifyRegisterTagBo, error) {
info := &model.WechatNotifyRegisterTag{}
tx := p.DB(ctx).Where(model.WechatNotifyRegisterTag{StockID: stockId, StockCreatorMchID: stockCreatorMchID}).Find(&info)
if tx.Error != nil {
return nil, tx.Error
}
if tx.RowsAffected == 0 {
return nil, gorm.ErrRecordNotFound
}
return p.ToBo(info), nil
}
func (p *WechatNotifyRegisterTagRepoImpl) Create(ctx context.Context, req *bo.WechatNotifyRegisterTagBo) (*bo.WechatNotifyRegisterTagBo, error) {
now := time.Now()
info := &model.WechatNotifyRegisterTag{
StockID: req.StockID,
StockCreatorMchID: req.StockCreatorMchID,
Tag: req.Tag,
Status: vo.WechatNotifyRegisterTagStatusWait.GetValue(),
CreateTime: &now,
}
if err := p.db.DB(ctx).Create(info).Error; err != nil {
return nil, err
}
return p.ToBo(info), nil
}
func (p *WechatNotifyRegisterTagRepoImpl) Success(ctx context.Context, id int32) error {
now := time.Now()
res := p.db.DB(ctx).
Where(model.WechatNotifyRegisterTag{
ID: id,
Status: vo.WechatNotifyRegisterTagStatusWait.GetValue(),
}).
Updates(model.WechatNotifyRegisterTag{
Status: vo.WechatNotifyRegisterTagStatusSuccess.GetValue(),
UpdateTime: &now,
})
if res.Error != nil {
return res.Error
}
return nil
}
func (p *WechatNotifyRegisterTagRepoImpl) Fail(ctx context.Context, id int32, remark string) error {
if utf8.RuneCountInString(remark) > 100 {
runes := []rune(remark)
if len(runes) > 100 {
remark = string(runes[:100])
}
}
now := time.Now()
res := p.db.DB(ctx).
Where(model.WechatNotifyRegisterTag{
ID: id,
Status: vo.WechatNotifyRegisterTagStatusWait.GetValue(),
}).
Updates(model.WechatNotifyRegisterTag{
Status: vo.WechatNotifyRegisterTagStatusFail.GetValue(),
Remark: remark,
UpdateTime: &now,
})
if res.Error != nil {
return res.Error
}
return nil
}