This commit is contained in:
parent
01ac62f2bc
commit
f4872bfe74
|
|
@ -7,10 +7,10 @@ import (
|
||||||
|
|
||||||
// UseLogBo 领域实体Bo结构,字段和模型字段保持一致
|
// UseLogBo 领域实体Bo结构,字段和模型字段保持一致
|
||||||
type UseLogBo struct {
|
type UseLogBo struct {
|
||||||
ID uint64
|
ID uint64
|
||||||
OrderNo string
|
OrderNo string
|
||||||
Amount int64
|
Amount int64
|
||||||
Type vo.UseLogType
|
Type vo.UseLogType
|
||||||
UseTime *time.Time
|
OperateTime *time.Time
|
||||||
CreateTime *time.Time
|
CreateTime *time.Time
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,23 +35,24 @@ func (v *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req *
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.PlainText.ConsumeInformation.ConsumeTime != "" {
|
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 {
|
if err2 != nil {
|
||||||
return err2
|
return err2
|
||||||
}
|
}
|
||||||
|
|
||||||
useLog, err2 := v.UseLogRepo.GetByUseTimeOrder(ctx, order.OrderNo, &useTime)
|
useLog, err2 := v.UseLogRepo.GetByUseTimeOrder(ctx, order.OrderNo, &useTime)
|
||||||
|
|
||||||
if err2 != nil && !errors.Is(err2, gorm.ErrRecordNotFound) {
|
if err2 != nil && !errors.Is(err2, gorm.ErrRecordNotFound) {
|
||||||
return err2
|
return err2
|
||||||
}
|
}
|
||||||
|
|
||||||
if useLog == nil {
|
if useLog == nil {
|
||||||
_, err = v.UseLogRepo.Create(ctx, &bo.UseLogBo{
|
_, err = v.UseLogRepo.Create(ctx, &bo.UseLogBo{
|
||||||
OrderNo: order.OrderNo,
|
OrderNo: order.OrderNo,
|
||||||
Amount: req.PlainText.ConsumeInformation.ConsumeAmount,
|
Amount: req.PlainText.ConsumeInformation.ConsumeAmount,
|
||||||
Type: vo.UseLogTypeUsed,
|
Type: vo.UseLogTypeUsed,
|
||||||
UseTime: &useTime,
|
OperateTime: &useTime,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,12 @@ const TableNameUseLog = "use_log"
|
||||||
|
|
||||||
// UseLog mapped from table <user_log>
|
// UseLog mapped from table <user_log>
|
||||||
type UseLog struct {
|
type UseLog struct {
|
||||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||||
OrderNo string `gorm:"column:order_no;not null" json:"order_no"`
|
OrderNo string `gorm:"column:order_no;not null" json:"order_no"`
|
||||||
Amount int64 `gorm:"column:amount;not null;comment:核销金额" json:"amount"`
|
Amount int64 `gorm:"column:amount;not null;comment:核销金额" json:"amount"`
|
||||||
Type uint8 `gorm:"column:type;not null;comment:1:核销 2:退款" json:"type"`
|
Type uint8 `gorm:"column:type;not null;comment:1:核销 2:退款" json:"type"`
|
||||||
UseTime *time.Time `gorm:"column:use_time;not null" json:"use_time"`
|
OperateTime *time.Time `gorm:"column:operate_time;not null" json:"operate_time"`
|
||||||
CreateTime *time.Time `gorm:"column:create_time;not null" json:"create_time"`
|
CreateTime *time.Time `gorm:"column:create_time;not null" json:"create_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName UseLog's table name
|
// TableName UseLog's table name
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,11 @@ func (this *UseLogRepoImpl) Create(ctx context.Context, req *bo.UseLogBo) (*bo.U
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
info := &model.UseLog{
|
info := &model.UseLog{
|
||||||
OrderNo: req.OrderNo,
|
OrderNo: req.OrderNo,
|
||||||
Type: req.Type.GetValue(),
|
Type: req.Type.GetValue(),
|
||||||
Amount: req.Amount,
|
Amount: req.Amount,
|
||||||
UseTime: req.UseTime,
|
OperateTime: req.OperateTime,
|
||||||
CreateTime: &now,
|
CreateTime: &now,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := this.DB(ctx).Create(info).Error; err != nil {
|
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) {
|
func (this *UseLogRepoImpl) GetByUseTimeOrder(ctx context.Context, orderNo string, useTime *time.Time) (*bo.UseLogBo, error) {
|
||||||
var item model.UseLog
|
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 {
|
if tx.Error != nil {
|
||||||
return nil, tx.Error
|
return nil, tx.Error
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue