update:个人中心
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
package v1
|
||||
|
||||
import "github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
type CommonReq struct {
|
||||
}
|
||||
|
||||
type CommonPostReq struct {
|
||||
g.Meta `method:"post"`
|
||||
}
|
||||
|
||||
type CommonPageReq struct {
|
||||
Page int `json:"page" d:"1"`
|
||||
Size int `json:"Size" d:"10"`
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package v1
|
||||
|
||||
import "github.com/shopspring/decimal"
|
||||
import (
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
type UserMenuRes struct {
|
||||
ID int64 `json:"id"`
|
||||
@@ -36,3 +40,17 @@ type UserProfileRes struct {
|
||||
InviteCount int `json:"invite_count"`
|
||||
InviteCashback decimal.Decimal `json:"invite_cashback"`
|
||||
}
|
||||
|
||||
type InviteCashbackRes struct {
|
||||
Total int `json:"total"`
|
||||
MonthTotal int `json:"month_total"`
|
||||
TotalCashback decimal.Decimal `json:"total_cashback"`
|
||||
}
|
||||
|
||||
type UserInviteRes struct {
|
||||
Id int64 `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
CreatedTime *ent2.CustomTime `json:"created_time"`
|
||||
Cashback decimal.Decimal `json:"cashback"`
|
||||
}
|
||||
|
||||
@@ -19,4 +19,10 @@ type IUserInfoV1 interface {
|
||||
UsedCardList(ctx context.Context, req *v1.CommonPageReq) (*utils.Response[[]*ent.SysCard], error)
|
||||
// 卡密充值
|
||||
CardRecharge(ctx context.Context, req *v1.CardRechargeReq) (*utils.Response[any], error)
|
||||
// 邀请返现信息
|
||||
InviteCashbackInfo(ctx context.Context, req *v1.CommonReq) (*utils.Response[any], error)
|
||||
// 下级用户返现列表
|
||||
InviteUserList(ctx context.Context, req *v1.CommonPageReq) (*utils.Response[[]*v1.UserInviteRes], error)
|
||||
// 生成邀请码
|
||||
GenerateInviteCode(ctx context.Context, req *v1.CommonPostReq) (*utils.Response[any], error)
|
||||
}
|
||||
|
||||
@@ -48,3 +48,15 @@ func (c *UserInfoV1) CardRecharge(ctx context.Context, req *v1.CardRechargeReq)
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.UserInfo.CardRecharge(ctx, req), nil
|
||||
}
|
||||
func (c *UserInfoV1) InviteCashbackInfo(ctx context.Context, req *v1.CommonReq) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.UserInfo.InviteCashbackInfo(ctx, req), nil
|
||||
}
|
||||
func (c *UserInfoV1) InviteUserList(ctx context.Context, req *v1.CommonPageReq) (res *utils.Response[[]*v1.UserInviteRes], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.UserInfo.InviteUserList(ctx, req), nil
|
||||
}
|
||||
func (c *UserInfoV1) GenerateInviteCode(ctx context.Context, req *v1.CommonPostReq) (res *utils.Response[any], err error) {
|
||||
defer utils.Pass(&err)
|
||||
return service.Global.UserInfo.GenerateInviteCode(ctx, req), nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package cst
|
||||
|
||||
const (
|
||||
CardStatusEnable = iota + 1
|
||||
CardStatusUsed
|
||||
CardStatusDisable
|
||||
CardStatusCashback
|
||||
)
|
||||
+34
-1
@@ -1247,9 +1247,26 @@ func (c *SysCardClient) QueryUser(_m *SysCard) *SysUserQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryCashUser queries the cash_user edge of a SysCard.
|
||||
func (c *SysCardClient) QueryCashUser(_m *SysCard) *SysUserQuery {
|
||||
query := (&SysUserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(syscard.Table, syscard.FieldID, id),
|
||||
sqlgraph.To(sysuser.Table, sysuser.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, syscard.CashUserTable, syscard.CashUserColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SysCardClient) Hooks() []Hook {
|
||||
return c.hooks.SysCard
|
||||
hooks := c.hooks.SysCard
|
||||
return append(hooks[:len(hooks):len(hooks)], syscard.Hooks[:]...)
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
@@ -1872,6 +1889,22 @@ func (c *SysUserClient) QueryUsedCards(_m *SysUser) *SysCardQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryCashbackCards queries the cashback_cards edge of a SysUser.
|
||||
func (c *SysUserClient) QueryCashbackCards(_m *SysUser) *SysCardQuery {
|
||||
query := (&SysCardClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(sysuser.Table, sysuser.FieldID, id),
|
||||
sqlgraph.To(syscard.Table, syscard.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, sysuser.CashbackCardsTable, sysuser.CashbackCardsColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SysUserClient) Hooks() []Hook {
|
||||
hooks := c.hooks.SysUser
|
||||
|
||||
@@ -153,11 +153,15 @@ var (
|
||||
// SysCardColumns holds the columns for the "sys_card" table.
|
||||
SysCardColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "create_time", Type: field.TypeString, SchemaType: map[string]string{"mysql": "datetime", "postgres": "timestamp", "sqlite3": "datetime"}},
|
||||
{Name: "update_time", Type: field.TypeString, SchemaType: map[string]string{"mysql": "datetime", "postgres": "timestamp", "sqlite3": "datetime"}},
|
||||
{Name: "content", Type: field.TypeString, Unique: true},
|
||||
{Name: "status", Type: field.TypeInt, Default: 1},
|
||||
{Name: "value", Type: field.TypeUint64},
|
||||
{Name: "cash_value", Type: field.TypeString, SchemaType: map[string]string{"mysql": "decimal(10,2)", "postgres": "numeric(10,2)"}},
|
||||
{Name: "creator_id", Type: field.TypeInt64},
|
||||
{Name: "used_id", Type: field.TypeInt64, Nullable: true},
|
||||
{Name: "cash_user_id", Type: field.TypeInt64, Nullable: true},
|
||||
}
|
||||
// SysCardTable holds the schema information for the "sys_card" table.
|
||||
SysCardTable = &schema.Table{
|
||||
@@ -167,13 +171,19 @@ var (
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "sys_card_sys_user_created_cards",
|
||||
Columns: []*schema.Column{SysCardColumns[4]},
|
||||
Columns: []*schema.Column{SysCardColumns[7]},
|
||||
RefColumns: []*schema.Column{SysUserColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
{
|
||||
Symbol: "sys_card_sys_user_used_cards",
|
||||
Columns: []*schema.Column{SysCardColumns[5]},
|
||||
Columns: []*schema.Column{SysCardColumns[8]},
|
||||
RefColumns: []*schema.Column{SysUserColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "sys_card_sys_user_cashback_cards",
|
||||
Columns: []*schema.Column{SysCardColumns[9]},
|
||||
RefColumns: []*schema.Column{SysUserColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -348,6 +358,7 @@ func init() {
|
||||
}
|
||||
SysCardTable.ForeignKeys[0].RefTable = SysUserTable
|
||||
SysCardTable.ForeignKeys[1].RefTable = SysUserTable
|
||||
SysCardTable.ForeignKeys[2].RefTable = SysUserTable
|
||||
SysCardTable.Annotation = &entsql.Annotation{
|
||||
Table: "sys_card",
|
||||
}
|
||||
|
||||
+429
-65
@@ -4564,22 +4564,27 @@ func (m *SysAgentMutation) ResetEdge(name string) error {
|
||||
// SysCardMutation represents an operation that mutates the SysCard nodes in the graph.
|
||||
type SysCardMutation struct {
|
||||
config
|
||||
op Op
|
||||
typ string
|
||||
id *int64
|
||||
content *string
|
||||
status *int
|
||||
addstatus *int
|
||||
value *uint64
|
||||
addvalue *int64
|
||||
clearedFields map[string]struct{}
|
||||
creator *int64
|
||||
clearedcreator bool
|
||||
user *int64
|
||||
cleareduser bool
|
||||
done bool
|
||||
oldValue func(context.Context) (*SysCard, error)
|
||||
predicates []predicate.SysCard
|
||||
op Op
|
||||
typ string
|
||||
id *int64
|
||||
create_time **ent2.CustomTime
|
||||
update_time **ent2.CustomTime
|
||||
content *string
|
||||
status *int
|
||||
addstatus *int
|
||||
value *uint64
|
||||
addvalue *int64
|
||||
cash_value *decimal.Decimal
|
||||
clearedFields map[string]struct{}
|
||||
creator *int64
|
||||
clearedcreator bool
|
||||
user *int64
|
||||
cleareduser bool
|
||||
cash_user *int64
|
||||
clearedcash_user bool
|
||||
done bool
|
||||
oldValue func(context.Context) (*SysCard, error)
|
||||
predicates []predicate.SysCard
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*SysCardMutation)(nil)
|
||||
@@ -4680,6 +4685,78 @@ func (m *SysCardMutation) IDs(ctx context.Context) ([]int64, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (m *SysCardMutation) SetCreateTime(et *ent2.CustomTime) {
|
||||
m.create_time = &et
|
||||
}
|
||||
|
||||
// CreateTime returns the value of the "create_time" field in the mutation.
|
||||
func (m *SysCardMutation) CreateTime() (r *ent2.CustomTime, exists bool) {
|
||||
v := m.create_time
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldCreateTime returns the old "create_time" field's value of the SysCard entity.
|
||||
// If the SysCard object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *SysCardMutation) OldCreateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldCreateTime requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
|
||||
}
|
||||
return oldValue.CreateTime, nil
|
||||
}
|
||||
|
||||
// ResetCreateTime resets all changes to the "create_time" field.
|
||||
func (m *SysCardMutation) ResetCreateTime() {
|
||||
m.create_time = nil
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (m *SysCardMutation) SetUpdateTime(et *ent2.CustomTime) {
|
||||
m.update_time = &et
|
||||
}
|
||||
|
||||
// UpdateTime returns the value of the "update_time" field in the mutation.
|
||||
func (m *SysCardMutation) UpdateTime() (r *ent2.CustomTime, exists bool) {
|
||||
v := m.update_time
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldUpdateTime returns the old "update_time" field's value of the SysCard entity.
|
||||
// If the SysCard object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *SysCardMutation) OldUpdateTime(ctx context.Context) (v *ent2.CustomTime, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldUpdateTime requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err)
|
||||
}
|
||||
return oldValue.UpdateTime, nil
|
||||
}
|
||||
|
||||
// ResetUpdateTime resets all changes to the "update_time" field.
|
||||
func (m *SysCardMutation) ResetUpdateTime() {
|
||||
m.update_time = nil
|
||||
}
|
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (m *SysCardMutation) SetContent(s string) {
|
||||
m.content = &s
|
||||
@@ -4913,6 +4990,91 @@ func (m *SysCardMutation) ResetUsedID() {
|
||||
delete(m.clearedFields, syscard.FieldUsedID)
|
||||
}
|
||||
|
||||
// SetCashUserID sets the "cash_user_id" field.
|
||||
func (m *SysCardMutation) SetCashUserID(i int64) {
|
||||
m.cash_user = &i
|
||||
}
|
||||
|
||||
// CashUserID returns the value of the "cash_user_id" field in the mutation.
|
||||
func (m *SysCardMutation) CashUserID() (r int64, exists bool) {
|
||||
v := m.cash_user
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldCashUserID returns the old "cash_user_id" field's value of the SysCard entity.
|
||||
// If the SysCard object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *SysCardMutation) OldCashUserID(ctx context.Context) (v int64, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldCashUserID is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldCashUserID requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldCashUserID: %w", err)
|
||||
}
|
||||
return oldValue.CashUserID, nil
|
||||
}
|
||||
|
||||
// ClearCashUserID clears the value of the "cash_user_id" field.
|
||||
func (m *SysCardMutation) ClearCashUserID() {
|
||||
m.cash_user = nil
|
||||
m.clearedFields[syscard.FieldCashUserID] = struct{}{}
|
||||
}
|
||||
|
||||
// CashUserIDCleared returns if the "cash_user_id" field was cleared in this mutation.
|
||||
func (m *SysCardMutation) CashUserIDCleared() bool {
|
||||
_, ok := m.clearedFields[syscard.FieldCashUserID]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetCashUserID resets all changes to the "cash_user_id" field.
|
||||
func (m *SysCardMutation) ResetCashUserID() {
|
||||
m.cash_user = nil
|
||||
delete(m.clearedFields, syscard.FieldCashUserID)
|
||||
}
|
||||
|
||||
// SetCashValue sets the "cash_value" field.
|
||||
func (m *SysCardMutation) SetCashValue(d decimal.Decimal) {
|
||||
m.cash_value = &d
|
||||
}
|
||||
|
||||
// CashValue returns the value of the "cash_value" field in the mutation.
|
||||
func (m *SysCardMutation) CashValue() (r decimal.Decimal, exists bool) {
|
||||
v := m.cash_value
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldCashValue returns the old "cash_value" field's value of the SysCard entity.
|
||||
// If the SysCard object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *SysCardMutation) OldCashValue(ctx context.Context) (v decimal.Decimal, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldCashValue is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldCashValue requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldCashValue: %w", err)
|
||||
}
|
||||
return oldValue.CashValue, nil
|
||||
}
|
||||
|
||||
// ResetCashValue resets all changes to the "cash_value" field.
|
||||
func (m *SysCardMutation) ResetCashValue() {
|
||||
m.cash_value = nil
|
||||
}
|
||||
|
||||
// ClearCreator clears the "creator" edge to the SysUser entity.
|
||||
func (m *SysCardMutation) ClearCreator() {
|
||||
m.clearedcreator = true
|
||||
@@ -4980,6 +5142,33 @@ func (m *SysCardMutation) ResetUser() {
|
||||
m.cleareduser = false
|
||||
}
|
||||
|
||||
// ClearCashUser clears the "cash_user" edge to the SysUser entity.
|
||||
func (m *SysCardMutation) ClearCashUser() {
|
||||
m.clearedcash_user = true
|
||||
m.clearedFields[syscard.FieldCashUserID] = struct{}{}
|
||||
}
|
||||
|
||||
// CashUserCleared reports if the "cash_user" edge to the SysUser entity was cleared.
|
||||
func (m *SysCardMutation) CashUserCleared() bool {
|
||||
return m.CashUserIDCleared() || m.clearedcash_user
|
||||
}
|
||||
|
||||
// CashUserIDs returns the "cash_user" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// CashUserID instead. It exists only for internal usage by the builders.
|
||||
func (m *SysCardMutation) CashUserIDs() (ids []int64) {
|
||||
if id := m.cash_user; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetCashUser resets all changes to the "cash_user" edge.
|
||||
func (m *SysCardMutation) ResetCashUser() {
|
||||
m.cash_user = nil
|
||||
m.clearedcash_user = false
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysCardMutation builder.
|
||||
func (m *SysCardMutation) Where(ps ...predicate.SysCard) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
@@ -5014,7 +5203,13 @@ func (m *SysCardMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *SysCardMutation) Fields() []string {
|
||||
fields := make([]string, 0, 5)
|
||||
fields := make([]string, 0, 9)
|
||||
if m.create_time != nil {
|
||||
fields = append(fields, syscard.FieldCreateTime)
|
||||
}
|
||||
if m.update_time != nil {
|
||||
fields = append(fields, syscard.FieldUpdateTime)
|
||||
}
|
||||
if m.content != nil {
|
||||
fields = append(fields, syscard.FieldContent)
|
||||
}
|
||||
@@ -5030,6 +5225,12 @@ func (m *SysCardMutation) Fields() []string {
|
||||
if m.user != nil {
|
||||
fields = append(fields, syscard.FieldUsedID)
|
||||
}
|
||||
if m.cash_user != nil {
|
||||
fields = append(fields, syscard.FieldCashUserID)
|
||||
}
|
||||
if m.cash_value != nil {
|
||||
fields = append(fields, syscard.FieldCashValue)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -5038,6 +5239,10 @@ func (m *SysCardMutation) Fields() []string {
|
||||
// schema.
|
||||
func (m *SysCardMutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case syscard.FieldCreateTime:
|
||||
return m.CreateTime()
|
||||
case syscard.FieldUpdateTime:
|
||||
return m.UpdateTime()
|
||||
case syscard.FieldContent:
|
||||
return m.Content()
|
||||
case syscard.FieldStatus:
|
||||
@@ -5048,6 +5253,10 @@ func (m *SysCardMutation) Field(name string) (ent.Value, bool) {
|
||||
return m.CreatorID()
|
||||
case syscard.FieldUsedID:
|
||||
return m.UsedID()
|
||||
case syscard.FieldCashUserID:
|
||||
return m.CashUserID()
|
||||
case syscard.FieldCashValue:
|
||||
return m.CashValue()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
@@ -5057,6 +5266,10 @@ func (m *SysCardMutation) Field(name string) (ent.Value, bool) {
|
||||
// database failed.
|
||||
func (m *SysCardMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
switch name {
|
||||
case syscard.FieldCreateTime:
|
||||
return m.OldCreateTime(ctx)
|
||||
case syscard.FieldUpdateTime:
|
||||
return m.OldUpdateTime(ctx)
|
||||
case syscard.FieldContent:
|
||||
return m.OldContent(ctx)
|
||||
case syscard.FieldStatus:
|
||||
@@ -5067,6 +5280,10 @@ func (m *SysCardMutation) OldField(ctx context.Context, name string) (ent.Value,
|
||||
return m.OldCreatorID(ctx)
|
||||
case syscard.FieldUsedID:
|
||||
return m.OldUsedID(ctx)
|
||||
case syscard.FieldCashUserID:
|
||||
return m.OldCashUserID(ctx)
|
||||
case syscard.FieldCashValue:
|
||||
return m.OldCashValue(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown SysCard field %s", name)
|
||||
}
|
||||
@@ -5076,6 +5293,20 @@ func (m *SysCardMutation) OldField(ctx context.Context, name string) (ent.Value,
|
||||
// type.
|
||||
func (m *SysCardMutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case syscard.FieldCreateTime:
|
||||
v, ok := value.(*ent2.CustomTime)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetCreateTime(v)
|
||||
return nil
|
||||
case syscard.FieldUpdateTime:
|
||||
v, ok := value.(*ent2.CustomTime)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUpdateTime(v)
|
||||
return nil
|
||||
case syscard.FieldContent:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
@@ -5111,6 +5342,20 @@ func (m *SysCardMutation) SetField(name string, value ent.Value) error {
|
||||
}
|
||||
m.SetUsedID(v)
|
||||
return nil
|
||||
case syscard.FieldCashUserID:
|
||||
v, ok := value.(int64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetCashUserID(v)
|
||||
return nil
|
||||
case syscard.FieldCashValue:
|
||||
v, ok := value.(decimal.Decimal)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetCashValue(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown SysCard field %s", name)
|
||||
}
|
||||
@@ -5171,6 +5416,9 @@ func (m *SysCardMutation) ClearedFields() []string {
|
||||
if m.FieldCleared(syscard.FieldUsedID) {
|
||||
fields = append(fields, syscard.FieldUsedID)
|
||||
}
|
||||
if m.FieldCleared(syscard.FieldCashUserID) {
|
||||
fields = append(fields, syscard.FieldCashUserID)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -5188,6 +5436,9 @@ func (m *SysCardMutation) ClearField(name string) error {
|
||||
case syscard.FieldUsedID:
|
||||
m.ClearUsedID()
|
||||
return nil
|
||||
case syscard.FieldCashUserID:
|
||||
m.ClearCashUserID()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown SysCard nullable field %s", name)
|
||||
}
|
||||
@@ -5196,6 +5447,12 @@ func (m *SysCardMutation) ClearField(name string) error {
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *SysCardMutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case syscard.FieldCreateTime:
|
||||
m.ResetCreateTime()
|
||||
return nil
|
||||
case syscard.FieldUpdateTime:
|
||||
m.ResetUpdateTime()
|
||||
return nil
|
||||
case syscard.FieldContent:
|
||||
m.ResetContent()
|
||||
return nil
|
||||
@@ -5211,19 +5468,28 @@ func (m *SysCardMutation) ResetField(name string) error {
|
||||
case syscard.FieldUsedID:
|
||||
m.ResetUsedID()
|
||||
return nil
|
||||
case syscard.FieldCashUserID:
|
||||
m.ResetCashUserID()
|
||||
return nil
|
||||
case syscard.FieldCashValue:
|
||||
m.ResetCashValue()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown SysCard field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *SysCardMutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 2)
|
||||
edges := make([]string, 0, 3)
|
||||
if m.creator != nil {
|
||||
edges = append(edges, syscard.EdgeCreator)
|
||||
}
|
||||
if m.user != nil {
|
||||
edges = append(edges, syscard.EdgeUser)
|
||||
}
|
||||
if m.cash_user != nil {
|
||||
edges = append(edges, syscard.EdgeCashUser)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
@@ -5239,13 +5505,17 @@ func (m *SysCardMutation) AddedIDs(name string) []ent.Value {
|
||||
if id := m.user; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
case syscard.EdgeCashUser:
|
||||
if id := m.cash_user; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *SysCardMutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 2)
|
||||
edges := make([]string, 0, 3)
|
||||
return edges
|
||||
}
|
||||
|
||||
@@ -5257,13 +5527,16 @@ func (m *SysCardMutation) RemovedIDs(name string) []ent.Value {
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *SysCardMutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 2)
|
||||
edges := make([]string, 0, 3)
|
||||
if m.clearedcreator {
|
||||
edges = append(edges, syscard.EdgeCreator)
|
||||
}
|
||||
if m.cleareduser {
|
||||
edges = append(edges, syscard.EdgeUser)
|
||||
}
|
||||
if m.clearedcash_user {
|
||||
edges = append(edges, syscard.EdgeCashUser)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
@@ -5275,6 +5548,8 @@ func (m *SysCardMutation) EdgeCleared(name string) bool {
|
||||
return m.clearedcreator
|
||||
case syscard.EdgeUser:
|
||||
return m.cleareduser
|
||||
case syscard.EdgeCashUser:
|
||||
return m.clearedcash_user
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -5289,6 +5564,9 @@ func (m *SysCardMutation) ClearEdge(name string) error {
|
||||
case syscard.EdgeUser:
|
||||
m.ClearUser()
|
||||
return nil
|
||||
case syscard.EdgeCashUser:
|
||||
m.ClearCashUser()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown SysCard unique edge %s", name)
|
||||
}
|
||||
@@ -5303,6 +5581,9 @@ func (m *SysCardMutation) ResetEdge(name string) error {
|
||||
case syscard.EdgeUser:
|
||||
m.ResetUser()
|
||||
return nil
|
||||
case syscard.EdgeCashUser:
|
||||
m.ResetCashUser()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown SysCard edge %s", name)
|
||||
}
|
||||
@@ -7388,48 +7669,51 @@ func (m *SysRoleMutation) ResetEdge(name string) error {
|
||||
// SysUserMutation represents an operation that mutates the SysUser nodes in the graph.
|
||||
type SysUserMutation struct {
|
||||
config
|
||||
op Op
|
||||
typ string
|
||||
id *int64
|
||||
create_time **ent2.CustomTime
|
||||
update_time **ent2.CustomTime
|
||||
username *string
|
||||
password *string
|
||||
email *string
|
||||
invite_code *string
|
||||
balance *decimal.Decimal
|
||||
block *bool
|
||||
verify *bool
|
||||
invite_cashback *decimal.Decimal
|
||||
clearedFields map[string]struct{}
|
||||
parent *int64
|
||||
clearedparent bool
|
||||
children map[int64]struct{}
|
||||
removedchildren map[int64]struct{}
|
||||
clearedchildren bool
|
||||
roles map[int64]struct{}
|
||||
removedroles map[int64]struct{}
|
||||
clearedroles bool
|
||||
agent *int64
|
||||
clearedagent bool
|
||||
images map[int64]struct{}
|
||||
removedimages map[int64]struct{}
|
||||
clearedimages bool
|
||||
cpuser map[int64]struct{}
|
||||
removedcpuser map[int64]struct{}
|
||||
clearedcpuser bool
|
||||
cp_task_logs map[int64]struct{}
|
||||
removedcp_task_logs map[int64]struct{}
|
||||
clearedcp_task_logs bool
|
||||
created_cards map[int64]struct{}
|
||||
removedcreated_cards map[int64]struct{}
|
||||
clearedcreated_cards bool
|
||||
used_cards map[int64]struct{}
|
||||
removedused_cards map[int64]struct{}
|
||||
clearedused_cards bool
|
||||
done bool
|
||||
oldValue func(context.Context) (*SysUser, error)
|
||||
predicates []predicate.SysUser
|
||||
op Op
|
||||
typ string
|
||||
id *int64
|
||||
create_time **ent2.CustomTime
|
||||
update_time **ent2.CustomTime
|
||||
username *string
|
||||
password *string
|
||||
email *string
|
||||
invite_code *string
|
||||
balance *decimal.Decimal
|
||||
block *bool
|
||||
verify *bool
|
||||
invite_cashback *decimal.Decimal
|
||||
clearedFields map[string]struct{}
|
||||
parent *int64
|
||||
clearedparent bool
|
||||
children map[int64]struct{}
|
||||
removedchildren map[int64]struct{}
|
||||
clearedchildren bool
|
||||
roles map[int64]struct{}
|
||||
removedroles map[int64]struct{}
|
||||
clearedroles bool
|
||||
agent *int64
|
||||
clearedagent bool
|
||||
images map[int64]struct{}
|
||||
removedimages map[int64]struct{}
|
||||
clearedimages bool
|
||||
cpuser map[int64]struct{}
|
||||
removedcpuser map[int64]struct{}
|
||||
clearedcpuser bool
|
||||
cp_task_logs map[int64]struct{}
|
||||
removedcp_task_logs map[int64]struct{}
|
||||
clearedcp_task_logs bool
|
||||
created_cards map[int64]struct{}
|
||||
removedcreated_cards map[int64]struct{}
|
||||
clearedcreated_cards bool
|
||||
used_cards map[int64]struct{}
|
||||
removedused_cards map[int64]struct{}
|
||||
clearedused_cards bool
|
||||
cashback_cards map[int64]struct{}
|
||||
removedcashback_cards map[int64]struct{}
|
||||
clearedcashback_cards bool
|
||||
done bool
|
||||
oldValue func(context.Context) (*SysUser, error)
|
||||
predicates []predicate.SysUser
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*SysUserMutation)(nil)
|
||||
@@ -8359,6 +8643,60 @@ func (m *SysUserMutation) ResetUsedCards() {
|
||||
m.removedused_cards = nil
|
||||
}
|
||||
|
||||
// AddCashbackCardIDs adds the "cashback_cards" edge to the SysCard entity by ids.
|
||||
func (m *SysUserMutation) AddCashbackCardIDs(ids ...int64) {
|
||||
if m.cashback_cards == nil {
|
||||
m.cashback_cards = make(map[int64]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
m.cashback_cards[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// ClearCashbackCards clears the "cashback_cards" edge to the SysCard entity.
|
||||
func (m *SysUserMutation) ClearCashbackCards() {
|
||||
m.clearedcashback_cards = true
|
||||
}
|
||||
|
||||
// CashbackCardsCleared reports if the "cashback_cards" edge to the SysCard entity was cleared.
|
||||
func (m *SysUserMutation) CashbackCardsCleared() bool {
|
||||
return m.clearedcashback_cards
|
||||
}
|
||||
|
||||
// RemoveCashbackCardIDs removes the "cashback_cards" edge to the SysCard entity by IDs.
|
||||
func (m *SysUserMutation) RemoveCashbackCardIDs(ids ...int64) {
|
||||
if m.removedcashback_cards == nil {
|
||||
m.removedcashback_cards = make(map[int64]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
delete(m.cashback_cards, ids[i])
|
||||
m.removedcashback_cards[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// RemovedCashbackCards returns the removed IDs of the "cashback_cards" edge to the SysCard entity.
|
||||
func (m *SysUserMutation) RemovedCashbackCardsIDs() (ids []int64) {
|
||||
for id := range m.removedcashback_cards {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// CashbackCardsIDs returns the "cashback_cards" edge IDs in the mutation.
|
||||
func (m *SysUserMutation) CashbackCardsIDs() (ids []int64) {
|
||||
for id := range m.cashback_cards {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetCashbackCards resets all changes to the "cashback_cards" edge.
|
||||
func (m *SysUserMutation) ResetCashbackCards() {
|
||||
m.cashback_cards = nil
|
||||
m.clearedcashback_cards = false
|
||||
m.removedcashback_cards = nil
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysUserMutation builder.
|
||||
func (m *SysUserMutation) Where(ps ...predicate.SysUser) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
@@ -8654,7 +8992,7 @@ func (m *SysUserMutation) ResetField(name string) error {
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *SysUserMutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 9)
|
||||
edges := make([]string, 0, 10)
|
||||
if m.parent != nil {
|
||||
edges = append(edges, sysuser.EdgeParent)
|
||||
}
|
||||
@@ -8682,6 +9020,9 @@ func (m *SysUserMutation) AddedEdges() []string {
|
||||
if m.used_cards != nil {
|
||||
edges = append(edges, sysuser.EdgeUsedCards)
|
||||
}
|
||||
if m.cashback_cards != nil {
|
||||
edges = append(edges, sysuser.EdgeCashbackCards)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
@@ -8739,13 +9080,19 @@ func (m *SysUserMutation) AddedIDs(name string) []ent.Value {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
case sysuser.EdgeCashbackCards:
|
||||
ids := make([]ent.Value, 0, len(m.cashback_cards))
|
||||
for id := range m.cashback_cards {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *SysUserMutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 9)
|
||||
edges := make([]string, 0, 10)
|
||||
if m.removedchildren != nil {
|
||||
edges = append(edges, sysuser.EdgeChildren)
|
||||
}
|
||||
@@ -8767,6 +9114,9 @@ func (m *SysUserMutation) RemovedEdges() []string {
|
||||
if m.removedused_cards != nil {
|
||||
edges = append(edges, sysuser.EdgeUsedCards)
|
||||
}
|
||||
if m.removedcashback_cards != nil {
|
||||
edges = append(edges, sysuser.EdgeCashbackCards)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
@@ -8816,13 +9166,19 @@ func (m *SysUserMutation) RemovedIDs(name string) []ent.Value {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
case sysuser.EdgeCashbackCards:
|
||||
ids := make([]ent.Value, 0, len(m.removedcashback_cards))
|
||||
for id := range m.removedcashback_cards {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *SysUserMutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 9)
|
||||
edges := make([]string, 0, 10)
|
||||
if m.clearedparent {
|
||||
edges = append(edges, sysuser.EdgeParent)
|
||||
}
|
||||
@@ -8850,6 +9206,9 @@ func (m *SysUserMutation) ClearedEdges() []string {
|
||||
if m.clearedused_cards {
|
||||
edges = append(edges, sysuser.EdgeUsedCards)
|
||||
}
|
||||
if m.clearedcashback_cards {
|
||||
edges = append(edges, sysuser.EdgeCashbackCards)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
@@ -8875,6 +9234,8 @@ func (m *SysUserMutation) EdgeCleared(name string) bool {
|
||||
return m.clearedcreated_cards
|
||||
case sysuser.EdgeUsedCards:
|
||||
return m.clearedused_cards
|
||||
case sysuser.EdgeCashbackCards:
|
||||
return m.clearedcashback_cards
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -8924,6 +9285,9 @@ func (m *SysUserMutation) ResetEdge(name string) error {
|
||||
case sysuser.EdgeUsedCards:
|
||||
m.ResetUsedCards()
|
||||
return nil
|
||||
case sysuser.EdgeCashbackCards:
|
||||
m.ResetCashbackCards()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown SysUser edge %s", name)
|
||||
}
|
||||
|
||||
@@ -91,12 +91,29 @@ func init() {
|
||||
sysagentDescUpdateTime := sysagentMixinFields0[1].Descriptor()
|
||||
// sysagent.DefaultUpdateTime holds the default value on creation for the update_time field.
|
||||
sysagent.DefaultUpdateTime = sysagentDescUpdateTime.Default.(func() *ent2.CustomTime)
|
||||
syscardMixin := schema.SysCard{}.Mixin()
|
||||
syscardMixinHooks0 := syscardMixin[0].Hooks()
|
||||
syscard.Hooks[0] = syscardMixinHooks0[0]
|
||||
syscardMixinFields0 := syscardMixin[0].Fields()
|
||||
_ = syscardMixinFields0
|
||||
syscardFields := schema.SysCard{}.Fields()
|
||||
_ = syscardFields
|
||||
// syscardDescCreateTime is the schema descriptor for create_time field.
|
||||
syscardDescCreateTime := syscardMixinFields0[0].Descriptor()
|
||||
// syscard.DefaultCreateTime holds the default value on creation for the create_time field.
|
||||
syscard.DefaultCreateTime = syscardDescCreateTime.Default.(func() *ent2.CustomTime)
|
||||
// syscardDescUpdateTime is the schema descriptor for update_time field.
|
||||
syscardDescUpdateTime := syscardMixinFields0[1].Descriptor()
|
||||
// syscard.DefaultUpdateTime holds the default value on creation for the update_time field.
|
||||
syscard.DefaultUpdateTime = syscardDescUpdateTime.Default.(func() *ent2.CustomTime)
|
||||
// syscardDescStatus is the schema descriptor for status field.
|
||||
syscardDescStatus := syscardFields[1].Descriptor()
|
||||
// syscard.DefaultStatus holds the default value on creation for the status field.
|
||||
syscard.DefaultStatus = syscardDescStatus.Default.(int)
|
||||
// syscardDescCashValue is the schema descriptor for cash_value field.
|
||||
syscardDescCashValue := syscardFields[6].Descriptor()
|
||||
// syscard.DefaultCashValue holds the default value on creation for the cash_value field.
|
||||
syscard.DefaultCashValue = syscardDescCashValue.Default.(func() decimal.Decimal)
|
||||
sysmenuMixin := schema.SysMenu{}.Mixin()
|
||||
sysmenuMixinHooks0 := sysmenuMixin[0].Hooks()
|
||||
sysmenu.Hooks[0] = sysmenuMixinHooks0[0]
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/ent/schema/mix"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// SysCard holds the schema definition for the SysCard entity.
|
||||
@@ -15,11 +20,16 @@ type SysCard struct {
|
||||
|
||||
func (SysCard) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("content").Unique(), // 充值卡密
|
||||
field.Int("status").Default(1), //1:未使用 2:使用 3:禁用
|
||||
field.Uint64("value"), // 充值金额
|
||||
field.Int64("creator_id"),
|
||||
field.Int64("used_id").Optional(),
|
||||
field.String("content").Unique(), // 充值卡密
|
||||
field.Int("status").Default(1), //1:未使用 2:使用 3:禁用
|
||||
field.Uint64("value"), // 充值金额
|
||||
field.Int64("creator_id"), //创建者
|
||||
field.Int64("used_id").Optional(), //使用者
|
||||
field.Int64("cash_user_id").Optional(), //返现者
|
||||
field.String("cash_value").GoType(decimal.Decimal{}).SchemaType(map[string]string{
|
||||
dialect.MySQL: "decimal(10,2)",
|
||||
dialect.Postgres: "numeric(10,2)",
|
||||
}).DefaultFunc(ent2.DecimalDefaultFunc), // 返现金额
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +37,7 @@ func (SysCard) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("creator", SysUser.Type).Ref("created_cards").Field("creator_id").Unique().Required(), // 创建人
|
||||
edge.From("user", SysUser.Type).Ref("used_cards").Field("used_id").Unique(), // 使用人
|
||||
edge.From("cash_user", SysUser.Type).Ref("cashback_cards").Field("cash_user_id").Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,3 +46,8 @@ func (SysCard) Annotations() []schema.Annotation {
|
||||
entsql.Annotation{Table: "sys_card"},
|
||||
}
|
||||
}
|
||||
func (SysCard) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mix.MixinTime{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ func (SysUser) Edges() []ent.Edge {
|
||||
edge.To("cp_task_logs", CpTaskLog.Type), // 用户拥有的cp任务日志
|
||||
edge.To("created_cards", SysCard.Type), // 用户创建的卡
|
||||
edge.To("used_cards", SysCard.Type), // 用户使用的卡
|
||||
edge.To("cashback_cards", SysCard.Type),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+70
-2
@@ -6,10 +6,12 @@ import (
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// SysCard is the model entity for the SysCard schema.
|
||||
@@ -17,6 +19,10 @@ type SysCard struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int64 `json:"id,omitempty"`
|
||||
// CreateTime holds the value of the "create_time" field.
|
||||
CreateTime *ent2.CustomTime `json:"createTime"`
|
||||
// UpdateTime holds the value of the "update_time" field.
|
||||
UpdateTime *ent2.CustomTime `json:"updateTime"`
|
||||
// Content holds the value of the "content" field.
|
||||
Content string `json:"content,omitempty"`
|
||||
// Status holds the value of the "status" field.
|
||||
@@ -27,6 +33,10 @@ type SysCard struct {
|
||||
CreatorID int64 `json:"creator_id,omitempty"`
|
||||
// UsedID holds the value of the "used_id" field.
|
||||
UsedID int64 `json:"used_id,omitempty"`
|
||||
// CashUserID holds the value of the "cash_user_id" field.
|
||||
CashUserID int64 `json:"cash_user_id,omitempty"`
|
||||
// CashValue holds the value of the "cash_value" field.
|
||||
CashValue decimal.Decimal `json:"cash_value,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the SysCardQuery when eager-loading is set.
|
||||
Edges SysCardEdges `json:"edges"`
|
||||
@@ -39,9 +49,11 @@ type SysCardEdges struct {
|
||||
Creator *SysUser `json:"creator,omitempty"`
|
||||
// User holds the value of the user edge.
|
||||
User *SysUser `json:"user,omitempty"`
|
||||
// CashUser holds the value of the cash_user edge.
|
||||
CashUser *SysUser `json:"cash_user,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [2]bool
|
||||
loadedTypes [3]bool
|
||||
}
|
||||
|
||||
// CreatorOrErr returns the Creator value or an error if the edge
|
||||
@@ -66,12 +78,27 @@ func (e SysCardEdges) UserOrErr() (*SysUser, error) {
|
||||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// CashUserOrErr returns the CashUser value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e SysCardEdges) CashUserOrErr() (*SysUser, error) {
|
||||
if e.CashUser != nil {
|
||||
return e.CashUser, nil
|
||||
} else if e.loadedTypes[2] {
|
||||
return nil, &NotFoundError{label: sysuser.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "cash_user"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*SysCard) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case syscard.FieldID, syscard.FieldStatus, syscard.FieldValue, syscard.FieldCreatorID, syscard.FieldUsedID:
|
||||
case syscard.FieldCashValue:
|
||||
values[i] = new(decimal.Decimal)
|
||||
case syscard.FieldCreateTime, syscard.FieldUpdateTime:
|
||||
values[i] = new(ent2.CustomTime)
|
||||
case syscard.FieldID, syscard.FieldStatus, syscard.FieldValue, syscard.FieldCreatorID, syscard.FieldUsedID, syscard.FieldCashUserID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case syscard.FieldContent:
|
||||
values[i] = new(sql.NullString)
|
||||
@@ -96,6 +123,18 @@ func (_m *SysCard) assignValues(columns []string, values []any) error {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int64(value.Int64)
|
||||
case syscard.FieldCreateTime:
|
||||
if value, ok := values[i].(*ent2.CustomTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field create_time", values[i])
|
||||
} else if value != nil {
|
||||
_m.CreateTime = value
|
||||
}
|
||||
case syscard.FieldUpdateTime:
|
||||
if value, ok := values[i].(*ent2.CustomTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field update_time", values[i])
|
||||
} else if value != nil {
|
||||
_m.UpdateTime = value
|
||||
}
|
||||
case syscard.FieldContent:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field content", values[i])
|
||||
@@ -126,6 +165,18 @@ func (_m *SysCard) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
_m.UsedID = value.Int64
|
||||
}
|
||||
case syscard.FieldCashUserID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field cash_user_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.CashUserID = value.Int64
|
||||
}
|
||||
case syscard.FieldCashValue:
|
||||
if value, ok := values[i].(*decimal.Decimal); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field cash_value", values[i])
|
||||
} else if value != nil {
|
||||
_m.CashValue = *value
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
@@ -149,6 +200,11 @@ func (_m *SysCard) QueryUser() *SysUserQuery {
|
||||
return NewSysCardClient(_m.config).QueryUser(_m)
|
||||
}
|
||||
|
||||
// QueryCashUser queries the "cash_user" edge of the SysCard entity.
|
||||
func (_m *SysCard) QueryCashUser() *SysUserQuery {
|
||||
return NewSysCardClient(_m.config).QueryCashUser(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this SysCard.
|
||||
// Note that you need to call SysCard.Unwrap() before calling this method if this SysCard
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
@@ -172,6 +228,12 @@ func (_m *SysCard) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("SysCard(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("create_time=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.CreateTime))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("update_time=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.UpdateTime))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("content=")
|
||||
builder.WriteString(_m.Content)
|
||||
builder.WriteString(", ")
|
||||
@@ -186,6 +248,12 @@ func (_m *SysCard) String() string {
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("used_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.UsedID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("cash_user_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.CashUserID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("cash_value=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.CashValue))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -3,8 +3,12 @@
|
||||
package syscard
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -12,6 +16,10 @@ const (
|
||||
Label = "sys_card"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCreateTime holds the string denoting the create_time field in the database.
|
||||
FieldCreateTime = "create_time"
|
||||
// FieldUpdateTime holds the string denoting the update_time field in the database.
|
||||
FieldUpdateTime = "update_time"
|
||||
// FieldContent holds the string denoting the content field in the database.
|
||||
FieldContent = "content"
|
||||
// FieldStatus holds the string denoting the status field in the database.
|
||||
@@ -22,10 +30,16 @@ const (
|
||||
FieldCreatorID = "creator_id"
|
||||
// FieldUsedID holds the string denoting the used_id field in the database.
|
||||
FieldUsedID = "used_id"
|
||||
// FieldCashUserID holds the string denoting the cash_user_id field in the database.
|
||||
FieldCashUserID = "cash_user_id"
|
||||
// FieldCashValue holds the string denoting the cash_value field in the database.
|
||||
FieldCashValue = "cash_value"
|
||||
// EdgeCreator holds the string denoting the creator edge name in mutations.
|
||||
EdgeCreator = "creator"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// EdgeCashUser holds the string denoting the cash_user edge name in mutations.
|
||||
EdgeCashUser = "cash_user"
|
||||
// Table holds the table name of the syscard in the database.
|
||||
Table = "sys_card"
|
||||
// CreatorTable is the table that holds the creator relation/edge.
|
||||
@@ -42,16 +56,27 @@ const (
|
||||
UserInverseTable = "sys_user"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "used_id"
|
||||
// CashUserTable is the table that holds the cash_user relation/edge.
|
||||
CashUserTable = "sys_card"
|
||||
// CashUserInverseTable is the table name for the SysUser entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "sysuser" package.
|
||||
CashUserInverseTable = "sys_user"
|
||||
// CashUserColumn is the table column denoting the cash_user relation/edge.
|
||||
CashUserColumn = "cash_user_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for syscard fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreateTime,
|
||||
FieldUpdateTime,
|
||||
FieldContent,
|
||||
FieldStatus,
|
||||
FieldValue,
|
||||
FieldCreatorID,
|
||||
FieldUsedID,
|
||||
FieldCashUserID,
|
||||
FieldCashValue,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@@ -64,9 +89,21 @@ func ValidColumn(column string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Note that the variables below are initialized by the runtime
|
||||
// package on the initialization of the application. Therefore,
|
||||
// it should be imported in the main as follows:
|
||||
//
|
||||
// import _ "likedream-goframe/internal/ent/runtime"
|
||||
var (
|
||||
Hooks [1]ent.Hook
|
||||
// DefaultCreateTime holds the default value on creation for the "create_time" field.
|
||||
DefaultCreateTime func() *ent2.CustomTime
|
||||
// DefaultUpdateTime holds the default value on creation for the "update_time" field.
|
||||
DefaultUpdateTime func() *ent2.CustomTime
|
||||
// DefaultStatus holds the default value on creation for the "status" field.
|
||||
DefaultStatus int
|
||||
// DefaultCashValue holds the default value on creation for the "cash_value" field.
|
||||
DefaultCashValue func() decimal.Decimal
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the SysCard queries.
|
||||
@@ -77,6 +114,16 @@ func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreateTime orders the results by the create_time field.
|
||||
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdateTime orders the results by the update_time field.
|
||||
func ByUpdateTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdateTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByContent orders the results by the content field.
|
||||
func ByContent(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldContent, opts...).ToFunc()
|
||||
@@ -102,6 +149,16 @@ func ByUsedID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUsedID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCashUserID orders the results by the cash_user_id field.
|
||||
func ByCashUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCashUserID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCashValue orders the results by the cash_value field.
|
||||
func ByCashValue(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCashValue, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatorField orders the results by creator field.
|
||||
func ByCreatorField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
@@ -115,6 +172,13 @@ func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByCashUserField orders the results by cash_user field.
|
||||
func ByCashUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newCashUserStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newCreatorStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
@@ -129,3 +193,10 @@ func newUserStep() *sqlgraph.Step {
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
}
|
||||
func newCashUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(CashUserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, CashUserTable, CashUserColumn),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ package syscard
|
||||
|
||||
import (
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
@@ -54,6 +56,16 @@ func IDLTE(id int64) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ.
|
||||
func CreateTime(v *ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTime applies equality check predicate on the "update_time" field. It's identical to UpdateTimeEQ.
|
||||
func UpdateTime(v *ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// Content applies equality check predicate on the "content" field. It's identical to ContentEQ.
|
||||
func Content(v string) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldEQ(FieldContent, v))
|
||||
@@ -79,6 +91,156 @@ func UsedID(v int64) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldEQ(FieldUsedID, v))
|
||||
}
|
||||
|
||||
// CashUserID applies equality check predicate on the "cash_user_id" field. It's identical to CashUserIDEQ.
|
||||
func CashUserID(v int64) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldEQ(FieldCashUserID, v))
|
||||
}
|
||||
|
||||
// CashValue applies equality check predicate on the "cash_value" field. It's identical to CashValueEQ.
|
||||
func CashValue(v decimal.Decimal) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldEQ(FieldCashValue, v))
|
||||
}
|
||||
|
||||
// CreateTimeEQ applies the EQ predicate on the "create_time" field.
|
||||
func CreateTimeEQ(v *ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeNEQ applies the NEQ predicate on the "create_time" field.
|
||||
func CreateTimeNEQ(v *ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldNEQ(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeIn applies the In predicate on the "create_time" field.
|
||||
func CreateTimeIn(vs ...*ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeNotIn applies the NotIn predicate on the "create_time" field.
|
||||
func CreateTimeNotIn(vs ...*ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldNotIn(FieldCreateTime, vs...))
|
||||
}
|
||||
|
||||
// CreateTimeGT applies the GT predicate on the "create_time" field.
|
||||
func CreateTimeGT(v *ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldGT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeGTE applies the GTE predicate on the "create_time" field.
|
||||
func CreateTimeGTE(v *ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldGTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLT applies the LT predicate on the "create_time" field.
|
||||
func CreateTimeLT(v *ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldLT(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeLTE applies the LTE predicate on the "create_time" field.
|
||||
func CreateTimeLTE(v *ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldLTE(FieldCreateTime, v))
|
||||
}
|
||||
|
||||
// CreateTimeContains applies the Contains predicate on the "create_time" field.
|
||||
func CreateTimeContains(v *ent2.CustomTime) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldContains(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeHasPrefix applies the HasPrefix predicate on the "create_time" field.
|
||||
func CreateTimeHasPrefix(v *ent2.CustomTime) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldHasPrefix(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeHasSuffix applies the HasSuffix predicate on the "create_time" field.
|
||||
func CreateTimeHasSuffix(v *ent2.CustomTime) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldHasSuffix(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeEqualFold applies the EqualFold predicate on the "create_time" field.
|
||||
func CreateTimeEqualFold(v *ent2.CustomTime) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldEqualFold(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// CreateTimeContainsFold applies the ContainsFold predicate on the "create_time" field.
|
||||
func CreateTimeContainsFold(v *ent2.CustomTime) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldContainsFold(FieldCreateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeEQ applies the EQ predicate on the "update_time" field.
|
||||
func UpdateTimeEQ(v *ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field.
|
||||
func UpdateTimeNEQ(v *ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldNEQ(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeIn applies the In predicate on the "update_time" field.
|
||||
func UpdateTimeIn(vs ...*ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldIn(FieldUpdateTime, vs...))
|
||||
}
|
||||
|
||||
// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field.
|
||||
func UpdateTimeNotIn(vs ...*ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldNotIn(FieldUpdateTime, vs...))
|
||||
}
|
||||
|
||||
// UpdateTimeGT applies the GT predicate on the "update_time" field.
|
||||
func UpdateTimeGT(v *ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldGT(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeGTE applies the GTE predicate on the "update_time" field.
|
||||
func UpdateTimeGTE(v *ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldGTE(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeLT applies the LT predicate on the "update_time" field.
|
||||
func UpdateTimeLT(v *ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldLT(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeLTE applies the LTE predicate on the "update_time" field.
|
||||
func UpdateTimeLTE(v *ent2.CustomTime) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldLTE(FieldUpdateTime, v))
|
||||
}
|
||||
|
||||
// UpdateTimeContains applies the Contains predicate on the "update_time" field.
|
||||
func UpdateTimeContains(v *ent2.CustomTime) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldContains(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeHasPrefix applies the HasPrefix predicate on the "update_time" field.
|
||||
func UpdateTimeHasPrefix(v *ent2.CustomTime) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldHasPrefix(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeHasSuffix applies the HasSuffix predicate on the "update_time" field.
|
||||
func UpdateTimeHasSuffix(v *ent2.CustomTime) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldHasSuffix(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeEqualFold applies the EqualFold predicate on the "update_time" field.
|
||||
func UpdateTimeEqualFold(v *ent2.CustomTime) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldEqualFold(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// UpdateTimeContainsFold applies the ContainsFold predicate on the "update_time" field.
|
||||
func UpdateTimeContainsFold(v *ent2.CustomTime) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldContainsFold(FieldUpdateTime, vc))
|
||||
}
|
||||
|
||||
// ContentEQ applies the EQ predicate on the "content" field.
|
||||
func ContentEQ(v string) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldEQ(FieldContent, v))
|
||||
@@ -274,6 +436,106 @@ func UsedIDNotNil() predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldNotNull(FieldUsedID))
|
||||
}
|
||||
|
||||
// CashUserIDEQ applies the EQ predicate on the "cash_user_id" field.
|
||||
func CashUserIDEQ(v int64) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldEQ(FieldCashUserID, v))
|
||||
}
|
||||
|
||||
// CashUserIDNEQ applies the NEQ predicate on the "cash_user_id" field.
|
||||
func CashUserIDNEQ(v int64) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldNEQ(FieldCashUserID, v))
|
||||
}
|
||||
|
||||
// CashUserIDIn applies the In predicate on the "cash_user_id" field.
|
||||
func CashUserIDIn(vs ...int64) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldIn(FieldCashUserID, vs...))
|
||||
}
|
||||
|
||||
// CashUserIDNotIn applies the NotIn predicate on the "cash_user_id" field.
|
||||
func CashUserIDNotIn(vs ...int64) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldNotIn(FieldCashUserID, vs...))
|
||||
}
|
||||
|
||||
// CashUserIDIsNil applies the IsNil predicate on the "cash_user_id" field.
|
||||
func CashUserIDIsNil() predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldIsNull(FieldCashUserID))
|
||||
}
|
||||
|
||||
// CashUserIDNotNil applies the NotNil predicate on the "cash_user_id" field.
|
||||
func CashUserIDNotNil() predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldNotNull(FieldCashUserID))
|
||||
}
|
||||
|
||||
// CashValueEQ applies the EQ predicate on the "cash_value" field.
|
||||
func CashValueEQ(v decimal.Decimal) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldEQ(FieldCashValue, v))
|
||||
}
|
||||
|
||||
// CashValueNEQ applies the NEQ predicate on the "cash_value" field.
|
||||
func CashValueNEQ(v decimal.Decimal) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldNEQ(FieldCashValue, v))
|
||||
}
|
||||
|
||||
// CashValueIn applies the In predicate on the "cash_value" field.
|
||||
func CashValueIn(vs ...decimal.Decimal) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldIn(FieldCashValue, vs...))
|
||||
}
|
||||
|
||||
// CashValueNotIn applies the NotIn predicate on the "cash_value" field.
|
||||
func CashValueNotIn(vs ...decimal.Decimal) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldNotIn(FieldCashValue, vs...))
|
||||
}
|
||||
|
||||
// CashValueGT applies the GT predicate on the "cash_value" field.
|
||||
func CashValueGT(v decimal.Decimal) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldGT(FieldCashValue, v))
|
||||
}
|
||||
|
||||
// CashValueGTE applies the GTE predicate on the "cash_value" field.
|
||||
func CashValueGTE(v decimal.Decimal) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldGTE(FieldCashValue, v))
|
||||
}
|
||||
|
||||
// CashValueLT applies the LT predicate on the "cash_value" field.
|
||||
func CashValueLT(v decimal.Decimal) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldLT(FieldCashValue, v))
|
||||
}
|
||||
|
||||
// CashValueLTE applies the LTE predicate on the "cash_value" field.
|
||||
func CashValueLTE(v decimal.Decimal) predicate.SysCard {
|
||||
return predicate.SysCard(sql.FieldLTE(FieldCashValue, v))
|
||||
}
|
||||
|
||||
// CashValueContains applies the Contains predicate on the "cash_value" field.
|
||||
func CashValueContains(v decimal.Decimal) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldContains(FieldCashValue, vc))
|
||||
}
|
||||
|
||||
// CashValueHasPrefix applies the HasPrefix predicate on the "cash_value" field.
|
||||
func CashValueHasPrefix(v decimal.Decimal) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldHasPrefix(FieldCashValue, vc))
|
||||
}
|
||||
|
||||
// CashValueHasSuffix applies the HasSuffix predicate on the "cash_value" field.
|
||||
func CashValueHasSuffix(v decimal.Decimal) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldHasSuffix(FieldCashValue, vc))
|
||||
}
|
||||
|
||||
// CashValueEqualFold applies the EqualFold predicate on the "cash_value" field.
|
||||
func CashValueEqualFold(v decimal.Decimal) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldEqualFold(FieldCashValue, vc))
|
||||
}
|
||||
|
||||
// CashValueContainsFold applies the ContainsFold predicate on the "cash_value" field.
|
||||
func CashValueContainsFold(v decimal.Decimal) predicate.SysCard {
|
||||
vc := v.String()
|
||||
return predicate.SysCard(sql.FieldContainsFold(FieldCashValue, vc))
|
||||
}
|
||||
|
||||
// HasCreator applies the HasEdge predicate on the "creator" edge.
|
||||
func HasCreator() predicate.SysCard {
|
||||
return predicate.SysCard(func(s *sql.Selector) {
|
||||
@@ -320,6 +582,29 @@ func HasUserWith(preds ...predicate.SysUser) predicate.SysCard {
|
||||
})
|
||||
}
|
||||
|
||||
// HasCashUser applies the HasEdge predicate on the "cash_user" edge.
|
||||
func HasCashUser() predicate.SysCard {
|
||||
return predicate.SysCard(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, CashUserTable, CashUserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasCashUserWith applies the HasEdge predicate on the "cash_user" edge with a given conditions (other predicates).
|
||||
func HasCashUserWith(preds ...predicate.SysUser) predicate.SysCard {
|
||||
return predicate.SysCard(func(s *sql.Selector) {
|
||||
step := newCashUserStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.SysCard) predicate.SysCard {
|
||||
return predicate.SysCard(sql.AndPredicates(predicates...))
|
||||
|
||||
@@ -8,10 +8,12 @@ import (
|
||||
"fmt"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// SysCardCreate is the builder for creating a SysCard entity.
|
||||
@@ -22,6 +24,18 @@ type SysCardCreate struct {
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// SetCreateTime sets the "create_time" field.
|
||||
func (_c *SysCardCreate) SetCreateTime(v *ent2.CustomTime) *SysCardCreate {
|
||||
_c.mutation.SetCreateTime(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_c *SysCardCreate) SetUpdateTime(v *ent2.CustomTime) *SysCardCreate {
|
||||
_c.mutation.SetUpdateTime(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (_c *SysCardCreate) SetContent(v string) *SysCardCreate {
|
||||
_c.mutation.SetContent(v)
|
||||
@@ -68,6 +82,34 @@ func (_c *SysCardCreate) SetNillableUsedID(v *int64) *SysCardCreate {
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCashUserID sets the "cash_user_id" field.
|
||||
func (_c *SysCardCreate) SetCashUserID(v int64) *SysCardCreate {
|
||||
_c.mutation.SetCashUserID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCashUserID sets the "cash_user_id" field if the given value is not nil.
|
||||
func (_c *SysCardCreate) SetNillableCashUserID(v *int64) *SysCardCreate {
|
||||
if v != nil {
|
||||
_c.SetCashUserID(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCashValue sets the "cash_value" field.
|
||||
func (_c *SysCardCreate) SetCashValue(v decimal.Decimal) *SysCardCreate {
|
||||
_c.mutation.SetCashValue(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCashValue sets the "cash_value" field if the given value is not nil.
|
||||
func (_c *SysCardCreate) SetNillableCashValue(v *decimal.Decimal) *SysCardCreate {
|
||||
if v != nil {
|
||||
_c.SetCashValue(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCreator sets the "creator" edge to the SysUser entity.
|
||||
func (_c *SysCardCreate) SetCreator(v *SysUser) *SysCardCreate {
|
||||
return _c.SetCreatorID(v.ID)
|
||||
@@ -92,6 +134,11 @@ func (_c *SysCardCreate) SetUser(v *SysUser) *SysCardCreate {
|
||||
return _c.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// SetCashUser sets the "cash_user" edge to the SysUser entity.
|
||||
func (_c *SysCardCreate) SetCashUser(v *SysUser) *SysCardCreate {
|
||||
return _c.SetCashUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the SysCardMutation object of the builder.
|
||||
func (_c *SysCardCreate) Mutation() *SysCardMutation {
|
||||
return _c.mutation
|
||||
@@ -99,7 +146,9 @@ func (_c *SysCardCreate) Mutation() *SysCardMutation {
|
||||
|
||||
// Save creates the SysCard in the database.
|
||||
func (_c *SysCardCreate) Save(ctx context.Context) (*SysCard, error) {
|
||||
_c.defaults()
|
||||
if err := _c.defaults(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
@@ -126,15 +175,43 @@ func (_c *SysCardCreate) ExecX(ctx context.Context) {
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *SysCardCreate) defaults() {
|
||||
func (_c *SysCardCreate) defaults() error {
|
||||
if _, ok := _c.mutation.CreateTime(); !ok {
|
||||
if syscard.DefaultCreateTime == nil {
|
||||
return fmt.Errorf("ent: uninitialized syscard.DefaultCreateTime (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := syscard.DefaultCreateTime()
|
||||
_c.mutation.SetCreateTime(v)
|
||||
}
|
||||
if _, ok := _c.mutation.UpdateTime(); !ok {
|
||||
if syscard.DefaultUpdateTime == nil {
|
||||
return fmt.Errorf("ent: uninitialized syscard.DefaultUpdateTime (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := syscard.DefaultUpdateTime()
|
||||
_c.mutation.SetUpdateTime(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Status(); !ok {
|
||||
v := syscard.DefaultStatus
|
||||
_c.mutation.SetStatus(v)
|
||||
}
|
||||
if _, ok := _c.mutation.CashValue(); !ok {
|
||||
if syscard.DefaultCashValue == nil {
|
||||
return fmt.Errorf("ent: uninitialized syscard.DefaultCashValue (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := syscard.DefaultCashValue()
|
||||
_c.mutation.SetCashValue(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *SysCardCreate) check() error {
|
||||
if _, ok := _c.mutation.CreateTime(); !ok {
|
||||
return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "SysCard.create_time"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdateTime(); !ok {
|
||||
return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "SysCard.update_time"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Content(); !ok {
|
||||
return &ValidationError{Name: "content", err: errors.New(`ent: missing required field "SysCard.content"`)}
|
||||
}
|
||||
@@ -147,6 +224,9 @@ func (_c *SysCardCreate) check() error {
|
||||
if _, ok := _c.mutation.CreatorID(); !ok {
|
||||
return &ValidationError{Name: "creator_id", err: errors.New(`ent: missing required field "SysCard.creator_id"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.CashValue(); !ok {
|
||||
return &ValidationError{Name: "cash_value", err: errors.New(`ent: missing required field "SysCard.cash_value"`)}
|
||||
}
|
||||
if len(_c.mutation.CreatorIDs()) == 0 {
|
||||
return &ValidationError{Name: "creator", err: errors.New(`ent: missing required edge "SysCard.creator"`)}
|
||||
}
|
||||
@@ -177,6 +257,14 @@ func (_c *SysCardCreate) createSpec() (*SysCard, *sqlgraph.CreateSpec) {
|
||||
_spec = sqlgraph.NewCreateSpec(syscard.Table, sqlgraph.NewFieldSpec(syscard.FieldID, field.TypeInt64))
|
||||
)
|
||||
_spec.OnConflict = _c.conflict
|
||||
if value, ok := _c.mutation.CreateTime(); ok {
|
||||
_spec.SetField(syscard.FieldCreateTime, field.TypeString, value)
|
||||
_node.CreateTime = value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdateTime(); ok {
|
||||
_spec.SetField(syscard.FieldUpdateTime, field.TypeString, value)
|
||||
_node.UpdateTime = value
|
||||
}
|
||||
if value, ok := _c.mutation.Content(); ok {
|
||||
_spec.SetField(syscard.FieldContent, field.TypeString, value)
|
||||
_node.Content = value
|
||||
@@ -189,6 +277,10 @@ func (_c *SysCardCreate) createSpec() (*SysCard, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(syscard.FieldValue, field.TypeUint64, value)
|
||||
_node.Value = value
|
||||
}
|
||||
if value, ok := _c.mutation.CashValue(); ok {
|
||||
_spec.SetField(syscard.FieldCashValue, field.TypeString, value)
|
||||
_node.CashValue = value
|
||||
}
|
||||
if nodes := _c.mutation.CreatorIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
@@ -223,6 +315,23 @@ func (_c *SysCardCreate) createSpec() (*SysCard, *sqlgraph.CreateSpec) {
|
||||
_node.UsedID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.CashUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: syscard.CashUserTable,
|
||||
Columns: []string{syscard.CashUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.CashUserID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
@@ -230,7 +339,7 @@ func (_c *SysCardCreate) createSpec() (*SysCard, *sqlgraph.CreateSpec) {
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.SysCard.Create().
|
||||
// SetContent(v).
|
||||
// SetCreateTime(v).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
@@ -239,7 +348,7 @@ func (_c *SysCardCreate) createSpec() (*SysCard, *sqlgraph.CreateSpec) {
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.SysCardUpsert) {
|
||||
// SetContent(v+v).
|
||||
// SetCreateTime(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (_c *SysCardCreate) OnConflict(opts ...sql.ConflictOption) *SysCardUpsertOne {
|
||||
@@ -275,6 +384,18 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *SysCardUpsert) SetUpdateTime(v *ent2.CustomTime) *SysCardUpsert {
|
||||
u.Set(syscard.FieldUpdateTime, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *SysCardUpsert) UpdateUpdateTime() *SysCardUpsert {
|
||||
u.SetExcluded(syscard.FieldUpdateTime)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (u *SysCardUpsert) SetContent(v string) *SysCardUpsert {
|
||||
u.Set(syscard.FieldContent, v)
|
||||
@@ -353,6 +474,36 @@ func (u *SysCardUpsert) ClearUsedID() *SysCardUpsert {
|
||||
return u
|
||||
}
|
||||
|
||||
// SetCashUserID sets the "cash_user_id" field.
|
||||
func (u *SysCardUpsert) SetCashUserID(v int64) *SysCardUpsert {
|
||||
u.Set(syscard.FieldCashUserID, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateCashUserID sets the "cash_user_id" field to the value that was provided on create.
|
||||
func (u *SysCardUpsert) UpdateCashUserID() *SysCardUpsert {
|
||||
u.SetExcluded(syscard.FieldCashUserID)
|
||||
return u
|
||||
}
|
||||
|
||||
// ClearCashUserID clears the value of the "cash_user_id" field.
|
||||
func (u *SysCardUpsert) ClearCashUserID() *SysCardUpsert {
|
||||
u.SetNull(syscard.FieldCashUserID)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetCashValue sets the "cash_value" field.
|
||||
func (u *SysCardUpsert) SetCashValue(v decimal.Decimal) *SysCardUpsert {
|
||||
u.Set(syscard.FieldCashValue, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateCashValue sets the "cash_value" field to the value that was provided on create.
|
||||
func (u *SysCardUpsert) UpdateCashValue() *SysCardUpsert {
|
||||
u.SetExcluded(syscard.FieldCashValue)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
@@ -363,6 +514,11 @@ func (u *SysCardUpsert) ClearUsedID() *SysCardUpsert {
|
||||
// Exec(ctx)
|
||||
func (u *SysCardUpsertOne) UpdateNewValues() *SysCardUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
if _, exists := u.create.mutation.CreateTime(); exists {
|
||||
s.SetIgnore(syscard.FieldCreateTime)
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
@@ -393,6 +549,20 @@ func (u *SysCardUpsertOne) Update(set func(*SysCardUpsert)) *SysCardUpsertOne {
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *SysCardUpsertOne) SetUpdateTime(v *ent2.CustomTime) *SysCardUpsertOne {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
s.SetUpdateTime(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *SysCardUpsertOne) UpdateUpdateTime() *SysCardUpsertOne {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
s.UpdateUpdateTime()
|
||||
})
|
||||
}
|
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (u *SysCardUpsertOne) SetContent(v string) *SysCardUpsertOne {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
@@ -484,6 +654,41 @@ func (u *SysCardUpsertOne) ClearUsedID() *SysCardUpsertOne {
|
||||
})
|
||||
}
|
||||
|
||||
// SetCashUserID sets the "cash_user_id" field.
|
||||
func (u *SysCardUpsertOne) SetCashUserID(v int64) *SysCardUpsertOne {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
s.SetCashUserID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateCashUserID sets the "cash_user_id" field to the value that was provided on create.
|
||||
func (u *SysCardUpsertOne) UpdateCashUserID() *SysCardUpsertOne {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
s.UpdateCashUserID()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearCashUserID clears the value of the "cash_user_id" field.
|
||||
func (u *SysCardUpsertOne) ClearCashUserID() *SysCardUpsertOne {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
s.ClearCashUserID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetCashValue sets the "cash_value" field.
|
||||
func (u *SysCardUpsertOne) SetCashValue(v decimal.Decimal) *SysCardUpsertOne {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
s.SetCashValue(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateCashValue sets the "cash_value" field to the value that was provided on create.
|
||||
func (u *SysCardUpsertOne) UpdateCashValue() *SysCardUpsertOne {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
s.UpdateCashValue()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *SysCardUpsertOne) Exec(ctx context.Context) error {
|
||||
if len(u.create.conflict) == 0 {
|
||||
@@ -619,7 +824,7 @@ func (_c *SysCardCreateBulk) ExecX(ctx context.Context) {
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.SysCardUpsert) {
|
||||
// SetContent(v+v).
|
||||
// SetCreateTime(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (_c *SysCardCreateBulk) OnConflict(opts ...sql.ConflictOption) *SysCardUpsertBulk {
|
||||
@@ -658,6 +863,13 @@ type SysCardUpsertBulk struct {
|
||||
// Exec(ctx)
|
||||
func (u *SysCardUpsertBulk) UpdateNewValues() *SysCardUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
for _, b := range u.create.builders {
|
||||
if _, exists := b.mutation.CreateTime(); exists {
|
||||
s.SetIgnore(syscard.FieldCreateTime)
|
||||
}
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
@@ -688,6 +900,20 @@ func (u *SysCardUpsertBulk) Update(set func(*SysCardUpsert)) *SysCardUpsertBulk
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (u *SysCardUpsertBulk) SetUpdateTime(v *ent2.CustomTime) *SysCardUpsertBulk {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
s.SetUpdateTime(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
||||
func (u *SysCardUpsertBulk) UpdateUpdateTime() *SysCardUpsertBulk {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
s.UpdateUpdateTime()
|
||||
})
|
||||
}
|
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (u *SysCardUpsertBulk) SetContent(v string) *SysCardUpsertBulk {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
@@ -779,6 +1005,41 @@ func (u *SysCardUpsertBulk) ClearUsedID() *SysCardUpsertBulk {
|
||||
})
|
||||
}
|
||||
|
||||
// SetCashUserID sets the "cash_user_id" field.
|
||||
func (u *SysCardUpsertBulk) SetCashUserID(v int64) *SysCardUpsertBulk {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
s.SetCashUserID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateCashUserID sets the "cash_user_id" field to the value that was provided on create.
|
||||
func (u *SysCardUpsertBulk) UpdateCashUserID() *SysCardUpsertBulk {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
s.UpdateCashUserID()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearCashUserID clears the value of the "cash_user_id" field.
|
||||
func (u *SysCardUpsertBulk) ClearCashUserID() *SysCardUpsertBulk {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
s.ClearCashUserID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetCashValue sets the "cash_value" field.
|
||||
func (u *SysCardUpsertBulk) SetCashValue(v decimal.Decimal) *SysCardUpsertBulk {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
s.SetCashValue(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateCashValue sets the "cash_value" field to the value that was provided on create.
|
||||
func (u *SysCardUpsertBulk) UpdateCashValue() *SysCardUpsertBulk {
|
||||
return u.Update(func(s *SysCardUpsert) {
|
||||
s.UpdateCashValue()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *SysCardUpsertBulk) Exec(ctx context.Context) error {
|
||||
if u.create.err != nil {
|
||||
|
||||
@@ -19,12 +19,13 @@ import (
|
||||
// SysCardQuery is the builder for querying SysCard entities.
|
||||
type SysCardQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []syscard.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.SysCard
|
||||
withCreator *SysUserQuery
|
||||
withUser *SysUserQuery
|
||||
ctx *QueryContext
|
||||
order []syscard.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.SysCard
|
||||
withCreator *SysUserQuery
|
||||
withUser *SysUserQuery
|
||||
withCashUser *SysUserQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
@@ -105,6 +106,28 @@ func (_q *SysCardQuery) QueryUser() *SysUserQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryCashUser chains the current query on the "cash_user" edge.
|
||||
func (_q *SysCardQuery) QueryCashUser() *SysUserQuery {
|
||||
query := (&SysUserClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(syscard.Table, syscard.FieldID, selector),
|
||||
sqlgraph.To(sysuser.Table, sysuser.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, syscard.CashUserTable, syscard.CashUserColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first SysCard entity from the query.
|
||||
// Returns a *NotFoundError when no SysCard was found.
|
||||
func (_q *SysCardQuery) First(ctx context.Context) (*SysCard, error) {
|
||||
@@ -292,13 +315,14 @@ func (_q *SysCardQuery) Clone() *SysCardQuery {
|
||||
return nil
|
||||
}
|
||||
return &SysCardQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]syscard.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.SysCard{}, _q.predicates...),
|
||||
withCreator: _q.withCreator.Clone(),
|
||||
withUser: _q.withUser.Clone(),
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]syscard.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.SysCard{}, _q.predicates...),
|
||||
withCreator: _q.withCreator.Clone(),
|
||||
withUser: _q.withUser.Clone(),
|
||||
withCashUser: _q.withCashUser.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
@@ -327,18 +351,29 @@ func (_q *SysCardQuery) WithUser(opts ...func(*SysUserQuery)) *SysCardQuery {
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithCashUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "cash_user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *SysCardQuery) WithCashUser(opts ...func(*SysUserQuery)) *SysCardQuery {
|
||||
query := (&SysUserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withCashUser = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Content string `json:"content,omitempty"`
|
||||
// CreateTime *ent2.CustomTime `json:"createTime"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.SysCard.Query().
|
||||
// GroupBy(syscard.FieldContent).
|
||||
// GroupBy(syscard.FieldCreateTime).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *SysCardQuery) GroupBy(field string, fields ...string) *SysCardGroupBy {
|
||||
@@ -356,11 +391,11 @@ func (_q *SysCardQuery) GroupBy(field string, fields ...string) *SysCardGroupBy
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Content string `json:"content,omitempty"`
|
||||
// CreateTime *ent2.CustomTime `json:"createTime"`
|
||||
// }
|
||||
//
|
||||
// client.SysCard.Query().
|
||||
// Select(syscard.FieldContent).
|
||||
// Select(syscard.FieldCreateTime).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *SysCardQuery) Select(fields ...string) *SysCardSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
@@ -405,9 +440,10 @@ func (_q *SysCardQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysC
|
||||
var (
|
||||
nodes = []*SysCard{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [2]bool{
|
||||
loadedTypes = [3]bool{
|
||||
_q.withCreator != nil,
|
||||
_q.withUser != nil,
|
||||
_q.withCashUser != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
@@ -440,6 +476,12 @@ func (_q *SysCardQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysC
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withCashUser; query != nil {
|
||||
if err := _q.loadCashUser(ctx, query, nodes, nil,
|
||||
func(n *SysCard, e *SysUser) { n.Edges.CashUser = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
@@ -501,6 +543,35 @@ func (_q *SysCardQuery) loadUser(ctx context.Context, query *SysUserQuery, nodes
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *SysCardQuery) loadCashUser(ctx context.Context, query *SysUserQuery, nodes []*SysCard, init func(*SysCard), assign func(*SysCard, *SysUser)) error {
|
||||
ids := make([]int64, 0, len(nodes))
|
||||
nodeids := make(map[int64][]*SysCard)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].CashUserID
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(sysuser.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "cash_user_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *SysCardQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
@@ -533,6 +604,9 @@ func (_q *SysCardQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
if _q.withUser != nil {
|
||||
_spec.Node.AddColumnOnce(syscard.FieldUsedID)
|
||||
}
|
||||
if _q.withCashUser != nil {
|
||||
_spec.Node.AddColumnOnce(syscard.FieldCashUserID)
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
|
||||
@@ -9,10 +9,12 @@ import (
|
||||
"likedream-goframe/internal/ent/predicate"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// SysCardUpdate is the builder for updating SysCard entities.
|
||||
@@ -28,6 +30,12 @@ func (_u *SysCardUpdate) Where(ps ...predicate.SysCard) *SysCardUpdate {
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_u *SysCardUpdate) SetUpdateTime(v *ent2.CustomTime) *SysCardUpdate {
|
||||
_u.mutation.SetUpdateTime(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (_u *SysCardUpdate) SetContent(v string) *SysCardUpdate {
|
||||
_u.mutation.SetContent(v)
|
||||
@@ -118,6 +126,40 @@ func (_u *SysCardUpdate) ClearUsedID() *SysCardUpdate {
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCashUserID sets the "cash_user_id" field.
|
||||
func (_u *SysCardUpdate) SetCashUserID(v int64) *SysCardUpdate {
|
||||
_u.mutation.SetCashUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCashUserID sets the "cash_user_id" field if the given value is not nil.
|
||||
func (_u *SysCardUpdate) SetNillableCashUserID(v *int64) *SysCardUpdate {
|
||||
if v != nil {
|
||||
_u.SetCashUserID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearCashUserID clears the value of the "cash_user_id" field.
|
||||
func (_u *SysCardUpdate) ClearCashUserID() *SysCardUpdate {
|
||||
_u.mutation.ClearCashUserID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCashValue sets the "cash_value" field.
|
||||
func (_u *SysCardUpdate) SetCashValue(v decimal.Decimal) *SysCardUpdate {
|
||||
_u.mutation.SetCashValue(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCashValue sets the "cash_value" field if the given value is not nil.
|
||||
func (_u *SysCardUpdate) SetNillableCashValue(v *decimal.Decimal) *SysCardUpdate {
|
||||
if v != nil {
|
||||
_u.SetCashValue(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCreator sets the "creator" edge to the SysUser entity.
|
||||
func (_u *SysCardUpdate) SetCreator(v *SysUser) *SysCardUpdate {
|
||||
return _u.SetCreatorID(v.ID)
|
||||
@@ -142,6 +184,11 @@ func (_u *SysCardUpdate) SetUser(v *SysUser) *SysCardUpdate {
|
||||
return _u.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// SetCashUser sets the "cash_user" edge to the SysUser entity.
|
||||
func (_u *SysCardUpdate) SetCashUser(v *SysUser) *SysCardUpdate {
|
||||
return _u.SetCashUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the SysCardMutation object of the builder.
|
||||
func (_u *SysCardUpdate) Mutation() *SysCardMutation {
|
||||
return _u.mutation
|
||||
@@ -159,6 +206,12 @@ func (_u *SysCardUpdate) ClearUser() *SysCardUpdate {
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearCashUser clears the "cash_user" edge to the SysUser entity.
|
||||
func (_u *SysCardUpdate) ClearCashUser() *SysCardUpdate {
|
||||
_u.mutation.ClearCashUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *SysCardUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
@@ -206,6 +259,9 @@ func (_u *SysCardUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdateTime(); ok {
|
||||
_spec.SetField(syscard.FieldUpdateTime, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Content(); ok {
|
||||
_spec.SetField(syscard.FieldContent, field.TypeString, value)
|
||||
}
|
||||
@@ -221,6 +277,9 @@ func (_u *SysCardUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if value, ok := _u.mutation.AddedValue(); ok {
|
||||
_spec.AddField(syscard.FieldValue, field.TypeUint64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.CashValue(); ok {
|
||||
_spec.SetField(syscard.FieldCashValue, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.CreatorCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
@@ -279,6 +338,35 @@ func (_u *SysCardUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.CashUserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: syscard.CashUserTable,
|
||||
Columns: []string{syscard.CashUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.CashUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: syscard.CashUserTable,
|
||||
Columns: []string{syscard.CashUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.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{syscard.Label}
|
||||
@@ -299,6 +387,12 @@ type SysCardUpdateOne struct {
|
||||
mutation *SysCardMutation
|
||||
}
|
||||
|
||||
// SetUpdateTime sets the "update_time" field.
|
||||
func (_u *SysCardUpdateOne) SetUpdateTime(v *ent2.CustomTime) *SysCardUpdateOne {
|
||||
_u.mutation.SetUpdateTime(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (_u *SysCardUpdateOne) SetContent(v string) *SysCardUpdateOne {
|
||||
_u.mutation.SetContent(v)
|
||||
@@ -389,6 +483,40 @@ func (_u *SysCardUpdateOne) ClearUsedID() *SysCardUpdateOne {
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCashUserID sets the "cash_user_id" field.
|
||||
func (_u *SysCardUpdateOne) SetCashUserID(v int64) *SysCardUpdateOne {
|
||||
_u.mutation.SetCashUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCashUserID sets the "cash_user_id" field if the given value is not nil.
|
||||
func (_u *SysCardUpdateOne) SetNillableCashUserID(v *int64) *SysCardUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetCashUserID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearCashUserID clears the value of the "cash_user_id" field.
|
||||
func (_u *SysCardUpdateOne) ClearCashUserID() *SysCardUpdateOne {
|
||||
_u.mutation.ClearCashUserID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCashValue sets the "cash_value" field.
|
||||
func (_u *SysCardUpdateOne) SetCashValue(v decimal.Decimal) *SysCardUpdateOne {
|
||||
_u.mutation.SetCashValue(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCashValue sets the "cash_value" field if the given value is not nil.
|
||||
func (_u *SysCardUpdateOne) SetNillableCashValue(v *decimal.Decimal) *SysCardUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetCashValue(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCreator sets the "creator" edge to the SysUser entity.
|
||||
func (_u *SysCardUpdateOne) SetCreator(v *SysUser) *SysCardUpdateOne {
|
||||
return _u.SetCreatorID(v.ID)
|
||||
@@ -413,6 +541,11 @@ func (_u *SysCardUpdateOne) SetUser(v *SysUser) *SysCardUpdateOne {
|
||||
return _u.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// SetCashUser sets the "cash_user" edge to the SysUser entity.
|
||||
func (_u *SysCardUpdateOne) SetCashUser(v *SysUser) *SysCardUpdateOne {
|
||||
return _u.SetCashUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the SysCardMutation object of the builder.
|
||||
func (_u *SysCardUpdateOne) Mutation() *SysCardMutation {
|
||||
return _u.mutation
|
||||
@@ -430,6 +563,12 @@ func (_u *SysCardUpdateOne) ClearUser() *SysCardUpdateOne {
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearCashUser clears the "cash_user" edge to the SysUser entity.
|
||||
func (_u *SysCardUpdateOne) ClearCashUser() *SysCardUpdateOne {
|
||||
_u.mutation.ClearCashUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysCardUpdate builder.
|
||||
func (_u *SysCardUpdateOne) Where(ps ...predicate.SysCard) *SysCardUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
@@ -507,6 +646,9 @@ func (_u *SysCardUpdateOne) sqlSave(ctx context.Context) (_node *SysCard, err er
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdateTime(); ok {
|
||||
_spec.SetField(syscard.FieldUpdateTime, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Content(); ok {
|
||||
_spec.SetField(syscard.FieldContent, field.TypeString, value)
|
||||
}
|
||||
@@ -522,6 +664,9 @@ func (_u *SysCardUpdateOne) sqlSave(ctx context.Context) (_node *SysCard, err er
|
||||
if value, ok := _u.mutation.AddedValue(); ok {
|
||||
_spec.AddField(syscard.FieldValue, field.TypeUint64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.CashValue(); ok {
|
||||
_spec.SetField(syscard.FieldCashValue, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.CreatorCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
@@ -580,6 +725,35 @@ func (_u *SysCardUpdateOne) sqlSave(ctx context.Context) (_node *SysCard, err er
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.CashUserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: syscard.CashUserTable,
|
||||
Columns: []string{syscard.CashUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.CashUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: syscard.CashUserTable,
|
||||
Columns: []string{syscard.CashUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &SysCard{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
||||
+17
-1
@@ -66,9 +66,11 @@ type SysUserEdges struct {
|
||||
CreatedCards []*SysCard `json:"created_cards,omitempty"`
|
||||
// UsedCards holds the value of the used_cards edge.
|
||||
UsedCards []*SysCard `json:"used_cards,omitempty"`
|
||||
// CashbackCards holds the value of the cashback_cards edge.
|
||||
CashbackCards []*SysCard `json:"cashback_cards,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [9]bool
|
||||
loadedTypes [10]bool
|
||||
}
|
||||
|
||||
// ParentOrErr returns the Parent value or an error if the edge
|
||||
@@ -156,6 +158,15 @@ func (e SysUserEdges) UsedCardsOrErr() ([]*SysCard, error) {
|
||||
return nil, &NotLoadedError{edge: "used_cards"}
|
||||
}
|
||||
|
||||
// CashbackCardsOrErr returns the CashbackCards value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e SysUserEdges) CashbackCardsOrErr() ([]*SysCard, error) {
|
||||
if e.loadedTypes[9] {
|
||||
return e.CashbackCards, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "cashback_cards"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*SysUser) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
@@ -319,6 +330,11 @@ func (_m *SysUser) QueryUsedCards() *SysCardQuery {
|
||||
return NewSysUserClient(_m.config).QueryUsedCards(_m)
|
||||
}
|
||||
|
||||
// QueryCashbackCards queries the "cashback_cards" edge of the SysUser entity.
|
||||
func (_m *SysUser) QueryCashbackCards() *SysCardQuery {
|
||||
return NewSysUserClient(_m.config).QueryCashbackCards(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this SysUser.
|
||||
// Note that you need to call SysUser.Unwrap() before calling this method if this SysUser
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
|
||||
@@ -54,6 +54,8 @@ const (
|
||||
EdgeCreatedCards = "created_cards"
|
||||
// EdgeUsedCards holds the string denoting the used_cards edge name in mutations.
|
||||
EdgeUsedCards = "used_cards"
|
||||
// EdgeCashbackCards holds the string denoting the cashback_cards edge name in mutations.
|
||||
EdgeCashbackCards = "cashback_cards"
|
||||
// Table holds the table name of the sysuser in the database.
|
||||
Table = "sys_user"
|
||||
// ParentTable is the table that holds the parent relation/edge.
|
||||
@@ -111,6 +113,13 @@ const (
|
||||
UsedCardsInverseTable = "sys_card"
|
||||
// UsedCardsColumn is the table column denoting the used_cards relation/edge.
|
||||
UsedCardsColumn = "used_id"
|
||||
// CashbackCardsTable is the table that holds the cashback_cards relation/edge.
|
||||
CashbackCardsTable = "sys_card"
|
||||
// CashbackCardsInverseTable is the table name for the SysCard entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "syscard" package.
|
||||
CashbackCardsInverseTable = "sys_card"
|
||||
// CashbackCardsColumn is the table column denoting the cashback_cards relation/edge.
|
||||
CashbackCardsColumn = "cash_user_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for sysuser fields.
|
||||
@@ -347,6 +356,20 @@ func ByUsedCards(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
sqlgraph.OrderByNeighborTerms(s, newUsedCardsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByCashbackCardsCount orders the results by cashback_cards count.
|
||||
func ByCashbackCardsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newCashbackCardsStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByCashbackCards orders the results by cashback_cards terms.
|
||||
func ByCashbackCards(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newCashbackCardsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newParentStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
@@ -410,3 +433,10 @@ func newUsedCardsStep() *sqlgraph.Step {
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, UsedCardsTable, UsedCardsColumn),
|
||||
)
|
||||
}
|
||||
func newCashbackCardsStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(CashbackCardsInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, CashbackCardsTable, CashbackCardsColumn),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -883,6 +883,29 @@ func HasUsedCardsWith(preds ...predicate.SysCard) predicate.SysUser {
|
||||
})
|
||||
}
|
||||
|
||||
// HasCashbackCards applies the HasEdge predicate on the "cashback_cards" edge.
|
||||
func HasCashbackCards() predicate.SysUser {
|
||||
return predicate.SysUser(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, CashbackCardsTable, CashbackCardsColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasCashbackCardsWith applies the HasEdge predicate on the "cashback_cards" edge with a given conditions (other predicates).
|
||||
func HasCashbackCardsWith(preds ...predicate.SysCard) predicate.SysUser {
|
||||
return predicate.SysUser(func(s *sql.Selector) {
|
||||
step := newCashbackCardsStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.SysUser) predicate.SysUser {
|
||||
return predicate.SysUser(sql.AndPredicates(predicates...))
|
||||
|
||||
@@ -272,6 +272,21 @@ func (_c *SysUserCreate) AddUsedCards(v ...*SysCard) *SysUserCreate {
|
||||
return _c.AddUsedCardIDs(ids...)
|
||||
}
|
||||
|
||||
// AddCashbackCardIDs adds the "cashback_cards" edge to the SysCard entity by IDs.
|
||||
func (_c *SysUserCreate) AddCashbackCardIDs(ids ...int64) *SysUserCreate {
|
||||
_c.mutation.AddCashbackCardIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddCashbackCards adds the "cashback_cards" edges to the SysCard entity.
|
||||
func (_c *SysUserCreate) AddCashbackCards(v ...*SysCard) *SysUserCreate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the SysUserMutation object of the builder.
|
||||
func (_c *SysUserCreate) Mutation() *SysUserMutation {
|
||||
return _c.mutation
|
||||
@@ -594,6 +609,22 @@ func (_c *SysUserCreate) createSpec() (*SysUser, *sqlgraph.CreateSpec) {
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.CashbackCardsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.CashbackCardsTable,
|
||||
Columns: []string{sysuser.CashbackCardsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(syscard.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
||||
+102
-29
@@ -25,20 +25,21 @@ import (
|
||||
// SysUserQuery is the builder for querying SysUser entities.
|
||||
type SysUserQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []sysuser.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.SysUser
|
||||
withParent *SysUserQuery
|
||||
withChildren *SysUserQuery
|
||||
withRoles *SysRoleQuery
|
||||
withAgent *SysAgentQuery
|
||||
withImages *CpImageQuery
|
||||
withCpuser *CpUserQuery
|
||||
withCpTaskLogs *CpTaskLogQuery
|
||||
withCreatedCards *SysCardQuery
|
||||
withUsedCards *SysCardQuery
|
||||
withFKs bool
|
||||
ctx *QueryContext
|
||||
order []sysuser.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.SysUser
|
||||
withParent *SysUserQuery
|
||||
withChildren *SysUserQuery
|
||||
withRoles *SysRoleQuery
|
||||
withAgent *SysAgentQuery
|
||||
withImages *CpImageQuery
|
||||
withCpuser *CpUserQuery
|
||||
withCpTaskLogs *CpTaskLogQuery
|
||||
withCreatedCards *SysCardQuery
|
||||
withUsedCards *SysCardQuery
|
||||
withCashbackCards *SysCardQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
@@ -273,6 +274,28 @@ func (_q *SysUserQuery) QueryUsedCards() *SysCardQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryCashbackCards chains the current query on the "cashback_cards" edge.
|
||||
func (_q *SysUserQuery) QueryCashbackCards() *SysCardQuery {
|
||||
query := (&SysCardClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(sysuser.Table, sysuser.FieldID, selector),
|
||||
sqlgraph.To(syscard.Table, syscard.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, sysuser.CashbackCardsTable, sysuser.CashbackCardsColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first SysUser entity from the query.
|
||||
// Returns a *NotFoundError when no SysUser was found.
|
||||
func (_q *SysUserQuery) First(ctx context.Context) (*SysUser, error) {
|
||||
@@ -460,20 +483,21 @@ func (_q *SysUserQuery) Clone() *SysUserQuery {
|
||||
return nil
|
||||
}
|
||||
return &SysUserQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]sysuser.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.SysUser{}, _q.predicates...),
|
||||
withParent: _q.withParent.Clone(),
|
||||
withChildren: _q.withChildren.Clone(),
|
||||
withRoles: _q.withRoles.Clone(),
|
||||
withAgent: _q.withAgent.Clone(),
|
||||
withImages: _q.withImages.Clone(),
|
||||
withCpuser: _q.withCpuser.Clone(),
|
||||
withCpTaskLogs: _q.withCpTaskLogs.Clone(),
|
||||
withCreatedCards: _q.withCreatedCards.Clone(),
|
||||
withUsedCards: _q.withUsedCards.Clone(),
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]sysuser.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.SysUser{}, _q.predicates...),
|
||||
withParent: _q.withParent.Clone(),
|
||||
withChildren: _q.withChildren.Clone(),
|
||||
withRoles: _q.withRoles.Clone(),
|
||||
withAgent: _q.withAgent.Clone(),
|
||||
withImages: _q.withImages.Clone(),
|
||||
withCpuser: _q.withCpuser.Clone(),
|
||||
withCpTaskLogs: _q.withCpTaskLogs.Clone(),
|
||||
withCreatedCards: _q.withCreatedCards.Clone(),
|
||||
withUsedCards: _q.withUsedCards.Clone(),
|
||||
withCashbackCards: _q.withCashbackCards.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
@@ -579,6 +603,17 @@ func (_q *SysUserQuery) WithUsedCards(opts ...func(*SysCardQuery)) *SysUserQuery
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithCashbackCards tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "cashback_cards" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *SysUserQuery) WithCashbackCards(opts ...func(*SysCardQuery)) *SysUserQuery {
|
||||
query := (&SysCardClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withCashbackCards = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
@@ -658,7 +693,7 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
|
||||
nodes = []*SysUser{}
|
||||
withFKs = _q.withFKs
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [9]bool{
|
||||
loadedTypes = [10]bool{
|
||||
_q.withParent != nil,
|
||||
_q.withChildren != nil,
|
||||
_q.withRoles != nil,
|
||||
@@ -668,6 +703,7 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
|
||||
_q.withCpTaskLogs != nil,
|
||||
_q.withCreatedCards != nil,
|
||||
_q.withUsedCards != nil,
|
||||
_q.withCashbackCards != nil,
|
||||
}
|
||||
)
|
||||
if _q.withParent != nil {
|
||||
@@ -755,6 +791,13 @@ func (_q *SysUserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SysU
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withCashbackCards; query != nil {
|
||||
if err := _q.loadCashbackCards(ctx, query, nodes,
|
||||
func(n *SysUser) { n.Edges.CashbackCards = []*SysCard{} },
|
||||
func(n *SysUser, e *SysCard) { n.Edges.CashbackCards = append(n.Edges.CashbackCards, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
@@ -1060,6 +1103,36 @@ func (_q *SysUserQuery) loadUsedCards(ctx context.Context, query *SysCardQuery,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *SysUserQuery) loadCashbackCards(ctx context.Context, query *SysCardQuery, nodes []*SysUser, init func(*SysUser), assign func(*SysUser, *SysCard)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int64]*SysUser)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
if len(query.ctx.Fields) > 0 {
|
||||
query.ctx.AppendFieldOnce(syscard.FieldCashUserID)
|
||||
}
|
||||
query.Where(predicate.SysCard(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(sysuser.CashbackCardsColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.CashUserID
|
||||
node, ok := nodeids[fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "cash_user_id" returned %v for node %v`, fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *SysUserQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
|
||||
@@ -302,6 +302,21 @@ func (_u *SysUserUpdate) AddUsedCards(v ...*SysCard) *SysUserUpdate {
|
||||
return _u.AddUsedCardIDs(ids...)
|
||||
}
|
||||
|
||||
// AddCashbackCardIDs adds the "cashback_cards" edge to the SysCard entity by IDs.
|
||||
func (_u *SysUserUpdate) AddCashbackCardIDs(ids ...int64) *SysUserUpdate {
|
||||
_u.mutation.AddCashbackCardIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddCashbackCards adds the "cashback_cards" edges to the SysCard entity.
|
||||
func (_u *SysUserUpdate) AddCashbackCards(v ...*SysCard) *SysUserUpdate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the SysUserMutation object of the builder.
|
||||
func (_u *SysUserUpdate) Mutation() *SysUserMutation {
|
||||
return _u.mutation
|
||||
@@ -466,6 +481,27 @@ func (_u *SysUserUpdate) RemoveUsedCards(v ...*SysCard) *SysUserUpdate {
|
||||
return _u.RemoveUsedCardIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearCashbackCards clears all "cashback_cards" edges to the SysCard entity.
|
||||
func (_u *SysUserUpdate) ClearCashbackCards() *SysUserUpdate {
|
||||
_u.mutation.ClearCashbackCards()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveCashbackCardIDs removes the "cashback_cards" edge to SysCard entities by IDs.
|
||||
func (_u *SysUserUpdate) RemoveCashbackCardIDs(ids ...int64) *SysUserUpdate {
|
||||
_u.mutation.RemoveCashbackCardIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveCashbackCards removes "cashback_cards" edges to SysCard entities.
|
||||
func (_u *SysUserUpdate) RemoveCashbackCards(v ...*SysCard) *SysUserUpdate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *SysUserUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
@@ -918,6 +954,51 @@ func (_u *SysUserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.CashbackCardsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.CashbackCardsTable,
|
||||
Columns: []string{sysuser.CashbackCardsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(syscard.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedCashbackCardsIDs(); len(nodes) > 0 && !_u.mutation.CashbackCardsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.CashbackCardsTable,
|
||||
Columns: []string{sysuser.CashbackCardsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(syscard.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.CashbackCardsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.CashbackCardsTable,
|
||||
Columns: []string{sysuser.CashbackCardsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(syscard.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{sysuser.Label}
|
||||
@@ -1205,6 +1286,21 @@ func (_u *SysUserUpdateOne) AddUsedCards(v ...*SysCard) *SysUserUpdateOne {
|
||||
return _u.AddUsedCardIDs(ids...)
|
||||
}
|
||||
|
||||
// AddCashbackCardIDs adds the "cashback_cards" edge to the SysCard entity by IDs.
|
||||
func (_u *SysUserUpdateOne) AddCashbackCardIDs(ids ...int64) *SysUserUpdateOne {
|
||||
_u.mutation.AddCashbackCardIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddCashbackCards adds the "cashback_cards" edges to the SysCard entity.
|
||||
func (_u *SysUserUpdateOne) AddCashbackCards(v ...*SysCard) *SysUserUpdateOne {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the SysUserMutation object of the builder.
|
||||
func (_u *SysUserUpdateOne) Mutation() *SysUserMutation {
|
||||
return _u.mutation
|
||||
@@ -1369,6 +1465,27 @@ func (_u *SysUserUpdateOne) RemoveUsedCards(v ...*SysCard) *SysUserUpdateOne {
|
||||
return _u.RemoveUsedCardIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearCashbackCards clears all "cashback_cards" edges to the SysCard entity.
|
||||
func (_u *SysUserUpdateOne) ClearCashbackCards() *SysUserUpdateOne {
|
||||
_u.mutation.ClearCashbackCards()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveCashbackCardIDs removes the "cashback_cards" edge to SysCard entities by IDs.
|
||||
func (_u *SysUserUpdateOne) RemoveCashbackCardIDs(ids ...int64) *SysUserUpdateOne {
|
||||
_u.mutation.RemoveCashbackCardIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveCashbackCards removes "cashback_cards" edges to SysCard entities.
|
||||
func (_u *SysUserUpdateOne) RemoveCashbackCards(v ...*SysCard) *SysUserUpdateOne {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveCashbackCardIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SysUserUpdate builder.
|
||||
func (_u *SysUserUpdateOne) Where(ps ...predicate.SysUser) *SysUserUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
@@ -1851,6 +1968,51 @@ func (_u *SysUserUpdateOne) sqlSave(ctx context.Context) (_node *SysUser, err er
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.CashbackCardsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.CashbackCardsTable,
|
||||
Columns: []string{sysuser.CashbackCardsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(syscard.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedCashbackCardsIDs(); len(nodes) > 0 && !_u.mutation.CashbackCardsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.CashbackCardsTable,
|
||||
Columns: []string{sysuser.CashbackCardsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(syscard.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.CashbackCardsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: sysuser.CashbackCardsTable,
|
||||
Columns: []string{sysuser.CashbackCardsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(syscard.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &SysUser{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
||||
@@ -4,14 +4,17 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
v1 "likedream-goframe/internal/api/v1"
|
||||
"likedream-goframe/internal/cst"
|
||||
"likedream-goframe/internal/db"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/ent/syscard"
|
||||
"likedream-goframe/internal/ent/sysmenu"
|
||||
"likedream-goframe/internal/ent/sysrole"
|
||||
"likedream-goframe/internal/ent/sysuser"
|
||||
"likedream-goframe/internal/framework/ent2"
|
||||
"likedream-goframe/internal/utils"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/samber/oops"
|
||||
"github.com/shopspring/decimal"
|
||||
@@ -116,12 +119,28 @@ func (s *UserInfoServiceV1) CardRecharge(ctx context.Context, req *v1.CardRechar
|
||||
if ent.IsNotFound(err) {
|
||||
return utils.FailParam("卡密错误")
|
||||
}
|
||||
if card.Status != 1 {
|
||||
if card.Status != cst.CardStatusEnable {
|
||||
return utils.FailParam("卡密错误")
|
||||
}
|
||||
if utils.HasRole(user.Edges.Roles, cst.KeyRoleAgent) {
|
||||
return utils.FailParam("代理用户请联系上级充值")
|
||||
}
|
||||
tx, err := db.Global.Tx(ctx)
|
||||
utils.OkOrPanic(err)
|
||||
tx.SysCard.UpdateOneID(card.ID).SetStatus(2).SetUsedID(user.ID).ExecX(ctx)
|
||||
parent := user.QueryParent().WithAgent().FirstX(ctx)
|
||||
if parent != nil {
|
||||
// 返现20%
|
||||
r, _ := decimal.NewFromString("0.2")
|
||||
cashbackValue := decimal.NewFromUint64(card.Value).Mul(r)
|
||||
// 这里查询父级是否是代理,代理的话要x代理费率
|
||||
if parent.Edges.Agent != nil {
|
||||
cashbackValue = cashbackValue.Mul(parent.Edges.Agent.Rate)
|
||||
}
|
||||
tx.SysUser.UpdateOneID(user.Edges.Parent.ID).SetBalance(parent.Balance.Add(cashbackValue)).SetInviteCashback(parent.InviteCashback.Add(cashbackValue)).ExecX(ctx)
|
||||
tx.SysCard.UpdateOneID(card.ID).SetStatus(cst.CardStatusCashback).SetUsedID(user.ID).SetCashUserID(user.Edges.Parent.ID).SetCashValue(cashbackValue).ExecX(ctx)
|
||||
} else {
|
||||
tx.SysCard.UpdateOneID(card.ID).SetStatus(cst.CardStatusUsed).SetUsedID(user.ID).ExecX(ctx)
|
||||
}
|
||||
tx.SysUser.UpdateOneID(user.ID).SetBalance(user.Balance.Add(decimal.NewFromUint64(card.Value))).ExecX(ctx)
|
||||
err = tx.Commit()
|
||||
utils.OkOrPanic(err, func(err error) error {
|
||||
@@ -133,6 +152,62 @@ func (s *UserInfoServiceV1) CardRecharge(ctx context.Context, req *v1.CardRechar
|
||||
return utils.SuccessWithMsg("充值成功")
|
||||
}
|
||||
|
||||
func (s *UserInfoServiceV1) InviteCashbackInfo(ctx context.Context, req *v1.CommonReq) *utils.Response[any] {
|
||||
user := utils.GetUserInfoFromCtx(ctx)
|
||||
// 查询总邀请人数
|
||||
total := db.Global.SysUser.Query().Where(sysuser.HasParentWith(sysuser.ID(utils.GetUserInfoFromCtx(ctx).ID))).CountX(ctx)
|
||||
// 查询本月邀请人数
|
||||
monthTotal := db.Global.SysUser.Query().Where(sysuser.HasParentWith(sysuser.ID(utils.GetUserInfoFromCtx(ctx).ID)), sysuser.CreateTimeGTE(ent2.NewCustomTime(time.Now().AddDate(0, 0, -30)))).CountX(ctx)
|
||||
// 累计邀请返现
|
||||
totalCashback := user.InviteCashback
|
||||
return utils.SuccessWithData[any](&v1.InviteCashbackRes{
|
||||
Total: total,
|
||||
MonthTotal: monthTotal,
|
||||
TotalCashback: totalCashback,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *UserInfoServiceV1) InviteUserList(ctx context.Context, req *v1.CommonPageReq) *utils.Response[[]*v1.UserInviteRes] {
|
||||
user := utils.GetUserInfoFromCtx(ctx)
|
||||
query := db.Global.SysUser.Query().Where(sysuser.HasParentWith(sysuser.ID(user.ID))).WithUsedCards()
|
||||
total := query.CountX(ctx)
|
||||
var list []*ent.SysUser
|
||||
if total > 0 {
|
||||
list = query.Limit(req.Size).Offset((req.Page - 1) * req.Size).AllX(ctx)
|
||||
}
|
||||
userList := make([]*v1.UserInviteRes, 0)
|
||||
for _, u := range list {
|
||||
tempUser := &v1.UserInviteRes{
|
||||
Id: u.ID,
|
||||
Username: u.Username,
|
||||
Email: u.Email,
|
||||
CreatedTime: u.CreateTime,
|
||||
Cashback: decimal.NewFromInt(0),
|
||||
}
|
||||
if u.Edges.UsedCards != nil {
|
||||
for _, card := range u.Edges.UsedCards {
|
||||
tempUser.Cashback = tempUser.Cashback.Add(card.CashValue)
|
||||
}
|
||||
}
|
||||
userList = append(userList, tempUser)
|
||||
}
|
||||
return utils.SuccessWithTotal[[]*v1.UserInviteRes](userList, total)
|
||||
}
|
||||
|
||||
func (s *UserInfoServiceV1) GenerateInviteCode(ctx context.Context, req *v1.CommonPostReq) *utils.Response[any] {
|
||||
user := utils.GetUserInfoFromCtx(ctx)
|
||||
inviteCode := ""
|
||||
for {
|
||||
inviteCode = utils.GenerateInviteCode(8)
|
||||
// 判断是否已生成
|
||||
if !db.Global.SysUser.Query().Where(sysuser.InviteCode(inviteCode)).ExistX(ctx) {
|
||||
break
|
||||
}
|
||||
}
|
||||
db.Global.SysUser.UpdateOneID(user.ID).SetInviteCode(inviteCode).ExecX(ctx)
|
||||
return utils.SuccessWithMsg("生成成功")
|
||||
}
|
||||
|
||||
func buildTreeMenu(list []*ent.SysMenu, parentId int64) []*v1.UserMenuRes {
|
||||
var menuList []*v1.UserMenuRes
|
||||
for _, menu := range list {
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"likedream-goframe/internal/cst"
|
||||
"likedream-goframe/internal/ent"
|
||||
"likedream-goframe/internal/framework/errors"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
@@ -73,3 +75,13 @@ func HasRole(roles []*ent.SysRole, key string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func GenerateInviteCode(length int) string {
|
||||
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
b := make([]byte, length)
|
||||
for i := range b {
|
||||
b[i] = letters[rng.Intn(len(letters))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user