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,23 +8,24 @@ import (
"fmt"
"strings"
"reflect"
"time"
"ycc-server/common/globalkey"
"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"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
"ycc-server/common/globalkey"
)
var (
orderRefundFieldNames = builder.RawFieldNames(&OrderRefund{})
orderRefundRows = strings.Join(orderRefundFieldNames, ",")
orderRefundRowsExpectAutoSet = strings.Join(stringx.Remove(orderRefundFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
orderRefundRowsExpectAutoSet = strings.Join(stringx.Remove(orderRefundFieldNames, "`create_time`", "`update_time`"), ",")
orderRefundRowsWithPlaceHolder = strings.Join(stringx.Remove(orderRefundFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
cacheYccOrderRefundIdPrefix = "cache:ycc:orderRefund:id:"
@@ -35,7 +36,7 @@ var (
type (
orderRefundModel interface {
Insert(ctx context.Context, session sqlx.Session, data *OrderRefund) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*OrderRefund, error)
FindOne(ctx context.Context, id string) (*OrderRefund, error)
FindOneByPlatformRefundId(ctx context.Context, platformRefundId sql.NullString) (*OrderRefund, error)
FindOneByRefundNo(ctx context.Context, refundNo string) (*OrderRefund, error)
Update(ctx context.Context, session sqlx.Session, data *OrderRefund) (sql.Result, error)
@@ -50,7 +51,7 @@ type (
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*OrderRefund, int64, error)
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*OrderRefund, error)
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*OrderRefund, error)
Delete(ctx context.Context, session sqlx.Session, id int64) error
Delete(ctx context.Context, session sqlx.Session, id string) error
}
defaultOrderRefundModel struct {
@@ -59,11 +60,11 @@ type (
}
OrderRefund struct {
Id int64 `db:"id"` // 主键ID
RefundNo string `db:"refund_no"` // 退款单号
OrderId int64 `db:"order_id"` // 关联的订单ID
UserId int64 `db:"user_id"` // 用户ID
ProductId int64 `db:"product_id"` // 产品ID
Id string `db:"id"`
RefundNo string `db:"refund_no"` // 退款单号
OrderId string `db:"order_id"`
UserId string `db:"user_id"`
ProductId string `db:"product_id"`
PlatformRefundId sql.NullString `db:"platform_refund_id"` // 支付平台退款单号
RefundAmount float64 `db:"refund_amount"` // 退款金额
RefundReason sql.NullString `db:"refund_reason"` // 退款原因
@@ -87,19 +88,36 @@ func newOrderRefundModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultOrderRefu
func (m *defaultOrderRefundModel) Insert(ctx context.Context, session sqlx.Session, data *OrderRefund) (sql.Result, error) {
data.DelState = globalkey.DelStateNo
m.insertUUID(data)
yccOrderRefundIdKey := fmt.Sprintf("%s%v", cacheYccOrderRefundIdPrefix, data.Id)
yccOrderRefundPlatformRefundIdKey := fmt.Sprintf("%s%v", cacheYccOrderRefundPlatformRefundIdPrefix, data.PlatformRefundId)
yccOrderRefundRefundNoKey := fmt.Sprintf("%s%v", cacheYccOrderRefundRefundNoPrefix, data.RefundNo)
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, orderRefundRowsExpectAutoSet)
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, orderRefundRowsExpectAutoSet)
if session != nil {
return session.ExecCtx(ctx, query, data.RefundNo, data.OrderId, data.UserId, data.ProductId, data.PlatformRefundId, data.RefundAmount, data.RefundReason, data.Status, data.DelState, data.Version, data.RefundTime, data.CloseTime, data.DeleteTime)
return session.ExecCtx(ctx, query, data.Id, data.RefundNo, data.OrderId, data.UserId, data.ProductId, data.PlatformRefundId, data.RefundAmount, data.RefundReason, data.Status, data.DelState, data.Version, data.RefundTime, data.CloseTime, data.DeleteTime)
}
return conn.ExecCtx(ctx, query, data.RefundNo, data.OrderId, data.UserId, data.ProductId, data.PlatformRefundId, data.RefundAmount, data.RefundReason, data.Status, data.DelState, data.Version, data.RefundTime, data.CloseTime, data.DeleteTime)
return conn.ExecCtx(ctx, query, data.Id, data.RefundNo, data.OrderId, data.UserId, data.ProductId, data.PlatformRefundId, data.RefundAmount, data.RefundReason, data.Status, data.DelState, data.Version, data.RefundTime, data.CloseTime, data.DeleteTime)
}, yccOrderRefundIdKey, yccOrderRefundPlatformRefundIdKey, yccOrderRefundRefundNoKey)
}
func (m *defaultOrderRefundModel) insertUUID(data *OrderRefund) {
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 *defaultOrderRefundModel) FindOne(ctx context.Context, id int64) (*OrderRefund, error) {
func (m *defaultOrderRefundModel) FindOne(ctx context.Context, id string) (*OrderRefund, error) {
yccOrderRefundIdKey := fmt.Sprintf("%s%v", cacheYccOrderRefundIdPrefix, id)
var resp OrderRefund
err := m.QueryRowCtx(ctx, &resp, yccOrderRefundIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
@@ -411,7 +429,7 @@ func (m *defaultOrderRefundModel) Trans(ctx context.Context, fn func(ctx context
func (m *defaultOrderRefundModel) SelectBuilder() squirrel.SelectBuilder {
return squirrel.Select().From(m.table)
}
func (m *defaultOrderRefundModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
func (m *defaultOrderRefundModel) Delete(ctx context.Context, session sqlx.Session, id string) error {
data, err := m.FindOne(ctx, id)
if err != nil {
return err