feat: complete charge

This commit is contained in:
Rogee
2024-12-10 14:50:50 +08:00
parent e3ef31037c
commit db0eacbc46
12 changed files with 431 additions and 64 deletions

179
backend/pkg/pg/users.gen.go Normal file
View File

@@ -0,0 +1,179 @@
// Code generated by go-enum DO NOT EDIT.
// Version: -
// Revision: -
// Build Date: -
// Built By: -
package pg
import (
"database/sql/driver"
"errors"
"fmt"
"strings"
)
const (
// BalanceTypeCharge is a BalanceType of type Charge.
BalanceTypeCharge BalanceType = "charge"
// BalanceTypeConsume is a BalanceType of type Consume.
BalanceTypeConsume BalanceType = "consume"
// BalanceTypeRefund is a BalanceType of type Refund.
BalanceTypeRefund BalanceType = "refund"
)
var ErrInvalidBalanceType = fmt.Errorf("not a valid BalanceType, try [%s]", strings.Join(_BalanceTypeNames, ", "))
var _BalanceTypeNames = []string{
string(BalanceTypeCharge),
string(BalanceTypeConsume),
string(BalanceTypeRefund),
}
// BalanceTypeNames returns a list of possible string values of BalanceType.
func BalanceTypeNames() []string {
tmp := make([]string, len(_BalanceTypeNames))
copy(tmp, _BalanceTypeNames)
return tmp
}
// BalanceTypeValues returns a list of the values for BalanceType
func BalanceTypeValues() []BalanceType {
return []BalanceType{
BalanceTypeCharge,
BalanceTypeConsume,
BalanceTypeRefund,
}
}
// String implements the Stringer interface.
func (x BalanceType) String() string {
return string(x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x BalanceType) IsValid() bool {
_, err := ParseBalanceType(string(x))
return err == nil
}
var _BalanceTypeValue = map[string]BalanceType{
"charge": BalanceTypeCharge,
"consume": BalanceTypeConsume,
"refund": BalanceTypeRefund,
}
// ParseBalanceType attempts to convert a string to a BalanceType.
func ParseBalanceType(name string) (BalanceType, error) {
if x, ok := _BalanceTypeValue[name]; ok {
return x, nil
}
return BalanceType(""), fmt.Errorf("%s is %w", name, ErrInvalidBalanceType)
}
var errBalanceTypeNilPtr = errors.New("value pointer is nil") // one per type for package clashes
// Scan implements the Scanner interface.
func (x *BalanceType) Scan(value interface{}) (err error) {
if value == nil {
*x = BalanceType("")
return
}
// A wider range of scannable types.
// driver.Value values at the top of the list for expediency
switch v := value.(type) {
case string:
*x, err = ParseBalanceType(v)
case []byte:
*x, err = ParseBalanceType(string(v))
case BalanceType:
*x = v
case *BalanceType:
if v == nil {
return errBalanceTypeNilPtr
}
*x = *v
case *string:
if v == nil {
return errBalanceTypeNilPtr
}
*x, err = ParseBalanceType(*v)
default:
return errors.New("invalid type for BalanceType")
}
return
}
// Value implements the driver Valuer interface.
func (x BalanceType) Value() (driver.Value, error) {
return x.String(), nil
}
// Set implements the Golang flag.Value interface func.
func (x *BalanceType) Set(val string) error {
v, err := ParseBalanceType(val)
*x = v
return err
}
// Get implements the Golang flag.Getter interface func.
func (x *BalanceType) Get() interface{} {
return *x
}
// Type implements the github.com/spf13/pFlag Value interface.
func (x *BalanceType) Type() string {
return "BalanceType"
}
type NullBalanceType struct {
BalanceType BalanceType
Valid bool
}
func NewNullBalanceType(val interface{}) (x NullBalanceType) {
err := x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
_ = err // make any errcheck linters happy
return
}
// Scan implements the Scanner interface.
func (x *NullBalanceType) Scan(value interface{}) (err error) {
if value == nil {
x.BalanceType, x.Valid = BalanceType(""), false
return
}
err = x.BalanceType.Scan(value)
x.Valid = (err == nil)
return
}
// Value implements the driver Valuer interface.
func (x NullBalanceType) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
// driver.Value accepts int64 for int values.
return string(x.BalanceType), nil
}
type NullBalanceTypeStr struct {
NullBalanceType
}
func NewNullBalanceTypeStr(val interface{}) (x NullBalanceTypeStr) {
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
return
}
// Value implements the driver Valuer interface.
func (x NullBalanceTypeStr) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
return x.BalanceType.String(), nil
}

View File

@@ -4,6 +4,8 @@ import (
"database/sql/driver"
"encoding/json"
"errors"
"github.com/samber/lo"
)
type UserOAuth struct {
@@ -16,7 +18,7 @@ type UserOAuth struct {
Unionid string `json:"unionid,omitempty"`
}
func (x UserOAuth) Scan(value interface{}) (err error) {
func (x *UserOAuth) Scan(value interface{}) (err error) {
switch v := value.(type) {
case string:
return json.Unmarshal([]byte(v), &x)
@@ -31,3 +33,36 @@ func (x UserOAuth) Scan(value interface{}) (err error) {
func (x UserOAuth) Value() (driver.Value, error) {
return json.Marshal(x)
}
type BalanceTarget struct {
ID int64 `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}
func (x BalanceTarget) MustValue() driver.Value {
return lo.Must(json.Marshal(x))
}
func (x *BalanceTarget) Scan(value interface{}) (err error) {
switch v := value.(type) {
case string:
return json.Unmarshal([]byte(v), &x)
case []byte:
return json.Unmarshal(v, &x)
case *string:
return json.Unmarshal([]byte(*v), &x)
}
return errors.New("Unknown type for ")
}
func (x BalanceTarget) Value() (driver.Value, error) {
return json.Marshal(x)
}
// swagger:enum BalanceType
// ENUM(
// Charge = "charge",
// Consume = "consume",
// Refund = "refund",
// )
type BalanceType string