voucher/internal/data/repoimpl/order_notify.go

64 lines
1.2 KiB
Go

package repoimpl
import (
"context"
"gorm.io/gorm"
"time"
"voucher/internal/biz/bo"
"voucher/internal/biz/repo"
"voucher/internal/data"
"voucher/internal/data/model"
)
// OrderNotifyRepoImpl .
type OrderNotifyRepoImpl struct {
Base[model.OrderNotify, bo.OrderNotifyBo]
db *data.Db
}
// NewOrderNotifyRepoImpl .
func NewOrderNotifyRepoImpl() repo.OrderNotifyRepo {
return &OrderNotifyRepoImpl{}
}
func (p *OrderNotifyRepoImpl) DB(ctx context.Context) *gorm.DB {
return p.db.DB(ctx).Model(model.OrderNotify{})
}
func (p *OrderNotifyRepoImpl) Create(ctx context.Context, req *bo.OrderNotifyBo) (*bo.OrderNotifyBo, error) {
now := time.Now()
info := &model.OrderNotify{
OrderNo: req.OrderNo,
OutRequestNo: req.OutRequestNo,
Request: req.Request,
CreateTime: &now,
UpdateTime: &now,
}
if err := p.db.DB(ctx).Create(info).Error; err != nil {
return nil, err
}
return p.ToBo(info), nil
}
func (p *OrderNotifyRepoImpl) UpdateResponses(ctx context.Context, id uint64, responses string) error {
now := time.Now()
res := p.db.DB(ctx).
Where(model.OrderNotify{
ID: id,
}).
Updates(model.OrderNotify{
Responses: responses,
UpdateTime: &now,
})
if res.Error != nil {
return res.Error
}
return nil
}