This commit is contained in:
2025-12-09 18:55:28 +08:00
parent 8d00d67540
commit c23ab8338b
209 changed files with 5445 additions and 3963 deletions

View File

@@ -8,9 +8,11 @@ import (
"fmt"
"strings"
"reflect"
"time"
"github.com/Masterminds/squirrel"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/cache"
@@ -23,7 +25,7 @@ import (
var (
agentWithdrawalFieldNames = builder.RawFieldNames(&AgentWithdrawal{})
agentWithdrawalRows = strings.Join(agentWithdrawalFieldNames, ",")
agentWithdrawalRowsExpectAutoSet = strings.Join(stringx.Remove(agentWithdrawalFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
agentWithdrawalRowsExpectAutoSet = strings.Join(stringx.Remove(agentWithdrawalFieldNames, "`create_time`", "`update_time`"), ",")
agentWithdrawalRowsWithPlaceHolder = strings.Join(stringx.Remove(agentWithdrawalFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
cacheYccAgentWithdrawalIdPrefix = "cache:ycc:agentWithdrawal:id:"
@@ -33,7 +35,7 @@ var (
type (
agentWithdrawalModel interface {
Insert(ctx context.Context, session sqlx.Session, data *AgentWithdrawal) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*AgentWithdrawal, error)
FindOne(ctx context.Context, id string) (*AgentWithdrawal, error)
FindOneByWithdrawNo(ctx context.Context, withdrawNo string) (*AgentWithdrawal, error)
Update(ctx context.Context, session sqlx.Session, data *AgentWithdrawal) (sql.Result, error)
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentWithdrawal) error
@@ -47,7 +49,7 @@ type (
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentWithdrawal, int64, error)
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentWithdrawal, error)
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentWithdrawal, error)
Delete(ctx context.Context, session sqlx.Session, id int64) error
Delete(ctx context.Context, session sqlx.Session, id string) error
}
defaultAgentWithdrawalModel struct {
@@ -56,8 +58,8 @@ type (
}
AgentWithdrawal struct {
Id int64 `db:"id"` // 主键ID
AgentId int64 `db:"agent_id"` // 代理ID
Id string `db:"id"`
AgentId string `db:"agent_id"`
WithdrawNo string `db:"withdraw_no"` // 提现单号
PayeeAccount string `db:"payee_account"` // 收款账户
PayeeName string `db:"payee_name"` // 收款人姓名
@@ -83,18 +85,35 @@ func newAgentWithdrawalModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgent
func (m *defaultAgentWithdrawalModel) Insert(ctx context.Context, session sqlx.Session, data *AgentWithdrawal) (sql.Result, error) {
data.DelState = globalkey.DelStateNo
m.insertUUID(data)
yccAgentWithdrawalIdKey := fmt.Sprintf("%s%v", cacheYccAgentWithdrawalIdPrefix, data.Id)
yccAgentWithdrawalWithdrawNoKey := fmt.Sprintf("%s%v", cacheYccAgentWithdrawalWithdrawNoPrefix, data.WithdrawNo)
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, agentWithdrawalRowsExpectAutoSet)
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, agentWithdrawalRowsExpectAutoSet)
if session != nil {
return session.ExecCtx(ctx, query, data.AgentId, data.WithdrawNo, data.PayeeAccount, data.PayeeName, data.Amount, data.ActualAmount, data.TaxAmount, data.Status, data.Remark, data.DeleteTime, data.DelState, data.Version)
return session.ExecCtx(ctx, query, data.Id, data.AgentId, data.WithdrawNo, data.PayeeAccount, data.PayeeName, data.Amount, data.ActualAmount, data.TaxAmount, data.Status, data.Remark, data.DeleteTime, data.DelState, data.Version)
}
return conn.ExecCtx(ctx, query, data.AgentId, data.WithdrawNo, data.PayeeAccount, data.PayeeName, data.Amount, data.ActualAmount, data.TaxAmount, data.Status, data.Remark, data.DeleteTime, data.DelState, data.Version)
return conn.ExecCtx(ctx, query, data.Id, data.AgentId, data.WithdrawNo, data.PayeeAccount, data.PayeeName, data.Amount, data.ActualAmount, data.TaxAmount, data.Status, data.Remark, data.DeleteTime, data.DelState, data.Version)
}, yccAgentWithdrawalIdKey, yccAgentWithdrawalWithdrawNoKey)
}
func (m *defaultAgentWithdrawalModel) insertUUID(data *AgentWithdrawal) {
t := reflect.TypeOf(data).Elem()
v := reflect.ValueOf(data).Elem()
for i := 0; i < t.NumField(); i++ {
sf := t.Field(i)
if sf.Tag.Get("db") == "id" {
f := v.Field(i)
if f.IsValid() && f.CanSet() && f.Kind() == reflect.String {
if f.String() == "" {
f.SetString(uuid.NewString())
}
}
break
}
}
}
func (m *defaultAgentWithdrawalModel) FindOne(ctx context.Context, id int64) (*AgentWithdrawal, error) {
func (m *defaultAgentWithdrawalModel) FindOne(ctx context.Context, id string) (*AgentWithdrawal, error) {
yccAgentWithdrawalIdKey := fmt.Sprintf("%s%v", cacheYccAgentWithdrawalIdPrefix, id)
var resp AgentWithdrawal
err := m.QueryRowCtx(ctx, &resp, yccAgentWithdrawalIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
@@ -384,7 +403,7 @@ func (m *defaultAgentWithdrawalModel) Trans(ctx context.Context, fn func(ctx con
func (m *defaultAgentWithdrawalModel) SelectBuilder() squirrel.SelectBuilder {
return squirrel.Select().From(m.table)
}
func (m *defaultAgentWithdrawalModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
func (m *defaultAgentWithdrawalModel) Delete(ctx context.Context, session sqlx.Session, id string) error {
data, err := m.FindOne(ctx, id)
if err != nil {
return err