diff --git a/backend/app/services/order.go b/backend/app/services/order.go index 436b3d4..841285b 100644 --- a/backend/app/services/order.go +++ b/backend/app/services/order.go @@ -14,6 +14,7 @@ import ( "quyun/v2/pkg/consts" "github.com/google/uuid" + "go.ipao.vip/gen/field" "go.ipao.vip/gen/types" "gorm.io/gorm" ) @@ -29,8 +30,10 @@ func (s *order) ListUserOrders(ctx context.Context, tenantID, userID int64, stat tbl, q := models.OrderQuery.QueryContext(ctx) if tenantID > 0 { - q = q.Where(tbl.UserID.Eq(uid), tbl.TenantID.Eq(tenantID)). - Or(tbl.UserID.Eq(uid), tbl.Type.Eq(consts.OrderTypeRecharge)) + q = q.Where(field.Or( + field.And(tbl.UserID.Eq(uid), tbl.TenantID.Eq(tenantID)), + field.And(tbl.UserID.Eq(uid), tbl.Type.Eq(consts.OrderTypeRecharge)), + )) } else { 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) itemQuery := q if tenantID > 0 { - itemQuery = itemQuery.Where(tbl.ID.Eq(id), tbl.UserID.Eq(uid), tbl.TenantID.Eq(tenantID)). - Or(tbl.ID.Eq(id), tbl.UserID.Eq(uid), tbl.Type.Eq(consts.OrderTypeRecharge)) + itemQuery = itemQuery.Where(field.Or( + 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 { itemQuery = itemQuery.Where(tbl.ID.Eq(id), tbl.UserID.Eq(uid)) } diff --git a/backend/app/services/wallet.go b/backend/app/services/wallet.go index 9d17f49..c9b26c1 100644 --- a/backend/app/services/wallet.go +++ b/backend/app/services/wallet.go @@ -12,6 +12,7 @@ import ( "quyun/v2/pkg/consts" "github.com/google/uuid" + "go.ipao.vip/gen/field" "go.ipao.vip/gen/types" "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) tbl, q := models.OrderQuery.QueryContext(ctx) if tenantID > 0 { - q = q.Where(tbl.UserID.Eq(userID), tbl.Status.Eq(consts.OrderStatusPaid), tbl.TenantID.Eq(tenantID)). - Or(tbl.UserID.Eq(userID), tbl.Status.Eq(consts.OrderStatusPaid), tbl.Type.Eq(consts.OrderTypeRecharge)) + q = q.Where(tbl.Status.Eq(consts.OrderStatusPaid)). + 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 { q = q.Where(tbl.UserID.Eq(userID), tbl.Status.Eq(consts.OrderStatusPaid)) }