From f4872bfe74462d84ef43cc558f4441af160864ee Mon Sep 17 00:00:00 2001 From: ziming Date: Wed, 21 May 2025 10:51:57 +0800 Subject: [PATCH] kg --- internal/biz/bo/use_log_bo.go | 12 ++++++------ internal/biz/wechat_notify.go | 13 +++++++------ internal/data/model/use_log.gen.go | 12 ++++++------ internal/data/repoimpl/use_log.go | 12 ++++++------ 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/internal/biz/bo/use_log_bo.go b/internal/biz/bo/use_log_bo.go index 8abf097..be12f5a 100644 --- a/internal/biz/bo/use_log_bo.go +++ b/internal/biz/bo/use_log_bo.go @@ -7,10 +7,10 @@ import ( // UseLogBo 领域实体Bo结构,字段和模型字段保持一致 type UseLogBo struct { - ID uint64 - OrderNo string - Amount int64 - Type vo.UseLogType - UseTime *time.Time - CreateTime *time.Time + ID uint64 + OrderNo string + Amount int64 + Type vo.UseLogType + OperateTime *time.Time + CreateTime *time.Time } diff --git a/internal/biz/wechat_notify.go b/internal/biz/wechat_notify.go index 739d72b..f259af2 100644 --- a/internal/biz/wechat_notify.go +++ b/internal/biz/wechat_notify.go @@ -35,23 +35,24 @@ func (v *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req * } if req.PlainText.ConsumeInformation.ConsumeTime != "" { - inputFormat := time.RFC3339 - useTime, err2 := time.Parse(inputFormat, req.PlainText.ConsumeInformation.ConsumeTime) + + useTime, err2 := time.Parse(time.RFC3339, req.PlainText.ConsumeInformation.ConsumeTime) if err2 != nil { return err2 } useLog, err2 := v.UseLogRepo.GetByUseTimeOrder(ctx, order.OrderNo, &useTime) + if err2 != nil && !errors.Is(err2, gorm.ErrRecordNotFound) { return err2 } if useLog == nil { _, err = v.UseLogRepo.Create(ctx, &bo.UseLogBo{ - OrderNo: order.OrderNo, - Amount: req.PlainText.ConsumeInformation.ConsumeAmount, - Type: vo.UseLogTypeUsed, - UseTime: &useTime, + OrderNo: order.OrderNo, + Amount: req.PlainText.ConsumeInformation.ConsumeAmount, + Type: vo.UseLogTypeUsed, + OperateTime: &useTime, }) if err != nil { return err diff --git a/internal/data/model/use_log.gen.go b/internal/data/model/use_log.gen.go index cf73907..9c88624 100644 --- a/internal/data/model/use_log.gen.go +++ b/internal/data/model/use_log.gen.go @@ -12,12 +12,12 @@ const TableNameUseLog = "use_log" // UseLog mapped from table type UseLog struct { - ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` - OrderNo string `gorm:"column:order_no;not null" json:"order_no"` - Amount int64 `gorm:"column:amount;not null;comment:核销金额" json:"amount"` - Type uint8 `gorm:"column:type;not null;comment:1:核销 2:退款" json:"type"` - UseTime *time.Time `gorm:"column:use_time;not null" json:"use_time"` - CreateTime *time.Time `gorm:"column:create_time;not null" json:"create_time"` + ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` + OrderNo string `gorm:"column:order_no;not null" json:"order_no"` + Amount int64 `gorm:"column:amount;not null;comment:核销金额" json:"amount"` + Type uint8 `gorm:"column:type;not null;comment:1:核销 2:退款" json:"type"` + OperateTime *time.Time `gorm:"column:operate_time;not null" json:"operate_time"` + CreateTime *time.Time `gorm:"column:create_time;not null" json:"create_time"` } // TableName UseLog's table name diff --git a/internal/data/repoimpl/use_log.go b/internal/data/repoimpl/use_log.go index 2cb153e..168da18 100644 --- a/internal/data/repoimpl/use_log.go +++ b/internal/data/repoimpl/use_log.go @@ -29,11 +29,11 @@ func (this *UseLogRepoImpl) Create(ctx context.Context, req *bo.UseLogBo) (*bo.U now := time.Now() info := &model.UseLog{ - OrderNo: req.OrderNo, - Type: req.Type.GetValue(), - Amount: req.Amount, - UseTime: req.UseTime, - CreateTime: &now, + OrderNo: req.OrderNo, + Type: req.Type.GetValue(), + Amount: req.Amount, + OperateTime: req.OperateTime, + CreateTime: &now, } if err := this.DB(ctx).Create(info).Error; err != nil { @@ -62,7 +62,7 @@ func (this *UseLogRepoImpl) GetByID(ctx context.Context, id uint64) (*bo.UseLogB func (this *UseLogRepoImpl) GetByUseTimeOrder(ctx context.Context, orderNo string, useTime *time.Time) (*bo.UseLogBo, error) { var item model.UseLog - tx := this.DB(ctx).Where(model.UseLog{OrderNo: orderNo, UseTime: useTime}).First(&item) + tx := this.DB(ctx).Where(model.UseLog{OrderNo: orderNo, OperateTime: useTime}).First(&item) if tx.Error != nil { return nil, tx.Error