Files
sub2api/backend/ent/paymentchannel_update.go
T
erio 64c4495ae5 feat: integrate payment system (EasyPay, Alipay, WxPay, Stripe)
Replace iframe-based external payment with native implementation:

Backend (Go):
- 5 new Ent schemas: PaymentOrder, PaymentAuditLog, PaymentChannel,
  SubscriptionPlan, PaymentProviderInstance
- 5 SQL migrations (090-094)
- Payment provider interface + registry + load balancer
- 4 provider implementations (EasyPay, Alipay, WxPay, Stripe)
- PaymentService (order lifecycle, fulfillment, refund 3-phase)
- PaymentConfigService (settings, instance/channel/plan CRUD)
- 31 API endpoints (9 user + 4 webhook + 18 admin)
- Wire DI integration

Frontend (Vue3):
- Payment types, API modules, store, router changes
- Sidebar: payment_enabled controls visibility, new menu items
- User pages: PaymentView (replace iframe), QR payment, Stripe,
  result page, order list
- Admin pages: Order management (4 tabs), provider instance mgmt
- Settings: new payment tab, removed old purchase iframe config
- i18n: full payment namespace (en + zh)

Docs:
- PAYMENT_FRONTEND_MIGRATION_PLAN.md
- PAYMENT_BACKEND_MIGRATION_PLAN.md
- PAYMENT_IMPLEMENTATION_ROADMAP.md
2026-04-05 15:06:05 +08:00

633 lines
19 KiB
Go

// 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/paymentchannel"
"github.com/Wei-Shaw/sub2api/ent/predicate"
)
// PaymentChannelUpdate is the builder for updating PaymentChannel entities.
type PaymentChannelUpdate struct {
config
hooks []Hook
mutation *PaymentChannelMutation
}
// Where appends a list predicates to the PaymentChannelUpdate builder.
func (_u *PaymentChannelUpdate) Where(ps ...predicate.PaymentChannel) *PaymentChannelUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetGroupID sets the "group_id" field.
func (_u *PaymentChannelUpdate) SetGroupID(v int64) *PaymentChannelUpdate {
_u.mutation.ResetGroupID()
_u.mutation.SetGroupID(v)
return _u
}
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func (_u *PaymentChannelUpdate) SetNillableGroupID(v *int64) *PaymentChannelUpdate {
if v != nil {
_u.SetGroupID(*v)
}
return _u
}
// AddGroupID adds value to the "group_id" field.
func (_u *PaymentChannelUpdate) AddGroupID(v int64) *PaymentChannelUpdate {
_u.mutation.AddGroupID(v)
return _u
}
// ClearGroupID clears the value of the "group_id" field.
func (_u *PaymentChannelUpdate) ClearGroupID() *PaymentChannelUpdate {
_u.mutation.ClearGroupID()
return _u
}
// SetName sets the "name" field.
func (_u *PaymentChannelUpdate) SetName(v string) *PaymentChannelUpdate {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *PaymentChannelUpdate) SetNillableName(v *string) *PaymentChannelUpdate {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetPlatform sets the "platform" field.
func (_u *PaymentChannelUpdate) SetPlatform(v string) *PaymentChannelUpdate {
_u.mutation.SetPlatform(v)
return _u
}
// SetNillablePlatform sets the "platform" field if the given value is not nil.
func (_u *PaymentChannelUpdate) SetNillablePlatform(v *string) *PaymentChannelUpdate {
if v != nil {
_u.SetPlatform(*v)
}
return _u
}
// SetRateMultiplier sets the "rate_multiplier" field.
func (_u *PaymentChannelUpdate) SetRateMultiplier(v float64) *PaymentChannelUpdate {
_u.mutation.ResetRateMultiplier()
_u.mutation.SetRateMultiplier(v)
return _u
}
// SetNillableRateMultiplier sets the "rate_multiplier" field if the given value is not nil.
func (_u *PaymentChannelUpdate) SetNillableRateMultiplier(v *float64) *PaymentChannelUpdate {
if v != nil {
_u.SetRateMultiplier(*v)
}
return _u
}
// AddRateMultiplier adds value to the "rate_multiplier" field.
func (_u *PaymentChannelUpdate) AddRateMultiplier(v float64) *PaymentChannelUpdate {
_u.mutation.AddRateMultiplier(v)
return _u
}
// SetDescription sets the "description" field.
func (_u *PaymentChannelUpdate) SetDescription(v string) *PaymentChannelUpdate {
_u.mutation.SetDescription(v)
return _u
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *PaymentChannelUpdate) SetNillableDescription(v *string) *PaymentChannelUpdate {
if v != nil {
_u.SetDescription(*v)
}
return _u
}
// SetModels sets the "models" field.
func (_u *PaymentChannelUpdate) SetModels(v string) *PaymentChannelUpdate {
_u.mutation.SetModels(v)
return _u
}
// SetNillableModels sets the "models" field if the given value is not nil.
func (_u *PaymentChannelUpdate) SetNillableModels(v *string) *PaymentChannelUpdate {
if v != nil {
_u.SetModels(*v)
}
return _u
}
// SetFeatures sets the "features" field.
func (_u *PaymentChannelUpdate) SetFeatures(v string) *PaymentChannelUpdate {
_u.mutation.SetFeatures(v)
return _u
}
// SetNillableFeatures sets the "features" field if the given value is not nil.
func (_u *PaymentChannelUpdate) SetNillableFeatures(v *string) *PaymentChannelUpdate {
if v != nil {
_u.SetFeatures(*v)
}
return _u
}
// SetSortOrder sets the "sort_order" field.
func (_u *PaymentChannelUpdate) SetSortOrder(v int) *PaymentChannelUpdate {
_u.mutation.ResetSortOrder()
_u.mutation.SetSortOrder(v)
return _u
}
// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
func (_u *PaymentChannelUpdate) SetNillableSortOrder(v *int) *PaymentChannelUpdate {
if v != nil {
_u.SetSortOrder(*v)
}
return _u
}
// AddSortOrder adds value to the "sort_order" field.
func (_u *PaymentChannelUpdate) AddSortOrder(v int) *PaymentChannelUpdate {
_u.mutation.AddSortOrder(v)
return _u
}
// SetEnabled sets the "enabled" field.
func (_u *PaymentChannelUpdate) SetEnabled(v bool) *PaymentChannelUpdate {
_u.mutation.SetEnabled(v)
return _u
}
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
func (_u *PaymentChannelUpdate) SetNillableEnabled(v *bool) *PaymentChannelUpdate {
if v != nil {
_u.SetEnabled(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *PaymentChannelUpdate) SetUpdatedAt(v time.Time) *PaymentChannelUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// Mutation returns the PaymentChannelMutation object of the builder.
func (_u *PaymentChannelUpdate) Mutation() *PaymentChannelMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *PaymentChannelUpdate) 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 *PaymentChannelUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *PaymentChannelUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *PaymentChannelUpdate) 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 *PaymentChannelUpdate) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := paymentchannel.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *PaymentChannelUpdate) check() error {
if v, ok := _u.mutation.Name(); ok {
if err := paymentchannel.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "PaymentChannel.name": %w`, err)}
}
}
if v, ok := _u.mutation.Platform(); ok {
if err := paymentchannel.PlatformValidator(v); err != nil {
return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "PaymentChannel.platform": %w`, err)}
}
}
return nil
}
func (_u *PaymentChannelUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(paymentchannel.Table, paymentchannel.Columns, sqlgraph.NewFieldSpec(paymentchannel.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.GroupID(); ok {
_spec.SetField(paymentchannel.FieldGroupID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedGroupID(); ok {
_spec.AddField(paymentchannel.FieldGroupID, field.TypeInt64, value)
}
if _u.mutation.GroupIDCleared() {
_spec.ClearField(paymentchannel.FieldGroupID, field.TypeInt64)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(paymentchannel.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.Platform(); ok {
_spec.SetField(paymentchannel.FieldPlatform, field.TypeString, value)
}
if value, ok := _u.mutation.RateMultiplier(); ok {
_spec.SetField(paymentchannel.FieldRateMultiplier, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedRateMultiplier(); ok {
_spec.AddField(paymentchannel.FieldRateMultiplier, field.TypeFloat64, value)
}
if value, ok := _u.mutation.Description(); ok {
_spec.SetField(paymentchannel.FieldDescription, field.TypeString, value)
}
if value, ok := _u.mutation.Models(); ok {
_spec.SetField(paymentchannel.FieldModels, field.TypeString, value)
}
if value, ok := _u.mutation.Features(); ok {
_spec.SetField(paymentchannel.FieldFeatures, field.TypeString, value)
}
if value, ok := _u.mutation.SortOrder(); ok {
_spec.SetField(paymentchannel.FieldSortOrder, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedSortOrder(); ok {
_spec.AddField(paymentchannel.FieldSortOrder, field.TypeInt, value)
}
if value, ok := _u.mutation.Enabled(); ok {
_spec.SetField(paymentchannel.FieldEnabled, field.TypeBool, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(paymentchannel.FieldUpdatedAt, field.TypeTime, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{paymentchannel.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// PaymentChannelUpdateOne is the builder for updating a single PaymentChannel entity.
type PaymentChannelUpdateOne struct {
config
fields []string
hooks []Hook
mutation *PaymentChannelMutation
}
// SetGroupID sets the "group_id" field.
func (_u *PaymentChannelUpdateOne) SetGroupID(v int64) *PaymentChannelUpdateOne {
_u.mutation.ResetGroupID()
_u.mutation.SetGroupID(v)
return _u
}
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func (_u *PaymentChannelUpdateOne) SetNillableGroupID(v *int64) *PaymentChannelUpdateOne {
if v != nil {
_u.SetGroupID(*v)
}
return _u
}
// AddGroupID adds value to the "group_id" field.
func (_u *PaymentChannelUpdateOne) AddGroupID(v int64) *PaymentChannelUpdateOne {
_u.mutation.AddGroupID(v)
return _u
}
// ClearGroupID clears the value of the "group_id" field.
func (_u *PaymentChannelUpdateOne) ClearGroupID() *PaymentChannelUpdateOne {
_u.mutation.ClearGroupID()
return _u
}
// SetName sets the "name" field.
func (_u *PaymentChannelUpdateOne) SetName(v string) *PaymentChannelUpdateOne {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *PaymentChannelUpdateOne) SetNillableName(v *string) *PaymentChannelUpdateOne {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetPlatform sets the "platform" field.
func (_u *PaymentChannelUpdateOne) SetPlatform(v string) *PaymentChannelUpdateOne {
_u.mutation.SetPlatform(v)
return _u
}
// SetNillablePlatform sets the "platform" field if the given value is not nil.
func (_u *PaymentChannelUpdateOne) SetNillablePlatform(v *string) *PaymentChannelUpdateOne {
if v != nil {
_u.SetPlatform(*v)
}
return _u
}
// SetRateMultiplier sets the "rate_multiplier" field.
func (_u *PaymentChannelUpdateOne) SetRateMultiplier(v float64) *PaymentChannelUpdateOne {
_u.mutation.ResetRateMultiplier()
_u.mutation.SetRateMultiplier(v)
return _u
}
// SetNillableRateMultiplier sets the "rate_multiplier" field if the given value is not nil.
func (_u *PaymentChannelUpdateOne) SetNillableRateMultiplier(v *float64) *PaymentChannelUpdateOne {
if v != nil {
_u.SetRateMultiplier(*v)
}
return _u
}
// AddRateMultiplier adds value to the "rate_multiplier" field.
func (_u *PaymentChannelUpdateOne) AddRateMultiplier(v float64) *PaymentChannelUpdateOne {
_u.mutation.AddRateMultiplier(v)
return _u
}
// SetDescription sets the "description" field.
func (_u *PaymentChannelUpdateOne) SetDescription(v string) *PaymentChannelUpdateOne {
_u.mutation.SetDescription(v)
return _u
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *PaymentChannelUpdateOne) SetNillableDescription(v *string) *PaymentChannelUpdateOne {
if v != nil {
_u.SetDescription(*v)
}
return _u
}
// SetModels sets the "models" field.
func (_u *PaymentChannelUpdateOne) SetModels(v string) *PaymentChannelUpdateOne {
_u.mutation.SetModels(v)
return _u
}
// SetNillableModels sets the "models" field if the given value is not nil.
func (_u *PaymentChannelUpdateOne) SetNillableModels(v *string) *PaymentChannelUpdateOne {
if v != nil {
_u.SetModels(*v)
}
return _u
}
// SetFeatures sets the "features" field.
func (_u *PaymentChannelUpdateOne) SetFeatures(v string) *PaymentChannelUpdateOne {
_u.mutation.SetFeatures(v)
return _u
}
// SetNillableFeatures sets the "features" field if the given value is not nil.
func (_u *PaymentChannelUpdateOne) SetNillableFeatures(v *string) *PaymentChannelUpdateOne {
if v != nil {
_u.SetFeatures(*v)
}
return _u
}
// SetSortOrder sets the "sort_order" field.
func (_u *PaymentChannelUpdateOne) SetSortOrder(v int) *PaymentChannelUpdateOne {
_u.mutation.ResetSortOrder()
_u.mutation.SetSortOrder(v)
return _u
}
// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
func (_u *PaymentChannelUpdateOne) SetNillableSortOrder(v *int) *PaymentChannelUpdateOne {
if v != nil {
_u.SetSortOrder(*v)
}
return _u
}
// AddSortOrder adds value to the "sort_order" field.
func (_u *PaymentChannelUpdateOne) AddSortOrder(v int) *PaymentChannelUpdateOne {
_u.mutation.AddSortOrder(v)
return _u
}
// SetEnabled sets the "enabled" field.
func (_u *PaymentChannelUpdateOne) SetEnabled(v bool) *PaymentChannelUpdateOne {
_u.mutation.SetEnabled(v)
return _u
}
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
func (_u *PaymentChannelUpdateOne) SetNillableEnabled(v *bool) *PaymentChannelUpdateOne {
if v != nil {
_u.SetEnabled(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *PaymentChannelUpdateOne) SetUpdatedAt(v time.Time) *PaymentChannelUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// Mutation returns the PaymentChannelMutation object of the builder.
func (_u *PaymentChannelUpdateOne) Mutation() *PaymentChannelMutation {
return _u.mutation
}
// Where appends a list predicates to the PaymentChannelUpdate builder.
func (_u *PaymentChannelUpdateOne) Where(ps ...predicate.PaymentChannel) *PaymentChannelUpdateOne {
_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 *PaymentChannelUpdateOne) Select(field string, fields ...string) *PaymentChannelUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated PaymentChannel entity.
func (_u *PaymentChannelUpdateOne) Save(ctx context.Context) (*PaymentChannel, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *PaymentChannelUpdateOne) SaveX(ctx context.Context) *PaymentChannel {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *PaymentChannelUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *PaymentChannelUpdateOne) 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 *PaymentChannelUpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := paymentchannel.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *PaymentChannelUpdateOne) check() error {
if v, ok := _u.mutation.Name(); ok {
if err := paymentchannel.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "PaymentChannel.name": %w`, err)}
}
}
if v, ok := _u.mutation.Platform(); ok {
if err := paymentchannel.PlatformValidator(v); err != nil {
return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "PaymentChannel.platform": %w`, err)}
}
}
return nil
}
func (_u *PaymentChannelUpdateOne) sqlSave(ctx context.Context) (_node *PaymentChannel, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(paymentchannel.Table, paymentchannel.Columns, sqlgraph.NewFieldSpec(paymentchannel.FieldID, field.TypeInt64))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PaymentChannel.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, paymentchannel.FieldID)
for _, f := range fields {
if !paymentchannel.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != paymentchannel.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.GroupID(); ok {
_spec.SetField(paymentchannel.FieldGroupID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedGroupID(); ok {
_spec.AddField(paymentchannel.FieldGroupID, field.TypeInt64, value)
}
if _u.mutation.GroupIDCleared() {
_spec.ClearField(paymentchannel.FieldGroupID, field.TypeInt64)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(paymentchannel.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.Platform(); ok {
_spec.SetField(paymentchannel.FieldPlatform, field.TypeString, value)
}
if value, ok := _u.mutation.RateMultiplier(); ok {
_spec.SetField(paymentchannel.FieldRateMultiplier, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedRateMultiplier(); ok {
_spec.AddField(paymentchannel.FieldRateMultiplier, field.TypeFloat64, value)
}
if value, ok := _u.mutation.Description(); ok {
_spec.SetField(paymentchannel.FieldDescription, field.TypeString, value)
}
if value, ok := _u.mutation.Models(); ok {
_spec.SetField(paymentchannel.FieldModels, field.TypeString, value)
}
if value, ok := _u.mutation.Features(); ok {
_spec.SetField(paymentchannel.FieldFeatures, field.TypeString, value)
}
if value, ok := _u.mutation.SortOrder(); ok {
_spec.SetField(paymentchannel.FieldSortOrder, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedSortOrder(); ok {
_spec.AddField(paymentchannel.FieldSortOrder, field.TypeInt, value)
}
if value, ok := _u.mutation.Enabled(); ok {
_spec.SetField(paymentchannel.FieldEnabled, field.TypeBool, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(paymentchannel.FieldUpdatedAt, field.TypeTime, value)
}
_node = &PaymentChannel{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{paymentchannel.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}