fix(dashboard): scope owner and service views by resolved shop
This commit is contained in:
@@ -12,6 +12,8 @@ import {
|
||||
TableRow,
|
||||
} from "@/components/ui/table"
|
||||
import { listTransactions } from "@/lib/api"
|
||||
import { isActiveOrder, isCompletedOrder } from "@/lib/domain/order-filters"
|
||||
import { resolveOwnerShop } from "@/lib/domain/resolve-current-shop"
|
||||
import { useAuthStore } from "@/store/auth"
|
||||
import { useOrderStore } from "@/store/orders"
|
||||
import { useShopStore } from "@/store/shops"
|
||||
@@ -20,9 +22,14 @@ export default function ShopIncomePage() {
|
||||
const userId = useAuthStore((state) => state.user?.id)
|
||||
const shops = useShopStore((state) => state.shops)
|
||||
const orders = useOrderStore((state) => state.orders)
|
||||
const shop = shops.find((item) => item.owner.id === userId) ?? shops[0]
|
||||
const shop = resolveOwnerShop(userId, shops)
|
||||
|
||||
if (!shop) {
|
||||
return <div className="text-sm text-muted-foreground">当前账号没有可管理的店铺</div>
|
||||
}
|
||||
|
||||
const shopOrders = orders.filter((order) => order.shopId === shop?.id)
|
||||
const completedOrders = shopOrders.filter((o) => o.status === "completed")
|
||||
const completedOrders = shopOrders.filter((o) => isCompletedOrder(o.status))
|
||||
const totalIncome = completedOrders.reduce((acc, order) => acc + order.totalPrice, 0)
|
||||
|
||||
const currentMonth = new Date().getMonth()
|
||||
@@ -31,7 +38,10 @@ export default function ShopIncomePage() {
|
||||
.reduce((acc, order) => acc + order.totalPrice, 0)
|
||||
|
||||
const pendingSettlement = shopOrders
|
||||
.filter((o) => ["in_progress", "pending_close", "pending_review"].includes(o.status))
|
||||
.filter(
|
||||
(o) =>
|
||||
isActiveOrder(o.status) && o.status !== "pending_payment" && o.status !== "pending_accept",
|
||||
)
|
||||
.reduce((acc, order) => acc + order.totalPrice, 0)
|
||||
|
||||
const shopOrderIds = new Set(shopOrders.map((order) => order.id))
|
||||
|
||||
Reference in New Issue
Block a user