cmb
This commit is contained in:
parent
a3852ede6e
commit
50c6f1f995
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -8,14 +8,15 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Cmb struct {
|
type Cmb struct {
|
||||||
bc *conf.Bootstrap
|
bc *conf.Bootstrap
|
||||||
OrderRepo repo.OrderRepo
|
OrderRepo repo.OrderRepo
|
||||||
OrderWechatRepo repo.OrderWechatRepo
|
OrderWechatRepo repo.OrderWechatRepo
|
||||||
ProductRepo repo.ProductRepo
|
ProductRepo repo.ProductRepo
|
||||||
OrderNotifyRepo repo.OrderNotifyRepo
|
OrderNotifyRepo repo.OrderNotifyRepo
|
||||||
WechatCpnRepo wechatrepo.WechatCpnRepo
|
WechatNotifyRegisterTagRepo repo.WechatNotifyRegisterTagRepo
|
||||||
GenerateMixRepo mixrepos.GenerateMixRepo
|
WechatCpnRepo wechatrepo.WechatCpnRepo
|
||||||
CmbMixRepo mixrepos.CmbMixRepo
|
GenerateMixRepo mixrepos.GenerateMixRepo
|
||||||
|
CmbMixRepo mixrepos.CmbMixRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCmb(
|
func NewCmb(
|
||||||
|
|
@ -24,18 +25,20 @@ func NewCmb(
|
||||||
OrderWechatRepo repo.OrderWechatRepo,
|
OrderWechatRepo repo.OrderWechatRepo,
|
||||||
ProductRepo repo.ProductRepo,
|
ProductRepo repo.ProductRepo,
|
||||||
OrderNotifyRepo repo.OrderNotifyRepo,
|
OrderNotifyRepo repo.OrderNotifyRepo,
|
||||||
|
WechatNotifyRegisterTagRepo repo.WechatNotifyRegisterTagRepo,
|
||||||
WechatCpnRepo wechatrepo.WechatCpnRepo,
|
WechatCpnRepo wechatrepo.WechatCpnRepo,
|
||||||
GenerateMixRepo mixrepos.GenerateMixRepo,
|
GenerateMixRepo mixrepos.GenerateMixRepo,
|
||||||
CmbMixRepo mixrepos.CmbMixRepo,
|
CmbMixRepo mixrepos.CmbMixRepo,
|
||||||
) *Cmb {
|
) *Cmb {
|
||||||
return &Cmb{
|
return &Cmb{
|
||||||
bc: bc,
|
bc: bc,
|
||||||
OrderRepo: orderRepo,
|
OrderRepo: orderRepo,
|
||||||
OrderWechatRepo: OrderWechatRepo,
|
OrderWechatRepo: OrderWechatRepo,
|
||||||
ProductRepo: ProductRepo,
|
ProductRepo: ProductRepo,
|
||||||
OrderNotifyRepo: OrderNotifyRepo,
|
OrderNotifyRepo: OrderNotifyRepo,
|
||||||
WechatCpnRepo: WechatCpnRepo,
|
WechatNotifyRegisterTagRepo: WechatNotifyRegisterTagRepo,
|
||||||
GenerateMixRepo: GenerateMixRepo,
|
WechatCpnRepo: WechatCpnRepo,
|
||||||
CmbMixRepo: CmbMixRepo,
|
GenerateMixRepo: GenerateMixRepo,
|
||||||
|
CmbMixRepo: CmbMixRepo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -10,4 +10,5 @@ var ProviderRepoImplSet = wire.NewSet(
|
||||||
NewOrderWechatRepoImpl,
|
NewOrderWechatRepoImpl,
|
||||||
NewProductRepoImpl,
|
NewProductRepoImpl,
|
||||||
NewOrderNotifyRepoImpl,
|
NewOrderNotifyRepoImpl,
|
||||||
|
NewWechatNotifyRegisterTagRepoImpl,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue