This commit is contained in:
@@ -94,6 +94,25 @@ func (s *RechargeOrderStore) Update(ctx context.Context, order *model.RechargeOr
|
||||
return s.db.WithContext(ctx).Save(order).Error
|
||||
}
|
||||
|
||||
// UpdateStatusWithRejection 条件更新订单状态为已驳回并写入驳回原因
|
||||
// 仅当 status = 0(待支付)时更新,RowsAffected=0 说明订单不存在或状态已变更
|
||||
func (s *RechargeOrderStore) UpdateStatusWithRejection(ctx context.Context, id uint, rejectionReason string) error {
|
||||
result := s.db.WithContext(ctx).
|
||||
Model(&model.RechargeOrder{}).
|
||||
Where("id = ? AND status = ?", id, model.RechargeOrderStatusPending).
|
||||
Updates(map[string]interface{}{
|
||||
"status": model.RechargeOrderStatusRejected,
|
||||
"rejection_reason": rejectionReason,
|
||||
})
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
if result.RowsAffected == 0 {
|
||||
return gorm.ErrRecordNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *RechargeOrderStore) ListByCard(ctx context.Context, iotCardID uint, generation int, offset, limit int) ([]*model.RechargeOrder, error) {
|
||||
var orders []*model.RechargeOrder
|
||||
query := s.db.WithContext(ctx).
|
||||
|
||||
Reference in New Issue
Block a user