// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/Wei-Shaw/sub2api/ent/paymentorder"
	"github.com/Wei-Shaw/sub2api/ent/predicate"
	"github.com/Wei-Shaw/sub2api/ent/user"
)

// PaymentOrderUpdate is the builder for updating PaymentOrder entities.
type PaymentOrderUpdate struct {
	config
	hooks    []Hook
	mutation *PaymentOrderMutation
}

// Where appends a list predicates to the PaymentOrderUpdate builder.
func (_u *PaymentOrderUpdate) Where(ps ...predicate.PaymentOrder) *PaymentOrderUpdate {
	_u.mutation.Where(ps...)
	return _u
}

// SetUserID sets the "user_id" field.
func (_u *PaymentOrderUpdate) SetUserID(v int64) *PaymentOrderUpdate {
	_u.mutation.SetUserID(v)
	return _u
}

// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableUserID(v *int64) *PaymentOrderUpdate {
	if v != nil {
		_u.SetUserID(*v)
	}
	return _u
}

// SetUserEmail sets the "user_email" field.
func (_u *PaymentOrderUpdate) SetUserEmail(v string) *PaymentOrderUpdate {
	_u.mutation.SetUserEmail(v)
	return _u
}

// SetNillableUserEmail sets the "user_email" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableUserEmail(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetUserEmail(*v)
	}
	return _u
}

// SetUserName sets the "user_name" field.
func (_u *PaymentOrderUpdate) SetUserName(v string) *PaymentOrderUpdate {
	_u.mutation.SetUserName(v)
	return _u
}

// SetNillableUserName sets the "user_name" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableUserName(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetUserName(*v)
	}
	return _u
}

// SetUserNotes sets the "user_notes" field.
func (_u *PaymentOrderUpdate) SetUserNotes(v string) *PaymentOrderUpdate {
	_u.mutation.SetUserNotes(v)
	return _u
}

// SetNillableUserNotes sets the "user_notes" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableUserNotes(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetUserNotes(*v)
	}
	return _u
}

// ClearUserNotes clears the value of the "user_notes" field.
func (_u *PaymentOrderUpdate) ClearUserNotes() *PaymentOrderUpdate {
	_u.mutation.ClearUserNotes()
	return _u
}

// SetAmount sets the "amount" field.
func (_u *PaymentOrderUpdate) SetAmount(v float64) *PaymentOrderUpdate {
	_u.mutation.ResetAmount()
	_u.mutation.SetAmount(v)
	return _u
}

// SetNillableAmount sets the "amount" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableAmount(v *float64) *PaymentOrderUpdate {
	if v != nil {
		_u.SetAmount(*v)
	}
	return _u
}

// AddAmount adds value to the "amount" field.
func (_u *PaymentOrderUpdate) AddAmount(v float64) *PaymentOrderUpdate {
	_u.mutation.AddAmount(v)
	return _u
}

// SetPayAmount sets the "pay_amount" field.
func (_u *PaymentOrderUpdate) SetPayAmount(v float64) *PaymentOrderUpdate {
	_u.mutation.ResetPayAmount()
	_u.mutation.SetPayAmount(v)
	return _u
}

// SetNillablePayAmount sets the "pay_amount" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillablePayAmount(v *float64) *PaymentOrderUpdate {
	if v != nil {
		_u.SetPayAmount(*v)
	}
	return _u
}

// AddPayAmount adds value to the "pay_amount" field.
func (_u *PaymentOrderUpdate) AddPayAmount(v float64) *PaymentOrderUpdate {
	_u.mutation.AddPayAmount(v)
	return _u
}

// SetFeeRate sets the "fee_rate" field.
func (_u *PaymentOrderUpdate) SetFeeRate(v float64) *PaymentOrderUpdate {
	_u.mutation.ResetFeeRate()
	_u.mutation.SetFeeRate(v)
	return _u
}

// SetNillableFeeRate sets the "fee_rate" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableFeeRate(v *float64) *PaymentOrderUpdate {
	if v != nil {
		_u.SetFeeRate(*v)
	}
	return _u
}

// AddFeeRate adds value to the "fee_rate" field.
func (_u *PaymentOrderUpdate) AddFeeRate(v float64) *PaymentOrderUpdate {
	_u.mutation.AddFeeRate(v)
	return _u
}

// SetRechargeCode sets the "recharge_code" field.
func (_u *PaymentOrderUpdate) SetRechargeCode(v string) *PaymentOrderUpdate {
	_u.mutation.SetRechargeCode(v)
	return _u
}

// SetNillableRechargeCode sets the "recharge_code" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableRechargeCode(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetRechargeCode(*v)
	}
	return _u
}

// SetOutTradeNo sets the "out_trade_no" field.
func (_u *PaymentOrderUpdate) SetOutTradeNo(v string) *PaymentOrderUpdate {
	_u.mutation.SetOutTradeNo(v)
	return _u
}

// SetNillableOutTradeNo sets the "out_trade_no" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableOutTradeNo(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetOutTradeNo(*v)
	}
	return _u
}

// SetPaymentType sets the "payment_type" field.
func (_u *PaymentOrderUpdate) SetPaymentType(v string) *PaymentOrderUpdate {
	_u.mutation.SetPaymentType(v)
	return _u
}

// SetNillablePaymentType sets the "payment_type" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillablePaymentType(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetPaymentType(*v)
	}
	return _u
}

// SetPaymentTradeNo sets the "payment_trade_no" field.
func (_u *PaymentOrderUpdate) SetPaymentTradeNo(v string) *PaymentOrderUpdate {
	_u.mutation.SetPaymentTradeNo(v)
	return _u
}

// SetNillablePaymentTradeNo sets the "payment_trade_no" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillablePaymentTradeNo(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetPaymentTradeNo(*v)
	}
	return _u
}

// SetPayURL sets the "pay_url" field.
func (_u *PaymentOrderUpdate) SetPayURL(v string) *PaymentOrderUpdate {
	_u.mutation.SetPayURL(v)
	return _u
}

// SetNillablePayURL sets the "pay_url" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillablePayURL(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetPayURL(*v)
	}
	return _u
}

// ClearPayURL clears the value of the "pay_url" field.
func (_u *PaymentOrderUpdate) ClearPayURL() *PaymentOrderUpdate {
	_u.mutation.ClearPayURL()
	return _u
}

// SetQrCode sets the "qr_code" field.
func (_u *PaymentOrderUpdate) SetQrCode(v string) *PaymentOrderUpdate {
	_u.mutation.SetQrCode(v)
	return _u
}

// SetNillableQrCode sets the "qr_code" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableQrCode(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetQrCode(*v)
	}
	return _u
}

// ClearQrCode clears the value of the "qr_code" field.
func (_u *PaymentOrderUpdate) ClearQrCode() *PaymentOrderUpdate {
	_u.mutation.ClearQrCode()
	return _u
}

// SetQrCodeImg sets the "qr_code_img" field.
func (_u *PaymentOrderUpdate) SetQrCodeImg(v string) *PaymentOrderUpdate {
	_u.mutation.SetQrCodeImg(v)
	return _u
}

// SetNillableQrCodeImg sets the "qr_code_img" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableQrCodeImg(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetQrCodeImg(*v)
	}
	return _u
}

// ClearQrCodeImg clears the value of the "qr_code_img" field.
func (_u *PaymentOrderUpdate) ClearQrCodeImg() *PaymentOrderUpdate {
	_u.mutation.ClearQrCodeImg()
	return _u
}

// SetOrderType sets the "order_type" field.
func (_u *PaymentOrderUpdate) SetOrderType(v string) *PaymentOrderUpdate {
	_u.mutation.SetOrderType(v)
	return _u
}

// SetNillableOrderType sets the "order_type" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableOrderType(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetOrderType(*v)
	}
	return _u
}

// SetPlanID sets the "plan_id" field.
func (_u *PaymentOrderUpdate) SetPlanID(v int64) *PaymentOrderUpdate {
	_u.mutation.ResetPlanID()
	_u.mutation.SetPlanID(v)
	return _u
}

// SetNillablePlanID sets the "plan_id" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillablePlanID(v *int64) *PaymentOrderUpdate {
	if v != nil {
		_u.SetPlanID(*v)
	}
	return _u
}

// AddPlanID adds value to the "plan_id" field.
func (_u *PaymentOrderUpdate) AddPlanID(v int64) *PaymentOrderUpdate {
	_u.mutation.AddPlanID(v)
	return _u
}

// ClearPlanID clears the value of the "plan_id" field.
func (_u *PaymentOrderUpdate) ClearPlanID() *PaymentOrderUpdate {
	_u.mutation.ClearPlanID()
	return _u
}

// SetSubscriptionGroupID sets the "subscription_group_id" field.
func (_u *PaymentOrderUpdate) SetSubscriptionGroupID(v int64) *PaymentOrderUpdate {
	_u.mutation.ResetSubscriptionGroupID()
	_u.mutation.SetSubscriptionGroupID(v)
	return _u
}

// SetNillableSubscriptionGroupID sets the "subscription_group_id" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableSubscriptionGroupID(v *int64) *PaymentOrderUpdate {
	if v != nil {
		_u.SetSubscriptionGroupID(*v)
	}
	return _u
}

// AddSubscriptionGroupID adds value to the "subscription_group_id" field.
func (_u *PaymentOrderUpdate) AddSubscriptionGroupID(v int64) *PaymentOrderUpdate {
	_u.mutation.AddSubscriptionGroupID(v)
	return _u
}

// ClearSubscriptionGroupID clears the value of the "subscription_group_id" field.
func (_u *PaymentOrderUpdate) ClearSubscriptionGroupID() *PaymentOrderUpdate {
	_u.mutation.ClearSubscriptionGroupID()
	return _u
}

// SetSubscriptionDays sets the "subscription_days" field.
func (_u *PaymentOrderUpdate) SetSubscriptionDays(v int) *PaymentOrderUpdate {
	_u.mutation.ResetSubscriptionDays()
	_u.mutation.SetSubscriptionDays(v)
	return _u
}

// SetNillableSubscriptionDays sets the "subscription_days" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableSubscriptionDays(v *int) *PaymentOrderUpdate {
	if v != nil {
		_u.SetSubscriptionDays(*v)
	}
	return _u
}

// AddSubscriptionDays adds value to the "subscription_days" field.
func (_u *PaymentOrderUpdate) AddSubscriptionDays(v int) *PaymentOrderUpdate {
	_u.mutation.AddSubscriptionDays(v)
	return _u
}

// ClearSubscriptionDays clears the value of the "subscription_days" field.
func (_u *PaymentOrderUpdate) ClearSubscriptionDays() *PaymentOrderUpdate {
	_u.mutation.ClearSubscriptionDays()
	return _u
}

// SetProviderInstanceID sets the "provider_instance_id" field.
func (_u *PaymentOrderUpdate) SetProviderInstanceID(v string) *PaymentOrderUpdate {
	_u.mutation.SetProviderInstanceID(v)
	return _u
}

// SetNillableProviderInstanceID sets the "provider_instance_id" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableProviderInstanceID(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetProviderInstanceID(*v)
	}
	return _u
}

// ClearProviderInstanceID clears the value of the "provider_instance_id" field.
func (_u *PaymentOrderUpdate) ClearProviderInstanceID() *PaymentOrderUpdate {
	_u.mutation.ClearProviderInstanceID()
	return _u
}

// SetStatus sets the "status" field.
func (_u *PaymentOrderUpdate) SetStatus(v string) *PaymentOrderUpdate {
	_u.mutation.SetStatus(v)
	return _u
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableStatus(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetStatus(*v)
	}
	return _u
}

// SetRefundAmount sets the "refund_amount" field.
func (_u *PaymentOrderUpdate) SetRefundAmount(v float64) *PaymentOrderUpdate {
	_u.mutation.ResetRefundAmount()
	_u.mutation.SetRefundAmount(v)
	return _u
}

// SetNillableRefundAmount sets the "refund_amount" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableRefundAmount(v *float64) *PaymentOrderUpdate {
	if v != nil {
		_u.SetRefundAmount(*v)
	}
	return _u
}

// AddRefundAmount adds value to the "refund_amount" field.
func (_u *PaymentOrderUpdate) AddRefundAmount(v float64) *PaymentOrderUpdate {
	_u.mutation.AddRefundAmount(v)
	return _u
}

// SetRefundReason sets the "refund_reason" field.
func (_u *PaymentOrderUpdate) SetRefundReason(v string) *PaymentOrderUpdate {
	_u.mutation.SetRefundReason(v)
	return _u
}

// SetNillableRefundReason sets the "refund_reason" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableRefundReason(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetRefundReason(*v)
	}
	return _u
}

// ClearRefundReason clears the value of the "refund_reason" field.
func (_u *PaymentOrderUpdate) ClearRefundReason() *PaymentOrderUpdate {
	_u.mutation.ClearRefundReason()
	return _u
}

// SetRefundAt sets the "refund_at" field.
func (_u *PaymentOrderUpdate) SetRefundAt(v time.Time) *PaymentOrderUpdate {
	_u.mutation.SetRefundAt(v)
	return _u
}

// SetNillableRefundAt sets the "refund_at" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableRefundAt(v *time.Time) *PaymentOrderUpdate {
	if v != nil {
		_u.SetRefundAt(*v)
	}
	return _u
}

// ClearRefundAt clears the value of the "refund_at" field.
func (_u *PaymentOrderUpdate) ClearRefundAt() *PaymentOrderUpdate {
	_u.mutation.ClearRefundAt()
	return _u
}

// SetForceRefund sets the "force_refund" field.
func (_u *PaymentOrderUpdate) SetForceRefund(v bool) *PaymentOrderUpdate {
	_u.mutation.SetForceRefund(v)
	return _u
}

// SetNillableForceRefund sets the "force_refund" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableForceRefund(v *bool) *PaymentOrderUpdate {
	if v != nil {
		_u.SetForceRefund(*v)
	}
	return _u
}

// SetRefundRequestedAt sets the "refund_requested_at" field.
func (_u *PaymentOrderUpdate) SetRefundRequestedAt(v time.Time) *PaymentOrderUpdate {
	_u.mutation.SetRefundRequestedAt(v)
	return _u
}

// SetNillableRefundRequestedAt sets the "refund_requested_at" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableRefundRequestedAt(v *time.Time) *PaymentOrderUpdate {
	if v != nil {
		_u.SetRefundRequestedAt(*v)
	}
	return _u
}

// ClearRefundRequestedAt clears the value of the "refund_requested_at" field.
func (_u *PaymentOrderUpdate) ClearRefundRequestedAt() *PaymentOrderUpdate {
	_u.mutation.ClearRefundRequestedAt()
	return _u
}

// SetRefundRequestReason sets the "refund_request_reason" field.
func (_u *PaymentOrderUpdate) SetRefundRequestReason(v string) *PaymentOrderUpdate {
	_u.mutation.SetRefundRequestReason(v)
	return _u
}

// SetNillableRefundRequestReason sets the "refund_request_reason" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableRefundRequestReason(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetRefundRequestReason(*v)
	}
	return _u
}

// ClearRefundRequestReason clears the value of the "refund_request_reason" field.
func (_u *PaymentOrderUpdate) ClearRefundRequestReason() *PaymentOrderUpdate {
	_u.mutation.ClearRefundRequestReason()
	return _u
}

// SetRefundRequestedBy sets the "refund_requested_by" field.
func (_u *PaymentOrderUpdate) SetRefundRequestedBy(v string) *PaymentOrderUpdate {
	_u.mutation.SetRefundRequestedBy(v)
	return _u
}

// SetNillableRefundRequestedBy sets the "refund_requested_by" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableRefundRequestedBy(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetRefundRequestedBy(*v)
	}
	return _u
}

// ClearRefundRequestedBy clears the value of the "refund_requested_by" field.
func (_u *PaymentOrderUpdate) ClearRefundRequestedBy() *PaymentOrderUpdate {
	_u.mutation.ClearRefundRequestedBy()
	return _u
}

// SetExpiresAt sets the "expires_at" field.
func (_u *PaymentOrderUpdate) SetExpiresAt(v time.Time) *PaymentOrderUpdate {
	_u.mutation.SetExpiresAt(v)
	return _u
}

// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableExpiresAt(v *time.Time) *PaymentOrderUpdate {
	if v != nil {
		_u.SetExpiresAt(*v)
	}
	return _u
}

// SetPaidAt sets the "paid_at" field.
func (_u *PaymentOrderUpdate) SetPaidAt(v time.Time) *PaymentOrderUpdate {
	_u.mutation.SetPaidAt(v)
	return _u
}

// SetNillablePaidAt sets the "paid_at" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillablePaidAt(v *time.Time) *PaymentOrderUpdate {
	if v != nil {
		_u.SetPaidAt(*v)
	}
	return _u
}

// ClearPaidAt clears the value of the "paid_at" field.
func (_u *PaymentOrderUpdate) ClearPaidAt() *PaymentOrderUpdate {
	_u.mutation.ClearPaidAt()
	return _u
}

// SetCompletedAt sets the "completed_at" field.
func (_u *PaymentOrderUpdate) SetCompletedAt(v time.Time) *PaymentOrderUpdate {
	_u.mutation.SetCompletedAt(v)
	return _u
}

// SetNillableCompletedAt sets the "completed_at" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableCompletedAt(v *time.Time) *PaymentOrderUpdate {
	if v != nil {
		_u.SetCompletedAt(*v)
	}
	return _u
}

// ClearCompletedAt clears the value of the "completed_at" field.
func (_u *PaymentOrderUpdate) ClearCompletedAt() *PaymentOrderUpdate {
	_u.mutation.ClearCompletedAt()
	return _u
}

// SetFailedAt sets the "failed_at" field.
func (_u *PaymentOrderUpdate) SetFailedAt(v time.Time) *PaymentOrderUpdate {
	_u.mutation.SetFailedAt(v)
	return _u
}

// SetNillableFailedAt sets the "failed_at" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableFailedAt(v *time.Time) *PaymentOrderUpdate {
	if v != nil {
		_u.SetFailedAt(*v)
	}
	return _u
}

// ClearFailedAt clears the value of the "failed_at" field.
func (_u *PaymentOrderUpdate) ClearFailedAt() *PaymentOrderUpdate {
	_u.mutation.ClearFailedAt()
	return _u
}

// SetFailedReason sets the "failed_reason" field.
func (_u *PaymentOrderUpdate) SetFailedReason(v string) *PaymentOrderUpdate {
	_u.mutation.SetFailedReason(v)
	return _u
}

// SetNillableFailedReason sets the "failed_reason" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableFailedReason(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetFailedReason(*v)
	}
	return _u
}

// ClearFailedReason clears the value of the "failed_reason" field.
func (_u *PaymentOrderUpdate) ClearFailedReason() *PaymentOrderUpdate {
	_u.mutation.ClearFailedReason()
	return _u
}

// SetClientIP sets the "client_ip" field.
func (_u *PaymentOrderUpdate) SetClientIP(v string) *PaymentOrderUpdate {
	_u.mutation.SetClientIP(v)
	return _u
}

// SetNillableClientIP sets the "client_ip" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableClientIP(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetClientIP(*v)
	}
	return _u
}

// SetSrcHost sets the "src_host" field.
func (_u *PaymentOrderUpdate) SetSrcHost(v string) *PaymentOrderUpdate {
	_u.mutation.SetSrcHost(v)
	return _u
}

// SetNillableSrcHost sets the "src_host" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableSrcHost(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetSrcHost(*v)
	}
	return _u
}

// SetSrcURL sets the "src_url" field.
func (_u *PaymentOrderUpdate) SetSrcURL(v string) *PaymentOrderUpdate {
	_u.mutation.SetSrcURL(v)
	return _u
}

// SetNillableSrcURL sets the "src_url" field if the given value is not nil.
func (_u *PaymentOrderUpdate) SetNillableSrcURL(v *string) *PaymentOrderUpdate {
	if v != nil {
		_u.SetSrcURL(*v)
	}
	return _u
}

// ClearSrcURL clears the value of the "src_url" field.
func (_u *PaymentOrderUpdate) ClearSrcURL() *PaymentOrderUpdate {
	_u.mutation.ClearSrcURL()
	return _u
}

// SetUpdatedAt sets the "updated_at" field.
func (_u *PaymentOrderUpdate) SetUpdatedAt(v time.Time) *PaymentOrderUpdate {
	_u.mutation.SetUpdatedAt(v)
	return _u
}

// SetUser sets the "user" edge to the User entity.
func (_u *PaymentOrderUpdate) SetUser(v *User) *PaymentOrderUpdate {
	return _u.SetUserID(v.ID)
}

// Mutation returns the PaymentOrderMutation object of the builder.
func (_u *PaymentOrderUpdate) Mutation() *PaymentOrderMutation {
	return _u.mutation
}

// ClearUser clears the "user" edge to the User entity.
func (_u *PaymentOrderUpdate) ClearUser() *PaymentOrderUpdate {
	_u.mutation.ClearUser()
	return _u
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *PaymentOrderUpdate) Save(ctx context.Context) (int, error) {
	_u.defaults()
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (_u *PaymentOrderUpdate) SaveX(ctx context.Context) int {
	affected, err := _u.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

// Exec executes the query.
func (_u *PaymentOrderUpdate) Exec(ctx context.Context) error {
	_, err := _u.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (_u *PaymentOrderUpdate) ExecX(ctx context.Context) {
	if err := _u.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (_u *PaymentOrderUpdate) defaults() {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		v := paymentorder.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_u *PaymentOrderUpdate) check() error {
	if v, ok := _u.mutation.UserEmail(); ok {
		if err := paymentorder.UserEmailValidator(v); err != nil {
			return &ValidationError{Name: "user_email", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.user_email": %w`, err)}
		}
	}
	if v, ok := _u.mutation.UserName(); ok {
		if err := paymentorder.UserNameValidator(v); err != nil {
			return &ValidationError{Name: "user_name", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.user_name": %w`, err)}
		}
	}
	if v, ok := _u.mutation.RechargeCode(); ok {
		if err := paymentorder.RechargeCodeValidator(v); err != nil {
			return &ValidationError{Name: "recharge_code", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.recharge_code": %w`, err)}
		}
	}
	if v, ok := _u.mutation.OutTradeNo(); ok {
		if err := paymentorder.OutTradeNoValidator(v); err != nil {
			return &ValidationError{Name: "out_trade_no", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.out_trade_no": %w`, err)}
		}
	}
	if v, ok := _u.mutation.PaymentType(); ok {
		if err := paymentorder.PaymentTypeValidator(v); err != nil {
			return &ValidationError{Name: "payment_type", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.payment_type": %w`, err)}
		}
	}
	if v, ok := _u.mutation.PaymentTradeNo(); ok {
		if err := paymentorder.PaymentTradeNoValidator(v); err != nil {
			return &ValidationError{Name: "payment_trade_no", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.payment_trade_no": %w`, err)}
		}
	}
	if v, ok := _u.mutation.OrderType(); ok {
		if err := paymentorder.OrderTypeValidator(v); err != nil {
			return &ValidationError{Name: "order_type", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.order_type": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ProviderInstanceID(); ok {
		if err := paymentorder.ProviderInstanceIDValidator(v); err != nil {
			return &ValidationError{Name: "provider_instance_id", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.provider_instance_id": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Status(); ok {
		if err := paymentorder.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.status": %w`, err)}
		}
	}
	if v, ok := _u.mutation.RefundRequestedBy(); ok {
		if err := paymentorder.RefundRequestedByValidator(v); err != nil {
			return &ValidationError{Name: "refund_requested_by", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.refund_requested_by": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ClientIP(); ok {
		if err := paymentorder.ClientIPValidator(v); err != nil {
			return &ValidationError{Name: "client_ip", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.client_ip": %w`, err)}
		}
	}
	if v, ok := _u.mutation.SrcHost(); ok {
		if err := paymentorder.SrcHostValidator(v); err != nil {
			return &ValidationError{Name: "src_host", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.src_host": %w`, err)}
		}
	}
	if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "PaymentOrder.user"`)
	}
	return nil
}

func (_u *PaymentOrderUpdate) sqlSave(ctx context.Context) (_node int, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(paymentorder.Table, paymentorder.Columns, sqlgraph.NewFieldSpec(paymentorder.FieldID, field.TypeInt64))
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.UserEmail(); ok {
		_spec.SetField(paymentorder.FieldUserEmail, field.TypeString, value)
	}
	if value, ok := _u.mutation.UserName(); ok {
		_spec.SetField(paymentorder.FieldUserName, field.TypeString, value)
	}
	if value, ok := _u.mutation.UserNotes(); ok {
		_spec.SetField(paymentorder.FieldUserNotes, field.TypeString, value)
	}
	if _u.mutation.UserNotesCleared() {
		_spec.ClearField(paymentorder.FieldUserNotes, field.TypeString)
	}
	if value, ok := _u.mutation.Amount(); ok {
		_spec.SetField(paymentorder.FieldAmount, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedAmount(); ok {
		_spec.AddField(paymentorder.FieldAmount, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.PayAmount(); ok {
		_spec.SetField(paymentorder.FieldPayAmount, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedPayAmount(); ok {
		_spec.AddField(paymentorder.FieldPayAmount, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.FeeRate(); ok {
		_spec.SetField(paymentorder.FieldFeeRate, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedFeeRate(); ok {
		_spec.AddField(paymentorder.FieldFeeRate, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.RechargeCode(); ok {
		_spec.SetField(paymentorder.FieldRechargeCode, field.TypeString, value)
	}
	if value, ok := _u.mutation.OutTradeNo(); ok {
		_spec.SetField(paymentorder.FieldOutTradeNo, field.TypeString, value)
	}
	if value, ok := _u.mutation.PaymentType(); ok {
		_spec.SetField(paymentorder.FieldPaymentType, field.TypeString, value)
	}
	if value, ok := _u.mutation.PaymentTradeNo(); ok {
		_spec.SetField(paymentorder.FieldPaymentTradeNo, field.TypeString, value)
	}
	if value, ok := _u.mutation.PayURL(); ok {
		_spec.SetField(paymentorder.FieldPayURL, field.TypeString, value)
	}
	if _u.mutation.PayURLCleared() {
		_spec.ClearField(paymentorder.FieldPayURL, field.TypeString)
	}
	if value, ok := _u.mutation.QrCode(); ok {
		_spec.SetField(paymentorder.FieldQrCode, field.TypeString, value)
	}
	if _u.mutation.QrCodeCleared() {
		_spec.ClearField(paymentorder.FieldQrCode, field.TypeString)
	}
	if value, ok := _u.mutation.QrCodeImg(); ok {
		_spec.SetField(paymentorder.FieldQrCodeImg, field.TypeString, value)
	}
	if _u.mutation.QrCodeImgCleared() {
		_spec.ClearField(paymentorder.FieldQrCodeImg, field.TypeString)
	}
	if value, ok := _u.mutation.OrderType(); ok {
		_spec.SetField(paymentorder.FieldOrderType, field.TypeString, value)
	}
	if value, ok := _u.mutation.PlanID(); ok {
		_spec.SetField(paymentorder.FieldPlanID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedPlanID(); ok {
		_spec.AddField(paymentorder.FieldPlanID, field.TypeInt64, value)
	}
	if _u.mutation.PlanIDCleared() {
		_spec.ClearField(paymentorder.FieldPlanID, field.TypeInt64)
	}
	if value, ok := _u.mutation.SubscriptionGroupID(); ok {
		_spec.SetField(paymentorder.FieldSubscriptionGroupID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedSubscriptionGroupID(); ok {
		_spec.AddField(paymentorder.FieldSubscriptionGroupID, field.TypeInt64, value)
	}
	if _u.mutation.SubscriptionGroupIDCleared() {
		_spec.ClearField(paymentorder.FieldSubscriptionGroupID, field.TypeInt64)
	}
	if value, ok := _u.mutation.SubscriptionDays(); ok {
		_spec.SetField(paymentorder.FieldSubscriptionDays, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedSubscriptionDays(); ok {
		_spec.AddField(paymentorder.FieldSubscriptionDays, field.TypeInt, value)
	}
	if _u.mutation.SubscriptionDaysCleared() {
		_spec.ClearField(paymentorder.FieldSubscriptionDays, field.TypeInt)
	}
	if value, ok := _u.mutation.ProviderInstanceID(); ok {
		_spec.SetField(paymentorder.FieldProviderInstanceID, field.TypeString, value)
	}
	if _u.mutation.ProviderInstanceIDCleared() {
		_spec.ClearField(paymentorder.FieldProviderInstanceID, field.TypeString)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(paymentorder.FieldStatus, field.TypeString, value)
	}
	if value, ok := _u.mutation.RefundAmount(); ok {
		_spec.SetField(paymentorder.FieldRefundAmount, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedRefundAmount(); ok {
		_spec.AddField(paymentorder.FieldRefundAmount, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.RefundReason(); ok {
		_spec.SetField(paymentorder.FieldRefundReason, field.TypeString, value)
	}
	if _u.mutation.RefundReasonCleared() {
		_spec.ClearField(paymentorder.FieldRefundReason, field.TypeString)
	}
	if value, ok := _u.mutation.RefundAt(); ok {
		_spec.SetField(paymentorder.FieldRefundAt, field.TypeTime, value)
	}
	if _u.mutation.RefundAtCleared() {
		_spec.ClearField(paymentorder.FieldRefundAt, field.TypeTime)
	}
	if value, ok := _u.mutation.ForceRefund(); ok {
		_spec.SetField(paymentorder.FieldForceRefund, field.TypeBool, value)
	}
	if value, ok := _u.mutation.RefundRequestedAt(); ok {
		_spec.SetField(paymentorder.FieldRefundRequestedAt, field.TypeTime, value)
	}
	if _u.mutation.RefundRequestedAtCleared() {
		_spec.ClearField(paymentorder.FieldRefundRequestedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.RefundRequestReason(); ok {
		_spec.SetField(paymentorder.FieldRefundRequestReason, field.TypeString, value)
	}
	if _u.mutation.RefundRequestReasonCleared() {
		_spec.ClearField(paymentorder.FieldRefundRequestReason, field.TypeString)
	}
	if value, ok := _u.mutation.RefundRequestedBy(); ok {
		_spec.SetField(paymentorder.FieldRefundRequestedBy, field.TypeString, value)
	}
	if _u.mutation.RefundRequestedByCleared() {
		_spec.ClearField(paymentorder.FieldRefundRequestedBy, field.TypeString)
	}
	if value, ok := _u.mutation.ExpiresAt(); ok {
		_spec.SetField(paymentorder.FieldExpiresAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.PaidAt(); ok {
		_spec.SetField(paymentorder.FieldPaidAt, field.TypeTime, value)
	}
	if _u.mutation.PaidAtCleared() {
		_spec.ClearField(paymentorder.FieldPaidAt, field.TypeTime)
	}
	if value, ok := _u.mutation.CompletedAt(); ok {
		_spec.SetField(paymentorder.FieldCompletedAt, field.TypeTime, value)
	}
	if _u.mutation.CompletedAtCleared() {
		_spec.ClearField(paymentorder.FieldCompletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.FailedAt(); ok {
		_spec.SetField(paymentorder.FieldFailedAt, field.TypeTime, value)
	}
	if _u.mutation.FailedAtCleared() {
		_spec.ClearField(paymentorder.FieldFailedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.FailedReason(); ok {
		_spec.SetField(paymentorder.FieldFailedReason, field.TypeString, value)
	}
	if _u.mutation.FailedReasonCleared() {
		_spec.ClearField(paymentorder.FieldFailedReason, field.TypeString)
	}
	if value, ok := _u.mutation.ClientIP(); ok {
		_spec.SetField(paymentorder.FieldClientIP, field.TypeString, value)
	}
	if value, ok := _u.mutation.SrcHost(); ok {
		_spec.SetField(paymentorder.FieldSrcHost, field.TypeString, value)
	}
	if value, ok := _u.mutation.SrcURL(); ok {
		_spec.SetField(paymentorder.FieldSrcURL, field.TypeString, value)
	}
	if _u.mutation.SrcURLCleared() {
		_spec.ClearField(paymentorder.FieldSrcURL, field.TypeString)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(paymentorder.FieldUpdatedAt, field.TypeTime, value)
	}
	if _u.mutation.UserCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   paymentorder.UserTable,
			Columns: []string{paymentorder.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   paymentorder.UserTable,
			Columns: []string{paymentorder.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{paymentorder.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	_u.mutation.done = true
	return _node, nil
}

// PaymentOrderUpdateOne is the builder for updating a single PaymentOrder entity.
type PaymentOrderUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *PaymentOrderMutation
}

// SetUserID sets the "user_id" field.
func (_u *PaymentOrderUpdateOne) SetUserID(v int64) *PaymentOrderUpdateOne {
	_u.mutation.SetUserID(v)
	return _u
}

// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableUserID(v *int64) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetUserID(*v)
	}
	return _u
}

// SetUserEmail sets the "user_email" field.
func (_u *PaymentOrderUpdateOne) SetUserEmail(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetUserEmail(v)
	return _u
}

// SetNillableUserEmail sets the "user_email" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableUserEmail(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetUserEmail(*v)
	}
	return _u
}

// SetUserName sets the "user_name" field.
func (_u *PaymentOrderUpdateOne) SetUserName(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetUserName(v)
	return _u
}

// SetNillableUserName sets the "user_name" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableUserName(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetUserName(*v)
	}
	return _u
}

// SetUserNotes sets the "user_notes" field.
func (_u *PaymentOrderUpdateOne) SetUserNotes(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetUserNotes(v)
	return _u
}

// SetNillableUserNotes sets the "user_notes" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableUserNotes(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetUserNotes(*v)
	}
	return _u
}

// ClearUserNotes clears the value of the "user_notes" field.
func (_u *PaymentOrderUpdateOne) ClearUserNotes() *PaymentOrderUpdateOne {
	_u.mutation.ClearUserNotes()
	return _u
}

// SetAmount sets the "amount" field.
func (_u *PaymentOrderUpdateOne) SetAmount(v float64) *PaymentOrderUpdateOne {
	_u.mutation.ResetAmount()
	_u.mutation.SetAmount(v)
	return _u
}

// SetNillableAmount sets the "amount" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableAmount(v *float64) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetAmount(*v)
	}
	return _u
}

// AddAmount adds value to the "amount" field.
func (_u *PaymentOrderUpdateOne) AddAmount(v float64) *PaymentOrderUpdateOne {
	_u.mutation.AddAmount(v)
	return _u
}

// SetPayAmount sets the "pay_amount" field.
func (_u *PaymentOrderUpdateOne) SetPayAmount(v float64) *PaymentOrderUpdateOne {
	_u.mutation.ResetPayAmount()
	_u.mutation.SetPayAmount(v)
	return _u
}

// SetNillablePayAmount sets the "pay_amount" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillablePayAmount(v *float64) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetPayAmount(*v)
	}
	return _u
}

// AddPayAmount adds value to the "pay_amount" field.
func (_u *PaymentOrderUpdateOne) AddPayAmount(v float64) *PaymentOrderUpdateOne {
	_u.mutation.AddPayAmount(v)
	return _u
}

// SetFeeRate sets the "fee_rate" field.
func (_u *PaymentOrderUpdateOne) SetFeeRate(v float64) *PaymentOrderUpdateOne {
	_u.mutation.ResetFeeRate()
	_u.mutation.SetFeeRate(v)
	return _u
}

// SetNillableFeeRate sets the "fee_rate" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableFeeRate(v *float64) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetFeeRate(*v)
	}
	return _u
}

// AddFeeRate adds value to the "fee_rate" field.
func (_u *PaymentOrderUpdateOne) AddFeeRate(v float64) *PaymentOrderUpdateOne {
	_u.mutation.AddFeeRate(v)
	return _u
}

// SetRechargeCode sets the "recharge_code" field.
func (_u *PaymentOrderUpdateOne) SetRechargeCode(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetRechargeCode(v)
	return _u
}

// SetNillableRechargeCode sets the "recharge_code" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableRechargeCode(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetRechargeCode(*v)
	}
	return _u
}

// SetOutTradeNo sets the "out_trade_no" field.
func (_u *PaymentOrderUpdateOne) SetOutTradeNo(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetOutTradeNo(v)
	return _u
}

// SetNillableOutTradeNo sets the "out_trade_no" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableOutTradeNo(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetOutTradeNo(*v)
	}
	return _u
}

// SetPaymentType sets the "payment_type" field.
func (_u *PaymentOrderUpdateOne) SetPaymentType(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetPaymentType(v)
	return _u
}

// SetNillablePaymentType sets the "payment_type" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillablePaymentType(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetPaymentType(*v)
	}
	return _u
}

// SetPaymentTradeNo sets the "payment_trade_no" field.
func (_u *PaymentOrderUpdateOne) SetPaymentTradeNo(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetPaymentTradeNo(v)
	return _u
}

// SetNillablePaymentTradeNo sets the "payment_trade_no" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillablePaymentTradeNo(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetPaymentTradeNo(*v)
	}
	return _u
}

// SetPayURL sets the "pay_url" field.
func (_u *PaymentOrderUpdateOne) SetPayURL(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetPayURL(v)
	return _u
}

// SetNillablePayURL sets the "pay_url" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillablePayURL(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetPayURL(*v)
	}
	return _u
}

// ClearPayURL clears the value of the "pay_url" field.
func (_u *PaymentOrderUpdateOne) ClearPayURL() *PaymentOrderUpdateOne {
	_u.mutation.ClearPayURL()
	return _u
}

// SetQrCode sets the "qr_code" field.
func (_u *PaymentOrderUpdateOne) SetQrCode(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetQrCode(v)
	return _u
}

// SetNillableQrCode sets the "qr_code" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableQrCode(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetQrCode(*v)
	}
	return _u
}

// ClearQrCode clears the value of the "qr_code" field.
func (_u *PaymentOrderUpdateOne) ClearQrCode() *PaymentOrderUpdateOne {
	_u.mutation.ClearQrCode()
	return _u
}

// SetQrCodeImg sets the "qr_code_img" field.
func (_u *PaymentOrderUpdateOne) SetQrCodeImg(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetQrCodeImg(v)
	return _u
}

// SetNillableQrCodeImg sets the "qr_code_img" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableQrCodeImg(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetQrCodeImg(*v)
	}
	return _u
}

// ClearQrCodeImg clears the value of the "qr_code_img" field.
func (_u *PaymentOrderUpdateOne) ClearQrCodeImg() *PaymentOrderUpdateOne {
	_u.mutation.ClearQrCodeImg()
	return _u
}

// SetOrderType sets the "order_type" field.
func (_u *PaymentOrderUpdateOne) SetOrderType(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetOrderType(v)
	return _u
}

// SetNillableOrderType sets the "order_type" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableOrderType(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetOrderType(*v)
	}
	return _u
}

// SetPlanID sets the "plan_id" field.
func (_u *PaymentOrderUpdateOne) SetPlanID(v int64) *PaymentOrderUpdateOne {
	_u.mutation.ResetPlanID()
	_u.mutation.SetPlanID(v)
	return _u
}

// SetNillablePlanID sets the "plan_id" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillablePlanID(v *int64) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetPlanID(*v)
	}
	return _u
}

// AddPlanID adds value to the "plan_id" field.
func (_u *PaymentOrderUpdateOne) AddPlanID(v int64) *PaymentOrderUpdateOne {
	_u.mutation.AddPlanID(v)
	return _u
}

// ClearPlanID clears the value of the "plan_id" field.
func (_u *PaymentOrderUpdateOne) ClearPlanID() *PaymentOrderUpdateOne {
	_u.mutation.ClearPlanID()
	return _u
}

// SetSubscriptionGroupID sets the "subscription_group_id" field.
func (_u *PaymentOrderUpdateOne) SetSubscriptionGroupID(v int64) *PaymentOrderUpdateOne {
	_u.mutation.ResetSubscriptionGroupID()
	_u.mutation.SetSubscriptionGroupID(v)
	return _u
}

// SetNillableSubscriptionGroupID sets the "subscription_group_id" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableSubscriptionGroupID(v *int64) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetSubscriptionGroupID(*v)
	}
	return _u
}

// AddSubscriptionGroupID adds value to the "subscription_group_id" field.
func (_u *PaymentOrderUpdateOne) AddSubscriptionGroupID(v int64) *PaymentOrderUpdateOne {
	_u.mutation.AddSubscriptionGroupID(v)
	return _u
}

// ClearSubscriptionGroupID clears the value of the "subscription_group_id" field.
func (_u *PaymentOrderUpdateOne) ClearSubscriptionGroupID() *PaymentOrderUpdateOne {
	_u.mutation.ClearSubscriptionGroupID()
	return _u
}

// SetSubscriptionDays sets the "subscription_days" field.
func (_u *PaymentOrderUpdateOne) SetSubscriptionDays(v int) *PaymentOrderUpdateOne {
	_u.mutation.ResetSubscriptionDays()
	_u.mutation.SetSubscriptionDays(v)
	return _u
}

// SetNillableSubscriptionDays sets the "subscription_days" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableSubscriptionDays(v *int) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetSubscriptionDays(*v)
	}
	return _u
}

// AddSubscriptionDays adds value to the "subscription_days" field.
func (_u *PaymentOrderUpdateOne) AddSubscriptionDays(v int) *PaymentOrderUpdateOne {
	_u.mutation.AddSubscriptionDays(v)
	return _u
}

// ClearSubscriptionDays clears the value of the "subscription_days" field.
func (_u *PaymentOrderUpdateOne) ClearSubscriptionDays() *PaymentOrderUpdateOne {
	_u.mutation.ClearSubscriptionDays()
	return _u
}

// SetProviderInstanceID sets the "provider_instance_id" field.
func (_u *PaymentOrderUpdateOne) SetProviderInstanceID(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetProviderInstanceID(v)
	return _u
}

// SetNillableProviderInstanceID sets the "provider_instance_id" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableProviderInstanceID(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetProviderInstanceID(*v)
	}
	return _u
}

// ClearProviderInstanceID clears the value of the "provider_instance_id" field.
func (_u *PaymentOrderUpdateOne) ClearProviderInstanceID() *PaymentOrderUpdateOne {
	_u.mutation.ClearProviderInstanceID()
	return _u
}

// SetStatus sets the "status" field.
func (_u *PaymentOrderUpdateOne) SetStatus(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetStatus(v)
	return _u
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableStatus(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetStatus(*v)
	}
	return _u
}

// SetRefundAmount sets the "refund_amount" field.
func (_u *PaymentOrderUpdateOne) SetRefundAmount(v float64) *PaymentOrderUpdateOne {
	_u.mutation.ResetRefundAmount()
	_u.mutation.SetRefundAmount(v)
	return _u
}

// SetNillableRefundAmount sets the "refund_amount" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableRefundAmount(v *float64) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetRefundAmount(*v)
	}
	return _u
}

// AddRefundAmount adds value to the "refund_amount" field.
func (_u *PaymentOrderUpdateOne) AddRefundAmount(v float64) *PaymentOrderUpdateOne {
	_u.mutation.AddRefundAmount(v)
	return _u
}

// SetRefundReason sets the "refund_reason" field.
func (_u *PaymentOrderUpdateOne) SetRefundReason(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetRefundReason(v)
	return _u
}

// SetNillableRefundReason sets the "refund_reason" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableRefundReason(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetRefundReason(*v)
	}
	return _u
}

// ClearRefundReason clears the value of the "refund_reason" field.
func (_u *PaymentOrderUpdateOne) ClearRefundReason() *PaymentOrderUpdateOne {
	_u.mutation.ClearRefundReason()
	return _u
}

// SetRefundAt sets the "refund_at" field.
func (_u *PaymentOrderUpdateOne) SetRefundAt(v time.Time) *PaymentOrderUpdateOne {
	_u.mutation.SetRefundAt(v)
	return _u
}

// SetNillableRefundAt sets the "refund_at" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableRefundAt(v *time.Time) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetRefundAt(*v)
	}
	return _u
}

// ClearRefundAt clears the value of the "refund_at" field.
func (_u *PaymentOrderUpdateOne) ClearRefundAt() *PaymentOrderUpdateOne {
	_u.mutation.ClearRefundAt()
	return _u
}

// SetForceRefund sets the "force_refund" field.
func (_u *PaymentOrderUpdateOne) SetForceRefund(v bool) *PaymentOrderUpdateOne {
	_u.mutation.SetForceRefund(v)
	return _u
}

// SetNillableForceRefund sets the "force_refund" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableForceRefund(v *bool) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetForceRefund(*v)
	}
	return _u
}

// SetRefundRequestedAt sets the "refund_requested_at" field.
func (_u *PaymentOrderUpdateOne) SetRefundRequestedAt(v time.Time) *PaymentOrderUpdateOne {
	_u.mutation.SetRefundRequestedAt(v)
	return _u
}

// SetNillableRefundRequestedAt sets the "refund_requested_at" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableRefundRequestedAt(v *time.Time) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetRefundRequestedAt(*v)
	}
	return _u
}

// ClearRefundRequestedAt clears the value of the "refund_requested_at" field.
func (_u *PaymentOrderUpdateOne) ClearRefundRequestedAt() *PaymentOrderUpdateOne {
	_u.mutation.ClearRefundRequestedAt()
	return _u
}

// SetRefundRequestReason sets the "refund_request_reason" field.
func (_u *PaymentOrderUpdateOne) SetRefundRequestReason(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetRefundRequestReason(v)
	return _u
}

// SetNillableRefundRequestReason sets the "refund_request_reason" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableRefundRequestReason(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetRefundRequestReason(*v)
	}
	return _u
}

// ClearRefundRequestReason clears the value of the "refund_request_reason" field.
func (_u *PaymentOrderUpdateOne) ClearRefundRequestReason() *PaymentOrderUpdateOne {
	_u.mutation.ClearRefundRequestReason()
	return _u
}

// SetRefundRequestedBy sets the "refund_requested_by" field.
func (_u *PaymentOrderUpdateOne) SetRefundRequestedBy(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetRefundRequestedBy(v)
	return _u
}

// SetNillableRefundRequestedBy sets the "refund_requested_by" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableRefundRequestedBy(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetRefundRequestedBy(*v)
	}
	return _u
}

// ClearRefundRequestedBy clears the value of the "refund_requested_by" field.
func (_u *PaymentOrderUpdateOne) ClearRefundRequestedBy() *PaymentOrderUpdateOne {
	_u.mutation.ClearRefundRequestedBy()
	return _u
}

// SetExpiresAt sets the "expires_at" field.
func (_u *PaymentOrderUpdateOne) SetExpiresAt(v time.Time) *PaymentOrderUpdateOne {
	_u.mutation.SetExpiresAt(v)
	return _u
}

// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableExpiresAt(v *time.Time) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetExpiresAt(*v)
	}
	return _u
}

// SetPaidAt sets the "paid_at" field.
func (_u *PaymentOrderUpdateOne) SetPaidAt(v time.Time) *PaymentOrderUpdateOne {
	_u.mutation.SetPaidAt(v)
	return _u
}

// SetNillablePaidAt sets the "paid_at" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillablePaidAt(v *time.Time) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetPaidAt(*v)
	}
	return _u
}

// ClearPaidAt clears the value of the "paid_at" field.
func (_u *PaymentOrderUpdateOne) ClearPaidAt() *PaymentOrderUpdateOne {
	_u.mutation.ClearPaidAt()
	return _u
}

// SetCompletedAt sets the "completed_at" field.
func (_u *PaymentOrderUpdateOne) SetCompletedAt(v time.Time) *PaymentOrderUpdateOne {
	_u.mutation.SetCompletedAt(v)
	return _u
}

// SetNillableCompletedAt sets the "completed_at" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableCompletedAt(v *time.Time) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetCompletedAt(*v)
	}
	return _u
}

// ClearCompletedAt clears the value of the "completed_at" field.
func (_u *PaymentOrderUpdateOne) ClearCompletedAt() *PaymentOrderUpdateOne {
	_u.mutation.ClearCompletedAt()
	return _u
}

// SetFailedAt sets the "failed_at" field.
func (_u *PaymentOrderUpdateOne) SetFailedAt(v time.Time) *PaymentOrderUpdateOne {
	_u.mutation.SetFailedAt(v)
	return _u
}

// SetNillableFailedAt sets the "failed_at" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableFailedAt(v *time.Time) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetFailedAt(*v)
	}
	return _u
}

// ClearFailedAt clears the value of the "failed_at" field.
func (_u *PaymentOrderUpdateOne) ClearFailedAt() *PaymentOrderUpdateOne {
	_u.mutation.ClearFailedAt()
	return _u
}

// SetFailedReason sets the "failed_reason" field.
func (_u *PaymentOrderUpdateOne) SetFailedReason(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetFailedReason(v)
	return _u
}

// SetNillableFailedReason sets the "failed_reason" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableFailedReason(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetFailedReason(*v)
	}
	return _u
}

// ClearFailedReason clears the value of the "failed_reason" field.
func (_u *PaymentOrderUpdateOne) ClearFailedReason() *PaymentOrderUpdateOne {
	_u.mutation.ClearFailedReason()
	return _u
}

// SetClientIP sets the "client_ip" field.
func (_u *PaymentOrderUpdateOne) SetClientIP(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetClientIP(v)
	return _u
}

// SetNillableClientIP sets the "client_ip" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableClientIP(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetClientIP(*v)
	}
	return _u
}

// SetSrcHost sets the "src_host" field.
func (_u *PaymentOrderUpdateOne) SetSrcHost(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetSrcHost(v)
	return _u
}

// SetNillableSrcHost sets the "src_host" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableSrcHost(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetSrcHost(*v)
	}
	return _u
}

// SetSrcURL sets the "src_url" field.
func (_u *PaymentOrderUpdateOne) SetSrcURL(v string) *PaymentOrderUpdateOne {
	_u.mutation.SetSrcURL(v)
	return _u
}

// SetNillableSrcURL sets the "src_url" field if the given value is not nil.
func (_u *PaymentOrderUpdateOne) SetNillableSrcURL(v *string) *PaymentOrderUpdateOne {
	if v != nil {
		_u.SetSrcURL(*v)
	}
	return _u
}

// ClearSrcURL clears the value of the "src_url" field.
func (_u *PaymentOrderUpdateOne) ClearSrcURL() *PaymentOrderUpdateOne {
	_u.mutation.ClearSrcURL()
	return _u
}

// SetUpdatedAt sets the "updated_at" field.
func (_u *PaymentOrderUpdateOne) SetUpdatedAt(v time.Time) *PaymentOrderUpdateOne {
	_u.mutation.SetUpdatedAt(v)
	return _u
}

// SetUser sets the "user" edge to the User entity.
func (_u *PaymentOrderUpdateOne) SetUser(v *User) *PaymentOrderUpdateOne {
	return _u.SetUserID(v.ID)
}

// Mutation returns the PaymentOrderMutation object of the builder.
func (_u *PaymentOrderUpdateOne) Mutation() *PaymentOrderMutation {
	return _u.mutation
}

// ClearUser clears the "user" edge to the User entity.
func (_u *PaymentOrderUpdateOne) ClearUser() *PaymentOrderUpdateOne {
	_u.mutation.ClearUser()
	return _u
}

// Where appends a list predicates to the PaymentOrderUpdate builder.
func (_u *PaymentOrderUpdateOne) Where(ps ...predicate.PaymentOrder) *PaymentOrderUpdateOne {
	_u.mutation.Where(ps...)
	return _u
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *PaymentOrderUpdateOne) Select(field string, fields ...string) *PaymentOrderUpdateOne {
	_u.fields = append([]string{field}, fields...)
	return _u
}

// Save executes the query and returns the updated PaymentOrder entity.
func (_u *PaymentOrderUpdateOne) Save(ctx context.Context) (*PaymentOrder, error) {
	_u.defaults()
	return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (_u *PaymentOrderUpdateOne) SaveX(ctx context.Context) *PaymentOrder {
	node, err := _u.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (_u *PaymentOrderUpdateOne) Exec(ctx context.Context) error {
	_, err := _u.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (_u *PaymentOrderUpdateOne) ExecX(ctx context.Context) {
	if err := _u.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (_u *PaymentOrderUpdateOne) defaults() {
	if _, ok := _u.mutation.UpdatedAt(); !ok {
		v := paymentorder.UpdateDefaultUpdatedAt()
		_u.mutation.SetUpdatedAt(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (_u *PaymentOrderUpdateOne) check() error {
	if v, ok := _u.mutation.UserEmail(); ok {
		if err := paymentorder.UserEmailValidator(v); err != nil {
			return &ValidationError{Name: "user_email", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.user_email": %w`, err)}
		}
	}
	if v, ok := _u.mutation.UserName(); ok {
		if err := paymentorder.UserNameValidator(v); err != nil {
			return &ValidationError{Name: "user_name", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.user_name": %w`, err)}
		}
	}
	if v, ok := _u.mutation.RechargeCode(); ok {
		if err := paymentorder.RechargeCodeValidator(v); err != nil {
			return &ValidationError{Name: "recharge_code", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.recharge_code": %w`, err)}
		}
	}
	if v, ok := _u.mutation.OutTradeNo(); ok {
		if err := paymentorder.OutTradeNoValidator(v); err != nil {
			return &ValidationError{Name: "out_trade_no", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.out_trade_no": %w`, err)}
		}
	}
	if v, ok := _u.mutation.PaymentType(); ok {
		if err := paymentorder.PaymentTypeValidator(v); err != nil {
			return &ValidationError{Name: "payment_type", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.payment_type": %w`, err)}
		}
	}
	if v, ok := _u.mutation.PaymentTradeNo(); ok {
		if err := paymentorder.PaymentTradeNoValidator(v); err != nil {
			return &ValidationError{Name: "payment_trade_no", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.payment_trade_no": %w`, err)}
		}
	}
	if v, ok := _u.mutation.OrderType(); ok {
		if err := paymentorder.OrderTypeValidator(v); err != nil {
			return &ValidationError{Name: "order_type", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.order_type": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ProviderInstanceID(); ok {
		if err := paymentorder.ProviderInstanceIDValidator(v); err != nil {
			return &ValidationError{Name: "provider_instance_id", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.provider_instance_id": %w`, err)}
		}
	}
	if v, ok := _u.mutation.Status(); ok {
		if err := paymentorder.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.status": %w`, err)}
		}
	}
	if v, ok := _u.mutation.RefundRequestedBy(); ok {
		if err := paymentorder.RefundRequestedByValidator(v); err != nil {
			return &ValidationError{Name: "refund_requested_by", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.refund_requested_by": %w`, err)}
		}
	}
	if v, ok := _u.mutation.ClientIP(); ok {
		if err := paymentorder.ClientIPValidator(v); err != nil {
			return &ValidationError{Name: "client_ip", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.client_ip": %w`, err)}
		}
	}
	if v, ok := _u.mutation.SrcHost(); ok {
		if err := paymentorder.SrcHostValidator(v); err != nil {
			return &ValidationError{Name: "src_host", err: fmt.Errorf(`ent: validator failed for field "PaymentOrder.src_host": %w`, err)}
		}
	}
	if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "PaymentOrder.user"`)
	}
	return nil
}

func (_u *PaymentOrderUpdateOne) sqlSave(ctx context.Context) (_node *PaymentOrder, err error) {
	if err := _u.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(paymentorder.Table, paymentorder.Columns, sqlgraph.NewFieldSpec(paymentorder.FieldID, field.TypeInt64))
	id, ok := _u.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PaymentOrder.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := _u.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, paymentorder.FieldID)
		for _, f := range fields {
			if !paymentorder.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != paymentorder.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := _u.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := _u.mutation.UserEmail(); ok {
		_spec.SetField(paymentorder.FieldUserEmail, field.TypeString, value)
	}
	if value, ok := _u.mutation.UserName(); ok {
		_spec.SetField(paymentorder.FieldUserName, field.TypeString, value)
	}
	if value, ok := _u.mutation.UserNotes(); ok {
		_spec.SetField(paymentorder.FieldUserNotes, field.TypeString, value)
	}
	if _u.mutation.UserNotesCleared() {
		_spec.ClearField(paymentorder.FieldUserNotes, field.TypeString)
	}
	if value, ok := _u.mutation.Amount(); ok {
		_spec.SetField(paymentorder.FieldAmount, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedAmount(); ok {
		_spec.AddField(paymentorder.FieldAmount, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.PayAmount(); ok {
		_spec.SetField(paymentorder.FieldPayAmount, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedPayAmount(); ok {
		_spec.AddField(paymentorder.FieldPayAmount, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.FeeRate(); ok {
		_spec.SetField(paymentorder.FieldFeeRate, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedFeeRate(); ok {
		_spec.AddField(paymentorder.FieldFeeRate, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.RechargeCode(); ok {
		_spec.SetField(paymentorder.FieldRechargeCode, field.TypeString, value)
	}
	if value, ok := _u.mutation.OutTradeNo(); ok {
		_spec.SetField(paymentorder.FieldOutTradeNo, field.TypeString, value)
	}
	if value, ok := _u.mutation.PaymentType(); ok {
		_spec.SetField(paymentorder.FieldPaymentType, field.TypeString, value)
	}
	if value, ok := _u.mutation.PaymentTradeNo(); ok {
		_spec.SetField(paymentorder.FieldPaymentTradeNo, field.TypeString, value)
	}
	if value, ok := _u.mutation.PayURL(); ok {
		_spec.SetField(paymentorder.FieldPayURL, field.TypeString, value)
	}
	if _u.mutation.PayURLCleared() {
		_spec.ClearField(paymentorder.FieldPayURL, field.TypeString)
	}
	if value, ok := _u.mutation.QrCode(); ok {
		_spec.SetField(paymentorder.FieldQrCode, field.TypeString, value)
	}
	if _u.mutation.QrCodeCleared() {
		_spec.ClearField(paymentorder.FieldQrCode, field.TypeString)
	}
	if value, ok := _u.mutation.QrCodeImg(); ok {
		_spec.SetField(paymentorder.FieldQrCodeImg, field.TypeString, value)
	}
	if _u.mutation.QrCodeImgCleared() {
		_spec.ClearField(paymentorder.FieldQrCodeImg, field.TypeString)
	}
	if value, ok := _u.mutation.OrderType(); ok {
		_spec.SetField(paymentorder.FieldOrderType, field.TypeString, value)
	}
	if value, ok := _u.mutation.PlanID(); ok {
		_spec.SetField(paymentorder.FieldPlanID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedPlanID(); ok {
		_spec.AddField(paymentorder.FieldPlanID, field.TypeInt64, value)
	}
	if _u.mutation.PlanIDCleared() {
		_spec.ClearField(paymentorder.FieldPlanID, field.TypeInt64)
	}
	if value, ok := _u.mutation.SubscriptionGroupID(); ok {
		_spec.SetField(paymentorder.FieldSubscriptionGroupID, field.TypeInt64, value)
	}
	if value, ok := _u.mutation.AddedSubscriptionGroupID(); ok {
		_spec.AddField(paymentorder.FieldSubscriptionGroupID, field.TypeInt64, value)
	}
	if _u.mutation.SubscriptionGroupIDCleared() {
		_spec.ClearField(paymentorder.FieldSubscriptionGroupID, field.TypeInt64)
	}
	if value, ok := _u.mutation.SubscriptionDays(); ok {
		_spec.SetField(paymentorder.FieldSubscriptionDays, field.TypeInt, value)
	}
	if value, ok := _u.mutation.AddedSubscriptionDays(); ok {
		_spec.AddField(paymentorder.FieldSubscriptionDays, field.TypeInt, value)
	}
	if _u.mutation.SubscriptionDaysCleared() {
		_spec.ClearField(paymentorder.FieldSubscriptionDays, field.TypeInt)
	}
	if value, ok := _u.mutation.ProviderInstanceID(); ok {
		_spec.SetField(paymentorder.FieldProviderInstanceID, field.TypeString, value)
	}
	if _u.mutation.ProviderInstanceIDCleared() {
		_spec.ClearField(paymentorder.FieldProviderInstanceID, field.TypeString)
	}
	if value, ok := _u.mutation.Status(); ok {
		_spec.SetField(paymentorder.FieldStatus, field.TypeString, value)
	}
	if value, ok := _u.mutation.RefundAmount(); ok {
		_spec.SetField(paymentorder.FieldRefundAmount, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.AddedRefundAmount(); ok {
		_spec.AddField(paymentorder.FieldRefundAmount, field.TypeFloat64, value)
	}
	if value, ok := _u.mutation.RefundReason(); ok {
		_spec.SetField(paymentorder.FieldRefundReason, field.TypeString, value)
	}
	if _u.mutation.RefundReasonCleared() {
		_spec.ClearField(paymentorder.FieldRefundReason, field.TypeString)
	}
	if value, ok := _u.mutation.RefundAt(); ok {
		_spec.SetField(paymentorder.FieldRefundAt, field.TypeTime, value)
	}
	if _u.mutation.RefundAtCleared() {
		_spec.ClearField(paymentorder.FieldRefundAt, field.TypeTime)
	}
	if value, ok := _u.mutation.ForceRefund(); ok {
		_spec.SetField(paymentorder.FieldForceRefund, field.TypeBool, value)
	}
	if value, ok := _u.mutation.RefundRequestedAt(); ok {
		_spec.SetField(paymentorder.FieldRefundRequestedAt, field.TypeTime, value)
	}
	if _u.mutation.RefundRequestedAtCleared() {
		_spec.ClearField(paymentorder.FieldRefundRequestedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.RefundRequestReason(); ok {
		_spec.SetField(paymentorder.FieldRefundRequestReason, field.TypeString, value)
	}
	if _u.mutation.RefundRequestReasonCleared() {
		_spec.ClearField(paymentorder.FieldRefundRequestReason, field.TypeString)
	}
	if value, ok := _u.mutation.RefundRequestedBy(); ok {
		_spec.SetField(paymentorder.FieldRefundRequestedBy, field.TypeString, value)
	}
	if _u.mutation.RefundRequestedByCleared() {
		_spec.ClearField(paymentorder.FieldRefundRequestedBy, field.TypeString)
	}
	if value, ok := _u.mutation.ExpiresAt(); ok {
		_spec.SetField(paymentorder.FieldExpiresAt, field.TypeTime, value)
	}
	if value, ok := _u.mutation.PaidAt(); ok {
		_spec.SetField(paymentorder.FieldPaidAt, field.TypeTime, value)
	}
	if _u.mutation.PaidAtCleared() {
		_spec.ClearField(paymentorder.FieldPaidAt, field.TypeTime)
	}
	if value, ok := _u.mutation.CompletedAt(); ok {
		_spec.SetField(paymentorder.FieldCompletedAt, field.TypeTime, value)
	}
	if _u.mutation.CompletedAtCleared() {
		_spec.ClearField(paymentorder.FieldCompletedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.FailedAt(); ok {
		_spec.SetField(paymentorder.FieldFailedAt, field.TypeTime, value)
	}
	if _u.mutation.FailedAtCleared() {
		_spec.ClearField(paymentorder.FieldFailedAt, field.TypeTime)
	}
	if value, ok := _u.mutation.FailedReason(); ok {
		_spec.SetField(paymentorder.FieldFailedReason, field.TypeString, value)
	}
	if _u.mutation.FailedReasonCleared() {
		_spec.ClearField(paymentorder.FieldFailedReason, field.TypeString)
	}
	if value, ok := _u.mutation.ClientIP(); ok {
		_spec.SetField(paymentorder.FieldClientIP, field.TypeString, value)
	}
	if value, ok := _u.mutation.SrcHost(); ok {
		_spec.SetField(paymentorder.FieldSrcHost, field.TypeString, value)
	}
	if value, ok := _u.mutation.SrcURL(); ok {
		_spec.SetField(paymentorder.FieldSrcURL, field.TypeString, value)
	}
	if _u.mutation.SrcURLCleared() {
		_spec.ClearField(paymentorder.FieldSrcURL, field.TypeString)
	}
	if value, ok := _u.mutation.UpdatedAt(); ok {
		_spec.SetField(paymentorder.FieldUpdatedAt, field.TypeTime, value)
	}
	if _u.mutation.UserCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   paymentorder.UserTable,
			Columns: []string{paymentorder.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   paymentorder.UserTable,
			Columns: []string{paymentorder.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &PaymentOrder{config: _u.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{paymentorder.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	_u.mutation.done = true
	return _node, nil
}
