fix: group order queries to preserve tenant scope
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
|||||||
"quyun/v2/pkg/consts"
|
"quyun/v2/pkg/consts"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"go.ipao.vip/gen/field"
|
||||||
"go.ipao.vip/gen/types"
|
"go.ipao.vip/gen/types"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -29,8 +30,10 @@ func (s *order) ListUserOrders(ctx context.Context, tenantID, userID int64, stat
|
|||||||
|
|
||||||
tbl, q := models.OrderQuery.QueryContext(ctx)
|
tbl, q := models.OrderQuery.QueryContext(ctx)
|
||||||
if tenantID > 0 {
|
if tenantID > 0 {
|
||||||
q = q.Where(tbl.UserID.Eq(uid), tbl.TenantID.Eq(tenantID)).
|
q = q.Where(field.Or(
|
||||||
Or(tbl.UserID.Eq(uid), tbl.Type.Eq(consts.OrderTypeRecharge))
|
field.And(tbl.UserID.Eq(uid), tbl.TenantID.Eq(tenantID)),
|
||||||
|
field.And(tbl.UserID.Eq(uid), tbl.Type.Eq(consts.OrderTypeRecharge)),
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
q = q.Where(tbl.UserID.Eq(uid))
|
q = q.Where(tbl.UserID.Eq(uid))
|
||||||
}
|
}
|
||||||
@@ -60,8 +63,10 @@ func (s *order) GetUserOrder(ctx context.Context, tenantID, userID, id int64) (*
|
|||||||
tbl, q := models.OrderQuery.QueryContext(ctx)
|
tbl, q := models.OrderQuery.QueryContext(ctx)
|
||||||
itemQuery := q
|
itemQuery := q
|
||||||
if tenantID > 0 {
|
if tenantID > 0 {
|
||||||
itemQuery = itemQuery.Where(tbl.ID.Eq(id), tbl.UserID.Eq(uid), tbl.TenantID.Eq(tenantID)).
|
itemQuery = itemQuery.Where(field.Or(
|
||||||
Or(tbl.ID.Eq(id), tbl.UserID.Eq(uid), tbl.Type.Eq(consts.OrderTypeRecharge))
|
field.And(tbl.ID.Eq(id), tbl.UserID.Eq(uid), tbl.TenantID.Eq(tenantID)),
|
||||||
|
field.And(tbl.ID.Eq(id), tbl.UserID.Eq(uid), tbl.Type.Eq(consts.OrderTypeRecharge)),
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
itemQuery = itemQuery.Where(tbl.ID.Eq(id), tbl.UserID.Eq(uid))
|
itemQuery = itemQuery.Where(tbl.ID.Eq(id), tbl.UserID.Eq(uid))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"quyun/v2/pkg/consts"
|
"quyun/v2/pkg/consts"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"go.ipao.vip/gen/field"
|
||||||
"go.ipao.vip/gen/types"
|
"go.ipao.vip/gen/types"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -33,8 +34,11 @@ func (s *wallet) GetWallet(ctx context.Context, tenantID, userID int64) (*user_d
|
|||||||
// Both purchase (expense) and recharge (income - if paid)
|
// Both purchase (expense) and recharge (income - if paid)
|
||||||
tbl, q := models.OrderQuery.QueryContext(ctx)
|
tbl, q := models.OrderQuery.QueryContext(ctx)
|
||||||
if tenantID > 0 {
|
if tenantID > 0 {
|
||||||
q = q.Where(tbl.UserID.Eq(userID), tbl.Status.Eq(consts.OrderStatusPaid), tbl.TenantID.Eq(tenantID)).
|
q = q.Where(tbl.Status.Eq(consts.OrderStatusPaid)).
|
||||||
Or(tbl.UserID.Eq(userID), tbl.Status.Eq(consts.OrderStatusPaid), tbl.Type.Eq(consts.OrderTypeRecharge))
|
Where(field.Or(
|
||||||
|
field.And(tbl.UserID.Eq(userID), tbl.TenantID.Eq(tenantID)),
|
||||||
|
field.And(tbl.UserID.Eq(userID), tbl.Type.Eq(consts.OrderTypeRecharge)),
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
q = q.Where(tbl.UserID.Eq(userID), tbl.Status.Eq(consts.OrderStatusPaid))
|
q = q.Where(tbl.UserID.Eq(userID), tbl.Status.Eq(consts.OrderStatusPaid))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user